blob: df41ecc4e7fcb7788cb7ea870a94b155a599b128 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Standard Hot Plug Controller Driver
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
Kristen Accardi8cf4c192005-08-16 15:16:10 -070026 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kernel.h>
33#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/pci.h>
Kenji Kaneshigef7391f52006-02-21 15:45:45 -080035#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "shpchp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/* Global variables */
39int shpchp_debug;
40int shpchp_poll_mode;
41int shpchp_poll_time;
Adrian Bunk552fe042008-05-05 21:21:51 +030042static int shpchp_slot_with_bus;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -080043struct workqueue_struct *shpchp_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#define DRIVER_VERSION "0.4"
46#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
47#define DRIVER_DESC "Standard Hot Plug PCI Controller Driver"
48
49MODULE_AUTHOR(DRIVER_AUTHOR);
50MODULE_DESCRIPTION(DRIVER_DESC);
51MODULE_LICENSE("GPL");
52
53module_param(shpchp_debug, bool, 0644);
54module_param(shpchp_poll_mode, bool, 0644);
55module_param(shpchp_poll_time, int, 0644);
Kenji Kaneshigeef0ff952008-04-25 14:39:12 -070056module_param(shpchp_slot_with_bus, bool, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not");
58MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not");
59MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds");
Kenji Kaneshigeef0ff952008-04-25 14:39:12 -070060MODULE_PARM_DESC(shpchp_slot_with_bus, "Use bus number in the slot name");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#define SHPC_MODULE_NAME "shpchp"
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int set_attention_status (struct hotplug_slot *slot, u8 value);
65static int enable_slot (struct hotplug_slot *slot);
66static int disable_slot (struct hotplug_slot *slot);
67static int get_power_status (struct hotplug_slot *slot, u8 *value);
68static int get_attention_status (struct hotplug_slot *slot, u8 *value);
69static int get_latch_status (struct hotplug_slot *slot, u8 *value);
70static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
Kenji Kaneshige81f15442005-12-05 19:31:00 +090071static int get_address (struct hotplug_slot *slot, u32 *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
73static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
74
75static struct hotplug_slot_ops shpchp_hotplug_slot_ops = {
76 .owner = THIS_MODULE,
77 .set_attention_status = set_attention_status,
78 .enable_slot = enable_slot,
79 .disable_slot = disable_slot,
80 .get_power_status = get_power_status,
81 .get_attention_status = get_attention_status,
82 .get_latch_status = get_latch_status,
83 .get_adapter_status = get_adapter_status,
Kenji Kaneshige81f15442005-12-05 19:31:00 +090084 .get_address = get_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 .get_max_bus_speed = get_max_bus_speed,
86 .get_cur_bus_speed = get_cur_bus_speed,
87};
88
89/**
90 * release_slot - free up the memory used by a slot
91 * @hotplug_slot: slot to free
92 */
93static void release_slot(struct hotplug_slot *hotplug_slot)
94{
Dely Syee17fd92005-05-05 11:57:25 -070095 struct slot *slot = hotplug_slot->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Harvey Harrison66bef8c2008-03-03 19:09:46 -080097 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 kfree(slot->hotplug_slot->info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 kfree(slot->hotplug_slot);
101 kfree(slot);
102}
103
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900104static void make_slot_name(struct slot *slot)
105{
Kenji Kaneshigeef0ff952008-04-25 14:39:12 -0700106 if (shpchp_slot_with_bus)
107 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
108 slot->bus, slot->number);
109 else
110 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d",
111 slot->number);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static int init_slots(struct controller *ctrl)
115{
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900116 struct slot *slot;
117 struct hotplug_slot *hotplug_slot;
118 struct hotplug_slot_info *info;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900119 int retval = -ENOMEM;
120 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900122 for (i = 0; i < ctrl->num_slots; i++) {
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900123 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900124 if (!slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 goto error;
126
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900127 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900128 if (!hotplug_slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 goto error_slot;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900130 slot->hotplug_slot = hotplug_slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900132 info = kzalloc(sizeof(*info), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900133 if (!info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 goto error_hpslot;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900135 hotplug_slot->info = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900137 hotplug_slot->name = slot->name;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900138
139 slot->hp_slot = i;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900140 slot->ctrl = ctrl;
Kenji Kaneshige227b84c2006-12-16 15:25:42 -0800141 slot->bus = ctrl->pci_dev->subordinate->number;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900142 slot->device = ctrl->slot_device_offset + i;
143 slot->hpc_ops = ctrl->hpc_ops;
Kenji Kaneshige6f39be22006-12-16 15:25:49 -0800144 slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i);
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800145 mutex_init(&slot->lock);
Kristen Carlson Accardie325e1f2007-03-21 11:45:31 -0700146 INIT_DELAYED_WORK(&slot->work, shpchp_queue_pushbutton_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* register this slot with the hotplug pci core */
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900149 hotplug_slot->private = slot;
150 hotplug_slot->release = &release_slot;
151 make_slot_name(slot);
152 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900154 get_power_status(hotplug_slot, &info->power_status);
155 get_attention_status(hotplug_slot, &info->attention_status);
156 get_latch_status(hotplug_slot, &info->latch_status);
157 get_adapter_status(hotplug_slot, &info->adapter_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900159 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
160 "slot_device_offset=%x\n", slot->bus, slot->device,
161 slot->hp_slot, slot->number, ctrl->slot_device_offset);
162 retval = pci_hp_register(slot->hotplug_slot);
163 if (retval) {
164 err("pci_hp_register failed with error %d\n", retval);
Kenji Kaneshigeb3bd3072008-05-27 19:08:23 +0900165 if (retval == -EEXIST)
166 err("Failed to register slot because of name "
167 "collision. Try \'shpchp_slot_with_bus\' "
168 "module option.\n");
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900169 goto error_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900172 list_add(&slot->slot_list, &ctrl->slot_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
175 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176error_info:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900177 kfree(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178error_hpslot:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900179 kfree(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180error_slot:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900181 kfree(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182error:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900183 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800186void cleanup_slots(struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900188 struct list_head *tmp;
189 struct list_head *next;
190 struct slot *slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900192 list_for_each_safe(tmp, next, &ctrl->slot_list) {
193 slot = list_entry(tmp, struct slot, slot_list);
194 list_del(&slot->slot_list);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800195 cancel_delayed_work(&slot->work);
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800196 flush_scheduled_work();
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800197 flush_workqueue(shpchp_wq);
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900198 pci_hp_deregister(slot->hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/*
203 * set_attention_status - Turns the Amber LED for a slot on, off or blink
204 */
205static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
206{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800207 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800209 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 hotplug_slot->info->attention_status = status;
212 slot->hpc_ops->set_attention_status(slot, status);
213
214 return 0;
215}
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217static int enable_slot (struct hotplug_slot *hotplug_slot)
218{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800219 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800221 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800223 return shpchp_sysfs_enable_slot(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static int disable_slot (struct hotplug_slot *hotplug_slot)
227{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800228 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800230 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800232 return shpchp_sysfs_disable_slot(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
236{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800237 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 int retval;
239
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800240 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 retval = slot->hpc_ops->get_power_status(slot, value);
243 if (retval < 0)
244 *value = hotplug_slot->info->power_status;
245
246 return 0;
247}
248
249static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
250{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800251 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 int retval;
253
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800254 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 retval = slot->hpc_ops->get_attention_status(slot, value);
257 if (retval < 0)
258 *value = hotplug_slot->info->attention_status;
259
260 return 0;
261}
262
263static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
264{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800265 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 int retval;
267
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800268 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 retval = slot->hpc_ops->get_latch_status(slot, value);
271 if (retval < 0)
272 *value = hotplug_slot->info->latch_status;
273
274 return 0;
275}
276
277static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
278{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800279 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 int retval;
281
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800282 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 retval = slot->hpc_ops->get_adapter_status(slot, value);
285 if (retval < 0)
286 *value = hotplug_slot->info->adapter_status;
287
288 return 0;
289}
290
Kenji Kaneshige81f15442005-12-05 19:31:00 +0900291static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
292{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800293 struct slot *slot = get_slot(hotplug_slot);
Kenji Kaneshige81f15442005-12-05 19:31:00 +0900294 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
295
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800296 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Kenji Kaneshige81f15442005-12-05 19:31:00 +0900297
298 *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device;
299
300 return 0;
301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
304{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800305 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 int retval;
307
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800308 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
311 if (retval < 0)
312 *value = PCI_SPEED_UNKNOWN;
313
314 return 0;
315}
316
317static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
318{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800319 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 int retval;
321
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800322 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
325 if (retval < 0)
326 *value = PCI_SPEED_UNKNOWN;
327
328 return 0;
329}
330
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700331static int is_shpc_capable(struct pci_dev *dev)
332{
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900333 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device ==
334 PCI_DEVICE_ID_AMD_GOLAM_7450))
335 return 1;
336 if (!pci_find_capability(dev, PCI_CAP_ID_SHPC))
337 return 0;
338 if (get_hp_hw_control_from_firmware(dev))
339 return 0;
340 return 1;
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700341}
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
344{
345 int rc;
346 struct controller *ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700348 if (!is_shpc_capable(pdev))
349 return -ENODEV;
350
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900351 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 if (!ctrl) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800353 err("%s : out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 goto err_out_none;
355 }
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900356 INIT_LIST_HEAD(&ctrl->slot_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700358 rc = shpc_init(ctrl, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (rc) {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900360 dbg("%s: controller initialization failed\n",
361 SHPC_MODULE_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 goto err_out_free_ctrl;
363 }
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 pci_set_drvdata(pdev, ctrl);
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* Setup the slot information structures */
368 rc = init_slots(ctrl);
369 if (rc) {
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800370 err("%s: slot initialization failed\n", SHPC_MODULE_NAME);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800371 goto err_out_release_ctlr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
373
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -0700374 rc = shpchp_create_ctrl_files(ctrl);
375 if (rc)
376 goto err_cleanup_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 return 0;
379
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -0700380err_cleanup_slots:
381 cleanup_slots(ctrl);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800382err_out_release_ctlr:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 ctrl->hpc_ops->release_ctlr(ctrl);
384err_out_free_ctrl:
385 kfree(ctrl);
386err_out_none:
387 return -ENODEV;
388}
389
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800390static void shpc_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800392 struct controller *ctrl = pci_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800394 shpchp_remove_ctrl_files(ctrl);
395 ctrl->hpc_ops->release_ctlr(ctrl);
396 kfree(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399static struct pci_device_id shpcd_pci_tbl[] = {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900400 {PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 { /* end: all zeroes */ }
402};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403MODULE_DEVICE_TABLE(pci, shpcd_pci_tbl);
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405static struct pci_driver shpc_driver = {
406 .name = SHPC_MODULE_NAME,
407 .id_table = shpcd_pci_tbl,
408 .probe = shpc_probe,
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800409 .remove = shpc_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410};
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412static int __init shpcd_init(void)
413{
414 int retval = 0;
415
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700416 retval = pci_register_driver(&shpc_driver);
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800417 dbg("%s: pci_register_driver = %d\n", __func__, retval);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700418 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return retval;
420}
421
422static void __exit shpcd_cleanup(void)
423{
424 dbg("unload_shpchpd()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 pci_unregister_driver(&shpc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
427}
428
429module_init(shpcd_init);
430module_exit(shpcd_cleanup);