请教各位高手。我想用drivers/i2c/busses/i2c-gpio.c 模拟iic,硬件iic口没有使用,io被占用了。要怎么玩?
menuconfig配置如下
-*- I2C support
Enable compatibility bits for old user-space
<*> I2C device interface
<*> I2C bus multiplexing support
Multiplexer I2C Chip support --->
[**] Autoselect pertinent helper modules
I2C Hardware Bus support --->
*** I2C system bus drivers (mostly embedded / system-on-chip)
│ │ < > CBUS I2C driver
│ │ < > Synopsys DesignWare Platform
│ │ < > EMMA Mobile series I2C adapter
│ │ <*> GPIO-based bitbanging I2C
│ │ < > Marvell mv64xxx I2C Controller
│ │ < > OpenCores I2C Controller
│ │ < > PCA9564/PCA9665 as platform device
│ │ < > Rockchip RK3xxx I2C adapter
│ │ < > Simtec Generic I2C interface
dts如下
i2c0@0 {
compatible = "i2c-gpio";
gpios = <&pio 2 2 // sda
&pio 2 1 // scl
>;
i2c-gpio,sda-open-drain;
i2c-gpio,scl-open-drain;
i2c-gpio,delay-us = <2>;
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
//rv3029c2@56 {
//compatible = "rv3029c2";
//reg = <0x56>;
//};
};
启动后报错, OF: /soc/i2c0@0: could not get #gpio-cells for /soc/clock@01c20000
是不是gpio配置不对,
&pio 2 2 /* sda */
&pio 2 1这两个口是串口,没有使用,应该不会被占用,
设备树怎么写?请教大家了
最近编辑记录 psst (2019-11-16 18:19:36)
离线
软件模拟也需要定时器吧,否则时序无法控制
离线
你的设备树配置有误, 来这里抄一个吧:
i2c {
compatible = "i2c-gpio";
sda-gpios = <&pio 4 13 GPIO_ACTIVE_HIGH>;
scl-gpios = <&pio 4 12 GPIO_ACTIVE_HIGH>;
i2c-gpio,delay-us = <5>;
#address-cells = <1>;
#size-cells = <0>;
...
离线
我也在用模拟iic,请问启动了吗?
# dmesg | grep i2c
[ 0.120130] i2c-gpio i2c-gpio: error trying to get descriptor: -2
[ 0.981720] i2c /dev entries driver
[ 6.656316] goodix-ts 1-005d: GTP i2c test failed time 1
[ 11.086325] goodix-ts 1-005d: GTP i2c test failed time 2
[ 15.516320] goodix-ts 1-005d: GTP i2c test failed time 3
[ 15.544682] i2c-gpio i2c-gpio: using lines 3 (SDA) and 0 (SCL),-1
一直是这个错误
离线
在pinctrl里面要声明使用的引脚,然后在使用它gpio模拟iic的,应该是类似的
可以参考一下这个gpio模拟spi的例子
在根节点下加入
spi2:spi2{
compatible = "spi-gpio";
#address-cells = <0x1>;
#size-cells = <0>;
//ranges;
gpio-sck = <&pio 3 0 1>;
gpio-miso = <&pio 3 1 1>;
gpio-mosi = <&pio 3 2 1>;
cs-gpios = <&pio 3 3 1>;
num-chipselects = <1>;
pinctrl-names = "default";//注意这两排
pinctrl-0 = <&spi2_pins_a>;//
spidev2 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "rohm,dh2228fv";
spi-max-frequency = <20000000>;
reg = <0>;
};
};
在pinctrl里面加入
&pio{
spi2_pins_a: spi2-pins-pc {
pins = "PD0", "PD1", "PD2", "PD3";
function = "gpio_out";
bias-pull-up;
};
};
最近编辑记录 lignin (2020-08-02 20:05:48)
离线
就在两地方,毫无问题
.config - Linux/arm 5.4.99 Kernel Configuration
> Device Drivers > I2C support > I2C Hardware Bus support ────────────────────
┌─────────────────────── I2C Hardware Bus support ────────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty │
│ submenus ----). Highlighted letters are hotkeys. Pressing <Y> │
│ includes, <N> excludes, <M> modularizes features. Press <Esc><Esc> to │
│ exit, <?> for Help, </> for Search. Legend: [*] built-in [ ] │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ *** I2C system bus drivers (mostly embedded / system-on-chip)│ │
│ │ < > CBUS I2C driver │ │
│ │ < > Synopsys DesignWare Platform │ │
│ │ < > EMMA Mobile series I2C adapter │ │
│ │ <*> GPIO-based bitbanging I2C
i2c_gpio0: i2c-gpio-0 {
compatible = "i2c-gpio";
sda-gpios = <&pio 4 0 GPIO_ACTIVE_HIGH>;
scl-gpios = <&pio 4 1 GPIO_ACTIVE_HIGH>;
i2c-gpio,delay-us = <5>;
#address-cells = <1>;
#size-cells = <0>;
ft6x06@38 {
compatible = "focaltech,ft6236";
reg = <0x38>;
interrupt-parent = <&pio>;
interrupts = <4 2 IRQ_TYPE_LEVEL_LOW>;
reset-gpios = <&pio 4 3 GPIO_ACTIVE_LOW>;
touchscreen-size-x = <240>;
touchscreen-size-y = <240>;
};
};
离线