platform/x86: int3472/discrete: Make it work with IPU6
Subsystems (3)
cover platform/x86: int3472/discrete: Make it work with IPU6
Hi All,
Here is a small set of patches to make the int3472/discrete code work with the sensor drivers bundled with the (unfortunately out of tree) IPU6 driver.
There are parts of the out of tree IPU6 code, like the sensor drivers, which can be moved to the mainline and I do plan to work on this at some point and then some of this might need to change. But for now the goal is to make the out of tree driver work with standard mainline distro kernels through e.g. dkms. Otherwise users need to run a patched kernel just for a couple of small differences.
This is basically a rewrite of this patch:
https://github.com/intel/ipu6-drivers/blob/master/patch/int3472-support-independent-clock-and-LED-gpios-5.17%2B.patch
Wich users who want to use the IPU6 driver so far have had to manually apply to their kernels which is quite inconvenient.
This rewrite makes 2 significant changes:
1. Don't break things on IPU3 platforms
2. Instead of extending the int3472_sensor_configs[] quirks table for each model which needs "clken" and "pled" GPIOs, do this based on matching the ACPI HID of the ACPI device describing the sensor.
The need for these GPIOs is a property of the specific sensor driver which binds using this same HID, so by using this we avoid having to extend the int3472_sensor_configs[] quirks table all the time.
This allows roling back the behavior to at least use a clk-framework clk instead of clken GPIO on a per sensor(-driver) basis as we mainline the sensor drivers, assuming that the drivers are switched over to the clk framework as part of their mainlining.
A bigger question is what to do with the privacy-led GPIO on IPU3 we so far have turned the LED on/off at the same as te clock, but at least on some IPU6 models this won't work, because they only have a privacy-led GPIO and no clk_en GPIO (there is no sensor clk-control at all on some models).
I think we should maybe move all models, including IPU3 based models over to using a normal GPIO for controlling the privacy-led to make things consistent.
And likewise (eventually) completely drop the "clken" GPIO this patch series introduces (with some sensors) and instead always model this through the clk-framework.
Regards,
Hans
Hans de Goede (3):
platform/x86: int3472/discrete: Refactor GPIO to sensor mapping platform/x86: int3472/discrete: Get the polarity from the _DSM entry platform/x86: int3472/discrete: Add support for sensor-drivers which
expect clken + pled GPIOs
drivers/platform/x86/intel/int3472/common.h | 2 +- drivers/platform/x86/intel/int3472/discrete.c | 92 ++++++++++++++++--- 2 files changed, 78 insertions(+), 16 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/3 platform/x86: int3472/discrete: Refactor GPIO to sensor mapping
Make the GPIO to sensor mapping more generic and fold the INT3472_GPIO_TYPE_RESET and INT3472_GPIO_TYPE_POWERDOWN cases into a single generic case.
This is a preparation patch for further GPIO mapping changes.
--- drivers/platform/x86/intel/int3472/discrete.c | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +23 -8
@@ -184,6 +184,24 @@ static int skl_int3472_map_gpio_to_clk(struct int3472_discrete_device *int3472,return 0 ; } +static const char *int3472_dsm_type_to_func (u8 type) +{ +switch (type) { +case INT3472_GPIO_TYPE_RESET : +return "reset" ; +case INT3472_GPIO_TYPE_POWERDOWN : +return "powerdown" ; +case INT3472_GPIO_TYPE_CLK_ENABLE : +return "clken" ; +case INT3472_GPIO_TYPE_PRIVACY_LED : +return "pled" ; +case INT3472_GPIO_TYPE_POWER_ENABLE : +return "power-enable" ; + } + +return "unknown" ; +} +/** * skl_int3472_handle_gpio_resources: Map PMIC resources to consuming sensor * @ares: A pointer to a &struct acpi_resource
@@ -223,6 +241,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,struct acpi_resource_gpio *agpio;union acpi_object *obj;const char *err_msg; +const char *func;int ret;u8 type;
@@ -246,19 +265,15 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, type = obj->integer.value &0xff ; + func =int3472_dsm_type_to_func (type); +switch (type) {case INT3472_GPIO_TYPE_RESET : - ret =skl_int3472_map_gpio_to_sensor (int3472, agpio,"reset" , -GPIO_ACTIVE_LOW ); -if (ret) - err_msg ="Failed to map reset pin to sensor\n" ; - -break ;case INT3472_GPIO_TYPE_POWERDOWN : - ret =skl_int3472_map_gpio_to_sensor (int3472, agpio,"powerdown" , + ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, func,GPIO_ACTIVE_LOW );if (ret) - err_msg ="Failed to map powerdown pin to sensor\n" ; + err_msg ="Failed to map GPIO pin to sensor\n" ;break ;case INT3472_GPIO_TYPE_CLK_ENABLE :
Signature · 1 line
2.38.1
PATCH 2/3 platform/x86: int3472/discrete: Get the polarity from the _DSM entry
In reply to Hans de GoedeThe out of tree IPU6 driver has moved to also using the in kernel INT3472 code for doing power-ctrl rather then doing their own thing (good!).
On IPU6 the polarity is encoded in the _DSM entry rather then being hardcoded to GPIO_ACTIVE_LOW.
Using the _DSM entry for this on IPU3 leads to regressions, so only use the _DSM entry for this on non IPU3 devices.
Note there is a whole bunch of PCI-ids for the IPU6 which is why the check is for the IPU3-CIO2, because the CIO2 there has a unique PCI-id which can be used for this.
--- drivers/platform/x86/intel/int3472/discrete.c | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +26 -2
@@ -11,6 +11,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/overflow.h> +#include <linux/pci.h> #include <linux/platform_device.h> #include <linux/uuid.h>
@@ -36,6 +37,19 @@ static const guid_t cio2_sensor_module_guid =GUID_INIT (0x822ace8f ,0x2814 ,0x4174 ,0xa5 ,0x6b ,0x5f ,0x02 ,0x9f ,0xe0 ,0x79 ,0xee ); +/* IPU3 vs IPU6 needs to be handled differently */ +#define IPU3_CIO2_PCI_ID 0x9d32 + +static const struct pci_device_id ipu3_cio2_pci_id_table[] = { + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,IPU3_CIO2_PCI_ID ) }, + { } +}; + +static int ipu3_present (void ) +{ +return pci_dev_present (ipu3_cio2_pci_id_table); +} +/* * Here follows platform specific mapping information that we can pass to * the functions mapping resources to the sensors. Where the sensors have
@@ -242,6 +256,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,union acpi_object *obj;const char *err_msg;const char *func; +u32 polarity;int ret;u8 type;
@@ -265,13 +280,22 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, type = obj->integer.value &0xff ; +/* IPU3 always uses active-low, IPU6 polarity is encoded in the _DSM entry. */ +if (ipu3_present ()) + polarity =GPIO_ACTIVE_LOW ; +else + polarity = ((obj->integer.value >>24 ) &0xff ) ?GPIO_ACTIVE_HIGH :GPIO_ACTIVE_LOW ; + func =int3472_dsm_type_to_func (type); +dev_dbg (int3472->dev,"%s %s pin %d active-%s\n" , func, + agpio->resource_source.string_ptr, agpio->pin_table[0 ], + (polarity ==GPIO_ACTIVE_HIGH ) ?"high" :"low" ); +switch (type) {case INT3472_GPIO_TYPE_RESET :case INT3472_GPIO_TYPE_POWERDOWN : - ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, func, -GPIO_ACTIVE_LOW ); + ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, func, polarity);if (ret) err_msg ="Failed to map GPIO pin to sensor\n" ;
Signature · 1 line
2.38.1
PATCH 3/3 platform/x86: int3472/discrete: Add support for sensor-drivers which expect clken + pled GPIOs
In reply to Hans de GoedeThe hm11b1 and ov01a1s sensor drivers shipped with the out of tree IPU6 driver, expect the clk_en GPIO to be modelled as a "clken" GPIO rather then using the clk framework; and the hm11b1, ov01a1s and ov2740 driver all 3 expect the privacy-led to be modelled as a "pled" GPIO, rather then it being turned on/off at the same time as the clk.
Adjust how we handle the GPIOs on these sensors accordingly, for now at least, so that the out of tree driver can work with standard distro kernels through e.g. dkms. Otherwise users need to run a patched kernel just for this small difference.
This of course needs to be revisited when we mainline these sensor drivers, I can imagine the drivers getting clk-framework support when they are mainlined and then at that same time their acpi HID can be dropped from the use_gpio_for_clk_acpi_ids[] array.
Note there already is a mainline driver for the ov2740, but that is not impacted by this change since atm it uses neither the clk framework nor a "clken" GPIO.
---
Maybe we should patch the sensor drivers for sensors supported with the IPU3 to also expect the privacy-led to always be a separate GPIO?
This way we can also avoid the camera LED briefly going on at boot, when the driver is powering things up to read the sensor's ID register.
And I have also put looking at making the mainline ov2740 driver suitable for use with the (out of tree) IPU6 driver on my TODO list.
--- drivers/platform/x86/intel/int3472/common.h | 2 +- drivers/platform/x86/intel/int3472/discrete.c | 37 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-)
drivers/platform/x86/intel/int3472/common.h +1 -1
@@ -23,7 +23,7 @@#define INT3472_GPIO_TYPE_PRIVACY_LED 0x0d#define INT3472_PDEV_MAX_NAME_LEN 23 -#define INT3472_MAX_SENSOR_GPIOS 3 +#define INT3472_MAX_SENSOR_GPIOS 4#define GPIO_REGULATOR_NAME_LENGTH 21#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9
drivers/platform/x86/intel/int3472/discrete.c +30 -7
@@ -216,6 +216,26 @@ static const char *int3472_dsm_type_to_func(u8 type)return "unknown" ; } +/* +* The hm11b1 and ov01a1s sensor drivers shipped with the out of tree IPU6 driver, +* expect the clk_en GPIO to be modelled as a "clken" GPIO rather then as a clk and +* the hm11b1, ov01a1s and ov2740 driver all 3 expect the privacy-led to be modelled +* as a "pled" GPIO, rather then it being turned on/off at the same time as the clk. +* +* Note there also is a mainline driver for the ov2740, but that does not use +* the clk framework atm either. +* +* Adjust how we handle the GPIOs on these sensors accordingly, for now at least. +* This needs to be revisited when we mainline these sensor drivers / when we merge +* the necessary changes in the ov2740 sensor driver so that it can work on the IPU6. +*/ +static const struct acpi_device_id use_gpio_for_clk_acpi_ids[] = { + {"HIMX11B1" },/* hm11b1 */ + {"OVTI01AS" },/* ov01a1s */ + {"INT3474" },/* ov2740 */ + {} +}; +/** * skl_int3472_handle_gpio_resources: Map PMIC resources to consuming sensor * @ares: A pointer to a &struct acpi_resource
@@ -293,19 +313,22 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, (polarity == GPIO_ACTIVE_HIGH) ? "high" : "low");switch (type) { +case INT3472_GPIO_TYPE_CLK_ENABLE : +case INT3472_GPIO_TYPE_PRIVACY_LED : +if (!acpi_match_device_ids (int3472->adev, use_gpio_for_clk_acpi_ids)) { + ret =skl_int3472_map_gpio_to_clk (int3472, agpio, type); +if (ret) + err_msg ="Failed to map GPIO to clock\n" ; + +break ; + } + fallthrough;case INT3472_GPIO_TYPE_RESET :case INT3472_GPIO_TYPE_POWERDOWN : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, func, polarity);if (ret) err_msg ="Failed to map GPIO pin to sensor\n" ; -break ; -case INT3472_GPIO_TYPE_CLK_ENABLE : -case INT3472_GPIO_TYPE_PRIVACY_LED : - ret =skl_int3472_map_gpio_to_clk (int3472, agpio, type); -if (ret) - err_msg ="Failed to map GPIO to clock\n" ; -break ;case INT3472_GPIO_TYPE_POWER_ENABLE : ret =skl_int3472_register_regulator (int3472, agpio);
Signature · 1 line
2.38.1
Hi,
Sorry this series was sent to the wrong people / list. I will resend it to the right people now. Please ignore.
Regards,
Hans
Quoted 65 lines · Hans de Goede
Hi All,
Here is a small set of patches to make the int3472/discrete code work with the sensor drivers bundled with the (unfortunately out of tree) IPU6 driver.
There are parts of the out of tree IPU6 code, like the sensor drivers, which can be moved to the mainline and I do plan to work on this at some point and then some of this might need to change. But for now the goal is to make the out of tree driver work with standard mainline distro kernels through e.g. dkms. Otherwise users need to run a patched kernel just for a couple of small differences.
This is basically a rewrite of this patch:
https://github.com/intel/ipu6-drivers/blob/master/patch/int3472-support-independent-clock-and-LED-gpios-5.17%2B.patchWich users who want to use the IPU6 driver so far have had to manually apply to their kernels which is quite inconvenient.
This rewrite makes 2 significant changes:
1. Don't break things on IPU3 platforms
2. Instead of extending the int3472_sensor_configs[] quirks table for each model which needs "clken" and "pled" GPIOs, do this based on matching the ACPI HID of the ACPI device describing the sensor.
The need for these GPIOs is a property of the specific sensor driver which binds using this same HID, so by using this we avoid having to extend the int3472_sensor_configs[] quirks table all the time.
This allows roling back the behavior to at least use a clk-framework clk instead of clken GPIO on a per sensor(-driver) basis as we mainline the sensor drivers, assuming that the drivers are switched over to the clk framework as part of their mainlining.
A bigger question is what to do with the privacy-led GPIO on IPU3 we so far have turned the LED on/off at the same as te clock, but at least on some IPU6 models this won't work, because they only have a privacy-led GPIO and no
clk_enGPIO (there is no sensor clk-control at all on some models).I think we should maybe move all models, including IPU3 based models over to using a normal GPIO for controlling the privacy-led to make things consistent.
And likewise (eventually) completely drop the "clken" GPIO this patch series introduces (with some sensors) and instead always model this through the clk-framework.
Regards,
Hans
Hans de Goede (3):
platform/x86: int3472/discrete: Refactor GPIO to sensor mapping platform/x86: int3472/discrete: Get the polarity from the_DSMentry platform/x86: int3472/discrete: Add support for sensor-drivers which
expect clken + pled GPIOsdrivers/platform/x86/intel/int3472/common.h | 2 +- drivers/platform/x86/intel/int3472/discrete.c | 92 ++++++++++++++++--- 2 files changed, 78 insertions(+), 16 deletions(-)