Add support for Intel IXP42x GPIO-based I2C
PATCH 1/1 Add support for Intel IXP42x GPIO-based I2C
Greg,
The following patch against Linus' BK tree adds a driver for using GPIO pins on Intel's IXP42x ARM SOCs for an I2C interface.
Tnx,
~Deepak
drivers/i2c/busses/Kconfig +11 -0
@@ -144,6 +144,17 @@ This support is also available as a module. If so, the module will be called i2c-ite. +config I2C_IXP42X + tristate "IXP42x GPIO-Based I2C Interface" + depends on I2C && ARCH_IXP425 + select I2C_ALGOBIT + help + Say Y here if you have an Intel IXP42x(420,421,422,425) based + system and are using GPIO lines for an I2C bus. + + This support is also available as a module. If so, the module + will be called i2c-ixp42x. + config I2C_KEYWEST tristate "Powermac Keywest I2C interface" depends on I2C && PPC_PMAC
drivers/i2c/busses/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_ISA) += i2c-isa.o obj-$(CONFIG_I2C_ITE) += i2c-ite.o +obj-$(CONFIG_I2C_IXP42X) += i2c-ixp42x.o obj-$(CONFIG_I2C_KEYWEST) += i2c-keywest.o obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o obj-$(CONFIG_I2C_PHILIPSPAR) += i2c-philips-par.o
drivers/i2c/busses/i2c-ixp42x.c new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
Deepak Saxena - dsaxena at plexity dot net - http://www.plexity.net/
PATCH 1/1 Add support for Intel IXP42x GPIO-based I2C
Quoted 5 lines
The following patch against Linus' BK tree adds a driver for using GPIO pins on Intel's IXP42x ARM SOCs for an I2C interface.
Tnx,
~Deepak
See my comments inline.
Quoted 36 lines
diff -Nru a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
drivers/i2c/busses/Kconfig +11
-0@@ -144,6 +144,17 @@ This support is also available as a module. If so, the module will be called i2c-ite. +config I2C_IXP42X + tristate "IXP42x GPIO-Based I2C Interface" + depends on I2C && ARCH_IXP425 + select I2C_ALGOBIT + help + Say Y here if you have an Intel IXP42x(420,421,422,425) based + system and are using GPIO lines for an I2C bus. + + This support is also available as a module. If so, the module + will be called i2c-ixp42x. + config I2C_KEYWEST tristate "Powermac Keywest I2C interface" depends on I2C && PPC_PMACdiff -Nru a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
drivers/i2c/busses/Makefile +1
-0@@ -15,6 +15,7 @@ obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_ISA) += i2c-isa.o obj-$(CONFIG_I2C_ITE) += i2c-ite.o +obj-$(CONFIG_I2C_IXP42X) += i2c-ixp42x.o obj-$(CONFIG_I2C_KEYWEST) += i2c-keywest.o obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o obj-$(CONFIG_I2C_PHILIPSPAR) += i2c-philips-par.odiff -Nru
a/drivers/i2c/busses/i2c-ixp42x.c
b/drivers/i2c/busses/i2c-ixp42x.c---/dev/nullWed Dec 31 16:00:00 1969
+++b/drivers/i2c/busses/i2c-ixp42x.cFri Feb 13 16:56:09 2004
drivers/i2c/busses/Makefile line 2
Quoted 2 lines
drivers/i2c/busses/Makefile +2
-0@@ -0,0 +1,170 @@ +/* + * drivers/i2c/i2c-adap-ixp425.c
Doesn't match the actual filename and module name advertised above.
Quoted 9 lines
drivers/i2c/busses/Makefile +9
-0+ * + * Driver for gpio-based i2c adapter on Intel IXP42x systems. + * + * Author: Deepak Saxena <[email protected]> + * + * Copyright (c) 2003-2004 MontaVista Software Inc. + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any
drivers/i2c/busses/Makefile line 21
Quoted 10 lines
drivers/i2c/busses/Makefile +10
-0+ * warranty of any kind, whether express or implied. + * + * NOTE: Do NOT add board specific hooks here. All that belongs in platform + * specific code in arch/arm/mach-ixp425/your_platform.c. See + * arch/arm/mach-ixp425/ixdp425.c for an example of building a + * device list and filling in the ixp425_i2c_pins data structure + * that is passed as the platform_data to this driver. + */ + +#include <linux/config.h>
Please insert the usual 3 lines debug stuff here (see other bus drivers).
drivers/i2c/busses/Makefile line 28
Quoted 7 lines
drivers/i2c/busses/Makefile +7
-0+#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/i2c-algo-bit.h> +#include <linux/i2c-id.h>
You do not need to include this, i2c.h includes it for you.
Quoted 17 lines
drivers/i2c/busses/Makefile +17
-0+ +#include <asm/hardware.h> + +static inline int ixp425_scl_pin(void *data) +{ + return ((struct ixp425_i2c_pins*)data)->scl_pin; +} + +static inline int ixp425_sda_pin(void *data) +{ + return ((struct ixp425_i2c_pins*)data)->sda_pin; +} + +static void ixdp425_bit_setscl(void *data, int val) +{ + gpio_line_set(ixp425_scl_pin(data), 0); + gpio_line_config(ixp425_scl_pin(data),
drivers/i2c/busses/Makefile line 55
Quoted 10 lines
drivers/i2c/busses/Makefile +10
-0+ val ? IXP425_GPIO_IN : IXP425_GPIO_OUT ); +} + +static void ixdp425_bit_setsda(void *data, int val) +{ + gpio_line_set(ixp425_sda_pin(data), 0); + gpio_line_config(ixp425_sda_pin(data), + val ? IXP425_GPIO_IN : IXP425_GPIO_OUT ); +} +
Where are these gpio_line_* functions defined? and the IXP425_GPIO_* constants?
drivers/i2c/busses/Makefile
Quoted 4 lines
drivers/i2c/busses/Makefile +3
-0+MODULE_DESCRIPTION("GPIO-based I2C adapter for IXP425 systems"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Deepak Saxena<[email protected]>");
Missing space between name and address.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 Add support for Intel IXP42x GPIO-based I2C
In reply to Deepak SaxenaOn Feb 14 2004, at 09:28, Jean Delvare was caught saying:
Quoted 6 lines
Quoted 5 lines
The following patch against Linus' BK tree adds a driver for using GPIO pins on Intel's IXP42x ARM SOCs for an I2C interface.
Tnx,
~Deepak
Quoted 6 lines
See my comments inline.
Quoted 2 lines
+/*
+ *drivers/i2c/i2c-adap-ixp425.cDoesn't match the actual filename and module name advertised above.
Will fix
Quoted 4 lines
drivers/i2c/busses/i2c-ixp42x.c line 21
Quoted 2 lines
drivers/i2c/busses/i2c-ixp42x.c new file +2
-0+ +#include <linux/config.h> Please insert the usual 3 lines debug stuff here (see other bus drivers).
Will fix.
Quoted 4 lines
Quoted 1 line
+#include <
linux/i2c-id.h>You do not need to include this,
i2c.hincludes it for you.
Will fix.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+} +Where are these gpio_line_* functions defined? and the IXP425_GPIO_* constants?
<include/asm-arm/arch-ixp425/hardware.h> which is included by the file <include/asm-arm/hardware.h>. These definitions need to be in a location that is shared by various IXP425-specific drivers.
Quoted 6 lines
drivers/i2c/busses/i2c-ixp42x.c line 169
Quoted 4 lines
(...)
drivers/i2c/busses/i2c-ixp42x.c new file +3
-0+MODULE_DESCRIPTION ("GPIO-based I2C adapter for IXP425 systems" ); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Deepak Saxena<[email protected]>" );Missing space between name and address.
Will fix.
~Deepak
Signature · 1 line
Deepak Saxena - dsaxena at plexity dot net - http://www.plexity.net/
PATCH 1/1 Add support for Intel IXP42x GPIO-based I2C
In reply to Deepak SaxenaOn Feb 14 2004, at 23:19, Mark Studebaker was caught saying:
Quoted 3 lines
This is quite board-specific.
By definition General Purpose I/O are General Purpose. Why should the kernel have a GPIO-based I2C driver?
Because the way you access the GPIO is dependent on the specific chipset underneath. The registers you use to access GPIO on a IXP425 CPU is different than how you do so on an IXP2000 CPU. The GPIO lines are being used to create a bit-bang interface, and the driver takes the bit-banging instructions for SDA and SCL and swizzles the appropriate GPIO lines for the given platform. I don't see how you would not have a driver to do this unless the algo-bit driver becomes aware of the low-level interface.
Quoted 4 lines
Is separating the GPIO definitions into
your_platform.c(please provide example...)
really provide much benefit compared to just writing a driver for each motherboard?
Yes. The IXP425 has 16 GPIO pins and platform vendors are free to choose just about anyone. My original driver in 2.4 has ugly #IFDEF CONFIG_FOO stuff to force the GPIO numbers for the specific platform we're runing on. Since the access code for GPIOs is the same across all IXP425 platforms and the only thing that changes is the GPIO numbers, the device model seems like a good way to do this. This also allows me to build a single kernel that I can boot on multiple IXP425 platforms and configure the driver at runtime dependent on what platform I am. Makes it really nice for doing system testing.
Here's the relevant code for arch/arm/mach-ixp425/ixdp425.c:
static struct ixp425_i2c_pins ixdp425_i2c_pins = {
.sda_pin = IXP425_GPIO_PIN_7,
.scl_pin = IXP425_GPIO_PIN_6
};static struct platform_device ixdp425_i2c_controller = {
.name = "IXP425-I2C",
.id = 0,
.dev = {
.platform_data = &ixdp425_i2c_pins,
},
.num_resources = 0
};static int __init ixdp425_init(void)
{
if (!machine_is_ixdp425() && !machine_is_ixcdp1100())
return -ENODEV;
platform_add_device(&ixdp425_flash_device);
platform_add_device(&ixdp425_i2c_controller);
return 0;
}Basically we create a platform device and then add it to the system. The i2c-ixp42x driver catches this and grabs the GPIO numbers.
I don't want to force the driver into having the GPIO numbers built in staticly or using module paramters for the reason above of multiple platform kernels.
~Deepak
Signature · 1 line
Deepak Saxena - dsaxena at plexity dot net - http://www.plexity.net/
PATCH 1/1 Add support for Intel IXP42x GPIO-based I2C
In reply to Deepak SaxenaThis is quite board-specific.
By definition General Purpose I/O are General Purpose.
Why should the kernel have a GPIO-based I2C driver?
Is separating the GPIO definitions into your_platform.c (please provide example...) really provide much benefit compared to just writing a driver
for each motherboard?
Quoted 215 lines · Deepak Saxena
Greg,
The following patch against Linus' BK tree adds a driver for using GPIO pins on Intel's IXP42x ARM SOCs for an I2C interface.
Tnx,
~Deepakdiff -Nru a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
drivers/i2c/busses/Kconfig +11
-0@@ -144,6 +144,17 @@ This support is also available as a module. If so, the module will be called i2c-ite. +config I2C_IXP42X + tristate "IXP42x GPIO-Based I2C Interface" + depends on I2C && ARCH_IXP425 + select I2C_ALGOBIT + help + Say Y here if you have an Intel IXP42x(420,421,422,425) based + system and are using GPIO lines for an I2C bus. + + This support is also available as a module. If so, the module + will be called i2c-ixp42x. + config I2C_KEYWEST tristate "Powermac Keywest I2C interface" depends on I2C && PPC_PMACdiff -Nru a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
drivers/i2c/busses/Makefile +1
-0@@ -15,6 +15,7 @@ obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_ISA) += i2c-isa.o obj-$(CONFIG_I2C_ITE) += i2c-ite.o +obj-$(CONFIG_I2C_IXP42X) += i2c-ixp42x.o obj-$(CONFIG_I2C_KEYWEST) += i2c-keywest.o obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o obj-$(CONFIG_I2C_PHILIPSPAR) += i2c-philips-par.odiff -Nru
a/drivers/i2c/busses/i2c-ixp42x.cb/drivers/i2c/busses/i2c-ixp42x.cdrivers/i2c/busses/i2c-ixp42x.c new file +170
-0@@ -0,0 +1,170 @@ +/* +* drivers/i2c/i2c-adap-ixp425.c +* +* Driver for gpio-based i2c adapter on Intel IXP42x systems. +* +* Author: Deepak Saxena <[email protected]> +* +* Copyright (c) 2003-2004 MontaVista Software Inc. +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +* +* NOTE: Do NOT add board specific hooks here. All that belongs in platform +* specific code in arch/arm/mach-ixp425/your_platform.c. See +* arch/arm/mach-ixp425/ixdp425.c for an example of building a +* device list and filling in the ixp425_i2c_pins data structure +* that is passed as the platform_data to this driver. +*/ + +#include <linux/config.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/i2c-algo-bit.h> +#include <linux/i2c-id.h> + +#include <asm/hardware.h> + +static inline int ixp425_scl_pin (void *data) +{ +return ((struct ixp425_i2c_pins *)data)->scl_pin; +} + +static inline int ixp425_sda_pin (void *data) +{ +return ((struct ixp425_i2c_pins *)data)->sda_pin; +} + +static void ixdp425_bit_setscl (void *data,int val) +{ +gpio_line_set (ixp425_scl_pin (data),0 ); +gpio_line_config (ixp425_scl_pin (data), + val ?IXP425_GPIO_IN :IXP425_GPIO_OUT ); +} + +static void ixdp425_bit_setsda (void *data,int val) +{ +gpio_line_set (ixp425_sda_pin (data),0 ); +gpio_line_config (ixp425_sda_pin (data), + val ?IXP425_GPIO_IN :IXP425_GPIO_OUT ); +} + +static int ixdp425_bit_getscl (void *data) +{ +int scl; + +gpio_line_config (ixp425_scl_pin (data),IXP425_GPIO_IN ); +gpio_line_get (ixp425_scl_pin (data), &scl); + +return scl; +} + +static int ixdp425_bit_getsda (void *data) +{ +int sda; + +gpio_line_config (ixp425_sda_pin (data),IXP425_GPIO_IN ); +gpio_line_get (ixp425_sda_pin (data), &sda); + +return sda; +} + +struct ixp425_i2c_data { +struct ixp425_i2c_pins *gpio_pins; +struct i2c_adapter adapter; +struct i2c_algo_bit_data algo_data; +}; + +static int ixp425_i2c_remove (struct device *dev) +{ +struct platform_device *plat_dev =to_platform_device (dev); +struct ixp425_i2c_data *drv_data =dev_get_drvdata (&plat_dev->dev); + +dev_set_drvdata (&plat_dev->dev,NULL ); + +i2c_bit_del_bus (&drv_data->adapter); + +kfree (drv_data); + +return 0 ; +} + +static int ixp425_i2c_probe (struct device *dev) +{ +int err; +struct platform_device *plat_dev =to_platform_device (dev); +struct ixp425_i2c_pins *gpio = plat_dev->dev.platform_data; +struct ixp425_i2c_data *drv_data = +kmalloc (sizeof (struct ixp425_i2c_data ),GFP_KERNEL ); + +if (!drv_data) +return -ENOMEM ; + +memzero (drv_data,sizeof (struct ixp425_i2c_data )); + drv_data->gpio_pins = gpio; + +/* +* We could make a lot of these structures static, but +* certain platforms may have multiple GPIO-based I2C +* buses for various device domains, so we need per-device +* algo_data->data. +*/ + drv_data->algo_data.data = gpio; + drv_data->algo_data.setsda = ixdp425_bit_setsda; + drv_data->algo_data.setscl = ixdp425_bit_setscl; + drv_data->algo_data.getsda = ixdp425_bit_getsda; + drv_data->algo_data.getscl = ixdp425_bit_getscl; + drv_data->algo_data.udelay =10 ; + drv_data->algo_data.mdelay =10 ; + drv_data->algo_data.timeout =100 ; + + drv_data->adapter.id =I2C_HW_B_IXP425 , + drv_data->adapter.algo_data = &drv_data->algo_data, + + drv_data->adapter.dev.parent = &plat_dev->dev; + +gpio_line_config (gpio->scl_pin,IXP425_GPIO_IN ); +gpio_line_config (gpio->sda_pin,IXP425_GPIO_IN ); +gpio_line_set (gpio->scl_pin,0 ); +gpio_line_set (gpio->sda_pin,0 ); + +if ((err =i2c_bit_add_bus (&drv_data->adapter) !=0 )) { +printk (KERN_ERR "ERROR: Could not install %s\n" , dev->bus_id); + +kfree (drv_data); +return err; + } + +dev_set_drvdata (&plat_dev->dev, drv_data); + +return 0 ; +} + +static struct device_driver ixp425_i2c_driver = { + .name ="IXP425-I2C" , + .bus = &platform_bus_type, + .probe = ixp425_i2c_probe, + .remove = ixp425_i2c_remove, +}; + +static int __init ixp425_i2c_init (void ) +{ +return driver_register (&ixp425_i2c_driver); +} + +static void __exit ixp425_i2c_exit(void) +{ +driver_unregister (&ixp425_i2c_driver); +} + +module_init (ixp425_i2c_init); +module_exit (ixp425_i2c_exit); + +MODULE_DESCRIPTION ("GPIO-based I2C adapter for IXP425 systems" ); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Deepak Saxena<[email protected]>" ); +
PATCH 1/1 Add support for Intel IXP42x GPIO-based I2C
In reply to Deepak SaxenaQuoted 5 lines · Deepak Saxena
Greg,
The following patch against Linus' BK tree adds a driver for using GPIO pins on Intel's IXP42x ARM SOCs for an I2C interface.
I'll hold off on applying this patch, for a updated based on everyone's comments.
thanks,
greg k-h