Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1453093 > unrolled thread
| Started by | Enric Balletbo i Serra <enric.balletbo@collabora.com> |
|---|---|
| First post | 2016-08-01 12:00 +0200 |
| Last post | 2016-08-09 16:00 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v4 0/4] Add support for cros-ec-sensors Enric Balletbo i Serra <enric.balletbo@collabora.com> - 2016-08-01 12:00 +0200
[PATCH v4 3/4] platform/chrome: Introduce a new function to check EC features. Enric Balletbo i Serra <enric.balletbo@collabora.com> - 2016-08-01 12:00 +0200
Re: [PATCH v4 3/4] platform/chrome: Introduce a new function to check EC features. Lee Jones <lee.jones@linaro.org> - 2016-08-09 16:00 +0200
| From | Enric Balletbo i Serra <enric.balletbo@collabora.com> |
|---|---|
| Date | 2016-08-01 12:00 +0200 |
| Subject | [PATCH v4 0/4] Add support for cros-ec-sensors |
| Message-ID | <s1iaR-4Cd-11@gated-at.bofh.it> |
Hi,
This is the four patchset to add support for the sensors behind the ChromeOS
Embedded Controller.
This version has only the patches to support common functions and 3d
contiguous sensors like Accelerometers, Gyroscope and Magnetometer that are
presented by the ChromeOS EC Sensor hub. The patches were tested on an Oak board.
The code was checked out from the ChromeOS v3.18 tree and forward ported to
mainline solving all the conflicts and build issues. I splitted the code in
single patches that have sense by themselves in order to avoid the chances
to fail.
Note that the patches depends on this [1] to apply and work.
[1] https://lkml.org/lkml/2016/7/1/188
Waiting for your reviews and feedback.
Changes since v3 (requested by Guenter Roeck)
- Convert structure to a simple array
- Remove PM declarations
- Remove unnecessary initializations
- cros_ec_sensors_cmd_read_u16: Conversion should only be done if ret >= 0
- Remove unnecessary else
- Add Reviewed-by tag for two last patches.
Changes since v2 (requested by Guenter Roeck and Jonhatan Cameron)
- Rebased and fix build error.
- Include a list of possible values in the description of location attr.
- Fix some typos.
- Remove id sysfs entry.
- Skip filling by zero structure parameters that already zero'd.
- Order includes alphabetically.
- Propagate error codes.
Changes since v1 (requested by Peter Meerwald-Stadler and Jonhatan Cameron)
- Check kernel-doc documentation and
- Bring some patches together.
- Fix some spelling mistakes.
- Include ABI documentation.
- Be more careful with buffer sizes (sprintf -> snprintf)
- Add cros_ec_sensors prefix to all function.
- Check return values on some functions.
Best regards,
Enric Balletbo i Serra (3):
iio: cros_ec_sensors_core: Add common functions for the ChromeOS EC
Sensor Hub.
iio: cros_ec_sensors: add ChromeOS EC Contiguous Sensors driver
platform/chrome: cros_ec_dev - Register cros-ec sensors
Vincent Palatin (1):
platform/chrome: Introduce a new function to check EC features.
Documentation/ABI/testing/sysfs-bus-iio-cros-ec | 18 +
drivers/iio/common/Kconfig | 1 +
drivers/iio/common/Makefile | 1 +
drivers/iio/common/cros_ec_sensors/Kconfig | 22 +
drivers/iio/common/cros_ec_sensors/Makefile | 6 +
.../iio/common/cros_ec_sensors/cros_ec_sensors.c | 322 +++++++++++++++
.../common/cros_ec_sensors/cros_ec_sensors_core.c | 450 +++++++++++++++++++++
.../common/cros_ec_sensors/cros_ec_sensors_core.h | 175 ++++++++
drivers/platform/chrome/cros_ec_dev.c | 159 ++++++++
include/linux/mfd/cros_ec.h | 10 +
include/linux/mfd/cros_ec_commands.h | 183 ++++++++-
11 files changed, 1342 insertions(+), 5 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-cros-ec
create mode 100644 drivers/iio/common/cros_ec_sensors/Kconfig
create mode 100644 drivers/iio/common/cros_ec_sensors/Makefile
create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.h
--
2.1.0
[toc] | [next] | [standalone]
| From | Enric Balletbo i Serra <enric.balletbo@collabora.com> |
|---|---|
| Date | 2016-08-01 12:00 +0200 |
| Subject | [PATCH v4 3/4] platform/chrome: Introduce a new function to check EC features. |
| Message-ID | <s1iaS-4Cd-41@gated-at.bofh.it> |
| In reply to | #1453093 |
From: Vincent Palatin <vpalatin@chromium.org>
Use the EC_CMD_GET_FEATURES message to check the supported features for
each MCU.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
[tomeu: adapted to changes in mainline]
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
[enric: remove references to USB PD feature and do it more generic]
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
---
Changes since v3:
- Add Reviewed-by tag.
drivers/platform/chrome/cros_ec_dev.c | 37 +++++++++++++++
include/linux/mfd/cros_ec.h | 1 +
include/linux/mfd/cros_ec_commands.h | 84 +++++++++++++++++++++++++++++++++++
3 files changed, 122 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
index 8abd80d..7eb5307 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);
+}
+
/* Device file ops */
static int ec_device_open(struct inode *inode, struct file *filp)
{
@@ -245,6 +280,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);
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index 7769ea6..7f039b2 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -187,6 +187,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 8826e0f..1683003 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -713,6 +713,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 */
--
2.1.0
[toc] | [prev] | [next] | [standalone]
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-08-09 16:00 +0200 |
| Subject | Re: [PATCH v4 3/4] platform/chrome: Introduce a new function to check EC features. |
| Message-ID | <s4fJv-8kJ-9@gated-at.bofh.it> |
| In reply to | #1453094 |
On Mon, 01 Aug 2016, Enric Balletbo i Serra wrote:
> From: Vincent Palatin <vpalatin@chromium.org>
>
> Use the EC_CMD_GET_FEATURES message to check the supported features for
> each MCU.
>
> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
> [tomeu: adapted to changes in mainline]
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> [enric: remove references to USB PD feature and do it more generic]
> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
>
> Changes since v3:
> - Add Reviewed-by tag.
>
> drivers/platform/chrome/cros_ec_dev.c | 37 +++++++++++++++
> include/linux/mfd/cros_ec.h | 1 +
> include/linux/mfd/cros_ec_commands.h | 84 +++++++++++++++++++++++++++++++++++
For the MFD changes:
Acked-by: Lee Jones <lee.jones@linaro.org>
> 3 files changed, 122 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
> index 8abd80d..7eb5307 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);
> +}
> +
> /* Device file ops */
> static int ec_device_open(struct inode *inode, struct file *filp)
> {
> @@ -245,6 +280,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);
>
> diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
> index 7769ea6..7f039b2 100644
> --- a/include/linux/mfd/cros_ec.h
> +++ b/include/linux/mfd/cros_ec.h
> @@ -187,6 +187,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 8826e0f..1683003 100644
> --- a/include/linux/mfd/cros_ec_commands.h
> +++ b/include/linux/mfd/cros_ec_commands.h
> @@ -713,6 +713,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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web