10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/types.h>
16 #include <linux/slab.h>
17 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
21 #define CRC16_VALID 0xb001
26 #include "../w1_int.h"
27 #include "../w1_family.h"
33 #define W1_EEPROM_SIZE 512
34 #define W1_PAGE_COUNT 16
35 #define W1_PAGE_SIZE 32
36 #define W1_PAGE_BITS 5
37 #define W1_PAGE_MASK 0x1F
39 #define W1_F23_TIME 300
41 #define W1_F23_READ_EEPROM 0xF0
42 #define W1_F23_WRITE_SCRATCH 0x0F
43 #define W1_F23_READ_SCRATCH 0xAA
44 #define W1_F23_COPY_SCRATCH 0x55
55 static inline size_t w1_f23_fix_count(loff_t off,
size_t count,
size_t size)
60 if ((off + count) > size)
66 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
82 wrbuf[1] = off & 0xff;
99 struct w1_slave *sl = kobj_to_w1_slave(kobj);
100 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
102 int i, min_page, max_page;
112 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
116 for (i = min_page; i <= max_page; i++) {
117 if (w1_f23_refresh_block(sl, data, i)) {
133 wrbuf[1] = off & 0xff;
158 static int w1_f23_write(
struct w1_slave *sl,
int addr,
int len,
const u8 *data)
160 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
164 u8 rdbuf[W1_PAGE_SIZE + 3];
165 u8 es = (addr + len - 1) & 0x1f;
172 wrbuf[1] = addr & 0xff;
173 wrbuf[2] = addr >> 8;
186 if ((rdbuf[0] != wrbuf[1]) || (rdbuf[1] != wrbuf[2]) ||
187 (rdbuf[2] != es) || (
memcmp(data, &rdbuf[3], len) != 0))
203 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
211 char *buf, loff_t off,
size_t count)
213 struct w1_slave *sl = kobj_to_w1_slave(kobj);
219 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
222 dev_err(&sl->dev,
"invalid offset/count off=%d cnt=%zd\n",
230 dev_err(&sl->dev,
"bad CRC at offset %d\n", (
int)off);
240 while (idx < count) {
243 if (len > (count - idx))
246 if (w1_f23_write(sl, addr, len, &buf[idx]) < 0) {
265 .read = w1_f23_read_bin,
266 .write = w1_f23_write_bin,
269 static int w1_f23_add_slave(
struct w1_slave *sl)
272 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
278 sl->family_data =
data;
284 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
292 static void w1_f23_remove_slave(
struct w1_slave *sl)
294 #ifdef CONFIG_W1_SLAVE_DS2433_CRC
295 kfree(sl->family_data);
296 sl->family_data =
NULL;
302 .add_slave = w1_f23_add_slave,
303 .remove_slave = w1_f23_remove_slave,
308 .fops = &w1_f23_fops,
311 static int __init w1_f23_init(
void)
316 static void __exit w1_f23_fini(
void)