diff mbox series

platform/x86: serial-multi-instantiate: allow single GpioInt IRQ for INT3515

Message ID 20231212103823.546118-2-michal.kopec@3mdeb.com (mailing list archive)
State New, archived
Headers show
Series platform/x86: serial-multi-instantiate: allow single GpioInt IRQ for INT3515 | expand

Commit Message

Michał Kopeć Dec. 12, 2023, 10:38 a.m. UTC
From: Michał Kopeć <michal@nozomi.space>

On some devices, such as the Lenovo ThinkPad T14 Gen1 (AMD), there is
only one GpioInt resource defined for all i2c device instances. Handle
this case appropriately by autodetecting the irq type and allowing
fallback to the first IRQ index for the second, third and fourth
tps6598x instances.

Additionally, to use the `platform_get_irq_optional` function to silence
errors that may not be relevant if the IRQ is optional. In cases where
the IRQ is not optional, `dev_err_probe` is still triggered, so other
devices will not be affected by this change.

v2: fix linewrap in summary
v3: fix more patch formatting issues

Signed-off-by: Michał Kopeć <michal@nozomi.space>
---
 .../platform/x86/serial-multi-instantiate.c   | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

kernel test robot Dec. 12, 2023, 10:37 p.m. UTC | #1
Hi Michał,

kernel test robot noticed the following build warnings:

[auto build test WARNING on westeri-thunderbolt/next]
[also build test WARNING on linus/master v6.7-rc5 next-20231212]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Micha-Kope/platform-x86-serial-multi-instantiate-allow-single-GpioInt-IRQ-for-INT3515/20231212-184116
base:   https://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git next
patch link:    https://lore.kernel.org/r/20231212103823.546118-2-michal.kopec%403mdeb.com
patch subject: [PATCH] platform/x86: serial-multi-instantiate: allow single GpioInt IRQ for INT3515
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20231213/202312130609.vkwtG6qJ-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231213/202312130609.vkwtG6qJ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312130609.vkwtG6qJ-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/platform/x86/serial-multi-instantiate.c:79:17: warning: logical not is only applied to the left hand side of this bitwise operator [-Wlogical-not-parentheses]
           if (ret < 0 && !inst->flags & IRQ_OPTIONAL)
                          ^            ~
   drivers/platform/x86/serial-multi-instantiate.c:79:17: note: add parentheses after the '!' to evaluate the bitwise operator first
           if (ret < 0 && !inst->flags & IRQ_OPTIONAL)
                          ^
                           (                         )
   drivers/platform/x86/serial-multi-instantiate.c:79:17: note: add parentheses around left hand side expression to silence this warning
           if (ret < 0 && !inst->flags & IRQ_OPTIONAL)
                          ^
                          (           )
   1 warning generated.


vim +79 drivers/platform/x86/serial-multi-instantiate.c

    51	
    52	static int smi_get_irq(struct platform_device *pdev, struct acpi_device *adev,
    53			       const struct smi_instance *inst)
    54	{
    55		int ret;
    56	
    57		switch (inst->flags & IRQ_RESOURCE_TYPE) {
    58		case IRQ_RESOURCE_AUTO:
    59			ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
    60			if (ret > 0) {
    61				dev_dbg(&pdev->dev, "Using gpio irq\n");
    62				break;
    63			}
    64			ret = platform_get_irq_optional(pdev, inst->irq_idx);
    65			if (ret > 0) {
    66				dev_dbg(&pdev->dev, "Using platform irq\n");
    67				break;
    68			}
    69			break;
    70		case IRQ_RESOURCE_GPIO:
    71			ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
    72			break;
    73		case IRQ_RESOURCE_APIC:
    74			ret = platform_get_irq_optional(pdev, inst->irq_idx);
    75			break;
    76		default:
    77			return 0;
    78		}
  > 79		if (ret < 0 && !inst->flags & IRQ_OPTIONAL)
    80			return dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d\n",
    81					     inst->irq_idx);
    82	
    83		return ret;
    84	}
    85
kernel test robot Dec. 18, 2023, 12:54 a.m. UTC | #2
Hi Michał,

kernel test robot noticed the following build warnings:

