1# Copyright (c) 2024-2025 Gerson Fernando Budke <nandojve@gmail.com>
2# SPDX-License-Identifier: Apache-2.0
3
4if SOC_SERIES_SAMD20 || SOC_SERIES_SAMD21 || SOC_SERIES_SAMR21
5
6config SOC_ATMEL_SAMD_NVM_WAIT_STATES
7	int "NVM wait states"
8	default 1
9	help
10	  Wait states to set for NVM. Consult the datasheet as these are highly
11	  dependent on the device operationg conditions.
12
13config SOC_ATMEL_SAMD_OSC32K
14	bool "Internal 32.768 kHz RC oscillator"
15	help
16	  Enable the internal 32.768 kHz RC oscillator at startup.
17	  This can then be selected as the main clock reference for the SOC.
18
19config SOC_ATMEL_SAMD_OSC8M
20	bool "Internal 8 MHz RC oscillator"
21	help
22	  Enable the internal 8 MHz RC oscillator at startup.
23	  This can then be selected as the main clock reference for the SOC.
24
25config SOC_ATMEL_SAMD_XOSC32K
26	bool "External 32.768 kHz clock source"
27	help
28	  Enable the external 32.768 kHz clock source at startup.
29	  This can then be selected as the main clock reference for the SOC.
30
31config SOC_ATMEL_SAMD_XOSC32K_CRYSTAL
32	bool "External 32.768 kHz clock is a crystal oscillator"
33	depends on SOC_ATMEL_SAMD_XOSC32K
34	default y
35	help
36	  Enable the crystal oscillator (if disabled, expect a clock signal on
37	  XIN32).
38
39DT_ATMEL_RTC := $(dt_nodelabel_path,rtc)
40DT_ATMEL_RTC_COUNTER_CLOCK_MODE := $(dt_node_str_prop_equals,$(DT_ATMEL_RTC),counter-mode,clock)
41
42config SOC_ATMEL_SAMD_XOSC32K_PRESCALER
43	int "XOSC32 Generic Clock Prescaler"
44	range 1 512
45	default 32 if "$(DT_ATMEL_RTC_COUNTER_CLOCK_MODE)"
46	default 1
47	depends on SOC_ATMEL_SAMD_XOSC32K
48	help
49	  Configure the prescaler for the generic clock output
50	  connected on the xosc32. When using RTC in calendar mode
51	  the GCLK should be divided by 32 to RTC receive the
52	  1024 Hz reference clock.
53
54config SOC_ATMEL_SAMD_XOSC
55	bool "External 0.4..32 MHz clock source"
56	help
57	  Enable the external 0.4..32 MHz clock source at startup.
58	  This can then be selected as the main clock reference for the SOC.
59
60config SOC_ATMEL_SAMD_XOSC_CRYSTAL
61	bool "External 0.4..32 MHz clock is a crystal oscillator"
62	depends on SOC_ATMEL_SAMD_XOSC
63	default y
64	help
65	  Enable the crystal oscillator (if disabled, expect a clock signal on
66	  XIN).
67
68config SOC_ATMEL_SAMD_XOSC_FREQ_HZ
69	int "External 0.4..32 MHz clock oscillator frequency"
70	range 400000 32000000
71	default 8000000
72	depends on SOC_ATMEL_SAMD_XOSC
73	help
74	  External 0.4..32 MHz clock oscillator reference frequency.
75
76choice
77	prompt "Main clock reference"
78	default SOC_ATMEL_SAMD_DEFAULT_AS_MAIN
79	help
80	  Selects the clock that will be used for the DFLL48M's reference.
81	  Main clocks, such as the CPU and AHB clocks will be derived from
82	  DFLL48M.
83
84config SOC_ATMEL_SAMD_DEFAULT_AS_MAIN
85	bool "DEFAULT"
86	help
87	  This choice will leave all clocks to their current state.
88	  This can be the default reset state or a state set by a bootloader.
89
90config SOC_ATMEL_SAMD_OSC32K_AS_MAIN
91	bool "OSC32K"
92	depends on SOC_ATMEL_SAMD_OSC32K
93
94config SOC_ATMEL_SAMD_XOSC32K_AS_MAIN
95	bool "XOSC32K"
96	depends on SOC_ATMEL_SAMD_XOSC32K
97
98config SOC_ATMEL_SAMD_OSC8M_AS_MAIN
99	bool "OSC8M"
100	depends on SOC_ATMEL_SAMD_OSC8M
101
102config SOC_ATMEL_SAMD_XOSC_AS_MAIN
103	bool "XOSC"
104	depends on SOC_ATMEL_SAMD_XOSC
105
106endchoice
107
108endif # SOC_SERIES_SAMD20 || SOC_SERIES_SAMD21 || SOC_SERIES_SAMR21
109