Lines Matching +full:mux +full:- +full:int +full:- +full:port
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
14 #include <drm/bridge/aux-bridge.h>
68 unsigned int index;
94 unsigned int owner_id;
107 static int pmic_glink_altmode_request(struct pmic_glink_altmode *altmode, u32 cmd, u32 arg) in pmic_glink_altmode_request()
111 int ret; in pmic_glink_altmode_request()
117 mutex_lock(&altmode->lock); in pmic_glink_altmode_request()
119 req.hdr.owner = cpu_to_le32(altmode->owner_id); in pmic_glink_altmode_request()
125 ret = pmic_glink_send(altmode->client, &req, sizeof(req)); in pmic_glink_altmode_request()
127 dev_err(altmode->dev, "failed to send altmode request: %#x (%d)\n", cmd, ret); in pmic_glink_altmode_request()
131 left = wait_for_completion_timeout(&altmode->pan_ack, 5 * HZ); in pmic_glink_altmode_request()
133 dev_err(altmode->dev, "timeout waiting for altmode request ack for: %#x\n", cmd); in pmic_glink_altmode_request()
134 ret = -ETIMEDOUT; in pmic_glink_altmode_request()
138 mutex_unlock(&altmode->lock); in pmic_glink_altmode_request()
143 struct pmic_glink_altmode_port *port, in pmic_glink_altmode_enable_dp() argument
148 int ret; in pmic_glink_altmode_enable_dp()
157 port->state.alt = &port->dp_alt; in pmic_glink_altmode_enable_dp()
158 port->state.data = &dp_data; in pmic_glink_altmode_enable_dp()
159 port->state.mode = TYPEC_MODAL_STATE(mode); in pmic_glink_altmode_enable_dp()
161 ret = typec_mux_set(port->typec_mux, &port->state); in pmic_glink_altmode_enable_dp()
163 dev_err(altmode->dev, "failed to switch mux to DP: %d\n", ret); in pmic_glink_altmode_enable_dp()
165 port->retimer_state.alt = &port->dp_alt; in pmic_glink_altmode_enable_dp()
166 port->retimer_state.data = &dp_data; in pmic_glink_altmode_enable_dp()
167 port->retimer_state.mode = TYPEC_MODAL_STATE(mode); in pmic_glink_altmode_enable_dp()
169 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); in pmic_glink_altmode_enable_dp()
171 dev_err(altmode->dev, "failed to setup retimer to DP: %d\n", ret); in pmic_glink_altmode_enable_dp()
175 struct pmic_glink_altmode_port *port) in pmic_glink_altmode_enable_usb() argument
177 int ret; in pmic_glink_altmode_enable_usb()
179 port->state.alt = NULL; in pmic_glink_altmode_enable_usb()
180 port->state.data = NULL; in pmic_glink_altmode_enable_usb()
181 port->state.mode = TYPEC_STATE_USB; in pmic_glink_altmode_enable_usb()
183 ret = typec_mux_set(port->typec_mux, &port->state); in pmic_glink_altmode_enable_usb()
185 dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); in pmic_glink_altmode_enable_usb()
187 port->retimer_state.alt = NULL; in pmic_glink_altmode_enable_usb()
188 port->retimer_state.data = NULL; in pmic_glink_altmode_enable_usb()
189 port->retimer_state.mode = TYPEC_STATE_USB; in pmic_glink_altmode_enable_usb()
191 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); in pmic_glink_altmode_enable_usb()
193 dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); in pmic_glink_altmode_enable_usb()
197 struct pmic_glink_altmode_port *port) in pmic_glink_altmode_safe() argument
199 int ret; in pmic_glink_altmode_safe()
201 port->state.alt = NULL; in pmic_glink_altmode_safe()
202 port->state.data = NULL; in pmic_glink_altmode_safe()
203 port->state.mode = TYPEC_STATE_SAFE; in pmic_glink_altmode_safe()
205 ret = typec_mux_set(port->typec_mux, &port->state); in pmic_glink_altmode_safe()
207 dev_err(altmode->dev, "failed to switch mux to safe mode: %d\n", ret); in pmic_glink_altmode_safe()
209 port->retimer_state.alt = NULL; in pmic_glink_altmode_safe()
210 port->retimer_state.data = NULL; in pmic_glink_altmode_safe()
211 port->retimer_state.mode = TYPEC_STATE_SAFE; in pmic_glink_altmode_safe()
213 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); in pmic_glink_altmode_safe()
215 dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); in pmic_glink_altmode_safe()
221 struct pmic_glink_altmode *altmode = alt_port->altmode; in pmic_glink_altmode_worker()
223 typec_switch_set(alt_port->typec_switch, alt_port->orientation); in pmic_glink_altmode_worker()
225 if (alt_port->svid == USB_TYPEC_DP_SID && alt_port->mode == 0xff) in pmic_glink_altmode_worker()
227 else if (alt_port->svid == USB_TYPEC_DP_SID) in pmic_glink_altmode_worker()
228 pmic_glink_altmode_enable_dp(altmode, alt_port, alt_port->mode, in pmic_glink_altmode_worker()
229 alt_port->hpd_state, alt_port->hpd_irq); in pmic_glink_altmode_worker()
233 drm_aux_hpd_bridge_notify(&alt_port->bridge->dev, in pmic_glink_altmode_worker()
234 alt_port->hpd_state ? in pmic_glink_altmode_worker()
238 pmic_glink_altmode_request(altmode, ALTMODE_PAN_ACK, alt_port->index); in pmic_glink_altmode_worker()
241 static enum typec_orientation pmic_glink_altmode_orientation(unsigned int orientation) in pmic_glink_altmode_orientation()
268 u8 port; in pmic_glink_altmode_sc8180xp_notify() local
270 u8 mux; in pmic_glink_altmode_sc8180xp_notify() local
273 dev_warn(altmode->dev, "invalid length of USBC_NOTIFY indication: %zd\n", len); in pmic_glink_altmode_sc8180xp_notify()
278 notification = le32_to_cpu(msg->notification); in pmic_glink_altmode_sc8180xp_notify()
279 port = FIELD_GET(SC8180X_PORT_MASK, notification); in pmic_glink_altmode_sc8180xp_notify()
281 mux = FIELD_GET(SC8180X_MUX_MASK, notification); in pmic_glink_altmode_sc8180xp_notify()
286 svid = mux == 2 ? USB_TYPEC_DP_SID : 0; in pmic_glink_altmode_sc8180xp_notify()
288 if (port >= ARRAY_SIZE(altmode->ports) || !altmode->ports[port].altmode) { in pmic_glink_altmode_sc8180xp_notify()
289 dev_dbg(altmode->dev, "notification on undefined port %d\n", port); in pmic_glink_altmode_sc8180xp_notify()
293 alt_port = &altmode->ports[port]; in pmic_glink_altmode_sc8180xp_notify()
294 alt_port->orientation = pmic_glink_altmode_orientation(orientation); in pmic_glink_altmode_sc8180xp_notify()
295 alt_port->svid = svid; in pmic_glink_altmode_sc8180xp_notify()
296 alt_port->mode = mode; in pmic_glink_altmode_sc8180xp_notify()
297 alt_port->hpd_state = hpd_state; in pmic_glink_altmode_sc8180xp_notify()
298 alt_port->hpd_irq = hpd_irq; in pmic_glink_altmode_sc8180xp_notify()
299 schedule_work(&alt_port->work); in pmic_glink_altmode_sc8180xp_notify()
315 u8 port; in pmic_glink_altmode_sc8280xp_notify() local
318 dev_warn(altmode->dev, "invalid length USBC_NOTIFY_IND: %zd\n", in pmic_glink_altmode_sc8280xp_notify()
325 port = notify->payload[0]; in pmic_glink_altmode_sc8280xp_notify()
326 orientation = notify->payload[1]; in pmic_glink_altmode_sc8280xp_notify()
327 mode = FIELD_GET(SC8280XP_DPAM_MASK, notify->payload[8]) - DPAM_HPD_A; in pmic_glink_altmode_sc8280xp_notify()
328 hpd_state = FIELD_GET(SC8280XP_HPD_STATE_MASK, notify->payload[8]); in pmic_glink_altmode_sc8280xp_notify()
329 hpd_irq = FIELD_GET(SC8280XP_HPD_IRQ_MASK, notify->payload[8]); in pmic_glink_altmode_sc8280xp_notify()
331 if (port >= ARRAY_SIZE(altmode->ports) || !altmode->ports[port].altmode) { in pmic_glink_altmode_sc8280xp_notify()
332 dev_dbg(altmode->dev, "notification on undefined port %d\n", port); in pmic_glink_altmode_sc8280xp_notify()
336 alt_port = &altmode->ports[port]; in pmic_glink_altmode_sc8280xp_notify()
337 alt_port->orientation = pmic_glink_altmode_orientation(orientation); in pmic_glink_altmode_sc8280xp_notify()
338 alt_port->svid = svid; in pmic_glink_altmode_sc8280xp_notify()
339 alt_port->mode = mode; in pmic_glink_altmode_sc8280xp_notify()
340 alt_port->hpd_state = hpd_state; in pmic_glink_altmode_sc8280xp_notify()
341 alt_port->hpd_irq = hpd_irq; in pmic_glink_altmode_sc8280xp_notify()
342 schedule_work(&alt_port->work); in pmic_glink_altmode_sc8280xp_notify()
352 opcode = le32_to_cpu(hdr->opcode) & 0xff; in pmic_glink_altmode_callback()
353 svid = le32_to_cpu(hdr->opcode) >> 16; in pmic_glink_altmode_callback()
357 complete(&altmode->pan_ack); in pmic_glink_altmode_callback()
386 int ret; in pmic_glink_altmode_enable_worker()
390 dev_err(altmode->dev, "failed to request altmode notifications: %d\n", ret); in pmic_glink_altmode_enable_worker()
393 static void pmic_glink_altmode_pdr_notify(void *priv, int state) in pmic_glink_altmode_pdr_notify()
398 schedule_work(&altmode->enable_work); in pmic_glink_altmode_pdr_notify()
402 { .compatible = "qcom,sc8180x-pmic-glink", .data = (void *)PMIC_GLINK_OWNER_USBC },
406 static int pmic_glink_altmode_probe(struct auxiliary_device *adev, in pmic_glink_altmode_probe()
413 struct device *dev = &adev->dev; in pmic_glink_altmode_probe()
414 u32 port; in pmic_glink_altmode_probe() local
415 int ret; in pmic_glink_altmode_probe()
419 return -ENOMEM; in pmic_glink_altmode_probe()
421 altmode->dev = dev; in pmic_glink_altmode_probe()
423 match = of_match_device(pmic_glink_altmode_of_quirks, dev->parent); in pmic_glink_altmode_probe()
425 altmode->owner_id = (unsigned long)match->data; in pmic_glink_altmode_probe()
427 altmode->owner_id = PMIC_GLINK_OWNER_USBC_PAN; in pmic_glink_altmode_probe()
429 INIT_WORK(&altmode->enable_work, pmic_glink_altmode_enable_worker); in pmic_glink_altmode_probe()
430 init_completion(&altmode->pan_ack); in pmic_glink_altmode_probe()
431 mutex_init(&altmode->lock); in pmic_glink_altmode_probe()
434 ret = fwnode_property_read_u32(fwnode, "reg", &port); in pmic_glink_altmode_probe()
441 if (port >= ARRAY_SIZE(altmode->ports)) { in pmic_glink_altmode_probe()
446 if (altmode->ports[port].altmode) { in pmic_glink_altmode_probe()
447 dev_err(dev, "multiple connector definition for port %u\n", port); in pmic_glink_altmode_probe()
449 return -EINVAL; in pmic_glink_altmode_probe()
452 alt_port = &altmode->ports[port]; in pmic_glink_altmode_probe()
453 alt_port->altmode = altmode; in pmic_glink_altmode_probe()
454 alt_port->index = port; in pmic_glink_altmode_probe()
455 INIT_WORK(&alt_port->work, pmic_glink_altmode_worker); in pmic_glink_altmode_probe()
457 alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode)); in pmic_glink_altmode_probe()
458 if (IS_ERR(alt_port->bridge)) { in pmic_glink_altmode_probe()
460 return PTR_ERR(alt_port->bridge); in pmic_glink_altmode_probe()
463 alt_port->dp_alt.svid = USB_TYPEC_DP_SID; in pmic_glink_altmode_probe()
464 alt_port->dp_alt.mode = USB_TYPEC_DP_MODE; in pmic_glink_altmode_probe()
465 alt_port->dp_alt.active = 1; in pmic_glink_altmode_probe()
467 alt_port->typec_mux = fwnode_typec_mux_get(fwnode); in pmic_glink_altmode_probe()
468 if (IS_ERR(alt_port->typec_mux)) { in pmic_glink_altmode_probe()
470 return dev_err_probe(dev, PTR_ERR(alt_port->typec_mux), in pmic_glink_altmode_probe()
471 "failed to acquire mode-switch for port: %d\n", in pmic_glink_altmode_probe()
472 port); in pmic_glink_altmode_probe()
476 alt_port->typec_mux); in pmic_glink_altmode_probe()
482 alt_port->typec_retimer = fwnode_typec_retimer_get(fwnode); in pmic_glink_altmode_probe()
483 if (IS_ERR(alt_port->typec_retimer)) { in pmic_glink_altmode_probe()
485 return dev_err_probe(dev, PTR_ERR(alt_port->typec_retimer), in pmic_glink_altmode_probe()
486 "failed to acquire retimer-switch for port: %d\n", in pmic_glink_altmode_probe()
487 port); in pmic_glink_altmode_probe()
491 alt_port->typec_retimer); in pmic_glink_altmode_probe()
497 alt_port->typec_switch = fwnode_typec_switch_get(fwnode); in pmic_glink_altmode_probe()
498 if (IS_ERR(alt_port->typec_switch)) { in pmic_glink_altmode_probe()
500 return dev_err_probe(dev, PTR_ERR(alt_port->typec_switch), in pmic_glink_altmode_probe()
501 "failed to acquire orientation-switch for port: %d\n", in pmic_glink_altmode_probe()
502 port); in pmic_glink_altmode_probe()
506 alt_port->typec_switch); in pmic_glink_altmode_probe()
513 for (port = 0; port < ARRAY_SIZE(altmode->ports); port++) { in pmic_glink_altmode_probe()
514 alt_port = &altmode->ports[port]; in pmic_glink_altmode_probe()
515 if (!alt_port->bridge) in pmic_glink_altmode_probe()
518 ret = devm_drm_dp_hpd_bridge_add(dev, alt_port->bridge); in pmic_glink_altmode_probe()
523 altmode->client = devm_pmic_glink_client_alloc(dev, in pmic_glink_altmode_probe()
524 altmode->owner_id, in pmic_glink_altmode_probe()
528 if (IS_ERR(altmode->client)) in pmic_glink_altmode_probe()
529 return PTR_ERR(altmode->client); in pmic_glink_altmode_probe()
531 pmic_glink_client_register(altmode->client); in pmic_glink_altmode_probe()