diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-08 11:12:16 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-08 11:12:16 -0500 |
commit | 41440ffe21f29bdb985cab76b2d0b06d83e63b19 (patch) | |
tree | 1d7d1ff6f699ccbabb71c7bc4172f7d15bc4bc45 /drivers/misc | |
parent | dad3de7d0090280f44ff27131ed2878f1ab6ddad (diff) | |
parent | 6471b68982d3bb1a593c3e183c804ecf830125d3 (diff) |
Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
i2c-stub: Documentation update
i2c-stub: Allow user to disable some commands
i2c-stub: Implement I2C block support
i2c: Refactor for_each callbacks
i2c-i801: Retry on lost arbitration
i2c: Remove big kernel lock from i2cdev_open
ics932s401: Clean up detect function
i2c: Simplify i2c_detect_address
i2c: Drop probe, ignore and force module parameters
i2c: Add missing __devinit markers to old i2c adapter drivers
i2c: Bus drivers don't have to support I2C_M_REV_DIR_ADDR
i2c: Prevent priority inversion on top of bus lock
i2c-voodoo3: Delete
i2c-powermac: Drop temporary name buffer
i2c-powermac: Include the i2c_adapter in struct pmac_i2c_bus
i2c-powermac: Log errors
i2c-powermac: Refactor i2c_powermac_smbus_xfer
i2c-powermac: Reject unsupported I2C transactions
i2c/chips: Move ds1682 to drivers/misc
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/misc/Makefile | 1 | ||||
-rw-r--r-- | drivers/misc/ds1682.c | 267 | ||||
-rw-r--r-- | drivers/misc/ics932s401.c | 37 |
4 files changed, 293 insertions, 22 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index a2ea383105a..2c16ca6501d 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -246,6 +246,16 @@ config EP93XX_PWM | |||
246 | To compile this driver as a module, choose M here: the module will | 246 | To compile this driver as a module, choose M here: the module will |
247 | be called ep93xx_pwm. | 247 | be called ep93xx_pwm. |
248 | 248 | ||
249 | config DS1682 | ||
250 | tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm" | ||
251 | depends on I2C && EXPERIMENTAL | ||
252 | help | ||
253 | If you say yes here you get support for Dallas Semiconductor | ||
254 | DS1682 Total Elapsed Time Recorder. | ||
255 | |||
256 | This driver can also be built as a module. If so, the module | ||
257 | will be called ds1682. | ||
258 | |||
249 | source "drivers/misc/c2port/Kconfig" | 259 | source "drivers/misc/c2port/Kconfig" |
250 | source "drivers/misc/eeprom/Kconfig" | 260 | source "drivers/misc/eeprom/Kconfig" |
251 | source "drivers/misc/cb710/Kconfig" | 261 | source "drivers/misc/cb710/Kconfig" |
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index e311267a355..906a0edcea4 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile | |||
@@ -20,6 +20,7 @@ obj-$(CONFIG_SGI_GRU) += sgi-gru/ | |||
20 | obj-$(CONFIG_HP_ILO) += hpilo.o | 20 | obj-$(CONFIG_HP_ILO) += hpilo.o |
21 | obj-$(CONFIG_ISL29003) += isl29003.o | 21 | obj-$(CONFIG_ISL29003) += isl29003.o |
22 | obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o | 22 | obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o |
23 | obj-$(CONFIG_DS1682) += ds1682.o | ||
23 | obj-$(CONFIG_C2PORT) += c2port/ | 24 | obj-$(CONFIG_C2PORT) += c2port/ |
24 | obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/ | 25 | obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/ |
25 | obj-y += eeprom/ | 26 | obj-y += eeprom/ |
diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c new file mode 100644 index 00000000000..f3ee4a1abb7 --- /dev/null +++ b/drivers/misc/ds1682.c | |||
@@ -0,0 +1,267 @@ | |||
1 | /* | ||
2 | * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver | ||
3 | * | ||
4 | * Written by: Grant Likely <grant.likely@secretlab.ca> | ||
5 | * | ||
6 | * Copyright (C) 2007 Secret Lab Technologies Ltd. | ||
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 version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * The DS1682 elapsed timer recorder is a simple device that implements | ||
15 | * one elapsed time counter, one event counter, an alarm signal and 10 | ||
16 | * bytes of general purpose EEPROM. | ||
17 | * | ||
18 | * This driver provides access to the DS1682 counters and user data via | ||
19 | * the sysfs. The following attributes are added to the device node: | ||
20 | * elapsed_time (u32): Total elapsed event time in ms resolution | ||
21 | * alarm_time (u32): When elapsed time exceeds the value in alarm_time, | ||
22 | * then the alarm pin is asserted. | ||
23 | * event_count (u16): number of times the event pin has gone low. | ||
24 | * eeprom (u8[10]): general purpose EEPROM | ||
25 | * | ||
26 | * Counter registers and user data are both read/write unless the device | ||
27 | * has been write protected. This driver does not support turning off write | ||
28 | * protection. Once write protection is turned on, it is impossible to | ||
29 | * turn it off again, so I have left the feature out of this driver to avoid | ||
30 | * accidental enabling, but it is trivial to add write protect support. | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include <linux/module.h> | ||
35 | #include <linux/init.h> | ||
36 | #include <linux/slab.h> | ||
37 | #include <linux/i2c.h> | ||
38 | #include <linux/string.h> | ||
39 | #include <linux/list.h> | ||
40 | #include <linux/sysfs.h> | ||
41 | #include <linux/ctype.h> | ||
42 | #include <linux/hwmon-sysfs.h> | ||
43 | |||
44 | /* Device registers */ | ||
45 | #define DS1682_REG_CONFIG 0x00 | ||
46 | #define DS1682_REG_ALARM 0x01 | ||
47 | #define DS1682_REG_ELAPSED 0x05 | ||
48 | #define DS1682_REG_EVT_CNTR 0x09 | ||
49 | #define DS1682_REG_EEPROM 0x0b | ||
50 | #define DS1682_REG_RESET 0x1d | ||
51 | #define DS1682_REG_WRITE_DISABLE 0x1e | ||
52 | #define DS1682_REG_WRITE_MEM_DISABLE 0x1f | ||
53 | |||
54 | #define DS1682_EEPROM_SIZE 10 | ||
55 | |||
56 | /* | ||
57 | * Generic counter attributes | ||
58 | */ | ||
59 | static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr, | ||
60 | char *buf) | ||
61 | { | ||
62 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); | ||
63 | struct i2c_client *client = to_i2c_client(dev); | ||
64 | __le32 val = 0; | ||
65 | int rc; | ||
66 | |||
67 | dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name); | ||
68 | |||
69 | /* Read the register */ | ||
70 | rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr, | ||
71 | (u8 *) & val); | ||
72 | if (rc < 0) | ||
73 | return -EIO; | ||
74 | |||
75 | /* Special case: the 32 bit regs are time values with 1/4s | ||
76 | * resolution, scale them up to milliseconds */ | ||
77 | if (sattr->nr == 4) | ||
78 | return sprintf(buf, "%llu\n", | ||
79 | ((unsigned long long)le32_to_cpu(val)) * 250); | ||
80 | |||
81 | /* Format the output string and return # of bytes */ | ||
82 | return sprintf(buf, "%li\n", (long)le32_to_cpu(val)); | ||
83 | } | ||
84 | |||
85 | static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr, | ||
86 | const char *buf, size_t count) | ||
87 | { | ||
88 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); | ||
89 | struct i2c_client *client = to_i2c_client(dev); | ||
90 | char *endp; | ||
91 | u64 val; | ||
92 | __le32 val_le; | ||
93 | int rc; | ||
94 | |||
95 | dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name); | ||
96 | |||
97 | /* Decode input */ | ||
98 | val = simple_strtoull(buf, &endp, 0); | ||
99 | if (buf == endp) { | ||
100 | dev_dbg(dev, "input string not a number\n"); | ||
101 | return -EINVAL; | ||
102 | } | ||
103 | |||
104 | /* Special case: the 32 bit regs are time values with 1/4s | ||
105 | * resolution, scale input down to quarter-seconds */ | ||
106 | if (sattr->nr == 4) | ||
107 | do_div(val, 250); | ||
108 | |||
109 | /* write out the value */ | ||
110 | val_le = cpu_to_le32(val); | ||
111 | rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr, | ||
112 | (u8 *) & val_le); | ||
113 | if (rc < 0) { | ||
114 | dev_err(dev, "register write failed; reg=0x%x, size=%i\n", | ||
115 | sattr->index, sattr->nr); | ||
116 | return -EIO; | ||
117 | } | ||
118 | |||
119 | return count; | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * Simple register attributes | ||
124 | */ | ||
125 | static SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, | ||
126 | ds1682_store, 4, DS1682_REG_ELAPSED); | ||
127 | static SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, | ||
128 | ds1682_store, 4, DS1682_REG_ALARM); | ||
129 | static SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show, | ||
130 | ds1682_store, 2, DS1682_REG_EVT_CNTR); | ||
131 | |||
132 | static const struct attribute_group ds1682_group = { | ||
133 | .attrs = (struct attribute *[]) { | ||
134 | &sensor_dev_attr_elapsed_time.dev_attr.attr, | ||
135 | &sensor_dev_attr_alarm_time.dev_attr.attr, | ||
136 | &sensor_dev_attr_event_count.dev_attr.attr, | ||
137 | NULL, | ||
138 | }, | ||
139 | }; | ||
140 | |||
141 | /* | ||
142 | * User data attribute | ||
143 | */ | ||
144 | static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *attr, | ||
145 | char *buf, loff_t off, size_t count) | ||
146 | { | ||
147 | struct i2c_client *client = kobj_to_i2c_client(kobj); | ||
148 | int rc; | ||
149 | |||
150 | dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n", | ||
151 | buf, off, count); | ||
152 | |||
153 | if (off >= DS1682_EEPROM_SIZE) | ||
154 | return 0; | ||
155 | |||
156 | if (off + count > DS1682_EEPROM_SIZE) | ||
157 | count = DS1682_EEPROM_SIZE - off; | ||
158 | |||
159 | rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off, | ||
160 | count, buf); | ||
161 | if (rc < 0) | ||
162 | return -EIO; | ||
163 | |||
164 | return count; | ||
165 | } | ||
166 | |||
167 | static ssize_t ds1682_eeprom_write(struct kobject *kobj, struct bin_attribute *attr, | ||
168 | char *buf, loff_t off, size_t count) | ||
169 | { | ||
170 | struct i2c_client *client = kobj_to_i2c_client(kobj); | ||
171 | |||
172 | dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n", | ||
173 | buf, off, count); | ||
174 | |||
175 | if (off >= DS1682_EEPROM_SIZE) | ||
176 | return -ENOSPC; | ||
177 | |||
178 | if (off + count > DS1682_EEPROM_SIZE) | ||
179 | count = DS1682_EEPROM_SIZE - off; | ||
180 | |||
181 | /* Write out to the device */ | ||
182 | if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off, | ||
183 | count, buf) < 0) | ||
184 | return -EIO; | ||
185 | |||
186 | return count; | ||
187 | } | ||
188 | |||
189 | static struct bin_attribute ds1682_eeprom_attr = { | ||
190 | .attr = { | ||
191 | .name = "eeprom", | ||
192 | .mode = S_IRUGO | S_IWUSR, | ||
193 | }, | ||
194 | .size = DS1682_EEPROM_SIZE, | ||
195 | .read = ds1682_eeprom_read, | ||
196 | .write = ds1682_eeprom_write, | ||
197 | }; | ||
198 | |||
199 | /* | ||
200 | * Called when a ds1682 device is matched with this driver | ||
201 | */ | ||
202 | static int ds1682_probe(struct i2c_client *client, | ||
203 | const struct i2c_device_id *id) | ||
204 | { | ||
205 | int rc; | ||
206 | |||
207 | if (!i2c_check_functionality(client->adapter, | ||
208 | I2C_FUNC_SMBUS_I2C_BLOCK)) { | ||
209 | dev_err(&client->dev, "i2c bus does not support the ds1682\n"); | ||
210 | rc = -ENODEV; | ||
211 | goto exit; | ||
212 | } | ||
213 | |||
214 | rc = sysfs_create_group(&client->dev.kobj, &ds1682_group); | ||
215 | if (rc) | ||
216 | goto exit; | ||
217 | |||
218 | rc = sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr); | ||
219 | if (rc) | ||
220 | goto exit_bin_attr; | ||
221 | |||
222 | return 0; | ||
223 | |||
224 | exit_bin_attr: | ||
225 | sysfs_remove_group(&client->dev.kobj, &ds1682_group); | ||
226 | exit: | ||
227 | return rc; | ||
228 | } | ||
229 | |||
230 | static int ds1682_remove(struct i2c_client *client) | ||
231 | { | ||
232 | sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr); | ||
233 | sysfs_remove_group(&client->dev.kobj, &ds1682_group); | ||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static const struct i2c_device_id ds1682_id[] = { | ||
238 | { "ds1682", 0 }, | ||
239 | { } | ||
240 | }; | ||
241 | MODULE_DEVICE_TABLE(i2c, ds1682_id); | ||
242 | |||
243 | static struct i2c_driver ds1682_driver = { | ||
244 | .driver = { | ||
245 | .name = "ds1682", | ||
246 | }, | ||
247 | .probe = ds1682_probe, | ||
248 | .remove = ds1682_remove, | ||
249 | .id_table = ds1682_id, | ||
250 | }; | ||
251 | |||
252 | static int __init ds1682_init(void) | ||
253 | { | ||
254 | return i2c_add_driver(&ds1682_driver); | ||
255 | } | ||
256 | |||
257 | static void __exit ds1682_exit(void) | ||
258 | { | ||
259 | i2c_del_driver(&ds1682_driver); | ||
260 | } | ||
261 | |||
262 | MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); | ||
263 | MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver"); | ||
264 | MODULE_LICENSE("GPL"); | ||
265 | |||
266 | module_init(ds1682_init); | ||
267 | module_exit(ds1682_exit); | ||
diff --git a/drivers/misc/ics932s401.c b/drivers/misc/ics932s401.c index 6e43ab4231a..4bb7a3af9ad 100644 --- a/drivers/misc/ics932s401.c +++ b/drivers/misc/ics932s401.c | |||
@@ -417,32 +417,25 @@ static int ics932s401_detect(struct i2c_client *client, int kind, | |||
417 | struct i2c_board_info *info) | 417 | struct i2c_board_info *info) |
418 | { | 418 | { |
419 | struct i2c_adapter *adapter = client->adapter; | 419 | struct i2c_adapter *adapter = client->adapter; |
420 | int vendor, device, revision; | ||
420 | 421 | ||
421 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 422 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
422 | return -ENODEV; | 423 | return -ENODEV; |
423 | 424 | ||
424 | if (kind <= 0) { | 425 | vendor = i2c_smbus_read_word_data(client, ICS932S401_REG_VENDOR_REV); |
425 | int vendor, device, revision; | 426 | vendor >>= 8; |
426 | 427 | revision = vendor >> ICS932S401_REV_SHIFT; | |
427 | vendor = i2c_smbus_read_word_data(client, | 428 | vendor &= ICS932S401_VENDOR_MASK; |
428 | ICS932S401_REG_VENDOR_REV); | 429 | if (vendor != ICS932S401_VENDOR) |
429 | vendor >>= 8; | 430 | return -ENODEV; |
430 | revision = vendor >> ICS932S401_REV_SHIFT; | 431 | |
431 | vendor &= ICS932S401_VENDOR_MASK; | 432 | device = i2c_smbus_read_word_data(client, ICS932S401_REG_DEVICE); |
432 | if (vendor != ICS932S401_VENDOR) | 433 | device >>= 8; |
433 | return -ENODEV; | 434 | if (device != ICS932S401_DEVICE) |
434 | 435 | return -ENODEV; | |
435 | device = i2c_smbus_read_word_data(client, | 436 | |
436 | ICS932S401_REG_DEVICE); | 437 | if (revision != ICS932S401_REV) |
437 | device >>= 8; | 438 | dev_info(&adapter->dev, "Unknown revision %d\n", revision); |
438 | if (device != ICS932S401_DEVICE) | ||
439 | return -ENODEV; | ||
440 | |||
441 | if (revision != ICS932S401_REV) | ||
442 | dev_info(&adapter->dev, "Unknown revision %d\n", | ||
443 | revision); | ||
444 | } else | ||
445 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
446 | 439 | ||
447 | strlcpy(info->type, "ics932s401", I2C_NAME_SIZE); | 440 | strlcpy(info->type, "ics932s401", I2C_NAME_SIZE); |
448 | 441 | ||