Android UART 使用说明
硬件
1. 设备树
1. 设备树pinctrl
# kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8953-pinctrl.dtsi
pmx-uartconsole {
uart_console_active: uart_console_active {
mux {
pins = "gpio4", "gpio5";
function = "blsp_uart2";
};
config {
pins = "gpio4", "gpio5";
drive-strength = <2>;
bias-disable;
};
};
uart_console_sleep: uart_console_sleep {
mux {
pins = "gpio4", "gpio5";
function = "blsp_uart2";
};
config {
pins = "gpio4", "gpio5";
drive-strength = <2>;
bias-pull-down;
};
};
uart4_active: uart4_active {
mux {
pins = "gpio12", "gpio13";
function = "blsp_uart4";
};
config {
pins = "gpio12", "gpio13";
drive-strength = <8>;
bias-disable;
};
};
uart4_sleep: uart4_sleep {
mux {
pins = "gpio12", "gpio13";
function = "blsp_uart4";
};
config {
pins = "gpio12", "gpio13";
drive-strength = <2>;
bias-pull-down;
};
};
uart5_active: uart5_active {
mux {
pins = "gpio16", "gpio17";
function = "blsp_uart5";
};
config {
pins = "gpio16", "gpio17";
drive-strength = <8>;
bias-disable;
};
};
uart5_sleep: uart5_sleep {
mux {
pins = "gpio16", "gpio17";
function = "blsp_uart5";
};
config {
pins = "gpio16", "gpio17";
drive-strength = <2>;
bias-pull-down;
};
};
uart6_active: uart6_active {
mux {
pins = "gpio20", "gpio21";
function = "blsp_uart6";
};
config {
pins = "gpio20", "gpio21";
drive-strength = <8>;
bias-disable;
};
};
uart6_sleep: uart6_sleep {
mux {
pins = "gpio20", "gpio21";
function = "blsp_uart6";
};
config {
pins = "gpio20", "gpio21";
drive-strength = <2>;
bias-pull-down;
};
};
};
注意
- 电流不能太小
2. 设备树使能
# kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8953.dtsi
/* uart5 */
blsp2_uart0_ls: serial@7aef000 {
compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm";
reg = <0x7aef000 0x200>;
interrupts = <0 306 0>;
clocks = <&clock_gcc clk_gcc_blsp2_uart1_apps_clk>,
<&clock_gcc clk_gcc_blsp2_ahb_clk>;
clock-names = "core", "iface";
pinctrl-names = "default";
pinctrl-0 = <&uart5_active>;
status = "ok";
};
/* uart4 */
blsp1_serial1: serial@78b0000 {
compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm";
reg = <0x78b0000 0x200>;
interrupts = <0 108 0>;
clocks = <&clock_gcc clk_gcc_blsp1_uart2_apps_clk>,
<&clock_gcc clk_gcc_blsp1_ahb_clk>;
clock-names = "core", "iface";
pinctrl-names = "default";
pinctrl-0 = <&uart4_active>;
status = "ok";
};
/* uart6 */
blsp2_uart1_ls: serial@7af0000 {
compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm";
reg = <0x7af0000 0x200>;
interrupts = <0 307 0>;
clock-names = "core", "iface";
clocks = <&clock_gcc clk_gcc_blsp2_uart2_apps_clk>,
<&clock_gcc clk_gcc_blsp2_ahb_clk>;
pinctrl-names = "default";
pinctrl-0 = <&uart6_active>;
status = "ok";
};
注意
- UART和SPI冲突,使用UART要把SPI关闭
- 低速串口模式
3. 高速串口
# kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8953.dtsi
blsp2_uart1: uart@7af0000 {
compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm";
reg = <0x7af0000 0x200>,
<0x7ac4000 0x1f000>;
reg-names = "core_mem", "bam_mem";
interrupt-names = "core_irq", "bam_irq", "wakeup_irq";
#address-cells = <0>;
interrupt-parent = <&blsp2_uart1>;
interrupts = <0 1 2>;
#interrupt-cells = <1>;
interrupt-map-mask = <0xffffffff>;
interrupt-map = <0 &intc 0 307 0
1 &intc 0 239 0
2 &tlmm 21 0>;
qcom,inject-rx-on-wakeup;
qcom,rx-char-to-inject = <0xFD>;
qcom,master-id = <84>;
clock-names = "core_clk", "iface_clk";
clocks = <&clock_gcc clk_gcc_blsp2_uart2_apps_clk>,
<&clock_gcc clk_gcc_blsp2_ahb_clk>;
pinctrl-names = "sleep", "default";
pinctrl-0 = <&blsp2_uart1_sleep>;
pinctrl-1 = <&blsp2_uart1_active>;
qcom,bam-tx-ep-pipe-index = <2>;
qcom,bam-rx-ep-pipe-index = <3>;
qcom,msm-bus,name = "blsp2_uart1";
qcom,msm-bus,num-cases = <2>;
qcom,msm-bus,num-paths = <1>;
qcom,msm-bus,vectors-KBps =
<84 512 0 0>,
<84 512 500 800>;
status = "ok";
};
2. 驱动
# kernel/msm-4.9/drivers/tty/serial/msm_serial.c
在 static struct msm_port msm_uart_ports[] 中添加元素:
.uart = {
.iotype = UPIO_MEM,
.ops = &msm_uart_pops,
.flags = UPF_BOOT_AUTOCONF,
.fifosize = 64,
.line = 3,
},
注意
- 在probe函数中根据msm_uart_ports的元素个数来决定是否创建设备节点
- 设备节点名是根据设备树中的顺序决定的
- 改了设备树和驱动,只需编译内核,更换boot.img
- 高速串口:kernel/msm-4.9/drivers/tty/serial/msm_serial_hs.c
- 时钟:kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8953-qrd.dtsi
- 时钟:kernel/msm-4.9/drivers/clk/msm/clock-gcc-8953.c
- 初始化成功,调试串口打印输出:msm_serial: detected port
3. 设备树节点
cat /sys/class/tty/ttyHSL2/device/of_node/name # 查看节点名称
cat /sys/class/tty/ttyHSL1/device/uevent # 查看驱动、寄存器等