From patchwork Wed Mar 4 04:55:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: keita kobayashi X-Patchwork-Id: 5928601 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5CC94BF440 for ; Wed, 4 Mar 2015 04:56:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4B4B9203EB for ; Wed, 4 Mar 2015 04:56:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29F69203C1 for ; Wed, 4 Mar 2015 04:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753157AbbCDE4D (ORCPT ); Tue, 3 Mar 2015 23:56:03 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:24158 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752665AbbCDE4B (ORCPT ); Tue, 3 Mar 2015 23:56:01 -0500 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 04 Mar 2015 13:56:00 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 597C545D27; Wed, 4 Mar 2015 13:56:00 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 39763480A5; Wed, 4 Mar 2015 13:56:00 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 338B0480A3; Wed, 4 Mar 2015 13:56:00 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac4.idc.renesas.com with ESMTP id PAG27874; Wed, 4 Mar 2015 13:56:00 +0900 X-IronPort-AV: E=Sophos;i="5.09,685,1418050800"; d="scan'208";a="181119552" Received: from mail-sg1lp0094.outbound.protection.outlook.com (HELO APAC01-SG1-obe.outbound.protection.outlook.com) ([207.46.51.94]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 04 Mar 2015 13:55:59 +0900 Received: from localhost (211.11.155.147) by HKXPR06MB0565.apcprd06.prod.outlook.com (25.161.177.143) with Microsoft SMTP Server (TLS) id 15.1.99.14; Wed, 4 Mar 2015 04:55:57 +0000 From: Keita Kobayashi To: , CC: , , , Keita Kobayashi Subject: [RFC/PATCH 1/6] cpuidle: renesas: Add CPUIdle Driver for Renesas SoCs Date: Wed, 4 Mar 2015 13:55:41 +0900 Message-ID: <1425444946-3084-2-git-send-email-keita.kobayashi.ym@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.2 In-Reply-To: <1425444946-3084-1-git-send-email-keita.kobayashi.ym@renesas.com> References: <1425444946-3084-1-git-send-email-keita.kobayashi.ym@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.147] X-ClientProxiedBy: OS2PR01CA0001.jpnprd01.prod.outlook.com (25.161.74.139) To HKXPR06MB0565.apcprd06.prod.outlook.com (25.161.177.143) Authentication-Results: verge.net.au; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HKXPR06MB0565; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006); SRVR:HKXPR06MB0565; BCL:0; PCL:0; RULEID:; SRVR:HKXPR06MB0565; X-Forefront-PRVS: 0505147DDB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(6009001)(6029001)(22564002)(50986999)(47776003)(48376002)(66066001)(77156002)(2950100001)(36756003)(62966003)(50466002)(78352002)(87976001)(19580395003)(50226001)(19580405001)(92566002)(46102003)(122386002)(76176999)(76506005)(42186005)(229853001)(33646002)(40100003)(42382002); DIR:OUT; SFP:1102; SCL:1; SRVR:HKXPR06MB0565; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2015 04:55:57.8342 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKXPR06MB0565 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 This patch adds a cpuidle driver for Renesas SoCs. Signed-off-by: Keita Kobayashi --- drivers/cpuidle/Kconfig.arm | 8 ++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/cpuidle-renesas.c | 118 ++++++++++++++++++++++++++ include/linux/platform_data/renesas-cpuidle.h | 24 ++++++ 4 files changed, 151 insertions(+) create mode 100644 drivers/cpuidle/cpuidle-renesas.c create mode 100644 include/linux/platform_data/renesas-cpuidle.h diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index 8e07c94..01cb8cc 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -64,3 +64,11 @@ config ARM_MVEBU_V7_CPUIDLE depends on ARCH_MVEBU help Select this to enable cpuidle on Armada 370, 38x and XP processors. + +config ARM_RENESAS_CPUIDLE + bool "CPU Idle Driver for the renesas SoCs" + depends on ARCH_SHMOBILE_MULTI + select ARM_CPU_SUSPEND + select CPU_IDLE_MULTIPLE_DRIVERS + help + Select this to enable cpuidle for renesas SoCs diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index 4d177b9..c718906 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_ARM_ZYNQ_CPUIDLE) += cpuidle-zynq.o obj-$(CONFIG_ARM_U8500_CPUIDLE) += cpuidle-ux500.o obj-$(CONFIG_ARM_AT91_CPUIDLE) += cpuidle-at91.o obj-$(CONFIG_ARM_EXYNOS_CPUIDLE) += cpuidle-exynos.o +obj-$(CONFIG_ARM_RENESAS_CPUIDLE) += cpuidle-renesas.o ############################################################################### # MIPS drivers diff --git a/drivers/cpuidle/cpuidle-renesas.c b/drivers/cpuidle/cpuidle-renesas.c new file mode 100644 index 0000000..b469e95 --- /dev/null +++ b/drivers/cpuidle/cpuidle-renesas.c @@ -0,0 +1,118 @@ +/* + * CPUIdle support code for Renesas ARM + * + * Copyright (C) 2014 Renesas Electronics Corporation + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct cpuidle_driver renesas_cpuidle_default_driver = { + .name = "renesas_default_cpuidle", + .owner = THIS_MODULE, + .states[0] = ARM_CPUIDLE_WFI_STATE, + .safe_state_index = 0, /* C1 */ + .state_count = 1, +}; + +static struct renesas_cpuidle_driver default_driver = { + .target_cpu = -1, /* default */ + .renesas_drv = &renesas_cpuidle_default_driver, +}; + +static struct renesas_cpuidle cpuidle_data = { + .num_drvs = 1, + .rcd = &default_driver, +}; + +static int __init renesas_idle_driver_init(struct device *dev, + struct renesas_cpuidle_driver *rcd) +{ + struct cpumask *cpumask = NULL; + int cpu; + + for_each_online_cpu(cpu) { + if (smp_cpuid_part(cpu) == rcd->target_cpu || + rcd->target_cpu == -1) { /* default */ + if (!cpumask) { + cpumask = devm_kzalloc(dev, + cpumask_size(), GFP_KERNEL); + if (!cpumask) + return -ENOMEM; + } + cpumask_set_cpu(cpu, cpumask); + rcd->renesas_drv->cpumask = cpumask; + } + } + + return 0; +} + +static int renesas_cpuidle_probe(struct platform_device *pdev) +{ + struct renesas_cpuidle *pd = pdev->dev.platform_data; + struct renesas_cpuidle_driver *rcd; + int i, j, ret; + + if (!pd->num_drvs || !pd->rcd) + pd = &cpuidle_data; + + for (i = 0; i < pd->num_drvs; i++) { + rcd = pd->rcd + i; + ret = renesas_idle_driver_init(&pdev->dev, rcd); + if (ret) + goto out_uninit_driver; + + if (!rcd->renesas_drv->cpumask) + continue; + + ret = cpuidle_register(rcd->renesas_drv, NULL); + if (ret) { + dev_err(&pdev->dev, + "failed to register cpuidle driver\n"); + goto out_uninit_driver; + } + } + + return 0; + +out_uninit_driver: + for (j = 0; j < i; j++) { + rcd = pd->rcd + j; + + if (!rcd->renesas_drv->cpumask) + continue; + + cpuidle_unregister(rcd->renesas_drv); + } + + return ret; +} + +static struct platform_driver renesas_cpuidle_driver = { + .probe = renesas_cpuidle_probe, + .driver = { + .name = "cpuidle-renesas", + .owner = THIS_MODULE, + }, +}; + +module_platform_driver(renesas_cpuidle_driver); + +MODULE_DESCRIPTION("Renesas cpuidle driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/platform_data/renesas-cpuidle.h b/include/linux/platform_data/renesas-cpuidle.h new file mode 100644 index 0000000..9446215 --- /dev/null +++ b/include/linux/platform_data/renesas-cpuidle.h @@ -0,0 +1,24 @@ +/* + * renesas-cpuidle.h -- CPUIdle support code for Renesas ARM + * + * Copyright (C) 2014 Renesas Electronics Corporation + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ + +#ifndef __RENESAS_CPUIDLE_H__ +#define __RENESAS_CPUIDLE_H__ + +struct renesas_cpuidle_driver { + unsigned int target_cpu; + struct cpuidle_driver *renesas_drv; +}; + +struct renesas_cpuidle { + unsigned int num_drvs; + struct renesas_cpuidle_driver *rcd; +}; + +#endif /* __RENESAS_CPUIDLE_H__ */