diff mbox series

[v9,11/11] pwm: core: Convert period and duty cycle to u64

Message ID ecc35a71d489baa0dd46d1a583edafa8399a0a64.1584473399.git.gurus@codeaurora.org
State Changes Requested
Headers show
Series [v9,01/11] drm/i915: Use 64-bit division macro | expand

Commit Message

Guru Das Srinagesh March 17, 2020, 8:05 p.m. UTC
Because period and duty cycle are defined as ints with units of
nanoseconds, the maximum time duration that can be set is limited to
~2.147 seconds. Change their definitions to u64 in the structs of the
PWM framework so that higher durations may be set.

Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
---
 drivers/pwm/core.c  |  4 ++--
 drivers/pwm/sysfs.c |  8 ++++----
 include/linux/pwm.h | 12 ++++++------
 3 files changed, 12 insertions(+), 12 deletions(-)

Comments

kernel test robot March 18, 2020, 6:51 p.m. UTC | #1
Hi Guru,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on pwm/for-next]
[also build test ERROR on hwmon/hwmon-next linuxtv-media/master shawnguo/for-next stm32/stm32-next sunxi/sunxi/for-next v5.6-rc6]
[cannot apply to drm-intel/for-linux-next next-20200317]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Guru-Das-Srinagesh/Convert-PWM-period-and-duty-cycle-to-u64/20200318-094102
base:   https://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git for-next
config: microblaze-randconfig-a001-20200318 (attached as .config)
compiler: microblaze-linux-gcc (GCC) 9.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=9.2.0 make.cross ARCH=microblaze 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   microblaze-linux-ld: drivers/clk/clk-pwm.o: in function `clk_pwm_probe':
>> drivers/clk/clk-pwm.c:92: undefined reference to `__udivdi3'
   `.exit.data' referenced in section `.exit.text' of drivers/tty/n_hdlc.o: defined in discarded section `.exit.data' of drivers/tty/n_hdlc.o
   `.exit.data' referenced in section `.exit.text' of drivers/tty/n_hdlc.o: defined in discarded section `.exit.data' of drivers/tty/n_hdlc.o

vim +92 drivers/clk/clk-pwm.c

9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   66  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   67  static int clk_pwm_probe(struct platform_device *pdev)
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   68  {
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   69  	struct device_node *node = pdev->dev.of_node;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   70  	struct clk_init_data init;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   71  	struct clk_pwm *clk_pwm;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   72  	struct pwm_device *pwm;
dd0b38b7ca0d8c Boris Brezillon 2016-04-14   73  	struct pwm_args pargs;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   74  	const char *clk_name;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   75  	int ret;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   76  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   77  	clk_pwm = devm_kzalloc(&pdev->dev, sizeof(*clk_pwm), GFP_KERNEL);
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   78  	if (!clk_pwm)
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   79  		return -ENOMEM;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   80  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   81  	pwm = devm_pwm_get(&pdev->dev, NULL);
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   82  	if (IS_ERR(pwm))
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   83  		return PTR_ERR(pwm);
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   84  
dd0b38b7ca0d8c Boris Brezillon 2016-04-14   85  	pwm_get_args(pwm, &pargs);
dd0b38b7ca0d8c Boris Brezillon 2016-04-14   86  	if (!pargs.period) {
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   87  		dev_err(&pdev->dev, "invalid PWM period\n");
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   88  		return -EINVAL;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   89  	}
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   90  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   91  	if (of_property_read_u32(node, "clock-frequency", &clk_pwm->fixed_rate))
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  @92  		clk_pwm->fixed_rate = NSEC_PER_SEC / pargs.period;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   93  
dd0b38b7ca0d8c Boris Brezillon 2016-04-14   94  	if (pargs.period != NSEC_PER_SEC / clk_pwm->fixed_rate &&
dd0b38b7ca0d8c Boris Brezillon 2016-04-14   95  	    pargs.period != DIV_ROUND_UP(NSEC_PER_SEC, clk_pwm->fixed_rate)) {
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   96  		dev_err(&pdev->dev,
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   97  			"clock-frequency does not match PWM period\n");
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   98  		return -EINVAL;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13   99  	}
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  100  
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  101  	/*
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  102  	 * FIXME: pwm_apply_args() should be removed when switching to the
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  103  	 * atomic PWM API.
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  104  	 */
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  105  	pwm_apply_args(pwm);
dd0b38b7ca0d8c Boris Brezillon 2016-04-14  106  	ret = pwm_config(pwm, (pargs.period + 1) >> 1, pargs.period);
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  107  	if (ret < 0)
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  108  		return ret;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  109  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  110  	clk_name = node->name;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  111  	of_property_read_string(node, "clock-output-names", &clk_name);
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  112  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  113  	init.name = clk_name;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  114  	init.ops = &clk_pwm_ops;
90b6c5c73c6904 Stephen Boyd    2019-04-25  115  	init.flags = 0;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  116  	init.num_parents = 0;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  117  
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  118  	clk_pwm->pwm = pwm;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  119  	clk_pwm->hw.init = &init;
4cf915dfb8ede6 Stephen Boyd    2016-06-01  120  	ret = devm_clk_hw_register(&pdev->dev, &clk_pwm->hw);
4cf915dfb8ede6 Stephen Boyd    2016-06-01  121  	if (ret)
4cf915dfb8ede6 Stephen Boyd    2016-06-01  122  		return ret;
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  123  
4cf915dfb8ede6 Stephen Boyd    2016-06-01  124  	return of_clk_add_hw_provider(node, of_clk_hw_simple_get, &clk_pwm->hw);
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  125  }
9a74ccdbbb8fa6 Philipp Zabel   2015-02-13  126  

