Re: [PATCH v7 08/11] gpio: max7360: Add MAX7360 gpio support
From: Andy Shevchenko
Date: Fri May 02 2025 - 06:40:03 EST
On Mon, Apr 28, 2025 at 01:57:26PM +0200, Mathieu Dubois-Briand wrote:
> Add driver for Maxim Integrated MAX7360 GPIO/GPO controller.
>
> Two sets of GPIOs are provided by the device:
> - Up to 8 GPIOs, shared with the PWM and rotary encoder functionalities.
> These GPIOs also provide interrupts on input changes.
> - Up to 6 GPOs, on unused keypad columns pins.
...
> +#include <linux/bitmap.h>
> +#include <linux/err.h>
> +#include <linux/gpio/driver.h>
Is this still needed?
> +#include <linux/gpio/regmap.h>
> +#include <linux/init.h>
> +#include <linux/interrupt.h>
> +#include <linux/mfd/max7360.h>
+ minmax.h
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
...
> +static int max7360_gpio_probe(struct platform_device *pdev)
> +{
> + const struct max7360_gpio_plat_data *plat_data;
> + struct gpio_regmap_config gpio_config = { };
> + struct regmap_irq_chip *irq_chip;
> + struct device *dev = &pdev->dev;
> + struct regmap *regmap;
> + unsigned int outconf;
> + int ret;
> +
> + regmap = dev_get_regmap(dev->parent, NULL);
> + if (!regmap)
> + return dev_err_probe(dev, -ENODEV, "could not get parent regmap\n");
> +
> + plat_data = device_get_match_data(dev);
> + if (plat_data->function == MAX7360_GPIO_PORT) {
> + if (device_property_read_bool(dev, "interrupt-controller")) {
> + /*
> + * Port GPIOs with interrupt-controller property: add IRQ
> + * controller.
> + */
> + gpio_config.regmap_irq_flags = IRQF_ONESHOT | IRQF_SHARED;
> + gpio_config.regmap_irq_line =
> + fwnode_irq_get_byname(dev_fwnode(dev->parent), "inti");
> + if (gpio_config.regmap_irq_line < 0)
> + return dev_err_probe(dev, gpio_config.regmap_irq_line,
> + "Failed to get IRQ\n");
> + irq_chip = devm_kzalloc(dev, sizeof(*irq_chip), GFP_KERNEL);
Can this be made static const instead?
> + gpio_config.regmap_irq_chip = irq_chip;
> + if (!irq_chip)
> + return -ENOMEM;
> +
> + irq_chip->name = dev_name(dev);
> + irq_chip->status_base = MAX7360_REG_GPIOIN;
> + irq_chip->status_is_level = true;
> + irq_chip->num_regs = 1;
> + irq_chip->num_irqs = MAX7360_MAX_GPIO;
> + irq_chip->irqs = max7360_regmap_irqs;
> + irq_chip->handle_mask_sync = max7360_handle_mask_sync;
> + irq_chip->irq_drv_data = regmap;
> + for (unsigned int i = 0; i < MAX7360_MAX_GPIO; i++) {
> + ret = regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i),
> + MAX7360_PORT_CFG_INTERRUPT_EDGES,
> + MAX7360_PORT_CFG_INTERRUPT_EDGES);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to enable interrupts\n");
> + }
> + }
> +
> + /*
> + * Port GPIOs: set output mode configuration (constant-current or not).
> + * This property is optional.
> + */
> + ret = device_property_read_u32(dev, "maxim,constant-current-disable", &outconf);
> + if (!ret) {
> + ret = regmap_write(regmap, MAX7360_REG_GPIOOUTM, outconf);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to set constant-current configuration\n");
> + }
> + }
> +
> + /* Add gpio device. */
> + gpio_config.parent = dev;
> + gpio_config.regmap = regmap;
> + if (plat_data->function == MAX7360_GPIO_PORT) {
> + gpio_config.ngpio = MAX7360_MAX_GPIO;
> + gpio_config.reg_dat_base = GPIO_REGMAP_ADDR(MAX7360_REG_GPIOIN);
> + gpio_config.reg_set_base = GPIO_REGMAP_ADDR(MAX7360_REG_PWMBASE);
> + gpio_config.reg_dir_out_base = GPIO_REGMAP_ADDR(MAX7360_REG_GPIOCTRL);
> + gpio_config.ngpio_per_reg = MAX7360_MAX_GPIO;
> + gpio_config.reg_mask_xlate = max7360_gpio_reg_mask_xlate;
> + } else {
> + ret = max7360_set_gpos_count(dev, regmap);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to set GPOS pin count\n");
> +
> + gpio_config.reg_set_base = GPIO_REGMAP_ADDR(MAX7360_REG_PORTS);
> + gpio_config.ngpio = MAX7360_MAX_KEY_COLS;
> + gpio_config.init_valid_mask = max7360_gpo_init_valid_mask;
> + }
> +
> + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config));
> +}
--
With Best Regards,
Andy Shevchenko