Lines Matching +full:adc +full:- +full:chan
1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/extcon/extcon-adc-jack.c
5 * Analog Jack extcon driver with ADC-based detection capability.
13 * Modified for calling to IIO to get adc by <anish.singh@samsung.com>
24 #include <linux/extcon/extcon-adc-jack.h>
25 #include <linux/extcon-provider.h>
28 * struct adc_jack_data - internal data for adc_jack device driver
31 * @adc_conditions: list of adc value conditions.
37 * @chan: iio channel being queried.
51 struct iio_channel *chan; member
64 ret = iio_read_channel_raw(data->chan, &adc_val); in adc_jack_handler()
66 dev_err(data->dev, "read channel() error: %d\n", ret); in adc_jack_handler()
70 /* Get state from adc value with adc_conditions */ in adc_jack_handler()
71 for (i = 0; i < data->num_conditions; i++) { in adc_jack_handler()
72 def = &data->adc_conditions[i]; in adc_jack_handler()
73 if (def->min_adc <= adc_val && def->max_adc >= adc_val) { in adc_jack_handler()
74 extcon_set_state_sync(data->edev, def->id, true); in adc_jack_handler()
79 /* Set the detached state if adc value is not included in the range */ in adc_jack_handler()
80 for (i = 0; i < data->num_conditions; i++) { in adc_jack_handler()
81 def = &data->adc_conditions[i]; in adc_jack_handler()
82 extcon_set_state_sync(data->edev, def->id, false); in adc_jack_handler()
91 &data->handler, data->handling_delay); in adc_jack_irq_thread()
98 struct adc_jack_pdata *pdata = dev_get_platdata(&pdev->dev); in adc_jack_probe()
101 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in adc_jack_probe()
103 return -ENOMEM; in adc_jack_probe()
105 if (!pdata->cable_names) { in adc_jack_probe()
106 dev_err(&pdev->dev, "error: cable_names not defined.\n"); in adc_jack_probe()
107 return -EINVAL; in adc_jack_probe()
110 data->dev = &pdev->dev; in adc_jack_probe()
111 data->edev = devm_extcon_dev_allocate(&pdev->dev, pdata->cable_names); in adc_jack_probe()
112 if (IS_ERR(data->edev)) { in adc_jack_probe()
113 dev_err(&pdev->dev, "failed to allocate extcon device\n"); in adc_jack_probe()
114 return -ENOMEM; in adc_jack_probe()
117 if (!pdata->adc_conditions) { in adc_jack_probe()
118 dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); in adc_jack_probe()
119 return -EINVAL; in adc_jack_probe()
121 data->adc_conditions = pdata->adc_conditions; in adc_jack_probe()
124 for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++); in adc_jack_probe()
125 data->num_conditions = i; in adc_jack_probe()
127 data->chan = devm_iio_channel_get(&pdev->dev, pdata->consumer_channel); in adc_jack_probe()
128 if (IS_ERR(data->chan)) in adc_jack_probe()
129 return PTR_ERR(data->chan); in adc_jack_probe()
131 data->handling_delay = msecs_to_jiffies(pdata->handling_delay_ms); in adc_jack_probe()
132 data->wakeup_source = pdata->wakeup_source; in adc_jack_probe()
134 INIT_DEFERRABLE_WORK(&data->handler, adc_jack_handler); in adc_jack_probe()
138 err = devm_extcon_dev_register(&pdev->dev, data->edev); in adc_jack_probe()
142 data->irq = platform_get_irq(pdev, 0); in adc_jack_probe()
143 if (data->irq < 0) in adc_jack_probe()
144 return -ENODEV; in adc_jack_probe()
146 err = request_any_context_irq(data->irq, adc_jack_irq_thread, in adc_jack_probe()
147 pdata->irq_flags, pdata->name, data); in adc_jack_probe()
150 dev_err(&pdev->dev, "error: irq %d\n", data->irq); in adc_jack_probe()
154 if (data->wakeup_source) in adc_jack_probe()
155 device_init_wakeup(&pdev->dev, 1); in adc_jack_probe()
157 adc_jack_handler(&data->handler.work); in adc_jack_probe()
165 free_irq(data->irq, data); in adc_jack_remove()
166 cancel_work_sync(&data->handler.work); in adc_jack_remove()
176 cancel_delayed_work_sync(&data->handler); in adc_jack_suspend()
177 if (device_may_wakeup(data->dev)) in adc_jack_suspend()
178 enable_irq_wake(data->irq); in adc_jack_suspend()
187 if (device_may_wakeup(data->dev)) in adc_jack_resume()
188 disable_irq_wake(data->irq); in adc_jack_resume()
201 .name = "adc-jack",
209 MODULE_DESCRIPTION("ADC Jack extcon driver");