diff options
author | juhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2007-10-10 14:14:34 +0000 |
---|---|---|
committer | juhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2007-10-10 14:14:34 +0000 |
commit | 76d4ca5d5056998ade5e27262b640d9bbad0d72d (patch) | |
tree | 0b42e7ec93911e2e69650f900154d8c974f9ab2c /target/linux | |
parent | 8dba7c58613c7f48c08a3ee0109b270dd23e5c78 (diff) |
[adm5120] enhance the custom i2c-gpio driver (supports 4 buses from now on), update kernel configuration
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@9244 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux')
4 files changed, 151 insertions, 73 deletions
diff --git a/target/linux/adm5120/files/drivers/i2c/busses/i2c-gpio-custom.c b/target/linux/adm5120/files/drivers/i2c/busses/i2c-gpio-custom.c index a019fafcc8..9d62a2d909 100644 --- a/target/linux/adm5120/files/drivers/i2c/busses/i2c-gpio-custom.c +++ b/target/linux/adm5120/files/drivers/i2c/busses/i2c-gpio-custom.c @@ -6,6 +6,40 @@ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. + * + * --------------------------------------------------------------------------- + * + * The behaviour of this driver can be altered by setting some parameters + * from the insmod command line. + * + * The following parameters are adjustable: + * + * bus0 These four arguments can be arrays of + * bus1 1-8 unsigned integers as follows: + * bus2 + * bus3 <id>,<sda>,<scl>,<udelay>,<timeout>,<sda_od>,<scl_od>,<scl_oo> + * + * where: + * + * <id> ID to used as device_id for the corresponding bus (required) + * <sda> GPIO pin ID to used for SDA (required) + * <scl> GPIO pin ID to used for SCL (required) + * <udelay> signal toggle delay. + * <timeout> clock stretching timeout. + * <sda_od> SDA is configured as open drain. + * <scl_od> SCL is configured as open drain. + * <scl_oo> SCL output drivers cannot be turned off. + * + * See include/i2c-gpio.h for more information about the parameters. + * + * If this driver is built into the kernel, you can use the following kernel + * command line parameters, with the same values as the corresponding module + * parameters listed above: + * + * i2c-gpio-custom.bus0 + * i2c-gpio-custom.bus1 + * i2c-gpio-custom.bus2 + * i2c-gpio-custom.bus3 */ #include <linux/kernel.h> @@ -16,56 +50,141 @@ #include <linux/i2c-gpio.h> #define DRV_NAME "i2c-gpio-custom" -#define DRV_DESC "Custom GPIO I2C device driver" +#define DRV_DESC "Custom GPIO-based I2C driver" +#define DRV_VERSION "0.1.0" + +#define PFX DRV_NAME ": " + +#define BUS_PARAM_ID 0 +#define BUS_PARAM_SDA 1 +#define BUS_PARAM_SCL 2 +#define BUS_PARAM_UDELAY 3 +#define BUS_PARAM_TIMEOUT 4 +#define BUS_PARAM_SDA_OD 5 +#define BUS_PARAM_SCL_OD 6 +#define BUS_PARAM_SCL_OO 7 + +#define BUS_PARAM_REQUIRED 3 +#define BUS_PARAM_COUNT 8 +#define BUS_COUNT_MAX 4 + +static unsigned int bus0[BUS_PARAM_COUNT] __initdata; +static unsigned int bus1[BUS_PARAM_COUNT] __initdata; +static unsigned int bus2[BUS_PARAM_COUNT] __initdata; +static unsigned int bus3[BUS_PARAM_COUNT] __initdata; + +static unsigned int bus_nump[BUS_COUNT_MAX] __initdata; + +#define BUS_PARM_DESC \ + " config -> id,sda,scl[,udelay,timeout,sda_od,scl_od,scl_oo]" + +module_param_array(bus0, uint, &bus_nump[0], 0); +MODULE_PARM_DESC(bus0, "bus0" BUS_PARM_DESC); +module_param_array(bus1, uint, &bus_nump[1], 0); +MODULE_PARM_DESC(bus1, "bus1" BUS_PARM_DESC); +module_param_array(bus2, uint, &bus_nump[2], 0); +MODULE_PARM_DESC(bus2, "bus2" BUS_PARM_DESC); +module_param_array(bus3, uint, &bus_nump[3], 0); +MODULE_PARM_DESC(bus3, "bus3" BUS_PARM_DESC); + +static struct platform_device *devices[BUS_COUNT_MAX]; +static unsigned int nr_devices; + +static void i2c_gpio_custom_cleanup(void) +{ + int i; -static unsigned int sda = CONFIG_I2C_GPIO_CUSTOM_SDA; -static unsigned int scl = CONFIG_I2C_GPIO_CUSTOM_SCL; -static int id = CONFIG_I2C_GPIO_CUSTOM_DEVICE_ID; + for (i = 0; i < nr_devices; i++) + if (devices[i]) + platform_device_unregister(devices[i]); +} -module_param(sda, uint, S_IRUGO); -MODULE_PARM_DESC(sda, "GPIO pin for SDA"); +static int __init i2c_gpio_custom_add_one(unsigned int id, unsigned int *params) +{ + struct platform_device *pdev; + struct i2c_gpio_platform_data pdata; + int err; -module_param(scl, uint, S_IRUGO); -MODULE_PARM_DESC(scl, "GPIO pin for SCL"); + if (!bus_nump[id]) + return 0; -module_param(id, int, S_IRUGO); -MODULE_PARM_DESC(id, "device id of the i2c-gpio device"); + if (bus_nump[id] < BUS_PARAM_REQUIRED) { + printk(KERN_ERR PFX "not enough parameters for bus%d\n", id); + err = -EINVAL; + goto err; + } -static struct i2c_gpio_platform_data i2c_data; -static struct platform_device i2c_device; + pdev = platform_device_alloc("i2c-gpio", params[BUS_PARAM_ID]); + if (!pdev) { + err = -ENOMEM; + goto err; + } -static void i2c_gpio_custom_release(struct platform_device *pdev) -{ - /* nothing to do */ + devices[nr_devices++] = pdev; + + pdata.sda_pin = params[BUS_PARAM_SDA]; + pdata.scl_pin = params[BUS_PARAM_SCL]; + pdata.udelay = params[BUS_PARAM_UDELAY]; + pdata.timeout = params[BUS_PARAM_TIMEOUT]; + pdata.sda_is_open_drain = params[BUS_PARAM_SDA_OD] != 0; + pdata.scl_is_open_drain = params[BUS_PARAM_SCL_OD] != 0; + pdata.scl_is_output_only = params[BUS_PARAM_SCL_OO] != 0; + + err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); + if (err) + goto err; + + err = platform_device_register(pdev); + if (err) + goto err; + + return 0; + +err: + return err; } static int __init i2c_gpio_custom_init(void) { int err; - i2c_data.sda_pin = sda; - i2c_data.scl_pin = scl; + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n"); + + err = i2c_gpio_custom_add_one(0, bus0); + if (err) goto err; - i2c_device.name = "i2c-gpio"; - i2c_device.id = id; + err = i2c_gpio_custom_add_one(1, bus1); + if (err) goto err; - i2c_device.dev.platform_data = &i2c_data, - i2c_device.dev.release = i2c_gpio_custom_release, + err = i2c_gpio_custom_add_one(2, bus2); + if (err) goto err; - err = platform_device_register(&i2c_device); + err = i2c_gpio_custom_add_one(3, bus3); + if (err) goto err; + if (!nr_devices) { + printk(KERN_ERR PFX "no bus parameter(s) specified\n"); + err = -ENODEV; + goto err; + } + + return 0; + +err: + i2c_gpio_custom_cleanup(); return err; } +module_init(i2c_gpio_custom_init); static void __exit i2c_gpio_custom_exit(void) { - platform_device_unregister(&i2c_device); + i2c_gpio_custom_cleanup(); } - -module_init(i2c_gpio_custom_init); module_exit(i2c_gpio_custom_exit); + MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org >"); MODULE_DESCRIPTION(DRV_DESC); +MODULE_VERSION(DRV_VERSION); diff --git a/target/linux/adm5120/patches-2.6.22/300-i2c_gpio_custom.patch b/target/linux/adm5120/patches-2.6.22/300-i2c_gpio_custom.patch index 2bbb197d69..8c08b74037 100644 --- a/target/linux/adm5120/patches-2.6.22/300-i2c_gpio_custom.patch +++ b/target/linux/adm5120/patches-2.6.22/300-i2c_gpio_custom.patch @@ -1,42 +1,19 @@ --- linux-2.6.22.4.orig/drivers/i2c/busses/Kconfig 2007-08-21 06:33:06.000000000 +0200 +++ linux-2.6.22.4/drivers/i2c/busses/Kconfig 2007-10-09 12:53:13.000000000 +0200 -@@ -125,6 +125,40 @@ +@@ -125,6 +125,17 @@ This is a very simple bitbanging I2C driver utilizing the arch-neutral GPIO API to control the SCL and SDA lines. +config I2C_GPIO_CUSTOM -+ tristate "Custom GPIO-based I2C device" ++ tristate "Custom GPIO-based I2C driver" + depends on GENERIC_GPIO + select I2C_GPIO + help -+ This is an I2C driver to register a custom i2c-gpio device. ++ This is an I2C driver to register 1 to 4 custom I2C buses using ++ GPIO lines. + + This support is also available as a module. If so, the module -+ will be called i2c-gpio-dev. -+ -+config I2C_GPIO_CUSTOM_SDA -+ int "Custom GPIO pin for SDA" -+ depends on I2C_GPIO_CUSTOM -+ default "0" -+ help -+ Enter the GPIO pin number used for the SDA signal. This value can -+ also be specified with a module parameter. -+ -+config I2C_GPIO_CUSTOM_SCL -+ int "Custom GPIO pin for SCL" -+ depends on I2C_GPIO_CUSTOM -+ default "1" -+ help -+ Enter the GPIO pin number used for the SCL signal. This value can -+ also be specified with a module parameter. -+ -+config I2C_GPIO_CUSTOM_DEVICE_ID -+ int "Custom GPIO device id" -+ depends on I2C_GPIO_CUSTOM -+ default "0" -+ help -+ Enter the number used for the device id of the custom i2c-gpio device. -+ This value can also be specified with a module parameter. ++ will be called i2c-gpio-custom. + config I2C_HYDRA tristate "CHRP Apple Hydra Mac I/O I2C interface" diff --git a/target/linux/adm5120/router_be/config-2.6.22 b/target/linux/adm5120/router_be/config-2.6.22 index bb5244688f..0fca8f8fb1 100644 --- a/target/linux/adm5120/router_be/config-2.6.22 +++ b/target/linux/adm5120/router_be/config-2.6.22 @@ -73,15 +73,7 @@ CONFIG_HW_RANDOM=y CONFIG_HZ=250 # CONFIG_HZ_100 is not set CONFIG_HZ_250=y -CONFIG_I2C=m -CONFIG_I2C_ALGOBIT=m -CONFIG_I2C_BOARDINFO=y -CONFIG_I2C_CHARDEV=m -CONFIG_I2C_GPIO=m -CONFIG_I2C_GPIO_CUSTOM=m -CONFIG_I2C_GPIO_CUSTOM_DEVICE_ID=0 -CONFIG_I2C_GPIO_CUSTOM_SCL=1 -CONFIG_I2C_GPIO_CUSTOM_SDA=0 +# CONFIG_I2C is not set # CONFIG_IDE is not set CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m CONFIG_INITRAMFS_SOURCE="" @@ -196,7 +188,6 @@ CONFIG_PCI_ADM5120=y CONFIG_RWSEM_GENERIC_SPINLOCK=y CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y CONFIG_SCSI_WAIT_SCAN=m -# CONFIG_SENSORS_PC87360 is not set # CONFIG_SERIAL_8250 is not set # CONFIG_SERIAL_ADM5120 is not set CONFIG_SERIAL_AMBA_PL010=y diff --git a/target/linux/adm5120/router_le/config-2.6.22 b/target/linux/adm5120/router_le/config-2.6.22 index 579e2cfdb5..a876583603 100644 --- a/target/linux/adm5120/router_le/config-2.6.22 +++ b/target/linux/adm5120/router_le/config-2.6.22 @@ -73,15 +73,7 @@ CONFIG_HW_RANDOM=y CONFIG_HZ=250 # CONFIG_HZ_100 is not set CONFIG_HZ_250=y -CONFIG_I2C=m -CONFIG_I2C_ALGOBIT=m -CONFIG_I2C_BOARDINFO=y -CONFIG_I2C_CHARDEV=m -CONFIG_I2C_GPIO=m -CONFIG_I2C_GPIO_CUSTOM=m -CONFIG_I2C_GPIO_CUSTOM_DEVICE_ID=0 -CONFIG_I2C_GPIO_CUSTOM_SCL=1 -CONFIG_I2C_GPIO_CUSTOM_SDA=0 +# CONFIG_I2C is not set # CONFIG_IDE is not set CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m CONFIG_INITRAMFS_SOURCE="" @@ -206,7 +198,6 @@ CONFIG_PCI_ADM5120=y CONFIG_RWSEM_GENERIC_SPINLOCK=y CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y CONFIG_SCSI_WAIT_SCAN=m -# CONFIG_SENSORS_PC87360 is not set # CONFIG_SERIAL_8250 is not set # CONFIG_SERIAL_ADM5120 is not set CONFIG_SERIAL_AMBA_PL010=y |