Lines Matching refs:ctrl

31 static void set_slot_off(struct controller *ctrl)  in set_slot_off()  argument
37 if (POWER_CTRL(ctrl)) { in set_slot_off()
38 pciehp_power_off_slot(ctrl); in set_slot_off()
48 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in set_slot_off()
59 static int board_added(struct controller *ctrl) in board_added() argument
62 struct pci_bus *parent = ctrl->pcie->port->subordinate; in board_added()
64 if (POWER_CTRL(ctrl)) { in board_added()
66 retval = pciehp_power_on_slot(ctrl); in board_added()
71 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_BLINK, in board_added()
75 retval = pciehp_check_link_status(ctrl); in board_added()
77 ctrl_err(ctrl, "Failed to check link status\n"); 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()
88 retval = pciehp_configure_device(ctrl); in board_added()
91 ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n", in board_added()
97 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, in board_added()
102 set_slot_off(ctrl); in board_added()
111 static void remove_board(struct controller *ctrl, bool safe_removal) in remove_board() argument
113 pciehp_unconfigure_device(ctrl, safe_removal); in remove_board()
115 if (POWER_CTRL(ctrl)) { in remove_board()
116 pciehp_power_off_slot(ctrl); in remove_board()
127 &ctrl->pending_events); in remove_board()
130 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in remove_board()
134 static int pciehp_enable_slot(struct controller *ctrl);
135 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal);
137 void pciehp_request(struct controller *ctrl, int action) in pciehp_request() argument
139 atomic_or(action, &ctrl->pending_events); in pciehp_request()
141 irq_wake_thread(ctrl->pcie->irq, ctrl); in pciehp_request()
146 struct controller *ctrl = container_of(work, struct controller, in pciehp_queue_pushbutton_work() local
149 mutex_lock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
150 switch (ctrl->state) { in pciehp_queue_pushbutton_work()
152 pciehp_request(ctrl, DISABLE_SLOT); in pciehp_queue_pushbutton_work()
155 pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); in pciehp_queue_pushbutton_work()
160 mutex_unlock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
163 void pciehp_handle_button_press(struct controller *ctrl) in pciehp_handle_button_press() argument
165 mutex_lock(&ctrl->state_lock); in pciehp_handle_button_press()
166 switch (ctrl->state) { in pciehp_handle_button_press()
169 if (ctrl->state == ON_STATE) { in pciehp_handle_button_press()
170 ctrl->state = BLINKINGOFF_STATE; in pciehp_handle_button_press()
171 ctrl_info(ctrl, "Slot(%s): Powering off due to button press\n", in pciehp_handle_button_press()
172 slot_name(ctrl)); in pciehp_handle_button_press()
174 ctrl->state = BLINKINGON_STATE; in pciehp_handle_button_press()
175 ctrl_info(ctrl, "Slot(%s) Powering on due to button press\n", in pciehp_handle_button_press()
176 slot_name(ctrl)); in pciehp_handle_button_press()
179 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_BLINK, in pciehp_handle_button_press()
181 schedule_delayed_work(&ctrl->button_work, 5 * HZ); in pciehp_handle_button_press()
190 ctrl_info(ctrl, "Slot(%s): Button cancel\n", slot_name(ctrl)); in pciehp_handle_button_press()
191 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_button_press()
192 if (ctrl->state == BLINKINGOFF_STATE) { in pciehp_handle_button_press()
193 ctrl->state = ON_STATE; in pciehp_handle_button_press()
194 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, in pciehp_handle_button_press()
197 ctrl->state = OFF_STATE; in pciehp_handle_button_press()
198 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_handle_button_press()
201 ctrl_info(ctrl, "Slot(%s): Action canceled due to button press\n", in pciehp_handle_button_press()
202 slot_name(ctrl)); in pciehp_handle_button_press()
205 ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n", in pciehp_handle_button_press()
206 slot_name(ctrl), ctrl->state); in pciehp_handle_button_press()
209 mutex_unlock(&ctrl->state_lock); in pciehp_handle_button_press()
212 void pciehp_handle_disable_request(struct controller *ctrl) in pciehp_handle_disable_request() argument
214 mutex_lock(&ctrl->state_lock); in pciehp_handle_disable_request()
215 switch (ctrl->state) { in pciehp_handle_disable_request()
218 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_disable_request()
221 ctrl->state = POWEROFF_STATE; in pciehp_handle_disable_request()
222 mutex_unlock(&ctrl->state_lock); in pciehp_handle_disable_request()
224 ctrl->request_result = pciehp_disable_slot(ctrl, SAFE_REMOVAL); in pciehp_handle_disable_request()
227 void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) in pciehp_handle_presence_or_link_change() argument
235 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
236 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
238 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
241 ctrl->state = POWEROFF_STATE; in pciehp_handle_presence_or_link_change()
242 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
244 ctrl_info(ctrl, "Slot(%s): Link Down\n", in pciehp_handle_presence_or_link_change()
245 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
247 ctrl_info(ctrl, "Slot(%s): Card not present\n", in pciehp_handle_presence_or_link_change()
248 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
249 pciehp_disable_slot(ctrl, SURPRISE_REMOVAL); in pciehp_handle_presence_or_link_change()
252 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
257 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
258 present = pciehp_card_present(ctrl); in pciehp_handle_presence_or_link_change()
259 link_active = pciehp_check_link_active(ctrl); in pciehp_handle_presence_or_link_change()
261 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
265 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
267 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
270 ctrl->state = POWERON_STATE; in pciehp_handle_presence_or_link_change()
271 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
273 ctrl_info(ctrl, "Slot(%s): Card present\n", in pciehp_handle_presence_or_link_change()
274 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
276 ctrl_info(ctrl, "Slot(%s): Link Up\n", in pciehp_handle_presence_or_link_change()
277 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
278 ctrl->request_result = pciehp_enable_slot(ctrl); in pciehp_handle_presence_or_link_change()
281 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
286 static int __pciehp_enable_slot(struct controller *ctrl) in __pciehp_enable_slot() argument
290 if (MRL_SENS(ctrl)) { in __pciehp_enable_slot()
291 pciehp_get_latch_status(ctrl, &getstatus); in __pciehp_enable_slot()
293 ctrl_info(ctrl, "Slot(%s): Latch open\n", in __pciehp_enable_slot()
294 slot_name(ctrl)); in __pciehp_enable_slot()
299 if (POWER_CTRL(ctrl)) { in __pciehp_enable_slot()
300 pciehp_get_power_status(ctrl, &getstatus); in __pciehp_enable_slot()
302 ctrl_info(ctrl, "Slot(%s): Already enabled\n", in __pciehp_enable_slot()
303 slot_name(ctrl)); in __pciehp_enable_slot()
308 return board_added(ctrl); in __pciehp_enable_slot()
311 static int pciehp_enable_slot(struct controller *ctrl) in pciehp_enable_slot() argument
315 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_enable_slot()
316 ret = __pciehp_enable_slot(ctrl); in pciehp_enable_slot()
317 if (ret && ATTN_BUTTN(ctrl)) in pciehp_enable_slot()
319 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_enable_slot()
321 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_enable_slot()
323 mutex_lock(&ctrl->state_lock); in pciehp_enable_slot()
324 ctrl->state = ret ? OFF_STATE : ON_STATE; in pciehp_enable_slot()
325 mutex_unlock(&ctrl->state_lock); in pciehp_enable_slot()
330 static int __pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in __pciehp_disable_slot() argument
334 if (POWER_CTRL(ctrl)) { in __pciehp_disable_slot()
335 pciehp_get_power_status(ctrl, &getstatus); in __pciehp_disable_slot()
337 ctrl_info(ctrl, "Slot(%s): Already disabled\n", in __pciehp_disable_slot()
338 slot_name(ctrl)); in __pciehp_disable_slot()
343 remove_board(ctrl, safe_removal); in __pciehp_disable_slot()
347 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in pciehp_disable_slot() argument
351 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_disable_slot()
352 ret = __pciehp_disable_slot(ctrl, safe_removal); in pciehp_disable_slot()
353 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_disable_slot()
355 mutex_lock(&ctrl->state_lock); in pciehp_disable_slot()
356 ctrl->state = OFF_STATE; in pciehp_disable_slot()
357 mutex_unlock(&ctrl->state_lock); in pciehp_disable_slot()
364 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_enable_slot() local
366 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
367 switch (ctrl->state) { in pciehp_sysfs_enable_slot()
370 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
375 ctrl->request_result = -ENODEV; in pciehp_sysfs_enable_slot()
376 pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); in pciehp_sysfs_enable_slot()
377 wait_event(ctrl->requester, in pciehp_sysfs_enable_slot()
378 !atomic_read(&ctrl->pending_events)); in pciehp_sysfs_enable_slot()
379 return ctrl->request_result; in pciehp_sysfs_enable_slot()
381 ctrl_info(ctrl, "Slot(%s): Already in powering on state\n", in pciehp_sysfs_enable_slot()
382 slot_name(ctrl)); in pciehp_sysfs_enable_slot()
387 ctrl_info(ctrl, "Slot(%s): Already enabled\n", in pciehp_sysfs_enable_slot()
388 slot_name(ctrl)); in pciehp_sysfs_enable_slot()
391 ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", in pciehp_sysfs_enable_slot()
392 slot_name(ctrl), ctrl->state); in pciehp_sysfs_enable_slot()
395 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
402 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_disable_slot() local
404 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
405 switch (ctrl->state) { in pciehp_sysfs_disable_slot()
408 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
409 pciehp_request(ctrl, DISABLE_SLOT); in pciehp_sysfs_disable_slot()
410 wait_event(ctrl->requester, in pciehp_sysfs_disable_slot()
411 !atomic_read(&ctrl->pending_events)); in pciehp_sysfs_disable_slot()
412 return ctrl->request_result; in pciehp_sysfs_disable_slot()
414 ctrl_info(ctrl, "Slot(%s): Already in powering off state\n", in pciehp_sysfs_disable_slot()
415 slot_name(ctrl)); in pciehp_sysfs_disable_slot()
420 ctrl_info(ctrl, "Slot(%s): Already disabled\n", in pciehp_sysfs_disable_slot()
421 slot_name(ctrl)); in pciehp_sysfs_disable_slot()
424 ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", 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()