[auto build test WARNING on westeri-thunderbolt/next]
[also build test WARNING on linus/master v6.7-rc5 next-20231215]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Micha-Kope/platform-x86-serial-multi-instantiate-allow-single-GpioInt-IRQ-for-INT3515/20231212-184116
base:   https://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git next
patch link:    https://lore.kernel.org/r/20231212103823.546118-2-michal.kopec%403mdeb.com
patch subject: [PATCH] platform/x86: serial-multi-instantiate: allow single GpioInt IRQ for INT3515
config: i386-randconfig-r112-20231217 (https://download.01.org/0day-ci/archive/20231218/202312180832.j4FO9TyV-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231218/202312180832.j4FO9TyV-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312180832.j4FO9TyV-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/platform/x86/serial-multi-instantiate.c:79:37: sparse: sparse: dubious: !x & y

vim +79 drivers/platform/x86/serial-multi-instantiate.c

    51	
    52	static int smi_get_irq(struct platform_device *pdev, struct acpi_device *adev,
    53			       const struct smi_instance *inst)
    54	{
    55		int ret;
    56	
    57		switch (inst->flags & IRQ_RESOURCE_TYPE) {
    58		case IRQ_RESOURCE_AUTO:
    59			ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
    60			if (ret > 0) {
    61				dev_dbg(&pdev->dev, "Using gpio irq\n");
    62				break;
    63			}
    64			ret = platform_get_irq_optional(pdev, inst->irq_idx);
    65			if (ret > 0) {
    66				dev_dbg(&pdev->dev, "Using platform irq\n");
    67				break;
    68			}
    69			break;
    70		case IRQ_RESOURCE_GPIO:
    71			ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
    72			break;
    73		case IRQ_RESOURCE_APIC:
    74			ret = platform_get_irq_optional(pdev, inst->irq_idx);
    75			break;
    76		default:
    77			return 0;
    78		}
  > 79		if (ret < 0 && !inst->flags & IRQ_OPTIONAL)
    80			return dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d\n",
    81					     inst->irq_idx);
    82	
    83		return ret;
    84	}
    85
Dan Carpenter Jan. 3, 2024, 11:17 a.m. UTC | #3
Hi Michał,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Micha-Kope/platform-x86-serial-multi-instantiate-allow-single-GpioInt-IRQ-for-INT3515/20231212-184116
base:   https://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git next
patch link:    https://lore.kernel.org/r/20231212103823.546118-2-michal.kopec%403mdeb.com
patch subject: [PATCH] platform/x86: serial-multi-instantiate: allow single GpioInt IRQ for INT3515
config: x86_64-randconfig-161-20231219 (https://download.01.org/0day-ci/archive/20231220/202312200538.fJidUMf0-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202312200538.fJidUMf0-lkp@intel.com/

smatch warnings:
drivers/platform/x86/serial-multi-instantiate.c:79 smi_get_irq() warn: add some parenthesis here?
drivers/platform/x86/serial-multi-instantiate.c:79 smi_get_irq() warn: maybe use && instead of &

vim +79 drivers/platform/x86/serial-multi-instantiate.c

35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  52  static int smi_get_irq(struct platform_device *pdev, struct acpi_device *adev,
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  53  		       const struct smi_instance *inst)
e64e84987de5486 drivers/platform/x86/i2c-multi-instantiate.c    Hans de Goede   2018-08-09  54  {
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  55  	int ret;
e64e84987de5486 drivers/platform/x86/i2c-multi-instantiate.c    Hans de Goede   2018-08-09  56  
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  57  	switch (inst->flags & IRQ_RESOURCE_TYPE) {
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  58  	case IRQ_RESOURCE_AUTO:
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  59  		ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  60  		if (ret > 0) {
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  61  			dev_dbg(&pdev->dev, "Using gpio irq\n");
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  62  			break;
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  63  		}
fef1688e82fe3ee drivers/platform/x86/serial-multi-instantiate.c Michał Kopeć    2023-12-12  64  		ret = platform_get_irq_optional(pdev, inst->irq_idx);
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  65  		if (ret > 0) {
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  66  			dev_dbg(&pdev->dev, "Using platform irq\n");
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  67  			break;
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  68  		}
676b7c5ecab3627 drivers/platform/x86/serial-multi-instantiate.c David Xu        2023-07-13  69  		break;
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  70  	case IRQ_RESOURCE_GPIO:
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  71  		ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  72  		break;
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  73  	case IRQ_RESOURCE_APIC:
fef1688e82fe3ee drivers/platform/x86/serial-multi-instantiate.c Michał Kopeć    2023-12-12  74  		ret = platform_get_irq_optional(pdev, inst->irq_idx);
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  75  		break;
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  76  	default:
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  77  		return 0;
e64e84987de5486 drivers/platform/x86/i2c-multi-instantiate.c    Hans de Goede   2018-08-09  78  	}
fef1688e82fe3ee drivers/platform/x86/serial-multi-instantiate.c Michał Kopeć    2023-12-12 @79  	if (ret < 0 && !inst->flags & IRQ_OPTIONAL)

Precedence bug.  This should be:

	if (ret < 0 && !(inst->flags & IRQ_OPTIONAL))

14a9aa99aca6c28 drivers/platform/x86/serial-multi-instantiate.c Andy Shevchenko 2022-07-10  80  		return dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d\n",
14a9aa99aca6c28 drivers/platform/x86/serial-multi-instantiate.c Andy Shevchenko 2022-07-10  81  				     inst->irq_idx);
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  82  
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  83  	return ret;
35a36cbb7b1ce75 drivers/platform/x86/serial-multi-instantiate.c Lucas Tanure    2022-01-21  84  }
diff mbox series

