All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 1/3] pwm: Introduce single-PWM of_xlate function
@ 2021-10-25 17:09 Bjorn Andersson
  2021-10-25 17:09 ` [PATCH v7 2/3] drm/bridge: ti-sn65dsi86: Use regmap_bulk_write API Bjorn Andersson
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Bjorn Andersson @ 2021-10-25 17:09 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König, Lee Jones, Robert Foss
  Cc: linux-pwm, linux-kernel, linux-arm-msm, Steev Klimaszewski

The existing pxa driver and the upcoming addition of PWM support in the
TI sn565dsi86 DSI/eDP bridge driver both has a single PWM channel and
thereby a need for a of_xlate function with the period as its single
argument.

Introduce a common helper function in the core that can be used as
of_xlate by such drivers and migrate the pxa driver to use this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tested-by: Steev Klimaszewski <steev@kali.org>
---

Changes since v6:
- None

 drivers/pwm/core.c    | 26 ++++++++++++++++++++++++++
 drivers/pwm/pwm-pxa.c | 16 +---------------
 include/linux/pwm.h   |  2 ++
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 4527f09a5c50..2c6b155002a2 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -152,6 +152,32 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
 }
 EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
 
+struct pwm_device *
+of_pwm_single_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
+{
+	struct pwm_device *pwm;
+
+	if (pc->of_pwm_n_cells < 1)
+		return ERR_PTR(-EINVAL);
+
+	/* validate that one cell is specified, optionally with flags */
+	if (args->args_count != 1 && args->args_count != 2)
+		return ERR_PTR(-EINVAL);
+
+	pwm = pwm_request_from_chip(pc, 0, NULL);
+	if (IS_ERR(pwm))
+		return pwm;
+
+	pwm->args.period = args->args[0];
+	pwm->args.polarity = PWM_POLARITY_NORMAL;
+
+	if (args->args_count == 2 && args->args[2] & PWM_POLARITY_INVERTED)
+		pwm->args.polarity = PWM_POLARITY_INVERSED;
+
+	return pwm;
+}
+EXPORT_SYMBOL_GPL(of_pwm_single_xlate);
+
 static void of_pwmchip_add(struct pwm_chip *chip)
 {
 	if (!chip->dev || !chip->dev->of_node)
diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
index a9efdcf839ae..238ec88c130b 100644
--- a/drivers/pwm/pwm-pxa.c
+++ b/drivers/pwm/pwm-pxa.c
@@ -148,20 +148,6 @@ static const struct platform_device_id *pxa_pwm_get_id_dt(struct device *dev)
 	return id ? id->data : NULL;
 }
 
-static struct pwm_device *
-pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
-{
-	struct pwm_device *pwm;
-
-	pwm = pwm_request_from_chip(pc, 0, NULL);
-	if (IS_ERR(pwm))
-		return pwm;
-
-	pwm->args.period = args->args[0];
-
-	return pwm;
-}
-
 static int pwm_probe(struct platform_device *pdev)
 {
 	const struct platform_device_id *id = platform_get_device_id(pdev);
@@ -187,7 +173,7 @@ static int pwm_probe(struct platform_device *pdev)
 	pc->chip.npwm = (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1;
 
 	if (IS_ENABLED(CONFIG_OF)) {
-		pc->chip.of_xlate = pxa_pwm_of_xlate;
+		pc->chip.of_xlate = of_pwm_single_xlate;
 		pc->chip.of_pwm_n_cells = 1;
 	}
 
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 725c9b784e60..dd51d4931fdc 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -414,6 +414,8 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
 
 struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
 		const struct of_phandle_args *args);
+struct pwm_device *of_pwm_single_xlate(struct pwm_chip *pc,
+				       const struct of_phandle_args *args);
 
 struct pwm_device *pwm_get(struct device *dev, const char *con_id);
 struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread
* Re: [PATCH v7 3/3] drm/bridge: ti-sn65dsi86: Implement the pwm_chip
  2021-10-25 17:09 ` [PATCH v7 3/3] drm/bridge: ti-sn65dsi86: Implement the pwm_chip Bjorn Andersson
@ 2021-11-03 14:35 ` Dan Carpenter
  2021-10-27 12:42   ` kernel test robot
  2021-10-27 18:43     ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-10-27 13:43 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 4109 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20211025170925.3096444-3-bjorn.andersson@linaro.org>
