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