Add Freescale FTM PWM driver.
Subsystems (2)
v7 cover Add Freescale FTM PWM driver.
This patch series is the Freescale FTM PWM implementation. And there are 8 channels most supported by the FTM PWM. This implementation is only compatible with device tree definition.
This patch series is based on linux-next and has been tested on Vybrid VF610 Tower board using device tree.
Changes in v7:
- Add big-endian mode support.
- Add FTM mutex lock.
- Add period time check with the current running pwm(s).
- Recode the counter clock source selecting.
- Sort some header files alphabetically, etc.
Changes in v6:
- Remove "fsl,pwm-counter-clk".
Changes in v5:
- Remove active/idle pinctrl stuff.
Changes in v4:
- Check for the result and return an error for devm_kzalloc().
- Move pinmux setting from the SoC file to the board specific file.
- Revise the written mistake of 'ret |= FTMSC_CLKEXT;' --> 'reg |= FTMSC_CLKEXT;'.
Changes in v3:
- Remove "availabe" field.
- Remove "fsl,pwm-avaliable-chs" property.
- ...
Changes in v2:
- Remove PWM CPWM/EPWM feature and sysfs.
- Remove some redundant code.
- Revise some code for more readable.
- Remove "fsl,pwm-clk-ps", "fsl,pwm-number", "fsl,pwm-channels",etc.
- Add "fsl,pwm-avaliable-chs", "fsl,pwm-counter-clk", etc.
- Support 8 channels default in dtsi file.
- Add counter clock source selection.
- Rename some function name, macro name, etc.
- Use PWM's and OF's existing function interfaces.
- Split clk_unprepare_enable to clk_unprepare and clk_enable,etc.
- ...
Added in v1:
- Add Freescale FTM PWM driver support.
- Add Freescale FTM PWM node for VF610.
- Enable Enables FTM PWM device for Vybrid VF610 TOWER.
- Add device tree bindings for Freescale.
PATCH v7 1/4 pwm: Add Freescale FTM PWM driver support
The FTM PWM device can be found on Vybrid VF610 Tower and Layerscape LS-1 SoCs.
--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-fsl-ftm.c | 508 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 519 insertions(+) create mode 100644 drivers/pwm/pwm-fsl-ftm.c
drivers/pwm/Kconfig +10 -0
@@ -71,6 +71,16 @@ config PWM_EP93XX To compile this driver as a module, choose M here: the module will be called pwm-ep93xx. +config PWM_FSL_FTM + tristate "Freescale FlexTimer Module (FTM) PWM support" + depends on OF + help + Generic FTM PWM framework driver for Freescale VF610 and + Layerscape LS-1 SoCs. + + To compile this driver as a module, choose M here: the module + will be called pwm-fsl-ftm. + config PWM_IMX tristate "i.MX PWM support" depends on ARCH_MXC
drivers/pwm/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o obj-$(CONFIG_PWM_IMX) += pwm-imx.o +obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.o obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o obj-$(CONFIG_PWM_MXS) += pwm-mxs.o
drivers/pwm/pwm-fsl-ftm.c new file +508 -0
508 lines not on this page · raw message
Signature · 1 line
1.8.4
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
On Fri, Dec 13, 2013 at 04:57:04PM +0800, Xiubo Li wrote:
[...]
drivers/pwm/Makefile obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o · line 8
Quoted 9 lines
drivers/pwm/Makefile +1
-0@@ -5,6 +5,7 @@ obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o obj-$(CONFIG_PWM_IMX) += pwm-imx.o +obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.o
This needs to move up one line to preserve the alphabetical ordering.
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +0
-0
[...]
Quoted 1 line
+struct
fsl_pwm_chip{
[...]
drivers/pwm/pwm-fsl-ftm.c line 91
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +1
-0+int big_endian;
This should be of type bool.
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 10 lines
drivers/pwm/pwm-fsl-ftm.c +10
-0+}; + +static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))
The likely() probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val); +rmb ();
I'd prefer the rmb() to follow the __raw_readl() immediately to make the relationship more explicit.
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+ +return val; +} +
drivers/pwm/pwm-fsl-ftm.c line 119
Quoted 10 lines
drivers/pwm/pwm-fsl-ftm.c +10
-0+static inline void fsl_pwm_writel (struct fsl_pwm_chip *fpc, +u32 val,void __iomem *addr) +{ +wmb (); +if (likely (fpc->big_endian)) + val =cpu_to_be32 (val); +else + val =cpu_to_le32 (val); + +__raw_writel (val, addr);
Same here. wmb() should precede __raw_writel() immediately.
drivers/pwm/pwm-fsl-ftm.c line 142
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+static inline int fsl_pwm_calculate_default_ps (struct fsl_pwm_chip *fpc, +int index)
Please align arguments on subsequent lines with the first argument on the first line. There are a few more of those in this file, please check all other functions as well.
Also I think it's better to turn the FSL_PWM_CLK_* enum into a named enum and reuse the type here. That way you get proper type-checking.
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +1
-0+switch (index) {
[...]
drivers/pwm/pwm-fsl-ftm.c line 170
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+default : +return -EINVAL ;
And with proper type checking you don't need this default case anymore.
drivers/pwm/pwm-fsl-ftm.c line 205
Quoted 11 lines
drivers/pwm/pwm-fsl-ftm.c +11
-0+static unsigned long fsl_pwm_calculate_period_cycles (struct fsl_pwm_chip *fpc, +unsigned long period_ns,int index) +{ +int ret; +unsigned long cycles; + + fpc->counter_clk_select =FTM_SC_CLK (index); + + ret =fsl_pwm_calculate_default_ps (fpc, index); +if (ret) { +dev_err (fpc->chip.dev,"failed to calculate default ps.\n" );
No need for the terminating fullstop (.) here, but perhaps you could write out what "ps" actually stands for. Also including the error code in the error message would be good since you're not propagating the error to the caller.
drivers/pwm/pwm-fsl-ftm.c line 211
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+ cycles =fsl_pwm_calculate_cycles (fpc, period_ns); + +return cycles;
This can simply be "return fsl_pwm_calculate_cycles(fpc, period_ns);", in which case you can get rid of the cycles variable.
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+static unsigned long fsl_pwm_calculate_period (struct fsl_pwm_chip *fpc, +unsigned long period_ns) +{
[...]
drivers/pwm/pwm-fsl-ftm.c line 250
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c +8
-0+if (fix_rate > ext_rate) { + m0 =FSL_PWM_CLK_FIX ; + m1 =FSL_PWM_CLK_EXT ; + }else { + m0 =FSL_PWM_CLK_EXT ; + m1 =FSL_PWM_CLK_FIX ; + + }
There's a gratuitous blank line above this one.
drivers/pwm/pwm-fsl-ftm.c line 282
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c +8
-0+static int fsl_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, +int duty_ns,int period_ns) +{ +u32 val, period, duty; +struct fsl_pwm_chip *fpc =to_fsl_chip (chip); + +mutex_lock (&fpc->lock); +if (fpc->period_ns && fpc->period_ns != period_ns) {
There should be a blank line between the above two.
drivers/pwm/pwm-fsl-ftm.c line 285
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+dev_err (fpc->chip.dev,"fail to config pwm%d, the period " +"time should be the same with the current " +"running pwm(s).\n" , pwm->hwpwm);
I think I'd make this error message more terse and put more information into a comment. Perhaps something like this:
/*
* The FSL FTM controller supports only a single period for all PWM
* channels, therefore incompatible changes need to be refused.
*/
if (fpc->period_ns && fpc->period_ns != period_ns) {
dev_err(fpc->chip.dev,
"conflicting period requested for PWM %u\n",
pwm->hwpwm);
...
}drivers/pwm/pwm-fsl-ftm.c
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+mutex_unlock (&fpc->lock); +return -EINVAL ;
I think something like -EBUSY would be more appropriate here.
drivers/pwm/pwm-fsl-ftm.c line 293
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+if (!fpc->period_ns && duty_ns) { + period =fsl_pwm_calculate_period (fpc, period_ns); +if (!period) { + dev_err(fpc->chip.dev, "fail to calculate the "
"failed"
drivers/pwm/pwm-fsl-ftm.c line 294
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +1
-0+ "period cycles.\n");
And no fullstop either. Also I don't think you need "cycles" here. In fact something equally accurate like this:
dev_err(fpc->chip.dev, "failed to calculate period\n");
Still fits within 80 characters.
drivers/pwm/pwm-fsl-ftm.c line 307
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+ fpc->period_ns = period_ns; + } +mutex_unlock (&fpc->lock);
This could use a blank line as well.
drivers/pwm/pwm-fsl-ftm.c line 325
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c +8
-0+static int fsl_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm, +enum pwm_polarity polarity) +{ +u32 val; +struct fsl_pwm_chip *fpc =to_fsl_chip (chip); + + val =fsl_pwm_readl (fpc, fpc->base +FTM_POL ); +if (polarity ==PWM_POLARITY_INVERSED )
Blank line between the above.
drivers/pwm/pwm-fsl-ftm.c line 329
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+ val |=BIT (pwm->hwpwm); + else + val &= ~BIT(pwm->hwpwm); +fsl_pwm_writel (fpc, val, fpc->base +FTM_POL );
And here.
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c +8
-0+static void fsl_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) +{ +u32 val; +struct fsl_pwm_chip *fpc =to_fsl_chip (chip); + + val =fsl_pwm_readl (fpc, fpc->base +FTM_OUTMASK ); + val |=BIT (pwm->hwpwm); +fsl_pwm_writel (fpc, val, fpc->base +FTM_OUTMASK );
drivers/pwm/pwm-fsl-ftm.c line 412
Quoted 10 lines
drivers/pwm/pwm-fsl-ftm.c +10
-0+ +mutex_lock (&fpc->lock); +fsl_counter_clock_disable (fpc); + + val =fsl_pwm_readl (fpc, fpc->base +FTM_OUTMASK ); +if ((val &0xFF ) ==0xFF ) { + fpc->period_ns =0 ; + fpc->counter_clk_en =NULL ; + } +mutex_unlock (&fpc->lock);
Same here.
Quoted 13 lines
drivers/pwm/pwm-fsl-ftm.c +13
-0+static int fsl_pwm_probe (struct platform_device *pdev) +{ +int ret; +struct fsl_pwm_chip *fpc; +struct resource *res; +struct device_node *np = pdev->dev.of_node; + + fpc =devm_kzalloc (&pdev->dev,sizeof (*fpc),GFP_KERNEL ); +if (!fpc) +return -ENOMEM ; + +mutex_init (&fpc->lock); +
drivers/pwm/pwm-fsl-ftm.c line 447
Quoted 10 lines
drivers/pwm/pwm-fsl-ftm.c +10
-0+ fpc->chip.dev = &pdev->dev; + + fpc->big_endian =of_property_read_bool (np,"big-endian" ); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + fpc->base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (fpc->base)) +return PTR_ERR (fpc->base); + + fpc->sys_clk =devm_clk_get (fpc->chip.dev,"ftm_sys" );
For consistency I'd use &pdev->dev here...
drivers/pwm/pwm-fsl-ftm.c line 449
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+if (IS_ERR (fpc->sys_clk)) { + dev_err(fpc->chip.dev,
... and here.
drivers/pwm/pwm-fsl-ftm.c line 471
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+ ret =pwmchip_add (&fpc->chip); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to add PWM chip %d\n" , ret);
Perhaps "failed to add PWM chip: %d\n", so that %d isn't confused to mean the PWM chip number?
drivers/pwm/pwm-fsl-ftm.c line 484
Quoted 5 lines
drivers/pwm/pwm-fsl-ftm.c +5
-0+static int fsl_pwm_remove (struct platform_device *pdev) +{ +struct fsl_pwm_chip *fpc =platform_get_drvdata (pdev); + +mutex_destroy (&fpc->lock);
I think you can drop this. Once fsl_pwm_remove() exists, the memory pointed to by fpc will be freed, so you won't be able to access the mutex anyway.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131217/4343ace0/attachment.sig>
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 15 lines · Thierry Reding
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 8 lines · Xiubo Li
drivers/pwm/pwm-fsl-ftm.c new file +8
-0+static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c line 104
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c new file +3
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val);
This will also cause sparse errors, because when sparse is enabled, these expect __le32 or __be32 arguments, not u32.
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c new file +1
-0+rmb ();I'd prefer the
rmb()to follow the__raw_readl()immediately to make the relationship more explicit.
A better question to ask is: why is this barrier here? What memory ordering operations is it trying to serialise?
Quoted 4 lines
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c new file +4
-0+static inline void fsl_pwm_writel (struct fsl_pwm_chip *fpc, +u32 val,void __iomem *addr) +{ +wmb ();
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c line 119
Quoted 6 lines
drivers/pwm/pwm-fsl-ftm.c new file +6
-0+if (likely (fpc->big_endian)) + val =cpu_to_be32 (val); +else + val =cpu_to_le32 (val); + +__raw_writel (val, addr);Same here.
wmb()should precede__raw_writel()immediately.
Same comments here - what memory operations is the wmb() trying to serialise? Does this PWM driver somehow end up doing DMA?
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 16 lines · On Tuesday 17 of December 2013 11:51:36 Russell King - ARM Linux wrote:
Quoted 15 lines · Thierry Reding
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 8 lines · Xiubo Li
drivers/pwm/pwm-fsl-ftm.c new file +8
-0+static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).
Quoted 6 lines
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c line 104
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c new file +3
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val);This will also cause sparse errors, because when sparse is enabled, these expect
__le32or__be32arguments, not u32.
My question is why can't you just create two sets of accessors, one big endian and one little endian, add two function pointers to your fsl_pwm_chip struct and let the driver set the to correct accessors in probe?
This would eliminate the problem with types Russell mentioned and IMHO make the code cleaner.
Best regards,
Tomasz
Quoted 8 lines
Quoted 5 lines
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c new file +1
-0+rmb ();I'd prefer the
rmb()to follow the__raw_readl()immediately to make the relationship more explicit.A better question to ask is: why is this barrier here? What memory ordering operations is it trying to serialise?
I'd also add a question why __raw accessors are used here.
Best regards,
Tomasz
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 24 lines · Tomasz Figa
Quoted 16 lines · On Tuesday 17 of December 2013 11:51:36 Russell King - ARM Linux wrote:
Quoted 15 lines · Thierry Reding
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 8 lines · Xiubo Li
drivers/pwm/pwm-fsl-ftm.c new file +8
-0+static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).Quoted 6 lines
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c line 104
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c new file +3
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val);This will also cause sparse errors, because when sparse is enabled, these expect
__le32or__be32arguments, not u32.
Quoted 4 lines
My question is why can't you just create two sets of accessors, one big endian and one little endian, add two function pointers to your
fsl_pwm_chipstruct and let the driver set the to correct accessors in probe?
I guess that would be one possibility.
Quoted 2 lines
This would eliminate the problem with types Russell mentioned and IMHO make the code cleaner.
I fail to see how that would eliminate the problem with the types. That said I don't actually see sparse complaining about any type mismatches. That's probably because the various macros implicitly cast to u32.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c new file +1
-0+rmb ();I'd prefer the
rmb()to follow the__raw_readl()immediately to make the relationship more explicit.A better question to ask is: why is this barrier here? What memory ordering operations is it trying to serialise?
I'd also add a question why
__rawaccessors are used here.
Because both readl() and writel() explicitly perform little endian accesses.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131217/4d7e0ae3/attachment.sig>
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 30 lines · On Tuesday 17 of December 2013 13:45:06 Thierry Reding wrote:
Quoted 24 lines · Tomasz Figa
Quoted 16 lines · On Tuesday 17 of December 2013 11:51:36 Russell King - ARM Linux wrote:
Quoted 15 lines · Thierry Reding
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 8 lines · Xiubo Li
drivers/pwm/pwm-fsl-ftm.c new file +8
-0+static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).Quoted 6 lines
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c line 104
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c new file +3
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val);This will also cause sparse errors, because when sparse is enabled, these expect
__le32or__be32arguments, not u32.Quoted 4 lines
My question is why can't you just create two sets of accessors, one big endian and one little endian, add two function pointers to your
fsl_pwm_chipstruct and let the driver set the to correct accessors in probe?
Quoted 8 lines
I guess that would be one possibility.
Quoted 2 lines
This would eliminate the problem with types Russell mentioned and IMHO make the code cleaner.
I fail to see how that would eliminate the problem with the types. That said I don't actually see sparse complaining about any type mismatches. That's probably because the various macros implicitly cast to u32.
Well, in BE variant you would read the register using __raw_readl() into a __be32 and then get an u32 from be32_to_cpu() and return it. Similarly for writes
In LE variant, readl()/writel() could be used directly.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c new file +1
-0+rmb ();I'd prefer the
rmb()to follow the__raw_readl()immediately to make the relationship more explicit.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
A better question to ask is: why is this barrier here? What memory ordering operations is it trying to serialise?
I'd also add a question why
__rawaccessors are used here.Because both
readl()andwritel()explicitly perform little endian accesses.
Right. Thanks for pointing this out.
Best regards,
Tomasz
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 8 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 17 of December 2013 13:45:06 Thierry Reding wrote:
I fail to see how that would eliminate the problem with the types. That said I don't actually see sparse complaining about any type mismatches. That's probably because the various macros implicitly cast to u32.
Well, in BE variant you would read the register using
__raw_readl()into a__be32and then get an u32 frombe32_to_cpu()and return it. Similarly for writes
__raw_readl() returns a u32, so you'll get a warning trying to assign a u32 to a __be32.
We do have ioread32() and ioread32be() which do the appropriate conversion, as well as the write versions too. They both include the barrier if you're overly concerned about that.
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 10 lines · On Tuesday 17 of December 2013 13:04:35 Russell King - ARM Linux wrote:
Quoted 8 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 17 of December 2013 13:45:06 Thierry Reding wrote:
I fail to see how that would eliminate the problem with the types. That said I don't actually see sparse complaining about any type mismatches. That's probably because the various macros implicitly cast to u32.
Well, in BE variant you would read the register using
__raw_readl()into a__be32and then get an u32 frombe32_to_cpu()and return it. Similarly for writes
Quoted 6 lines
__raw_readl()returns a u32, so you'll get a warning trying to assign a u32 to a__be32.We do have
ioread32()andioread32be()which do the appropriate conversion, as well as the write versions too. They both include the barrier if you're overly concerned about that.
Nice. I wasn't aware of their existence. Thanks.
Best regards,
Tomasz
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
In reply to Russell King - ARM LinuxQuoted 6 lines · Russell King - ARM Linux
Quoted 5 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 17 of December 2013 13:45:06 Thierry Reding wrote:
I fail to see how that would eliminate the problem with the types. That said I don't actually see sparse complaining about any type mismatches. That's probably because the various macros implicitly cast to u32.
Quoted 6 lines
Quoted 3 lines
Well, in BE variant you would read the register using
__raw_readl()into a__be32and then get an u32 frombe32_to_cpu()and return it. Similarly for writes
__raw_readl()returns a u32, so you'll get a warning trying to assign a u32 to a__be32.
If sparse doesn't complain about the original code here, does that mean we have a bug that should be fixed?
Quoted 3 lines
We do have
ioread32()andioread32be()which do the appropriate conversion, as well as the write versions too. They both include the barrier if you're overly concerned about that.
A few years ago GregKH commented in response to a patch that ioread*() weren't supposed to be used for memory-mapped only devices. The original purpose apparently was to allow drivers to work with both I/O and memory-mapped devices.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131217/f4f9097f/attachment.sig>
RE: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
In reply to Russell King - ARM LinuxQuoted 6 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 17 of December 2013 13:45:06 Thierry Reding wrote:
Quoted 2 lines
I fail to see how that would eliminate the problem with the types. That said I don't actually see sparse complaining about any type
mismatches.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
That's probably because the various macros implicitly cast to u32.
Well, in BE variant you would read the register using
__raw_readl()into a__be32and then get an u32 frombe32_to_cpu()and return it. Similarly for writes
__raw_readl()returns a u32, so you'll get a warning trying to assign a u32 to a__be32.
If all are ok about this method.
How about the following:
+static inline u32 fsl_pwm_readl(struct fsl_pwm_chip *fpc,
+ const void __iomem *addr)
+{
+ u32 val;
+
+ val = __raw_readl(addr);
+
+ if (likely(fpc->big_endian))
+ val = be32_to_cpu((__force __be32)val);
+ else
+ val = le32_to_cpu((__force __le32)val);
+ rmb();
+
+ return val;
+}
+
+static inline void fsl_pwm_writel(struct fsl_pwm_chip *fpc,
+ u32 val, void __iomem *addr)
+{
+ wmb();
+ if (likely(fpc->big_endian))
+ val = (__force u32)cpu_to_be32(val);
+ else
+ val = (__force u32)cpu_to_le32(val);
+
+ __raw_writel(val, addr);
+}
Best Regards,
Xiubo
RE: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
In reply to Thierry RedingQuoted 26 lines · Tomasz Figa
Quoted 24 lines · On Tuesday 17 of December 2013 11:51:36 Russell King - ARM Linux wrote:
Quoted 22 lines · Thierry Reding
Quoted 15 lines · Xiubo Li
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c new file +8
-0+static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c line 104
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c new file +3
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val);This will also cause sparse errors, because when sparse is enabled, these expect
__le32or__be32arguments, not u32.
Quoted 7 lines
Quoted 4 lines
My question is why can't you just create two sets of accessors, one big endian and one little endian, add two function pointers to your
fsl_pwm_chipstruct and let the driver set the to correct accessors in probe?I guess that would be one possibility.
Yes, that's one possibility.
If so, it must deference the function pointers and do the C stack push/pop stuff every time when doing the accesses. For instance, but for some devices(USB, NET, DMA..), we need to do many accesses every time in the frequent interrupt handler, and I think the inline type functions will be more efficiency.
In LS-1 series platforms, there are many devices that need to do the same work like this, and could these be moved to some global files ?
--
Xiubo
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
In reply to Russell King - ARM LinuxQuoted 23 lines · Russell King - ARM Linux
Quoted 15 lines · Thierry Reding
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 8 lines · Xiubo Li
drivers/pwm/pwm-fsl-ftm.c new file +8
-0+static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c line 104
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c new file +3
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val);This will also cause sparse errors, because when sparse is enabled, these expect
__le32or__be32arguments, not u32.
Quoted 7 lines
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c new file +1
-0+rmb ();I'd prefer the
rmb()to follow the__raw_readl()immediately to make the relationship more explicit.A better question to ask is: why is this barrier here? What memory ordering operations is it trying to serialise?
I suppose that this was done so that the accesses would essentially remain the same as those performed by readl() and writel().
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c new file +4
-0+static inline void fsl_pwm_writel (struct fsl_pwm_chip *fpc, +u32 val,void __iomem *addr) +{ +wmb ();Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c line 119
Quoted 6 lines
drivers/pwm/pwm-fsl-ftm.c new file +6
-0+if (likely (fpc->big_endian)) + val =cpu_to_be32 (val); +else + val =cpu_to_le32 (val); + +__raw_writel (val, addr);Same here.
wmb()should precede__raw_writel()immediately.
Quoted 2 lines
Same comments here - what memory operations is the
wmb()trying to serialise? Does this PWM driver somehow end up doing DMA?
Not that I can see. But if my understanding is correct, not using the barriers would allow the compiler and CPU to reorder accesses, and by that cause the register accesses to potentially happen in the wrong order.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131217/feceab50/attachment.sig>
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 8 lines · Thierry Reding
Quoted 2 lines · Russell King - ARM Linux
Same comments here - what memory operations is the
wmb()trying to serialise? Does this PWM driver somehow end up doing DMA?Not that I can see. But if my understanding is correct, not using the barriers would allow the compiler and CPU to reorder accesses, and by that cause the register accesses to potentially happen in the wrong order.
The compiler won't reorder them, but the CPU may if it meets certain criteria. The architecture guarantees that accesses to device memory within a (minimum of) 1KB block will be ordered.
The ARM ARM is slightly ambiguous in how this is applied - in one place it says that "Accesses must arrive at any particular memory-mapped peripheral or block of memory in program order" and another part it says "The size of a memory mapped peripheral, or a block of memory, is IMPLEMENTATION DEFINED, but is not smaller than 1KByte. Note This implies that the maximum memory-mapped peripheral size for which the architecture guarantees order for all implementations is 1KB." See page A3-148.
What this means (to me at least) is that on any SoC, the architecture guarantees that accesses _within_ a 1KB device memory block will always be ordered, but two accesses outside of a 1KB block _to the same device_ is implementation defined whether it is ordered or not.
The interesting point here though is that the "note" contradicts the first definition if you have (eg) AMBA Primecell peripherals which are generally 4KB in size, since if the architecture only guarantees 1KB, then accesses _may_ _not_ arrive at one primecell in program order. Hence, the note is a direct contradiction of the first definition.
Re: [PATCHv7 1/4] pwm: Add Freescale FTM PWM driver support
Quoted 14 lines · Russell King - ARM Linux
Quoted 8 lines · Thierry Reding
Quoted 2 lines · Russell King - ARM Linux
Same comments here - what memory operations is the
wmb()trying to serialise? Does this PWM driver somehow end up doing DMA?Not that I can see. But if my understanding is correct, not using the barriers would allow the compiler and CPU to reorder accesses, and by that cause the register accesses to potentially happen in the wrong order.
The compiler won't reorder them, but the CPU may if it meets certain criteria. The architecture guarantees that accesses to device memory within a (minimum of) 1KB block will be ordered.
Quoted 8 lines
The ARM ARM is slightly ambiguous in how this is applied - in one place it says that "Accesses must arrive at any particular memory-mapped peripheral or block of memory in program order" and another part it says "The size of a memory mapped peripheral, or a block of memory, is IMPLEMENTATION DEFINED, but is not smaller than 1KByte. Note This implies that the maximum memory-mapped peripheral size for which the architecture guarantees order for all implementations is 1KB." See page A3-148.
None of the ARM ARM versions that I have seem to have page A3-148. Which version should I be looking at? Not that I'm in any way doubting what you're saying, I'd just like to make sure to have the correct reference to look at in the future.
Quoted 4 lines
What this means (to me at least) is that on any SoC, the architecture guarantees that accesses _within_ a 1KB device memory block will always be ordered, but two accesses outside of a 1KB block
_tothe samedevice_is implementation defined whether it is ordered or not.
This means at least every ARM SoC would behave that way. Since this driver doesn't have an explicit dependency on ARM I assume it could eventually be used on a different architecture. Even more so since there's Freescale in the name.
Quoted 5 lines
The interesting point here though is that the "note" contradicts the first definition if you have (eg) AMBA Primecell peripherals which are generally 4KB in size, since if the architecture only guarantees 1KB, then accesses _may_ _not_ arrive at one primecell in program order. Hence, the note is a direct contradiction of the first definition.
Interesting indeed. Perhaps implementation defined in this case means that an implementation would have to adjust the size of a memory mapped peripheral or block of memory accordingly, depending on the largest block within the SoC.
I suppose, though, that if the architecture doesn't give any guarantees about it, we can't safely assume that the implementation will.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131217/5b351e0f/attachment.sig>
PATCH v7 1/4 pwm: Add Freescale FTM PWM driver support
In reply to Thierry RedingQuoted 10 lines
drivers/pwm/Makefile obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o · line 8
Quoted 7 lines
drivers/pwm/Makefile +1
-0@@ -5,6 +5,7 @@ obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o obj-$(CONFIG_PWM_IMX) += pwm-imx.o +obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.oThis needs to move up one line to preserve the alphabetical ordering.
Yes, it had been. It caused by the rebase operation and after that I haven't aware about this. I will revise this.
Quoted 7 lines
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +0
-0[...]
Quoted 1 line
+struct
fsl_pwm_chip{[...]
drivers/pwm/pwm-fsl-ftm.c line 91
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +1
-0+int big_endian;This should be of type bool.
I'll revise it.
Quoted 17 lines
drivers/pwm/pwm-fsl-ftm.c line 101
Quoted 11 lines
drivers/pwm/pwm-fsl-ftm.c +10
-0+}; + +static inline u32 fsl_pwm_readl (struct fsl_pwm_chip *fpc, +const void __iomem *addr) +{ +u32 val; + + val =__raw_readl (addr); + +if (likely (fpc->big_endian))The
likely()probably isn't very useful in this case. But if you want to keep it, it should at least be reversed, since little-endian is actually the default (you have to specify the big-endian property to activate the big endian mode).
So why added the likely() for bit endian mode is that this driver maybe used for ARM and like PowerPC architectures, and in PowerPC platforms and LS-1 series the big endian mode will be used almostly. Now only VF610-twr is the little endian mode devices, and this is also why I added the big endian mode support.
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c line 105
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+ val =be32_to_cpu (val); + else + val =le32_to_cpu (val); +rmb ();I'd prefer the
rmb()to follow the__raw_readl()immediately to make the relationship more explicit.
The fsl_pwm_readl() and fsl_pwm_writel() are almost copied the readl() and writel().
For instance:
+ static inline u32 fsl_pwm_readl(struct fsl_pwm_chip *fpc,
+ const void __iomem *addr)
+ {
+ u32 val;
+
+ val = __raw_readl(addr);
+
+ if (likely(fpc->big_endian))
+ val = be32_to_cpu(val);
+ else
+ val = le32_to_cpu(val);
+ rmb();
+
+ return val;
+ }
As we can see, this is one inline function, if locating the rmb() just follow __raw_readl() immediately, I'm not very sure the compiler will do the following reorders ?
In some function calls the fsl_pwm_readl(Address1) and little-endain mode is used:
The original code is:
tmp = fsl_pwm_readl(Address1)
<Do calculating about the tmp value returned from fsl_pwm_readl here>
Maybe reordered to :
tmp = raw_readl(addr);rmb();
<Do calculating about the tmp value returned from fsl_pwm_readl here> tmp = le32_to_cpu(tmp);
...
As we have known that in the fsl_pwm_readl(), the 'val' used by le32_to_cpu() has a dependency on __raw_readl(), so the compiler will grantee the right orders, and also the Arch will grantee the right orders too.
This is why I located the rmb() just before 'return val'.
Quoted 10 lines
drivers/pwm/pwm-fsl-ftm.c line 142
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+static inline int fsl_pwm_calculate_default_ps (struct fsl_pwm_chip *fpc, +int index)Please align arguments on subsequent lines with the first argument on the first line. There are a few more of those in this file, please check all other functions as well.
Also I think it's better to turn the FSL_PWM_CLK_* enum into a named enum and reuse the type here. That way you get proper type-checking.
Quoted 7 lines
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +1
-0+switch (index) {[...]
drivers/pwm/pwm-fsl-ftm.c line 170
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+default : +return -EINVAL ;And with proper type checking you don't need this default case anymore.
I'll revise this.
Quoted 17 lines
Quoted 1 line
+static unsigned long fsl_pwm_calculate_period_cycles(struct
fsl_pwm_chip*fpc,
drivers/pwm/pwm-fsl-ftm.c line 205
Quoted 9 lines
drivers/pwm/pwm-fsl-ftm.c +9
-0+ unsigned long period_ns, int index) { + int ret; +unsigned long cycles; + + fpc->counter_clk_select =FTM_SC_CLK (index); + + ret =fsl_pwm_calculate_default_ps (fpc, index); +if (ret) { +dev_err (fpc->chip.dev,"failed to calculate default ps.\n" );No need for the terminating fullstop (.) here, but perhaps you could write out what "ps" actually stands for. Also including the error code in the error message would be good since you're not propagating the error to the caller.
Yes, I will.
Quoted 7 lines
drivers/pwm/pwm-fsl-ftm.c line 211
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+ cycles =fsl_pwm_calculate_cycles (fpc, period_ns); + +return cycles;This can simply be "return
fsl_pwm_calculate_cycles(fpc, period_ns);", in which case you can get rid of the cycles variable.
That's better.
Quoted 4 lines
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+static unsigned long fsl_pwm_calculate_period (struct fsl_pwm_chip *fpc, +unsigned long period_ns) +{[...]
Quoted 11 lines
drivers/pwm/pwm-fsl-ftm.c line 250
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c +8
-0+if (fix_rate > ext_rate) { + m0 =FSL_PWM_CLK_FIX ; + m1 =FSL_PWM_CLK_EXT ; + }else { + m0 =FSL_PWM_CLK_EXT ; + m1 =FSL_PWM_CLK_FIX ; + + }There's a gratuitous blank line above this one.
I'll remove it.
Quoted 18 lines
drivers/pwm/pwm-fsl-ftm.c line 285
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+dev_err (fpc->chip.dev,"fail to config pwm%d, the period " +"time should be the same with the current " +"running pwm(s).\n" , pwm->hwpwm);I think I'd make this error message more terse and put more information into a comment. Perhaps something like this:
/* * The FSL FTM controller supports only a single period for all PWM * channels, therefore incompatible changes need to be refused. */ if (fpc->period_ns && fpc->period_ns != period_ns) { dev_err(fpc->chip.dev, "conflicting period requested for PWM %u\n", pwm->hwpwm); ... }
Quoted 5 lines
drivers/pwm/pwm-fsl-ftm.c
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+mutex_unlock (&fpc->lock); +return -EINVAL ;I think something like
-EBUSYwould be more appropriate here.
Agree, I will use this.
Quoted 7 lines
drivers/pwm/pwm-fsl-ftm.c line 293
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+if (!fpc->period_ns && duty_ns) { + period =fsl_pwm_calculate_period (fpc, period_ns); +if (!period) { + dev_err(fpc->chip.dev, "fail to calculate the ""failed"
Quoted 9 lines
drivers/pwm/pwm-fsl-ftm.c line 294
Quoted 1 line
drivers/pwm/pwm-fsl-ftm.c +1
-0+ "period cycles.\n");And no fullstop either. Also I don't think you need "cycles" here. In fact something equally accurate like this:
dev_err(fpc->chip.dev, "failed to calculate period\n");Still fits within 80 characters.
Yes, I will.
Quoted 6 lines
drivers/pwm/pwm-fsl-ftm.c line 307
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+ fpc->period_ns = period_ns; + } +mutex_unlock (&fpc->lock);This could use a blank line as well.
I'll add it.
Quoted 12 lines
Quoted 1 line
+static int fsl_pwm_set_polarity(struct
pwm_chip*chip, structpwm_device*pwm,
drivers/pwm/pwm-fsl-ftm.c line 325
Quoted 7 lines
drivers/pwm/pwm-fsl-ftm.c +7
-0+ enum pwm_polarity polarity) +{ +u32 val; +struct fsl_pwm_chip *fpc =to_fsl_chip (chip); + + val =fsl_pwm_readl (fpc, fpc->base +FTM_POL ); +if (polarity ==PWM_POLARITY_INVERSED )Blank line between the above.
I will.
Quoted 25 lines
Quoted 12 lines
drivers/pwm/pwm-fsl-ftm.c +12
-0+static int fsl_pwm_probe (struct platform_device *pdev) { +int ret; +struct fsl_pwm_chip *fpc; +struct resource *res; +struct device_node *np = pdev->dev.of_node; + + fpc =devm_kzalloc (&pdev->dev,sizeof (*fpc),GFP_KERNEL ); +if (!fpc) +return -ENOMEM ; + +mutex_init (&fpc->lock); +drivers/pwm/pwm-fsl-ftm.c line 447
Quoted 10 lines
drivers/pwm/pwm-fsl-ftm.c +10
-0+ fpc->chip.dev = &pdev->dev; + + fpc->big_endian =of_property_read_bool (np,"big-endian" ); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + fpc->base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (fpc->base)) +return PTR_ERR (fpc->base); + + fpc->sys_clk =devm_clk_get (fpc->chip.dev,"ftm_sys" );For consistency I'd use
&pdev->devhere...
Quoted 5 lines
drivers/pwm/pwm-fsl-ftm.c line 449
Quoted 2 lines
drivers/pwm/pwm-fsl-ftm.c +2
-0+if (IS_ERR (fpc->sys_clk)) { + dev_err(fpc->chip.dev,... and here.
I will.
Quoted 7 lines
drivers/pwm/pwm-fsl-ftm.c line 471
Quoted 3 lines
drivers/pwm/pwm-fsl-ftm.c +3
-0+ ret =pwmchip_add (&fpc->chip); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to add PWM chip %d\n" , ret);Perhaps "failed to add PWM chip: %d\n", so that %d isn't confused to mean the PWM chip number?
Yes, that's better.
Quoted 8 lines
drivers/pwm/pwm-fsl-ftm.c line 484
Quoted 4 lines
drivers/pwm/pwm-fsl-ftm.c +4
-0+static int fsl_pwm_remove (struct platform_device *pdev) { +struct fsl_pwm_chip *fpc =platform_get_drvdata (pdev); + +mutex_destroy (&fpc->lock);I think you can drop this. Once
fsl_pwm_remove()exists, the memory pointed to by fpc will be freed, so you won't be able to access the mutex anyway.
Yes, actually it is.
Well I think this can make the code more robust and uniform.
Thanks,
--
Xiubo
PATCH v7 2/4 ARM: dts: Add Freescale FTM PWM node for VF610.
In reply to Xiubo LiThis adds devicetree node for VF610, and there are 8 channels supported.
--- arch/arm/boot/dts/vf610.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/boot/dts/vf610.dtsi +13 -0
@@ -140,6 +140,19 @@ clock-names = "pit"; }; + pwm0: pwm at 40038000 { + compatible = "fsl,vf610-ftm-pwm"; + #pwm-cells = <3>; + reg = <0x40038000 0x1000>; + clock-names = "ftm_sys", "ftm_ext", + "ftm_fix", "ftm_cnt_clk_en"; + clocks = <&clks VF610_CLK_FTM0>, + <&clks VF610_CLK_FTM0_EXT_SEL>, + <&clks VF610_CLK_FTM0_FIX_SEL>, + <&clks VF610_CLK_FTM0_EXT_FIX_EN>; + status = "disabled"; + }; + wdog at 4003e000 { compatible = "fsl,vf610-wdt", "fsl,imx21-wdt"; reg = <0x4003e000 0x1000>;
Signature · 1 line
1.8.4
PATCH v7 3/4 ARM: dts: Enables FTM PWM device for Vybrid VF610 TOWER board.
In reply to Xiubo Li--- arch/arm/boot/dts/vf610-twr.dts | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/boot/dts/vf610-twr.dts +6 -0
@@ -83,6 +83,12 @@ status = "okay"; }; +&pwm0 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_pwm0_1>; + status = "okay"; +}; + &uart1 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart1_1>;
Signature · 1 line
1.8.4
PATCH v7 4/4 Documentation: Add device tree bindings for Freescale FTM PWM.
In reply to Xiubo LiThis adds the binding documentation for Freescale FlexTimer Module (FTM) PWM driver under Documentation/devicetree/bindings/pwm/.
--- .../devicetree/bindings/pwm/pwm-fsl-ftm.txt | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt new file +38 -0
@@ -0,0 +1,38 @@ +Freescale FlexTimer Module (FTM) PWM controller + +Required properties: +- compatible: Should be "fsl,vf610-ftm-pwm". +- reg: Physical base address and length of the controller's registers +- #pwm-cells: Should be 3. See pwm.txt in this directory for a description of + the cells format. +- clock-names : Should include the following module clock source entries: + "ftm_sys" (module clock, also can be used as counter clock), + "ftm_ext" (external counter clock), + "ftm_fix" (fixed counter clock), + "ftm_cnt_clk_en" (external and fixed counter clock enable/disable). +- clocks : Must contain a clock specifier for each entry in clock-names, + See clock/clock-bindings.txt for details of the property values. +- pinctrl-names: Must contain a "default" entry. +- pinctrl-NNN: One property must exist for each entry in pinctrl-names. + See pinctrl/pinctrl-bindings.txt for details of the property values. +- big-endian: If this property is absent, the little endian mode will be in + use as default, or the big endian mode will be in use for all the device + registers. + + +Example: + +pwm0: pwm at 40038000 { + compatible = "fsl,vf610-ftm-pwm"; + reg = <0x40038000 0x1000>; + #pwm-cells = <3>; + clock-names = "ftm_sys", "ftm_ext", + "ftm_fix", "ftm_cnt_clk_en"; + clocks = <&clks VF610_CLK_FTM0>, + <&clks VF610_CLK_FTM0_EXT_SEL>, + <&clks VF610_CLK_FTM0_FIX_SEL>, + <&clks VF610_CLK_FTM0_EXT_FIX_EN>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_pwm0_1>; + big-endian; +};
Signature · 1 line
1.8.4