From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D33B606A6A9 for ; Tue, 1 Dec 2026 19:44:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=XVBUXy0E DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=ZEiu+2uesxZ1HRmQFyQsNWANMfCttYl2TNo7Qqvk1jE=; b=XVBUXy0EbYmeGY flH8XclkEyb+olvZX5A/qIzcz7rRg3Z2+VuqmIYxc39BTv06m4V+L/d1Wtph/rOoEET2ATn7SdrMr sEAJKfHom0dAXvwCpJKLAzqxHCUyl0sqbwTsGtBzBocc7Aa/9LtOXPdENwfs0hBmC1IYDP0Vb+rvS srpD1Sz/Bq7YJxudPmgSthGYwhAqsai+BaS05H+OxvDNMJh2dVWmBxHOl5pjSFRuOL0IxokQFNbiH 21pjTL6IS7pZJfk/+uUpdn0gMrjBpxqlqE96+pJsvdU/1snxY3i7CROXq1CizSRJobbGjcS5F3PoP dq3FnZNcLpSrX99to+dQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYTmU-00000009Fu3-3a6Y; Tue, 01 Dec 2026 19:44:50 +0000 Received: from nbd.name ([46.4.11.11]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYTmS-00000009FrV-1UkF for linux-mediatek@lists.infradead.org; Tue, 01 Dec 2026 19:44:49 +0000 Received: from [2a04:4540:1405:15fc:bd72:1c73:6cc3:2cda] (helo=bertha10..) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xYTmO-00AtKQ-0s; Tue, 01 Dec 2026 20:44:44 +0100 From: John Crispin To: Lorenzo Bianconi , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Christian Marangi , devicetree@vger.kernel.org, lei.dong@airoha.com, Linqi.zhang@airoha.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pwm@vger.kernel.org, mfd@lists.linux.dev, Rajeev.kumar@airoha.com, upstream@airoha.com, Weifeng.xu@airoha.com, zhengping.zhang@airoha.com Subject: [PATCH 3/3] pwm: airoha: add support for AN7589 Date: Tue, 1 Dec 2026 20:44:34 +0100 Message-Id: <20261201194434.3132187-4-john@phrozen.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201194434.3132187-1-john@phrozen.org> References: <20261201194434.3132187-1-john@phrozen.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_114448_546499_405ED1A2 X-CRM114-Status: GOOD ( 22.85 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The AN7589 flash map has a 4 bit set-id per channel instead of 3, and the channel enable moves out of the map word into a separate register at 0xe0, one bit per channel. Describe both layouts in match data. A SoC with an enable register uses it in place of the enable bit of the map word. That register holds 32 channels, so the channel count moves into the match data as well: 32 for the AN7589, 33 for the EN7581 as before. The AN7589 PWM controller has no device tree node of its own. The GPIO system controller MFD driver registers it as a cell. Match the cell by name and use the device tree node of the parent, which is the PWM provider. Signed-off-by: John Crispin --- drivers/pwm/pwm-airoha.c | 116 +++++++++++++++++++++++++++++++++++---- 1 file changed, 104 insertions(+), 12 deletions(-) diff --git a/drivers/pwm/pwm-airoha.c b/drivers/pwm/pwm-airoha.c index 0cf6b011520a..14f8948dc6ea 100644 --- a/drivers/pwm/pwm-airoha.c +++ b/drivers/pwm/pwm-airoha.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ #define AIROHA_PWM_REG_GPIO_FLASH_MAP_SHIFT(_n) (4 * (_n)) #define AIROHA_PWM_GPIO_FLASH_EN BIT(3) #define AIROHA_PWM_GPIO_FLASH_SET_ID GENMASK(2, 0) +#define AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE GENMASK(3, 0) /* Register map is equal to GPIO flash map */ #define AIROHA_PWM_REG_SIPO_FLASH_MAP(_n) (0x0054 + (4 * (_n))) @@ -61,6 +63,8 @@ #define AIROHA_PWM_REG_CYCLE_CFG_SHIFT(_n) (8 * (_n)) #define AIROHA_PWM_WAVE_GEN_CYCLE GENMASK(7, 0) +#define AIROHA_PWM_REG_GPIO_FLASH_EN 0x00e0 + /* GPIO/SIPO flash map handles 8 pins in one register */ #define AIROHA_PWM_PINS_PER_FLASH_MAP 8 /* Cycle(Period) registers handles 4 generators in one 32-bit register */ @@ -78,6 +82,14 @@ #define AIROHA_PWM_NUM_GPIO 16 #define AIROHA_PWM_NUM_SIPO 17 #define AIROHA_PWM_MAX_CHANNELS (AIROHA_PWM_NUM_GPIO + AIROHA_PWM_NUM_SIPO) +#define AN7589_PWM_NUM_CHANNELS BITS_PER_TYPE(u32) + +struct airoha_pwm_soc_data { + unsigned int npwm; + u32 flash_set_id_mask; + u32 flash_en_mask; + u32 flash_en_reg; +}; struct airoha_pwm_bucket { /* Concurrent access protected by PWM core */ @@ -88,6 +100,7 @@ struct airoha_pwm_bucket { struct airoha_pwm { struct regmap *regmap; + const struct airoha_pwm_soc_data *soc; DECLARE_BITMAP(initialized, AIROHA_PWM_MAX_CHANNELS); @@ -417,9 +430,52 @@ static int airoha_pwm_sipo_init(struct airoha_pwm *pc) AIROHA_PWM_SERIAL_GPIO_FLASH_MODE); } +static void airoha_pwm_flash_en_reg_get(struct airoha_pwm *pc, + unsigned int hwpwm, u32 shift, + u32 *addr, u32 *mask) +{ + const struct airoha_pwm_soc_data *soc = pc->soc; + + if (!soc->flash_en_reg) { + *mask = soc->flash_en_mask << shift; + return; + } + + *addr = soc->flash_en_reg; + *mask = BIT(hwpwm); +} + +static int airoha_pwm_flash_enable(struct airoha_pwm *pc, unsigned int hwpwm, + u32 addr, u32 shift, bool enable) +{ + u32 mask; + + airoha_pwm_flash_en_reg_get(pc, hwpwm, shift, &addr, &mask); + + return regmap_update_bits(pc->regmap, addr, mask, enable ? mask : 0); +} + +static int airoha_pwm_flash_enabled(struct airoha_pwm *pc, unsigned int hwpwm, + u32 addr, u32 shift, bool *enabled) +{ + u32 mask, val; + int ret; + + airoha_pwm_flash_en_reg_get(pc, hwpwm, shift, &addr, &mask); + + ret = regmap_read(pc->regmap, addr, &val); + if (ret) + return ret; + + *enabled = !!(val & mask); + + return 0; +} + static int airoha_pwm_config_flash_map(struct airoha_pwm *pc, unsigned int hwpwm, int index) { + u32 set_id_mask = pc->soc->flash_set_id_mask; unsigned int addr; u32 shift; int ret; @@ -432,17 +488,15 @@ static int airoha_pwm_config_flash_map(struct airoha_pwm *pc, * If we need to disable the PWM, we just put low the * GPIO. No need to setup buckets. */ - return regmap_clear_bits(pc->regmap, addr, - AIROHA_PWM_GPIO_FLASH_EN << shift); + return airoha_pwm_flash_enable(pc, hwpwm, addr, shift, false); } - ret = regmap_update_bits(pc->regmap, addr, - AIROHA_PWM_GPIO_FLASH_SET_ID << shift, - FIELD_PREP(AIROHA_PWM_GPIO_FLASH_SET_ID, index) << shift); + ret = regmap_update_bits(pc->regmap, addr, set_id_mask << shift, + field_prep(set_id_mask, index) << shift); if (ret) return ret; - return regmap_set_bits(pc->regmap, addr, AIROHA_PWM_GPIO_FLASH_EN << shift); + return airoha_pwm_flash_enable(pc, hwpwm, addr, shift, true); } static int airoha_pwm_config(struct airoha_pwm *pc, struct pwm_device *pwm, @@ -552,17 +606,20 @@ static int airoha_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, airoha_pwm_get_flash_map_addr_and_shift(hwpwm, &addr, &shift); - ret = regmap_read(pc->regmap, addr, &val); + ret = airoha_pwm_flash_enabled(pc, hwpwm, addr, shift, &state->enabled); if (ret) return ret; - state->enabled = FIELD_GET(AIROHA_PWM_GPIO_FLASH_EN, val >> shift); if (!state->enabled) return 0; + ret = regmap_read(pc->regmap, addr, &val); + if (ret) + return ret; + state->polarity = PWM_POLARITY_NORMAL; - bucket = FIELD_GET(AIROHA_PWM_GPIO_FLASH_SET_ID, val >> shift); + bucket = field_get(pc->soc->flash_set_id_mask, val >> shift); return airoha_pwm_get_bucket(pc, bucket, &state->period, &state->duty_cycle); } @@ -574,17 +631,30 @@ static const struct pwm_ops airoha_pwm_ops = { static int airoha_pwm_probe(struct platform_device *pdev) { + const struct airoha_pwm_soc_data *soc; + const struct platform_device_id *id; struct device *dev = &pdev->dev; struct airoha_pwm *pc; struct pwm_chip *chip; int ret; - chip = devm_pwmchip_alloc(dev, AIROHA_PWM_MAX_CHANNELS, sizeof(*pc)); + id = platform_get_device_id(pdev); + if (id) { + soc = (const struct airoha_pwm_soc_data *)id->driver_data; + device_set_of_node_from_dev(dev, dev->parent); + } else { + soc = device_get_match_data(dev); + } + if (!soc) + return -EINVAL; + + chip = devm_pwmchip_alloc(dev, soc->npwm, sizeof(*pc)); if (IS_ERR(chip)) return PTR_ERR(chip); chip->ops = &airoha_pwm_ops; pc = pwmchip_get_drvdata(chip); + pc->soc = soc; pc->regmap = device_node_to_regmap(dev_of_node(dev->parent)); if (IS_ERR(pc->regmap)) @@ -597,12 +667,33 @@ static int airoha_pwm_probe(struct platform_device *pdev) return 0; } +static const struct airoha_pwm_soc_data en7581_pwm_soc_data = { + .npwm = AIROHA_PWM_MAX_CHANNELS, + .flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID, + .flash_en_mask = AIROHA_PWM_GPIO_FLASH_EN, +}; + +static const struct airoha_pwm_soc_data an7589_pwm_soc_data = { + .npwm = AN7589_PWM_NUM_CHANNELS, + .flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE, + .flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_EN, +}; + static const struct of_device_id airoha_pwm_of_match[] = { - { .compatible = "airoha,en7581-pwm" }, + { .compatible = "airoha,en7581-pwm", .data = &en7581_pwm_soc_data }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, airoha_pwm_of_match); +static const struct platform_device_id airoha_pwm_id_table[] = { + { + .name = "airoha-an7589-pwm", + .driver_data = (kernel_ulong_t)&an7589_pwm_soc_data, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, airoha_pwm_id_table); + static struct platform_driver airoha_pwm_driver = { .driver = { .name = "pwm-airoha", @@ -610,6 +701,7 @@ static struct platform_driver airoha_pwm_driver = { .of_match_table = airoha_pwm_of_match, }, .probe = airoha_pwm_probe, + .id_table = airoha_pwm_id_table, }; module_platform_driver(airoha_pwm_driver); @@ -617,5 +709,5 @@ MODULE_AUTHOR("Lorenzo Bianconi "); MODULE_AUTHOR("Markus Gothe "); MODULE_AUTHOR("Benjamin Larsson "); MODULE_AUTHOR("Christian Marangi "); -MODULE_DESCRIPTION("Airoha EN7581 PWM driver"); +MODULE_DESCRIPTION("Airoha PWM driver"); MODULE_LICENSE("GPL"); -- 2.34.1