12 #include <linux/kernel.h>
13 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/types.h>
20 #include "../w1_int.h"
21 #include "../w1_family.h"
23 #define W1_F2D_EEPROM_SIZE 128
24 #define W1_F2D_PAGE_COUNT 4
25 #define W1_F2D_PAGE_BITS 5
26 #define W1_F2D_PAGE_SIZE (1<<W1_F2D_PAGE_BITS)
27 #define W1_F2D_PAGE_MASK 0x1F
29 #define W1_F2D_SCRATCH_BITS 3
30 #define W1_F2D_SCRATCH_SIZE (1<<W1_F2D_SCRATCH_BITS)
31 #define W1_F2D_SCRATCH_MASK (W1_F2D_SCRATCH_SIZE-1)
33 #define W1_F2D_READ_EEPROM 0xF0
34 #define W1_F2D_WRITE_SCRATCH 0x0F
35 #define W1_F2D_READ_SCRATCH 0xAA
36 #define W1_F2D_COPY_SCRATCH 0x55
39 #define W1_F2D_TPROG_MS 11
41 #define W1_F2D_READ_RETRIES 10
42 #define W1_F2D_READ_MAXLEN 8
48 static inline size_t w1_f2d_fix_count(loff_t off,
size_t count,
size_t size)
53 if ((off + count) > size)
66 static int w1_f2d_readblock(
struct w1_slave *
sl,
int off,
int count,
char *
buf)
74 wrbuf[1] = off & 0xff;
89 if (!
memcmp(cmp, buf, count))
93 dev_err(&sl->dev,
"proof reading failed %d times\n",
101 char *buf, loff_t off,
size_t count)
103 struct w1_slave *sl = kobj_to_w1_slave(kobj);
121 if (w1_f2d_readblock(sl, off, block_read, buf) < 0)
147 static int w1_f2d_write(
struct w1_slave *sl,
int addr,
int len,
const u8 *
data)
161 wrbuf[1] = addr & 0xff;
162 wrbuf[2] = addr >> 8;
175 if ((rdbuf[0] != wrbuf[1]) || (rdbuf[1] != wrbuf[2]) ||
176 (rdbuf[2] != es) || (
memcmp(data, &rdbuf[3], len) != 0)) {
182 "could not write to eeprom, scratchpad compare failed %d times\n",
207 char *buf, loff_t off,
size_t count)
209 struct w1_slave *sl = kobj_to_w1_slave(kobj);
229 if (w1_f2d_readblock(sl, addr & ~W1_F2D_SCRATCH_MASK,
242 memcpy(&tmp[addr & W1_F2D_SCRATCH_MASK], buf, copy);
243 if (w1_f2d_write(sl, addr & ~W1_F2D_SCRATCH_MASK,
251 if (w1_f2d_write(sl, addr, copy, buf) < 0) {
273 .read = w1_f2d_read_bin,
274 .write = w1_f2d_write_bin,
277 static int w1_f2d_add_slave(
struct w1_slave *sl)
282 static void w1_f2d_remove_slave(
struct w1_slave *sl)
288 .add_slave = w1_f2d_add_slave,
289 .remove_slave = w1_f2d_remove_slave,
294 .fops = &w1_f2d_fops,
297 static int __init w1_f2d_init(
void)
302 static void __exit w1_f2d_fini(
void)