Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: ucsi: glink: use the connector orientation GPIO to provide switch events

On SM8550, the non-altmode orientation is not given anymore within
altmode events, even with USB SVIDs events.

On the other side, the Type-C connector orientation is correctly
reported by a signal from the PMIC.

Take this gpio signal when we detect some Type-C port activity
to notify any Type-C switches tied to the Type-C port connectors.

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Link: https://lore.kernel.org/r/20231002-topic-sm8550-upstream-type-c-orientation-v2-2-125410d3ff95@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Neil Armstrong and committed by
Greg Kroah-Hartman
c6165ed2 65682407

+53 -1
+53 -1
drivers/usb/typec/ucsi/ucsi_glink.c
··· 8 8 #include <linux/mutex.h> 9 9 #include <linux/property.h> 10 10 #include <linux/soc/qcom/pdr.h> 11 + #include <linux/usb/typec_mux.h> 12 + #include <linux/gpio/consumer.h> 11 13 #include <linux/soc/qcom/pmic_glink.h> 12 14 #include "ucsi.h" 15 + 16 + #define PMIC_GLINK_MAX_PORTS 2 13 17 14 18 #define UCSI_BUF_SIZE 48 15 19 ··· 55 51 56 52 struct pmic_glink_ucsi { 57 53 struct device *dev; 54 + 55 + struct gpio_desc *port_orientation[PMIC_GLINK_MAX_PORTS]; 56 + struct typec_switch *port_switch[PMIC_GLINK_MAX_PORTS]; 58 57 59 58 struct pmic_glink_client *client; 60 59 ··· 227 220 } 228 221 229 222 con_num = UCSI_CCI_CONNECTOR(cci); 230 - if (con_num) 223 + if (con_num) { 224 + if (con_num < PMIC_GLINK_MAX_PORTS && 225 + ucsi->port_orientation[con_num - 1]) { 226 + int orientation = gpiod_get_value(ucsi->port_orientation[con_num - 1]); 227 + 228 + if (orientation >= 0) { 229 + typec_switch_set(ucsi->port_switch[con_num - 1], 230 + orientation ? TYPEC_ORIENTATION_REVERSE 231 + : TYPEC_ORIENTATION_NORMAL); 232 + } 233 + } 234 + 231 235 ucsi_connector_change(ucsi->ucsi, con_num); 236 + } 232 237 233 238 if (ucsi->sync_pending && cci & UCSI_CCI_BUSY) { 234 239 ucsi->sync_val = -EBUSY; ··· 301 282 { 302 283 struct pmic_glink_ucsi *ucsi; 303 284 struct device *dev = &adev->dev; 285 + struct fwnode_handle *fwnode; 304 286 int ret; 305 287 306 288 ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL); ··· 328 308 return ret; 329 309 330 310 ucsi_set_drvdata(ucsi->ucsi, ucsi); 311 + 312 + device_for_each_child_node(dev, fwnode) { 313 + struct gpio_desc *desc; 314 + u32 port; 315 + 316 + ret = fwnode_property_read_u32(fwnode, "reg", &port); 317 + if (ret < 0) { 318 + dev_err(dev, "missing reg property of %pOFn\n", fwnode); 319 + return ret; 320 + } 321 + 322 + if (port >= PMIC_GLINK_MAX_PORTS) { 323 + dev_warn(dev, "invalid connector number, ignoring\n"); 324 + continue; 325 + } 326 + 327 + desc = devm_gpiod_get_index_optional(&adev->dev, "orientation", port, GPIOD_IN); 328 + 329 + /* If GPIO isn't found, continue */ 330 + if (!desc) 331 + continue; 332 + 333 + if (IS_ERR(desc)) 334 + return dev_err_probe(dev, PTR_ERR(desc), 335 + "unable to acquire orientation gpio\n"); 336 + ucsi->port_orientation[port] = desc; 337 + 338 + ucsi->port_switch[port] = fwnode_typec_switch_get(fwnode); 339 + if (IS_ERR(ucsi->port_switch[port])) 340 + return dev_err_probe(dev, PTR_ERR(ucsi->port_switch[port]), 341 + "failed to acquire orientation-switch\n"); 342 + } 331 343 332 344 ucsi->client = devm_pmic_glink_register_client(dev, 333 345 PMIC_GLINK_OWNER_USBC,