12 #include <linux/device.h>
13 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/slab.h>
23 #define OP_WRITE (OP_START | 0x1)
24 #define OP_READ (OP_START | 0x2)
25 #define ADDR_EWDS 0x00
26 #define ADDR_ERAL 0x20
27 #define ADDR_EWEN 0x30
38 eeprom_93xx46_bin_read(
struct file *filp,
struct kobject *kobj,
54 if ((off + count) > edev->
bin.size)
55 count = edev->
bin.size - off;
62 cmd_addr |= off & 0x7f;
65 cmd_addr |= off & 0x3f;
69 dev_dbg(&edev->
spi->dev,
"read cmd 0x%x, %d Hz\n",
70 cmd_addr, edev->
spi->max_speed_hz);
75 t[0].
tx_buf = (
char *)&cmd_addr;
78 spi_message_add_tail(&t[0], &m);
83 spi_message_add_tail(&t[1], &m);
87 if (edev->
pdata->prepare)
88 edev->
pdata->prepare(edev);
94 dev_err(&edev->
spi->dev,
"read %zu bytes at %d: err. %d\n",
95 count, (
int)off, ret);
98 if (edev->
pdata->finish)
99 edev->
pdata->finish(edev);
102 return ret ? :
count;
121 dev_dbg(&edev->
spi->dev,
"ew cmd 0x%04x\n", cmd_addr);
123 spi_message_init(&m);
129 spi_message_add_tail(&t, &m);
133 if (edev->
pdata->prepare)
134 edev->
pdata->prepare(edev);
140 dev_err(&edev->
spi->dev,
"erase/write %sable error %d\n",
141 is_on ?
"en" :
"dis", ret);
143 if (edev->
pdata->finish)
144 edev->
pdata->finish(edev);
152 const char *buf,
unsigned off)
162 cmd_addr |= off & 0x7f;
166 cmd_addr |= off & 0x3f;
171 dev_dbg(&edev->
spi->dev,
"write cmd 0x%x\n", cmd_addr);
173 spi_message_init(&m);
176 t[0].
tx_buf = (
char *)&cmd_addr;
179 spi_message_add_tail(&t[0], &m);
184 spi_message_add_tail(&t[1], &m);
193 eeprom_93xx46_bin_write(
struct file *filp,
struct kobject *kobj,
195 char *buf, loff_t off,
size_t count)
206 if ((off + count) > edev->
bin.size)
207 count = edev->
bin.size - off;
218 ret = eeprom_93xx46_ew(edev, 1);
224 if (edev->
pdata->prepare)
225 edev->
pdata->prepare(edev);
228 ret = eeprom_93xx46_write_word(edev, &buf[i], off + i);
230 dev_err(&edev->
spi->dev,
"write failed at %d: %d\n",
236 if (edev->
pdata->finish)
237 edev->
pdata->finish(edev);
242 eeprom_93xx46_ew(edev, 0);
243 return ret ? :
count;
263 spi_message_init(&m);
269 spi_message_add_tail(&t, &m);
273 if (edev->
pdata->prepare)
274 edev->
pdata->prepare(edev);
278 dev_err(&edev->
spi->dev,
"erase error %d\n", ret);
291 const char *buf,
size_t count)
296 sscanf(buf,
"%d", &erase);
298 ret = eeprom_93xx46_ew(edev, 1);
301 ret = eeprom_93xx46_eral(edev);
304 ret = eeprom_93xx46_ew(edev, 0);
318 pd = spi->
dev.platform_data;
320 dev_err(&spi->
dev,
"missing platform data\n");
333 dev_err(&spi->
dev,
"unspecified address type\n");
340 edev->
spi = spi_dev_get(spi);
344 edev->
bin.attr.name =
"eeprom";
346 edev->
bin.read = eeprom_93xx46_bin_read;
347 edev->
bin.size = 128;
349 edev->
bin.write = eeprom_93xx46_bin_write;
363 dev_err(&spi->
dev,
"can't create erase interface\n");
386 static struct spi_driver eeprom_93xx46_driver = {
391 .probe = eeprom_93xx46_probe,