drivers/gpio/gpio-cgbc.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-cgbc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-cgbc.c- Extension
.c- Size
- 4740 bytes
- Lines
- 201
- 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/mfd/cgbc.hlinux/module.hlinux/mutex.hlinux/platform_device.h
Detected Declarations
struct cgbc_gpio_datafunction cgbc_gpio_cmdfunction cgbc_gpio_getfunction __cgbc_gpio_setfunction cgbc_gpio_setfunction cgbc_gpio_direction_setfunction cgbc_gpio_direction_inputfunction cgbc_gpio_direction_outputfunction cgbc_gpio_get_directionfunction cgbc_gpio_probe
Annotated Snippet
struct cgbc_gpio_data {
struct gpio_chip chip;
struct cgbc_device_data *cgbc;
struct mutex lock;
};
static int cgbc_gpio_cmd(struct cgbc_device_data *cgbc,
u8 cmd0, u8 cmd1, u8 cmd2, u8 *value)
{
u8 cmd[3] = {cmd0, cmd1, cmd2};
return cgbc_command(cgbc, cmd, sizeof(cmd), value, 1, NULL);
}
static int cgbc_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
struct cgbc_gpio_data *gpio = gpiochip_get_data(chip);
struct cgbc_device_data *cgbc = gpio->cgbc;
int ret;
u8 val;
scoped_guard(mutex, &gpio->lock)
ret = cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_GET, (offset > 7) ? 1 : 0, 0, &val);
offset %= 8;
if (ret)
return ret;
return !!(val & BIT(offset));
}
static int __cgbc_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
struct cgbc_gpio_data *gpio = gpiochip_get_data(chip);
struct cgbc_device_data *cgbc = gpio->cgbc;
u8 val;
int ret;
ret = cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_GET, (offset > 7) ? 1 : 0, 0, &val);
if (ret)
return ret;
if (value)
val |= BIT(offset % 8);
else
val &= ~(BIT(offset % 8));
return cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_SET, (offset > 7) ? 1 : 0, val, &val);
}
static int cgbc_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
{
struct cgbc_gpio_data *gpio = gpiochip_get_data(chip);
guard(mutex)(&gpio->lock);
return __cgbc_gpio_set(chip, offset, value);
}
static int cgbc_gpio_direction_set(struct gpio_chip *chip,
unsigned int offset, int direction)
{
struct cgbc_gpio_data *gpio = gpiochip_get_data(chip);
struct cgbc_device_data *cgbc = gpio->cgbc;
int ret;
u8 val;
ret = cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_DIR_GET, (offset > 7) ? 1 : 0, 0, &val);
if (ret)
goto end;
if (direction == GPIO_LINE_DIRECTION_IN)
val &= ~(BIT(offset % 8));
else
val |= BIT(offset % 8);
ret = cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_DIR_SET, (offset > 7) ? 1 : 0, val, &val);
end:
return ret;
}
static int cgbc_gpio_direction_input(struct gpio_chip *chip,
unsigned int offset)
{
struct cgbc_gpio_data *gpio = gpiochip_get_data(chip);
guard(mutex)(&gpio->lock);
Annotation
- Immediate include surface: `linux/gpio/driver.h`, `linux/mfd/cgbc.h`, `linux/module.h`, `linux/mutex.h`, `linux/platform_device.h`.
- Detected declarations: `struct cgbc_gpio_data`, `function cgbc_gpio_cmd`, `function cgbc_gpio_get`, `function __cgbc_gpio_set`, `function cgbc_gpio_set`, `function cgbc_gpio_direction_set`, `function cgbc_gpio_direction_input`, `function cgbc_gpio_direction_output`, `function cgbc_gpio_get_direction`, `function cgbc_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.