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 42D81606A336 for ; Thu, 3 Dec 2026 10:47:47 +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=tJaEKd4J; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lI/LK9Dg 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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=5ocAGgR7haJy2sKBi8JnyfbGoaphIHG4IXDE2Ckk1dY=; b=tJaEKd4JU5bgpfVxSHb6e0C/0n Jni34Nsf3ta2d9jzGnegMXoFjmbz9m7IKHqrpkMcY92BrZ4H8DL+pD3qUs2Du9JP8dXvMTQZWCSaZ 5hrPgyBCYV4bQxmr0JqjkS49SUUE80dBCzWpomnPRPYHPf45mbT3dEu2baFYHG4W204e072fvV7AT jGeNLKLx4jqKh3XFIvfF9py7FKYQlIJUpba/Icb9q82iozmVSJ/FP7/Y3IUxA5mgJUwgFYYgypDEj kzdOxNMHJzzb0XfkRR2WCG3y7+t3tVysm9mDdhfhYYeOD7l0gugj8vY7JWJD6SCbOZjw+YXrtW2qG UMrydtxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ4Lq-0000000EEXu-3j4Y; Thu, 03 Dec 2026 10:47:46 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ4Lj-0000000EEK9-43Fc for linux-mediatek@lists.infradead.org; Thu, 03 Dec 2026 10:47:43 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with UTF8SMTP id 480E262219; Thu, 3 Dec 2026 10:47:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 752D91F00896; Thu, 3 Dec 2026 10:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796294859; bh=5ocAGgR7haJy2sKBi8JnyfbGoaphIHG4IXDE2Ckk1dY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=lI/LK9DgymiIgrHUY71eajbZ+tv5TAtmlL6ti8c2rEq/IfzZ7q/aQY/3wxWZemkxC IjLk4bI5Oq9n88gd9jSHjxJlr0jNmFrU5iVCsqgn+NKfQDrMgdebRRXHo9BL9IkVy5 dkTn7fRTlQUvRbM5ggNyMMfPeCmh0opozNXtn1L+Pc/2avB0uFLlCVSKDXL8jEN5k/ NI/HD6WVWwtoSRwtJIgVVh9cTSbq+zrHiC/rf0vwC8i2v79vgQCNIp3EYQBwyCQSPX ZRQfhi0mfIFVM+JracZWuiq74dtrlK8znKQc09cUiUr6GFlxA1ZYmJNLl6gScEI8Us GX04e3jV0CN8Q== Date: Thu, 3 Dec 2026 11:47:36 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: John Crispin Cc: Lorenzo Bianconi , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , 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: Re: [PATCH 3/3] pwm: airoha: add support for AN7589 Message-ID: References: <20261201194434.3132187-1-john@phrozen.org> <20261201194434.3132187-4-john@phrozen.org> X-Archived-By: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gsqawekepdgi3ae6" Content-Disposition: inline In-Reply-To: <20261201194434.3132187-4-john@phrozen.org> 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=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 --gsqawekepdgi3ae6 Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH 3/3] pwm: airoha: add support for AN7589 MIME-Version: 1.0 Hello John, On Tue, Dec 01, 2026 at 08:44:34PM +0100, John Crispin wrote: > 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. >=20 > 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. >=20 > 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. Why do we have this difference? And why is the PWM's parent device the PWM provider? > Signed-off-by: John Crispin > --- > drivers/pwm/pwm-airoha.c | 116 +++++++++++++++++++++++++++++++++++---- > 1 file changed, 104 insertions(+), 12 deletions(-) >=20 > 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) What is bit 3 for en7581? If it's reserved and reads as zero, you can set it to GENMASK(3, 0) unconditionally. > /* 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) > =20 > +#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; > +}; > =20 > struct airoha_pwm_bucket { > /* Concurrent access protected by PWM core */ > @@ -88,6 +100,7 @@ struct airoha_pwm_bucket { > =20 > struct airoha_pwm { > struct regmap *regmap; > + const struct airoha_pwm_soc_data *soc; > =20 > DECLARE_BITMAP(initialized, AIROHA_PWM_MAX_CHANNELS); > =20 > @@ -417,9 +430,52 @@ static int airoha_pwm_sipo_init(struct airoha_pwm *p= c) > AIROHA_PWM_SERIAL_GPIO_FLASH_MODE); > } > =20 > +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 =3D pc->soc; > + > + if (!soc->flash_en_reg) { This register selection is quite complicated already. Is it possible to set .flash_en_reg and .flash_en_mask for all device variants and drop the condition check here or simplify otherwise? > + *mask =3D soc->flash_en_mask << shift; > + return; > + } > + > + *addr =3D soc->flash_en_reg; > + *mask =3D BIT(hwpwm); > +} > + > +static int airoha_pwm_flash_enable(struct airoha_pwm *pc, unsigned int h= wpwm, > + 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 =3D regmap_read(pc->regmap, addr, &val); > + if (ret) > + return ret; > + > + *enabled =3D !!(val & mask); > + > + return 0; > +} > + > static int airoha_pwm_config_flash_map(struct airoha_pwm *pc, > unsigned int hwpwm, int index) > { > + u32 set_id_mask =3D 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 airoh= a_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); > } > =20 > - ret =3D regmap_update_bits(pc->regmap, addr, > - AIROHA_PWM_GPIO_FLASH_SET_ID << shift, > - FIELD_PREP(AIROHA_PWM_GPIO_FLASH_SET_ID, index) << shift); > + ret =3D regmap_update_bits(pc->regmap, addr, set_id_mask << shift, > + field_prep(set_id_mask, index) << shift); > if (ret) > return ret; > =20 > - return regmap_set_bits(pc->regmap, addr, AIROHA_PWM_GPIO_FLASH_EN << sh= ift); > + return airoha_pwm_flash_enable(pc, hwpwm, addr, shift, true); > } > =20 > static int airoha_pwm_config(struct airoha_pwm *pc, struct pwm_device *p= wm, > @@ -552,17 +606,20 @@ static int airoha_pwm_get_state(struct pwm_chip *ch= ip, struct pwm_device *pwm, > =20 > airoha_pwm_get_flash_map_addr_and_shift(hwpwm, &addr, &shift); > =20 > - ret =3D regmap_read(pc->regmap, addr, &val); > + ret =3D airoha_pwm_flash_enabled(pc, hwpwm, addr, shift, &state->enable= d); > if (ret) > return ret; > =20 > - state->enabled =3D FIELD_GET(AIROHA_PWM_GPIO_FLASH_EN, val >> shift); > if (!state->enabled) > return 0; > =20 > + ret =3D regmap_read(pc->regmap, addr, &val); > + if (ret) > + return ret; > + > state->polarity =3D PWM_POLARITY_NORMAL; > =20 > - bucket =3D FIELD_GET(AIROHA_PWM_GPIO_FLASH_SET_ID, val >> shift); > + bucket =3D 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 =3D { > =20 > 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 =3D &pdev->dev; > struct airoha_pwm *pc; > struct pwm_chip *chip; > int ret; > =20 > - chip =3D devm_pwmchip_alloc(dev, AIROHA_PWM_MAX_CHANNELS, sizeof(*pc)); > + id =3D platform_get_device_id(pdev); > + if (id) { > + soc =3D (const struct airoha_pwm_soc_data *)id->driver_data; > + device_set_of_node_from_dev(dev, dev->parent); > + } else { > + soc =3D device_get_match_data(dev); > + } > + if (!soc) > + return -EINVAL; > + > + chip =3D devm_pwmchip_alloc(dev, soc->npwm, sizeof(*pc)); > if (IS_ERR(chip)) > return PTR_ERR(chip); > =20 > chip->ops =3D &airoha_pwm_ops; > pc =3D pwmchip_get_drvdata(chip); > + pc->soc =3D soc; > =20 > pc->regmap =3D 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; > } > =20 > +static const struct airoha_pwm_soc_data en7581_pwm_soc_data =3D { > + .npwm =3D AIROHA_PWM_MAX_CHANNELS, EN7581_PWM_NUM_CHANNELS? > + .flash_set_id_mask =3D AIROHA_PWM_GPIO_FLASH_SET_ID, > + .flash_en_mask =3D AIROHA_PWM_GPIO_FLASH_EN, > +}; > + > +static const struct airoha_pwm_soc_data an7589_pwm_soc_data =3D { > + .npwm =3D AN7589_PWM_NUM_CHANNELS, > + .flash_set_id_mask =3D AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE, > + .flash_en_reg =3D AIROHA_PWM_REG_GPIO_FLASH_EN, > +}; > + > static const struct of_device_id airoha_pwm_of_match[] =3D { > - { .compatible =3D "airoha,en7581-pwm" }, > + { .compatible =3D "airoha,en7581-pwm", .data =3D &en7581_pwm_soc_data }, > { /* sentinel */ } > }; > MODULE_DEVICE_TABLE(of, airoha_pwm_of_match); > =20 > +static const struct platform_device_id airoha_pwm_id_table[] =3D { > + { > + .name =3D "airoha-an7589-pwm", > + .driver_data =3D (kernel_ulong_t)&an7589_pwm_soc_data, > + }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(platform, airoha_pwm_id_table); > + > static struct platform_driver airoha_pwm_driver =3D { > .driver =3D { > .name =3D "pwm-airoha", > @@ -610,6 +701,7 @@ static struct platform_driver airoha_pwm_driver =3D { > .of_match_table =3D airoha_pwm_of_match, > }, > .probe =3D airoha_pwm_probe, > + .id_table =3D airoha_pwm_id_table, By introducing the id_table you make platform_match() stop match for devices with (strcmp(pdev->name, "pwm-airoha"). Did you check this doesn't matter? Please mention that change in the commit log. > }; > module_platform_driver(airoha_pwm_driver); > =20 Best regards Uwe --gsqawekepdgi3ae6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmsRSMYACgkQj4D7WH0S /k72dQf/TVVkdz+Ws6Pxqc0fVnmRWTs/zHCLWmhI3eM7gzuYLixd8qUZ/3WZ1cVd 5MUslAhlWl2Og6A7gQSyVxoX7f8OcfDc9wM1/PvNZ9mj35zWL2K+ES0J6y6jWa87 pUqQKiz7rb57n3C9GrylG7Oldn8F575PnyfkTwy037YttAnvhlXClJhaxiTof5bK TEtn/aHX20Uo2bF6yx8tVYDx2ALwuMQxN1DLlZj8Ddr7dbXHfq4gZv6q2LpMeRFy e7PX+fT1Tf4fxrRb60mmhNXxIglYkX/IzWq5r1kdh1Okbc84PN0vH4eweAtGZW+4 p8ZRFdf0eVLwwTzk1I6bB18xLmOCsg== =nBho -----END PGP SIGNATURE----- --gsqawekepdgi3ae6--