gpio: mlxbf: enable GPIO interface and ACPI event for host-gpio[7]
PATCH 1/1 gpio: mlxbf: enable GPIO interface and ACPI event for host-gpio[7]
This commit adds ACPI handling for host-gpio[7] to trigger the power-button event.
--- drivers/gpio/gpio-mlxbf.c | 65 +++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 10 deletions(-)
drivers/gpio/gpio-mlxbf.c +55 -10
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/acpi.h> +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/device.h> #include <linux/gpio/driver.h>
@@ -12,19 +13,30 @@#include <linux/resource.h> #include <linux/types.h> +#include "gpiolib-acpi.h" +/* Number of pins on BlueField */ #define MLXBF_GPIO_NR 54/* Pad Electrical Controls. */ -#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700 -#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708 -#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710 -#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718 +#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700 +#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708 +#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710 +#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718 + +#define MLXBF_GPIO_PIN_DIR_I 0x1040 +#define MLXBF_GPIO_PIN_DIR_O 0x1048 +#define MLXBF_GPIO_PIN_STATE 0x1000 +#define MLXBF_GPIO_SCRATCHPAD 0x20 +#define MLXBF_GPIO_INT_SETUP 0x0040 +#define MLXBF_GPIO_INT_SETUP_GBL_ENA_MASK 0x1 + +/* GPIO pin 7 is reserved for power good indication on BlueField. */ +#define MLXBF_GPIO_POWER_GOOD_PIN 7 -#define MLXBF_GPIO_PIN_DIR_I 0x1040 -#define MLXBF_GPIO_PIN_DIR_O 0x1048 -#define MLXBF_GPIO_PIN_STATE 0x1000 -#define MLXBF_GPIO_SCRATCHPAD 0x20 +/* GPIO pins enabled for interrupt */ +#define MLXBF_GPIO_INT_ENA_DEASSERT 0x3008 +#define MLXBF_GPIO_INT_DEASSERT_ENA_BITS BIT(MLXBF_GPIO_POWER_GOOD_PIN)#ifdef CONFIG_PM struct mlxbf_gpio_context_save_regs {
@@ -42,17 +54,39 @@ struct mlxbf_gpio_state {/* Memory Address */ void __iomem *base; +int hwirq; +#ifdef CONFIG_PM struct mlxbf_gpio_context_save_regs csave_regs;#endif }; +static int mlxbf_gpio_to_irq (struct gpio_chip *chip,u32 gpio) +{ +struct mlxbf_gpio_state *gs =gpiochip_get_data (chip); + +return gs->hwirq; +} + +static void mlxbf_gpio_cfg_irq (struct mlxbf_gpio_state *gs) +{ +u64 intr_cfg; + + intr_cfg =readq (gs->base +MLXBF_GPIO_INT_SETUP ); + intr_cfg |=MLXBF_GPIO_INT_SETUP_GBL_ENA_MASK ; +writeq (intr_cfg, gs->base +MLXBF_GPIO_INT_SETUP ); + + intr_cfg =readq (gs->base +MLXBF_GPIO_INT_ENA_DEASSERT ); + intr_cfg |=MLXBF_GPIO_INT_DEASSERT_ENA_BITS ; +writeq (intr_cfg, gs->base +MLXBF_GPIO_INT_ENA_DEASSERT ); +} +static int mlxbf_gpio_probe (struct platform_device *pdev) { -struct mlxbf_gpio_state *gs;struct device *dev = &pdev->dev; +struct mlxbf_gpio_state *gs;struct gpio_chip *gc; -int ret; +int ret, irq; gs =devm_kzalloc (&pdev->dev,sizeof (*gs),GFP_KERNEL );if (!gs)
@@ -63,6 +97,7 @@ static int mlxbf_gpio_probe(struct platform_device *pdev)return PTR_ERR (gs->base); gc = &gs->gc; + ret = bgpio_init(gc, dev, 8, gs->base + MLXBF_GPIO_PIN_STATE, NULL,
@@ -73,8 +108,16 @@ static int mlxbf_gpio_probe(struct platform_device *pdev)if (ret)return -ENODEV ; + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + gc->owner =THIS_MODULE ; gc->ngpio =MLXBF_GPIO_NR ; + gs->hwirq = irq; + gc->to_irq = mlxbf_gpio_to_irq; + +mlxbf_gpio_cfg_irq (gs); ret =devm_gpiochip_add_data (dev, &gs->gc, gs);if (ret) {
@@ -83,7 +126,9 @@ static int mlxbf_gpio_probe(struct platform_device *pdev) }platform_set_drvdata (pdev, gs); +acpi_gpiochip_request_interrupts (gc);dev_info (&pdev->dev,"registered Mellanox BlueField GPIO" ); +return 0 ; }
Signature · 1 line
2.30.1
Quoted 2 lines · David Thompson
This commit adds ACPI handling for host-gpio[7] to trigger the power-button event.
This has something to discuss...
...
drivers/gpio/gpio-mlxbf.c line 25
Quoted 9 lines
/* Pad Electrical Controls. */
drivers/gpio/gpio-mlxbf.c +4
-4-#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700 -#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708 -#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710 -#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718 +#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700 +#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708 +#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710 +#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718
Unrelated change.
drivers/gpio/gpio-mlxbf.c line 30
Quoted 4 lines
drivers/gpio/gpio-mlxbf.c +4
-0+#define MLXBF_GPIO_PIN_DIR_I 0x1040 +#define MLXBF_GPIO_PIN_DIR_O 0x1048 +#define MLXBF_GPIO_PIN_STATE 0x1000 +#define MLXBF_GPIO_SCRATCHPAD 0x20
Ditto. You already have it defined, why to change?
Quoted 4 lines
drivers/gpio/gpio-mlxbf.c +0
-4-#define MLXBF_GPIO_PIN_DIR_I 0x1040 -#define MLXBF_GPIO_PIN_DIR_O 0x1048 -#define MLXBF_GPIO_PIN_STATE 0x1000 -#define MLXBF_GPIO_SCRATCHPAD 0x20
...
drivers/gpio/gpio-mlxbf.c static int mlxbf_gpio_probe(struct platform_device *pdev) · line 118
Quoted 2 lines
drivers/gpio/gpio-mlxbf.c +2
-0+ gs->hwirq = irq; + gc->to_irq = mlxbf_gpio_to_irq;
This sounds incorrect. Seems like for _any_ interrupt you will give the same result. Moreover, you should not use to_irq(). Try to model proper IRQ chip.
...
drivers/gpio/gpio-mlxbf.c static int mlxbf_gpio_probe(struct platform_device *pdev) · line 129
Quoted 2 lines
drivers/gpio/gpio-mlxbf.c +1
-0platform_set_drvdata (pdev, gs); +acpi_gpiochip_request_interrupts (gc);
This is done by GPIO library, no?
...
drivers/gpio/gpio-mlxbf.c static int mlxbf_gpio_probe(struct platform_device *pdev) · line 132
Quoted 3 lines
drivers/gpio/gpio-mlxbf.c +1
-0dev_info (&pdev->dev,"registered Mellanox BlueField GPIO" ); +return 0 ;
Stray change.
Signature · 2 lines
With Best Regards, Andy Shevchenko