[PATCH 2/5] Modify several rtc drivers to use the alias names list property of i2c

2007-12-19 Thread Jon Smirl
This patch modifies the ds1307, ds1374, and rs5c372 i2c drivers to support
device tree names using the new i2c mod alias support

Signed-off-by: Jon Smirl <[EMAIL PROTECTED]>
---

 arch/powerpc/sysdev/fsl_soc.c |   44 
 drivers/rtc/rtc-ds1307.c  |   20 +-
 drivers/rtc/rtc-ds1374.c  |9 ++
 drivers/rtc/rtc-m41t80.c  |   57 -
 drivers/rtc/rtc-rs5c372.c |   16 ++--
 5 files changed, 85 insertions(+), 61 deletions(-)


diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 3ace747..268638a 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -320,48 +320,12 @@ arch_initcall(gfar_of_init);
 
 #ifdef CONFIG_I2C_BOARDINFO
 #include 
-struct i2c_driver_device {
-   char*of_device;
-   char*i2c_driver;
-   char*i2c_type;
-};
-
-static struct i2c_driver_device i2c_devices[] __initdata = {
-   {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
-   {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
-   {"ricoh,rv5c386",  "rtc-rs5c372", "rv5c386",},
-   {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
-   {"dallas,ds1307",  "rtc-ds1307",  "ds1307",},
-   {"dallas,ds1337",  "rtc-ds1307",  "ds1337",},
-   {"dallas,ds1338",  "rtc-ds1307",  "ds1338",},
-   {"dallas,ds1339",  "rtc-ds1307",  "ds1339",},
-   {"dallas,ds1340",  "rtc-ds1307",  "ds1340",},
-   {"stm,m41t00", "rtc-ds1307",  "m41t00"},
-   {"dallas,ds1374",  "rtc-ds1374",  "rtc-ds1374",},
-};
-
-static int __init of_find_i2c_driver(struct device_node *node,
-struct i2c_board_info *info)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
-   if (!of_device_is_compatible(node, i2c_devices[i].of_device))
-   continue;
-   if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
-   KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
-   strlcpy(info->type, i2c_devices[i].i2c_type,
-   I2C_NAME_SIZE) >= I2C_NAME_SIZE)
-   return -ENOMEM;
-   return 0;
-   }
-   return -ENODEV;
-}
 
 static void __init of_register_i2c_devices(struct device_node *adap_node,
   int bus_num)
 {
struct device_node *node = NULL;
+   const char *compatible;
 
while ((node = of_get_next_child(adap_node, node))) {
struct i2c_board_info info = {};
@@ -378,8 +342,12 @@ static void __init of_register_i2c_devices(struct 
device_node *adap_node,
if (info.irq == NO_IRQ)
info.irq = -1;
 
-   if (of_find_i2c_driver(node, &info) < 0)
+   compatible = of_get_property(node, "compatible", &len);
+   if (!compatible) {
+   printk(KERN_WARNING "i2c-mpc.c: invalid entry, missing 
compatible attribute\n");
continue;
+   }
+   strncpy(info.driver_name, compatible, sizeof(info.driver_name));
 
info.addr = *addr;
 
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index bc1c7fe..d4874ff 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -139,6 +139,17 @@ static inline const struct chip_desc *find_chip(const char 
*s)
return NULL;
 }
 
+static struct i2c_device_id ds1307_id[] = {
+   OF_I2C_ID("dallas,ds1307", ds_1307)
+   OF_I2C_ID("dallas,ds1337", ds_1337)
+   OF_I2C_ID("dallas,ds1338", ds_1338)
+   OF_I2C_ID("dallas,ds1339", ds_1339)
+   OF_I2C_ID("dallas,ds1340", ds_1340)
+   OF_I2C_ID("stm,m41t00", m41t00)
+   {},
+};
+MODULE_DEVICE_TABLE(i2c, ds1307_id);
+
 static int ds1307_get_time(struct device *dev, struct rtc_time *t)
 {
struct ds1307   *ds1307 = dev_get_drvdata(dev);
@@ -326,7 +337,7 @@ static struct bin_attribute nvram = {
 
 static struct i2c_driver ds1307_driver;
 
-static int __devinit ds1307_probe(struct i2c_client *client)
+static int __devinit ds1307_probe(struct i2c_client *client, const struct 
i2c_device_id *id)
 {
struct ds1307   *ds1307;
int err = -ENODEV;
@@ -334,7 +345,11 @@ static int __devinit ds1307_probe(struct i2c_client 
*client)
const struct chip_desc  *chip;
struct i2c_adapter  *adapter = to_i2c_adapter(client->dev.parent);
 
-   chip = find_chip(client->name);
+   if (id)
+   chip = &chips[id->driver_data];
+   else
+   chip = find_chip(client->name);
+
if (!chip) {
dev_err(&client->dev, "unknown chip type '%s'\n",
client->name);
@@ -537,6 +552,7 @@ static struct i2c_driver ds1307_driver = {
},
.probe  = ds1307_probe,
.remove = __devexit_p(ds1307_remove),
+

[PATCH 2/5] Modify several rtc drivers to use the alias names list property of i2c

2007-12-10 Thread Jon Smirl
This patch modifies the ds1307, ds1374, and rs5c372 i2c drivers to support
device tree names using the new i2c mod alias support

Signed-off-by: Jon Smirl <[EMAIL PROTECTED]>
---

 arch/powerpc/sysdev/fsl_soc.c |   44 ++---
 drivers/rtc/rtc-ds1307.c  |   38 +++
 drivers/rtc/rtc-ds1374.c  |   11 +-
 drivers/rtc/rtc-rs5c372.c |   31 -
 4 files changed, 53 insertions(+), 71 deletions(-)


diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 3ace747..268638a 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -320,48 +320,12 @@ arch_initcall(gfar_of_init);
 
 #ifdef CONFIG_I2C_BOARDINFO
 #include 
-struct i2c_driver_device {
-   char*of_device;
-   char*i2c_driver;
-   char*i2c_type;
-};
-
-static struct i2c_driver_device i2c_devices[] __initdata = {
-   {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
-   {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
-   {"ricoh,rv5c386",  "rtc-rs5c372", "rv5c386",},
-   {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
-   {"dallas,ds1307",  "rtc-ds1307",  "ds1307",},
-   {"dallas,ds1337",  "rtc-ds1307",  "ds1337",},
-   {"dallas,ds1338",  "rtc-ds1307",  "ds1338",},
-   {"dallas,ds1339",  "rtc-ds1307",  "ds1339",},
-   {"dallas,ds1340",  "rtc-ds1307",  "ds1340",},
-   {"stm,m41t00", "rtc-ds1307",  "m41t00"},
-   {"dallas,ds1374",  "rtc-ds1374",  "rtc-ds1374",},
-};
-
-static int __init of_find_i2c_driver(struct device_node *node,
-struct i2c_board_info *info)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
-   if (!of_device_is_compatible(node, i2c_devices[i].of_device))
-   continue;
-   if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
-   KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
-   strlcpy(info->type, i2c_devices[i].i2c_type,
-   I2C_NAME_SIZE) >= I2C_NAME_SIZE)
-   return -ENOMEM;
-   return 0;
-   }
-   return -ENODEV;
-}
 
 static void __init of_register_i2c_devices(struct device_node *adap_node,
   int bus_num)
 {
struct device_node *node = NULL;
+   const char *compatible;
 
while ((node = of_get_next_child(adap_node, node))) {
struct i2c_board_info info = {};
@@ -378,8 +342,12 @@ static void __init of_register_i2c_devices(struct 
device_node *adap_node,
if (info.irq == NO_IRQ)
info.irq = -1;
 
-   if (of_find_i2c_driver(node, &info) < 0)
+   compatible = of_get_property(node, "compatible", &len);
+   if (!compatible) {
+   printk(KERN_WARNING "i2c-mpc.c: invalid entry, missing 
compatible attribute\n");
continue;
+   }
+   strncpy(info.driver_name, compatible, sizeof(info.driver_name));
 
info.addr = *addr;
 
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index bc1c7fe..a4dec4b 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -99,45 +99,46 @@ struct ds1307 {
 };
 
 struct chip_desc {
-   charname[9];
unsignednvram56:1;
unsignedalarm:1;
enum ds_typetype;
 };
 
 static const struct chip_desc chips[] = { {
-   .name   = "ds1307",
.type   = ds_1307,
.nvram56= 1,
 }, {
-   .name   = "ds1337",
.type   = ds_1337,
.alarm  = 1,
 }, {
-   .name   = "ds1338",
.type   = ds_1338,
.nvram56= 1,
 }, {
-   .name   = "ds1339",
.type   = ds_1339,
.alarm  = 1,
 }, {
-   .name   = "ds1340",
.type   = ds_1340,
 }, {
-   .name   = "m41t00",
.type   = m41t00,
 }, };
 
-static inline const struct chip_desc *find_chip(const char *s)
-{
-   unsigned i;
-
-   for (i = 0; i < ARRAY_SIZE(chips); i++)
-   if (strnicmp(s, chips[i].name, sizeof chips[i].name) == 0)
-   return &chips[i];
-   return NULL;
-}
+static struct i2c_device_id ds1307_id[] = {
+   {"rtc-ds1307", ds_1307},
+   {"ds1307", ds_1307},
+   {"ds1337", ds_1337},
+   {"ds1338", ds_1338},
+   {"ds1339", ds_1339},
+   {"ds1340", ds_1340},
+   {"m41t00", m41t00},
+   {"dallas,ds1307", ds_1307},
+   {"dallas,ds1337", ds_1337},
+   {"dallas,ds1338", ds_1338},
+   {"dallas,ds1339", ds_1339},
+   {"dallas,ds1340", ds_1340},
+   {"stm,m41t00", m41t00},
+   {},
+};
+MODULE_DEVICE_TABLE(i2c, ds1307_id);