All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@kernel.org>
To: Andreas Kemnade <andreas@kemnade.info>,
	Kevin Hilman <khilman@baylibre.com>,
	Michael Turquette <mturquette@baylibre.com>,
	Aaro Koskinen <aaro.koskinen@iki.fi>,
	linux-kernel@vger.kernel.org, Tony Lindgren <tony@atomide.com>,
	linux-clk@vger.kernel.org, Lee Jones <lee@kernel.org>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-omap@vger.kernel.org
Subject: Re: [PATCH v4 3/3] clk: twl: add TWL6030 support
Date: Thu, 10 Oct 2024 14:36:58 +0300	[thread overview]
Message-ID: <901ab11e-bfe3-487c-9867-53289c848792@kernel.org> (raw)
In-Reply-To: <20241010074355.58161-4-andreas@kemnade.info>

Hi Andreas,

On 10/10/2024 10:43, Andreas Kemnade wrote:
> The TWL6030 has similar clocks, so add support for it. Take care of the
> resource grouping handling needed.
> 
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
> ---
>  drivers/clk/Kconfig   |  2 +-
>  drivers/clk/clk-twl.c | 52 +++++++++++++++++++++++++++++++++++--------
>  2 files changed, 44 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 299bc678ed1b..82ec12f9b82c 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -291,7 +291,7 @@ config CLK_TWL
>  	help
>  	  Enable support for controlling the clock resources on TWL family
>  	  PMICs. These devices have some 32K clock outputs which can be
> -	  controlled by software. For now, only the TWL6032 clocks are
> +	  controlled by software. For now, the TWL6032 and TWL6030 clocks are
>  	  supported.
>  
>  config CLK_TWL6040
> diff --git a/drivers/clk/clk-twl.c b/drivers/clk/clk-twl.c
> index 1d684b358401..c04bcb61e260 100644
> --- a/drivers/clk/clk-twl.c
> +++ b/drivers/clk/clk-twl.c
> @@ -11,13 +11,29 @@
>  #include <linux/platform_device.h>
>  #include <linux/slab.h>
>  
> -#define VREG_STATE              2
> +#define VREG_STATE		2
> +#define VREG_GRP		0
>  #define TWL6030_CFG_STATE_OFF   0x00
>  #define TWL6030_CFG_STATE_ON    0x01
>  #define TWL6030_CFG_STATE_MASK  0x03
> +#define TWL6030_CFG_STATE_GRP_SHIFT	5
> +#define TWL6030_CFG_STATE_APP_SHIFT	2
> +#define TWL6030_CFG_STATE_APP_MASK	(0x03 << TWL6030_CFG_STATE_APP_SHIFT)
> +#define TWL6030_CFG_STATE_APP(v)	(((v) & TWL6030_CFG_STATE_APP_MASK) >>\
> +						TWL6030_CFG_STATE_APP_SHIFT)
> +#define P1_GRP BIT(0) /* processor power group */
> +#define P2_GRP BIT(1)
> +#define P3_GRP BIT(2)
> +#define ALL_GRP (P1_GRP | P2_GRP | P3_GRP)
> +
> +enum twl_type {
> +	TWL_TYPE_6030,
> +	TWL_TYPE_6032,
> +};
>  
>  struct twl_clock_info {
>  	struct device *dev;
> +	enum twl_type type;
>  	u8 base;
>  	struct clk_hw hw;
>  };
> @@ -56,14 +72,21 @@ static unsigned long twl_clks_recalc_rate(struct clk_hw *hw,
>  static int twl6032_clks_prepare(struct clk_hw *hw)
>  {
>  	struct twl_clock_info *cinfo = to_twl_clks_info(hw);
> -	int ret;
>  
> -	ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
> -			   TWL6030_CFG_STATE_ON);
> -	if (ret < 0)
> -		dev_err(cinfo->dev, "clk prepare failed\n");
> +	if (cinfo->type == TWL_TYPE_6030) {
> +		int grp;
> +
> +		grp = twlclk_read(cinfo, TWL_MODULE_PM_RECEIVER, VREG_GRP);
> +		if (grp < 0)
> +			return grp;
>  
> -	return ret;
> +		return twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
> +				    grp << TWL6030_CFG_STATE_GRP_SHIFT |
> +				    TWL6030_CFG_STATE_ON);
> +	}
> +
> +	return twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
> +			    TWL6030_CFG_STATE_ON);
>  }
>  
>  static void twl6032_clks_unprepare(struct clk_hw *hw)
> @@ -71,8 +94,14 @@ static void twl6032_clks_unprepare(struct clk_hw *hw)
>  	struct twl_clock_info *cinfo = to_twl_clks_info(hw);
>  	int ret;
>  
> -	ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
> -			   TWL6030_CFG_STATE_OFF);
> +	if (cinfo->type == TWL_TYPE_6032)

Shouldn't this be done for TWL_TYPE_6030?

> +		ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
> +				   ALL_GRP << TWL6030_CFG_STATE_GRP_SHIFT |
> +				   TWL6030_CFG_STATE_OFF);
> +	else> +		ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
> +				   TWL6030_CFG_STATE_OFF);
> +
>  	if (ret < 0)
>  		dev_err(cinfo->dev, "clk unprepare failed\n");
>  }
> @@ -138,6 +167,7 @@ static int twl_clks_probe(struct platform_device *pdev)
>  	for (i = 0; i < count; i++) {
>  		cinfo[i].base = hw_data[i].base;
>  		cinfo[i].dev = &pdev->dev;
> +		cinfo[i].type = platform_get_device_id(pdev)->driver_data;
>  		cinfo[i].hw.init = &hw_data[i].init;
>  		ret = devm_clk_hw_register(&pdev->dev, &cinfo[i].hw);
>  		if (ret) {
> @@ -159,7 +189,11 @@ static int twl_clks_probe(struct platform_device *pdev)
>  
>  static const struct platform_device_id twl_clks_id[] = {
>  	{
> +		.name = "twl6030-clk",
> +		.driver_data = TWL_TYPE_6030,
> +	}, {
>  		.name = "twl6032-clk",
> +		.driver_data = TWL_TYPE_6032,
>  	}, {
>  		/* sentinel */
>  	}

-- 
cheers,
-roger

  reply	other threads:[~2024-10-10 11:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10  7:43 [PATCH v4 0/3] mfd: twl: Add clock for TWL6030 Andreas Kemnade
2024-10-10  7:43 ` [PATCH v4 1/3] mfd: twl-core: Add a clock subdevice for the TWL6030 Andreas Kemnade
2024-10-10  7:43 ` [PATCH v4 2/3] clk: twl: remove is_prepared Andreas Kemnade
2024-10-10  7:43 ` [PATCH v4 3/3] clk: twl: add TWL6030 support Andreas Kemnade
2024-10-10 11:36   ` Roger Quadros [this message]
2024-10-10 12:32     ` Andreas Kemnade

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=901ab11e-bfe3-487c-9867-53289c848792@kernel.org \
    --to=rogerq@kernel.org \
    --cc=aaro.koskinen@iki.fi \
    --cc=andreas@kemnade.info \
    --cc=khilman@baylibre.com \
    --cc=lee@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=tony@atomide.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.