[DRIVER MODEL] Convert platform drivers to use struct platform_driver
[deliverable/linux.git] / drivers / i2c / busses / i2c-ixp2000.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/i2c/busses/i2c-ixp2000.c
3 *
4 * I2C adapter for IXP2000 systems using GPIOs for I2C bus
5 *
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>
9 *
10 * Copyright (c) 2003-2004 MontaVista Software Inc.
11 *
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.
15 *
16 * From Jeff Daly:
17 *
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.
23 *
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.
27 */
28
1da177e4
LT
29#include <linux/kernel.h>
30#include <linux/init.h>
d052d1be 31#include <linux/platform_device.h>
1da177e4
LT
32#include <linux/module.h>
33#include <linux/i2c.h>
34#include <linux/i2c-algo-bit.h>
35
c4982887
LB
36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */
37#include <asm/arch/gpio.h>
1da177e4 38
8a1b028b
JD
39static struct device_driver ixp2000_i2c_driver;
40
1da177e4
LT
41static inline int ixp2000_scl_pin(void *data)
42{
43 return ((struct ixp2000_i2c_pins*)data)->scl_pin;
44}
45
46static inline int ixp2000_sda_pin(void *data)
47{
48 return ((struct ixp2000_i2c_pins*)data)->sda_pin;
49}
50
51
52static void ixp2000_bit_setscl(void *data, int val)
53{
54 int i = 5000;
55
56 if (val) {
57 gpio_line_config(ixp2000_scl_pin(data), GPIO_IN);
58 while(!gpio_line_get(ixp2000_scl_pin(data)) && i--);
59 } else {
60 gpio_line_config(ixp2000_scl_pin(data), GPIO_OUT);
61 }
62}
63
64static void ixp2000_bit_setsda(void *data, int val)
65{
66 if (val) {
67 gpio_line_config(ixp2000_sda_pin(data), GPIO_IN);
68 } else {
69 gpio_line_config(ixp2000_sda_pin(data), GPIO_OUT);
70 }
71}
72
73static int ixp2000_bit_getscl(void *data)
74{
75 return gpio_line_get(ixp2000_scl_pin(data));
76}
77
78static int ixp2000_bit_getsda(void *data)
79{
80 return gpio_line_get(ixp2000_sda_pin(data));
81}
82
83struct ixp2000_i2c_data {
84 struct ixp2000_i2c_pins *gpio_pins;
85 struct i2c_adapter adapter;
86 struct i2c_algo_bit_data algo_data;
87};
88
3ae5eaec 89static int ixp2000_i2c_remove(struct platform_device *plat_dev)
1da177e4 90{
3ae5eaec 91 struct ixp2000_i2c_data *drv_data = platform_get_drvdata(plat_dev);
1da177e4 92
3ae5eaec 93 platform_set_drvdata(plat_dev, NULL);
1da177e4
LT
94
95 i2c_bit_del_bus(&drv_data->adapter);
96
97 kfree(drv_data);
98
99 return 0;
100}
101
3ae5eaec 102static int ixp2000_i2c_probe(struct platform_device *plat_dev)
1da177e4
LT
103{
104 int err;
1da177e4
LT
105 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data;
106 struct ixp2000_i2c_data *drv_data =
2286066f 107 kzalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL);
1da177e4
LT
108
109 if (!drv_data)
110 return -ENOMEM;
1da177e4
LT
111 drv_data->gpio_pins = gpio;
112
113 drv_data->algo_data.data = gpio;
114 drv_data->algo_data.setsda = ixp2000_bit_setsda;
115 drv_data->algo_data.setscl = ixp2000_bit_setscl;
116 drv_data->algo_data.getsda = ixp2000_bit_getsda;
117 drv_data->algo_data.getscl = ixp2000_bit_getscl;
118 drv_data->algo_data.udelay = 6;
119 drv_data->algo_data.mdelay = 6;
120 drv_data->algo_data.timeout = 100;
121
122 drv_data->adapter.id = I2C_HW_B_IXP2000,
8a1b028b
JD
123 strlcpy(drv_data->adapter.name, ixp2000_i2c_driver.name,
124 I2C_NAME_SIZE);
1da177e4
LT
125 drv_data->adapter.algo_data = &drv_data->algo_data,
126
127 drv_data->adapter.dev.parent = &plat_dev->dev;
128
129 gpio_line_config(gpio->sda_pin, GPIO_IN);
130 gpio_line_config(gpio->scl_pin, GPIO_IN);
131 gpio_line_set(gpio->scl_pin, 0);
132 gpio_line_set(gpio->sda_pin, 0);
133
134 if ((err = i2c_bit_add_bus(&drv_data->adapter)) != 0) {
135 dev_err(dev, "Could not install, error %d\n", err);
136 kfree(drv_data);
137 return err;
138 }
139
3ae5eaec 140 platform_set_drvdata(plat_dev, drv_data);
1da177e4
LT
141
142 return 0;
143}
144
3ae5eaec 145static struct platform_driver ixp2000_i2c_driver = {
1da177e4
LT
146 .probe = ixp2000_i2c_probe,
147 .remove = ixp2000_i2c_remove,
3ae5eaec
RK
148 .driver = {
149 .name = "IXP2000-I2C",
150 .owner = THIS_MODULE,
151 },
1da177e4
LT
152};
153
154static int __init ixp2000_i2c_init(void)
155{
3ae5eaec 156 return platform_driver_register(&ixp2000_i2c_driver);
1da177e4
LT
157}
158
159static void __exit ixp2000_i2c_exit(void)
160{
3ae5eaec 161 platform_driver_unregister(&ixp2000_i2c_driver);
1da177e4
LT
162}
163
164module_init(ixp2000_i2c_init);
165module_exit(ixp2000_i2c_exit);
166
167MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>");
168MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver");
169MODULE_LICENSE("GPL");
170
This page took 0.088666 seconds and 5 git commands to generate.