aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-29 22:12:08 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-29 22:12:08 -0400
commitc0a6720977f89c50473366af965ae28cd8fce923 (patch)
treef7d0d9fcc56bb03fd87e7e1e83525c906c06bd08 /drivers/w1
parentf4cce69611ee941bac0729c6069795f106905ef9 (diff)
Revert "w1: Add 1-wire slave device driver for DS28E04-100"
This reverts commit f19420c1acb0b573c88a12deb2d42035e22d4a17. It contained lots of errors and warnings and shouldn't have ever been applied, that was my fault, sorry. Cc: Markus Franke <markus.franke@s2002.tu-chemnitz.de> Cc: Evgeniy Polyakov <zbr@ioremap.net>, Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r--drivers/w1/slaves/Kconfig7
-rw-r--r--drivers/w1/slaves/Makefile1
-rw-r--r--drivers/w1/slaves/w1_ds28e04.c464
-rw-r--r--drivers/w1/w1_family.h1
4 files changed, 0 insertions, 473 deletions
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index 605ee36c96f8..eb9e376d6244 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -94,13 +94,6 @@ config W1_SLAVE_DS2781
94 94
95 If you are unsure, say N. 95 If you are unsure, say N.
96 96
97config W1_SLAVE_DS28E04
98 tristate "4096-Bit Addressable 1-Wire EEPROM with PIO (DS28E04-100)"
99 depends on W1
100 help
101 Say Y here if you want to use a 1-wire
102 4kb EEPROM with PIO family device (DS28E04).
103
104config W1_SLAVE_BQ27000 97config W1_SLAVE_BQ27000
105 tristate "BQ27000 slave support" 98 tristate "BQ27000 slave support"
106 depends on W1 99 depends on W1
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
index 05188f6aab5a..c4f1859fb520 100644
--- a/drivers/w1/slaves/Makefile
+++ b/drivers/w1/slaves/Makefile
@@ -12,4 +12,3 @@ obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o
12obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o 12obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o
13obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o 13obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o
14obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o 14obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o
15obj-$(CONFIG_W1_SLAVE_DS28E04) += w1_ds28e04.o
diff --git a/drivers/w1/slaves/w1_ds28e04.c b/drivers/w1/slaves/w1_ds28e04.c
deleted file mode 100644
index 4aa1aa90480d..000000000000
--- a/drivers/w1/slaves/w1_ds28e04.c
+++ /dev/null
@@ -1,464 +0,0 @@
1/*
2 * w1_ds28e04.c - w1 family 1C (DS28E04) driver
3 *
4 * Copyright (c) 2012 Markus Franke <franke.m@sebakmt.com>
5 *
6 * This source code is licensed under the GNU General Public License,
7 * Version 2. See the file COPYING for more details.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/moduleparam.h>
13#include <linux/device.h>
14#include <linux/types.h>
15#include <linux/delay.h>
16#include <linux/slab.h>
17#include <linux/crc16.h>
18#include <linux/uaccess.h>
19
20#define CRC16_INIT 0
21#define CRC16_VALID 0xb001
22
23#include "../w1.h"
24#include "../w1_int.h"
25#include "../w1_family.h"
26
27MODULE_LICENSE("GPL");
28MODULE_AUTHOR("Markus Franke <franke.m@sebakmt.com>, <franm@hrz.tu-chemnitz.de>");
29MODULE_DESCRIPTION("w1 family 1C driver for DS28E04, 4kb EEPROM and PIO");
30
31/* Allow the strong pullup to be disabled, but default to enabled.
32 * If it was disabled a parasite powered device might not get the required
33 * current to copy the data from the scratchpad to EEPROM. If it is enabled parasite powered
34 * devices have a better chance of getting the current required.
35 */
36static int w1_strong_pullup = 1;
37module_param_named(strong_pullup, w1_strong_pullup, int, 0);
38
39/* enable/disable CRC checking on DS28E04-100 memory accesses */
40static char w1_enable_crccheck = 1;
41
42#define W1_EEPROM_SIZE 512
43#define W1_PAGE_COUNT 16
44#define W1_PAGE_SIZE 32
45#define W1_PAGE_BITS 5
46#define W1_PAGE_MASK 0x1F
47
48#define W1_F1C_READ_EEPROM 0xF0
49#define W1_F1C_WRITE_SCRATCH 0x0F
50#define W1_F1C_READ_SCRATCH 0xAA
51#define W1_F1C_COPY_SCRATCH 0x55
52#define W1_F1C_ACCESS_WRITE 0x5A
53
54#define W1_1C_REG_LOGIC_STATE 0x220
55
56struct w1_f1C_data {
57 u8 memory[W1_EEPROM_SIZE];
58 u32 validcrc;
59};
60
61/**
62 * Check the file size bounds and adjusts count as needed.
63 * This would not be needed if the file size didn't reset to 0 after a write.
64 */
65static inline size_t w1_f1C_fix_count(loff_t off, size_t count, size_t size)
66{
67 if (off > size)
68 return 0;
69
70 if ((off + count) > size)
71 return (size - off);
72
73 return count;
74}
75
76static int w1_f1C_refresh_block(struct w1_slave *sl, struct w1_f1C_data *data,
77 int block)
78{
79 u8 wrbuf[3];
80 int off = block * W1_PAGE_SIZE;
81
82 if (data->validcrc & (1 << block))
83 return 0;
84
85 if (w1_reset_select_slave(sl)) {
86 data->validcrc = 0;
87 return -EIO;
88 }
89
90 wrbuf[0] = W1_F1C_READ_EEPROM;
91 wrbuf[1] = off & 0xff;
92 wrbuf[2] = off >> 8;
93 w1_write_block(sl->master, wrbuf, 3);
94 w1_read_block(sl->master, &data->memory[off], W1_PAGE_SIZE);
95
96 /* cache the block if the CRC is valid */
97 if (crc16(CRC16_INIT, &data->memory[off], W1_PAGE_SIZE) == CRC16_VALID)
98 data->validcrc |= (1 << block);
99
100 return 0;
101}
102
103static int w1_f1C_read(struct w1_slave *sl, int addr, int len, char *data)
104{
105 u8 wrbuf[3];
106
107 /* read directly from the EEPROM */
108 if (w1_reset_select_slave(sl))
109 return -EIO;
110
111 wrbuf[0] = W1_F1C_READ_EEPROM;
112 wrbuf[1] = addr & 0xff;
113 wrbuf[2] = addr >> 8;
114
115 w1_write_block(sl->master, wrbuf, sizeof(wrbuf));
116 return w1_read_block(sl->master, data, len);
117}
118
119static ssize_t w1_f1C_read_bin(struct file *filp, struct kobject *kobj,
120 struct bin_attribute *bin_attr,
121 char *buf, loff_t off, size_t count)
122{
123 struct w1_slave *sl = kobj_to_w1_slave(kobj);
124 struct w1_f1C_data *data = sl->family_data;
125 int i, min_page, max_page;
126
127 if ((count = w1_f1C_fix_count(off, count, W1_EEPROM_SIZE)) == 0)
128 return 0;
129
130 mutex_lock(&sl->master->mutex);
131
132 if(w1_enable_crccheck) {
133 min_page = (off >> W1_PAGE_BITS);
134 max_page = (off + count - 1) >> W1_PAGE_BITS;
135 for (i = min_page; i <= max_page; i++) {
136 if (w1_f1C_refresh_block(sl, data, i)) {
137 count = -EIO;
138 goto out_up;
139 }
140 }
141 memcpy(buf, &data->memory[off], count);
142 }
143 else {
144 count = w1_f1C_read(sl, off, count, buf);
145 }
146
147out_up:
148 mutex_unlock(&sl->master->mutex);
149
150 return count;
151}
152
153/**
154 * Writes to the scratchpad and reads it back for verification.
155 * Then copies the scratchpad to EEPROM.
156 * The data must be on one page.
157 * The master must be locked.
158 *
159 * @param sl The slave structure
160 * @param addr Address for the write
161 * @param len length must be <= (W1_PAGE_SIZE - (addr & W1_PAGE_MASK))
162 * @param data The data to write
163 * @return 0=Success -1=failure
164 */
165static int w1_f1C_write(struct w1_slave *sl, int addr, int len, const u8 *data)
166{
167 u8 wrbuf[4];
168 u8 rdbuf[W1_PAGE_SIZE + 3];
169 u8 es = (addr + len - 1) & 0x1f;
170 unsigned int tm = 10;
171 int i;
172 struct w1_f1C_data *f1C = sl->family_data;
173
174 /* Write the data to the scratchpad */
175 if (w1_reset_select_slave(sl))
176 return -1;
177
178 wrbuf[0] = W1_F1C_WRITE_SCRATCH;
179 wrbuf[1] = addr & 0xff;
180 wrbuf[2] = addr >> 8;
181
182 w1_write_block(sl->master, wrbuf, 3);
183 w1_write_block(sl->master, data, len);
184
185 /* Read the scratchpad and verify */
186 if (w1_reset_select_slave(sl))
187 return -1;
188
189 w1_write_8(sl->master, W1_F1C_READ_SCRATCH);
190 w1_read_block(sl->master, rdbuf, len + 3);
191
192 /* Compare what was read against the data written */
193 if ((rdbuf[0] != wrbuf[1]) || (rdbuf[1] != wrbuf[2]) ||
194 (rdbuf[2] != es) || (memcmp(data, &rdbuf[3], len) != 0))
195 return -1;
196
197 /* Copy the scratchpad to EEPROM */
198 if (w1_reset_select_slave(sl))
199 return -1;
200
201 wrbuf[0] = W1_F1C_COPY_SCRATCH;
202 wrbuf[3] = es;
203
204 for(i = 0; i < sizeof(wrbuf); ++i) {
205 /* issue 10ms strong pullup (or delay) on the last byte for writing the data from the scratchpad to EEPROM */
206 if(w1_strong_pullup && i == sizeof(wrbuf)-1)
207 w1_next_pullup(sl->master, tm);
208
209 w1_write_8(sl->master, wrbuf[i]);
210 }
211
212 if(!w1_strong_pullup)
213 msleep(tm);
214
215 if(w1_enable_crccheck) {
216 /* invalidate cached data */
217 f1C->validcrc &= ~(1 << (addr >> W1_PAGE_BITS));
218 }
219
220 /* Reset the bus to wake up the EEPROM (this may not be needed) */
221 w1_reset_bus(sl->master);
222
223 return 0;
224}
225
226static ssize_t w1_f1C_write_bin(struct file *filp, struct kobject *kobj,
227 struct bin_attribute *bin_attr,
228 char *buf, loff_t off, size_t count)
229
230{
231 struct w1_slave *sl = kobj_to_w1_slave(kobj);
232 int addr, len, idx;
233
234 if ((count = w1_f1C_fix_count(off, count, W1_EEPROM_SIZE)) == 0)
235 return 0;
236
237 if(w1_enable_crccheck) {
238 /* can only write full blocks in cached mode */
239 if ((off & W1_PAGE_MASK) || (count & W1_PAGE_MASK)) {
240 dev_err(&sl->dev, "invalid offset/count off=%d cnt=%zd\n",
241 (int)off, count);
242 return -EINVAL;
243 }
244
245 /* make sure the block CRCs are valid */
246 for (idx = 0; idx < count; idx += W1_PAGE_SIZE) {
247 if (crc16(CRC16_INIT, &buf[idx], W1_PAGE_SIZE) != CRC16_VALID) {
248 dev_err(&sl->dev, "bad CRC at offset %d\n", (int)off);
249 return -EINVAL;
250 }
251 }
252 }
253
254 mutex_lock(&sl->master->mutex);
255
256 /* Can only write data to one page at a time */
257 idx = 0;
258 while (idx < count) {
259 addr = off + idx;
260 len = W1_PAGE_SIZE - (addr & W1_PAGE_MASK);
261 if (len > (count - idx))
262 len = count - idx;
263
264 if (w1_f1C_write(sl, addr, len, &buf[idx]) < 0) {
265 count = -EIO;
266 goto out_up;
267 }
268 idx += len;
269 }
270
271out_up:
272 mutex_unlock(&sl->master->mutex);
273
274 return count;
275}
276
277static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj,
278 struct bin_attribute *bin_attr,
279 char *buf, loff_t off, size_t count)
280
281{
282 struct w1_slave *sl = kobj_to_w1_slave(kobj);
283 int ret;
284
285 /* check arguments */
286 if(off != 0 || count != 1 || buf == NULL)
287 return -EINVAL;
288
289 mutex_lock(&sl->master->mutex);
290 ret = w1_f1C_read(sl, W1_1C_REG_LOGIC_STATE, count, buf);
291 mutex_unlock(&sl->master->mutex);
292
293 return ret;
294}
295
296static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj,
297 struct bin_attribute *bin_attr,
298 char *buf, loff_t off, size_t count)
299
300{
301 struct w1_slave *sl = kobj_to_w1_slave(kobj);
302 u8 wrbuf[3];
303 u8 ack;
304
305 /* check arguments */
306 if(off != 0 || count != 1 || buf == NULL)
307 return -EINVAL;
308
309 mutex_lock(&sl->master->mutex);
310
311 /* Write the PIO data */
312 if (w1_reset_select_slave(sl)) {
313 mutex_unlock(&sl->master->mutex);
314 return -1;
315 }
316
317 /* set bit 7..2 to value '1' */
318 *buf = *buf | 0xFC;
319
320 wrbuf[0] = W1_F1C_ACCESS_WRITE;
321 wrbuf[1] = *buf;
322 wrbuf[2] = ~(*buf);
323 w1_write_block(sl->master, wrbuf, 3);
324
325 w1_read_block(sl->master, &ack, sizeof(ack));
326
327 mutex_unlock(&sl->master->mutex);
328
329 /* check for acknowledgement */
330 if(ack != 0xAA) return -EIO;
331
332 return count;
333}
334
335static ssize_t w1_f1C_show_crccheck(struct device *dev, struct device_attribute *attr,
336 char *buf)
337{
338 if(put_user(w1_enable_crccheck + 0x30, buf))
339 return -EFAULT;
340
341 return sizeof(w1_enable_crccheck);
342}
343
344static ssize_t w1_f1C_store_crccheck(struct device *dev, struct device_attribute *attr,
345 const char *buf, size_t count)
346{
347 char val;
348
349 if(count != 1 || !buf) return -EINVAL;
350
351 if(get_user(val, buf))
352 return -EFAULT;
353
354 /* convert to decimal */
355 val = val - 0x30;
356 if(val != 0 && val != 1) return -EINVAL;
357
358 /* set the new value */
359 w1_enable_crccheck = val;
360
361 return sizeof(w1_enable_crccheck);
362}
363
364#define NB_SYSFS_BIN_FILES 2
365static struct bin_attribute w1_f1C_bin_attr[NB_SYSFS_BIN_FILES] = {
366 {
367 .attr = {
368 .name = "eeprom",
369 .mode = S_IRUGO | S_IWUSR,
370 },
371 .size = W1_EEPROM_SIZE,
372 .read = w1_f1C_read_bin,
373 .write = w1_f1C_write_bin,
374 },
375 {
376 .attr = {
377 .name = "pio",
378 .mode = S_IRUGO | S_IWUSR,
379 },
380 .size = 1,
381 .read = w1_f1C_read_pio,
382 .write = w1_f1C_write_pio,
383 }
384};
385
386static DEVICE_ATTR(crccheck, S_IWUSR | S_IRUGO, w1_f1C_show_crccheck, w1_f1C_store_crccheck);
387
388static int w1_f1C_add_slave(struct w1_slave *sl)
389{
390 int err = 0;
391 int i;
392 struct w1_f1C_data *data = NULL;
393
394 if(w1_enable_crccheck) {
395 data = kzalloc(sizeof(struct w1_f1C_data), GFP_KERNEL);
396 if (!data)
397 return -ENOMEM;
398 sl->family_data = data;
399 }
400
401 /* create binary sysfs attributes */
402 for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i)
403 err = sysfs_create_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
404
405 if(err)
406 goto out;
407
408 /* create device attributes */
409 err = device_create_file(&sl->dev, &dev_attr_crccheck);
410
411 if(err) {
412 /* remove binary sysfs attributes */
413 for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
414 sysfs_remove_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
415 }
416
417out:
418 if(err) {
419 if(w1_enable_crccheck)
420 kfree(data);
421 }
422
423 return err;
424}
425
426static void w1_f1C_remove_slave(struct w1_slave *sl)
427{
428 int i;
429
430 if(w1_enable_crccheck) {
431 kfree(sl->family_data);
432 sl->family_data = NULL;
433 }
434
435 /* remove device attributes */
436 device_remove_file(&sl->dev, &dev_attr_crccheck);
437
438 /* remove binary sysfs attributes */
439 for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
440 sysfs_remove_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
441}
442
443static struct w1_family_ops w1_f1C_fops = {
444 .add_slave = w1_f1C_add_slave,
445 .remove_slave = w1_f1C_remove_slave,
446};
447
448static struct w1_family w1_family_1C = {
449 .fid = W1_FAMILY_DS28E04,
450 .fops = &w1_f1C_fops,
451};
452
453static int __init w1_f1C_init(void)
454{
455 return w1_register_family(&w1_family_1C);
456}
457
458static void __exit w1_f1C_fini(void)
459{
460 w1_unregister_family(&w1_family_1C);
461}
462
463module_init(w1_f1C_init);
464module_exit(w1_f1C_fini);
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h
index b00ada44a89b..874aeb05011b 100644
--- a/drivers/w1/w1_family.h
+++ b/drivers/w1/w1_family.h
@@ -30,7 +30,6 @@
30#define W1_FAMILY_SMEM_01 0x01 30#define W1_FAMILY_SMEM_01 0x01
31#define W1_FAMILY_SMEM_81 0x81 31#define W1_FAMILY_SMEM_81 0x81
32#define W1_THERM_DS18S20 0x10 32#define W1_THERM_DS18S20 0x10
33#define W1_FAMILY_DS28E04 0x1C
34#define W1_COUNTER_DS2423 0x1D 33#define W1_COUNTER_DS2423 0x1D
35#define W1_THERM_DS1822 0x22 34#define W1_THERM_DS1822 0x22
36#define W1_EEPROM_DS2433 0x23 35#define W1_EEPROM_DS2433 0x23