[PATCH] shpchp: Remove unused wait_for_ctrl_irq
[linux-2.6/libata-dev.git] / drivers / pci / hotplug / shpchp_ctrl.c
blobb709328a41451845a5b3c57c4cd0a8b483d81eac
1 /*
2 * Standard Hot Plug Controller Driver
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
9 * All rights reserved.
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.
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.
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.
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/smp_lock.h>
34 #include <linux/pci.h>
35 #include "../pci.h"
36 #include "shpchp.h"
38 static void interrupt_event_handler(struct controller *ctrl);
40 static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
41 static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
42 static int event_finished;
43 static unsigned long pushbutton_pending; /* = 0 */
45 u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
47 struct controller *ctrl = (struct controller *) inst_id;
48 struct slot *p_slot;
49 u8 rc = 0;
50 u8 getstatus;
51 struct event_info *taskInfo;
53 /* Attention Button Change */
54 dbg("shpchp: Attention button interrupt received.\n");
56 /* This is the structure that tells the worker thread what to do */
57 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
58 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
60 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
61 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
63 ctrl->next_event = (ctrl->next_event + 1) % 10;
64 taskInfo->hp_slot = hp_slot;
66 rc++;
69 * Button pressed - See if need to TAKE ACTION!!!
71 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
72 taskInfo->event_type = INT_BUTTON_PRESS;
74 if ((p_slot->state == BLINKINGON_STATE)
75 || (p_slot->state == BLINKINGOFF_STATE)) {
76 /* Cancel if we are still blinking; this means that we press the
77 * attention again before the 5 sec. limit expires to cancel hot-add
78 * or hot-remove
80 taskInfo->event_type = INT_BUTTON_CANCEL;
81 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
82 } else if ((p_slot->state == POWERON_STATE)
83 || (p_slot->state == POWEROFF_STATE)) {
84 /* Ignore if the slot is on power-on or power-off state; this
85 * means that the previous attention button action to hot-add or
86 * hot-remove is undergoing
88 taskInfo->event_type = INT_BUTTON_IGNORE;
89 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
92 if (rc)
93 up(&event_semaphore); /* signal event thread that new event is posted */
95 return 0;
99 u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
101 struct controller *ctrl = (struct controller *) inst_id;
102 struct slot *p_slot;
103 u8 rc = 0;
104 u8 getstatus;
105 struct event_info *taskInfo;
107 /* Switch Change */
108 dbg("shpchp: Switch interrupt received.\n");
110 /* This is the structure that tells the worker thread
111 * what to do
113 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
114 ctrl->next_event = (ctrl->next_event + 1) % 10;
115 taskInfo->hp_slot = hp_slot;
117 rc++;
118 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
119 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
120 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
121 dbg("%s: Card present %x Power status %x\n", __FUNCTION__,
122 p_slot->presence_save, p_slot->pwr_save);
124 if (getstatus) {
126 * Switch opened
128 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
129 taskInfo->event_type = INT_SWITCH_OPEN;
130 if (p_slot->pwr_save && p_slot->presence_save) {
131 taskInfo->event_type = INT_POWER_FAULT;
132 err("Surprise Removal of card\n");
134 } else {
136 * Switch closed
138 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
139 taskInfo->event_type = INT_SWITCH_CLOSE;
142 if (rc)
143 up(&event_semaphore); /* signal event thread that new event is posted */
145 return rc;
148 u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
150 struct controller *ctrl = (struct controller *) inst_id;
151 struct slot *p_slot;
152 u8 rc = 0;
153 /*u8 temp_byte;*/
154 struct event_info *taskInfo;
156 /* Presence Change */
157 dbg("shpchp: Presence/Notify input change.\n");
159 /* This is the structure that tells the worker thread
160 * what to do
162 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
163 ctrl->next_event = (ctrl->next_event + 1) % 10;
164 taskInfo->hp_slot = hp_slot;
166 rc++;
167 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
170 * Save the presence state
172 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
173 if (p_slot->presence_save) {
175 * Card Present
177 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
178 taskInfo->event_type = INT_PRESENCE_ON;
179 } else {
181 * Not Present
183 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
184 taskInfo->event_type = INT_PRESENCE_OFF;
187 if (rc)
188 up(&event_semaphore); /* signal event thread that new event is posted */
190 return rc;
193 u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
195 struct controller *ctrl = (struct controller *) inst_id;
196 struct slot *p_slot;
197 u8 rc = 0;
198 struct event_info *taskInfo;
200 /* Power fault */
201 dbg("shpchp: Power fault interrupt received.\n");
203 /* This is the structure that tells the worker thread
204 * what to do
206 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
207 ctrl->next_event = (ctrl->next_event + 1) % 10;
208 taskInfo->hp_slot = hp_slot;
210 rc++;
211 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
213 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
215 * Power fault Cleared
217 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
218 p_slot->status = 0x00;
219 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
220 } else {
222 * Power fault
224 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
225 taskInfo->event_type = INT_POWER_FAULT;
226 /* set power fault status for this board */
227 p_slot->status = 0xFF;
228 info("power fault bit %x set\n", hp_slot);
230 if (rc)
231 up(&event_semaphore); /* signal event thread that new event is posted */
233 return rc;
236 /* The following routines constitute the bulk of the
237 hotplug controller logic
239 static int change_bus_speed(struct controller *ctrl, struct slot *p_slot,
240 enum pci_bus_speed speed)
242 int rc = 0;
244 dbg("%s: change to speed %d\n", __FUNCTION__, speed);
245 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) {
246 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
247 return WRONG_BUS_FREQUENCY;
249 return rc;
252 static int fix_bus_speed(struct controller *ctrl, struct slot *pslot,
253 u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp,
254 enum pci_bus_speed msp)
256 int rc = 0;
258 if (flag != 0) { /* Other slots on the same bus are occupied */
259 if ( asp < bsp ) {
260 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bsp, asp);
261 return WRONG_BUS_FREQUENCY;
263 } else {
264 /* Other slots on the same bus are empty */
265 if (msp == bsp) {
266 /* if adapter_speed >= bus_speed, do nothing */
267 if (asp < bsp) {
269 * Try to lower bus speed to accommodate the adapter if other slots
270 * on the same controller are empty
272 if ((rc = change_bus_speed(ctrl, pslot, asp)))
273 return rc;
275 } else {
276 if (asp < msp) {
277 if ((rc = change_bus_speed(ctrl, pslot, asp)))
278 return rc;
279 } else {
280 if ((rc = change_bus_speed(ctrl, pslot, msp)))
281 return rc;
285 return rc;
289 * board_added - Called after a board has been added to the system.
291 * Turns power on for the board
292 * Configures board
295 static int board_added(struct slot *p_slot)
297 u8 hp_slot;
298 u8 slots_not_empty = 0;
299 int rc = 0;
300 enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed;
301 u8 pi, mode;
302 struct controller *ctrl = p_slot->ctrl;
304 hp_slot = p_slot->device - ctrl->slot_device_offset;
306 dbg("%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n",
307 __FUNCTION__, p_slot->device,
308 ctrl->slot_device_offset, hp_slot);
310 /* Power on slot without connecting to bus */
311 rc = p_slot->hpc_ops->power_on_slot(p_slot);
312 if (rc) {
313 err("%s: Failed to power on slot\n", __FUNCTION__);
314 return -1;
317 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
318 if (slots_not_empty)
319 return WRONG_BUS_FREQUENCY;
321 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) {
322 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
323 return WRONG_BUS_FREQUENCY;
326 /* turn on board, blink green LED, turn off Amber LED */
327 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
328 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
329 return rc;
333 rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed);
334 /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */
335 /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */
336 /* 0xd = PCI-X 133 Mhz 533 */
337 /* This encoding is different from the one used in cur_bus_speed & */
338 /* max_bus_speed */
340 if (rc || adapter_speed == PCI_SPEED_UNKNOWN) {
341 err("%s: Can't get adapter speed or bus mode mismatch\n", __FUNCTION__);
342 return WRONG_BUS_FREQUENCY;
345 rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bus_speed);
346 if (rc || bus_speed == PCI_SPEED_UNKNOWN) {
347 err("%s: Can't get bus operation speed\n", __FUNCTION__);
348 return WRONG_BUS_FREQUENCY;
351 rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed);
352 if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) {
353 err("%s: Can't get max bus operation speed\n", __FUNCTION__);
354 max_bus_speed = bus_speed;
357 if ((rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi))) {
358 err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__);
359 pi = 1;
362 /* Check if there are other slots or devices on the same bus */
363 if (!list_empty(&ctrl->pci_dev->subordinate->devices))
364 slots_not_empty = 1;
366 dbg("%s: slots_not_empty %d, pi %d\n", __FUNCTION__,
367 slots_not_empty, pi);
368 dbg("adapter_speed %d, bus_speed %d, max_bus_speed %d\n",
369 adapter_speed, bus_speed, max_bus_speed);
371 if (pi == 2) {
372 dbg("%s: In PI = %d\n", __FUNCTION__, pi);
373 if ((rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode))) {
374 err("%s: Can't get Mode1_ECC, set mode to 0\n", __FUNCTION__);
375 mode = 0;
378 switch (adapter_speed) {
379 case PCI_SPEED_133MHz_PCIX_533:
380 case PCI_SPEED_133MHz_PCIX_266:
381 if ((bus_speed != adapter_speed) &&
382 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
383 return rc;
384 break;
385 case PCI_SPEED_133MHz_PCIX_ECC:
386 case PCI_SPEED_133MHz_PCIX:
387 if (mode) { /* Bus - Mode 1 ECC */
388 if ((bus_speed != 0x7) &&
389 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
390 return rc;
391 } else {
392 if ((bus_speed != 0x4) &&
393 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
394 return rc;
396 break;
397 case PCI_SPEED_66MHz_PCIX_ECC:
398 case PCI_SPEED_66MHz_PCIX:
399 if (mode) { /* Bus - Mode 1 ECC */
400 if ((bus_speed != 0x5) &&
401 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
402 return rc;
403 } else {
404 if ((bus_speed != 0x2) &&
405 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
406 return rc;
408 break;
409 case PCI_SPEED_66MHz:
410 if ((bus_speed != 0x1) &&
411 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
412 return rc;
413 break;
414 case PCI_SPEED_33MHz:
415 if (bus_speed > 0x0) {
416 if (slots_not_empty == 0) {
417 if ((rc = change_bus_speed(ctrl, p_slot, adapter_speed)))
418 return rc;
419 } else {
420 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
421 return WRONG_BUS_FREQUENCY;
424 break;
425 default:
426 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
427 return WRONG_BUS_FREQUENCY;
429 } else {
430 /* If adpater_speed == bus_speed, nothing to do here */
431 dbg("%s: In PI = %d\n", __FUNCTION__, pi);
432 if ((adapter_speed != bus_speed) &&
433 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
434 return rc;
437 /* turn on board, blink green LED, turn off Amber LED */
438 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
439 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
440 return rc;
443 /* Wait for ~1 second */
444 msleep(1000);
446 dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status);
447 /* Check for a power fault */
448 if (p_slot->status == 0xFF) {
449 /* power fault occurred, but it was benign */
450 dbg("%s: power fault\n", __FUNCTION__);
451 rc = POWER_FAILURE;
452 p_slot->status = 0;
453 goto err_exit;
456 if (shpchp_configure_device(p_slot)) {
457 err("Cannot add device at 0x%x:0x%x\n", p_slot->bus,
458 p_slot->device);
459 goto err_exit;
462 p_slot->status = 0;
463 p_slot->is_a_board = 0x01;
464 p_slot->pwr_save = 1;
466 p_slot->hpc_ops->green_led_on(p_slot);
468 return 0;
470 err_exit:
471 /* turn off slot, turn on Amber LED, turn off Green LED */
472 rc = p_slot->hpc_ops->slot_disable(p_slot);
473 if (rc) {
474 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
475 return rc;
478 return(rc);
483 * remove_board - Turns off slot and LED's
486 static int remove_board(struct slot *p_slot)
488 struct controller *ctrl = p_slot->ctrl;
489 u8 hp_slot;
490 int rc;
492 if (shpchp_unconfigure_device(p_slot))
493 return(1);
495 hp_slot = p_slot->device - ctrl->slot_device_offset;
496 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
498 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
500 /* Change status to shutdown */
501 if (p_slot->is_a_board)
502 p_slot->status = 0x01;
504 /* turn off slot, turn on Amber LED, turn off Green LED */
505 rc = p_slot->hpc_ops->slot_disable(p_slot);
506 if (rc) {
507 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
508 return rc;
511 rc = p_slot->hpc_ops->set_attention_status(p_slot, 0);
512 if (rc) {
513 err("%s: Issue of Set Attention command failed\n", __FUNCTION__);
514 return rc;
517 p_slot->pwr_save = 0;
518 p_slot->is_a_board = 0;
520 return 0;
524 static void pushbutton_helper_thread (unsigned long data)
526 pushbutton_pending = data;
528 up(&event_semaphore);
533 * shpchp_pushbutton_thread
535 * Scheduled procedure to handle blocking stuff for the pushbuttons
536 * Handles all pending events and exits.
539 static void shpchp_pushbutton_thread (unsigned long slot)
541 struct slot *p_slot = (struct slot *) slot;
542 u8 getstatus;
544 pushbutton_pending = 0;
546 if (!p_slot) {
547 dbg("%s: Error! slot NULL\n", __FUNCTION__);
548 return;
551 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
552 if (getstatus) {
553 p_slot->state = POWEROFF_STATE;
555 shpchp_disable_slot(p_slot);
556 p_slot->state = STATIC_STATE;
557 } else {
558 p_slot->state = POWERON_STATE;
560 if (shpchp_enable_slot(p_slot))
561 p_slot->hpc_ops->green_led_off(p_slot);
563 p_slot->state = STATIC_STATE;
566 return;
570 /* this is the main worker thread */
571 static int event_thread(void* data)
573 struct controller *ctrl;
574 lock_kernel();
575 daemonize("shpchpd_event");
576 unlock_kernel();
578 while (1) {
579 dbg("!!!!event_thread sleeping\n");
580 down_interruptible (&event_semaphore);
581 dbg("event_thread woken finished = %d\n", event_finished);
582 if (event_finished || signal_pending(current))
583 break;
584 /* Do stuff here */
585 if (pushbutton_pending)
586 shpchp_pushbutton_thread(pushbutton_pending);
587 else
588 list_for_each_entry(ctrl, &shpchp_ctrl_list, ctrl_list)
589 interrupt_event_handler(ctrl);
591 dbg("event_thread signals exit\n");
592 up(&event_exit);
593 return 0;
596 int shpchp_event_start_thread (void)
598 int pid;
600 /* initialize our semaphores */
601 init_MUTEX_LOCKED(&event_exit);
602 event_finished=0;
604 init_MUTEX_LOCKED(&event_semaphore);
605 pid = kernel_thread(event_thread, NULL, 0);
607 if (pid < 0) {
608 err ("Can't start up our event thread\n");
609 return -1;
611 return 0;
615 void shpchp_event_stop_thread (void)
617 event_finished = 1;
618 up(&event_semaphore);
619 down(&event_exit);
623 static int update_slot_info (struct slot *slot)
625 struct hotplug_slot_info *info;
626 int result;
628 info = kmalloc(sizeof(*info), GFP_KERNEL);
629 if (!info)
630 return -ENOMEM;
632 slot->hpc_ops->get_power_status(slot, &(info->power_status));
633 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
634 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
635 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
637 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
638 kfree (info);
639 return result;
642 static void interrupt_event_handler(struct controller *ctrl)
644 int loop = 0;
645 int change = 1;
646 u8 hp_slot;
647 u8 getstatus;
648 struct slot *p_slot;
650 while (change) {
651 change = 0;
653 for (loop = 0; loop < 10; loop++) {
654 if (ctrl->event_queue[loop].event_type != 0) {
655 dbg("%s:loop %x event_type %x\n", __FUNCTION__, loop,
656 ctrl->event_queue[loop].event_type);
657 hp_slot = ctrl->event_queue[loop].hp_slot;
659 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
661 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
662 dbg("%s: button cancel\n", __FUNCTION__);
663 del_timer(&p_slot->task_event);
665 switch (p_slot->state) {
666 case BLINKINGOFF_STATE:
667 p_slot->hpc_ops->green_led_on(p_slot);
668 p_slot->hpc_ops->set_attention_status(p_slot, 0);
669 break;
670 case BLINKINGON_STATE:
671 p_slot->hpc_ops->green_led_off(p_slot);
672 p_slot->hpc_ops->set_attention_status(p_slot, 0);
673 break;
674 default:
675 warn("Not a valid state\n");
676 return;
678 info(msg_button_cancel, p_slot->number);
679 p_slot->state = STATIC_STATE;
680 } else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
681 /* Button Pressed (No action on 1st press...) */
682 dbg("%s: Button pressed\n", __FUNCTION__);
684 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
685 if (getstatus) {
686 /* slot is on */
687 dbg("%s: slot is on\n", __FUNCTION__);
688 p_slot->state = BLINKINGOFF_STATE;
689 info(msg_button_off, p_slot->number);
690 } else {
691 /* slot is off */
692 dbg("%s: slot is off\n", __FUNCTION__);
693 p_slot->state = BLINKINGON_STATE;
694 info(msg_button_on, p_slot->number);
697 /* blink green LED and turn off amber */
698 p_slot->hpc_ops->green_led_blink(p_slot);
699 p_slot->hpc_ops->set_attention_status(p_slot, 0);
701 init_timer(&p_slot->task_event);
702 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
703 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
704 p_slot->task_event.data = (unsigned long) p_slot;
706 dbg("%s: add_timer p_slot = %p\n", __FUNCTION__,(void *) p_slot);
707 add_timer(&p_slot->task_event);
708 } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
709 /***********POWER FAULT********************/
710 dbg("%s: power fault\n", __FUNCTION__);
711 p_slot->hpc_ops->set_attention_status(p_slot, 1);
712 p_slot->hpc_ops->green_led_off(p_slot);
713 } else {
714 /* refresh notification */
715 if (p_slot)
716 update_slot_info(p_slot);
719 ctrl->event_queue[loop].event_type = 0;
721 change = 1;
723 } /* End of FOR loop */
726 return;
730 int shpchp_enable_slot (struct slot *p_slot)
732 u8 getstatus = 0;
733 int rc, retval = -ENODEV;
735 /* Check to see if (latch closed, card present, power off) */
736 mutex_lock(&p_slot->ctrl->crit_sect);
737 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
738 if (rc || !getstatus) {
739 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
740 goto out;
742 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
743 if (rc || getstatus) {
744 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
745 goto out;
747 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
748 if (rc || getstatus) {
749 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
750 goto out;
753 p_slot->is_a_board = 1;
755 /* We have to save the presence info for these slots */
756 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
757 p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save));
758 dbg("%s: p_slot->pwr_save %x\n", __FUNCTION__, p_slot->pwr_save);
759 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
761 if(((p_slot->ctrl->pci_dev->vendor == PCI_VENDOR_ID_AMD) ||
762 (p_slot->ctrl->pci_dev->device == PCI_DEVICE_ID_AMD_POGO_7458))
763 && p_slot->ctrl->num_slots == 1) {
764 /* handle amd pogo errata; this must be done before enable */
765 amd_pogo_errata_save_misc_reg(p_slot);
766 retval = board_added(p_slot);
767 /* handle amd pogo errata; this must be done after enable */
768 amd_pogo_errata_restore_misc_reg(p_slot);
769 } else
770 retval = board_added(p_slot);
772 if (retval) {
773 p_slot->hpc_ops->get_adapter_status(p_slot,
774 &(p_slot->presence_save));
775 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
778 update_slot_info(p_slot);
779 out:
780 mutex_unlock(&p_slot->ctrl->crit_sect);
781 return retval;
785 int shpchp_disable_slot (struct slot *p_slot)
787 u8 getstatus = 0;
788 int rc, retval = -ENODEV;
790 if (!p_slot->ctrl)
791 return -ENODEV;
793 /* Check to see if (latch closed, card present, power on) */
794 mutex_lock(&p_slot->ctrl->crit_sect);
796 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
797 if (rc || !getstatus) {
798 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
799 goto out;
801 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
802 if (rc || getstatus) {
803 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
804 goto out;
806 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
807 if (rc || !getstatus) {
808 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
809 goto out;
812 retval = remove_board(p_slot);
813 update_slot_info(p_slot);
814 out:
815 mutex_unlock(&p_slot->ctrl->crit_sect);
816 return retval;