笔记:
调试步骤:
1. BLSPcheck:主要确认GPIO功能和BLSP通道
2. pinctrl文件配置
3. 平台设备树文件配置
4. 时钟文件修改
5. 添加从设备:
1 设备树注册方法
2 设备数节点创建
一、I2C配置 1.根据原理图,查找相关的i2c引脚对应的GPIO值,以GPIO10作为I2C_SDA,GPIO11作为I2C_SCL为例。 2.根据MSM8937 DEVICE SPECIFICATION文档,查找GPIO10与GPIO11对应的BLSP,以及检查GPIO10与GPIO11是否可以作为I2C来使用。根据文档,GPIO10对应BLSP3_1,GPIO11对应BLSP3_0。 3.根据80-nu767-1_h_linux_bam_low-speed_peripherals_configuration_and_debug_guide文件,查找I2C部分BLSP3_0与BLSP3_1对应内容,包括其物理地址、reg size、中断号…… 4.进入kernel/msm-3.18/arch/arm/boot/dts/qcom/路径下修改msm8937-pinctrl.dtsi文件 GPIO配置如下: i2c_3 {
i2c_3_active: i2c_3_active {
/* active state */
mux {
pins = “gpio10”, “gpio11”;
function = “blsp_i2c3”;
};
config {
pins = “gpio10”, “gpio11”;
drive-strength = <2>;
bias-disable;
};
};
i2c_3_sleep: i2c_3_sleep {
/* suspended state */
mux {
pins = “gpio10”, “gpio11”;
function = “gpio”;
};
config {
pins = “gpio10”, “gpio11”;
drive-strength = <2>;
bias-disable;
};
};
};
5.进入kernel/msm-3.18/arch/arm/boot/dts/qcom/路径下修改msm8937.dtsi文件 添加一个新的设备树节点
(1)添加i2c_3 aliases {
smd1 = &smdtty_apps_fm;
smd2 = &smdtty_apps_riva_bt_acl;
smd3 = &smdtty_apps_riva_bt_cmd;
smd4 = &smdtty_mbalbridge;
smd5 = &smdtty_apps_riva_ant_cmd;
smd6 = &smdtty_apps_riva_ant_data;
smd7 = &smdtty_data1;
smd8 = &smdtty_data4;
smd11 = &smdtty_data11;
smd21 = &smdtty_data21;
smd36 = &smdtty_loopback;
spi3 = &spi_3;
i2c2 = &i2c_2;
i2c5 = &i2c_5;
i2c3 = &i2c_3;
sdhc1 = &sdhc_1; /* SDC1 eMMC slot */
sdhc2 = &sdhc_2; /* SDC2 for SD card */
};
(2)配置i2c_3 i2c_3: i2c@78b7000 { /* BLSP1 QUP3 */
compatible = “qcom,i2c-msm-v2”;
#address-cells = <1>;
#size-cells = <0>;
reg-names = “qup_phys_addr”;
reg = <0x78b7000 0x600>;
interrupt-names = “qup_irq”;
interrupts = <0 97 0>;
qcom,clk-freq-out = <400000>;
qcom,clk-freq-in = <19200000>;
clock-names = “iface_clk”, “core_clk”;
clocks = <&clock_gcc clk_gcc_blsp1_ahb_clk>,
<&clock_gcc clk_gcc_blsp1_qup3_i2c_apps_clk>;
pinctrl-names = “i2c_active”, “i2c_sleep”;
pinctrl-0 = <&i2c_3_active>;
pinctrl-1 = <&i2c_3_sleep>;
qcom,noise-rjct-scl = <0>;
qcom,noise-rjct-sda = <0>;
qcom,master-id = <86>;
dmas = <&dma_blsp1 8 64 0x20000020 0x20>,
<&dma_blsp1 9 32 0x20000020 0x20>;
dma-names = “tx”, “rx”;
status = “okey”;
}; 6.进入kernel/msm-3.18/drivers/clk/msm路径下修改clock-gcc-8952.c文件 添加时钟节点如下图所示: static struct rcg_clk blsp1_qup1_i2c_apps_clk_src = {
.cmd_rcgr_reg = BLSP1_QUP1_I2C_APPS_CMD_RCGR,
.set_rate = set_rate_hid,
.freq_tbl = ftbl_gcc_blsp1_2_qup1_4_i2c_apps_clk,
.current_freq = &rcg_dummy_freq,
.base = &virt_bases[GCC_BASE],
.c = {
.dbg_name = “blsp1_qup1_i2c_apps_clk_src”,
.ops = &clk_ops_rcg,
VDD_DIG_FMAX_MAP1LOWER, 50000000),
CLK_INITblsp1_qup1_i2c_apps_clk_src.c),
},
};
二、I2C BUS验证 配置好I2C后,我们需保证I2C BUS被注册 验证过程如下: adb shell //——-> Get adb shell cd /dev/ ls i2c* //——–> to list all the i2c buses 如果显示i2c-3,则表示I2C BUS已被注册 三、I2C调试检查 1、检查I2C配置的相关内容,是否存在错误,或者漏配。 2、确保SDA和SCL所配置的GPIO没有被配置,否则会硬件配置出问题或者GPIO设置无效。 3、若I2C配置无误后,检查相关硬件问题 使用万用表测量I2C_SDA以及I2C_SCL的供电电压,如果与原理图中所示供电电压相差无几,则表示I2C供电电压没有问题。反之,则代表供电电压存在问题。 4、添加从设备 (1)、 通过设备树来注册一个从设备 如果I2C总线正常工作,我们就可以创建一个从设备驱动程序并注册到i2c总线上 我们使用st1663i触摸屏的驱动注册作为范例,引用文件: kernel/drivers/input/touchscreen/st1663i/sitronix_i2c_touch.c.c (2)、创建一个设备树节点 文件修改: /kernel/arch/arm/boot/dts/qcom/msm8917-pmi8937-qrd-sku5.dtsi 添加一个新的设备树节点: i2c@78b7000 {
status = “ok”;
st1663i@70 {
compatible = “sitronix-tp”;
reg = <0x70>;
interrupt-parent = <&tlmm>;
interrupts = <65 0x00>;
reset-gpio = <&tlmm 64 0x00>;
irq-gpio = <&tlmm 65 0x2002>;
/*avdd-supply = <&tp_power>;*/
vdd-supply = <&pm8917_l17>;
vcc_i2c-supply = <&pm8917_l5>;
/* pins used by touchscreen */
pinctrl-names = “pmx_ts_active”,
“pmx_ts_suspend”,
“pmx_ts_release”;
pinctrl-0 = <&ts_int_active &ts_reset_active>;
pinctrl-1 = <&ts_int_suspend &ts_reset_suspend>;
pinctrl-2 = <&ts_release>;
st1663i,i2c-pull-up;
st1663i,no-force-update;
st1663i,num_max_touches = <10>;
st1663i,panel-coords = <0 0 480 800>;
st1663i,display-coords = <0 0 480 800>;
st1663i,button-map= <139 172 158>;
st1663i,have-touch-key;
st1663i,driver-send-cfg;
};
}; (3)、编译完成后,利用示波器测量I2C_SDA以及I2C_SCL波形 测试流程如下 adb root adb remount adb push i2c_test system/bin adb shell cd system/bin chmod 777 i2c_test ./i2c_test /dev/i2c-3 0xaddr(从设备物理地址) 0(读) 0xaddr寄存器地址) 如果I2C没有问题,所示I2C_SDA波形应为以下形式 I2C start > 0xE0 write of 0x70) > 0x1 reg offset ) > I2C stop > delay > I2C start > 0xE1 read of 0x70) > > 8 bytes > I2C stop