| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Standard PCI Hot Plug Driver | 
 | 3 |  * | 
 | 4 |  * Copyright (C) 1995,2001 Compaq Computer Corporation | 
 | 5 |  * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) | 
 | 6 |  * Copyright (C) 2001 IBM Corp. | 
 | 7 |  * Copyright (C) 2003-2004 Intel Corporation | 
 | 8 |  * | 
 | 9 |  * All rights reserved. | 
 | 10 |  * | 
 | 11 |  * This program is free software; you can redistribute it and/or modify | 
 | 12 |  * it under the terms of the GNU General Public License as published by | 
 | 13 |  * the Free Software Foundation; either version 2 of the License, or (at | 
 | 14 |  * your option) any later version. | 
 | 15 |  * | 
 | 16 |  * This program is distributed in the hope that it will be useful, but | 
 | 17 |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 18 |  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | 
 | 19 |  * NON INFRINGEMENT.  See the GNU General Public License for more | 
 | 20 |  * details. | 
 | 21 |  * | 
 | 22 |  * You should have received a copy of the GNU General Public License | 
 | 23 |  * along with this program; if not, write to the Free Software | 
 | 24 |  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 25 |  * | 
| Kristen Accardi | 8cf4c19 | 2005-08-16 15:16:10 -0700 | [diff] [blame] | 26 |  * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 |  * | 
 | 28 |  */ | 
 | 29 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> | 
 | 31 | #include <linux/module.h> | 
 | 32 | #include <linux/types.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> | 
| Andrew Morton | d4d28dd | 2005-11-13 16:06:40 -0800 | [diff] [blame] | 34 | #include <linux/interrupt.h> | 
 | 35 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "shpchp.h" | 
 | 37 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* 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 Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 61 | /* | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 62 |  * Interrupt Locator Register definitions | 
 | 63 |  */ | 
 | 64 | #define CMD_INTR_PENDING	(1 << 0) | 
 | 65 | #define SLOT_INTR_PENDING(i)	(1 << (i + 1)) | 
 | 66 |  | 
 | 67 | /* | 
| Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 68 |  * 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 Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 79 |  * Logical Slot Register definitions | 
 | 80 |  */ | 
 | 81 | #define SLOT_REG(i)		(SLOT1 + (4 * i)) | 
 | 82 |  | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 83 | #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 Carpenter | 3b8fdb7 | 2010-05-26 12:46:39 +0200 | [diff] [blame] | 116 | #define SLOT_REG_RSVDZ_MASK	((1 << 15) | (7 << 21)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 118 | /* | 
 | 119 |  * SHPC Command Code definitnions | 
 | 120 |  * | 
 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | #define SETA_PCI_66MHZ		0x41 | 
 | 140 | #define SETA_PCIX_66MHZ		0x42 | 
 | 141 | #define SETA_PCIX_100MHZ	0x43 | 
 | 142 | #define SETA_PCIX_133MHZ	0x44 | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 143 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #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 Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 162 | #define SETB_RESERVED1		0x5e | 
 | 163 | #define SETB_RESERVED2		0x5f | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 165 | /* | 
 | 166 |  * SHPC controller command error code | 
 | 167 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #define SWITCH_OPEN		0x1 | 
 | 169 | #define INVALID_CMD		0x2 | 
 | 170 | #define INVALID_SPEED_MODE	0x4 | 
 | 171 |  | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 172 | /* | 
 | 173 |  * For accessing SHPC Working Register Set via PCI Configuration Space | 
 | 174 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #define DWORD_SELECT		0x2 | 
 | 176 | #define DWORD_DATA		0x4 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 |  | 
 | 178 | /* Field Offset in Logical Slot Register - byte boundary */ | 
 | 179 | #define SLOT_EVENT_LATCH	0x2 | 
 | 180 | #define SLOT_SERR_INT_MASK	0x3 | 
 | 181 |  | 
| Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 182 | static atomic_t shpchp_num_controllers = ATOMIC_INIT(0); | 
 | 183 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 184 | static irqreturn_t shpc_isr(int irq, void *dev_id); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 185 | static void start_int_poll_timer(struct controller *ctrl, int sec); | 
| Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 186 | static int hpc_check_cmd_status(struct controller *ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 188 | static inline u8 shpc_readb(struct controller *ctrl, int reg) | 
 | 189 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 190 | 	return readb(ctrl->creg + reg); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 191 | } | 
 | 192 |  | 
 | 193 | static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val) | 
 | 194 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 195 | 	writeb(val, ctrl->creg + reg); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 196 | } | 
 | 197 |  | 
 | 198 | static inline u16 shpc_readw(struct controller *ctrl, int reg) | 
 | 199 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 200 | 	return readw(ctrl->creg + reg); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 201 | } | 
 | 202 |  | 
 | 203 | static inline void shpc_writew(struct controller *ctrl, int reg, u16 val) | 
 | 204 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 205 | 	writew(val, ctrl->creg + reg); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 206 | } | 
 | 207 |  | 
 | 208 | static inline u32 shpc_readl(struct controller *ctrl, int reg) | 
 | 209 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 210 | 	return readl(ctrl->creg + reg); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 211 | } | 
 | 212 |  | 
 | 213 | static inline void shpc_writel(struct controller *ctrl, int reg, u32 val) | 
 | 214 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 215 | 	writel(val, ctrl->creg + reg); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 216 | } | 
 | 217 |  | 
 | 218 | static inline int shpc_indirect_read(struct controller *ctrl, int index, | 
 | 219 | 				     u32 *value) | 
 | 220 | { | 
 | 221 | 	int rc; | 
 | 222 | 	u32 cap_offset = ctrl->cap_offset; | 
 | 223 | 	struct pci_dev *pdev = ctrl->pci_dev; | 
 | 224 |  | 
 | 225 | 	rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index); | 
 | 226 | 	if (rc) | 
 | 227 | 		return rc; | 
 | 228 | 	return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value); | 
 | 229 | } | 
 | 230 |  | 
