Skip to content

Commit

Permalink
usb: ucsi: glink: use the connector orientation GPIO to provide switc…
Browse files Browse the repository at this point in the history
…h events

[ Upstream commit c6165ed ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
superna9999 authored and gregkh committed Nov 28, 2023
1 parent 5a6afa6 commit 5b13bb6
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion drivers/usb/typec/ucsi/ucsi_glink.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#include <linux/mutex.h>
#include <linux/property.h>
#include <linux/soc/qcom/pdr.h>
#include <linux/usb/typec_mux.h>
#include <linux/gpio/consumer.h>
#include <linux/soc/qcom/pmic_glink.h>
#include "ucsi.h"

#define PMIC_GLINK_MAX_PORTS 2

#define UCSI_BUF_SIZE 48

#define MSG_TYPE_REQ_RESP 1
Expand Down Expand Up @@ -53,6 +57,9 @@ struct ucsi_notify_ind_msg {
struct pmic_glink_ucsi {
struct device *dev;

struct gpio_desc *port_orientation[PMIC_GLINK_MAX_PORTS];
struct typec_switch *port_switch[PMIC_GLINK_MAX_PORTS];

struct pmic_glink_client *client;

struct ucsi *ucsi;
Expand Down Expand Up @@ -221,8 +228,20 @@ static void pmic_glink_ucsi_notify(struct work_struct *work)
}

con_num = UCSI_CCI_CONNECTOR(cci);
if (con_num)
if (con_num) {
if (con_num < PMIC_GLINK_MAX_PORTS &&
ucsi->port_orientation[con_num - 1]) {
int orientation = gpiod_get_value(ucsi->port_orientation[con_num - 1]);

if (orientation >= 0) {
typec_switch_set(ucsi->port_switch[con_num - 1],
orientation ? TYPEC_ORIENTATION_REVERSE
: TYPEC_ORIENTATION_NORMAL);
}
}

ucsi_connector_change(ucsi->ucsi, con_num);
}

if (ucsi->sync_pending && cci & UCSI_CCI_BUSY) {
ucsi->sync_val = -EBUSY;
Expand Down Expand Up @@ -283,6 +302,7 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
{
struct pmic_glink_ucsi *ucsi;
struct device *dev = &adev->dev;
struct fwnode_handle *fwnode;
int ret;

ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL);
Expand Down Expand Up @@ -310,6 +330,38 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,

ucsi_set_drvdata(ucsi->ucsi, ucsi);

device_for_each_child_node(dev, fwnode) {
struct gpio_desc *desc;
u32 port;

ret = fwnode_property_read_u32(fwnode, "reg", &port);
if (ret < 0) {
dev_err(dev, "missing reg property of %pOFn\n", fwnode);
return ret;
}

if (port >= PMIC_GLINK_MAX_PORTS) {
dev_warn(dev, "invalid connector number, ignoring\n");
continue;
}

desc = devm_gpiod_get_index_optional(&adev->dev, "orientation", port, GPIOD_IN);

/* If GPIO isn't found, continue */
if (!desc)
continue;

if (IS_ERR(desc))
return dev_err_probe(dev, PTR_ERR(desc),
"unable to acquire orientation gpio\n");
ucsi->port_orientation[port] = desc;

ucsi->port_switch[port] = fwnode_typec_switch_get(fwnode);
if (IS_ERR(ucsi->port_switch[port]))
return dev_err_probe(dev, PTR_ERR(ucsi->port_switch[port]),
"failed to acquire orientation-switch\n");
}

ucsi->client = devm_pmic_glink_register_client(dev,
PMIC_GLINK_OWNER_USBC,
pmic_glink_ucsi_callback,
Expand Down

0 comments on commit 5b13bb6

Please sign in to comment.