References: <20211025170925.3096444-3-bjorn.andersson@linaro.org>
TO: Bjorn Andersson <bjorn.andersson@linaro.org>

Hi Bjorn,

I love your patch! Perhaps something to improve:

[auto build test WARNING on v5.15-rc6]
[also build test WARNING on next-20211027]
[cannot apply to thierry-reding-pwm/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bjorn-Andersson/pwm-Introduce-single-PWM-of_xlate-function/20211026-011243
base:    519d81956ee277b4419c723adfb154603c2565ba
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-m001-20211027 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/gpu/drm/bridge/ti-sn65dsi86.c:302 ti_sn_bridge_set_refclk_freq() error: buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5 (assuming for loop doesn't break)

vim +302 drivers/gpu/drm/bridge/ti-sn65dsi86.c

f7a5ee2cd3e23f Douglas Anderson 2021-04-23  271  
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  272  static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  273  {
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  274  	int i;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  275  	u32 refclk_rate;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  276  	const u32 *refclk_lut;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  277  	size_t refclk_lut_size;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  278  
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  279  	if (pdata->refclk) {
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  280  		refclk_rate = clk_get_rate(pdata->refclk);
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  281  		refclk_lut = ti_sn_bridge_refclk_lut;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  282  		refclk_lut_size = ARRAY_SIZE(ti_sn_bridge_refclk_lut);
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  283  		clk_prepare_enable(pdata->refclk);
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  284  	} else {
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  285  		refclk_rate = ti_sn_bridge_get_dsi_freq(pdata) * 1000;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  286  		refclk_lut = ti_sn_bridge_dsiclk_lut;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  287  		refclk_lut_size = ARRAY_SIZE(ti_sn_bridge_dsiclk_lut);
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  288  	}
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  289  
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  290  	/* for i equals to refclk_lut_size means default frequency */
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  291  	for (i = 0; i < refclk_lut_size; i++)
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  292  		if (refclk_lut[i] == refclk_rate)
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  293  			break;
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  294  
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  295  	regmap_update_bits(pdata->regmap, SN_DPPLL_SRC_REG, REFCLK_FREQ_MASK,
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  296  			   REFCLK_FREQ(i));
e5ac651e6c7c72 Bjorn Andersson  2021-10-25  297  
e5ac651e6c7c72 Bjorn Andersson  2021-10-25  298  	/*
e5ac651e6c7c72 Bjorn Andersson  2021-10-25  299  	 * The PWM refclk is based on the value written to SN_DPPLL_SRC_REG,
e5ac651e6c7c72 Bjorn Andersson  2021-10-25  300  	 * regardless of its actual sourcing.
e5ac651e6c7c72 Bjorn Andersson  2021-10-25  301  	 */
e5ac651e6c7c72 Bjorn Andersson  2021-10-25 @302  	pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i];
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  303  }
f7a5ee2cd3e23f Douglas Anderson 2021-04-23  304  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37412 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-11-03 14:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-25 17:09 [PATCH v7 1/3] pwm: Introduce single-PWM of_xlate function Bjorn Andersson
2021-10-25 17:09 ` [PATCH v7 2/3] drm/bridge: ti-sn65dsi86: Use regmap_bulk_write API Bjorn Andersson
2021-10-27  8:29   ` Robert Foss
2021-10-27 14:06     ` Bjorn Andersson
2021-10-27 14:38       ` Robert Foss
2021-10-25 17:09 ` [PATCH v7 3/3] drm/bridge: ti-sn65dsi86: Implement the pwm_chip Bjorn Andersson
2021-10-25 19:14   ` Uwe Kleine-König
2021-10-27 12:42   ` kernel test robot
2021-10-27 18:43   ` kernel test robot
2021-10-27 18:43     ` kernel test robot
2021-10-26 17:21 ` [PATCH v7 1/3] pwm: Introduce single-PWM of_xlate function Steev Klimaszewski
2021-10-27 15:06   ` Robert Foss
2021-10-30  9:27     ` Uwe Kleine-König
2021-11-02 11:37       ` Robert Foss
  -- strict thread matches above, loose matches on Subject: below --
2021-10-27 13:43 [PATCH v7 3/3] drm/bridge: ti-sn65dsi86: Implement the pwm_chip kernel test robot
2021-11-03 14:35 ` Dan Carpenter

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.