All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: linux-kernel@vger.kernel.org,
	"Sameer Nanda" <snanda@chromium.org>,
	"Benson Leung" <bleung@chromium.org>,
	"Enric Balletbò" <enric.balletbo@collabora.co.uk>,
	"Vic Yang" <victoryang@chromium.org>,
	"Vincent Palatin" <vpalatin@chromium.org>,
	"Randall Spangler" <rspangler@chromium.org>,
	"Gwendal Grignou" <gwendal@chromium.org>,
	"Olof Johansson" <olof@lixom.net>
Subject: Re: [PATCH v1 6/6] platform/chrome: Check the USB PD feature before creating a charger
Date: Wed, 10 Feb 2016 16:28:20 +0000	[thread overview]
Message-ID: <20160210162820.GL3782@x1> (raw)
In-Reply-To: <1454679181-8949-7-git-send-email-tomeu.vizoso@collabora.com>

On Fri, 05 Feb 2016, Tomeu Vizoso wrote:

> From: Vincent Palatin <vpalatin@chromium.org>
> 
> Use the EC_CMD_GET_FEATURES message to check the supported features for
> each MCU before instantied a USB-PD charger.
> 
> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
> [tomeu: adapted to changes in mainline]
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
> 
> ---
> 
>  drivers/platform/chrome/cros_ec_dev.c | 40 ++++++++++++++++-
>  include/linux/mfd/cros_ec.h           |  1 +
>  include/linux/mfd/cros_ec_commands.h  | 84 +++++++++++++++++++++++++++++++++++

Acked-by: Lee Jones <lee.jones@linaro.org>

