linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice.
@ 2018-02-23 15:11 Enric Balletbo i Serra
  2018-02-23 15:11 ` [PATCH v2 6/8] mfd: cros_ec_dev: register shutdown function for debugfs Enric Balletbo i Serra
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-23 15:11 UTC (permalink / raw)
  To: lee.jones; +Cc: groeck, gwendal, kernel, linux-kernel

With this patch, the cros_ec_ctl driver will register the legacy
accelerometer driver (named cros_ec_accel_legacy) if it fails to
register sensors through the usual path cros_ec_sensors_register().
This legacy device is present on Chromebook devices with older EC
firmware only supporting deprecated EC commands (Glimmer based devices).

Tested-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
---

Changes in v2:
- [5/8] Add the Reviewed-by Gwendal.

 drivers/mfd/cros_ec_dev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index 33fe1b439ee2..fd7f0068fb45 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -389,6 +389,63 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
 	kfree(msg);
 }
 
+#define CROS_EC_SENSOR_LEGACY_NUM 2
+static struct mfd_cell cros_ec_accel_legacy_cells[CROS_EC_SENSOR_LEGACY_NUM];
+
+static void cros_ec_accel_legacy_register(struct cros_ec_dev *ec)
+{
+	struct cros_ec_device *ec_dev = ec->ec_dev;
+	u8 status;
+	int i, ret;
+	struct cros_ec_sensor_platform
+		sensor_platforms[CROS_EC_SENSOR_LEGACY_NUM];
+
+	/*
+	 * EC that need legacy support are the main EC, directly connected to
+	 * the AP.
+	 */
+	if (ec->cmd_offset != 0)
+		return;
+
+	/*
+	 * Check if EC supports direct memory reads and if EC has
+	 * accelerometers.
+	 */
+	if (!ec_dev->cmd_readmem)
+		return;
+
+	ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS, 1, &status);
+	if (ret < 0) {
+		dev_warn(ec->dev, "EC does not support direct reads.\n");
+		return;
+	}
+
+	/* Check if EC has accelerometers. */
+	if (!(status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT)) {
+		dev_info(ec->dev, "EC does not have accelerometers.\n");
+		return;
+	}
+
+	/*
+	 * Register 2 accelerometers
+	 */
+	for (i = 0; i < CROS_EC_SENSOR_LEGACY_NUM; i++) {
+		cros_ec_accel_legacy_cells[i].name = "cros-ec-accel-legacy";
+		sensor_platforms[i].sensor_num = i;
+		cros_ec_accel_legacy_cells[i].id = i;
+		cros_ec_accel_legacy_cells[i].platform_data =
+			&sensor_platforms[i];
+		cros_ec_accel_legacy_cells[i].pdata_size =
+			sizeof(struct cros_ec_sensor_platform);
+	}
+	ret = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO,
+			      cros_ec_accel_legacy_cells,
+			      CROS_EC_SENSOR_LEGACY_NUM,
+			      NULL, 0, NULL);
+	if (ret)
+		dev_err(ec_dev->dev, "failed to add EC sensors\n");
+}
+
 static const struct mfd_cell cros_ec_rtc_cell = {
 	.name = "cros-ec-rtc",
 };
@@ -440,6 +497,9 @@ static int ec_device_probe(struct platform_device *pdev)
 	/* check whether this EC is a sensor hub. */
 	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
 		cros_ec_sensors_register(ec);
+	else
+		/* Workaroud for older EC firmware */
+		cros_ec_accel_legacy_register(ec);
 
 	/* check whether this EC instance has RTC host command support */
 	if (cros_ec_check_features(ec, EC_FEATURE_RTC)) {
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 6/8] mfd: cros_ec_dev: register shutdown function for debugfs
  2018-02-23 15:11 [PATCH v2 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice Enric Balletbo i Serra
@ 2018-02-23 15:11 ` Enric Balletbo i Serra
  2018-02-23 15:11 ` [PATCH v2 7/8] mfd: cros_ec_i2c: add ACPI module device table Enric Balletbo i Serra
  2018-02-23 15:11 ` [PATCH v2 8/8] mfd: cros_ec_i2c: moving the system sleep pm ops to late Enric Balletbo i Serra
  2 siblings, 0 replies; 6+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-23 15:11 UTC (permalink / raw)
  To: lee.jones
  Cc: groeck, gwendal, kernel, linux-kernel, Daniel Hung-yu Wu,
	Daniel Hung-yu Wu

From: Daniel Hung-yu Wu <hywu@google.com>

