blob: ba0a4f6483a2134845fc26ed2db51194ed7011de [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
Yoichi Yuasa2f2a2d92007-08-16 22:20:11 +090028#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/cpu.h>
30#include <asm/io.h>
Yoichi Yuasa61a33162007-08-07 00:09:17 +090031#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/reboot.h>
33#include <asm/system.h>
34
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070035#define PMU_TYPE1_BASE 0x0b0000a0UL
36#define PMU_TYPE1_SIZE 0x0eUL
37
38#define PMU_TYPE2_BASE 0x0f0000c0UL
39#define PMU_TYPE2_SIZE 0x10UL
40
41#define PMUCNT2REG 0x06
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 #define SOFTRST 0x0010
43
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070044static void __iomem *pmu_base;
45
46#define pmu_read(offset) readw(pmu_base + (offset))
47#define pmu_write(offset, value) writew((value), pmu_base + (offset))
48
Yoichi Yuasa61a33162007-08-07 00:09:17 +090049static void vr41xx_cpu_wait(void)
50{
51 local_irq_disable();
52 if (!need_resched())
53 /*
54 * "standby" sets IE bit of the CP0_STATUS to 1.
55 */
56 __asm__("standby;\n");
57 else
58 local_irq_enable();
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static inline void software_reset(void)
62{
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070063 uint16_t pmucnt2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 switch (current_cpu_data.cputype) {
66 case CPU_VR4122:
67 case CPU_VR4131:
68 case CPU_VR4133:
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070069 pmucnt2 = pmu_read(PMUCNT2REG);
70 pmucnt2 |= SOFTRST;
71 pmu_write(PMUCNT2REG, pmucnt2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 break;
73 default:
Yoichi Yuasa2f2a2d92007-08-16 22:20:11 +090074 set_c0_status(ST0_BEV | ST0_ERL);
75 change_c0_config(CONF_CM_CMASK, CONF_CM_UNCACHED);
76 flush_cache_all();
77 write_c0_wired(0);
78 __asm__("jr %0"::"r"(0xbfc00000));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 break;
80 }
81}
82
83static void vr41xx_restart(char *command)
84{
85 local_irq_disable();
86 software_reset();
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 while (1) ;
88}
89
90static void vr41xx_halt(void)
91{
92 local_irq_disable();
93 printk(KERN_NOTICE "\nYou can turn off the power supply\n");
94 while (1) ;
95}
96
97static void vr41xx_power_off(void)
98{
99 local_irq_disable();
100 printk(KERN_NOTICE "\nYou can turn off the power supply\n");
101 while (1) ;
102}
103
104static int __init vr41xx_pmu_init(void)
105{
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -0700106 unsigned long start, size;
107
108 switch (current_cpu_data.cputype) {
109 case CPU_VR4111:
110 case CPU_VR4121:
111 start = PMU_TYPE1_BASE;
112 size = PMU_TYPE1_SIZE;
113 break;
114 case CPU_VR4122:
115 case CPU_VR4131:
116 case CPU_VR4133:
117 start = PMU_TYPE2_BASE;
118 size = PMU_TYPE2_SIZE;
119 break;
120 default:
121 printk("Unexpected CPU of NEC VR4100 series\n");
122 return -ENODEV;
123 }
124
125 if (request_mem_region(start, size, "PMU") == NULL)
126 return -EBUSY;
127
128 pmu_base = ioremap(start, size);
129 if (pmu_base == NULL) {
130 release_mem_region(start, size);
131 return -EBUSY;
132 }
133
Yoichi Yuasa61a33162007-08-07 00:09:17 +0900134 cpu_wait = vr41xx_cpu_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 _machine_restart = vr41xx_restart;
136 _machine_halt = vr41xx_halt;
Ralf Baechlefcdb27a2006-01-18 17:37:07 +0000137 pm_power_off = vr41xx_power_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 return 0;
140}
141
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -0700142core_initcall(vr41xx_pmu_init);