From patchwork Tue Sep 22 16:34:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3423 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mxe881.netcup.net (Postfix) with ESMTPS id B29461C6C3F for ; Tue, 22 Sep 2026 18:37:03 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.232.135.74) smtp.mailfrom=linux-sunxi+bounces-26150-noreply=patchwork.local@lists.linux.dev smtp.helo=sto.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.232.135.74 as permitted sender) client-ip=172.232.135.74; envelope-from=linux-sunxi+bounces-26150-noreply=patchwork.local@lists.linux.dev; helo=sto.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sto.lore.kernel.org (Postfix) with ESMTP id 0CB9860493D for ; Tue, 22 Sep 2026 16:34:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBD0B568FC9; Tue, 22 Sep 2026 16:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tj4f/1+Q" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-oi2-f12.google.com (mail-oi2-f12.google.com [74.125.231.204]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F76A5678F8 for ; Tue, 22 Sep 2026 16:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790094890; cv=none; b=AGmHqbd/uNDpMfHbMHnYi6xVYwcFqLjduHcbHFwYpp/tY/APowBGO0dk8ct4+psa1Cy0J6AimzvFpxFeSTdMd8TPl1EhxTC2sOqb8HW9bpDLXXb1xRmzfqxrTCH2sVjfVevjZIsPWHXNQL5FRPGcb754Ill9B6HRKTqKR+BD6WQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790094890; c=relaxed/simple; bh=sQ3EwTgn0EUt9L8CXBhCZb8lf3xC0w0ejiBjOSV8Pco=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RhLgStal5qLvQgMALlqtP7jpSa77dvAm4lsD+1SKevJvKe26BSXoMuQPWP8oPCJr5kDBkjt2CdPCWQrvX88A3wXe4uhjwWqgpV2/ikrD+1Von2/YVa13sHTxhWrF0jIj6PaKFoxMsuRxghm6GsTH31Z9ncTgD7eaRMGuRhWLEIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tj4f/1+Q; arc=none smtp.client-ip=74.125.231.204 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi2-f12.google.com with SMTP id 46e09a7af769-7f4f0cfb33cso129509a34.0 for ; Tue, 22 Sep 2026 09:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790094886; x=1790699686; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=660IpMR0mIr/dOv4xwWcEolN+/t1yP+V7wW0zQGaZaQ=; b=Tj4f/1+QIXBvob7aJ9fSt6QOJCZQpgn4n+1mhKzhzbvMMqH8BV6b6W6WfG/i+5b336 /iY5WeWrZWjRJj7lTblLcMjA5St1QCkDT8TkiU0scn9U+MAO/Ij+qoHbVSyazD1mFVNc VOh2FiinHghOtDClj1ltz1Di7zwIv+GGbI/w/w25wy3pcLE+ZcqUKUZouKdgLXKKIyWH 3rzLQfKJTztXaeXZVAMNMUb1eKtC76KX4z7KjyNoBvc5x56SHKCdDliy9jKcGLwcj3gk O5BHHoMVaZCXDg+pU/Uc4wTxdt9FqiC7Po1prrmE05N7p+lGUuOQ2lcdiIr58Y3N3VWt +1+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790094886; x=1790699686; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=660IpMR0mIr/dOv4xwWcEolN+/t1yP+V7wW0zQGaZaQ=; b=LQTRIL7T5jSzGNor0RV369xvmyckUJ8ne3AsesJTMsy67pEoVLYqnEcpMPbW9Fne5R 6uL+mk6pS9ldd9Yrwk2n9pUiooljrqWEUwDk1D+UdUD+NZSu5WMzmDrfVaMa5q4uR39N s5pb7WRPUWsfqcSLMiO6WD7KExNlvfmsnUb19Rh59Jz4enM6CMyjo54tD8xbWvt47nKx My0W/rVkIqVJ7THW+FPzUMNl3Ah4M0aFltXYkCCLC6uvAocoGjfCY7zn35skQ8yeXH2/ HYaDheWwi9vu940fZqMWAKzJDW2e5QTvWu9ImPjZ8LSQbq/H39EgwpHFEi0Y0T8wX6yM 2KAQ== X-Forwarded-Encrypted: i=1; AKwUvBySLCVjxYfy4Grx2FhOMi9D252AZyB35ijLlVU2P4EXBiJYvpQH8CsTBhwKlNd1STxSpoA0qMYID90y/g==@lists.linux.dev X-Gm-Message-State: AFuF++ma8ifX+HTLde5N0MZwXEzoWnsfSX/j8RX2BjW2RwbXkOF4GCQw zOnXz3Z6gpKv2LP7muVy5tkSxa43dv0NNvpsBWon1I4mZ9MHi6GCZWvO X-Gm-Gg: AYBFou1YgsDxgJXfF6EYvhVWQw4Bxbd0NfAQbe33rGfRn20MWfUjIC8TMejzJYPYyN1 BbuuJUWFSy56/dS5oGF0Y8i6MkjQwAZjwY0U+cXLLtgDXCKJ49pZc/RDPQ7CPY+SnLuuFo6Fip/ tFT2vO1mgkznPZiIa7Jp36gRc/5R2Iqdshsd1jzT4H54KacdqWcU9+wL8c9t4j9puIglqPNZMow DabQLkT5Tsict+2v23Ej4ya58nFJjYD0YnLkrQuz5KjSKQwAI7s17kczsCrvhf2yMz7LQR/ucdY sp4B+rRKCsThPsAQ7DdTorBpnovUIN03kS6nik8o/dNQU6zBBpzvrwf3iAuBJwSFMEPKqMyibyG 5iRZtGda1rrkYwT5BgYf6e8yYG54QycgMxlmH0PmVHOsYwZC/oC4RXGRdU6N+o0D9qAuiODMz1Z i12dn0NiZfEL+zbtYGE6qZvXICRBcTztOvivhAjdi6X4/mktgq7f78K7DiN6pOR0yk0Eyosn5DO sQ6zf6QUF8f5BSZrliwiVU+UHjP2IHrrNh1QukmbKyqMz4rsb4vxFRi+OZ1Qbij5DCJiBy/AeV1 k9UgOrqfORhAw2d+pAAQRsm2jtkoFLBw9PJ2xjV8TRkoAw4jpkUmUr+yEa/ZD/NalKAqhMN8rPc qbHsvY0pM3+spJJv0sPUO/Q8= X-Received: by 2002:a05:6830:44ab:b0:7f8:4ebe:2854 with SMTP id 46e09a7af769-815ef49c682mr197798a34.4.1790094886387; Tue, 22 Sep 2026 09:34:46 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-814e0a13a73sm2679320a34.0.2026.09.22.09.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 09:34:45 -0700 (PDT) From: James Hilliard Date: Tue, 22 Sep 2026 10:34:35 -0600 Subject: [PATCH v13 2/2] mfd: ac200: Add X-Powers AC200 support Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20260922-submit-ac200-mfd-v13-2-8832afd2481c@gmail.com> References: <20260922-submit-ac200-mfd-v13-0-8832afd2481c@gmail.com> In-Reply-To: <20260922-submit-ac200-mfd-v13-0-8832afd2481c@gmail.com> To: Jernej Skrabec , James Hilliard , Lee Jones , Arnd Bergmann , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Andrew Lunn , "Jagielski, Jedrzej" , Andre Przywara , Chen-Yu Tsai , linux-sunxi@lists.linux.dev, mfd@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.15.2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= 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, retain the vendor resume path's 40 ms wait before creating the regmap and accessing registers, and deassert the common reset. No minimum delay is documented. Set only the deassert bit instead of forcing a reset cycle, avoiding a chip-wide reset of unrelated function registers. Leave the common reset deasserted during driver removal and system shutdown; function drivers own their block resets. Supplier unbind still tears down linked consumers and releases the provider's clock references. Cache only the common page selector. Individual functions can reset independently and invalidate their other registers, so leave all functional registers volatile. Register the audio codec and TV encoder using static MFD cells and automatically assigned platform device IDs. Their firmware properties belong to the parent node. Map their supply lookups to the parent with MFD supply aliases, without assigning separate OF nodes to the cells. When INTB is connected, pass its physical IRQ to the TV encoder cell. Select a cell array without IRQ resources when INTB is absent. No regmap IRQ controller or private IRQ domain is needed. Configure the level-triggered INTB output, defaulting to level-low when the upstream IRQ has no trigger type. Mask all sources before enabling INTB. Function drivers request shared threaded IRQs before enabling their own source, check and clear their own status, and mask their source before freeing the IRQ. Disable INTB after removing the children on failure or removal, while the regmap and clock are still available. 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. Co-developed-by: Jernej Skrabec Signed-off-by: Jernej Skrabec Signed-off-by: James Hilliard --- MAINTAINERS | 1 + drivers/mfd/Kconfig | 14 ++++ drivers/mfd/Makefile | 1 + drivers/mfd/ac200.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 238 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 419340093c9b..1d03b0060bda 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -29510,6 +29510,7 @@ M: James Hilliard 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 diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 857ca3bb0d5b..071cba7c775b 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -205,6 +205,20 @@ 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 MFD_CORE + 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 and instantiates the individual function + devices. + config MFD_AXP20X tristate select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 72d3944b0ad8..f8101d2a9ce9 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -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 diff --git a/drivers/mfd/ac200.c b/drivers/mfd/ac200.c new file mode 100644 index 000000000000..3c6543a1688c --- /dev/null +++ b/drivers/mfd/ac200.c @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * X-Powers AC200 Core driver + * + * Copyright (C) 2019 Jernej Skrabec + * Copyright (C) 2026 James Hilliard + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define AC200_SYS_CONTROL_REG 0x0002 +#define AC200_SYS_CONTROL_CHIP_RESET_DEASSERT BIT(0) +#define AC200_SYS_IRQ_ENABLE_REG 0x0004 +#define AC200_SYS_IRQ_INTB_ENABLE BIT(15) +#define AC200_SYS_IRQ_INTB_ACTIVE_HIGH BIT(14) +#define AC200_SYS_IRQ_RTC BIT(12) +#define AC200_SYS_IRQ_EPHY BIT(8) +#define AC200_SYS_IRQ_TVE BIT(4) + +/* 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 const char * const ac200_codec_supplies[] = { + "ac-ldoin", +}; + +static const char * const ac200_tve_supplies[] = { + "tv-vcc", +}; + +static const struct resource ac200_tve_resources[] = { + DEFINE_RES_IRQ_NAMED(0, "intb"), +}; + +#define AC200_CELL(_name, _supplies, _resources) \ + { \ + .name = (_name), \ + .parent_supplies = (_supplies), \ + .num_parent_supplies = ARRAY_SIZE(_supplies), \ + .resources = (_resources), \ + .num_resources = MFD_RES_SIZE(_resources), \ + } + +static const struct mfd_cell ac200_cells[] = { + AC200_CELL("ac200-codec", ac200_codec_supplies, NULL), + AC200_CELL("ac200-tve", ac200_tve_supplies, ac200_tve_resources), +}; + +static const struct mfd_cell ac200_noirq_cells[] = { + AC200_CELL("ac200-codec", ac200_codec_supplies, NULL), + AC200_CELL("ac200-tve", ac200_tve_supplies, NULL), +}; + +static void ac200_disable_intb(void *data) +{ + struct regmap *regmap = data; + int ret; + + ret = regmap_clear_bits(regmap, AC200_SYS_IRQ_ENABLE_REG, AC200_SYS_IRQ_INTB_ENABLE); + if (ret) + dev_err(regmap_get_device(regmap), "failed to disable INTB: %d\n", ret); +} + +static int ac200_init_irq(struct device *dev, struct regmap *regmap, int irq) +{ + unsigned int trigger; + u16 value = 0; + int ret; + + trigger = irq_get_trigger_type(irq); + switch (trigger) { + case IRQ_TYPE_LEVEL_HIGH: + value |= AC200_SYS_IRQ_INTB_ACTIVE_HIGH; + break; + case IRQ_TYPE_NONE: + case IRQ_TYPE_LEVEL_LOW: + break; + default: + return dev_err_probe(dev, -EINVAL, + "INTB is level triggered, not type %u\n", trigger); + } + + /* Mask every source before enabling the shared output. */ + ret = regmap_update_bits(regmap, AC200_SYS_IRQ_ENABLE_REG, + AC200_SYS_IRQ_INTB_ENABLE | AC200_SYS_IRQ_INTB_ACTIVE_HIGH | + AC200_SYS_IRQ_RTC | AC200_SYS_IRQ_EPHY | AC200_SYS_IRQ_TVE, value); + if (ret) + return ret; + + /* Children are removed before INTB is disabled and the regmap released. */ + ret = devm_add_action_or_reset(dev, ac200_disable_intb, regmap); + if (ret) + return ret; + + if (trigger == IRQ_TYPE_NONE) { + ret = irq_set_irq_type(irq, IRQ_TYPE_LEVEL_LOW); + if (ret) + return dev_err_probe(dev, ret, "failed to set INTB trigger\n"); + } + + /* + * Function drivers request INTB with IRQF_SHARED | IRQF_ONESHOT before + * enabling their own source. They check and clear their own status and + * mask their source before freeing the IRQ. No IRQ domain is needed. + */ + return regmap_set_bits(regmap, AC200_SYS_IRQ_ENABLE_REG, AC200_SYS_IRQ_INTB_ENABLE); +} + +static int ac200_probe(struct i2c_client *client) +{ + const struct mfd_cell *cells = ac200_noirq_cells; + unsigned int num_cells = ARRAY_SIZE(ac200_noirq_cells); + 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"); + + /* + * No minimum delay is documented. Retain the vendor resume path's 40 ms + * wait after enabling the input clock and before register access. + */ + msleep(40); + + 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"); + + ret = regmap_set_bits(regmap, AC200_SYS_CONTROL_REG, AC200_SYS_CONTROL_CHIP_RESET_DEASSERT); + if (ret) + return ret; + + if (client->irq > 0) { + ret = ac200_init_irq(dev, regmap, client->irq); + if (ret) + return ret; + cells = ac200_cells; + num_cells = ARRAY_SIZE(ac200_cells); + } + + /* Function drivers read their firmware properties from the parent. */ + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, cells, num_cells, + NULL, client->irq, NULL); + if (ret) + return dev_err_probe(dev, ret, "failed to add function devices\n"); + + 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("Jernej Skrabec "); +MODULE_AUTHOR("James Hilliard "); +MODULE_DESCRIPTION("X-Powers AC200 Core driver"); +MODULE_LICENSE("GPL");