1 // SPDX-License-Identifier: GPL-2.0+
9 struct sl28cpld_child_plat {
14 * The access methods works either with the first argument being a child
15 * device or with the MFD device itself.
17 static int sl28cpld_read_child(struct udevice *dev, uint offset)
19 struct sl28cpld_child_plat *plat = dev_get_parent_plat(dev);
20 struct udevice *mfd = dev_get_parent(dev);
22 return dm_i2c_reg_read(mfd, offset + plat->offset);
25 int sl28cpld_read(struct udevice *dev, uint offset)
27 if (dev->driver == DM_DRIVER_GET(sl28cpld))
28 return dm_i2c_reg_read(dev, offset);
30 return sl28cpld_read_child(dev, offset);
33 static int sl28cpld_write_child(struct udevice *dev, uint offset,
36 struct sl28cpld_child_plat *plat = dev_get_parent_plat(dev);
37 struct udevice *mfd = dev_get_parent(dev);
39 return dm_i2c_reg_write(mfd, offset + plat->offset, value);
42 int sl28cpld_write(struct udevice *dev, uint offset, uint8_t value)
44 if (dev->driver == DM_DRIVER_GET(sl28cpld))
45 return dm_i2c_reg_write(dev, offset, value);
47 return sl28cpld_write_child(dev, offset, value);
50 int sl28cpld_update(struct udevice *dev, uint offset, uint8_t clear,
55 val = sl28cpld_read(dev, offset);
62 return sl28cpld_write(dev, offset, val);
65 static int sl28cpld_probe(struct udevice *dev)
67 i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS |
68 DM_I2C_CHIP_WR_ADDRESS);
73 static int sl28cpld_child_post_bind(struct udevice *dev)
75 struct sl28cpld_child_plat *plat = dev_get_parent_plat(dev);
78 if (!dev_has_ofnode(dev))
81 offset = dev_read_u32_default(dev, "reg", -1);
85 plat->offset = offset;
90 static const struct udevice_id sl28cpld_ids[] = {
91 { .compatible = "kontron,sl28cpld" },
95 U_BOOT_DRIVER(sl28cpld) = {
98 .of_match = sl28cpld_ids,
99 .probe = sl28cpld_probe,
100 .bind = dm_scan_fdt_dev,
101 .flags = DM_FLAG_PRE_RELOC,
102 .per_child_plat_auto = sizeof(struct sl28cpld_child_plat),
103 .child_post_bind = sl28cpld_child_post_bind,