linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] platform/x86: int3472: discrete: Use FIELD_GET() on the GPIO _DSM return value
@ 2023-06-13 11:08 Hans de Goede
  2023-06-13 11:08 ` [PATCH 2/2] platform/x86: int3472: discrete: Log a warning if the pin-numbers don't match Hans de Goede
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2023-06-13 11:08 UTC (permalink / raw)
  To: Ilpo Järvinen, Andy Shevchenko, Dan Scally
  Cc: Hans de Goede, platform-driver-x86, linux-media

Add defines for the various fields encoded in the GPIO _DSM integer
return value and then use FIELD_GET() to get field values.

Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/intel/int3472/discrete.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
index fc839a73e411..a31964076883 100644
--- a/drivers/platform/x86/intel/int3472/discrete.c
+++ b/drivers/platform/x86/intel/int3472/discrete.c
@@ -2,6 +2,7 @@
 /* Author: Dan Scally <djrscally@gmail.com> */
 
 #include <linux/acpi.h>
+#include <linux/bitfield.h>
 #include <linux/device.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
@@ -25,6 +26,10 @@ static const guid_t int3472_gpio_guid =
 	GUID_INIT(0x79234640, 0x9e10, 0x4fea,
 		  0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f);
 
+#define INT3472_GPIO_DSM_TYPE				GENMASK(7, 0)
+#define INT3472_GPIO_DSM_PIN				GENMASK(15, 8)
+#define INT3472_GPIO_DSM_SENSOR_ON_VAL			GENMASK(31, 24)
+
 /*
  * 822ace8f-2814-4174-a56b-5f029fe079ee
  * This _DSM GUID returns a string from the sensor device, which acts as a
@@ -174,12 +179,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 		return 1;
 	}
 
-	type = obj->integer.value & 0xff;
+	type = FIELD_GET(INT3472_GPIO_DSM_TYPE, obj->integer.value);
 
 	int3472_get_func_and_polarity(type, &func, &polarity);
 
-	/* If bits 31-24 of the _DSM entry are all 0 then the signal is inverted */
-	active_value = obj->integer.value >> 24;
+	active_value = FIELD_GET(INT3472_GPIO_DSM_SENSOR_ON_VAL, obj->integer.value);
 	if (!active_value)
 		polarity ^= GPIO_ACTIVE_LOW;
 
-- 
2.40.1


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

* [PATCH 2/2] platform/x86: int3472: discrete: Log a warning if the pin-numbers don't match
  2023-06-13 11:08 [PATCH 1/2] platform/x86: int3472: discrete: Use FIELD_GET() on the GPIO _DSM return value Hans de Goede
@ 2023-06-13 11:08 ` Hans de Goede
  2023-06-13 11:17   ` Ilpo Järvinen
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2023-06-13 11:08 UTC (permalink / raw)
  To: Ilpo Järvinen, Andy Shevchenko, Dan Scally
  Cc: Hans de Goede, platform-driver-x86, linux-media

The INT3472 discrete code assumes that the ACPI GPIO resources are
in the same order as the pin-info _DSM entries.

The returned pin-info includes the pin-number in bits 15-8. Add a check
that this matches with the ACPI GPIO resource pin-number in case
the assumption is not true with some ACPI tables.

Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/intel/int3472/discrete.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
index a31964076883..850f306214c7 100644
--- a/drivers/platform/x86/intel/int3472/discrete.c
+++ b/drivers/platform/x86/intel/int3472/discrete.c
@@ -154,8 +154,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 {
 	struct int3472_discrete_device *int3472 = data;
 	struct acpi_resource_gpio *agpio;
+	u8 active_value, pin, type;
 	union acpi_object *obj;
-	u8 active_value, type;
 	const char *err_msg;
 	const char *func;
 	u32 polarity;
@@ -183,6 +183,12 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 
 	int3472_get_func_and_polarity(type, &func, &polarity);
 
+	pin = FIELD_GET(INT3472_GPIO_DSM_PIN, obj->integer.value);
+	if (pin != agpio->pin_table[0])
+		dev_warn(int3472->dev, "%s %s pin number mismatch _DSM %d resource %d\n",
+			 func, agpio->resource_source.string_ptr, pin,
+			 agpio->pin_table[0]);
+
 	active_value = FIELD_GET(INT3472_GPIO_DSM_SENSOR_ON_VAL, obj->integer.value);
 	if (!active_value)
 		polarity ^= GPIO_ACTIVE_LOW;
-- 
2.40.1


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

* Re: [PATCH 2/2] platform/x86: int3472: discrete: Log a warning if the pin-numbers don't match
  2023-06-13 11:08 ` [PATCH 2/2] platform/x86: int3472: discrete: Log a warning if the pin-numbers don't match Hans de Goede
@ 2023-06-13 11:17   ` Ilpo Järvinen
  2023-06-15 12:38     ` Hans de Goede
  0 siblings, 1 reply; 4+ messages in thread
