ARM: 7409/1: Do not call flush_cache_user_range with mmap_sem held
[linux/fpc-iii.git] / drivers / i2c / busses / i2c-ixp2000.c
blob5d8aed5ec21bb85863743e4855d450403074cf64
1 /*
2 * drivers/i2c/busses/i2c-ixp2000.c
4 * I2C adapter for IXP2000 systems using GPIOs for I2C bus
6 * Author: Deepak Saxena <dsaxena@plexity.net>
7 * Based on IXDP2400 code by: Naeem M. Afzal <naeem.m.afzal@intel.com>
8 * Made generic by: Jeff Daly <jeffrey.daly@intel.com>
10 * Copyright (c) 2003-2004 MontaVista Software Inc.
12 * This file is licensed under the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
16 * From Jeff Daly:
18 * I2C adapter driver for Intel IXDP2xxx platforms. This should work for any
19 * IXP2000 platform if it uses the HW GPIO in the same manner. Basically,
20 * SDA and SCL GPIOs have external pullups. Setting the respective GPIO to
21 * an input will make the signal a '1' via the pullup. Setting them to
22 * outputs will pull them down.
24 * The GPIOs are open drain signals and are used as configuration strap inputs
25 * during power-up so there's generally a buffer on the board that needs to be
26 * 'enabled' to drive the GPIOs.
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/platform_device.h>
32 #include <linux/module.h>
33 #include <linux/i2c.h>
34 #include <linux/i2c-algo-bit.h>
35 #include <linux/slab.h>
37 #include <mach/hardware.h> /* Pick up IXP2000-specific bits */
38 #include <mach/gpio.h>
40 static inline int ixp2000_scl_pin(void *data)
42 return ((struct ixp2000_i2c_pins*)data)->scl_pin;
45 static inline int ixp2000_sda_pin(void *data)
47 return ((struct ixp2000_i2c_pins*)data)->sda_pin;
51 static void ixp2000_bit_setscl(void *data, int val)
53 int i = 5000;
55 if (val) {
56 gpio_line_config(ixp2000_scl_pin(data), GPIO_IN);
57 while(!gpio_line_get(ixp2000_scl_pin(data)) && i--);
58 } else {
59 gpio_line_config(ixp2000_scl_pin(data), GPIO_OUT);
63 static void ixp2000_bit_setsda(void *data, int val)
65 if (val) {
66 gpio_line_config(ixp2000_sda_pin(data), GPIO_IN);
67 } else {
68 gpio_line_config(ixp2000_sda_pin(data), GPIO_OUT);
72 static int ixp2000_bit_getscl(void *data)
74 return gpio_line_get(ixp2000_scl_pin(data));
77 static int ixp2000_bit_getsda(void *data)
79 return gpio_line_get(ixp2000_sda_pin(data));
82 struct ixp2000_i2c_data {
83 struct ixp2000_i2c_pins *gpio_pins;
84 struct i2c_adapter adapter;
85 struct i2c_algo_bit_data algo_data;
88 static int ixp2000_i2c_remove(struct platform_device *plat_dev)
90 struct ixp2000_i2c_data *drv_data = platform_get_drvdata(plat_dev);
92 platform_set_drvdata(plat_dev, NULL);
94 i2c_del_adapter(&drv_data->adapter);
96 kfree(drv_data);
98 return 0;
101 static int ixp2000_i2c_probe(struct platform_device *plat_dev)
103 int err;
104 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data;
105 struct ixp2000_i2c_data *drv_data =
106 kzalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL);
108 if (!drv_data)
109 return -ENOMEM;
110 drv_data->gpio_pins = gpio;
112 drv_data->algo_data.data = gpio;
113 drv_data->algo_data.setsda = ixp2000_bit_setsda;
114 drv_data->algo_data.setscl = ixp2000_bit_setscl;
115 drv_data->algo_data.getsda = ixp2000_bit_getsda;
116 drv_data->algo_data.getscl = ixp2000_bit_getscl;
117 drv_data->algo_data.udelay = 6;
118 drv_data->algo_data.timeout = HZ;
120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
121 sizeof(drv_data->adapter.name));
122 drv_data->adapter.algo_data = &drv_data->algo_data,
124 drv_data->adapter.dev.parent = &plat_dev->dev;
126 gpio_line_config(gpio->sda_pin, GPIO_IN);
127 gpio_line_config(gpio->scl_pin, GPIO_IN);
128 gpio_line_set(gpio->scl_pin, 0);
129 gpio_line_set(gpio->sda_pin, 0);
131 if ((err = i2c_bit_add_bus(&drv_data->adapter)) != 0) {
132 dev_err(&plat_dev->dev, "Could not install, error %d\n", err);
133 kfree(drv_data);
134 return err;
137 platform_set_drvdata(plat_dev, drv_data);
139 return 0;
142 static struct platform_driver ixp2000_i2c_driver = {
143 .probe = ixp2000_i2c_probe,
144 .remove = ixp2000_i2c_remove,
145 .driver = {
146 .name = "IXP2000-I2C",
147 .owner = THIS_MODULE,
151 static int __init ixp2000_i2c_init(void)
153 return platform_driver_register(&ixp2000_i2c_driver);
156 static void __exit ixp2000_i2c_exit(void)
158 platform_driver_unregister(&ixp2000_i2c_driver);
161 module_init(ixp2000_i2c_init);
162 module_exit(ixp2000_i2c_exit);
164 MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>");
165 MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver");
166 MODULE_LICENSE("GPL");
167 MODULE_ALIAS("platform:IXP2000-I2C");