From: Li Jun <jun.li@nxp.com>
To: gregkh@linuxfoundation.org, robh+dt@kernel.org,
mark.rutland@arm.com, heikki.krogerus@linux.intel.com,
hdegoede@redhat.com
Cc: linux@roeck-us.net, rmfrfs@gmail.com, yueyao.zhu@gmail.com,
linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
linux-imx@nxp.com
Subject: [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink config
Date: Fri, 23 Mar 2018 22:58:44 +0800 [thread overview]
Message-ID: <1521817127-23061-3-git-send-email-jun.li@nxp.com> (raw)
In-Reply-To: <1521817127-23061-1-git-send-email-jun.li@nxp.com>
Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
variable PDO for sink config.
Signed-off-by: Li Jun <jun.li@nxp.com>
---
drivers/usb/typec/fusb302/fusb302.c | 51 +++++++++++++++++++++++++++----------
1 file changed, 37 insertions(+), 14 deletions(-)
diff --git a/drivers/usb/typec/fusb302/fusb302.c b/drivers/usb/typec/fusb302/fusb302.c
index 7036171..db4d9cd 100644
--- a/drivers/usb/typec/fusb302/fusb302.c
+++ b/drivers/usb/typec/fusb302/fusb302.c
@@ -120,6 +120,7 @@ struct fusb302_chip {
enum typec_cc_polarity cc_polarity;
enum typec_cc_status cc1;
enum typec_cc_status cc2;
+ u32 snk_pdo[PDO_MAX_OBJECTS];
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
@@ -1212,11 +1213,6 @@ static const u32 snk_pdo[] = {
static const struct tcpc_config fusb302_tcpc_config = {
.src_pdo = src_pdo,
.nr_src_pdo = ARRAY_SIZE(src_pdo),
- .snk_pdo = snk_pdo,
- .nr_snk_pdo = ARRAY_SIZE(snk_pdo),
- .max_snk_mv = 5000,
- .max_snk_ma = 3000,
- .max_snk_mw = 15000,
.operating_snk_mw = 2500,
.type = TYPEC_PORT_DRP,
.data = TYPEC_PORT_DRD,
@@ -1756,6 +1752,38 @@ static int init_gpio(struct fusb302_chip *chip)
return 0;
}
+static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip)
+{
+ struct device *dev = chip->dev;
+ u32 mv, ma, mw, min_mv;
+ unsigned int i;
+
+ /* Copy the static snk pdo */
+ for (i = 0; i < ARRAY_SIZE(snk_pdo); i++)
+ chip->snk_pdo[i] = snk_pdo[i];
+
+ if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &mv) ||
+ device_property_read_u32(dev, "fcs,max-sink-microamp", &ma) ||
+ device_property_read_u32(dev, "fcs,max-sink-microwatt", &mw))
+ return i;
+
+ mv = mv / 1000;
+ ma = ma / 1000;
+ mw = mw / 1000;
+
+ min_mv = 1000 * chip->tcpc_config.operating_snk_mw / ma;
+ if (pdo_type(snk_pdo[i-1] == PDO_TYPE_FIXED))
+ min_mv = max(min_mv, pdo_fixed_voltage(snk_pdo[i-1]));
+ else
+ min_mv = max(min_mv, pdo_max_voltage(snk_pdo[i-1]));
+ ma = min(ma, 1000 * mw / min_mv);
+
+ /* Insert the new pdo to the end */
+ chip->snk_pdo[i] = PDO_VAR(min_mv, mv, ma);
+
+ return i+1;
+}
+
static int fusb302_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -1784,18 +1812,13 @@ static int fusb302_probe(struct i2c_client *client,
chip->tcpc_dev.config = &chip->tcpc_config;
mutex_init(&chip->lock);
- if (!device_property_read_u32(dev, "fcs,max-sink-microvolt", &v))
- chip->tcpc_config.max_snk_mv = v / 1000;
-
- if (!device_property_read_u32(dev, "fcs,max-sink-microamp", &v))
- chip->tcpc_config.max_snk_ma = v / 1000;
-
- if (!device_property_read_u32(dev, "fcs,max-sink-microwatt", &v))
- chip->tcpc_config.max_snk_mw = v / 1000;
-
if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", &v))
chip->tcpc_config.operating_snk_mw = v / 1000;
+ /* Composite sink PDO */
+ chip->tcpc_config.nr_snk_pdo = fusb302_composite_snk_pdo_array(chip);
+ chip->tcpc_config.snk_pdo = chip->snk_pdo;
+
/*
* Devicetree platforms should get extcon via phandle (not yet
* supported). On ACPI platforms, we get the name from a device prop.
--
2.7.4
next prev parent reply other threads:[~2018-03-23 14:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 14:58 [PATCH v2 0/5] usb: typec: remove max_snk_mv/ma/mw Li Jun
2018-03-23 14:58 ` [PATCH v2 1/5] usb: typec: tcpm: pdo matching optimization Li Jun
2018-04-03 15:17 ` Hans de Goede
2018-04-09 6:06 ` Jun Li
2018-03-23 14:58 ` Li Jun [this message]
2018-04-03 15:25 ` [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink config Hans de Goede
2018-04-09 7:04 ` Jun Li
2018-04-04 12:06 ` Mats Karrman
2018-04-04 20:12 ` Hans de Goede
2018-04-09 9:03 ` Jun Li
2018-04-09 8:48 ` Jun Li
2018-03-23 14:58 ` [PATCH v2 3/5] dt-bindings: usb: fusb302: remove max-sink-* properties Li Jun
2018-03-26 22:25 ` Rob Herring
2018-03-23 14:58 ` [PATCH v2 4/5] usb: typec: wcove: remove max_snk_* for sink config Li Jun
2018-03-23 14:58 ` [PATCH v2 5/5] usb: typec: tcpm: remove max_snk_mv/ma/mw Li Jun
2018-04-03 15:27 ` [PATCH v2 0/5] usb: typec: " Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1521817127-23061-3-git-send-email-jun.li@nxp.com \
--to=jun.li@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-imx@nxp.com \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--cc=rmfrfs@gmail.com \
--cc=robh+dt@kernel.org \
--cc=yueyao.zhu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).