1- From 53ed54d6246d88ea6d9f8f7c9554cdd4590c87ba Mon Sep 17 00:00:00 2001
1+ From 74b22155ad0689ec154c77a08c96181407fbd539 Mon Sep 17 00:00:00 2001
22From: Robert Nelson <
[email protected] >
3- Date: Thu, 13 Aug 2020 15:31:11 -0500
3+ Date: Thu, 13 Aug 2020 15:55:14 -0500
44Subject: [PATCH] backports: typec: from: linux.git
55
6- Reference: v4.20.17
6+ Reference: v5.0.21
77Signed-off-by: Robert Nelson <
[email protected] >
88---
99 drivers/usb/typec/typec/Kconfig | 66 +
2222 drivers/usb/typec/typec/tcpm/Makefile | 7 +
2323 drivers/usb/typec/typec/tcpm/fusb302.c | 1885 +++++++
2424 drivers/usb/typec/typec/tcpm/fusb302_reg.h | 177 +
25- drivers/usb/typec/typec/tcpm/tcpci.c | 612 +++
25+ drivers/usb/typec/typec/tcpm/tcpci.c | 612 ++
2626 drivers/usb/typec/typec/tcpm/tcpci.h | 139 +
2727 drivers/usb/typec/typec/tcpm/tcpci_rt1711h.c | 312 ++
28- drivers/usb/typec/typec/tcpm/tcpm.c | 4862 +++++++++++++++++
29- drivers/usb/typec/typec/tcpm/wcove.c | 693 +++
30- drivers/usb/typec/typec/tps6598x.c | 522 ++
28+ drivers/usb/typec/typec/tcpm/tcpm.c | 4900 +++++++++++++++++
29+ drivers/usb/typec/typec/tcpm/wcove.c | 698 +++
30+ drivers/usb/typec/typec/tps6598x.c | 536 ++
3131 drivers/usb/typec/typec/ucsi/Kconfig | 48 +
3232 drivers/usb/typec/typec/ucsi/Makefile | 12 +
3333 drivers/usb/typec/typec/ucsi/debug.h | 65 +
3737 drivers/usb/typec/typec/ucsi/ucsi.h | 337 ++
3838 drivers/usb/typec/typec/ucsi/ucsi_acpi.c | 160 +
3939 drivers/usb/typec/typec/ucsi/ucsi_ccg.c | 307 ++
40- 31 files changed, 14310 insertions(+)
40+ 31 files changed, 14367 insertions(+)
4141 create mode 100644 drivers/usb/typec/typec/Kconfig
4242 create mode 100644 drivers/usb/typec/typec/Makefile
4343 create mode 100644 drivers/usb/typec/typec/altmodes/Kconfig
@@ -3374,7 +3374,7 @@ index 000000000000..a5ff6c8eb892
33743374+ obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
33753375diff --git a/drivers/usb/typec/typec/tcpm/fusb302.c b/drivers/usb/typec/typec/tcpm/fusb302.c
33763376new file mode 100644
3377- index 000000000000..43b64d9309d0
3377+ index 000000000000..e9344997329c
33783378--- /dev/null
33793379+++ b/drivers/usb/typec/typec/tcpm/fusb302.c
33803380@@ -0,0 +1,1885 @@
@@ -5145,7 +5145,7 @@ index 000000000000..43b64d9309d0
51455145+ * to be set by the platform code which also registers the i2c client
51465146+ * for the fusb302.
51475147+ */
5148- + if (device_property_read_string(dev, "fcs ,extcon-name", &name) == 0) {
5148+ + if (device_property_read_string(dev, "linux ,extcon-name", &name) == 0) {
51495149+ chip->extcon = extcon_get_extcon_dev(name);
51505150+ if (!chip->extcon)
51515151+ return -EPROBE_DEFER;
@@ -6529,10 +6529,10 @@ index 000000000000..017389021b96
65296529+ MODULE_LICENSE("GPL");
65306530diff --git a/drivers/usb/typec/typec/tcpm/tcpm.c b/drivers/usb/typec/typec/tcpm/tcpm.c
65316531new file mode 100644
6532- index 000000000000..ba6e5cdaed2c
6532+ index 000000000000..d34e945e5d09
65336533--- /dev/null
65346534+++ b/drivers/usb/typec/typec/tcpm/tcpm.c
6535- @@ -0,0 +1,4862 @@
6535+ @@ -0,0 +1,4900 @@
65366536+ // SPDX-License-Identifier: GPL-2.0+
65376537+ /*
65386538+ * Copyright 2015-2017 Google, Inc
@@ -6572,6 +6572,7 @@ index 000000000000..ba6e5cdaed2c
65726572+ S(SRC_ATTACHED), \
65736573+ S(SRC_STARTUP), \
65746574+ S(SRC_SEND_CAPABILITIES), \
6575+ + S(SRC_SEND_CAPABILITIES_TIMEOUT), \
65756576+ S(SRC_NEGOTIATE_CAPABILITIES), \
65766577+ S(SRC_TRANSITION_SUPPLY), \
65776578+ S(SRC_READY), \
@@ -8748,7 +8749,8 @@ index 000000000000..ba6e5cdaed2c
87488749+ unsigned int i, j, max_mw = 0, max_mv = 0;
87498750+ unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
87508751+ unsigned int min_snk_mv, max_snk_mv;
8751- + u32 pdo;
8752+ + unsigned int max_op_mv;
8753+ + u32 pdo, src, snk;
87528754+ unsigned int src_pdo = 0, snk_pdo = 0;
87538755+
87548756+ /*
@@ -8798,16 +8800,18 @@ index 000000000000..ba6e5cdaed2c
87988800+ continue;
87998801+ }
88008802+
8801- + if (max_src_mv <= max_snk_mv &&
8802- + min_src_mv >= min_snk_mv) {
8803+ + if (min_src_mv <= max_snk_mv &&
8804+ + max_src_mv >= min_snk_mv) {
8805+ + max_op_mv = min(max_src_mv, max_snk_mv);
8806+ + src_mw = (max_op_mv * src_ma) / 1000;
88038807+ /* Prefer higher voltages if available */
88048808+ if ((src_mw == max_mw &&
8805- + min_src_mv > max_mv) ||
8809+ + max_op_mv > max_mv) ||
88068810+ src_mw > max_mw) {
88078811+ src_pdo = i;
88088812+ snk_pdo = j;
88098813+ max_mw = src_mw;
8810- + max_mv = max_src_mv ;
8814+ + max_mv = max_op_mv ;
88118815+ }
88128816+ }
88138817+ }
@@ -8820,16 +8824,19 @@ index 000000000000..ba6e5cdaed2c
88208824+ }
88218825+
88228826+ if (src_pdo) {
8823- + pdo = port->source_caps[src_pdo];
8827+ + src = port->source_caps[src_pdo];
8828+ + snk = port->snk_pdo[snk_pdo];
88248829+
8825- + port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
8826- + port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
8827- + port->pps_data.max_curr =
8828- + min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
8829- + port->pps_data.out_volt =
8830- + min(pdo_pps_apdo_max_voltage(pdo), port->pps_data.out_volt);
8831- + port->pps_data.op_curr =
8832- + min(port->pps_data.max_curr, port->pps_data.op_curr);
8830+ + port->pps_data.min_volt = max(pdo_pps_apdo_min_voltage(src),
8831+ + pdo_pps_apdo_min_voltage(snk));
8832+ + port->pps_data.max_volt = min(pdo_pps_apdo_max_voltage(src),
8833+ + pdo_pps_apdo_max_voltage(snk));
8834+ + port->pps_data.max_curr = min_pps_apdo_current(src, snk);
8835+ + port->pps_data.out_volt = min(port->pps_data.max_volt,
8836+ + max(port->pps_data.min_volt,
8837+ + port->pps_data.out_volt));
8838+ + port->pps_data.op_curr = min(port->pps_data.max_curr,
8839+ + port->pps_data.op_curr);
88338840+ }
88348841+
88358842+ return src_pdo;
@@ -9495,10 +9502,34 @@ index 000000000000..ba6e5cdaed2c
94959502+ /* port->hard_reset_count = 0; */
94969503+ port->caps_count = 0;
94979504+ port->pd_capable = true;
9498- + tcpm_set_state_cond(port, hard_reset_state(port) ,
9505+ + tcpm_set_state_cond(port, SRC_SEND_CAPABILITIES_TIMEOUT ,
94999506+ PD_T_SEND_SOURCE_CAP);
95009507+ }
95019508+ break;
9509+ + case SRC_SEND_CAPABILITIES_TIMEOUT:
9510+ + /*
9511+ + * Error recovery for a PD_DATA_SOURCE_CAP reply timeout.
9512+ + *
9513+ + * PD 2.0 sinks are supposed to accept src-capabilities with a
9514+ + * 3.0 header and simply ignore any src PDOs which the sink does
9515+ + * not understand such as PPS but some 2.0 sinks instead ignore
9516+ + * the entire PD_DATA_SOURCE_CAP message, causing contract
9517+ + * negotiation to fail.
9518+ + *
9519+ + * After PD_N_HARD_RESET_COUNT hard-reset attempts, we try
9520+ + * sending src-capabilities with a lower PD revision to
9521+ + * make these broken sinks work.
9522+ + */
9523+ + if (port->hard_reset_count < PD_N_HARD_RESET_COUNT) {
9524+ + tcpm_set_state(port, HARD_RESET_SEND, 0);
9525+ + } else if (port->negotiated_rev > PD_REV20) {
9526+ + port->negotiated_rev--;
9527+ + port->hard_reset_count = 0;
9528+ + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0);
9529+ + } else {
9530+ + tcpm_set_state(port, hard_reset_state(port), 0);
9531+ + }
9532+ + break;
95029533+ case SRC_NEGOTIATE_CAPABILITIES:
95039534+ ret = tcpm_pd_check_request(port);
95049535+ if (ret < 0) {
@@ -9805,7 +9836,8 @@ index 000000000000..ba6e5cdaed2c
98059836+ case SNK_HARD_RESET_SINK_OFF:
98069837+ memset(&port->pps_data, 0, sizeof(port->pps_data));
98079838+ tcpm_set_vconn(port, false);
9808- + tcpm_set_charge(port, false);
9839+ + if (port->pd_capable)
9840+ + tcpm_set_charge(port, false);
98099841+ tcpm_set_roles(port, port->self_powered, TYPEC_SINK,
98109842+ TYPEC_DEVICE);
98119843+ /*
@@ -9837,6 +9869,12 @@ index 000000000000..ba6e5cdaed2c
98379869+ * Similar, dual-mode ports in source mode should transition
98389870+ * to PE_SNK_Transition_to_default.
98399871+ */
9872+ + if (port->pd_capable) {
9873+ + tcpm_set_current_limit(port,
9874+ + tcpm_get_current_limit(port),
9875+ + 5000);
9876+ + tcpm_set_charge(port, true);
9877+ + }
98409878+ tcpm_set_attached_state(port, true);
98419879+ tcpm_set_state(port, SNK_STARTUP, 0);
98429880+ break;
@@ -11397,10 +11435,10 @@ index 000000000000..ba6e5cdaed2c
1139711435+ MODULE_LICENSE("GPL");
1139811436diff --git a/drivers/usb/typec/typec/tcpm/wcove.c b/drivers/usb/typec/typec/tcpm/wcove.c
1139911437new file mode 100644
11400- index 000000000000..423208e19383
11438+ index 000000000000..6770afd40765
1140111439--- /dev/null
1140211440+++ b/drivers/usb/typec/typec/tcpm/wcove.c
11403- @@ -0,0 +1,693 @@
11441+ @@ -0,0 +1,698 @@
1140411442+ // SPDX-License-Identifier: GPL-2.0
1140511443+ /**
1140611444+ * typec_wcove.c - WhiskeyCove PMIC USB Type-C PHY driver
@@ -12018,8 +12056,13 @@ index 000000000000..423208e19383
1201812056+ wcove->dev = &pdev->dev;
1201912057+ wcove->regmap = pmic->regmap;
1202012058+
12021- + irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr,
12022- + platform_get_irq(pdev, 0));
12059+ + irq = platform_get_irq(pdev, 0);
12060+ + if (irq < 0) {
12061+ + dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
12062+ + return irq;
12063+ + }
12064+ +
12065+ + irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr, irq);
1202312066+ if (irq < 0)
1202412067+ return irq;
1202512068+
@@ -12096,10 +12139,10 @@ index 000000000000..423208e19383
1209612139+ MODULE_ALIAS("platform:bxt_wcove_usbc");
1209712140diff --git a/drivers/usb/typec/typec/tps6598x.c b/drivers/usb/typec/typec/tps6598x.c
1209812141new file mode 100644
12099- index 000000000000..c84c8c189e90
12142+ index 000000000000..e1109b15636d
1210012143--- /dev/null
1210112144+++ b/drivers/usb/typec/typec/tps6598x.c
12102- @@ -0,0 +1,522 @@
12145+ @@ -0,0 +1,536 @@
1210312146+ // SPDX-License-Identifier: GPL-2.0
1210412147+ /*
1210512148+ * Driver for TI TPS6598x USB Power Delivery controller family
@@ -12212,6 +12255,20 @@ index 000000000000..c84c8c189e90
1221212255+ return 0;
1221312256+ }
1221412257+
12258+ + static int tps6598x_block_write(struct tps6598x *tps, u8 reg,
12259+ + void *val, size_t len)
12260+ + {
12261+ + u8 data[TPS_MAX_LEN + 1];
12262+ +
12263+ + if (!tps->i2c_protocol)
12264+ + return regmap_raw_write(tps->regmap, reg, val, len);
12265+ +
12266+ + data[0] = len;
12267+ + memcpy(&data[1], val, len);
12268+ +
12269+ + return regmap_raw_write(tps->regmap, reg, data, sizeof(data));
12270+ + }
12271+ +
1221512272+ static inline int tps6598x_read16(struct tps6598x *tps, u8 reg, u16 *val)
1221612273+ {
1221712274+ return tps6598x_block_read(tps, reg, val, sizeof(u16));
@@ -12229,23 +12286,23 @@ index 000000000000..c84c8c189e90
1222912286+
1223012287+ static inline int tps6598x_write16(struct tps6598x *tps, u8 reg, u16 val)
1223112288+ {
12232- + return regmap_raw_write (tps->regmap , reg, &val, sizeof(u16));
12289+ + return tps6598x_block_write (tps, reg, &val, sizeof(u16));
1223312290+ }
1223412291+
1223512292+ static inline int tps6598x_write32(struct tps6598x *tps, u8 reg, u32 val)
1223612293+ {
12237- + return regmap_raw_write (tps->regmap , reg, &val, sizeof(u32));
12294+ + return tps6598x_block_write (tps, reg, &val, sizeof(u32));
1223812295+ }
1223912296+
1224012297+ static inline int tps6598x_write64(struct tps6598x *tps, u8 reg, u64 val)
1224112298+ {
12242- + return regmap_raw_write (tps->regmap , reg, &val, sizeof(u64));
12299+ + return tps6598x_block_write (tps, reg, &val, sizeof(u64));
1224312300+ }
1224412301+
1224512302+ static inline int
1224612303+ tps6598x_write_4cc(struct tps6598x *tps, u8 reg, const char *val)
1224712304+ {
12248- + return regmap_raw_write (tps->regmap , reg, &val, sizeof(u32));
12305+ + return tps6598x_block_write (tps, reg, &val, sizeof(u32));
1224912306+ }
1225012307+
1225112308+ static int tps6598x_read_partner_identity(struct tps6598x *tps)
@@ -12331,8 +12388,8 @@ index 000000000000..c84c8c189e90
1233112388+ return -EBUSY;
1233212389+
1233312390+ if (in_len) {
12334- + ret = regmap_raw_write (tps->regmap , TPS_REG_DATA1,
12335- + in_data, in_len);
12391+ + ret = tps6598x_block_write (tps, TPS_REG_DATA1,
12392+ + in_data, in_len);
1233612393+ if (ret)
1233712394+ return ret;
1233812395+ }
@@ -12603,19 +12660,19 @@ index 000000000000..c84c8c189e90
1260312660+ return 0;
1260412661+ }
1260512662+
12606- + static const struct acpi_device_id tps6598x_acpi_match [] = {
12607- + { "INT3515", 0 },
12663+ + static const struct i2c_device_id tps6598x_id [] = {
12664+ + { "tps6598x" },
1260812665+ { }
1260912666+ };
12610- + MODULE_DEVICE_TABLE(acpi, tps6598x_acpi_match );
12667+ + MODULE_DEVICE_TABLE(i2c, tps6598x_id );
1261112668+
1261212669+ static struct i2c_driver tps6598x_i2c_driver = {
1261312670+ .driver = {
1261412671+ .name = "tps6598x",
12615- + .acpi_match_table = tps6598x_acpi_match,
1261612672+ },
1261712673+ .probe_new = tps6598x_probe,
1261812674+ .remove = tps6598x_remove,
12675+ + .id_table = tps6598x_id,
1261912676+ };
1262012677+ module_i2c_driver(tps6598x_i2c_driver);
1262112678+
0 commit comments