Lines Matching +full:data +full:- +full:role
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/extcon-provider.h>
28 unsigned int dr; /* data role */
29 bool pr; /* power role (true if VBUS enabled) */
49 * cros_ec_pd_command() - Send a command to the EC.
53 * @outdata: EC command output data
55 * @indata: EC command input data
73 return -ENOMEM; in cros_ec_pd_command()
75 msg->version = version; in cros_ec_pd_command()
76 msg->command = command; in cros_ec_pd_command()
77 msg->outsize = outsize; in cros_ec_pd_command()
78 msg->insize = insize; in cros_ec_pd_command()
81 memcpy(msg->data, outdata, outsize); in cros_ec_pd_command()
83 ret = cros_ec_cmd_xfer_status(info->ec, msg); in cros_ec_pd_command()
85 memcpy(indata, msg->data, insize); in cros_ec_pd_command()
92 * cros_ec_usb_get_power_type() - Get power type info about PD device attached
104 req.port = info->port_id; in cros_ec_usb_get_power_type()
114 * cros_ec_usb_get_pd_mux_state() - Get PD mux state for given port.
125 req.port = info->port_id; in cros_ec_usb_get_pd_mux_state()
136 * cros_ec_usb_get_role() - Get role info about possible PD device attached to a
141 * Return: role info on success, -ENOTCONN if no cable is connected, <0 on
151 pd_control.port = info->port_id; in cros_ec_usb_get_role()
152 pd_control.role = USB_PD_CTRL_ROLE_NO_CHANGE; in cros_ec_usb_get_role()
162 return -ENOTCONN; in cros_ec_usb_get_role()
166 return resp.role; in cros_ec_usb_get_role()
170 * cros_ec_pd_get_num_ports() - Get number of EC charge ports.
188 static const char *cros_ec_usb_role_string(unsigned int role) in cros_ec_usb_role_string() argument
190 return role == DR_NONE ? "DISCONNECTED" : in cros_ec_usb_role_string()
191 (role == DR_HOST ? "DFP" : "UFP"); in cros_ec_usb_role_string()
223 unsigned int role) in cros_ec_usb_power_type_is_wall_wart() argument
228 * here from that code because that breaks Suzy-Q and other kinds of in cros_ec_usb_power_type_is_wall_wart()
229 * USB Type-C cables and peripherals. in cros_ec_usb_power_type_is_wall_wart()
250 struct device *dev = info->dev; in extcon_cros_ec_detect_cable()
251 int role, power_type; in extcon_cros_ec_detect_cable() local
266 role = cros_ec_usb_get_role(info, &polarity); in extcon_cros_ec_detect_cable()
267 if (role < 0) { in extcon_cros_ec_detect_cable()
268 if (role != -ENOTCONN) { in extcon_cros_ec_detect_cable()
269 dev_err(dev, "failed getting role err = %d\n", role); in extcon_cros_ec_detect_cable()
270 return role; in extcon_cros_ec_detect_cable()
276 dr = (role & PD_CTRL_RESP_ROLE_DATA) ? DR_HOST : DR_DEVICE; in extcon_cros_ec_detect_cable()
277 pr = (role & PD_CTRL_RESP_ROLE_POWER); in extcon_cros_ec_detect_cable()
287 "connected role 0x%x pwr type %d dr %d pr %d pol %d mux %d dp %d hpd %d\n", in extcon_cros_ec_detect_cable()
288 role, power_type, dr, pr, polarity, mux, dp, hpd); in extcon_cros_ec_detect_cable()
296 cros_ec_usb_power_type_is_wall_wart(power_type, role)) in extcon_cros_ec_detect_cable()
299 if (force || info->dr != dr || info->pr != pr || info->dp != dp || in extcon_cros_ec_detect_cable()
300 info->mux != mux || info->power_type != power_type) { in extcon_cros_ec_detect_cable()
303 dev_dbg(dev, "Type/Role switch! type = %s role = %s\n", in extcon_cros_ec_detect_cable()
306 info->dr = dr; in extcon_cros_ec_detect_cable()
307 info->pr = pr; in extcon_cros_ec_detect_cable()
308 info->dp = dp; in extcon_cros_ec_detect_cable()
309 info->mux = mux; in extcon_cros_ec_detect_cable()
310 info->power_type = power_type; in extcon_cros_ec_detect_cable()
317 extcon_set_state(info->edev, EXTCON_USB, device_connected); in extcon_cros_ec_detect_cable()
318 extcon_set_state(info->edev, EXTCON_USB_HOST, host_connected); in extcon_cros_ec_detect_cable()
319 extcon_set_state(info->edev, EXTCON_DISP_DP, dp); in extcon_cros_ec_detect_cable()
320 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
323 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
326 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
329 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
332 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
335 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
338 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
341 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
344 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
348 extcon_sync(info->edev, EXTCON_USB); in extcon_cros_ec_detect_cable()
349 extcon_sync(info->edev, EXTCON_USB_HOST); in extcon_cros_ec_detect_cable()
350 extcon_sync(info->edev, EXTCON_DISP_DP); in extcon_cros_ec_detect_cable()
353 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
356 extcon_sync(info->edev, EXTCON_DISP_DP); in extcon_cros_ec_detect_cable()
371 ec = info->ec; in extcon_cros_ec_event()
386 struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); in extcon_cros_ec_probe()
387 struct device *dev = &pdev->dev; in extcon_cros_ec_probe()
388 struct device_node *np = dev->of_node; in extcon_cros_ec_probe()
393 return -ENOMEM; in extcon_cros_ec_probe()
395 info->dev = dev; in extcon_cros_ec_probe()
396 info->ec = ec; in extcon_cros_ec_probe()
401 ret = of_property_read_u32(np, "google,usb-port-id", &port); in extcon_cros_ec_probe()
403 dev_err(dev, "Missing google,usb-port-id property\n"); in extcon_cros_ec_probe()
406 info->port_id = port; in extcon_cros_ec_probe()
408 info->port_id = pdev->id; in extcon_cros_ec_probe()
418 if (info->port_id >= numports) { in extcon_cros_ec_probe()
420 return -ENODEV; in extcon_cros_ec_probe()
423 info->edev = devm_extcon_dev_allocate(dev, usb_type_c_cable); in extcon_cros_ec_probe()
424 if (IS_ERR(info->edev)) { in extcon_cros_ec_probe()
426 return -ENOMEM; in extcon_cros_ec_probe()
429 ret = devm_extcon_dev_register(dev, info->edev); in extcon_cros_ec_probe()
435 extcon_set_property_capability(info->edev, EXTCON_USB, in extcon_cros_ec_probe()
437 extcon_set_property_capability(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_probe()
439 extcon_set_property_capability(info->edev, EXTCON_USB, in extcon_cros_ec_probe()
441 extcon_set_property_capability(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_probe()
443 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_probe()
445 extcon_set_property_capability(info->edev, EXTCON_USB, in extcon_cros_ec_probe()
447 extcon_set_property_capability(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_probe()
449 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_probe()
451 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_probe()
454 info->dr = DR_NONE; in extcon_cros_ec_probe()
455 info->pr = false; in extcon_cros_ec_probe()
460 info->notifier.notifier_call = extcon_cros_ec_event; in extcon_cros_ec_probe()
461 ret = blocking_notifier_chain_register(&info->ec->event_notifier, in extcon_cros_ec_probe()
462 &info->notifier); in extcon_cros_ec_probe()
478 blocking_notifier_chain_unregister(&info->ec->event_notifier, in extcon_cros_ec_probe()
479 &info->notifier); in extcon_cros_ec_probe()
487 blocking_notifier_chain_unregister(&info->ec->event_notifier, in extcon_cros_ec_remove()
488 &info->notifier); in extcon_cros_ec_remove()
522 { .compatible = "google,extcon-usbc-cros-ec" },
530 .name = "extcon-usbc-cros-ec",