Commit 5fed73b8 authored by Prashant Malani's avatar Prashant Malani Committed by Enric Balletbo i Serra

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: default avatarPrashant Malani <pmalani@chromium.org>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
parent 7110f5f0
...@@ -17,6 +17,13 @@ ...@@ -17,6 +17,13 @@
#define DRV_NAME "cros-ec-typec" #define DRV_NAME "cros-ec-typec"
/* Per port data. */
struct cros_typec_port {
struct typec_port *port;
/* Initial capabilities for the port. */
struct typec_capability caps;
};
/* Platform-specific data for the Chrome OS EC Type C controller. */ /* Platform-specific data for the Chrome OS EC Type C controller. */
struct cros_typec_data { struct cros_typec_data {
struct device *dev; struct device *dev;
...@@ -24,9 +31,7 @@ struct cros_typec_data { ...@@ -24,9 +31,7 @@ struct cros_typec_data {
int num_ports; int num_ports;
unsigned int cmd_ver; unsigned int cmd_ver;
/* Array of ports, indexed by port number. */ /* Array of ports, indexed by port number. */
struct typec_port *ports[EC_USB_PD_MAX_PORTS]; struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
/* Initial capabilities for each port. */
struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
struct notifier_block nb; struct notifier_block nb;
}; };
...@@ -76,14 +81,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap, ...@@ -76,14 +81,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
return 0; return 0;
} }
static void cros_unregister_ports(struct cros_typec_data *typec)
{
int i;
for (i = 0; i < typec->num_ports; i++) {
if (!typec->ports[i])
continue;
typec_unregister_port(typec->ports[i]->port);
}
}
static int cros_typec_init_ports(struct cros_typec_data *typec) static int cros_typec_init_ports(struct cros_typec_data *typec)
{ {
struct device *dev = typec->dev; struct device *dev = typec->dev;
struct typec_capability *cap; struct typec_capability *cap;
struct fwnode_handle *fwnode; struct fwnode_handle *fwnode;
struct cros_typec_port *cros_port;
const char *port_prop; const char *port_prop;
int ret; int ret;
int i;
int nports; int nports;
u32 port_num = 0; u32 port_num = 0;
...@@ -115,22 +131,23 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) ...@@ -115,22 +131,23 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
dev_dbg(dev, "Registering port %d\n", port_num); dev_dbg(dev, "Registering port %d\n", port_num);
cap = devm_kzalloc(dev, sizeof(*cap), GFP_KERNEL); cros_port = devm_kzalloc(dev, sizeof(*cros_port), GFP_KERNEL);
if (!cap) { if (!cros_port) {
ret = -ENOMEM; ret = -ENOMEM;
goto unregister_ports; goto unregister_ports;
} }
typec->caps[port_num] = cap; typec->ports[port_num] = cros_port;
cap = &cros_port->caps;
ret = cros_typec_parse_port_props(cap, fwnode, dev); ret = cros_typec_parse_port_props(cap, fwnode, dev);
if (ret < 0) if (ret < 0)
goto unregister_ports; goto unregister_ports;
typec->ports[port_num] = typec_register_port(dev, cap); cros_port->port = typec_register_port(dev, cap);
if (IS_ERR(typec->ports[port_num])) { if (IS_ERR(cros_port->port)) {
dev_err(dev, "Failed to register port %d\n", port_num); dev_err(dev, "Failed to register port %d\n", port_num);
ret = PTR_ERR(typec->ports[port_num]); ret = PTR_ERR(cros_port->port);
goto unregister_ports; goto unregister_ports;
} }
} }
...@@ -138,8 +155,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) ...@@ -138,8 +155,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
return 0; return 0;
unregister_ports: unregister_ports:
for (i = 0; i < typec->num_ports; i++) cros_unregister_ports(typec);
typec_unregister_port(typec->ports[i]);
return ret; return ret;
} }
...@@ -177,7 +193,7 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, ...@@ -177,7 +193,7 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
int port_num, struct ec_response_usb_pd_control *resp) int port_num, struct ec_response_usb_pd_control *resp)
{ {
struct typec_port *port = typec->ports[port_num]; struct typec_port *port = typec->ports[port_num]->port;
enum typec_orientation polarity; enum typec_orientation polarity;
if (!resp->enabled) if (!resp->enabled)
...@@ -194,7 +210,7 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, ...@@ -194,7 +210,7 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
int port_num, struct ec_response_usb_pd_control_v1 *resp) int port_num, struct ec_response_usb_pd_control_v1 *resp)
{ {
struct typec_port *port = typec->ports[port_num]; struct typec_port *port = typec->ports[port_num]->port;
enum typec_orientation polarity; enum typec_orientation polarity;
if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED))
...@@ -358,9 +374,7 @@ static int cros_typec_probe(struct platform_device *pdev) ...@@ -358,9 +374,7 @@ static int cros_typec_probe(struct platform_device *pdev)
return 0; return 0;
unregister_ports: unregister_ports:
for (i = 0; i < typec->num_ports; i++) cros_unregister_ports(typec);
if (typec->ports[i])
typec_unregister_port(typec->ports[i]);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment