diff mbox series

[2/3] pwm: atmel: use a constant for maximum prescale value

Message ID 20190815214133.11134-2-uwe@kleine-koenig.org
State Superseded
Headers show
Series [1/3] pwm: atmel: Add link to reference manual | expand

Commit Message

Uwe Kleine-König Aug. 15, 2019, 9:41 p.m. UTC
The maximal prescale value is 10 for all supported variants. So drop the
member in the variant description and introduce a global constant instead.

This reduces the size of the variant descriptions and the .apply() callback
can be compiled a bit more effectively.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 drivers/pwm/pwm-atmel.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Claudiu Beznea Aug. 19, 2019, 9:27 a.m. UTC | #1
On 16.08.2019 00:41, Uwe Kleine-König wrote:
> External E-Mail
> 
> 
> The maximal prescale value is 10 for all supported variants. So drop the
> member in the variant description and introduce a global constant instead.
> 
> This reduces the size of the variant descriptions and the .apply() callback
> can be compiled a bit more effectively.
> 
> Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>

Acked-by: Claudiu Beznea <claudiu.beznea@microchip.com>

Tested on SAMA5D2_Xplained.

> ---
>  drivers/pwm/pwm-atmel.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index ac3d7a200b9e..d7a6d32b5774 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -50,6 +50,8 @@
>  #define PWMV2_CPRD		0x0C
>  #define PWMV2_CPRDUPD		0x10
>  
> +#define PWM_MAX_PRES		10
> +
>  struct atmel_pwm_registers {
>  	u8 period;
>  	u8 period_upd;
> @@ -59,7 +61,6 @@ struct atmel_pwm_registers {
>  
>  struct atmel_pwm_config {
>  	u32 max_period;
> -	u32 max_pres;
>  };
>  
>  struct atmel_pwm_data {
> @@ -126,7 +127,7 @@ static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip,
>  	for (*pres = 0; cycles > atmel_pwm->data->cfg.max_period; cycles >>= 1)
>  		(*pres)++;
>  
> -	if (*pres > atmel_pwm->data->cfg.max_pres) {
> +	if (*pres > PWM_MAX_PRES) {
>  		dev_err(chip->dev, "pres exceeds the maximum value\n");
>  		return -EINVAL;
>  	}
> @@ -289,7 +290,6 @@ static const struct atmel_pwm_data atmel_sam9rl_pwm_data = {
>  	.cfg = {
>  		/* 16 bits to keep period and duty. */
>  		.max_period	= 0xffff,
> -		.max_pres	= 10,
>  	},
>  };
>  
> @@ -303,7 +303,6 @@ static const struct atmel_pwm_data atmel_sama5_pwm_data = {
>  	.cfg = {
>  		/* 16 bits to keep period and duty. */
>  		.max_period	= 0xffff,
> -		.max_pres	= 10,
>  	},
>  };
>  
> @@ -317,7 +316,6 @@ static const struct atmel_pwm_data mchp_sam9x60_pwm_data = {
>  	.cfg = {
>  		/* 32 bits to keep period and duty. */
>  		.max_period	= 0xffffffff,
> -		.max_pres	= 10,
>  	},
>  };
>  
>
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index ac3d7a200b9e..d7a6d32b5774 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -50,6 +50,8 @@ 
 #define PWMV2_CPRD		0x0C
 #define PWMV2_CPRDUPD		0x10
 
+#define PWM_MAX_PRES		10
+
 struct atmel_pwm_registers {
 	u8 period;
 	u8 period_upd;
@@ -59,7 +61,6 @@  struct atmel_pwm_registers {
 
 struct atmel_pwm_config {
 	u32 max_period;
-	u32 max_pres;
 };
 
 struct atmel_pwm_data {
@@ -126,7 +127,7 @@  static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip,
 	for (*pres = 0; cycles > atmel_pwm->data->cfg.max_period; cycles >>= 1)
 		(*pres)++;
 
-	if (*pres > atmel_pwm->data->cfg.max_pres) {
+	if (*pres > PWM_MAX_PRES) {
 		dev_err(chip->dev, "pres exceeds the maximum value\n");
 		return -EINVAL;
 	}
@@ -289,7 +290,6 @@  static const struct atmel_pwm_data atmel_sam9rl_pwm_data = {
 	.cfg = {
 		/* 16 bits to keep period and duty. */
 		.max_period	= 0xffff,
-		.max_pres	= 10,
 	},
 };
 
@@ -303,7 +303,6 @@  static const struct atmel_pwm_data atmel_sama5_pwm_data = {
 	.cfg = {
 		/* 16 bits to keep period and duty. */
 		.max_period	= 0xffff,
-		.max_pres	= 10,
 	},
 };
 
@@ -317,7 +316,6 @@  static const struct atmel_pwm_data mchp_sam9x60_pwm_data = {
 	.cfg = {
 		/* 32 bits to keep period and duty. */
 		.max_period	= 0xffffffff,
-		.max_pres	= 10,
 	},
 };