Reboot or shutdown during delayed works could corrupt communication with
EC and certain I2C controller may not be able to recover from the error
state.

This patch registers a shutdown callback used to cancel the debugfs log
worker thread.

Signed-off-by: Daniel Hung-yu Wu <hywu@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v2:
- [6/8] This patch is new in this series.

 drivers/mfd/cros_ec_dev.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index fd7f0068fb45..354eb9e01d52 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -535,6 +535,14 @@ static int ec_device_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void ec_device_shutdown(struct platform_device *pdev)
+{
+	struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
+
+	/* Be sure to clear up debugfs delayed works */
+	cros_ec_debugfs_remove(ec);
+}
+
 static const struct platform_device_id cros_ec_id[] = {
 	{ DRV_NAME, 0 },
 	{ /* sentinel */ },
@@ -577,6 +585,7 @@ static struct platform_driver cros_ec_dev_driver = {
 	},
 	.probe = ec_device_probe,
 	.remove = ec_device_remove,
+	.shutdown = ec_device_shutdown,
 };
 
 static int __init cros_ec_dev_init(void)
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 7/8] mfd: cros_ec_i2c: add ACPI module device table
  2018-02-23 15:11 [PATCH v2 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice Enric Balletbo i Serra
  2018-02-23 15:11 ` [PATCH v2 6/8] mfd: cros_ec_dev: register shutdown function for debugfs Enric Balletbo i Serra
@ 2018-02-23 15:11 ` Enric Balletbo i Serra
  2018-02-23 16:26   ` Andy Shevchenko
  2018-02-23 15:11 ` [PATCH v2 8/8] mfd: cros_ec_i2c: moving the system sleep pm ops to late Enric Balletbo i Serra
  2 siblings, 1 reply; 6+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-23 15:11 UTC (permalink / raw)
  To: lee.jones; +Cc: groeck, gwendal, kernel, linux-kernel, Wei-Ning Huang

From: Wei-Ning Huang <wnhuang@google.com>

Add ACPI module device table for matching cros-ec devices to load the
cros_ec_i2c driver automatically.

Signed-off-by: Wei-Ning Huang <wnhuang@google.com>
Acked-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
---

Changes in v2:
- [7/8] Add the Reviewed-by Gwendal.

 drivers/mfd/cros_ec_i2c.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mfd/cros_ec_i2c.c b/drivers/mfd/cros_ec_i2c.c
index 9f70de1e4c70..9248490504a9 100644
--- a/drivers/mfd/cros_ec_i2c.c
+++ b/drivers/mfd/cros_ec_i2c.c
@@ -13,6 +13,7 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/acpi.h>
 #include <linux/delay.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -344,11 +345,13 @@ static int cros_ec_i2c_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(cros_ec_i2c_pm_ops, cros_ec_i2c_suspend,
 			  cros_ec_i2c_resume);
 
