Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: hwregs - Read/write access functions for the various ACPI |
| 5 | * control and status registers. |
| 6 | * |
| 7 | ******************************************************************************/ |
| 8 | |
| 9 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 10 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * All rights reserved. |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or without |
| 14 | * modification, are permitted provided that the following conditions |
| 15 | * are met: |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions, and the following disclaimer, |
| 18 | * without modification. |
| 19 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 20 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 21 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 22 | * including a substantially similar Disclaimer requirement for further |
| 23 | * binary redistribution. |
| 24 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 25 | * of any contributors may be used to endorse or promote products derived |
| 26 | * from this software without specific prior written permission. |
| 27 | * |
| 28 | * Alternatively, this software may be distributed under the terms of the |
| 29 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 30 | * Software Foundation. |
| 31 | * |
| 32 | * NO WARRANTY |
| 33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 37 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 38 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 39 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 40 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 41 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 42 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 43 | * POSSIBILITY OF SUCH DAMAGES. |
| 44 | */ |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
| 49 | #include "acevents.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("hwregs") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 54 | /* Local Prototypes */ |
| 55 | static acpi_status |
| 56 | acpi_hw_read_multiple(u32 *value, |
| 57 | struct acpi_generic_address *register_a, |
| 58 | struct acpi_generic_address *register_b); |
| 59 | |
| 60 | static acpi_status |
| 61 | acpi_hw_write_multiple(u32 value, |
| 62 | struct acpi_generic_address *register_a, |
| 63 | struct acpi_generic_address *register_b); |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /******************************************************************************* |
| 66 | * |
| 67 | * FUNCTION: acpi_hw_clear_acpi_status |
| 68 | * |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 69 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 71 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * |
| 73 | * DESCRIPTION: Clears all fixed and general purpose status bits |
| 74 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 75 | * |
| 76 | ******************************************************************************/ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 77 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 78 | acpi_status acpi_hw_clear_acpi_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | acpi_status status; |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 81 | acpi_cpu_flags lock_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 83 | ACPI_FUNCTION_TRACE(hw_clear_acpi_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n", |
| 86 | ACPI_BITMASK_ALL_FIXED_STATUS, |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 87 | (u16) acpi_gbl_xpm1a_status.address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 89 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 91 | /* Clear the fixed events */ |
| 92 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 93 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | ACPI_BITMASK_ALL_FIXED_STATUS); |
| 95 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | goto unlock_and_exit; |
| 97 | } |
| 98 | |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 99 | /* Write PM1B register if present */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 101 | if (acpi_gbl_xpm1b_status.address) { |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 102 | status = acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS, |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 103 | &acpi_gbl_xpm1b_status); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | goto unlock_and_exit; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /* Clear the GPE Bits in all GPE registers in all GPE blocks */ |
| 110 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 111 | status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | unlock_and_exit: |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 114 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /******************************************************************************* |
| 119 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | * FUNCTION: acpi_hw_get_register_bit_mask |
| 121 | * |
| 122 | * PARAMETERS: register_id - Index of ACPI Register to access |
| 123 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 124 | * RETURN: The bitmask to be used when accessing the register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 126 | * DESCRIPTION: Map register_id into a register bitmask. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * |
| 128 | ******************************************************************************/ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 129 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 132 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | if (register_id > ACPI_BITREG_MAX) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 135 | ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 136 | register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return (NULL); |
| 138 | } |
| 139 | |
| 140 | return (&acpi_gbl_bit_register_info[register_id]); |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /****************************************************************************** |
| 144 | * |
| 145 | * FUNCTION: acpi_hw_register_read |
| 146 | * |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 147 | * PARAMETERS: register_id - ACPI Register ID |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 148 | * return_value - Where the register value is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | * |
| 150 | * RETURN: Status and the value read. |
| 151 | * |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 152 | * DESCRIPTION: Read from the specified ACPI register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | * |
| 154 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | acpi_status |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 156 | acpi_hw_register_read(u32 register_id, u32 * return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 158 | u32 value = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 161 | ACPI_FUNCTION_TRACE(hw_register_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | switch (register_id) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 164 | case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 166 | status = acpi_hw_read_multiple(&value, |
| 167 | &acpi_gbl_xpm1a_status, |
| 168 | &acpi_gbl_xpm1b_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | break; |
| 170 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 171 | case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 173 | status = acpi_hw_read_multiple(&value, |
| 174 | &acpi_gbl_xpm1a_enable, |
| 175 | &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | break; |
| 177 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 178 | case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 180 | status = acpi_hw_read_multiple(&value, |
| 181 | &acpi_gbl_FADT. |
| 182 | xpm1a_control_block, |
| 183 | &acpi_gbl_FADT. |
| 184 | xpm1b_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | break; |
| 186 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 189 | status = acpi_read(&value, &acpi_gbl_FADT.xpm2_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | break; |
| 191 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 192 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 194 | status = acpi_read(&value, &acpi_gbl_FADT.xpm_timer_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | break; |
| 196 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 199 | status = |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 200 | acpi_os_read_port(acpi_gbl_FADT.smi_command, &value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | break; |
| 202 | |
| 203 | default: |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 204 | ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | status = AE_BAD_PARAMETER; |
| 206 | break; |
| 207 | } |
| 208 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | if (ACPI_SUCCESS(status)) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 210 | *return_value = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /****************************************************************************** |
| 217 | * |
| 218 | * FUNCTION: acpi_hw_register_write |
| 219 | * |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 220 | * PARAMETERS: register_id - ACPI Register ID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | * Value - The value to write |
| 222 | * |
| 223 | * RETURN: Status |
| 224 | * |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 225 | * DESCRIPTION: Write to the specified ACPI register |
| 226 | * |
| 227 | * NOTE: In accordance with the ACPI specification, this function automatically |
| 228 | * preserves the value of the following bits, meaning that these bits cannot be |
| 229 | * changed via this interface: |
| 230 | * |
| 231 | * PM1_CONTROL[0] = SCI_EN |
| 232 | * PM1_CONTROL[9] |
| 233 | * PM1_STATUS[11] |
| 234 | * |
| 235 | * ACPI References: |
| 236 | * 1) Hardware Ignored Bits: When software writes to a register with ignored |
| 237 | * bit fields, it preserves the ignored bit fields |
| 238 | * 2) SCI_EN: OSPM always preserves this bit position |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | * |
| 240 | ******************************************************************************/ |
| 241 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 242 | acpi_status acpi_hw_register_write(u32 register_id, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | acpi_status status; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 245 | u32 read_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 247 | ACPI_FUNCTION_TRACE(hw_register_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | switch (register_id) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 250 | case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 252 | /* Perform a read first to preserve certain bits (per ACPI spec) */ |
| 253 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 254 | status = acpi_hw_read_multiple(&read_value, |
| 255 | &acpi_gbl_xpm1a_status, |
| 256 | &acpi_gbl_xpm1b_status); |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 257 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 258 | goto exit; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* Insert the bits to be preserved */ |
| 262 | |
| 263 | ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS, |
| 264 | read_value); |
| 265 | |
| 266 | /* Now we can write the data */ |
| 267 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 268 | status = acpi_hw_write_multiple(value, |
| 269 | &acpi_gbl_xpm1a_status, |
| 270 | &acpi_gbl_xpm1b_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | break; |
| 272 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 273 | case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 275 | status = acpi_hw_write_multiple(value, |
| 276 | &acpi_gbl_xpm1a_enable, |
| 277 | &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | break; |
| 279 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 280 | case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 282 | /* |
| 283 | * Perform a read first to preserve certain bits (per ACPI spec) |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 284 | * Note: This includes SCI_EN, we never want to change this bit |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 285 | */ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 286 | status = acpi_hw_read_multiple(&read_value, |
| 287 | &acpi_gbl_FADT. |
| 288 | xpm1a_control_block, |
| 289 | &acpi_gbl_FADT. |
| 290 | xpm1b_control_block); |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 291 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 292 | goto exit; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* Insert the bits to be preserved */ |
| 296 | |
| 297 | ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS, |
| 298 | read_value); |
| 299 | |
| 300 | /* Now we can write the data */ |
| 301 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 302 | status = acpi_hw_write_multiple(value, |
| 303 | &acpi_gbl_FADT. |
| 304 | xpm1a_control_block, |
| 305 | &acpi_gbl_FADT. |
| 306 | xpm1b_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | break; |
| 308 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 311 | status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | break; |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 316 | status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | break; |
| 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 321 | status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | break; |
| 323 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 326 | status = acpi_write(value, &acpi_gbl_FADT.xpm_timer_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | break; |
| 328 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | /* SMI_CMD is currently always in IO space */ |
| 332 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 333 | status = |
| 334 | acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | break; |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | default: |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 338 | ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | status = AE_BAD_PARAMETER; |
| 340 | break; |
| 341 | } |
| 342 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 343 | exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame^] | 346 | |
| 347 | /****************************************************************************** |
| 348 | * |
| 349 | * FUNCTION: acpi_hw_read_multiple |
| 350 | * |
| 351 | * PARAMETERS: Value - Where the register value is returned |
| 352 | * register_a - First ACPI register (required) |
| 353 | * register_b - Second ACPI register (optional) |
| 354 | * |
| 355 | * RETURN: Status |
| 356 | * |
| 357 | * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B) |
| 358 | * |
| 359 | ******************************************************************************/ |
| 360 | |
| 361 | static acpi_status |
| 362 | acpi_hw_read_multiple(u32 *value, |
| 363 | struct acpi_generic_address *register_a, |
| 364 | struct acpi_generic_address *register_b) |
| 365 | { |
| 366 | u32 value_a = 0; |
| 367 | u32 value_b = 0; |
| 368 | acpi_status status; |
| 369 | |
| 370 | /* The first register is always required */ |
| 371 | |
| 372 | status = acpi_read(&value_a, register_a); |
| 373 | if (ACPI_FAILURE(status)) { |
| 374 | return (status); |
| 375 | } |
| 376 | |
| 377 | /* Second register is optional */ |
| 378 | |
| 379 | if (register_b->address) { |
| 380 | status = acpi_read(&value_b, register_b); |
| 381 | if (ACPI_FAILURE(status)) { |
| 382 | return (status); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /* Shift the B bits above the A bits */ |
| 387 | |
| 388 | *value = value_a | (value_b << register_a->bit_width); |
| 389 | return (AE_OK); |
| 390 | } |
| 391 | |
| 392 | /****************************************************************************** |
| 393 | * |
| 394 | * FUNCTION: acpi_hw_write_multiple |
| 395 | * |
| 396 | * PARAMETERS: Value - The value to write |
| 397 | * register_a - First ACPI register (required) |
| 398 | * register_b - Second ACPI register (optional) |
| 399 | * |
| 400 | * RETURN: Status |
| 401 | * |
| 402 | * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B) |
| 403 | * |
| 404 | ******************************************************************************/ |
| 405 | |
| 406 | static acpi_status |
| 407 | acpi_hw_write_multiple(u32 value, |
| 408 | struct acpi_generic_address *register_a, |
| 409 | struct acpi_generic_address *register_b) |
| 410 | { |
| 411 | acpi_status status; |
| 412 | |
| 413 | /* The first register is always required */ |
| 414 | |
| 415 | status = acpi_write(value, register_a); |
| 416 | if (ACPI_FAILURE(status)) { |
| 417 | return (status); |
| 418 | } |
| 419 | |
| 420 | /* Second register is optional */ |
| 421 | |
| 422 | if (register_b->address) { |
| 423 | |
| 424 | /* Normalize the B bits before write */ |
| 425 | |
| 426 | status = acpi_write(value >> register_a->bit_width, register_b); |
| 427 | } |
| 428 | |
| 429 | return (status); |
| 430 | } |