Help with DTS for new device


Christoph Schramm
 

Dear *,

 

I’m currently developing a driver for MAX170XX fuel gauge IC family.

 

Preferably, I want to load all the bus settings (I2C bus, etc) from generated_dts_board.h.

 

This is how far I got in my board’s dts:

&i2c1 {
   status = "ok";
    sda-pin = <24>;
    scl-pin = <41>;

    max170xx@40004000 {
        compatible = "max170xx";
        status = "ok";
        reg = < 0x40004000 0x04 >;
    };
};

 

 

At least now I have

#define I2C_1_MAX170XX_40004000_BUS_NAME DT_NORDIC_NRF_I2C_40004000_MAX170XX_40004000_BUS_NAME

In my generated_dts_board.h which is nearly perfect, BUT: it makes no sense using I2C_1_MAX170XX_40004000_BUS_NAME because there are two variables: i2c port number (1 in this case) and 40004000 (i2c reg). Also, to get this far at all, I had to include “40004000” twice – once at the max170xx note and once in the reg array. Otherwise it won’t compile.

 

Is there no way to do this more intuitively like

&i2c1 {
   status = "ok";
    sda-pin = <24>;
    scl-pin = <41>;

    max170xx {
        compatible = "max170xx";
        status = "ok";
        reg = <0x04>;
    };
};

 

Where 0x04 would be the i2c slave address in this example. And it could generate a define like

#define I2C_MAX170XX_BUS_NAME DT_NORDIC_NRF_I2C_40004000_BASE_ADDRESS

#define I2C_MAX170XX_BASE_ADDRESS 0x04

 

Everything already is logically included in the tree, isn’t it? i2c1 is mapped via nrf52840.dtsi and because I’ve added max170xx node to i2c1 I should be able to get this assignment.

 

Is it understandable what I mean? Hope so!

 

Thanks,

Chris


Kumar Gala
 

On Dec 13, 2018, at 3:04 PM, Christoph Schramm <schramm@...> wrote:

Dear *,

I’m currently developing a driver for MAX170XX fuel gauge IC family.

Preferably, I want to load all the bus settings (I2C bus, etc) from generated_dts_board.h.

This is how far I got in my board’s dts:
&i2c1 {
status = "ok";
sda-pin = <24>;
scl-pin = <41>;

max170xx@40004000 {
compatible = "max170xx";
status = "ok";
reg = < 0x40004000 0x04 >;
};
};
The reg for max170xx is incorrect, this should be the I2C address you use to talk to the max170xx.

At least now I have
#define I2C_1_MAX170XX_40004000_BUS_NAME DT_NORDIC_NRF_I2C_40004000_MAX170XX_40004000_BUS_NAME
In my generated_dts_board.h which is nearly perfect, BUT: it makes no sense using I2C_1_MAX170XX_40004000_BUS_NAME because there are two variables: i2c port number (1 in this case) and 40004000 (i2c reg). Also, to get this far at all, I had to include “40004000” twice – once at the max170xx note and once in the reg array. Otherwise it won’t compile.

Is there no way to do this more intuitively like
&i2c1 {
status = "ok";
sda-pin = <24>;
scl-pin = <41>;

max170xx {
compatible = "max170xx";
status = "ok";
reg = <0x04>;
};
};
This is what you should be doing. Might need the node name to be ‘max170xx@4’ but that shouldn’t impact things too much.


Where 0x04 would be the i2c slave address in this example. And it could generate a define like
#define I2C_MAX170XX_BUS_NAME DT_NORDIC_NRF_I2C_40004000_BASE_ADDRESS
#define I2C_MAX170XX_BASE_ADDRESS 0x04

Everything already is logically included in the tree, isn’t it? i2c1 is mapped via nrf52840.dtsi and because I’ve added max170xx node to i2c1 I should be able to get this assignment.

Is it understandable what I mean? Hope so!
If you are able to post your code I can take a look and see what’s going on. Also available on the slack or irc channel.

- k