1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright (c) 2015 Free Electrons
5 * Copyright (c) 2015 NextThing Co.
6 * Copyright (c) 2018 Microchip Technology, Inc.
8 * Maxime Ripard <maxime.ripard@free-electrons.com>
9 * Eugen Hristev <eugen.hristev@microchip.com>
16 #include <w1-eeprom.h>
18 #include <dm/device-internal.h>
20 int w1_eeprom_read_buf(struct udevice *dev, unsigned int offset,
21 u8 *buf, unsigned int count)
23 const struct w1_eeprom_ops *ops = device_get_ops(dev);
30 ret = w1_eeprom_get_id(dev, &id);
36 return ops->read_buf(dev, offset, buf, count);
39 int w1_eeprom_register_new_device(u64 id)
41 u8 family = id & 0xff;
45 for (ret = uclass_first_device(UCLASS_W1_EEPROM, &dev);
47 uclass_next_device(&dev)) {
49 debug("cannot find w1 eeprom dev\n");
52 if (dev_get_driver_data(dev) == family) {
55 w1 = dev_get_parent_platdata(dev);
56 if (w1->id) /* device already in use */
59 debug("%s: Match found: %s:%s %llx\n", __func__,
60 dev->name, dev->driver->name, id);
65 debug("%s: No matches found: error %d\n", __func__, ret);
70 int w1_eeprom_get_id(struct udevice *dev, u64 *id)
72 struct w1_device *w1 = dev_get_parent_platdata(dev);
81 UCLASS_DRIVER(w1_eeprom) = {
83 .id = UCLASS_W1_EEPROM,
84 .flags = DM_UC_FLAG_SEQ_ALIAS,
85 #if CONFIG_IS_ENABLED(OF_CONTROL)
86 .post_bind = dm_scan_fdt_dev,
90 int w1_eeprom_dm_init(void)
96 ret = uclass_get(UCLASS_W1_EEPROM, &uc);
98 debug("W1_EEPROM uclass not available\n");
102 uclass_foreach_dev(dev, uc) {
103 ret = device_probe(dev);
104 if (ret == -ENODEV) { /* No such device. */
105 debug("W1_EEPROM not available.\n");
109 if (ret) { /* Other error. */
110 printf("W1_EEPROM probe failed, error %d\n", ret);