Convert PowerPC MPC i2c to of_platform_driver from platform_driver
Subsystems (2)
PATCH 1/1 Convert PowerPC MPC i2c to of_platform_driver from platform_driver
Changed common name from powerpc_ to of_ per Olof's suggestion.
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 of-common.* Orginal ppc driver left intact for deletion when ppc arch is removed.
Signed-off-by Jon Smirl <[email protected]>
---
arch/powerpc/sysdev/fsl_soc.c | 125 ----------------------------- drivers/i2c/busses/Makefile | 2 drivers/i2c/busses/i2c-mpc-drv.c | 164 +++++++++++++++++++++++++++++++++++--- drivers/i2c/busses/of-common.c | 81 +++++++++++++++++++ drivers/i2c/busses/of-common.h | 23 +++++ include/linux/mod_devicetable.h | 9 ++ 6 files changed, 263 insertions(+), 141 deletions(-) create mode 100644 drivers/i2c/busses/of-common.c create mode 100644 drivers/i2c/busses/of-common.h
arch/powerpc/sysdev/fsl_soc.c +0 -125
@@ -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_83xxstatic int __init mpc83xx_wdt_init (void ) {
drivers/i2c/busses/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for the i2c bus drivers. # -i2c-mpc-objs := i2c-mpc-drv.o +i2c-mpc-objs := i2c-mpc-drv.o of-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/of-common.c new file +81 -0
81 lines not on this page · raw message
drivers/i2c/busses/of-common.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* of-common.h - routines common to device tree parsing for all +* open firmware 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
@@ -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 ];
_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c