aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTin Huynh <tnhuynh@apm.com>2016-11-29 21:57:31 -0500
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-12-18 18:59:07 -0500
commit9c19b8930d2cf95f5dc5ec11610400a7c61845d1 (patch)
tree3ecc209dc12297529094a6771e9f004de893965d
parentb88e0ae958267dc63bea661d66c15f61ba1dd93c (diff)
rtc: ds1307: Add ACPI support
This patch enables ACPI support for rtc-ds1307 driver. Signed-off-by: Tin Huynh <tnhuynh@apm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
-rw-r--r--drivers/rtc/rtc-ds1307.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 4e31036ee259..4ad97be48043 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -11,6 +11,7 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13 13
14#include <linux/acpi.h>
14#include <linux/bcd.h> 15#include <linux/bcd.h>
15#include <linux/i2c.h> 16#include <linux/i2c.h>
16#include <linux/init.h> 17#include <linux/init.h>
@@ -191,6 +192,26 @@ static const struct i2c_device_id ds1307_id[] = {
191}; 192};
192MODULE_DEVICE_TABLE(i2c, ds1307_id); 193MODULE_DEVICE_TABLE(i2c, ds1307_id);
193 194
195#ifdef CONFIG_ACPI
196static const struct acpi_device_id ds1307_acpi_ids[] = {
197 { .id = "DS1307", .driver_data = ds_1307 },
198 { .id = "DS1337", .driver_data = ds_1337 },
199 { .id = "DS1338", .driver_data = ds_1338 },
200 { .id = "DS1339", .driver_data = ds_1339 },
201 { .id = "DS1388", .driver_data = ds_1388 },
202 { .id = "DS1340", .driver_data = ds_1340 },
203 { .id = "DS3231", .driver_data = ds_3231 },
204 { .id = "M41T00", .driver_data = m41t00 },
205 { .id = "MCP7940X", .driver_data = mcp794xx },
206 { .id = "MCP7941X", .driver_data = mcp794xx },
207 { .id = "PT7C4338", .driver_data = ds_1307 },
208 { .id = "RX8025", .driver_data = rx_8025 },
209 { .id = "ISL12057", .driver_data = ds_1337 },
210 { }
211};
212MODULE_DEVICE_TABLE(acpi, ds1307_acpi_ids);
213#endif
214
194/*----------------------------------------------------------------------*/ 215/*----------------------------------------------------------------------*/
195 216
196#define BLOCK_DATA_MAX_TRIES 10 217#define BLOCK_DATA_MAX_TRIES 10
@@ -874,17 +895,17 @@ static u8 do_trickle_setup_ds1339(struct i2c_client *client,
874 return setup; 895 return setup;
875} 896}
876 897
877static void ds1307_trickle_of_init(struct i2c_client *client, 898static void ds1307_trickle_init(struct i2c_client *client,
878 struct chip_desc *chip) 899 struct chip_desc *chip)
879{ 900{
880 uint32_t ohms = 0; 901 uint32_t ohms = 0;
881 bool diode = true; 902 bool diode = true;
882 903
883 if (!chip->do_trickle_setup) 904 if (!chip->do_trickle_setup)
884 goto out; 905 goto out;
885 if (of_property_read_u32(client->dev.of_node, "trickle-resistor-ohms" , &ohms)) 906 if (device_property_read_u32(&client->dev, "trickle-resistor-ohms", &ohms))
886 goto out; 907 goto out;
887 if (of_property_read_bool(client->dev.of_node, "trickle-diode-disable")) 908 if (device_property_read_bool(&client->dev, "trickle-diode-disable"))
888 diode = false; 909 diode = false;
889 chip->trickle_charger_setup = chip->do_trickle_setup(client, 910 chip->trickle_charger_setup = chip->do_trickle_setup(client,
890 ohms, diode); 911 ohms, diode);
@@ -1268,7 +1289,7 @@ static int ds1307_probe(struct i2c_client *client,
1268 struct ds1307 *ds1307; 1289 struct ds1307 *ds1307;
1269 int err = -ENODEV; 1290 int err = -ENODEV;
1270 int tmp, wday; 1291 int tmp, wday;
1271 struct chip_desc *chip = &chips[id->driver_data]; 1292 struct chip_desc *chip;
1272 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1293 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1273 bool want_irq = false; 1294 bool want_irq = false;
1274 bool ds1307_can_wakeup_device = false; 1295 bool ds1307_can_wakeup_device = false;
@@ -1297,11 +1318,23 @@ static int ds1307_probe(struct i2c_client *client,
1297 i2c_set_clientdata(client, ds1307); 1318 i2c_set_clientdata(client, ds1307);
1298 1319
1299 ds1307->client = client; 1320 ds1307->client = client;
1300 ds1307->type = id->driver_data; 1321 if (id) {
1322 chip = &chips[id->driver_data];
1323 ds1307->type = id->driver_data;
1324 } else {
1325 const struct acpi_device_id *acpi_id;
1326
1327 acpi_id = acpi_match_device(ACPI_PTR(ds1307_acpi_ids),
1328 &client->dev);
1329 if (!acpi_id)
1330 return -ENODEV;
1331 chip = &chips[acpi_id->driver_data];
1332 ds1307->type = acpi_id->driver_data;
1333 }
1301 1334
1302 if (!pdata && client->dev.of_node) 1335 if (!pdata)
1303 ds1307_trickle_of_init(client, chip); 1336 ds1307_trickle_init(client, chip);
1304 else if (pdata && pdata->trickle_charger_setup) 1337 else if (pdata->trickle_charger_setup)
1305 chip->trickle_charger_setup = pdata->trickle_charger_setup; 1338 chip->trickle_charger_setup = pdata->trickle_charger_setup;
1306 1339
1307 if (chip->trickle_charger_setup && chip->trickle_charger_reg) { 1340 if (chip->trickle_charger_setup && chip->trickle_charger_reg) {
@@ -1678,6 +1711,7 @@ static int ds1307_remove(struct i2c_client *client)
1678static struct i2c_driver ds1307_driver = { 1711static struct i2c_driver ds1307_driver = {
1679 .driver = { 1712 .driver = {
1680 .name = "rtc-ds1307", 1713 .name = "rtc-ds1307",
1714 .acpi_match_table = ACPI_PTR(ds1307_acpi_ids),
1681 }, 1715 },
1682 .probe = ds1307_probe, 1716 .probe = ds1307_probe,
1683 .remove = ds1307_remove, 1717 .remove = ds1307_remove,