linux设备树文件(dtb)

linux 自内核3.x之后引入设备树的概念.而不像2.6时代在arch/arm/mach-s2440.c添加修改设备信息。

(推荐一下宋宝华的Linux设备驱动开发详解:基于最新的Linux 4.0内核》,奉劝各位正学习嵌入式linux的在校学生也要与时俱进)

我使用的设备是beagleboard X15(芯片am5728)

下面是开启uart,i2c ,spi,can等外设的脚本,仅供参考。配置设备树推荐ti 的工具Pinmux

&dra7_pmx_core {
//系统自带
	gpio_keys_pins_default: gpio_keys_pins_default {
		pinctrl-single,pins = <
			DRA7XX_CORE_IOPAD(0x358C, PIN_INPUT_PULLUP | MUX_MODE14)	/* cam0_field.gpio4_2 */
		>;
	};

	myuart1_pins_default: myuart1_pins_default {
		pinctrl-single,pins = <
			DRA7XX_CORE_IOPAD(0x37E0, PIN_INPUT | MUX_MODE0)
			DRA7XX_CORE_IOPAD(0x37E4, PIN_INPUT | MUX_MODE0)
		>;
	};
//系统自带

//Tag : 开启uart10
//0x3570,0x3574为物理地址,MUX_MODE8为引脚映射模式8,这些需要通过ti 的工具Pinmux
	myuart10_pins_default: myuart10_pins_default {
		pinctrl-single,pins = <

			DRA7XX_CORE_IOPAD(0x3570, (PIN_INPUT_PULLUP | MUX_MODE8)) /* vin2a_d2.uart10_rxd */
			DRA7XX_CORE_IOPAD(0x3574, (PIN_OUTPUT_PULLUP | MUX_MODE8)) /* vin2a_d3.uart10_txd */
		>;
	};

//Tag : 开启i2c5
	i2c5_pins_default:i2c5_pins_default{
		pinctrl-single,pins = <

			DRA7XX_CORE_IOPAD(0x3744, PIN_INPUT_PULLUP | PIN_INPUT_SLEW |MUX_MODE4) 	// i2c5_sda aa3
			DRA7XX_CORE_IOPAD(0x3748, PIN_INPUT_PULLUP |PIN_INPUT_SLEW | MUX_MODE4) 	// i2c5 scl ab9 
			
		>;

	};

//Tag : can1
	dcan1_pins_default: dcan1_pins_default {
		pinctrl-single,pins = <
			DRA7XX_CORE_IOPAD(0x37d0, PIN_OUTPUT_PULLUP | MUX_MODE0)	// dcan1_tx 
			DRA7XX_CORE_IOPAD(0x37d4, PIN_INPUT_PULLUP | MUX_MODE0)		// dcan1_rx 
		>;
	};

	dcan1_pins_sleep: dcan1_pins_sleep {
		pinctrl-single,pins = <
			DRA7XX_CORE_IOPAD(0x37d0, MUX_MODE15 | PULL_UP)	// dcan1_tx.off 
			DRA7XX_CORE_IOPAD(0x37d4, MUX_MODE15 | PULL_UP)	// dcan1_rx.off 
		>;
	};


};

重要:配置can通信"default", "sleep", "active"三个模式都要配置。我试过就是直接配置active,结果试了一天,can都无法正常通信。切记

&uart10 {
	pinctrl-names = "default";
	pinctrl-0 = <&myuart10_pins_default>;	
	status = "okay";
};



&i2c5 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2c5_pins_default>;
	clock-frequency = <400000>;
	
};
//Tag : 配置 spi,
//compatible为匹配驱动
&mcspi3 {
	pinctrl-names = "default";
	status = "okay";
	
	spidev@0{
		compatible = "spidev";
		spi-max-frequency = <48000000>;
		reg = <0>;
		status = "okay";
		spi-cpol; spi-cpha;
	};

};

&mcspi4 {
	pinctrl-names = "default";
	status = "okay";

	spidev@0 {
		compatible = "spidev";
		spi-max-frequency = <48000000>;
		reg = <0>;
		status = "okay";
		spi-cpol; spi-cpha;
	};

};
//Tag : 配置can通信

&dcan1 {
	status = "okay";
	pinctrl-names = "default", "sleep", "active";
	pinctrl-0 = <&dcan1_pins_sleep>;
	pinctrl-1 = <&dcan1_pins_sleep>;
	pinctrl-2 = <&dcan1_pins_default>;
};

你可能感兴趣的:(linux)