Lines Matching +full:mux +full:- +full:int +full:- +full:port

1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/extcon-provider.h>
22 int port_id;
28 unsigned int dr; /* data role */
31 bool mux; /* SuperSpeed (usb3) enabled */ member
32 unsigned int power_type;
35 static const unsigned int usb_type_c_cable[] = {
49 * cros_ec_pd_command() - Send a command to the EC.
60 static int cros_ec_pd_command(struct cros_ec_extcon_info *info, in cros_ec_pd_command()
61 unsigned int command, in cros_ec_pd_command()
62 unsigned int version, in cros_ec_pd_command()
64 unsigned int outsize, in cros_ec_pd_command()
66 unsigned int insize) in cros_ec_pd_command()
69 int ret; in cros_ec_pd_command()
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
93 * to given port.
98 static int cros_ec_usb_get_power_type(struct cros_ec_extcon_info *info) in cros_ec_usb_get_power_type()
102 int ret; in cros_ec_usb_get_power_type()
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.
117 * Return: PD mux state on success, <0 on failure.
119 static int cros_ec_usb_get_pd_mux_state(struct cros_ec_extcon_info *info) in cros_ec_usb_get_pd_mux_state()
123 int ret; in cros_ec_usb_get_pd_mux_state()
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
137 * given port.
141 * Return: role info on success, -ENOTCONN if no cable is connected, <0 on
144 static int cros_ec_usb_get_role(struct cros_ec_extcon_info *info, in cros_ec_usb_get_role()
149 int ret; in cros_ec_usb_get_role()
151 pd_control.port = info->port_id; in cros_ec_usb_get_role()
153 pd_control.mux = USB_PD_CTRL_MUX_NO_CHANGE; in cros_ec_usb_get_role()
162 return -ENOTCONN; in cros_ec_usb_get_role()
170 * cros_ec_pd_get_num_ports() - Get number of EC charge ports.
175 static int cros_ec_pd_get_num_ports(struct cros_ec_extcon_info *info) in cros_ec_pd_get_num_ports()
178 int ret; in cros_ec_pd_get_num_ports()
188 static const char *cros_ec_usb_role_string(unsigned int role) in cros_ec_usb_role_string()
194 static const char *cros_ec_usb_power_type_string(unsigned int type) in cros_ec_usb_power_type_string()
222 static bool cros_ec_usb_power_type_is_wall_wart(unsigned int type, in cros_ec_usb_power_type_is_wall_wart()
223 unsigned int role) in cros_ec_usb_power_type_is_wall_wart()
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()
247 static int extcon_cros_ec_detect_cable(struct cros_ec_extcon_info *info, in extcon_cros_ec_detect_cable()
250 struct device *dev = info->dev; in extcon_cros_ec_detect_cable()
251 int role, power_type; in extcon_cros_ec_detect_cable()
252 unsigned int dr = DR_NONE; in extcon_cros_ec_detect_cable()
256 bool mux = false; in extcon_cros_ec_detect_cable() local
268 if (role != -ENOTCONN) { in extcon_cros_ec_detect_cable()
274 int pd_mux_state; in extcon_cros_ec_detect_cable()
283 mux = pd_mux_state & USB_PD_MUX_USB_ENABLED; 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()
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()
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()
322 (union extcon_property_value)(int)pr); in extcon_cros_ec_detect_cable()
323 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
325 (union extcon_property_value)(int)pr); in extcon_cros_ec_detect_cable()
326 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
328 (union extcon_property_value)(int)polarity); in extcon_cros_ec_detect_cable()
329 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
331 (union extcon_property_value)(int)polarity); in extcon_cros_ec_detect_cable()
332 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
334 (union extcon_property_value)(int)polarity); in extcon_cros_ec_detect_cable()
335 extcon_set_property(info->edev, EXTCON_USB, in extcon_cros_ec_detect_cable()
337 (union extcon_property_value)(int)mux); in extcon_cros_ec_detect_cable()
338 extcon_set_property(info->edev, EXTCON_USB_HOST, in extcon_cros_ec_detect_cable()
340 (union extcon_property_value)(int)mux); in extcon_cros_ec_detect_cable()
341 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
343 (union extcon_property_value)(int)mux); in extcon_cros_ec_detect_cable()
344 extcon_set_property(info->edev, EXTCON_DISP_DP, in extcon_cros_ec_detect_cable()
346 (union extcon_property_value)(int)hpd); 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()
355 (union extcon_property_value)(int)hpd); in extcon_cros_ec_detect_cable()
356 extcon_sync(info->edev, EXTCON_DISP_DP); in extcon_cros_ec_detect_cable()
362 static int extcon_cros_ec_event(struct notifier_block *nb, in extcon_cros_ec_event()
371 ec = info->ec; in extcon_cros_ec_event()
383 static int extcon_cros_ec_probe(struct platform_device *pdev) in extcon_cros_ec_probe()
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()
389 int numports, ret; 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()
399 u32 port; in extcon_cros_ec_probe() local
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()
492 static int extcon_cros_ec_suspend(struct device *dev) in extcon_cros_ec_suspend()
497 static int extcon_cros_ec_resume(struct device *dev) in extcon_cros_ec_resume()
499 int ret; in extcon_cros_ec_resume()
520 { .compatible = "google,extcon-usbc-cros-ec" },
528 .name = "extcon-usbc-cros-ec",