Skip to content

Commit a7da72e

Browse files
committed
extcon: adc-jack: Remove the usage of extcon_set_state()
This patch removes the usage of extcon_set_state() because it uses the bit masking to change the state of external connectors. The extcon framework should handle the state by extcon_set/get_cable_state_() with extcon id. Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
1 parent 5475e63 commit a7da72e

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

‎drivers/extcon/extcon-adc-jack.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
*
44
* Analog Jack extcon driver with ADC-based detection capability.
55
*
6+
* Copyright (C) 2016 Samsung Electronics
7+
* Chanwoo Choi <cw00.choi@samsung.com>
8+
*
69
* Copyright (C) 2012 Samsung Electronics
710
* MyungJoo Ham <myungjoo.ham@samsung.com>
811
*
@@ -58,7 +61,7 @@ static void adc_jack_handler(struct work_struct *work)
5861
struct adc_jack_data *data = container_of(to_delayed_work(work),
5962
struct adc_jack_data,
6063
handler);
61-
u32 state = 0;
64+
struct adc_jack_cond *def;
6265
int ret, adc_val;
6366
int i;
6467

@@ -70,17 +73,18 @@ static void adc_jack_handler(struct work_struct *work)
7073

7174
/* Get state from adc value with adc_conditions */
7275
for (i = 0; i < data->num_conditions; i++) {
73-
struct adc_jack_cond *def = &data->adc_conditions[i];
74-
if (!def->state)
75-
break;
76+
def = &data->adc_conditions[i];
7677
if (def->min_adc <= adc_val && def->max_adc >= adc_val) {
77-
state = def->state;
78-
break;
78+
extcon_set_cable_state_(data->edev, def->id, true);
79+
return;
7980
}
8081
}
81-
/* if no def has met, it means state = 0 (no cables attached) */
8282

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+
}
8488
}
8589

8690
static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
@@ -114,16 +118,14 @@ static int adc_jack_probe(struct platform_device *pdev)
114118
return -ENOMEM;
115119
}
116120

117-
if (!pdata->adc_conditions ||
118-
!pdata->adc_conditions[0].state) {
121+
if (!pdata->adc_conditions) {
119122
dev_err(&pdev->dev, "error: adc_conditions not defined.\n");
120123
return -EINVAL;
121124
}
122125
data->adc_conditions = pdata->adc_conditions;
123126

124127
/* Check the length of array and set num_conditions */
125-
for (i = 0; data->adc_conditions[i].state; i++)
126-
;
128+
for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++);
127129
data->num_conditions = i;
128130

129131
data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);

‎include/linux/extcon/extcon-adc-jack.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
/**
2222
* struct adc_jack_cond - condition to use an extcon state
23-
* @state: the corresponding extcon state (if 0, this struct
2423
* denotes the last adc_jack_cond element among the array)
24+
* @id: the unique id of each external connector
2525
* @min_adc: min adc value for this condition
2626
* @max_adc: max adc value for this condition
2727
*
@@ -33,7 +33,7 @@
3333
* because when no adc_jack_cond is met, state = 0 is automatically chosen.
3434
*/
3535
struct adc_jack_cond {
36-
u32 state; /* extcon state value. 0 if invalid */
36+
unsigned int id;
3737
u32 min_adc;
3838
u32 max_adc;
3939
};

0 commit comments

Comments
 (0)