Lines Matching defs:ci
19 #include "ci.h"
26 * @ci: the controller
29 u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
32 u32 val = hw_read(ci, OP_OTGSC, mask);
38 cable = &ci->platdata->vbus_extcon;
39 if (!IS_ERR(cable->edev) || ci->role_switch) {
56 cable = &ci->platdata->id_extcon;
57 if (!IS_ERR(cable->edev) || ci->role_switch) {
79 * @ci: the controller
83 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
87 cable = &ci->platdata->vbus_extcon;
88 if (!IS_ERR(cable->edev) || ci->role_switch) {
101 cable = &ci->platdata->id_extcon;
102 if (!IS_ERR(cable->edev) || ci->role_switch) {
115 hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
120 * @ci: the controller
122 enum ci_role ci_otg_role(struct ci_hdrc *ci)
124 enum ci_role role = hw_read_otgsc(ci, OTGSC_ID)
131 void ci_handle_vbus_change(struct ci_hdrc *ci)
133 if (!ci->is_otg)
136 if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
137 usb_gadget_vbus_connect(&ci->gadget);
138 else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
139 usb_gadget_vbus_disconnect(&ci->gadget);
146 * @ci: the controller
150 static int hw_wait_vbus_lower_bsv(struct ci_hdrc *ci)
155 while (hw_read_otgsc(ci, mask)) {
157 dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n",
167 static void ci_handle_id_switch(struct ci_hdrc *ci)
171 mutex_lock(&ci->mutex);
172 role = ci_otg_role(ci);
173 if (role != ci->role) {
174 dev_dbg(ci->dev, "switching from %s to %s\n",
175 ci_role(ci)->name, ci->roles[role]->name);
177 if (ci->vbus_active && ci->role == CI_ROLE_GADGET)
182 usb_gadget_vbus_disconnect(&ci->gadget);
184 ci_role_stop(ci);
187 IS_ERR(ci->platdata->vbus_extcon.edev))
195 hw_wait_vbus_lower_bsv(ci);
197 ci_role_start(ci, role);
200 ci_handle_vbus_change(ci);
202 mutex_unlock(&ci->mutex);
210 struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work);
212 if (ci_otg_is_fsm_mode(ci) && !ci_otg_fsm_work(ci)) {
213 enable_irq(ci->irq);
217 pm_runtime_get_sync(ci->dev);
219 if (ci->id_event) {
220 ci->id_event = false;
221 ci_handle_id_switch(ci);
224 if (ci->b_sess_valid_event) {
225 ci->b_sess_valid_event = false;
226 ci_handle_vbus_change(ci);
229 pm_runtime_put_sync(ci->dev);
231 enable_irq(ci->irq);
237 * @ci: the controller
239 int ci_hdrc_otg_init(struct ci_hdrc *ci)
241 INIT_WORK(&ci->work, ci_otg_work);
242 ci->wq = create_freezable_workqueue("ci_otg");
243 if (!ci->wq) {
244 dev_err(ci->dev, "can't create workqueue\n");
248 if (ci_otg_is_fsm_mode(ci))
249 return ci_hdrc_otg_fsm_init(ci);
256 * @ci: the controller
258 void ci_hdrc_otg_destroy(struct ci_hdrc *ci)
260 if (ci->wq) {
261 flush_workqueue(ci->wq);
262 destroy_workqueue(ci->wq);
265 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
267 if (ci_otg_is_fsm_mode(ci))
268 ci_hdrc_otg_fsm_remove(ci);