| Kenji Kaneshige | f426395 | 2006-05-12 11:13:02 +0900 | [diff] [blame] | 231 | /* | 
 | 232 |  * This is the interrupt polling timeout function. | 
 | 233 |  */ | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 234 | static void int_poll_timeout(unsigned long data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 236 | 	struct controller *ctrl = (struct controller *)data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 |  | 
| Kenji Kaneshige | f426395 | 2006-05-12 11:13:02 +0900 | [diff] [blame] | 238 | 	/* Poll for interrupt events.  regs == NULL => polling */ | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 239 | 	shpc_isr(0, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 241 | 	init_timer(&ctrl->poll_timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | 	if (!shpchp_poll_time) | 
| Kenji Kaneshige | f426395 | 2006-05-12 11:13:02 +0900 | [diff] [blame] | 243 | 		shpchp_poll_time = 2; /* default polling interval is 2 sec */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 245 | 	start_int_poll_timer(ctrl, shpchp_poll_time); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } | 
 | 247 |  | 
| Kenji Kaneshige | f426395 | 2006-05-12 11:13:02 +0900 | [diff] [blame] | 248 | /* | 
 | 249 |  * This function starts the interrupt polling timer. | 
 | 250 |  */ | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 251 | static void start_int_poll_timer(struct controller *ctrl, int sec) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { | 
| Kenji Kaneshige | f426395 | 2006-05-12 11:13:02 +0900 | [diff] [blame] | 253 | 	/* Clamp to sane value */ | 
 | 254 | 	if ((sec <= 0) || (sec > 60)) | 
 | 255 | 		sec = 2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 257 | 	ctrl->poll_timer.function = &int_poll_timeout; | 
 | 258 | 	ctrl->poll_timer.data = (unsigned long)ctrl; | 
 | 259 | 	ctrl->poll_timer.expires = jiffies + sec * HZ; | 
 | 260 | 	add_timer(&ctrl->poll_timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } | 
 | 262 |  | 
| Kenji Kaneshige | d1729cc | 2006-09-28 15:51:21 -0700 | [diff] [blame] | 263 | static inline int is_ctrl_busy(struct controller *ctrl) | 
 | 264 | { | 
 | 265 | 	u16 cmd_status = shpc_readw(ctrl, CMD_STATUS); | 
 | 266 | 	return cmd_status & 0x1; | 
 | 267 | } | 
 | 268 |  | 
| Kenji Kaneshige | b4a1eff | 2006-09-22 12:52:37 -0700 | [diff] [blame] | 269 | /* | 
 | 270 |  * Returns 1 if SHPC finishes executing a command within 1 sec, | 
 | 271 |  * otherwise returns 0. | 
 | 272 |  */ | 
 | 273 | static inline int shpc_poll_ctrl_busy(struct controller *ctrl) | 
 | 274 | { | 
 | 275 | 	int i; | 
| Kenji Kaneshige | b4a1eff | 2006-09-22 12:52:37 -0700 | [diff] [blame] | 276 |  | 
| Kenji Kaneshige | d1729cc | 2006-09-28 15:51:21 -0700 | [diff] [blame] | 277 | 	if (!is_ctrl_busy(ctrl)) | 
| Kenji Kaneshige | b4a1eff | 2006-09-22 12:52:37 -0700 | [diff] [blame] | 278 | 		return 1; | 
 | 279 |  | 
 | 280 | 	/* Check every 0.1 sec for a total of 1 sec */ | 
 | 281 | 	for (i = 0; i < 10; i++) { | 
 | 282 | 		msleep(100); | 
| Kenji Kaneshige | d1729cc | 2006-09-28 15:51:21 -0700 | [diff] [blame] | 283 | 		if (!is_ctrl_busy(ctrl)) | 
| Kenji Kaneshige | b4a1eff | 2006-09-22 12:52:37 -0700 | [diff] [blame] | 284 | 			return 1; | 
 | 285 | 	} | 
 | 286 |  | 
 | 287 | 	return 0; | 
 | 288 | } | 
 | 289 |  | 
| Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 290 | static inline int shpc_wait_cmd(struct controller *ctrl) | 
 | 291 | { | 
 | 292 | 	int retval = 0; | 
| Kenji Kaneshige | b4a1eff | 2006-09-22 12:52:37 -0700 | [diff] [blame] | 293 | 	unsigned long timeout = msecs_to_jiffies(1000); | 
 | 294 | 	int rc; | 
 | 295 |  | 
 | 296 | 	if (shpchp_poll_mode) | 
 | 297 | 		rc = shpc_poll_ctrl_busy(ctrl); | 
 | 298 | 	else | 
 | 299 | 		rc = wait_event_interruptible_timeout(ctrl->queue, | 
| Kenji Kaneshige | 6aa562c | 2006-09-28 15:51:36 -0700 | [diff] [blame] | 300 | 						!is_ctrl_busy(ctrl), timeout); | 
| Kenji Kaneshige | d1729cc | 2006-09-28 15:51:21 -0700 | [diff] [blame] | 301 | 	if (!rc && is_ctrl_busy(ctrl)) { | 
| Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 302 | 		retval = -EIO; | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 303 | 		ctrl_err(ctrl, "Command not completed in 1000 msec\n"); | 
| Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 304 | 	} else if (rc < 0) { | 
 | 305 | 		retval = -EINTR; | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 306 | 		ctrl_info(ctrl, "Command was interrupted by a signal\n"); | 
| Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 307 | 	} | 
| Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 308 |  | 
 | 309 | 	return retval; | 
 | 310 | } | 
 | 311 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) | 
 | 313 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 314 | 	struct controller *ctrl = slot->ctrl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | 	u16 cmd_status; | 
 | 316 | 	int retval = 0; | 
 | 317 | 	u16 temp_word; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 |  | 
| Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 319 | 	mutex_lock(&slot->ctrl->cmd_lock); | 
 | 320 |  | 
| Kenji Kaneshige | b4a1eff | 2006-09-22 12:52:37 -0700 | [diff] [blame] | 321 | 	if (!shpc_poll_ctrl_busy(ctrl)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | 		/* After 1 sec and and the controller is still busy */ | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 323 | 		ctrl_err(ctrl, "Controller is still busy after 1 sec\n"); | 
| Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 324 | 		retval = -EBUSY; | 
 | 325 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 	} | 
 | 327 |  | 
 | 328 | 	++t_slot; | 
 | 329 | 	temp_word =  (t_slot << 8) | (cmd & 0xFF); | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 330 | 	ctrl_dbg(ctrl, "%s: t_slot %x cmd %x\n", __func__, t_slot, cmd); | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 331 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | 	/* To make sure the Controller Busy bit is 0 before we send out the | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 333 | 	 * command. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | 	 */ | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 335 | 	shpc_writew(ctrl, CMD, temp_word); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 |  | 
| Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 337 | 	/* | 
 | 338 | 	 * Wait for command completion. | 
 | 339 | 	 */ | 
 | 340 | 	retval = shpc_wait_cmd(slot->ctrl); | 
| Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 341 | 	if (retval) | 
 | 342 | 		goto out; | 
 | 343 |  | 
 | 344 | 	cmd_status = hpc_check_cmd_status(slot->ctrl); | 
 | 345 | 	if (cmd_status) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 346 | 		ctrl_err(ctrl, | 
 | 347 | 			 "Failed to issued command 0x%x (error code = %d)\n", | 
 | 348 | 			 cmd, cmd_status); | 
| Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 349 | 		retval = -EIO; | 
 | 350 | 	} | 
 | 351 |  out: | 
 | 352 | 	mutex_unlock(&slot->ctrl->cmd_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | 	return retval; | 
 | 354 | } | 
 | 355 |  | 
 | 356 | static int hpc_check_cmd_status(struct controller *ctrl) | 
 | 357 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | 	int retval = 0; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 359 | 	u16 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F; | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 360 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | 	switch (cmd_status >> 1) { | 
 | 362 | 	case 0: | 
 | 363 | 		retval = 0; | 
 | 364 | 		break; | 
 | 365 | 	case 1: | 
 | 366 | 		retval = SWITCH_OPEN; | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 367 | 		ctrl_err(ctrl, "Switch opened!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | 		break; | 
 | 369 | 	case 2: | 
 | 370 | 		retval = INVALID_CMD; | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 371 | 		ctrl_err(ctrl, "Invalid HPC command!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | 		break; | 
 | 373 | 	case 4: | 
 | 374 | 		retval = INVALID_SPEED_MODE; | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 375 | 		ctrl_err(ctrl, "Invalid bus speed/mode!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | 		break; | 
 | 377 | 	default: | 
 | 378 | 		retval = cmd_status; | 
 | 379 | 	} | 
 | 380 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | 	return retval; | 
 | 382 | } | 
 | 383 |  | 
 | 384 |  | 
 | 385 | static int hpc_get_attention_status(struct slot *slot, u8 *status) | 
 | 386 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 387 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 388 | 	u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); | 
 | 389 | 	u8 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 |  | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 391 | 	switch (state) { | 
 | 392 | 	case ATN_LED_STATE_ON: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 		*status = 1;	/* On */ | 
 | 394 | 		break; | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 395 | 	case ATN_LED_STATE_BLINK: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | 		*status = 2;	/* Blink */ | 
 | 397 | 		break; | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 398 | 	case ATN_LED_STATE_OFF: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | 		*status = 0;	/* Off */ | 
 | 400 | 		break; | 
 | 401 | 	default: | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 402 | 		*status = 0xFF;	/* Reserved */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 		break; | 
 | 404 | 	} | 
 | 405 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | 	return 0; | 
 | 407 | } | 
 | 408 |  | 
 | 409 | static int hpc_get_power_status(struct slot * slot, u8 *status) | 
 | 410 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 411 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 412 | 	u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); | 
 | 413 | 	u8 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 |  | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 415 | 	switch (state) { | 
 | 416 | 	case SLOT_STATE_PWRONLY: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | 		*status = 2;	/* Powered only */ | 
 | 418 | 		break; | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 419 | 	case SLOT_STATE_ENABLED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | 		*status = 1;	/* Enabled */ | 
 | 421 | 		break; | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 422 | 	case SLOT_STATE_DISABLED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | 		*status = 0;	/* Disabled */ | 
 | 424 | 		break; | 
 | 425 | 	default: | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 426 | 		*status = 0xFF;	/* Reserved */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | 		break; | 
 | 428 | 	} | 
 | 429 |  | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 430 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } | 
 | 432 |  | 
 | 433 |  | 
 | 434 | static int hpc_get_latch_status(struct slot *slot, u8 *status) | 
 | 435 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 436 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 437 | 	u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 |  | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 439 | 	*status = !!(slot_reg & MRL_SENSOR);	/* 0 -> close; 1 -> open */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | 	return 0; | 
 | 442 | } | 
 | 443 |  | 
 | 444 | static int hpc_get_adapter_status(struct slot *slot, u8 *status) | 
 | 445 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 446 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 447 | 	u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); | 
 | 448 | 	u8 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 |  | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 450 | 	*status = (state != 0x3) ? 1 : 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | 	return 0; | 
 | 453 | } | 
 | 454 |  | 
 | 455 | static int hpc_get_prog_int(struct slot *slot, u8 *prog_int) | 
 | 456 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 457 | 	struct controller *ctrl = slot->ctrl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 459 | 	*prog_int = shpc_readb(ctrl, PROG_INTERFACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | 	return 0; | 
 | 462 | } | 
 | 463 |  | 
 | 464 | static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value) | 
 | 465 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | 	int retval = 0; | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 467 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 468 | 	u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 469 | 	u8 m66_cap  = !!(slot_reg & MHZ66_CAP); | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 470 | 	u8 pi, pcix_cap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 |  | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 472 | 	if ((retval = hpc_get_prog_int(slot, &pi))) | 
 | 473 | 		return retval; | 
 | 474 |  | 
 | 475 | 	switch (pi) { | 
 | 476 | 	case 1: | 
 | 477 | 		pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT; | 
 | 478 | 		break; | 
 | 479 | 	case 2: | 
 | 480 | 		pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT; | 
 | 481 | 		break; | 
 | 482 | 	default: | 
 | 483 | 		return -ENODEV; | 
 | 484 | 	} | 
 | 485 |  | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 486 | 	ctrl_dbg(ctrl, "%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n", | 
 | 487 | 		 __func__, slot_reg, pcix_cap, m66_cap); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 |  | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 489 | 	switch (pcix_cap) { | 
 | 490 | 	case 0x0: | 
 | 491 | 		*value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz; | 
 | 492 | 		break; | 
 | 493 | 	case 0x1: | 
 | 494 | 		*value = PCI_SPEED_66MHz_PCIX; | 
 | 495 | 		break; | 
 | 496 | 	case 0x3: | 
 | 497 | 		*value = PCI_SPEED_133MHz_PCIX; | 
 | 498 | 		break; | 
 | 499 | 	case 0x4: | 
 | 500 | 		*value = PCI_SPEED_133MHz_PCIX_266; | 
 | 501 | 		break; | 
 | 502 | 	case 0x5: | 
 | 503 | 		*value = PCI_SPEED_133MHz_PCIX_533; | 
 | 504 | 		break; | 
 | 505 | 	case 0x2: | 
 | 506 | 	default: | 
 | 507 | 		*value = PCI_SPEED_UNKNOWN; | 
 | 508 | 		retval = -ENODEV; | 
 | 509 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | 	} | 
 | 511 |  | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 512 | 	ctrl_dbg(ctrl, "Adapter speed = %d\n", *value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 	return retval; | 
 | 514 | } | 
 | 515 |  | 
 | 516 | static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode) | 
 | 517 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | 	int retval = 0; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 519 | 	struct controller *ctrl = slot->ctrl; | 
 | 520 | 	u16 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG); | 
 | 521 | 	u8 pi = shpc_readb(ctrl, PROG_INTERFACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 |  | 
 | 523 | 	if (pi == 2) { | 
| Kenji Kaneshige | 87d6c55 | 2005-11-24 11:35:05 +0900 | [diff] [blame] | 524 | 		*mode = (sec_bus_status & 0x0100) >> 8; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | 	} else { | 
 | 526 | 		retval = -1; | 
 | 527 | 	} | 
 | 528 |  | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 529 | 	ctrl_dbg(ctrl, "Mode 1 ECC cap = %d\n", *mode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | 	return retval; | 
 | 531 | } | 
 | 532 |  | 
 | 533 | static int hpc_query_power_fault(struct slot * slot) | 
 | 534 | { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 535 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 536 | 	u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | 	/* Note: Logic 0 => fault */ | 
| Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 539 | 	return !(slot_reg & POWER_FAULT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } | 
 | 541 |  | 
 | 542 | static int hpc_set_attention_status(struct slot *slot, u8 value) | 
 | 543 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | 	u8 slot_cmd = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 |  | 
 | 546 | 	switch (value) { | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 547 | 		case 0 : | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 548 | 			slot_cmd = SET_ATTN_OFF;	/* OFF */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | 			break; | 
 | 550 | 		case 1: | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 551 | 			slot_cmd = SET_ATTN_ON;		/* ON */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | 			break; | 
 | 553 | 		case 2: | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 554 | 			slot_cmd = SET_ATTN_BLINK;	/* BLINK */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | 			break; | 
 | 556 | 		default: | 
 | 557 | 			return -1; | 
 | 558 | 	} | 
 | 559 |  | 
| Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 560 | 	return shpc_write_cmd(slot, slot->hp_slot, slot_cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } | 
 | 562 |  | 
 | 563 |  | 
 | 564 | static void hpc_set_green_led_on(struct slot *slot) | 
 | 565 | { | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 566 | 	shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } | 
 | 568 |  | 
 | 569 | static void hpc_set_green_led_off(struct slot *slot) | 
 | 570 | { | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 571 | 	shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } | 
 | 573 |  | 
 | 574 | static void hpc_set_green_led_blink(struct slot *slot) | 
 | 575 | { | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 576 | 	shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } | 
 | 578 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | static void hpc_release_ctlr(struct controller *ctrl) | 
 | 580 | { | 
| Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 581 | 	int i; | 
| Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 582 | 	u32 slot_reg, serr_int; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 |  | 
| Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 584 | 	/* | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 585 | 	 * Mask event interrupts and SERRs of all slots | 
| Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 586 | 	 */ | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 587 | 	for (i = 0; i < ctrl->num_slots; i++) { | 
 | 588 | 		slot_reg = shpc_readl(ctrl, SLOT_REG(i)); | 
 | 589 | 		slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | | 
 | 590 | 			     BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | | 
 | 591 | 			     CON_PFAULT_INTR_MASK   | MRL_CHANGE_SERR_MASK | | 
 | 592 | 			     CON_PFAULT_SERR_MASK); | 
 | 593 | 		slot_reg &= ~SLOT_REG_RSVDZ_MASK; | 
 | 594 | 		shpc_writel(ctrl, SLOT_REG(i), slot_reg); | 
 | 595 | 	} | 
| Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 596 |  | 
 | 597 | 	cleanup_slots(ctrl); | 
 | 598 |  | 
| Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 599 | 	/* | 
| Joe Perches | 3609801 | 2007-12-17 11:40:11 -0800 | [diff] [blame] | 600 | 	 * Mask SERR and System Interrupt generation | 
| Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 601 | 	 */ | 
 | 602 | 	serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
 | 603 | 	serr_int |= (GLOBAL_INTR_MASK  | GLOBAL_SERR_MASK | | 
 | 604 | 		     COMMAND_INTR_MASK | ARBITER_SERR_MASK); | 
 | 605 | 	serr_int &= ~SERR_INTR_RSVDZ_MASK; | 
 | 606 | 	shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); | 
 | 607 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 608 | 	if (shpchp_poll_mode) | 
 | 609 | 		del_timer(&ctrl->poll_timer); | 
 | 610 | 	else { | 
 | 611 | 		free_irq(ctrl->pci_dev->irq, ctrl); | 
 | 612 | 		pci_disable_msi(ctrl->pci_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | 	} | 
| Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 614 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 615 | 	iounmap(ctrl->creg); | 
 | 616 | 	release_mem_region(ctrl->mmio_base, ctrl->mmio_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 |  | 
| Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 618 | 	/* | 
 | 619 | 	 * If this is the last controller to be released, destroy the | 
 | 620 | 	 * shpchpd work queue | 
 | 621 | 	 */ | 
 | 622 | 	if (atomic_dec_and_test(&shpchp_num_controllers)) | 
 | 623 | 		destroy_workqueue(shpchp_wq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } | 
 | 625 |  | 
 | 626 | static int hpc_power_on_slot(struct slot * slot) | 
 | 627 | { | 
| Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 628 | 	int retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 |  | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 630 | 	retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR); | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 631 | 	if (retval) | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 632 | 		ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 |  | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 634 | 	return retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } | 
 | 636 |  | 
 | 637 | static int hpc_slot_enable(struct slot * slot) | 
 | 638 | { | 
| Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 639 | 	int retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 |  | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 641 | 	/* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */ | 
 | 642 | 	retval = shpc_write_cmd(slot, slot->hp_slot, | 
 | 643 | 			SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF); | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 644 | 	if (retval) | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 645 | 		ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 |  | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 647 | 	return retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } | 
 | 649 |  | 
 | 650 | static int hpc_slot_disable(struct slot * slot) | 
 | 651 | { | 
| Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 652 | 	int retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 |  | 
| Kenji Kaneshige | 4085399 | 2006-05-12 11:11:48 +0900 | [diff] [blame] | 654 | 	/* Slot - Disable, Power Indicator - Off, Attention Indicator - On */ | 
 | 655 | 	retval = shpc_write_cmd(slot, slot->hp_slot, | 
 | 656 | 			SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON); | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 657 | 	if (retval) | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 658 | 		ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 |  | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 660 | 	return retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } | 
 | 662 |  | 
| Matthew Wilcox | 3749c51 | 2009-12-13 08:11:32 -0500 | [diff] [blame] | 663 | static int shpc_get_cur_bus_speed(struct controller *ctrl) | 
 | 664 | { | 
 | 665 | 	int retval = 0; | 
 | 666 | 	struct pci_bus *bus = ctrl->pci_dev->subordinate; | 
 | 667 | 	enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; | 
 | 668 | 	u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG); | 
 | 669 | 	u8 pi = shpc_readb(ctrl, PROG_INTERFACE); | 
 | 670 | 	u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7); | 
 | 671 |  | 
 | 672 | 	if ((pi == 1) && (speed_mode > 4)) { | 
 | 673 | 		retval = -ENODEV; | 
 | 674 | 		goto out; | 
 | 675 | 	} | 
 | 676 |  | 
 | 677 | 	switch (speed_mode) { | 
 | 678 | 	case 0x0: | 
 | 679 | 		bus_speed = PCI_SPEED_33MHz; | 
 | 680 | 		break; | 
 | 681 | 	case 0x1: | 
 | 682 | 		bus_speed = PCI_SPEED_66MHz; | 
 | 683 | 		break; | 
 | 684 | 	case 0x2: | 
 | 685 | 		bus_speed = PCI_SPEED_66MHz_PCIX; | 
 | 686 | 		break; | 
 | 687 | 	case 0x3: | 
 | 688 | 		bus_speed = PCI_SPEED_100MHz_PCIX; | 
 | 689 | 		break; | 
 | 690 | 	case 0x4: | 
 | 691 | 		bus_speed = PCI_SPEED_133MHz_PCIX; | 
 | 692 | 		break; | 
 | 693 | 	case 0x5: | 
 | 694 | 		bus_speed = PCI_SPEED_66MHz_PCIX_ECC; | 
 | 695 | 		break; | 
 | 696 | 	case 0x6: | 
 | 697 | 		bus_speed = PCI_SPEED_100MHz_PCIX_ECC; | 
 | 698 | 		break; | 
 | 699 | 	case 0x7: | 
 | 700 | 		bus_speed = PCI_SPEED_133MHz_PCIX_ECC; | 
 | 701 | 		break; | 
 | 702 | 	case 0x8: | 
 | 703 | 		bus_speed = PCI_SPEED_66MHz_PCIX_266; | 
 | 704 | 		break; | 
 | 705 | 	case 0x9: | 
 | 706 | 		bus_speed = PCI_SPEED_100MHz_PCIX_266; | 
 | 707 | 		break; | 
 | 708 | 	case 0xa: | 
 | 709 | 		bus_speed = PCI_SPEED_133MHz_PCIX_266; | 
 | 710 | 		break; | 
 | 711 | 	case 0xb: | 
 | 712 | 		bus_speed = PCI_SPEED_66MHz_PCIX_533; | 
 | 713 | 		break; | 
 | 714 | 	case 0xc: | 
 | 715 | 		bus_speed = PCI_SPEED_100MHz_PCIX_533; | 
 | 716 | 		break; | 
 | 717 | 	case 0xd: | 
 | 718 | 		bus_speed = PCI_SPEED_133MHz_PCIX_533; | 
 | 719 | 		break; | 
 | 720 | 	default: | 
 | 721 | 		retval = -ENODEV; | 
 | 722 | 		break; | 
 | 723 | 	} | 
 | 724 |  | 
 | 725 |  out: | 
 | 726 | 	bus->cur_bus_speed = bus_speed; | 
 | 727 | 	dbg("Current bus speed = %d\n", bus_speed); | 
 | 728 | 	return retval; | 
 | 729 | } | 
 | 730 |  | 
 | 731 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) | 
 | 733 | { | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 734 | 	int retval; | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 735 | 	struct controller *ctrl = slot->ctrl; | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 736 | 	u8 pi, cmd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 738 | 	pi = shpc_readb(ctrl, PROG_INTERFACE); | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 739 | 	if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX)) | 
 | 740 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 |  | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 742 | 	switch (value) { | 
 | 743 | 	case PCI_SPEED_33MHz: | 
 | 744 | 		cmd = SETA_PCI_33MHZ; | 
 | 745 | 		break; | 
 | 746 | 	case PCI_SPEED_66MHz: | 
 | 747 | 		cmd = SETA_PCI_66MHZ; | 
 | 748 | 		break; | 
 | 749 | 	case PCI_SPEED_66MHz_PCIX: | 
 | 750 | 		cmd = SETA_PCIX_66MHZ; | 
 | 751 | 		break; | 
 | 752 | 	case PCI_SPEED_100MHz_PCIX: | 
 | 753 | 		cmd = SETA_PCIX_100MHZ; | 
 | 754 | 		break; | 
 | 755 | 	case PCI_SPEED_133MHz_PCIX: | 
 | 756 | 		cmd = SETA_PCIX_133MHZ; | 
 | 757 | 		break; | 
 | 758 | 	case PCI_SPEED_66MHz_PCIX_ECC: | 
 | 759 | 		cmd = SETB_PCIX_66MHZ_EM; | 
 | 760 | 		break; | 
 | 761 | 	case PCI_SPEED_100MHz_PCIX_ECC: | 
 | 762 | 		cmd = SETB_PCIX_100MHZ_EM; | 
 | 763 | 		break; | 
 | 764 | 	case PCI_SPEED_133MHz_PCIX_ECC: | 
 | 765 | 		cmd = SETB_PCIX_133MHZ_EM; | 
 | 766 | 		break; | 
 | 767 | 	case PCI_SPEED_66MHz_PCIX_266: | 
 | 768 | 		cmd = SETB_PCIX_66MHZ_266; | 
 | 769 | 		break; | 
 | 770 | 	case PCI_SPEED_100MHz_PCIX_266: | 
 | 771 | 		cmd = SETB_PCIX_100MHZ_266; | 
 | 772 | 		break; | 
 | 773 | 	case PCI_SPEED_133MHz_PCIX_266: | 
 | 774 | 		cmd = SETB_PCIX_133MHZ_266; | 
 | 775 | 		break; | 
 | 776 | 	case PCI_SPEED_66MHz_PCIX_533: | 
 | 777 | 		cmd = SETB_PCIX_66MHZ_533; | 
 | 778 | 		break; | 
 | 779 | 	case PCI_SPEED_100MHz_PCIX_533: | 
 | 780 | 		cmd = SETB_PCIX_100MHZ_533; | 
 | 781 | 		break; | 
 | 782 | 	case PCI_SPEED_133MHz_PCIX_533: | 
 | 783 | 		cmd = SETB_PCIX_133MHZ_533; | 
 | 784 | 		break; | 
 | 785 | 	default: | 
 | 786 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | 	} | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 788 |  | 
 | 789 | 	retval = shpc_write_cmd(slot, 0, cmd); | 
 | 790 | 	if (retval) | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 791 | 		ctrl_err(ctrl, "%s: Write command failed!\n", __func__); | 
