File Index
Files and directories
Sign in
FILE

regmap.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/gpio/regmap.h C
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2
  3#ifndef _LINUX_GPIO_REGMAP_H
  4#define _LINUX_GPIO_REGMAP_H
  5
  6struct device;
  7struct fwnode_handle;
  8struct gpio_regmap;
  9struct gpio_chip;
 10struct irq_domain;
 11struct regmap;
 12
 13#define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))
 14#define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
 15
 16/**
 17 * struct gpio_regmap_config - Description of a generic regmap gpio_chip.
 18 * @parent:		The parent device
 19 * @regmap:		The regmap used to access the registers
 20 *			given, the name of the device is used
 21 * @fwnode:		(Optional) The firmware node.
 22 *			If not given, the fwnode of the parent is used.
 23 * @label:		(Optional) Descriptive name for GPIO controller.
 24 *			If not given, the name of the device is used.
 25 * @ngpio:		(Optional) Number of GPIOs
 26 * @names:		(Optional) Array of names for gpios
 27 * @reg_dat_base:	(Optional) (in) register base address
 28 * @reg_set_base:	(Optional) set register base address
 29 * @reg_clr_base:	(Optional) clear register base address
 30 * @reg_dir_in_base:	(Optional) in setting register base address
 31 * @reg_dir_out_base:	(Optional) out setting register base address
 32 * @reg_stride:		(Optional) May be set if the registers (of the
 33 *			same type, dat, set, etc) are not consecutive.
 34 * @ngpio_per_reg:	(Optional) Number of GPIOs per register
 35 * @irq_domain:		(Optional) IRQ domain if the controller is
 36 *			interrupt-capable
 37 * @reg_mask_xlate:     (Optional) Translates base address and GPIO
 38 *			offset to a register/bitmask pair. If not
 39 *			given the default gpio_regmap_simple_xlate()
 40 *			is used.
 41 * @fixed_direction_output:
 42 *			(Optional) Bitmap representing the fixed direction of
 43 *			the GPIO lines. Useful when there are GPIO lines with a
 44 *			fixed direction mixed together in the same register.
 45 * @drvdata:		(Optional) Pointer to driver specific data which is
 46 *			not used by gpio-remap but is provided "as is" to the
 47 *			driver callback(s).
 48 * @init_valid_mask:	(Optional) Routine to initialize @valid_mask, to be used
 49 *			if not all GPIOs are valid.
 50 * @regmap_irq_chip:	(Optional) Pointer on an regmap_irq_chip structure. If
 51 *			set, a regmap-irq device will be created and the IRQ
 52 *			domain will be set accordingly.
 53 * @regmap_irq_line:	(Optional) The IRQ the device uses to signal interrupts.
 54 * @regmap_irq_flags:	(Optional) The IRQF_ flags to use for the interrupt.
 55 *
 56 * The ->reg_mask_xlate translates a given base address and GPIO offset to
 57 * register and mask pair. The base address is one of the given register
 58 * base addresses in this structure.
 59 *
 60 * Although all register base addresses are marked as optional, there are
 61 * several rules:
 62 *     1. if you only have @reg_dat_base set, then it is input-only
 63 *     2. if you only have @reg_set_base set, then it is output-only
 64 *     3. if you have either @reg_dir_in_base or @reg_dir_out_base set, then
 65 *        you have to set both @reg_dat_base and @reg_set_base
 66 *     4. if you have @reg_set_base set, you may also set @reg_clr_base to have
 67 *        two different registers for setting and clearing the output. This is
 68 *        also valid for the output-only case.
 69 *     5. @reg_dir_in_base and @reg_dir_out_base are exclusive; is there really
 70 *        hardware which has redundant registers?
 71 *
 72 * Note: All base addresses may have the special value %GPIO_REGMAP_ADDR_ZERO
 73 * which forces the address to the value 0.
 74 */
 75struct gpio_regmap_config {
 76	struct device *parent;
 77	struct regmap *regmap;
 78	struct fwnode_handle *fwnode;
 79
 80	const char *label;
 81	int ngpio;
 82	const char *const *names;
 83
 84	unsigned int reg_dat_base;
 85	unsigned int reg_set_base;
 86	unsigned int reg_clr_base;
 87	unsigned int reg_dir_in_base;
 88	unsigned int reg_dir_out_base;
 89	int reg_stride;
 90	int ngpio_per_reg;
 91	struct irq_domain *irq_domain;
 92	unsigned long *fixed_direction_output;
 93
 94#ifdef CONFIG_REGMAP_IRQ
 95	struct regmap_irq_chip *regmap_irq_chip;
 96	int regmap_irq_line;
 97	unsigned long regmap_irq_flags;
 98#endif
 99
100	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
101			      unsigned int offset, unsigned int *reg,
102			      unsigned int *mask);
103
104	int (*init_valid_mask)(struct gpio_chip *gc,
105			       unsigned long *valid_mask,
106			       unsigned int ngpios);
107
108	void *drvdata;
109};
110
111struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config);
112void gpio_regmap_unregister(struct gpio_regmap *gpio);
113struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
114					      const struct gpio_regmap_config *config);
115void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio);
116
117#endif /* _LINUX_GPIO_REGMAP_H */
~/ Read-only file preview.