Lines Matching +full:factory +full:- +full:programmed

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. */
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,
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()
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()
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()
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()
604 info.addr = 0x18 | (client->addr & 7); in at24_probe_temp_sensor()
606 i2c_new_client_device(client->adapter, &info); in at24_probe_temp_sensor()
615 struct device *dev = &client->dev; in at24_probe()
625 i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C); in at24_probe()
626 i2c_fn_block = i2c_check_functionality(client->adapter, in at24_probe()
637 * play safe. Specifying custom eeprom-types via device tree in at24_probe()
642 flags = cdata->flags; in at24_probe()
643 if (device_property_present(dev, "read-only")) in at24_probe()
645 if (device_property_present(dev, "no-read-rollover")) in at24_probe()
648 err = device_property_read_u32(dev, "address-width", &addrw); in at24_probe()
661 dev_warn(dev, "Bad \"address-width\" property: %u\n", in at24_probe()
668 byte_len = cdata->byte_len; in at24_probe()
675 return -EINVAL; in at24_probe()
681 err = device_property_read_u32(dev, "num-addresses", &num_addresses); in at24_probe()
692 "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); in at24_probe()
693 return -EINVAL; in at24_probe()
707 return -ENOMEM; in at24_probe()
709 mutex_init(&at24->lock); in at24_probe()
710 at24->byte_len = byte_len; in at24_probe()
711 at24->page_size = page_size; in at24_probe()
712 at24->flags = flags; in at24_probe()
713 at24->read_post = cdata->read_post; in at24_probe()
714 at24->bank_addr_shift = cdata->bank_addr_shift; in at24_probe()
715 at24->num_addresses = num_addresses; in at24_probe()
716 at24->offset_adj = at24_get_offset_adj(flags, byte_len); in at24_probe()
717 at24->client_regmaps[0] = regmap; in at24_probe()
719 at24->vcc_reg = devm_regulator_get(dev, "vcc"); in at24_probe()
720 if (IS_ERR(at24->vcc_reg)) in at24_probe()
721 return PTR_ERR(at24->vcc_reg); in at24_probe()
725 at24->write_max = min_t(unsigned int, in at24_probe()
727 if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX) in at24_probe()
728 at24->write_max = I2C_SMBUS_BLOCK_MAX; in at24_probe()
731 /* use dummy devices for multiple-address chips */ in at24_probe()
772 full_power = acpi_dev_state_d0(&client->dev); in at24_probe()
774 err = regulator_enable(at24->vcc_reg); in at24_probe()
785 * Perform a one-byte test read to verify that the chip is functional, in at24_probe()
794 regulator_disable(at24->vcc_reg); in at24_probe()
795 return -ENODEV; in at24_probe()
799 at24->nvmem = devm_nvmem_register(dev, &nvmem_config); in at24_probe()
800 if (IS_ERR(at24->nvmem)) { in at24_probe()
803 regulator_disable(at24->vcc_reg); in at24_probe()
804 return dev_err_probe(dev, PTR_ERR(at24->nvmem), in at24_probe()
816 byte_len, client->name, at24->write_max); in at24_probe()
818 dev_info(dev, "%u byte %s EEPROM, read-only\n", in at24_probe()
819 byte_len, client->name); in at24_probe()
828 pm_runtime_disable(&client->dev); in at24_remove()
829 if (acpi_dev_state_d0(&client->dev)) { in at24_remove()
830 if (!pm_runtime_status_suspended(&client->dev)) in at24_remove()
831 regulator_disable(at24->vcc_reg); in at24_remove()
832 pm_runtime_set_suspended(&client->dev); in at24_remove()
841 return regulator_disable(at24->vcc_reg); in at24_suspend()
849 return regulator_enable(at24->vcc_reg); in at24_resume()
875 return -EINVAL; in at24_init()