Lines Matching +full:no +full:- +full:read +full:- +full:rollover
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * at24.c - handle most I2C EEPROMs
5 * Copyright (C) 2005-2007 David Brownell
20 #include <linux/nvmem-provider.h>
30 /* sysfs-entry will be read-only. */
32 /* sysfs-entry will be world-readable. */
36 /* Factory-programmed serial number. */
38 /* Factory-programmed mac address. */
40 /* Does not auto-rollover reads to the next slave address. */
46 * MicroChip 24LC, etc) won't much matter for typical read/write access.
50 * However, misconfiguration can lose data. "Set 16-bit memory address"
51 * to a part with 8-bit addressing will overwrite data. Writing with too
56 * Accordingly, explicit board-specific configuration data should be used
61 * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or
62 * similar kernel-resident tables; or, configuration data coming from
67 * It also handles larger devices (32 kbit and up) with two-byte addresses,
101 * clock, one 256 byte read takes about 1/43 second which is excessive;
152 * - BIOS passwords: bytes 0x00 to 0x0f in at24_read_post_vaio()
153 * - UUID: bytes 0x10 to 0x1f in at24_read_post_vaio()
154 * - Serial number: 0xc0 to 0xdf in at24_read_post_vaio()
163 /* needs 8 addresses as A0-A2 are ignored */
186 /* 24rf08 quirk is handled at i2c-core */
217 { "24c02-vaio", (kernel_ulong_t)&at24_data_24c02_vaio },
278 * Assumes that sanity checks for offset happened at sysfs-layer.
281 * set the byte address; on a multi-master board, another master
289 if (at24->flags & AT24_FLAG_ADDR16) { in at24_translate_offset()
297 return at24->client_regmaps[i]; in at24_translate_offset()
302 return regmap_get_device(at24->client_regmaps[0]); in at24_base_client_dev()
312 * In case of multi-address chips that don't rollover reads to in at24_adjust_read_count()
314 * so that the read never straddles slaves. in at24_adjust_read_count()
316 if (at24->flags & AT24_FLAG_NO_RDROL) { in at24_adjust_read_count()
317 bits = (at24->flags & AT24_FLAG_ADDR16) ? 16 : 8; in at24_adjust_read_count()
318 remainder = BIT(bits) - offset; in at24_adjust_read_count()
339 /* adjust offset for mac and serial read ops */ in at24_regmap_read()
340 offset += at24->offset_adj; in at24_regmap_read()
351 dev_dbg(regmap_get_device(regmap), "read %zu@%d --> %d (%ld)\n", in at24_regmap_read()
359 return -ETIMEDOUT; in at24_regmap_read()
363 * Note that if the hardware write-protect pin is pulled high, the whole
377 if (count > at24->write_max) in at24_adjust_write_count()
378 count = at24->write_max; in at24_adjust_write_count()
381 next_page = roundup(offset + 1, at24->page_size); in at24_adjust_write_count()
383 count = next_page - offset; in at24_adjust_write_count()
407 dev_dbg(regmap_get_device(regmap), "write %zu@%d --> %d (%ld)\n", in at24_regmap_write()
415 return -ETIMEDOUT; in at24_regmap_write()
431 if (off + count > at24->byte_len) in at24_read()
432 return -EINVAL; in at24_read()
441 * Read data from chip, protecting against concurrent updates in at24_read()
444 mutex_lock(&at24->lock); in at24_read()
446 for (i = 0; count; i += ret, count -= ret) { in at24_read()
449 mutex_unlock(&at24->lock); in at24_read()
455 mutex_unlock(&at24->lock); in at24_read()
459 if (unlikely(at24->read_post)) in at24_read()
460 at24->read_post(off, buf, i); in at24_read()
476 return -EINVAL; in at24_write()
478 if (off + count > at24->byte_len) in at24_write()
479 return -EINVAL; in at24_write()
491 mutex_lock(&at24->lock); in at24_write()
496 mutex_unlock(&at24->lock); in at24_write()
502 count -= ret; in at24_write()
505 mutex_unlock(&at24->lock); in at24_write()
514 struct device_node *of_node = dev->of_node; in at24_get_chip_data()
528 cdata = (void *)id->driver_data; in at24_get_chip_data()
533 return ERR_PTR(-ENODEV); in at24_get_chip_data()
545 dummy_client = devm_i2c_new_dummy_device(&base_client->dev, in at24_make_dummy_client()
546 base_client->adapter, in at24_make_dummy_client()
547 base_client->addr + in at24_make_dummy_client()
548 (index << at24->bank_addr_shift)); in at24_make_dummy_client()
556 at24->client_regmaps[index] = regmap; in at24_make_dummy_client()
564 /* EUI-48 starts from 0x9a, EUI-64 from 0x98 */ in at24_get_offset_adj()
565 return 0xa0 - byte_len; in at24_get_offset_adj()
590 struct device *dev = &client->dev; in at24_probe()
600 i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C); in at24_probe()
601 i2c_fn_block = i2c_check_functionality(client->adapter, in at24_probe()
612 * play safe. Specifying custom eeprom-types via device tree in at24_probe()
617 flags = cdata->flags; in at24_probe()
618 if (device_property_present(dev, "read-only")) in at24_probe()
620 if (device_property_present(dev, "no-read-rollover")) in at24_probe()
623 err = device_property_read_u32(dev, "address-width", &addrw); in at24_probe()
636 dev_warn(dev, "Bad \"address-width\" property: %u\n", in at24_probe()
643 byte_len = cdata->byte_len; in at24_probe()
650 return -EINVAL; in at24_probe()
654 dev_warn(dev, "page_size looks suspicious (no power of 2)!\n"); in at24_probe()
656 err = device_property_read_u32(dev, "num-addresses", &num_addresses); in at24_probe()
667 "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); in at24_probe()
668 return -EINVAL; in at24_probe()
682 return -ENOMEM; in at24_probe()
684 mutex_init(&at24->lock); in at24_probe()
685 at24->byte_len = byte_len; in at24_probe()
686 at24->page_size = page_size; in at24_probe()
687 at24->flags = flags; in at24_probe()
688 at24->read_post = cdata->read_post; in at24_probe()
689 at24->bank_addr_shift = cdata->bank_addr_shift; in at24_probe()
690 at24->num_addresses = num_addresses; in at24_probe()
691 at24->offset_adj = at24_get_offset_adj(flags, byte_len); in at24_probe()
692 at24->client_regmaps[0] = regmap; in at24_probe()
694 at24->vcc_reg = devm_regulator_get(dev, "vcc"); in at24_probe()
695 if (IS_ERR(at24->vcc_reg)) in at24_probe()
696 return PTR_ERR(at24->vcc_reg); in at24_probe()
700 at24->write_max = min_t(unsigned int, in at24_probe()
702 if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX) in at24_probe()
703 at24->write_max = I2C_SMBUS_BLOCK_MAX; in at24_probe()
706 /* use dummy devices for multiple-address chips */ in at24_probe()
747 full_power = acpi_dev_state_d0(&client->dev); in at24_probe()
749 err = regulator_enable(at24->vcc_reg); in at24_probe()
759 at24->nvmem = devm_nvmem_register(dev, &nvmem_config); in at24_probe()
760 if (IS_ERR(at24->nvmem)) { in at24_probe()
763 regulator_disable(at24->vcc_reg); in at24_probe()
764 return PTR_ERR(at24->nvmem); in at24_probe()
768 * Perform a one-byte test read to verify that the chip is functional, in at24_probe()
777 regulator_disable(at24->vcc_reg); in at24_probe()
778 return -ENODEV; in at24_probe()
786 byte_len, client->name, at24->write_max); in at24_probe()
788 dev_info(dev, "%u byte %s EEPROM, read-only\n", in at24_probe()
789 byte_len, client->name); in at24_probe()
798 pm_runtime_disable(&client->dev); in at24_remove()
799 if (acpi_dev_state_d0(&client->dev)) { in at24_remove()
800 if (!pm_runtime_status_suspended(&client->dev)) in at24_remove()
801 regulator_disable(at24->vcc_reg); in at24_remove()
802 pm_runtime_set_suspended(&client->dev); in at24_remove()
811 return regulator_disable(at24->vcc_reg); in at24_suspend()
819 return regulator_enable(at24->vcc_reg); in at24_resume()
845 return -EINVAL; in at24_init()