From: Konrad Dybcio <konrad.dybcio@linaro.org>
To: wuxilin123@gmail.com,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Junhao Xie" <bigfoot@classfun.cn>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Jessica Zhang" <quic_jesszhan@quicinc.com>,
"Sam Ravnborg" <sam@ravnborg.org>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Bjorn Andersson" <andersson@kernel.org>,
"Tengfei Fan" <quic_tengfan@quicinc.com>,
"Molly Sophia" <mollysophia379@gmail.com>
Cc: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH 02/10] pwm: Add SI-EN SN3112 PWM support
Date: Wed, 24 Apr 2024 21:37:25 +0200 [thread overview]
Message-ID: <af62742c-8d6d-4fa9-b2e4-f83253e6e388@linaro.org> (raw)
In-Reply-To: <20240424-ayn-odin2-initial-v1-2-e0aa05c991fd@gmail.com>
On 4/24/24 17:29, Xilin Wu via B4 Relay wrote:
> From: Junhao Xie <bigfoot@classfun.cn>
>
> Add a new driver for the SI-EN SN3112 12-channel 8-bit PWM LED controller.
>
> Signed-off-by: Junhao Xie <bigfoot@classfun.cn>
> ---
[...]
> +static int sn3112_set_en_reg(struct sn3112 *priv, unsigned int channel,
> + bool enabled, bool write)
> +{
> + unsigned int reg, bit;
> +
> + if (channel >= SN3112_CHANNELS)
> + return -EINVAL;
> +
> + /* LED_EN1: BIT5:BIT3 = OUT3:OUT1 */
> + if (channel >= 0 && channel <= 2)
> + reg = 0, bit = channel + 3;
> + /* LED_EN2: BIT5:BIT0 = OUT9:OUT4 */
> + else if (channel >= 3 && channel <= 8)
> + reg = 1, bit = channel - 3;
> + /* LED_EN3: BIT2:BIT0 = OUT12:OUT10 */
> + else if (channel >= 9 && channel <= 11)
> + reg = 2, bit = channel - 9;
> + else
> + return -EINVAL;
> +
> + dev_dbg(priv->pdev, "channel %u enabled %u\n", channel, enabled);
> + dev_dbg(priv->pdev, "reg %u bit %u\n", reg, bit);
> + if (enabled)
> + set_bit(bit, (ulong *)&priv->pwm_en_reg[reg]);
> + else
> + clear_bit(bit, (ulong *)&priv->pwm_en_reg[reg]);
> + dev_dbg(priv->pdev, "set enable reg %u to %u\n", reg,
> + priv->pwm_en_reg[reg]);
> +
> + if (!write)
> + return 0;
> + return sn3112_write_reg(priv, SN3112_REG_PWM_EN + reg,
> + priv->pwm_en_reg[reg]);
This looks like a weird reimplementation of regmap_update_bits
> +}
> +
> +static int sn3112_set_val_reg(struct sn3112 *priv, unsigned int channel,
> + uint8_t val, bool write)
> +{
> + if (channel >= SN3112_CHANNELS)
> + return -EINVAL;
> + priv->pwm_val[channel] = val;
> + dev_dbg(priv->pdev, "set value reg %u to %u\n", channel,
> + priv->pwm_val[channel]);
> +
> + if (!write)
> + return 0;
There's only a single call, with write == true
> + return sn3112_write_reg(priv, SN3112_REG_PWM_VAL + channel,
> + priv->pwm_val[channel]);
> +}
> +
> +static int sn3112_write_all(struct sn3112 *priv)
> +{
> + int i, ret;
> +
> + /* regenerate enable register values */
> + for (i = 0; i < SN3112_CHANNELS; i++) {
> + ret = sn3112_set_en_reg(priv, i, priv->pwm_en[i], false);
> + if (ret != 0)
> + return ret;
> + }
> +
> + /* use random value to clear all registers */
> + ret = sn3112_write_reg(priv, SN3112_REG_RESET, 0x66);
> + if (ret != 0)
if (ret) is the same as if (ret != 0)
[...]
> +
> + /* use random value to apply changes */
> + ret = sn3112_write_reg(priv, SN3112_REG_APPLY, 0x66);
"a random value"? sounds suspicious..
> + if (ret != 0)
> + return ret;
> +
> + dev_dbg(priv->pdev, "reinitialized\n");
Please remove such "got here" messages once you're done with testing
the driver locally
[...]
> +
> +#if IS_ENABLED(CONFIG_GPIOLIB)
I'm not sure this would be ever disabled on any embedded system nowadays.
Especially with I2C.
[...]
> +
> + dev_info(&client->dev,
> + "Found SI-EN SN3112 12-channel 8-bit PWM LED controller\n");
This sort of message only makes sense if there's a CHIP_ID register that
you can actually validate. If you bind this driver to a device at the same
expected address, it will say it's there even if it's not.
> + return 0;
> +}
> +
> +static void sn3112_pwm_remove(struct i2c_client *client)
> +{
> + struct pwm_chip *chip = i2c_get_clientdata(client);
> + struct sn3112 *priv = pwmchip_get_drvdata(chip);
> +
> + dev_dbg(priv->pdev, "remove\n");
> +
> + /* set software enable register */
> + sn3112_write_reg(priv, SN3112_REG_ENABLE, 0);
> +
> + /* use random value to apply changes */
> + sn3112_write_reg(priv, SN3112_REG_APPLY, 0x66);
> +
> +#if IS_ENABLED(CONFIG_GPIOLIB)
> + /* enable hardware shutdown pin */
> + if (priv->sdb)
> + gpiod_set_value(priv->sdb, 1);
> +#endif
> +
> + /* power-off sn5112 power vdd */
> + regulator_disable(priv->vdd);
> +
> + pwmchip_remove(chip);
devm_pwmchip_add?
Konrad
next prev parent reply other threads:[~2024-04-24 19:37 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-24 15:29 [PATCH 00/10] AYN Odin 2 support Xilin Wu via B4 Relay
2024-04-24 15:29 ` [PATCH 01/10] dt-bindings: pwm: Add SI-EN SN3112 PWM support Xilin Wu via B4 Relay
2024-04-25 6:04 ` Uwe Kleine-König
2024-04-24 15:29 ` [PATCH 02/10] " Xilin Wu via B4 Relay
2024-04-24 15:55 ` Bryan O'Donoghue
2024-04-24 19:09 ` BigfootACA
2024-04-25 6:08 ` Uwe Kleine-König
2024-04-24 19:37 ` Konrad Dybcio [this message]
2024-04-25 0:57 ` Junhao Xie
2024-04-25 7:57 ` Neil Armstrong
2024-04-25 6:14 ` Uwe Kleine-König
2024-04-25 6:02 ` Uwe Kleine-König
2024-04-25 7:03 ` Junhao Xie
2024-04-24 15:29 ` [PATCH 03/10] dt-bindings: display: panel: Add Synaptics TD4328 Xilin Wu via B4 Relay
2024-04-25 16:11 ` Rob Herring
2024-04-28 3:25 ` Xilin Wu
2024-04-24 15:29 ` [PATCH 04/10] drm/panel: Add driver for Synaptics TD4328 LCD panel Xilin Wu via B4 Relay
2024-04-24 15:58 ` Bryan O'Donoghue
2024-04-28 3:29 ` Xilin Wu
2024-04-24 15:29 ` [PATCH 05/10] arm64: dts: qcom: pmk8550: Add PWM controller Xilin Wu via B4 Relay
2024-04-24 19:38 ` Konrad Dybcio
2024-04-24 15:29 ` [PATCH 06/10] arm64: dts: qcom: sm8550: Add UART15 Xilin Wu via B4 Relay
2024-04-24 23:39 ` Dmitry Baryshkov
2024-04-24 15:29 ` [PATCH 07/10] arm64: dts: qcom: sm8550: Update EAS properties Xilin Wu via B4 Relay
2024-04-24 22:45 ` Bryan O'Donoghue
2024-04-28 3:43 ` Xilin Wu
2024-04-24 15:29 ` [PATCH 08/10] dt-bindings: vendor-prefixes: Add AYN Technologies Xilin Wu via B4 Relay
2024-04-25 16:13 ` Rob Herring
2024-04-28 3:44 ` Xilin Wu
2024-04-24 15:29 ` [PATCH 09/10] dt-bindings: arm: qcom: Add AYN Odin 2 Xilin Wu via B4 Relay
2024-04-24 15:43 ` Bryan O'Donoghue
2024-04-24 15:29 ` [PATCH 10/10] arm64: dts: " Xilin Wu via B4 Relay
2024-04-25 6:28 ` Krzysztof Kozlowski
2024-04-28 3:54 ` Xilin Wu
2024-04-30 10:26 ` Konrad Dybcio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af62742c-8d6d-4fa9-b2e4-f83253e6e388@linaro.org \
--to=konrad.dybcio@linaro.org \
--cc=airlied@gmail.com \
--cc=andersson@kernel.org \
--cc=bigfoot@classfun.cn \
--cc=conor+dt@kernel.org \
--cc=daniel@ffwll.ch \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mollysophia379@gmail.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=quic_jesszhan@quicinc.com \
--cc=quic_tengfan@quicinc.com \
--cc=robh@kernel.org \
--cc=sam@ravnborg.org \
--cc=tzimmermann@suse.de \
--cc=u.kleine-koenig@pengutronix.de \
--cc=wuxilin123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).