diff options
Diffstat (limited to 'drivers/i2c/chips')
-rw-r--r-- | drivers/i2c/chips/Kconfig | 48 | ||||
-rw-r--r-- | drivers/i2c/chips/Makefile | 3 | ||||
-rw-r--r-- | drivers/i2c/chips/pca9539.c | 152 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8574.c | 215 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8575.c | 198 | ||||
-rw-r--r-- | drivers/i2c/chips/tsl2550.c | 42 |
6 files changed, 10 insertions, 648 deletions
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig index 02d746c9c474..f9618f4d4e47 100644 --- a/drivers/i2c/chips/Kconfig +++ b/drivers/i2c/chips/Kconfig | |||
@@ -16,54 +16,6 @@ config DS1682 | |||
16 | This driver can also be built as a module. If so, the module | 16 | This driver can also be built as a module. If so, the module |
17 | will be called ds1682. | 17 | will be called ds1682. |
18 | 18 | ||
19 | config SENSORS_PCF8574 | ||
20 | tristate "Philips PCF8574 and PCF8574A (DEPRECATED)" | ||
21 | depends on EXPERIMENTAL && GPIO_PCF857X = "n" | ||
22 | default n | ||
23 | help | ||
24 | If you say yes here you get support for Philips PCF8574 and | ||
25 | PCF8574A chips. These chips are 8-bit I/O expanders for the I2C bus. | ||
26 | |||
27 | This driver can also be built as a module. If so, the module | ||
28 | will be called pcf8574. | ||
29 | |||
30 | This driver is deprecated and will be dropped soon. Use | ||
31 | drivers/gpio/pcf857x.c instead. | ||
32 | |||
33 | These devices are hard to detect and rarely found on mainstream | ||
34 | hardware. If unsure, say N. | ||
35 | |||
36 | config PCF8575 | ||
37 | tristate "Philips PCF8575 (DEPRECATED)" | ||
38 | default n | ||
39 | depends on GPIO_PCF857X = "n" | ||
40 | help | ||
41 | If you say yes here you get support for Philips PCF8575 chip. | ||
42 | This chip is a 16-bit I/O expander for the I2C bus. Several other | ||
43 | chip manufacturers sell equivalent chips, e.g. Texas Instruments. | ||
44 | |||
45 | This driver can also be built as a module. If so, the module | ||
46 | will be called pcf8575. | ||
47 | |||
48 | This driver is deprecated and will be dropped soon. Use | ||
49 | drivers/gpio/pcf857x.c instead. | ||
50 | |||
51 | This device is hard to detect and is rarely found on mainstream | ||
52 | hardware. If unsure, say N. | ||
53 | |||
54 | config SENSORS_PCA9539 | ||
55 | tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)" | ||
56 | depends on EXPERIMENTAL && GPIO_PCA953X = "n" | ||
57 | help | ||
58 | If you say yes here you get support for the Philips PCA9539 | ||
59 | 16-bit I/O port. | ||
60 | |||
61 | This driver can also be built as a module. If so, the module | ||
62 | will be called pca9539. | ||
63 | |||
64 | This driver is deprecated and will be dropped soon. Use | ||
65 | drivers/gpio/pca953x.c instead. | ||
66 | |||
67 | config SENSORS_TSL2550 | 19 | config SENSORS_TSL2550 |
68 | tristate "Taos TSL2550 ambient light sensor" | 20 | tristate "Taos TSL2550 ambient light sensor" |
69 | depends on EXPERIMENTAL | 21 | depends on EXPERIMENTAL |
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile index f4680d16ee34..749cf3606294 100644 --- a/drivers/i2c/chips/Makefile +++ b/drivers/i2c/chips/Makefile | |||
@@ -11,9 +11,6 @@ | |||
11 | # | 11 | # |
12 | 12 | ||
13 | obj-$(CONFIG_DS1682) += ds1682.o | 13 | obj-$(CONFIG_DS1682) += ds1682.o |
14 | obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o | ||
15 | obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o | ||
16 | obj-$(CONFIG_PCF8575) += pcf8575.o | ||
17 | obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o | 14 | obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o |
18 | 15 | ||
19 | ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) | 16 | ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) |
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c deleted file mode 100644 index 270de4e56a81..000000000000 --- a/drivers/i2c/chips/pca9539.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* | ||
2 | pca9539.c - 16-bit I/O port with interrupt and reset | ||
3 | |||
4 | Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; version 2 of the License. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/i2c.h> | ||
15 | #include <linux/hwmon-sysfs.h> | ||
16 | |||
17 | /* Addresses to scan: none, device is not autodetected */ | ||
18 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
19 | |||
20 | /* Insmod parameters */ | ||
21 | I2C_CLIENT_INSMOD_1(pca9539); | ||
22 | |||
23 | enum pca9539_cmd | ||
24 | { | ||
25 | PCA9539_INPUT_0 = 0, | ||
26 | PCA9539_INPUT_1 = 1, | ||
27 | PCA9539_OUTPUT_0 = 2, | ||
28 | PCA9539_OUTPUT_1 = 3, | ||
29 | PCA9539_INVERT_0 = 4, | ||
30 | PCA9539_INVERT_1 = 5, | ||
31 | PCA9539_DIRECTION_0 = 6, | ||
32 | PCA9539_DIRECTION_1 = 7, | ||
33 | }; | ||
34 | |||
35 | /* following are the sysfs callback functions */ | ||
36 | static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, | ||
37 | char *buf) | ||
38 | { | ||
39 | struct sensor_device_attribute *psa = to_sensor_dev_attr(attr); | ||
40 | struct i2c_client *client = to_i2c_client(dev); | ||
41 | return sprintf(buf, "%d\n", i2c_smbus_read_byte_data(client, | ||
42 | psa->index)); | ||
43 | } | ||
44 | |||
45 | static ssize_t pca9539_store(struct device *dev, struct device_attribute *attr, | ||
46 | const char *buf, size_t count) | ||
47 | { | ||
48 | struct sensor_device_attribute *psa = to_sensor_dev_attr(attr); | ||
49 | struct i2c_client *client = to_i2c_client(dev); | ||
50 | unsigned long val = simple_strtoul(buf, NULL, 0); | ||
51 | if (val > 0xff) | ||
52 | return -EINVAL; | ||
53 | i2c_smbus_write_byte_data(client, psa->index, val); | ||
54 | return count; | ||
55 | } | ||
56 | |||
57 | /* Define the device attributes */ | ||
58 | |||
59 | #define PCA9539_ENTRY_RO(name, cmd_idx) \ | ||
60 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, pca9539_show, NULL, cmd_idx) | ||
61 | |||
62 | #define PCA9539_ENTRY_RW(name, cmd_idx) \ | ||
63 | static SENSOR_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, pca9539_show, \ | ||
64 | pca9539_store, cmd_idx) | ||
65 | |||
66 | PCA9539_ENTRY_RO(input0, PCA9539_INPUT_0); | ||
67 | PCA9539_ENTRY_RO(input1, PCA9539_INPUT_1); | ||
68 | PCA9539_ENTRY_RW(output0, PCA9539_OUTPUT_0); | ||
69 | PCA9539_ENTRY_RW(output1, PCA9539_OUTPUT_1); | ||
70 | PCA9539_ENTRY_RW(invert0, PCA9539_INVERT_0); | ||
71 | PCA9539_ENTRY_RW(invert1, PCA9539_INVERT_1); | ||
72 | PCA9539_ENTRY_RW(direction0, PCA9539_DIRECTION_0); | ||
73 | PCA9539_ENTRY_RW(direction1, PCA9539_DIRECTION_1); | ||
74 | |||
75 | static struct attribute *pca9539_attributes[] = { | ||
76 | &sensor_dev_attr_input0.dev_attr.attr, | ||
77 | &sensor_dev_attr_input1.dev_attr.attr, | ||
78 | &sensor_dev_attr_output0.dev_attr.attr, | ||
79 | &sensor_dev_attr_output1.dev_attr.attr, | ||
80 | &sensor_dev_attr_invert0.dev_attr.attr, | ||
81 | &sensor_dev_attr_invert1.dev_attr.attr, | ||
82 | &sensor_dev_attr_direction0.dev_attr.attr, | ||
83 | &sensor_dev_attr_direction1.dev_attr.attr, | ||
84 | NULL | ||
85 | }; | ||
86 | |||
87 | static struct attribute_group pca9539_defattr_group = { | ||
88 | .attrs = pca9539_attributes, | ||
89 | }; | ||
90 | |||
91 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
92 | static int pca9539_detect(struct i2c_client *client, int kind, | ||
93 | struct i2c_board_info *info) | ||
94 | { | ||
95 | struct i2c_adapter *adapter = client->adapter; | ||
96 | |||
97 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
98 | return -ENODEV; | ||
99 | |||
100 | strlcpy(info->type, "pca9539", I2C_NAME_SIZE); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int pca9539_probe(struct i2c_client *client, | ||
106 | const struct i2c_device_id *id) | ||
107 | { | ||
108 | /* Register sysfs hooks */ | ||
109 | return sysfs_create_group(&client->dev.kobj, | ||
110 | &pca9539_defattr_group); | ||
111 | } | ||
112 | |||
113 | static int pca9539_remove(struct i2c_client *client) | ||
114 | { | ||
115 | sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static const struct i2c_device_id pca9539_id[] = { | ||
120 | { "pca9539", 0 }, | ||
121 | { } | ||
122 | }; | ||
123 | |||
124 | static struct i2c_driver pca9539_driver = { | ||
125 | .driver = { | ||
126 | .name = "pca9539", | ||
127 | }, | ||
128 | .probe = pca9539_probe, | ||
129 | .remove = pca9539_remove, | ||
130 | .id_table = pca9539_id, | ||
131 | |||
132 | .detect = pca9539_detect, | ||
133 | .address_data = &addr_data, | ||
134 | }; | ||
135 | |||
136 | static int __init pca9539_init(void) | ||
137 | { | ||
138 | return i2c_add_driver(&pca9539_driver); | ||
139 | } | ||
140 | |||
141 | static void __exit pca9539_exit(void) | ||
142 | { | ||
143 | i2c_del_driver(&pca9539_driver); | ||
144 | } | ||
145 | |||
146 | MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>"); | ||
147 | MODULE_DESCRIPTION("PCA9539 driver"); | ||
148 | MODULE_LICENSE("GPL"); | ||
149 | |||
150 | module_init(pca9539_init); | ||
151 | module_exit(pca9539_exit); | ||
152 | |||
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c deleted file mode 100644 index 6ec309894c88..000000000000 --- a/drivers/i2c/chips/pcf8574.c +++ /dev/null | |||
@@ -1,215 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>, | ||
3 | Philip Edelbrock <phil@netroedge.com>, | ||
4 | Dan Eaton <dan.eaton@rocketlogix.com> | ||
5 | Ported to Linux 2.6 by Aurelien Jarno <aurel32@debian.org> with | ||
6 | the help of Jean Delvare <khali@linux-fr.org> | ||
7 | |||
8 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | /* A few notes about the PCF8574: | ||
24 | |||
25 | * The PCF8574 is an 8-bit I/O expander for the I2C bus produced by | ||
26 | Philips Semiconductors. It is designed to provide a byte I2C | ||
27 | interface to up to 8 separate devices. | ||
28 | |||
29 | * The PCF8574 appears as a very simple SMBus device which can be | ||
30 | read from or written to with SMBUS byte read/write accesses. | ||
31 | |||
32 | --Dan | ||
33 | |||
34 | */ | ||
35 | |||
36 | #include <linux/module.h> | ||
37 | #include <linux/init.h> | ||
38 | #include <linux/slab.h> | ||
39 | #include <linux/i2c.h> | ||
40 | |||
41 | /* Addresses to scan: none, device can't be detected */ | ||
42 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
43 | |||
44 | /* Insmod parameters */ | ||
45 | I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); | ||
46 | |||
47 | /* Each client has this additional data */ | ||
48 | struct pcf8574_data { | ||
49 | int write; /* Remember last written value */ | ||
50 | }; | ||
51 | |||
52 | static void pcf8574_init_client(struct i2c_client *client); | ||
53 | |||
54 | /* following are the sysfs callback functions */ | ||
55 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) | ||
56 | { | ||
57 | struct i2c_client *client = to_i2c_client(dev); | ||
58 | return sprintf(buf, "%u\n", i2c_smbus_read_byte(client)); | ||
59 | } | ||
60 | |||
61 | static DEVICE_ATTR(read, S_IRUGO, show_read, NULL); | ||
62 | |||
63 | static ssize_t show_write(struct device *dev, struct device_attribute *attr, char *buf) | ||
64 | { | ||
65 | struct pcf8574_data *data = i2c_get_clientdata(to_i2c_client(dev)); | ||
66 | |||
67 | if (data->write < 0) | ||
68 | return data->write; | ||
69 | |||
70 | return sprintf(buf, "%d\n", data->write); | ||
71 | } | ||
72 | |||
73 | static ssize_t set_write(struct device *dev, struct device_attribute *attr, const char *buf, | ||
74 | size_t count) | ||
75 | { | ||
76 | struct i2c_client *client = to_i2c_client(dev); | ||
77 | struct pcf8574_data *data = i2c_get_clientdata(client); | ||
78 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
79 | |||
80 | if (val > 0xff) | ||
81 | return -EINVAL; | ||
82 | |||
83 | data->write = val; | ||
84 | i2c_smbus_write_byte(client, data->write); | ||
85 | return count; | ||
86 | } | ||
87 | |||
88 | static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); | ||
89 | |||
90 | static struct attribute *pcf8574_attributes[] = { | ||
91 | &dev_attr_read.attr, | ||
92 | &dev_attr_write.attr, | ||
93 | NULL | ||
94 | }; | ||
95 | |||
96 | static const struct attribute_group pcf8574_attr_group = { | ||
97 | .attrs = pcf8574_attributes, | ||
98 | }; | ||
99 | |||
100 | /* | ||
101 | * Real code | ||
102 | */ | ||
103 | |||
104 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
105 | static int pcf8574_detect(struct i2c_client *client, int kind, | ||
106 | struct i2c_board_info *info) | ||
107 | { | ||
108 | struct i2c_adapter *adapter = client->adapter; | ||
109 | const char *client_name; | ||
110 | |||
111 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | ||
112 | return -ENODEV; | ||
113 | |||
114 | /* Now, we would do the remaining detection. But the PCF8574 is plainly | ||
115 | impossible to detect! Stupid chip. */ | ||
116 | |||
117 | /* Determine the chip type */ | ||
118 | if (kind <= 0) { | ||
119 | if (client->addr >= 0x38 && client->addr <= 0x3f) | ||
120 | kind = pcf8574a; | ||
121 | else | ||
122 | kind = pcf8574; | ||
123 | } | ||
124 | |||
125 | if (kind == pcf8574a) | ||
126 | client_name = "pcf8574a"; | ||
127 | else | ||
128 | client_name = "pcf8574"; | ||
129 | strlcpy(info->type, client_name, I2C_NAME_SIZE); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static int pcf8574_probe(struct i2c_client *client, | ||
135 | const struct i2c_device_id *id) | ||
136 | { | ||
137 | struct pcf8574_data *data; | ||
138 | int err; | ||
139 | |||
140 | data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL); | ||
141 | if (!data) { | ||
142 | err = -ENOMEM; | ||
143 | goto exit; | ||
144 | } | ||
145 | |||
146 | i2c_set_clientdata(client, data); | ||
147 | |||
148 | /* Initialize the PCF8574 chip */ | ||
149 | pcf8574_init_client(client); | ||
150 | |||
151 | /* Register sysfs hooks */ | ||
152 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); | ||
153 | if (err) | ||
154 | goto exit_free; | ||
155 | return 0; | ||
156 | |||
157 | exit_free: | ||
158 | kfree(data); | ||
159 | exit: | ||
160 | return err; | ||
161 | } | ||
162 | |||
163 | static int pcf8574_remove(struct i2c_client *client) | ||
164 | { | ||
165 | sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); | ||
166 | kfree(i2c_get_clientdata(client)); | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* Called when we have found a new PCF8574. */ | ||
171 | static void pcf8574_init_client(struct i2c_client *client) | ||
172 | { | ||
173 | struct pcf8574_data *data = i2c_get_clientdata(client); | ||
174 | data->write = -EAGAIN; | ||
175 | } | ||
176 | |||
177 | static const struct i2c_device_id pcf8574_id[] = { | ||
178 | { "pcf8574", 0 }, | ||
179 | { "pcf8574a", 0 }, | ||
180 | { } | ||
181 | }; | ||
182 | |||
183 | static struct i2c_driver pcf8574_driver = { | ||
184 | .driver = { | ||
185 | .name = "pcf8574", | ||
186 | }, | ||
187 | .probe = pcf8574_probe, | ||
188 | .remove = pcf8574_remove, | ||
189 | .id_table = pcf8574_id, | ||
190 | |||
191 | .detect = pcf8574_detect, | ||
192 | .address_data = &addr_data, | ||
193 | }; | ||
194 | |||
195 | static int __init pcf8574_init(void) | ||
196 | { | ||
197 | return i2c_add_driver(&pcf8574_driver); | ||
198 | } | ||
199 | |||
200 | static void __exit pcf8574_exit(void) | ||
201 | { | ||
202 | i2c_del_driver(&pcf8574_driver); | ||
203 | } | ||
204 | |||
205 | |||
206 | MODULE_AUTHOR | ||
207 | ("Frodo Looijaard <frodol@dds.nl>, " | ||
208 | "Philip Edelbrock <phil@netroedge.com>, " | ||
209 | "Dan Eaton <dan.eaton@rocketlogix.com> " | ||
210 | "and Aurelien Jarno <aurelien@aurel32.net>"); | ||
211 | MODULE_DESCRIPTION("PCF8574 driver"); | ||
212 | MODULE_LICENSE("GPL"); | ||
213 | |||
214 | module_init(pcf8574_init); | ||
215 | module_exit(pcf8574_exit); | ||
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c deleted file mode 100644 index 07fd7cb3c57d..000000000000 --- a/drivers/i2c/chips/pcf8575.c +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /* | ||
2 | pcf8575.c | ||
3 | |||
4 | About the PCF8575 chip: the PCF8575 is a 16-bit I/O expander for the I2C bus | ||
5 | produced by a.o. Philips Semiconductors. | ||
6 | |||
7 | Copyright (C) 2006 Michael Hennerich, Analog Devices Inc. | ||
8 | <hennerich@blackfin.uclinux.org> | ||
9 | Based on pcf8574.c. | ||
10 | |||
11 | Copyright (c) 2007 Bart Van Assche <bart.vanassche@gmail.com>. | ||
12 | Ported this driver from ucLinux to the mainstream Linux kernel. | ||
13 | |||
14 | This program is free software; you can redistribute it and/or modify | ||
15 | it under the terms of the GNU General Public License as published by | ||
16 | the Free Software Foundation; either version 2 of the License, or | ||
17 | (at your option) any later version. | ||
18 | |||
19 | This program is distributed in the hope that it will be useful, | ||
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | GNU General Public License for more details. | ||
23 | |||
24 | You should have received a copy of the GNU General Public License | ||
25 | along with this program; if not, write to the Free Software | ||
26 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | */ | ||
28 | |||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/i2c.h> | ||
32 | #include <linux/slab.h> /* kzalloc() */ | ||
33 | #include <linux/sysfs.h> /* sysfs_create_group() */ | ||
34 | |||
35 | /* Addresses to scan: none, device can't be detected */ | ||
36 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
37 | |||
38 | /* Insmod parameters */ | ||
39 | I2C_CLIENT_INSMOD; | ||
40 | |||
41 | |||
42 | /* Each client has this additional data */ | ||
43 | struct pcf8575_data { | ||
44 | int write; /* last written value, or error code */ | ||
45 | }; | ||
46 | |||
47 | /* following are the sysfs callback functions */ | ||
48 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, | ||
49 | char *buf) | ||
50 | { | ||
51 | struct i2c_client *client = to_i2c_client(dev); | ||
52 | u16 val; | ||
53 | u8 iopin_state[2]; | ||
54 | |||
55 | i2c_master_recv(client, iopin_state, 2); | ||
56 | |||
57 | val = iopin_state[0]; | ||
58 | val |= iopin_state[1] << 8; | ||
59 | |||
60 | return sprintf(buf, "%u\n", val); | ||
61 | } | ||
62 | |||
63 | static DEVICE_ATTR(read, S_IRUGO, show_read, NULL); | ||
64 | |||
65 | static ssize_t show_write(struct device *dev, struct device_attribute *attr, | ||
66 | char *buf) | ||
67 | { | ||
68 | struct pcf8575_data *data = dev_get_drvdata(dev); | ||
69 | if (data->write < 0) | ||
70 | return data->write; | ||
71 | return sprintf(buf, "%d\n", data->write); | ||
72 | } | ||
73 | |||
74 | static ssize_t set_write(struct device *dev, struct device_attribute *attr, | ||
75 | const char *buf, size_t count) | ||
76 | { | ||
77 | struct i2c_client *client = to_i2c_client(dev); | ||
78 | struct pcf8575_data *data = i2c_get_clientdata(client); | ||
79 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
80 | u8 iopin_state[2]; | ||
81 | |||
82 | if (val > 0xffff) | ||
83 | return -EINVAL; | ||
84 | |||
85 | data->write = val; | ||
86 | |||
87 | iopin_state[0] = val & 0xFF; | ||
88 | iopin_state[1] = val >> 8; | ||
89 | |||
90 | i2c_master_send(client, iopin_state, 2); | ||
91 | |||
92 | return count; | ||
93 | } | ||
94 | |||
95 | static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); | ||
96 | |||
97 | static struct attribute *pcf8575_attributes[] = { | ||
98 | &dev_attr_read.attr, | ||
99 | &dev_attr_write.attr, | ||
100 | NULL | ||
101 | }; | ||
102 | |||
103 | static const struct attribute_group pcf8575_attr_group = { | ||
104 | .attrs = pcf8575_attributes, | ||
105 | }; | ||
106 | |||
107 | /* | ||
108 | * Real code | ||
109 | */ | ||
110 | |||
111 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
112 | static int pcf8575_detect(struct i2c_client *client, int kind, | ||
113 | struct i2c_board_info *info) | ||
114 | { | ||
115 | struct i2c_adapter *adapter = client->adapter; | ||
116 | |||
117 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) | ||
118 | return -ENODEV; | ||
119 | |||
120 | /* This is the place to detect whether the chip at the specified | ||
121 | address really is a PCF8575 chip. However, there is no method known | ||
122 | to detect whether an I2C chip is a PCF8575 or any other I2C chip. */ | ||
123 | |||
124 | strlcpy(info->type, "pcf8575", I2C_NAME_SIZE); | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | static int pcf8575_probe(struct i2c_client *client, | ||
130 | const struct i2c_device_id *id) | ||
131 | { | ||
132 | struct pcf8575_data *data; | ||
133 | int err; | ||
134 | |||
135 | data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); | ||
136 | if (!data) { | ||
137 | err = -ENOMEM; | ||
138 | goto exit; | ||
139 | } | ||
140 | |||
141 | i2c_set_clientdata(client, data); | ||
142 | data->write = -EAGAIN; | ||
143 | |||
144 | /* Register sysfs hooks */ | ||
145 | err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); | ||
146 | if (err) | ||
147 | goto exit_free; | ||
148 | |||
149 | return 0; | ||
150 | |||
151 | exit_free: | ||
152 | kfree(data); | ||
153 | exit: | ||
154 | return err; | ||
155 | } | ||
156 | |||
157 | static int pcf8575_remove(struct i2c_client *client) | ||
158 | { | ||
159 | sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); | ||
160 | kfree(i2c_get_clientdata(client)); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static const struct i2c_device_id pcf8575_id[] = { | ||
165 | { "pcf8575", 0 }, | ||
166 | { } | ||
167 | }; | ||
168 | |||
169 | static struct i2c_driver pcf8575_driver = { | ||
170 | .driver = { | ||
171 | .owner = THIS_MODULE, | ||
172 | .name = "pcf8575", | ||
173 | }, | ||
174 | .probe = pcf8575_probe, | ||
175 | .remove = pcf8575_remove, | ||
176 | .id_table = pcf8575_id, | ||
177 | |||
178 | .detect = pcf8575_detect, | ||
179 | .address_data = &addr_data, | ||
180 | }; | ||
181 | |||
182 | static int __init pcf8575_init(void) | ||
183 | { | ||
184 | return i2c_add_driver(&pcf8575_driver); | ||
185 | } | ||
186 | |||
187 | static void __exit pcf8575_exit(void) | ||
188 | { | ||
189 | i2c_del_driver(&pcf8575_driver); | ||
190 | } | ||
191 | |||
192 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>, " | ||
193 | "Bart Van Assche <bart.vanassche@gmail.com>"); | ||
194 | MODULE_DESCRIPTION("pcf8575 driver"); | ||
195 | MODULE_LICENSE("GPL"); | ||
196 | |||
197 | module_init(pcf8575_init); | ||
198 | module_exit(pcf8575_exit); | ||
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c index b96f3025e588..aa96bd2d27ea 100644 --- a/drivers/i2c/chips/tsl2550.c +++ b/drivers/i2c/chips/tsl2550.c | |||
@@ -24,10 +24,9 @@ | |||
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/mutex.h> | 26 | #include <linux/mutex.h> |
27 | #include <linux/delay.h> | ||
28 | 27 | ||
29 | #define TSL2550_DRV_NAME "tsl2550" | 28 | #define TSL2550_DRV_NAME "tsl2550" |
30 | #define DRIVER_VERSION "1.1.2" | 29 | #define DRIVER_VERSION "1.2" |
31 | 30 | ||
32 | /* | 31 | /* |
33 | * Defines | 32 | * Defines |
@@ -96,32 +95,13 @@ static int tsl2550_set_power_state(struct i2c_client *client, int state) | |||
96 | 95 | ||
97 | static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd) | 96 | static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd) |
98 | { | 97 | { |
99 | unsigned long end; | 98 | int ret; |
100 | int loop = 0, ret = 0; | ||
101 | 99 | ||
102 | /* | 100 | ret = i2c_smbus_read_byte_data(client, cmd); |
103 | * Read ADC channel waiting at most 400ms (see data sheet for further | 101 | if (ret < 0) |
104 | * info). | 102 | return ret; |
105 | * To avoid long busy wait we spin for few milliseconds then | ||
106 | * start sleeping. | ||
107 | */ | ||
108 | end = jiffies + msecs_to_jiffies(400); | ||
109 | while (time_before(jiffies, end)) { | ||
110 | i2c_smbus_write_byte(client, cmd); | ||
111 | |||
112 | if (loop++ < 5) | ||
113 | mdelay(1); | ||
114 | else | ||
115 | msleep(1); | ||
116 | |||
117 | ret = i2c_smbus_read_byte(client); | ||
118 | if (ret < 0) | ||
119 | return ret; | ||
120 | else if (ret & 0x0080) | ||
121 | break; | ||
122 | } | ||
123 | if (!(ret & 0x80)) | 103 | if (!(ret & 0x80)) |
124 | return -EIO; | 104 | return -EAGAIN; |
125 | return ret & 0x7f; /* remove the "valid" bit */ | 105 | return ret & 0x7f; /* remove the "valid" bit */ |
126 | } | 106 | } |
127 | 107 | ||
@@ -285,8 +265,6 @@ static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf) | |||
285 | return ret; | 265 | return ret; |
286 | ch0 = ret; | 266 | ch0 = ret; |
287 | 267 | ||
288 | mdelay(1); | ||
289 | |||
290 | ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1); | 268 | ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1); |
291 | if (ret < 0) | 269 | if (ret < 0) |
292 | return ret; | 270 | return ret; |
@@ -345,11 +323,10 @@ static int tsl2550_init_client(struct i2c_client *client) | |||
345 | * Probe the chip. To do so we try to power up the device and then to | 323 | * Probe the chip. To do so we try to power up the device and then to |
346 | * read back the 0x03 code | 324 | * read back the 0x03 code |
347 | */ | 325 | */ |
348 | err = i2c_smbus_write_byte(client, TSL2550_POWER_UP); | 326 | err = i2c_smbus_read_byte_data(client, TSL2550_POWER_UP); |
349 | if (err < 0) | 327 | if (err < 0) |
350 | return err; | 328 | return err; |
351 | mdelay(1); | 329 | if (err != TSL2550_POWER_UP) |
352 | if (i2c_smbus_read_byte(client) != TSL2550_POWER_UP) | ||
353 | return -ENODEV; | 330 | return -ENODEV; |
354 | data->power_state = 1; | 331 | data->power_state = 1; |
355 | 332 | ||
@@ -374,7 +351,8 @@ static int __devinit tsl2550_probe(struct i2c_client *client, | |||
374 | struct tsl2550_data *data; | 351 | struct tsl2550_data *data; |
375 | int *opmode, err = 0; | 352 | int *opmode, err = 0; |
376 | 353 | ||
377 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) { | 354 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE |
355 | | I2C_FUNC_SMBUS_READ_BYTE_DATA)) { | ||
378 | err = -EIO; | 356 | err = -EIO; |
379 | goto exit; | 357 | goto exit; |
380 | } | 358 | } |