Re: [PATCH 2/3] power: supply: add cros-ec USB PD charger driver.
On Wed, Jan 17, 2018 at 6:59 PM, Enric Balletbo i Serra wrote: > From: Sameer Nanda > > This driver gets various bits of information about what is connected to > USB PD ports from the EC and converts that into power_supply properties. > > Signed-off-by: Sameer Nanda > Signed-off-by: Enric Balletbo i Serra > --- > drivers/power/supply/Kconfig | 11 + > drivers/power/supply/Makefile | 1 + > drivers/power/supply/cros_usbpd-charger.c | 953 > ++ > include/linux/mfd/cros_ec.h | 3 + > 4 files changed, 968 insertions(+) > create mode 100644 drivers/power/supply/cros_usbpd-charger.c > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > index 428b426842f4..641503c1d40a 100644 > --- a/drivers/power/supply/Kconfig > +++ b/drivers/power/supply/Kconfig > @@ -624,4 +624,15 @@ config CHARGER_RT9455 > help > Say Y to enable support for Richtek RT9455 battery charger. > > +config CHARGER_CROS_USB_PD > + tristate "Chrome OS EC based USB PD charger" > + depends on MFD_CROS_EC > + select RTC_LIB > + default n > + help > + Say Y here to enable Chrome OS EC based USB PD charger > + driver. This driver gets various bits of information about > + what is connected to USB PD ports from the EC and converts > + that into power_supply properties. > + > endif # POWER_SUPPLY > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > index e83aa843bcc6..c412fe8b562d 100644 > --- a/drivers/power/supply/Makefile > +++ b/drivers/power/supply/Makefile > @@ -83,3 +83,4 @@ obj-$(CONFIG_CHARGER_TPS65090)+= tps65090-charger.o > obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o > obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o > obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o > +obj-$(CONFIG_CHARGER_CROS_USB_PD) += cros_usbpd-charger.o > diff --git a/drivers/power/supply/cros_usbpd-charger.c > b/drivers/power/supply/cros_usbpd-charger.c > new file mode 100644 > index ..1c48185f8163 > --- /dev/null > +++ b/drivers/power/supply/cros_usbpd-charger.c > @@ -0,0 +1,953 @@ > +/* > + * Power supply driver for ChromeOS EC based USB PD Charger. > + * > + * Copyright (c) 2014 - 2018 Google, Inc > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define CROS_USB_PD_MAX_LOG_ENTRIES30 > + > +#define CROS_USB_PD_LOG_UPDATE_DELAY msecs_to_jiffies(6) > +#define CROS_USB_PD_CACHE_UPDATE_DELAY msecs_to_jiffies(500) > + > +/* Buffer + macro for building PDLOG string */ > +#define BUF_SIZE 80 > +#define APPEND_STRING(buf, len, str, ...) ((len) += \ > + snprintf((buf) + (len), max(BUF_SIZE - (len), 0), (str), > ##__VA_ARGS__)) > + > +#define CHARGER_DIR_NAME "CROS_USB_PD_CHARGER%d" > +#define CHARGER_DIR_NAME_LENGTHsizeof(CHARGER_DIR_NAME) > +#define DRV_NAME "cros-usb-pd-charger" > + > +#define MANUFACTURER_MODEL_LENGTH 32 > + > +struct port_data { > + int port_number; > + char name[CHARGER_DIR_NAME_LENGTH]; > + char manufacturer[MANUFACTURER_MODEL_LENGTH]; > + char model_name[MANUFACTURER_MODEL_LENGTH]; > + struct power_supply *psy; > + struct power_supply_desc psy_desc; > + int psy_type; > + int psy_online; > + int psy_status; > + int psy_current_max; > + int psy_voltage_max_design; > + int psy_voltage_now; > + int psy_power_max; > + struct charger_data *charger; > + unsigned long last_update; > +}; > + > +struct charger_data { > + struct device *dev; > + struct cros_ec_dev *ec_dev; > + struct cros_ec_device *ec_device; > + int num_charger_ports; > + int num_registered_psy; > + struct port_data *ports[EC_USB_PD_MAX_PORTS]; > + struct delayed_work log_work; > + struct workqueue_struct *log_workqueue; > + struct notifier_block notifier; > + bool suspended; > +}; > + > +#define EC_MAX_IN_SIZE EC_PROTO2_MAX_REQUEST_SIZE > +#define EC_MAX_OUT_SIZE EC_PROTO2_MAX_RESPONSE_SIZE > +u8 ec_inbuf[EC_MAX_IN_SIZE]; > +u8 ec_outbuf[EC_MAX_OUT_SIZE]; > + > +static enum power_supply_property cros_usb_pd_charger_props[] = { > + POWER_SUPPLY_PROP_ONLINE, > + POWER_SUPPLY_PROP_STATUS, > + POWER_SUPPLY_PROP_CURRENT_MAX, >
Re: [PATCH 2/3] power: supply: add cros-ec USB PD charger driver.
Hi Enric, On Wed, Jan 17, 2018 at 06:59:31PM +0100, Enric Balletbo i Serra wrote: > From: Sameer Nanda > > This driver gets various bits of information about what is connected to > USB PD ports from the EC and converts that into power_supply properties. > > Signed-off-by: Sameer Nanda > Signed-off-by: Enric Balletbo i Serra > --- > drivers/power/supply/Kconfig | 11 + > drivers/power/supply/Makefile | 1 + > drivers/power/supply/cros_usbpd-charger.c | 953 > ++ > include/linux/mfd/cros_ec.h | 3 + > 4 files changed, 968 insertions(+) > create mode 100644 drivers/power/supply/cros_usbpd-charger.c Documentation for custom sysfs files is missing. > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > index 428b426842f4..641503c1d40a 100644 > --- a/drivers/power/supply/Kconfig > +++ b/drivers/power/supply/Kconfig > @@ -624,4 +624,15 @@ config CHARGER_RT9455 > help > Say Y to enable support for Richtek RT9455 battery charger. > > +config CHARGER_CROS_USB_PD > + tristate "Chrome OS EC based USB PD charger" > + depends on MFD_CROS_EC > + select RTC_LIB > + default n > + help > + Say Y here to enable Chrome OS EC based USB PD charger > + driver. This driver gets various bits of information about > + what is connected to USB PD ports from the EC and converts > + that into power_supply properties. > + > endif # POWER_SUPPLY > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > index e83aa843bcc6..c412fe8b562d 100644 > --- a/drivers/power/supply/Makefile > +++ b/drivers/power/supply/Makefile > @@ -83,3 +83,4 @@ obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o > obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o > obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o > obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o > +obj-$(CONFIG_CHARGER_CROS_USB_PD)+= cros_usbpd-charger.o > diff --git a/drivers/power/supply/cros_usbpd-charger.c > b/drivers/power/supply/cros_usbpd-charger.c > new file mode 100644 > index ..1c48185f8163 > --- /dev/null > +++ b/drivers/power/supply/cros_usbpd-charger.c > @@ -0,0 +1,953 @@ Please add SPDX header. > +/* > + * Power supply driver for ChromeOS EC based USB PD Charger. > + * > + * Copyright (c) 2014 - 2018 Google, Inc > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define CROS_USB_PD_MAX_LOG_ENTRIES 30 > + > +#define CROS_USB_PD_LOG_UPDATE_DELAY msecs_to_jiffies(6) > +#define CROS_USB_PD_CACHE_UPDATE_DELAY msecs_to_jiffies(500) > + > +/* Buffer + macro for building PDLOG string */ > +#define BUF_SIZE 80 > +#define APPEND_STRING(buf, len, str, ...) ((len) += \ > + snprintf((buf) + (len), max(BUF_SIZE - (len), 0), (str), ##__VA_ARGS__)) > + > +#define CHARGER_DIR_NAME "CROS_USB_PD_CHARGER%d" > +#define CHARGER_DIR_NAME_LENGTH sizeof(CHARGER_DIR_NAME) > +#define DRV_NAME "cros-usb-pd-charger" > + > +#define MANUFACTURER_MODEL_LENGTH32 > + > +struct port_data { > + int port_number; > + char name[CHARGER_DIR_NAME_LENGTH]; > + char manufacturer[MANUFACTURER_MODEL_LENGTH]; > + char model_name[MANUFACTURER_MODEL_LENGTH]; > + struct power_supply *psy; > + struct power_supply_desc psy_desc; > + int psy_type; > + int psy_online; > + int psy_status; > + int psy_current_max; > + int psy_voltage_max_design; > + int psy_voltage_now; > + int psy_power_max; > + struct charger_data *charger; > + unsigned long last_update; > +}; > + > +struct charger_data { > + struct device *dev; > + struct cros_ec_dev *ec_dev; > + struct cros_ec_device *ec_device; > + int num_charger_ports; > + int num_registered_psy; > + struct port_data *ports[EC_USB_PD_MAX_PORTS]; > + struct delayed_work log_work; > + struct workqueue_struct *log_workqueue; > + struct notifier_block notifier; > + bool suspended; > +}; > + > +#define EC_MAX_IN_SIZE EC_PROTO2_MAX_REQUEST_SIZE > +#define EC_MAX_OUT_SIZE EC_PROTO2_MAX_RESPONSE_SIZE > +u8 ec_inbuf[EC_MAX_IN_SIZE]; > +u8 ec_outbuf[EC_MAX_OUT_SIZE]; > + > +static enum power_supply_property cros_usb_pd_charger_props[] = { > + POWER_SUPPLY_PROP_ONLINE, > + POWER_SUPPLY_PROP_STATUS, > + POWER_SUPPLY_PROP_CURRENT
Re: [PATCH 2/3] power: supply: add cros-ec USB PD charger driver.
On Wed, 17 Jan 2018, Enric Balletbo i Serra wrote: > From: Sameer Nanda > > This driver gets various bits of information about what is connected to > USB PD ports from the EC and converts that into power_supply properties. > > Signed-off-by: Sameer Nanda > Signed-off-by: Enric Balletbo i Serra > --- > drivers/power/supply/Kconfig | 11 + > drivers/power/supply/Makefile | 1 + > drivers/power/supply/cros_usbpd-charger.c | 953 > ++ > include/linux/mfd/cros_ec.h | 3 + Acked-by: Lee Jones > 4 files changed, 968 insertions(+) > create mode 100644 drivers/power/supply/cros_usbpd-charger.c -- Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH 2/3] power: supply: add cros-ec USB PD charger driver.
On Wed, Jan 17, 2018 at 06:59:31PM +0100, Enric Balletbo i Serra wrote: > From: Sameer Nanda > > This driver gets various bits of information about what is connected to > USB PD ports from the EC and converts that into power_supply properties. > > Signed-off-by: Sameer Nanda > Signed-off-by: Enric Balletbo i Serra > --- > drivers/power/supply/Kconfig | 11 + > drivers/power/supply/Makefile | 1 + > drivers/power/supply/cros_usbpd-charger.c | 953 > ++ > include/linux/mfd/cros_ec.h | 3 + > 4 files changed, 968 insertions(+) > create mode 100644 drivers/power/supply/cros_usbpd-charger.c > +static DEVICE_ATTR(ext_current_lim, 0664, get_ec_ext_current_lim, > +set_ec_ext_current_lim); > +static DEVICE_ATTR(ext_voltage_lim, 0664, get_ec_ext_voltage_lim, > +set_ec_ext_voltage_lim); > + Hi I see that you have added new files to the sysfs ABI. It would probably be a good idea to have these new interfaces documented in Documentation/ABI. Aishwarya > +static struct attribute *__ext_power_cmds_attrs[] = { > + &dev_attr_ext_current_lim.attr, > + &dev_attr_ext_voltage_lim.attr, > + NULL, > +};