From patchwork Wed Jun 26 13:33:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2786681 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 20F0B9F245 for ; Wed, 26 Jun 2013 15:31:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B318F202AB for ; Wed, 26 Jun 2013 15:31:55 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32E3C2026C for ; Wed, 26 Jun 2013 15:31:54 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UrrgZ-0005qb-14; Wed, 26 Jun 2013 15:31:08 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Urrg6-000484-I8; Wed, 26 Jun 2013 15:30:38 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Urrg4-00037P-Jw for linux-arm-kernel@merlin.infradead.org; Wed, 26 Jun 2013 15:30:36 +0000 Received: from mail-we0-x233.google.com ([2a00:1450:400c:c03::233]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Urpr4-00007L-Oi for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2013 13:33:51 +0000 Received: by mail-we0-f179.google.com with SMTP id w59so10031157wes.24 for ; Wed, 26 Jun 2013 06:33:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=cmBJE5IMb6rdTlNaV7QLR5O5rbjzN4OL6oiOLcePyMY=; b=JsRpPkf2/FmKECpT35L/5LU9bPzi7WRs3ew1OgZmITsP8nrGzPW2ekQ0KjFFZ9RF0z 2BWY+ZHSePKV+fpxclsEfQaw0ohMHNbpmOBCyfdih4ozvNIUio0qSF+7HEKy/TLSSWVJ 3qNerHrxlSpSD5sHs2sfKoF6O6Agcv2DICDwNGy63+Oi9R31ov0gnNdIXjgJdTSE9rS/ xoJAJ19SUNNCMoOSX64uViWXaLAe+jSlWtZqBoh71mwhQL8/oS+v0zg3nuJY85kVRqec 7auXz+ZpK/v0qRAvqRfWmIGRfPxbQdYGZ0bdNZ+RDbkMDocApvvfE1ZSU8N6s5zZ5LPn sVpA== X-Received: by 10.180.76.103 with SMTP id j7mr2723239wiw.21.1372253603552; Wed, 26 Jun 2013 06:33:23 -0700 (PDT) Received: from mai.home (AToulouse-654-1-288-212.w90-5.abo.wanadoo.fr. [90.5.191.212]) by mx.google.com with ESMTPSA id d8sm10951264wiz.0.2013.06.26.06.33.21 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Jun 2013 06:33:22 -0700 (PDT) From: Daniel Lezcano To: linux@maxim.org.za, nicolas.ferre@atmel.com, plagnioj@jcrosoft.com Subject: [RFC PATCH] ARM: at91: cpuidle: encapsulate the standby code Date: Wed, 26 Jun 2013 15:33:36 +0200 Message-Id: <1372253616-28086-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQmA9+E3I2FVNr+wM632v2XLRh2aV8eW84w1AWohRoCQIH9sJuBjNP4Vdzbrs4IZtYkBsp20 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130626_143350_972821_3E2827CC X-CRM114-Status: GOOD ( 21.76 ) X-Spam-Score: -1.9 (-) Cc: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to split the pm code from the cpuidle driver, add an ops for the standby function which will be initialized by the platform data depending of the SoC. Cleanup also the headers included in this file as they are no longer needed. Signed-off-by: Daniel Lezcano --- arch/arm/mach-at91/board-usb-a926x.c | 17 +++++++++++++++- arch/arm/mach-at91/cpuidle.c | 33 ++++++++++++++---------------- arch/arm/mach-at91/pm.c | 37 +++++++++++++++++++++++++--------- arch/arm/mach-at91/pm.h | 9 +++++++++ 4 files changed, 68 insertions(+), 28 deletions(-) diff --git a/arch/arm/mach-at91/board-usb-a926x.c b/arch/arm/mach-at91/board-usb-a926x.c index 2487d94..b35f8fd 100644 --- a/arch/arm/mach-at91/board-usb-a926x.c +++ b/arch/arm/mach-at91/board-usb-a926x.c @@ -49,7 +49,6 @@ #include "sam9_smc.h" #include "generic.h" - static void __init ek_init_early(void) { /* Initialize processor: 12.00 MHz crystal */ @@ -319,6 +318,19 @@ static void __init ek_add_device_leds(void) at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds)); } +#ifdef CONFIG_PM +static struct platform_device at91_pm_device = { + .name = "pm-at91", + .id = -1, +}; +#endif + +static struct platform_device *platform_devices[] __initdata = { +#ifdef CONFIG_PM + &at91_pm_device, +#endif +}; + static void __init ek_board_init(void) { /* Serial */ @@ -351,6 +363,9 @@ static void __init ek_board_init(void) | AT91_SHDW_WKMODE0_LOW | AT91_SHDW_RTTWKEN); } + + /* Platform devices */ + platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices)); } MACHINE_START(USB_A9263, "CALAO USB_A9263") diff --git a/arch/arm/mach-at91/cpuidle.c b/arch/arm/mach-at91/cpuidle.c index 4ec6a6d..8bfaad0 100644 --- a/arch/arm/mach-at91/cpuidle.c +++ b/arch/arm/mach-at91/cpuidle.c @@ -13,33 +13,21 @@ * #2 wait-for-interrupt and RAM self refresh */ -#include #include #include #include -#include -#include -#include #include -#include - -#include "pm.h" #define AT91_MAX_STATES 2 +static void (*at91_standby_ops)(void); + /* Actual code that puts the SoC in different idle states */ static int at91_enter_idle(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { - if (cpu_is_at91rm9200()) - at91rm9200_standby(); - else if (cpu_is_at91sam9g45()) - at91sam9g45_standby(); - else if (cpu_is_at91sam9263()) - at91sam9263_standby(); - else - at91sam9_standby(); + at91_standby_ops(); return index; } @@ -60,9 +48,18 @@ static struct cpuidle_driver at91_idle_driver = { }; /* Initialize CPU idle by registering the idle states */ -static int __init at91_init_cpuidle(void) +int __init at91_init_cpuidle(struct platform_device *pdev) { - return cpuidle_register(&at91_idle_driver, NULL); + if (!pdev->dev.platform_data) + BUG(); + + at91_standby_ops = pdev->dev.platform_data; + + return 0; } -device_initcall(at91_init_cpuidle); +static int __init at91_cpuidle_init(void) +{ + return cpuidle_register(&at91_idle_driver, NULL); +} +device_initcall(at91_cpuidle_init); diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c index 530db30..c5f4654 100644 --- a/arch/arm/mach-at91/pm.c +++ b/arch/arm/mach-at91/pm.c @@ -314,21 +314,40 @@ static const struct platform_suspend_ops at91_pm_ops = { .end = at91_pm_end, }; -static int __init at91_pm_init(void) +static int __init at91_pm_probe(struct platform_device *pdev) { -#ifdef CONFIG_AT91_SLOW_CLOCK - slow_clock = (void *) (AT91_IO_VIRT_BASE - at91_slow_clock_sz); -#endif - - pr_info("AT91: Power Management%s\n", (slow_clock ? " (with slow clock mode)" : "")); - /* AT91RM9200 SDRAM low-power mode cannot be used with self-refresh. */ - if (cpu_is_at91rm9200()) + if (of_machine_is_compatible("atmel,at91rm9200")) { at91_ramc_write(0, AT91RM9200_SDRAMC_LPR, 0); + pdev->dev.platform_data = at91rm9200_standby; + } else if (of_machine_is_compatible("atmel,atmel,at91sam9g45")) { + pdev->dev.platform_data = at91sam9g45_standby; + } else { + pdev->dev.platform_data = at91sam9_standby; + } suspend_set_ops(&at91_pm_ops); show_reset_status(); - return 0; + + return at91_init_cpuidle(pdev); +} + +static struct platform_driver at91_pm_driver = { + .driver = { + .name = "pm-at91", + .owner = THIS_MODULE, + }, +}; + +static int __init at91_pm_init(void) +{ +#ifdef CONFIG_AT91_SLOW_CLOCK + slow_clock = (void *) (AT91_IO_VIRT_BASE - at91_slow_clock_sz); +#endif + pr_info("AT91: Power Management%s\n", + (slow_clock ? " (with slow clock mode)" : "")); + + return platform_driver_probe(&at91_pm_driver, at91_pm_probe); } arch_initcall(at91_pm_init); diff --git a/arch/arm/mach-at91/pm.h b/arch/arm/mach-at91/pm.h index 2f5908f..897bed5 100644 --- a/arch/arm/mach-at91/pm.h +++ b/arch/arm/mach-at91/pm.h @@ -111,4 +111,13 @@ static inline void at91sam9_standby(void) at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr); } +#ifdef CONFIG_CPU_IDLE +extern int at91_init_cpuidle(struct platform_device *pdev); +#else +static inline int at91_init_cpuidle(struct platform_device *pdev) +{ + return 0; +} +#endif + #endif