Message ID | 1320410349-14600-1-git-send-email-chenhui.zhao@freescale.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On 11/04/2011 07:39 AM, Zhao Chenhui wrote: > @@ -45,6 +46,72 @@ static int has_lossless; > * code can be compatible with both 32-bit & 36-bit */ > extern void mpc85xx_enter_deep_sleep(u64 ccsrbar, u32 powmgtreq); > > +#ifdef CONFIG_FSL_PMC > +/** > + * pmc_enable_wake - enable OF device as wakeup event source > + * @pdev: platform device affected > + * @state: PM state from which device will issue wakeup events > + * @enable: True to enable event generation; false to disable > + * > + * This enables the device as a wakeup event source, or disables it. > + * > + * RETURN VALUE: > + * 0 is returned on success > + * -EINVAL is returned if device is not supposed to wake up the system > + * Error code depending on the platform is returned if both the platform and > + * the native mechanism fail to enable the generation of wake-up events > + */ > +int pmc_enable_wake(struct platform_device *pdev, > + suspend_state_t state, bool enable) "pmc" is too generic for a global function. If this can be either enable or disable, perhaps it should be something like mpc85xx_pmc_set_wake(). > +{ > + int ret = 0; > + struct device_node *clk_np; > + u32 *pmcdr_mask; > + > + if (!pmc_regs) { > + printk(KERN_WARNING "PMC is unavailable\n"); > + return -ENOMEM; > + } -ENOMEM is not appropriate here, maybe -ENODEV? Should print __func__ so the user knows what's complaining. > + if (enable && !device_may_wakeup(&pdev->dev)) > + return -EINVAL; > + > + clk_np = of_parse_phandle(pdev->dev.of_node, "clk-handle", 0); > + if (!clk_np) > + return -EINVAL; > + > + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); > + if (!pmcdr_mask) { > + ret = -EINVAL; > + goto out; > + } > + > + /* clear to enable clock in low power mode */ > + if (enable) > + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); > + else > + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); We should probably initialize PMCDR to all bits set (or at least all ones we know are valid) -- the default should be "not a wakeup source". > +/** > + * pmc_enable_lossless - enable lossless ethernet in low power mode > + * @enable: True to enable event generation; false to disable > + */ > +void pmc_enable_lossless(int enable) > +{ > + if (enable && has_lossless) > + setbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); > + else > + clrbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); > +} > +EXPORT_SYMBOL_GPL(pmc_enable_lossless); > +#endif Won't we overwrite this later? -Scott
On Fri, Nov 4, 2011 at 7:39 AM, Zhao Chenhui <chenhui.zhao@freescale.com> wrote: > + if (!pmc_regs) { > + printk(KERN_WARNING "PMC is unavailable\n"); Use pr_warn() and the other pr_xxx functions. > + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); The typecast is unnecessary here. > + /* clear to enable clock in low power mode */ > + if (enable) > + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); > + else > + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); You need to use be32_to_cpup() when dereferencing a pointer to a device tree property.
On Fri, Nov 04, 2011 at 04:14:25PM -0500, Scott Wood wrote: > On 11/04/2011 07:39 AM, Zhao Chenhui wrote: > > @@ -45,6 +46,72 @@ static int has_lossless; > > * code can be compatible with both 32-bit & 36-bit */ > > extern void mpc85xx_enter_deep_sleep(u64 ccsrbar, u32 powmgtreq); > > > > +#ifdef CONFIG_FSL_PMC > > +/** > > + * pmc_enable_wake - enable OF device as wakeup event source > > + * @pdev: platform device affected > > + * @state: PM state from which device will issue wakeup events > > + * @enable: True to enable event generation; false to disable > > + * > > + * This enables the device as a wakeup event source, or disables it. > > + * > > + * RETURN VALUE: > > + * 0 is returned on success > > + * -EINVAL is returned if device is not supposed to wake up the system > > + * Error code depending on the platform is returned if both the platform and > > + * the native mechanism fail to enable the generation of wake-up events > > + */ > > +int pmc_enable_wake(struct platform_device *pdev, > > + suspend_state_t state, bool enable) > > "pmc" is too generic for a global function. If this can be either > enable or disable, perhaps it should be something like > mpc85xx_pmc_set_wake(). > > > +{ > > + int ret = 0; > > + struct device_node *clk_np; > > + u32 *pmcdr_mask; > > + > > + if (!pmc_regs) { > > + printk(KERN_WARNING "PMC is unavailable\n"); > > + return -ENOMEM; > > + } > > -ENOMEM is not appropriate here, maybe -ENODEV? > > Should print __func__ so the user knows what's complaining. > > > + if (enable && !device_may_wakeup(&pdev->dev)) > > + return -EINVAL; > > + > > + clk_np = of_parse_phandle(pdev->dev.of_node, "clk-handle", 0); > > + if (!clk_np) > > + return -EINVAL; > > + > > + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); > > + if (!pmcdr_mask) { > > + ret = -EINVAL; > > + goto out; > > + } > > + > > + /* clear to enable clock in low power mode */ > > + if (enable) > > + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); > > + else > > + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); > > We should probably initialize PMCDR to all bits set (or at least all > ones we know are valid) -- the default should be "not a wakeup source". I think it should be initialized in u-boot. > > > +/** > > + * pmc_enable_lossless - enable lossless ethernet in low power mode > > + * @enable: True to enable event generation; false to disable > > + */ > > +void pmc_enable_lossless(int enable) > > +{ > > + if (enable && has_lossless) > > + setbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); > > + else > > + clrbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); > > +} > > +EXPORT_SYMBOL_GPL(pmc_enable_lossless); > > +#endif > > Won't we overwrite this later? > > -Scott Do you have any idea? -chenhui
On Fri, Nov 04, 2011 at 07:08:24PM -0500, Tabi Timur-B04825 wrote: > On Fri, Nov 4, 2011 at 7:39 AM, Zhao Chenhui <chenhui.zhao@freescale.com> wrote: > > > + if (!pmc_regs) { > > + printk(KERN_WARNING "PMC is unavailable\n"); > > Use pr_warn() and the other pr_xxx functions. > > > + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); > > The typecast is unnecessary here. > > > + /* clear to enable clock in low power mode */ > > + if (enable) > > + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); > > + else > > + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); > > You need to use be32_to_cpup() when dereferencing a pointer to a > device tree property. > > -- > Timur Tabi > Linux kernel developer at Freescale Thanks. I will fix them all. -chenhui
On 11/07/2011 05:22 AM, Zhao Chenhui wrote: > On Fri, Nov 04, 2011 at 04:14:25PM -0500, Scott Wood wrote: >> On 11/04/2011 07:39 AM, Zhao Chenhui wrote: >>> + if (enable && !device_may_wakeup(&pdev->dev)) >>> + return -EINVAL; >>> + >>> + clk_np = of_parse_phandle(pdev->dev.of_node, "clk-handle", 0); >>> + if (!clk_np) >>> + return -EINVAL; >>> + >>> + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); >>> + if (!pmcdr_mask) { >>> + ret = -EINVAL; >>> + goto out; >>> + } >>> + >>> + /* clear to enable clock in low power mode */ >>> + if (enable) >>> + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); >>> + else >>> + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); >> >> We should probably initialize PMCDR to all bits set (or at least all >> ones we know are valid) -- the default should be "not a wakeup source". > > I think it should be initialized in u-boot. I don't see it. If you mean you think this should be added to U-Boot, I disagree. U-Boot does not use this, and we should not add gratuitous U-Boot dependencies to Linux -- especially in cases where there are existing U-Boots in use for relevant boards, that do not have this. >>> +/** >>> + * pmc_enable_lossless - enable lossless ethernet in low power mode >>> + * @enable: True to enable event generation; false to disable >>> + */ >>> +void pmc_enable_lossless(int enable) >>> +{ >>> + if (enable && has_lossless) >>> + setbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); >>> + else >>> + clrbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); >>> +} >>> +EXPORT_SYMBOL_GPL(pmc_enable_lossless); >>> +#endif >> >> Won't we overwrite this later? >> >> -Scott > > Do you have any idea? Set a flag that the code that enters (deep) sleep can use. Also, rename function to mpc85xx_pmc_set_lossless_ethernet(). -Scott
On 11/04/2011 07:08 PM, Tabi Timur-B04825 wrote: > On Fri, Nov 4, 2011 at 7:39 AM, Zhao Chenhui <chenhui.zhao@freescale.com> wrote: >> + /* clear to enable clock in low power mode */ >> + if (enable) >> + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); >> + else >> + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); > > You need to use be32_to_cpup() when dereferencing a pointer to a > device tree property. Or just use of_property_read_u32(). -Scott
>-----Original Message----- >From: linuxppc-dev-bounces+leoli=freescale.com@lists.ozlabs.org >[mailto:linuxppc-dev-bounces+leoli=freescale.com@lists.ozlabs.org] On >Behalf Of Scott Wood >Sent: Saturday, November 05, 2011 5:14 AM >To: Zhao Chenhui-B35336 >Cc: netdev@vger.kernel.org; linuxppc-dev@lists.ozlabs.org >Subject: Re: [PATCH 6/7] fsl_pmc: Add API to enable device as wakeup event >source > >On 11/04/2011 07:39 AM, Zhao Chenhui wrote: >> @@ -45,6 +46,72 @@ static int has_lossless; >> * code can be compatible with both 32-bit & 36-bit */ extern void >> mpc85xx_enter_deep_sleep(u64 ccsrbar, u32 powmgtreq); >> >> +#ifdef CONFIG_FSL_PMC >> +/** >> + * pmc_enable_wake - enable OF device as wakeup event source >> + * @pdev: platform device affected >> + * @state: PM state from which device will issue wakeup events >> + * @enable: True to enable event generation; false to disable >> + * >> + * This enables the device as a wakeup event source, or disables it. >> + * >> + * RETURN VALUE: >> + * 0 is returned on success >> + * -EINVAL is returned if device is not supposed to wake up the >> +system >> + * Error code depending on the platform is returned if both the >> +platform and >> + * the native mechanism fail to enable the generation of wake-up >> +events */ int pmc_enable_wake(struct platform_device *pdev, >> + suspend_state_t state, bool enable) > >"pmc" is too generic for a global function. If this can be either enable >or disable, perhaps it should be something like mpc85xx_pmc_set_wake(). > >> +{ >> + int ret = 0; >> + struct device_node *clk_np; >> + u32 *pmcdr_mask; >> + >> + if (!pmc_regs) { >> + printk(KERN_WARNING "PMC is unavailable\n"); >> + return -ENOMEM; >> + } > >-ENOMEM is not appropriate here, maybe -ENODEV? > >Should print __func__ so the user knows what's complaining. > >> + if (enable && !device_may_wakeup(&pdev->dev)) >> + return -EINVAL; >> + >> + clk_np = of_parse_phandle(pdev->dev.of_node, "clk-handle", 0); >> + if (!clk_np) >> + return -EINVAL; >> + >> + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); >> + if (!pmcdr_mask) { >> + ret = -EINVAL; >> + goto out; >> + } >> + >> + /* clear to enable clock in low power mode */ >> + if (enable) >> + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); >> + else >> + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); > >We should probably initialize PMCDR to all bits set (or at least all ones >we know are valid) -- the default should be "not a wakeup source". Ideally I agree with you. But currently we only have the UI of changing wake-up source for Ethernet device. Will do when we can change all of the devices. > >> +/** >> + * pmc_enable_lossless - enable lossless ethernet in low power mode >> + * @enable: True to enable event generation; false to disable */ >> +void pmc_enable_lossless(int enable) { >> + if (enable && has_lossless) >> + setbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); >> + else >> + clrbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); } >> +EXPORT_SYMBOL_GPL(pmc_enable_lossless); >> +#endif > >Won't we overwrite this later? You are right. Will remove the code that overwrite this. - Leo
diff --git a/arch/powerpc/sysdev/fsl_pmc.c b/arch/powerpc/sysdev/fsl_pmc.c index 58d35d8..dab8161 100644 --- a/arch/powerpc/sysdev/fsl_pmc.c +++ b/arch/powerpc/sysdev/fsl_pmc.c @@ -38,6 +38,7 @@ static struct device *pmc_dev; static struct pmc_regs __iomem *pmc_regs; #define PMCSR_SLP 0x00020000 +#define PMCSR_LOSSLESS 0x00400000 static int has_deep_sleep; static int has_lossless; @@ -45,6 +46,72 @@ static int has_lossless; * code can be compatible with both 32-bit & 36-bit */ extern void mpc85xx_enter_deep_sleep(u64 ccsrbar, u32 powmgtreq); +#ifdef CONFIG_FSL_PMC +/** + * pmc_enable_wake - enable OF device as wakeup event source + * @pdev: platform device affected + * @state: PM state from which device will issue wakeup events + * @enable: True to enable event generation; false to disable + * + * This enables the device as a wakeup event source, or disables it. + * + * RETURN VALUE: + * 0 is returned on success + * -EINVAL is returned if device is not supposed to wake up the system + * Error code depending on the platform is returned if both the platform and + * the native mechanism fail to enable the generation of wake-up events + */ +int pmc_enable_wake(struct platform_device *pdev, + suspend_state_t state, bool enable) +{ + int ret = 0; + struct device_node *clk_np; + u32 *pmcdr_mask; + + if (!pmc_regs) { + printk(KERN_WARNING "PMC is unavailable\n"); + return -ENOMEM; + } + + if (enable && !device_may_wakeup(&pdev->dev)) + return -EINVAL; + + clk_np = of_parse_phandle(pdev->dev.of_node, "clk-handle", 0); + if (!clk_np) + return -EINVAL; + + pmcdr_mask = (u32 *)of_get_property(clk_np, "fsl,pmcdr-mask", NULL); + if (!pmcdr_mask) { + ret = -EINVAL; + goto out; + } + + /* clear to enable clock in low power mode */ + if (enable) + clrbits32(&pmc_regs->pmcdr, *pmcdr_mask); + else + setbits32(&pmc_regs->pmcdr, *pmcdr_mask); + +out: + of_node_put(clk_np); + return ret; +} +EXPORT_SYMBOL_GPL(pmc_enable_wake); + +/** + * pmc_enable_lossless - enable lossless ethernet in low power mode + * @enable: True to enable event generation; false to disable + */ +void pmc_enable_lossless(int enable) +{ + if (enable && has_lossless) + setbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); + else + clrbits32(&pmc_regs->pmcsr, PMCSR_LOSSLESS); +} +EXPORT_SYMBOL_GPL(pmc_enable_lossless); +#endif + static int pmc_suspend_enter(suspend_state_t state) { int ret; diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h index c6d0073..f4f322a 100644 --- a/arch/powerpc/sysdev/fsl_soc.h +++ b/arch/powerpc/sysdev/fsl_soc.h @@ -3,6 +3,8 @@ #ifdef __KERNEL__ #include <asm/mmu.h> +#include <linux/platform_device.h> +#include <linux/suspend.h> struct spi_device; @@ -21,6 +23,15 @@ struct device_node; extern void fsl_rstcr_restart(char *cmd); +#ifdef CONFIG_FSL_PMC +int pmc_enable_wake(struct platform_device *pdev, suspend_state_t state, + bool enable); +void pmc_enable_lossless(int enable); +#else +#define pmc_enable_wake(pdev, state, enable) +#define pmc_enable_lossless(enable) +#endif + #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) /* The different ports that the DIU can be connected to */