diff options
| author | Heiner Kallweit <hkallweit1@gmail.com> | 2017-07-12 01:49:28 -0400 |
|---|---|---|
| committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2017-08-31 19:10:13 -0400 |
| commit | d8490fd55ab90e0039242a5f53acf8a6c2c5e961 (patch) | |
| tree | 4cfd89803fe3d974fe172f5beb1ff16cd098b2d9 /drivers/rtc/rtc-ds1307.c | |
| parent | 0b6ee8059448003591cc67fa1ee7db4d979a5bab (diff) | |
rtc: ds1307: improve trickle charger initialization
Instead of storing the trickle_charger_setup value in struct chip_desc
we can let function ds1307_trickle_init return it because it's used
in the probe function only.
This allows us to constify struct chip_desc variables in a next step.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc/rtc-ds1307.c')
| -rw-r--r-- | drivers/rtc/rtc-ds1307.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index eecf6b272d3f..5a3c563fc1e6 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c | |||
| @@ -141,7 +141,6 @@ struct chip_desc { | |||
| 141 | u8 century_bit; | 141 | u8 century_bit; |
| 142 | u8 bbsqi_bit; | 142 | u8 bbsqi_bit; |
| 143 | u16 trickle_charger_reg; | 143 | u16 trickle_charger_reg; |
| 144 | u8 trickle_charger_setup; | ||
| 145 | u8 (*do_trickle_setup)(struct ds1307 *, uint32_t, | 144 | u8 (*do_trickle_setup)(struct ds1307 *, uint32_t, |
| 146 | bool); | 145 | bool); |
| 147 | }; | 146 | }; |
| @@ -941,23 +940,23 @@ static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, | |||
| 941 | return setup; | 940 | return setup; |
| 942 | } | 941 | } |
| 943 | 942 | ||
| 944 | static void ds1307_trickle_init(struct ds1307 *ds1307, | 943 | static u8 ds1307_trickle_init(struct ds1307 *ds1307, |
| 945 | struct chip_desc *chip) | 944 | struct chip_desc *chip) |
| 946 | { | 945 | { |
| 947 | uint32_t ohms = 0; | 946 | uint32_t ohms; |
| 948 | bool diode = true; | 947 | bool diode = true; |
| 949 | 948 | ||
| 950 | if (!chip->do_trickle_setup) | 949 | if (!chip->do_trickle_setup) |
| 951 | goto out; | 950 | return 0; |
| 951 | |||
| 952 | if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", | 952 | if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", |
| 953 | &ohms)) | 953 | &ohms)) |
| 954 | goto out; | 954 | return 0; |
| 955 | |||
| 955 | if (device_property_read_bool(ds1307->dev, "trickle-diode-disable")) | 956 | if (device_property_read_bool(ds1307->dev, "trickle-diode-disable")) |
| 956 | diode = false; | 957 | diode = false; |
| 957 | chip->trickle_charger_setup = chip->do_trickle_setup(ds1307, | 958 | |
| 958 | ohms, diode); | 959 | return chip->do_trickle_setup(ds1307, ohms, diode); |
| 959 | out: | ||
| 960 | return; | ||
| 961 | } | 960 | } |
| 962 | 961 | ||
| 963 | /*----------------------------------------------------------------------*/ | 962 | /*----------------------------------------------------------------------*/ |
| @@ -1319,6 +1318,7 @@ static int ds1307_probe(struct i2c_client *client, | |||
| 1319 | struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); | 1318 | struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); |
| 1320 | struct rtc_time tm; | 1319 | struct rtc_time tm; |
| 1321 | unsigned long timestamp; | 1320 | unsigned long timestamp; |
| 1321 | u8 trickle_charger_setup = 0; | ||
| 1322 | 1322 | ||
| 1323 | irq_handler_t irq_handler = ds1307_irq; | 1323 | irq_handler_t irq_handler = ds1307_irq; |
| 1324 | 1324 | ||
| @@ -1359,18 +1359,17 @@ static int ds1307_probe(struct i2c_client *client, | |||
| 1359 | } | 1359 | } |
| 1360 | 1360 | ||
| 1361 | if (!pdata) | 1361 | if (!pdata) |
| 1362 | ds1307_trickle_init(ds1307, chip); | 1362 | trickle_charger_setup = ds1307_trickle_init(ds1307, chip); |
| 1363 | else if (pdata->trickle_charger_setup) | 1363 | else if (pdata->trickle_charger_setup) |
| 1364 | chip->trickle_charger_setup = pdata->trickle_charger_setup; | 1364 | trickle_charger_setup = pdata->trickle_charger_setup; |
| 1365 | 1365 | ||
| 1366 | if (chip->trickle_charger_setup && chip->trickle_charger_reg) { | 1366 | if (trickle_charger_setup && chip->trickle_charger_reg) { |
| 1367 | trickle_charger_setup |= DS13XX_TRICKLE_CHARGER_MAGIC; | ||
| 1367 | dev_dbg(ds1307->dev, | 1368 | dev_dbg(ds1307->dev, |
| 1368 | "writing trickle charger info 0x%x to 0x%x\n", | 1369 | "writing trickle charger info 0x%x to 0x%x\n", |
| 1369 | DS13XX_TRICKLE_CHARGER_MAGIC | chip->trickle_charger_setup, | 1370 | trickle_charger_setup, chip->trickle_charger_reg); |
| 1370 | chip->trickle_charger_reg); | ||
| 1371 | regmap_write(ds1307->regmap, chip->trickle_charger_reg, | 1371 | regmap_write(ds1307->regmap, chip->trickle_charger_reg, |
| 1372 | DS13XX_TRICKLE_CHARGER_MAGIC | | 1372 | trickle_charger_setup); |
| 1373 | chip->trickle_charger_setup); | ||
| 1374 | } | 1373 | } |
| 1375 | 1374 | ||
| 1376 | buf = ds1307->regs; | 1375 | buf = ds1307->regs; |
