blob: 285a21d36524fee61b97a274f731fed6a434f5cb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Accardi8cf4c192005-08-16 15:16:10 -070026 * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/pci.h>
Andrew Mortond4d28dd2005-11-13 16:06:40 -080034#include <linux/interrupt.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#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 Torvalds1da177e2005-04-16 15:20:36 -070085/* 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 Kaneshige2b34da72006-05-02 11:09:42 +090093/*
94 * Logical Slot Register definitions
95 */
96#define SLOT_REG(i) (SLOT1 + (4 * i))
97
Kenji Kaneshige58587592006-05-02 11:10:37 +090098#define SLOT_STATE_SHIFT (0)
99#define SLOT_STATE_MASK (3 << 0)
100#define SLOT_STATE_PWRONLY (1)
101#define SLOT_STATE_ENABLED (2)
102#define SLOT_STATE_DISABLED (3)
103#define PWR_LED_STATE_SHIFT (2)
104#define PWR_LED_STATE_MASK (3 << 2)
105#define ATN_LED_STATE_SHIFT (4)
106#define ATN_LED_STATE_MASK (3 << 4)
107#define ATN_LED_STATE_ON (1)
108#define ATN_LED_STATE_BLINK (2)
109#define ATN_LED_STATE_OFF (3)
110#define POWER_FAULT (1 << 6)
111#define ATN_BUTTON (1 << 7)
112#define MRL_SENSOR (1 << 8)
113#define MHZ66_CAP (1 << 9)
114#define PRSNT_SHIFT (10)
115#define PRSNT_MASK (3 << 10)
116#define PCIX_CAP_SHIFT (12)
117#define PCIX_CAP_MASK_PI1 (3 << 12)
118#define PCIX_CAP_MASK_PI2 (7 << 12)
119#define PRSNT_CHANGE_DETECTED (1 << 16)
120#define ISO_PFAULT_DETECTED (1 << 17)
121#define BUTTON_PRESS_DETECTED (1 << 18)
122#define MRL_CHANGE_DETECTED (1 << 19)
123#define CON_PFAULT_DETECTED (1 << 20)
124#define PRSNT_CHANGE_INTR_MASK (1 << 24)
125#define ISO_PFAULT_INTR_MASK (1 << 25)
126#define BUTTON_PRESS_INTR_MASK (1 << 26)
127#define MRL_CHANGE_INTR_MASK (1 << 27)
128#define CON_PFAULT_INTR_MASK (1 << 28)
129#define MRL_CHANGE_SERR_MASK (1 << 29)
130#define CON_PFAULT_SERR_MASK (1 << 30)
131#define SLOT_REG_RSVDZ_MASK (1 << 15) | (7 << 21)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* SHPC 'write' operations/commands */
134
135/* Slot operation - 0x00h to 0x3Fh */
136
137#define NO_CHANGE 0x00
138
139/* Slot state - Bits 0 & 1 of controller command register */
140#define SET_SLOT_PWR 0x01
141#define SET_SLOT_ENABLE 0x02
142#define SET_SLOT_DISABLE 0x03
143
144/* Power indicator state - Bits 2 & 3 of controller command register*/
145#define SET_PWR_ON 0x04
146#define SET_PWR_BLINK 0x08
147#define SET_PWR_OFF 0x0C
148
149/* Attention indicator state - Bits 4 & 5 of controller command register*/
150#define SET_ATTN_ON 0x010
151#define SET_ATTN_BLINK 0x020
152#define SET_ATTN_OFF 0x030
153
154/* Set bus speed/mode A - 0x40h to 0x47h */
155#define SETA_PCI_33MHZ 0x40
156#define SETA_PCI_66MHZ 0x41
157#define SETA_PCIX_66MHZ 0x42
158#define SETA_PCIX_100MHZ 0x43
159#define SETA_PCIX_133MHZ 0x44
160#define RESERV_1 0x45
161#define RESERV_2 0x46
162#define RESERV_3 0x47
163
164/* Set bus speed/mode B - 0x50h to 0x5fh */
165#define SETB_PCI_33MHZ 0x50
166#define SETB_PCI_66MHZ 0x51
167#define SETB_PCIX_66MHZ_PM 0x52
168#define SETB_PCIX_100MHZ_PM 0x53
169#define SETB_PCIX_133MHZ_PM 0x54
170#define SETB_PCIX_66MHZ_EM 0x55
171#define SETB_PCIX_100MHZ_EM 0x56
172#define SETB_PCIX_133MHZ_EM 0x57
173#define SETB_PCIX_66MHZ_266 0x58
174#define SETB_PCIX_100MHZ_266 0x59
175#define SETB_PCIX_133MHZ_266 0x5a
176#define SETB_PCIX_66MHZ_533 0x5b
177#define SETB_PCIX_100MHZ_533 0x5c
178#define SETB_PCIX_133MHZ_533 0x5d
179
180
181/* Power-on all slots - 0x48h */
182#define SET_PWR_ON_ALL 0x48
183
184/* Enable all slots - 0x49h */
185#define SET_ENABLE_ALL 0x49
186
187/* SHPC controller command error code */
188#define SWITCH_OPEN 0x1
189#define INVALID_CMD 0x2
190#define INVALID_SPEED_MODE 0x4
191
192/* For accessing SHPC Working Register Set */
193#define DWORD_SELECT 0x2
194#define DWORD_DATA 0x4
195#define BASE_OFFSET 0x0
196
197/* Field Offset in Logical Slot Register - byte boundary */
198#define SLOT_EVENT_LATCH 0x2
199#define SLOT_SERR_INT_MASK 0x3
200
201static spinlock_t hpc_event_lock;
202
203DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
204static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
205static int ctlr_seq_num = 0; /* Controller sequenc # */
206static spinlock_t list_lock;
207
208static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs);
209
210static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900211static int hpc_check_cmd_status(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900213static inline u8 shpc_readb(struct controller *ctrl, int reg)
214{
215 return readb(ctrl->hpc_ctlr_handle->creg + reg);
216}
217
218static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
219{
220 writeb(val, ctrl->hpc_ctlr_handle->creg + reg);
221}
222
223static inline u16 shpc_readw(struct controller *ctrl, int reg)
224{
225 return readw(ctrl->hpc_ctlr_handle->creg + reg);
226}
227
228static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
229{
230 writew(val, ctrl->hpc_ctlr_handle->creg + reg);
231}
232
233static inline u32 shpc_readl(struct controller *ctrl, int reg)
234{
235 return readl(ctrl->hpc_ctlr_handle->creg + reg);
236}
237
238static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
239{
240 writel(val, ctrl->hpc_ctlr_handle->creg + reg);
241}
242
243static inline int shpc_indirect_read(struct controller *ctrl, int index,
244 u32 *value)
245{
246 int rc;
247 u32 cap_offset = ctrl->cap_offset;
248 struct pci_dev *pdev = ctrl->pci_dev;
249
250 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
251 if (rc)
252 return rc;
253 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
254}
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256/* This is the interrupt polling timeout function. */
257static void int_poll_timeout(unsigned long lphp_ctlr)
258{
259 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr;
260
261 DBG_ENTER_ROUTINE
262
263 if ( !php_ctlr ) {
264 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
265 return;
266 }
267
268 /* Poll for interrupt events. regs == NULL => polling */
269 shpc_isr( 0, (void *)php_ctlr, NULL );
270
271 init_timer(&php_ctlr->int_poll_timer);
272 if (!shpchp_poll_time)
273 shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
274
275 start_int_poll_timer(php_ctlr, shpchp_poll_time);
276
277 return;
278}
279
280/* This function starts the interrupt polling timer. */
281static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
282{
283 if (!php_ctlr) {
284 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
285 return;
286 }
287
288 if ( ( seconds <= 0 ) || ( seconds > 60 ) )
289 seconds = 2; /* Clamp to sane value */
290
291 php_ctlr->int_poll_timer.function = &int_poll_timeout;
292 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */
293 php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ;
294 add_timer(&php_ctlr->int_poll_timer);
295
296 return;
297}
298
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900299static inline int shpc_wait_cmd(struct controller *ctrl)
300{
301 int retval = 0;
302 unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000;
303 unsigned long timeout = msecs_to_jiffies(timeout_msec);
304 int rc = wait_event_interruptible_timeout(ctrl->queue,
305 !ctrl->cmd_busy, timeout);
306 if (!rc) {
307 retval = -EIO;
308 err("Command not completed in %d msec\n", timeout_msec);
309 } else if (rc < 0) {
310 retval = -EINTR;
311 info("Command was interrupted by a signal\n");
312 }
313 ctrl->cmd_busy = 0;
314
315 return retval;
316}
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
319{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700320 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900321 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 u16 cmd_status;
323 int retval = 0;
324 u16 temp_word;
325 int i;
326
327 DBG_ENTER_ROUTINE
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900328
329 mutex_lock(&slot->ctrl->cmd_lock);
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (!php_ctlr) {
332 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900333 retval = -EINVAL;
334 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336
337 for (i = 0; i < 10; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900338 cmd_status = shpc_readw(ctrl, CMD_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 if (!(cmd_status & 0x1))
341 break;
342 /* Check every 0.1 sec for a total of 1 sec*/
343 msleep(100);
344 }
345
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900346 cmd_status = shpc_readw(ctrl, CMD_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 if (cmd_status & 0x1) {
349 /* After 1 sec and and the controller is still busy */
350 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900351 retval = -EBUSY;
352 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354
355 ++t_slot;
356 temp_word = (t_slot << 8) | (cmd & 0xFF);
357 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
358
359 /* To make sure the Controller Busy bit is 0 before we send out the
360 * command.
361 */
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900362 slot->ctrl->cmd_busy = 1;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900363 shpc_writew(ctrl, CMD, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900365 /*
366 * Wait for command completion.
367 */
368 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900369 if (retval)
370 goto out;
371
372 cmd_status = hpc_check_cmd_status(slot->ctrl);
373 if (cmd_status) {
374 err("%s: Failed to issued command 0x%x (error code = %d)\n",
375 __FUNCTION__, cmd, cmd_status);
376 retval = -EIO;
377 }
378 out:
379 mutex_unlock(&slot->ctrl->cmd_lock);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 DBG_LEAVE_ROUTINE
382 return retval;
383}
384
385static int hpc_check_cmd_status(struct controller *ctrl)
386{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 u16 cmd_status;
388 int retval = 0;
389
390 DBG_ENTER_ROUTINE
391
392 if (!ctrl->hpc_ctlr_handle) {
393 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
394 return -1;
395 }
396
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900397 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 switch (cmd_status >> 1) {
400 case 0:
401 retval = 0;
402 break;
403 case 1:
404 retval = SWITCH_OPEN;
405 err("%s: Switch opened!\n", __FUNCTION__);
406 break;
407 case 2:
408 retval = INVALID_CMD;
409 err("%s: Invalid HPC command!\n", __FUNCTION__);
410 break;
411 case 4:
412 retval = INVALID_SPEED_MODE;
413 err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
414 break;
415 default:
416 retval = cmd_status;
417 }
418
419 DBG_LEAVE_ROUTINE
420 return retval;
421}
422
423
424static int hpc_get_attention_status(struct slot *slot, u8 *status)
425{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900426 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900428 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 DBG_ENTER_ROUTINE
431
432 if (!slot->ctrl->hpc_ctlr_handle) {
433 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
434 return -1;
435 }
436
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900437 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900438 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Kenji Kaneshige58587592006-05-02 11:10:37 +0900440 switch (state) {
441 case ATN_LED_STATE_ON:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *status = 1; /* On */
443 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900444 case ATN_LED_STATE_BLINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 *status = 2; /* Blink */
446 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900447 case ATN_LED_STATE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 *status = 0; /* Off */
449 break;
450 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900451 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 break;
453 }
454
455 DBG_LEAVE_ROUTINE
456 return 0;
457}
458
459static int hpc_get_power_status(struct slot * slot, u8 *status)
460{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900461 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900463 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 DBG_ENTER_ROUTINE
466
467 if (!slot->ctrl->hpc_ctlr_handle) {
468 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
469 return -1;
470 }
471
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900472 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900473 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Kenji Kaneshige58587592006-05-02 11:10:37 +0900475 switch (state) {
476 case SLOT_STATE_PWRONLY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 *status = 2; /* Powered only */
478 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900479 case SLOT_STATE_ENABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 *status = 1; /* Enabled */
481 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900482 case SLOT_STATE_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 *status = 0; /* Disabled */
484 break;
485 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900486 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 break;
488 }
489
490 DBG_LEAVE_ROUTINE
Kenji Kaneshige58587592006-05-02 11:10:37 +0900491 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494
495static int hpc_get_latch_status(struct slot *slot, u8 *status)
496{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900497 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 DBG_ENTER_ROUTINE
501
502 if (!slot->ctrl->hpc_ctlr_handle) {
503 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
504 return -1;
505 }
506
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900507 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900508 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 DBG_LEAVE_ROUTINE
511 return 0;
512}
513
514static int hpc_get_adapter_status(struct slot *slot, u8 *status)
515{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900516 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900518 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 DBG_ENTER_ROUTINE
521
522 if (!slot->ctrl->hpc_ctlr_handle) {
523 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
524 return -1;
525 }
526
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900527 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900528 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
529 *status = (state != 0x3) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 DBG_LEAVE_ROUTINE
532 return 0;
533}
534
535static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
536{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900537 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 DBG_ENTER_ROUTINE
540
541 if (!slot->ctrl->hpc_ctlr_handle) {
542 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
543 return -1;
544 }
545
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900546 *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 DBG_LEAVE_ROUTINE
549 return 0;
550}
551
552static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
553{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900555 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900556 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900557 u8 m66_cap = !!(slot_reg & MHZ66_CAP);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900558 u8 pi, pcix_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 DBG_ENTER_ROUTINE
561
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900562 if ((retval = hpc_get_prog_int(slot, &pi)))
563 return retval;
564
565 switch (pi) {
566 case 1:
567 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
568 break;
569 case 2:
570 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
571 break;
572 default:
573 return -ENODEV;
574 }
575
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900576 dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
577 __FUNCTION__, slot_reg, pcix_cap, m66_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900579 switch (pcix_cap) {
580 case 0x0:
581 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
582 break;
583 case 0x1:
584 *value = PCI_SPEED_66MHz_PCIX;
585 break;
586 case 0x3:
587 *value = PCI_SPEED_133MHz_PCIX;
588 break;
589 case 0x4:
590 *value = PCI_SPEED_133MHz_PCIX_266;
591 break;
592 case 0x5:
593 *value = PCI_SPEED_133MHz_PCIX_533;
594 break;
595 case 0x2:
596 default:
597 *value = PCI_SPEED_UNKNOWN;
598 retval = -ENODEV;
599 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
601
602 dbg("Adapter speed = %d\n", *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 DBG_LEAVE_ROUTINE
604 return retval;
605}
606
607static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
608{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900609 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 u16 sec_bus_status;
611 u8 pi;
612 int retval = 0;
613
614 DBG_ENTER_ROUTINE
615
616 if (!slot->ctrl->hpc_ctlr_handle) {
617 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
618 return -1;
619 }
620
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900621 pi = shpc_readb(ctrl, PROG_INTERFACE);
622 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 if (pi == 2) {
Kenji Kaneshige87d6c552005-11-24 11:35:05 +0900625 *mode = (sec_bus_status & 0x0100) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 } else {
627 retval = -1;
628 }
629
630 dbg("Mode 1 ECC cap = %d\n", *mode);
631
632 DBG_LEAVE_ROUTINE
633 return retval;
634}
635
636static int hpc_query_power_fault(struct slot * slot)
637{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900638 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 DBG_ENTER_ROUTINE
642
643 if (!slot->ctrl->hpc_ctlr_handle) {
644 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
645 return -1;
646 }
647
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900648 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 DBG_LEAVE_ROUTINE
651 /* Note: Logic 0 => fault */
Kenji Kaneshige58587592006-05-02 11:10:37 +0900652 return !(slot_reg & POWER_FAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
655static int hpc_set_attention_status(struct slot *slot, u8 value)
656{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700657 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 u8 slot_cmd = 0;
659 int rc = 0;
660
661 if (!slot->ctrl->hpc_ctlr_handle) {
662 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
663 return -1;
664 }
665
666 if (slot->hp_slot >= php_ctlr->num_slots) {
667 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
668 return -1;
669 }
670
671 switch (value) {
672 case 0 :
673 slot_cmd = 0x30; /* OFF */
674 break;
675 case 1:
676 slot_cmd = 0x10; /* ON */
677 break;
678 case 2:
679 slot_cmd = 0x20; /* BLINK */
680 break;
681 default:
682 return -1;
683 }
684
685 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
686
687 return rc;
688}
689
690
691static void hpc_set_green_led_on(struct slot *slot)
692{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700693 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 u8 slot_cmd;
695
696 if (!slot->ctrl->hpc_ctlr_handle) {
697 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
698 return ;
699 }
700
701 if (slot->hp_slot >= php_ctlr->num_slots) {
702 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
703 return ;
704 }
705
706 slot_cmd = 0x04;
707
708 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
709
710 return;
711}
712
713static void hpc_set_green_led_off(struct slot *slot)
714{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700715 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 u8 slot_cmd;
717
718 if (!slot->ctrl->hpc_ctlr_handle) {
719 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
720 return ;
721 }
722
723 if (slot->hp_slot >= php_ctlr->num_slots) {
724 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
725 return ;
726 }
727
728 slot_cmd = 0x0C;
729
730 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
731
732 return;
733}
734
735static void hpc_set_green_led_blink(struct slot *slot)
736{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700737 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 u8 slot_cmd;
739
740 if (!slot->ctrl->hpc_ctlr_handle) {
741 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
742 return ;
743 }
744
745 if (slot->hp_slot >= php_ctlr->num_slots) {
746 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
747 return ;
748 }
749
750 slot_cmd = 0x08;
751
752 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
753
754 return;
755}
756
757int shpc_get_ctlr_slot_config(struct controller *ctrl,
758 int *num_ctlr_slots, /* number of slots in this HPC */
759 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
760 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
761 int *updown, /* physical_slot_num increament: 1 or -1 */
762 int *flags)
763{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900764 u32 slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 DBG_ENTER_ROUTINE
767
768 if (!ctrl->hpc_ctlr_handle) {
769 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
770 return -1;
771 }
772
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900773 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
774 *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8;
775 *num_ctlr_slots = slot_config & SLOT_NUM;
776 *physical_slot_num = (slot_config & PSN) >> 16;
777 *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 DBG_LEAVE_ROUTINE
782 return 0;
783}
784
785static void hpc_release_ctlr(struct controller *ctrl)
786{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700787 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 struct php_ctlr_state_s *p, *p_prev;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800789 int i;
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900790 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 DBG_ENTER_ROUTINE
793
794 if (!ctrl->hpc_ctlr_handle) {
795 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
796 return ;
797 }
798
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800799 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900800 * Mask event interrupts and SERRs of all slots
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800801 */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900802 for (i = 0; i < ctrl->num_slots; i++) {
803 slot_reg = shpc_readl(ctrl, SLOT_REG(i));
804 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
805 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
806 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
807 CON_PFAULT_SERR_MASK);
808 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
809 shpc_writel(ctrl, SLOT_REG(i), slot_reg);
810 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800811
812 cleanup_slots(ctrl);
813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if (shpchp_poll_mode) {
815 del_timer(&php_ctlr->int_poll_timer);
816 } else {
817 if (php_ctlr->irq) {
818 free_irq(php_ctlr->irq, ctrl);
819 php_ctlr->irq = 0;
820 pci_disable_msi(php_ctlr->pci_dev);
821 }
822 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (php_ctlr->pci_dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 iounmap(php_ctlr->creg);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900826 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 php_ctlr->pci_dev = NULL;
828 }
829
830 spin_lock(&list_lock);
831 p = php_ctlr_list_head;
832 p_prev = NULL;
833 while (p) {
834 if (p == php_ctlr) {
835 if (p_prev)
836 p_prev->pnext = p->pnext;
837 else
838 php_ctlr_list_head = p->pnext;
839 break;
840 } else {
841 p_prev = p;
842 p = p->pnext;
843 }
844 }
845 spin_unlock(&list_lock);
846
847 kfree(php_ctlr);
848
849DBG_LEAVE_ROUTINE
850
851}
852
853static int hpc_power_on_slot(struct slot * slot)
854{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700855 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 u8 slot_cmd;
857 int retval = 0;
858
859 DBG_ENTER_ROUTINE
860
861 if (!slot->ctrl->hpc_ctlr_handle) {
862 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
863 return -1;
864 }
865
866 if (slot->hp_slot >= php_ctlr->num_slots) {
867 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
868 return -1;
869 }
870 slot_cmd = 0x01;
871
872 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
873
874 if (retval) {
875 err("%s: Write command failed!\n", __FUNCTION__);
876 return -1;
877 }
878
879 DBG_LEAVE_ROUTINE
880
881 return retval;
882}
883
884static int hpc_slot_enable(struct slot * slot)
885{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700886 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 u8 slot_cmd;
888 int retval = 0;
889
890 DBG_ENTER_ROUTINE
891
892 if (!slot->ctrl->hpc_ctlr_handle) {
893 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
894 return -1;
895 }
896
897 if (slot->hp_slot >= php_ctlr->num_slots) {
898 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
899 return -1;
900 }
901 /* 3A => Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
902 slot_cmd = 0x3A;
903
904 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
905
906 if (retval) {
907 err("%s: Write command failed!\n", __FUNCTION__);
908 return -1;
909 }
910
911 DBG_LEAVE_ROUTINE
912 return retval;
913}
914
915static int hpc_slot_disable(struct slot * slot)
916{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700917 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 u8 slot_cmd;
919 int retval = 0;
920
921 DBG_ENTER_ROUTINE
922
923 if (!slot->ctrl->hpc_ctlr_handle) {
924 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
925 return -1;
926 }
927
928 if (slot->hp_slot >= php_ctlr->num_slots) {
929 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
930 return -1;
931 }
932
933 /* 1F => Slot - Disable, Power Indicator - Off, Attention Indicator - On */
934 slot_cmd = 0x1F;
935
936 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
937
938 if (retval) {
939 err("%s: Write command failed!\n", __FUNCTION__);
940 return -1;
941 }
942
943 DBG_LEAVE_ROUTINE
944 return retval;
945}
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
948{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900949 int retval;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900950 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900951 u8 pi, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900955 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900956 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
957 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900959 switch (value) {
960 case PCI_SPEED_33MHz:
961 cmd = SETA_PCI_33MHZ;
962 break;
963 case PCI_SPEED_66MHz:
964 cmd = SETA_PCI_66MHZ;
965 break;
966 case PCI_SPEED_66MHz_PCIX:
967 cmd = SETA_PCIX_66MHZ;
968 break;
969 case PCI_SPEED_100MHz_PCIX:
970 cmd = SETA_PCIX_100MHZ;
971 break;
972 case PCI_SPEED_133MHz_PCIX:
973 cmd = SETA_PCIX_133MHZ;
974 break;
975 case PCI_SPEED_66MHz_PCIX_ECC:
976 cmd = SETB_PCIX_66MHZ_EM;
977 break;
978 case PCI_SPEED_100MHz_PCIX_ECC:
979 cmd = SETB_PCIX_100MHZ_EM;
980 break;
981 case PCI_SPEED_133MHz_PCIX_ECC:
982 cmd = SETB_PCIX_133MHZ_EM;
983 break;
984 case PCI_SPEED_66MHz_PCIX_266:
985 cmd = SETB_PCIX_66MHZ_266;
986 break;
987 case PCI_SPEED_100MHz_PCIX_266:
988 cmd = SETB_PCIX_100MHZ_266;
989 break;
990 case PCI_SPEED_133MHz_PCIX_266:
991 cmd = SETB_PCIX_133MHZ_266;
992 break;
993 case PCI_SPEED_66MHz_PCIX_533:
994 cmd = SETB_PCIX_66MHZ_533;
995 break;
996 case PCI_SPEED_100MHz_PCIX_533:
997 cmd = SETB_PCIX_100MHZ_533;
998 break;
999 case PCI_SPEED_133MHz_PCIX_533:
1000 cmd = SETB_PCIX_133MHZ_533;
1001 break;
1002 default:
1003 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 }
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001005
1006 retval = shpc_write_cmd(slot, 0, cmd);
1007 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 err("%s: Write command failed!\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 DBG_LEAVE_ROUTINE
1011 return retval;
1012}
1013
1014static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1015{
1016 struct controller *ctrl = NULL;
1017 struct php_ctlr_state_s *php_ctlr;
1018 u8 schedule_flag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 u32 temp_dword, intr_loc, intr_loc2;
1020 int hp_slot;
1021
1022 if (!dev_id)
1023 return IRQ_NONE;
1024
1025 if (!shpchp_poll_mode) {
1026 ctrl = (struct controller *)dev_id;
1027 php_ctlr = ctrl->hpc_ctlr_handle;
1028 } else {
1029 php_ctlr = (struct php_ctlr_state_s *) dev_id;
1030 ctrl = (struct controller *)php_ctlr->callback_instance_id;
1031 }
1032
1033 if (!ctrl)
1034 return IRQ_NONE;
1035
1036 if (!php_ctlr || !php_ctlr->creg)
1037 return IRQ_NONE;
1038
1039 /* Check to see if it was our interrupt */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001040 intr_loc = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042 if (!intr_loc)
1043 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
1045
1046 if(!shpchp_poll_mode) {
1047 /* Mask Global Interrupt Mask - see implementation note on p. 139 */
1048 /* of SHPC spec rev 1.0*/
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001049 temp_dword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 temp_dword |= 0x00000001;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001051 shpc_writel(ctrl, SERR_INTR_ENABLE, temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001053 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1055 }
1056
1057 if (intr_loc & 0x0001) {
1058 /*
1059 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +09001060 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 * Detect bit in Controller SERR-INT register
1062 */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001063 temp_dword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigef467f612005-11-24 11:39:29 +09001064 temp_dword &= 0xfffdffff;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001065 shpc_writel(ctrl, SERR_INTR_ENABLE, temp_dword);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +09001066 ctrl->cmd_busy = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 wake_up_interruptible(&ctrl->queue);
1068 }
1069
Kenji Kaneshigee4e73042006-01-26 10:05:57 +09001070 if ((intr_loc = (intr_loc >> 1)) == 0)
1071 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1074 /* To find out which slot has interrupt pending */
1075 if ((intr_loc >> hp_slot) & 0x01) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001076 temp_dword = shpc_readl(ctrl, SLOT_REG(hp_slot));
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001077 dbg("%s: Slot %x with intr, slot register = %x\n",
1078 __FUNCTION__, hp_slot, temp_dword);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001079 if ((php_ctlr->switch_change_callback) &&
1080 (temp_dword & MRL_CHANGE_DETECTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 schedule_flag += php_ctlr->switch_change_callback(
1082 hp_slot, php_ctlr->callback_instance_id);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001083 if ((php_ctlr->attention_button_callback) &&
1084 (temp_dword & BUTTON_PRESS_DETECTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 schedule_flag += php_ctlr->attention_button_callback(
1086 hp_slot, php_ctlr->callback_instance_id);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001087 if ((php_ctlr->presence_change_callback) &&
1088 (temp_dword & PRSNT_CHANGE_DETECTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 schedule_flag += php_ctlr->presence_change_callback(
1090 hp_slot , php_ctlr->callback_instance_id);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001091 if ((php_ctlr->power_fault_callback) &&
1092 (temp_dword & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 schedule_flag += php_ctlr->power_fault_callback(
1094 hp_slot, php_ctlr->callback_instance_id);
1095
1096 /* Clear all slot events */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001097 temp_dword &= ~SLOT_REG_RSVDZ_MASK;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001098 shpc_writel(ctrl, SLOT_REG(hp_slot), temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001100 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1102 }
1103 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +09001104 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (!shpchp_poll_mode) {
1106 /* Unmask Global Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001107 temp_dword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 temp_dword &= 0xfffffffe;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001109 shpc_writel(ctrl, SERR_INTR_ENABLE, temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111
1112 return IRQ_HANDLED;
1113}
1114
1115static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1116{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001117 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001118 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001120 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
1121 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
1122 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 DBG_ENTER_ROUTINE
1125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001127 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001128 bus_speed = PCI_SPEED_133MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001129 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001130 bus_speed = PCI_SPEED_100MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001131 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001132 bus_speed = PCI_SPEED_66MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001133 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001134 bus_speed = PCI_SPEED_133MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001135 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001136 bus_speed = PCI_SPEED_100MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001137 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001138 bus_speed = PCI_SPEED_66MHz_PCIX_266;
1139 }
1140
1141 if (bus_speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001142 if (slot_avail1 & SLOT_133MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001143 bus_speed = PCI_SPEED_133MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001144 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001145 bus_speed = PCI_SPEED_100MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001146 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001147 bus_speed = PCI_SPEED_66MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001148 else if (slot_avail2 & SLOT_66MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001149 bus_speed = PCI_SPEED_66MHz;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001150 else if (slot_avail1 & SLOT_33MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001151 bus_speed = PCI_SPEED_33MHz;
1152 else
1153 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155
1156 *value = bus_speed;
1157 dbg("Max bus speed = %d\n", bus_speed);
1158 DBG_LEAVE_ROUTINE
1159 return retval;
1160}
1161
1162static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1163{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001164 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001165 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001167 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
1168 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001169 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 DBG_ENTER_ROUTINE
1172
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001173 if ((pi == 1) && (speed_mode > 4)) {
1174 *value = PCI_SPEED_UNKNOWN;
1175 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
1177
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001178 switch (speed_mode) {
1179 case 0x0:
1180 *value = PCI_SPEED_33MHz;
1181 break;
1182 case 0x1:
1183 *value = PCI_SPEED_66MHz;
1184 break;
1185 case 0x2:
1186 *value = PCI_SPEED_66MHz_PCIX;
1187 break;
1188 case 0x3:
1189 *value = PCI_SPEED_100MHz_PCIX;
1190 break;
1191 case 0x4:
1192 *value = PCI_SPEED_133MHz_PCIX;
1193 break;
1194 case 0x5:
1195 *value = PCI_SPEED_66MHz_PCIX_ECC;
1196 break;
1197 case 0x6:
1198 *value = PCI_SPEED_100MHz_PCIX_ECC;
1199 break;
1200 case 0x7:
1201 *value = PCI_SPEED_133MHz_PCIX_ECC;
1202 break;
1203 case 0x8:
1204 *value = PCI_SPEED_66MHz_PCIX_266;
1205 break;
1206 case 0x9:
1207 *value = PCI_SPEED_100MHz_PCIX_266;
1208 break;
1209 case 0xa:
1210 *value = PCI_SPEED_133MHz_PCIX_266;
1211 break;
1212 case 0xb:
1213 *value = PCI_SPEED_66MHz_PCIX_533;
1214 break;
1215 case 0xc:
1216 *value = PCI_SPEED_100MHz_PCIX_533;
1217 break;
1218 case 0xd:
1219 *value = PCI_SPEED_133MHz_PCIX_533;
1220 break;
1221 default:
1222 *value = PCI_SPEED_UNKNOWN;
1223 retval = -ENODEV;
1224 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 }
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 dbg("Current bus speed = %d\n", bus_speed);
1228 DBG_LEAVE_ROUTINE
1229 return retval;
1230}
1231
1232static struct hpc_ops shpchp_hpc_ops = {
1233 .power_on_slot = hpc_power_on_slot,
1234 .slot_enable = hpc_slot_enable,
1235 .slot_disable = hpc_slot_disable,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1237 .set_attention_status = hpc_set_attention_status,
1238 .get_power_status = hpc_get_power_status,
1239 .get_attention_status = hpc_get_attention_status,
1240 .get_latch_status = hpc_get_latch_status,
1241 .get_adapter_status = hpc_get_adapter_status,
1242
1243 .get_max_bus_speed = hpc_get_max_bus_speed,
1244 .get_cur_bus_speed = hpc_get_cur_bus_speed,
1245 .get_adapter_speed = hpc_get_adapter_speed,
1246 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
1247 .get_prog_int = hpc_get_prog_int,
1248
1249 .query_power_fault = hpc_query_power_fault,
1250 .green_led_on = hpc_set_green_led_on,
1251 .green_led_off = hpc_set_green_led_off,
1252 .green_led_blink = hpc_set_green_led_blink,
1253
1254 .release_ctlr = hpc_release_ctlr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255};
1256
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001257int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 struct php_ctlr_state_s *php_ctlr, *p;
1260 void *instance_id = ctrl;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001261 int rc, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 u8 hp_slot;
1263 static int first = 1;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001264 u32 shpc_base_offset;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001265 u32 tempdword, slot_reg, slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 u8 i;
1267
1268 DBG_ENTER_ROUTINE
1269
Kenji Kaneshige04559862005-11-24 11:36:59 +09001270 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1271
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 spin_lock_init(&list_lock);
Kenji Kaneshige57c95c02006-01-26 10:02:41 +09001273 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
1275 if (!php_ctlr) { /* allocate controller state data */
1276 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1277 goto abort;
1278 }
1279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1281
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001282 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1283 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001284 /* amd shpc driver doesn't use Base Offset; assume 0 */
1285 ctrl->mmio_base = pci_resource_start(pdev, 0);
1286 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001288 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1289 if (!ctrl->cap_offset) {
1290 err("%s : cap_offset == 0\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 goto abort_free_ctlr;
1292 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001293 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1294
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001295 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001297 err("%s: cannot read base_offset\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 goto abort_free_ctlr;
1299 }
1300
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001301 rc = shpc_indirect_read(ctrl, 3, &tempdword);
Kenji Kaneshige04559862005-11-24 11:36:59 +09001302 if (rc) {
1303 err("%s: cannot read slot config\n", __FUNCTION__);
1304 goto abort_free_ctlr;
1305 }
1306 num_slots = tempdword & SLOT_NUM;
1307 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
1308
1309 for (i = 0; i < 9 + num_slots; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001310 rc = shpc_indirect_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001312 err("%s: cannot read creg (index = %d)\n",
1313 __FUNCTION__, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 goto abort_free_ctlr;
1315 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001316 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1317 tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001319
1320 ctrl->mmio_base =
1321 pci_resource_start(pdev, 0) + shpc_base_offset;
1322 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 }
1324
1325 if (first) {
1326 spin_lock_init(&hpc_event_lock);
1327 first = 0;
1328 }
1329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1331 pdev->subsystem_device);
1332
1333 if (pci_enable_device(pdev))
1334 goto abort_free_ctlr;
1335
Kenji Kaneshige04559862005-11-24 11:36:59 +09001336 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1338 goto abort_free_ctlr;
1339 }
1340
Kenji Kaneshige04559862005-11-24 11:36:59 +09001341 php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 if (!php_ctlr->creg) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001343 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1344 ctrl->mmio_size, ctrl->mmio_base);
1345 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 goto abort_free_ctlr;
1347 }
1348 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001350 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +09001351 mutex_init(&ctrl->cmd_lock);
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 /* Setup wait queue */
1354 init_waitqueue_head(&ctrl->queue);
1355
1356 /* Find the IRQ */
1357 php_ctlr->irq = pdev->irq;
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001358 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1359 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1360 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1361 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 php_ctlr->callback_instance_id = instance_id;
1363
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001364 ctrl->hpc_ctlr_handle = php_ctlr;
1365 ctrl->hpc_ops = &shpchp_hpc_ops;
1366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 /* Return PCI Controller Info */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001368 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
1369 php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1370 php_ctlr->num_slots = slot_config & SLOT_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
1372 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
1373
1374 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001375 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1377 tempdword = 0x0003000f;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001378 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1379 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1381
1382 /* Mask the MRL sensor SERR Mask of individual slot in
1383 * Slot SERR-INT Mask & clear all the existing event if any
1384 */
1385 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001386 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1388 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001389 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1390 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1391 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
1392 CON_PFAULT_SERR_MASK);
1393 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
1394 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
1396
1397 if (shpchp_poll_mode) {/* Install interrupt polling code */
1398 /* Install and start the interrupt polling timer */
1399 init_timer(&php_ctlr->int_poll_timer);
1400 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
1401 } else {
1402 /* Installs the interrupt handler */
1403 rc = pci_enable_msi(pdev);
1404 if (rc) {
1405 info("Can't get msi for the hotplug controller\n");
1406 info("Use INTx for the hotplug controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 } else
1408 php_ctlr->irq = pdev->irq;
1409
1410 rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);
1411 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
1412 if (rc) {
1413 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
1414 goto abort_free_ctlr;
1415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001417 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
1418 pdev->bus->number, PCI_SLOT(pdev->devfn),
1419 PCI_FUNC(pdev->devfn), pdev->irq);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -07001420 get_hp_hw_control_from_firmware(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 /* Add this HPC instance into the HPC list */
1423 spin_lock(&list_lock);
1424 if (php_ctlr_list_head == 0) {
1425 php_ctlr_list_head = php_ctlr;
1426 p = php_ctlr_list_head;
1427 p->pnext = NULL;
1428 } else {
1429 p = php_ctlr_list_head;
1430
1431 while (p->pnext)
1432 p = p->pnext;
1433
1434 p->pnext = php_ctlr;
1435 }
1436 spin_unlock(&list_lock);
1437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 ctlr_seq_num++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001440 /*
1441 * Unmask all event interrupts of all slots
1442 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001444 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1446 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001447 slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1448 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1449 CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
1450 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 }
1452 if (!shpchp_poll_mode) {
1453 /* Unmask all general input interrupts and SERR */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001454 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 tempdword = 0x0000000a;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001456 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1457 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1459 }
1460
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 DBG_LEAVE_ROUTINE
1462 return 0;
1463
1464 /* We end up here for the many possible ways to fail this API. */
1465abort_free_ctlr:
1466 kfree(php_ctlr);
1467abort:
1468 DBG_LEAVE_ROUTINE
1469 return -1;
1470}