Skip to contentSkip to conversation

Implement device tree based i2c module loading on mpc5200 powerpc

PATCH In review Jon Smirl 4 participants 6 messages Jan 28, 2008 3 messages not in the archive

Subsystems (6)
lore
Share & tools
lore

Jon Smirl

author
#0 lore raw

cover Implement device tree based i2c module loading on mpc5200 powerpc

These are the final three patches in the series implementing device tree directed loading of i2c modules on mpc5200 powerpc. These patches have been posted multiple times. This revision implements a few minor changes suggested in the last two weeks.

A message that is not in the archive (sent off-list or not yet received): 20080128144202.8410.14647.stgit-+J+k29bDNxlBDLzU/[email protected]

author
#2 lore raw

PATCH 1/3 Rename i2c-mpc to i2c-mpc-drv in preparation for breaking out common code.

Rename i2c-mpc to i2c-mpc-drv in preparation for breaking out common code.

---

 drivers/i2c/busses/Makefile      |    2 
 drivers/i2c/busses/i2c-mpc-drv.c |  421 ++++++++++++++++++++++++++++++++++++++
 drivers/i2c/busses/i2c-mpc.c     |  421 --------------------------------------
 3 files changed, 423 insertions(+), 421 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-mpc-drv.c
 delete mode 100644 drivers/i2c/busses/i2c-mpc.c
drivers/i2c/busses/Makefile +2 -0
index ea7068f..171800d 100644
@@ -2,6 +2,8 @@
 # Makefile for the i2c bus drivers.
 #
 
+i2c-mpc-objs	:= i2c-mpc-drv.o
+
 obj-$(CONFIG_I2C_ALI1535)	+= i2c-ali1535.o
 obj-$(CONFIG_I2C_ALI1563)	+= i2c-ali1563.o
 obj-$(CONFIG_I2C_ALI15X3)	+= i2c-ali15x3.o
drivers/i2c/busses/i2c-mpc-drv.c renamed from drivers/i2c/busses/i2c-mpc.c +0 -0
similarity index 100%
rename from drivers/i2c/busses/i2c-mpc.c
rename to drivers/i2c/busses/i2c-mpc-drv.c

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

author
#3 lore raw

PATCH 3/3 Add device tree compatible aliases to i2c drivers

In reply to a message not in the archive

PowerPC device trees use a different naming convention than the Linux kernel. Provide alias names for i2c drivers in order to allow them to be loaded by device tree name. The OF_ID macro ensures that the aliases are only present in powerpc builds and separated into their own namespace.

---

 drivers/hwmon/f75375s.c      |    2 ++
 drivers/i2c/chips/ds1682.c   |    1 +
 drivers/i2c/chips/menelaus.c |    1 +
 drivers/i2c/chips/tps65010.c |    4 ++++
 drivers/i2c/chips/tsl2550.c  |    1 +
 drivers/rtc/rtc-ds1307.c     |    6 ++++++
 drivers/rtc/rtc-ds1374.c     |    1 +
 drivers/rtc/rtc-m41t80.c     |    8 ++++++++
 drivers/rtc/rtc-pcf8563.c    |    2 ++
 drivers/rtc/rtc-rs5c372.c    |    4 ++++
 10 files changed, 30 insertions(+), 0 deletions(-)
