blob: 012b9e3fe5b0e291832c3d8fec75b52789264b4b [file] [log] [blame]
Bjorn Helgaas736759e2018-01-26 14:22:04 -06001// SPDX-License-Identifier: GPL-2.0+
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Standard PCI Hot Plug Driver
4 *
5 * Copyright (C) 1995,2001 Compaq Computer Corporation
6 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
7 * Copyright (C) 2001 IBM Corp.
8 * Copyright (C) 2003-2004 Intel Corporation
9 *
10 * All rights reserved.
11 *
Kristen Accardi8cf4c192005-08-16 15:16:10 -070012 * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
14 */
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/pci.h>
Andrew Mortond4d28dd2005-11-13 16:06:40 -080020#include <linux/interrupt.h>
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "shpchp.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/* Slot Available Register I field definition */
25#define SLOT_33MHZ 0x0000001f
26#define SLOT_66MHZ_PCIX 0x00001f00
27#define SLOT_100MHZ_PCIX 0x001f0000
28#define SLOT_133MHZ_PCIX 0x1f000000
29
30/* Slot Available Register II field definition */
31#define SLOT_66MHZ 0x0000001f
32#define SLOT_66MHZ_PCIX_266 0x00000f00
33#define SLOT_100MHZ_PCIX_266 0x0000f000
34#define SLOT_133MHZ_PCIX_266 0x000f0000
35#define SLOT_66MHZ_PCIX_533 0x00f00000
36#define SLOT_100MHZ_PCIX_533 0x0f000000
37#define SLOT_133MHZ_PCIX_533 0xf0000000
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/* Slot Configuration */
40#define SLOT_NUM 0x0000001F
41#define FIRST_DEV_NUM 0x00001F00
42#define PSN 0x07FF0000
43#define UPDOWN 0x20000000
44#define MRLSENSOR 0x40000000
45#define ATTN_BUTTON 0x80000000
46
Kenji Kaneshige2b34da72006-05-02 11:09:42 +090047/*
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +090048 * Interrupt Locator Register definitions
49 */
50#define CMD_INTR_PENDING (1 << 0)
51#define SLOT_INTR_PENDING(i) (1 << (i + 1))
52
53/*
Kenji Kaneshigee7138722006-05-02 11:12:37 +090054 * Controller SERR-INT Register
55 */
56#define GLOBAL_INTR_MASK (1 << 0)
57#define GLOBAL_SERR_MASK (1 << 1)
58#define COMMAND_INTR_MASK (1 << 2)
59#define ARBITER_SERR_MASK (1 << 3)
60#define COMMAND_DETECTED (1 << 16)
61#define ARBITER_DETECTED (1 << 17)
62#define SERR_INTR_RSVDZ_MASK 0xfffc0000
63
64/*
Kenji Kaneshige2b34da72006-05-02 11:09:42 +090065 * Logical Slot Register definitions
66 */
67#define SLOT_REG(i) (SLOT1 + (4 * i))
68
Kenji Kaneshige58587592006-05-02 11:10:37 +090069#define SLOT_STATE_SHIFT (0)
70#define SLOT_STATE_MASK (3 << 0)
71#define SLOT_STATE_PWRONLY (1)
72#define SLOT_STATE_ENABLED (2)
73#define SLOT_STATE_DISABLED (3)
74#define PWR_LED_STATE_SHIFT (2)
75#define PWR_LED_STATE_MASK (3 << 2)
76#define ATN_LED_STATE_SHIFT (4)
77#define ATN_LED_STATE_MASK (3 << 4)
78#define ATN_LED_STATE_ON (1)
79#define ATN_LED_STATE_BLINK (2)
80#define ATN_LED_STATE_OFF (3)
81#define POWER_FAULT (1 << 6)
82#define ATN_BUTTON (1 << 7)
83#define MRL_SENSOR (1 << 8)
84#define MHZ66_CAP (1 << 9)
85#define PRSNT_SHIFT (10)
86#define PRSNT_MASK (3 << 10)
87#define PCIX_CAP_SHIFT (12)
88#define PCIX_CAP_MASK_PI1 (3 << 12)
89#define PCIX_CAP_MASK_PI2 (7 << 12)
90#define PRSNT_CHANGE_DETECTED (1 << 16)
91#define ISO_PFAULT_DETECTED (1 << 17)
92#define BUTTON_PRESS_DETECTED (1 << 18)
93#define MRL_CHANGE_DETECTED (1 << 19)
94#define CON_PFAULT_DETECTED (1 << 20)
95#define PRSNT_CHANGE_INTR_MASK (1 << 24)
96#define ISO_PFAULT_INTR_MASK (1 << 25)
97#define BUTTON_PRESS_INTR_MASK (1 << 26)
98#define MRL_CHANGE_INTR_MASK (1 << 27)
99#define CON_PFAULT_INTR_MASK (1 << 28)
100#define MRL_CHANGE_SERR_MASK (1 << 29)
101#define CON_PFAULT_SERR_MASK (1 << 30)
Dan Carpenter3b8fdb72010-05-26 12:46:39 +0200102#define SLOT_REG_RSVDZ_MASK ((1 << 15) | (7 << 21))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Kenji Kaneshige40853992006-05-12 11:11:48 +0900104/*
Bjorn Helgaasf7625982013-11-14 11:28:18 -0700105 * SHPC Command Code definitions
Kenji Kaneshige40853992006-05-12 11:11:48 +0900106 *
107 * Slot Operation 00h - 3Fh
108 * Set Bus Segment Speed/Mode A 40h - 47h
109 * Power-Only All Slots 48h
110 * Enable All Slots 49h
111 * Set Bus Segment Speed/Mode B (PI=2) 50h - 5Fh
112 * Reserved Command Codes 60h - BFh
113 * Vendor Specific Commands C0h - FFh
114 */
115#define SET_SLOT_PWR 0x01 /* Slot Operation */
116#define SET_SLOT_ENABLE 0x02
117#define SET_SLOT_DISABLE 0x03
118#define SET_PWR_ON 0x04
119#define SET_PWR_BLINK 0x08
120#define SET_PWR_OFF 0x0c
121#define SET_ATTN_ON 0x10
122#define SET_ATTN_BLINK 0x20
123#define SET_ATTN_OFF 0x30
124#define SETA_PCI_33MHZ 0x40 /* Set Bus Segment Speed/Mode A */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define SETA_PCI_66MHZ 0x41
126#define SETA_PCIX_66MHZ 0x42
127#define SETA_PCIX_100MHZ 0x43
128#define SETA_PCIX_133MHZ 0x44
Kenji Kaneshige40853992006-05-12 11:11:48 +0900129#define SETA_RESERVED1 0x45
130#define SETA_RESERVED2 0x46
131#define SETA_RESERVED3 0x47
132#define SET_PWR_ONLY_ALL 0x48 /* Power-Only All Slots */
133#define SET_ENABLE_ALL 0x49 /* Enable All Slots */
134#define SETB_PCI_33MHZ 0x50 /* Set Bus Segment Speed/Mode B */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define SETB_PCI_66MHZ 0x51
136#define SETB_PCIX_66MHZ_PM 0x52
137#define SETB_PCIX_100MHZ_PM 0x53
138#define SETB_PCIX_133MHZ_PM 0x54
139#define SETB_PCIX_66MHZ_EM 0x55
140#define SETB_PCIX_100MHZ_EM 0x56
141#define SETB_PCIX_133MHZ_EM 0x57
142#define SETB_PCIX_66MHZ_266 0x58
143#define SETB_PCIX_100MHZ_266 0x59
144#define SETB_PCIX_133MHZ_266 0x5a
145#define SETB_PCIX_66MHZ_533 0x5b
146#define SETB_PCIX_100MHZ_533 0x5c
147#define SETB_PCIX_133MHZ_533 0x5d
Kenji Kaneshige40853992006-05-12 11:11:48 +0900148#define SETB_RESERVED1 0x5e
149#define SETB_RESERVED2 0x5f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Kenji Kaneshige40853992006-05-12 11:11:48 +0900151/*
152 * SHPC controller command error code
153 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#define SWITCH_OPEN 0x1
155#define INVALID_CMD 0x2
156#define INVALID_SPEED_MODE 0x4
157
Kenji Kaneshige40853992006-05-12 11:11:48 +0900158/*
159 * For accessing SHPC Working Register Set via PCI Configuration Space
160 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#define DWORD_SELECT 0x2
162#define DWORD_DATA 0x4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164/* Field Offset in Logical Slot Register - byte boundary */
165#define SLOT_EVENT_LATCH 0x2
166#define SLOT_SERR_INT_MASK 0x3
167
David Howells7d12e782006-10-05 14:55:46 +0100168static irqreturn_t shpc_isr(int irq, void *dev_id);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800169static void start_int_poll_timer(struct controller *ctrl, int sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900171static inline u8 shpc_readb(struct controller *ctrl, int reg)
172{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800173 return readb(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900174}
175
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900176static inline u16 shpc_readw(struct controller *ctrl, int reg)
177{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800178 return readw(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900179}
180
181static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
182{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800183 writew(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900184}
185
186static inline u32 shpc_readl(struct controller *ctrl, int reg)
187{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800188 return readl(ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900189}
190
191static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
192{
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800193 writel(val, ctrl->creg + reg);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900194}
195
196static inline int shpc_indirect_read(struct controller *ctrl, int index,
197 u32 *value)
198{
199 int rc;
200 u32 cap_offset = ctrl->cap_offset;
201 struct pci_dev *pdev = ctrl->pci_dev;
202
203 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
204 if (rc)
205 return rc;
206 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
207}
208
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900209/*
210 * This is the interrupt polling timeout function.
211 */
Kees Cook36913142017-10-20 15:11:42 -0500212static void int_poll_timeout(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Kees Cook36913142017-10-20 15:11:42 -0500214 struct controller *ctrl = from_timer(ctrl, t, poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900216 /* Poll for interrupt events. regs == NULL => polling */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800217 shpc_isr(0, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 if (!shpchp_poll_time)
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900220 shpchp_poll_time = 2; /* default polling interval is 2 sec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800222 start_int_poll_timer(ctrl, shpchp_poll_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900225/*
226 * This function starts the interrupt polling timer.
227 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800228static void start_int_poll_timer(struct controller *ctrl, int sec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900230 /* Clamp to sane value */
231 if ((sec <= 0) || (sec > 60))
232 sec = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800234 ctrl->poll_timer.expires = jiffies + sec * HZ;
235 add_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700238static inline int is_ctrl_busy(struct controller *ctrl)
239{
240 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
241 return cmd_status & 0x1;
242}
243
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700244/*
245 * Returns 1 if SHPC finishes executing a command within 1 sec,
246 * otherwise returns 0.
247 */
248static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
249{
250 int i;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700251
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700252 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700253 return 1;
254
255 /* Check every 0.1 sec for a total of 1 sec */
256 for (i = 0; i < 10; i++) {
257 msleep(100);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700258 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700259 return 1;
260 }
261
262 return 0;
263}
264
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900265static inline int shpc_wait_cmd(struct controller *ctrl)
266{
267 int retval = 0;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700268 unsigned long timeout = msecs_to_jiffies(1000);
269 int rc;
270
271 if (shpchp_poll_mode)
272 rc = shpc_poll_ctrl_busy(ctrl);
273 else
274 rc = wait_event_interruptible_timeout(ctrl->queue,
Kenji Kaneshige6aa562c2006-09-28 15:51:36 -0700275 !is_ctrl_busy(ctrl), timeout);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700276 if (!rc && is_ctrl_busy(ctrl)) {
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900277 retval = -EIO;
Taku Izumif98ca312008-10-23 11:52:12 +0900278 ctrl_err(ctrl, "Command not completed in 1000 msec\n");
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900279 } else if (rc < 0) {
280 retval = -EINTR;
Taku Izumif98ca312008-10-23 11:52:12 +0900281 ctrl_info(ctrl, "Command was interrupted by a signal\n");
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900282 }
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900283
284 return retval;
285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
288{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900289 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 u16 cmd_status;
291 int retval = 0;
292 u16 temp_word;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900294 mutex_lock(&slot->ctrl->cmd_lock);
295
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700296 if (!shpc_poll_ctrl_busy(ctrl)) {
Krzysztof Wilczyńskib2105b92021-10-06 23:38:27 +0000297 /* After 1 sec and the controller is still busy */
Taku Izumibe7bce22008-10-23 11:54:39 +0900298 ctrl_err(ctrl, "Controller is still busy after 1 sec\n");
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900299 retval = -EBUSY;
300 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
302
303 ++t_slot;
304 temp_word = (t_slot << 8) | (cmd & 0xFF);
Taku Izumif98ca312008-10-23 11:52:12 +0900305 ctrl_dbg(ctrl, "%s: t_slot %x cmd %x\n", __func__, t_slot, cmd);
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /* To make sure the Controller Busy bit is 0 before we send out the
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800308 * command.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900310 shpc_writew(ctrl, CMD, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900312 /*
313 * Wait for command completion.
314 */
315 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900316 if (retval)
317 goto out;
318
ngn5d8491a2024-07-23 14:43:25 +0300319 cmd_status = shpchp_check_cmd_status(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900320 if (cmd_status) {
Ryan Desfosses227f0642014-04-18 20:13:50 -0400321 ctrl_err(ctrl, "Failed to issued command 0x%x (error code = %d)\n",
Taku Izumibe7bce22008-10-23 11:54:39 +0900322 cmd, cmd_status);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900323 retval = -EIO;
324 }
325 out:
326 mutex_unlock(&slot->ctrl->cmd_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return retval;
328}
329
ngn5d8491a2024-07-23 14:43:25 +0300330int shpchp_check_cmd_status(struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 int retval = 0;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800333 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 switch (cmd_status >> 1) {
336 case 0:
337 retval = 0;
338 break;
339 case 1:
340 retval = SWITCH_OPEN;
Taku Izumibe7bce22008-10-23 11:54:39 +0900341 ctrl_err(ctrl, "Switch opened!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
343 case 2:
344 retval = INVALID_CMD;
Taku Izumibe7bce22008-10-23 11:54:39 +0900345 ctrl_err(ctrl, "Invalid HPC command!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347 case 4:
348 retval = INVALID_SPEED_MODE;
Taku Izumibe7bce22008-10-23 11:54:39 +0900349 ctrl_err(ctrl, "Invalid bus speed/mode!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
351 default:
352 retval = cmd_status;
353 }
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 return retval;
356}
357
358
ngn5d8491a2024-07-23 14:43:25 +0300359int shpchp_get_attention_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900361 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800362 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
363 u8 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Kenji Kaneshige58587592006-05-02 11:10:37 +0900365 switch (state) {
366 case ATN_LED_STATE_ON:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 *status = 1; /* On */
368 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900369 case ATN_LED_STATE_BLINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 *status = 2; /* Blink */
371 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900372 case ATN_LED_STATE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 *status = 0; /* Off */
374 break;
375 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900376 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 break;
378 }
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return 0;
381}
382
ngn5d8491a2024-07-23 14:43:25 +0300383int shpchp_get_power_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900385 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800386 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
387 u8 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Kenji Kaneshige58587592006-05-02 11:10:37 +0900389 switch (state) {
390 case SLOT_STATE_PWRONLY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 *status = 2; /* Powered only */
392 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900393 case SLOT_STATE_ENABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 *status = 1; /* Enabled */
395 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900396 case SLOT_STATE_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 *status = 0; /* Disabled */
398 break;
399 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900400 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
402 }
403
Kenji Kaneshige58587592006-05-02 11:10:37 +0900404 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
407
ngn5d8491a2024-07-23 14:43:25 +0300408int shpchp_get_latch_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900410 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800411 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Kenji Kaneshige58587592006-05-02 11:10:37 +0900413 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return 0;
416}
417
ngn5d8491a2024-07-23 14:43:25 +0300418int shpchp_get_adapter_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900420 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800421 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
422 u8 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Kenji Kaneshige58587592006-05-02 11:10:37 +0900424 *status = (state != 0x3) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return 0;
427}
428
ngn5d8491a2024-07-23 14:43:25 +0300429int shpchp_get_prog_int(struct slot *slot, u8 *prog_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900431 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900433 *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 return 0;
436}
437
ngn5d8491a2024-07-23 14:43:25 +0300438int shpchp_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900441 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900442 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900443 u8 m66_cap = !!(slot_reg & MHZ66_CAP);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900444 u8 pi, pcix_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
ngn5d8491a2024-07-23 14:43:25 +0300446 retval = shpchp_get_prog_int(slot, &pi);
Quentin Lambert79e50e72014-09-07 20:03:32 +0200447 if (retval)
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900448 return retval;
449
450 switch (pi) {
451 case 1:
452 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
453 break;
454 case 2:
455 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
456 break;
457 default:
458 return -ENODEV;
459 }
460
Taku Izumif98ca312008-10-23 11:52:12 +0900461 ctrl_dbg(ctrl, "%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
462 __func__, slot_reg, pcix_cap, m66_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900464 switch (pcix_cap) {
465 case 0x0:
466 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
467 break;
468 case 0x1:
469 *value = PCI_SPEED_66MHz_PCIX;
470 break;
471 case 0x3:
472 *value = PCI_SPEED_133MHz_PCIX;
473 break;
474 case 0x4:
475 *value = PCI_SPEED_133MHz_PCIX_266;
476 break;
477 case 0x5:
478 *value = PCI_SPEED_133MHz_PCIX_533;
479 break;
480 case 0x2:
481 default:
482 *value = PCI_SPEED_UNKNOWN;
483 retval = -ENODEV;
484 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486
Taku Izumif98ca312008-10-23 11:52:12 +0900487 ctrl_dbg(ctrl, "Adapter speed = %d\n", *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return retval;
489}
490
ngn5d8491a2024-07-23 14:43:25 +0300491int shpchp_query_power_fault(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900493 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800494 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /* Note: Logic 0 => fault */
Kenji Kaneshige58587592006-05-02 11:10:37 +0900497 return !(slot_reg & POWER_FAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
ngn5d8491a2024-07-23 14:43:25 +0300500int shpchp_set_attention_status(struct slot *slot, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 u8 slot_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 switch (value) {
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800505 case 0:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900506 slot_cmd = SET_ATTN_OFF; /* OFF */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 break;
508 case 1:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900509 slot_cmd = SET_ATTN_ON; /* ON */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 break;
511 case 2:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900512 slot_cmd = SET_ATTN_BLINK; /* BLINK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514 default:
515 return -1;
516 }
517
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900518 return shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
521
ngn5d8491a2024-07-23 14:43:25 +0300522void shpchp_green_led_on(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900524 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525}
526
ngn5d8491a2024-07-23 14:43:25 +0300527void shpchp_green_led_off(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900529 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530}
531
ngn5d8491a2024-07-23 14:43:25 +0300532void shpchp_green_led_blink(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900534 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
ngn5d8491a2024-07-23 14:43:25 +0300537void shpchp_release_ctlr(struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800539 int i;
Kenji Kaneshiged49f2c492006-05-03 23:34:17 +0900540 u32 slot_reg, serr_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800542 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900543 * Mask event interrupts and SERRs of all slots
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800544 */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900545 for (i = 0; i < ctrl->num_slots; i++) {
546 slot_reg = shpc_readl(ctrl, SLOT_REG(i));
547 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
548 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
549 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
550 CON_PFAULT_SERR_MASK);
551 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
552 shpc_writel(ctrl, SLOT_REG(i), slot_reg);
553 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800554
555 cleanup_slots(ctrl);
556
Kenji Kaneshiged49f2c492006-05-03 23:34:17 +0900557 /*
Joe Perches36098012007-12-17 11:40:11 -0800558 * Mask SERR and System Interrupt generation
Kenji Kaneshiged49f2c492006-05-03 23:34:17 +0900559 */
560 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
561 serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
562 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
563 serr_int &= ~SERR_INTR_RSVDZ_MASK;
564 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
565
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800566 if (shpchp_poll_mode)
567 del_timer(&ctrl->poll_timer);
568 else {
569 free_irq(ctrl->pci_dev->irq, ctrl);
570 pci_disable_msi(ctrl->pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800572
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800573 iounmap(ctrl->creg);
574 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
ngn5d8491a2024-07-23 14:43:25 +0300577int shpchp_power_on_slot(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900579 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Kenji Kaneshige40853992006-05-12 11:11:48 +0900581 retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800582 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900583 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800585 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
ngn5d8491a2024-07-23 14:43:25 +0300588int shpchp_slot_enable(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900590 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Kenji Kaneshige40853992006-05-12 11:11:48 +0900592 /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
593 retval = shpc_write_cmd(slot, slot->hp_slot,
594 SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800595 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900596 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800598 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
ngn5d8491a2024-07-23 14:43:25 +0300601int shpchp_slot_disable(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900603 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Kenji Kaneshige40853992006-05-12 11:11:48 +0900605 /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */
606 retval = shpc_write_cmd(slot, slot->hp_slot,
607 SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800608 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900609 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800611 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Matthew Wilcox3749c512009-12-13 08:11:32 -0500614static int shpc_get_cur_bus_speed(struct controller *ctrl)
615{
616 int retval = 0;
617 struct pci_bus *bus = ctrl->pci_dev->subordinate;
618 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
619 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
620 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
621 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
622
623 if ((pi == 1) && (speed_mode > 4)) {
624 retval = -ENODEV;
625 goto out;
626 }
627
628 switch (speed_mode) {
629 case 0x0:
630 bus_speed = PCI_SPEED_33MHz;
631 break;
632 case 0x1:
633 bus_speed = PCI_SPEED_66MHz;
634 break;
635 case 0x2:
636 bus_speed = PCI_SPEED_66MHz_PCIX;
637 break;
638 case 0x3:
639 bus_speed = PCI_SPEED_100MHz_PCIX;
640 break;
641 case 0x4:
642 bus_speed = PCI_SPEED_133MHz_PCIX;
643 break;
644 case 0x5:
645 bus_speed = PCI_SPEED_66MHz_PCIX_ECC;
646 break;
647 case 0x6:
648 bus_speed = PCI_SPEED_100MHz_PCIX_ECC;
649 break;
650 case 0x7:
651 bus_speed = PCI_SPEED_133MHz_PCIX_ECC;
652 break;
653 case 0x8:
654 bus_speed = PCI_SPEED_66MHz_PCIX_266;
655 break;
656 case 0x9:
657 bus_speed = PCI_SPEED_100MHz_PCIX_266;
658 break;
659 case 0xa:
660 bus_speed = PCI_SPEED_133MHz_PCIX_266;
661 break;
662 case 0xb:
663 bus_speed = PCI_SPEED_66MHz_PCIX_533;
664 break;
665 case 0xc:
666 bus_speed = PCI_SPEED_100MHz_PCIX_533;
667 break;
668 case 0xd:
669 bus_speed = PCI_SPEED_133MHz_PCIX_533;
670 break;
671 default:
672 retval = -ENODEV;
673 break;
674 }
675
676 out:
677 bus->cur_bus_speed = bus_speed;
678 dbg("Current bus speed = %d\n", bus_speed);
679 return retval;
680}
681
682
ngn5d8491a2024-07-23 14:43:25 +0300683int shpchp_set_bus_speed_mode(struct slot *slot, enum pci_bus_speed value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900685 int retval;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900686 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900687 u8 pi, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900689 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900690 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
691 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900693 switch (value) {
694 case PCI_SPEED_33MHz:
695 cmd = SETA_PCI_33MHZ;
696 break;
697 case PCI_SPEED_66MHz:
698 cmd = SETA_PCI_66MHZ;
699 break;
700 case PCI_SPEED_66MHz_PCIX:
701 cmd = SETA_PCIX_66MHZ;
702 break;
703 case PCI_SPEED_100MHz_PCIX:
704 cmd = SETA_PCIX_100MHZ;
705 break;
706 case PCI_SPEED_133MHz_PCIX:
707 cmd = SETA_PCIX_133MHZ;
708 break;
709 case PCI_SPEED_66MHz_PCIX_ECC:
710 cmd = SETB_PCIX_66MHZ_EM;
711 break;
712 case PCI_SPEED_100MHz_PCIX_ECC:
713 cmd = SETB_PCIX_100MHZ_EM;
714 break;
715 case PCI_SPEED_133MHz_PCIX_ECC:
716 cmd = SETB_PCIX_133MHZ_EM;
717 break;
718 case PCI_SPEED_66MHz_PCIX_266:
719 cmd = SETB_PCIX_66MHZ_266;
720 break;
721 case PCI_SPEED_100MHz_PCIX_266:
722 cmd = SETB_PCIX_100MHZ_266;
723 break;
724 case PCI_SPEED_133MHz_PCIX_266:
725 cmd = SETB_PCIX_133MHZ_266;
726 break;
727 case PCI_SPEED_66MHz_PCIX_533:
728 cmd = SETB_PCIX_66MHZ_533;
729 break;
730 case PCI_SPEED_100MHz_PCIX_533:
731 cmd = SETB_PCIX_100MHZ_533;
732 break;
733 case PCI_SPEED_133MHz_PCIX_533:
734 cmd = SETB_PCIX_133MHZ_533;
735 break;
736 default:
737 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900739
740 retval = shpc_write_cmd(slot, 0, cmd);
741 if (retval)
Taku Izumif98ca312008-10-23 11:52:12 +0900742 ctrl_err(ctrl, "%s: Write command failed!\n", __func__);
Matthew Wilcox3749c512009-12-13 08:11:32 -0500743 else
744 shpc_get_cur_bus_speed(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 return retval;
747}
748
David Howells7d12e782006-10-05 14:55:46 +0100749static irqreturn_t shpc_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900751 struct controller *ctrl = (struct controller *)dev_id;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900752 u32 serr_int, slot_reg, intr_loc, intr_loc2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 int hp_slot;
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 /* Check to see if it was our interrupt */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900756 intr_loc = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 if (!intr_loc)
758 return IRQ_NONE;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900759
Taku Izumif98ca312008-10-23 11:52:12 +0900760 ctrl_dbg(ctrl, "%s: intr_loc = %x\n", __func__, intr_loc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Quentin Lambert382a9c92014-09-07 20:02:04 +0200762 if (!shpchp_poll_mode) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900763 /*
764 * Mask Global Interrupt Mask - see implementation
765 * note on p. 139 of SHPC spec rev 1.0
766 */
767 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
768 serr_int |= GLOBAL_INTR_MASK;
769 serr_int &= ~SERR_INTR_RSVDZ_MASK;
770 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900772 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Taku Izumif98ca312008-10-23 11:52:12 +0900773 ctrl_dbg(ctrl, "%s: intr_loc2 = %x\n", __func__, intr_loc2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900776 if (intr_loc & CMD_INTR_PENDING) {
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800777 /*
778 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +0900779 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 * Detect bit in Controller SERR-INT register
781 */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900782 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
783 serr_int &= ~SERR_INTR_RSVDZ_MASK;
784 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 wake_up_interruptible(&ctrl->queue);
787 }
788
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900789 if (!(intr_loc & ~CMD_INTR_PENDING))
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900790 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800792 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900793 /* To find out which slot has interrupt pending */
794 if (!(intr_loc & SLOT_INTR_PENDING(hp_slot)))
795 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900797 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Taku Izumibe7bce22008-10-23 11:54:39 +0900798 ctrl_dbg(ctrl, "Slot %x with intr, slot register = %x\n",
799 hp_slot, slot_reg);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900800
801 if (slot_reg & MRL_CHANGE_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800802 shpchp_handle_switch_change(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900803
804 if (slot_reg & BUTTON_PRESS_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800805 shpchp_handle_attention_button(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900806
807 if (slot_reg & PRSNT_CHANGE_DETECTED)
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800808 shpchp_handle_presence_change(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900809
810 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800811 shpchp_handle_power_fault(hp_slot, ctrl);
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900812
813 /* Clear all slot events */
814 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
815 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900817 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (!shpchp_poll_mode) {
819 /* Unmask Global Interrupt Mask */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900820 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
821 serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
822 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 return IRQ_HANDLED;
826}
827
Matthew Wilcox3749c512009-12-13 08:11:32 -0500828static int shpc_get_max_bus_speed(struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900830 int retval = 0;
Matthew Wilcox3749c512009-12-13 08:11:32 -0500831 struct pci_bus *bus = ctrl->pci_dev->subordinate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900833 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
834 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
835 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900838 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900839 bus_speed = PCI_SPEED_133MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900840 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900841 bus_speed = PCI_SPEED_100MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900842 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900843 bus_speed = PCI_SPEED_66MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900844 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900845 bus_speed = PCI_SPEED_133MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900846 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900847 bus_speed = PCI_SPEED_100MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900848 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900849 bus_speed = PCI_SPEED_66MHz_PCIX_266;
850 }
851
852 if (bus_speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900853 if (slot_avail1 & SLOT_133MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900854 bus_speed = PCI_SPEED_133MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900855 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900856 bus_speed = PCI_SPEED_100MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900857 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900858 bus_speed = PCI_SPEED_66MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900859 else if (slot_avail2 & SLOT_66MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900860 bus_speed = PCI_SPEED_66MHz;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900861 else if (slot_avail1 & SLOT_33MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900862 bus_speed = PCI_SPEED_33MHz;
863 else
864 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
866
Matthew Wilcox3749c512009-12-13 08:11:32 -0500867 bus->max_bus_speed = bus_speed;
Taku Izumif98ca312008-10-23 11:52:12 +0900868 ctrl_dbg(ctrl, "Max bus speed = %d\n", bus_speed);
Kenji Kaneshige1555b332007-01-09 13:03:01 -0800869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 return retval;
871}
872
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800873int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Amol Lad662a98f2006-10-05 12:07:32 +0530875 int rc = -1, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 u8 hp_slot;
Kenji Kaneshige04559862005-11-24 11:36:59 +0900877 u32 shpc_base_offset;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900878 u32 tempdword, slot_reg, slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 u8 i;
880
Kenji Kaneshige04559862005-11-24 11:36:59 +0900881 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
Taku Izumibe7bce22008-10-23 11:54:39 +0900882 ctrl_dbg(ctrl, "Hotplug Controller:\n");
Kenji Kaneshige04559862005-11-24 11:36:59 +0900883
Bjorn Helgaas4cac2eb2011-08-23 10:16:43 -0600884 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
885 pdev->device == PCI_DEVICE_ID_AMD_GOLAM_7450) {
Kenji Kaneshige04559862005-11-24 11:36:59 +0900886 /* amd shpc driver doesn't use Base Offset; assume 0 */
887 ctrl->mmio_base = pci_resource_start(pdev, 0);
888 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +0900890 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
891 if (!ctrl->cap_offset) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900892 ctrl_err(ctrl, "Cannot find PCI capability\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800893 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
Taku Izumibe7bce22008-10-23 11:54:39 +0900895 ctrl_dbg(ctrl, " cap_offset = %x\n", ctrl->cap_offset);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900896
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900897 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 if (rc) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900899 ctrl_err(ctrl, "Cannot read base_offset\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800900 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900903 rc = shpc_indirect_read(ctrl, 3, &tempdword);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900904 if (rc) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900905 ctrl_err(ctrl, "Cannot read slot config\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800906 goto abort;
Kenji Kaneshige04559862005-11-24 11:36:59 +0900907 }
908 num_slots = tempdword & SLOT_NUM;
Taku Izumibe7bce22008-10-23 11:54:39 +0900909 ctrl_dbg(ctrl, " num_slots (indirect) %x\n", num_slots);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900910
911 for (i = 0; i < 9 + num_slots; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900912 rc = shpc_indirect_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (rc) {
Ryan Desfosses227f0642014-04-18 20:13:50 -0400914 ctrl_err(ctrl, "Cannot read creg (index = %d)\n",
915 i);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800916 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
Taku Izumibe7bce22008-10-23 11:54:39 +0900918 ctrl_dbg(ctrl, " offset %d: value %x\n", i, tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
Kenji Kaneshige04559862005-11-24 11:36:59 +0900920
921 ctrl->mmio_base =
922 pci_resource_start(pdev, 0) + shpc_base_offset;
923 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925
Taku Izumif98ca312008-10-23 11:52:12 +0900926 ctrl_info(ctrl, "HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
927 pdev->vendor, pdev->device, pdev->subsystem_vendor,
928 pdev->subsystem_device);
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800929
Amol Lad662a98f2006-10-05 12:07:32 +0530930 rc = pci_enable_device(pdev);
931 if (rc) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900932 ctrl_err(ctrl, "pci_enable_device failed\n");
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800933 goto abort;
Amol Lad662a98f2006-10-05 12:07:32 +0530934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Kenji Kaneshige04559862005-11-24 11:36:59 +0900936 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900937 ctrl_err(ctrl, "Cannot reserve MMIO region\n");
Amol Lad662a98f2006-10-05 12:07:32 +0530938 rc = -1;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800939 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 }
941
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800942 ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
943 if (!ctrl->creg) {
Taku Izumibe7bce22008-10-23 11:54:39 +0900944 ctrl_err(ctrl, "Cannot remap MMIO region %lx @ %lx\n",
945 ctrl->mmio_size, ctrl->mmio_base);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900946 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Amol Lad662a98f2006-10-05 12:07:32 +0530947 rc = -1;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800948 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
Taku Izumibe7bce22008-10-23 11:54:39 +0900950 ctrl_dbg(ctrl, "ctrl->creg %p\n", ctrl->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +0100952 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900953 mutex_init(&ctrl->cmd_lock);
954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 /* Setup wait queue */
956 init_waitqueue_head(&ctrl->queue);
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 /* Return PCI Controller Info */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900959 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800960 ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
961 ctrl->num_slots = slot_config & SLOT_NUM;
962 ctrl->first_slot = (slot_config & PSN) >> 16;
963 ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900966 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Taku Izumibe7bce22008-10-23 11:54:39 +0900967 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword);
Kenji Kaneshigee7138722006-05-02 11:12:37 +0900968 tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
969 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
970 tempdword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900971 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
972 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Taku Izumibe7bce22008-10-23 11:54:39 +0900973 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /* Mask the MRL sensor SERR Mask of individual slot in
976 * Slot SERR-INT Mask & clear all the existing event if any
977 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800978 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900979 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Taku Izumibe7bce22008-10-23 11:54:39 +0900980 ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n",
981 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900982 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
983 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
984 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
985 CON_PFAULT_SERR_MASK);
986 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
987 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
Kenji Kaneshige9f593e32007-01-09 13:03:10 -0800989
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800990 if (shpchp_poll_mode) {
991 /* Install interrupt polling timer. Start with 10 sec delay */
Kees Cook36913142017-10-20 15:11:42 -0500992 timer_setup(&ctrl->poll_timer, int_poll_timeout, 0);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800993 start_int_poll_timer(ctrl, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 } else {
995 /* Installs the interrupt handler */
996 rc = pci_enable_msi(pdev);
997 if (rc) {
Ryan Desfosses227f0642014-04-18 20:13:50 -0400998 ctrl_info(ctrl, "Can't get msi for the hotplug controller\n");
999 ctrl_info(ctrl, "Use INTx for the hotplug controller\n");
Aleksandr Bezzubikov48b79a12017-07-18 17:12:25 +03001000 } else {
1001 pci_set_master(pdev);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001002 }
Kenji Kaneshige9f593e32007-01-09 13:03:10 -08001003
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001004 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
1005 MY_NAME, (void *)ctrl);
Tejun Heoe24dcbe2010-10-18 08:33:02 +02001006 ctrl_dbg(ctrl, "request_irq %d (returns %d)\n",
1007 ctrl->pci_dev->irq, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (rc) {
Ryan Desfosses227f0642014-04-18 20:13:50 -04001009 ctrl_err(ctrl, "Can't get irq %d for the hotplug controller\n",
1010 ctrl->pci_dev->irq);
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001011 goto abort_iounmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 }
Taku Izumibe7bce22008-10-23 11:54:39 +09001014 ctrl_dbg(ctrl, "HPC at %s irq=%x\n", pci_name(pdev), pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Matthew Wilcox3749c512009-12-13 08:11:32 -05001016 shpc_get_max_bus_speed(ctrl);
1017 shpc_get_cur_bus_speed(ctrl);
1018
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001019 /*
1020 * Unmask all event interrupts of all slots
1021 */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001022 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001023 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Taku Izumibe7bce22008-10-23 11:54:39 +09001024 ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n",
1025 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001026 slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1027 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1028 CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
1029 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031 if (!shpchp_poll_mode) {
1032 /* Unmask all general input interrupts and SERR */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001033 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001034 tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
1035 SERR_INTR_RSVDZ_MASK);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001036 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1037 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Taku Izumibe7bce22008-10-23 11:54:39 +09001038 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 return 0;
1042
1043 /* We end up here for the many possible ways to fail this API. */
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -08001044abort_iounmap:
1045 iounmap(ctrl->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046abort:
Amol Lad662a98f2006-10-05 12:07:32 +05301047 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}