diff options
Diffstat (limited to 'drivers/extcon/extcon-adc-jack.c')
-rw-r--r-- | drivers/extcon/extcon-adc-jack.c | 26 |
1 files changed, 14 insertions, 12 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); |