|
Lines 3-8
Link Here
|
| 3 |
* |
3 |
* |
| 4 |
* Analog Jack extcon driver with ADC-based detection capability. |
4 |
* Analog Jack extcon driver with ADC-based detection capability. |
| 5 |
* |
5 |
* |
|
|
6 |
* Copyright (C) 2016 Samsung Electronics |
| 7 |
* Chanwoo Choi <cw00.choi@samsung.com> |
| 8 |
* |
| 6 |
* Copyright (C) 2012 Samsung Electronics |
9 |
* Copyright (C) 2012 Samsung Electronics |
| 7 |
* MyungJoo Ham <myungjoo.ham@samsung.com> |
10 |
* MyungJoo Ham <myungjoo.ham@samsung.com> |
| 8 |
* |
11 |
* |
|
Lines 56-62
static void adc_jack_handler(struct work_struct *work)
Link Here
|
| 56 |
struct adc_jack_data *data = container_of(to_delayed_work(work), |
59 |
struct adc_jack_data *data = container_of(to_delayed_work(work), |
| 57 |
struct adc_jack_data, |
60 |
struct adc_jack_data, |
| 58 |
handler); |
61 |
handler); |
| 59 |
u32 state = 0; |
62 |
struct adc_jack_cond *def; |
| 60 |
int ret, adc_val; |
63 |
int ret, adc_val; |
| 61 |
int i; |
64 |
int i; |
| 62 |
|
65 |
|
|
Lines 68-84
static void adc_jack_handler(struct work_struct *work)
Link Here
|
| 68 |
|
71 |
|
| 69 |
/* Get state from adc value with adc_conditions */ |
72 |
/* Get state from adc value with adc_conditions */ |
| 70 |
for (i = 0; i < data->num_conditions; i++) { |
73 |
for (i = 0; i < data->num_conditions; i++) { |
| 71 |
struct adc_jack_cond *def = &data->adc_conditions[i]; |
74 |
def = &data->adc_conditions[i]; |
| 72 |
if (!def->state) |
|
|
| 73 |
break; |
| 74 |
if (def->min_adc <= adc_val && def->max_adc >= adc_val) { |
75 |
if (def->min_adc <= adc_val && def->max_adc >= adc_val) { |
| 75 |
state = def->state; |
76 |
extcon_set_cable_state_(data->edev, def->id, true); |
| 76 |
break; |
77 |
return; |
| 77 |
} |
78 |
} |
| 78 |
} |
79 |
} |
| 79 |
/* if no def has met, it means state = 0 (no cables attached) */ |
|
|
| 80 |
|
80 |
|
| 81 |
extcon_set_state(data->edev, state); |
81 |
/* Set the detached state if adc value is not included in the range */ |
|
|
82 |
for (i = 0; i < data->num_conditions; i++) { |
| 83 |
def = &data->adc_conditions[i]; |
| 84 |
extcon_set_cable_state_(data->edev, def->id, false); |
| 85 |
} |
| 82 |
} |
86 |
} |
| 83 |
|
87 |
|
| 84 |
static irqreturn_t adc_jack_irq_thread(int irq, void *_data) |
88 |
static irqreturn_t adc_jack_irq_thread(int irq, void *_data) |
|
Lines 111-126
static int adc_jack_probe(struct platform_device *pdev)
Link Here
|
| 111 |
return -ENOMEM; |
115 |
return -ENOMEM; |
| 112 |
} |
116 |
} |
| 113 |
|
117 |
|
| 114 |
if (!pdata->adc_conditions || |
118 |
if (!pdata->adc_conditions) { |
| 115 |
!pdata->adc_conditions[0].state) { |
|
|
| 116 |
dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); |
119 |
dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); |
| 117 |
return -EINVAL; |
120 |
return -EINVAL; |
| 118 |
} |
121 |
} |
| 119 |
data->adc_conditions = pdata->adc_conditions; |
122 |
data->adc_conditions = pdata->adc_conditions; |
| 120 |
|
123 |
|
| 121 |
/* Check the length of array and set num_conditions */ |
124 |
/* Check the length of array and set num_conditions */ |
| 122 |
for (i = 0; data->adc_conditions[i].state; i++) |
125 |
for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++); |
| 123 |
; |
|
|
| 124 |
data->num_conditions = i; |
126 |
data->num_conditions = i; |
| 125 |
|
127 |
|
| 126 |
data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel); |
128 |
data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel); |