Patch

diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/platform/x86/serial-multi-instantiate.c
index 8158e3cf5d6d..1c4cc44d5a88 100644
--- a/drivers/platform/x86/serial-multi-instantiate.c
+++ b/drivers/platform/x86/serial-multi-instantiate.c
@@ -23,6 +23,8 @@ 
 #define IRQ_RESOURCE_APIC	2
 #define IRQ_RESOURCE_AUTO   3
 
+#define IRQ_OPTIONAL		BIT(2)
+
 enum smi_bus_type {
 	SMI_I2C,
 	SMI_SPI,
@@ -59,7 +61,7 @@  static int smi_get_irq(struct platform_device *pdev, struct acpi_device *adev,
 			dev_dbg(&pdev->dev, "Using gpio irq\n");
 			break;
 		}
-		ret = platform_get_irq(pdev, inst->irq_idx);
+		ret = platform_get_irq_optional(pdev, inst->irq_idx);
 		if (ret > 0) {
 			dev_dbg(&pdev->dev, "Using platform irq\n");
 			break;
@@ -69,12 +71,12 @@  static int smi_get_irq(struct platform_device *pdev, struct acpi_device *adev,
 		ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx);
 		break;
 	case IRQ_RESOURCE_APIC:
-		ret = platform_get_irq(pdev, inst->irq_idx);
+		ret = platform_get_irq_optional(pdev, inst->irq_idx);
 		break;
 	default:
 		return 0;
 	}
-	if (ret < 0)
+	if (ret < 0 && !inst->flags & IRQ_OPTIONAL)
 		return dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d\n",
 				     inst->irq_idx);
 
@@ -210,6 +212,8 @@  static int smi_i2c_probe(struct platform_device *pdev, struct smi *smi,
 		board_info.dev_name = name;
 
 		ret = smi_get_irq(pdev, adev, &inst_array[i]);
+		if (ret < 0 && inst_array[i].flags & IRQ_OPTIONAL)
+			ret = smi_get_irq(pdev, adev, &inst_array[0]);
 		if (ret < 0)
 			goto error;
 		board_info.irq = ret;
@@ -309,10 +313,11 @@  static const struct smi_node bsg2150_data = {
 
 static const struct smi_node int3515_data = {
 	.instances = {
-		{ "tps6598x", IRQ_RESOURCE_APIC, 0 },
-		{ "tps6598x", IRQ_RESOURCE_APIC, 1 },
-		{ "tps6598x", IRQ_RESOURCE_APIC, 2 },
-		{ "tps6598x", IRQ_RESOURCE_APIC, 3 },
+		{ "tps6598x", IRQ_RESOURCE_AUTO, 0 },
+		/* On some platforms only one shared GpioInt is defined */
+		{ "tps6598x", IRQ_RESOURCE_AUTO | IRQ_OPTIONAL, 1 },
+		{ "tps6598x", IRQ_RESOURCE_AUTO | IRQ_OPTIONAL, 2 },
+		{ "tps6598x", IRQ_RESOURCE_AUTO | IRQ_OPTIONAL, 3 },
 		{}
 	},
 	.bus_type = SMI_I2C,