Lines Matching refs:hd3ss3220

36 struct hd3ss3220 {  struct
46 static int hd3ss3220_set_source_pref(struct hd3ss3220 *hd3ss3220, int src_pref) in hd3ss3220_set_source_pref() argument
48 return regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL, in hd3ss3220_set_source_pref()
53 static enum usb_role hd3ss3220_get_attached_state(struct hd3ss3220 *hd3ss3220) in hd3ss3220_get_attached_state() argument
59 ret = regmap_read(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL, in hd3ss3220_get_attached_state()
81 struct hd3ss3220 *hd3ss3220 = typec_get_drvdata(port); in hd3ss3220_dr_set() local
93 ret = hd3ss3220_set_source_pref(hd3ss3220, pref); in hd3ss3220_dr_set()
96 usb_role_switch_set_role(hd3ss3220->role_sw, role_val); in hd3ss3220_dr_set()
97 typec_set_data_role(hd3ss3220->port, role); in hd3ss3220_dr_set()
106 static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220) in hd3ss3220_set_role() argument
108 enum usb_role role_state = hd3ss3220_get_attached_state(hd3ss3220); in hd3ss3220_set_role()
110 usb_role_switch_set_role(hd3ss3220->role_sw, role_state); in hd3ss3220_set_role()
112 hd3ss3220_set_source_pref(hd3ss3220, in hd3ss3220_set_role()
117 typec_set_data_role(hd3ss3220->port, TYPEC_HOST); in hd3ss3220_set_role()
120 typec_set_data_role(hd3ss3220->port, TYPEC_DEVICE); in hd3ss3220_set_role()
126 hd3ss3220->role_state = role_state; in hd3ss3220_set_role()
132 struct hd3ss3220 *hd3ss3220 = container_of(delayed_work, in output_poll_execute() local
133 struct hd3ss3220, in output_poll_execute()
135 enum usb_role role_state = hd3ss3220_get_attached_state(hd3ss3220); in output_poll_execute()
137 if (hd3ss3220->role_state != role_state) in output_poll_execute()
138 hd3ss3220_set_role(hd3ss3220); in output_poll_execute()
140 schedule_delayed_work(&hd3ss3220->output_poll_work, HZ); in output_poll_execute()
143 static irqreturn_t hd3ss3220_irq(struct hd3ss3220 *hd3ss3220) in hd3ss3220_irq() argument
147 hd3ss3220_set_role(hd3ss3220); in hd3ss3220_irq()
148 err = regmap_write_bits(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL, in hd3ss3220_irq()
160 struct hd3ss3220 *hd3ss3220 = i2c_get_clientdata(client); in hd3ss3220_irq_handler() local
162 return hd3ss3220_irq(hd3ss3220); in hd3ss3220_irq_handler()
174 struct hd3ss3220 *hd3ss3220; in hd3ss3220_probe() local
179 hd3ss3220 = devm_kzalloc(&client->dev, sizeof(struct hd3ss3220), in hd3ss3220_probe()
181 if (!hd3ss3220) in hd3ss3220_probe()
184 i2c_set_clientdata(client, hd3ss3220); in hd3ss3220_probe()
186 hd3ss3220->dev = &client->dev; in hd3ss3220_probe()
187 hd3ss3220->regmap = devm_regmap_init_i2c(client, &config); in hd3ss3220_probe()
188 if (IS_ERR(hd3ss3220->regmap)) in hd3ss3220_probe()
189 return PTR_ERR(hd3ss3220->regmap); in hd3ss3220_probe()
191 hd3ss3220_set_source_pref(hd3ss3220, in hd3ss3220_probe()
194 connector = device_get_named_child_node(hd3ss3220->dev, "connector"); in hd3ss3220_probe()
196 hd3ss3220->role_sw = fwnode_usb_role_switch_get(connector); in hd3ss3220_probe()
198 ep = fwnode_graph_get_next_endpoint(dev_fwnode(hd3ss3220->dev), NULL); in hd3ss3220_probe()
205 hd3ss3220->role_sw = usb_role_switch_get(hd3ss3220->dev); in hd3ss3220_probe()
208 if (IS_ERR(hd3ss3220->role_sw)) { in hd3ss3220_probe()
209 ret = PTR_ERR(hd3ss3220->role_sw); in hd3ss3220_probe()
214 typec_cap.driver_data = hd3ss3220; in hd3ss3220_probe()
220 hd3ss3220->port = typec_register_port(&client->dev, &typec_cap); in hd3ss3220_probe()
221 if (IS_ERR(hd3ss3220->port)) { in hd3ss3220_probe()
222 ret = PTR_ERR(hd3ss3220->port); in hd3ss3220_probe()
226 hd3ss3220_set_role(hd3ss3220); in hd3ss3220_probe()
227 ret = regmap_read(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL, &data); in hd3ss3220_probe()
232 ret = regmap_write(hd3ss3220->regmap, in hd3ss3220_probe()
247 INIT_DELAYED_WORK(&hd3ss3220->output_poll_work, output_poll_execute); in hd3ss3220_probe()
248 hd3ss3220->poll = true; in hd3ss3220_probe()
257 if (hd3ss3220->poll) in hd3ss3220_probe()
258 schedule_delayed_work(&hd3ss3220->output_poll_work, HZ); in hd3ss3220_probe()
264 typec_unregister_port(hd3ss3220->port); in hd3ss3220_probe()
266 usb_role_switch_put(hd3ss3220->role_sw); in hd3ss3220_probe()
275 struct hd3ss3220 *hd3ss3220 = i2c_get_clientdata(client); in hd3ss3220_remove() local
277 if (hd3ss3220->poll) in hd3ss3220_remove()
278 cancel_delayed_work_sync(&hd3ss3220->output_poll_work); in hd3ss3220_remove()
280 typec_unregister_port(hd3ss3220->port); in hd3ss3220_remove()
281 usb_role_switch_put(hd3ss3220->role_sw); in hd3ss3220_remove()