Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Standard PCI Hot Plug Driver |
| 3 | * |
| 4 | * Copyright (C) 1995,2001 Compaq Computer Corporation |
| 5 | * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) |
| 6 | * Copyright (C) 2001 IBM Corp. |
| 7 | * Copyright (C) 2003-2004 Intel Corporation |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 19 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 20 | * details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
Kristen Accardi | 8cf4c19 | 2005-08-16 15:16:10 -0700 | [diff] [blame] | 26 | * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> |
Andrew Morton | d4d28dd | 2005-11-13 16:06:40 -0800 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "shpchp.h" |
| 37 | |
| 38 | #ifdef DEBUG |
| 39 | #define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */ |
| 40 | #define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */ |
| 41 | #define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */ |
| 42 | #define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */ |
| 43 | #define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT) |
| 44 | #define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE) |
| 45 | /* Redefine this flagword to set debug level */ |
| 46 | #define DEBUG_LEVEL DBG_K_STANDARD |
| 47 | |
| 48 | #define DEFINE_DBG_BUFFER char __dbg_str_buf[256]; |
| 49 | |
| 50 | #define DBG_PRINT( dbg_flags, args... ) \ |
| 51 | do { \ |
| 52 | if ( DEBUG_LEVEL & ( dbg_flags ) ) \ |
| 53 | { \ |
| 54 | int len; \ |
| 55 | len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \ |
| 56 | __FILE__, __LINE__, __FUNCTION__ ); \ |
| 57 | sprintf( __dbg_str_buf + len, args ); \ |
| 58 | printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \ |
| 59 | } \ |
| 60 | } while (0) |
| 61 | |
| 62 | #define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]"); |
| 63 | #define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]"); |
| 64 | #else |
| 65 | #define DEFINE_DBG_BUFFER |
| 66 | #define DBG_ENTER_ROUTINE |
| 67 | #define DBG_LEAVE_ROUTINE |
| 68 | #endif /* DEBUG */ |
| 69 | |
| 70 | /* Slot Available Register I field definition */ |
| 71 | #define SLOT_33MHZ 0x0000001f |
| 72 | #define SLOT_66MHZ_PCIX 0x00001f00 |
| 73 | #define SLOT_100MHZ_PCIX 0x001f0000 |
| 74 | #define SLOT_133MHZ_PCIX 0x1f000000 |
| 75 | |
| 76 | /* Slot Available Register II field definition */ |
| 77 | #define SLOT_66MHZ 0x0000001f |
| 78 | #define SLOT_66MHZ_PCIX_266 0x00000f00 |
| 79 | #define SLOT_100MHZ_PCIX_266 0x0000f000 |
| 80 | #define SLOT_133MHZ_PCIX_266 0x000f0000 |
| 81 | #define SLOT_66MHZ_PCIX_533 0x00f00000 |
| 82 | #define SLOT_100MHZ_PCIX_533 0x0f000000 |
| 83 | #define SLOT_133MHZ_PCIX_533 0xf0000000 |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* Slot Configuration */ |
| 86 | #define SLOT_NUM 0x0000001F |
| 87 | #define FIRST_DEV_NUM 0x00001F00 |
| 88 | #define PSN 0x07FF0000 |
| 89 | #define UPDOWN 0x20000000 |
| 90 | #define MRLSENSOR 0x40000000 |
| 91 | #define ATTN_BUTTON 0x80000000 |
| 92 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 93 | /* |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 94 | * Interrupt Locator Register definitions |
| 95 | */ |
| 96 | #define CMD_INTR_PENDING (1 << 0) |
| 97 | #define SLOT_INTR_PENDING(i) (1 << (i + 1)) |
| 98 | |
| 99 | /* |
Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 100 | * Controller SERR-INT Register |
| 101 | */ |
| 102 | #define GLOBAL_INTR_MASK (1 << 0) |
| 103 | #define GLOBAL_SERR_MASK (1 << 1) |
| 104 | #define COMMAND_INTR_MASK (1 << 2) |
| 105 | #define ARBITER_SERR_MASK (1 << 3) |
| 106 | #define COMMAND_DETECTED (1 << 16) |
| 107 | #define ARBITER_DETECTED (1 << 17) |
| 108 | #define SERR_INTR_RSVDZ_MASK 0xfffc0000 |
| 109 | |
| 110 | /* |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 111 | * Logical Slot Register definitions |
| 112 | */ |
| 113 | #define SLOT_REG(i) (SLOT1 + (4 * i)) |
| 114 | |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 115 | #define SLOT_STATE_SHIFT (0) |
| 116 | #define SLOT_STATE_MASK (3 << 0) |
| 117 | #define SLOT_STATE_PWRONLY (1) |
| 118 | #define SLOT_STATE_ENABLED (2) |
| 119 | #define SLOT_STATE_DISABLED (3) |
| 120 | #define PWR_LED_STATE_SHIFT (2) |
| 121 | #define PWR_LED_STATE_MASK (3 << 2) |
| 122 | #define ATN_LED_STATE_SHIFT (4) |
| 123 | #define ATN_LED_STATE_MASK (3 << 4) |
| 124 | #define ATN_LED_STATE_ON (1) |
| 125 | #define ATN_LED_STATE_BLINK (2) |
| 126 | #define ATN_LED_STATE_OFF (3) |
| 127 | #define POWER_FAULT (1 << 6) |
| 128 | #define ATN_BUTTON (1 << 7) |
| 129 | #define MRL_SENSOR (1 << 8) |
| 130 | #define MHZ66_CAP (1 << 9) |
| 131 | #define PRSNT_SHIFT (10) |
| 132 | #define PRSNT_MASK (3 << 10) |
| 133 | #define PCIX_CAP_SHIFT (12) |
| 134 | #define PCIX_CAP_MASK_PI1 (3 << 12) |
| 135 | #define PCIX_CAP_MASK_PI2 (7 << 12) |
| 136 | #define PRSNT_CHANGE_DETECTED (1 << 16) |
| 137 | #define ISO_PFAULT_DETECTED (1 << 17) |
| 138 | #define BUTTON_PRESS_DETECTED (1 << 18) |
| 139 | #define MRL_CHANGE_DETECTED (1 << 19) |
| 140 | #define CON_PFAULT_DETECTED (1 << 20) |
| 141 | #define PRSNT_CHANGE_INTR_MASK (1 << 24) |
| 142 | #define ISO_PFAULT_INTR_MASK (1 << 25) |
| 143 | #define BUTTON_PRESS_INTR_MASK (1 << 26) |
| 144 | #define MRL_CHANGE_INTR_MASK (1 << 27) |
| 145 | #define CON_PFAULT_INTR_MASK (1 << 28) |
| 146 | #define MRL_CHANGE_SERR_MASK (1 << 29) |
| 147 | #define CON_PFAULT_SERR_MASK (1 << 30) |
| 148 | #define SLOT_REG_RSVDZ_MASK (1 << 15) | (7 << 21) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 150 | /* |
| 151 | * SHPC Command Code definitnions |
| 152 | * |
| 153 | * Slot Operation 00h - 3Fh |
| 154 | * Set Bus Segment Speed/Mode A 40h - 47h |
| 155 | * Power-Only All Slots 48h |
| 156 | * Enable All Slots 49h |
| 157 | * Set Bus Segment Speed/Mode B (PI=2) 50h - 5Fh |
| 158 | * Reserved Command Codes 60h - BFh |
| 159 | * Vendor Specific Commands C0h - FFh |
| 160 | */ |
| 161 | #define SET_SLOT_PWR 0x01 /* Slot Operation */ |
| 162 | #define SET_SLOT_ENABLE 0x02 |
| 163 | #define SET_SLOT_DISABLE 0x03 |
| 164 | #define SET_PWR_ON 0x04 |
| 165 | #define SET_PWR_BLINK 0x08 |
| 166 | #define SET_PWR_OFF 0x0c |
| 167 | #define SET_ATTN_ON 0x10 |
| 168 | #define SET_ATTN_BLINK 0x20 |
| 169 | #define SET_ATTN_OFF 0x30 |
| 170 | #define SETA_PCI_33MHZ 0x40 /* Set Bus Segment Speed/Mode A */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | #define SETA_PCI_66MHZ 0x41 |
| 172 | #define SETA_PCIX_66MHZ 0x42 |
| 173 | #define SETA_PCIX_100MHZ 0x43 |
| 174 | #define SETA_PCIX_133MHZ 0x44 |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 175 | #define SETA_RESERVED1 0x45 |
| 176 | #define SETA_RESERVED2 0x46 |
| 177 | #define SETA_RESERVED3 0x47 |
| 178 | #define SET_PWR_ONLY_ALL 0x48 /* Power-Only All Slots */ |
| 179 | #define SET_ENABLE_ALL 0x49 /* Enable All Slots */ |
| 180 | #define SETB_PCI_33MHZ 0x50 /* Set Bus Segment Speed/Mode B */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #define SETB_PCI_66MHZ 0x51 |
| 182 | #define SETB_PCIX_66MHZ_PM 0x52 |
| 183 | #define SETB_PCIX_100MHZ_PM 0x53 |
| 184 | #define SETB_PCIX_133MHZ_PM 0x54 |
| 185 | #define SETB_PCIX_66MHZ_EM 0x55 |
| 186 | #define SETB_PCIX_100MHZ_EM 0x56 |
| 187 | #define SETB_PCIX_133MHZ_EM 0x57 |
| 188 | #define SETB_PCIX_66MHZ_266 0x58 |
| 189 | #define SETB_PCIX_100MHZ_266 0x59 |
| 190 | #define SETB_PCIX_133MHZ_266 0x5a |
| 191 | #define SETB_PCIX_66MHZ_533 0x5b |
| 192 | #define SETB_PCIX_100MHZ_533 0x5c |
| 193 | #define SETB_PCIX_133MHZ_533 0x5d |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 194 | #define SETB_RESERVED1 0x5e |
| 195 | #define SETB_RESERVED2 0x5f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 197 | /* |
| 198 | * SHPC controller command error code |
| 199 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | #define SWITCH_OPEN 0x1 |
| 201 | #define INVALID_CMD 0x2 |
| 202 | #define INVALID_SPEED_MODE 0x4 |
| 203 | |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 204 | /* |
| 205 | * For accessing SHPC Working Register Set via PCI Configuration Space |
| 206 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | #define DWORD_SELECT 0x2 |
| 208 | #define DWORD_DATA 0x4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | /* Field Offset in Logical Slot Register - byte boundary */ |
| 211 | #define SLOT_EVENT_LATCH 0x2 |
| 212 | #define SLOT_SERR_INT_MASK 0x3 |
| 213 | |
| 214 | static spinlock_t hpc_event_lock; |
| 215 | |
| 216 | DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ |
| 217 | static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */ |
| 218 | static int ctlr_seq_num = 0; /* Controller sequenc # */ |
| 219 | static spinlock_t list_lock; |
| 220 | |
Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 221 | static atomic_t shpchp_num_controllers = ATOMIC_INIT(0); |
| 222 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 223 | static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 226 | static int hpc_check_cmd_status(struct controller *ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 228 | static inline u8 shpc_readb(struct controller *ctrl, int reg) |
| 229 | { |
| 230 | return readb(ctrl->hpc_ctlr_handle->creg + reg); |
| 231 | } |
| 232 | |
| 233 | static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val) |
| 234 | { |
| 235 | writeb(val, ctrl->hpc_ctlr_handle->creg + reg); |
| 236 | } |
| 237 | |
| 238 | static inline u16 shpc_readw(struct controller *ctrl, int reg) |
| 239 | { |
| 240 | return readw(ctrl->hpc_ctlr_handle->creg + reg); |
| 241 | } |
| 242 | |
| 243 | static inline void shpc_writew(struct controller *ctrl, int reg, u16 val) |
| 244 | { |
| 245 | writew(val, ctrl->hpc_ctlr_handle->creg + reg); |
| 246 | } |
| 247 | |
| 248 | static inline u32 shpc_readl(struct controller *ctrl, int reg) |
| 249 | { |
| 250 | return readl(ctrl->hpc_ctlr_handle->creg + reg); |
| 251 | } |
| 252 | |
| 253 | static inline void shpc_writel(struct controller *ctrl, int reg, u32 val) |
| 254 | { |
| 255 | writel(val, ctrl->hpc_ctlr_handle->creg + reg); |
| 256 | } |
| 257 | |
| 258 | static inline int shpc_indirect_read(struct controller *ctrl, int index, |
| 259 | u32 *value) |
| 260 | { |
| 261 | int rc; |
| 262 | u32 cap_offset = ctrl->cap_offset; |
| 263 | struct pci_dev *pdev = ctrl->pci_dev; |
| 264 | |
| 265 | rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index); |
| 266 | if (rc) |
| 267 | return rc; |
| 268 | return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value); |
| 269 | } |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /* This is the interrupt polling timeout function. */ |
| 272 | static void int_poll_timeout(unsigned long lphp_ctlr) |
| 273 | { |
| 274 | struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr; |
| 275 | |
| 276 | DBG_ENTER_ROUTINE |
| 277 | |
| 278 | if ( !php_ctlr ) { |
| 279 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | /* Poll for interrupt events. regs == NULL => polling */ |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 284 | shpc_isr(0, php_ctlr->callback_instance_id, NULL ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | init_timer(&php_ctlr->int_poll_timer); |
| 287 | if (!shpchp_poll_time) |
| 288 | shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ |
| 289 | |
| 290 | start_int_poll_timer(php_ctlr, shpchp_poll_time); |
| 291 | |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | /* This function starts the interrupt polling timer. */ |
| 296 | static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds) |
| 297 | { |
| 298 | if (!php_ctlr) { |
| 299 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | if ( ( seconds <= 0 ) || ( seconds > 60 ) ) |
| 304 | seconds = 2; /* Clamp to sane value */ |
| 305 | |
| 306 | php_ctlr->int_poll_timer.function = &int_poll_timeout; |
| 307 | php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */ |
| 308 | php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ; |
| 309 | add_timer(&php_ctlr->int_poll_timer); |
| 310 | |
| 311 | return; |
| 312 | } |
| 313 | |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 314 | static inline int shpc_wait_cmd(struct controller *ctrl) |
| 315 | { |
| 316 | int retval = 0; |
| 317 | unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000; |
| 318 | unsigned long timeout = msecs_to_jiffies(timeout_msec); |
| 319 | int rc = wait_event_interruptible_timeout(ctrl->queue, |
| 320 | !ctrl->cmd_busy, timeout); |
| 321 | if (!rc) { |
| 322 | retval = -EIO; |
| 323 | err("Command not completed in %d msec\n", timeout_msec); |
| 324 | } else if (rc < 0) { |
| 325 | retval = -EINTR; |
| 326 | info("Command was interrupted by a signal\n"); |
| 327 | } |
| 328 | ctrl->cmd_busy = 0; |
| 329 | |
| 330 | return retval; |
| 331 | } |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) |
| 334 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 335 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | u16 cmd_status; |
| 337 | int retval = 0; |
| 338 | u16 temp_word; |
| 339 | int i; |
| 340 | |
| 341 | DBG_ENTER_ROUTINE |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 342 | |
| 343 | mutex_lock(&slot->ctrl->cmd_lock); |
| 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | for (i = 0; i < 10; i++) { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 346 | cmd_status = shpc_readw(ctrl, CMD_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | if (!(cmd_status & 0x1)) |
| 349 | break; |
| 350 | /* Check every 0.1 sec for a total of 1 sec*/ |
| 351 | msleep(100); |
| 352 | } |
| 353 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 354 | cmd_status = shpc_readw(ctrl, CMD_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | if (cmd_status & 0x1) { |
| 357 | /* After 1 sec and and the controller is still busy */ |
| 358 | err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 359 | retval = -EBUSY; |
| 360 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | ++t_slot; |
| 364 | temp_word = (t_slot << 8) | (cmd & 0xFF); |
| 365 | dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd); |
| 366 | |
| 367 | /* To make sure the Controller Busy bit is 0 before we send out the |
| 368 | * command. |
| 369 | */ |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 370 | slot->ctrl->cmd_busy = 1; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 371 | shpc_writew(ctrl, CMD, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 373 | /* |
| 374 | * Wait for command completion. |
| 375 | */ |
| 376 | retval = shpc_wait_cmd(slot->ctrl); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 377 | if (retval) |
| 378 | goto out; |
| 379 | |
| 380 | cmd_status = hpc_check_cmd_status(slot->ctrl); |
| 381 | if (cmd_status) { |
| 382 | err("%s: Failed to issued command 0x%x (error code = %d)\n", |
| 383 | __FUNCTION__, cmd, cmd_status); |
| 384 | retval = -EIO; |
| 385 | } |
| 386 | out: |
| 387 | mutex_unlock(&slot->ctrl->cmd_lock); |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | DBG_LEAVE_ROUTINE |
| 390 | return retval; |
| 391 | } |
| 392 | |
| 393 | static int hpc_check_cmd_status(struct controller *ctrl) |
| 394 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | u16 cmd_status; |
| 396 | int retval = 0; |
| 397 | |
| 398 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 400 | cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | switch (cmd_status >> 1) { |
| 403 | case 0: |
| 404 | retval = 0; |
| 405 | break; |
| 406 | case 1: |
| 407 | retval = SWITCH_OPEN; |
| 408 | err("%s: Switch opened!\n", __FUNCTION__); |
| 409 | break; |
| 410 | case 2: |
| 411 | retval = INVALID_CMD; |
| 412 | err("%s: Invalid HPC command!\n", __FUNCTION__); |
| 413 | break; |
| 414 | case 4: |
| 415 | retval = INVALID_SPEED_MODE; |
| 416 | err("%s: Invalid bus speed/mode!\n", __FUNCTION__); |
| 417 | break; |
| 418 | default: |
| 419 | retval = cmd_status; |
| 420 | } |
| 421 | |
| 422 | DBG_LEAVE_ROUTINE |
| 423 | return retval; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | static int hpc_get_attention_status(struct slot *slot, u8 *status) |
| 428 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 429 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | u32 slot_reg; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 431 | u8 state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | DBG_ENTER_ROUTINE |
| 434 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 435 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 436 | state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 438 | switch (state) { |
| 439 | case ATN_LED_STATE_ON: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | *status = 1; /* On */ |
| 441 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 442 | case ATN_LED_STATE_BLINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | *status = 2; /* Blink */ |
| 444 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 445 | case ATN_LED_STATE_OFF: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | *status = 0; /* Off */ |
| 447 | break; |
| 448 | default: |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 449 | *status = 0xFF; /* Reserved */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | break; |
| 451 | } |
| 452 | |
| 453 | DBG_LEAVE_ROUTINE |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int hpc_get_power_status(struct slot * slot, u8 *status) |
| 458 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 459 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | u32 slot_reg; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 461 | u8 state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | DBG_ENTER_ROUTINE |
| 464 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 465 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 466 | state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 468 | switch (state) { |
| 469 | case SLOT_STATE_PWRONLY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | *status = 2; /* Powered only */ |
| 471 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 472 | case SLOT_STATE_ENABLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | *status = 1; /* Enabled */ |
| 474 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 475 | case SLOT_STATE_DISABLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | *status = 0; /* Disabled */ |
| 477 | break; |
| 478 | default: |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 479 | *status = 0xFF; /* Reserved */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | |
| 483 | DBG_LEAVE_ROUTINE |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 484 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
| 488 | static int hpc_get_latch_status(struct slot *slot, u8 *status) |
| 489 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 490 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | u32 slot_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | DBG_ENTER_ROUTINE |
| 494 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 495 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 496 | *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | DBG_LEAVE_ROUTINE |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | static int hpc_get_adapter_status(struct slot *slot, u8 *status) |
| 503 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 504 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | u32 slot_reg; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 506 | u8 state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | DBG_ENTER_ROUTINE |
| 509 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 510 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 511 | state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT; |
| 512 | *status = (state != 0x3) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | DBG_LEAVE_ROUTINE |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int hpc_get_prog_int(struct slot *slot, u8 *prog_int) |
| 519 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 520 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 524 | *prog_int = shpc_readb(ctrl, PROG_INTERFACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | DBG_LEAVE_ROUTINE |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value) |
| 531 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | int retval = 0; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 533 | struct controller *ctrl = slot->ctrl; |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 534 | u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 535 | u8 m66_cap = !!(slot_reg & MHZ66_CAP); |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 536 | u8 pi, pcix_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
| 538 | DBG_ENTER_ROUTINE |
| 539 | |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 540 | if ((retval = hpc_get_prog_int(slot, &pi))) |
| 541 | return retval; |
| 542 | |
| 543 | switch (pi) { |
| 544 | case 1: |
| 545 | pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT; |
| 546 | break; |
| 547 | case 2: |
| 548 | pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT; |
| 549 | break; |
| 550 | default: |
| 551 | return -ENODEV; |
| 552 | } |
| 553 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 554 | dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n", |
| 555 | __FUNCTION__, slot_reg, pcix_cap, m66_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 557 | switch (pcix_cap) { |
| 558 | case 0x0: |
| 559 | *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz; |
| 560 | break; |
| 561 | case 0x1: |
| 562 | *value = PCI_SPEED_66MHz_PCIX; |
| 563 | break; |
| 564 | case 0x3: |
| 565 | *value = PCI_SPEED_133MHz_PCIX; |
| 566 | break; |
| 567 | case 0x4: |
| 568 | *value = PCI_SPEED_133MHz_PCIX_266; |
| 569 | break; |
| 570 | case 0x5: |
| 571 | *value = PCI_SPEED_133MHz_PCIX_533; |
| 572 | break; |
| 573 | case 0x2: |
| 574 | default: |
| 575 | *value = PCI_SPEED_UNKNOWN; |
| 576 | retval = -ENODEV; |
| 577 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | dbg("Adapter speed = %d\n", *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | DBG_LEAVE_ROUTINE |
| 582 | return retval; |
| 583 | } |
| 584 | |
| 585 | static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode) |
| 586 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 587 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | u16 sec_bus_status; |
| 589 | u8 pi; |
| 590 | int retval = 0; |
| 591 | |
| 592 | DBG_ENTER_ROUTINE |
| 593 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 594 | pi = shpc_readb(ctrl, PROG_INTERFACE); |
| 595 | sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | if (pi == 2) { |
Kenji Kaneshige | 87d6c55 | 2005-11-24 11:35:05 +0900 | [diff] [blame] | 598 | *mode = (sec_bus_status & 0x0100) >> 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } else { |
| 600 | retval = -1; |
| 601 | } |
| 602 | |
| 603 | dbg("Mode 1 ECC cap = %d\n", *mode); |
| 604 | |
| 605 | DBG_LEAVE_ROUTINE |
| 606 | return retval; |
| 607 | } |
| 608 | |
| 609 | static int hpc_query_power_fault(struct slot * slot) |
| 610 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 611 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | u32 slot_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | DBG_ENTER_ROUTINE |
| 615 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 616 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | DBG_LEAVE_ROUTINE |
| 619 | /* Note: Logic 0 => fault */ |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 620 | return !(slot_reg & POWER_FAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static int hpc_set_attention_status(struct slot *slot, u8 value) |
| 624 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | u8 slot_cmd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | switch (value) { |
| 628 | case 0 : |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 629 | slot_cmd = SET_ATTN_OFF; /* OFF */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | break; |
| 631 | case 1: |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 632 | slot_cmd = SET_ATTN_ON; /* ON */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | break; |
| 634 | case 2: |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 635 | slot_cmd = SET_ATTN_BLINK; /* BLINK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | break; |
| 637 | default: |
| 638 | return -1; |
| 639 | } |
| 640 | |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 641 | return shpc_write_cmd(slot, slot->hp_slot, slot_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
| 645 | static void hpc_set_green_led_on(struct slot *slot) |
| 646 | { |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 647 | shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | static void hpc_set_green_led_off(struct slot *slot) |
| 651 | { |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 652 | shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static void hpc_set_green_led_blink(struct slot *slot) |
| 656 | { |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 657 | shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | int shpc_get_ctlr_slot_config(struct controller *ctrl, |
| 661 | int *num_ctlr_slots, /* number of slots in this HPC */ |
| 662 | int *first_device_num, /* PCI dev num of the first slot in this SHPC */ |
| 663 | int *physical_slot_num, /* phy slot num of the first slot in this SHPC */ |
| 664 | int *updown, /* physical_slot_num increament: 1 or -1 */ |
| 665 | int *flags) |
| 666 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 667 | u32 slot_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | DBG_ENTER_ROUTINE |
| 670 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 671 | slot_config = shpc_readl(ctrl, SLOT_CONFIG); |
| 672 | *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8; |
| 673 | *num_ctlr_slots = slot_config & SLOT_NUM; |
| 674 | *physical_slot_num = (slot_config & PSN) >> 16; |
| 675 | *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
| 679 | DBG_LEAVE_ROUTINE |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static void hpc_release_ctlr(struct controller *ctrl) |
| 684 | { |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 685 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | struct php_ctlr_state_s *p, *p_prev; |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 687 | int i; |
Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 688 | u32 slot_reg, serr_int; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | DBG_ENTER_ROUTINE |
| 691 | |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 692 | /* |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 693 | * Mask event interrupts and SERRs of all slots |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 694 | */ |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 695 | for (i = 0; i < ctrl->num_slots; i++) { |
| 696 | slot_reg = shpc_readl(ctrl, SLOT_REG(i)); |
| 697 | slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | |
| 698 | BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | |
| 699 | CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK | |
| 700 | CON_PFAULT_SERR_MASK); |
| 701 | slot_reg &= ~SLOT_REG_RSVDZ_MASK; |
| 702 | shpc_writel(ctrl, SLOT_REG(i), slot_reg); |
| 703 | } |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 704 | |
| 705 | cleanup_slots(ctrl); |
| 706 | |
Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 707 | /* |
| 708 | * Mask SERR and System Interrut generation |
| 709 | */ |
| 710 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 711 | serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK | |
| 712 | COMMAND_INTR_MASK | ARBITER_SERR_MASK); |
| 713 | serr_int &= ~SERR_INTR_RSVDZ_MASK; |
| 714 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
| 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | if (shpchp_poll_mode) { |
| 717 | del_timer(&php_ctlr->int_poll_timer); |
| 718 | } else { |
| 719 | if (php_ctlr->irq) { |
| 720 | free_irq(php_ctlr->irq, ctrl); |
| 721 | php_ctlr->irq = 0; |
| 722 | pci_disable_msi(php_ctlr->pci_dev); |
| 723 | } |
| 724 | } |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | if (php_ctlr->pci_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | iounmap(php_ctlr->creg); |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 728 | release_mem_region(ctrl->mmio_base, ctrl->mmio_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | php_ctlr->pci_dev = NULL; |
| 730 | } |
| 731 | |
| 732 | spin_lock(&list_lock); |
| 733 | p = php_ctlr_list_head; |
| 734 | p_prev = NULL; |
| 735 | while (p) { |
| 736 | if (p == php_ctlr) { |
| 737 | if (p_prev) |
| 738 | p_prev->pnext = p->pnext; |
| 739 | else |
| 740 | php_ctlr_list_head = p->pnext; |
| 741 | break; |
| 742 | } else { |
| 743 | p_prev = p; |
| 744 | p = p->pnext; |
| 745 | } |
| 746 | } |
| 747 | spin_unlock(&list_lock); |
| 748 | |
| 749 | kfree(php_ctlr); |
| 750 | |
Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 751 | /* |
| 752 | * If this is the last controller to be released, destroy the |
| 753 | * shpchpd work queue |
| 754 | */ |
| 755 | if (atomic_dec_and_test(&shpchp_num_controllers)) |
| 756 | destroy_workqueue(shpchp_wq); |
| 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | DBG_LEAVE_ROUTINE |
| 759 | |
| 760 | } |
| 761 | |
| 762 | static int hpc_power_on_slot(struct slot * slot) |
| 763 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 764 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | DBG_ENTER_ROUTINE |
| 767 | |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 768 | retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | if (retval) { |
| 770 | err("%s: Write command failed!\n", __FUNCTION__); |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 771 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | DBG_LEAVE_ROUTINE |
| 775 | |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 776 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | static int hpc_slot_enable(struct slot * slot) |
| 780 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 781 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
| 783 | DBG_ENTER_ROUTINE |
| 784 | |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 785 | /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */ |
| 786 | retval = shpc_write_cmd(slot, slot->hp_slot, |
| 787 | SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | if (retval) { |
| 789 | err("%s: Write command failed!\n", __FUNCTION__); |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 790 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | DBG_LEAVE_ROUTINE |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 794 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static int hpc_slot_disable(struct slot * slot) |
| 798 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 799 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
| 801 | DBG_ENTER_ROUTINE |
| 802 | |
Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame^] | 803 | /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */ |
| 804 | retval = shpc_write_cmd(slot, slot->hp_slot, |
| 805 | SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | if (retval) { |
| 807 | err("%s: Write command failed!\n", __FUNCTION__); |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 808 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | DBG_LEAVE_ROUTINE |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 812 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) |
| 816 | { |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 817 | int retval; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 818 | struct controller *ctrl = slot->ctrl; |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 819 | u8 pi, cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 823 | pi = shpc_readb(ctrl, PROG_INTERFACE); |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 824 | if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX)) |
| 825 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 827 | switch (value) { |
| 828 | case PCI_SPEED_33MHz: |
| 829 | cmd = SETA_PCI_33MHZ; |
| 830 | break; |
| 831 | case PCI_SPEED_66MHz: |
| 832 | cmd = SETA_PCI_66MHZ; |
| 833 | break; |
| 834 | case PCI_SPEED_66MHz_PCIX: |
| 835 | cmd = SETA_PCIX_66MHZ; |
| 836 | break; |
| 837 | case PCI_SPEED_100MHz_PCIX: |
| 838 | cmd = SETA_PCIX_100MHZ; |
| 839 | break; |
| 840 | case PCI_SPEED_133MHz_PCIX: |
| 841 | cmd = SETA_PCIX_133MHZ; |
| 842 | break; |
| 843 | case PCI_SPEED_66MHz_PCIX_ECC: |
| 844 | cmd = SETB_PCIX_66MHZ_EM; |
| 845 | break; |
| 846 | case PCI_SPEED_100MHz_PCIX_ECC: |
| 847 | cmd = SETB_PCIX_100MHZ_EM; |
| 848 | break; |
| 849 | case PCI_SPEED_133MHz_PCIX_ECC: |
| 850 | cmd = SETB_PCIX_133MHZ_EM; |
| 851 | break; |
| 852 | case PCI_SPEED_66MHz_PCIX_266: |
| 853 | cmd = SETB_PCIX_66MHZ_266; |
| 854 | break; |
| 855 | case PCI_SPEED_100MHz_PCIX_266: |
| 856 | cmd = SETB_PCIX_100MHZ_266; |
| 857 | break; |
| 858 | case PCI_SPEED_133MHz_PCIX_266: |
| 859 | cmd = SETB_PCIX_133MHZ_266; |
| 860 | break; |
| 861 | case PCI_SPEED_66MHz_PCIX_533: |
| 862 | cmd = SETB_PCIX_66MHZ_533; |
| 863 | break; |
| 864 | case PCI_SPEED_100MHz_PCIX_533: |
| 865 | cmd = SETB_PCIX_100MHZ_533; |
| 866 | break; |
| 867 | case PCI_SPEED_133MHz_PCIX_533: |
| 868 | cmd = SETB_PCIX_133MHZ_533; |
| 869 | break; |
| 870 | default: |
| 871 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 873 | |
| 874 | retval = shpc_write_cmd(slot, 0, cmd); |
| 875 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | err("%s: Write command failed!\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | DBG_LEAVE_ROUTINE |
| 879 | return retval; |
| 880 | } |
| 881 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 882 | static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | { |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 884 | struct controller *ctrl = (struct controller *)dev_id; |
| 885 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; |
| 886 | u32 serr_int, slot_reg, intr_loc, intr_loc2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | int hp_slot; |
| 888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | /* Check to see if it was our interrupt */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 890 | intr_loc = shpc_readl(ctrl, INTR_LOC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | if (!intr_loc) |
| 892 | return IRQ_NONE; |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); |
| 895 | |
| 896 | if(!shpchp_poll_mode) { |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 897 | /* |
| 898 | * Mask Global Interrupt Mask - see implementation |
| 899 | * note on p. 139 of SHPC spec rev 1.0 |
| 900 | */ |
| 901 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 902 | serr_int |= GLOBAL_INTR_MASK; |
| 903 | serr_int &= ~SERR_INTR_RSVDZ_MASK; |
| 904 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 906 | intr_loc2 = shpc_readl(ctrl, INTR_LOC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); |
| 908 | } |
| 909 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 910 | if (intr_loc & CMD_INTR_PENDING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | /* |
| 912 | * Command Complete Interrupt Pending |
Kenji Kaneshige | f467f61 | 2005-11-24 11:39:29 +0900 | [diff] [blame] | 913 | * RO only - clear by writing 1 to the Command Completion |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | * Detect bit in Controller SERR-INT register |
| 915 | */ |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 916 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 917 | serr_int &= ~SERR_INTR_RSVDZ_MASK; |
| 918 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
| 919 | |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 920 | ctrl->cmd_busy = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | wake_up_interruptible(&ctrl->queue); |
| 922 | } |
| 923 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 924 | if (!(intr_loc & ~CMD_INTR_PENDING)) |
Kenji Kaneshige | e4e7304 | 2006-01-26 10:05:57 +0900 | [diff] [blame] | 925 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 928 | /* To find out which slot has interrupt pending */ |
| 929 | if (!(intr_loc & SLOT_INTR_PENDING(hp_slot))) |
| 930 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 932 | slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); |
| 933 | dbg("%s: Slot %x with intr, slot register = %x\n", |
| 934 | __FUNCTION__, hp_slot, slot_reg); |
| 935 | |
| 936 | if (slot_reg & MRL_CHANGE_DETECTED) |
| 937 | php_ctlr->switch_change_callback( |
| 938 | hp_slot, php_ctlr->callback_instance_id); |
| 939 | |
| 940 | if (slot_reg & BUTTON_PRESS_DETECTED) |
| 941 | php_ctlr->attention_button_callback( |
| 942 | hp_slot, php_ctlr->callback_instance_id); |
| 943 | |
| 944 | if (slot_reg & PRSNT_CHANGE_DETECTED) |
| 945 | php_ctlr->presence_change_callback( |
| 946 | hp_slot , php_ctlr->callback_instance_id); |
| 947 | |
| 948 | if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)) |
| 949 | php_ctlr->power_fault_callback( |
| 950 | hp_slot, php_ctlr->callback_instance_id); |
| 951 | |
| 952 | /* Clear all slot events */ |
| 953 | slot_reg &= ~SLOT_REG_RSVDZ_MASK; |
| 954 | shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | } |
Kenji Kaneshige | e4e7304 | 2006-01-26 10:05:57 +0900 | [diff] [blame] | 956 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | if (!shpchp_poll_mode) { |
| 958 | /* Unmask Global Interrupt Mask */ |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 959 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 960 | serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK); |
| 961 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | return IRQ_HANDLED; |
| 965 | } |
| 966 | |
| 967 | static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value) |
| 968 | { |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 969 | int retval = 0; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 970 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 972 | u8 pi = shpc_readb(ctrl, PROG_INTERFACE); |
| 973 | u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1); |
| 974 | u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
| 976 | DBG_ENTER_ROUTINE |
| 977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | if (pi == 2) { |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 979 | if (slot_avail2 & SLOT_133MHZ_PCIX_533) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 980 | bus_speed = PCI_SPEED_133MHz_PCIX_533; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 981 | else if (slot_avail2 & SLOT_100MHZ_PCIX_533) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 982 | bus_speed = PCI_SPEED_100MHz_PCIX_533; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 983 | else if (slot_avail2 & SLOT_66MHZ_PCIX_533) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 984 | bus_speed = PCI_SPEED_66MHz_PCIX_533; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 985 | else if (slot_avail2 & SLOT_133MHZ_PCIX_266) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 986 | bus_speed = PCI_SPEED_133MHz_PCIX_266; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 987 | else if (slot_avail2 & SLOT_100MHZ_PCIX_266) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 988 | bus_speed = PCI_SPEED_100MHz_PCIX_266; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 989 | else if (slot_avail2 & SLOT_66MHZ_PCIX_266) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 990 | bus_speed = PCI_SPEED_66MHz_PCIX_266; |
| 991 | } |
| 992 | |
| 993 | if (bus_speed == PCI_SPEED_UNKNOWN) { |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 994 | if (slot_avail1 & SLOT_133MHZ_PCIX) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 995 | bus_speed = PCI_SPEED_133MHz_PCIX; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 996 | else if (slot_avail1 & SLOT_100MHZ_PCIX) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 997 | bus_speed = PCI_SPEED_100MHz_PCIX; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 998 | else if (slot_avail1 & SLOT_66MHZ_PCIX) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 999 | bus_speed = PCI_SPEED_66MHz_PCIX; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 1000 | else if (slot_avail2 & SLOT_66MHZ) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1001 | bus_speed = PCI_SPEED_66MHz; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 1002 | else if (slot_avail1 & SLOT_33MHZ) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1003 | bus_speed = PCI_SPEED_33MHz; |
| 1004 | else |
| 1005 | retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | *value = bus_speed; |
| 1009 | dbg("Max bus speed = %d\n", bus_speed); |
| 1010 | DBG_LEAVE_ROUTINE |
| 1011 | return retval; |
| 1012 | } |
| 1013 | |
| 1014 | static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value) |
| 1015 | { |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1016 | int retval = 0; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1017 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1019 | u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG); |
| 1020 | u8 pi = shpc_readb(ctrl, PROG_INTERFACE); |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1021 | u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
| 1023 | DBG_ENTER_ROUTINE |
| 1024 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1025 | if ((pi == 1) && (speed_mode > 4)) { |
| 1026 | *value = PCI_SPEED_UNKNOWN; |
| 1027 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1030 | switch (speed_mode) { |
| 1031 | case 0x0: |
| 1032 | *value = PCI_SPEED_33MHz; |
| 1033 | break; |
| 1034 | case 0x1: |
| 1035 | *value = PCI_SPEED_66MHz; |
| 1036 | break; |
| 1037 | case 0x2: |
| 1038 | *value = PCI_SPEED_66MHz_PCIX; |
| 1039 | break; |
| 1040 | case 0x3: |
| 1041 | *value = PCI_SPEED_100MHz_PCIX; |
| 1042 | break; |
| 1043 | case 0x4: |
| 1044 | *value = PCI_SPEED_133MHz_PCIX; |
| 1045 | break; |
| 1046 | case 0x5: |
| 1047 | *value = PCI_SPEED_66MHz_PCIX_ECC; |
| 1048 | break; |
| 1049 | case 0x6: |
| 1050 | *value = PCI_SPEED_100MHz_PCIX_ECC; |
| 1051 | break; |
| 1052 | case 0x7: |
| 1053 | *value = PCI_SPEED_133MHz_PCIX_ECC; |
| 1054 | break; |
| 1055 | case 0x8: |
| 1056 | *value = PCI_SPEED_66MHz_PCIX_266; |
| 1057 | break; |
| 1058 | case 0x9: |
| 1059 | *value = PCI_SPEED_100MHz_PCIX_266; |
| 1060 | break; |
| 1061 | case 0xa: |
| 1062 | *value = PCI_SPEED_133MHz_PCIX_266; |
| 1063 | break; |
| 1064 | case 0xb: |
| 1065 | *value = PCI_SPEED_66MHz_PCIX_533; |
| 1066 | break; |
| 1067 | case 0xc: |
| 1068 | *value = PCI_SPEED_100MHz_PCIX_533; |
| 1069 | break; |
| 1070 | case 0xd: |
| 1071 | *value = PCI_SPEED_133MHz_PCIX_533; |
| 1072 | break; |
| 1073 | default: |
| 1074 | *value = PCI_SPEED_UNKNOWN; |
| 1075 | retval = -ENODEV; |
| 1076 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | dbg("Current bus speed = %d\n", bus_speed); |
| 1080 | DBG_LEAVE_ROUTINE |
| 1081 | return retval; |
| 1082 | } |
| 1083 | |
| 1084 | static struct hpc_ops shpchp_hpc_ops = { |
| 1085 | .power_on_slot = hpc_power_on_slot, |
| 1086 | .slot_enable = hpc_slot_enable, |
| 1087 | .slot_disable = hpc_slot_disable, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | .set_bus_speed_mode = hpc_set_bus_speed_mode, |
| 1089 | .set_attention_status = hpc_set_attention_status, |
| 1090 | .get_power_status = hpc_get_power_status, |
| 1091 | .get_attention_status = hpc_get_attention_status, |
| 1092 | .get_latch_status = hpc_get_latch_status, |
| 1093 | .get_adapter_status = hpc_get_adapter_status, |
| 1094 | |
| 1095 | .get_max_bus_speed = hpc_get_max_bus_speed, |
| 1096 | .get_cur_bus_speed = hpc_get_cur_bus_speed, |
| 1097 | .get_adapter_speed = hpc_get_adapter_speed, |
| 1098 | .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap, |
| 1099 | .get_prog_int = hpc_get_prog_int, |
| 1100 | |
| 1101 | .query_power_fault = hpc_query_power_fault, |
| 1102 | .green_led_on = hpc_set_green_led_on, |
| 1103 | .green_led_off = hpc_set_green_led_off, |
| 1104 | .green_led_blink = hpc_set_green_led_blink, |
| 1105 | |
| 1106 | .release_ctlr = hpc_release_ctlr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | }; |
| 1108 | |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 1109 | int shpc_init(struct controller * ctrl, struct pci_dev * pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
| 1111 | struct php_ctlr_state_s *php_ctlr, *p; |
| 1112 | void *instance_id = ctrl; |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1113 | int rc, num_slots = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | u8 hp_slot; |
| 1115 | static int first = 1; |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1116 | u32 shpc_base_offset; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1117 | u32 tempdword, slot_reg, slot_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | u8 i; |
| 1119 | |
| 1120 | DBG_ENTER_ROUTINE |
| 1121 | |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1122 | ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ |
| 1123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | spin_lock_init(&list_lock); |
Kenji Kaneshige | 57c95c0 | 2006-01-26 10:02:41 +0900 | [diff] [blame] | 1125 | php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | if (!php_ctlr) { /* allocate controller state data */ |
| 1128 | err("%s: HPC controller memory allocation error!\n", __FUNCTION__); |
| 1129 | goto abort; |
| 1130 | } |
| 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | php_ctlr->pci_dev = pdev; /* save pci_dev in context */ |
| 1133 | |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 1134 | if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == |
| 1135 | PCI_DEVICE_ID_AMD_GOLAM_7450)) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1136 | /* amd shpc driver doesn't use Base Offset; assume 0 */ |
| 1137 | ctrl->mmio_base = pci_resource_start(pdev, 0); |
| 1138 | ctrl->mmio_size = pci_resource_len(pdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } else { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1140 | ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC); |
| 1141 | if (!ctrl->cap_offset) { |
| 1142 | err("%s : cap_offset == 0\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | goto abort_free_ctlr; |
| 1144 | } |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1145 | dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset); |
| 1146 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1147 | rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | if (rc) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1149 | err("%s: cannot read base_offset\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | goto abort_free_ctlr; |
| 1151 | } |
| 1152 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1153 | rc = shpc_indirect_read(ctrl, 3, &tempdword); |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1154 | if (rc) { |
| 1155 | err("%s: cannot read slot config\n", __FUNCTION__); |
| 1156 | goto abort_free_ctlr; |
| 1157 | } |
| 1158 | num_slots = tempdword & SLOT_NUM; |
| 1159 | dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots); |
| 1160 | |
| 1161 | for (i = 0; i < 9 + num_slots; i++) { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1162 | rc = shpc_indirect_read(ctrl, i, &tempdword); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | if (rc) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1164 | err("%s: cannot read creg (index = %d)\n", |
| 1165 | __FUNCTION__, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | goto abort_free_ctlr; |
| 1167 | } |
rajesh.shah@intel.com | 7c8942f | 2005-10-13 12:05:43 -0700 | [diff] [blame] | 1168 | dbg("%s: offset %d: value %x\n", __FUNCTION__,i, |
| 1169 | tempdword); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1171 | |
| 1172 | ctrl->mmio_base = |
| 1173 | pci_resource_start(pdev, 0) + shpc_base_offset; |
| 1174 | ctrl->mmio_size = 0x24 + 0x4 * num_slots; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | if (first) { |
| 1178 | spin_lock_init(&hpc_event_lock); |
| 1179 | first = 0; |
| 1180 | } |
| 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, |
| 1183 | pdev->subsystem_device); |
| 1184 | |
| 1185 | if (pci_enable_device(pdev)) |
| 1186 | goto abort_free_ctlr; |
| 1187 | |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1188 | if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | err("%s: cannot reserve MMIO region\n", __FUNCTION__); |
| 1190 | goto abort_free_ctlr; |
| 1191 | } |
| 1192 | |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1193 | php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | if (!php_ctlr->creg) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1195 | err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, |
| 1196 | ctrl->mmio_size, ctrl->mmio_base); |
| 1197 | release_mem_region(ctrl->mmio_base, ctrl->mmio_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | goto abort_free_ctlr; |
| 1199 | } |
| 1200 | dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1202 | mutex_init(&ctrl->crit_sect); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 1203 | mutex_init(&ctrl->cmd_lock); |
| 1204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | /* Setup wait queue */ |
| 1206 | init_waitqueue_head(&ctrl->queue); |
| 1207 | |
| 1208 | /* Find the IRQ */ |
| 1209 | php_ctlr->irq = pdev->irq; |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 1210 | php_ctlr->attention_button_callback = shpchp_handle_attention_button, |
| 1211 | php_ctlr->switch_change_callback = shpchp_handle_switch_change; |
| 1212 | php_ctlr->presence_change_callback = shpchp_handle_presence_change; |
| 1213 | php_ctlr->power_fault_callback = shpchp_handle_power_fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | php_ctlr->callback_instance_id = instance_id; |
| 1215 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1216 | ctrl->hpc_ctlr_handle = php_ctlr; |
| 1217 | ctrl->hpc_ops = &shpchp_hpc_ops; |
| 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | /* Return PCI Controller Info */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1220 | slot_config = shpc_readl(ctrl, SLOT_CONFIG); |
| 1221 | php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8; |
| 1222 | php_ctlr->num_slots = slot_config & SLOT_NUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset); |
| 1224 | dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots); |
| 1225 | |
| 1226 | /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1227 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); |
Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 1229 | tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK | |
| 1230 | COMMAND_INTR_MASK | ARBITER_SERR_MASK); |
| 1231 | tempdword &= ~SERR_INTR_RSVDZ_MASK; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1232 | shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); |
| 1233 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); |
| 1235 | |
| 1236 | /* Mask the MRL sensor SERR Mask of individual slot in |
| 1237 | * Slot SERR-INT Mask & clear all the existing event if any |
| 1238 | */ |
| 1239 | for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 1240 | slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, |
| 1242 | hp_slot, slot_reg); |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1243 | slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | |
| 1244 | BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | |
| 1245 | CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK | |
| 1246 | CON_PFAULT_SERR_MASK); |
| 1247 | slot_reg &= ~SLOT_REG_RSVDZ_MASK; |
| 1248 | shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | if (shpchp_poll_mode) {/* Install interrupt polling code */ |
| 1252 | /* Install and start the interrupt polling timer */ |
| 1253 | init_timer(&php_ctlr->int_poll_timer); |
| 1254 | start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */ |
| 1255 | } else { |
| 1256 | /* Installs the interrupt handler */ |
| 1257 | rc = pci_enable_msi(pdev); |
| 1258 | if (rc) { |
| 1259 | info("Can't get msi for the hotplug controller\n"); |
| 1260 | info("Use INTx for the hotplug controller\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } else |
| 1262 | php_ctlr->irq = pdev->irq; |
| 1263 | |
| 1264 | rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl); |
| 1265 | dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc); |
| 1266 | if (rc) { |
| 1267 | err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); |
| 1268 | goto abort_free_ctlr; |
| 1269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | } |
rajesh.shah@intel.com | 7c8942f | 2005-10-13 12:05:43 -0700 | [diff] [blame] | 1271 | dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__, |
| 1272 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
| 1273 | PCI_FUNC(pdev->devfn), pdev->irq); |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 1274 | get_hp_hw_control_from_firmware(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
| 1276 | /* Add this HPC instance into the HPC list */ |
| 1277 | spin_lock(&list_lock); |
| 1278 | if (php_ctlr_list_head == 0) { |
| 1279 | php_ctlr_list_head = php_ctlr; |
| 1280 | p = php_ctlr_list_head; |
| 1281 | p->pnext = NULL; |
| 1282 | } else { |
| 1283 | p = php_ctlr_list_head; |
| 1284 | |
| 1285 | while (p->pnext) |
| 1286 | p = p->pnext; |
| 1287 | |
| 1288 | p->pnext = php_ctlr; |
| 1289 | } |
| 1290 | spin_unlock(&list_lock); |
| 1291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | ctlr_seq_num++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1294 | /* |
Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 1295 | * If this is the first controller to be initialized, |
| 1296 | * initialize the shpchpd work queue |
| 1297 | */ |
| 1298 | if (atomic_add_return(1, &shpchp_num_controllers) == 1) { |
| 1299 | shpchp_wq = create_singlethread_workqueue("shpchpd"); |
| 1300 | if (!shpchp_wq) |
| 1301 | return -ENOMEM; |
| 1302 | } |
| 1303 | |
| 1304 | /* |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1305 | * Unmask all event interrupts of all slots |
| 1306 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 1308 | slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, |
| 1310 | hp_slot, slot_reg); |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1311 | slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | |
| 1312 | BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | |
| 1313 | CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK); |
| 1314 | shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | } |
| 1316 | if (!shpchp_poll_mode) { |
| 1317 | /* Unmask all general input interrupts and SERR */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1318 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 1319 | tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK | |
| 1320 | SERR_INTR_RSVDZ_MASK); |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1321 | shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); |
| 1322 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); |
| 1324 | } |
| 1325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | DBG_LEAVE_ROUTINE |
| 1327 | return 0; |
| 1328 | |
| 1329 | /* We end up here for the many possible ways to fail this API. */ |
| 1330 | abort_free_ctlr: |
| 1331 | kfree(php_ctlr); |
| 1332 | abort: |
| 1333 | DBG_LEAVE_ROUTINE |
| 1334 | return -1; |
| 1335 | } |