From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:44:40
Hello,
Changes since v4:
- Commit message for patch #7 (DT binding for the leds-pwm driver) has been
updated
Changes since v3:
Addressed comments from Thierry Redding:
- DT binding documentation for leds-pwm updated
- of_pwm_request() renamed as of_pwm_get()
- introduction of devm_of_pwm_get()
- Commit message updates
- Other comments has been also addressed
- Acked-by from Grant is not added to the patches since they were modified since
v3
Changes since v2:
- rebased on top of linux-next
- DT bindings now alligned with Grant's request
- exporting of_pwm_request() from PWM core to allow clean DT bindings
- DT binding documentation changed to reflect the changes
Changes since v1:
- As suggested by Bryan Wu: the legacy pwm_request() has been removed from
patch 1
- Device tree bindings added for leds-pwm driver.
When we boot with Device tree we handle one LED per device to be more aligned
with PWM core's DT implementation.
An example of the DT usage is provided in the new DT binding documentation for
leds-pwm.
Tested on OMAP4 Blaze (SDP), BeagleBoard with legacy and DT boot. On Zoom2 with
legacy boot.
Regards,
Peter
---
Peter Ujfalusi (7):
leds: leds-pwm: Convert to use devm_get_pwm
leds: leds-pwm: Preparing the driver for device tree support
pwm: Correct parameter name in header for *pwm_get() functions
pwm: core: Rename of_pwm_request() to of_pwm_get() and export it
pwm: Add devm_of_pwm_get() as exported API for users
leds: leds-pwm: Simplify cleanup code
leds: leds-pwm: Add device tree bindings
.../devicetree/bindings/leds/leds-pwm.txt | 48 +++++++
drivers/leds/leds-pwm.c | 152 +++++++++++++++------
drivers/pwm/core.c | 38 +++++-
include/linux/leds_pwm.h | 2 +-
include/linux/pwm.h | 20 ++-
5 files changed, 212 insertions(+), 48 deletions(-)
create mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.txt
--
1.8.0.2
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:44:28
In order to be able to add device tree support for leds-pwm driver we need
to rearrange the data structures used by the drivers.
Signed-off-by: Peter Ujfalusi <redacted>
---
drivers/leds/leds-pwm.c | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:44:54
Update the driver to use the new API for requesting pwm so we can take
advantage of the pwm_lookup table to find the correct pwm to be used for the
LED functionality.
Signed-off-by: Peter Ujfalusi <redacted>
---
drivers/leds/leds-pwm.c | 19 ++++++-------------
include/linux/leds_pwm.h | 2 +-
2 files changed, 7 insertions(+), 14 deletions(-)
@@ -67,12 +67,11 @@ static int led_pwm_probe(struct platform_device *pdev)cur_led=&pdata->leds[i];led_dat=&leds_data[i];-led_dat->pwm=pwm_request(cur_led->pwm_id,-cur_led->name);+led_dat->pwm=devm_pwm_get(&pdev->dev,cur_led->name);if(IS_ERR(led_dat->pwm)){ret=PTR_ERR(led_dat->pwm);-dev_err(&pdev->dev,"unable to request PWM %d\n",-cur_led->pwm_id);+dev_err(&pdev->dev,"unable to request PWM for %s\n",+cur_led->name);gotoerr;}
@@ -86,10 +85,8 @@ static int led_pwm_probe(struct platform_device *pdev)led_dat->cdev.flags|=LED_CORE_SUSPENDRESUME;ret=led_classdev_register(&pdev->dev,&led_dat->cdev);-if(ret<0){-pwm_free(led_dat->pwm);+if(ret<0)gotoerr;-}}platform_set_drvdata(pdev,leds_data);
@@ -98,10 +95,8 @@ static int led_pwm_probe(struct platform_device *pdev)err:if(i>0){-for(i=i-1;i>=0;i--){+for(i=i-1;i>=0;i--)led_classdev_unregister(&leds_data[i].cdev);-pwm_free(leds_data[i].pwm);-}}returnret;
@@ -115,10 +110,8 @@ static int led_pwm_remove(struct platform_device *pdev)leds_data=platform_get_drvdata(pdev);-for(i=0;i<pdata->num_leds;i++){+for(i=0;i<pdata->num_leds;i++)led_classdev_unregister(&leds_data[i].cdev);-pwm_free(leds_data[i].pwm);-}return0;}
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:44:59
To synchronize the header file definition and the actual code. In the code
the consumer parameter is named as con_id, change the header file and replace
consumer -> con_id in the parameter list.
Signed-off-by: Peter Ujfalusi <redacted>
---
include/linux/pwm.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:45:08
Allow client driver to use of_pwm_get() to get the PWM they need. This
is needed for drivers which handle more than one PWM separately, like
leds-pwm driver, which have:
pwmleds {
compatible = "pwm-leds";
kpad {
label = "omap4::keypad";
pwms = <&twl_pwm 0 7812500>;
max-brightness = <127>;
};
charging {
label = "omap4:green:chrg";
pwms = <&twl_pwmled 0 7812500>;
max-brightness = <255>;
};
};
in the dts files.
Signed-off-by: Peter Ujfalusi <redacted>
---
drivers/pwm/core.c | 8 ++++----
include/linux/pwm.h | 7 +++++++
2 files changed, 11 insertions(+), 4 deletions(-)
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:45:16
When booted with DT users can use devm version of of_pwm_get() to benefit
from automatic resource release.
Signed-off-by: Peter Ujfalusi <redacted>
---
drivers/pwm/core.c | 30 ++++++++++++++++++++++++++++++
include/linux/pwm.h | 9 +++++++++
2 files changed, 39 insertions(+)
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:45:20
The code looks more nicer if we use:
while (i--)
instead:
if (i > 0)
for (i = i - 1; i >= 0; i--)
Signed-off-by: Peter Ujfalusi <redacted>
---
drivers/leds/leds-pwm.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Peter Ujfalusi <hidden> Date: 2012-12-21 09:45:27
The DT binding for the pwm-leds devices are similar to the gpio-leds type.
LEDs are represented as sub-nodes of the pwm-leds device.
The code for handling the DT boot is based on the code found in the
leds-gpio driver and adapted to use PWMs instead of GPIOs.
To avoid having custom cleanup code in case of DT boot the newly created
devm_of_pwm_get() API is used to get the correct PWM instance.
For usage see:
Documentation/devicetree/bindings/leds/leds-pwm.txt
Signed-off-by: Peter Ujfalusi <redacted>
Acked-by: Grant Likely <redacted>
---
.../devicetree/bindings/leds/leds-pwm.txt | 48 +++++++++
drivers/leds/leds-pwm.c | 112 +++++++++++++++++----
2 files changed, 140 insertions(+), 20 deletions(-)
create mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.txt
@@ -0,0 +1,48 @@+LED connected to PWM++Required properties:+- compatible : should be "pwm-leds".++Each LED is represented as a sub-node of the pwm-leds device. Each+node's name represents the name of the corresponding LED.++LED sub-node properties:+- pwms : PWM property to point to the PWM device (phandle)/port (id) and to+ specify the period time to be used: <&phandle id period_ns>;+- pwm-names : (optional) Name to be used by the PWM subsystem for the PWM device+ For the pwms and pwm-names property please refer to:+ Documentation/devicetree/bindings/pwm/pwm.txt+- max-brightness : Maximum brightness possible for the LED+- label : (optional)+ see Documentation/devicetree/bindings/leds/common.txt+- linux,default-trigger : (optional)+ see Documentation/devicetree/bindings/leds/common.txt++Example:++twl_pwm: pwm {+ /* provides two PWMs (id 0, 1 for PWM1 and PWM2) */+ compatible = "ti,twl6030-pwm";+ #pwm-cells = <2>;+};++twl_pwmled: pwmled {+ /* provides one PWM (id 0 for Charing indicator LED) */+ compatible = "ti,twl6030-pwmled";+ #pwm-cells = <2>;+};++pwmleds {+ compatible = "pwm-leds";+ kpad {+ label = "omap4::keypad";+ pwms = <&twl_pwm 0 7812500>;+ max-brightness = <127>;+ };++ charging {+ label = "omap4:green:chrg";+ pwms = <&twl_pwmled 0 7812500>;+ max-brightness = <255>;+ };+};
@@ -58,46 +59,110 @@ static inline size_t sizeof_pwm_leds_priv(int num_leds)(sizeof(structled_pwm_data)*num_leds);}-staticintled_pwm_probe(structplatform_device*pdev)+staticstructled_pwm_priv*led_pwm_create_of(structplatform_device*pdev){-structled_pwm_platform_data*pdata=pdev->dev.platform_data;+structdevice_node*node=pdev->dev.of_node;+structdevice_node*child;structled_pwm_priv*priv;-inti,ret=0;+intcount,ret;-if(!pdata)-return-EBUSY;+/* count LEDs in this device, so we know how much to allocate */+count=of_get_child_count(node);+if(!count)+returnNULL;-priv=devm_kzalloc(&pdev->dev,sizeof_pwm_leds_priv(pdata->num_leds),+priv=devm_kzalloc(&pdev->dev,sizeof_pwm_leds_priv(count),GFP_KERNEL);if(!priv)-return-ENOMEM;+returnNULL;-for(i=0;i<pdata->num_leds;i++){-structled_pwm*cur_led=&pdata->leds[i];-structled_pwm_data*led_dat=&priv->leds[i];+for_each_child_of_node(node,child){+structled_pwm_data*led_dat=&priv->leds[priv->num_leds];-led_dat->pwm=devm_pwm_get(&pdev->dev,cur_led->name);+led_dat->cdev.name=of_get_property(child,"label",+NULL)?:child->name;++led_dat->pwm=devm_of_pwm_get(&pdev->dev,child,NULL);if(IS_ERR(led_dat->pwm)){-ret=PTR_ERR(led_dat->pwm);dev_err(&pdev->dev,"unable to request PWM for %s\n",-cur_led->name);+led_dat->cdev.name);gotoerr;}+/* Get the period from PWM core when n*/+led_dat->period=pwm_get_period(led_dat->pwm);++led_dat->cdev.default_trigger=of_get_property(child,+"linux,default-trigger",NULL);+of_property_read_u32(child,"max-brightness",+&led_dat->cdev.max_brightness);-led_dat->cdev.name=cur_led->name;-led_dat->cdev.default_trigger=cur_led->default_trigger;-led_dat->active_low=cur_led->active_low;-led_dat->period=cur_led->pwm_period_ns;led_dat->cdev.brightness_set=led_pwm_set;led_dat->cdev.brightness=LED_OFF;-led_dat->cdev.max_brightness=cur_led->max_brightness;led_dat->cdev.flags|=LED_CORE_SUSPENDRESUME;ret=led_classdev_register(&pdev->dev,&led_dat->cdev);-if(ret<0)+if(ret<0){+dev_err(&pdev->dev,"failed to register for %s\n",+led_dat->cdev.name);+of_node_put(child);gotoerr;+}+priv->num_leds++;+}++returnpriv;+err:+while(priv->num_leds--)+led_classdev_unregister(&priv->leds[priv->num_leds].cdev);++returnNULL;+}++staticintled_pwm_probe(structplatform_device*pdev)+{+structled_pwm_platform_data*pdata=pdev->dev.platform_data;+structled_pwm_priv*priv;+inti,ret=0;++if(pdata&&pdata->num_leds){+priv=devm_kzalloc(&pdev->dev,+sizeof_pwm_leds_priv(pdata->num_leds),+GFP_KERNEL);+if(!priv)+return-ENOMEM;++for(i=0;i<pdata->num_leds;i++){+structled_pwm*cur_led=&pdata->leds[i];+structled_pwm_data*led_dat=&priv->leds[i];++led_dat->pwm=devm_pwm_get(&pdev->dev,cur_led->name);+if(IS_ERR(led_dat->pwm)){+ret=PTR_ERR(led_dat->pwm);+dev_err(&pdev->dev,+"unable to request PWM for %s\n",+cur_led->name);+gotoerr;+}++led_dat->cdev.name=cur_led->name;+led_dat->cdev.default_trigger=cur_led->default_trigger;+led_dat->active_low=cur_led->active_low;+led_dat->period=cur_led->pwm_period_ns;+led_dat->cdev.brightness_set=led_pwm_set;+led_dat->cdev.brightness=LED_OFF;+led_dat->cdev.max_brightness=cur_led->max_brightness;+led_dat->cdev.flags|=LED_CORE_SUSPENDRESUME;++ret=led_classdev_register(&pdev->dev,&led_dat->cdev);+if(ret<0)+gotoerr;+}+priv->num_leds=pdata->num_leds;+}else{+priv=led_pwm_create_of(pdev);+if(!priv)+return-ENODEV;}-priv->num_leds=pdata->num_leds;platform_set_drvdata(pdev,priv);
@@ -121,12 +186,19 @@ static int led_pwm_remove(struct platform_device *pdev)return0;}+staticconststructof_device_idof_pwm_leds_match[]={+{.compatible="pwm-leds",},+{},+};+MODULE_DEVICE_TABLE(of,of_pwm_leds_match);+staticstructplatform_driverled_pwm_driver={.probe=led_pwm_probe,.remove=led_pwm_remove,.driver={.name="leds_pwm",.owner=THIS_MODULE,+.of_match_table=of_match_ptr(of_pwm_leds_match),},};
Hi Peter,
I merged this patchset into my for-next branch already.
Thanks for pushing this.
-Bryan
On Fri, Dec 21, 2012 at 1:43 AM, Peter Ujfalusi [off-list ref] wrote:
Hello,
Changes since v4:
- Commit message for patch #7 (DT binding for the leds-pwm driver) has been
updated
Changes since v3:
Addressed comments from Thierry Redding:
- DT binding documentation for leds-pwm updated
- of_pwm_request() renamed as of_pwm_get()
- introduction of devm_of_pwm_get()
- Commit message updates
- Other comments has been also addressed
- Acked-by from Grant is not added to the patches since they were modified since
v3
Changes since v2:
- rebased on top of linux-next
- DT bindings now alligned with Grant's request
- exporting of_pwm_request() from PWM core to allow clean DT bindings
- DT binding documentation changed to reflect the changes
Changes since v1:
- As suggested by Bryan Wu: the legacy pwm_request() has been removed from
patch 1
- Device tree bindings added for leds-pwm driver.
When we boot with Device tree we handle one LED per device to be more aligned
with PWM core's DT implementation.
An example of the DT usage is provided in the new DT binding documentation for
leds-pwm.
Tested on OMAP4 Blaze (SDP), BeagleBoard with legacy and DT boot. On Zoom2 with
legacy boot.
Regards,
Peter
---
Peter Ujfalusi (7):
leds: leds-pwm: Convert to use devm_get_pwm
leds: leds-pwm: Preparing the driver for device tree support
pwm: Correct parameter name in header for *pwm_get() functions
pwm: core: Rename of_pwm_request() to of_pwm_get() and export it
pwm: Add devm_of_pwm_get() as exported API for users
leds: leds-pwm: Simplify cleanup code
leds: leds-pwm: Add device tree bindings
.../devicetree/bindings/leds/leds-pwm.txt | 48 +++++++
drivers/leds/leds-pwm.c | 152 +++++++++++++++------
drivers/pwm/core.c | 38 +++++-
include/linux/leds_pwm.h | 2 +-
include/linux/pwm.h | 20 ++-
5 files changed, 212 insertions(+), 48 deletions(-)
create mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.txt
--
1.8.0.2
On Wed, Jan 02, 2013 at 06:10:13PM -0800, Bryan Wu wrote:
Hi Peter,
I merged this patchset into my for-next branch already.
Thanks for pushing this.
Hi Bryan,
Did you also take the PWM patches (3-5)? I was going to add those to my
tree, but if you already take them feel free to add my Acked-by.
Thierry
On Wed, Jan 2, 2013 at 11:22 PM, Thierry Reding
[off-list ref] wrote:
On Wed, Jan 02, 2013 at 06:10:13PM -0800, Bryan Wu wrote:
quoted
Hi Peter,
I merged this patchset into my for-next branch already.
Thanks for pushing this.
Hi Bryan,
Did you also take the PWM patches (3-5)? I was going to add those to my
tree, but if you already take them feel free to add my Acked-by.
Thierry
I should ask for that before I merged this patchset. I will add you
Acked-by for sure.
Thanks,
-Bryan
On Thu, Jan 03, 2013 at 09:14:06AM -0800, Bryan Wu wrote:
On Wed, Jan 2, 2013 at 11:22 PM, Thierry Reding
[off-list ref] wrote:
quoted
On Wed, Jan 02, 2013 at 06:10:13PM -0800, Bryan Wu wrote:
quoted
Hi Peter,
I merged this patchset into my for-next branch already.
Thanks for pushing this.
Hi Bryan,
Did you also take the PWM patches (3-5)? I was going to add those to my
tree, but if you already take them feel free to add my Acked-by.
Thierry
I should ask for that before I merged this patchset. I will add you
Acked-by for sure.
From: Peter Ujfalusi <hidden> Date: 2013-01-03 08:01:11
Hi Bryan,
On 01/03/2013 03:10 AM, Bryan Wu wrote:
Hi Peter,
I merged this patchset into my for-next branch already.
Thank you!
Thanks for pushing this.
It was my pleasure!
Thanks for the help on this.
Péter
-Bryan
On Fri, Dec 21, 2012 at 1:43 AM, Peter Ujfalusi [off-list ref] wrote:
quoted
Hello,
Changes since v4:
- Commit message for patch #7 (DT binding for the leds-pwm driver) has been
updated
Changes since v3:
Addressed comments from Thierry Redding:
- DT binding documentation for leds-pwm updated
- of_pwm_request() renamed as of_pwm_get()
- introduction of devm_of_pwm_get()
- Commit message updates
- Other comments has been also addressed
- Acked-by from Grant is not added to the patches since they were modified since
v3
Changes since v2:
- rebased on top of linux-next
- DT bindings now alligned with Grant's request
- exporting of_pwm_request() from PWM core to allow clean DT bindings
- DT binding documentation changed to reflect the changes
Changes since v1:
- As suggested by Bryan Wu: the legacy pwm_request() has been removed from
patch 1
- Device tree bindings added for leds-pwm driver.
When we boot with Device tree we handle one LED per device to be more aligned
with PWM core's DT implementation.
An example of the DT usage is provided in the new DT binding documentation for
leds-pwm.
Tested on OMAP4 Blaze (SDP), BeagleBoard with legacy and DT boot. On Zoom2 with
legacy boot.
Regards,
Peter
---
Peter Ujfalusi (7):
leds: leds-pwm: Convert to use devm_get_pwm
leds: leds-pwm: Preparing the driver for device tree support
pwm: Correct parameter name in header for *pwm_get() functions
pwm: core: Rename of_pwm_request() to of_pwm_get() and export it
pwm: Add devm_of_pwm_get() as exported API for users
leds: leds-pwm: Simplify cleanup code
leds: leds-pwm: Add device tree bindings
.../devicetree/bindings/leds/leds-pwm.txt | 48 +++++++
drivers/leds/leds-pwm.c | 152 +++++++++++++++------
drivers/pwm/core.c | 38 +++++-
include/linux/leds_pwm.h | 2 +-
include/linux/pwm.h | 20 ++-
5 files changed, 212 insertions(+), 48 deletions(-)
create mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.txt
--
1.8.0.2