History

usb: typec: Separate the operations vector

Introducing struct typec_operations which has the same callbacks as struct typec_capability. The old callbacks are kept for now, but after all users have been converted, they will be removed.

Heikki Krogerus committed 7 years ago

Commit 46310e41 parent 8c127a42 files · +49 −10Browse files

Unified · Split

2 files
  1. drivers/usb/typec/class.c +29 −10
  2. include/linux/usb/typec.h +20 −0
drivers/usb/typec/class.c+29−10
@@ -54,6 +54,7 @@ struct typec_port { · 53 unmodified lines
5454
5555 const struct typec_capability *orig_cap; /* to be removed */
5656 const struct typec_capability *cap;
57+ const struct typec_operations *ops;
5758 };
5859
5960 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
@@ -956,7 +957,7 @@ preferred_role_store(struct device *dev, struct device_attribute *attr, · 896 unmodified lines
956957 return -EOPNOTSUPP;
957958 }
958959
959− if (!port->cap->try_role) {
960+ if (!port->cap->try_role && (!port->ops || !port->ops->try_role)) {
960961 dev_dbg(dev, "Setting preferred role not supported\n");
961962 return -EOPNOTSUPP;
962963 }
@@ -969,7 +970,10 @@ preferred_role_store(struct device *dev, struct device_attribute *attr, · 6 unmodified lines
969970 return -EINVAL;
970971 }
971972
972− ret = port->cap->try_role(port->orig_cap, role);
973+ if (port->ops && port->ops->try_role)
974+ ret = port->ops->try_role(port, role);
975+ else
976+ ret = port->cap->try_role(port->orig_cap, role);
973977 if (ret)
974978 return ret;
975979
@@ -1000,7 +1004,7 @@ static ssize_t data_role_store(struct device *dev, · 24 unmodified lines
10001004 struct typec_port *port = to_typec_port(dev);
10011005 int ret;
10021006
1003− if (!port->cap->dr_set) {
1007+ if (!port->cap->dr_set && (!port->ops || !port->ops->dr_set)) {
10041008 dev_dbg(dev, "data role swapping not supported\n");
10051009 return -EOPNOTSUPP;
10061010 }
@@ -1015,7 +1019,10 @@ static ssize_t data_role_store(struct device *dev, · 8 unmodified lines
10151019 goto unlock_and_ret;
10161020 }
10171021
1018− ret = port->cap->dr_set(port->orig_cap, ret);
1022+ if (port->ops && port->ops->dr_set)
1023+ ret = port->ops->dr_set(port, ret);
1024+ else
1025+ ret = port->cap->dr_set(port->orig_cap, ret);
10191026 if (ret)
10201027 goto unlock_and_ret;
10211028
@@ -1050,7 +1057,7 @@ static ssize_t power_role_store(struct device *dev, · 28 unmodified lines
10501057 return -EOPNOTSUPP;
10511058 }
10521059
1053− if (!port->cap->pr_set) {
1060+ if (!port->cap->pr_set && (!port->ops || !port->ops->pr_set)) {
10541061 dev_dbg(dev, "power role swapping not supported\n");
10551062 return -EOPNOTSUPP;
10561063 }
@@ -1072,7 +1079,10 @@ static ssize_t power_role_store(struct device *dev, · 15 unmodified lines
10721079 goto unlock_and_ret;
10731080 }
10741081
1075− ret = port->cap->pr_set(port->orig_cap, ret);
1082+ if (port->ops && port->ops->dr_set)
1083+ ret = port->ops->pr_set(port, ret);
1084+ else
1085+ ret = port->cap->pr_set(port->orig_cap, ret);
10761086 if (ret)
10771087 goto unlock_and_ret;
10781088
@@ -1103,7 +1113,8 @@ port_type_store(struct device *dev, struct device_attribute *attr, · 24 unmodified lines
11031113 int ret;
11041114 enum typec_port_type type;
11051115
1106− if (!port->cap->port_type_set || port->cap->type != TYPEC_PORT_DRP) {
1116+ if (port->cap->type != TYPEC_PORT_DRP || (!port->cap->port_type_set &&
1117+ (!port->ops || !port->ops->port_type_set))) {
11071118 dev_dbg(dev, "changing port type not supported\n");
11081119 return -EOPNOTSUPP;
11091120 }
@@ -1120,7 +1131,10 @@ port_type_store(struct device *dev, struct device_attribute *attr, · 10 unmodified lines
11201131 goto unlock_and_ret;
11211132 }
11221133
1123− ret = port->cap->port_type_set(port->orig_cap, type);
1134+ if (port->ops && port->ops->port_type_set)
1135+ ret = port->ops->port_type_set(port, type);
1136+ else
1137+ ret = port->cap->port_type_set(port->orig_cap, type);
11241138 if (ret)
11251139 goto unlock_and_ret;
11261140
@@ -1176,7 +1190,7 @@ static ssize_t vconn_source_store(struct device *dev, · 49 unmodified lines
11761190 return -EOPNOTSUPP;
11771191 }
11781192
1179− if (!port->cap->vconn_set) {
1193+ if (!port->cap->vconn_set && (!port->ops || !port->ops->vconn_set)) {
11801194 dev_dbg(dev, "VCONN swapping not supported\n");
11811195 return -EOPNOTSUPP;
11821196 }
@@ -1185,7 +1199,11 @@ static ssize_t vconn_source_store(struct device *dev, · 2 unmodified lines
11851199 if (ret)
11861200 return ret;
11871201
1188− ret = port->cap->vconn_set(port->orig_cap, (enum typec_role)source);
1202+ if (port->ops && port->ops->vconn_set)
1203+ ret = port->ops->vconn_set(port, (enum typec_role)source);
1204+ else
1205+ ret = port->cap->vconn_set(port->orig_cap,
1206+ (enum typec_role)source);
11891207 if (ret)
11901208 return ret;
11911209
@@ -1591,6 +1609,7 @@ struct typec_port *typec_register_port(struct device *parent, · 399 unmodified lines
15911609 mutex_init(&port->port_type_lock);
15921610
15931611 port->id = id;
1612+ port->ops = cap->ops;
15941613 port->orig_cap = cap;
15951614 port->port_type = cap->type;
15961615 port->prefer_role = cap->prefer_role;
include/linux/usb/typec.h+20−0
@@ -168,6 +168,23 @@ struct typec_partner_desc { · 167 unmodified lines
168168 struct usb_pd_identity *identity;
169169 };
170170
171+/**
172+ * struct typec_operations - USB Type-C Port Operations
173+ * @try_role: Set data role preference for DRP port
174+ * @dr_set: Set Data Role
175+ * @pr_set: Set Power Role
176+ * @vconn_set: Source VCONN
177+ * @port_type_set: Set port type
178+ */
179+struct typec_operations {
180+ int (*try_role)(struct typec_port *port, int role);
181+ int (*dr_set)(struct typec_port *port, enum typec_data_role role);
182+ int (*pr_set)(struct typec_port *port, enum typec_role role);
183+ int (*vconn_set)(struct typec_port *port, enum typec_role role);
184+ int (*port_type_set)(struct typec_port *port,
185+ enum typec_port_type type);
186+};
187+
171188 /*
172189 * struct typec_capability - USB Type-C Port Capabilities
173190 * @type: Supported power role of the port
@@ -180,6 +197,7 @@ struct typec_partner_desc { · 6 unmodified lines
180197 * @mux: Multiplexer switch for Alternate/Accessory Modes
181198 * @fwnode: Optional fwnode of the port
182199 * @driver_data: Private pointer for driver specific info
200+ * @ops: Port operations vector
183201 * @try_role: Set data role preference for DRP port
184202 * @dr_set: Set Data Role
185203 * @pr_set: Set Power Role
@@ -201,6 +219,8 @@ struct typec_capability { · 15 unmodified lines
201219 struct fwnode_handle *fwnode;
202220 void *driver_data;
203221
222+ const struct typec_operations *ops;
223+
204224 int (*try_role)(const struct typec_capability *,
205225 int role);
206226

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t