LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found
@ 2021-04-05 20:28 Gwendal Grignou
  2021-04-05 20:28 ` [PATCH v2 1/2] platform/chrome: Use dev_groups to set device sysfs attributes Gwendal Grignou
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gwendal Grignou @ 2021-04-05 20:28 UTC (permalink / raw)
  To: bleung, enric.balletbo, groeck; +Cc: linux-kernel, Gwendal Grignou

Attribute "kb_wake_angle" in /sys/<cros_ec hw path>/chromeos/cros_ec,
used to set at which angle the embedded controller must wake up the
host, is only set when there is at least 2 accelerometers in the
chromebook.

The detection of these sensors is done in cros_ec_sensorhub, driver that
can be probed after the cros_ec_sysfs driver that sets the attribute.
Therefore, we need to upgrade the cros_ec sysfs groups in the sensorhub
probe routine.

The first patch cleans up cros_ec_sysfs by using .dev_groups driver
field, the second patch fixes the problem.

Gwendal Grignou (2):
  platform/chrome: Use dev_groups to set device sysfs attributes
  platform/chrome: Update cros_ec sysfs attributes on sensors discovery

 drivers/platform/chrome/cros_ec_sensorhub.c |  5 ++++-
 drivers/platform/chrome/cros_ec_sysfs.c     | 22 +++++++--------------
 include/linux/platform_data/cros_ec_proto.h |  2 ++
 3 files changed, 13 insertions(+), 16 deletions(-)

-- 
2.31.0.208.g409f899ff0-goog


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

* [PATCH v2 1/2] platform/chrome: Use dev_groups to set device sysfs attributes
  2021-04-05 20:28 [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
@ 2021-04-05 20:28 ` Gwendal Grignou
  2021-04-05 20:28 ` [PATCH v2 2/2] platform/chrome: Update cros_ec sysfs attributes on sensors discovery Gwendal Grignou
  2021-05-27 21:01 ` [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
  2 siblings, 0 replies; 6+ messages in thread
From: Gwendal Grignou @ 2021-04-05 20:28 UTC (permalink / raw)
  To: bleung, enric.balletbo, groeck; +Cc: linux-kernel, Gwendal Grignou, stable

Instead of manually call sysfs_create_group()/sysfs_remove_group(), set
.dev_groups driver data structure, and let the bus base code create
sysfs attributes.

Fixes: 6fd7f2bbd442 ("mfd / platform: cros_ec: Move device sysfs attributes to its own driver")
Cc: stable@vger.kernel.org
Signed-off-by: Gwendal Grignou <gwendal@google.com>
---
 New in v2.

 drivers/platform/chrome/cros_ec_sysfs.c | 28 +++++--------------------
 1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index f07eabcf9494c..114b9dbe981e7 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -335,34 +335,16 @@ static const struct attribute_group cros_ec_attr_group = {
 	.is_visible = cros_ec_ctrl_visible,
 };
 
-static int cros_ec_sysfs_probe(struct platform_device *pd)
-{
-	struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
-	struct device *dev = &pd->dev;
-	int ret;
-
-	ret = sysfs_create_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
-	if (ret < 0)
-		dev_err(dev, "failed to create attributes. err=%d\n", ret);
-
-	return ret;
-}
-
-static int cros_ec_sysfs_remove(struct platform_device *pd)
-{
-	struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
-
-	sysfs_remove_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
-
-	return 0;
-}
+static const struct attribute_group *cros_ec_attr_groups[] = {
+	&cros_ec_attr_group,
+	NULL,
+};
 
 static struct platform_driver cros_ec_sysfs_driver = {
 	.driver = {
 		.name = DRV_NAME,
+		.dev_groups = cros_ec_attr_groups,
 	},
-	.probe = cros_ec_sysfs_probe,
-	.remove = cros_ec_sysfs_remove,
 };
 
 module_platform_driver(cros_ec_sysfs_driver);
-- 
2.31.0.208.g409f899ff0-goog


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

* [PATCH v2 2/2] platform/chrome: Update cros_ec sysfs attributes on sensors discovery
  2021-04-05 20:28 [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
  2021-04-05 20:28 ` [PATCH v2 1/2] platform/chrome: Use dev_groups to set device sysfs attributes Gwendal Grignou
@ 2021-04-05 20:28 ` Gwendal Grignou
  2021-05-27 21:01 ` [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
  2 siblings, 0 replies; 6+ messages in thread
From: Gwendal Grignou @ 2021-04-05 20:28 UTC (permalink / raw)
  To: bleung, enric.balletbo, groeck; +Cc: linux-kernel, Gwendal Grignou, stable

When cros_ec_sysfs probe is called before cros_ec_sensorhub probe
routine, the |kb_wake_angle| attribute will not be displayed, even if
there are two accelerometers in the chromebook.

Call sysfs_update_groups() when accelerometers are enumerated if the
cros_ec sysfs attributes groups have already been created.

Fixes: d60ac88a62df ("mfd / platform / iio: cros_ec: Register sensor through sensorhub")
Cc: stable@vger.kernel.org
Signed-off-by: Gwendal Grignou <gwendal@google.com>
---
 Changes in v2:
 Rebase after .dev_groups is used.

 drivers/platform/chrome/cros_ec_sensorhub.c |  6 +++++-
 drivers/platform/chrome/cros_ec_sysfs.c     | 10 ++++++++++
 include/linux/platform_data/cros_ec_proto.h |  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_sensorhub.c b/drivers/platform/chrome/cros_ec_sensorhub.c
index 9c4af76a9956e..c69fec935fb50 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub.c
@@ -106,8 +106,11 @@ static int cros_ec_sensorhub_register(struct device *dev,
 		sensor_type[sensorhub->resp->info.type]++;
 	}
 
-	if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2)
+	if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2) {
 		ec->has_kb_wake_angle = true;
+		if (ec->groups && sysfs_update_groups(&ec->class_dev.kobj, ec->groups))
+			dev_warn(dev, "Unable to update cros-ec-sysfs");
+	}
 
 	if (cros_ec_check_features(ec,
 				   EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS)) {
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index 114b9dbe981e7..b363f70270a38 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -340,11 +340,21 @@ static const struct attribute_group *cros_ec_attr_groups[] = {
 	NULL,
 };
 
+static int cros_ec_sysfs_probe(struct platform_device *pd)
+{
+	struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
+
+	ec_dev->groups = cros_ec_attr_groups;
+
+	return 0;
+}
+
 static struct platform_driver cros_ec_sysfs_driver = {
 	.driver = {
 		.name = DRV_NAME,
 		.dev_groups = cros_ec_attr_groups,
 	},
+	.probe = cros_ec_sysfs_probe,
 };
 
 module_platform_driver(cros_ec_sysfs_driver);
diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
index 02599687770c5..de940112f53ae 100644
--- a/include/linux/platform_data/cros_ec_proto.h
+++ b/include/linux/platform_data/cros_ec_proto.h
@@ -191,6 +191,7 @@ struct cros_ec_platform {
 /**
  * struct cros_ec_dev - ChromeOS EC device entry point.
  * @class_dev: Device structure used in sysfs.
+ * @groups: sysfs attributes groups for this EC.
  * @ec_dev: cros_ec_device structure to talk to the physical device.
  * @dev: Pointer to the platform device.
  * @debug_info: cros_ec_debugfs structure for debugging information.
@@ -200,6 +201,7 @@ struct cros_ec_platform {
  */
 struct cros_ec_dev {
 	struct device class_dev;
+	const struct attribute_group **groups;
 	struct cros_ec_device *ec_dev;
 	struct device *dev;
 	struct cros_ec_debugfs *debug_info;
-- 
2.31.0.208.g409f899ff0-goog


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

* Re: [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found
  2021-04-05 20:28 [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
  2021-04-05 20:28 ` [PATCH v2 1/2] platform/chrome: Use dev_groups to set device sysfs attributes Gwendal Grignou
  2021-04-05 20:28 ` [PATCH v2 2/2] platform/chrome: Update cros_ec sysfs attributes on sensors discovery Gwendal Grignou
@ 2021-05-27 21:01 ` Gwendal Grignou
  2021-05-31  5:36   ` Dmitry Torokhov
  2 siblings, 1 reply; 6+ messages in thread
From: Gwendal Grignou @ 2021-05-27 21:01 UTC (permalink / raw)
  To: Benson Leung, Enric Balletbo i Serra, Guenter Roeck
  Cc: linux-kernel, Gwendal Grignou, Dmitry Torokhov

[+dtor]
Is this change acceptable? I was worried it could break when
asynchronous probing is used [https://lwn.net/Articles/629895/], but
since all probes are deferred in a single thread, it is safe.
Gwendal.


Gwendal.

On Mon, Apr 5, 2021 at 1:29 PM Gwendal Grignou <gwendal@chromium.org> wrote:
>
> Attribute "kb_wake_angle" in /sys/<cros_ec hw path>/chromeos/cros_ec,
> used to set at which angle the embedded controller must wake up the
> host, is only set when there is at least 2 accelerometers in the
> chromebook.
>
> The detection of these sensors is done in cros_ec_sensorhub, driver that
> can be probed after the cros_ec_sysfs driver that sets the attribute.
> Therefore, we need to upgrade the cros_ec sysfs groups in the sensorhub
> probe routine.
>
> The first patch cleans up cros_ec_sysfs by using .dev_groups driver
> field, the second patch fixes the problem.
>
> Gwendal Grignou (2):
>   platform/chrome: Use dev_groups to set device sysfs attributes
>   platform/chrome: Update cros_ec sysfs attributes on sensors discovery
>
>  drivers/platform/chrome/cros_ec_sensorhub.c |  5 ++++-
>  drivers/platform/chrome/cros_ec_sysfs.c     | 22 +++++++--------------
>  include/linux/platform_data/cros_ec_proto.h |  2 ++
>  3 files changed, 13 insertions(+), 16 deletions(-)
>
> --
> 2.31.0.208.g409f899ff0-goog
>

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

* Re: [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found
  2021-05-27 21:01 ` [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
@ 2021-05-31  5:36   ` Dmitry Torokhov
  2021-08-04 21:09     ` Gwendal Grignou
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2021-05-31  5:36 UTC (permalink / raw)
  To: Gwendal Grignou
  Cc: Benson Leung, Enric Balletbo i Serra, Guenter Roeck,
	linux-kernel, Gwendal Grignou

Hi Gwendal,

On Thu, May 27, 2021 at 2:01 PM Gwendal Grignou <gwendal@chromium.org> wrote:
>
> [+dtor]
> Is this change acceptable? I was worried it could break when
> asynchronous probing is used [https://lwn.net/Articles/629895/], but
> since all probes are deferred in a single thread, it is safe.

I think this is a bit awkward that we need to poke a separate sub-driver.

Have you considered having cros_ec_sensorhub.c create its own
attribute group (it does not have to have a name and it looks like one
can register as many unnamed groups as they want) and have wake angle
show and store methods directly in cros_ec_sensorhub.c?

Thanks,
Dmitry

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

* Re: [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found
  2021-05-31  5:36   ` Dmitry Torokhov
@ 2021-08-04 21:09     ` Gwendal Grignou
  0 siblings, 0 replies; 6+ messages in thread
From: Gwendal Grignou @ 2021-08-04 21:09 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Benson Leung, Enric Balletbo i Serra, Guenter Roeck,
	linux-kernel, Gwendal Grignou

The v2 patches I submitted were wrong, as cros_ec sysfs driver is
modifying the attributes of the class driver, not its own. I repost a
patch that takes that into account.
Gwendal.

On Sun, May 30, 2021 at 10:36 PM Dmitry Torokhov <dtor@chromium.org> wrote:
>
> Hi Gwendal,
>
> On Thu, May 27, 2021 at 2:01 PM Gwendal Grignou <gwendal@chromium.org> wrote:
> >
> > [+dtor]
> > Is this change acceptable? I was worried it could break when
> > asynchronous probing is used [https://lwn.net/Articles/629895/], but
> > since all probes are deferred in a single thread, it is safe.
>
> I think this is a bit awkward that we need to poke a separate sub-driver.
>
> Have you considered having cros_ec_sensorhub.c create its own
> attribute group (it does not have to have a name and it looks like one
> can register as many unnamed groups as they want) and have wake angle
> show and store methods directly in cros_ec_sensorhub.c?
>
> Thanks,
> Dmitry

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

end of thread, other threads:[~2021-08-04 21:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05 20:28 [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
2021-04-05 20:28 ` [PATCH v2 1/2] platform/chrome: Use dev_groups to set device sysfs attributes Gwendal Grignou
2021-04-05 20:28 ` [PATCH v2 2/2] platform/chrome: Update cros_ec sysfs attributes on sensors discovery Gwendal Grignou
2021-05-27 21:01 ` [PATCH v2 0/2] platform/chrome: Update cros_ec sysfs attribute after sensors are found Gwendal Grignou
2021-05-31  5:36   ` Dmitry Torokhov
2021-08-04 21:09     ` Gwendal Grignou

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).