From patchwork Wed Nov 16 09:55:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenhui zhao X-Patchwork-Id: 125968 X-Patchwork-Delegate: galak@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 33240B7512 for ; Wed, 16 Nov 2011 20:56:50 +1100 (EST) Received: from TX2EHSOBE008.bigfish.com (tx2ehsobe004.messaging.microsoft.com [65.55.88.14]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client CN "mail.global.frontbridge.com", Issuer "Microsoft Secure Server Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 73BF2B6F98 for ; Wed, 16 Nov 2011 20:56:05 +1100 (EST) Received: from mail194-tx2-R.bigfish.com (10.9.14.251) by TX2EHSOBE008.bigfish.com (10.9.40.28) with Microsoft SMTP Server id 14.1.225.22; Wed, 16 Nov 2011 09:55:26 +0000 Received: from mail194-tx2 (localhost.localdomain [127.0.0.1]) by mail194-tx2-R.bigfish.com (Postfix) with ESMTP id C3C5817800AE for ; Wed, 16 Nov 2011 09:55:44 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail194-tx2 (localhost.localdomain [127.0.0.1]) by mail194-tx2 (MessageSwitch) id 1321437344391369_5310; Wed, 16 Nov 2011 09:55:44 +0000 (UTC) Received: from TX2EHSMHS044.bigfish.com (unknown [10.9.14.254]) by mail194-tx2.bigfish.com (Postfix) with ESMTP id 50C9D1C1804C for ; Wed, 16 Nov 2011 09:55:44 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS044.bigfish.com (10.9.99.144) with Microsoft SMTP Server (TLS) id 14.1.225.22; Wed, 16 Nov 2011 09:55:57 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server id 14.1.339.2; Wed, 16 Nov 2011 03:55:53 -0600 Received: from localhost.localdomain ([10.193.20.166]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id pAG9tfgQ005587; Wed, 16 Nov 2011 03:55:51 -0600 (CST) From: Zhao Chenhui To: Subject: [PATCH v2 6/7] fsl_pmc: Add API to enable device as wakeup event source Date: Wed, 16 Nov 2011 17:55:44 +0800 Message-ID: <1321437344-19253-6-git-send-email-chenhui.zhao@freescale.com> X-Mailer: git-send-email 1.6.4.1 In-Reply-To: <1321437344-19253-1-git-send-email-chenhui.zhao@freescale.com> References: <1321437344-19253-1-git-send-email-chenhui.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Cc: scottwood@freescale.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Add APIs for setting wakeup source and lossless Ethernet in low power modes. These APIs can be used by wake-on-packet feature. Signed-off-by: Dave Liu Signed-off-by: Li Yang Signed-off-by: Jin Qing Signed-off-by: Zhao Chenhui --- Changes for v2: - rename functions - add pmc_flag arch/powerpc/sysdev/fsl_pmc.c | 72 ++++++++++++++++++++++++++++++++++++++++- arch/powerpc/sysdev/fsl_soc.h | 9 +++++ 2 files changed, 80 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/sysdev/fsl_pmc.c b/arch/powerpc/sysdev/fsl_pmc.c index d6c65a7..6a2f8b4 100644 --- a/arch/powerpc/sysdev/fsl_pmc.c +++ b/arch/powerpc/sysdev/fsl_pmc.c @@ -40,13 +40,83 @@ static unsigned int pmc_flag; #define PMC_SLEEP 0x1 #define PMC_DEEP_SLEEP 0x2 +#define PMC_LOSSLESS 0x4 #define POWMGTCSR_SLP_MASK 0x00020000 +#define POWMGTCSR_LOSSLESS_MASK 0x00400000 /* Cast the ccsrbar to 64-bit parameter so that the assembly * code can be compatible with both 32-bit & 36-bit */ extern void mpc85xx_enter_deep_sleep(u64 ccsrbar); +#ifdef CONFIG_FSL_PMC +/** + * mpc85xx_pmc_set_wake - enable OF device as wakeup event source + * @pdev: platform device affected + * @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 mpc85xx_pmc_set_wake(struct platform_device *pdev, bool enable) +{ + int ret = 0; + struct device_node *clk_np; + u32 pmcdr_mask; + + if (!pmc_regs) { + pr_err("%s: PMC is unavailable\n", __func__); + return -ENODEV; + } + + 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; + + if (of_property_read_u32(clk_np, "fsl,pmcdr-mask", &pmcdr_mask)) { + ret = -EINVAL; + goto out; + } + + if (enable) + /* clear to enable clock in low power mode */ + clrbits32(&pmc_regs->pmcdr, pmcdr_mask); + else + setbits32(&pmc_regs->pmcdr, pmcdr_mask); + +out: + of_node_put(clk_np); + return ret; +} +EXPORT_SYMBOL_GPL(mpc85xx_pmc_set_wake); + +/** + * mpc85xx_pmc_set_lossless_ethernet - enable lossless ethernet + * in (deep) sleep mode + * @enable: True to enable event generation; false to disable + */ +void mpc85xx_pmc_set_lossless_ethernet(int enable) +{ + if (pmc_flag & PMC_LOSSLESS) { + if (enable) + setbits32(&pmc_regs->powmgtcsr, + POWMGTCSR_LOSSLESS_MASK); + else + clrbits32(&pmc_regs->powmgtcsr, + POWMGTCSR_LOSSLESS_MASK); + } +} +EXPORT_SYMBOL_GPL(mpc85xx_pmc_set_lossless_ethernet); +#endif + static int pmc_suspend_enter(suspend_state_t state) { int ret = 0; @@ -120,7 +190,7 @@ static int pmc_probe(struct platform_device *pdev) pmc_flag |= PMC_DEEP_SLEEP; if (of_device_is_compatible(np, "fsl,p1022-pmc")) - pmc_flag |= PMC_DEEP_SLEEP; + pmc_flag |= PMC_DEEP_SLEEP | PMC_LOSSLESS; suspend_set_ops(&pmc_suspend_ops); diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h index c6d0073..3422b0d 100644 --- a/arch/powerpc/sysdev/fsl_soc.h +++ b/arch/powerpc/sysdev/fsl_soc.h @@ -3,6 +3,7 @@ #ifdef __KERNEL__ #include +#include struct spi_device; @@ -21,6 +22,14 @@ struct device_node; extern void fsl_rstcr_restart(char *cmd); +#ifdef CONFIG_FSL_PMC +int mpc85xx_pmc_set_wake(struct platform_device *pdev, bool enable); +void mpc85xx_pmc_set_lossless_ethernet(int enable); +#else +#define mpc85xx_pmc_set_wake(pdev, enable) +#define mpc85xx_pmc_set_lossless_ethernet(enable) +#endif + #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) /* The different ports that the DIU can be connected to */