Re: [PATCH 1/9] media: v4l: Add v4l2_acpi_parse_sensor_gpios() helper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 5/18/23 18:36, Andy Shevchenko wrote:
> On Thu, May 18, 2023 at 6:32 PM Hans de Goede <hdegoede@xxxxxxxxxx> wrote:
>>
>> On x86/ACPI platforms the GPIO resources do not provide information
>> about which GPIO resource maps to which connection-id. So e.g.
>> gpiod_get(devg, "reset") does not work.
>>
>> On devices with an Intel IPU3 or newer ISP there is a special ACPI
>> INT3472 device describing the GPIOs and instantiating of the i2c_client
>> for a sensor is deferred until the INT3472 driver has been bound based
>> on the sensor ACPI device having a _DEP on the INT3472 ACPI device.
>>
>> This allows the INT3472 driver to add the necessary GPIO lookups
>> without needing any special ACPI handling in the sensor driver.
>>
>> Unfortunately this does not work on devices with an atomisp2 ISP,
>> there the _DSM describing the GPIOs is part of the sensor ACPI device
>> itself, rather then being part of a separate ACPI device.
> 
> than
> 
> (not the first time I see the same typo in your commit messages :-)
> 
> 
>> IOW there is no separate firmware-node to which we can bind to register
>> the GPIO lookups (and also no way to defer creating the sensor i2c_client).
>>
>> This unfortunately means that all sensor drivers which may be used on
>> BYT or CHT hw need some code to deal with ACPI integration.
>>
>> This patch adds a new v4l2_acpi_parse_sensor_gpios() helper function
>> for this, which does all the necessary work. This minimizes the
>> (unavoidable) change to sensor drivers for ACPI integration to just
>> adding a single line calling this void function to probe().
>>
>> There also is a no-op stub provided for non ACPI platforms so that
>> no #ifdef-s are necessary in the driver.
>>
>> Note v4l2_acpi_parse_sensor_gpios() is basically a copy of
>> the atomisp2 v4l2_get_acpi_sensor_info() helper from:
>> drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
>> minus logging the sensor module-name using a second _DSM.
> 
>> v4l2_get_acpi_sensor_info() was already reviewed by Andy,
>> see the Link tag below.
>>
>> (this code duplication is removed in the next patch in this series)
> 
> I believe the above is not needed to be in the commit message, but
> rather in the comments below (after the '---' cutter line).
> 
> ...

<snip>

>> + * Note this code uses the same DSM GUID as the INT3472 discrete.c code
>> + * and there is some overlap, but there are enough differences that it is
>> + * difficult to share the code.
> 
> Can you add the name of the variable in that file, so likely the
> source code indexing tool might add a link?

You mean change the comment something like this:

 * Note this code uses the same DSM GUID as the int3472_gpio_guid in
 * the INT3472 discrete.c code and there is some overlap, but there are
 * enough differences that it is difficult to share the code.

I guess, where int3472_gpio_guid comes from:

drivers/platform/x86/intel/int3472/discrete.c:

static const guid_t int3472_gpio_guid =
        GUID_INIT(0x79234640, 0x9e10, 0x4fea,
                  0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f);


?


>> +       devm_acpi_dev_add_driver_gpios(dev, data.map->mapping);
> 
> Won't we print a warning here as well in case of error?

The only way this can fail is with -ENOMEM (we already know dev
has an ACPI companion) and generally speaking the rule is to
not log errors for ENOMEM since when we hit that the kernel
already complains loudly before returning from the alloc call.

> ...
> 
>> +#ifdef CONFIG_ACPI
> 
>> +struct device;
> 
> This should be outside of previous ifdeffery as it's used in a stub.
> 
>> +/**
>> + * v4l2_acpi_parse_sensor_gpios - Parse ACPI info describing sensor GPIOs.
>> + *
> 
> Dunno the style of v4l2, but this line is redundant.
> 
>> + * @dev: Device to parse the ACPI info for
>> + *
>> + * On x86/ACPI platforms the GPIO resources do not provide information
>> + * about which resource maps to which connection-id.
>> + *
>> + * Sensor drivers can call this function to use platform specific methods
>> + * (e.g. the Intel 79234640-9e10-4fea-a5c1-b5aa8b19756f _DSM) to get
>> + * information about the pins and add GPIO mappings to make standard gpiod_get()
>> + * calls work.
>> + *
>> + * The registered mappings use devm managed memory and are automatically free-ed
>> + * on remove() and on probe() failure.
>> + */
> 
> Usually the kernel doc is attached to the function implementation

Thank you for the review!

I agree with all your other points and I'll address them
in the next version.

The kernel doc being here is modeled after newer (less old)
v4l2 APIs like include/media/v4l2-fwnode.h and
include/media/v4l2-async.h which all also have this in the header.

So unless the v4l2 folks want me to change this I'm going to keep
the kernel docs in the header.

(more in general I have seen both header and next to the body
placements for these kernel docs in various places in the kernel)

Regards,

Hans




>> +void v4l2_acpi_parse_sensor_gpios(struct device *dev);
>> +
>> +#else /* ifdef CONFIG_ACPI */
>> +static inline void v4l2_acpi_parse_sensor_gpios(struct device *dev) { return 0; }
>> +#endif /* ifdef CONFIG_ACPI */
> 




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux