diff mbox

[1/5] rtc: ds1307: factor out determining the chip type

Message ID 6096da22-92b7-ecac-382c-39dbb7f494db@gmail.com
State Superseded
Headers show

Commit Message

Heiner Kallweit Aug. 25, 2017, 8:06 p.m. UTC
ds1307_probe is very long and confusing, so let's factor out
functionalities. As a first step factor out determining the chip type.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/rtc/rtc-ds1307.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)
diff mbox

Patch

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 4f00cea2..2b5c6d60 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1329,6 +1329,21 @@  static void ds1307_clks_register(struct ds1307 *ds1307)
 
 #endif /* CONFIG_COMMON_CLK */
 
+static enum ds_type ds1307_get_type(struct device *dev,
+				    const struct i2c_device_id *id)
+{
+	const struct acpi_device_id *acpi_id;
+
+	if (dev->of_node)
+		return (enum ds_type) of_device_get_match_data(dev);
+
+	if (id)
+		return id->driver_data;
+
+	acpi_id = acpi_match_device(ACPI_PTR(ds1307_acpi_ids), dev);
+	return acpi_id ? acpi_id->driver_data : -ENODEV;
+}
+
 static const struct regmap_config regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -1365,23 +1380,11 @@  static int ds1307_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, ds1307);
 
-	if (client->dev.of_node) {
-		ds1307->type = (enum ds_type)
-			of_device_get_match_data(&client->dev);
-		chip = &chips[ds1307->type];
-	} else if (id) {
-		chip = &chips[id->driver_data];
-		ds1307->type = id->driver_data;
-	} else {
-		const struct acpi_device_id *acpi_id;
-
-		acpi_id = acpi_match_device(ACPI_PTR(ds1307_acpi_ids),
-					    ds1307->dev);
-		if (!acpi_id)
-			return -ENODEV;
-		chip = &chips[acpi_id->driver_data];
-		ds1307->type = acpi_id->driver_data;
-	}
+	ds1307->type = ds1307_get_type(&client->dev, id);
+	if (ds1307->type < 0)
+		return ds1307->type;
+
+	chip = &chips[ds1307->type];
 
 	want_irq = client->irq > 0 && chip->alarm;