>  3 files changed, 124 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
> index 7a97cd313c68..1995cccfc59c 100644
> --- a/drivers/platform/chrome/cros_ec_dev.c
> +++ b/drivers/platform/chrome/cros_ec_dev.c
> @@ -87,6 +87,41 @@ exit:
>  	return ret;
>  }
>  
> +static int cros_ec_check_features(struct cros_ec_dev *ec, int feature)
> +{
> +	struct cros_ec_command *msg;
> +	int ret;
> +
> +	if (ec->features[0] == -1U && ec->features[1] == -1U) {
> +		/* features bitmap not read yet */
> +
> +		msg = kmalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
> +		if (!msg)
> +			return -ENOMEM;
> +
> +		msg->version = 0;
> +		msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
> +		msg->insize = sizeof(ec->features);
> +		msg->outsize = 0;
> +
> +		ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
> +		if ((ret < 0) || msg->result != EC_RES_SUCCESS) {
> +			dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
> +				 ret, msg->result);
> +			memset(ec->features, 0, sizeof(ec->features));
> +		}
> +
> +		memcpy(ec->features, msg->data, sizeof(ec->features));
> +
> +		dev_dbg(ec->dev, "EC features %08x %08x\n",
> +			ec->features[0], ec->features[1]);
> +
> +		kfree(msg);
> +	}
> +
> +	return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature);
> +}
> +
>  static int cros_ec_has_cmd_usb_pd_ports(struct cros_ec_dev *ec)
>  {
>  	struct cros_ec_command *msg;
> @@ -255,6 +290,8 @@ static int ec_device_probe(struct platform_device *pdev)
>  	ec->ec_dev = dev_get_drvdata(dev->parent);
>  	ec->dev = dev;
>  	ec->cmd_offset = ec_platform->cmd_offset;
> +	ec->features[0] = -1U; /* Not cached yet */
> +	ec->features[1] = -1U; /* Not cached yet */
>  	device_initialize(&ec->class_dev);
>  	cdev_init(&ec->cdev, &fops);
>  
> @@ -293,7 +330,8 @@ static int ec_device_probe(struct platform_device *pdev)
>  	}
>  
>  	/* check whether this EC instance has the PD charge manager */
> -	if (cros_ec_has_cmd_usb_pd_ports(ec)) {
> +	if (cros_ec_check_features(ec, EC_FEATURE_USB_PD) ||
> +	    cros_ec_has_cmd_usb_pd_ports(ec)) {
>  		retval = cros_ec_usb_pd_charger_register(dev);
>  		if (retval) {
>  			dev_err(dev, "failed to add usb-pd-charger device\n");
> diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
> index 543191f493a9..02ad92572d5a 100644
> --- a/include/linux/mfd/cros_ec.h
> +++ b/include/linux/mfd/cros_ec.h
> @@ -193,6 +193,7 @@ struct cros_ec_dev {
>  	struct cros_ec_device *ec_dev;
>  	struct device *dev;
>  	u16 cmd_offset;
> +	u32 features[2];
>  };
>  
>  /**
> diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h
> index 4f056d2747ff..cc3a4b1b19e8 100644
> --- a/include/linux/mfd/cros_ec_commands.h
> +++ b/include/linux/mfd/cros_ec_commands.h
> @@ -716,6 +716,90 @@ struct ec_response_get_set_value {
>  /* More than one command can use these structs to get/set paramters. */
>  #define EC_CMD_GSV_PAUSE_IN_S5	0x0c
>  
> +/*****************************************************************************/
> +/* List the features supported by the firmware */
> +#define EC_CMD_GET_FEATURES  0x0d
> +
> +/* Supported features */
> +enum ec_feature_code {
> +	/*
> +	 * This image contains a limited set of features. Another image
> +	 * in RW partition may support more features.
> +	 */
> +	EC_FEATURE_LIMITED = 0,
> +	/*
> +	 * Commands for probing/reading/writing/erasing the flash in the
> +	 * EC are present.
> +	 */
> +	EC_FEATURE_FLASH = 1,
> +	/*
> +	 * Can control the fan speed directly.
> +	 */
> +	EC_FEATURE_PWM_FAN = 2,
> +	/*
> +	 * Can control the intensity of the keyboard backlight.
> +	 */
> +	EC_FEATURE_PWM_KEYB = 3,
> +	/*
> +	 * Support Google lightbar, introduced on Pixel.
> +	 */
> +	EC_FEATURE_LIGHTBAR = 4,
> +	/* Control of LEDs  */
> +	EC_FEATURE_LED = 5,
> +	/* Exposes an interface to control gyro and sensors.
> +	 * The host goes through the EC to access these sensors.
> +	 * In addition, the EC may provide composite sensors, like lid angle.
> +	 */
> +	EC_FEATURE_MOTION_SENSE = 6,
> +	/* The keyboard is controlled by the EC */
> +	EC_FEATURE_KEYB = 7,
> +	/* The AP can use part of the EC flash as persistent storage. */
> +	EC_FEATURE_PSTORE = 8,
> +	/* The EC monitors BIOS port 80h, and can return POST codes. */
> +	EC_FEATURE_PORT80 = 9,
> +	/*
> +	 * Thermal management: include TMP specific commands.
> +	 * Higher level than direct fan control.
> +	 */
> +	EC_FEATURE_THERMAL = 10,
> +	/* Can switch the screen backlight on/off */
> +	EC_FEATURE_BKLIGHT_SWITCH = 11,
> +	/* Can switch the wifi module on/off */
> +	EC_FEATURE_WIFI_SWITCH = 12,
> +	/* Monitor host events, through for example SMI or SCI */
> +	EC_FEATURE_HOST_EVENTS = 13,
> +	/* The EC exposes GPIO commands to control/monitor connected devices. */
> +	EC_FEATURE_GPIO = 14,
> +	/* The EC can send i2c messages to downstream devices. */
> +	EC_FEATURE_I2C = 15,
> +	/* Command to control charger are included */
> +	EC_FEATURE_CHARGER = 16,
> +	/* Simple battery support. */
> +	EC_FEATURE_BATTERY = 17,
> +	/*
> +	 * Support Smart battery protocol
> +	 * (Common Smart Battery System Interface Specification)
> +	 */
> +	EC_FEATURE_SMART_BATTERY = 18,
> +	/* EC can dectect when the host hangs. */
> +	EC_FEATURE_HANG_DETECT = 19,
> +	/* Report power information, for pit only */
> +	EC_FEATURE_PMU = 20,
> +	/* Another Cros EC device is present downstream of this one */
> +	EC_FEATURE_SUB_MCU = 21,
> +	/* Support USB Power delivery (PD) commands */
> +	EC_FEATURE_USB_PD = 22,
> +	/* Control USB multiplexer, for audio through USB port for instance. */
> +	EC_FEATURE_USB_MUX = 23,
> +	/* Motion Sensor code has an internal software FIFO */
> +	EC_FEATURE_MOTION_SENSE_FIFO = 24,
> +};
> +
> +#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
> +#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
> +struct ec_response_get_features {
> +	uint32_t flags[2];
> +} __packed;
>  
>  /*****************************************************************************/
>  /* Flash commands */

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

      reply	other threads:[~2016-02-10 16:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-05 13:32 [PATCH v1 0/6] EC-based USB Power Delivery support for Chrome machines Tomeu Vizoso
2016-02-05 13:32 ` [PATCH v1 1/6] mfd: cros_ec: small kerneldoc fix Tomeu Vizoso
2016-02-05 18:46   ` Benson Leung
2016-02-10 16:25   ` Lee Jones
2016-02-05 13:32 ` [PATCH v1 2/6] mfd: cros_ec: Add MKBP event support Tomeu Vizoso
2016-02-10 17:41   ` Gwendal Grignou
2016-02-11  9:15     ` Lee Jones
2016-02-11  9:15       ` Lee Jones
     [not found]   ` <CAMHSBOXRvC7U_KWeg+rX3Qymaos0-3FN6AuaXT2cyP=gAN47mA@mail.gmail.com>
2016-02-11 14:52     ` Tomeu Vizoso
2016-02-11 14:52       ` Tomeu Vizoso
2016-02-11 18:49       ` Gwendal Grignou
2016-02-05 13:32 ` [PATCH v1 3/6] power_supply: Add types for USB Type C and PD chargers Tomeu Vizoso
2016-02-05 18:38   ` Benson Leung
2016-02-11 10:00     ` Tomeu Vizoso
2016-02-11 15:05       ` Benson Leung
2016-02-05 13:32 ` [PATCH v1 4/6] power: cros_usbpd-charger: Add EC-based USB PD charger driver Tomeu Vizoso
2016-02-10 16:49   ` Lee Jones
2016-02-12 11:07     ` Tomeu Vizoso
2016-02-05 13:33 ` [PATCH v1 5/6] platform/chrome: Register USB PD charger device Tomeu Vizoso
2016-02-10 16:46   ` Lee Jones
2016-02-12 11:06     ` Tomeu Vizoso
2016-02-05 13:33 ` [PATCH v1 6/6] platform/chrome: Check the USB PD feature before creating a charger Tomeu Vizoso
2016-02-10 16:28   ` Lee Jones [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160210162820.GL3782@x1 \
    --to=lee.jones@linaro.org \
    --cc=bleung@chromium.org \
    --cc=enric.balletbo@collabora.co.uk \
    --cc=gwendal@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=rspangler@chromium.org \
    --cc=snanda@chromium.org \
    --cc=tomeu.vizoso@collabora.com \
    --cc=victoryang@chromium.org \
    --cc=vpalatin@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.