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 ([email protected])
8 * Copyright (C) 2003-2004 Intel Corporation
27 hotplug controller logic
33 static void set_slot_off(struct controller *ctrl) in set_slot_off()
36 * Turn off slot, turn on attention indicator, turn off power in set_slot_off()
43 * After turning power off, we must wait for at least 1 second in set_slot_off()
44 * before taking any action that relies on power having been in set_slot_off()
55 * board_added - Called after a board has been added to the system.
56 * @ctrl: PCIe hotplug controller where board is added
58 * Turns power on for the board.
61 static int board_added(struct controller *ctrl) in board_added()
64 struct pci_bus *parent = ctrl->pcie->port->subordinate; in board_added()
67 /* Power on slot */ in board_added()
81 /* Check for a power fault */ in board_added()
82 if (ctrl->power_fault_detected || pciehp_query_power_fault(ctrl)) { in board_added()
83 ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(ctrl)); in board_added()
84 retval = -EIO; in board_added()
90 if (retval != -EEXIST) { in board_added()
92 pci_domain_nr(parent), parent->number); in board_added()
107 * remove_board - Turn off slot and Power Indicator
108 * @ctrl: PCIe hotplug controller where board is being removed
111 static void remove_board(struct controller *ctrl, bool safe_removal) in remove_board()
119 * After turning power off, we must wait for at least 1 second in remove_board()
120 * before taking any action that relies on power having been in remove_board()
125 /* Ignore link or presence changes caused by power off */ in remove_board()
127 &ctrl->pending_events); in remove_board()
134 pcie_reset_lbms_count(ctrl->pcie->port); in remove_board()
137 static int pciehp_enable_slot(struct controller *ctrl);
138 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal);
140 void pciehp_request(struct controller *ctrl, int action) in pciehp_request()
142 atomic_or(action, &ctrl->pending_events); in pciehp_request()
144 irq_wake_thread(ctrl->pcie->irq, ctrl); in pciehp_request()
149 struct controller *ctrl = container_of(work, struct controller, in pciehp_queue_pushbutton_work()
152 mutex_lock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
153 switch (ctrl->state) { in pciehp_queue_pushbutton_work()
163 mutex_unlock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
166 void pciehp_handle_button_press(struct controller *ctrl) in pciehp_handle_button_press()
168 mutex_lock(&ctrl->state_lock); in pciehp_handle_button_press()
169 switch (ctrl->state) { in pciehp_handle_button_press()
172 if (ctrl->state == ON_STATE) { in pciehp_handle_button_press()
173 ctrl->state = BLINKINGOFF_STATE; in pciehp_handle_button_press()
174 ctrl_info(ctrl, "Slot(%s): Button press: will power off in 5 sec\n", in pciehp_handle_button_press()
177 ctrl->state = BLINKINGON_STATE; in pciehp_handle_button_press()
178 ctrl_info(ctrl, "Slot(%s): Button press: will power on in 5 sec\n", in pciehp_handle_button_press()
181 /* blink power indicator and turn off attention */ in pciehp_handle_button_press()
184 schedule_delayed_work(&ctrl->button_work, 5 * HZ); in pciehp_handle_button_press()
191 * expires to cancel hot-add or hot-remove in pciehp_handle_button_press()
193 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_button_press()
194 if (ctrl->state == BLINKINGOFF_STATE) { in pciehp_handle_button_press()
195 ctrl->state = ON_STATE; in pciehp_handle_button_press()
198 ctrl_info(ctrl, "Slot(%s): Button press: canceling request to power off\n", in pciehp_handle_button_press()
201 ctrl->state = OFF_STATE; in pciehp_handle_button_press()
204 ctrl_info(ctrl, "Slot(%s): Button press: canceling request to power on\n", in pciehp_handle_button_press()
210 slot_name(ctrl), ctrl->state); in pciehp_handle_button_press()
213 mutex_unlock(&ctrl->state_lock); in pciehp_handle_button_press()
216 void pciehp_handle_disable_request(struct controller *ctrl) in pciehp_handle_disable_request()
218 mutex_lock(&ctrl->state_lock); in pciehp_handle_disable_request()
219 switch (ctrl->state) { in pciehp_handle_disable_request()
222 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_disable_request()
225 ctrl->state = POWEROFF_STATE; in pciehp_handle_disable_request()
226 mutex_unlock(&ctrl->state_lock); in pciehp_handle_disable_request()
228 ctrl->request_result = pciehp_disable_slot(ctrl, SAFE_REMOVAL); in pciehp_handle_disable_request()
231 void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) in pciehp_handle_presence_or_link_change()
239 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
240 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
242 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
245 ctrl->state = POWEROFF_STATE; in pciehp_handle_presence_or_link_change()
246 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
256 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
261 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
265 if (ctrl->state == BLINKINGON_STATE) { in pciehp_handle_presence_or_link_change()
266 ctrl->state = OFF_STATE; in pciehp_handle_presence_or_link_change()
267 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
273 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
277 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
279 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
282 ctrl->state = POWERON_STATE; in pciehp_handle_presence_or_link_change()
283 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
290 ctrl->request_result = pciehp_enable_slot(ctrl); in pciehp_handle_presence_or_link_change()
293 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
298 static int __pciehp_enable_slot(struct controller *ctrl) in __pciehp_enable_slot()
307 return -ENODEV; in __pciehp_enable_slot()
323 static int pciehp_enable_slot(struct controller *ctrl) in pciehp_enable_slot()
327 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_enable_slot()
333 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_enable_slot()
335 mutex_lock(&ctrl->state_lock); in pciehp_enable_slot()
336 ctrl->state = ret ? OFF_STATE : ON_STATE; in pciehp_enable_slot()
337 mutex_unlock(&ctrl->state_lock); in pciehp_enable_slot()
342 static int __pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in __pciehp_disable_slot()
351 return -EINVAL; in __pciehp_disable_slot()
359 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in pciehp_disable_slot()
363 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_disable_slot()
365 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_disable_slot()
367 mutex_lock(&ctrl->state_lock); in pciehp_disable_slot()
368 ctrl->state = OFF_STATE; in pciehp_disable_slot()
369 mutex_unlock(&ctrl->state_lock); in pciehp_disable_slot()
376 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_enable_slot()
378 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
379 switch (ctrl->state) { in pciehp_sysfs_enable_slot()
382 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
384 * The IRQ thread becomes a no-op if the user pulls out the in pciehp_sysfs_enable_slot()
385 * card before the thread wakes up, so initialize to -ENODEV. in pciehp_sysfs_enable_slot()
387 ctrl->request_result = -ENODEV; in pciehp_sysfs_enable_slot()
389 wait_event(ctrl->requester, in pciehp_sysfs_enable_slot()
390 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_enable_slot()
391 !ctrl->ist_running); in pciehp_sysfs_enable_slot()
392 return ctrl->request_result; in pciehp_sysfs_enable_slot()
405 slot_name(ctrl), ctrl->state); in pciehp_sysfs_enable_slot()
408 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
410 return -ENODEV; in pciehp_sysfs_enable_slot()
415 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_disable_slot()
417 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
418 switch (ctrl->state) { in pciehp_sysfs_disable_slot()
421 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
423 wait_event(ctrl->requester, in pciehp_sysfs_disable_slot()
424 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_disable_slot()
425 !ctrl->ist_running); in pciehp_sysfs_disable_slot()
426 return ctrl->request_result; in pciehp_sysfs_disable_slot()
439 slot_name(ctrl), ctrl->state); in pciehp_sysfs_disable_slot()
442 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
444 return -ENODEV; in pciehp_sysfs_disable_slot()