Lines Matching +full:dram +full:- +full:access +full:- +full:quirk

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>
31 /* sysfs-entry will be read-only. */
33 /* sysfs-entry will be world-readable. */
37 /* Factory-programmed serial number. */
39 /* Factory-programmed mac address. */
41 /* Does not auto-rollover reads to the next slave address. */
47 * MicroChip 24LC, etc) won't much matter for typical read/write access.
51 * However, misconfiguration can lose data. "Set 16-bit memory address"
52 * to a part with 8-bit addressing will overwrite data. Writing with too
57 * Accordingly, explicit board-specific configuration data should be used
58 * in almost all cases. (One partial exception is an SMBus used to access
59 * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.)
62 * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or
63 * similar kernel-resident tables; or, configuration data coming from
67 * that this one handles write access and isn't restricted to 24c02 devices.
68 * It also handles larger devices (32 kbit and up) with two-byte addresses,
153 * - BIOS passwords: bytes 0x00 to 0x0f in at24_read_post_vaio()
154 * - UUID: bytes 0x10 to 0x1f in at24_read_post_vaio()
155 * - Serial number: 0xc0 to 0xdf in at24_read_post_vaio()
164 /* needs 8 addresses as A0-A2 are ignored */
191 /* 24rf08 quirk is handled at i2c-core */
199 /* M24C32-D Additional Write lockable page (M24C32-D order codes) */
204 /* M24C64-D Additional Write lockable page (M24C64-D order codes) */
210 /* M24256E Additional Write lockable page (M24256E-F order codes) */
230 { "24c02-vaio", (kernel_ulong_t)&at24_data_24c02_vaio },
238 { "24c32d-wl", (kernel_ulong_t)&at24_data_24c32d_wlp },
241 { "24c64-wl", (kernel_ulong_t)&at24_data_24c64d_wlp },
245 { "24256e-wl", (kernel_ulong_t)&at24_data_24256e_wlp },
271 { .compatible = "atmel,24c32d-wl", .data = &at24_data_24c32d_wlp },
274 { .compatible = "atmel,24c64d-wl", .data = &at24_data_24c64d_wlp },
284 { .compatible = "st,24256e-wl", .data = &at24_data_24256e_wlp },
299 * Assumes that sanity checks for offset happened at sysfs-layer.
302 * set the byte address; on a multi-master board, another master
310 if (at24->flags & AT24_FLAG_ADDR16) { in at24_translate_offset()
318 return at24->client_regmaps[i]; in at24_translate_offset()
323 return regmap_get_device(at24->client_regmaps[0]); in at24_base_client_dev()
333 * In case of multi-address chips that don't rollover reads to in at24_adjust_read_count()
337 if (at24->flags & AT24_FLAG_NO_RDROL) { in at24_adjust_read_count()
338 bits = (at24->flags & AT24_FLAG_ADDR16) ? 16 : 8; in at24_adjust_read_count()
339 remainder = BIT(bits) - offset; in at24_adjust_read_count()
361 offset += at24->offset_adj; in at24_regmap_read()
372 dev_dbg(regmap_get_device(regmap), "read %zu@%d --> %d (%ld)\n", in at24_regmap_read()
380 return -ETIMEDOUT; in at24_regmap_read()
384 * Note that if the hardware write-protect pin is pulled high, the whole
398 if (count > at24->write_max) in at24_adjust_write_count()
399 count = at24->write_max; in at24_adjust_write_count()
402 next_page = roundup(offset + 1, at24->page_size); in at24_adjust_write_count()
404 count = next_page - offset; in at24_adjust_write_count()
428 dev_dbg(regmap_get_device(regmap), "write %zu@%d --> %d (%ld)\n", in at24_regmap_write()
436 return -ETIMEDOUT; in at24_regmap_write()
452 if (off + count > at24->byte_len) in at24_read()
453 return -EINVAL; in at24_read()
462 mutex_lock(&at24->lock); in at24_read()
464 for (i = 0; count; i += ret, count -= ret) { in at24_read()
467 mutex_unlock(&at24->lock); in at24_read()
473 mutex_unlock(&at24->lock); in at24_read()
477 if (unlikely(at24->read_post)) in at24_read()
478 at24->read_post(off, buf, i); in at24_read()
494 return -EINVAL; in at24_write()
496 if (off + count > at24->byte_len) in at24_write()
497 return -EINVAL; in at24_write()
506 mutex_lock(&at24->lock); in at24_write()
511 mutex_unlock(&at24->lock); in at24_write()
517 count -= ret; in at24_write()
520 mutex_unlock(&at24->lock); in at24_write()
534 dummy_client = devm_i2c_new_dummy_device(&base_client->dev, in at24_make_dummy_client()
535 base_client->adapter, in at24_make_dummy_client()
536 base_client->addr + in at24_make_dummy_client()
537 (index << at24->bank_addr_shift)); in at24_make_dummy_client()
545 at24->client_regmaps[index] = regmap; in at24_make_dummy_client()
553 /* EUI-48 starts from 0x9a, EUI-64 from 0x98 */ in at24_get_offset_adj()
554 return 0xa0 - byte_len; in at24_get_offset_adj()
593 info.addr = 0x18 | (client->addr & 7); in at24_probe_temp_sensor()
595 i2c_new_client_device(client->adapter, &info); in at24_probe_temp_sensor()
604 struct device *dev = &client->dev; in at24_probe()
614 i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C); in at24_probe()
615 i2c_fn_block = i2c_check_functionality(client->adapter, in at24_probe()
620 return -ENODEV; in at24_probe()
626 * play safe. Specifying custom eeprom-types via device tree in at24_probe()
631 flags = cdata->flags; in at24_probe()
632 if (device_property_present(dev, "read-only")) in at24_probe()
634 if (device_property_present(dev, "no-read-rollover")) in at24_probe()
637 err = device_property_read_u32(dev, "address-width", &addrw); in at24_probe()
650 dev_warn(dev, "Bad \"address-width\" property: %u\n", in at24_probe()
657 byte_len = cdata->byte_len; in at24_probe()
664 return -EINVAL; in at24_probe()
670 err = device_property_read_u32(dev, "num-addresses", &num_addresses); in at24_probe()
681 "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); in at24_probe()
682 return -EINVAL; in at24_probe()
696 return -ENOMEM; in at24_probe()
698 mutex_init(&at24->lock); in at24_probe()
699 at24->byte_len = byte_len; in at24_probe()
700 at24->page_size = page_size; in at24_probe()
701 at24->flags = flags; in at24_probe()
702 at24->read_post = cdata->read_post; in at24_probe()
703 at24->bank_addr_shift = cdata->bank_addr_shift; in at24_probe()
704 at24->num_addresses = num_addresses; in at24_probe()
705 at24->offset_adj = at24_get_offset_adj(flags, byte_len); in at24_probe()
706 at24->client_regmaps[0] = regmap; in at24_probe()
708 at24->vcc_reg = devm_regulator_get(dev, "vcc"); in at24_probe()
709 if (IS_ERR(at24->vcc_reg)) in at24_probe()
710 return PTR_ERR(at24->vcc_reg); in at24_probe()
714 at24->write_max = min_t(unsigned int, in at24_probe()
716 if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX) in at24_probe()
717 at24->write_max = I2C_SMBUS_BLOCK_MAX; in at24_probe()
720 /* use dummy devices for multiple-address chips */ in at24_probe()
761 full_power = acpi_dev_state_d0(&client->dev); in at24_probe()
763 err = regulator_enable(at24->vcc_reg); in at24_probe()
774 * Perform a one-byte test read to verify that the chip is functional, in at24_probe()
783 regulator_disable(at24->vcc_reg); in at24_probe()
784 return -ENODEV; in at24_probe()
788 at24->nvmem = devm_nvmem_register(dev, &nvmem_config); in at24_probe()
789 if (IS_ERR(at24->nvmem)) { in at24_probe()
792 regulator_disable(at24->vcc_reg); in at24_probe()
793 return dev_err_probe(dev, PTR_ERR(at24->nvmem), in at24_probe()
805 byte_len, client->name, at24->write_max); in at24_probe()
807 dev_info(dev, "%u byte %s EEPROM, read-only\n", in at24_probe()
808 byte_len, client->name); in at24_probe()
817 pm_runtime_disable(&client->dev); in at24_remove()
818 if (acpi_dev_state_d0(&client->dev)) { in at24_remove()
819 if (!pm_runtime_status_suspended(&client->dev)) in at24_remove()
820 regulator_disable(at24->vcc_reg); in at24_remove()
821 pm_runtime_set_suspended(&client->dev); in at24_remove()
830 return regulator_disable(at24->vcc_reg); in at24_suspend()
838 return regulator_enable(at24->vcc_reg); in at24_resume()
864 return -EINVAL; in at24_init()