Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2/3 powerdomain control |
| 3 | * |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 4 | * Copyright (C) 2007-2008 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2007-2009 Nokia Corporation |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 6 | * |
| 7 | * Written by Paul Walmsley |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #ifndef ASM_ARM_ARCH_OMAP_POWERDOMAIN |
| 15 | #define ASM_ARM_ARCH_OMAP_POWERDOMAIN |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/list.h> |
| 19 | |
| 20 | #include <asm/atomic.h> |
| 21 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 22 | #include <plat/cpu.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /* Powerdomain basic power states */ |
| 26 | #define PWRDM_POWER_OFF 0x0 |
| 27 | #define PWRDM_POWER_RET 0x1 |
| 28 | #define PWRDM_POWER_INACTIVE 0x2 |
| 29 | #define PWRDM_POWER_ON 0x3 |
| 30 | |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 31 | #define PWRDM_MAX_PWRSTS 4 |
| 32 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 33 | /* Powerdomain allowable state bitfields */ |
| 34 | #define PWRSTS_OFF_ON ((1 << PWRDM_POWER_OFF) | \ |
| 35 | (1 << PWRDM_POWER_ON)) |
| 36 | |
| 37 | #define PWRSTS_OFF_RET ((1 << PWRDM_POWER_OFF) | \ |
| 38 | (1 << PWRDM_POWER_RET)) |
| 39 | |
Abhijit Pagare | f37c6df | 2010-01-26 20:12:52 -0700 | [diff] [blame] | 40 | #define PWRSTS_RET_ON ((1 << PWRDM_POWER_RET) | \ |
| 41 | (1 << PWRDM_POWER_ON)) |
| 42 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 43 | #define PWRSTS_OFF_RET_ON (PWRSTS_OFF_RET | (1 << PWRDM_POWER_ON)) |
| 44 | |
| 45 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 46 | /* Powerdomain flags */ |
| 47 | #define PWRDM_HAS_HDWR_SAR (1 << 0) /* hardware save-and-restore support */ |
Thara Gopinath | 3863c74 | 2009-12-08 16:33:15 -0700 | [diff] [blame] | 48 | #define PWRDM_HAS_MPU_QUIRK (1 << 1) /* MPU pwr domain has MEM bank 0 bits |
| 49 | * in MEM bank 1 position. This is |
| 50 | * true for OMAP3430 |
| 51 | */ |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 52 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 53 | /* |
Abhijit Pagare | 38900c2 | 2010-01-26 20:12:52 -0700 | [diff] [blame] | 54 | * Number of memory banks that are power-controllable. On OMAP4430, the |
| 55 | * maximum is 5. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 56 | */ |
Abhijit Pagare | 38900c2 | 2010-01-26 20:12:52 -0700 | [diff] [blame] | 57 | #define PWRDM_MAX_MEM_BANKS 5 |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 58 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 59 | /* |
| 60 | * Maximum number of clockdomains that can be associated with a powerdomain. |
Abhijit Pagare | 38900c2 | 2010-01-26 20:12:52 -0700 | [diff] [blame] | 61 | * CORE powerdomain on OMAP4 is the worst case |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 62 | */ |
Abhijit Pagare | 38900c2 | 2010-01-26 20:12:52 -0700 | [diff] [blame] | 63 | #define PWRDM_MAX_CLKDMS 9 |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 64 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 65 | /* XXX A completely arbitrary number. What is reasonable here? */ |
| 66 | #define PWRDM_TRANSITION_BAILOUT 100000 |
| 67 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 68 | struct clockdomain; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 69 | struct powerdomain; |
| 70 | |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame^] | 71 | /** |
| 72 | * struct powerdomain - OMAP powerdomain |
| 73 | * @name: Powerdomain name |
| 74 | * @omap_chip: represents the OMAP chip types containing this pwrdm |
| 75 | * @prcm_offs: the address offset from CM_BASE/PRM_BASE |
| 76 | * @pwrsts: Possible powerdomain power states |
| 77 | * @pwrsts_logic_ret: Possible logic power states when pwrdm in RETENTION |
| 78 | * @flags: Powerdomain flags |
| 79 | * @banks: Number of software-controllable memory banks in this powerdomain |
| 80 | * @pwrsts_mem_ret: Possible memory bank pwrstates when pwrdm in RETENTION |
| 81 | * @pwrsts_mem_on: Possible memory bank pwrstates when pwrdm in ON |
| 82 | * @pwrdm_clkdms: Clockdomains in this powerdomain |
| 83 | * @node: list_head linking all powerdomains |
| 84 | * @state: |
| 85 | * @state_counter: |
| 86 | * @timer: |
| 87 | * @state_timer: |
| 88 | */ |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 89 | struct powerdomain { |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 90 | const char *name; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 91 | const struct omap_chip_id omap_chip; |
Paul Walmsley | e0594b4 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 92 | const s16 prcm_offs; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 93 | const u8 pwrsts; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 94 | const u8 pwrsts_logic_ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 95 | const u8 flags; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 96 | const u8 banks; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 97 | const u8 pwrsts_mem_ret[PWRDM_MAX_MEM_BANKS]; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 98 | const u8 pwrsts_mem_on[PWRDM_MAX_MEM_BANKS]; |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 99 | struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS]; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 100 | struct list_head node; |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 101 | int state; |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 102 | unsigned state_counter[PWRDM_MAX_PWRSTS]; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 103 | |
| 104 | #ifdef CONFIG_PM_DEBUG |
| 105 | s64 timer; |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 106 | s64 state_timer[PWRDM_MAX_PWRSTS]; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 107 | #endif |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
| 111 | void pwrdm_init(struct powerdomain **pwrdm_list); |
| 112 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 113 | struct powerdomain *pwrdm_lookup(const char *name); |
| 114 | |
Peter 'p2' De Schrijver | a23456e | 2008-10-15 18:13:47 +0300 | [diff] [blame] | 115 | int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user), |
| 116 | void *user); |
Artem Bityutskiy | ee894b1 | 2009-10-01 10:01:55 +0300 | [diff] [blame] | 117 | int pwrdm_for_each_nolock(int (*fn)(struct powerdomain *pwrdm, void *user), |
| 118 | void *user); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 119 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 120 | int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm); |
| 121 | int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm); |
| 122 | int pwrdm_for_each_clkdm(struct powerdomain *pwrdm, |
| 123 | int (*fn)(struct powerdomain *pwrdm, |
| 124 | struct clockdomain *clkdm)); |
| 125 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 126 | int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm); |
| 127 | |
| 128 | int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst); |
| 129 | int pwrdm_read_next_pwrst(struct powerdomain *pwrdm); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 130 | int pwrdm_read_pwrst(struct powerdomain *pwrdm); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 131 | int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm); |
| 132 | int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm); |
| 133 | |
| 134 | int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst); |
| 135 | int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst); |
| 136 | int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst); |
| 137 | |
| 138 | int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm); |
| 139 | int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm); |
| 140 | int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank); |
| 141 | int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank); |
| 142 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 143 | int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm); |
| 144 | int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm); |
| 145 | bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm); |
| 146 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 147 | int pwrdm_wait_transition(struct powerdomain *pwrdm); |
| 148 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 149 | int pwrdm_state_switch(struct powerdomain *pwrdm); |
| 150 | int pwrdm_clkdm_state_switch(struct clockdomain *clkdm); |
| 151 | int pwrdm_pre_transition(void); |
| 152 | int pwrdm_post_transition(void); |
| 153 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 154 | #endif |