1/*
2 * Copyright 2023-2024 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/dts-v1/;
8#include <arm/nxp/nxp_s32k344_m7.dtsi>
9#include <dt-bindings/gpio/gpio.h>
10#include <zephyr/dt-bindings/input/input-event-codes.h>
11#include <freq.h>
12#include <dt-bindings/pwm/pwm.h>
13#include "mr_canhubk3-pinctrl.dtsi"
14#include <zephyr/dt-bindings/sensor/qdec_nxp_s32.h>
15
16/ {
17	model = "NXP MR-CANHUBK3";
18	compatible = "nxp,mr_canhubk3";
19
20	chosen {
21		zephyr,sram = &sram0_1;
22		zephyr,flash = &flash0;
23		zephyr,itcm = &itcm;
24		zephyr,dtcm = &dtcm;
25		zephyr,code-partition = &code_partition;
26		zephyr,console = &lpuart2;
27		zephyr,shell-uart = &lpuart2;
28		zephyr,flash-controller = &mx25l6433f;
29		zephyr,canbus = &flexcan0;
30		zephyr,display = &ssd1306;
31	};
32
33	aliases {
34		dma0 = &edma0;
35		led0 = &user_led1_red;
36		led1 = &user_led1_green;
37		led2 = &user_led1_blue;
38		sw0 = &user_button_1;
39		sw1 = &user_button_2;
40		watchdog0 = &swt0;
41		/* For pwm test suites */
42		pwm-0 = &emios0_pwm;
43		pwm-1 = &flexio0_pwm;
44		red-pwm-led = &user_led1_red_pwm;
45		green-pwm-led = &user_led1_green_pwm;
46		blue-pwm-led = &user_led1_blue_pwm;
47		pwm-led0 = &user_led1_blue_pwm;
48		qdec0 = &qdec0;
49	};
50
51	leds {
52		compatible = "gpio-leds";
53		user_led1_green: user_led1_green {
54			gpios = <&gpioa_h 11 GPIO_ACTIVE_LOW>;
55			label = "User RGB LED1 GREEN";
56		};
57		user_led1_blue: user_led1_blue {
58			gpios = <&gpioe_l 12 GPIO_ACTIVE_LOW>;
59			label = "User RGB LED1 BLUE";
60		};
61		user_led1_red: user_led1_red {
62			gpios = <&gpioe_l 14 GPIO_ACTIVE_LOW>;
63			label = "User RGB LED1 RED";
64		};
65		can_led0: can_led0 {
66			gpios = <&gpioc_h 2 GPIO_ACTIVE_LOW>;
67			label = "CAN LED0";
68		};
69		can_led1: can_led1 {
70			gpios = <&gpioe_l 5 GPIO_ACTIVE_LOW>;
71			label = "CAN LED1";
72		};
73		can_led2: can_led2 {
74			gpios = <&gpiod_h 4 GPIO_ACTIVE_LOW>;
75			label = "CAN LED2";
76		};
77		can_led3: can_led3 {
78			gpios = <&gpiob_h 8 GPIO_ACTIVE_LOW>;
79			label = "CAN LED3";
80		};
81		can_led4: can_led4 {
82			gpios = <&gpiob_h 10 GPIO_ACTIVE_LOW>;
83			label = "CAN LED4";
84		};
85		can_led5: can_led5 {
86			gpios = <&gpiod_h 15 GPIO_ACTIVE_LOW>;
87			label = "CAN LED5";
88		};
89	};
90
91	/* gpio-leds and pwm-leds are the same RGB LED and cannot be used at the same time. */
92	pwmleds {
93		compatible = "pwm-leds";
94
95		user_led1_blue_pwm: user_led1_blue {
96			pwms = <&emios1_pwm 5 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
97		};
98
99		user_led1_green_pwm: user_led1_green {
100			pwms = <&emios1_pwm 10 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
101		};
102
103		user_led1_red_pwm: user_led1_red {
104			pwms = <&emios0_pwm 19 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
105		};
106	};
107
108	qdec0: qdec0 {
109		compatible = "nxp,qdec-s32";
110		pinctrl-0 = <&qdec_s32>;
111		pinctrl-names = "default";
112		micro-ticks-per-rev = <685440000>;
113		status = "okay";
114		trgmux = <&trgmux>;
115		trgmux-io-config =
116		<0 TRGMUX_IP_OUTPUT_EMIOS0_CH5_9_IPP_IND_CH6 TRGMUX_IP_INPUT_LCU1_LC0_OUT_I2>,
117		<1 TRGMUX_IP_OUTPUT_EMIOS0_CH5_9_IPP_IND_CH7 TRGMUX_IP_INPUT_LCU1_LC0_OUT_I3>,
118		<2 TRGMUX_IP_OUTPUT_LCU1_0_INP_I0            TRGMUX_IP_INPUT_SIUL2_IN2>,
119		<3 TRGMUX_IP_OUTPUT_LCU1_0_INP_I1            TRGMUX_IP_INPUT_SIUL2_IN3>;
120		lcu = <&lcu1>;
121		lcu-input-idx =
122		<LCU_IP_IN_0 LCU_IP_IN_1
123		 LCU_IP_IN_2 LCU_IP_IN_3>;
124		lcu-mux-sel =
125		<LCU_IP_MUX_SEL_LU_IN_0 LCU_IP_MUX_SEL_LU_IN_1
126		 LCU_IP_MUX_SEL_LU_OUT_0 LCU_IP_MUX_SEL_LU_OUT_1>;
127		lcu-output-filter-config =
128			/* LCU Out HW ID, Rise Filter, Fall Filter */
129			<0 5 5>, /* LCU O0 */
130			<1 5 5>, /* LCU O1 */
131			<2 2 2>, /* LCU O2 */
132			<3 2 2>; /* LCU O3 */
133		emios = <&emios0>;
134		/*
135		 * eMios channel numbers for qdec should be beyond the channel numbers
136		 * used by the emios pwm
137		 */
138		emios-channels = <6 7>;
139	};
140
141	gpio_keys {
142		compatible = "gpio-keys";
143		user_button_1: button_0 {
144			label = "User SW1";
145			gpios = <&gpiod_l 15 GPIO_ACTIVE_HIGH>;
146			zephyr,code = <INPUT_KEY_0>;
147		};
148		user_button_2: button_1 {
149			label = "User SW2";
150			gpios = <&gpioa_h 9 GPIO_ACTIVE_HIGH>;
151			zephyr,code = <INPUT_KEY_1>;
152		};
153	};
154
155	can_phy0: can-phy0 {
156		compatible = "nxp,tja1443", "can-transceiver-gpio";
157		enable-gpios = <&gpioc_h 8 GPIO_ACTIVE_HIGH>;
158		standby-gpios = <&gpioc_h 5 GPIO_ACTIVE_LOW>;
159		max-bitrate = <5000000>;
160		#phy-cells = <0>;
161	};
162
163	can_phy1: can-phy1 {
164		compatible = "nxp,tja1443", "can-transceiver-gpio";
165		enable-gpios = <&gpiod_l 2 GPIO_ACTIVE_HIGH>;
166		standby-gpios = <&gpiod_h 7 GPIO_ACTIVE_LOW>;
167		max-bitrate = <5000000>;
168		#phy-cells = <0>;
169	};
170
171	can_phy2: can-phy2 {
172		compatible = "nxp,tja1463", "can-transceiver-gpio";
173		enable-gpios = <&gpiod_l 4 GPIO_ACTIVE_HIGH>;
174		standby-gpios = <&gpiod_h 6 GPIO_ACTIVE_LOW>;
175		max-bitrate = <8000000>;
176		#phy-cells = <0>;
177	};
178
179	can_phy3: can-phy3 {
180		compatible = "nxp,tja1463", "can-transceiver-gpio";
181		enable-gpios = <&gpiob_l 0 GPIO_ACTIVE_HIGH>;
182		standby-gpios = <&gpiob_l 1 GPIO_ACTIVE_LOW>;
183		max-bitrate = <8000000>;
184		#phy-cells = <0>;
185	};
186
187	can_phy4: can-phy4 {
188		compatible = "nxp,tja1153", "can-transceiver-gpio";
189		enable-gpios = <&gpioc_h 10 GPIO_ACTIVE_HIGH>;
190		standby-gpios = <&gpioc_h 9 GPIO_ACTIVE_LOW>;
191		max-bitrate = <2000000>;
192		#phy-cells = <0>;
193	};
194
195	can_phy5: can-phy5 {
196		compatible = "nxp,tja1153", "can-transceiver-gpio";
197		enable-gpios = <&gpioe_h 1 GPIO_ACTIVE_HIGH>;
198		standby-gpios = <&gpiod_h 14 GPIO_ACTIVE_LOW>;
199		max-bitrate = <2000000>;
200		#phy-cells = <0>;
201	};
202};
203
204&pmc {
205	lm-reg;
206};
207
208&flash0 {
209	partitions {
210		compatible = "fixed-partitions";
211		#address-cells = <1>;
212		#size-cells = <1>;
213
214		ivt_header: partition@0 {
215			label = "ivt-header";
216			reg = <0x00000000 0x100>;
217		};
218
219		code_partition: partition@100 {
220			label = "code-partition";
221			reg = <0x00000100 (DT_SIZE_K(4048) - 0x100)>;
222		};
223	};
224};
225
226&gpioa_h {
227	status = "okay";
228};
229
230&gpioe_l {
231	status = "okay";
232};
233
234/* Enable gpio to control the CAN transceivers and LEDs */
235
236&gpiob_h {
237	status = "okay";
238};
239
240&gpioc_h {
241	status = "okay";
242};
243
244&gpiod_l {
245	status = "okay";
246};
247
248&gpiod_h {
249	status = "okay";
250};
251
252&gpiob_l {
253	status = "okay";
254};
255
256&gpioe_h {
257	status = "okay";
258};
259
260&eirq0 {
261	pinctrl-0 = <&eirq0_default>;
262	pinctrl-names = "default";
263	status = "okay";
264};
265
266&lpuart0 {
267	pinctrl-0 = <&lpuart0_default>;
268	pinctrl-names = "default";
269	dmas = <&edma0 0 37>, <&edma0 1 38>;
270	dma-names = "tx", "rx";
271};
272
273&lpuart1 {
274	pinctrl-0 = <&lpuart1_default>;
275	pinctrl-names = "default";
276	dmas = <&edma0 2 39>, <&edma0 3 40>;
277	dma-names = "tx", "rx";
278};
279
280&lpuart2 {
281	pinctrl-0 = <&lpuart2_default>;
282	pinctrl-names = "default";
283	current-speed = <115200>;
284	dmas = <&edma0 16 38>, <&edma0 17 39>;
285	dma-names = "tx", "rx";
286	status = "okay";
287};
288
289&lpuart9 {
290	pinctrl-0 = <&lpuart9_default>;
291	pinctrl-names = "default";
292	/*
293	 * LPUART 1 and 9 share the same DMA source for TX
294	 * and RX, using UART async API for both instances
295	 * should be careful.
296	 */
297	dmas = <&edma0 4 39>, <&edma0 5 40>;
298	dma-names = "tx", "rx";
299};
300
301&lpuart10 {
302	pinctrl-0 = <&lpuart10_default>;
303	pinctrl-names = "default";
304	/*
305	 * LPUART 2 and 10 share the same DMA source for TX
306	 * and RX, using UART async API for both instances
307	 * should be careful.
308	 */
309	dmas = <&edma0 18 38>, <&edma0 19 39>;
310	dma-names = "tx", "rx";
311};
312
313&lpuart13 {
314	pinctrl-0 = <&lpuart13_default>;
315	pinctrl-names = "default";
316	dmas = <&edma0 20 44>, <&edma0 21 45>;
317	dma-names = "tx", "rx";
318};
319
320&lpuart14 {
321	pinctrl-0 = <&lpuart14_default>;
322	pinctrl-names = "default";
323	dmas = <&edma0 22 46>, <&edma0 23 47>;
324	dma-names = "tx", "rx";
325};
326
327&qspi0 {
328	pinctrl-0 = <&qspi0_default>;
329	pinctrl-names = "default";
330	data-rate = "SDR";
331	a-rx-clock-source = "LOOPBACK";
332	a-dll-mode = "BYPASSED";
333	ahb-buffers-masters = <0 1 2 3>;
334	ahb-buffers-sizes = <0 0 0 256>;
335	ahb-buffers-all-masters;
336	status = "okay";
337
338	mx25l6433f: mx25l6433f@0 {
339		compatible = "nxp,s32-qspi-nor";
340		reg = <0>;
341		size = <DT_SIZE_M(64)>;
342		jedec-id = [c2 20 17];
343		quad-enable-requirements = "S1B6";
344		readoc = "1-4-4";
345		writeoc = "1-4-4";
346		has-32k-erase;
347		max-program-buffer-size = <256>;
348		write-block-size = <1>;
349		status = "okay";
350
351		partitions {
352			compatible = "fixed-partitions";
353			#address-cells = <1>;
354			#size-cells = <1>;
355
356			storage_partition: partition@0 {
357				label = "storage";
358				reg = <0x0 0x100000>;
359			};
360		};
361	};
362};
363
364&flexcan0 {
365	pinctrl-0 = <&flexcan0_default>;
366	pinctrl-names = "default";
367	phys = <&can_phy0>;
368	status = "okay";
369};
370
371&flexcan1 {
372	pinctrl-0 = <&flexcan1_default>;
373	pinctrl-names = "default";
374	phys = <&can_phy1>;
375};
376
377&flexcan2 {
378	pinctrl-0 = <&flexcan2_default>;
379	pinctrl-names = "default";
380	phys = <&can_phy2>;
381};
382
383&flexcan3 {
384	pinctrl-0 = <&flexcan3_default>;
385	pinctrl-names = "default";
386	phys = <&can_phy3>;
387};
388
389&flexcan4 {
390	pinctrl-0 = <&flexcan4_default>;
391	pinctrl-names = "default";
392	phys = <&can_phy4>;
393};
394
395&flexcan5 {
396	pinctrl-0 = <&flexcan5_default>;
397	pinctrl-names = "default";
398	phys = <&can_phy5>;
399};
400
401&lpi2c0 {
402	pinctrl-0 = <&lpi2c0_default>;
403	pinctrl-names = "default";
404	clock-frequency = <I2C_BITRATE_STANDARD>;
405	status = "okay";
406
407	ssd1306: ssd1306@3c {
408		compatible = "solomon,ssd1306fb";
409		reg = <0x3c>;
410		width = <128>;
411		height = <32>;
412		segment-offset = <0>;
413		page-offset = <0>;
414		display-offset = <0>;
415		multiplex-ratio = <31>;
416		segment-remap;
417		com-invdir;
418		com-sequential;
419		prechargep = <0x22>;
420	};
421};
422
423&lpi2c1 {
424	pinctrl-0 = <&lpi2c1_default>;
425	pinctrl-names = "default";
426	clock-frequency = <I2C_BITRATE_STANDARD>;
427};
428
429&lpspi1 {
430	pinctrl-0 = <&lpspi1_default>;
431	pinctrl-names = "default";
432	data-pin-config = "sdo-in,sdi-out";
433};
434
435&lpspi2 {
436	pinctrl-0 = <&lpspi2_default>;
437	pinctrl-names = "default";
438	data-pin-config = "sdo-in,sdi-out";
439};
440
441&lpspi3 {
442	pinctrl-0 = <&lpspi3_default>;
443	pinctrl-names = "default";
444	data-pin-config = "sdo-in,sdi-out";
445	status = "okay";
446
447	fs26_wdt: watchdog@0 {
448		compatible = "nxp,fs26-wdog";
449		reg = <0>;
450		spi-max-frequency = <DT_FREQ_M(5)>;
451		type = "challenger";
452		int-gpios = <&gpioa_h 2 GPIO_ACTIVE_LOW>;
453		status = "okay";
454	};
455};
456
457&lpspi4 {
458	pinctrl-0 = <&lpspi4_default>;
459	pinctrl-names = "default";
460	data-pin-config = "sdo-in,sdi-out";
461};
462
463&lpspi5 {
464	pinctrl-0 = <&lpspi5_default>;
465	pinctrl-names = "default";
466	data-pin-config = "sdo-in,sdi-out";
467};
468
469&emac0 {
470	pinctrl-0 = <&emac0_default>;
471	pinctrl-names = "default";
472	phy-connection-type = "rmii";
473	local-mac-address = [02 04 9f aa bb cc];
474	phy-handle = <&phy>;
475	status = "okay";
476};
477
478&mdio0 {
479	pinctrl-0 = <&mdio0_default>;
480	pinctrl-names = "default";
481	status = "okay";
482
483	phy: ethernet-phy@12 {
484		compatible = "nxp,tja1103";
485		status = "okay";
486		reg = <0x12>;
487		int-gpios = <&gpiod_l 5 GPIO_ACTIVE_LOW>;
488		master-slave = "slave";
489	};
490};
491
492&emios0 {
493	clock-divider = <200>;
494	status = "okay";
495
496	master_bus {
497		/*
498		 * Timebase for PWM led, setting clock 50KHz for internal counter,
499		 * default period is 1000 cycles <-> 20ms.
500		 */
501		emios0_bus_a {
502			mode = "MCB_UP_COUNTER";
503			prescaler = <16>;
504			status = "okay";
505		};
506	};
507
508	emios0_pwm: pwm {
509		pinctrl-0 = <&emios0_default>;
510		pinctrl-names = "default";
511		status = "okay";
512
513		/* Default clock for internal counter for PWM channel 0-7 is 100Khz */
514		pwm_0 {
515			channel = <0>;
516			pwm-mode = "OPWFMB";
517			prescaler = <8>;
518		};
519
520		pwm_1 {
521			channel = <1>;
522			pwm-mode = "OPWFMB";
523			prescaler = <8>;
524		};
525
526		pwm_2 {
527			channel = <2>;
528			pwm-mode = "OPWFMB";
529			prescaler = <8>;
530		};
531
532		pwm_3 {
533			channel = <3>;
534			pwm-mode = "OPWFMB";
535			prescaler = <8>;
536		};
537
538		pwm_4 {
539			channel = <4>;
540			pwm-mode = "OPWFMB";
541			prescaler = <8>;
542		};
543
544		pwm_5 {
545			channel = <5>;
546			pwm-mode = "OPWFMB";
547			prescaler = <8>;
548		};
549
550		rgb_red {
551			channel = <19>;
552			master-bus = <&emios0_bus_a>;
553			pwm-mode = "OPWMB";
554		};
555	};
556};
557
558&emios1 {
559	clock-divider = <200>;
560	status = "okay";
561
562	master_bus {
563		/*
564		 * Timebase for PWM led, setting clock 50KHz for internal counter,
565		 * default period is 1000 cycles <-> 20ms.
566		 */
567		emios1_bus_a {
568			prescaler = <16>;
569			mode = "MCB_UP_COUNTER";
570			status = "okay";
571		};
572
573		emios1_bus_f {
574			prescaler = <16>;
575			mode = "MCB_UP_COUNTER";
576			status = "okay";
577		};
578	};
579
580	emios1_pwm: pwm {
581		pinctrl-0 = <&emios1_default>;
582		pinctrl-names = "default";
583		status = "okay";
584
585		rgb_green {
586			channel = <10>;
587			master-bus = <&emios1_bus_a>;
588			pwm-mode = "OPWMB";
589		};
590
591		rgb_blue {
592			channel = <5>;
593			master-bus = <&emios1_bus_f>;
594			pwm-mode = "OPWMB";
595		};
596	};
597};
598
599&flexio0 {
600	status = "okay";
601
602	flexio0_pwm: flexio0_pwm {
603		pinctrl-0 = <&flexio0_pwm_default>;
604		pinctrl-names = "default";
605		status = "okay";
606
607		pwm_0 {
608			pin-id = <19>;
609			prescaler = <1>;
610		};
611
612		pwm_1 {
613			pin-id = <11>;
614			prescaler = <1>;
615		};
616	};
617
618};
619
620&lcu1 {
621	status = "okay";
622};
623
624&trgmux {
625	status = "okay";
626};
627
628&edma0 {
629	status = "okay";
630};
631