ep93xx GPIO I2C bus driver. Index: linux-2.6.18-rc1-git7/drivers/i2c/busses/Kconfig =================================================================== --- linux-2.6.18-rc1-git7.orig/drivers/i2c/busses/Kconfig +++ linux-2.6.18-rc1-git7/drivers/i2c/busses/Kconfig @@ -537,4 +537,16 @@ config I2C_MV64XXX This driver can also be built as a module. If so, the module will be called i2c-mv64xxx. +config I2C_EP93XX + tristate "Cirrus Logic EP93XX GPIO-based I2C interface" + depends on I2C && ARCH_EP93XX + select I2C_ALGOBIT + help + Say Y here if you have an Cirrus Logic EP93XX 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-ep93xx. + + endmenu Index: linux-2.6.18-rc1-git7/drivers/i2c/busses/Makefile =================================================================== --- linux-2.6.18-rc1-git7.orig/drivers/i2c/busses/Makefile +++ linux-2.6.18-rc1-git7/drivers/i2c/busses/Makefile @@ -43,6 +43,7 @@ obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o obj-$(CONFIG_SCx200_ACB) += scx200_acb.o obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o +obj-$(CONFIG_I2C_EP93XX) += i2c-ep93xx.o ifeq ($(CONFIG_I2C_DEBUG_BUS),y) EXTRA_CFLAGS += -DDEBUG Index: linux-2.6.18-rc1-git7/drivers/i2c/busses/i2c-ep93xx.c =================================================================== --- /dev/null +++ linux-2.6.18-rc1-git7/drivers/i2c/busses/i2c-ep93xx.c @@ -0,0 +1,174 @@ +/* + * Intel's IXP4xx XScale NPU chipsets (IXP420, 421, 422, 425) do not have + * an on board I2C controller but provide 16 GPIO pins that are often + * used to create an I2C bus. This driver provides an i2c_adapter + * interface that plugs in under algo_bit and drives the GPIO pins + * as instructed by the alogorithm driver. + * + * Based on i2x-ixp4xx.c + * Author: Deepak Saxena + * 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: Since different platforms will use different GPIO pins for + * I2C, this driver uses an ep93xx specific platform_data + * pointer to pass the GPIO numbers to the driver. This + * allows us to support all the different boards + * w/o having to put #ifdefs in this driver. + * + * See arch/arm/mach-ep93xx/core.c for an example of building a + * device list and filling in the ep93xx_i2c_pins data structure + * that is passed as the platform_data to this driver. + */ + +#include +#include +#include +#include +#include + +#include +#include + +static inline int ep93xx_scl_pin(void *data) +{ + return ((struct ep93xx_i2c_pins *)data)->scl_pin; +} + +static inline int ep93xx_sda_pin(void *data) +{ + return ((struct ep93xx_i2c_pins *)data)->sda_pin; +} + +static void ep93xx_bit_setscl(void *data, int val) +{ + gpio_line_set(ep93xx_scl_pin(data), 0); + gpio_line_config(ep93xx_scl_pin(data), + val ? GPIO_IN : GPIO_OUT); +} + +static void ep93xx_bit_setsda(void *data, int val) +{ + gpio_line_set(ep93xx_sda_pin(data), 0); + gpio_line_config(ep93xx_sda_pin(data), + val ? GPIO_IN : GPIO_OUT); +} + +static int ep93xx_bit_getscl(void *data) +{ + int scl; + + gpio_line_config(ep93xx_scl_pin(data), GPIO_IN); + scl = gpio_line_get(ep93xx_scl_pin(data)); + + return scl; +} + +static int ep93xx_bit_getsda(void *data) +{ + int sda; + + gpio_line_config(ep93xx_sda_pin(data), GPIO_IN); + sda = gpio_line_get(ep93xx_sda_pin(data)); + + return sda; +} + +struct ep93xx_i2c_data { + struct ep93xx_i2c_pins *gpio_pins; + struct i2c_adapter adapter; + struct i2c_algo_bit_data algo_data; +}; + +static int ep93xx_i2c_remove(struct platform_device *plat_dev) +{ + struct ep93xx_i2c_data *drv_data = platform_get_drvdata(plat_dev); + + platform_set_drvdata(plat_dev, NULL); + + i2c_bit_del_bus(&drv_data->adapter); + + kfree(drv_data); + + return 0; +} + +static int ep93xx_i2c_probe(struct platform_device *plat_dev) +{ + int err; + struct ep93xx_i2c_pins *gpio = plat_dev->dev.platform_data; + struct ep93xx_i2c_data *drv_data = + kzalloc(sizeof(struct ep93xx_i2c_data), GFP_KERNEL); + + if (!drv_data) + return -ENOMEM; + + 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 = ep93xx_bit_setsda; + drv_data->algo_data.setscl = ep93xx_bit_setscl; + drv_data->algo_data.getsda = ep93xx_bit_getsda; + drv_data->algo_data.getscl = ep93xx_bit_getscl; + drv_data->algo_data.udelay = 10; + drv_data->algo_data.mdelay = 10; + drv_data->algo_data.timeout = 100; + + strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, + I2C_NAME_SIZE); + drv_data->adapter.algo_data = &drv_data->algo_data; + drv_data->adapter.class = I2C_CLASS_ALL; + + drv_data->adapter.dev.parent = &plat_dev->dev; + + gpio_line_config(gpio->scl_pin, GPIO_IN); + gpio_line_config(gpio->sda_pin, 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", plat_dev->dev.bus_id); + + kfree(drv_data); + return err; + } + + platform_set_drvdata(plat_dev, drv_data); + + return 0; +} + +static struct platform_driver ep93xx_i2c_driver = { + .probe = ep93xx_i2c_probe, + .remove = ep93xx_i2c_remove, + .driver = { + .name = "ep93xx-i2c", + .owner = THIS_MODULE, + }, +}; + +static int __init ep93xx_i2c_init(void) +{ + return platform_driver_register(&ep93xx_i2c_driver); +} + +static void __exit ep93xx_i2c_exit(void) +{ + platform_driver_unregister(&ep93xx_i2c_driver); +} + +module_init(ep93xx_i2c_init); +module_exit(ep93xx_i2c_exit); + +MODULE_DESCRIPTION("GPIO-based I2C adapter for EP93XX systems"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Alessandro Zummo "); Index: linux-2.6.18-rc1-git7/include/asm-arm/arch-ep93xx/platform.h =================================================================== --- linux-2.6.18-rc1-git7.orig/include/asm-arm/arch-ep93xx/platform.h +++ linux-2.6.18-rc1-git7/include/asm-arm/arch-ep93xx/platform.h @@ -18,5 +18,10 @@ struct ep93xx_eth_data unsigned char mdc_preamble_suppress; }; +struct ep93xx_i2c_pins { + unsigned long sda_pin; + unsigned long scl_pin; +}; + #endif