Skip to content

Commit 5fed73b

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Add struct for port data
Add a separate struct for storing port data, including Type C connector class struct pointers and caps. Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent 7110f5f commit 5fed73b

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717

1818
#define DRV_NAME "cros-ec-typec"
1919

20+
/* Per port data. */
21+
struct cros_typec_port {
22+
struct typec_port *port;
23+
/* Initial capabilities for the port. */
24+
struct typec_capability caps;
25+
};
26+
2027
/* Platform-specific data for the Chrome OS EC Type C controller. */
2128
struct cros_typec_data {
2229
struct device *dev;
2330
struct cros_ec_device *ec;
2431
int num_ports;
2532
unsigned int cmd_ver;
2633
/* Array of ports, indexed by port number. */
27-
struct typec_port *ports[EC_USB_PD_MAX_PORTS];
28-
/* Initial capabilities for each port. */
29-
struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
34+
struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
3035
struct notifier_block nb;
3136
};
3237

@@ -76,14 +81,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
7681
return 0;
7782
}
7883

84+
static void cros_unregister_ports(struct cros_typec_data *typec)
85+
{
86+
int i;
87+
88+
for (i = 0; i < typec->num_ports; i++) {
89+
if (!typec->ports[i])
90+
continue;
91+
typec_unregister_port(typec->ports[i]->port);
92+
}
93+
}
94+
7995
static int cros_typec_init_ports(struct cros_typec_data *typec)
8096
{
8197
struct device *dev = typec->dev;
8298
struct typec_capability *cap;
8399
struct fwnode_handle *fwnode;
100+
struct cros_typec_port *cros_port;
84101
const char *port_prop;
85102
int ret;
86-
int i;
87103
int nports;
88104
u32 port_num = 0;
89105

@@ -115,31 +131,31 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
115131

116132
dev_dbg(dev, "Registering port %d\n", port_num);
117133

118-
cap = devm_kzalloc(dev, sizeof(*cap), GFP_KERNEL);
119-
if (!cap) {
134+
cros_port = devm_kzalloc(dev, sizeof(*cros_port), GFP_KERNEL);
135+
if (!cros_port) {
120136
ret = -ENOMEM;
121137
goto unregister_ports;
122138
}
123139

124-
typec->caps[port_num] = cap;
140+
typec->ports[port_num] = cros_port;
141+
cap = &cros_port->caps;
125142

126143
ret = cros_typec_parse_port_props(cap, fwnode, dev);
127144
if (ret < 0)
128145
goto unregister_ports;
129146

130-
typec->ports[port_num] = typec_register_port(dev, cap);
131-
if (IS_ERR(typec->ports[port_num])) {
147+
cros_port->port = typec_register_port(dev, cap);
148+
if (IS_ERR(cros_port->port)) {
132149
dev_err(dev, "Failed to register port %d\n", port_num);
133-
ret = PTR_ERR(typec->ports[port_num]);
150+
ret = PTR_ERR(cros_port->port);
134151
goto unregister_ports;
135152
}
136153
}
137154

138155
return 0;
139156

140157
unregister_ports:
141-
for (i = 0; i < typec->num_ports; i++)
142-
typec_unregister_port(typec->ports[i]);
158+
cros_unregister_ports(typec);
143159
return ret;
144160
}
145161

@@ -177,7 +193,7 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
177193
static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
178194
int port_num, struct ec_response_usb_pd_control *resp)
179195
{
180-
struct typec_port *port = typec->ports[port_num];
196+
struct typec_port *port = typec->ports[port_num]->port;
181197
enum typec_orientation polarity;
182198

183199
if (!resp->enabled)
@@ -194,7 +210,7 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
194210
static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
195211
int port_num, struct ec_response_usb_pd_control_v1 *resp)
196212
{
197-
struct typec_port *port = typec->ports[port_num];
213+
struct typec_port *port = typec->ports[port_num]->port;
198214
enum typec_orientation polarity;
199215

200216
if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED))
@@ -358,9 +374,7 @@ static int cros_typec_probe(struct platform_device *pdev)
358374
return 0;
359375

360376
unregister_ports:
361-
for (i = 0; i < typec->num_ports; i++)
362-
if (typec->ports[i])
363-
typec_unregister_port(typec->ports[i]);
377+
cros_unregister_ports(typec);
364378
return ret;
365379
}
366380

0 commit comments

Comments
 (0)