blob: e0ffbe9a984458789339db560ddc77ffeeb88477 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pmu.c, Power Management Unit routines for NEC VR4100 series.
3 *
Yoichi Yuasa61a33162007-08-07 00:09:17 +09004 * Copyright (C) 2003-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070020#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070022#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel.h>
Ralf Baechlefcdb27a2006-01-18 17:37:07 +000024#include <linux/pm.h>
Yoichi Yuasa61a33162007-08-07 00:09:17 +090025#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/types.h>
27
28#include <asm/cpu.h>
29#include <asm/io.h>
Yoichi Yuasa61a33162007-08-07 00:09:17 +090030#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/reboot.h>
32#include <asm/system.h>
33
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070034#define PMU_TYPE1_BASE 0x0b0000a0UL
35#define PMU_TYPE1_SIZE 0x0eUL
36
37#define PMU_TYPE2_BASE 0x0f0000c0UL
38#define PMU_TYPE2_SIZE 0x10UL
39
40#define PMUCNT2REG 0x06
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 #define SOFTRST 0x0010
42
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070043static void __iomem *pmu_base;
44
45#define pmu_read(offset) readw(pmu_base + (offset))
46#define pmu_write(offset, value) writew((value), pmu_base + (offset))
47
Yoichi Yuasa61a33162007-08-07 00:09:17 +090048static void vr41xx_cpu_wait(void)
49{
50 local_irq_disable();
51 if (!need_resched())
52 /*
53 * "standby" sets IE bit of the CP0_STATUS to 1.
54 */
55 __asm__("standby;\n");
56 else
57 local_irq_enable();
58}
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static inline void software_reset(void)
61{
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070062 uint16_t pmucnt2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 switch (current_cpu_data.cputype) {
65 case CPU_VR4122:
66 case CPU_VR4131:
67 case CPU_VR4133:
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070068 pmucnt2 = pmu_read(PMUCNT2REG);
69 pmucnt2 |= SOFTRST;
70 pmu_write(PMUCNT2REG, pmucnt2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 break;
72 default:
73 break;
74 }
75}
76
77static void vr41xx_restart(char *command)
78{
79 local_irq_disable();
80 software_reset();
81 printk(KERN_NOTICE "\nYou can reset your system\n");
82 while (1) ;
83}
84
85static void vr41xx_halt(void)
86{
87 local_irq_disable();
88 printk(KERN_NOTICE "\nYou can turn off the power supply\n");
89 while (1) ;
90}
91
92static void vr41xx_power_off(void)
93{
94 local_irq_disable();
95 printk(KERN_NOTICE "\nYou can turn off the power supply\n");
96 while (1) ;
97}
98
99static int __init vr41xx_pmu_init(void)
100{
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -0700101 unsigned long start, size;
102
103 switch (current_cpu_data.cputype) {
104 case CPU_VR4111:
105 case CPU_VR4121:
106 start = PMU_TYPE1_BASE;
107 size = PMU_TYPE1_SIZE;
108 break;
109 case CPU_VR4122:
110 case CPU_VR4131:
111 case CPU_VR4133:
112 start = PMU_TYPE2_BASE;
113 size = PMU_TYPE2_SIZE;
114 break;
115 default:
116 printk("Unexpected CPU of NEC VR4100 series\n");
117 return -ENODEV;
118 }
119
120 if (request_mem_region(start, size, "PMU") == NULL)
121 return -EBUSY;
122
123 pmu_base = ioremap(start, size);
124 if (pmu_base == NULL) {
125 release_mem_region(start, size);
126 return -EBUSY;
127 }
128
Yoichi Yuasa61a33162007-08-07 00:09:17 +0900129 cpu_wait = vr41xx_cpu_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 _machine_restart = vr41xx_restart;
131 _machine_halt = vr41xx_halt;
Ralf Baechlefcdb27a2006-01-18 17:37:07 +0000132 pm_power_off = vr41xx_power_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 return 0;
135}
136
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -0700137core_initcall(vr41xx_pmu_init);