• Home
  • Raw
  • Download

Lines Matching +full:power +full:- +full:controller

1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI Express Hot Plug Controller Driver
6 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
8 * Copyright (C) 2003-2004 Intel Corporation
25 hotplug controller logic
31 static void set_slot_off(struct controller *ctrl) in set_slot_off()
34 * Turn off slot, turn on attention indicator, turn off power in set_slot_off()
41 * After turning power off, we must wait for at least 1 second in set_slot_off()
42 * before taking any action that relies on power having been in set_slot_off()
53 * board_added - Called after a board has been added to the system.
54 * @ctrl: PCIe hotplug controller where board is added
56 * Turns power on for the board.
59 static int board_added(struct controller *ctrl) in board_added()
62 struct pci_bus *parent = ctrl->pcie->port->subordinate; in board_added()
65 /* Power on slot */ in board_added()
79 /* Check for a power fault */ in board_added()
80 if (ctrl->power_fault_detected || pciehp_query_power_fault(ctrl)) { in board_added()
81 ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(ctrl)); in board_added()
82 retval = -EIO; in board_added()
88 if (retval != -EEXIST) { in board_added()
90 pci_domain_nr(parent), parent->number); in board_added()
105 * remove_board - Turn off slot and Power Indicator
106 * @ctrl: PCIe hotplug controller where board is being removed
109 static void remove_board(struct controller *ctrl, bool safe_removal) in remove_board()
117 * After turning power off, we must wait for at least 1 second in remove_board()
118 * before taking any action that relies on power having been in remove_board()
123 /* Ignore link or presence changes caused by power off */ in remove_board()
125 &ctrl->pending_events); in remove_board()
132 static int pciehp_enable_slot(struct controller *ctrl);
133 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal);
135 void pciehp_request(struct controller *ctrl, int action) in pciehp_request()
137 atomic_or(action, &ctrl->pending_events); in pciehp_request()
139 irq_wake_thread(ctrl->pcie->irq, ctrl); in pciehp_request()
144 struct controller *ctrl = container_of(work, struct controller, in pciehp_queue_pushbutton_work()
147 mutex_lock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
148 switch (ctrl->state) { in pciehp_queue_pushbutton_work()
158 mutex_unlock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
161 void pciehp_handle_button_press(struct controller *ctrl) in pciehp_handle_button_press()
163 mutex_lock(&ctrl->state_lock); in pciehp_handle_button_press()
164 switch (ctrl->state) { in pciehp_handle_button_press()
167 if (ctrl->state == ON_STATE) { in pciehp_handle_button_press()
168 ctrl->state = BLINKINGOFF_STATE; in pciehp_handle_button_press()
172 ctrl->state = BLINKINGON_STATE; in pciehp_handle_button_press()
176 /* blink power indicator and turn off attention */ in pciehp_handle_button_press()
179 schedule_delayed_work(&ctrl->button_work, 5 * HZ); in pciehp_handle_button_press()
186 * expires to cancel hot-add or hot-remove in pciehp_handle_button_press()
189 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_button_press()
190 if (ctrl->state == BLINKINGOFF_STATE) { in pciehp_handle_button_press()
191 ctrl->state = ON_STATE; in pciehp_handle_button_press()
195 ctrl->state = OFF_STATE; in pciehp_handle_button_press()
204 slot_name(ctrl), ctrl->state); in pciehp_handle_button_press()
207 mutex_unlock(&ctrl->state_lock); in pciehp_handle_button_press()
210 void pciehp_handle_disable_request(struct controller *ctrl) in pciehp_handle_disable_request()
212 mutex_lock(&ctrl->state_lock); in pciehp_handle_disable_request()
213 switch (ctrl->state) { in pciehp_handle_disable_request()
216 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_disable_request()
219 ctrl->state = POWEROFF_STATE; in pciehp_handle_disable_request()
220 mutex_unlock(&ctrl->state_lock); in pciehp_handle_disable_request()
222 ctrl->request_result = pciehp_disable_slot(ctrl, SAFE_REMOVAL); in pciehp_handle_disable_request()
225 void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) in pciehp_handle_presence_or_link_change()
233 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
234 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
236 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
239 ctrl->state = POWEROFF_STATE; in pciehp_handle_presence_or_link_change()
240 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
250 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
255 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
259 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
263 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
265 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
268 ctrl->state = POWERON_STATE; in pciehp_handle_presence_or_link_change()
269 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
276 ctrl->request_result = pciehp_enable_slot(ctrl); in pciehp_handle_presence_or_link_change()
279 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
284 static int __pciehp_enable_slot(struct controller *ctrl) in __pciehp_enable_slot()
293 return -ENODEV; in __pciehp_enable_slot()
309 static int pciehp_enable_slot(struct controller *ctrl) in pciehp_enable_slot()
313 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_enable_slot()
319 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_enable_slot()
321 mutex_lock(&ctrl->state_lock); in pciehp_enable_slot()
322 ctrl->state = ret ? OFF_STATE : ON_STATE; in pciehp_enable_slot()
323 mutex_unlock(&ctrl->state_lock); in pciehp_enable_slot()
328 static int __pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in __pciehp_disable_slot()
337 return -EINVAL; in __pciehp_disable_slot()
345 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in pciehp_disable_slot()
349 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_disable_slot()
351 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_disable_slot()
353 mutex_lock(&ctrl->state_lock); in pciehp_disable_slot()
354 ctrl->state = OFF_STATE; in pciehp_disable_slot()
355 mutex_unlock(&ctrl->state_lock); in pciehp_disable_slot()
362 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_enable_slot()
364 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
365 switch (ctrl->state) { in pciehp_sysfs_enable_slot()
368 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
370 * The IRQ thread becomes a no-op if the user pulls out the in pciehp_sysfs_enable_slot()
371 * card before the thread wakes up, so initialize to -ENODEV. in pciehp_sysfs_enable_slot()
373 ctrl->request_result = -ENODEV; in pciehp_sysfs_enable_slot()
375 wait_event(ctrl->requester, in pciehp_sysfs_enable_slot()
376 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_enable_slot()
377 !ctrl->ist_running); in pciehp_sysfs_enable_slot()
378 return ctrl->request_result; in pciehp_sysfs_enable_slot()
391 slot_name(ctrl), ctrl->state); in pciehp_sysfs_enable_slot()
394 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
396 return -ENODEV; in pciehp_sysfs_enable_slot()
401 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_disable_slot()
403 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
404 switch (ctrl->state) { in pciehp_sysfs_disable_slot()
407 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
409 wait_event(ctrl->requester, in pciehp_sysfs_disable_slot()
410 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_disable_slot()
411 !ctrl->ist_running); in pciehp_sysfs_disable_slot()
412 return ctrl->request_result; in pciehp_sysfs_disable_slot()
425 slot_name(ctrl), ctrl->state); in pciehp_sysfs_disable_slot()
428 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
430 return -ENODEV; in pciehp_sysfs_disable_slot()