| Matthew Wilcox | 3749c51 | 2009-12-13 08:11:32 -0500 | [diff] [blame] | 792 | 	else | 
 | 793 | 		shpc_get_cur_bus_speed(ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | 	return retval; | 
 | 796 | } | 
 | 797 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 798 | static irqreturn_t shpc_isr(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 800 | 	struct controller *ctrl = (struct controller *)dev_id; | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 801 | 	u32 serr_int, slot_reg, intr_loc, intr_loc2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | 	int hp_slot; | 
 | 803 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | 	/* Check to see if it was our interrupt */ | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 805 | 	intr_loc = shpc_readl(ctrl, INTR_LOC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | 	if (!intr_loc) | 
 | 807 | 		return IRQ_NONE; | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 808 |  | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 809 | 	ctrl_dbg(ctrl, "%s: intr_loc = %x\n", __func__, intr_loc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 |  | 
 | 811 | 	if(!shpchp_poll_mode) { | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 812 | 		/* | 
 | 813 | 		 * Mask Global Interrupt Mask - see implementation | 
 | 814 | 		 * note on p. 139 of SHPC spec rev 1.0 | 
 | 815 | 		 */ | 
 | 816 | 		serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
 | 817 | 		serr_int |= GLOBAL_INTR_MASK; | 
 | 818 | 		serr_int &= ~SERR_INTR_RSVDZ_MASK; | 
 | 819 | 		shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 821 | 		intr_loc2 = shpc_readl(ctrl, INTR_LOC); | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 822 | 		ctrl_dbg(ctrl, "%s: intr_loc2 = %x\n", __func__, intr_loc2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | 	} | 
 | 824 |  | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 825 | 	if (intr_loc & CMD_INTR_PENDING) { | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 826 | 		/* | 
 | 827 | 		 * Command Complete Interrupt Pending | 
| Kenji Kaneshige | f467f61 | 2005-11-24 11:39:29 +0900 | [diff] [blame] | 828 | 		 * RO only - clear by writing 1 to the Command Completion | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | 		 * Detect bit in Controller SERR-INT register | 
 | 830 | 		 */ | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 831 | 		serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
 | 832 | 		serr_int &= ~SERR_INTR_RSVDZ_MASK; | 
 | 833 | 		shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); | 
 | 834 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | 		wake_up_interruptible(&ctrl->queue); | 
 | 836 | 	} | 
 | 837 |  | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 838 | 	if (!(intr_loc & ~CMD_INTR_PENDING)) | 
| Kenji Kaneshige | e4e7304 | 2006-01-26 10:05:57 +0900 | [diff] [blame] | 839 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 |  | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 841 | 	for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 842 | 		/* To find out which slot has interrupt pending */ | 
 | 843 | 		if (!(intr_loc & SLOT_INTR_PENDING(hp_slot))) | 
 | 844 | 			continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 |  | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 846 | 		slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 847 | 		ctrl_dbg(ctrl, "Slot %x with intr, slot register = %x\n", | 
 | 848 | 			 hp_slot, slot_reg); | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 849 |  | 
 | 850 | 		if (slot_reg & MRL_CHANGE_DETECTED) | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 851 | 			shpchp_handle_switch_change(hp_slot, ctrl); | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 852 |  | 
 | 853 | 		if (slot_reg & BUTTON_PRESS_DETECTED) | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 854 | 			shpchp_handle_attention_button(hp_slot, ctrl); | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 855 |  | 
 | 856 | 		if (slot_reg & PRSNT_CHANGE_DETECTED) | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 857 | 			shpchp_handle_presence_change(hp_slot, ctrl); | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 858 |  | 
 | 859 | 		if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)) | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 860 | 			shpchp_handle_power_fault(hp_slot, ctrl); | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 861 |  | 
 | 862 | 		/* Clear all slot events */ | 
 | 863 | 		slot_reg &= ~SLOT_REG_RSVDZ_MASK; | 
 | 864 | 		shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | 	} | 
