drivers/gpio/gpio-ts4900.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-ts4900.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-ts4900.c- Extension
.c- Size
- 4958 bytes
- Lines
- 196
- Domain
- Driver Families
- Bucket
- drivers/gpio
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/gpio/driver.hlinux/i2c.hlinux/module.hlinux/property.hlinux/regmap.h
Detected Declarations
struct ts4900_gpio_privfunction ts4900_gpio_get_directionfunction ts4900_gpio_direction_inputfunction ts4900_gpio_direction_outputfunction ts4900_gpio_getfunction ts4900_gpio_setfunction ts4900_gpio_probe
Annotated Snippet
struct ts4900_gpio_priv {
struct regmap *regmap;
struct gpio_chip gpio_chip;
unsigned int input_bit;
};
static int ts4900_gpio_get_direction(struct gpio_chip *chip,
unsigned int offset)
{
struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);
unsigned int reg;
regmap_read(priv->regmap, offset, ®);
if (reg & TS4900_GPIO_OE)
return GPIO_LINE_DIRECTION_OUT;
return GPIO_LINE_DIRECTION_IN;
}
static int ts4900_gpio_direction_input(struct gpio_chip *chip,
unsigned int offset)
{
struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);
/*
* Only clear the OE bit here, requires a RMW. Prevents a potential issue
* with OE and DAT getting to the physical pin at different times.
*/
return regmap_update_bits(priv->regmap, offset, TS4900_GPIO_OE, 0);
}
static int ts4900_gpio_direction_output(struct gpio_chip *chip,
unsigned int offset, int value)
{
struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);
unsigned int reg;
int ret;
/*
* If changing from an input to an output, we need to first set the
* GPIO's DAT bit to what is requested and then set the OE bit. This
* prevents a glitch that can occur on the IO line.
*/
regmap_read(priv->regmap, offset, ®);
if (!(reg & TS4900_GPIO_OE)) {
if (value)
reg = TS4900_GPIO_OUT;
else
reg &= ~TS4900_GPIO_OUT;
regmap_write(priv->regmap, offset, reg);
}
if (value)
ret = regmap_write(priv->regmap, offset, TS4900_GPIO_OE |
TS4900_GPIO_OUT);
else
ret = regmap_write(priv->regmap, offset, TS4900_GPIO_OE);
return ret;
}
static int ts4900_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);
unsigned int reg;
regmap_read(priv->regmap, offset, ®);
return !!(reg & priv->input_bit);
}
static int ts4900_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);
if (value)
return regmap_update_bits(priv->regmap, offset,
TS4900_GPIO_OUT, TS4900_GPIO_OUT);
return regmap_update_bits(priv->regmap, offset, TS4900_GPIO_OUT, 0);
}
static const struct regmap_config ts4900_regmap_config = {
.reg_bits = 16,
.val_bits = 8,
};
Annotation
- Immediate include surface: `linux/gpio/driver.h`, `linux/i2c.h`, `linux/module.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct ts4900_gpio_priv`, `function ts4900_gpio_get_direction`, `function ts4900_gpio_direction_input`, `function ts4900_gpio_direction_output`, `function ts4900_gpio_get`, `function ts4900_gpio_set`, `function ts4900_gpio_probe`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.