drivers/extcon/extcon-adc-jack.c
Source file repositories/reference/linux-study-clean/drivers/extcon/extcon-adc-jack.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/extcon/extcon-adc-jack.c- Extension
.c- Size
- 5558 bytes
- Lines
- 213
- Domain
- Driver Families
- Bucket
- drivers/extcon
- 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/module.hlinux/slab.hlinux/device.hlinux/platform_device.hlinux/err.hlinux/interrupt.hlinux/workqueue.hlinux/iio/consumer.hlinux/extcon/extcon-adc-jack.hlinux/extcon-provider.h
Detected Declarations
struct adc_jack_datafunction adc_jack_handlerfunction adc_jack_irq_threadfunction adc_jack_probefunction adc_jack_removefunction adc_jack_suspendfunction adc_jack_resume
Annotated Snippet
struct adc_jack_data {
struct device *dev;
struct extcon_dev *edev;
const unsigned int **cable_names;
struct adc_jack_cond *adc_conditions;
int num_conditions;
int irq;
unsigned long handling_delay; /* in jiffies */
struct delayed_work handler;
struct iio_channel *chan;
bool wakeup_source;
};
static void adc_jack_handler(struct work_struct *work)
{
struct adc_jack_data *data = container_of(to_delayed_work(work),
struct adc_jack_data,
handler);
struct adc_jack_cond *def;
int ret, adc_val;
int i;
ret = iio_read_channel_raw(data->chan, &adc_val);
if (ret < 0) {
dev_err(data->dev, "read channel() error: %d\n", ret);
return;
}
/* Get state from adc value with adc_conditions */
for (i = 0; i < data->num_conditions; i++) {
def = &data->adc_conditions[i];
if (def->min_adc <= adc_val && def->max_adc >= adc_val) {
extcon_set_state_sync(data->edev, def->id, true);
return;
}
}
/* Set the detached state if adc value is not included in the range */
for (i = 0; i < data->num_conditions; i++) {
def = &data->adc_conditions[i];
extcon_set_state_sync(data->edev, def->id, false);
}
}
static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
{
struct adc_jack_data *data = _data;
queue_delayed_work(system_power_efficient_wq,
&data->handler, data->handling_delay);
return IRQ_HANDLED;
}
static int adc_jack_probe(struct platform_device *pdev)
{
struct adc_jack_data *data;
struct adc_jack_pdata *pdata = dev_get_platdata(&pdev->dev);
int i, err = 0;
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
if (!pdata->cable_names) {
dev_err(&pdev->dev, "error: cable_names not defined.\n");
return -EINVAL;
}
data->dev = &pdev->dev;
data->edev = devm_extcon_dev_allocate(&pdev->dev, pdata->cable_names);
if (IS_ERR(data->edev)) {
dev_err(&pdev->dev, "failed to allocate extcon device\n");
return -ENOMEM;
}
if (!pdata->adc_conditions) {
dev_err(&pdev->dev, "error: adc_conditions not defined.\n");
return -EINVAL;
}
data->adc_conditions = pdata->adc_conditions;
/* Check the length of array and set num_conditions */
for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++);
data->num_conditions = i;
data->chan = devm_iio_channel_get(&pdev->dev, pdata->consumer_channel);
if (IS_ERR(data->chan))
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/device.h`, `linux/platform_device.h`, `linux/err.h`, `linux/interrupt.h`, `linux/workqueue.h`, `linux/iio/consumer.h`.
- Detected declarations: `struct adc_jack_data`, `function adc_jack_handler`, `function adc_jack_irq_thread`, `function adc_jack_probe`, `function adc_jack_remove`, `function adc_jack_suspend`, `function adc_jack_resume`.
- Atlas domain: Driver Families / drivers/extcon.
- 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.