drivers/hwmon/f75375s.c +2 -0
index 4cb4db4..dd548e7 100644
@@ -132,6 +132,8 @@ static struct i2c_driver f75375_legacy_driver = {
 static const struct i2c_device_id f75375_id[] = {
 	{ "f75373", f75373 },
 	{ "f75375", f75375 },
+	OF_ID("fintek,f75373", f75373)
+	OF_ID("fintek,f75375", f75375)
 	{ },
 };
 MODULE_DEVICE_TABLE(i2c, f75375_id);
drivers/i2c/chips/ds1682.c +1 -0
index 51ff518..817ad1f 100644
@@ -237,6 +237,7 @@ static int ds1682_remove(struct i2c_client *client)
 
 static const struct i2c_device_id ds1682_id[] = {
 	{ "ds1682", 0 },
+	OF_ID("dallas,ds1682", 0)
 	{ },
 };
 MODULE_DEVICE_TABLE(i2c, ds1682_id);
drivers/i2c/chips/menelaus.c +1 -0
index 1f9ac5e..ba7d619 100644
@@ -1245,6 +1245,7 @@ static int __exit menelaus_remove(struct i2c_client *client)
 
 static const struct i2c_device_id menelaus_id[] = {
 	{ "menelaus", 0 },
+	OF_ID("ti,twl92330", 0)
 	{ },
 };
 MODULE_DEVICE_TABLE(i2c, menelaus_id);
drivers/i2c/chips/tps65010.c +4 -0
index e07274d..9cd1770 100644
@@ -571,6 +571,10 @@ static const struct i2c_device_id tps65010_id[] = {
 	{ "tps65011", TPS65011 },
 	{ "tps65012", TPS65012 },
 	{ "tps65013", TPS65013 },
+	OF_ID("ti,tps65010", TPS65010)
+	OF_ID("ti,tps65011", TPS65011)
+	OF_ID("ti,tps65012", TPS65012)
+	OF_ID("ti,tps65013", TPS65013)
 	{ },
 };
 MODULE_DEVICE_TABLE(i2c, tps65010_id);
drivers/i2c/chips/tsl2550.c +1 -0
index 2add8be..8071d6d 100644
@@ -454,6 +454,7 @@ static int tsl2550_resume(struct i2c_client *client)
 
 static const struct i2c_device_id tsl2550_id[] = {
 	{ "tsl2550", 0 },
+	OF_ID("taos,tsl2550", 0)
 	{ },
 };
 MODULE_DEVICE_TABLE(i2c, tsl2550_id);
drivers/rtc/rtc-ds1307.c +6 -0
index a5614ab..e363a5f 100644
@@ -129,6 +129,12 @@ static const struct i2c_device_id ds1307_id[] = {
 	{ "ds1339", ds_1339 },
 	{ "ds1340", ds_1340 },
 	{ "m41t00", m41t00 },
+	OF_ID("dallas,ds1307", ds_1307)
+	OF_ID("dallas,ds1337", ds_1337)
+	OF_ID("dallas,ds1338", ds_1338)
+	OF_ID("dallas,ds1339", ds_1339)
+	OF_ID("dallas,ds1340", ds_1340)
+	OF_ID("stm,m41t00", m41t00)
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, ds1307_id);
drivers/rtc/rtc-ds1374.c +1 -0
index 376ceeb..e4f680a 100644
@@ -43,6 +43,7 @@
 
 static const struct i2c_device_id ds1374_id[] = {
 	{ "ds1374", 0 },
+	OF_ID("dallas,ds1374", 0)
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, ds1374_id);
drivers/rtc/rtc-m41t80.c +8 -0
index c672557..663f8b5 100644
@@ -69,6 +69,14 @@ static const struct i2c_device_id m41t80_id[] = {
 	{ "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
 	{ "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
 	{ "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
+	OF_ID("stm,m41t80", 0)
+	OF_ID("stm,m41t81", M41T80_FEATURE_HT)
+	OF_ID("stm,m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL)
+	OF_ID("stm,m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL)
+	OF_ID("stm,m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL)
+	OF_ID("stm,m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL)
+	OF_ID("stm,m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL)
+	OF_ID("stm,m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL)
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, m41t80_id);
drivers/rtc/rtc-pcf8563.c +2 -0
index 8eff549..51d7471 100644
@@ -263,6 +263,8 @@ static int pcf8563_remove(struct i2c_client *client)
 static struct i2c_device_id pcf8563_id[] = {
 	{"pcf8563", 0},
 	{"rtc8564", 0},
+	OF_ID("phillips,pcf8563", 0)
+	OF_ID("epson,rtc8564", 0)
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, pcf8563_id);
drivers/rtc/rtc-rs5c372.c +4 -0
index a3e4f8d..cdd26c3 100644
@@ -74,6 +74,10 @@ static const struct i2c_device_id rs5c372_id[] = {
 	{ "rs5c372b", rtc_rs5c372b },
 	{ "rv5c386", rtc_rv5c386 },
 	{ "rv5c387a", rtc_rv5c387a },
+	OF_ID("ricoh,rs5c372a", rtc_rs5c372a)
+	OF_ID("ricoh,rs5c372b", rtc_rs5c372b)
+	OF_ID("ricoh,rv5c386", rtc_rv5c386)
+	OF_ID("ricoh,rv5c387a", rtc_rv5c387a)
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, rs5c372_id);

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

A message that is not in the archive (sent off-list or not yet received): 20080128144209.8410.37884.stgit-+J+k29bDNxlBDLzU/[email protected]

#5 lore raw

Re: [PATCH 3/3] Add device tree compatible aliases to i2c drivers

Quoted 4 lines · Jon Smirl

PowerPC device trees use a different naming convention than the Linux kernel. Provide alias names for i2c drivers in order to allow them to be loaded by device tree name. The OF_ID macro ensures that the aliases are only present in powerpc builds and separated into their own namespace.

---

Hi Jon,

Any chance we can have hard 70-ish column limited
log messages, please?

Thanks,
jdl

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

#6 lore raw

PATCH 2/3 Convert PowerPC MPC i2c to of_platform_driver from platform_driver

In reply to Jon Smirl

Convert MPC i2c driver from a platform_driver to a of_platform_driver. Add the ability to dynamically load i2c drivers based on device tree names. Routine names were changed from fsl_ to mpc_ to make them match the file name. Common code moved to powerpc-common.* Orginal ppc driver left intact for deletion when ppc arch is removed.

---

 arch/powerpc/sysdev/fsl_soc.c       |  125 ---------------------------
 drivers/i2c/busses/Makefile         |    2 
 drivers/i2c/busses/i2c-mpc-drv.c    |  164 ++++++++++++++++++++++++++++++++---
 drivers/i2c/busses/powerpc-common.c |   81 +++++++++++++++++
 drivers/i2c/busses/powerpc-common.h |   23 +++++
 include/linux/mod_devicetable.h     |    9 ++
 6 files changed, 263 insertions(+), 141 deletions(-)
 create mode 100644 drivers/i2c/busses/powerpc-common.c
 create mode 100644 drivers/i2c/busses/powerpc-common.h
arch/powerpc/sysdev/fsl_soc.c +0 -125
index e4b14a5..d6ef264 100644
@@ -318,131 +318,6 @@ err:
 
 arch_initcall(gfar_of_init);
 
-#ifdef CONFIG_I2C_BOARDINFO
-#include <linux/i2c.h>
-struct i2c_driver_device {
-	char	*of_device;
-	char	*i2c_type;
-};
-
-static struct i2c_driver_device i2c_devices[] __initdata = {
-	{"ricoh,rs5c372a", "rs5c372a",},
-	{"ricoh,rs5c372b", "rs5c372b",},
-	{"ricoh,rv5c386",  "rv5c386",},
-	{"ricoh,rv5c387a", "rv5c387a",},
-	{"dallas,ds1307",  "ds1307",},
-	{"dallas,ds1337",  "ds1337",},
-	{"dallas,ds1338",  "ds1338",},
-	{"dallas,ds1339",  "ds1339",},
-	{"dallas,ds1340",  "ds1340",},
-	{"stm,m41t00",     "m41t00"},
-	{"dallas,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->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;
-
-	while ((node = of_get_next_child(adap_node, node))) {
-		struct i2c_board_info info = {};
-		const u32 *addr;
-		int len;
-
-		addr = of_get_property(node, "reg", &len);
-		if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
-			printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
-			continue;
-		}
-
-		info.irq = irq_of_parse_and_map(node, 0);
-		if (info.irq == NO_IRQ)
-			info.irq = -1;
-
-		if (of_find_i2c_driver(node, &info) < 0)
-			continue;
-
-		info.addr = *addr;
-
-		i2c_register_board_info(bus_num, &info, 1);
-	}
-}
-
-static int __init fsl_i2c_of_init(void)
-{
-	struct device_node *np;
-	unsigned int i;
-	struct platform_device *i2c_dev;
-	int ret;
-
-	for (np = NULL, i = 0;
-	     (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
-	     i++) {
-		struct resource r[2];
-		struct fsl_i2c_platform_data i2c_data;
-		const unsigned char *flags = NULL;
-
-		memset(&r, 0, sizeof(r));
-		memset(&i2c_data, 0, sizeof(i2c_data));
-
-		ret = of_address_to_resource(np, 0, &r[0]);
-		if (ret)
-			goto err;
-
-		of_irq_to_resource(np, 0, &r[1]);
-
-		i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
-		if (IS_ERR(i2c_dev)) {
-			ret = PTR_ERR(i2c_dev);
-			goto err;
-		}
-
-		i2c_data.device_flags = 0;
-		flags = of_get_property(np, "dfsrr", NULL);
-		if (flags)
-			i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
-
-		flags = of_get_property(np, "fsl5200-clocking", NULL);
-		if (flags)
-			i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
-
-		ret =
-		    platform_device_add_data(i2c_dev, &i2c_data,
-					     sizeof(struct
-						    fsl_i2c_platform_data));
-		if (ret)
-			goto unreg;
-
-		of_register_i2c_devices(np, i);
-	}
-
-	return 0;
-
-unreg:
-	platform_device_unregister(i2c_dev);
-err:
-	return ret;
-}
-
-arch_initcall(fsl_i2c_of_init);
-#endif
-
 #ifdef CONFIG_PPC_83xx
 static int __init mpc83xx_wdt_init(void)
 {
drivers/i2c/busses/Makefile +1 -1
index 171800d..e94241f 100644
@@ -2,7 +2,7 @@
 # Makefile for the i2c bus drivers.
 #
 
-i2c-mpc-objs	:= i2c-mpc-drv.o
+i2c-mpc-objs	:= i2c-mpc-drv.o powerpc-common.o
 
 obj-$(CONFIG_I2C_ALI1535)	+= i2c-ali1535.o
 obj-$(CONFIG_I2C_ALI1563)	+= i2c-ali1563.o
drivers/i2c/busses/i2c-mpc-drv.c +150 -14

238 lines not on this page · raw message

drivers/i2c/busses/powerpc-common.c new file +81 -0

81 lines not on this page · raw message

drivers/i2c/busses/powerpc-common.h new file +23 -0
new file mode 100644
index 0000000..95f1347
@@ -0,0 +1,23 @@
+/*
+ * powerpc-common.h - routines common to device tree parsing for all
+ *                    powerpc based i2c hosts
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * (C) Copyright 2008 Jon Smirl <[email protected]>
+ *
+ */
+
+void of_register_i2c_devices(struct i2c_adapter *adap, struct device_node *adap_node);
include/linux/mod_devicetable.h +8 -1
index d1488a0..2e53b39 100644
@@ -371,8 +371,15 @@ struct virtio_device_id {
 
 /* These defines are used to separate PowerPC open firmware
  * drivers into their own namespace */
-#define I2C_NAME_SIZE	20
+#define I2C_NAME_SIZE	48  /* Needs to be large enough to hold device tree style names */
 #define I2C_MODULE_PREFIX "i2c:"
+#ifdef CONFIG_OF
+#define OF_PREFIX "OF," /* Used to put OF device tree names into their own namespace */
+#define I2C_OF_MODULE_PREFIX I2C_MODULE_PREFIX OF_PREFIX
+#define OF_ID(s, d) { OF_PREFIX s, (d) },
+#else
+#define OF_ID(s, d)
+#endif
 
 struct i2c_device_id {
 	char name[I2C_NAME_SIZE];

A message that is not in the archive (sent off-list or not yet received): 20080128144206.8410.2505.stgit-+J+k29bDNxlBDLzU/[email protected]

#8 lore raw

Re: [PATCH 2/3] Convert PowerPC MPC i2c to of_platform_driver from platform_driver

Hi,

Nice to see this one, I've been waiting for it. :)

drivers/i2c/busses/powerpc-common.c

Quoted 5 lines · Jon Smirl
drivers/i2c/busses/powerpc-common.c new file +0 -0
new file mode 100644
index 0000000..51b039f

This is really broader than powerpc. devtree-common.c would be a more suitable name.

Quoted 41 lines
drivers/i2c/busses/powerpc-common.c new file +40 -0
@@ -0,0 +1,81 @@
+/*
+ * powerpc-common.c - routines common to device tree parsing for all
+ *                    powerpc based i2c hosts
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * (C) Copyright 2008 Jon Smirl <[email protected]>
+ *
+ */
+
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/of_platform.h>
+
+#include "powerpc-common.h"
+
+#ifdef CONFIG_PPC_MERGE
+
+void of_register_i2c_devices(struct i2c_adapter *adap, struct device_node *adap_node)
+{
+	void *result;
+	struct device_node *node = NULL;
+
+	while ((node = of_get_next_child(adap_node, node))) {
+		struct i2c_board_info info;
+		const u32 *addr;
+		const char *compatible;
+		int len;

drivers/i2c/busses/powerpc-common.c line 50

Quoted 10 lines
drivers/i2c/busses/powerpc-common.c new file +10 -0
+
+		compatible = of_get_property(node, "compatible", NULL);
+		if (!compatible) {
+			printk(KERN_ERR "i2c-mpc.c: missing compatible attribute\n");
+			continue;
+		}
+
+		addr = of_get_property(node, "reg", &len);
+		if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
+			printk(KERN_ERR "i2c-mpc.c: missing reg attribute for %s\n", compatible);

This is no longer i2c-mpc. Same for the other comments in this function.

-Olof