linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Scally <djrscally@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Tomasz Figa <tfiga@chromium.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Rajmohan Mani <rajmohan.mani@intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Wolfram Sang <wsa@kernel.org>, Lee Jones <lee.jones@linaro.org>,
	kieran.bingham+renesas@ideasonboard.com,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Mark Gross <mgross@linux.intel.com>,
	Maximilian Luz <luzmaximilian@gmail.com>,
	Robert Moore <robert.moore@intel.com>,
	Erik Kaneda <erik.kaneda@intel.com>,
	me@fabwu.ch,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	linux-i2c <linux-i2c@vger.kernel.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	devel@acpica.org
Subject: Re: [PATCH v3 5/6] platform/x86: Add intel_skl_int3472 driver
Date: Mon, 22 Feb 2021 22:35:44 +0000	[thread overview]
Message-ID: <534849f6-c7b5-19b0-a09f-cd410cde93bd@gmail.com> (raw)
In-Reply-To: <CAHp75Vd2Dc2Poq7VNRXRT-0VjkYdEFY2WKpz8fWpAQViQRO4jA@mail.gmail.com>

Hi Andy - thanks for comments!

On 22/02/2021 14:58, Andy Shevchenko wrote:
> On Mon, Feb 22, 2021 at 3:12 PM Daniel Scally <djrscally@gmail.com> wrote:
>> ACPI devices with _HID INT3472 are currently matched to the tps68470
>> driver, however this does not cover all situations in which that _HID
>> occurs. We've encountered three possibilities:
>>
>> 1. On Chrome OS devices, an ACPI device with _HID INT3472 (representing
>> a physical TPS68470 device) that requires a GPIO and OpRegion driver
>> 2. On devices designed for Windows, an ACPI device with _HID INT3472
>> (again representing a physical TPS68470 device) which requires GPIO,
>> Clock and Regulator drivers.
>> 3. On other devices designed for Windows, an ACPI device with _HID
>> INT3472 which does **not** represent a physical TPS68470, and is instead
>> used as a dummy device to group some system GPIO lines which are meant
>> to be consumed by the sensor that is dependent on this entry.
>>
>> This commit adds a new module, registering a platform driver to deal
>> with the 3rd scenario plus an i2c driver to deal with #1 and #2, by
>> querying the CLDB buffer found against INT3472 entries to determine
>> which is most appropriate.
> Can you split CLK parts (and maybe regulators as well) to something
> like intel_skl_int3472_clk.c?


Sure, no problem

>
>> +#include <linux/acpi.h>
>> +#include <linux/i2c.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/slab.h>
>> +               dev_err(&adev->dev, "%s object is not an ACPI buffer\n", id);
> Perhaps acpi_handle_err() et al. instead of dev_*(&adev->dev, ...)
> where it's applicable?


Ah - yes, ok, thanks. TIL those exist

