From: Lee Jones <hidden> Date: 2016-03-02 15:34:18
The first part of this set extends the current PWM API to allow external
code to request a PWM Capture. Subsequent patches then make use of the
new API by providing a userspace offering via /sysfs. The final part of
the set supplies PWM Capture functionality into the already existing STi
PWM driver.
This patch-set has been tested end to end via /sysfs.
Lee Jones (11):
pwm: Add PWM Capture support
pwm: sysfs: Add PWM Capture support
pwm: sti: Reorganise register names in preparation for new
functionality
pwm: sti: Only request clock rate when you need to
pwm: sti: Supply PWM Capture register addresses and bit locations
pwm: sti: Supply PWM Capture clock handling
pwm: sti: Initialise PWM Capture channel data
pwm: sti: Add support for PWM Capture IRQs
pwm: sti: Add PWM Capture call-back
pwm: sti: Enable PWM Capture
pwm: sti: Take the opportunity to conduct a little house keeping
drivers/pwm/core.c | 26 ++++
drivers/pwm/pwm-sti.c | 384 ++++++++++++++++++++++++++++++++++++++++++--------
drivers/pwm/sysfs.c | 28 ++++
include/linux/pwm.h | 13 ++
4 files changed, 392 insertions(+), 59 deletions(-)
--
1.9.1
From: Lee Jones <hidden> Date: 2016-03-02 15:34:22
In the original code the clock rate was only obtained during
initialisation; however, the rate may change between then and
its use. This patch ensures the correct rate is acquired just
before use.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
@@ -86,13 +85,20 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,unsignedint*prescale){structsti_pwm_compat_data*cdata=pc->cdata;+unsignedlongclk_rate;unsignedlongval;unsignedintps;+clk_rate=clk_get_rate(pc->pwm_clk);+if(!clk_rate){+dev_err(pc->dev,"failed to get clock rate\n");+return-EINVAL;+}+/**prescale=((period_ns*clk_rate)/(10^9*(max_pwm_count+1))-1*/-val=NSEC_PER_SEC/pc->clk_rate;+val=NSEC_PER_SEC/clk_rate;val*=cdata->max_pwm_cnt+1;if(period%val){
@@ -353,12 +359,6 @@ static int sti_pwm_probe(struct platform_device *pdev)returnPTR_ERR(pc->pwm_clk);}-pc->clk_rate=clk_get_rate(pc->pwm_clk);-if(!pc->clk_rate){-dev_err(dev,"failed to get clock rate\n");-return-EINVAL;-}-ret=clk_prepare(pc->pwm_clk);if(ret){dev_err(dev,"failed to prepare clock\n");
From: Lee Jones <hidden> Date: 2016-03-02 15:34:24
Exciting functionality is on the way to this device. But
before we can add it, we need to do some basic housekeeping
so the additions can be added cleanly.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 76 +++++++++++++++++++++++++++------------------------
1 file changed, 41 insertions(+), 35 deletions(-)
@@ -277,15 +282,16 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)if(IS_ERR(pc->prescale_high))returnPTR_ERR(pc->prescale_high);-pc->pwm_en=devm_regmap_field_alloc(dev,pc->regmap,-reg_fields[PWM_EN]);-if(IS_ERR(pc->pwm_en))-returnPTR_ERR(pc->pwm_en);-pc->pwm_int_en=devm_regmap_field_alloc(dev,pc->regmap,-reg_fields[PWM_INT_EN]);-if(IS_ERR(pc->pwm_int_en))-returnPTR_ERR(pc->pwm_int_en);+pc->pwm_out_en=devm_regmap_field_alloc(dev,pc->regmap,+reg_fields[PWM_OUT_EN]);+if(IS_ERR(pc->pwm_out_en))+returnPTR_ERR(pc->pwm_out_en);++pc->pwm_cpt_int_en=devm_regmap_field_alloc(dev,pc->regmap,+reg_fields[PWM_CPT_INT_EN]);+if(IS_ERR(pc->pwm_cpt_int_en))+returnPTR_ERR(pc->pwm_cpt_int_en);return0;}
@@ -341,19 +347,19 @@ static int sti_pwm_probe(struct platform_device *pdev)if(ret)returnret;-pc->clk=of_clk_get_by_name(dev->of_node,"pwm");-if(IS_ERR(pc->clk)){+pc->pwm_clk=of_clk_get_by_name(dev->of_node,"pwm");+if(IS_ERR(pc->pwm_clk)){dev_err(dev,"failed to get PWM clock\n");-returnPTR_ERR(pc->clk);+returnPTR_ERR(pc->pwm_clk);}-pc->clk_rate=clk_get_rate(pc->clk);+pc->clk_rate=clk_get_rate(pc->pwm_clk);if(!pc->clk_rate){dev_err(dev,"failed to get clock rate\n");return-EINVAL;}-ret=clk_prepare(pc->clk);+ret=clk_prepare(pc->pwm_clk);if(ret){dev_err(dev,"failed to prepare clock\n");returnret;
@@ -367,7 +373,7 @@ static int sti_pwm_probe(struct platform_device *pdev)ret=pwmchip_add(&pc->chip);if(ret<0){-clk_unprepare(pc->clk);+clk_unprepare(pc->pwm_clk);returnret;}
@@ -384,7 +390,7 @@ static int sti_pwm_remove(struct platform_device *pdev)for(i=0;i<pc->cdata->num_chan;i++)pwm_disable(&pc->chip.pwms[i]);-clk_unprepare(pc->clk);+clk_unprepare(pc->pwm_clk);returnpwmchip_remove(&pc->chip);}
From: Lee Jones <hidden> Date: 2016-03-02 15:34:28
Once all functionality is in place, we provide the means to
enable PWM Capture. Here we are simply obtaining the
associated regmap and twiddling the relevant enable register
bits.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
From: Lee Jones <hidden> Date: 2016-03-02 15:34:30
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
@@ -309,7 +309,79 @@ static void sti_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)clear_bit(pwm->hwpwm,&pc->configured);}+staticintsti_pwm_capture(structpwm_chip*chip,structpwm_device*pwm,+intchannel,char*buf)+{+structsti_pwm_chip*pc=to_sti_pwmchip(chip);+structsti_pwm_compat_data*cdata=pc->cdata;+structsti_cpt_data*d=pc->cpt_data[channel];+structdevice*dev=pc->dev;+unsignedintf,dc;+unsignedinthigh,low;+boollevel;+intret;++if(channel>cdata->cpt_num_chan-1){+dev_err(dev,"Channel %d is not valid\n",channel);+return-EINVAL;+}++mutex_lock(&d->lock);++/* Prepare capture measurement */+d->index=0;+regmap_write(pc->regmap,PWM_CPT_EDGE(channel),CPT_EDGE_RISING);+regmap_field_write(pc->pwm_cpt_int_en,BIT(channel));+ret=wait_event_interruptible_timeout(d->wait,d->index>1,HZ);++/*+*Incasewewokeupforanotherreasonthancompletion+*makesuretodisablethecapture.+*/+regmap_write(pc->regmap,PWM_CPT_EDGE(channel),CPT_EDGE_DISABLED);++if(ret==-ERESTARTSYS)+gotoout;++switch(d->index){+case0:+case1:+/*+*Gettingherecouldmean:+*-inputsignalisconstantoflessthan1Hz+*-thereisnoinputsignalatall+*+*Insuchcasethefrequencyisroundeddownto0+*levelofthesupposedconstantsignalisreported+*usingdutycycleminandmaxvalues.+*/+level=gpio_get_value(d->gpio);++ret=sprintf(buf,"0:%u\n",level?CPT_DC_MAX:0);+break;+case2:+/* We have evertying we need */+high=d->snapshot[1]-d->snapshot[0];+low=d->snapshot[2]-d->snapshot[1];++/* Calculate frequency in Hz */+f=clk_get_rate(pc->cpt_clk)/(1*(high+low));++/* Calculate the duty cycle */+dc=CPT_DC_MAX*high/(high+low);++ret=sprintf(buf,"%u:%u\n",f,dc);+default:+dev_err(dev,"Internal error\n");+}++out:+mutex_unlock(&d->lock);+returnret;+}+staticconststructpwm_opssti_pwm_ops={+.capture=sti_pwm_capture,.config=sti_pwm_config,.enable=sti_pwm_enable,.disable=sti_pwm_disable,
From: Lee Jones <hidden> Date: 2016-03-02 15:35:41
This includes fixing some Coding Style issues and re-ordering/
simplifying a little code.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
From: Lee Jones <hidden> Date: 2016-03-02 15:35:58
Here we're requesting the PWM Capture IRQ and supplying the
handler which will be called in the event of an IRQ fire to
handle it.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 90 insertions(+), 1 deletion(-)
@@ -354,6 +425,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)if(IS_ERR(pc->pwm_cpt_int_en))returnPTR_ERR(pc->pwm_cpt_int_en);+pc->pwm_cpt_int_stat=devm_regmap_field_alloc(dev,pc->regmap,+reg_fields[PWM_CPT_INT_STAT]);+if(IS_ERR(pc->pwm_cpt_int_stat))+returnPTR_ERR(pc->pwm_cpt_int_stat);+return0;}
@@ -371,7 +447,7 @@ static int sti_pwm_probe(struct platform_device *pdev)structsti_pwm_chip*pc;structresource*res;unsignedintchan;-intret;+intret,irq;pc=devm_kzalloc(dev,sizeof(*pc),GFP_KERNEL);if(!pc)
@@ -392,6 +468,19 @@ static int sti_pwm_probe(struct platform_device *pdev)if(IS_ERR(pc->regmap))returnPTR_ERR(pc->regmap);+irq=platform_get_irq(pdev,0);+if(irq<0){+dev_err(&pdev->dev,"Failed to obtain IRQ\n");+return-ENODEV;+}++ret=devm_request_irq(&pdev->dev,irq,sti_pwm_interrupt,+0,pdev->name,(void*)pc);+if(ret<0){+dev_err(&pdev->dev,"Failed to request IRQ\n");+returnret;+}+/**SetupPWMdatawithdefaultvalues:somevaluescouldbereplaced*withspecificonesprovidedfromDeviceTree.
From: Lee Jones <hidden> Date: 2016-03-02 15:36:24
Each PWM Capture channel is allocated a structure to hold its own
state. During a capture the channel may be partaking in one of 3
phases. Initial (rising) phase change, a subsequent (falling)
phase change indicating end of the duty-cycle phase and finally
a final (rising) phase change indicating the end of the period.
The timer value snapshot each event is held in a variable of the
same name, and the phase number (0, 1, 2) is contained in the
index variable. Other channel specific information, such as GPIO
pin, the IRQ wait queue and locking is also contained in the
structure. This patch initialises this structure for each of
the available channels.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 49 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 42 insertions(+), 7 deletions(-)
@@ -378,7 +399,8 @@ static int sti_pwm_probe(struct platform_device *pdev)cdata->reg_fields=&sti_pwm_regfields[0];cdata->max_prescale=0xff;cdata->max_pwm_cnt=255;-cdata->num_chan=1;+cdata->pwm_num_chan=1;+cdata->cpt_num_chan=0;pc->cdata=cdata;pc->dev=dev;
@@ -389,6 +411,19 @@ static int sti_pwm_probe(struct platform_device *pdev)if(ret)returnret;+for(chan=0;chan<cdata->cpt_num_chan;chan++){+structsti_cpt_data*data;++data=devm_kzalloc(dev,sizeof(*data),GFP_KERNEL);+if(!data)+return-ENOMEM;++init_waitqueue_head(&data->wait);+mutex_init(&data->lock);+data->gpio=of_get_named_gpio(np,"capture-gpios",chan);+pc->cpt_data[chan]=data;+}+pc->pwm_clk=of_clk_get_by_name(dev->of_node,"pwm");if(IS_ERR(pc->pwm_clk)){dev_err(dev,"failed to get PWM clock\n");
@@ -416,7 +451,7 @@ static int sti_pwm_probe(struct platform_device *pdev)pc->chip.dev=dev;pc->chip.ops=&sti_pwm_ops;pc->chip.base=-1;-pc->chip.npwm=pc->cdata->num_chan;+pc->chip.npwm=pc->cdata->pwm_num_chan;pc->chip.can_sleep=true;ret=pwmchip_add(&pc->chip);
@@ -436,7 +471,7 @@ static int sti_pwm_remove(struct platform_device *pdev)structsti_pwm_chip*pc=platform_get_drvdata(pdev);unsignedinti;-for(i=0;i<pc->cdata->num_chan;i++)+for(i=0;i<pc->cdata->pwm_num_chan;i++)pwm_disable(&pc->chip.pwms[i]);clk_unprepare(pc->pwm_clk);
From: Lee Jones <hidden> Date: 2016-03-02 15:36:58
ST's PWM IP is supplied by 2 different clocks. One for PWM
Output and the other for Capture. This patch provides clock
handling for the latter.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
@@ -390,6 +401,18 @@ static int sti_pwm_probe(struct platform_device *pdev)returnret;}+pc->cpt_clk=of_clk_get_by_name(dev->of_node,"capture");+if(IS_ERR(pc->cpt_clk)){+dev_err(dev,"failed to get PWM capture clock\n");+returnPTR_ERR(pc->cpt_clk);+}++ret=clk_prepare(pc->cpt_clk);+if(ret){+dev_err(dev,"failed to prepare clock\n");+returnret;+}+pc->chip.dev=dev;pc->chip.ops=&sti_pwm_ops;pc->chip.base=-1;
@@ -399,6 +422,7 @@ static int sti_pwm_probe(struct platform_device *pdev)ret=pwmchip_add(&pc->chip);if(ret<0){clk_unprepare(pc->pwm_clk);+clk_unprepare(pc->cpt_clk);returnret;}
@@ -416,6 +440,7 @@ static int sti_pwm_remove(struct platform_device *pdev)pwm_disable(&pc->chip.pwms[i]);clk_unprepare(pc->pwm_clk);+clk_unprepare(pc->cpt_clk);returnpwmchip_remove(&pc->chip);}
From: Lee Jones <hidden> Date: 2016-03-02 15:45:00
Allow a user to read PWM Capture results from /sysfs. First,
the user must tell PWM Capture which channel they wish to
read from:
$ echo 2 > $PWMCHIP/capture
To start a capture and read the result, simply read the file:
$ cat $PWMCHIP/capture
The output format is left to the device.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/sysfs.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
From: Lee Jones <hidden> Date: 2016-03-02 16:10:08
Supply a PWM Capture call-back Op in order to pass back
information obtained by running analysis on PWM a signal.
This would normally (at least during testing) be called from
the Sysfs routines with a view to printing out PWM Capture
data which has been encoded into a string.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/core.c | 26 ++++++++++++++++++++++++++
include/linux/pwm.h | 13 +++++++++++++
2 files changed, 39 insertions(+)
From: Lee Jones <hidden> Date: 2016-04-12 07:28:56
On Wed, 02 Mar 2016, Lee Jones wrote:
The first part of this set extends the current PWM API to allow external
code to request a PWM Capture. Subsequent patches then make use of the
new API by providing a userspace offering via /sysfs. The final part of
the set supplies PWM Capture functionality into the already existing STi
PWM driver.
This patch-set has been tested end to end via /sysfs.
Hopefully you still have this set in your inbox.
Please let me know if you wish me to resend it.
Lee Jones (11):
pwm: Add PWM Capture support
pwm: sysfs: Add PWM Capture support
pwm: sti: Reorganise register names in preparation for new
functionality
pwm: sti: Only request clock rate when you need to
pwm: sti: Supply PWM Capture register addresses and bit locations
pwm: sti: Supply PWM Capture clock handling
pwm: sti: Initialise PWM Capture channel data
pwm: sti: Add support for PWM Capture IRQs
pwm: sti: Add PWM Capture call-back
pwm: sti: Enable PWM Capture
pwm: sti: Take the opportunity to conduct a little house keeping
drivers/pwm/core.c | 26 ++++
drivers/pwm/pwm-sti.c | 384 ++++++++++++++++++++++++++++++++++++++++++--------
drivers/pwm/sysfs.c | 28 ++++
include/linux/pwm.h | 13 ++
4 files changed, 392 insertions(+), 59 deletions(-)
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
On Wed, Mar 02, 2016 at 03:31:59PM +0000, Lee Jones wrote:
Supply a PWM Capture call-back Op in order to pass back
information obtained by running analysis on PWM a signal.
This would normally (at least during testing) be called from
the Sysfs routines with a view to printing out PWM Capture
data which has been encoded into a string.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/core.c | 26 ++++++++++++++++++++++++++
include/linux/pwm.h | 13 +++++++++++++
2 files changed, 39 insertions(+)
Overall I like the concept of introducing this capture functionality.
However I have a couple of questions, see below.
This public interface seems to be targetted specifically at sysfs. As
such I'm not sure if there is reason to make it public, since the code
is unlikely to ever be called by other users in the kernel.
Do you think it would be possible to make the interface more generic by
passing back some form of structure containing the capture result? That
way users within the kernel could use the result without having to go
and parse a string filled in by the driver. It would also be easy to
implement sysfs support on top of that. Another advantage is that there
would be a standard result structure rather than a free-form string
filled by drivers that can't be controlled.
What kind of result does the STi hardware return? Looking at the driver
later in the series it seems to support triggering interrupts on rising
and falling edges and capture some running counter at these events. If
the frequency of the counter increment is known, these numbers should
allow us to determine both the period and duty cycle of the PWM signal
in nanoseconds. Would it be possible to rewrite this function and the
driver patch to something like this:
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result);
Where
struct pwm_capture {
unsigned int period;
unsigned int duty_cycle;
};
?
Another thing I noticed is that the code here seems to be confusing
channels and devices. In the PWM subsystem a struct pwm_device
represents a single channel. Allowing the channel to be specified is
redundant at best, and confusing at worst.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160412/d4916185/attachment.sig>
On Wed, Mar 02, 2016 at 03:32:00PM +0000, Lee Jones wrote:
quoted hunk
Allow a user to read PWM Capture results from /sysfs. First,
the user must tell PWM Capture which channel they wish to
read from:
$ echo 2 > $PWMCHIP/capture
To start a capture and read the result, simply read the file:
$ cat $PWMCHIP/capture
The output format is left to the device.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/sysfs.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
These are all per-PWM attributes and the specific PWM device that they
are associated with can be retrieved using child_to_pwm_device(child)
(see the other attributes' implementation for examples). So I don't
think the capture attribute needs to be writable at all. You already
implement capture_show() in almost the right way, and if you drop the
channel parameter from pwm_capture() as I suggested in my reply to patch
1/11 this should resolve itself automatically.
Of course capture_show() would become slightly more beefy if we return a
standard result structure rather than leave it up to the drivers to fill
out the sysfs string. The good thing is that it will be common code and
therefore the sysfs interface would return the same format regardless of
the driver.
Perhaps something like
struct pwm_device *pwm = child_to_pwm_device(child);
struct pwm_capture result;
err = pwm_capture(pwm, &result);
if (err < 0)
return err;
return sprintf(buf, "%u %u\n", result.duty_cycle, result.period);
would work?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160412/2ee0ebc6/attachment-0001.sig>
The PWM subsystem allows chip-specific data to be associated with each
PWM device. I'd prefer if the driver used it rather than homebrew some-
thing similar. See pwm_set_chip_data() and pwm_get_chip_data().
quoted hunk
@@ -389,6 +411,19 @@ static int sti_pwm_probe(struct platform_device *pdev) if (ret) return ret;+ for (chan = 0; chan < cdata->cpt_num_chan; chan++) {+ struct sti_cpt_data *data;++ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);+ if (!data)+ return -ENOMEM;++ init_waitqueue_head(&data->wait);+ mutex_init(&data->lock);+ data->gpio = of_get_named_gpio(np, "capture-gpios", chan);+ pc->cpt_data[chan] = data;
Converting to per-PWM data should be as simple as turning this last line
into:
pwm_set_chip_data(pc->chip.pwms[chan], data);
Also I don't see any cleanup for this data in the driver. The memory for
the per-PWM data should be freed by devm_*() infrastructure, but how
will the GPIO be released?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160412/43bda11f/attachment.sig>
+static irqreturn_t sti_pwm_interrupt(int irq, void *data)
+{
+ struct sti_pwm_chip *pc = data;
+ struct device *dev = pc->dev;
+ struct sti_cpt_data *d;
+ int channel;
+ int cpt_int_stat;
+ int reg;
+ int ret = IRQ_NONE;
+
+ ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat);
+ if (ret)
+ return ret;
+
+ while (cpt_int_stat) {
+ channel = ffs(cpt_int_stat) - 1;
+
+ d = pc->cpt_data[channel];
+
+ /*
+ * Capture input:
+ * _______ _______
+ * | | | |
+ * __| |_________________| |________
+ * ^0 ^1 ^2
+ *
+ * Capture start by the first available rising edge
+ * When a capture event occurs, capture value (CPT_VALx)
+ * is stored, index incremented, capture edge changed.
+ *
+ * After the capture, if the index > 1, we have collected
+ * the necessary data so we signal the thread waiting for it
+ * and disable the capture by setting capture edge to none
+ *
+ */
How do you deal with the situation where someone will stop the PWM
signal half-way in? That is, suppose you've got events for the first and
second snapshots (0 and 1) and then someone stops the PWM and the event
for snapshot 2 never happens, how does the code recover?
@@ -354,6 +425,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc) if (IS_ERR(pc->pwm_cpt_int_en)) return PTR_ERR(pc->pwm_cpt_int_en);+ pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap,+ reg_fields[PWM_CPT_INT_STAT]);+ if (IS_ERR(pc->pwm_cpt_int_stat))+ return PTR_ERR(pc->pwm_cpt_int_stat);+ return 0; }
@@ -371,7 +447,7 @@ static int sti_pwm_probe(struct platform_device *pdev) struct sti_pwm_chip *pc; struct resource *res; unsigned int chan;- int ret;+ int ret, irq; pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); if (!pc)
@@ -392,6 +468,19 @@ static int sti_pwm_probe(struct platform_device *pdev) if (IS_ERR(pc->regmap)) return PTR_ERR(pc->regmap);+ irq = platform_get_irq(pdev, 0);+ if (irq < 0) {+ dev_err(&pdev->dev, "Failed to obtain IRQ\n");+ return -ENODEV;+ }
I think you need to propagate the return value of platform_get_irq()
here.
On Wed, Mar 02, 2016 at 03:32:07PM +0000, Lee Jones wrote:
quoted hunk
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
The timeout here should make sure callers don't hang forever. But maybe
you can still make sure that when the PWM gets disabled the wait queue
is woken and perhaps return an appropriate error code to let users know
that the operation was interrupted.
Also, how about letting callers choose the value of the timeout? In some
cases they may be interested in long-running signals. In other cases the
whole second timeout may be much too long.
+
+ /*
+ * In case we woke up for another reason than completion
+ * make sure to disable the capture.
+ */
+ regmap_write(pc->regmap, PWM_CPT_EDGE(channel), CPT_EDGE_DISABLED);
The comment here is slightly confusing because it implies that disabling
the capture should be done conditionally, whereas it is always disabled.
+
+ if (ret == -ERESTARTSYS)
+ goto out;
+
+ switch (d->index) {
+ case 0:
+ case 1:
+ /*
+ * Getting here could mean :
+ * - input signal is constant of less than 1Hz
+ * - there is no input signal at all
+ *
+ * In such case the frequency is rounded down to 0
+ * level of the supposed constant signal is reported
+ * using duty cycle min and max values.
+ */
+ level = gpio_get_value(d->gpio);
+
+ ret = sprintf(buf, "0:%u\n", level ? CPT_DC_MAX : 0);
+ break;
+ case 2:
+ /* We have evertying we need */
+ high = d->snapshot[1] - d->snapshot[0];
+ low = d->snapshot[2] - d->snapshot[1];
+
+ /* Calculate frequency in Hz */
+ f = clk_get_rate(pc->cpt_clk) / (1 * (high + low));
On Wed, Mar 02, 2016 at 03:32:08PM +0000, Lee Jones wrote:
quoted hunk
Once all functionality is in place, we provide the means to
enable PWM Capture. Here we are simply obtaining the
associated regmap and twiddling the relevant enable register
bits.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
@@ -279,6 +279,13 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)pwm->hwpwm);gotoout;}++ret=regmap_field_write(pc->pwm_cpt_en,1);+if(ret){+dev_err(dev,"failed to enable PWM capture:%d\n",+pwm->hwpwm);+gotoout;+}
Should this perhaps be part of the driver's ->capture() implementation?
It seems redundant to have this logic enabled if we may never use it.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160412/2e44a93e/attachment.sig>
From: Lee Jones <hidden> Date: 2016-04-13 09:36:14
On Tue, 12 Apr 2016, Thierry Reding wrote:
On Wed, Mar 02, 2016 at 03:31:59PM +0000, Lee Jones wrote:
quoted
Supply a PWM Capture call-back Op in order to pass back
information obtained by running analysis on PWM a signal.
This would normally (at least during testing) be called from
the Sysfs routines with a view to printing out PWM Capture
data which has been encoded into a string.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/core.c | 26 ++++++++++++++++++++++++++
include/linux/pwm.h | 13 +++++++++++++
2 files changed, 39 insertions(+)
Overall I like the concept of introducing this capture functionality.
However I have a couple of questions, see below.
This public interface seems to be targetted specifically at sysfs. As
such I'm not sure if there is reason to make it public, since the code
is unlikely to ever be called by other users in the kernel.
Do you think it would be possible to make the interface more generic by
passing back some form of structure containing the capture result? That
way users within the kernel could use the result without having to go
and parse a string filled in by the driver. It would also be easy to
implement sysfs support on top of that. Another advantage is that there
would be a standard result structure rather than a free-form string
filled by drivers that can't be controlled.
What kind of result does the STi hardware return? Looking at the driver
later in the series it seems to support triggering interrupts on rising
and falling edges and capture some running counter at these events. If
the frequency of the counter increment is known, these numbers should
allow us to determine both the period and duty cycle of the PWM signal
in nanoseconds. Would it be possible to rewrite this function and the
driver patch to something like this:
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result);
Where
struct pwm_capture {
unsigned int period;
unsigned int duty_cycle;
};
?
Yes, I think that sounds feasible.
Another thing I noticed is that the code here seems to be confusing
channels and devices. In the PWM subsystem a struct pwm_device
represents a single channel. Allowing the channel to be specified is
redundant at best, and confusing at worst.
On the STi platform I'm working on, we have 2 devices PWM{0,1} and
each device has 4 separate channels [0..3]. Not all of them support
PWM capture, but the channels are 'a thing'. I'd need to look into it
further, but I guess you'd like the driver to pretend we have 8
devices? If that's the case, what's the point in the core 'npwm'
parameter? Surely that's "channels per device"?
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
From: Lee Jones <hidden> Date: 2016-04-13 09:40:57
On Tue, 12 Apr 2016, Thierry Reding wrote:
On Wed, Mar 02, 2016 at 03:32:00PM +0000, Lee Jones wrote:
quoted
Allow a user to read PWM Capture results from /sysfs. First,
the user must tell PWM Capture which channel they wish to
read from:
$ echo 2 > $PWMCHIP/capture
To start a capture and read the result, simply read the file:
$ cat $PWMCHIP/capture
The output format is left to the device.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/sysfs.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
These are all per-PWM attributes and the specific PWM device that they
are associated with can be retrieved using child_to_pwm_device(child)
(see the other attributes' implementation for examples). So I don't
think the capture attribute needs to be writable at all. You already
implement capture_show() in almost the right way, and if you drop the
channel parameter from pwm_capture() as I suggested in my reply to patch
1/11 this should resolve itself automatically.
Of course capture_show() would become slightly more beefy if we return a
standard result structure rather than leave it up to the drivers to fill
out the sysfs string. The good thing is that it will be common code and
therefore the sysfs interface would return the same format regardless of
the driver.
Perhaps something like
struct pwm_device *pwm = child_to_pwm_device(child);
struct pwm_capture result;
err = pwm_capture(pwm, &result);
if (err < 0)
return err;
return sprintf(buf, "%u %u\n", result.duty_cycle, result.period);
would work?
Same reply as 1/11. Now I know that we should be treating each of our
channels, as *completely* separate devices, I think this method seems
reasonable.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
+static irqreturn_t sti_pwm_interrupt(int irq, void *data)
+{
+ struct sti_pwm_chip *pc = data;
+ struct device *dev = pc->dev;
+ struct sti_cpt_data *d;
+ int channel;
+ int cpt_int_stat;
+ int reg;
+ int ret = IRQ_NONE;
+
+ ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat);
+ if (ret)
+ return ret;
+
+ while (cpt_int_stat) {
+ channel = ffs(cpt_int_stat) - 1;
+
+ d = pc->cpt_data[channel];
+
+ /*
+ * Capture input:
+ * _______ _______
+ * | | | |
+ * __| |_________________| |________
+ * ^0 ^1 ^2
+ *
+ * Capture start by the first available rising edge
+ * When a capture event occurs, capture value (CPT_VALx)
+ * is stored, index incremented, capture edge changed.
+ *
+ * After the capture, if the index > 1, we have collected
+ * the necessary data so we signal the thread waiting for it
+ * and disable the capture by setting capture edge to none
+ *
+ */
How do you deal with the situation where someone will stop the PWM
signal half-way in? That is, suppose you've got events for the first and
second snapshots (0 and 1) and then someone stops the PWM and the event
for snapshot 2 never happens, how does the code recover?
The 'wait' will timeout and the cycle will be reset.
@@ -354,6 +425,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc) if (IS_ERR(pc->pwm_cpt_int_en)) return PTR_ERR(pc->pwm_cpt_int_en);+ pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap,+ reg_fields[PWM_CPT_INT_STAT]);+ if (IS_ERR(pc->pwm_cpt_int_stat))+ return PTR_ERR(pc->pwm_cpt_int_stat);+ return 0; }
@@ -371,7 +447,7 @@ static int sti_pwm_probe(struct platform_device *pdev) struct sti_pwm_chip *pc; struct resource *res; unsigned int chan;- int ret;+ int ret, irq; pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); if (!pc)
@@ -392,6 +468,19 @@ static int sti_pwm_probe(struct platform_device *pdev) if (IS_ERR(pc->regmap)) return PTR_ERR(pc->regmap);+ irq = platform_get_irq(pdev, 0);+ if (irq < 0) {+ dev_err(&pdev->dev, "Failed to obtain IRQ\n");+ return -ENODEV;+ }
I think you need to propagate the return value of platform_get_irq()
here.
Yes, could do. Although, I think we could go either way:
$ git grep -A5 platform_get_irq | grep "return ret\|return irq" | wc -l
176
$ git grep -A5 platform_get_irq | grep "return -EINVAL\|-ENODEV\|-ENXIO" | wc -l
256
Happy to change it though.
You're right. Will drop it.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
From: Lee Jones <hidden> Date: 2016-04-13 10:26:00
On Tue, 12 Apr 2016, Thierry Reding wrote:
On Wed, Mar 02, 2016 at 03:32:07PM +0000, Lee Jones wrote:
quoted
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
The timeout here should make sure callers don't hang forever. But maybe
you can still make sure that when the PWM gets disabled the wait queue
is woken and perhaps return an appropriate error code to let users know
that the operation was interrupted.
Sure. I'll look into that.
Also, how about letting callers choose the value of the timeout? In some
cases they may be interested in long-running signals. In other cases the
whole second timeout may be much too long.
I'm not opposed to it. How do you suggest we do that?
quoted
+ /*
+ * In case we woke up for another reason than completion
+ * make sure to disable the capture.
+ */
+ regmap_write(pc->regmap, PWM_CPT_EDGE(channel), CPT_EDGE_DISABLED);
The comment here is slightly confusing because it implies that disabling
the capture should be done conditionally, whereas it is always disabled.
Not really. We do it unconditionally for reason explained.
It says:
"disable the capture just in case X happens"
rather than
"disable the capture if X happens".
Perhaps the language is too subtle. I can reword for clarity.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
On Wed, Apr 13, 2016 at 10:36:05AM +0100, Lee Jones wrote:
On Tue, 12 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Mar 02, 2016 at 03:31:59PM +0000, Lee Jones wrote:
quoted
Supply a PWM Capture call-back Op in order to pass back
information obtained by running analysis on PWM a signal.
This would normally (at least during testing) be called from
the Sysfs routines with a view to printing out PWM Capture
data which has been encoded into a string.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/core.c | 26 ++++++++++++++++++++++++++
include/linux/pwm.h | 13 +++++++++++++
2 files changed, 39 insertions(+)
Overall I like the concept of introducing this capture functionality.
However I have a couple of questions, see below.
This public interface seems to be targetted specifically at sysfs. As
such I'm not sure if there is reason to make it public, since the code
is unlikely to ever be called by other users in the kernel.
Do you think it would be possible to make the interface more generic by
passing back some form of structure containing the capture result? That
way users within the kernel could use the result without having to go
and parse a string filled in by the driver. It would also be easy to
implement sysfs support on top of that. Another advantage is that there
would be a standard result structure rather than a free-form string
filled by drivers that can't be controlled.
What kind of result does the STi hardware return? Looking at the driver
later in the series it seems to support triggering interrupts on rising
and falling edges and capture some running counter at these events. If
the frequency of the counter increment is known, these numbers should
allow us to determine both the period and duty cycle of the PWM signal
in nanoseconds. Would it be possible to rewrite this function and the
driver patch to something like this:
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result);
Where
struct pwm_capture {
unsigned int period;
unsigned int duty_cycle;
};
?
Yes, I think that sounds feasible.
quoted
Another thing I noticed is that the code here seems to be confusing
channels and devices. In the PWM subsystem a struct pwm_device
represents a single channel. Allowing the channel to be specified is
redundant at best, and confusing at worst.
On the STi platform I'm working on, we have 2 devices PWM{0,1} and
each device has 4 separate channels [0..3]. Not all of them support
PWM capture, but the channels are 'a thing'. I'd need to look into it
further, but I guess you'd like the driver to pretend we have 8
devices? If that's the case, what's the point in the core 'npwm'
parameter? Surely that's "channels per device"?
Well, it's technically "channels per _chip_". Perhaps the confusion is
with the historical naming: a PWM channel is represented by a struct
pwm_device, whereas what I think you're referring to as device (as in
"channels per device") is represented as a struct pwm_chip.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160413/4e71a232/attachment.sig>
clear_bit() is a little unusual to use on regular data types, as
evidenced by the need for the goofy cast here.
It's just a bit neater (and provides locking) than manually bit
twiddling using bitwise operators. What do you suggest?
I think the cast indicates that you're mixing unrelated interfaces. Also
looking at patch 9/11 it seems like you'll need extra locking to protect
against concurrent accesses in the interrupt handler and the ->capture()
implementation anyway, so might as well use that lock for this access.
quoted
quoted
@@ -371,7 +447,7 @@ static int sti_pwm_probe(struct platform_device *pdev) struct sti_pwm_chip *pc; struct resource *res; unsigned int chan;- int ret;+ int ret, irq; pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); if (!pc)
@@ -392,6 +468,19 @@ static int sti_pwm_probe(struct platform_device *pdev) if (IS_ERR(pc->regmap)) return PTR_ERR(pc->regmap);+ irq = platform_get_irq(pdev, 0);+ if (irq < 0) {+ dev_err(&pdev->dev, "Failed to obtain IRQ\n");+ return -ENODEV;+ }
I think you need to propagate the return value of platform_get_irq()
here.
Yes, could do. Although, I think we could go either way:
$ git grep -A5 platform_get_irq | grep "return ret\|return irq" | wc -l
176
$ git grep -A5 platform_get_irq | grep "return -EINVAL\|-ENODEV\|-ENXIO" | wc -l
256
Happy to change it though.
I think all the latter are really wrong. Looking at the implementation
of platform_get_irq() there are a number of error codes that it can
return (-EPROBE_DEFER amongst them), so collapsing them all into an
-EINVAL, -ENODEV or -ENXIO is very wrong.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160413/f76e36c9/attachment-0001.sig>
On Wed, Apr 13, 2016 at 11:25:54AM +0100, Lee Jones wrote:
On Tue, 12 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Mar 02, 2016 at 03:32:07PM +0000, Lee Jones wrote:
quoted
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
The timeout here should make sure callers don't hang forever. But maybe
you can still make sure that when the PWM gets disabled the wait queue
is woken and perhaps return an appropriate error code to let users know
that the operation was interrupted.
Sure. I'll look into that.
quoted
Also, how about letting callers choose the value of the timeout? In some
cases they may be interested in long-running signals. In other cases the
whole second timeout may be much too long.
I'm not opposed to it. How do you suggest we do that?
The easiest would probably be to add an unsigned long timeout parameter
to the pwm_capture() function and ->capture() callbacks.
But thinking about this further I'm wondering if it might not be easier
and more flexible to move the timeout completely outside of this code
and into callers. I suspect that the most simple way to do that would be
to add a completion to struct pwm_capture that callers can use to wait
for completion of a capture. This would make the whole process
asynchronous and allow interesting things like making the sysfs capture
file pollable, for example.
quoted
quoted
+ /*
+ * In case we woke up for another reason than completion
+ * make sure to disable the capture.
+ */
+ regmap_write(pc->regmap, PWM_CPT_EDGE(channel), CPT_EDGE_DISABLED);
The comment here is slightly confusing because it implies that disabling
the capture should be done conditionally, whereas it is always disabled.
Not really. We do it unconditionally for reason explained.
It says:
"disable the capture just in case X happens"
rather than
"disable the capture if X happens".
Perhaps the language is too subtle. I can reword for clarity.
I'd be okay with just dropping the comment altogether, it seems rather
obvious to me. But clarifying is okay with me, too.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160413/82f89061/attachment.sig>
From: Lee Jones <hidden> Date: 2016-04-15 08:29:27
On Wed, 13 Apr 2016, Thierry Reding wrote:
On Wed, Apr 13, 2016 at 11:25:54AM +0100, Lee Jones wrote:
quoted
On Tue, 12 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Mar 02, 2016 at 03:32:07PM +0000, Lee Jones wrote:
quoted
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
The timeout here should make sure callers don't hang forever. But maybe
you can still make sure that when the PWM gets disabled the wait queue
is woken and perhaps return an appropriate error code to let users know
that the operation was interrupted.
Sure. I'll look into that.
quoted
Also, how about letting callers choose the value of the timeout? In some
cases they may be interested in long-running signals. In other cases the
whole second timeout may be much too long.
I'm not opposed to it. How do you suggest we do that?
The easiest would probably be to add an unsigned long timeout parameter
to the pwm_capture() function and ->capture() callbacks.
But thinking about this further I'm wondering if it might not be easier
and more flexible to move the timeout completely outside of this code
and into callers. I suspect that the most simple way to do that would be
to add a completion to struct pwm_capture that callers can use to wait
for completion of a capture. This would make the whole process
asynchronous and allow interesting things like making the sysfs capture
file pollable, for example.
Okay, so how do you propose we handle this with sysfs? Perhaps
another RW file to set it?
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
From: Lee Jones <hidden> Date: 2016-04-15 12:39:48
On Tue, 12 Apr 2016, Thierry Reding wrote:
On Wed, Mar 02, 2016 at 03:32:05PM +0000, Lee Jones wrote:
[...]
quoted
+struct sti_cpt_data {
+ u32 snapshot[3];
+ int index;
+ int gpio;
On a side-note, this should probably use struct gpio_desc * instead of
an integer along with the gpiod_*() APIs for the GPIO handling.
Why would you need to do that?
of_get_named_gpio() does all that for you.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Converting to per-PWM data should be as simple as turning this last line
into:
pwm_set_chip_data(pc->chip.pwms[chan], data);
Also I don't see any cleanup for this data in the driver. The memory for
the per-PWM data should be freed by devm_*() infrastructure, but how
will the GPIO be released?
There is no reason to release a GPIO.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
On Fri, Apr 15, 2016 at 09:29:00AM +0100, Lee Jones wrote:
On Wed, 13 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Apr 13, 2016 at 11:25:54AM +0100, Lee Jones wrote:
quoted
On Tue, 12 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Mar 02, 2016 at 03:32:07PM +0000, Lee Jones wrote:
quoted
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <redacted>
---
drivers/pwm/pwm-sti.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
The timeout here should make sure callers don't hang forever. But maybe
you can still make sure that when the PWM gets disabled the wait queue
is woken and perhaps return an appropriate error code to let users know
that the operation was interrupted.
Sure. I'll look into that.
quoted
Also, how about letting callers choose the value of the timeout? In some
cases they may be interested in long-running signals. In other cases the
whole second timeout may be much too long.
I'm not opposed to it. How do you suggest we do that?
The easiest would probably be to add an unsigned long timeout parameter
to the pwm_capture() function and ->capture() callbacks.
But thinking about this further I'm wondering if it might not be easier
and more flexible to move the timeout completely outside of this code
and into callers. I suspect that the most simple way to do that would be
to add a completion to struct pwm_capture that callers can use to wait
for completion of a capture. This would make the whole process
asynchronous and allow interesting things like making the sysfs capture
file pollable, for example.
Okay, so how do you propose we handle this with sysfs? Perhaps
another RW file to set it?
I'm unfamiliar with how this is done in other drivers, so I'd have to
look at them first. I suspect that it would be fine for now to simply
redesign the PWM API parts and keep some default timeout in sysfs. It
could be extended with some mechanism to override the default timeout
in the future.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160415/81e66e07/attachment.sig>
On Fri, Apr 15, 2016 at 01:39:41PM +0100, Lee Jones wrote:
On Tue, 12 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Mar 02, 2016 at 03:32:05PM +0000, Lee Jones wrote:
[...]
quoted
+struct sti_cpt_data {
+ u32 snapshot[3];
+ int index;
+ int gpio;
On a side-note, this should probably use struct gpio_desc * instead of
an integer along with the gpiod_*() APIs for the GPIO handling.
Why would you need to do that?
of_get_named_gpio() does all that for you.
Use the of_get_named_gpio*d*() function instead. My understanding is
that referring to GPIOs by integer is deprecated and should not be used
in new code.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160415/b8ca5610/attachment.sig>
Converting to per-PWM data should be as simple as turning this last line
into:
pwm_set_chip_data(pc->chip.pwms[chan], data);
Also I don't see any cleanup for this data in the driver. The memory for
the per-PWM data should be freed by devm_*() infrastructure, but how
will the GPIO be released?
From: Lee Jones <hidden> Date: 2016-04-15 14:31:30
On Fri, 15 Apr 2016, Thierry Reding wrote:
On Fri, Apr 15, 2016 at 01:39:41PM +0100, Lee Jones wrote:
quoted
On Tue, 12 Apr 2016, Thierry Reding wrote:
quoted
On Wed, Mar 02, 2016 at 03:32:05PM +0000, Lee Jones wrote:
[...]
quoted
+struct sti_cpt_data {
+ u32 snapshot[3];
+ int index;
+ int gpio;
On a side-note, this should probably use struct gpio_desc * instead of
an integer along with the gpiod_*() APIs for the GPIO handling.
Why would you need to do that?
of_get_named_gpio() does all that for you.
Use the of_get_named_gpio*d*() function instead. My understanding is
that referring to GPIOs by integer is deprecated and should not be used
in new code.
I've since conducted some research and have now converted over to
gpiod. Thanks for the pointer.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog