Lines Matching refs:edev

68 static inline bool has_quirk_single_word_read(struct eeprom_93xx46_dev *edev)  in has_quirk_single_word_read()  argument
70 return edev->pdata->quirks & EEPROM_93XX46_QUIRK_SINGLE_WORD_READ; in has_quirk_single_word_read()
73 static inline bool has_quirk_instruction_length(struct eeprom_93xx46_dev *edev) in has_quirk_instruction_length() argument
75 return edev->pdata->quirks & EEPROM_93XX46_QUIRK_INSTRUCTION_LENGTH; in has_quirk_instruction_length()
78 static inline bool has_quirk_extra_read_cycle(struct eeprom_93xx46_dev *edev) in has_quirk_extra_read_cycle() argument
80 return edev->pdata->quirks & EEPROM_93XX46_QUIRK_EXTRA_READ_CYCLE; in has_quirk_extra_read_cycle()
86 struct eeprom_93xx46_dev *edev = priv; in eeprom_93xx46_read() local
91 if (unlikely(off >= edev->size)) in eeprom_93xx46_read()
93 if ((off + count) > edev->size) in eeprom_93xx46_read()
94 count = edev->size - off; in eeprom_93xx46_read()
98 mutex_lock(&edev->lock); in eeprom_93xx46_read()
100 if (edev->pdata->prepare) in eeprom_93xx46_read()
101 edev->pdata->prepare(edev); in eeprom_93xx46_read()
104 bits = edev->addrlen + 3; in eeprom_93xx46_read()
109 u16 cmd_addr = OP_READ << edev->addrlen; in eeprom_93xx46_read()
112 if (edev->pdata->flags & EE_ADDR8) { in eeprom_93xx46_read()
114 if (has_quirk_single_word_read(edev)) in eeprom_93xx46_read()
118 if (has_quirk_single_word_read(edev)) in eeprom_93xx46_read()
122 dev_dbg(&edev->spi->dev, "read cmd 0x%x, %d Hz\n", in eeprom_93xx46_read()
123 cmd_addr, edev->spi->max_speed_hz); in eeprom_93xx46_read()
125 if (has_quirk_extra_read_cycle(edev)) { in eeprom_93xx46_read()
142 err = spi_sync(edev->spi, &m); in eeprom_93xx46_read()
147 dev_err(&edev->spi->dev, "read %zu bytes at %d: err. %d\n", in eeprom_93xx46_read()
157 if (edev->pdata->finish) in eeprom_93xx46_read()
158 edev->pdata->finish(edev); in eeprom_93xx46_read()
160 mutex_unlock(&edev->lock); in eeprom_93xx46_read()
165 static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on) in eeprom_93xx46_ew() argument
173 bits = edev->addrlen + 3; in eeprom_93xx46_ew()
175 cmd_addr = OP_START << edev->addrlen; in eeprom_93xx46_ew()
176 if (edev->pdata->flags & EE_ADDR8) in eeprom_93xx46_ew()
181 if (has_quirk_instruction_length(edev)) { in eeprom_93xx46_ew()
186 dev_dbg(&edev->spi->dev, "ew%s cmd 0x%04x, %d bits\n", in eeprom_93xx46_ew()
197 mutex_lock(&edev->lock); in eeprom_93xx46_ew()
199 if (edev->pdata->prepare) in eeprom_93xx46_ew()
200 edev->pdata->prepare(edev); in eeprom_93xx46_ew()
202 ret = spi_sync(edev->spi, &m); in eeprom_93xx46_ew()
206 dev_err(&edev->spi->dev, "erase/write %sable error %d\n", in eeprom_93xx46_ew()
209 if (edev->pdata->finish) in eeprom_93xx46_ew()
210 edev->pdata->finish(edev); in eeprom_93xx46_ew()
212 mutex_unlock(&edev->lock); in eeprom_93xx46_ew()
217 eeprom_93xx46_write_word(struct eeprom_93xx46_dev *edev, in eeprom_93xx46_write_word() argument
225 if (unlikely(off >= edev->size)) in eeprom_93xx46_write_word()
229 bits = edev->addrlen + 3; in eeprom_93xx46_write_word()
231 cmd_addr = OP_WRITE << edev->addrlen; in eeprom_93xx46_write_word()
233 if (edev->pdata->flags & EE_ADDR8) { in eeprom_93xx46_write_word()
241 dev_dbg(&edev->spi->dev, "write cmd 0x%x\n", cmd_addr); in eeprom_93xx46_write_word()
256 ret = spi_sync(edev->spi, &m); in eeprom_93xx46_write_word()
265 struct eeprom_93xx46_dev *edev = priv; in eeprom_93xx46_write() local
269 if (unlikely(off >= edev->size)) in eeprom_93xx46_write()
271 if ((off + count) > edev->size) in eeprom_93xx46_write()
272 count = edev->size - off; in eeprom_93xx46_write()
277 if (edev->pdata->flags & EE_ADDR16) { in eeprom_93xx46_write()
283 ret = eeprom_93xx46_ew(edev, 1); in eeprom_93xx46_write()
287 mutex_lock(&edev->lock); in eeprom_93xx46_write()
289 if (edev->pdata->prepare) in eeprom_93xx46_write()
290 edev->pdata->prepare(edev); in eeprom_93xx46_write()
293 ret = eeprom_93xx46_write_word(edev, &buf[i], off + i); in eeprom_93xx46_write()
295 dev_err(&edev->spi->dev, "write failed at %d: %d\n", in eeprom_93xx46_write()
301 if (edev->pdata->finish) in eeprom_93xx46_write()
302 edev->pdata->finish(edev); in eeprom_93xx46_write()
304 mutex_unlock(&edev->lock); in eeprom_93xx46_write()
307 eeprom_93xx46_ew(edev, 0); in eeprom_93xx46_write()
311 static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev) in eeprom_93xx46_eral() argument
313 struct eeprom_93xx46_platform_data *pd = edev->pdata; in eeprom_93xx46_eral()
320 bits = edev->addrlen + 3; in eeprom_93xx46_eral()
322 cmd_addr = OP_START << edev->addrlen; in eeprom_93xx46_eral()
323 if (edev->pdata->flags & EE_ADDR8) in eeprom_93xx46_eral()
328 if (has_quirk_instruction_length(edev)) { in eeprom_93xx46_eral()
333 dev_dbg(&edev->spi->dev, "eral cmd 0x%04x, %d bits\n", cmd_addr, bits); in eeprom_93xx46_eral()
343 mutex_lock(&edev->lock); in eeprom_93xx46_eral()
345 if (edev->pdata->prepare) in eeprom_93xx46_eral()
346 edev->pdata->prepare(edev); in eeprom_93xx46_eral()
348 ret = spi_sync(edev->spi, &m); in eeprom_93xx46_eral()
350 dev_err(&edev->spi->dev, "erase error %d\n", ret); in eeprom_93xx46_eral()
355 pd->finish(edev); in eeprom_93xx46_eral()
357 mutex_unlock(&edev->lock); in eeprom_93xx46_eral()
365 struct eeprom_93xx46_dev *edev = dev_get_drvdata(dev); in eeprom_93xx46_store_erase() local
370 ret = eeprom_93xx46_ew(edev, 1); in eeprom_93xx46_store_erase()
373 ret = eeprom_93xx46_eral(edev); in eeprom_93xx46_store_erase()
376 ret = eeprom_93xx46_ew(edev, 0); in eeprom_93xx46_store_erase()
386 struct eeprom_93xx46_dev *edev = context; in select_assert() local
388 gpiod_set_value_cansleep(edev->pdata->select, 1); in select_assert()
393 struct eeprom_93xx46_dev *edev = context; in select_deassert() local
395 gpiod_set_value_cansleep(edev->pdata->select, 0); in select_deassert()
481 struct eeprom_93xx46_dev *edev; in eeprom_93xx46_probe() local
496 edev = devm_kzalloc(&spi->dev, sizeof(*edev), GFP_KERNEL); in eeprom_93xx46_probe()
497 if (!edev) in eeprom_93xx46_probe()
501 edev->size = 128; in eeprom_93xx46_probe()
503 edev->size = 256; in eeprom_93xx46_probe()
505 edev->size = 512; in eeprom_93xx46_probe()
512 edev->addrlen = ilog2(edev->size); in eeprom_93xx46_probe()
514 edev->addrlen = ilog2(edev->size) - 1; in eeprom_93xx46_probe()
520 mutex_init(&edev->lock); in eeprom_93xx46_probe()
522 edev->spi = spi; in eeprom_93xx46_probe()
523 edev->pdata = pd; in eeprom_93xx46_probe()
525 edev->nvmem_config.type = NVMEM_TYPE_EEPROM; in eeprom_93xx46_probe()
526 edev->nvmem_config.name = dev_name(&spi->dev); in eeprom_93xx46_probe()
527 edev->nvmem_config.dev = &spi->dev; in eeprom_93xx46_probe()
528 edev->nvmem_config.read_only = pd->flags & EE_READONLY; in eeprom_93xx46_probe()
529 edev->nvmem_config.root_only = true; in eeprom_93xx46_probe()
530 edev->nvmem_config.owner = THIS_MODULE; in eeprom_93xx46_probe()
531 edev->nvmem_config.compat = true; in eeprom_93xx46_probe()
532 edev->nvmem_config.base_dev = &spi->dev; in eeprom_93xx46_probe()
533 edev->nvmem_config.reg_read = eeprom_93xx46_read; in eeprom_93xx46_probe()
534 edev->nvmem_config.reg_write = eeprom_93xx46_write; in eeprom_93xx46_probe()
535 edev->nvmem_config.priv = edev; in eeprom_93xx46_probe()
536 edev->nvmem_config.stride = 4; in eeprom_93xx46_probe()
537 edev->nvmem_config.word_size = 1; in eeprom_93xx46_probe()
538 edev->nvmem_config.size = edev->size; in eeprom_93xx46_probe()
540 edev->nvmem = devm_nvmem_register(&spi->dev, &edev->nvmem_config); in eeprom_93xx46_probe()
541 if (IS_ERR(edev->nvmem)) in eeprom_93xx46_probe()
542 return PTR_ERR(edev->nvmem); in eeprom_93xx46_probe()
546 edev->size, in eeprom_93xx46_probe()
554 spi_set_drvdata(spi, edev); in eeprom_93xx46_probe()
560 struct eeprom_93xx46_dev *edev = spi_get_drvdata(spi); in eeprom_93xx46_remove() local
562 if (!(edev->pdata->flags & EE_READONLY)) in eeprom_93xx46_remove()