drivers/media/cec/platform/cec-gpio/cec-gpio.c
Source file repositories/reference/linux-study-clean/drivers/media/cec/platform/cec-gpio/cec-gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/cec/platform/cec-gpio/cec-gpio.c- Extension
.c- Size
- 6985 bytes
- Lines
- 297
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- 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/delay.hlinux/gpio/consumer.hlinux/interrupt.hlinux/module.hlinux/platform_device.hlinux/seq_file.hmedia/cec-notifier.hmedia/cec-pin.h
Detected Declarations
struct cec_gpiofunction cec_gpio_readfunction cec_gpio_highfunction cec_gpio_lowfunction cec_gpio_5v_irq_handler_threadfunction cec_gpio_5v_irq_handlerfunction cec_gpio_hpd_irq_handler_threadfunction cec_gpio_hpd_irq_handlerfunction cec_gpio_cec_irq_handlerfunction cec_gpio_cec_enable_irqfunction cec_gpio_cec_disable_irqfunction cec_gpio_statusfunction cec_gpio_read_hpdfunction cec_gpio_read_5vfunction cec_gpio_probefunction cec_gpio_remove
Annotated Snippet
struct cec_gpio {
struct cec_adapter *adap;
struct cec_notifier *notifier;
struct device *dev;
struct gpio_desc *cec_gpio;
int cec_irq;
bool cec_is_low;
struct gpio_desc *hpd_gpio;
int hpd_irq;
bool hpd_is_high;
ktime_t hpd_ts;
struct gpio_desc *v5_gpio;
int v5_irq;
bool v5_is_high;
ktime_t v5_ts;
};
static int cec_gpio_read(struct cec_adapter *adap)
{
struct cec_gpio *cec = cec_get_drvdata(adap);
if (cec->cec_is_low)
return 0;
return gpiod_get_value(cec->cec_gpio);
}
static void cec_gpio_high(struct cec_adapter *adap)
{
struct cec_gpio *cec = cec_get_drvdata(adap);
if (!cec->cec_is_low)
return;
cec->cec_is_low = false;
gpiod_set_value(cec->cec_gpio, 1);
}
static void cec_gpio_low(struct cec_adapter *adap)
{
struct cec_gpio *cec = cec_get_drvdata(adap);
if (cec->cec_is_low)
return;
cec->cec_is_low = true;
gpiod_set_value(cec->cec_gpio, 0);
}
static irqreturn_t cec_gpio_5v_irq_handler_thread(int irq, void *priv)
{
struct cec_gpio *cec = priv;
int val = gpiod_get_value_cansleep(cec->v5_gpio);
bool is_high = val > 0;
if (val < 0 || is_high == cec->v5_is_high)
return IRQ_HANDLED;
cec->v5_is_high = is_high;
cec_queue_pin_5v_event(cec->adap, cec->v5_is_high, cec->v5_ts);
return IRQ_HANDLED;
}
static irqreturn_t cec_gpio_5v_irq_handler(int irq, void *priv)
{
struct cec_gpio *cec = priv;
cec->v5_ts = ktime_get();
return IRQ_WAKE_THREAD;
}
static irqreturn_t cec_gpio_hpd_irq_handler_thread(int irq, void *priv)
{
struct cec_gpio *cec = priv;
int val = gpiod_get_value_cansleep(cec->hpd_gpio);
bool is_high = val > 0;
if (val < 0 || is_high == cec->hpd_is_high)
return IRQ_HANDLED;
cec->hpd_is_high = is_high;
cec_queue_pin_hpd_event(cec->adap, cec->hpd_is_high, cec->hpd_ts);
return IRQ_HANDLED;
}
static irqreturn_t cec_gpio_hpd_irq_handler(int irq, void *priv)
{
struct cec_gpio *cec = priv;
cec->hpd_ts = ktime_get();
Annotation
- Immediate include surface: `linux/delay.h`, `linux/gpio/consumer.h`, `linux/interrupt.h`, `linux/module.h`, `linux/platform_device.h`, `linux/seq_file.h`, `media/cec-notifier.h`, `media/cec-pin.h`.
- Detected declarations: `struct cec_gpio`, `function cec_gpio_read`, `function cec_gpio_high`, `function cec_gpio_low`, `function cec_gpio_5v_irq_handler_thread`, `function cec_gpio_5v_irq_handler`, `function cec_gpio_hpd_irq_handler_thread`, `function cec_gpio_hpd_irq_handler`, `function cec_gpio_cec_irq_handler`, `function cec_gpio_cec_enable_irq`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- 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.