linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Ajay Gupta <ajayg@nvidia.com>
Cc: linux-usb@vger.kernel.org
Subject: [PATCH 01/14] usb: typec: Copy everything from struct typec_capability during registration
Date: Thu, 26 Sep 2019 13:07:19 +0300	[thread overview]
Message-ID: <20190926100727.71117-2-heikki.krogerus@linux.intel.com> (raw)
In-Reply-To: <20190926100727.71117-1-heikki.krogerus@linux.intel.com>

Copying everything from struct typec_capability to struct
typec_port during port registration.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 94a3eda62add..3835e2d9fba6 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -46,8 +46,14 @@ struct typec_port {
 	enum typec_role			vconn_role;
 	enum typec_pwr_opmode		pwr_opmode;
 	enum typec_port_type		port_type;
+	enum typec_port_type		fixed_role;
+	enum typec_port_data		port_roles;
+	enum typec_accessory		accessory[TYPEC_MAX_ACCESSORY];
 	struct mutex			port_type_lock;
 
+	u16				revision;
+	u16				pd_revision;
+
 	enum typec_orientation		orientation;
 	struct typec_switch		*sw;
 	struct typec_mux		*mux;
@@ -950,7 +956,7 @@ preferred_role_store(struct device *dev, struct device_attribute *attr,
 	int role;
 	int ret;
 
-	if (port->cap->type != TYPEC_PORT_DRP) {
+	if (port->fixed_role != TYPEC_PORT_DRP) {
 		dev_dbg(dev, "Preferred role only supported with DRP ports\n");
 		return -EOPNOTSUPP;
 	}
@@ -982,7 +988,7 @@ preferred_role_show(struct device *dev, struct device_attribute *attr,
 {
 	struct typec_port *port = to_typec_port(dev);
 
-	if (port->cap->type != TYPEC_PORT_DRP)
+	if (port->fixed_role != TYPEC_PORT_DRP)
 		return 0;
 
 	if (port->prefer_role < 0)
@@ -1009,7 +1015,7 @@ static ssize_t data_role_store(struct device *dev,
 		return ret;
 
 	mutex_lock(&port->port_type_lock);
-	if (port->cap->data != TYPEC_PORT_DRD) {
+	if (port->port_roles != TYPEC_PORT_DRD) {
 		ret = -EOPNOTSUPP;
 		goto unlock_and_ret;
 	}
@@ -1029,7 +1035,7 @@ static ssize_t data_role_show(struct device *dev,
 {
 	struct typec_port *port = to_typec_port(dev);
 
-	if (port->cap->data == TYPEC_PORT_DRD)
+	if (port->port_roles == TYPEC_PORT_DRD)
 		return sprintf(buf, "%s\n", port->data_role == TYPEC_HOST ?
 			       "[host] device" : "host [device]");
 
@@ -1044,7 +1050,7 @@ static ssize_t power_role_store(struct device *dev,
 	struct typec_port *port = to_typec_port(dev);
 	int ret;
 
-	if (!port->cap->pd_revision) {
+	if (!port->pd_revision) {
 		dev_dbg(dev, "USB Power Delivery not supported\n");
 		return -EOPNOTSUPP;
 	}
@@ -1064,9 +1070,9 @@ static ssize_t power_role_store(struct device *dev,
 		return ret;
 
 	mutex_lock(&port->port_type_lock);
-	if (port->port_type != TYPEC_PORT_DRP) {
+	if (port->fixed_role != TYPEC_PORT_DRP) {
 		dev_dbg(dev, "port type fixed at \"%s\"",
-			     typec_port_power_roles[port->port_type]);
+			     typec_port_power_roles[port->fixed_role]);
 		ret = -EOPNOTSUPP;
 		goto unlock_and_ret;
 	}
@@ -1086,7 +1092,7 @@ static ssize_t power_role_show(struct device *dev,
 {
 	struct typec_port *port = to_typec_port(dev);
 
-	if (port->cap->type == TYPEC_PORT_DRP)
+	if (port->fixed_role == TYPEC_PORT_DRP)
 		return sprintf(buf, "%s\n", port->pwr_role == TYPEC_SOURCE ?
 			       "[source] sink" : "source [sink]");
 
@@ -1102,7 +1108,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,
 	int ret;
 	enum typec_port_type type;
 
-	if (!port->cap->port_type_set || port->cap->type != TYPEC_PORT_DRP) {
+	if (!port->cap->port_type_set || port->fixed_role != TYPEC_PORT_DRP) {
 		dev_dbg(dev, "changing port type not supported\n");
 		return -EOPNOTSUPP;
 	}
@@ -1114,7 +1120,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,
 	type = ret;
 	mutex_lock(&port->port_type_lock);
 
-	if (port->port_type == type) {
+	if (port->fixed_role == type) {
 		ret = size;
 		goto unlock_and_ret;
 	}
@@ -1123,7 +1129,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,
 	if (ret)
 		goto unlock_and_ret;
 
-	port->port_type = type;
+	port->fixed_role = type;
 	ret = size;
 
 unlock_and_ret:
@@ -1137,11 +1143,11 @@ port_type_show(struct device *dev, struct device_attribute *attr,
 {
 	struct typec_port *port = to_typec_port(dev);
 
-	if (port->cap->type == TYPEC_PORT_DRP)
+	if (port->fixed_role == TYPEC_PORT_DRP)
 		return sprintf(buf, "%s\n",
-			       typec_port_types_drp[port->port_type]);
+			       typec_port_types_drp[port->fixed_role]);
 
-	return sprintf(buf, "[%s]\n", typec_port_power_roles[port->cap->type]);
+	return sprintf(buf, "[%s]\n", typec_port_power_roles[port->fixed_role]);
 }
 static DEVICE_ATTR_RW(port_type);
 
@@ -1170,7 +1176,7 @@ static ssize_t vconn_source_store(struct device *dev,
 	bool source;
 	int ret;
 
-	if (!port->cap->pd_revision) {
+	if (!port->pd_revision) {
 		dev_dbg(dev, "VCONN swap depends on USB Power Delivery\n");
 		return -EOPNOTSUPP;
 	}
@@ -1209,10 +1215,10 @@ static ssize_t supported_accessory_modes_show(struct device *dev,
 	ssize_t ret = 0;
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(port->cap->accessory); i++) {
-		if (port->cap->accessory[i])
+	for (i = 0; i < ARRAY_SIZE(port->accessory); i++) {
+		if (port->accessory[i])
 			ret += sprintf(buf + ret, "%s ",
-			       typec_accessory_modes[port->cap->accessory[i]]);
+			       typec_accessory_modes[port->accessory[i]]);
 	}
 
 	if (!ret)
@@ -1229,7 +1235,7 @@ static ssize_t usb_typec_revision_show(struct device *dev,
 				       char *buf)
 {
 	struct typec_port *port = to_typec_port(dev);
-	u16 rev = port->cap->revision;
+	u16 rev = port->revision;
 
 	return sprintf(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
 }
@@ -1241,7 +1247,7 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
 {
 	struct typec_port *p = to_typec_port(dev);
 
-	return sprintf(buf, "%d\n", (p->cap->pd_revision >> 8) & 0xff);
+	return sprintf(buf, "%d\n", (p->pd_revision >> 8) & 0xff);
 }
 static DEVICE_ATTR_RO(usb_power_delivery_revision);
 
@@ -1532,6 +1538,7 @@ struct typec_port *typec_register_port(struct device *parent,
 	struct typec_port *port;
 	int ret;
 	int id;
+	int i;
 
 	port = kzalloc(sizeof(*port), GFP_KERNEL);
 	if (!port)
@@ -1581,8 +1588,16 @@ struct typec_port *typec_register_port(struct device *parent,
 	port->id = id;
 	port->cap = cap;
 	port->port_type = cap->type;
+	port->fixed_role = cap->type;
+	port->port_roles = cap->data;
 	port->prefer_role = cap->prefer_role;
 
+	port->revision = cap->revision;
+	port->pd_revision = cap->pd_revision;
+
+	for (i = 0; i < TYPEC_MAX_ACCESSORY; i++)
+		port->accessory[i] = cap->accessory[i];
+
 	device_initialize(&port->dev);
 	port->dev.class = typec_class;
 	port->dev.parent = parent;
-- 
2.23.0


  reply	other threads:[~2019-09-26 10:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 10:07 [PATCH 00/14] usb: typec: UCSI driver overhaul Heikki Krogerus
2019-09-26 10:07 ` Heikki Krogerus [this message]
2019-09-26 10:07 ` [PATCH 02/14] usb: typec: Introduce typec_get_drvdata() Heikki Krogerus
2019-09-26 10:07 ` [PATCH 03/14] usb: typec: Separate the operations vector Heikki Krogerus
2019-09-26 10:07 ` [PATCH 04/14] usb: typec: tcpm: Start using struct typec_operations Heikki Krogerus
2019-09-26 10:07 ` [PATCH 05/14] usb: typec: tps6598x: " Heikki Krogerus
2019-09-26 10:07 ` [PATCH 06/14] usb: typec: ucsi: " Heikki Krogerus
2019-09-26 10:07 ` [PATCH 07/14] usb: typec: Remove the callback members from struct typec_capability Heikki Krogerus
2019-09-26 10:07 ` [PATCH 08/14] usb: typec: ucsi: ccg: Remove run_isr flag Heikki Krogerus
2019-09-26 10:07 ` [PATCH 09/14] usb: typec: ucsi: Simplified interface registration and I/O API Heikki Krogerus
2019-09-26 14:25 ` [PATCH 10/14] usb: typec: ucsi: acpi: Move to the new API Heikki Krogerus
2019-09-26 14:25 ` [PATCH 11/14] usb: typec: ucsi: ccg: " Heikki Krogerus
2019-09-26 14:25 ` [PATCH 12/14] usb: typec: ucsi: Remove the old API Heikki Krogerus
2019-09-26 14:25 ` [PATCH 13/14] usb: typec: ucsi: Remove struct ucsi_control Heikki Krogerus
2019-09-26 14:25 ` [PATCH 14/14] usb: typec: ucsi: Remove all bit-fields Heikki Krogerus
2019-09-27  0:13 ` [PATCH 00/14] usb: typec: UCSI driver overhaul Ajay Gupta
2019-09-27  9:44   ` Heikki Krogerus
2019-09-27 12:53   ` Heikki Krogerus
2019-09-27 16:30     ` Ajay Gupta
2019-10-01 18:36 ` Ajay Gupta
2019-10-03 14:24   ` Heikki Krogerus
2019-10-03 16:33     ` Ajay Gupta
2019-10-10 17:51       ` Ajay Gupta
2019-10-11 10:37         ` Heikki Krogerus

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=20190926100727.71117-2-heikki.krogerus@linux.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=ajayg@nvidia.com \
    --cc=linux-usb@vger.kernel.org \
    /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).