diff options
-rw-r--r-- | drivers/extcon/extcon-adc-jack.c | 26 | ||||
-rw-r--r-- | include/linux/extcon/extcon-adc-jack.h | 4 |
2 files changed, 16 insertions, 14 deletions
diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index 48dec94b487b..e62e6cd7e00a 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c | |||
@@ -3,6 +3,9 @@ | |||
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 | * |
@@ -58,7 +61,7 @@ static void adc_jack_handler(struct work_struct *work) | |||
58 | struct adc_jack_data *data = container_of(to_delayed_work(work), | 61 | struct adc_jack_data *data = container_of(to_delayed_work(work), |
59 | struct adc_jack_data, | 62 | struct adc_jack_data, |
60 | handler); | 63 | handler); |
61 | u32 state = 0; | 64 | struct adc_jack_cond *def; |
62 | int ret, adc_val; | 65 | int ret, adc_val; |
63 | int i; | 66 | int i; |
64 | 67 | ||
@@ -70,17 +73,18 @@ static void adc_jack_handler(struct work_struct *work) | |||
70 | 73 | ||
71 | /* Get state from adc value with adc_conditions */ | 74 | /* Get state from adc value with adc_conditions */ |
72 | for (i = 0; i < data->num_conditions; i++) { | 75 | for (i = 0; i < data->num_conditions; i++) { |
73 | struct adc_jack_cond *def = &data->adc_conditions[i]; | 76 | def = &data->adc_conditions[i]; |
74 | if (!def->state) | ||
75 | break; | ||
76 | if (def->min_adc <= adc_val && def->max_adc >= adc_val) { | 77 | if (def->min_adc <= adc_val && def->max_adc >= adc_val) { |
77 | state = def->state; | 78 | extcon_set_cable_state_(data->edev, def->id, true); |
78 | break; | 79 | return; |
79 | } | 80 | } |
80 | } | 81 | } |
81 | /* if no def has met, it means state = 0 (no cables attached) */ | ||
82 | 82 | ||
83 | extcon_set_state(data->edev, state); | 83 | /* Set the detached state if adc value is not included in the range */ |
84 | for (i = 0; i < data->num_conditions; i++) { | ||
85 | def = &data->adc_conditions[i]; | ||
86 | extcon_set_cable_state_(data->edev, def->id, false); | ||
87 | } | ||
84 | } | 88 | } |
85 | 89 | ||
86 | static irqreturn_t adc_jack_irq_thread(int irq, void *_data) | 90 | static irqreturn_t adc_jack_irq_thread(int irq, void *_data) |
@@ -114,16 +118,14 @@ static int adc_jack_probe(struct platform_device *pdev) | |||
114 | return -ENOMEM; | 118 | return -ENOMEM; |
115 | } | 119 | } |
116 | 120 | ||
117 | if (!pdata->adc_conditions || | 121 | if (!pdata->adc_conditions) { |
118 | !pdata->adc_conditions[0].state) { | ||
119 | dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); | 122 | dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); |
120 | return -EINVAL; | 123 | return -EINVAL; |
121 | } | 124 | } |
122 | data->adc_conditions = pdata->adc_conditions; | 125 | data->adc_conditions = pdata->adc_conditions; |
123 | 126 | ||
124 | /* Check the length of array and set num_conditions */ | 127 | /* Check the length of array and set num_conditions */ |
125 | for (i = 0; data->adc_conditions[i].state; i++) | 128 | for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++); |
126 | ; | ||
127 | data->num_conditions = i; | 129 | data->num_conditions = i; |
128 | 130 | ||
129 | data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel); | 131 | data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel); |
diff --git a/include/linux/extcon/extcon-adc-jack.h b/include/linux/extcon/extcon-adc-jack.h index ac85f2061351..a0e03b13b449 100644 --- a/include/linux/extcon/extcon-adc-jack.h +++ b/include/linux/extcon/extcon-adc-jack.h | |||
@@ -20,8 +20,8 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * struct adc_jack_cond - condition to use an extcon state | 22 | * struct adc_jack_cond - condition to use an extcon state |
23 | * @state: the corresponding extcon state (if 0, this struct | ||
24 | * denotes the last adc_jack_cond element among the array) | 23 | * denotes the last adc_jack_cond element among the array) |
24 | * @id: the unique id of each external connector | ||
25 | * @min_adc: min adc value for this condition | 25 | * @min_adc: min adc value for this condition |
26 | * @max_adc: max adc value for this condition | 26 | * @max_adc: max adc value for this condition |
27 | * | 27 | * |
@@ -33,7 +33,7 @@ | |||
33 | * because when no adc_jack_cond is met, state = 0 is automatically chosen. | 33 | * because when no adc_jack_cond is met, state = 0 is automatically chosen. |
34 | */ | 34 | */ |
35 | struct adc_jack_cond { | 35 | struct adc_jack_cond { |
36 | u32 state; /* extcon state value. 0 if invalid */ | 36 | unsigned int id; |
37 | u32 min_adc; | 37 | u32 min_adc; |
38 | u32 max_adc; | 38 | u32 max_adc; |
39 | }; | 39 | }; |