From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Wenhua Lin <Wenhua.Lin@unisoc.com>
Cc: Orson Zhai <orsonzhai@gmail.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
wenhua lin <wenhua.lin1994@gmail.com>,
Xiongpeng Wu <xiongpeng.wu@unisoc.com>,
zhaochen su <zhaochen.su29@gmail.com>,
Zhaochen Su <Zhaochen.Su@unisoc.com>,
Xiaolong Wang <Xiaolong.Wang@unisoc.com>
Subject: Re: [PATCH 1/6] pwm: sprd: Add support for UMS9620
Date: Fri, 26 Jan 2024 08:19:51 +0100 [thread overview]
Message-ID: <bvnhi4qeczrmlmaog6drlztg4x6ubozjzu57sukpejme7xecqc@724g62vjgxrq> (raw)
In-Reply-To: <20240122081754.17058-2-Wenhua.Lin@unisoc.com>
[-- Attachment #1: Type: text/plain, Size: 3770 bytes --]
On Mon, Jan 22, 2024 at 04:17:49PM +0800, Wenhua Lin wrote:
> The PMW unit on the current Unisoc's SoCs has 4 channels but has different
> address offsets. On UMS512, they are 0x0, 0x20, 0x40, 0x60 respectively,
> while are 0x0, 0x4000, 0x8000, 0xC000 on UMS9620.
>
> Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> ---
> drivers/pwm/pwm-sprd.c | 28 ++++++++++++++++++++++++----
> 1 file changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
> index 77939e161006..bc1e3ed13528 100644
> --- a/drivers/pwm/pwm-sprd.c
> +++ b/drivers/pwm/pwm-sprd.c
> @@ -9,6 +9,7 @@
> #include <linux/math64.h>
> #include <linux/mod_devicetable.h>
> #include <linux/module.h>
> +#include <linux/of.h>
> #include <linux/platform_device.h>
> #include <linux/pwm.h>
>
> @@ -23,7 +24,6 @@
> #define SPRD_PWM_ENABLE_BIT BIT(0)
>
> #define SPRD_PWM_CHN_NUM 4
> -#define SPRD_PWM_REGS_SHIFT 5
> #define SPRD_PWM_CHN_CLKS_NUM 2
> #define SPRD_PWM_CHN_OUTPUT_CLK 1
>
> @@ -32,14 +32,27 @@ struct sprd_pwm_chn {
> u32 clk_rate;
> };
>
> +struct sprd_pwm_data {
> + int reg_shift;
> +};
> +
> struct sprd_pwm_chip {
> void __iomem *base;
> struct device *dev;
> struct pwm_chip chip;
> + const struct sprd_pwm_data *pdata;
> int num_pwms;
> struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM];
> };
>
> +static const struct sprd_pwm_data ums512_data = {
> + .reg_shift = 5,
> +};
> +
> +static const struct sprd_pwm_data ums9620_data = {
> + .reg_shift = 14,
> +};
> +
> static inline struct sprd_pwm_chip* sprd_pwm_from_chip(struct pwm_chip *chip)
> {
> return container_of(chip, struct sprd_pwm_chip, chip);
> @@ -58,7 +71,7 @@ static const char * const sprd_pwm_clks[] = {
>
> static u32 sprd_pwm_read(struct sprd_pwm_chip *spc, u32 hwid, u32 reg)
> {
> - u32 offset = reg + (hwid << SPRD_PWM_REGS_SHIFT);
> + u32 offset = reg + (hwid << spc->pdata->reg_shift);
>
> return readl_relaxed(spc->base + offset);
> }
> @@ -66,7 +79,7 @@ static u32 sprd_pwm_read(struct sprd_pwm_chip *spc, u32 hwid, u32 reg)
> static void sprd_pwm_write(struct sprd_pwm_chip *spc, u32 hwid,
> u32 reg, u32 val)
> {
> - u32 offset = reg + (hwid << SPRD_PWM_REGS_SHIFT);
> + u32 offset = reg + (hwid << spc->pdata->reg_shift);
>
> writel_relaxed(val, spc->base + offset);
> }
> @@ -253,6 +266,7 @@ static int sprd_pwm_clk_init(struct sprd_pwm_chip *spc)
> static int sprd_pwm_probe(struct platform_device *pdev)
> {
> struct sprd_pwm_chip *spc;
> + const void *priv;
This can better be of type struct sprd_pwm_data *. Also pdata would be a
better name.
> int ret;
>
> spc = devm_kzalloc(&pdev->dev, sizeof(*spc), GFP_KERNEL);
> @@ -263,6 +277,11 @@ static int sprd_pwm_probe(struct platform_device *pdev)
> if (IS_ERR(spc->base))
> return PTR_ERR(spc->base);
>
> + priv = of_device_get_match_data(&pdev->dev);
> + if (!priv)
> + return dev_err_probe(&pdev->dev, -EINVAL, "get regs shift failed!\n");
> + spc->pdata = priv;
> +
> spc->dev = &pdev->dev;
>
> ret = sprd_pwm_clk_init(spc);
> @@ -281,7 +300,8 @@ static int sprd_pwm_probe(struct platform_device *pdev)
> }
>
> static const struct of_device_id sprd_pwm_of_match[] = {
> - { .compatible = "sprd,ums512-pwm", },
> + { .compatible = "sprd,ums512-pwm", .data = (void *)&ums512_data},
> + { .compatible = "sprd,ums9620-pwm", .data = (void *)&ums9620_data},
Please use one line per assignment. Do you really need the cast to void
*?
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2024-01-26 7:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 8:17 [PATCH 0/6] pwm: sprd: Modification of UNISOC Platform PWM Driver Wenhua Lin
2024-01-22 8:17 ` [PATCH 1/6] pwm: sprd: Add support for UMS9620 Wenhua Lin
2024-01-26 7:19 ` Uwe Kleine-König [this message]
2024-01-22 8:17 ` [PATCH 2/6] pwm: sprd: Improve the pwm backlight control function Wenhua Lin
2024-01-22 15:46 ` Krzysztof Kozlowski
2024-01-22 8:17 ` [PATCH 3/6] pwm: sprd: Optimize the calculation method of duty Wenhua Lin
2024-01-22 8:17 ` [PATCH 4/6] dt-bindings: pwm: sprd: Convert to YAML Wenhua Lin
2024-01-22 15:44 ` Krzysztof Kozlowski
2024-01-22 8:17 ` [PATCH 5/6] pwm: sprd: Add sprd,ums9620-pwm compatible Wenhua Lin
2024-01-22 15:45 ` Krzysztof Kozlowski
2024-01-22 8:17 ` [PATCH 6/6] dt-bindings: pwm: sprd: Add sprd,mod attribute Wenhua Lin
2024-01-22 15:45 ` Krzysztof Kozlowski
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=bvnhi4qeczrmlmaog6drlztg4x6ubozjzu57sukpejme7xecqc@724g62vjgxrq \
--to=u.kleine-koenig@pengutronix.de \
--cc=Wenhua.Lin@unisoc.com \
--cc=Xiaolong.Wang@unisoc.com \
--cc=Zhaochen.Su@unisoc.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=wenhua.lin1994@gmail.com \
--cc=xiongpeng.wu@unisoc.com \
--cc=zhang.lyra@gmail.com \
--cc=zhaochen.su29@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).