drivers/mfd/max7360.c

Source file repositories/reference/linux-study-clean/drivers/mfd/max7360.c

File Facts

System
Linux kernel
Corpus path
drivers/mfd/max7360.c
Extension
.c
Size
4731 bytes
Lines
172
Domain
Driver Families
Bucket
drivers/mfd
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Maxim MAX7360 Core Driver
 *
 * Copyright 2025 Bootlin
 *
 * Authors:
 *    Kamel Bouhara <kamel.bouhara@bootlin.com>
 *    Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
 */

#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/delay.h>
#include <linux/device/devres.h>
#include <linux/dev_printk.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/mfd/core.h>
#include <linux/mfd/max7360.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/types.h>

static const struct mfd_cell max7360_cells[] = {
	{ .name           = "max7360-pinctrl" },
	{ .name           = "max7360-pwm" },
	{ .name           = "max7360-keypad" },
	{ .name           = "max7360-rotary" },
	{
		.name           = "max7360-gpo",
		.of_compatible	= "maxim,max7360-gpo",
	},
	{
		.name           = "max7360-gpio",
		.of_compatible	= "maxim,max7360-gpio",
	},
};

static const struct regmap_range max7360_volatile_ranges[] = {
	regmap_reg_range(MAX7360_REG_KEYFIFO, MAX7360_REG_KEYFIFO),
	regmap_reg_range(MAX7360_REG_I2C_TIMEOUT, MAX7360_REG_RTR_CNT),
};

static const struct regmap_access_table max7360_volatile_table = {
	.yes_ranges = max7360_volatile_ranges,
	.n_yes_ranges = ARRAY_SIZE(max7360_volatile_ranges),
};

static const struct regmap_config max7360_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = MAX7360_REG_PWMCFG(MAX7360_PORT_PWM_COUNT - 1),
	.volatile_table = &max7360_volatile_table,
	.cache_type = REGCACHE_MAPLE,
};

static int max7360_mask_irqs(struct regmap *regmap)
{
	struct device *dev = regmap_get_device(regmap);
	unsigned int val;
	int ret;

	/*
	 * GPIO/PWM interrupts are not masked on reset: as the MAX7360 "INTI"
	 * interrupt line is shared between GPIOs and rotary encoder, this could
	 * result in repeated spurious interrupts on the rotary encoder driver
	 * if the GPIO driver is not loaded. Mask them now to avoid this
	 * situation.
	 */
	for (unsigned int i = 0; i < MAX7360_PORT_PWM_COUNT; i++) {
		ret = regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i),
					MAX7360_PORT_CFG_INTERRUPT_MASK,
					MAX7360_PORT_CFG_INTERRUPT_MASK);
		if (ret)
			return dev_err_probe(dev, ret,
					     "Failed to write MAX7360 port configuration\n");
	}

	/* Read GPIO in register, to ACK any pending IRQ. */
	ret = regmap_read(regmap, MAX7360_REG_GPIOIN, &val);
	if (ret)
		return dev_err_probe(dev, ret, "Failed to read GPIO values\n");

	return 0;
}

static int max7360_reset(struct regmap *regmap)

Annotation

Implementation Notes