Skip to content

Commit 810809f

Browse files
perezpriMaureenHelm
authored andcommitted
driver: adc: npcx: enable adding work queue for adc comparator
ADC comparator driver submits notifications into system work queue, this change will make driver to use dedicated work queue instead by using `CONFIG_ADC_CMP_NPCX_WORKQUEUE`. Dedicated work queue and priority are configurable as well. Signed-off-by: Bernardo Perez Priego <[email protected]>
1 parent d018b2b commit 810809f

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

drivers/adc/adc_npcx.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct adc_npcx_threshold_control {
7575
/* Sets the threshold value to which measured data is compared. */
7676
uint16_t thrval;
7777
/*
78-
* Pointer of work queue thread to be notified when threshold assertion
78+
* Pointer of work queue item to be notified when threshold assertion
7979
* occurs.
8080
*/
8181
struct k_work *work;
@@ -98,6 +98,11 @@ struct adc_npcx_threshold_data {
9898
/* This array holds current configuration for each threshold. */
9999
struct adc_npcx_threshold_control
100100
control[DT_INST_PROP(0, threshold_count)];
101+
/*
102+
* Pointer of work queue thread to be notified when threshold assertion
103+
* occurs.
104+
*/
105+
struct k_work_q *work_q;
101106
};
102107

103108
/* Driver data */
@@ -224,9 +229,11 @@ static void adc_npcx_isr(const struct device *dev)
224229
/* Clear threshold status */
225230
thrcts |= BIT(i);
226231
inst->THRCTS = thrcts;
227-
/* Notify work thread */
228232
if (t_data->control[i].work) {
229-
k_work_submit(t_data->control[i].work);
233+
/* Notify work thread */
234+
k_work_submit_to_queue(t_data->work_q ?
235+
t_data->work_q : &k_sys_work_q,
236+
t_data->control[i].work);
230237
}
231238
}
232239
}
@@ -727,6 +734,32 @@ static struct adc_npcx_data adc_npcx_data_0 = {
727734
ADC_CONTEXT_INIT_SYNC(adc_npcx_data_0, ctx),
728735
};
729736

737+
#if defined(CONFIG_ADC_CMP_NPCX_WORKQUEUE)
738+
struct k_work_q adc_npcx_work_q;
739+
740+
static K_KERNEL_STACK_DEFINE(adc_npcx_work_q_stack,
741+
CONFIG_ADC_CMP_NPCX_WORKQUEUE_STACK_SIZE);
742+
743+
static int adc_npcx_init_cmp_work_q(const struct device *dev)
744+
{
745+
ARG_UNUSED(dev);
746+
struct k_work_queue_config cfg = {
747+
.name = "adc_cmp_work",
748+
.no_yield = false,
749+
};
750+
751+
k_work_queue_start(&adc_npcx_work_q,
752+
adc_npcx_work_q_stack,
753+
K_KERNEL_STACK_SIZEOF(adc_npcx_work_q_stack),
754+
CONFIG_ADC_CMP_NPCX_WORKQUEUE_PRIORITY, &cfg);
755+
756+
threshold_data_0.work_q = &adc_npcx_work_q;
757+
return 0;
758+
}
759+
760+
SYS_INIT(adc_npcx_init_cmp_work_q, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY);
761+
#endif
762+
730763
DEVICE_DT_INST_DEFINE(0,
731764
adc_npcx_init, NULL,
732765
&adc_npcx_data_0, &adc_npcx_cfg_0,

drivers/sensor/nuvoton_adc_cmp_npcx/Kconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,32 @@ config ADC_CMP_NPCX
1313
This option enables threshold interruption using sensor
1414
trigger API.
1515

16+
if ADC_CMP_NPCX
17+
18+
config ADC_CMP_NPCX_WORKQUEUE
19+
bool "NPCX ADC threshold detection uses internal work queue"
20+
help
21+
Threshold detection ISR utilizes system work queue for calling
22+
trigger handlers; set this option to use dedicated work queue instead.
23+
24+
if ADC_CMP_NPCX_WORKQUEUE
25+
26+
config ADC_CMP_NPCX_WORKQUEUE_PRIORITY
27+
int "Nuvoton NPCX ADC trheshold detection work queue priority"
28+
default SYSTEM_WORKQUEUE_PRIORITY
29+
help
30+
This option sets internal ADC NPCX threshold detection workqueue
31+
priority.
32+
33+
config ADC_CMP_NPCX_WORKQUEUE_STACK_SIZE
34+
int "Nuvoton NPCX ADC trheshold detection work queue stack size"
35+
default 768
36+
help
37+
This option sets internal ADC NPCX threshold detection workqueue
38+
stack size.
39+
40+
endif # ADC_CMP_NPCX_WORKQUEUE
41+
42+
endif # ADC_CMP_NPCX
43+
1644
endif # ADC_NPCX

drivers/sensor/nuvoton_adc_cmp_npcx/adc_cmp_npcx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static const struct sensor_driver_api adc_cmp_npcx_api = {
264264
}; \
265265
DEVICE_DT_INST_DEFINE(inst, adc_cmp_npcx_init, NULL, \
266266
&adc_cmp_npcx_data_##inst, \
267-
&adc_cmp_npcx_config_##inst, PRE_KERNEL_2, \
267+
&adc_cmp_npcx_config_##inst, POST_KERNEL, \
268268
CONFIG_SENSOR_INIT_PRIORITY, \
269269
&adc_cmp_npcx_api);
270270
DT_INST_FOREACH_STATUS_OKAY(NPCX_ADC_CMP_INIT)

0 commit comments

Comments
 (0)