Lines Matching +full:otg +full:- +full:switch

1 // SPDX-License-Identifier: GPL-2.0
3 * otg.c - ChipIdea USB IP core OTG driver
11 * This file mainly handles otgsc register, OTG fsm operations for HNP and SRP
15 #include <linux/usb/otg.h>
21 #include "otg.h"
25 * hw_read_otgsc - returns otgsc register bits value.
38 cable = &ci->platdata->vbus_extcon; in hw_read_otgsc()
39 if (!IS_ERR(cable->edev) || ci->role_switch) { in hw_read_otgsc()
40 if (cable->changed) in hw_read_otgsc()
45 if (cable->connected) in hw_read_otgsc()
50 if (cable->enabled) in hw_read_otgsc()
56 cable = &ci->platdata->id_extcon; in hw_read_otgsc()
57 if (!IS_ERR(cable->edev) || ci->role_switch) { in hw_read_otgsc()
58 if (cable->changed) in hw_read_otgsc()
63 if (cable->connected) in hw_read_otgsc()
68 if (cable->enabled) in hw_read_otgsc()
78 * hw_write_otgsc - updates target bits of OTGSC register.
87 cable = &ci->platdata->vbus_extcon; in hw_write_otgsc()
88 if (!IS_ERR(cable->edev) || ci->role_switch) { in hw_write_otgsc()
90 cable->changed = false; in hw_write_otgsc()
94 cable->enabled = true; in hw_write_otgsc()
97 cable->enabled = false; in hw_write_otgsc()
101 cable = &ci->platdata->id_extcon; in hw_write_otgsc()
102 if (!IS_ERR(cable->edev) || ci->role_switch) { in hw_write_otgsc()
104 cable->changed = false; in hw_write_otgsc()
108 cable->enabled = true; in hw_write_otgsc()
111 cable->enabled = false; in hw_write_otgsc()
119 * ci_otg_role - pick role based on ID pin state
133 if (!ci->is_otg) { in ci_handle_vbus_change()
134 if (ci->platdata->flags & CI_HDRC_FORCE_VBUS_ACTIVE_ALWAYS) in ci_handle_vbus_change()
135 usb_gadget_vbus_connect(&ci->gadget); in ci_handle_vbus_change()
139 if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active) in ci_handle_vbus_change()
140 usb_gadget_vbus_connect(&ci->gadget); in ci_handle_vbus_change()
141 else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active) in ci_handle_vbus_change()
142 usb_gadget_vbus_disconnect(&ci->gadget); in ci_handle_vbus_change()
146 * hw_wait_vbus_lower_bsv - When we switch to device mode, the vbus value
161 dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n", in hw_wait_vbus_lower_bsv()
163 return -ETIMEDOUT; in hw_wait_vbus_lower_bsv()
175 mutex_lock(&ci->mutex); in ci_handle_id_switch()
177 if (role != ci->role) { in ci_handle_id_switch()
178 dev_dbg(ci->dev, "switching from %s to %s\n", in ci_handle_id_switch()
179 ci_role(ci)->name, ci->roles[role]->name); in ci_handle_id_switch()
181 if (ci->vbus_active && ci->role == CI_ROLE_GADGET) in ci_handle_id_switch()
184 * switch occurs during system suspend. in ci_handle_id_switch()
186 usb_gadget_vbus_disconnect(&ci->gadget); in ci_handle_id_switch()
191 IS_ERR(ci->platdata->vbus_extcon.edev)) in ci_handle_id_switch()
206 mutex_unlock(&ci->mutex); in ci_handle_id_switch()
209 * ci_otg_work - perform otg (vbus/id) event handle
217 enable_irq(ci->irq); in ci_otg_work()
221 pm_runtime_get_sync(ci->dev); in ci_otg_work()
223 if (ci->id_event) { in ci_otg_work()
224 ci->id_event = false; in ci_otg_work()
228 if (ci->b_sess_valid_event) { in ci_otg_work()
229 ci->b_sess_valid_event = false; in ci_otg_work()
233 pm_runtime_put_sync(ci->dev); in ci_otg_work()
235 enable_irq(ci->irq); in ci_otg_work()
240 * ci_hdrc_otg_init - initialize otg struct
245 INIT_WORK(&ci->work, ci_otg_work); in ci_hdrc_otg_init()
246 ci->wq = create_freezable_workqueue("ci_otg"); in ci_hdrc_otg_init()
247 if (!ci->wq) { in ci_hdrc_otg_init()
248 dev_err(ci->dev, "can't create workqueue\n"); in ci_hdrc_otg_init()
249 return -ENODEV; in ci_hdrc_otg_init()
259 * ci_hdrc_otg_destroy - destroy otg struct
264 if (ci->wq) in ci_hdrc_otg_destroy()
265 destroy_workqueue(ci->wq); in ci_hdrc_otg_destroy()
267 /* Disable all OTG irq and clear status */ in ci_hdrc_otg_destroy()