+#ifdef CONFIG_OF
 static const struct of_device_id cros_ec_i2c_of_match[] = {
 	{ .compatible = "google,cros-ec-i2c", },
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, cros_ec_i2c_of_match);
+#endif
 
 static const struct i2c_device_id cros_ec_i2c_id[] = {
 	{ "cros-ec-i2c", 0 },
@@ -356,9 +359,18 @@ static const struct i2c_device_id cros_ec_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, cros_ec_i2c_id);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id cros_ec_i2c_acpi_id[] = {
+	{ "GOOG0008", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, cros_ec_i2c_acpi_id);
+#endif
+
 static struct i2c_driver cros_ec_driver = {
 	.driver	= {
 		.name	= "cros-ec-i2c",
+		.acpi_match_table = ACPI_PTR(cros_ec_i2c_acpi_id),
 		.of_match_table = of_match_ptr(cros_ec_i2c_of_match),
 		.pm	= &cros_ec_i2c_pm_ops,
 	},
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 8/8] mfd: cros_ec_i2c: moving the system sleep pm ops to late
  2018-02-23 15:11 [PATCH v2 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice Enric Balletbo i Serra
  2018-02-23 15:11 ` [PATCH v2 6/8] mfd: cros_ec_dev: register shutdown function for debugfs Enric Balletbo i Serra
  2018-02-23 15:11 ` [PATCH v2 7/8] mfd: cros_ec_i2c: add ACPI module device table Enric Balletbo i Serra
@ 2018-02-23 15:11 ` Enric Balletbo i Serra
  2018-02-23 16:27   ` Andy Shevchenko
  2 siblings, 1 reply; 6+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-23 15:11 UTC (permalink / raw)
  To: lee.jones; +Cc: groeck, gwendal, kernel, linux-kernel, Joseph Lo

From: Joseph Lo <josephl@nvidia.com>

The cros_ec_i2c driver is still active after it had suspended or before it
resumes. Besides that, it also tried to transfer data even after the I2C
host had been suspended. This will lead the system to crash.

During the test, we also observe that the EC needs to be resumed earlier
due to some status polling from the EC FW (e.g. battery status). So we
move the PM ops to late stage to make it work normally.

Signed-off-by: Joseph Lo <josephl@nvidia.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v2:
- [8/8] This patch is new in this series replacing [5/6] of v1.

 drivers/mfd/cros_ec_i2c.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/cros_ec_i2c.c b/drivers/mfd/cros_ec_i2c.c
index 9248490504a9..56fc66712e9b 100644
--- a/drivers/mfd/cros_ec_i2c.c
+++ b/drivers/mfd/cros_ec_i2c.c
@@ -342,8 +342,9 @@ static int cros_ec_i2c_resume(struct device *dev)
 }
 #endif
 
-static SIMPLE_DEV_PM_OPS(cros_ec_i2c_pm_ops, cros_ec_i2c_suspend,
-			  cros_ec_i2c_resume);
+const struct dev_pm_ops cros_ec_i2c_pm_ops = {
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(cros_ec_i2c_suspend, cros_ec_i2c_resume)
+};
 
 #ifdef CONFIG_OF
 static const struct of_device_id cros_ec_i2c_of_match[] = {
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 7/8] mfd: cros_ec_i2c: add ACPI module device table
  2018-02-23 15:11 ` [PATCH v2 7/8] mfd: cros_ec_i2c: add ACPI module device table Enric Balletbo i Serra
@ 2018-02-23 16:26   ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2018-02-23 16:26 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Lee Jones, groeck, Gwendal Grignou, kernel,
	Linux Kernel Mailing List, Wei-Ning Huang

On Fri, Feb 23, 2018 at 5:11 PM, Enric Balletbo i Serra
<enric.balletbo@collabora.com> wrote:
> From: Wei-Ning Huang <wnhuang@google.com>
>
> Add ACPI module device table for matching cros-ec devices to load the
> cros_ec_i2c driver automatically.

> +static const struct acpi_device_id cros_ec_i2c_acpi_id[] = {
> +       { "GOOG0008", 0 },
> +       { },

Please, avoid commas in terminator entries.

> +};

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 8/8] mfd: cros_ec_i2c: moving the system sleep pm ops to late
  2018-02-23 15:11 ` [PATCH v2 8/8] mfd: cros_ec_i2c: moving the system sleep pm ops to late Enric Balletbo i Serra
@ 2018-02-23 16:27   ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2018-02-23 16:27 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Lee Jones, groeck, Gwendal Grignou, kernel,
	Linux Kernel Mailing List, Joseph Lo

On Fri, Feb 23, 2018 at 5:11 PM, Enric Balletbo i Serra
<enric.balletbo@collabora.com> wrote:
> From: Joseph Lo <josephl@nvidia.com>
>
> The cros_ec_i2c driver is still active after it had suspended or before it
> resumes. Besides that, it also tried to transfer data even after the I2C
> host had been suspended. This will lead the system to crash.
>
> During the test, we also observe that the EC needs to be resumed earlier
> due to some status polling from the EC FW (e.g. battery status). So we
> move the PM ops to late stage to make it work normally.

> -static SIMPLE_DEV_PM_OPS(cros_ec_i2c_pm_ops, cros_ec_i2c_suspend,
> -                         cros_ec_i2c_resume);

> +const struct dev_pm_ops cros_ec_i2c_pm_ops = {
> +       SET_LATE_SYSTEM_SLEEP_PM_OPS(cros_ec_i2c_suspend, cros_ec_i2c_resume)
> +};


Why static disappeared?

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-02-23 16:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-23 15:11 [PATCH v2 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice Enric Balletbo i Serra
2018-02-23 15:11 ` [PATCH v2 6/8] mfd: cros_ec_dev: register shutdown function for debugfs Enric Balletbo i Serra
2018-02-23 15:11 ` [PATCH v2 7/8] mfd: cros_ec_i2c: add ACPI module device table Enric Balletbo i Serra
2018-02-23 16:26   ` Andy Shevchenko
2018-02-23 15:11 ` [PATCH v2 8/8] mfd: cros_ec_i2c: moving the system sleep pm ops to late Enric Balletbo i Serra
2018-02-23 16:27   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).