Skip to content

Commit

Permalink
drivers: adc: add adc support in npcm4 series
Browse files Browse the repository at this point in the history
NPCM4 includes a 10-bit resolution Analog-to-Digital Converter (ADC). Up
to 14 voltage inputs can be measured and an internal voltage reference
(VREF), 2.048V (typical) is used for measurement. Each input channel is
assigned a separate result register, which is updated at the end of the
conversion.

The CL also includes:
— Add npcm adc device tree declarations.
— Zephyr adc api implementation.

Signed-off-by: Tyrone Ting <[email protected]>
  • Loading branch information
warp5tw committed Jun 18, 2024
1 parent 0db0527 commit ee863c8
Show file tree
Hide file tree
Showing 9 changed files with 565 additions and 0 deletions.
32 changes: 32 additions & 0 deletions boards/nuvoton/npcm400f_evb/npcm400f_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
aliases {
watchdog0 = &twd0;
};

zephyr,user {
/* adjust channel number according to enum adc_channel_en in adc_npcm.c */
/* Because VIN16, THR16, TD2P is the same pin, it must only select one type.
* Because VIN15, THR15, TD0P is the same pin, it must only select one type.
* Because VIN14, THR14, TD1P is the same pin, it must only select one type.
* Because VIN1, THR1, TD3P is the same pin, it must only select one type.
* Because VIN2, THR2, TD4P is the same pin, it must only select one type.
* Exsample : if you select channel 6(VIN16),
* and you can't select channel 7(THR16) and channel 19(TD2P).
*/
io-channels = <&adc0 17>, <&adc0 18>;
};
};

&uart0 {
Expand All @@ -37,3 +50,22 @@
pinctrl-0 = <&cr_uart2_sin_gp30 &cr_uart2_sout_gp31>;
pinctrl-names = "default";
};

&adc0 {
status = "okay";
/* Pin D7 is shared by thermal signal VIN16, THR16, TD2P.
* Pin C7 is shared by thermal signal VIN15, THR15, TD1P.
* Pin A6 is shared by thermal signal VIN14, THR14, TD0P.
* Pin B6 is shared by thermal signal VIN1, THR1, TD3P.
* Pin C6 is shared by thermal signal VIN2, THR2, TD4P.
*/
pinctrl-0 = <&adc_vin7_gp86 /* VIN7 - C8 */
&adc_vin5_gp87 /* VIN5 - F7 */
&adc_vin16_gp91 /* VIN16/THR16/TD2P - D7 */
&adc_vin15_gp91 /* VIN15/THR15/TD1P - C7 */
&adc_vin14_gp92 /* VIN14/THR14/TD0P - A6 */
&adc_vin1_gp93 /* VIN1/THR1/TD3P - B6 */
&adc_vin2_gp94 /* VIN2/THR2/TD4P - C6 */
&adc_vin3_gp95>; /* VIN3 - D6 */
pinctrl-names = "default";
};
4 changes: 4 additions & 0 deletions boards/nuvoton/npcm400f_evb/npcm400f_evb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ CONFIG_NPCM_MIWU=y
# Watchdog Driver
CONFIG_WATCHDOG=y
CONFIG_WDT_NPCM=y

# ADC Driver
CONFIG_ADC=y
CONFIG_ADC_NPCM=y
1 change: 1 addition & 0 deletions drivers/adc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ zephyr_library_sources_ifdef(CONFIG_ADC_LTC2451 adc_ltc2451.c)
zephyr_library_sources_ifdef(CONFIG_ADC_NUMAKER adc_numaker.c)
zephyr_library_sources_ifdef(CONFIG_ADC_ENE_KB1200 adc_ene_kb1200.c)
zephyr_library_sources_ifdef(CONFIG_ADC_MCUX_GAU adc_mcux_gau_adc.c)
zephyr_library_sources_ifdef(CONFIG_ADC_NPCM adc_npcm.c)
2 changes: 2 additions & 0 deletions drivers/adc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ source "drivers/adc/Kconfig.numaker"

source "drivers/adc/Kconfig.ene"

source "drivers/adc/Kconfig.npcm"

endif # ADC
13 changes: 13 additions & 0 deletions drivers/adc/Kconfig.npcm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# NPCM ADC driver configuration options

# Copyright (c) 2024 Nuvoton Technology Corporation.
# SPDX-License-Identifier: Apache-2.0

config ADC_NPCM
bool "Nuvoton NPCM ADC driver"
default y
depends on DT_HAS_NUVOTON_NPCM_ADC_ENABLED
help
This option enables the ADC driver for NPCM family of
processors.
Say y if you wish to use ADC channels on NPCM MCU.
Loading

0 comments on commit ee863c8

Please sign in to comment.