:::::: The code at line 92 was first introduced by commit
:::::: dd0b38b7ca0d8c8aadcf8a17d7c90d36ab8ab6e4 clk: pwm: Use pwm_get_args() where appropriate

:::::: TO: Boris Brezillon <boris.brezillon@free-electrons.com>
:::::: CC: Thierry Reding <thierry.reding@gmail.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 5a7f659..81aa3c2 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1163,8 +1163,8 @@  static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
 		if (state.enabled)
 			seq_puts(s, " enabled");
 
-		seq_printf(s, " period: %u ns", state.period);
-		seq_printf(s, " duty: %u ns", state.duty_cycle);
+		seq_printf(s, " period: %llu ns", state.period);
+		seq_printf(s, " duty: %llu ns", state.duty_cycle);
 		seq_printf(s, " polarity: %s",
 			   state.polarity ? "inverse" : "normal");
 
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 2389b86..449dbc0 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -42,7 +42,7 @@  static ssize_t period_show(struct device *child,
 
 	pwm_get_state(pwm, &state);
 
-	return sprintf(buf, "%u\n", state.period);
+	return sprintf(buf, "%llu\n", state.period);
 }
 
 static ssize_t period_store(struct device *child,
@@ -52,10 +52,10 @@  static ssize_t period_store(struct device *child,
 	struct pwm_export *export = child_to_pwm_export(child);
 	struct pwm_device *pwm = export->pwm;
 	struct pwm_state state;
-	unsigned int val;
+	u64 val;
 	int ret;
 
-	ret = kstrtouint(buf, 0, &val);
+	ret = kstrtou64(buf, 0, &val);
 	if (ret)
 		return ret;
 
@@ -77,7 +77,7 @@  static ssize_t duty_cycle_show(struct device *child,
 
 	pwm_get_state(pwm, &state);
 
-	return sprintf(buf, "%u\n", state.duty_cycle);
+	return sprintf(buf, "%llu\n", state.duty_cycle);
 }
 
 static ssize_t duty_cycle_store(struct device *child,
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 0ef808d..b53f13d 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -39,7 +39,7 @@  enum pwm_polarity {
  * current PWM hardware state.
  */
 struct pwm_args {
-	unsigned int period;
+	u64 period;
 	enum pwm_polarity polarity;
 };
 
@@ -56,8 +56,8 @@  enum {
  * @enabled: PWM enabled status
  */
 struct pwm_state {
-	unsigned int period;
-	unsigned int duty_cycle;
+	u64 period;
+	u64 duty_cycle;
 	enum pwm_polarity polarity;
 	bool enabled;
 };
@@ -105,13 +105,13 @@  static inline bool pwm_is_enabled(const struct pwm_device *pwm)
 	return state.enabled;
 }
 
-static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
+static inline void pwm_set_period(struct pwm_device *pwm, u64 period)
 {
 	if (pwm)
 		pwm->state.period = period;
 }
 
-static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
+static inline u64 pwm_get_period(const struct pwm_device *pwm)
 {
 	struct pwm_state state;
 
@@ -126,7 +126,7 @@  static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
 		pwm->state.duty_cycle = duty;
 }
 
-static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
+static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm)
 {
 	struct pwm_state state;