>> +       if (obj->buffer.length > sizeof(*cldb)) {
>> +               dev_err(&adev->dev, "The CLDB buffer is too large\n");
>> +               ret = -EINVAL;
> ENOSPC? ENOMEM?


I still think EINVAL actually, as in this case the problem isn't that
space couldn't be allocated but that the buffer in the SSDB is larger
than I expect it to be, which means the definition of it has changed /
this device isn't actually supported.

>> +       ret = platform_driver_register(&int3472_discrete);
>> +       if (ret)
>> +               return ret;
>> +
>> +       ret = i2c_register_driver(THIS_MODULE, &int3472_tps68470);
>> +       if (ret)
>> +               platform_driver_unregister(&int3472_discrete);
> Not a fan of the above, but let's see what others will say...


Yeah; happy to discuss this more if needed.

>> +#include <linux/clk-provider.h>
> This is definitely not for *.h. (Not all C files needed this)
>
>> +#include <linux/gpio/machine.h>
> Ditto.
>
>> +#include <linux/regulator/driver.h>
>> +#include <linux/regulator/machine.h>
> Ditto.


Yep; I'll move them to *_clk.c and *_regulator.c files.

>> +static int skl_int3472_clk_prepare(struct clk_hw *hw)
>> +{
>> +       struct int3472_gpio_clock *clk = to_int3472_clk(hw);
>> +
>> +       gpiod_set_value(clk->ena_gpio, 1);
>> +       if (clk->led_gpio)
> Make it optional and drop this check. Same for other places of use of this GPIO.


Oops, of course, thanks

>> +static int skl_int3472_clk_enable(struct clk_hw *hw)
>> +{
>> +       /*
>> +        * We're just turning a GPIO on to enable, which operation has the
>> +        * potential to sleep. Given enable cannot sleep, but prepare can,
>> +        * we toggle the GPIO in prepare instead. Thus, nothing to do here.
>> +        */
> Missed . and / or  () in some words? (Describing callbacks, personally
> I use the form "->callback()" in such cases)


OK, I'll fix the comment to match that style.


>> +static unsigned int skl_int3472_get_clk_frequency(struct int3472_discrete_device *int3472)
>> +{
>> +       union acpi_object *obj;
>>
>> +       unsigned int ret = 0;
> unsigned for ret is unusual. Looking into the code, first of all it
> doesn't need this assignment; second, it probably can gain a better
> name: "frequency"?


Yep ok, I'll rename to freq/frequency

>> +       if (!IS_ERR_OR_NULL(sensor_config) && sensor_config->function_maps) {
> Hmm...
>
> Would
>
> if (IS_ERR_OR_NULL(sensor_config))
>   return 0;
>
> if (!_maps)
>   return 0;
>
> with respective comments working here?


No, because the absence of either sensor_config or
sensor_config->function_maps is not a failure mode. We only need to
provide sensor_configs for some platforms, and function_maps for even
fewer. So if that check is false, the rest of the function should still
execute.

>> +static int skl_int3472_register_clock(struct int3472_discrete_device *int3472)
>> +{
>> +       struct clk_init_data init = {
>> +               .ops = &skl_int3472_clock_ops,
>> +               .flags = CLK_GET_RATE_NOCACHE,
>> +       };
>> +       int ret = 0;
>> +
>> +       init.name = kasprintf(GFP_KERNEL, "%s-clk",
>> +                             acpi_dev_name(int3472->adev));
> devm_*() ? Or is the lifetime different?


No it's not; I'll use devm_*(), thanks

>> +       sensor_config = int3472->sensor_config;
>> +       if (IS_ERR_OR_NULL(sensor_config)) {
>> +               dev_err(int3472->dev, "No sensor module config\n");
>> +               return PTR_ERR(sensor_config);
> NULL -> 0. Is it okay?


Ah, no it's not - good catch thank you.

>> +       if (ares->type != ACPI_RESOURCE_TYPE_GPIO ||
>> +           ares->data.gpio.connection_type != ACPI_RESOURCE_GPIO_TYPE_IO)
>> +               return 1; /* Deliberately positive so parsing continues */
> I don't like to lose control over ACPI_RESOURCE_TYPE_GPIO, i.e.
> spreading it over kernel code (yes, I know about one existing TS
> case).
> Consider to provide a helper in analogue to acpi_gpio_get_irq_resource().


Sure, but I probably name it acpi_gpio_is_io_resource() - a function
named "get" which returns a bool seems a bit funny to me.

>> +       if (ret < 0 && ret != -EPROBE_DEFER)
>> +               dev_err(int3472->dev, err_msg);
> dev_err_probe() will make the above conditional go away. And you may even do...


Ah-ha - thought that must exist but couldn't find it - thank you.

>> +       if (int3472->clock.ena_gpio) {
> Not sure you need this here.


We haven't seen a device that lacks a clock enable GPIO it's true, but
since all the other kinds seem optional it didn't seem impossible that
that one is optional too. I can remove if you prefer and we can just
deal with it when we encounter one like that though?

>> +       /* Max num GPIOs we've seen plus a terminator */
>> +       int3472 = kzalloc(struct_size(int3472, gpios.table,
>> +                         INT3472_MAX_SENSOR_GPIOS + 1), GFP_KERNEL);
> Wonder of you can use devm_*() APIs in this function.


Yeah I can, I'll switch to that.


>> +int skl_int3472_discrete_remove(struct platform_device *pdev)
>> +{
>> +       struct int3472_discrete_device *int3472 = platform_get_drvdata(pdev);
>> +       if (int3472->gpios.dev_id)
>> +               gpiod_remove_lookup_table(&int3472->gpios);
> gpiod_remove_lookup_table() is now NULL-aware.
> But in any case I guess you don't need the above check.


Sorry; forgot to call out that I didn't follow that suggestion;
int3472->gpios is a _struct_ rather than a pointer, so &int3472->gpios
won't be NULL, even if I haven't filled anything in to there yet because
it failed before it got to that point. So, not sure that it quite works
there.

>
>> +       if (!IS_ERR(int3472->regulator.rdev))
>> +               regulator_unregister(int3472->regulator.rdev);
> Shouldn't it be the pointer to the regulator itself?
int3472->regulator is type struct int3472_gpio_regulator, the .rdev is
the normal regulator_dev


>
>> +       if (!IS_ERR(int3472->clock.clk))
> If you get it optional, you won't need this additional check.


Yes - here it will definitely work; thanks, I'll add that patch

>> +       ret = skl_int3472_fill_cldb(adev, &cldb);
>> +       if (!ret && cldb.control_logic_type != 2) {
>> +               dev_err(&client->dev, "Unsupported control logic type %u\n",
>> +                       cldb.control_logic_type);
>> +               return -EINVAL;
>> +       }
>> +
>> +       if (ret)
>> +               cldb_present = false;
> if (ret)
>   ...
> else if (...)  {
>   ...
>   return ...;
> }


Oh yeah...now you point that out I have no idea what I was thinking there...


  reply	other threads:[~2021-02-22 22:36 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22 13:07 [PATCH v3 0/6] Introduce intel_skl_int3472 module Daniel Scally
2021-02-22 13:07 ` [PATCH v3 1/6] ACPI: scan: Extend acpi_walk_dep_device_list() Daniel Scally
2021-02-22 13:34   ` Andy Shevchenko
2021-03-07 13:36     ` Daniel Scally
2021-03-07 20:39       ` Andy Shevchenko
2021-03-08 13:36         ` Rafael J. Wysocki
2021-03-08 13:57           ` Andy Shevchenko
2021-03-08 15:45             ` Rafael J. Wysocki
2021-03-08 17:23               ` Rafael J. Wysocki
2021-03-08 20:49                 ` Daniel Scally
2021-02-22 13:38   ` Wolfram Sang
2021-03-08 17:46   ` Rafael J. Wysocki
2021-03-08 20:40     ` Daniel Scally
2021-02-22 13:07 ` [PATCH v3 2/6] ACPI: scan: Add function to fetch dependent of acpi device Daniel Scally
2021-02-22 13:41   ` Andy Shevchenko
2021-02-22 13:07 ` [PATCH v3 3/6] i2c: core: Add a format macro for I2C device names Daniel Scally
2021-02-22 13:38   ` Wolfram Sang
2021-02-22 13:07 ` [PATCH v3 4/6] gpiolib: acpi: Export acpi_get_gpiod() Daniel Scally
2021-02-22 13:54   ` Andy Shevchenko
2021-02-22 13:07 ` [PATCH v3 5/6] platform/x86: Add intel_skl_int3472 driver Daniel Scally
2021-02-22 13:19   ` Daniel Scally
2021-02-22 13:27     ` Hans de Goede
2021-02-22 22:50       ` Daniel Scally
2021-02-22 14:58   ` Andy Shevchenko
2021-02-22 22:35     ` Daniel Scally [this message]
2021-02-23 12:01       ` Andy Shevchenko
2021-02-23 13:06         ` Daniel Scally
2021-05-17 21:43     ` Daniel Scally
2021-05-17 21:47       ` Andy Shevchenko
2021-02-23 20:04   ` Laurent Pinchart
2021-02-23 22:36     ` Daniel Scally
2021-02-24 10:13       ` Laurent Pinchart
2021-02-24 10:18         ` Andy Shevchenko
2021-02-24 10:20           ` Daniel Scally
2021-02-22 13:07 ` [PATCH v3 6/6] mfd: tps68470: Remove tps68470 MFD driver Daniel Scally
2021-02-22 14:12   ` Andy Shevchenko
2021-02-22 22:37     ` Daniel Scally
2021-03-10  9:33   ` Lee Jones
2021-02-22 13:11 ` [PATCH v3 0/6] Introduce intel_skl_int3472 module Daniel Scally
2021-02-22 14:15 ` Andy Shevchenko
2021-03-04 13:37 ` Hans de Goede
2021-03-04 13:49   ` Daniel Scally
2021-03-29 15:03     ` Andy Shevchenko
2021-03-29 20:37       ` Daniel Scally

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=534849f6-c7b5-19b0-a09f-cd410cde93bd@gmail.com \
    --to=djrscally@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devel@acpica.org \
    --cc=erik.kaneda@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lee.jones@linaro.org \
    --cc=lenb@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luzmaximilian@gmail.com \
    --cc=me@fabwu.ch \
    --cc=mgross@linux.intel.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rajmohan.mani@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tfiga@chromium.org \
    --cc=wsa@kernel.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 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).