| Kenji Kaneshige | e4e7304 | 2006-01-26 10:05:57 +0900 | [diff] [blame] | 866 |  out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | 	if (!shpchp_poll_mode) { | 
 | 868 | 		/* Unmask Global Interrupt Mask */ | 
| Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame] | 869 | 		serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
 | 870 | 		serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK); | 
 | 871 | 		shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | 	} | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 873 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | 	return IRQ_HANDLED; | 
 | 875 | } | 
 | 876 |  | 
| Matthew Wilcox | 3749c51 | 2009-12-13 08:11:32 -0500 | [diff] [blame] | 877 | static int shpc_get_max_bus_speed(struct controller *ctrl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 879 | 	int retval = 0; | 
| Matthew Wilcox | 3749c51 | 2009-12-13 08:11:32 -0500 | [diff] [blame] | 880 | 	struct pci_bus *bus = ctrl->pci_dev->subordinate; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | 	enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 882 | 	u8 pi = shpc_readb(ctrl, PROG_INTERFACE); | 
 | 883 | 	u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1); | 
 | 884 | 	u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | 	if (pi == 2) { | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 887 | 		if (slot_avail2 & SLOT_133MHZ_PCIX_533) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 888 | 			bus_speed = PCI_SPEED_133MHz_PCIX_533; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 889 | 		else if (slot_avail2 & SLOT_100MHZ_PCIX_533) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 890 | 			bus_speed = PCI_SPEED_100MHz_PCIX_533; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 891 | 		else if (slot_avail2 & SLOT_66MHZ_PCIX_533) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 892 | 			bus_speed = PCI_SPEED_66MHz_PCIX_533; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 893 | 		else if (slot_avail2 & SLOT_133MHZ_PCIX_266) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 894 | 			bus_speed = PCI_SPEED_133MHz_PCIX_266; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 895 | 		else if (slot_avail2 & SLOT_100MHZ_PCIX_266) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 896 | 			bus_speed = PCI_SPEED_100MHz_PCIX_266; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 897 | 		else if (slot_avail2 & SLOT_66MHZ_PCIX_266) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 898 | 			bus_speed = PCI_SPEED_66MHz_PCIX_266; | 
 | 899 | 	} | 
 | 900 |  | 
 | 901 | 	if (bus_speed == PCI_SPEED_UNKNOWN) { | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 902 | 		if (slot_avail1 & SLOT_133MHZ_PCIX) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 903 | 			bus_speed = PCI_SPEED_133MHz_PCIX; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 904 | 		else if (slot_avail1 & SLOT_100MHZ_PCIX) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 905 | 			bus_speed = PCI_SPEED_100MHz_PCIX; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 906 | 		else if (slot_avail1 & SLOT_66MHZ_PCIX) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 907 | 			bus_speed = PCI_SPEED_66MHz_PCIX; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 908 | 		else if (slot_avail2 & SLOT_66MHZ) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 909 | 			bus_speed = PCI_SPEED_66MHz; | 
| Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 910 | 		else if (slot_avail1 & SLOT_33MHZ) | 
| Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 911 | 			bus_speed = PCI_SPEED_33MHz; | 
 | 912 | 		else | 
 | 913 | 			retval = -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | 	} | 
 | 915 |  | 
