blob: b7bede4b7c27037755ea22da751c39be3ac75ffe [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/*
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +090094 * Interrupt Locator Register definitions
95 */
96#define CMD_INTR_PENDING (1 << 0)
97#define SLOT_INTR_PENDING(i) (1 << (i + 1))
98
99/*
Kenji Kaneshigee7138722006-05-02 11:12:37 +0900100 * 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 Kaneshige2b34da72006-05-02 11:09:42 +0900111 * Logical Slot Register definitions
112 */
113#define SLOT_REG(i) (SLOT1 + (4 * i))
114
Kenji Kaneshige58587592006-05-02 11:10:37 +0900115#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 Torvalds1da177e2005-04-16 15:20:36 -0700149
Kenji Kaneshige40853992006-05-12 11:11:48 +0900150/*
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 Torvalds1da177e2005-04-16 15:20:36 -0700171#define SETA_PCI_66MHZ 0x41
172#define SETA_PCIX_66MHZ 0x42
173#define SETA_PCIX_100MHZ 0x43
174#define SETA_PCIX_133MHZ 0x44
Kenji Kaneshige40853992006-05-12 11:11:48 +0900175#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 Torvalds1da177e2005-04-16 15:20:36 -0700181#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 Kaneshige40853992006-05-12 11:11:48 +0900194#define SETB_RESERVED1 0x5e
195#define SETB_RESERVED2 0x5f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Kenji Kaneshige40853992006-05-12 11:11:48 +0900197/*
198 * SHPC controller command error code
199 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#define SWITCH_OPEN 0x1
201#define INVALID_CMD 0x2
202#define INVALID_SPEED_MODE 0x4
203
Kenji Kaneshige40853992006-05-12 11:11:48 +0900204/*
205 * For accessing SHPC Working Register Set via PCI Configuration Space
206 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define DWORD_SELECT 0x2
208#define DWORD_DATA 0x4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/* Field Offset in Logical Slot Register - byte boundary */
211#define SLOT_EVENT_LATCH 0x2
212#define SLOT_SERR_INT_MASK 0x3
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +0900215static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
216
David Howells7d12e782006-10-05 14:55:46 +0100217static irqreturn_t shpc_isr(int irq, void *dev_id);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800218static void start_int_poll_timer(struct controller *ctrl, int sec);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900219static int hpc_check_cmd_status(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900221static inline u8 shpc_readb(struct controller *ctrl, int reg)
222{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800223 return readb(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900224}
225
226static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
227{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800228 writeb(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900229}
230
231static inline u16 shpc_readw(struct controller *ctrl, int reg)
232{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800233 return readw(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900234}
235
236static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
237{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800238 writew(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900239}
240
241static inline u32 shpc_readl(struct controller *ctrl, int reg)
242{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800243 return readl(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900244}
245
246static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
247{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800248 writel(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900249}
250
251static inline int shpc_indirect_read(struct controller *ctrl, int index,
252 u32 *value)
253{
254 int rc;
255 u32 cap_offset = ctrl->cap_offset;
256 struct pci_dev *pdev = ctrl->pci_dev;
257
258 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
259 if (rc)
260 return rc;
261 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
262}
263
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900264/*
265 * This is the interrupt polling timeout function.
266 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800267static void int_poll_timeout(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800269 struct controller *ctrl = (struct controller *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900271 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900273 /* Poll for interrupt events. regs == NULL => polling */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800274 shpc_isr(0, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800276 init_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (!shpchp_poll_time)
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900278 shpchp_poll_time = 2; /* default polling interval is 2 sec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800280 start_int_poll_timer(ctrl, shpchp_poll_time);
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900281
282 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900285/*
286 * This function starts the interrupt polling timer.
287 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800288static void start_int_poll_timer(struct controller *ctrl, int sec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900290 /* Clamp to sane value */
291 if ((sec <= 0) || (sec > 60))
292 sec = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800294 ctrl->poll_timer.function = &int_poll_timeout;
295 ctrl->poll_timer.data = (unsigned long)ctrl;
296 ctrl->poll_timer.expires = jiffies + sec * HZ;
297 add_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700300static inline int is_ctrl_busy(struct controller *ctrl)
301{
302 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
303 return cmd_status & 0x1;
304}
305
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700306/*
307 * Returns 1 if SHPC finishes executing a command within 1 sec,
308 * otherwise returns 0.
309 */
310static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
311{
312 int i;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700313
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700314 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700315 return 1;
316
317 /* Check every 0.1 sec for a total of 1 sec */
318 for (i = 0; i < 10; i++) {
319 msleep(100);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700320 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700321 return 1;
322 }
323
324 return 0;
325}
326
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900327static inline int shpc_wait_cmd(struct controller *ctrl)
328{
329 int retval = 0;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700330 unsigned long timeout = msecs_to_jiffies(1000);
331 int rc;
332
333 if (shpchp_poll_mode)
334 rc = shpc_poll_ctrl_busy(ctrl);
335 else
336 rc = wait_event_interruptible_timeout(ctrl->queue,
Kenji Kaneshige6aa562c2006-09-28 15:51:36 -0700337 !is_ctrl_busy(ctrl), timeout);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700338 if (!rc && is_ctrl_busy(ctrl)) {
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900339 retval = -EIO;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700340 err("Command not completed in 1000 msec\n");
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900341 } else if (rc < 0) {
342 retval = -EINTR;
343 info("Command was interrupted by a signal\n");
344 }
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900345
346 return retval;
347}
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
350{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900351 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 u16 cmd_status;
353 int retval = 0;
354 u16 temp_word;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 DBG_ENTER_ROUTINE
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900357
358 mutex_lock(&slot->ctrl->cmd_lock);
359
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700360 if (!shpc_poll_ctrl_busy(ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 /* After 1 sec and and the controller is still busy */
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700362 err("%s : Controller is still busy after 1 sec.\n",
363 __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900364 retval = -EBUSY;
365 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367
368 ++t_slot;
369 temp_word = (t_slot << 8) | (cmd & 0xFF);
370 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
371
372 /* To make sure the Controller Busy bit is 0 before we send out the
373 * command.
374 */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900375 shpc_writew(ctrl, CMD, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900377 /*
378 * Wait for command completion.
379 */
380 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900381 if (retval)
382 goto out;
383
384 cmd_status = hpc_check_cmd_status(slot->ctrl);
385 if (cmd_status) {
386 err("%s: Failed to issued command 0x%x (error code = %d)\n",
387 __FUNCTION__, cmd, cmd_status);
388 retval = -EIO;
389 }
390 out:
391 mutex_unlock(&slot->ctrl->cmd_lock);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 DBG_LEAVE_ROUTINE
394 return retval;
395}
396
397static int hpc_check_cmd_status(struct controller *ctrl)
398{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 u16 cmd_status;
400 int retval = 0;
401
402 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900404 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 switch (cmd_status >> 1) {
407 case 0:
408 retval = 0;
409 break;
410 case 1:
411 retval = SWITCH_OPEN;
412 err("%s: Switch opened!\n", __FUNCTION__);
413 break;
414 case 2:
415 retval = INVALID_CMD;
416 err("%s: Invalid HPC command!\n", __FUNCTION__);
417 break;
418 case 4:
419 retval = INVALID_SPEED_MODE;
420 err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
421 break;
422 default:
423 retval = cmd_status;
424 }
425
426 DBG_LEAVE_ROUTINE
427 return retval;
428}
429
430
431static int hpc_get_attention_status(struct slot *slot, u8 *status)
432{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900433 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900435 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 DBG_ENTER_ROUTINE
438
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900439 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900440 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Kenji Kaneshige58587592006-05-02 11:10:37 +0900442 switch (state) {
443 case ATN_LED_STATE_ON:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 *status = 1; /* On */
445 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900446 case ATN_LED_STATE_BLINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 *status = 2; /* Blink */
448 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900449 case ATN_LED_STATE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 *status = 0; /* Off */
451 break;
452 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900453 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 break;
455 }
456
457 DBG_LEAVE_ROUTINE
458 return 0;
459}
460
461static int hpc_get_power_status(struct slot * slot, u8 *status)
462{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900463 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900465 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 DBG_ENTER_ROUTINE
468
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900469 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900470 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Kenji Kaneshige58587592006-05-02 11:10:37 +0900472 switch (state) {
473 case SLOT_STATE_PWRONLY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 *status = 2; /* Powered only */
475 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900476 case SLOT_STATE_ENABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 *status = 1; /* Enabled */
478 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900479 case SLOT_STATE_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 *status = 0; /* Disabled */
481 break;
482 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900483 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 break;
485 }
486
487 DBG_LEAVE_ROUTINE
Kenji Kaneshige58587592006-05-02 11:10:37 +0900488 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
491
492static int hpc_get_latch_status(struct slot *slot, u8 *status)
493{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900494 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 DBG_ENTER_ROUTINE
498
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900499 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900500 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 DBG_LEAVE_ROUTINE
503 return 0;
504}
505
506static int hpc_get_adapter_status(struct slot *slot, u8 *status)
507{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900508 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900510 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 DBG_ENTER_ROUTINE
513
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900514 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900515 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
516 *status = (state != 0x3) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 DBG_LEAVE_ROUTINE
519 return 0;
520}
521
522static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
523{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900524 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900528 *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 DBG_LEAVE_ROUTINE
531 return 0;
532}
533
534static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
535{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900537 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900538 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900539 u8 m66_cap = !!(slot_reg & MHZ66_CAP);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900540 u8 pi, pcix_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 DBG_ENTER_ROUTINE
543
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900544 if ((retval = hpc_get_prog_int(slot, &pi)))
545 return retval;
546
547 switch (pi) {
548 case 1:
549 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
550 break;
551 case 2:
552 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
553 break;
554 default:
555 return -ENODEV;
556 }
557
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900558 dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
559 __FUNCTION__, slot_reg, pcix_cap, m66_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900561 switch (pcix_cap) {
562 case 0x0:
563 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
564 break;
565 case 0x1:
566 *value = PCI_SPEED_66MHz_PCIX;
567 break;
568 case 0x3:
569 *value = PCI_SPEED_133MHz_PCIX;
570 break;
571 case 0x4:
572 *value = PCI_SPEED_133MHz_PCIX_266;
573 break;
574 case 0x5:
575 *value = PCI_SPEED_133MHz_PCIX_533;
576 break;
577 case 0x2:
578 default:
579 *value = PCI_SPEED_UNKNOWN;
580 retval = -ENODEV;
581 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583
584 dbg("Adapter speed = %d\n", *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 DBG_LEAVE_ROUTINE
586 return retval;
587}
588
589static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
590{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900591 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 u16 sec_bus_status;
593 u8 pi;
594 int retval = 0;
595
596 DBG_ENTER_ROUTINE
597
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900598 pi = shpc_readb(ctrl, PROG_INTERFACE);
599 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 if (pi == 2) {
Kenji Kaneshige87d6c552005-11-24 11:35:05 +0900602 *mode = (sec_bus_status & 0x0100) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 } else {
604 retval = -1;
605 }
606
607 dbg("Mode 1 ECC cap = %d\n", *mode);
608
609 DBG_LEAVE_ROUTINE
610 return retval;
611}
612
613static int hpc_query_power_fault(struct slot * slot)
614{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900615 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 DBG_ENTER_ROUTINE
619
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900620 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 DBG_LEAVE_ROUTINE
623 /* Note: Logic 0 => fault */
Kenji Kaneshige58587592006-05-02 11:10:37 +0900624 return !(slot_reg & POWER_FAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
626
627static int hpc_set_attention_status(struct slot *slot, u8 value)
628{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 u8 slot_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 switch (value) {
632 case 0 :
Kenji Kaneshige40853992006-05-12 11:11:48 +0900633 slot_cmd = SET_ATTN_OFF; /* OFF */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 break;
635 case 1:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900636 slot_cmd = SET_ATTN_ON; /* ON */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 break;
638 case 2:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900639 slot_cmd = SET_ATTN_BLINK; /* BLINK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 break;
641 default:
642 return -1;
643 }
644
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900645 return shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
648
649static void hpc_set_green_led_on(struct slot *slot)
650{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900651 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
654static void hpc_set_green_led_off(struct slot *slot)
655{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900656 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
659static void hpc_set_green_led_blink(struct slot *slot)
660{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900661 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664static void hpc_release_ctlr(struct controller *ctrl)
665{
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800666 int i;
Kenji Kaneshiged49f2c42006-05-03 23:34:17 +0900667 u32 slot_reg, serr_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 DBG_ENTER_ROUTINE
670
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800671 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900672 * Mask event interrupts and SERRs of all slots
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800673 */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900674 for (i = 0; i < ctrl->num_slots; i++) {
675 slot_reg = shpc_readl(ctrl, SLOT_REG(i));
676 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
677 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
678 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
679 CON_PFAULT_SERR_MASK);
680 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
681 shpc_writel(ctrl, SLOT_REG(i), slot_reg);
682 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800683
684 cleanup_slots(ctrl);
685
Kenji Kaneshiged49f2c42006-05-03 23:34:17 +0900686 /*
687 * Mask SERR and System Interrut generation
688 */
689 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
690 serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
691 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
692 serr_int &= ~SERR_INTR_RSVDZ_MASK;
693 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
694
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800695 if (shpchp_poll_mode)
696 del_timer(&ctrl->poll_timer);
697 else {
698 free_irq(ctrl->pci_dev->irq, ctrl);
699 pci_disable_msi(ctrl->pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800701
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800702 iounmap(ctrl->creg);
703 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +0900705 /*
706 * If this is the last controller to be released, destroy the
707 * shpchpd work queue
708 */
709 if (atomic_dec_and_test(&shpchp_num_controllers))
710 destroy_workqueue(shpchp_wq);
711
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800712 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715static int hpc_power_on_slot(struct slot * slot)
716{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900717 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 DBG_ENTER_ROUTINE
720
Kenji Kaneshige40853992006-05-12 11:11:48 +0900721 retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (retval) {
723 err("%s: Write command failed!\n", __FUNCTION__);
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900724 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
727 DBG_LEAVE_ROUTINE
728
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900729 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730}
731
732static int hpc_slot_enable(struct slot * slot)
733{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900734 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 DBG_ENTER_ROUTINE
737
Kenji Kaneshige40853992006-05-12 11:11:48 +0900738 /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
739 retval = shpc_write_cmd(slot, slot->hp_slot,
740 SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 if (retval) {
742 err("%s: Write command failed!\n", __FUNCTION__);
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900743 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745
746 DBG_LEAVE_ROUTINE
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900747 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749
750static int hpc_slot_disable(struct slot * slot)
751{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900752 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 DBG_ENTER_ROUTINE
755
Kenji Kaneshige40853992006-05-12 11:11:48 +0900756 /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */
757 retval = shpc_write_cmd(slot, slot->hp_slot,
758 SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 if (retval) {
760 err("%s: Write command failed!\n", __FUNCTION__);
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900761 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 }
763
764 DBG_LEAVE_ROUTINE
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900765 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
769{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900770 int retval;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900771 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900772 u8 pi, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900776 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900777 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
778 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900780 switch (value) {
781 case PCI_SPEED_33MHz:
782 cmd = SETA_PCI_33MHZ;
783 break;
784 case PCI_SPEED_66MHz:
785 cmd = SETA_PCI_66MHZ;
786 break;
787 case PCI_SPEED_66MHz_PCIX:
788 cmd = SETA_PCIX_66MHZ;
789 break;
790 case PCI_SPEED_100MHz_PCIX:
791 cmd = SETA_PCIX_100MHZ;
792 break;
793 case PCI_SPEED_133MHz_PCIX:
794 cmd = SETA_PCIX_133MHZ;
795 break;
796 case PCI_SPEED_66MHz_PCIX_ECC:
797 cmd = SETB_PCIX_66MHZ_EM;
798 break;
799 case PCI_SPEED_100MHz_PCIX_ECC:
800 cmd = SETB_PCIX_100MHZ_EM;
801 break;
802 case PCI_SPEED_133MHz_PCIX_ECC:
803 cmd = SETB_PCIX_133MHZ_EM;
804 break;
805 case PCI_SPEED_66MHz_PCIX_266:
806 cmd = SETB_PCIX_66MHZ_266;
807 break;
808 case PCI_SPEED_100MHz_PCIX_266:
809 cmd = SETB_PCIX_100MHZ_266;
810 break;
811 case PCI_SPEED_133MHz_PCIX_266:
812 cmd = SETB_PCIX_133MHZ_266;
813 break;
814 case PCI_SPEED_66MHz_PCIX_533:
815 cmd = SETB_PCIX_66MHZ_533;
816 break;
817 case PCI_SPEED_100MHz_PCIX_533:
818 cmd = SETB_PCIX_100MHZ_533;
819 break;
820 case PCI_SPEED_133MHz_PCIX_533:
821 cmd = SETB_PCIX_133MHZ_533;
822 break;
823 default:
824 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 }
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900826
827 retval = shpc_write_cmd(slot, 0, cmd);
828 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 err("%s: Write command failed!\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 DBG_LEAVE_ROUTINE
832 return retval;
833}
834
David Howells7d12e782006-10-05 14:55:46 +0100835static irqreturn_t shpc_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900837 struct controller *ctrl = (struct controller *)dev_id;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900838 u32 serr_int, slot_reg, intr_loc, intr_loc2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 int hp_slot;
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 /* Check to see if it was our interrupt */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900842 intr_loc = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 if (!intr_loc)
844 return IRQ_NONE;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
847
848 if(!shpchp_poll_mode) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900849 /*
850 * Mask Global Interrupt Mask - see implementation
851 * note on p. 139 of SHPC spec rev 1.0
852 */
853 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
854 serr_int |= GLOBAL_INTR_MASK;
855 serr_int &= ~SERR_INTR_RSVDZ_MASK;
856 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900858 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
860 }
861
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900862 if (intr_loc & CMD_INTR_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 /*
864 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +0900865 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 * Detect bit in Controller SERR-INT register
867 */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900868 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
869 serr_int &= ~SERR_INTR_RSVDZ_MASK;
870 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 wake_up_interruptible(&ctrl->queue);
873 }
874
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900875 if (!(intr_loc & ~CMD_INTR_PENDING))
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900876 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900879 /* To find out which slot has interrupt pending */
880 if (!(intr_loc & SLOT_INTR_PENDING(hp_slot)))
881 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900883 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
884 dbg("%s: Slot %x with intr, slot register = %x\n",
885 __FUNCTION__, hp_slot, slot_reg);
886
887 if (slot_reg & MRL_CHANGE_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800888 shpchp_handle_switch_change(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900889
890 if (slot_reg & BUTTON_PRESS_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800891 shpchp_handle_attention_button(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900892
893 if (slot_reg & PRSNT_CHANGE_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800894 shpchp_handle_presence_change(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900895
896 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800897 shpchp_handle_power_fault(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900898
899 /* Clear all slot events */
900 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
901 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900903 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 if (!shpchp_poll_mode) {
905 /* Unmask Global Interrupt Mask */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900906 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
907 serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
908 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910
911 return IRQ_HANDLED;
912}
913
914static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
915{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900916 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900917 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900919 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
920 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
921 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 DBG_ENTER_ROUTINE
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900926 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900927 bus_speed = PCI_SPEED_133MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900928 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900929 bus_speed = PCI_SPEED_100MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900930 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900931 bus_speed = PCI_SPEED_66MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900932 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900933 bus_speed = PCI_SPEED_133MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900934 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900935 bus_speed = PCI_SPEED_100MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900936 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900937 bus_speed = PCI_SPEED_66MHz_PCIX_266;
938 }
939
940 if (bus_speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900941 if (slot_avail1 & SLOT_133MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900942 bus_speed = PCI_SPEED_133MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900943 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900944 bus_speed = PCI_SPEED_100MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900945 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900946 bus_speed = PCI_SPEED_66MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900947 else if (slot_avail2 & SLOT_66MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900948 bus_speed = PCI_SPEED_66MHz;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900949 else if (slot_avail1 & SLOT_33MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900950 bus_speed = PCI_SPEED_33MHz;
951 else
952 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 }
954
955 *value = bus_speed;
956 dbg("Max bus speed = %d\n", bus_speed);
957 DBG_LEAVE_ROUTINE
958 return retval;
959}
960
961static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
962{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900963 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900964 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900966 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
967 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900968 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 DBG_ENTER_ROUTINE
971
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900972 if ((pi == 1) && (speed_mode > 4)) {
973 *value = PCI_SPEED_UNKNOWN;
974 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900977 switch (speed_mode) {
978 case 0x0:
979 *value = PCI_SPEED_33MHz;
980 break;
981 case 0x1:
982 *value = PCI_SPEED_66MHz;
983 break;
984 case 0x2:
985 *value = PCI_SPEED_66MHz_PCIX;
986 break;
987 case 0x3:
988 *value = PCI_SPEED_100MHz_PCIX;
989 break;
990 case 0x4:
991 *value = PCI_SPEED_133MHz_PCIX;
992 break;
993 case 0x5:
994 *value = PCI_SPEED_66MHz_PCIX_ECC;
995 break;
996 case 0x6:
997 *value = PCI_SPEED_100MHz_PCIX_ECC;
998 break;
999 case 0x7:
1000 *value = PCI_SPEED_133MHz_PCIX_ECC;
1001 break;
1002 case 0x8:
1003 *value = PCI_SPEED_66MHz_PCIX_266;
1004 break;
1005 case 0x9:
1006 *value = PCI_SPEED_100MHz_PCIX_266;
1007 break;
1008 case 0xa:
1009 *value = PCI_SPEED_133MHz_PCIX_266;
1010 break;
1011 case 0xb:
1012 *value = PCI_SPEED_66MHz_PCIX_533;
1013 break;
1014 case 0xc:
1015 *value = PCI_SPEED_100MHz_PCIX_533;
1016 break;
1017 case 0xd:
1018 *value = PCI_SPEED_133MHz_PCIX_533;
1019 break;
1020 default:
1021 *value = PCI_SPEED_UNKNOWN;
1022 retval = -ENODEV;
1023 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 }
1025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 dbg("Current bus speed = %d\n", bus_speed);
1027 DBG_LEAVE_ROUTINE
1028 return retval;
1029}
1030
1031static struct hpc_ops shpchp_hpc_ops = {
1032 .power_on_slot = hpc_power_on_slot,
1033 .slot_enable = hpc_slot_enable,
1034 .slot_disable = hpc_slot_disable,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1036 .set_attention_status = hpc_set_attention_status,
1037 .get_power_status = hpc_get_power_status,
1038 .get_attention_status = hpc_get_attention_status,
1039 .get_latch_status = hpc_get_latch_status,
1040 .get_adapter_status = hpc_get_adapter_status,
1041
1042 .get_max_bus_speed = hpc_get_max_bus_speed,
1043 .get_cur_bus_speed = hpc_get_cur_bus_speed,
1044 .get_adapter_speed = hpc_get_adapter_speed,
1045 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
1046 .get_prog_int = hpc_get_prog_int,
1047
1048 .query_power_fault = hpc_query_power_fault,
1049 .green_led_on = hpc_set_green_led_on,
1050 .green_led_off = hpc_set_green_led_off,
1051 .green_led_blink = hpc_set_green_led_blink,
1052
1053 .release_ctlr = hpc_release_ctlr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054};
1055
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001056int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Amol Lad662a98f2006-10-05 12:07:32 +05301058 int rc = -1, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 u8 hp_slot;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001060 u32 shpc_base_offset;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001061 u32 tempdword, slot_reg, slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 u8 i;
1063
1064 DBG_ENTER_ROUTINE
1065
Kenji Kaneshige04559862005-11-24 11:36:59 +09001066 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1067
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001068 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1069 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001070 /* amd shpc driver doesn't use Base Offset; assume 0 */
1071 ctrl->mmio_base = pci_resource_start(pdev, 0);
1072 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001074 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1075 if (!ctrl->cap_offset) {
1076 err("%s : cap_offset == 0\n", __FUNCTION__);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001077 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001079 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1080
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001081 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001083 err("%s: cannot read base_offset\n", __FUNCTION__);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001084 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001087 rc = shpc_indirect_read(ctrl, 3, &tempdword);
Kenji Kaneshige04559862005-11-24 11:36:59 +09001088 if (rc) {
1089 err("%s: cannot read slot config\n", __FUNCTION__);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001090 goto abort;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001091 }
1092 num_slots = tempdword & SLOT_NUM;
1093 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
1094
1095 for (i = 0; i < 9 + num_slots; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001096 rc = shpc_indirect_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001098 err("%s: cannot read creg (index = %d)\n",
1099 __FUNCTION__, i);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001100 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001102 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1103 tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001105
1106 ctrl->mmio_base =
1107 pci_resource_start(pdev, 0) + shpc_base_offset;
1108 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
1110
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1112 pdev->subsystem_device);
1113
Amol Lad662a98f2006-10-05 12:07:32 +05301114 rc = pci_enable_device(pdev);
1115 if (rc) {
1116 err("%s: pci_enable_device failed\n", __FUNCTION__);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001117 goto abort;
Amol Lad662a98f2006-10-05 12:07:32 +05301118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Kenji Kaneshige04559862005-11-24 11:36:59 +09001120 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
Amol Lad662a98f2006-10-05 12:07:32 +05301122 rc = -1;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001123 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
1125
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001126 ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
1127 if (!ctrl->creg) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001128 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1129 ctrl->mmio_size, ctrl->mmio_base);
1130 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Amol Lad662a98f2006-10-05 12:07:32 +05301131 rc = -1;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001132 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001134 dbg("%s: ctrl->creg %p\n", __FUNCTION__, ctrl->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001136 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +09001137 mutex_init(&ctrl->cmd_lock);
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 /* Setup wait queue */
1140 init_waitqueue_head(&ctrl->queue);
1141
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001142 ctrl->hpc_ops = &shpchp_hpc_ops;
1143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 /* Return PCI Controller Info */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001145 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001146 ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1147 ctrl->num_slots = slot_config & SLOT_NUM;
1148 ctrl->first_slot = (slot_config & PSN) >> 16;
1149 ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001152 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001154 tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
1155 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
1156 tempdword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001157 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1158 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1160
1161 /* Mask the MRL sensor SERR Mask of individual slot in
1162 * Slot SERR-INT Mask & clear all the existing event if any
1163 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001164 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001165 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1167 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001168 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1169 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1170 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
1171 CON_PFAULT_SERR_MASK);
1172 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
1173 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
1175
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001176 if (shpchp_poll_mode) {
1177 /* Install interrupt polling timer. Start with 10 sec delay */
1178 init_timer(&ctrl->poll_timer);
1179 start_int_poll_timer(ctrl, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 } else {
1181 /* Installs the interrupt handler */
1182 rc = pci_enable_msi(pdev);
1183 if (rc) {
1184 info("Can't get msi for the hotplug controller\n");
1185 info("Use INTx for the hotplug controller\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001188 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
1189 MY_NAME, (void *)ctrl);
1190 dbg("%s: request_irq %d for hpc%d (returns %d)\n",
1191 __FUNCTION__, ctrl->pci_dev->irq,
1192 atomic_read(&shpchp_num_controllers), rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (rc) {
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001194 err("Can't get irq %d for the hotplug controller\n",
1195 ctrl->pci_dev->irq);
1196 goto abort_iounmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001199 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
1200 pdev->bus->number, PCI_SLOT(pdev->devfn),
1201 PCI_FUNC(pdev->devfn), pdev->irq);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -07001202 get_hp_hw_control_from_firmware(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001204 /*
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +09001205 * If this is the first controller to be initialized,
1206 * initialize the shpchpd work queue
1207 */
1208 if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
1209 shpchp_wq = create_singlethread_workqueue("shpchpd");
Amol Lad662a98f2006-10-05 12:07:32 +05301210 if (!shpchp_wq) {
1211 rc = -ENOMEM;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001212 goto abort_iounmap;
Amol Lad662a98f2006-10-05 12:07:32 +05301213 }
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +09001214 }
1215
1216 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001217 * Unmask all event interrupts of all slots
1218 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001219 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001220 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1222 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001223 slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1224 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1225 CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
1226 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 }
1228 if (!shpchp_poll_mode) {
1229 /* Unmask all general input interrupts and SERR */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001230 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001231 tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
1232 SERR_INTR_RSVDZ_MASK);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001233 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1234 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1236 }
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 DBG_LEAVE_ROUTINE
1239 return 0;
1240
1241 /* We end up here for the many possible ways to fail this API. */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001242abort_iounmap:
1243 iounmap(ctrl->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244abort:
1245 DBG_LEAVE_ROUTINE
Amol Lad662a98f2006-10-05 12:07:32 +05301246 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}