From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796294859; b=KBXoMnw3tm2bGHdC7AaiQF4aJXZaDIwvYq3VAW5ATaLgI3mMOT0nTslRkDuIUcnYK/FR t4kPsDGivDDmVo3s9NVpKzGGDZ3mFPesMXStbk4ARlBI9hh5TNRybo+80tXSc83Mo3hht rqKiTZTstq4z2fsb1n+ACORxlItvW/gvoK3OcrueGY2t/go5TO3bH94GeWod5FwuTiYTV glkCf7y4azEx42Sai74hMKQUEj/qx4j5GnZca8HkcOOv+1qJogc+oFCdaBjrIn1sNxgx0 z18MzWEPOedSYs0SwbRfYVNnvzXpHYDpBvZ4J9HzbylsdspiWa0e4GY1lFHUzBs5p0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796294859; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=5ocAGgR7haJy2sKBi8JnyfbGoaphIHG4IXDE2Ckk1dY=; b=T3Z0EqWivDsNGc3L1XUUaTW6SAOJWaqd+0XbvLZjNxKlIBxNBD106H9KrxdfqAD7gKUF KU6K8LQejE3U3esrQkawelMe/xGkXHg5xbAhDfUCnUdjoiAfUascXsyB5sDl9D2Rh6XgO H3v39kPjrrR4hBZOdXyo2dhviuHfGdnIF9U/4IzftZavM9X7/CfLgIvlgqE273h6cV0xb nyrex0vE7O2Jdtp2mbQA6tDdF54OLhrJBtVHRxcCT5TBvaVoGf4cRogtSP642rsyTV4aB U77MDqh4XqQYN9sSStWt4TiNNOjHCpeOdjIt3W8hmVP1SnqfmBuLa++jXqnOb2BRgBg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="lI/LK9Dg"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 7645F606A32C; Thu, 3 Dec 2026 10:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lI/LK9Dg 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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> --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--