1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. 4 * Copyright (c) 2022, Linaro Ltd 5 */ 6 #include <linux/auxiliary_bus.h> 7 #include <linux/bitfield.h> 8 #include <linux/cleanup.h> 9 #include <linux/module.h> 10 #include <linux/of.h> 11 #include <linux/of_device.h> 12 #include <linux/mutex.h> 13 #include <linux/property.h> 14 #include <linux/soc/qcom/pdr.h> 15 #include <drm/bridge/aux-bridge.h> 16 17 #include <linux/usb/pd.h> 18 #include <linux/usb/typec_altmode.h> 19 #include <linux/usb/typec_dp.h> 20 #include <linux/usb/typec_mux.h> 21 #include <linux/usb/typec_retimer.h> 22 #include <linux/usb/typec_tbt.h> 23 24 #include <linux/soc/qcom/pmic_glink.h> 25 26 #define PMIC_GLINK_MAX_PORTS 3 27 28 #define USBC_SC8180X_NOTIFY_IND 0x13 29 #define USBC_CMD_WRITE_REQ 0x15 30 #define USBC_NOTIFY_IND 0x16 31 32 #define ALTMODE_PAN_EN 0x10 33 #define ALTMODE_PAN_ACK 0x11 34 35 struct usbc_write_req { 36 struct pmic_glink_hdr hdr; 37 __le32 cmd; 38 __le32 arg; 39 __le32 reserved; 40 }; 41 42 struct usbc_sc8280x_dp_data { 43 u8 pin_assignment : 6; 44 u8 hpd_state : 1; 45 u8 hpd_irq : 1; 46 u8 res[7]; 47 }; 48 49 /* Used for both TBT and USB4 notifications */ 50 struct usbc_sc8280x_tbt_data { 51 u8 usb_speed : 3; 52 u8 cable_type : 3; 53 /* This field is NOP on USB4, all cables support rounded rates by spec */ 54 u8 rounded_cable : 1; 55 u8 power_limited : 1; 56 u8 res[11]; 57 }; 58 59 struct usbc_notify { 60 struct pmic_glink_hdr hdr; 61 u8 port_idx; 62 u8 orientation; 63 u8 mux_ctrl; 64 #define MUX_CTRL_STATE_NO_CONN 0 65 #define MUX_CTRL_STATE_TUNNELING 4 66 67 u8 res; 68 __le16 vid; 69 __le16 svid; 70 union usbc_sc8280x_extended_data { 71 struct usbc_sc8280x_dp_data dp; 72 struct usbc_sc8280x_tbt_data tbt; 73 } extended_data; 74 }; 75 76 struct usbc_sc8180x_notify { 77 struct pmic_glink_hdr hdr; 78 __le32 notification; 79 __le32 reserved[2]; 80 }; 81 82 enum pmic_glink_altmode_pin_assignment { 83 DPAM_HPD_OUT, 84 DPAM_HPD_A, 85 DPAM_HPD_B, 86 DPAM_HPD_C, 87 DPAM_HPD_D, 88 DPAM_HPD_E, 89 DPAM_HPD_F, 90 }; 91 92 struct pmic_glink_altmode; 93 94 #define work_to_altmode_port(w) container_of((w), struct pmic_glink_altmode_port, work) 95 96 struct pmic_glink_altmode_port { 97 struct pmic_glink_altmode *altmode; 98 unsigned int index; 99 100 struct typec_switch *typec_switch; 101 struct typec_mux *typec_mux; 102 struct typec_mux_state state; 103 struct typec_retimer *typec_retimer; 104 struct typec_retimer_state retimer_state; 105 struct typec_altmode dp_alt; 106 struct typec_altmode tbt_alt; 107 108 struct work_struct work; 109 110 struct auxiliary_device *bridge; 111 112 enum typec_orientation orientation; 113 u16 svid; 114 struct usbc_sc8280x_tbt_data tbt_data; 115 u8 dp_data; 116 u8 mode; 117 u8 hpd_state; 118 u8 hpd_irq; 119 u8 mux_ctrl; 120 }; 121 122 #define work_to_altmode(w) container_of((w), struct pmic_glink_altmode, enable_work) 123 124 struct pmic_glink_altmode { 125 struct device *dev; 126 127 unsigned int owner_id; 128 129 /* To synchronize WRITE_REQ acks */ 130 struct mutex lock; 131 132 struct completion pan_ack; 133 struct pmic_glink_client *client; 134 135 struct work_struct enable_work; 136 137 struct pmic_glink_altmode_port ports[PMIC_GLINK_MAX_PORTS]; 138 }; 139 140 static int pmic_glink_altmode_request(struct pmic_glink_altmode *altmode, u32 cmd, u32 arg) 141 { 142 struct usbc_write_req req = {}; 143 unsigned long left; 144 int ret; 145 146 /* 147 * The USBC_CMD_WRITE_REQ ack doesn't identify the request, so wait for 148 * one ack at a time. 149 */ 150 guard(mutex)(&altmode->lock); 151 152 req.hdr.owner = cpu_to_le32(altmode->owner_id); 153 req.hdr.type = cpu_to_le32(PMIC_GLINK_REQ_RESP); 154 req.hdr.opcode = cpu_to_le32(USBC_CMD_WRITE_REQ); 155 req.cmd = cpu_to_le32(cmd); 156 req.arg = cpu_to_le32(arg); 157 158 ret = pmic_glink_send(altmode->client, &req, sizeof(req)); 159 if (ret) { 160 dev_err(altmode->dev, "failed to send altmode request: %#x (%d)\n", cmd, ret); 161 return ret; 162 } 163 164 left = wait_for_completion_timeout(&altmode->pan_ack, 5 * HZ); 165 if (!left) { 166 dev_err(altmode->dev, "timeout waiting for altmode request ack for: %#x\n", cmd); 167 return -ETIMEDOUT; 168 } 169 170 return 0; 171 } 172 173 static void pmic_glink_altmode_enable_dp(struct pmic_glink_altmode *altmode, 174 struct pmic_glink_altmode_port *port, 175 u8 mode, bool hpd_state, 176 bool hpd_irq) 177 { 178 struct typec_displayport_data dp_data = {}; 179 int ret; 180 181 dp_data.status = DP_STATUS_ENABLED; 182 if (hpd_state) 183 dp_data.status |= DP_STATUS_HPD_STATE; 184 if (hpd_irq) 185 dp_data.status |= DP_STATUS_IRQ_HPD; 186 dp_data.conf = DP_CONF_SET_PIN_ASSIGN(mode); 187 188 port->state.alt = &port->dp_alt; 189 port->state.data = &dp_data; 190 port->state.mode = TYPEC_MODAL_STATE(mode); 191 192 ret = typec_mux_set(port->typec_mux, &port->state); 193 if (ret) 194 dev_err(altmode->dev, "failed to switch mux to DP: %d\n", ret); 195 196 port->retimer_state.alt = &port->dp_alt; 197 port->retimer_state.data = &dp_data; 198 port->retimer_state.mode = TYPEC_MODAL_STATE(mode); 199 200 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); 201 if (ret) 202 dev_err(altmode->dev, "failed to setup retimer to DP: %d\n", ret); 203 } 204 205 static void pmic_glink_altmode_enable_tbt(struct pmic_glink_altmode *altmode, 206 struct pmic_glink_altmode_port *port) 207 { 208 struct usbc_sc8280x_tbt_data *tbt = &port->tbt_data; 209 struct typec_thunderbolt_data tbt_data = {}; 210 u32 cable_speed; 211 int ret; 212 213 /* Device Discover Mode VDO */ 214 tbt_data.device_mode = TBT_MODE; 215 tbt_data.device_mode |= TBT_SET_ADAPTER(TBT_ADAPTER_TBT3); 216 217 /* Cable Discover Mode VDO */ 218 tbt_data.cable_mode = TBT_MODE; 219 220 if (tbt->usb_speed == 0) { 221 cable_speed = TBT_CABLE_USB3_PASSIVE; 222 } else if (tbt->usb_speed == 1) { 223 cable_speed = TBT_CABLE_10_AND_20GBPS; 224 } else { 225 dev_err(altmode->dev, 226 "Got illegal TBT3 cable speed value (%u), falling back to passive\n", 227 tbt->usb_speed); 228 cable_speed = TBT_CABLE_USB3_PASSIVE; 229 } 230 tbt_data.cable_mode |= TBT_SET_CABLE_SPEED(cable_speed); 231 232 if (tbt->cable_type) { 233 tbt_data.cable_mode |= TBT_CABLE_ACTIVE_PASSIVE; 234 tbt_data.cable_mode |= TBT_SET_CABLE_ROUNDED(tbt->rounded_cable); 235 } 236 237 /* Enter Mode VDO */ 238 tbt_data.enter_vdo |= TBT_MODE; 239 tbt_data.enter_vdo |= TBT_ENTER_MODE_CABLE_SPEED(cable_speed); 240 241 if (tbt->cable_type) { 242 tbt_data.enter_vdo |= TBT_CABLE_ACTIVE_PASSIVE; 243 tbt_data.enter_vdo |= TBT_SET_CABLE_ROUNDED(tbt->rounded_cable); 244 } 245 246 port->state.alt = &port->tbt_alt; 247 port->state.data = &tbt_data; 248 port->state.mode = TYPEC_MODAL_STATE(port->mode); 249 250 ret = typec_mux_set(port->typec_mux, &port->state); 251 if (ret) 252 dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); 253 254 port->retimer_state.alt = &port->tbt_alt; 255 port->retimer_state.data = &tbt_data; 256 port->retimer_state.mode = TYPEC_MODAL_STATE(port->mode); 257 258 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); 259 if (ret) 260 dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); 261 } 262 263 static void pmic_glink_altmode_enable_usb4(struct pmic_glink_altmode *altmode, 264 struct pmic_glink_altmode_port *port) 265 { 266 struct usbc_sc8280x_tbt_data *tbt = &port->tbt_data; 267 struct enter_usb_data data = {}; 268 int ret; 269 270 data.eudo = FIELD_PREP(EUDO_USB_MODE_MASK, EUDO_USB_MODE_USB4); 271 272 if (tbt->usb_speed == 0) { 273 data.eudo |= FIELD_PREP(EUDO_CABLE_SPEED_MASK, EUDO_CABLE_SPEED_USB4_GEN2); 274 } else if (tbt->usb_speed == 1) { 275 data.eudo |= FIELD_PREP(EUDO_CABLE_SPEED_MASK, EUDO_CABLE_SPEED_USB4_GEN3); 276 } else { 277 pr_err("Got illegal USB4 cable speed value (%u), falling back to G2\n", 278 tbt->usb_speed); 279 data.eudo |= FIELD_PREP(EUDO_CABLE_SPEED_MASK, EUDO_CABLE_SPEED_USB4_GEN2); 280 } 281 282 data.eudo |= FIELD_PREP(EUDO_CABLE_TYPE_MASK, tbt->cable_type); 283 284 port->state.alt = NULL; 285 port->state.data = &data; 286 port->state.mode = TYPEC_MODE_USB4; 287 288 ret = typec_mux_set(port->typec_mux, &port->state); 289 if (ret) 290 dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); 291 292 port->retimer_state.alt = NULL; 293 port->retimer_state.data = &data; 294 port->retimer_state.mode = TYPEC_MODE_USB4; 295 296 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); 297 if (ret) 298 dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); 299 } 300 301 static void pmic_glink_altmode_enable_usb(struct pmic_glink_altmode *altmode, 302 struct pmic_glink_altmode_port *port) 303 { 304 int ret; 305 306 port->state.alt = NULL; 307 port->state.data = NULL; 308 port->state.mode = TYPEC_STATE_USB; 309 310 ret = typec_mux_set(port->typec_mux, &port->state); 311 if (ret) 312 dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); 313 314 port->retimer_state.alt = NULL; 315 port->retimer_state.data = NULL; 316 port->retimer_state.mode = TYPEC_STATE_USB; 317 318 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); 319 if (ret) 320 dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); 321 } 322 323 static void pmic_glink_altmode_safe(struct pmic_glink_altmode *altmode, 324 struct pmic_glink_altmode_port *port) 325 { 326 int ret; 327 328 port->state.alt = NULL; 329 port->state.data = NULL; 330 port->state.mode = TYPEC_STATE_SAFE; 331 332 ret = typec_mux_set(port->typec_mux, &port->state); 333 if (ret) 334 dev_err(altmode->dev, "failed to switch mux to safe mode: %d\n", ret); 335 336 port->retimer_state.alt = NULL; 337 port->retimer_state.data = NULL; 338 port->retimer_state.mode = TYPEC_STATE_SAFE; 339 340 ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); 341 if (ret) 342 dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); 343 } 344 345 static void pmic_glink_altmode_worker(struct work_struct *work) 346 { 347 struct pmic_glink_altmode_port *alt_port = work_to_altmode_port(work); 348 struct pmic_glink_altmode *altmode = alt_port->altmode; 349 enum drm_connector_status conn_status; 350 351 typec_switch_set(alt_port->typec_switch, alt_port->orientation); 352 353 if (alt_port->mux_ctrl == MUX_CTRL_STATE_NO_CONN) { 354 pmic_glink_altmode_safe(altmode, alt_port); 355 } else if (alt_port->svid == USB_TYPEC_TBT_SID) { 356 pmic_glink_altmode_enable_tbt(altmode, alt_port); 357 } else if (alt_port->svid == USB_TYPEC_DP_SID) { 358 pmic_glink_altmode_enable_dp(altmode, alt_port, 359 alt_port->mode, 360 alt_port->hpd_state, 361 alt_port->hpd_irq); 362 363 if (alt_port->hpd_state) 364 conn_status = connector_status_connected; 365 else 366 conn_status = connector_status_disconnected; 367 368 drm_aux_hpd_bridge_notify(&alt_port->bridge->dev, conn_status); 369 } else if (alt_port->mux_ctrl == MUX_CTRL_STATE_TUNNELING) { 370 pmic_glink_altmode_enable_usb4(altmode, alt_port); 371 } else { 372 pmic_glink_altmode_enable_usb(altmode, alt_port); 373 } 374 375 pmic_glink_altmode_request(altmode, ALTMODE_PAN_ACK, alt_port->index); 376 } 377 378 static enum typec_orientation pmic_glink_altmode_orientation(unsigned int orientation) 379 { 380 if (orientation == 0) 381 return TYPEC_ORIENTATION_NORMAL; 382 else if (orientation == 1) 383 return TYPEC_ORIENTATION_REVERSE; 384 else 385 return TYPEC_ORIENTATION_NONE; 386 } 387 388 #define SC8180X_PORT_MASK 0x000000ff 389 #define SC8180X_ORIENTATION_MASK 0x0000ff00 390 #define SC8180X_MUX_MASK 0x00ff0000 391 #define SC8180X_MODE_MASK 0x3f000000 392 #define SC8180X_HPD_STATE_MASK 0x40000000 393 #define SC8180X_HPD_IRQ_MASK 0x80000000 394 395 static void pmic_glink_altmode_sc8180xp_notify(struct pmic_glink_altmode *altmode, 396 const void *data, size_t len) 397 { 398 struct pmic_glink_altmode_port *alt_port; 399 const struct usbc_sc8180x_notify *msg; 400 u32 notification; 401 u8 orientation; 402 u8 hpd_state; 403 u8 hpd_irq; 404 u16 svid; 405 u8 port; 406 u8 mode; 407 u8 mux; 408 409 if (len != sizeof(*msg)) { 410 dev_warn(altmode->dev, "invalid length of USBC_NOTIFY indication: %zd\n", len); 411 return; 412 } 413 414 msg = data; 415 notification = le32_to_cpu(msg->notification); 416 port = FIELD_GET(SC8180X_PORT_MASK, notification); 417 orientation = FIELD_GET(SC8180X_ORIENTATION_MASK, notification); 418 mux = FIELD_GET(SC8180X_MUX_MASK, notification); 419 mode = FIELD_GET(SC8180X_MODE_MASK, notification); 420 hpd_state = FIELD_GET(SC8180X_HPD_STATE_MASK, notification); 421 hpd_irq = FIELD_GET(SC8180X_HPD_IRQ_MASK, notification); 422 423 svid = mux == 2 ? USB_TYPEC_DP_SID : 0; 424 425 if (port >= ARRAY_SIZE(altmode->ports) || !altmode->ports[port].altmode) { 426 dev_dbg(altmode->dev, "notification on undefined port %d\n", port); 427 return; 428 } 429 430 alt_port = &altmode->ports[port]; 431 alt_port->orientation = pmic_glink_altmode_orientation(orientation); 432 alt_port->svid = svid; 433 alt_port->mode = mode; 434 alt_port->hpd_state = hpd_state; 435 alt_port->hpd_irq = hpd_irq; 436 schedule_work(&alt_port->work); 437 } 438 439 #define SC8280XP_DPAM_MASK 0x3f 440 #define SC8280XP_HPD_STATE_MASK BIT(6) 441 #define SC8280XP_HPD_IRQ_MASK BIT(7) 442 443 static void pmic_glink_altmode_sc8280xp_notify(struct pmic_glink_altmode *altmode, 444 u16 svid, const void *data, size_t len) 445 { 446 struct pmic_glink_altmode_port *alt_port; 447 const struct usbc_sc8280x_tbt_data *tbt; 448 const struct usbc_sc8280x_dp_data *dp; 449 const struct usbc_notify *notify; 450 u8 orientation; 451 u8 port; 452 453 if (len != sizeof(*notify)) { 454 dev_warn(altmode->dev, "invalid length USBC_NOTIFY_IND: %zd\n", 455 len); 456 return; 457 } 458 459 notify = data; 460 461 port = notify->port_idx; 462 orientation = notify->orientation; 463 464 if (port >= ARRAY_SIZE(altmode->ports) || !altmode->ports[port].altmode) { 465 dev_dbg(altmode->dev, "notification on undefined port %d\n", port); 466 return; 467 } 468 469 alt_port = &altmode->ports[port]; 470 alt_port->orientation = pmic_glink_altmode_orientation(orientation); 471 alt_port->svid = svid; 472 alt_port->mux_ctrl = notify->mux_ctrl; 473 474 if (svid == USB_TYPEC_DP_SID) { 475 dp = ¬ify->extended_data.dp; 476 477 alt_port->mode = dp->pin_assignment - DPAM_HPD_A; 478 alt_port->hpd_state = dp->hpd_state; 479 alt_port->hpd_irq = dp->hpd_irq; 480 } else if (alt_port->mux_ctrl == MUX_CTRL_STATE_TUNNELING) { 481 /* Valid for both USB4 and TBT3 */ 482 tbt = ¬ify->extended_data.tbt; 483 484 alt_port->tbt_data = *tbt; 485 } 486 487 schedule_work(&alt_port->work); 488 } 489 490 static void pmic_glink_altmode_callback(const void *data, size_t len, void *priv) 491 { 492 struct pmic_glink_altmode *altmode = priv; 493 const struct pmic_glink_hdr *hdr = data; 494 u16 opcode; 495 u16 svid; 496 497 opcode = le32_to_cpu(hdr->opcode) & 0xff; 498 svid = le32_to_cpu(hdr->opcode) >> 16; 499 500 switch (opcode) { 501 case USBC_CMD_WRITE_REQ: 502 complete(&altmode->pan_ack); 503 break; 504 case USBC_NOTIFY_IND: 505 pmic_glink_altmode_sc8280xp_notify(altmode, svid, data, len); 506 break; 507 case USBC_SC8180X_NOTIFY_IND: 508 pmic_glink_altmode_sc8180xp_notify(altmode, data, len); 509 break; 510 } 511 } 512 513 static void pmic_glink_altmode_put_retimer(void *data) 514 { 515 typec_retimer_put(data); 516 } 517 518 static void pmic_glink_altmode_put_mux(void *data) 519 { 520 typec_mux_put(data); 521 } 522 523 static void pmic_glink_altmode_put_switch(void *data) 524 { 525 typec_switch_put(data); 526 } 527 528 static void pmic_glink_altmode_enable_worker(struct work_struct *work) 529 { 530 struct pmic_glink_altmode *altmode = work_to_altmode(work); 531 int ret; 532 533 ret = pmic_glink_altmode_request(altmode, ALTMODE_PAN_EN, 0); 534 if (ret) 535 dev_err(altmode->dev, "failed to request altmode notifications: %d\n", ret); 536 } 537 538 static void pmic_glink_altmode_pdr_notify(void *priv, int state) 539 { 540 struct pmic_glink_altmode *altmode = priv; 541 542 if (state == SERVREG_SERVICE_STATE_UP) 543 schedule_work(&altmode->enable_work); 544 } 545 546 static const struct of_device_id pmic_glink_altmode_of_quirks[] = { 547 { .compatible = "qcom,sc8180x-pmic-glink", .data = (void *)PMIC_GLINK_OWNER_USBC }, 548 {} 549 }; 550 551 static int pmic_glink_altmode_probe(struct auxiliary_device *adev, 552 const struct auxiliary_device_id *id) 553 { 554 struct pmic_glink_altmode_port *alt_port; 555 struct pmic_glink_altmode *altmode; 556 const struct of_device_id *match; 557 struct fwnode_handle *fwnode; 558 struct device *dev = &adev->dev; 559 u32 port; 560 int ret; 561 562 altmode = devm_kzalloc(dev, sizeof(*altmode), GFP_KERNEL); 563 if (!altmode) 564 return -ENOMEM; 565 566 altmode->dev = dev; 567 568 match = of_match_device(pmic_glink_altmode_of_quirks, dev->parent); 569 if (match) 570 altmode->owner_id = (unsigned long)match->data; 571 else 572 altmode->owner_id = PMIC_GLINK_OWNER_USBC_PAN; 573 574 INIT_WORK(&altmode->enable_work, pmic_glink_altmode_enable_worker); 575 init_completion(&altmode->pan_ack); 576 mutex_init(&altmode->lock); 577 578 device_for_each_child_node(dev, fwnode) { 579 ret = fwnode_property_read_u32(fwnode, "reg", &port); 580 if (ret < 0) { 581 dev_err(dev, "missing reg property of %pOFn\n", fwnode); 582 fwnode_handle_put(fwnode); 583 return ret; 584 } 585 586 if (port >= ARRAY_SIZE(altmode->ports)) { 587 dev_warn(dev, "invalid connector number, ignoring\n"); 588 continue; 589 } 590 591 if (altmode->ports[port].altmode) { 592 dev_err(dev, "multiple connector definition for port %u\n", port); 593 fwnode_handle_put(fwnode); 594 return -EINVAL; 595 } 596 597 alt_port = &altmode->ports[port]; 598 alt_port->altmode = altmode; 599 alt_port->index = port; 600 INIT_WORK(&alt_port->work, pmic_glink_altmode_worker); 601 602 alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode)); 603 if (IS_ERR(alt_port->bridge)) { 604 fwnode_handle_put(fwnode); 605 return PTR_ERR(alt_port->bridge); 606 } 607 608 alt_port->dp_alt.svid = USB_TYPEC_DP_SID; 609 alt_port->dp_alt.mode = USB_TYPEC_DP_MODE; 610 alt_port->dp_alt.active = 1; 611 612 alt_port->tbt_alt.svid = USB_TYPEC_TBT_SID; 613 alt_port->tbt_alt.mode = TYPEC_TBT_MODE; 614 alt_port->tbt_alt.active = 1; 615 616 alt_port->typec_mux = fwnode_typec_mux_get(fwnode); 617 if (IS_ERR(alt_port->typec_mux)) { 618 fwnode_handle_put(fwnode); 619 return dev_err_probe(dev, PTR_ERR(alt_port->typec_mux), 620 "failed to acquire mode-switch for port: %d\n", 621 port); 622 } 623 624 ret = devm_add_action_or_reset(dev, pmic_glink_altmode_put_mux, 625 alt_port->typec_mux); 626 if (ret) { 627 fwnode_handle_put(fwnode); 628 return ret; 629 } 630 631 alt_port->typec_retimer = fwnode_typec_retimer_get(fwnode); 632 if (IS_ERR(alt_port->typec_retimer)) { 633 fwnode_handle_put(fwnode); 634 return dev_err_probe(dev, PTR_ERR(alt_port->typec_retimer), 635 "failed to acquire retimer-switch for port: %d\n", 636 port); 637 } 638 639 ret = devm_add_action_or_reset(dev, pmic_glink_altmode_put_retimer, 640 alt_port->typec_retimer); 641 if (ret) { 642 fwnode_handle_put(fwnode); 643 return ret; 644 } 645 646 alt_port->typec_switch = fwnode_typec_switch_get(fwnode); 647 if (IS_ERR(alt_port->typec_switch)) { 648 fwnode_handle_put(fwnode); 649 return dev_err_probe(dev, PTR_ERR(alt_port->typec_switch), 650 "failed to acquire orientation-switch for port: %d\n", 651 port); 652 } 653 654 ret = devm_add_action_or_reset(dev, pmic_glink_altmode_put_switch, 655 alt_port->typec_switch); 656 if (ret) { 657 fwnode_handle_put(fwnode); 658 return ret; 659 } 660 } 661 662 for (port = 0; port < ARRAY_SIZE(altmode->ports); port++) { 663 alt_port = &altmode->ports[port]; 664 if (!alt_port->bridge) 665 continue; 666 667 ret = devm_drm_dp_hpd_bridge_add(dev, alt_port->bridge); 668 if (ret) 669 return ret; 670 } 671 672 altmode->client = devm_pmic_glink_client_alloc(dev, 673 altmode->owner_id, 674 pmic_glink_altmode_callback, 675 pmic_glink_altmode_pdr_notify, 676 altmode); 677 if (IS_ERR(altmode->client)) 678 return PTR_ERR(altmode->client); 679 680 pmic_glink_client_register(altmode->client); 681 682 return 0; 683 } 684 685 static const struct auxiliary_device_id pmic_glink_altmode_id_table[] = { 686 { .name = "pmic_glink.altmode", }, 687 {}, 688 }; 689 MODULE_DEVICE_TABLE(auxiliary, pmic_glink_altmode_id_table); 690 691 static struct auxiliary_driver pmic_glink_altmode_driver = { 692 .name = "pmic_glink_altmode", 693 .probe = pmic_glink_altmode_probe, 694 .id_table = pmic_glink_altmode_id_table, 695 }; 696 697 module_auxiliary_driver(pmic_glink_altmode_driver); 698 699 MODULE_DESCRIPTION("Qualcomm PMIC GLINK Altmode driver"); 700 MODULE_LICENSE("GPL"); 701