blob: 53166f3598b25fdd82cde85c1963fefa0e22c742 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pmu.c, Power Management Unit routines for NEC VR4100 series.
3 *
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -07004 * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@hh.iij4u.or.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>
24#include <linux/smp.h>
25#include <linux/types.h>
26
27#include <asm/cpu.h>
28#include <asm/io.h>
29#include <asm/reboot.h>
30#include <asm/system.h>
31
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070032#define PMU_TYPE1_BASE 0x0b0000a0UL
33#define PMU_TYPE1_SIZE 0x0eUL
34
35#define PMU_TYPE2_BASE 0x0f0000c0UL
36#define PMU_TYPE2_SIZE 0x10UL
37
38#define PMUCNT2REG 0x06
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 #define SOFTRST 0x0010
40
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070041static void __iomem *pmu_base;
42
43#define pmu_read(offset) readw(pmu_base + (offset))
44#define pmu_write(offset, value) writew((value), pmu_base + (offset))
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static inline void software_reset(void)
47{
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070048 uint16_t pmucnt2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 switch (current_cpu_data.cputype) {
51 case CPU_VR4122:
52 case CPU_VR4131:
53 case CPU_VR4133:
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070054 pmucnt2 = pmu_read(PMUCNT2REG);
55 pmucnt2 |= SOFTRST;
56 pmu_write(PMUCNT2REG, pmucnt2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 break;
58 default:
59 break;
60 }
61}
62
63static void vr41xx_restart(char *command)
64{
65 local_irq_disable();
66 software_reset();
67 printk(KERN_NOTICE "\nYou can reset your system\n");
68 while (1) ;
69}
70
71static void vr41xx_halt(void)
72{
73 local_irq_disable();
74 printk(KERN_NOTICE "\nYou can turn off the power supply\n");
75 while (1) ;
76}
77
78static void vr41xx_power_off(void)
79{
80 local_irq_disable();
81 printk(KERN_NOTICE "\nYou can turn off the power supply\n");
82 while (1) ;
83}
84
85static int __init vr41xx_pmu_init(void)
86{
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -070087 unsigned long start, size;
88
89 switch (current_cpu_data.cputype) {
90 case CPU_VR4111:
91 case CPU_VR4121:
92 start = PMU_TYPE1_BASE;
93 size = PMU_TYPE1_SIZE;
94 break;
95 case CPU_VR4122:
96 case CPU_VR4131:
97 case CPU_VR4133:
98 start = PMU_TYPE2_BASE;
99 size = PMU_TYPE2_SIZE;
100 break;
101 default:
102 printk("Unexpected CPU of NEC VR4100 series\n");
103 return -ENODEV;
104 }
105
106 if (request_mem_region(start, size, "PMU") == NULL)
107 return -EBUSY;
108
109 pmu_base = ioremap(start, size);
110 if (pmu_base == NULL) {
111 release_mem_region(start, size);
112 return -EBUSY;
113 }
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 _machine_restart = vr41xx_restart;
116 _machine_halt = vr41xx_halt;
117 _machine_power_off = vr41xx_power_off;
118
119 return 0;
120}
121
Yoichi Yuasa3407c0f2005-05-16 21:53:53 -0700122core_initcall(vr41xx_pmu_init);