Lines Matching +full:power +full:- +full:role
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/extcon-provider.h>
27 unsigned int dr; /* data role */
28 bool pr; /* power role (true if VBUS enabled) */
48 * cros_ec_pd_command() - Send a command to the EC.
72 return -ENOMEM; in cros_ec_pd_command()
74 msg->version = version; in cros_ec_pd_command()
75 msg->command = command; in cros_ec_pd_command()
76 msg->outsize = outsize; in cros_ec_pd_command()
77 msg->insize = insize; in cros_ec_pd_command()
80 memcpy(msg->data, outdata, outsize); in cros_ec_pd_command()
82 ret = cros_ec_cmd_xfer_status(info->ec, msg); in cros_ec_pd_command()
84 memcpy(indata, msg->data, insize); in cros_ec_pd_command()
91 * cros_ec_usb_get_power_type() - Get power type info about PD device attached
95 * Return: power type on success, <0 on failure.
103 req.port = info->port_id; in cros_ec_usb_get_power_type()
113 * cros_ec_usb_get_pd_mux_state() - Get PD mux state for given port.
124 req.port = info->port_id; in cros_ec_usb_get_pd_mux_state()
135 * cros_ec_usb_get_role() - Get role info about possible PD device attached to a
140 * Return: role info on success, -ENOTCONN if no cable is connected, <0 on
150 pd_control.port = info->port_id; in cros_ec_usb_get_role()
151 pd_control.role = USB_PD_CTRL_ROLE_NO_CHANGE; in cros_ec_usb_get_role()
161 return -ENOTCONN; in cros_ec_usb_get_role()
165 return resp.role; in cros_ec_usb_get_role()
169 * cros_ec_pd_get_num_ports() - Get number of EC charge ports.
187 static const char *cros_ec_usb_role_string(unsigned int role) in cros_ec_usb_role_string() argument
189 return role == DR_NONE ? "DISCONNECTED" : in cros_ec_usb_role_string()
190 (role == DR_HOST ? "DFP" : "UFP"); in cros_ec_usb_role_string()
222 unsigned int role) in cros_ec_usb_power_type_is_wall_wart() argument
227 * here from that code because that breaks Suzy-Q and other kinds of in cros_ec_usb_power_type_is_wall_wart()
228 * USB Type-C cables and peripherals. in cros_ec_usb_power_type_is_wall_wart()
249 struct device *dev = info->dev; in extcon_cros_ec_detect_cable()
250 int role, power_type; in extcon_cros_ec_detect_cable() local
260 dev_err(dev, "failed getting power type err = %d\n", in extcon_cros_ec_detect_cable()
265 role = cros_ec_usb_get_role(info, &polarity); in extcon_cros_ec_detect_cable()
266 if (role < 0) { in extcon_cros_ec_detect_cable()
267 if (role != -ENOTCONN) { in extcon_cros_ec_detect_cable()
268 dev_err(dev, "failed getting role err = %d\n", role); in extcon_cros_ec_detect_cable()
269 return role; in extcon_cros_ec_detect_cable()
275 dr = (role & PD_CTRL_RESP_ROLE_DATA) ? DR_HOST : DR_DEVICE; in extcon_cros_ec_detect_cable()
276 pr = (role & PD_CTRL_RESP_ROLE_POWER); in extcon_cros_ec_detect_cable()
286 "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()
287 role, power_type, dr, pr, polarity, mux, dp, hpd); in extcon_cros_ec_detect_cable()
295 cros_ec_usb_power_type_is_wall_wart(power_type, role)) in extcon_cros_ec_detect_cable()
298 if (force || info->dr != dr || info->pr != pr || info->dp != dp || in extcon_cros_ec_detect_cable()
299 info->mux != mux || info->power_type != power_type) { in extcon_cros_ec_detect_cable()
302 dev_dbg(dev, "Type/Role switch! type = %s role = %s\n", in extcon_cros_ec_detect_cable()
305 info->dr = dr; in extcon_cros_ec_detect_cable()
306 info->pr = pr; in extcon_cros_ec_detect_cable()
307 info->dp = dp; in extcon_cros_ec_detect_cable()
308 info->mux = mux; in extcon_cros_ec_detect_cable()
309 info->power_type = power_type; in extcon_cros_ec_detect_cable()
316 extcon_set_state(info->edev, EXTCON_USB, device_connected); in extcon_cros_ec_detect_cable()
317 extcon_set_state(info->edev, EXTCON_USB_HOST, host_connected); in extcon_cros_ec_detect_cable()
318 extcon_set_state(info->edev, EXTCON_DISP_DP, dp); in extcon_cros_ec_detect_cable()
319 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
322 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
325 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
328 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
331 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
334 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
337 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
340 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
343 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
347 extcon_sync(info->edev, EXTCON_USB); in extcon_cros_ec_detect_cable()
348 extcon_sync(info->edev, EXTCON_USB_HOST); in extcon_cros_ec_detect_cable()
349 extcon_sync(info->edev, EXTCON_DISP_DP); in extcon_cros_ec_detect_cable()
352 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
355 extcon_sync(info->edev, EXTCON_DISP_DP); in extcon_cros_ec_detect_cable()
370 ec = info->ec; in extcon_cros_ec_event()
385 struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); in extcon_cros_ec_probe()
386 struct device *dev = &pdev->dev; in extcon_cros_ec_probe()
387 struct device_node *np = dev->of_node; in extcon_cros_ec_probe()
392 return -ENOMEM; in extcon_cros_ec_probe()
394 info->dev = dev; in extcon_cros_ec_probe()
395 info->ec = ec; in extcon_cros_ec_probe()
400 ret = of_property_read_u32(np, "google,usb-port-id", &port); in extcon_cros_ec_probe()
402 dev_err(dev, "Missing google,usb-port-id property\n"); in extcon_cros_ec_probe()
405 info->port_id = port; in extcon_cros_ec_probe()
407 info->port_id = pdev->id; in extcon_cros_ec_probe()
417 if (info->port_id >= numports) { in extcon_cros_ec_probe()
419 return -ENODEV; in extcon_cros_ec_probe()
422 info->edev = devm_extcon_dev_allocate(dev, usb_type_c_cable); in extcon_cros_ec_probe()
423 if (IS_ERR(info->edev)) { in extcon_cros_ec_probe()
425 return -ENOMEM; in extcon_cros_ec_probe()
428 ret = devm_extcon_dev_register(dev, info->edev); in extcon_cros_ec_probe()
434 extcon_set_property_capability(info->edev, EXTCON_USB, in extcon_cros_ec_probe()
436 extcon_set_property_capability(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_probe()
438 extcon_set_property_capability(info->edev, EXTCON_USB, in extcon_cros_ec_probe()
440 extcon_set_property_capability(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_probe()
442 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_probe()
444 extcon_set_property_capability(info->edev, EXTCON_USB, in extcon_cros_ec_probe()
446 extcon_set_property_capability(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_probe()
448 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_probe()
450 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_probe()
453 info->dr = DR_NONE; in extcon_cros_ec_probe()
454 info->pr = false; in extcon_cros_ec_probe()
459 info->notifier.notifier_call = extcon_cros_ec_event; in extcon_cros_ec_probe()
460 ret = blocking_notifier_chain_register(&info->ec->event_notifier, in extcon_cros_ec_probe()
461 &info->notifier); in extcon_cros_ec_probe()
477 blocking_notifier_chain_unregister(&info->ec->event_notifier, in extcon_cros_ec_probe()
478 &info->notifier); in extcon_cros_ec_probe()
486 blocking_notifier_chain_unregister(&info->ec->event_notifier, in extcon_cros_ec_remove()
487 &info->notifier); in extcon_cros_ec_remove()
521 { .compatible = "google,extcon-usbc-cros-ec" },
529 .name = "extcon-usbc-cros-ec",