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()
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()
86 retval = pciehp_configure_device(ctrl); in board_added()
89 ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n", in board_added()
95 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, in board_added()
100 set_slot_off(ctrl); in board_added()
109 static void remove_board(struct controller *ctrl, bool safe_removal) in remove_board() argument
111 pciehp_unconfigure_device(ctrl, safe_removal); in remove_board()
113 if (POWER_CTRL(ctrl)) { in remove_board()
114 pciehp_power_off_slot(ctrl); in remove_board()
125 &ctrl->pending_events); in remove_board()
128 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, 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() argument
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() local
147 mutex_lock(&ctrl->state_lock); in pciehp_queue_pushbutton_work()
148 switch (ctrl->state) { in pciehp_queue_pushbutton_work()
150 pciehp_request(ctrl, DISABLE_SLOT); in pciehp_queue_pushbutton_work()
153 pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); 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() argument
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()
169 ctrl_info(ctrl, "Slot(%s): Button press: will power off in 5 sec\n", in pciehp_handle_button_press()
170 slot_name(ctrl)); in pciehp_handle_button_press()
172 ctrl->state = BLINKINGON_STATE; in pciehp_handle_button_press()
173 ctrl_info(ctrl, "Slot(%s): Button press: will power on in 5 sec\n", in pciehp_handle_button_press()
174 slot_name(ctrl)); in pciehp_handle_button_press()
177 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_BLINK, in pciehp_handle_button_press()
179 schedule_delayed_work(&ctrl->button_work, 5 * HZ); in pciehp_handle_button_press()
188 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_button_press()
189 if (ctrl->state == BLINKINGOFF_STATE) { in pciehp_handle_button_press()
190 ctrl->state = ON_STATE; in pciehp_handle_button_press()
191 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, in pciehp_handle_button_press()
193 ctrl_info(ctrl, "Slot(%s): Button press: canceling request to power off\n", in pciehp_handle_button_press()
194 slot_name(ctrl)); in pciehp_handle_button_press()
196 ctrl->state = OFF_STATE; in pciehp_handle_button_press()
197 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_handle_button_press()
199 ctrl_info(ctrl, "Slot(%s): Button press: canceling request to power on\n", in pciehp_handle_button_press()
200 slot_name(ctrl)); in pciehp_handle_button_press()
204 ctrl_err(ctrl, "Slot(%s): Button press: ignoring invalid state %#x\n", in pciehp_handle_button_press()
205 slot_name(ctrl), ctrl->state); in pciehp_handle_button_press()
208 mutex_unlock(&ctrl->state_lock); in pciehp_handle_button_press()
211 void pciehp_handle_disable_request(struct controller *ctrl) in pciehp_handle_disable_request() argument
213 mutex_lock(&ctrl->state_lock); in pciehp_handle_disable_request()
214 switch (ctrl->state) { in pciehp_handle_disable_request()
217 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_disable_request()
220 ctrl->state = POWEROFF_STATE; in pciehp_handle_disable_request()
221 mutex_unlock(&ctrl->state_lock); in pciehp_handle_disable_request()
223 ctrl->request_result = pciehp_disable_slot(ctrl, SAFE_REMOVAL); in pciehp_handle_disable_request()
226 void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) in pciehp_handle_presence_or_link_change() argument
234 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
235 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
237 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
240 ctrl->state = POWEROFF_STATE; in pciehp_handle_presence_or_link_change()
241 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
243 ctrl_info(ctrl, "Slot(%s): Link Down\n", in pciehp_handle_presence_or_link_change()
244 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
246 ctrl_info(ctrl, "Slot(%s): Card not present\n", in pciehp_handle_presence_or_link_change()
247 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
248 pciehp_disable_slot(ctrl, SURPRISE_REMOVAL); in pciehp_handle_presence_or_link_change()
251 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
256 mutex_lock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
257 present = pciehp_card_present(ctrl); in pciehp_handle_presence_or_link_change()
258 link_active = pciehp_check_link_active(ctrl); in pciehp_handle_presence_or_link_change()
260 if (ctrl->state == BLINKINGON_STATE) { in pciehp_handle_presence_or_link_change()
261 ctrl->state = OFF_STATE; in pciehp_handle_presence_or_link_change()
262 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
263 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_handle_presence_or_link_change()
265 ctrl_info(ctrl, "Slot(%s): Card not present\n", in pciehp_handle_presence_or_link_change()
266 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
268 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
272 switch (ctrl->state) { in pciehp_handle_presence_or_link_change()
274 cancel_delayed_work(&ctrl->button_work); in pciehp_handle_presence_or_link_change()
277 ctrl->state = POWERON_STATE; in pciehp_handle_presence_or_link_change()
278 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
280 ctrl_info(ctrl, "Slot(%s): Card present\n", in pciehp_handle_presence_or_link_change()
281 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
283 ctrl_info(ctrl, "Slot(%s): Link Up\n", in pciehp_handle_presence_or_link_change()
284 slot_name(ctrl)); in pciehp_handle_presence_or_link_change()
285 ctrl->request_result = pciehp_enable_slot(ctrl); in pciehp_handle_presence_or_link_change()
288 mutex_unlock(&ctrl->state_lock); in pciehp_handle_presence_or_link_change()
293 static int __pciehp_enable_slot(struct controller *ctrl) in __pciehp_enable_slot() argument
297 if (MRL_SENS(ctrl)) { in __pciehp_enable_slot()
298 pciehp_get_latch_status(ctrl, &getstatus); in __pciehp_enable_slot()
300 ctrl_info(ctrl, "Slot(%s): Latch open\n", in __pciehp_enable_slot()
301 slot_name(ctrl)); in __pciehp_enable_slot()
306 if (POWER_CTRL(ctrl)) { in __pciehp_enable_slot()
307 pciehp_get_power_status(ctrl, &getstatus); in __pciehp_enable_slot()
309 ctrl_info(ctrl, "Slot(%s): Already enabled\n", in __pciehp_enable_slot()
310 slot_name(ctrl)); in __pciehp_enable_slot()
315 return board_added(ctrl); in __pciehp_enable_slot()
318 static int pciehp_enable_slot(struct controller *ctrl) in pciehp_enable_slot() argument
322 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_enable_slot()
323 ret = __pciehp_enable_slot(ctrl); in pciehp_enable_slot()
324 if (ret && ATTN_BUTTN(ctrl)) in pciehp_enable_slot()
326 pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, in pciehp_enable_slot()
328 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_enable_slot()
330 mutex_lock(&ctrl->state_lock); in pciehp_enable_slot()
331 ctrl->state = ret ? OFF_STATE : ON_STATE; in pciehp_enable_slot()
332 mutex_unlock(&ctrl->state_lock); in pciehp_enable_slot()
337 static int __pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in __pciehp_disable_slot() argument
341 if (POWER_CTRL(ctrl)) { in __pciehp_disable_slot()
342 pciehp_get_power_status(ctrl, &getstatus); in __pciehp_disable_slot()
344 ctrl_info(ctrl, "Slot(%s): Already disabled\n", in __pciehp_disable_slot()
345 slot_name(ctrl)); in __pciehp_disable_slot()
350 remove_board(ctrl, safe_removal); in __pciehp_disable_slot()
354 static int pciehp_disable_slot(struct controller *ctrl, bool safe_removal) in pciehp_disable_slot() argument
358 pm_runtime_get_sync(&ctrl->pcie->port->dev); in pciehp_disable_slot()
359 ret = __pciehp_disable_slot(ctrl, safe_removal); in pciehp_disable_slot()
360 pm_runtime_put(&ctrl->pcie->port->dev); in pciehp_disable_slot()
362 mutex_lock(&ctrl->state_lock); in pciehp_disable_slot()
363 ctrl->state = OFF_STATE; in pciehp_disable_slot()
364 mutex_unlock(&ctrl->state_lock); in pciehp_disable_slot()
371 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_enable_slot() local
373 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
374 switch (ctrl->state) { in pciehp_sysfs_enable_slot()
377 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
382 ctrl->request_result = -ENODEV; in pciehp_sysfs_enable_slot()
383 pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); in pciehp_sysfs_enable_slot()
384 wait_event(ctrl->requester, in pciehp_sysfs_enable_slot()
385 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_enable_slot()
386 !ctrl->ist_running); in pciehp_sysfs_enable_slot()
387 return ctrl->request_result; in pciehp_sysfs_enable_slot()
389 ctrl_info(ctrl, "Slot(%s): Already in powering on state\n", in pciehp_sysfs_enable_slot()
390 slot_name(ctrl)); in pciehp_sysfs_enable_slot()
395 ctrl_info(ctrl, "Slot(%s): Already enabled\n", in pciehp_sysfs_enable_slot()
396 slot_name(ctrl)); in pciehp_sysfs_enable_slot()
399 ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", in pciehp_sysfs_enable_slot()
400 slot_name(ctrl), ctrl->state); in pciehp_sysfs_enable_slot()
403 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_enable_slot()
410 struct controller *ctrl = to_ctrl(hotplug_slot); in pciehp_sysfs_disable_slot() local
412 mutex_lock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
413 switch (ctrl->state) { in pciehp_sysfs_disable_slot()
416 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()
417 pciehp_request(ctrl, DISABLE_SLOT); in pciehp_sysfs_disable_slot()
418 wait_event(ctrl->requester, in pciehp_sysfs_disable_slot()
419 !atomic_read(&ctrl->pending_events) && in pciehp_sysfs_disable_slot()
420 !ctrl->ist_running); in pciehp_sysfs_disable_slot()
421 return ctrl->request_result; in pciehp_sysfs_disable_slot()
423 ctrl_info(ctrl, "Slot(%s): Already in powering off state\n", in pciehp_sysfs_disable_slot()
424 slot_name(ctrl)); in pciehp_sysfs_disable_slot()
429 ctrl_info(ctrl, "Slot(%s): Already disabled\n", in pciehp_sysfs_disable_slot()
430 slot_name(ctrl)); in pciehp_sysfs_disable_slot()
433 ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", in pciehp_sysfs_disable_slot()
434 slot_name(ctrl), ctrl->state); in pciehp_sysfs_disable_slot()
437 mutex_unlock(&ctrl->state_lock); in pciehp_sysfs_disable_slot()