| Matthew Wilcox | 3749c51 | 2009-12-13 08:11:32 -0500 | [diff] [blame] | 916 | 	bus->max_bus_speed = bus_speed; | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 917 | 	ctrl_dbg(ctrl, "Max bus speed = %d\n", bus_speed); | 
| Kenji Kaneshige | 1555b33 | 2007-01-09 13:03:01 -0800 | [diff] [blame] | 918 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | 	return retval; | 
 | 920 | } | 
 | 921 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | static struct hpc_ops shpchp_hpc_ops = { | 
 | 923 | 	.power_on_slot			= hpc_power_on_slot, | 
 | 924 | 	.slot_enable			= hpc_slot_enable, | 
 | 925 | 	.slot_disable			= hpc_slot_disable, | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 926 | 	.set_bus_speed_mode		= hpc_set_bus_speed_mode, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | 	.set_attention_status	= hpc_set_attention_status, | 
 | 928 | 	.get_power_status		= hpc_get_power_status, | 
 | 929 | 	.get_attention_status	= hpc_get_attention_status, | 
 | 930 | 	.get_latch_status		= hpc_get_latch_status, | 
 | 931 | 	.get_adapter_status		= hpc_get_adapter_status, | 
 | 932 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | 	.get_adapter_speed		= hpc_get_adapter_speed, | 
 | 934 | 	.get_mode1_ECC_cap		= hpc_get_mode1_ECC_cap, | 
 | 935 | 	.get_prog_int			= hpc_get_prog_int, | 
 | 936 |  | 
 | 937 | 	.query_power_fault		= hpc_query_power_fault, | 
 | 938 | 	.green_led_on			= hpc_set_green_led_on, | 
 | 939 | 	.green_led_off			= hpc_set_green_led_off, | 
 | 940 | 	.green_led_blink		= hpc_set_green_led_blink, | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 941 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | 	.release_ctlr			= hpc_release_ctlr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | }; | 
 | 944 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 945 | int shpc_init(struct controller *ctrl, struct pci_dev *pdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 947 | 	int rc = -1, num_slots = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | 	u8 hp_slot; | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 949 | 	u32 shpc_base_offset; | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 950 | 	u32 tempdword, slot_reg, slot_config; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | 	u8 i; | 
 | 952 |  | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 953 | 	ctrl->pci_dev = pdev;  /* pci_dev of the P2P bridge */ | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 954 | 	ctrl_dbg(ctrl, "Hotplug Controller:\n"); | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 955 |  | 
| rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 956 | 	if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == | 
 | 957 | 				PCI_DEVICE_ID_AMD_GOLAM_7450)) { | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 958 | 		/* amd shpc driver doesn't use Base Offset; assume 0 */ | 
 | 959 | 		ctrl->mmio_base = pci_resource_start(pdev, 0); | 
 | 960 | 		ctrl->mmio_size = pci_resource_len(pdev, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | 	} else { | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 962 | 		ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC); | 
 | 963 | 		if (!ctrl->cap_offset) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 964 | 			ctrl_err(ctrl, "Cannot find PCI capability\n"); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 965 | 			goto abort; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | 		} | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 967 | 		ctrl_dbg(ctrl, " cap_offset = %x\n", ctrl->cap_offset); | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 968 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 969 | 		rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | 		if (rc) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 971 | 			ctrl_err(ctrl, "Cannot read base_offset\n"); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 972 | 			goto abort; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | 		} | 
 | 974 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 975 | 		rc = shpc_indirect_read(ctrl, 3, &tempdword); | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 976 | 		if (rc) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 977 | 			ctrl_err(ctrl, "Cannot read slot config\n"); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 978 | 			goto abort; | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 979 | 		} | 
 | 980 | 		num_slots = tempdword & SLOT_NUM; | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 981 | 		ctrl_dbg(ctrl, " num_slots (indirect) %x\n", num_slots); | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 982 |  | 
 | 983 | 		for (i = 0; i < 9 + num_slots; i++) { | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 984 | 			rc = shpc_indirect_read(ctrl, i, &tempdword); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | 			if (rc) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 986 | 				ctrl_err(ctrl, | 
 | 987 | 					 "Cannot read creg (index = %d)\n", i); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 988 | 				goto abort; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | 			} | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 990 | 			ctrl_dbg(ctrl, " offset %d: value %x\n", i, tempdword); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | 		} | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 992 |  | 
 | 993 | 		ctrl->mmio_base = | 
 | 994 | 			pci_resource_start(pdev, 0) + shpc_base_offset; | 
 | 995 | 		ctrl->mmio_size = 0x24 + 0x4 * num_slots; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | 	} | 
 | 997 |  | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 998 | 	ctrl_info(ctrl, "HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", | 
 | 999 | 		  pdev->vendor, pdev->device, pdev->subsystem_vendor, | 
 | 1000 | 		  pdev->subsystem_device); | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 1001 |  | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1002 | 	rc = pci_enable_device(pdev); | 
 | 1003 | 	if (rc) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1004 | 		ctrl_err(ctrl, "pci_enable_device failed\n"); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1005 | 		goto abort; | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1006 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 |  | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1008 | 	if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1009 | 		ctrl_err(ctrl, "Cannot reserve MMIO region\n"); | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1010 | 		rc = -1; | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1011 | 		goto abort; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | 	} | 
 | 1013 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1014 | 	ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size); | 
 | 1015 | 	if (!ctrl->creg) { | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1016 | 		ctrl_err(ctrl, "Cannot remap MMIO region %lx @ %lx\n", | 
 | 1017 | 			 ctrl->mmio_size, ctrl->mmio_base); | 
| Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1018 | 		release_mem_region(ctrl->mmio_base, ctrl->mmio_size); | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1019 | 		rc = -1; | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1020 | 		goto abort; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | 	} | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1022 | 	ctrl_dbg(ctrl, "ctrl->creg %p\n", ctrl->creg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 |  | 
| Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1024 | 	mutex_init(&ctrl->crit_sect); | 
| Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 1025 | 	mutex_init(&ctrl->cmd_lock); | 
 | 1026 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | 	/* Setup wait queue */ | 
 | 1028 | 	init_waitqueue_head(&ctrl->queue); | 
 | 1029 |  | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1030 | 	ctrl->hpc_ops = &shpchp_hpc_ops; | 
 | 1031 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | 	/* Return PCI Controller Info */ | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1033 | 	slot_config = shpc_readl(ctrl, SLOT_CONFIG); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1034 | 	ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8; | 
 | 1035 | 	ctrl->num_slots = slot_config & SLOT_NUM; | 
 | 1036 | 	ctrl->first_slot = (slot_config & PSN) >> 16; | 
 | 1037 | 	ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 |  | 
 | 1039 | 	/* Mask Global Interrupt Mask & Command Complete Interrupt Mask */ | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1040 | 	tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1041 | 	ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword); | 
| Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 1042 | 	tempdword |= (GLOBAL_INTR_MASK  | GLOBAL_SERR_MASK | | 
 | 1043 | 		      COMMAND_INTR_MASK | ARBITER_SERR_MASK); | 
 | 1044 | 	tempdword &= ~SERR_INTR_RSVDZ_MASK; | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1045 | 	shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); | 
 | 1046 | 	tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1047 | 	ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 |  | 
 | 1049 | 	/* Mask the MRL sensor SERR Mask of individual slot in | 
 | 1050 | 	 * Slot SERR-INT Mask & clear all the existing event if any | 
 | 1051 | 	 */ | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1052 | 	for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { | 
| Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 1053 | 		slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1054 | 		ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n", | 
 | 1055 | 			 hp_slot, slot_reg); | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1056 | 		slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | | 
 | 1057 | 			     BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | | 
 | 1058 | 			     CON_PFAULT_INTR_MASK   | MRL_CHANGE_SERR_MASK | | 
 | 1059 | 			     CON_PFAULT_SERR_MASK); | 
 | 1060 | 		slot_reg &= ~SLOT_REG_RSVDZ_MASK; | 
 | 1061 | 		shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | 	} | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 1063 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1064 | 	if (shpchp_poll_mode) { | 
 | 1065 | 		/* Install interrupt polling timer. Start with 10 sec delay */ | 
 | 1066 | 		init_timer(&ctrl->poll_timer); | 
 | 1067 | 		start_int_poll_timer(ctrl, 10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | 	} else { | 
 | 1069 | 		/* Installs the interrupt handler */ | 
 | 1070 | 		rc = pci_enable_msi(pdev); | 
 | 1071 | 		if (rc) { | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 1072 | 			ctrl_info(ctrl, | 
 | 1073 | 				  "Can't get msi for the hotplug controller\n"); | 
 | 1074 | 			ctrl_info(ctrl, | 
 | 1075 | 				  "Use INTx for the hotplug controller\n"); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1076 | 		} | 
| Kenji Kaneshige | 9f593e3 | 2007-01-09 13:03:10 -0800 | [diff] [blame] | 1077 |  | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1078 | 		rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED, | 
 | 1079 | 				 MY_NAME, (void *)ctrl); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1080 | 		ctrl_dbg(ctrl, "request_irq %d for hpc%d (returns %d)\n", | 
 | 1081 | 			 ctrl->pci_dev->irq, | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1082 | 		    atomic_read(&shpchp_num_controllers), rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | 		if (rc) { | 
| Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 1084 | 			ctrl_err(ctrl, "Can't get irq %d for the hotplug " | 
 | 1085 | 				 "controller\n", ctrl->pci_dev->irq); | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1086 | 			goto abort_iounmap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | 	} | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1089 | 	ctrl_dbg(ctrl, "HPC at %s irq=%x\n", pci_name(pdev), pdev->irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 |  | 
| Matthew Wilcox | 3749c51 | 2009-12-13 08:11:32 -0500 | [diff] [blame] | 1091 | 	shpc_get_max_bus_speed(ctrl); | 
 | 1092 | 	shpc_get_cur_bus_speed(ctrl); | 
 | 1093 |  | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1094 | 	/* | 
| Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 1095 | 	 * If this is the first controller to be initialized, | 
 | 1096 | 	 * initialize the shpchpd work queue | 
 | 1097 | 	 */ | 
 | 1098 | 	if (atomic_add_return(1, &shpchp_num_controllers) == 1) { | 
 | 1099 | 		shpchp_wq = create_singlethread_workqueue("shpchpd"); | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1100 | 		if (!shpchp_wq) { | 
 | 1101 | 			rc = -ENOMEM; | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1102 | 			goto abort_iounmap; | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1103 | 		} | 
| Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 1104 | 	} | 
 | 1105 |  | 
 | 1106 | 	/* | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1107 | 	 * Unmask all event interrupts of all slots | 
 | 1108 | 	 */ | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1109 | 	for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { | 
| Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 1110 | 		slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1111 | 		ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n", | 
 | 1112 | 			 hp_slot, slot_reg); | 
| Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1113 | 		slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | | 
 | 1114 | 			      BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | | 
 | 1115 | 			      CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK); | 
 | 1116 | 		shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | 	} | 
 | 1118 | 	if (!shpchp_poll_mode) { | 
 | 1119 | 		/* Unmask all general input interrupts and SERR */ | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1120 | 		tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
| Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 1121 | 		tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK | | 
 | 1122 | 			       SERR_INTR_RSVDZ_MASK); | 
| Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1123 | 		shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); | 
 | 1124 | 		tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); | 
| Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 1125 | 		ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | 	} | 
 | 1127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | 	return 0; | 
 | 1129 |  | 
 | 1130 | 	/* We end up here for the many possible ways to fail this API.  */ | 
| Kenji Kaneshige | 0abe68c | 2006-12-16 15:25:34 -0800 | [diff] [blame] | 1131 | abort_iounmap: | 
 | 1132 | 	iounmap(ctrl->creg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | abort: | 
| Amol Lad | 662a98f | 2006-10-05 12:07:32 +0530 | [diff] [blame] | 1134 | 	return rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |