pwm: Add new helper to initialize a pwm_state variable with defaults
Subsystems (3)
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
This helps to convert drivers from the legacy API to pwm_apply_state without having to make the aware of the configured polarity (and in some cases even period).
--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
include/linux/pwm.h +10 -3
@@ -522,6 +522,15 @@ static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm) }#endif +static inline void pwm_get_state_default (const struct pwm_device *pwm, +struct pwm_state *state) +{ + state->period = pwm->args.period; + state->duty_cycle =0 ; + state->polarity = pwm->args.polarity; + state->enabled = false; +} +static inline void pwm_apply_args (struct pwm_device *pwm) {struct pwm_state state = { };
@@ -547,9 +556,7 @@ static inline void pwm_apply_args(struct pwm_device *pwm)* pwm_apply_args(). */ - state.enabled = false; - state.polarity = pwm->args.polarity; - state.period = pwm->args.period; +pwm_get_state_default (pwm, &state);pwm_apply_state (pwm, &state); }
Signature · 1 line
2.19.1
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
The legacy PWM API should be removed in the long run, so convert a user to the atomic PWM API.
--- arch/arm/mach-s3c24xx/mach-rx1950.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
arch/arm/mach-s3c24xx/mach-rx1950.c +9 -9
@@ -375,6 +375,7 @@ static struct pwm_lookup rx1950_pwm_lookup[] = { PWM_POLARITY_NORMAL), }; +static struct pwm_state lcd_pwm_state;static struct pwm_device *lcd_pwm;static void rx1950_lcd_power (int enable)
@@ -428,15 +429,17 @@ static void rx1950_lcd_power(int enable)/* GPB1->OUTPUT, GPB1->0 */ gpio_direction_output (S3C2410_GPB (1 ),0 ); -pwm_config (lcd_pwm,0 ,LCD_PWM_PERIOD ); -pwm_disable (lcd_pwm); + lcd_pwm_state.duty_cycle =0 ; + lcd_pwm_state.enabled = false; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);/* GPC0->0, GPC10->0 */ gpio_direction_output (S3C2410_GPC (0 ),0 );gpio_direction_output (S3C2410_GPC (10 ),0 ); }else { -pwm_config (lcd_pwm,LCD_PWM_DUTY ,LCD_PWM_PERIOD ); -pwm_enable (lcd_pwm); + lcd_pwm_state.duty_cycle =LCD_PWM_DUTY ; + lcd_pwm_state.enabled = true; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);gpio_direction_output (S3C2410_GPC (0 ),1 );gpio_direction_output (S3C2410_GPC (5 ),1 );
@@ -491,11 +494,8 @@ static int rx1950_backlight_init(struct device *dev)return PTR_ERR (lcd_pwm); } -/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (lcd_pwm); +pwm_get_state_default (lcd_pwm, &lcd_pwm_state); + lcd_pwm_state.period =LCD_PWM_PERIOD ;rx1950_lcd_power (1 );rx1950_bl_power (1 );
Signature · 1 line
2.19.1
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
Quoted 8 lines · Uwe Kleine-K?nig
The legacy PWM API should be removed in the long run, so convert a user to the atomic PWM API.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- arch/arm/mach-s3c24xx/mach-rx1950.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
I see this depends on first patch so I assume this will go through pwm tree.
Best regards,
Krzysztof
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
Quoted 6 lines · Krzysztof Kozlowski
Quoted 4 lines · Uwe Kleine-K?nig
The legacy PWM API should be removed in the long run, so convert a user to the atomic PWM API.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- arch/arm/mach-s3c24xx/mach-rx1950.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)Reviewed-by Krzysztof Kozlowski <[email protected]>I see this depends on first patch so I assume this will go through pwm tree.
Right, I assume so, too. Unfortunately I didn't hear anything back from Thierry about this because there seems to be a mail reception problem on his end.
@Thierry: Could you find the problem? It would be great to get some feedback from you regarding these patches. There are more pwm users that could benefit from this change, but I first want some feedback about this before investing more time here.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
In reply to Uwe Kleine-KönigQuoted 13 lines · Uwe Kleine-K?nig
The legacy PWM API should be removed in the long run, so convert a user to the atomic PWM API.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- arch/arm/mach-s3c24xx/mach-rx1950.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)arch/arm/mach-s3c24xx/mach-rx1950.c +0
-0
arch/arm/mach-s3c24xx/mach-rx1950.c static struct pwm_lookup rx1950_pwm_lookup[] = { · line 378
Quoted 4 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +1
-0@@ -375,6 +375,7 @@ static struct pwm_lookup rx1950_pwm_lookup[] = { PWM_POLARITY_NORMAL), }; +static struct pwm_state lcd_pwm_state;
You shouldn't need this. The whole point of the atomic API is that the PWM carries its state, so the proper way to make a change is to query the current state, make any required modifications and then apply the new state.
arch/arm/mach-s3c24xx/mach-rx1950.c static void rx1950_lcd_power(int enable) · line 434
Quoted 12 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +3
-2static struct pwm_device *lcd_pwm;static void rx1950_lcd_power (int enable)@@ -428,15 +429,17 @@ static void rx1950_lcd_power(int enable)/* GPB1->OUTPUT, GPB1->0 */ gpio_direction_output (S3C2410_GPB (1 ),0 ); -pwm_config (lcd_pwm,0 ,LCD_PWM_PERIOD ); -pwm_disable (lcd_pwm); + lcd_pwm_state.duty_cycle =0 ; + lcd_pwm_state.enabled = false; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);
The correct way to do this would be:
struct pwm_state state; pwm_get_state(lcd_pwm, &state); state.enabled = false; state.duty_cycle = 0; pwm_apply_state(lcd_pwm, &state);
arch/arm/mach-s3c24xx/mach-rx1950.c static void rx1950_lcd_power(int enable) · line 442
Quoted 10 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +3
-2/* GPC0->0, GPC10->0 */ gpio_direction_output (S3C2410_GPC (0 ),0 );gpio_direction_output (S3C2410_GPC (10 ),0 ); }else { -pwm_config (lcd_pwm,LCD_PWM_DUTY ,LCD_PWM_PERIOD ); -pwm_enable (lcd_pwm); + lcd_pwm_state.duty_cycle =LCD_PWM_DUTY ; + lcd_pwm_state.enabled = true; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);
Similarily here.
Quoted 4 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +0
-0gpio_direction_output (S3C2410_GPC (0 ),1 );gpio_direction_output (S3C2410_GPC (5 ),1 );
arch/arm/mach-s3c24xx/mach-rx1950.c static int rx1950_backlight_init(struct device *dev) · line 498
Quoted 10 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +2
-5@@ -491,11 +494,8 @@ static int rx1950_backlight_init(struct device *dev)return PTR_ERR (lcd_pwm); } -/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (lcd_pwm); +pwm_get_state_default (lcd_pwm, &lcd_pwm_state); + lcd_pwm_state.period =LCD_PWM_PERIOD ;
This is wrong, though it's probably because the comment is also confusing. There should be nothing wrong with using pwm_apply_args() in this case.
While at it, I think the conversion should also be include replacing the call to pwm_request() by pwm_get(). There's already a PWM lookup table in the RX1950 board code, so pwm_get() would be able to use that. Note that for some reason that table contains a period that is different from LCD_PWM_PERIOD, so I think that should also be addressed. Basically all the information other than duty cycle should be coming from either DT or a lookup table.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181114/016e5051/attachment.sig>
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
Hello Thierry,
Quoted 7 lines · Thierry Reding
Quoted 1 line · Uwe Kleine-K?nig
+static struct
pwm_statelcd_pwm_state;You shouldn't need this. The whole point of the atomic API is that the PWM carries its state, so the proper way to make a change is to query the current state, make any required modifications and then apply the new state.
I thought the whole point of the atomic API is to be atomic :-)
Quoted 15 lines
arch/arm/mach-s3c24xx/mach-rx1950.c static void rx1950_lcd_power(int enable) · line 434
Quoted 12 lines
static struct
pwm_device*lcd_pwm;static void
rx1950_lcd_power(int enable)arch/arm/mach-s3c24xx/mach-rx1950.c +3
-2@@ -428,15 +429,17 @@ static void rx1950_lcd_power(int enable)/* GPB1->OUTPUT, GPB1->0 */ gpio_direction_output (S3C2410_GPB (1 ),0 ); -pwm_config (lcd_pwm,0 ,LCD_PWM_PERIOD ); -pwm_disable (lcd_pwm); + lcd_pwm_state.duty_cycle =0 ; + lcd_pwm_state.enabled = false; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);The correct way to do this would be:
Quoted 6 lines
struct pwm_state state; pwm_get_state(lcd_pwm, &state); state.enabled = false; state.duty_cycle = 0; pwm_apply_state(lcd_pwm, &state);
The difference here is that with my approach the rx1950 driver caches the intended pwm_state saving a few cycles for repeatedly copying the pwm cache to a stack variable at the cost of some memory. I like my approach a little better but I'm not willing to argue about that one and can give in.
Quoted 6 lines
Quoted 6 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +0
-0gpio_direction_output (S3C2410_GPC (0 ),1 );gpio_direction_output (S3C2410_GPC (5 ),1 );@@ -491,11 +494,8 @@ static int rx1950_backlight_init(struct device *dev)return PTR_ERR (lcd_pwm); }
Quoted 11 lines
arch/arm/mach-s3c24xx/mach-rx1950.c static int rx1950_backlight_init(struct device *dev) · line 498
Quoted 7 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +2
-5-/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (lcd_pwm); +pwm_get_state_default (lcd_pwm, &lcd_pwm_state); + lcd_pwm_state.period =LCD_PWM_PERIOD ;This is wrong, though it's probably because the comment is also confusing. There should be nothing wrong with using
pwm_apply_args()in this case.
In my eyes it is wrong because it results in a call to the backend driver's apply callback to get the default setting just to fix the configuration and apply that in the code to follow.
Quoted 7 lines
While at it, I think the conversion should also be include replacing the call to
pwm_request()bypwm_get(). There's already a PWM lookup table in the RX1950 board code, sopwm_get()would be able to use that. Note that for some reason that table contains a period that is different fromLCD_PWM_PERIOD, so I think that should also be addressed. Basically all the information other than duty cycle should be coming from either DT or a lookup table.
Yeah, I noticed that, too. It's not entirely clear to me how to do that yet. So I thought to care about getting rid of the legacy usage of pwm_config and pwm_apply_args first.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
Quoted 35 lines · Uwe Kleine-K?nig
Hello Thierry,
Quoted 7 lines · Thierry Reding
Quoted 1 line · Uwe Kleine-K?nig
+static struct
pwm_statelcd_pwm_state;You shouldn't need this. The whole point of the atomic API is that the PWM carries its state, so the proper way to make a change is to query the current state, make any required modifications and then apply the new state.
I thought the whole point of the atomic API is to be atomic :-)
Quoted 15 lines
arch/arm/mach-s3c24xx/mach-rx1950.c static void rx1950_lcd_power(int enable) · line 434
Quoted 12 lines
static struct
pwm_device*lcd_pwm;static void
rx1950_lcd_power(int enable)arch/arm/mach-s3c24xx/mach-rx1950.c +3
-2@@ -428,15 +429,17 @@ static void rx1950_lcd_power(int enable)/* GPB1->OUTPUT, GPB1->0 */ gpio_direction_output (S3C2410_GPB (1 ),0 ); -pwm_config (lcd_pwm,0 ,LCD_PWM_PERIOD ); -pwm_disable (lcd_pwm); + lcd_pwm_state.duty_cycle =0 ; + lcd_pwm_state.enabled = false; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);The correct way to do this would be:
Quoted 6 lines
struct pwm_state state; pwm_get_state(lcd_pwm, &state); state.enabled = false; state.duty_cycle = 0; pwm_apply_state(lcd_pwm, &state);
Quoted 5 lines
The difference here is that with my approach the rx1950 driver caches the intended
pwm_statesaving a few cycles for repeatedly copying the pwm cache to a stack variable at the cost of some memory. I like my approach a little better but I'm not willing to argue about that one and can give in.
It's a redundant copy of the PWM's internal state and not guaranteed to remain in sync with the PWM hardware state. You also require a global variable, which is usually a bad idea. And we're not repeatedly copying data. We occasionally do. These operations are typically only executed once or twice per boot, so hardly anything that needs to be optimized for speed.
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +0
-0gpio_direction_output (S3C2410_GPC (0 ),1 );gpio_direction_output (S3C2410_GPC (5 ),1 );@@ -491,11 +494,8 @@ static int rx1950_backlight_init(struct device *dev)return PTR_ERR (lcd_pwm); }Quoted 11 lines
arch/arm/mach-s3c24xx/mach-rx1950.c static int rx1950_backlight_init(struct device *dev) · line 498
Quoted 7 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +2
-5-/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (lcd_pwm); +pwm_get_state_default (lcd_pwm, &lcd_pwm_state); + lcd_pwm_state.period =LCD_PWM_PERIOD ;This is wrong, though it's probably because the comment is also confusing. There should be nothing wrong with using
pwm_apply_args()in this case.
Quoted 3 lines
In my eyes it is wrong because it results in a call to the backend driver's apply callback to get the default setting just to fix the configuration and apply that in the code to follow.
Okay, I see. But there's already pwm_init_state() which pretty much does what you do here, right?
Thinking about it some more, I wonder if we shouldn't be more consistent about state handling here. So the reason why pwm_apply_args() exists is to program the PWM with a known state if the PWM doesn't support hardware readout. Since most drivers don't support hardware readout, we need this to at some specific point synchronize the hardware and internal states.
In retrospect I'm not sure that's necessary, because there's more and more evidence that we don't want to touch a PWM configuration until a consumer explicitly says so. There's also the slight problem that the pwm_apply_args() is really only necessary if the PWM driver doesn't support hardware readout, but that's not something that consumers are aware of or should worry about.
In light of that I think perhaps a better solution would be to basically apply the PWM arguments to the internal state at request time. We can't do it earlier because we don't know the arguments before the PWM is requested. So I think at request time we could do something like this:
if (chip->ops->get_state) chip->ops->get_state(chip, pwm, &pwm->state); else pwm_init_state(pwm, &pwm->state);
That way drivers always get either the current state or the "default" state that was configured via platform-specific means (DT or lookup).
Quoted 11 lines
Quoted 7 lines
While at it, I think the conversion should also be include replacing the call to
pwm_request()bypwm_get(). There's already a PWM lookup table in the RX1950 board code, sopwm_get()would be able to use that. Note that for some reason that table contains a period that is different fromLCD_PWM_PERIOD, so I think that should also be addressed. Basically all the information other than duty cycle should be coming from either DT or a lookup table.Yeah, I noticed that, too. It's not entirely clear to me how to do that yet. So I thought to care about getting rid of the legacy usage of
pwm_configandpwm_apply_argsfirst.
So I think I got the backlight PWM confused with the LCD PWM. The former is what we have in the PWM lookup table and which controls the backlight brightness. The latter is what we don't have in the table and which is requested using the legacy pwm_request() function. That also explains why there's a difference between the period in the PWM lookup table for the backlight PWM and the LCD_PWM_PERIOD macro.
Adding support for pwm_get() should be as simple ad adding an entry to rx1950_pwm_lookup[], such as this:
PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", "lcd", 192960,
PWM_POLARITY_NORMAL),Then in rx1950_backlight_init(), which is passed the device structure that represents the backlight (i.e. "pwm-backlight.0"), pwm_get() can be called like this:
lcd_pwm = pwm_get(dev, "lcd");
The matching code should then be able to find the second entry as the best match and return the correct one.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181115/e4101d15/attachment.sig>
PATCH 2/4 ARM: S3C24XX: rx1950: make use of atomic PWM API
Hello Thierry,
Quoted 26 lines · Thierry Reding
Quoted 25 lines · Uwe Kleine-K?nig
Quoted 23 lines · Thierry Reding
arch/arm/mach-s3c24xx/mach-rx1950.c static void rx1950_lcd_power(int enable) · line 434
Quoted 13 lines · Uwe Kleine-K?nig
arch/arm/mach-s3c24xx/mach-rx1950.c +4
-2+static struct pwm_state lcd_pwm_state;static struct pwm_device *lcd_pwm;static void rx1950_lcd_power (int enable)@@ -428,15 +429,17 @@ static void rx1950_lcd_power(int enable)/* GPB1->OUTPUT, GPB1->0 */ gpio_direction_output (S3C2410_GPB (1 ),0 ); -pwm_config (lcd_pwm,0 ,LCD_PWM_PERIOD ); -pwm_disable (lcd_pwm); + lcd_pwm_state.duty_cycle =0 ; + lcd_pwm_state.enabled = false; +pwm_apply_state (lcd_pwm, &lcd_pwm_state);The correct way to do this would be:
struct pwm_state state; pwm_get_state(lcd_pwm, &state); state.enabled = false; state.duty_cycle = 0; pwm_apply_state(lcd_pwm, &state);
Quoted 7 lines
Quoted 5 lines
The difference here is that with my approach the rx1950 driver caches the intended
pwm_statesaving a few cycles for repeatedly copying the pwm cache to a stack variable at the cost of some memory. I like my approach a little better but I'm not willing to argue about that one and can give in.It's a redundant copy of the PWM's internal state
That the pwm keeps a copy of this is an implementation detail of the pwm framework that shouldn't matter to its consumers.
Quoted 1 line
and not guaranteed to remain in sync with the PWM hardware state.
What should happen that the driver's pwm_state and the hardware state diverge?
Quoted 1 line
You also require a global variable, which is usually a bad idea.
Right, but that's attributable to the fact, that the struct pwm_device is a global variable, too.
Quoted 36 lines
And we're not repeatedly copying data. We occasionally do. These operations are typically only executed once or twice per boot, so hardly anything that needs to be optimized for speed.
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +0
-0gpio_direction_output (S3C2410_GPC (0 ),1 );gpio_direction_output (S3C2410_GPC (5 ),1 );@@ -491,11 +494,8 @@ static int rx1950_backlight_init(struct device *dev)return PTR_ERR (lcd_pwm); }Quoted 11 lines
arch/arm/mach-s3c24xx/mach-rx1950.c static int rx1950_backlight_init(struct device *dev) · line 498
Quoted 7 lines
arch/arm/mach-s3c24xx/mach-rx1950.c +2
-5-/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (lcd_pwm); +pwm_get_state_default (lcd_pwm, &lcd_pwm_state); + lcd_pwm_state.period =LCD_PWM_PERIOD ;This is wrong, though it's probably because the comment is also confusing. There should be nothing wrong with using
pwm_apply_args()in this case.Quoted 3 lines
In my eyes it is wrong because it results in a call to the backend driver's apply callback to get the default setting just to fix the configuration and apply that in the code to follow.
Okay, I see. But there's already
pwm_init_state()which pretty much does what you do here, right?Thinking about it some more, I wonder if we shouldn't be more consistent about state handling here. So the reason why
pwm_apply_args()exists is to program the PWM with a known state if the PWM doesn't support hardware readout. Since most drivers don't support hardware readout, we need this to at some specific point synchronize the hardware and internal states.
Quoted 6 lines
In retrospect I'm not sure that's necessary, because there's more and more evidence that we don't want to touch a PWM configuration until a consumer explicitly says so. There's also the slight problem that the
pwm_apply_args()is really only necessary if the PWM driver doesn't support hardware readout, but that's not something that consumers are aware of or should worry about.
I consider your words as a light in the tunnel. Maybe we will reach a conclusion eventually.
Quoted 5 lines
In light of that I think perhaps a better solution would be to basically apply the PWM arguments to the internal state at request time. We can't do it earlier because we don't know the arguments before the PWM is requested. So I think at request time we could do something like this:
Quoted 7 lines
if (chip->ops->get_state) chip->ops->get_state(chip, pwm, &pwm->state); else pwm_init_state(pwm, &pwm->state);That way drivers always get either the current state or the "default" state that was configured via platform-specific means (DT or lookup).
I think a gap in this reasoning is that if the DT dictates a period of say 1 ms and the hardware is configured to something else, the consumer should still work with the 1 ms value.
Quoted 25 lines
Quoted 11 lines
Quoted 7 lines
While at it, I think the conversion should also be include replacing the call to
pwm_request()bypwm_get(). There's already a PWM lookup table in the RX1950 board code, sopwm_get()would be able to use that. Note that for some reason that table contains a period that is different fromLCD_PWM_PERIOD, so I think that should also be addressed. Basically all the information other than duty cycle should be coming from either DT or a lookup table.Yeah, I noticed that, too. It's not entirely clear to me how to do that yet. So I thought to care about getting rid of the legacy usage of
pwm_configandpwm_apply_argsfirst.So I think I got the backlight PWM confused with the LCD PWM. The former is what we have in the PWM lookup table and which controls the backlight brightness. The latter is what we don't have in the table and which is requested using the legacy
pwm_request()function. That also explains why there's a difference between the period in the PWM lookup table for the backlight PWM and theLCD_PWM_PERIODmacro.Adding support for
pwm_get()should be as simple ad adding an entry to rx1950_pwm_lookup[], such as this:PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", "lcd", 192960, PWM_POLARITY_NORMAL),
Quoted 8 lines
Then in
rx1950_backlight_init(), which is passed the device structure that represents the backlight (i.e. "pwm-backlight.0"),pwm_get()can be called like this:lcd_pwm = pwm_get(dev, "lcd");The matching code should then be able to find the second entry as the best match and return the correct one.
Does this lookup belong to the board file or to a more general place near the provider of the "samsung-pwm" devices?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 3/4 bus: ts-nbus: convert to atomic PWM API
In reply to Uwe Kleine-KönigThe legacy PWM API should be removed in the long run, so convert a user to the atomic PWM API.
--- drivers/bus/ts-nbus.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
drivers/bus/ts-nbus.c +7 -13
@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(ts_nbus_write);static int ts_nbus_probe (struct platform_device *pdev) {struct pwm_device *pwm; -struct pwm_args pargs; +struct pwm_state pstate;struct device *dev = &pdev->dev;struct ts_nbus *ts_nbus;int ret;
@@ -305,25 +305,19 @@ static int ts_nbus_probe(struct platform_device *pdev)return ret; } -pwm_get_args (pwm, &pargs); -if (!pargs.period) { +pwm_get_state_default (pwm, &pstate); +if (!pstate.period) {dev_err (&pdev->dev,"invalid PWM period\n" );return -EINVAL ; } -/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (pwm); - ret =pwm_config (pwm, pargs.period, pargs.period); +/* We can start the FPGA and populate the peripherals now. */ + pstate.enabled = true; + pstate.duty_cycle = pstate.period; + ret =pwm_apply_state (pwm, &pstate);if (ret <0 )return ret; -/* -* we can now start the FPGA and populate the peripherals. -*/ -pwm_enable (pwm); ts_nbus->pwm = pwm;/*
Signature · 1 line
2.19.1
PATCH 3/4 bus: ts-nbus: convert to atomic PWM API
Quoted 43 lines · Uwe Kleine-K?nig
The legacy PWM API should be removed in the long run, so convert a user to the atomic PWM API.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- drivers/bus/ts-nbus.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)drivers/bus/ts-nbus.c +7
-9@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(ts_nbus_write);static int ts_nbus_probe (struct platform_device *pdev) {struct pwm_device *pwm; -struct pwm_args pargs; +struct pwm_state pstate;struct device *dev = &pdev->dev;struct ts_nbus *ts_nbus;int ret;@@ -305,25 +305,19 @@ static int ts_nbus_probe(struct platform_device *pdev)return ret; } -pwm_get_args (pwm, &pargs); -if (!pargs.period) { +pwm_get_state_default (pwm, &pstate); +if (!pstate.period) {dev_err (&pdev->dev,"invalid PWM period\n" );return -EINVAL ; } -/* -* FIXME: pwm_apply_args() should be removed when switching to -* the atomic PWM API. -*/ -pwm_apply_args (pwm); - ret =pwm_config (pwm, pargs.period, pargs.period); +/* We can start the FPGA and populate the peripherals now. */ + pstate.enabled = true; + pstate.duty_cycle = pstate.period; + ret =pwm_apply_state (pwm, &pstate);
drivers/bus/ts-nbus.c static int ts_nbus_probe(struct platform_device *pdev) · line 323
Quoted 10 lines
drivers/bus/ts-nbus.c +0
-4if (ret <0 )return ret; -/* -* we can now start the FPGA and populate the peripherals. -*/ -pwm_enable (pwm); ts_nbus->pwm = pwm;/*
This looks suspiciously like the PWM is actually powering this bus. It would've been better to model that as a PWM driven regulator rather than an PWM consumer.
Either way I don't see why pwm_get_state_default() would be useful here.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181114/6e41b905/attachment.sig>
PATCH 4/4 bus: ts-nbus: weaken driver dependency to allow broader compile testing
In reply to Uwe Kleine-KönigThere is nothing specific for the i.MX28 SoC in the ts-nbus driver and it compiles just fine with an ARM/s3c24xx configuration.
--- drivers/bus/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/Kconfig +1 -1
@@ -149,7 +149,7 @@ config TI_SYSC config TS_NBUS tristate "Technologic Systems NBUS Driver" - depends on SOC_IMX28 + depends on SOC_IMX28 || COMPILE_TEST depends on OF_GPIO && PWM help Driver for the Technologic Systems NBUS which is used to interface
Signature · 1 line
2.19.1
PATCH 4/4 bus: ts-nbus: weaken driver dependency to allow broader compile testing
Quoted 7 lines · Uwe Kleine-K?nig
There is nothing specific for the i.MX28 SoC in the ts-nbus driver and it compiles just fine with an ARM/s3c24xx configuration.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- drivers/bus/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Looks like Sebastien's email no longer exists. Seeing that this driver was merged a year ago and doesn't have any in-kernel users I wonder if there's any use in keeping it.
Arnd, this looks completely dead at this point and it doesn't seem like this ever had any users, should we remove it?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181114/ca9804ba/attachment.sig>
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
In reply to Uwe Kleine-KönigQuoted 8 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
You're going to have to at least Cc me on patches 2 & 3 so that I can see how you intend this to be used.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181029/66f34692/attachment.sig>
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
Hello Thierry,
Quoted 5 lines · Thierry Reding
Quoted 4 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).
Quoted 7 lines
Quoted 4 lines
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)You're going to have to at least Cc me on patches 2 & 3 so that I can see how you intend this to be used.
you were in To: for all four patches:
patch 1: https://www.spinics.net/lists/linux-pwm/msg08178.html
patch 2: https://www.spinics.net/lists/linux-pwm/msg08179.html
patch 3: https://www.spinics.net/lists/linux-pwm/msg08180.html
patch 4: https://www.spinics.net/lists/linux-pwm/msg08181.html
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
Hello,
Quoted 14 lines · Uwe Kleine-K?nig
Quoted 5 lines · Thierry Reding
Quoted 4 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Quoted 7 lines
Quoted 4 lines
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)You're going to have to at least Cc me on patches 2 & 3 so that I can see how you intend this to be used.
Quoted 6 lines
you were in To: for all four patches:
patch 1: https://www.spinics.net/lists/linux-pwm/msg08178.html
patch 2: https://www.spinics.net/lists/linux-pwm/msg08179.html
patch 3: https://www.spinics.net/lists/linux-pwm/msg08180.html
patch 4: https://www.spinics.net/lists/linux-pwm/msg08181.html
Did you find those in your mailbox in the meantime? If google just failed to put them in your inbox I can send you a bounce of 2 and 3 if you want to. Just tell me (in irc if you want to).
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
In reply to Uwe Kleine-KönigQuoted 8 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
So if I understand your intention correctly here you want consumers to be able to get at the default state, which would be the state as it was "configured" in DT or the PWM lookup table so that you can modify that state (well, really just setting the duty-cycle) before you actually send the state to the hardware.
So the difference to pwm_apply_args() is that you don't want the driver to specifically program a duty cycle of 0 before setting the actual duty cycle that you want to set.
Is that about right?
Isn't that exactly what pwm_init_state() already does? pwm-backlight uses it for exactly the same purpose that you seem to be using it in RX1950 backlight control.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181114/493f7c6e/attachment-0001.sig>
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
Hello Thierry,
Quoted 16 lines · Thierry Reding
Quoted 8 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)So if I understand your intention correctly here you want consumers to be able to get at the default state, which would be the state as it was "configured" in DT or the PWM lookup table so that you can modify that state (well, really just setting the duty-cycle) before you actually send the state to the hardware.
Quoted 5 lines
So the difference to
pwm_apply_args()is that you don't want the driver to specifically program a duty cycle of 0 before setting the actual duty cycle that you want to set.Is that about right?
Yes, and a resulting advantage is that the apply callback is only called once.
Quoted 3 lines
Isn't that exactly what
pwm_init_state()already does? pwm-backlight uses it for exactly the same purpose that you seem to be using it in RX1950 backlight control.
I didn't use pwm_init_state because that doesn't give a helpful value for state->enabled. (I think it is: if the driver provides a get_state callback it is whatever that one set, otherwise it's off.) Also the name pwm_init_state isn't that good IMHO. Just from the name I'd expect it to be something like
memset(state, 0, sizeof(&state));
instead of something more informed that depends on hardware state and/or data provided by a device tree.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
Quoted 28 lines · Uwe Kleine-K?nig
Hello Thierry,
Quoted 16 lines · Thierry Reding
Quoted 8 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)So if I understand your intention correctly here you want consumers to be able to get at the default state, which would be the state as it was "configured" in DT or the PWM lookup table so that you can modify that state (well, really just setting the duty-cycle) before you actually send the state to the hardware.
Quoted 5 lines
So the difference to
pwm_apply_args()is that you don't want the driver to specifically program a duty cycle of 0 before setting the actual duty cycle that you want to set.Is that about right?
Yes, and a resulting advantage is that the apply callback is only called once.
Quoted 7 lines
Quoted 3 lines
Isn't that exactly what
pwm_init_state()already does? pwm-backlight uses it for exactly the same purpose that you seem to be using it in RX1950 backlight control.I didn't use
pwm_init_statebecause that doesn't give a helpful value forstate->enabled. (I think it is: if the driver provides aget_statecallback it is whatever that one set, otherwise it's off.)
That's correct. It's pretty much the same thing that you have, except you explicitly set enable = false. But that's not really important because consumers are supposed to explicitly override that anyway.
Quoted 7 lines
Also the name
pwm_init_stateisn't that good IMHO. Just from the name I'd expect it to be something likememset(state, 0, sizeof(&state));instead of something more informed that depends on hardware state and/or data provided by a device tree.
Be that as it may, the kerneldoc is pretty explicit about what it does and so is the code. Not liking the name shouldn't be an excuse for duplicating functionality.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181115/775d5c3a/attachment.sig>
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
Hello Thierry,
Quoted 31 lines · Thierry Reding
Quoted 30 lines · Uwe Kleine-K?nig
Quoted 16 lines · Thierry Reding
Quoted 8 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)So if I understand your intention correctly here you want consumers to be able to get at the default state, which would be the state as it was "configured" in DT or the PWM lookup table so that you can modify that state (well, really just setting the duty-cycle) before you actually send the state to the hardware.
Quoted 5 lines
So the difference to
pwm_apply_args()is that you don't want the driver to specifically program a duty cycle of 0 before setting the actual duty cycle that you want to set.Is that about right?
Yes, and a resulting advantage is that the apply callback is only called once.
Quoted 3 lines
Isn't that exactly what
pwm_init_state()already does? pwm-backlight uses it for exactly the same purpose that you seem to be using it in RX1950 backlight control.
Quoted 7 lines
Quoted 3 lines
I didn't use
pwm_init_statebecause that doesn't give a helpful value forstate->enabled. (I think it is: if the driver provides aget_statecallback it is whatever that one set, otherwise it's off.)That's correct. It's pretty much the same thing that you have, except you explicitly set enable = false. But that's not really important because consumers are supposed to explicitly override that anyway.
If we hardcode to enable=false the call to pwm_get_state could be dropped, too. Then the two functions are really semantically identical.
Quoted 4 lines
Quoted 4 lines
Also the name
pwm_init_stateisn't that good IMHO. Just from the name I'd expect it to be something like
Quoted 8 lines
Quoted 4 lines
memset(state, 0, sizeof(&state));instead of something more informed that depends on hardware state and/or data provided by a device tree.
Be that as it may, the kerneldoc is pretty explicit about what it does and so is the code. Not liking the name shouldn't be an excuse for duplicating functionality.
With your suggestion to move the initialisation of ->state into the core, maybe this function can go away from the public API such that the naming doesn't really matter (and can be adapted easily).
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/4 pwm: Add new helper to initialize a pwm_state variable with defaults
Quoted 53 lines · Uwe Kleine-K?nig
Hello Thierry,
Quoted 31 lines · Thierry Reding
Quoted 30 lines · Uwe Kleine-K?nig
Quoted 16 lines · Thierry Reding
Quoted 8 lines · Uwe Kleine-K?nig
This helps to convert drivers from the legacy API to
pwm_apply_statewithout having to make the aware of the configured polarity (and in some cases even period).Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/pwm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)So if I understand your intention correctly here you want consumers to be able to get at the default state, which would be the state as it was "configured" in DT or the PWM lookup table so that you can modify that state (well, really just setting the duty-cycle) before you actually send the state to the hardware.
Quoted 5 lines
So the difference to
pwm_apply_args()is that you don't want the driver to specifically program a duty cycle of 0 before setting the actual duty cycle that you want to set.Is that about right?
Yes, and a resulting advantage is that the apply callback is only called once.
Quoted 3 lines
Isn't that exactly what
pwm_init_state()already does? pwm-backlight uses it for exactly the same purpose that you seem to be using it in RX1950 backlight control.Quoted 7 lines
Quoted 3 lines
I didn't use
pwm_init_statebecause that doesn't give a helpful value forstate->enabled. (I think it is: if the driver provides aget_statecallback it is whatever that one set, otherwise it's off.)That's correct. It's pretty much the same thing that you have, except you explicitly set enable = false. But that's not really important because consumers are supposed to explicitly override that anyway.
If we hardcode to enable=false the call to
pwm_get_statecould be dropped, too. Then the two functions are really semantically identical.Quoted 9 lines
Quoted 8 lines
Also the name
pwm_init_stateisn't that good IMHO. Just from the name I'd expect it to be something likememset(state, 0, sizeof(&state));instead of something more informed that depends on hardware state and/or data provided by a device tree.
Quoted 7 lines
Quoted 3 lines
Be that as it may, the kerneldoc is pretty explicit about what it does and so is the code. Not liking the name shouldn't be an excuse for duplicating functionality.
With your suggestion to move the initialisation of ->state into the core, maybe this function can go away from the public API such that the naming doesn't really matter (and can be adapted easily).
Yeah, I think it would be best to move it into core.c and make it static in that case. There should be no need for anyone to create any special state, they can just use pwm_get_state() instead.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181116/621c9ecc/attachment.sig>