[v9,2/4] mfd: ac200: Add X-Powers AC200 support
Commit Message
The X-Powers AC200 is a mixed-signal companion IC with a paged register
map accessed over I2C.
Enable and rate-lock the shared input clock, wait 40 ms before the first
register access, initialize the paged regmap and deassert the common
reset. Set only the deassert bit instead of forcing a reset cycle, so
state established by firmware or independently powered functions remains
intact. Leave the common reset deasserted during driver removal and system
shutdown; function drivers own their block resets.
The Ethernet PHY is enumerated on its MDIO bus rather than as an MFD
child. It follows the x-powers,ac200 phandle and uses this regmap for
ancillary package-control access. The audio codec and TV encoder are
added as MFD children by subsequent patches.
Cache only the common page selector. Individual functions can reset
independently and invalidate their other registers, so leave all
functional registers volatile.
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
MAINTAINERS | 1 +
drivers/mfd/Kconfig | 12 ++++++
drivers/mfd/Makefile | 1 +
drivers/mfd/ac200.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 127 insertions(+)
Comments
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Regmap exposed to userspace and consumers before hardware initialization delay completes.
--
commit 35526ae046a1822af569d5228aa956640657303c
Author: James Hilliard <james.hilliard1@gmail.com>
mfd: ac200: Add X-Powers AC200 support
This commit adds MFD core driver support for the X-Powers AC200 mixed-signal
companion IC. It configures the shared regmap over I2C, handles clock
enabling, and manages the common reset state for the device.
> diff --git a/drivers/mfd/ac200.c b/drivers/mfd/ac200.c
> new file mode 100644
> index 0000000000000..94aa13deb0f8c
> --- /dev/null
> +++ b/drivers/mfd/ac200.c
[ ... ]
> +static int ac200_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + struct regmap *regmap;
> + struct clk *clk;
> + int ret;
> +
> + clk = devm_clk_get_enabled(dev, NULL);
> + if (IS_ERR(clk))
> + return dev_err_probe(dev, PTR_ERR(clk),
> + "failed to enable input clock\n");
> +
> + ret = devm_clk_rate_exclusive_get(dev, clk);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to lock clock rate\n");
> +
> + regmap = devm_regmap_init_i2c(client, &ac200_regmap_config);
> + if (IS_ERR(regmap))
> + return dev_err_probe(dev, PTR_ERR(regmap),
> + "failed to initialize regmap\n");
> +
> + /*
> + * No minimum delay is documented. Match the vendor driver's 40 ms delay
> + * before its first AC200 register access after enabling the input clock.
> + */
> + msleep(40);
[Severity: Medium]
Could exposing the regmap before the 40 ms initialization delay completes lead
to I2C bus lockups or device malfunctions?
The devm_regmap_init_i2c() call exposes the regmap to userspace via debugfs
and to other consumers, such as an asynchronously probing Ethernet PHY. During
this 40 ms window, these concurrent access paths might attempt to access the
hardware before the stabilization delay is met.
Would it be safer to move the msleep(40) above the regmap initialization to
prevent this race condition?
> +
> + ret = regmap_set_bits(regmap, AC200_SYS_CONTROL_REG,
> + AC200_SYS_CONTROL_CHIP_RESET_DEASSERT);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
@@ -29510,6 +29510,7 @@ M: James Hilliard <james.hilliard1@gmail.com>
L: linux-sunxi@lists.linux.dev
S: Maintained
F: Documentation/devicetree/bindings/mfd/x-powers,ac200.yaml
+F: drivers/mfd/ac200.c
X-POWERS AXP288 PMIC DRIVERS
M: Hans de Goede <hansg@kernel.org>
@@ -205,6 +205,18 @@ config MFD_AC100
This driver include only the core APIs. You have to select individual
components like codecs or RTC under the corresponding menus.
+config MFD_AC200
+ tristate "X-Powers AC200"
+ depends on COMMON_CLK
+ depends on I2C
+ depends on OF
+ select REGMAP_I2C
+ help
+ Support for the X-Powers AC200 mixed-signal companion IC. The AC200
+ contains audio, video, RTC and Fast Ethernet PHY functions and is
+ co-packaged with some Allwinner H6 and H616 SoCs. This driver provides
+ the shared register access used by the individual function drivers.
+
config MFD_AXP20X
tristate
select MFD_CORE
@@ -150,6 +150,7 @@ obj-$(CONFIG_MFD_DA9052_SPI) += da9052-spi.o
obj-$(CONFIG_MFD_DA9052_I2C) += da9052-i2c.o
obj-$(CONFIG_MFD_AC100) += ac100.o
+obj-$(CONFIG_MFD_AC200) += ac200.o
obj-$(CONFIG_MFD_AXP20X) += axp20x.o
obj-$(CONFIG_MFD_AXP20X_I2C) += axp20x-i2c.o
obj-$(CONFIG_MFD_AXP20X_RSB) += axp20x-rsb.o
new file mode 100644
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MFD core driver for the X-Powers AC200
+ *
+ * Copyright (C) 2019 Jernej Skrabec <jernej.skrabec@gmail.com>
+ * Copyright (C) 2026 James Hilliard <james.hilliard1@gmail.com>
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#define AC200_SYS_CONTROL_REG 0x0002
+#define AC200_SYS_CONTROL_CHIP_RESET_DEASSERT BIT(0)
+
+/* Interface register accessible from every register page. */
+#define AC200_TWI_REG_ADDR_H 0x00fe
+#define AC200_MAX_REG 0xa1f2
+
+static const struct regmap_range_cfg ac200_range_cfg[] = {
+ {
+ .range_max = AC200_MAX_REG,
+ .selector_reg = AC200_TWI_REG_ADDR_H,
+ .selector_mask = 0xff,
+ .window_len = 256,
+ },
+};
+
+/*
+ * Each AC200 sub-block can reset independently, invalidating its register
+ * contents without regmap's knowledge. Cache only the common page selector;
+ * this avoids a selector read-modify-write for every access on the same page
+ * without ever returning stale functional-register values.
+ */
+static bool ac200_volatile_reg(struct device *dev, unsigned int reg)
+{
+ return reg != AC200_TWI_REG_ADDR_H;
+}
+
+static const struct regmap_config ac200_regmap_config = {
+ .name = "ac200",
+ .reg_bits = 8,
+ .reg_stride = 2,
+ .val_bits = 16,
+ .ranges = ac200_range_cfg,
+ .num_ranges = ARRAY_SIZE(ac200_range_cfg),
+ .max_register = AC200_MAX_REG,
+ .volatile_reg = ac200_volatile_reg,
+ .cache_type = REGCACHE_MAPLE,
+};
+
+static int ac200_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct regmap *regmap;
+ struct clk *clk;
+ int ret;
+
+ clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(clk))
+ return dev_err_probe(dev, PTR_ERR(clk),
+ "failed to enable input clock\n");
+
+ ret = devm_clk_rate_exclusive_get(dev, clk);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to lock clock rate\n");
+
+ regmap = devm_regmap_init_i2c(client, &ac200_regmap_config);
+ if (IS_ERR(regmap))
+ return dev_err_probe(dev, PTR_ERR(regmap),
+ "failed to initialize regmap\n");
+
+ /*
+ * No minimum delay is documented. Match the vendor driver's 40 ms delay
+ * before its first AC200 register access after enabling the input clock.
+ */
+ msleep(40);
+
+ ret = regmap_set_bits(regmap, AC200_SYS_CONTROL_REG,
+ AC200_SYS_CONTROL_CHIP_RESET_DEASSERT);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static const struct of_device_id ac200_of_match[] = {
+ { .compatible = "x-powers,ac200" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ac200_of_match);
+
+static const struct i2c_device_id ac200_i2c_ids[] = {
+ { .name = "ac200" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, ac200_i2c_ids);
+
+static struct i2c_driver ac200_driver = {
+ .driver = {
+ .name = "ac200",
+ .of_match_table = ac200_of_match,
+ },
+ .probe = ac200_probe,
+ .id_table = ac200_i2c_ids,
+};
+module_i2c_driver(ac200_driver);
+
+MODULE_AUTHOR("James Hilliard <james.hilliard1@gmail.com>");
+MODULE_DESCRIPTION("X-Powers AC200 MFD core driver");
+MODULE_LICENSE("GPL");