blob: 1d89916351ed06a190fe42797b57e6f72678caa9 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/* Slot Available Register I field definition */
39#define SLOT_33MHZ 0x0000001f
40#define SLOT_66MHZ_PCIX 0x00001f00
41#define SLOT_100MHZ_PCIX 0x001f0000
42#define SLOT_133MHZ_PCIX 0x1f000000
43
44/* Slot Available Register II field definition */
45#define SLOT_66MHZ 0x0000001f
46#define SLOT_66MHZ_PCIX_266 0x00000f00
47#define SLOT_100MHZ_PCIX_266 0x0000f000
48#define SLOT_133MHZ_PCIX_266 0x000f0000
49#define SLOT_66MHZ_PCIX_533 0x00f00000
50#define SLOT_100MHZ_PCIX_533 0x0f000000
51#define SLOT_133MHZ_PCIX_533 0xf0000000
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/* Slot Configuration */
54#define SLOT_NUM 0x0000001F
55#define FIRST_DEV_NUM 0x00001F00
56#define PSN 0x07FF0000
57#define UPDOWN 0x20000000
58#define MRLSENSOR 0x40000000
59#define ATTN_BUTTON 0x80000000
60
Kenji Kaneshige2b34da72006-05-02 11:09:42 +090061/*
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +090062 * Interrupt Locator Register definitions
63 */
64#define CMD_INTR_PENDING (1 << 0)
65#define SLOT_INTR_PENDING(i) (1 << (i + 1))
66
67/*
Kenji Kaneshigee7138722006-05-02 11:12:37 +090068 * Controller SERR-INT Register
69 */
70#define GLOBAL_INTR_MASK (1 << 0)
71#define GLOBAL_SERR_MASK (1 << 1)
72#define COMMAND_INTR_MASK (1 << 2)
73#define ARBITER_SERR_MASK (1 << 3)
74#define COMMAND_DETECTED (1 << 16)
75#define ARBITER_DETECTED (1 << 17)
76#define SERR_INTR_RSVDZ_MASK 0xfffc0000
77
78/*
Kenji Kaneshige2b34da72006-05-02 11:09:42 +090079 * Logical Slot Register definitions
80 */
81#define SLOT_REG(i) (SLOT1 + (4 * i))
82
Kenji Kaneshige58587592006-05-02 11:10:37 +090083#define SLOT_STATE_SHIFT (0)
84#define SLOT_STATE_MASK (3 << 0)
85#define SLOT_STATE_PWRONLY (1)
86#define SLOT_STATE_ENABLED (2)
87#define SLOT_STATE_DISABLED (3)
88#define PWR_LED_STATE_SHIFT (2)
89#define PWR_LED_STATE_MASK (3 << 2)
90#define ATN_LED_STATE_SHIFT (4)
91#define ATN_LED_STATE_MASK (3 << 4)
92#define ATN_LED_STATE_ON (1)
93#define ATN_LED_STATE_BLINK (2)
94#define ATN_LED_STATE_OFF (3)
95#define POWER_FAULT (1 << 6)
96#define ATN_BUTTON (1 << 7)
97#define MRL_SENSOR (1 << 8)
98#define MHZ66_CAP (1 << 9)
99#define PRSNT_SHIFT (10)
100#define PRSNT_MASK (3 << 10)
101#define PCIX_CAP_SHIFT (12)
102#define PCIX_CAP_MASK_PI1 (3 << 12)
103#define PCIX_CAP_MASK_PI2 (7 << 12)
104#define PRSNT_CHANGE_DETECTED (1 << 16)
105#define ISO_PFAULT_DETECTED (1 << 17)
106#define BUTTON_PRESS_DETECTED (1 << 18)
107#define MRL_CHANGE_DETECTED (1 << 19)
108#define CON_PFAULT_DETECTED (1 << 20)
109#define PRSNT_CHANGE_INTR_MASK (1 << 24)
110#define ISO_PFAULT_INTR_MASK (1 << 25)
111#define BUTTON_PRESS_INTR_MASK (1 << 26)
112#define MRL_CHANGE_INTR_MASK (1 << 27)
113#define CON_PFAULT_INTR_MASK (1 << 28)
114#define MRL_CHANGE_SERR_MASK (1 << 29)
115#define CON_PFAULT_SERR_MASK (1 << 30)
Dan Carpenter3b8fdb72010-05-26 12:46:39 +0200116#define SLOT_REG_RSVDZ_MASK ((1 << 15) | (7 << 21))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Kenji Kaneshige40853992006-05-12 11:11:48 +0900118/*
Bjorn Helgaasf7625982013-11-14 11:28:18 -0700119 * SHPC Command Code definitions
Kenji Kaneshige40853992006-05-12 11:11:48 +0900120 *
121 * Slot Operation 00h - 3Fh
122 * Set Bus Segment Speed/Mode A 40h - 47h
123 * Power-Only All Slots 48h
124 * Enable All Slots 49h
125 * Set Bus Segment Speed/Mode B (PI=2) 50h - 5Fh
126 * Reserved Command Codes 60h - BFh
127 * Vendor Specific Commands C0h - FFh
128 */
129#define SET_SLOT_PWR 0x01 /* Slot Operation */
130#define SET_SLOT_ENABLE 0x02
131#define SET_SLOT_DISABLE 0x03
132#define SET_PWR_ON 0x04
133#define SET_PWR_BLINK 0x08
134#define SET_PWR_OFF 0x0c
135#define SET_ATTN_ON 0x10
136#define SET_ATTN_BLINK 0x20
137#define SET_ATTN_OFF 0x30
138#define SETA_PCI_33MHZ 0x40 /* Set Bus Segment Speed/Mode A */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define SETA_PCI_66MHZ 0x41
140#define SETA_PCIX_66MHZ 0x42
141#define SETA_PCIX_100MHZ 0x43
142#define SETA_PCIX_133MHZ 0x44
Kenji Kaneshige40853992006-05-12 11:11:48 +0900143#define SETA_RESERVED1 0x45
144#define SETA_RESERVED2 0x46
145#define SETA_RESERVED3 0x47
146#define SET_PWR_ONLY_ALL 0x48 /* Power-Only All Slots */
147#define SET_ENABLE_ALL 0x49 /* Enable All Slots */
148#define SETB_PCI_33MHZ 0x50 /* Set Bus Segment Speed/Mode B */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define SETB_PCI_66MHZ 0x51
150#define SETB_PCIX_66MHZ_PM 0x52
151#define SETB_PCIX_100MHZ_PM 0x53
152#define SETB_PCIX_133MHZ_PM 0x54
153#define SETB_PCIX_66MHZ_EM 0x55
154#define SETB_PCIX_100MHZ_EM 0x56
155#define SETB_PCIX_133MHZ_EM 0x57
156#define SETB_PCIX_66MHZ_266 0x58
157#define SETB_PCIX_100MHZ_266 0x59
158#define SETB_PCIX_133MHZ_266 0x5a
159#define SETB_PCIX_66MHZ_533 0x5b
160#define SETB_PCIX_100MHZ_533 0x5c
161#define SETB_PCIX_133MHZ_533 0x5d
Kenji Kaneshige40853992006-05-12 11:11:48 +0900162#define SETB_RESERVED1 0x5e
163#define SETB_RESERVED2 0x5f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Kenji Kaneshige40853992006-05-12 11:11:48 +0900165/*
166 * SHPC controller command error code
167 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define SWITCH_OPEN 0x1
169#define INVALID_CMD 0x2
170#define INVALID_SPEED_MODE 0x4
171
Kenji Kaneshige40853992006-05-12 11:11:48 +0900172/*
173 * For accessing SHPC Working Register Set via PCI Configuration Space
174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#define DWORD_SELECT 0x2
176#define DWORD_DATA 0x4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/* Field Offset in Logical Slot Register - byte boundary */
179#define SLOT_EVENT_LATCH 0x2
180#define SLOT_SERR_INT_MASK 0x3
181
David Howells7d12e782006-10-05 14:55:46 +0100182static irqreturn_t shpc_isr(int irq, void *dev_id);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800183static void start_int_poll_timer(struct controller *ctrl, int sec);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900184static int hpc_check_cmd_status(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900186static inline u8 shpc_readb(struct controller *ctrl, int reg)
187{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800188 return readb(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900189}
190
191static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
192{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800193 writeb(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900194}
195
196static inline u16 shpc_readw(struct controller *ctrl, int reg)
197{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800198 return readw(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900199}
200
201static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
202{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800203 writew(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900204}
205
206static inline u32 shpc_readl(struct controller *ctrl, int reg)
207{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800208 return readl(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900209}
210
211static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
212{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800213 writel(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900214}
215
216static inline int shpc_indirect_read(struct controller *ctrl, int index,
217 u32 *value)
218{
219 int rc;
220 u32 cap_offset = ctrl->cap_offset;
221 struct pci_dev *pdev = ctrl->pci_dev;
222
223 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
224 if (rc)
225 return rc;
226 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
227}
228
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900229/*
230 * This is the interrupt polling timeout function.
231 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800232static void int_poll_timeout(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800234 struct controller *ctrl = (struct controller *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900236 /* Poll for interrupt events. regs == NULL => polling */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800237 shpc_isr(0, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800239 init_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (!shpchp_poll_time)
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900241 shpchp_poll_time = 2; /* default polling interval is 2 sec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800243 start_int_poll_timer(ctrl, shpchp_poll_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900246/*
247 * This function starts the interrupt polling timer.
248 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800249static void start_int_poll_timer(struct controller *ctrl, int sec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900251 /* Clamp to sane value */
252 if ((sec <= 0) || (sec > 60))
253 sec = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800255 ctrl->poll_timer.function = &int_poll_timeout;
256 ctrl->poll_timer.data = (unsigned long)ctrl;
257 ctrl->poll_timer.expires = jiffies + sec * HZ;
258 add_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700261static inline int is_ctrl_busy(struct controller *ctrl)
262{
263 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
264 return cmd_status & 0x1;
265}
266
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700267/*
268 * Returns 1 if SHPC finishes executing a command within 1 sec,
269 * otherwise returns 0.
270 */
271static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
272{
273 int i;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700274
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700275 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700276 return 1;
277
278 /* Check every 0.1 sec for a total of 1 sec */
279 for (i = 0; i < 10; i++) {
280 msleep(100);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700281 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700282 return 1;
283 }
284
285 return 0;
286}
287
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900288static inline int shpc_wait_cmd(struct controller *ctrl)
289{
290 int retval = 0;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700291 unsigned long timeout = msecs_to_jiffies(1000);
292 int rc;
293
294 if (shpchp_poll_mode)
295 rc = shpc_poll_ctrl_busy(ctrl);
296 else
297 rc = wait_event_interruptible_timeout(ctrl->queue,
Kenji Kaneshige6aa562c2006-09-28 15:51:36 -0700298 !is_ctrl_busy(ctrl), timeout);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700299 if (!rc && is_ctrl_busy(ctrl)) {
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900300 retval = -EIO;
Taku Izumif98ca312008-10-23 11:52:12 +0900301 ctrl_err(ctrl, "Command not completed in 1000 msec\n");
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900302 } else if (rc < 0) {
303 retval = -EINTR;
Taku Izumif98ca312008-10-23 11:52:12 +0900304 ctrl_info(ctrl, "Command was interrupted by a signal\n");
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900305 }
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900306
307 return retval;
308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
311{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900312 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 u16 cmd_status;
314 int retval = 0;
315 u16 temp_word;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900317 mutex_lock(&slot->ctrl->cmd_lock);
318
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700319 if (!shpc_poll_ctrl_busy(ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* After 1 sec and and the controller is still busy */
Taku Izumibe7bce22008-10-23 11:54:39 +0900321 ctrl_err(ctrl, "Controller is still busy after 1 sec\n");
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900322 retval = -EBUSY;
323 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325
326 ++t_slot;
327 temp_word = (t_slot << 8) | (cmd & 0xFF);
Taku Izumif98ca312008-10-23 11:52:12 +0900328 ctrl_dbg(ctrl, "%s: t_slot %x cmd %x\n", __func__, t_slot, cmd);
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* To make sure the Controller Busy bit is 0 before we send out the
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800331 * command.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900333 shpc_writew(ctrl, CMD, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900335 /*
336 * Wait for command completion.
337 */
338 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900339 if (retval)
340 goto out;
341
342 cmd_status = hpc_check_cmd_status(slot->ctrl);
343 if (cmd_status) {
Ryan Desfosses227f0642014-04-18 20:13:50 -0400344 ctrl_err(ctrl, "Failed to issued command 0x%x (error code = %d)\n",
Taku Izumibe7bce22008-10-23 11:54:39 +0900345 cmd, cmd_status);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900346 retval = -EIO;
347 }
348 out:
349 mutex_unlock(&slot->ctrl->cmd_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return retval;
351}
352
353static int hpc_check_cmd_status(struct controller *ctrl)
354{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 int retval = 0;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800356 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 switch (cmd_status >> 1) {
359 case 0:
360 retval = 0;
361 break;
362 case 1:
363 retval = SWITCH_OPEN;
Taku Izumibe7bce22008-10-23 11:54:39 +0900364 ctrl_err(ctrl, "Switch opened!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 break;
366 case 2:
367 retval = INVALID_CMD;
Taku Izumibe7bce22008-10-23 11:54:39 +0900368 ctrl_err(ctrl, "Invalid HPC command!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 break;
370 case 4:
371 retval = INVALID_SPEED_MODE;
Taku Izumibe7bce22008-10-23 11:54:39 +0900372 ctrl_err(ctrl, "Invalid bus speed/mode!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 break;
374 default:
375 retval = cmd_status;
376 }
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return retval;
379}
380
381
382static int hpc_get_attention_status(struct slot *slot, u8 *status)
383{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900384 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800385 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
386 u8 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Kenji Kaneshige58587592006-05-02 11:10:37 +0900388 switch (state) {
389 case ATN_LED_STATE_ON:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 *status = 1; /* On */
391 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900392 case ATN_LED_STATE_BLINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 *status = 2; /* Blink */
394 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900395 case ATN_LED_STATE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 *status = 0; /* Off */
397 break;
398 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900399 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 break;
401 }
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return 0;
404}
405
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400406static int hpc_get_power_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900408 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800409 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
410 u8 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Kenji Kaneshige58587592006-05-02 11:10:37 +0900412 switch (state) {
413 case SLOT_STATE_PWRONLY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 *status = 2; /* Powered only */
415 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900416 case SLOT_STATE_ENABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 *status = 1; /* Enabled */
418 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900419 case SLOT_STATE_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 *status = 0; /* Disabled */
421 break;
422 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900423 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 break;
425 }
426
Kenji Kaneshige58587592006-05-02 11:10:37 +0900427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
430
431static int hpc_get_latch_status(struct slot *slot, u8 *status)
432{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900433 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800434 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Kenji Kaneshige58587592006-05-02 11:10:37 +0900436 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 return 0;
439}
440
441static int hpc_get_adapter_status(struct slot *slot, u8 *status)
442{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900443 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800444 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
445 u8 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Kenji Kaneshige58587592006-05-02 11:10:37 +0900447 *status = (state != 0x3) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return 0;
450}
451
452static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
453{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900454 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900456 *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return 0;
459}
460
461static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
462{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900464 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900465 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900466 u8 m66_cap = !!(slot_reg & MHZ66_CAP);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900467 u8 pi, pcix_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900469 if ((retval = hpc_get_prog_int(slot, &pi)))
470 return retval;
471
472 switch (pi) {
473 case 1:
474 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
475 break;
476 case 2:
477 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
478 break;
479 default:
480 return -ENODEV;
481 }
482
Taku Izumif98ca312008-10-23 11:52:12 +0900483 ctrl_dbg(ctrl, "%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
484 __func__, slot_reg, pcix_cap, m66_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900486 switch (pcix_cap) {
487 case 0x0:
488 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
489 break;
490 case 0x1:
491 *value = PCI_SPEED_66MHz_PCIX;
492 break;
493 case 0x3:
494 *value = PCI_SPEED_133MHz_PCIX;
495 break;
496 case 0x4:
497 *value = PCI_SPEED_133MHz_PCIX_266;
498 break;
499 case 0x5:
500 *value = PCI_SPEED_133MHz_PCIX_533;
501 break;
502 case 0x2:
503 default:
504 *value = PCI_SPEED_UNKNOWN;
505 retval = -ENODEV;
506 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508
Taku Izumif98ca312008-10-23 11:52:12 +0900509 ctrl_dbg(ctrl, "Adapter speed = %d\n", *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 return retval;
511}
512
513static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
514{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 int retval = 0;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800516 struct controller *ctrl = slot->ctrl;
517 u16 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
518 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 if (pi == 2) {
Kenji Kaneshige87d6c552005-11-24 11:35:05 +0900521 *mode = (sec_bus_status & 0x0100) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 } else {
523 retval = -1;
524 }
525
Taku Izumif98ca312008-10-23 11:52:12 +0900526 ctrl_dbg(ctrl, "Mode 1 ECC cap = %d\n", *mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return retval;
528}
529
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400530static int hpc_query_power_fault(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900532 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800533 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* Note: Logic 0 => fault */
Kenji Kaneshige58587592006-05-02 11:10:37 +0900536 return !(slot_reg & POWER_FAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
539static int hpc_set_attention_status(struct slot *slot, u8 value)
540{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 u8 slot_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 switch (value) {
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800544 case 0 :
Kenji Kaneshige40853992006-05-12 11:11:48 +0900545 slot_cmd = SET_ATTN_OFF; /* OFF */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 break;
547 case 1:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900548 slot_cmd = SET_ATTN_ON; /* ON */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 break;
550 case 2:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900551 slot_cmd = SET_ATTN_BLINK; /* BLINK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 break;
553 default:
554 return -1;
555 }
556
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900557 return shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
560
561static void hpc_set_green_led_on(struct slot *slot)
562{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900563 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566static void hpc_set_green_led_off(struct slot *slot)
567{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900568 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
571static void hpc_set_green_led_blink(struct slot *slot)
572{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900573 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576static void hpc_release_ctlr(struct controller *ctrl)
577{
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800578 int i;
Kenji Kaneshiged49f2c492006-05-03 23:34:17 +0900579 u32 slot_reg, serr_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800581 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900582 * Mask event interrupts and SERRs of all slots
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800583 */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900584 for (i = 0; i < ctrl->num_slots; i++) {
585 slot_reg = shpc_readl(ctrl, SLOT_REG(i));
586 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
587 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
588 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
589 CON_PFAULT_SERR_MASK);
590 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
591 shpc_writel(ctrl, SLOT_REG(i), slot_reg);
592 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800593
594 cleanup_slots(ctrl);
595
Kenji Kaneshiged49f2c492006-05-03 23:34:17 +0900596 /*
Joe Perches36098012007-12-17 11:40:11 -0800597 * Mask SERR and System Interrupt generation
Kenji Kaneshiged49f2c492006-05-03 23:34:17 +0900598 */
599 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
600 serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
601 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
602 serr_int &= ~SERR_INTR_RSVDZ_MASK;
603 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
604
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800605 if (shpchp_poll_mode)
606 del_timer(&ctrl->poll_timer);
607 else {
608 free_irq(ctrl->pci_dev->irq, ctrl);
609 pci_disable_msi(ctrl->pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800611
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800612 iounmap(ctrl->creg);
613 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614}
615
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400616static int hpc_power_on_slot(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900618 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Kenji Kaneshige40853992006-05-12 11:11:48 +0900620 retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800621 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900622 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800624 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
626
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400627static int hpc_slot_enable(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900629 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Kenji Kaneshige40853992006-05-12 11:11:48 +0900631 /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
632 retval = shpc_write_cmd(slot, slot->hp_slot,
633 SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800634 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900635 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800637 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400640static int hpc_slot_disable(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900642 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Kenji Kaneshige40853992006-05-12 11:11:48 +0900644 /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */
645 retval = shpc_write_cmd(slot, slot->hp_slot,
646 SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800647 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900648 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800650 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
Matthew Wilcox3749c512009-12-13 08:11:32 -0500653static int shpc_get_cur_bus_speed(struct controller *ctrl)
654{
655 int retval = 0;
656 struct pci_bus *bus = ctrl->pci_dev->subordinate;
657 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
658 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
659 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
660 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
661
662 if ((pi == 1) && (speed_mode > 4)) {
663 retval = -ENODEV;
664 goto out;
665 }
666
667 switch (speed_mode) {
668 case 0x0:
669 bus_speed = PCI_SPEED_33MHz;
670 break;
671 case 0x1:
672 bus_speed = PCI_SPEED_66MHz;
673 break;
674 case 0x2:
675 bus_speed = PCI_SPEED_66MHz_PCIX;
676 break;
677 case 0x3:
678 bus_speed = PCI_SPEED_100MHz_PCIX;
679 break;
680 case 0x4:
681 bus_speed = PCI_SPEED_133MHz_PCIX;
682 break;
683 case 0x5:
684 bus_speed = PCI_SPEED_66MHz_PCIX_ECC;
685 break;
686 case 0x6:
687 bus_speed = PCI_SPEED_100MHz_PCIX_ECC;
688 break;
689 case 0x7:
690 bus_speed = PCI_SPEED_133MHz_PCIX_ECC;
691 break;
692 case 0x8:
693 bus_speed = PCI_SPEED_66MHz_PCIX_266;
694 break;
695 case 0x9:
696 bus_speed = PCI_SPEED_100MHz_PCIX_266;
697 break;
698 case 0xa:
699 bus_speed = PCI_SPEED_133MHz_PCIX_266;
700 break;
701 case 0xb:
702 bus_speed = PCI_SPEED_66MHz_PCIX_533;
703 break;
704 case 0xc:
705 bus_speed = PCI_SPEED_100MHz_PCIX_533;
706 break;
707 case 0xd:
708 bus_speed = PCI_SPEED_133MHz_PCIX_533;
709 break;
710 default:
711 retval = -ENODEV;
712 break;
713 }
714
715 out:
716 bus->cur_bus_speed = bus_speed;
717 dbg("Current bus speed = %d\n", bus_speed);
718 return retval;
719}
720
721
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400722static int hpc_set_bus_speed_mode(struct slot *slot, enum pci_bus_speed value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900724 int retval;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900725 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900726 u8 pi, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900728 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900729 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
730 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900732 switch (value) {
733 case PCI_SPEED_33MHz:
734 cmd = SETA_PCI_33MHZ;
735 break;
736 case PCI_SPEED_66MHz:
737 cmd = SETA_PCI_66MHZ;
738 break;
739 case PCI_SPEED_66MHz_PCIX:
740 cmd = SETA_PCIX_66MHZ;
741 break;
742 case PCI_SPEED_100MHz_PCIX:
743 cmd = SETA_PCIX_100MHZ;
744 break;
745 case PCI_SPEED_133MHz_PCIX:
746 cmd = SETA_PCIX_133MHZ;
747 break;
748 case PCI_SPEED_66MHz_PCIX_ECC:
749 cmd = SETB_PCIX_66MHZ_EM;
750 break;
751 case PCI_SPEED_100MHz_PCIX_ECC:
752 cmd = SETB_PCIX_100MHZ_EM;
753 break;
754 case PCI_SPEED_133MHz_PCIX_ECC:
755 cmd = SETB_PCIX_133MHZ_EM;
756 break;
757 case PCI_SPEED_66MHz_PCIX_266:
758 cmd = SETB_PCIX_66MHZ_266;
759 break;
760 case PCI_SPEED_100MHz_PCIX_266:
761 cmd = SETB_PCIX_100MHZ_266;
762 break;
763 case PCI_SPEED_133MHz_PCIX_266:
764 cmd = SETB_PCIX_133MHZ_266;
765 break;
766 case PCI_SPEED_66MHz_PCIX_533:
767 cmd = SETB_PCIX_66MHZ_533;
768 break;
769 case PCI_SPEED_100MHz_PCIX_533:
770 cmd = SETB_PCIX_100MHZ_533;
771 break;
772 case PCI_SPEED_133MHz_PCIX_533:
773 cmd = SETB_PCIX_133MHZ_533;
774 break;
775 default:
776 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900778
779 retval = shpc_write_cmd(slot, 0, cmd);
780 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900781 ctrl_err(ctrl, "%s: Write command failed!\n", __func__);
Matthew Wilcox3749c512009-12-13 08:11:32 -0500782 else
783 shpc_get_cur_bus_speed(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return retval;
786}
787
David Howells7d12e782006-10-05 14:55:46 +0100788static irqreturn_t shpc_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900790 struct controller *ctrl = (struct controller *)dev_id;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900791 u32 serr_int, slot_reg, intr_loc, intr_loc2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 int hp_slot;
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 /* Check to see if it was our interrupt */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900795 intr_loc = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 if (!intr_loc)
797 return IRQ_NONE;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900798
Taku Izumif98ca312008-10-23 11:52:12 +0900799 ctrl_dbg(ctrl, "%s: intr_loc = %x\n", __func__, intr_loc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Quentin Lambert382a9c92014-09-07 20:02:04 +0200801 if (!shpchp_poll_mode) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900802 /*
803 * Mask Global Interrupt Mask - see implementation
804 * note on p. 139 of SHPC spec rev 1.0
805 */
806 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
807 serr_int |= GLOBAL_INTR_MASK;
808 serr_int &= ~SERR_INTR_RSVDZ_MASK;
809 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900811 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Taku Izumif98ca312008-10-23 11:52:12 +0900812 ctrl_dbg(ctrl, "%s: intr_loc2 = %x\n", __func__, intr_loc2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900815 if (intr_loc & CMD_INTR_PENDING) {
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800816 /*
817 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +0900818 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 * Detect bit in Controller SERR-INT register
820 */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900821 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
822 serr_int &= ~SERR_INTR_RSVDZ_MASK;
823 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 wake_up_interruptible(&ctrl->queue);
826 }
827
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900828 if (!(intr_loc & ~CMD_INTR_PENDING))
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900829 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800831 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900832 /* To find out which slot has interrupt pending */
833 if (!(intr_loc & SLOT_INTR_PENDING(hp_slot)))
834 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900836 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Taku Izumibe7bce22008-10-23 11:54:39 +0900837 ctrl_dbg(ctrl, "Slot %x with intr, slot register = %x\n",
838 hp_slot, slot_reg);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900839
840 if (slot_reg & MRL_CHANGE_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800841 shpchp_handle_switch_change(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900842
843 if (slot_reg & BUTTON_PRESS_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800844 shpchp_handle_attention_button(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900845
846 if (slot_reg & PRSNT_CHANGE_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800847 shpchp_handle_presence_change(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900848
849 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800850 shpchp_handle_power_fault(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900851
852 /* Clear all slot events */
853 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
854 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900856 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (!shpchp_poll_mode) {
858 /* Unmask Global Interrupt Mask */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900859 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
860 serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
861 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return IRQ_HANDLED;
865}
866
Matthew Wilcox3749c512009-12-13 08:11:32 -0500867static int shpc_get_max_bus_speed(struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900869 int retval = 0;
Matthew Wilcox3749c512009-12-13 08:11:32 -0500870 struct pci_bus *bus = ctrl->pci_dev->subordinate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900872 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
873 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
874 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900877 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900878 bus_speed = PCI_SPEED_133MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900879 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900880 bus_speed = PCI_SPEED_100MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900881 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900882 bus_speed = PCI_SPEED_66MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900883 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900884 bus_speed = PCI_SPEED_133MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900885 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900886 bus_speed = PCI_SPEED_100MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900887 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900888 bus_speed = PCI_SPEED_66MHz_PCIX_266;
889 }
890
891 if (bus_speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900892 if (slot_avail1 & SLOT_133MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900893 bus_speed = PCI_SPEED_133MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900894 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900895 bus_speed = PCI_SPEED_100MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900896 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900897 bus_speed = PCI_SPEED_66MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900898 else if (slot_avail2 & SLOT_66MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900899 bus_speed = PCI_SPEED_66MHz;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900900 else if (slot_avail1 & SLOT_33MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900901 bus_speed = PCI_SPEED_33MHz;
902 else
903 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 }
905
Matthew Wilcox3749c512009-12-13 08:11:32 -0500906 bus->max_bus_speed = bus_speed;
Taku Izumif98ca312008-10-23 11:52:12 +0900907 ctrl_dbg(ctrl, "Max bus speed = %d\n", bus_speed);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return retval;
910}
911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912static struct hpc_ops shpchp_hpc_ops = {
913 .power_on_slot = hpc_power_on_slot,
914 .slot_enable = hpc_slot_enable,
915 .slot_disable = hpc_slot_disable,
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800916 .set_bus_speed_mode = hpc_set_bus_speed_mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 .set_attention_status = hpc_set_attention_status,
918 .get_power_status = hpc_get_power_status,
919 .get_attention_status = hpc_get_attention_status,
920 .get_latch_status = hpc_get_latch_status,
921 .get_adapter_status = hpc_get_adapter_status,
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 .get_adapter_speed = hpc_get_adapter_speed,
924 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
925 .get_prog_int = hpc_get_prog_int,
926
927 .query_power_fault = hpc_query_power_fault,
928 .green_led_on = hpc_set_green_led_on,
929 .green_led_off = hpc_set_green_led_off,
930 .green_led_blink = hpc_set_green_led_blink,
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 .release_ctlr = hpc_release_ctlr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933};
934
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800935int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Amol Lad662a98f2006-10-05 12:07:32 +0530937 int rc = -1, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 u8 hp_slot;
Kenji Kaneshige04559862005-11-24 11:36:59 +0900939 u32 shpc_base_offset;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900940 u32 tempdword, slot_reg, slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 u8 i;
942
Kenji Kaneshige04559862005-11-24 11:36:59 +0900943 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
Taku Izumibe7bce22008-10-23 11:54:39 +0900944 ctrl_dbg(ctrl, "Hotplug Controller:\n");
Kenji Kaneshige04559862005-11-24 11:36:59 +0900945
Bjorn Helgaas4cac2eb2011-08-23 10:16:43 -0600946 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
947 pdev->device == PCI_DEVICE_ID_AMD_GOLAM_7450) {
Kenji Kaneshige04559862005-11-24 11:36:59 +0900948 /* amd shpc driver doesn't use Base Offset; assume 0 */
949 ctrl->mmio_base = pci_resource_start(pdev, 0);
950 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +0900952 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
953 if (!ctrl->cap_offset) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900954 ctrl_err(ctrl, "Cannot find PCI capability\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800955 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
Taku Izumibe7bce22008-10-23 11:54:39 +0900957 ctrl_dbg(ctrl, " cap_offset = %x\n", ctrl->cap_offset);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900958
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900959 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (rc) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900961 ctrl_err(ctrl, "Cannot read base_offset\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800962 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
964
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900965 rc = shpc_indirect_read(ctrl, 3, &tempdword);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900966 if (rc) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900967 ctrl_err(ctrl, "Cannot read slot config\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800968 goto abort;
Kenji Kaneshige04559862005-11-24 11:36:59 +0900969 }
970 num_slots = tempdword & SLOT_NUM;
Taku Izumibe7bce22008-10-23 11:54:39 +0900971 ctrl_dbg(ctrl, " num_slots (indirect) %x\n", num_slots);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900972
973 for (i = 0; i < 9 + num_slots; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900974 rc = shpc_indirect_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (rc) {
Ryan Desfosses227f0642014-04-18 20:13:50 -0400976 ctrl_err(ctrl, "Cannot read creg (index = %d)\n",
977 i);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800978 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
Taku Izumibe7bce22008-10-23 11:54:39 +0900980 ctrl_dbg(ctrl, " offset %d: value %x\n", i, tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
Kenji Kaneshige04559862005-11-24 11:36:59 +0900982
983 ctrl->mmio_base =
984 pci_resource_start(pdev, 0) + shpc_base_offset;
985 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987
Taku Izumif98ca312008-10-23 11:52:12 +0900988 ctrl_info(ctrl, "HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
989 pdev->vendor, pdev->device, pdev->subsystem_vendor,
990 pdev->subsystem_device);
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800991
Amol Lad662a98f2006-10-05 12:07:32 +0530992 rc = pci_enable_device(pdev);
993 if (rc) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900994 ctrl_err(ctrl, "pci_enable_device failed\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800995 goto abort;
Amol Lad662a98f2006-10-05 12:07:32 +0530996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Kenji Kaneshige04559862005-11-24 11:36:59 +0900998 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900999 ctrl_err(ctrl, "Cannot reserve MMIO region\n");
Amol Lad662a98f2006-10-05 12:07:32 +05301000 rc = -1;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001001 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 }
1003
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001004 ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
1005 if (!ctrl->creg) {
Taku Izumibe7bce22008-10-23 11:54:39 +09001006 ctrl_err(ctrl, "Cannot remap MMIO region %lx @ %lx\n",
1007 ctrl->mmio_size, ctrl->mmio_base);
Kenji Kaneshige04559862005-11-24 11:36:59 +09001008 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Amol Lad662a98f2006-10-05 12:07:32 +05301009 rc = -1;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001010 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
Taku Izumibe7bce22008-10-23 11:54:39 +09001012 ctrl_dbg(ctrl, "ctrl->creg %p\n", ctrl->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001014 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +09001015 mutex_init(&ctrl->cmd_lock);
1016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 /* Setup wait queue */
1018 init_waitqueue_head(&ctrl->queue);
1019
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001020 ctrl->hpc_ops = &shpchp_hpc_ops;
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 /* Return PCI Controller Info */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001023 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001024 ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1025 ctrl->num_slots = slot_config & SLOT_NUM;
1026 ctrl->first_slot = (slot_config & PSN) >> 16;
1027 ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001030 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Taku Izumibe7bce22008-10-23 11:54:39 +09001031 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001032 tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
1033 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
1034 tempdword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001035 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1036 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Taku Izumibe7bce22008-10-23 11:54:39 +09001037 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 /* Mask the MRL sensor SERR Mask of individual slot in
1040 * Slot SERR-INT Mask & clear all the existing event if any
1041 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001042 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001043 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Taku Izumibe7bce22008-10-23 11:54:39 +09001044 ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n",
1045 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001046 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1047 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1048 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
1049 CON_PFAULT_SERR_MASK);
1050 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
1051 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
Kenji Kaneshige9f593e32007-01-09 13:03:10 -08001053
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001054 if (shpchp_poll_mode) {
1055 /* Install interrupt polling timer. Start with 10 sec delay */
1056 init_timer(&ctrl->poll_timer);
1057 start_int_poll_timer(ctrl, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 } else {
1059 /* Installs the interrupt handler */
1060 rc = pci_enable_msi(pdev);
1061 if (rc) {
Ryan Desfosses227f0642014-04-18 20:13:50 -04001062 ctrl_info(ctrl, "Can't get msi for the hotplug controller\n");
1063 ctrl_info(ctrl, "Use INTx for the hotplug controller\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001064 }
Kenji Kaneshige9f593e32007-01-09 13:03:10 -08001065
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001066 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
1067 MY_NAME, (void *)ctrl);
Tejun Heoe24dcbe2010-10-18 08:33:02 +02001068 ctrl_dbg(ctrl, "request_irq %d (returns %d)\n",
1069 ctrl->pci_dev->irq, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (rc) {
Ryan Desfosses227f0642014-04-18 20:13:50 -04001071 ctrl_err(ctrl, "Can't get irq %d for the hotplug controller\n",
1072 ctrl->pci_dev->irq);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001073 goto abort_iounmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
Taku Izumibe7bce22008-10-23 11:54:39 +09001076 ctrl_dbg(ctrl, "HPC at %s irq=%x\n", pci_name(pdev), pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Matthew Wilcox3749c512009-12-13 08:11:32 -05001078 shpc_get_max_bus_speed(ctrl);
1079 shpc_get_cur_bus_speed(ctrl);
1080
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001081 /*
1082 * Unmask all event interrupts of all slots
1083 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001084 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001085 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Taku Izumibe7bce22008-10-23 11:54:39 +09001086 ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n",
1087 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001088 slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1089 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1090 CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
1091 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 }
1093 if (!shpchp_poll_mode) {
1094 /* Unmask all general input interrupts and SERR */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001095 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001096 tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
1097 SERR_INTR_RSVDZ_MASK);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001098 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1099 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Taku Izumibe7bce22008-10-23 11:54:39 +09001100 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 }
1102
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 return 0;
1104
1105 /* We end up here for the many possible ways to fail this API. */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001106abort_iounmap:
1107 iounmap(ctrl->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108abort:
Amol Lad662a98f2006-10-05 12:07:32 +05301109 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}