From: Ilpo Järvinen @ 2023-06-13 11:17 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Andy Shevchenko, Dan Scally, platform-driver-x86, linux-media

[-- Attachment #1: Type: text/plain, Size: 1848 bytes --]

On Tue, 13 Jun 2023, Hans de Goede wrote:

> The INT3472 discrete code assumes that the ACPI GPIO resources are
> in the same order as the pin-info _DSM entries.
> 
> The returned pin-info includes the pin-number in bits 15-8. Add a check
> that this matches with the ACPI GPIO resource pin-number in case
> the assumption is not true with some ACPI tables.
> 
> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/intel/int3472/discrete.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
> index a31964076883..850f306214c7 100644
> --- a/drivers/platform/x86/intel/int3472/discrete.c
> +++ b/drivers/platform/x86/intel/int3472/discrete.c
> @@ -154,8 +154,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
>  {
>  	struct int3472_discrete_device *int3472 = data;
>  	struct acpi_resource_gpio *agpio;
> +	u8 active_value, pin, type;
>  	union acpi_object *obj;
> -	u8 active_value, type;
>  	const char *err_msg;
>  	const char *func;
>  	u32 polarity;
> @@ -183,6 +183,12 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
>  
>  	int3472_get_func_and_polarity(type, &func, &polarity);
>  
> +	pin = FIELD_GET(INT3472_GPIO_DSM_PIN, obj->integer.value);
> +	if (pin != agpio->pin_table[0])
> +		dev_warn(int3472->dev, "%s %s pin number mismatch _DSM %d resource %d\n",
> +			 func, agpio->resource_source.string_ptr, pin,
> +			 agpio->pin_table[0]);
> +
>  	active_value = FIELD_GET(INT3472_GPIO_DSM_SENSOR_ON_VAL, obj->integer.value);
>  	if (!active_value)
>  		polarity ^= GPIO_ACTIVE_LOW;

For both 1 and 2,

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>


--
 i.

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

* Re: [PATCH 2/2] platform/x86: int3472: discrete: Log a warning if the pin-numbers don't match
  2023-06-13 11:17   ` Ilpo Järvinen
@ 2023-06-15 12:38     ` Hans de Goede
  0 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2023-06-15 12:38 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Andy Shevchenko, Dan Scally, platform-driver-x86, linux-media

Hi,

On 6/13/23 13:17, Ilpo Järvinen wrote:
> On Tue, 13 Jun 2023, Hans de Goede wrote:
> 
>> The INT3472 discrete code assumes that the ACPI GPIO resources are
>> in the same order as the pin-info _DSM entries.
>>
>> The returned pin-info includes the pin-number in bits 15-8. Add a check
>> that this matches with the ACPI GPIO resource pin-number in case
>> the assumption is not true with some ACPI tables.
>>
>> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/platform/x86/intel/int3472/discrete.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
>> index a31964076883..850f306214c7 100644
>> --- a/drivers/platform/x86/intel/int3472/discrete.c
>> +++ b/drivers/platform/x86/intel/int3472/discrete.c
>> @@ -154,8 +154,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
>>  {
>>  	struct int3472_discrete_device *int3472 = data;
>>  	struct acpi_resource_gpio *agpio;
>> +	u8 active_value, pin, type;
>>  	union acpi_object *obj;
>> -	u8 active_value, type;
>>  	const char *err_msg;
>>  	const char *func;
>>  	u32 polarity;
>> @@ -183,6 +183,12 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
>>  
>>  	int3472_get_func_and_polarity(type, &func, &polarity);
>>  
>> +	pin = FIELD_GET(INT3472_GPIO_DSM_PIN, obj->integer.value);
>> +	if (pin != agpio->pin_table[0])
>> +		dev_warn(int3472->dev, "%s %s pin number mismatch _DSM %d resource %d\n",
>> +			 func, agpio->resource_source.string_ptr, pin,
>> +			 agpio->pin_table[0]);
>> +
>>  	active_value = FIELD_GET(INT3472_GPIO_DSM_SENSOR_ON_VAL, obj->integer.value);
>>  	if (!active_value)
>>  		polarity ^= GPIO_ACTIVE_LOW;
> 
> For both 1 and 2,
> 
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

Thank you.

I've added this to my review-hans (soon to be for-next) branch now.

Regards,

Hans




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

end of thread, other threads:[~2023-06-15 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13 11:08 [PATCH 1/2] platform/x86: int3472: discrete: Use FIELD_GET() on the GPIO _DSM return value Hans de Goede
2023-06-13 11:08 ` [PATCH 2/2] platform/x86: int3472: discrete: Log a warning if the pin-numbers don't match Hans de Goede
2023-06-13 11:17   ` Ilpo Järvinen
2023-06-15 12:38     ` Hans de Goede

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