drivers/gpio/gpio-nct6694.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-nct6694.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-nct6694.c- Extension
.c- Size
- 12562 bytes
- Lines
- 500
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bits.hlinux/gpio/driver.hlinux/idr.hlinux/interrupt.hlinux/mfd/nct6694.hlinux/module.hlinux/platform_device.h
Detected Declarations
struct nct6694_gpio_datafunction nct6694_get_directionfunction nct6694_direction_inputfunction nct6694_direction_outputfunction nct6694_get_valuefunction nct6694_set_valuefunction nct6694_set_configfunction nct6694_init_valid_maskfunction nct6694_irq_handlerfunction nct6694_get_irq_trigfunction nct6694_irq_maskfunction nct6694_irq_unmaskfunction nct6694_irq_set_typefunction nct6694_irq_bus_lockfunction nct6694_irq_bus_sync_unlockfunction scoped_guardfunction nct6694_irq_dispose_mappingfunction nct6694_gpio_ida_freefunction nct6694_gpio_probe
Annotated Snippet
struct nct6694_gpio_data {
struct nct6694 *nct6694;
struct gpio_chip gpio;
struct mutex lock;
/* Protect irq operation */
struct mutex irq_lock;
unsigned char reg_val;
unsigned char irq_trig_falling;
unsigned char irq_trig_rising;
/* Current gpio group */
unsigned char group;
int irq;
};
static int nct6694_get_direction(struct gpio_chip *gpio, unsigned int offset)
{
struct nct6694_gpio_data *data = gpiochip_get_data(gpio);
const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_GPIO_MOD,
.offset = cpu_to_le16(NCT6694_GPO_DIR + data->group),
.len = cpu_to_le16(sizeof(data->reg_val))
};
int ret;
guard(mutex)(&data->lock);
ret = nct6694_read_msg(data->nct6694, &cmd_hd, &data->reg_val);
if (ret < 0)
return ret;
return !(BIT(offset) & data->reg_val);
}
static int nct6694_direction_input(struct gpio_chip *gpio, unsigned int offset)
{
struct nct6694_gpio_data *data = gpiochip_get_data(gpio);
const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_GPIO_MOD,
.offset = cpu_to_le16(NCT6694_GPO_DIR + data->group),
.len = cpu_to_le16(sizeof(data->reg_val))
};
int ret;
guard(mutex)(&data->lock);
ret = nct6694_read_msg(data->nct6694, &cmd_hd, &data->reg_val);
if (ret < 0)
return ret;
data->reg_val &= ~BIT(offset);
return nct6694_write_msg(data->nct6694, &cmd_hd, &data->reg_val);
}
static int nct6694_direction_output(struct gpio_chip *gpio,
unsigned int offset, int val)
{
struct nct6694_gpio_data *data = gpiochip_get_data(gpio);
struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_GPIO_MOD,
.offset = cpu_to_le16(NCT6694_GPO_DIR + data->group),
.len = cpu_to_le16(sizeof(data->reg_val))
};
int ret;
guard(mutex)(&data->lock);
/* Set direction to output */
ret = nct6694_read_msg(data->nct6694, &cmd_hd, &data->reg_val);
if (ret < 0)
return ret;
data->reg_val |= BIT(offset);
ret = nct6694_write_msg(data->nct6694, &cmd_hd, &data->reg_val);
if (ret < 0)
return ret;
/* Then set output level */
cmd_hd.offset = cpu_to_le16(NCT6694_GPO_DATA + data->group);
ret = nct6694_read_msg(data->nct6694, &cmd_hd, &data->reg_val);
if (ret < 0)
return ret;
if (val)
data->reg_val |= BIT(offset);
else
data->reg_val &= ~BIT(offset);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/gpio/driver.h`, `linux/idr.h`, `linux/interrupt.h`, `linux/mfd/nct6694.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct nct6694_gpio_data`, `function nct6694_get_direction`, `function nct6694_direction_input`, `function nct6694_direction_output`, `function nct6694_get_value`, `function nct6694_set_value`, `function nct6694_set_config`, `function nct6694_init_valid_mask`, `function nct6694_irq_handler`, `function nct6694_get_irq_trig`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.