blob: a8cbd039b85bfde22a4f6e019d8de62cb5714f9e [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);
71static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
72static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
73
74static struct hotplug_slot_ops shpchp_hotplug_slot_ops = {
75 .owner = THIS_MODULE,
76 .set_attention_status = set_attention_status,
77 .enable_slot = enable_slot,
78 .disable_slot = disable_slot,
79 .get_power_status = get_power_status,
80 .get_attention_status = get_attention_status,
81 .get_latch_status = get_latch_status,
82 .get_adapter_status = get_adapter_status,
83 .get_max_bus_speed = get_max_bus_speed,
84 .get_cur_bus_speed = get_cur_bus_speed,
85};
86
87/**
88 * release_slot - free up the memory used by a slot
89 * @hotplug_slot: slot to free
90 */
91static void release_slot(struct hotplug_slot *hotplug_slot)
92{
Dely Syee17fd92005-05-05 11:57:25 -070093 struct slot *slot = hotplug_slot->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Harvey Harrison66bef8c2008-03-03 19:09:46 -080095 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 kfree(slot->hotplug_slot->info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 kfree(slot->hotplug_slot);
99 kfree(slot);
100}
101
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900102static void make_slot_name(struct slot *slot)
103{
Kenji Kaneshigeef0ff952008-04-25 14:39:12 -0700104 if (shpchp_slot_with_bus)
105 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
106 slot->bus, slot->number);
107 else
108 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d",
109 slot->number);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int init_slots(struct controller *ctrl)
113{
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900114 struct slot *slot;
115 struct hotplug_slot *hotplug_slot;
116 struct hotplug_slot_info *info;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900117 int retval = -ENOMEM;
118 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900120 for (i = 0; i < ctrl->num_slots; i++) {
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900121 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900122 if (!slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 goto error;
124
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900125 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900126 if (!hotplug_slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 goto error_slot;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900128 slot->hotplug_slot = hotplug_slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900130 info = kzalloc(sizeof(*info), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900131 if (!info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 goto error_hpslot;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900133 hotplug_slot->info = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900135 hotplug_slot->name = slot->name;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900136
137 slot->hp_slot = i;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900138 slot->ctrl = ctrl;
Kenji Kaneshige227b84c2006-12-16 15:25:42 -0800139 slot->bus = ctrl->pci_dev->subordinate->number;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900140 slot->device = ctrl->slot_device_offset + i;
141 slot->hpc_ops = ctrl->hpc_ops;
Kenji Kaneshige6f39be22006-12-16 15:25:49 -0800142 slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i);
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800143 mutex_init(&slot->lock);
Kristen Carlson Accardie325e1f2007-03-21 11:45:31 -0700144 INIT_DELAYED_WORK(&slot->work, shpchp_queue_pushbutton_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* register this slot with the hotplug pci core */
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900147 hotplug_slot->private = slot;
148 hotplug_slot->release = &release_slot;
149 make_slot_name(slot);
150 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900152 get_power_status(hotplug_slot, &info->power_status);
153 get_attention_status(hotplug_slot, &info->attention_status);
154 get_latch_status(hotplug_slot, &info->latch_status);
155 get_adapter_status(hotplug_slot, &info->adapter_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900157 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
158 "slot_device_offset=%x\n", slot->bus, slot->device,
159 slot->hp_slot, slot->number, ctrl->slot_device_offset);
Alex Chiangf46753c2008-06-10 15:28:50 -0600160 retval = pci_hp_register(slot->hotplug_slot,
161 ctrl->pci_dev->subordinate, slot->device);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900162 if (retval) {
163 err("pci_hp_register failed with error %d\n", retval);
Kenji Kaneshigeb3bd3072008-05-27 19:08:23 +0900164 if (retval == -EEXIST)
165 err("Failed to register slot because of name "
166 "collision. Try \'shpchp_slot_with_bus\' "
167 "module option.\n");
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900168 goto error_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
170
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900171 list_add(&slot->slot_list, &ctrl->slot_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
174 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175error_info:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900176 kfree(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177error_hpslot:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900178 kfree(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179error_slot:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900180 kfree(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181error:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900182 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800185void cleanup_slots(struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900187 struct list_head *tmp;
188 struct list_head *next;
189 struct slot *slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900191 list_for_each_safe(tmp, next, &ctrl->slot_list) {
192 slot = list_entry(tmp, struct slot, slot_list);
193 list_del(&slot->slot_list);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800194 cancel_delayed_work(&slot->work);
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800195 flush_scheduled_work();
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800196 flush_workqueue(shpchp_wq);
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900197 pci_hp_deregister(slot->hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
199}
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*
202 * set_attention_status - Turns the Amber LED for a slot on, off or blink
203 */
204static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
205{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800206 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800208 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 hotplug_slot->info->attention_status = status;
211 slot->hpc_ops->set_attention_status(slot, status);
212
213 return 0;
214}
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216static int enable_slot (struct hotplug_slot *hotplug_slot)
217{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800218 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800220 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800222 return shpchp_sysfs_enable_slot(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225static int disable_slot (struct hotplug_slot *hotplug_slot)
226{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800227 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800229 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800231 return shpchp_sysfs_disable_slot(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
234static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
235{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800236 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 int retval;
238
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800239 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 retval = slot->hpc_ops->get_power_status(slot, value);
242 if (retval < 0)
243 *value = hotplug_slot->info->power_status;
244
245 return 0;
246}
247
248static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
249{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800250 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 int retval;
252
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800253 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 retval = slot->hpc_ops->get_attention_status(slot, value);
256 if (retval < 0)
257 *value = hotplug_slot->info->attention_status;
258
259 return 0;
260}
261
262static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
263{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800264 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 int retval;
266
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800267 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 retval = slot->hpc_ops->get_latch_status(slot, value);
270 if (retval < 0)
271 *value = hotplug_slot->info->latch_status;
272
273 return 0;
274}
275
276static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
277{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800278 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 int retval;
280
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800281 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 retval = slot->hpc_ops->get_adapter_status(slot, value);
284 if (retval < 0)
285 *value = hotplug_slot->info->adapter_status;
286
287 return 0;
288}
289
Alex Chiangf46753c2008-06-10 15:28:50 -0600290static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
291 enum pci_bus_speed *value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800293 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 int retval;
295
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800296 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
299 if (retval < 0)
300 *value = PCI_SPEED_UNKNOWN;
301
302 return 0;
303}
304
305static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
306{
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800307 struct slot *slot = get_slot(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 int retval;
309
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800310 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
313 if (retval < 0)
314 *value = PCI_SPEED_UNKNOWN;
315
316 return 0;
317}
318
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700319static int is_shpc_capable(struct pci_dev *dev)
320{
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900321 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device ==
322 PCI_DEVICE_ID_AMD_GOLAM_7450))
323 return 1;
324 if (!pci_find_capability(dev, PCI_CAP_ID_SHPC))
325 return 0;
326 if (get_hp_hw_control_from_firmware(dev))
327 return 0;
328 return 1;
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
332{
333 int rc;
334 struct controller *ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700336 if (!is_shpc_capable(pdev))
337 return -ENODEV;
338
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900339 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (!ctrl) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800341 err("%s : out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 goto err_out_none;
343 }
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900344 INIT_LIST_HEAD(&ctrl->slot_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700346 rc = shpc_init(ctrl, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (rc) {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900348 dbg("%s: controller initialization failed\n",
349 SHPC_MODULE_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 goto err_out_free_ctrl;
351 }
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 pci_set_drvdata(pdev, ctrl);
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /* Setup the slot information structures */
356 rc = init_slots(ctrl);
357 if (rc) {
Kenji Kaneshige8352e042006-12-16 15:25:57 -0800358 err("%s: slot initialization failed\n", SHPC_MODULE_NAME);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800359 goto err_out_release_ctlr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -0700362 rc = shpchp_create_ctrl_files(ctrl);
363 if (rc)
364 goto err_cleanup_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 return 0;
367
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -0700368err_cleanup_slots:
369 cleanup_slots(ctrl);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800370err_out_release_ctlr:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 ctrl->hpc_ops->release_ctlr(ctrl);
372err_out_free_ctrl:
373 kfree(ctrl);
374err_out_none:
375 return -ENODEV;
376}
377
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800378static void shpc_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800380 struct controller *ctrl = pci_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800382 shpchp_remove_ctrl_files(ctrl);
383 ctrl->hpc_ops->release_ctlr(ctrl);
384 kfree(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387static struct pci_device_id shpcd_pci_tbl[] = {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900388 {PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 { /* end: all zeroes */ }
390};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391MODULE_DEVICE_TABLE(pci, shpcd_pci_tbl);
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393static struct pci_driver shpc_driver = {
394 .name = SHPC_MODULE_NAME,
395 .id_table = shpcd_pci_tbl,
396 .probe = shpc_probe,
Kenji Kaneshigee6b82b132006-02-21 15:45:50 -0800397 .remove = shpc_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398};
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400static int __init shpcd_init(void)
401{
402 int retval = 0;
403
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700404 retval = pci_register_driver(&shpc_driver);
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800405 dbg("%s: pci_register_driver = %d\n", __func__, retval);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700406 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return retval;
408}
409
410static void __exit shpcd_cleanup(void)
411{
412 dbg("unload_shpchpd()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 pci_unregister_driver(&shpc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
415}
416
417module_init(shpcd_init);
418module_exit(shpcd_cleanup);