Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pmu.c, Power Management Unit routines for NEC VR4100 series. |
| 3 | * |
Yoichi Yuasa | ada8e95 | 2009-07-03 00:39:38 +0900 | [diff] [blame] | 4 | * Copyright (C) 2003-2007 Yoichi Yuasa <yuasa@linux-mips.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 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 Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 20 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 22 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Ralf Baechle | fcdb27a | 2006-01-18 17:37:07 +0000 | [diff] [blame] | 24 | #include <linux/pm.h> |
Yoichi Yuasa | 61a3316 | 2007-08-07 00:09:17 +0900 | [diff] [blame] | 25 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/types.h> |
| 27 | |
Yoichi Yuasa | 2f2a2d9 | 2007-08-16 22:20:11 +0900 | [diff] [blame] | 28 | #include <asm/cacheflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/cpu.h> |
| 30 | #include <asm/io.h> |
Yoichi Yuasa | 61a3316 | 2007-08-07 00:09:17 +0900 | [diff] [blame] | 31 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/reboot.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 34 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define SOFTRST 0x0010 |
| 42 | |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 43 | static 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 Yuasa | 61a3316 | 2007-08-07 00:09:17 +0900 | [diff] [blame] | 48 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static inline void software_reset(void) |
| 61 | { |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 62 | uint16_t pmucnt2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 64 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | case CPU_VR4122: |
| 66 | case CPU_VR4131: |
| 67 | case CPU_VR4133: |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 68 | pmucnt2 = pmu_read(PMUCNT2REG); |
| 69 | pmucnt2 |= SOFTRST; |
| 70 | pmu_write(PMUCNT2REG, pmucnt2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | break; |
| 72 | default: |
Yoichi Yuasa | 2f2a2d9 | 2007-08-16 22:20:11 +0900 | [diff] [blame] | 73 | set_c0_status(ST0_BEV | ST0_ERL); |
| 74 | change_c0_config(CONF_CM_CMASK, CONF_CM_UNCACHED); |
| 75 | flush_cache_all(); |
| 76 | write_c0_wired(0); |
| 77 | __asm__("jr %0"::"r"(0xbfc00000)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void vr41xx_restart(char *command) |
| 83 | { |
| 84 | local_irq_disable(); |
| 85 | software_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | while (1) ; |
| 87 | } |
| 88 | |
| 89 | static void vr41xx_halt(void) |
| 90 | { |
| 91 | local_irq_disable(); |
| 92 | printk(KERN_NOTICE "\nYou can turn off the power supply\n"); |
Yoichi Yuasa | fa41780 | 2007-08-16 22:27:05 +0900 | [diff] [blame] | 93 | __asm__("hibernate;\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int __init vr41xx_pmu_init(void) |
| 97 | { |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 98 | unsigned long start, size; |
| 99 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 100 | switch (current_cpu_type()) { |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 101 | case CPU_VR4111: |
| 102 | case CPU_VR4121: |
| 103 | start = PMU_TYPE1_BASE; |
| 104 | size = PMU_TYPE1_SIZE; |
| 105 | break; |
| 106 | case CPU_VR4122: |
| 107 | case CPU_VR4131: |
| 108 | case CPU_VR4133: |
| 109 | start = PMU_TYPE2_BASE; |
| 110 | size = PMU_TYPE2_SIZE; |
| 111 | break; |
| 112 | default: |
| 113 | printk("Unexpected CPU of NEC VR4100 series\n"); |
| 114 | return -ENODEV; |
| 115 | } |
| 116 | |
| 117 | if (request_mem_region(start, size, "PMU") == NULL) |
| 118 | return -EBUSY; |
| 119 | |
| 120 | pmu_base = ioremap(start, size); |
| 121 | if (pmu_base == NULL) { |
| 122 | release_mem_region(start, size); |
| 123 | return -EBUSY; |
| 124 | } |
| 125 | |
Yoichi Yuasa | 61a3316 | 2007-08-07 00:09:17 +0900 | [diff] [blame] | 126 | cpu_wait = vr41xx_cpu_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | _machine_restart = vr41xx_restart; |
| 128 | _machine_halt = vr41xx_halt; |
Yoichi Yuasa | fa41780 | 2007-08-16 22:27:05 +0900 | [diff] [blame] | 129 | pm_power_off = vr41xx_halt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
Yoichi Yuasa | 3407c0f | 2005-05-16 21:53:53 -0700 | [diff] [blame] | 134 | core_initcall(vr41xx_pmu_init); |