1 /*
2  * Copyright (c) 2018 Sean Nyekjaer
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <init.h>
8 #include <drivers/pinmux.h>
9 #include <soc.h>
10 
board_pinmux_init(const struct device * dev)11 static int board_pinmux_init(const struct device *dev)
12 {
13 	const struct device *muxa = DEVICE_DT_GET(DT_NODELABEL(pinmux_a));
14 	const struct device *muxb = DEVICE_DT_GET(DT_NODELABEL(pinmux_b));
15 
16 	ARG_UNUSED(dev);
17 
18 	if (!device_is_ready(muxa)) {
19 		return -ENXIO;
20 	}
21 	if (!device_is_ready(muxb)) {
22 		return -ENXIO;
23 	}
24 
25 #if (ATMEL_SAM0_DT_SERCOM_CHECK(0, atmel_sam0_spi) && CONFIG_SPI_SAM0)
26 	/* SPI SERCOM0 on MISO=PA04, MOSI=PA06, SCK=PA07 */
27 	pinmux_pin_set(muxa,  4, PINMUX_FUNC_D);
28 	pinmux_pin_set(muxa,  6, PINMUX_FUNC_D);
29 	pinmux_pin_set(muxa,  7, PINMUX_FUNC_D);
30 #endif
31 #if (ATMEL_SAM0_DT_SERCOM_CHECK(1, atmel_sam0_spi) && CONFIG_SPI_SAM0)
32 #warning Pin mapping may not be configured
33 #endif
34 #if (ATMEL_SAM0_DT_SERCOM_CHECK(2, atmel_sam0_spi) && CONFIG_SPI_SAM0)
35 #warning Pin mapping may not be configured
36 #endif
37 #if (ATMEL_SAM0_DT_SERCOM_CHECK(3, atmel_sam0_spi) && CONFIG_SPI_SAM0)
38 #warning Pin mapping may not be configured
39 #endif
40 #if (ATMEL_SAM0_DT_SERCOM_CHECK(4, atmel_sam0_spi) && CONFIG_SPI_SAM0)
41 #warning Pin mapping may not be configured
42 #endif
43 #if (ATMEL_SAM0_DT_SERCOM_CHECK(5, atmel_sam0_spi) && CONFIG_SPI_SAM0)
44 #warning Pin mapping may not be configured
45 #endif
46 
47 #if (ATMEL_SAM0_DT_SERCOM_CHECK(0, atmel_sam0_i2c) && CONFIG_I2C_SAM0)
48 #warning Pin mapping may not be configured
49 #endif
50 #if (ATMEL_SAM0_DT_SERCOM_CHECK(1, atmel_sam0_i2c) && CONFIG_I2C_SAM0)
51 #warning Pin mapping may not be configured
52 #endif
53 #if (ATMEL_SAM0_DT_SERCOM_CHECK(2, atmel_sam0_i2c) && CONFIG_I2C_SAM0)
54 	/* SERCOM2 on SDA=PA08, SCL=PA09 */
55 	pinmux_pin_set(muxa, 8, PINMUX_FUNC_D);
56 	pinmux_pin_set(muxa, 9, PINMUX_FUNC_D);
57 #endif
58 #if (ATMEL_SAM0_DT_SERCOM_CHECK(3, atmel_sam0_i2c) && CONFIG_I2C_SAM0)
59 #warning Pin mapping may not be configured
60 #endif
61 #if (ATMEL_SAM0_DT_SERCOM_CHECK(4, atmel_sam0_i2c) && CONFIG_I2C_SAM0)
62 #warning Pin mapping may not be configured
63 #endif
64 #if (ATMEL_SAM0_DT_SERCOM_CHECK(5, atmel_sam0_i2c) && CONFIG_I2C_SAM0)
65 #warning Pin mapping may not be configured
66 #endif
67 
68 	return 0;
69 }
70 
71 SYS_INIT(board_pinmux_init, PRE_KERNEL_2, CONFIG_PINMUX_INIT_PRIORITY);
72