linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
To: Guenter Roeck <groeck@google.com>
Cc: Lee Jones <lee.jones@linaro.org>,
	Gwendal Grignou <gwendal@chromium.org>,
	Nicolas Boichat <drinkcat@chromium.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Guenter Roeck <groeck@chromium.org>,
	kernel@collabora.com, Benson Leung <bleung@chromium.org>,
	Olof Johansson <olof@lixom.net>
Subject: Re: [PATCH v3 7/8] platform/chrome: cros_ec_lightbar: instantiate only if the EC has a lightbar.
Date: Tue, 11 Dec 2018 12:18:10 +0100	[thread overview]
Message-ID: <be4b375e-32dd-4b62-f04b-e66c2f6092db@collabora.com> (raw)
In-Reply-To: <CABXOdTfagM6sRWYMNs3cEwtjvOe8LVvmZ6=0LfBueT7JJzw-MQ@mail.gmail.com>



On 10/12/18 19:20, Guenter Roeck wrote:
> On Tue, Nov 27, 2018 at 4:19 AM Enric Balletbo i Serra
> <enric.balletbo@collabora.com> wrote:
>>
>> Due to the way attribute groups visibility work, the function
>> cros_ec_lightbar_attrs_are_visible is called multiple times, once per
>> attribute, and each of these calls makes an EC transaction. For what is
>> worth the EC log reports multiple errors on boot when the lightbar is
>> not available. Instead, check if the EC has a lightbar in the probe
>> function and only instantiate the device.
>>
>> Ideally we should have instantiate the driver only if the
>> EC_FEATURE_LIGHTBAR is defined, but that's not possible because that flag
>> is not in the very first Pixel Chromebook (Link), only on Samus. So, the
>> driver is instantiated by his parent always.
>>
>> This patch changes a bit the actual behaviour. Before the patch if an EC
>> doesn't have a lightbar an empty lightbar folder is created in
>> /sys/class/chromeos/<ec device>, after the patch the empty folder is not
>> created, so, the folder is only created if the lightbar exists.
>>
>> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> 
> Nitpicks, otherwise
> 
> Reviewed-by: Guenter Roeck <groeck@chromium.org>
> 
>> ---
>>
>> Changes in v3: None
>> Changes in v2:
>> - Removed ec_with_lightbar variable.
>>
>>  drivers/platform/chrome/cros_ec_lightbar.c | 37 ++++++++--------------
>>  1 file changed, 13 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
>> index 80eed6317570..6f6a4cbfc3fc 100644
>> --- a/drivers/platform/chrome/cros_ec_lightbar.c
>> +++ b/drivers/platform/chrome/cros_ec_lightbar.c
>> @@ -43,7 +43,6 @@ static unsigned long lb_interval_jiffies = 50 * HZ / 1000;
>>   * If this is true, we won't do anything during suspend/resume.
>>   */
>>  static bool userspace_control;
>> -static struct cros_ec_dev *ec_with_lightbar;
>>
>>  static ssize_t interval_msec_show(struct device *dev,
>>                                   struct device_attribute *attr, char *buf)
>> @@ -381,9 +380,6 @@ static int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
>>         struct cros_ec_command *msg;
>>         int ret;
>>
>> -       if (ec != ec_with_lightbar)
>> -               return 0;
>> -
>>         msg = alloc_lightbar_cmd_msg(ec);
>>         if (!msg)
>>                 return -ENOMEM;
>> @@ -567,37 +563,26 @@ static struct attribute *__lb_cmds_attrs[] = {
>>         NULL,
>>  };
>>
>> -static bool ec_has_lightbar(struct cros_ec_dev *ec)
>> +static bool cros_ec_has_lightbar(struct cros_ec_dev *ec_dev)
>>  {
>> -       return !!get_lightbar_version(ec, NULL, NULL);
>> -}
>> -
>> -static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj,
>> -                                                 struct attribute *a, int n)
>> -{
>> -       struct device *dev = container_of(kobj, struct device, kobj);
>> -       struct cros_ec_dev *ec = to_cros_ec_dev(dev);
>> -       struct platform_device *pdev = to_platform_device(ec->dev);
>> +       struct platform_device *pdev = to_platform_device(ec_dev->dev);
>>         struct cros_ec_platform *pdata = pdev->dev.platform_data;
>>         int is_cros_ec;
>>
>>         is_cros_ec = strcmp(pdata->ec_name, CROS_EC_DEV_NAME);
>>
>>         if (is_cros_ec != 0)
>> -               return 0;
>> +               return false;
>>
> FWIW, is_cros_ec is really unnecessary here, though I guess that might
> be a different patch.
> 
>> -       /* Only instantiate this stuff if the EC has a lightbar */
>> -       if (ec_has_lightbar(ec)) {
>> -               ec_with_lightbar = ec;
>> -               return a->mode;
>> -       }
>> -       return 0;
>> +       if (!!get_lightbar_version(ec_dev, NULL, NULL))
>> +               return true;
>> +
>> +       return false;
> 
> Why not just the following ?
>             return !!get_lightbar_version(ec_dev, NULL, NULL);
> or even
>             return !strcmp(pdata->ec_name, CROS_EC_DEV_NAME) &&
>                       !!get_lightbar_version(ec_dev, NULL, NULL);
> 

Ack, I think that we can get rid of the cros_ec_has_lightbar function then. I'll
do in next version.

Thanks,
 Enric

>>  }
>>
>>  struct attribute_group cros_ec_lightbar_attr_group = {
>>         .name = "lightbar",
>>         .attrs = __lb_cmds_attrs,
>> -       .is_visible = cros_ec_lightbar_attrs_are_visible,
>>  };
>>
>>  static int cros_ec_lightbar_probe(struct platform_device *pd)
>> @@ -606,6 +591,10 @@ static int cros_ec_lightbar_probe(struct platform_device *pd)
>>         struct device *dev = &pd->dev;
>>         int ret;
>>
>> +       /* Only instantiate this stuff if the EC has a lightbar */
>> +       if (!cros_ec_has_lightbar(ec_dev))
>> +               return -ENODEV;
>> +
>>         /* Take control of the lightbar from the EC. */
>>         lb_manual_suspend_ctrl(ec_dev, 1);
>>
>> @@ -635,7 +624,7 @@ static int __maybe_unused cros_ec_lightbar_resume(struct device *dev)
>>  {
>>         struct cros_ec_dev *ec_dev = dev_get_drvdata(dev);
>>
>> -       if (userspace_control || ec_dev != ec_with_lightbar)
>> +       if (userspace_control)
>>                 return 0;
>>
>>         return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_RESUME);
>> @@ -645,7 +634,7 @@ static int __maybe_unused cros_ec_lightbar_suspend(struct device *dev)
>>  {
>>         struct cros_ec_dev *ec_dev = dev_get_drvdata(dev);
>>
>> -       if (userspace_control || ec_dev != ec_with_lightbar)
>> +       if (userspace_control)
>>                 return 0;
>>
>>         return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_SUSPEND);
>> --
>> 2.19.1
>>

  reply	other threads:[~2018-12-11 11:18 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 12:18 [PATCH v3 0/8] mfd / platform: cros_ec: move cros_ec sysfs attributes to its own drivers Enric Balletbo i Serra
2018-11-27 12:18 ` [PATCH v3 1/8] mfd / platform: cros_ec: use devm_mfd_add_devices Enric Balletbo i Serra
2018-11-29 23:30   ` Guenter Roeck
2018-12-03 10:32   ` Lee Jones
2018-12-03 22:13     ` Enric Balletbo i Serra
2018-12-04  9:22       ` Lee Jones
2018-11-27 12:18 ` [PATCH v3 2/8] mfd / platform: cros_ec: move lightbar attributes to its own driver Enric Balletbo i Serra
2018-11-29 23:34   ` Guenter Roeck
2018-12-03 10:36   ` Lee Jones
2018-12-03 22:21     ` Enric Balletbo i Serra
2018-12-04  9:21       ` Lee Jones
2018-12-04 11:52         ` Enric Balletbo i Serra
2018-12-04 16:57           ` Guenter Roeck
2018-12-05  8:09             ` Lee Jones
2018-12-05  7:25           ` Lee Jones
2018-11-27 12:18 ` [PATCH v3 3/8] mfd / platform: cros_ec: move vbc " Enric Balletbo i Serra
2018-11-29 23:36   ` Guenter Roeck
2018-12-03 10:42   ` Lee Jones
2018-11-27 12:18 ` [PATCH v3 4/8] mfd / platform: cros_ec: move debugfs " Enric Balletbo i Serra
2018-12-03 10:55   ` Lee Jones
2018-12-10 18:04   ` Guenter Roeck
2018-11-27 12:18 ` [PATCH v3 5/8] mfd / platform: cros_ec: move device sysfs " Enric Balletbo i Serra
2018-12-03 10:56   ` Lee Jones
2018-12-10 18:13   ` Guenter Roeck
2018-12-10 18:22     ` Enric Balletbo i Serra
2018-12-10 18:28       ` Guenter Roeck
2018-12-10 21:27         ` Enric Balletbo Serra
2018-12-10 21:50           ` Guenter Roeck
2018-12-10 22:11             ` Enric Balletbo Serra
2018-12-10 22:25               ` Guenter Roeck
2018-11-27 12:18 ` [PATCH v3 6/8] mfd / platform: cros_ec: instantiate only if th EC has a VBC NVRAM Enric Balletbo i Serra
2018-12-03 10:57   ` Lee Jones
2018-12-10 18:15   ` Guenter Roeck
2018-12-10 18:30     ` Guenter Roeck
2018-11-27 12:18 ` [PATCH v3 7/8] platform/chrome: cros_ec_lightbar: instantiate only if the EC has a lightbar Enric Balletbo i Serra
2018-12-10 18:20   ` Guenter Roeck
2018-12-11 11:18     ` Enric Balletbo i Serra [this message]
2018-11-27 12:18 ` [PATCH v3 8/8] mfd: cros_ec: add a dev_release empty method Enric Balletbo i Serra
2018-11-27 17:29   ` Guenter Roeck
2018-11-27 17:52     ` Greg Kroah-Hartman
2018-11-29  1:17       ` Guenter Roeck
2018-11-29  7:55         ` Greg Kroah-Hartman
2018-11-29 22:11           ` Enric Balletbo i Serra
2018-11-29 22:28             ` Guenter Roeck
2018-11-30  8:30             ` Greg Kroah-Hartman

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=be4b375e-32dd-4b62-f04b-e66c2f6092db@collabora.com \
    --to=enric.balletbo@collabora.com \
    --cc=bleung@chromium.org \
    --cc=drinkcat@chromium.org \
    --cc=groeck@chromium.org \
    --cc=groeck@google.com \
    --cc=gwendal@chromium.org \
    --cc=kernel@collabora.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    /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 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).