diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/i2c/busses/i2c-ixp2000.c |
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/i2c/busses/i2c-ixp2000.c')
-rw-r--r-- | drivers/i2c/busses/i2c-ixp2000.c | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c new file mode 100644 index 00000000000..21cd54d0230 --- /dev/null +++ b/drivers/i2c/busses/i2c-ixp2000.c | |||
@@ -0,0 +1,171 @@ | |||
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 | |||
29 | #include <linux/config.h> | ||
30 | #ifdef CONFIG_I2C_DEBUG_BUS | ||
31 | #define DEBUG 1 | ||
32 | #endif | ||
33 | |||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/init.h> | ||
36 | #include <linux/device.h> | ||
37 | #include <linux/module.h> | ||
38 | #include <linux/i2c.h> | ||
39 | #include <linux/i2c-algo-bit.h> | ||
40 | |||
41 | #include <asm/hardware.h> /* Pick up IXP42000-specific bits */ | ||
42 | |||
43 | static inline int ixp2000_scl_pin(void *data) | ||
44 | { | ||
45 | return ((struct ixp2000_i2c_pins*)data)->scl_pin; | ||
46 | } | ||
47 | |||
48 | static inline int ixp2000_sda_pin(void *data) | ||
49 | { | ||
50 | return ((struct ixp2000_i2c_pins*)data)->sda_pin; | ||
51 | } | ||
52 | |||
53 | |||
54 | static void ixp2000_bit_setscl(void *data, int val) | ||
55 | { | ||
56 | int i = 5000; | ||
57 | |||
58 | if (val) { | ||
59 | gpio_line_config(ixp2000_scl_pin(data), GPIO_IN); | ||
60 | while(!gpio_line_get(ixp2000_scl_pin(data)) && i--); | ||
61 | } else { | ||
62 | gpio_line_config(ixp2000_scl_pin(data), GPIO_OUT); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | static void ixp2000_bit_setsda(void *data, int val) | ||
67 | { | ||
68 | if (val) { | ||
69 | gpio_line_config(ixp2000_sda_pin(data), GPIO_IN); | ||
70 | } else { | ||
71 | gpio_line_config(ixp2000_sda_pin(data), GPIO_OUT); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | static int ixp2000_bit_getscl(void *data) | ||
76 | { | ||
77 | return gpio_line_get(ixp2000_scl_pin(data)); | ||
78 | } | ||
79 | |||
80 | static int ixp2000_bit_getsda(void *data) | ||
81 | { | ||
82 | return gpio_line_get(ixp2000_sda_pin(data)); | ||
83 | } | ||
84 | |||
85 | struct ixp2000_i2c_data { | ||
86 | struct ixp2000_i2c_pins *gpio_pins; | ||
87 | struct i2c_adapter adapter; | ||
88 | struct i2c_algo_bit_data algo_data; | ||
89 | }; | ||
90 | |||
91 | static int ixp2000_i2c_remove(struct device *dev) | ||
92 | { | ||
93 | struct platform_device *plat_dev = to_platform_device(dev); | ||
94 | struct ixp2000_i2c_data *drv_data = dev_get_drvdata(&plat_dev->dev); | ||
95 | |||
96 | dev_set_drvdata(&plat_dev->dev, NULL); | ||
97 | |||
98 | i2c_bit_del_bus(&drv_data->adapter); | ||
99 | |||
100 | kfree(drv_data); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int ixp2000_i2c_probe(struct device *dev) | ||
106 | { | ||
107 | int err; | ||
108 | struct platform_device *plat_dev = to_platform_device(dev); | ||
109 | struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data; | ||
110 | struct ixp2000_i2c_data *drv_data = | ||
111 | kmalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL); | ||
112 | |||
113 | if (!drv_data) | ||
114 | return -ENOMEM; | ||
115 | memzero(drv_data, sizeof(*drv_data)); | ||
116 | drv_data->gpio_pins = gpio; | ||
117 | |||
118 | drv_data->algo_data.data = gpio; | ||
119 | drv_data->algo_data.setsda = ixp2000_bit_setsda; | ||
120 | drv_data->algo_data.setscl = ixp2000_bit_setscl; | ||
121 | drv_data->algo_data.getsda = ixp2000_bit_getsda; | ||
122 | drv_data->algo_data.getscl = ixp2000_bit_getscl; | ||
123 | drv_data->algo_data.udelay = 6; | ||
124 | drv_data->algo_data.mdelay = 6; | ||
125 | drv_data->algo_data.timeout = 100; | ||
126 | |||
127 | drv_data->adapter.id = I2C_HW_B_IXP2000, | ||
128 | drv_data->adapter.algo_data = &drv_data->algo_data, | ||
129 | |||
130 | drv_data->adapter.dev.parent = &plat_dev->dev; | ||
131 | |||
132 | gpio_line_config(gpio->sda_pin, GPIO_IN); | ||
133 | gpio_line_config(gpio->scl_pin, GPIO_IN); | ||
134 | gpio_line_set(gpio->scl_pin, 0); | ||
135 | gpio_line_set(gpio->sda_pin, 0); | ||
136 | |||
137 | if ((err = i2c_bit_add_bus(&drv_data->adapter)) != 0) { | ||
138 | dev_err(dev, "Could not install, error %d\n", err); | ||
139 | kfree(drv_data); | ||
140 | return err; | ||
141 | } | ||
142 | |||
143 | dev_set_drvdata(&plat_dev->dev, drv_data); | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static struct device_driver ixp2000_i2c_driver = { | ||
149 | .name = "IXP2000-I2C", | ||
150 | .bus = &platform_bus_type, | ||
151 | .probe = ixp2000_i2c_probe, | ||
152 | .remove = ixp2000_i2c_remove, | ||
153 | }; | ||
154 | |||
155 | static int __init ixp2000_i2c_init(void) | ||
156 | { | ||
157 | return driver_register(&ixp2000_i2c_driver); | ||
158 | } | ||
159 | |||
160 | static void __exit ixp2000_i2c_exit(void) | ||
161 | { | ||
162 | driver_unregister(&ixp2000_i2c_driver); | ||
163 | } | ||
164 | |||
165 | module_init(ixp2000_i2c_init); | ||
166 | module_exit(ixp2000_i2c_exit); | ||
167 | |||
168 | MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>"); | ||
169 | MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver"); | ||
170 | MODULE_LICENSE("GPL"); | ||
171 | |||