2025年10月15日 星期三

STM32MP257f-EV1 enable SPI3

Board: STM32MP257f-EV1
OS: buildroot (branch: remotes/origin/st/2022.02)
patch: buildroot-external-st (branch: st/2022.02.7)


enable SPI3
$ vim buildroot-external-st/board/stmicroelectronics/stm32mp2/linux-dts/st/stm32mp257f-ev1-mx.dts

...
...
#include "stm32mp25-pinctrl.dtsi"

aliases{
		ethernet0 = ð2;
		ethernet1 = ð1;
		serial0 = &usart2;
		serial1 = &usart6;
		serial2 = &lpuart1;
        spi3 = &spi3;
	};
...
...
&spi3 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi3_pins_a>;
	pinctrl-1 = <&spi3_sleep_pins_a>;
	status = "okay";

    spidev@0 {
        compatible = "lwn,bk4";
        reg = <0>;
        spi-max-frequency = <10000000>;
    };
};

Kernel code
CONFIG_SPI_SPIDEV=m or y


drivers/spi/spidev.c
static const struct of_device_id spidev_dt_ids[] = {
	{ .compatible = "cisco,spi-petra", .data = &spidev_of_check },
	{ .compatible = "dh,dhcom-board", .data = &spidev_of_check },
	{ .compatible = "lineartechnology,ltc2488", .data = &spidev_of_check },
	{ .compatible = "lwn,bk4", .data = &spidev_of_check },
	{ .compatible = "menlo,m53cpld", .data = &spidev_of_check },
	{ .compatible = "micron,spi-authenta", .data = &spidev_of_check },
	{ .compatible = "rohm,bh2228fv", .data = &spidev_of_check },
	{ .compatible = "rohm,dh2228fv", .data = &spidev_of_check },
	{ .compatible = "semtech,sx1301", .data = &spidev_of_check },
	{ .compatible = "silabs,em3581", .data = &spidev_of_check },
	{ .compatible = "silabs,si3210", .data = &spidev_of_check },
	{},
};
MODULE_DEVICE_TABLE(of, spidev_dt_ids);


drivers/spi/spi-stm32.c
static const struct of_device_id stm32_spi_of_match[] = {
	{ .compatible = "st,stm32mp25-spi", .data = (void *)&stm32mp25_spi_cfg },
	{ .compatible = "st,stm32h7-spi", .data = (void *)&stm32h7_spi_cfg },
	{ .compatible = "st,stm32f4-spi", .data = (void *)&stm32f4_spi_cfg },
	{},
};
MODULE_DEVICE_TABLE(of, stm32_spi_of_match);

on EV-1 board
# dtc -I fs -O dts /proc/device-tree > dts

# vi dts

...
...
 aliases {
                ethernet0 = "/soc@0/bus@42080000/eth2@482d0000";
                serial1 = "/soc@0/bus@42080000/serial@40220000";
                ethernet1 = "/soc@0/bus@42080000/eth1@482c0000";
                spi3 = "/soc@0/bus@42080000/spi@400c0000";
                serial2 = "/soc@0/bus@42080000/serial@46030000";
                serial0 = "/soc@0/bus@42080000/serial@400e0000";
        };
...
...
spi@400c0000 {
                                power-domains = <0x0c>;
                                pinctrl-names = "default\0sleep";
                                #address-cells = <0x01>;
                                pinctrl-0 = <0x27>;
                                resets = <0x16 0x18>;
                                interrupts = <0x00 0x7d 0x04>;
                                clocks = <0x16 0x104>;
                                #size-cells = <0x00>;
                                dma-names = "rx\0tx";
                                compatible = "st,stm32mp25-spi";
                                pinctrl-1 = <0x28>;
                                status = "okay";
                                reg = <0x400c0000 0x400>;
                                phandle = <0xbc>;
                                dmas = <0x23 0x35 0x20 0x3012 0x23 0x36 0x20 0x3021>;
                                access-controllers = <0x1b 0x18>;

                                spidev@0 {
                                        spi-max-frequency = <0x989680>;
                                        compatible = "lwn,bk4";
                                        reg = <0x00>;
                                };
                        };
install spidev.ko
# modprobe spidev.ko

# ls /dev/spidev3.0
/dev/spidev3.0

沒有留言:

張貼留言