Lines Matching refs:ctrl
34 static void set_slot_off(struct controller *ctrl) in set_slot_off() argument
40 if (POWER_CTRL(ctrl)) { in set_slot_off()
41 pciehp_power_off_slot(ctrl); in set_slot_off()
51 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in set_slot_off()
62 static int board_added(struct controller *ctrl) in board_added() argument
65 struct pci_bus *parent = ctrl->pcie->port->subordinate; in board_added()
67 if (POWER_CTRL(ctrl)) { in board_added()
69 retval = pciehp_power_on_slot(ctrl); in board_added()
74 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_BLINK, in board_added()
78 retval = pciehp_check_link_status(ctrl); in board_added()
83 if (ctrl->power_fault_detected || pciehp_query_power_fault(ctrl)) { in board_added()
84 ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(ctrl)); in board_added()
89 retval = pciehp_configure_device(ctrl); in board_added()
92 ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n", in board_added()
98 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, in board_added()
103 set_slot_off(ctrl); in board_added()
112 static void remove_board(struct controller *ctrl, bool safe_removal) in remove_board() argument
114 pciehp_unconfigure_device(ctrl, safe_removal); in remove_board()
116 if (POWER_CTRL(ctrl)) { in remove_board()
117 pciehp_power_off_slot(ctrl); in remove_board()
128 &ctrl->pending_events); in remove_board()
131 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in remove_board()
135 pcie_reset_lbms(ctrl->pcie->port); in remove_board()
138 static int pciehp_enable_slot(struct controller *ctrl);
139 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal);
141 void pciehp_request(struct controller *ctrl, int action) in pciehp_request() argument
143 atomic_or(action, &ctrl->pending_events); in pciehp_request()
145 irq_wake_thread(ctrl->pcie->irq, ctrl); in pciehp_request()
150 struct controller *ctrl = container_of(work, struct controller, in pciehp_queue_pushbutton_work() local
153 mutex_lock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
154 switch (ctrl->state) { in pciehp_queue_pushbutton_work()
156 pciehp_request(ctrl, DISABLE_SLOT); in pciehp_queue_pushbutton_work()
159 pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); in pciehp_queue_pushbutton_work()
164 mutex_unlock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
167 void pciehp_handle_button_press(struct controller *ctrl) in pciehp_handle_button_press() argument
169 mutex_lock(&ctrl->state_lock); in pciehp_handle_button_press()
170 switch (ctrl->state) { in pciehp_handle_button_press()
173 if (ctrl->state == ON_STATE) { in pciehp_handle_button_press()
174 ctrl->state = BLINKINGOFF_STATE; in pciehp_handle_button_press()
175 ctrl_info(ctrl, "Slot(%s): Button press: will power off in 5 sec\n", in pciehp_handle_button_press()
176 slot_name(ctrl)); in pciehp_handle_button_press()
178 ctrl->state = BLINKINGON_STATE; in pciehp_handle_button_press()
179 ctrl_info(ctrl, "Slot(%s): Button press: will power on in 5 sec\n", in pciehp_handle_button_press()
180 slot_name(ctrl)); in pciehp_handle_button_press()
183 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_BLINK, in pciehp_handle_button_press()
185 schedule_delayed_work(&ctrl->button_work, 5 * HZ); in pciehp_handle_button_press()
194 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_button_press()
195 if (ctrl->state == BLINKINGOFF_STATE) { in pciehp_handle_button_press()
196 ctrl->state = ON_STATE; in pciehp_handle_button_press()
197 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, in pciehp_handle_button_press()
199 ctrl_info(ctrl, "Slot(%s): Button press: canceling request to power off\n", in pciehp_handle_button_press()
200 slot_name(ctrl)); in pciehp_handle_button_press()
202 ctrl->state = OFF_STATE; in pciehp_handle_button_press()
203 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_handle_button_press()
205 ctrl_info(ctrl, "Slot(%s): Button press: canceling request to power on\n", in pciehp_handle_button_press()
206 slot_name(ctrl)); in pciehp_handle_button_press()
210 ctrl_err(ctrl, "Slot(%s): Button press: ignoring invalid state %#x\n", in pciehp_handle_button_press()
211 slot_name(ctrl), ctrl->state); in pciehp_handle_button_press()
214 mutex_unlock(&ctrl->state_lock); in pciehp_handle_button_press()
217 void pciehp_handle_disable_request(struct controller *ctrl) in pciehp_handle_disable_request() argument
219 mutex_lock(&ctrl->state_lock); in pciehp_handle_disable_request()
220 switch (ctrl->state) { in pciehp_handle_disable_request()
223 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_disable_request()
226 ctrl->state = POWEROFF_STATE; in pciehp_handle_disable_request()
227 mutex_unlock(&ctrl->state_lock); in pciehp_handle_disable_request()
229 ctrl->request_result = pciehp_disable_slot(ctrl, SAFE_REMOVAL); in pciehp_handle_disable_request()
232 void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) in pciehp_handle_presence_or_link_change() argument
240 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
241 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
243 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
246 ctrl->state = POWEROFF_STATE; in pciehp_handle_presence_or_link_change()
247 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
249 ctrl_info(ctrl, "Slot(%s): Link Down\n", in pciehp_handle_presence_or_link_change()
250 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
251 trace_pci_hp_event(pci_name(ctrl->pcie->port), in pciehp_handle_presence_or_link_change()
252 slot_name(ctrl), in pciehp_handle_presence_or_link_change()
256 ctrl_info(ctrl, "Slot(%s): Card not present\n", in pciehp_handle_presence_or_link_change()
257 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
258 trace_pci_hp_event(pci_name(ctrl->pcie->port), in pciehp_handle_presence_or_link_change()
259 slot_name(ctrl), in pciehp_handle_presence_or_link_change()
262 pciehp_disable_slot(ctrl, SURPRISE_REMOVAL); in pciehp_handle_presence_or_link_change()
265 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
270 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
271 present = pciehp_card_present(ctrl); in pciehp_handle_presence_or_link_change()
272 link_active = pciehp_check_link_active(ctrl); in pciehp_handle_presence_or_link_change()
274 if (ctrl->state == BLINKINGON_STATE) { in pciehp_handle_presence_or_link_change()
275 ctrl->state = OFF_STATE; in pciehp_handle_presence_or_link_change()
276 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
277 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_handle_presence_or_link_change()
279 ctrl_info(ctrl, "Slot(%s): Card not present\n", in pciehp_handle_presence_or_link_change()
280 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
281 trace_pci_hp_event(pci_name(ctrl->pcie->port), in pciehp_handle_presence_or_link_change()
282 slot_name(ctrl), in pciehp_handle_presence_or_link_change()
285 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
289 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
291 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
294 ctrl->state = POWERON_STATE; in pciehp_handle_presence_or_link_change()
295 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
297 ctrl_info(ctrl, "Slot(%s): Card present\n", in pciehp_handle_presence_or_link_change()
298 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
299 trace_pci_hp_event(pci_name(ctrl->pcie->port), in pciehp_handle_presence_or_link_change()
300 slot_name(ctrl), in pciehp_handle_presence_or_link_change()
304 ctrl_info(ctrl, "Slot(%s): Link Up\n", slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
305 trace_pci_hp_event(pci_name(ctrl->pcie->port), in pciehp_handle_presence_or_link_change()
306 slot_name(ctrl), in pciehp_handle_presence_or_link_change()
309 ctrl->request_result = pciehp_enable_slot(ctrl); in pciehp_handle_presence_or_link_change()
312 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
317 static int __pciehp_enable_slot(struct controller *ctrl) in __pciehp_enable_slot() argument
321 if (MRL_SENS(ctrl)) { in __pciehp_enable_slot()
322 pciehp_get_latch_status(ctrl, &getstatus); in __pciehp_enable_slot()
324 ctrl_info(ctrl, "Slot(%s): Latch open\n", in __pciehp_enable_slot()
325 slot_name(ctrl)); in __pciehp_enable_slot()
330 if (POWER_CTRL(ctrl)) { in __pciehp_enable_slot()
331 pciehp_get_power_status(ctrl, &getstatus); in __pciehp_enable_slot()
333 ctrl_info(ctrl, "Slot(%s): Already enabled\n", in __pciehp_enable_slot()
334 slot_name(ctrl)); in __pciehp_enable_slot()
339 return board_added(ctrl); in __pciehp_enable_slot()
342 static int pciehp_enable_slot(struct controller *ctrl) in pciehp_enable_slot() argument
346 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_enable_slot()
347 ret = __pciehp_enable_slot(ctrl); in pciehp_enable_slot()
348 if (ret && ATTN_BUTTN(ctrl)) in pciehp_enable_slot()
350 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_enable_slot()
352 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_enable_slot()
354 mutex_lock(&ctrl->state_lock); in pciehp_enable_slot()
355 ctrl->state = ret ? OFF_STATE : ON_STATE; in pciehp_enable_slot()
356 mutex_unlock(&ctrl->state_lock); in pciehp_enable_slot()
361 static int __pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in __pciehp_disable_slot() argument
365 if (POWER_CTRL(ctrl)) { in __pciehp_disable_slot()
366 pciehp_get_power_status(ctrl, &getstatus); in __pciehp_disable_slot()
368 ctrl_info(ctrl, "Slot(%s): Already disabled\n", in __pciehp_disable_slot()
369 slot_name(ctrl)); in __pciehp_disable_slot()
374 remove_board(ctrl, safe_removal); in __pciehp_disable_slot()
378 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in pciehp_disable_slot() argument
382 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_disable_slot()
383 ret = __pciehp_disable_slot(ctrl, safe_removal); in pciehp_disable_slot()
384 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_disable_slot()
386 mutex_lock(&ctrl->state_lock); in pciehp_disable_slot()
387 ctrl->state = OFF_STATE; in pciehp_disable_slot()
388 mutex_unlock(&ctrl->state_lock); in pciehp_disable_slot()
395 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_enable_slot() local
397 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
398 switch (ctrl->state) { in pciehp_sysfs_enable_slot()
401 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
406 ctrl->request_result = -ENODEV; in pciehp_sysfs_enable_slot()
407 pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); in pciehp_sysfs_enable_slot()
408 wait_event(ctrl->requester, in pciehp_sysfs_enable_slot()
409 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_enable_slot()
410 !ctrl->ist_running); in pciehp_sysfs_enable_slot()
411 return ctrl->request_result; in pciehp_sysfs_enable_slot()
413 ctrl_info(ctrl, "Slot(%s): Already in powering on state\n", in pciehp_sysfs_enable_slot()
414 slot_name(ctrl)); in pciehp_sysfs_enable_slot()
419 ctrl_info(ctrl, "Slot(%s): Already enabled\n", in pciehp_sysfs_enable_slot()
420 slot_name(ctrl)); in pciehp_sysfs_enable_slot()
423 ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", in pciehp_sysfs_enable_slot()
424 slot_name(ctrl), ctrl->state); in pciehp_sysfs_enable_slot()
427 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
434 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_disable_slot() local
436 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
437 switch (ctrl->state) { in pciehp_sysfs_disable_slot()
440 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
441 pciehp_request(ctrl, DISABLE_SLOT); in pciehp_sysfs_disable_slot()
442 wait_event(ctrl->requester, in pciehp_sysfs_disable_slot()
443 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_disable_slot()
444 !ctrl->ist_running); in pciehp_sysfs_disable_slot()
445 return ctrl->request_result; in pciehp_sysfs_disable_slot()
447 ctrl_info(ctrl, "Slot(%s): Already in powering off state\n", in pciehp_sysfs_disable_slot()
448 slot_name(ctrl)); in pciehp_sysfs_disable_slot()
453 ctrl_info(ctrl, "Slot(%s): Already disabled\n", in pciehp_sysfs_disable_slot()
454 slot_name(ctrl)); in pciehp_sysfs_disable_slot()
457 ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", in pciehp_sysfs_disable_slot()
458 slot_name(ctrl), ctrl->state); in pciehp_sysfs_disable_slot()
461 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()