Lines Matching refs:ci
29 u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask) in hw_read_otgsc() argument
32 u32 val = hw_read(ci, OP_OTGSC, mask); in hw_read_otgsc()
38 cable = &ci->platdata->vbus_extcon; in hw_read_otgsc()
39 if (!IS_ERR(cable->edev) || ci->role_switch) { 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()
83 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data) in hw_write_otgsc() argument
87 cable = &ci->platdata->vbus_extcon; in hw_write_otgsc()
88 if (!IS_ERR(cable->edev) || ci->role_switch) { 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()
115 hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data); in hw_write_otgsc()
122 enum ci_role ci_otg_role(struct ci_hdrc *ci) in ci_otg_role() argument
124 enum ci_role role = hw_read_otgsc(ci, OTGSC_ID) in ci_otg_role()
131 void ci_handle_vbus_change(struct ci_hdrc *ci) in ci_handle_vbus_change() argument
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()
154 static int hw_wait_vbus_lower_bsv(struct ci_hdrc *ci) in hw_wait_vbus_lower_bsv() argument
159 while (hw_read_otgsc(ci, mask)) { in hw_wait_vbus_lower_bsv()
161 dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n", in hw_wait_vbus_lower_bsv()
171 void ci_handle_id_switch(struct ci_hdrc *ci) in ci_handle_id_switch() argument
175 mutex_lock(&ci->mutex); in ci_handle_id_switch()
176 role = ci_otg_role(ci); 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()
186 usb_gadget_vbus_disconnect(&ci->gadget); in ci_handle_id_switch()
188 ci_role_stop(ci); in ci_handle_id_switch()
191 IS_ERR(ci->platdata->vbus_extcon.edev)) in ci_handle_id_switch()
199 hw_wait_vbus_lower_bsv(ci); in ci_handle_id_switch()
201 ci_role_start(ci, role); in ci_handle_id_switch()
204 ci_handle_vbus_change(ci); in ci_handle_id_switch()
206 mutex_unlock(&ci->mutex); in ci_handle_id_switch()
214 struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work); in ci_otg_work() local
216 if (ci_otg_is_fsm_mode(ci) && !ci_otg_fsm_work(ci)) { in ci_otg_work()
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()
225 ci_handle_id_switch(ci); 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()
230 ci_handle_vbus_change(ci); in ci_otg_work()
233 pm_runtime_put_sync(ci->dev); in ci_otg_work()
235 enable_irq(ci->irq); in ci_otg_work()
243 int ci_hdrc_otg_init(struct ci_hdrc *ci) in ci_hdrc_otg_init() argument
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()
252 if (ci_otg_is_fsm_mode(ci)) in ci_hdrc_otg_init()
253 return ci_hdrc_otg_fsm_init(ci); in ci_hdrc_otg_init()
262 void ci_hdrc_otg_destroy(struct ci_hdrc *ci) in ci_hdrc_otg_destroy() argument
264 if (ci->wq) in ci_hdrc_otg_destroy()
265 destroy_workqueue(ci->wq); in ci_hdrc_otg_destroy()
268 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, in ci_hdrc_otg_destroy()
270 if (ci_otg_is_fsm_mode(ci)) in ci_hdrc_otg_destroy()
271 ci_hdrc_otg_fsm_remove(ci); in ci_hdrc_otg_destroy()