From patchwork Thu Mar 10 05:11:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 481 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:43:02 -0000 Delivered-To: patches@linaro.org Received: by 10.224.67.207 with SMTP id s15cs6033qai; Wed, 9 Mar 2011 21:11:38 -0800 (PST) Received: by 10.204.26.215 with SMTP id f23mr3721935bkc.140.1299733897630; Wed, 09 Mar 2011 21:11:37 -0800 (PST) Received: from mail-bw0-f50.google.com (mail-bw0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id b12si7366548bkb.26.2011.03.09.21.11.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Mar 2011 21:11:36 -0800 (PST) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 209.85.214.50 as permitted sender) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of amitdanielk@gmail.com designates 209.85.214.50 as permitted sender) smtp.mail=amitdanielk@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by bwz2 with SMTP id 2so1841135bwz.37 for ; Wed, 09 Mar 2011 21:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer; bh=3rOetL2rbgn97or9qd+O2mxLTSfx3SB/cRXcN2VF628=; b=DQmH5Nus8BKvXvjnvpwSYZqWij/Y9y2zrZhNu/HrRdjZggGg0BmM8BUlsBHga1Hy+9 5+xse5YH15A79v7KqQMKLTc+QIgHCTeBRz1shTbyz8ruJbsCgSxhmNXWxhJ/UdDnFs+1 /eReItXKMJG3dwXamFTjRELbILHD+TnCreXiE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; b=nr/T/6X1YMETwxXHNAtHLwwd5GJZ2sV+ctme/XbFVoH+4eOwcxUgortKxaQtNlv9gh /D45wgk29aGRYPOl3OEyIgynmBdEx60vaTZJ1R8KL0j2k/zRTtYHr5Zwxug1ew+8dcy9 YC7PmIfNKNkb6xX9kR91tts4YL1228frFdnSE= Received: by 10.204.46.84 with SMTP id i20mr3024838bkf.62.1299733894922; Wed, 09 Mar 2011 21:11:34 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id q18sm1830124bka.3.2011.03.09.21.11.29 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Mar 2011 21:11:32 -0800 (PST) Sender: amit kachhap From: Amit Daniel Kachhap To: nicolas.pitre@linaro.org Cc: linaro-dev@lists.linaro.org, jc.lee@samsung.com, amit.kachhap@linaro.org, patches@linaro.org Subject: [PATCH] ARM: Samsung: Basic CPUIDLE Support Date: Thu, 10 Mar 2011 00:11:25 -0500 Message-Id: <1299733885-19716-1-git-send-email-amit.kachhap@linaro.org> X-Mailer: git-send-email 1.7.1 This patch supports cpuidle framework for samsung S5PV310. Currently, Only one idle state is possible to use, but more idle states can be added followed by this patch. Signed-off-by: Jaecheol Lee Signed-off-by: Amit Daniel Kachhap --- Rebasing the patch for linaro 2.6.38 kernel. This patch adds basic cpuidle infrastructure and fixes the launchpad bug(bug id: 723543). This patch is under review in samsung mailing list. http://www.spinics.net/lists/linux-samsung-soc/msg04268.html arch/arm/mach-s5pv310/Makefile | 1 + arch/arm/mach-s5pv310/cpuidle.c | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-s5pv310/cpuidle.c diff --git a/arch/arm/mach-s5pv310/Makefile b/arch/arm/mach-s5pv310/Makefile index 036fb38..c5db0fa 100644 --- a/arch/arm/mach-s5pv310/Makefile +++ b/arch/arm/mach-s5pv310/Makefile @@ -15,6 +15,7 @@ obj- := obj-$(CONFIG_CPU_S5PV310) += cpu.o init.o clock.o irq-combiner.o obj-$(CONFIG_CPU_S5PV310) += setup-i2c0.o time.o gpiolib.o irq-eint.o dma.o obj-$(CONFIG_CPU_FREQ) += cpufreq.o +obj-$(CONFIG_CPU_IDLE) += cpuidle.o obj-$(CONFIG_SMP) += platsmp.o headsmp.o obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o diff --git a/arch/arm/mach-s5pv310/cpuidle.c b/arch/arm/mach-s5pv310/cpuidle.c new file mode 100644 index 0000000..f35b537 --- /dev/null +++ b/arch/arm/mach-s5pv310/cpuidle.c @@ -0,0 +1,87 @@ +/* linux/arch/arm/mach-s5pv310/cpuidle.c + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +*/ + +#include +#include +#include +#include + +#include + +static int s5pv310_enter_idle(struct cpuidle_device *dev, + struct cpuidle_state *state); + +static struct cpuidle_state s5pv310_cpuidle_set[] = { + [0] = { + .enter = s5pv310_enter_idle, + .exit_latency = 1, + .target_residency = 100000, + .flags = CPUIDLE_FLAG_TIME_VALID, + .name = "IDLE", + .desc = "ARM clock gating(WFI)", + }, +}; + +static DEFINE_PER_CPU(struct cpuidle_device, s5pv310_cpuidle_device); + +static struct cpuidle_driver s5pv310_idle_driver = { + .name = "s5pv310_idle", + .owner = THIS_MODULE, +}; + +static int s5pv310_enter_idle(struct cpuidle_device *dev, + struct cpuidle_state *state) +{ + struct timeval before, after; + int idle_time; + + local_irq_disable(); + do_gettimeofday(&before); + + cpu_do_idle(); + + do_gettimeofday(&after); + local_irq_enable(); + idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC + + (after.tv_usec - before.tv_usec); + + return idle_time; +} + +static int __init s5pv310_init_cpuidle(void) +{ + int i, max_cpuidle_state, cpu_id; + struct cpuidle_device *device; + + cpuidle_register_driver(&s5pv310_idle_driver); + + for_each_cpu(cpu_id, cpu_online_mask) { + device = &per_cpu(s5pv310_cpuidle_device, cpu_id); + device->cpu = cpu_id; + + device->state_count = (sizeof(s5pv310_cpuidle_set) / + sizeof(struct cpuidle_state)); + + max_cpuidle_state = device->state_count; + + for (i = 0; i < max_cpuidle_state; i++) { + memcpy(&device->states[i], &s5pv310_cpuidle_set[i], + sizeof(struct cpuidle_state)); + } + + if (cpuidle_register_device(device)) { + printk(KERN_ERR "CPUidle register device failed\n,"); + return -EIO; + } + } + return 0; +} + +device_initcall(s5pv310_init_cpuidle);