]> git.baikalelectronics.ru Git - uboot.git/commitdiff
misc: add sl28cpld base driver
authorMichael Walle <michael@walle.cc>
Fri, 25 Feb 2022 12:36:24 +0000 (18:06 +0530)
committerPriyanka Jain <priyanka.jain@nxp.com>
Mon, 28 Feb 2022 06:29:35 +0000 (11:59 +0530)
Add a multi-function device driver which will probe its children and
provides methods to access the device.

Signed-off-by: Michael Walle <michael@walle.cc>
[Rebased]
Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>
MAINTAINERS
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/sl28cpld.c [new file with mode: 0644]
include/sl28cpld.h [new file with mode: 0644]

index fb171e0c687bdb66ada15f7e5a302f99fe613e3c..8b3870ff96483d0b4ddcfa873687e0c851dd3b24 100644 (file)
@@ -1161,6 +1161,11 @@ S:       Maintained
 T:     git https://source.denx.de/u-boot/custodians/u-boot-sh.git
 F:     arch/sh/
 
+SL28CLPD
+M:     Michael Walle <michael@walle.cc>
+S:     Maintained
+F:     drivers/misc/sl28cpld.c
+
 SPI
 M:     Jagan Teki <jagan@amarulasolutions.com>
 S:     Maintained
index 0ade3e32b0ef3724e30f2ea7ff4e0bd951f7a3cf..7029bb7b5c58efecb1589ffceec4bb8d1d5c3678 100644 (file)
@@ -512,4 +512,12 @@ config ESM_PMIC
 config FSL_IFC
        bool
 
+config SL28CPLD
+       bool "Enable Kontron sl28cpld multi-function driver"
+       depends on DM_I2C
+       help
+         Support for the Kontron sl28cpld management controller. This is
+         the base driver which provides common access methods for the
+         sub-drivers.
+
 endmenu
index bca7b24e99ad6e22f3776906116f85a7375344eb..f22eff601a1eb1c68f17a5b7eaac300440d0f76d 100644 (file)
@@ -82,3 +82,4 @@ obj-$(CONFIG_MICROCHIP_FLEXCOM) += microchip_flexcom.o
 obj-$(CONFIG_K3_AVS0) += k3_avs.o
 obj-$(CONFIG_ESM_K3) += k3_esm.o
 obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
+obj-$(CONFIG_SL28CPLD) += sl28cpld.o
diff --git a/drivers/misc/sl28cpld.c b/drivers/misc/sl28cpld.c
new file mode 100644 (file)
index 0000000..01ef1c6
--- /dev/null
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Michael Walle <michael@walle.cc>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+
+struct sl28cpld_child_plat {
+       uint offset;
+};
+
+/*
+ * The access methods works either with the first argument being a child
+ * device or with the MFD device itself.
+ */
+static int sl28cpld_read_child(struct udevice *dev, uint offset)
+{
+       struct sl28cpld_child_plat *plat = dev_get_parent_plat(dev);
+       struct udevice *mfd = dev_get_parent(dev);
+
+       return dm_i2c_reg_read(mfd, offset + plat->offset);
+}
+
+int sl28cpld_read(struct udevice *dev, uint offset)
+{
+       if (dev->driver == DM_DRIVER_GET(sl28cpld))
+               return dm_i2c_reg_read(dev, offset);
+       else
+               return sl28cpld_read_child(dev, offset);
+}
+
+static int sl28cpld_write_child(struct udevice *dev, uint offset,
+                               uint8_t value)
+{
+       struct sl28cpld_child_plat *plat = dev_get_parent_plat(dev);
+       struct udevice *mfd = dev_get_parent(dev);
+
+       return dm_i2c_reg_write(mfd, offset + plat->offset, value);
+}
+
+int sl28cpld_write(struct udevice *dev, uint offset, uint8_t value)
+{
+       if (dev->driver == DM_DRIVER_GET(sl28cpld))
+               return dm_i2c_reg_write(dev, offset, value);
+       else
+               return sl28cpld_write_child(dev, offset, value);
+}
+
+int sl28cpld_update(struct udevice *dev, uint offset, uint8_t clear,
+                   uint8_t set)
+{
+       int val;
+
+       val = sl28cpld_read(dev, offset);
+       if (val < 0)
+               return val;
+
+       val &= ~clear;
+       val |= set;
+
+       return sl28cpld_write(dev, offset, val);
+}
+
+static int sl28cpld_probe(struct udevice *dev)
+{
+       i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS |
+                          DM_I2C_CHIP_WR_ADDRESS);
+
+       return 0;
+}
+
+static int sl28cpld_child_post_bind(struct udevice *dev)
+{
+       struct sl28cpld_child_plat *plat = dev_get_parent_plat(dev);
+       int offset;
+
+       if (!dev_has_ofnode(dev))
+               return 0;
+
+       offset = dev_read_u32_default(dev, "reg", -1);
+       if (offset == -1)
+               return -EINVAL;
+
+       plat->offset = offset;
+
+       return 0;
+}
+
+static const struct udevice_id sl28cpld_ids[] = {
+       { .compatible = "kontron,sl28cpld" },
+       {}
+};
+
+U_BOOT_DRIVER(sl28cpld) = {
+       .name           = "sl28cpld",
+       .id             = UCLASS_NOP,
+       .of_match       = sl28cpld_ids,
+       .probe          = sl28cpld_probe,
+       .bind           = dm_scan_fdt_dev,
+       .flags          = DM_FLAG_PRE_RELOC,
+       .per_child_plat_auto = sizeof(struct sl28cpld_child_plat),
+       .child_post_bind = sl28cpld_child_post_bind,
+};
diff --git a/include/sl28cpld.h b/include/sl28cpld.h
new file mode 100644 (file)
index 0000000..d116607
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2021 Michael Walle <michael@walle.cc>
+ */
+
+#ifndef __SL28CPLD_H
+#define __SL28CPLD_H
+
+int sl28cpld_read(struct udevice *dev, uint offset);
+int sl28cpld_write(struct udevice *dev, uint offset, uint8_t value);
+int sl28cpld_update(struct udevice *dev, uint offset, uint8_t clear,
+                   uint8_t set);
+
+#endif