Immutable branch for mfd and power-supply for v4.20
Immutable branch between mfd and power-supply for driver changes in CROS USBPD charger driver. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAlueOg8ACgkQ2O7X88g7 +powaA//eiDVCADkBlnhzzfks3KEpkoGCS4Hct3uIcKri7Nuua9KhHrkun6rUzmO +CTx78sQl9Ctswr78/40TaXsgc+EfbGIMBB8Prrux2P8cy+QbVWD3dRfZKyc/oQp m9MrJqa4jmvSLnKmujXP+bIlWVBc1OTDo+O1OVH1J1dBnGmR/LrvVBbVHnx7H5tj LAhNZ40GxDDNXd94uZ1csxlulSV3/ezWto8Lp8lyh4fuYLnpGBl/k/x15HoaBcQ1 TPSMg7I8OPrQkZaJQ3d2nMmpDmyuNgO4KTA7rLXc8MlwRGl4gx9zSZVOTstMlhE/ oVR5DSRnxIMQO7JUSRLtmYOWYQmVWRDZVs3+O9UQv2WPecsz9aCvMbkxYHeJIGkD 9jPTd/OT7uBmV+xketpTLPuIFcS72HDrrPhZAstkj+klt/aSoQDp9lecjcgU1ArE wAppp0YZ2Fj+m73XzDIUe3EqUMOmIBPQfUJd60ZAHOJot9p/4v40rnwgg8VA+WmU JhawDNa6Wq4cYYOpFPgPXWmsXB2mgPKJV+X6tjDDpwEtn+QF5c9OFWakgX06WN9h gZss2Qbn75dFDJUQyRzM8F5RkjVh7NrU1dMOgBMEXN5Hqb1//YJ5q4hiL280uFkD n9B07QL7oSvaV3qcXTkFFDqJG44nH91J6AMxUAqDG5L9Y63l5Hg= =ya3t -----END PGP SIGNATURE----- Merge tag 'psy-mfd-cros-immutable-for-v4.20-signed' into psy-next Immutable branch for mfd and power-supply for v4.20 Immutable branch between mfd and power-supply for driver changes in CROS USBPD charger driver. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
commit
782853cf9b
@ -12,8 +12,12 @@
|
||||
#include <linux/power_supply.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#define CHARGER_DIR_NAME "CROS_USBPD_CHARGER%d"
|
||||
#define CHARGER_DIR_NAME_LENGTH sizeof(CHARGER_DIR_NAME)
|
||||
#define CHARGER_USBPD_DIR_NAME "CROS_USBPD_CHARGER%d"
|
||||
#define CHARGER_DEDICATED_DIR_NAME "CROS_DEDICATED_CHARGER"
|
||||
#define CHARGER_DIR_NAME_LENGTH (sizeof(CHARGER_USBPD_DIR_NAME) >= \
|
||||
sizeof(CHARGER_DEDICATED_DIR_NAME) ? \
|
||||
sizeof(CHARGER_USBPD_DIR_NAME) : \
|
||||
sizeof(CHARGER_DEDICATED_DIR_NAME))
|
||||
#define CHARGER_CACHE_UPDATE_DELAY msecs_to_jiffies(500)
|
||||
#define CHARGER_MANUFACTURER_MODEL_LENGTH 32
|
||||
|
||||
@ -42,6 +46,7 @@ struct charger_data {
|
||||
struct cros_ec_dev *ec_dev;
|
||||
struct cros_ec_device *ec_device;
|
||||
int num_charger_ports;
|
||||
int num_usbpd_ports;
|
||||
int num_registered_psy;
|
||||
struct port_data *ports[EC_USB_PD_MAX_PORTS];
|
||||
struct notifier_block notifier;
|
||||
@ -58,6 +63,12 @@ static enum power_supply_property cros_usbpd_charger_props[] = {
|
||||
POWER_SUPPLY_PROP_USB_TYPE
|
||||
};
|
||||
|
||||
static enum power_supply_property cros_usbpd_dedicated_charger_props[] = {
|
||||
POWER_SUPPLY_PROP_ONLINE,
|
||||
POWER_SUPPLY_PROP_STATUS,
|
||||
POWER_SUPPLY_PROP_VOLTAGE_NOW,
|
||||
};
|
||||
|
||||
static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = {
|
||||
POWER_SUPPLY_USB_TYPE_UNKNOWN,
|
||||
POWER_SUPPLY_USB_TYPE_SDP,
|
||||
@ -69,6 +80,11 @@ static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = {
|
||||
POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID
|
||||
};
|
||||
|
||||
static bool cros_usbpd_charger_port_is_dedicated(struct port_data *port)
|
||||
{
|
||||
return port->port_number >= port->charger->num_usbpd_ports;
|
||||
}
|
||||
|
||||
static int cros_usbpd_charger_ec_command(struct charger_data *charger,
|
||||
unsigned int version,
|
||||
unsigned int command,
|
||||
@ -102,6 +118,23 @@ static int cros_usbpd_charger_ec_command(struct charger_data *charger,
|
||||
}
|
||||
|
||||
static int cros_usbpd_charger_get_num_ports(struct charger_data *charger)
|
||||
{
|
||||
struct ec_response_charge_port_count resp;
|
||||
int ret;
|
||||
|
||||
ret = cros_usbpd_charger_ec_command(charger, 0,
|
||||
EC_CMD_CHARGE_PORT_COUNT,
|
||||
NULL, 0, &resp, sizeof(resp));
|
||||
if (ret < 0) {
|
||||
dev_err(charger->dev,
|
||||
"Unable to get the number of ports (err:0x%x)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return resp.port_count;
|
||||
}
|
||||
|
||||
static int cros_usbpd_charger_get_usbpd_num_ports(struct charger_data *charger)
|
||||
{
|
||||
struct ec_response_usb_pd_ports resp;
|
||||
int ret;
|
||||
@ -246,6 +279,9 @@ static int cros_usbpd_charger_get_power_info(struct port_data *port)
|
||||
port->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP;
|
||||
}
|
||||
|
||||
if (cros_usbpd_charger_port_is_dedicated(port))
|
||||
port->psy_desc.type = POWER_SUPPLY_TYPE_MAINS;
|
||||
else
|
||||
port->psy_desc.type = POWER_SUPPLY_TYPE_USB;
|
||||
|
||||
dev_dbg(dev,
|
||||
@ -281,6 +317,7 @@ static int cros_usbpd_charger_get_port_status(struct port_data *port,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (!cros_usbpd_charger_port_is_dedicated(port))
|
||||
ret = cros_usbpd_charger_get_discovery_info(port);
|
||||
port->last_update = jiffies;
|
||||
|
||||
@ -424,17 +461,56 @@ static int cros_usbpd_charger_probe(struct platform_device *pd)
|
||||
|
||||
platform_set_drvdata(pd, charger);
|
||||
|
||||
charger->num_charger_ports = cros_usbpd_charger_get_num_ports(charger);
|
||||
if (charger->num_charger_ports <= 0) {
|
||||
/*
|
||||
* We need to know the number of USB PD ports in order to know whether
|
||||
* there is a dedicated port. The dedicated port will always be
|
||||
* after the USB PD ports, and there should be only one.
|
||||
*/
|
||||
charger->num_usbpd_ports =
|
||||
cros_usbpd_charger_get_usbpd_num_ports(charger);
|
||||
if (charger->num_usbpd_ports <= 0) {
|
||||
/*
|
||||
* This can happen on a system that doesn't support USB PD.
|
||||
* Log a message, but no need to warn.
|
||||
*/
|
||||
dev_info(dev, "No USB PD charging ports found\n");
|
||||
}
|
||||
|
||||
charger->num_charger_ports = cros_usbpd_charger_get_num_ports(charger);
|
||||
if (charger->num_charger_ports < 0) {
|
||||
/*
|
||||
* This can happen on a system that doesn't support USB PD.
|
||||
* Log a message, but no need to warn.
|
||||
* Older ECs do not support the above command, in that case
|
||||
* let's set up the number of charger ports equal to the number
|
||||
* of USB PD ports
|
||||
*/
|
||||
dev_info(dev, "Could not get charger port count\n");
|
||||
charger->num_charger_ports = charger->num_usbpd_ports;
|
||||
}
|
||||
|
||||
if (charger->num_charger_ports <= 0) {
|
||||
/*
|
||||
* This can happen on a system that doesn't support USB PD and
|
||||
* doesn't have a dedicated port.
|
||||
* Log a message, but no need to warn.
|
||||
*/
|
||||
dev_info(dev, "No charging ports found\n");
|
||||
ret = -ENODEV;
|
||||
goto fail_nowarn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sanity checks on the number of ports:
|
||||
* there should be at most 1 dedicated port
|
||||
*/
|
||||
if (charger->num_charger_ports < charger->num_usbpd_ports ||
|
||||
charger->num_charger_ports > (charger->num_usbpd_ports + 1)) {
|
||||
dev_err(dev, "Unexpected number of charge port count\n");
|
||||
ret = -EPROTO;
|
||||
goto fail_nowarn;
|
||||
}
|
||||
|
||||
for (i = 0; i < charger->num_charger_ports; i++) {
|
||||
struct power_supply_config psy_cfg = {};
|
||||
|
||||
@ -446,21 +522,32 @@ static int cros_usbpd_charger_probe(struct platform_device *pd)
|
||||
|
||||
port->charger = charger;
|
||||
port->port_number = i;
|
||||
sprintf(port->name, CHARGER_DIR_NAME, i);
|
||||
|
||||
psy_desc = &port->psy_desc;
|
||||
psy_desc->name = port->name;
|
||||
psy_desc->type = POWER_SUPPLY_TYPE_USB;
|
||||
psy_desc->get_property = cros_usbpd_charger_get_prop;
|
||||
psy_desc->external_power_changed =
|
||||
cros_usbpd_charger_power_changed;
|
||||
psy_cfg.drv_data = port;
|
||||
|
||||
if (cros_usbpd_charger_port_is_dedicated(port)) {
|
||||
sprintf(port->name, CHARGER_DEDICATED_DIR_NAME);
|
||||
psy_desc->type = POWER_SUPPLY_TYPE_MAINS;
|
||||
psy_desc->properties =
|
||||
cros_usbpd_dedicated_charger_props;
|
||||
psy_desc->num_properties =
|
||||
ARRAY_SIZE(cros_usbpd_dedicated_charger_props);
|
||||
} else {
|
||||
sprintf(port->name, CHARGER_USBPD_DIR_NAME, i);
|
||||
psy_desc->type = POWER_SUPPLY_TYPE_USB;
|
||||
psy_desc->properties = cros_usbpd_charger_props;
|
||||
psy_desc->num_properties =
|
||||
ARRAY_SIZE(cros_usbpd_charger_props);
|
||||
psy_desc->usb_types = cros_usbpd_charger_usb_types;
|
||||
psy_desc->num_usb_types =
|
||||
ARRAY_SIZE(cros_usbpd_charger_usb_types);
|
||||
psy_cfg.drv_data = port;
|
||||
}
|
||||
|
||||
psy_desc->name = port->name;
|
||||
|
||||
psy = devm_power_supply_register_no_ws(dev, psy_desc,
|
||||
&psy_cfg);
|
||||
|
@ -3102,6 +3102,16 @@ struct ec_params_usb_pd_info_request {
|
||||
uint8_t port;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* This command will return the number of USB PD charge port + the number
|
||||
* of dedicated port present.
|
||||
* EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
|
||||
*/
|
||||
#define EC_CMD_CHARGE_PORT_COUNT 0x0105
|
||||
struct ec_response_charge_port_count {
|
||||
uint8_t port_count;
|
||||
} __packed;
|
||||
|
||||
/* Read USB-PD Device discovery info */
|
||||
#define EC_CMD_USB_PD_DISCOVERY 0x0113
|
||||
struct ec_params_usb_pd_discovery_entry {
|
||||
|
Loading…
x
Reference in New Issue
Block a user