AnsweredAssumed Answered

how to binding the i2c platform data in the device tree dtsi configuration?

Question asked by Roger Chiu on Oct 26, 2016
Latest reply on Oct 27, 2016 by Roger Chiu

Hi all,

We have a i.mx6 solo boar with yocto linux 4.1.15 and need porting the i2c eeprom as the MAC address.

Now I could write and dump the eeprom data from console with command to see the MAC address what I write into.

But I have question about the Device tree (dtsi) how to binding the i2c platform data.

As my previous i.mx6 quard linux 3.0.35 experience. I could config it to work as follows 4 steps.

But in yocto linux 4.1.15, how to binding the i2c platform data in the device tree dtsi configuration? And I could not find the board.c file for the i.mx6 solo in kernel/.../mach-imx. Is there someone know which board.c is match for i.mx6 solo. 

Is there someone could help me. Thanks ~

 

/* CAT24C256 EEPROM */
eeprom@50 {
compatible = "at,24c256";
reg = <0x50>;
page_size = <64>;
byte_len = <32768>;
flags = <16>;
context = <0x0000>;
};

 

1. CONFIG_EEPROM_AT24=y

 

2. mach-mx6/board-mx6q_sabresd.c
static struct at24_platform_data eeprom_info = {
.byte_len = (256*1024) / 8,
.page_size = 64,
.flags = AT24_FLAG_ADDR16,
.setup = get_mac_addr,
.context = (void *)0x0000,
};

 

3.static struct i2c_board_info mxc_i2c2_board_info[] __initdata = {
{
I2C_BOARD_INFO("24c256", 0x50),
.platform_data = &eeprom_info,
},
};

 

4. drivers/net/fec.c

#include <linux/i2c.h>
#include <linux/memory.h>
char gmac_addr[6];
void get_mac_addr(struct memory_accessor *mem_acc, void *context)
{

int i;
off_t offset = (off_t)context;

mem_acc->read(mem_acc, gmac_addr, offset, ETH_ALEN);
for (i = 0; i < 6; i++) {
printk("mac_addr[%d]=0x%x\n",i,gmac_addr[i]);
}
}
EXPORT_SYMBOL(get_mac_addr);

static void __inline__ fec_get_mac(struct net_device *ndev)
{
struct fec_enet_private *fep = netdev_priv(ndev);
struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
unsigned char *iap, tmpaddr[ETH_ALEN];


/*
* try to get mac address in following order:
*
* 1) module parameter via kernel command line in form
* fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
*/
iap = macaddr;
printk(KERN_INFO "1 ========fec_get_mac==0x%x\n",*iap);
/*
* 2) from flash or fuse (via platform data)
*/
if (!is_valid_ether_addr(iap)) {
#ifdef CONFIG_M5272
if (FEC_FLASHMAC)
iap = (unsigned char *)FEC_FLASHMAC;
#else
//if (pdata)
if((gmac_addr[0]==0xff && gmac_addr[1]==0xff )){
memcpy(iap, pdata->mac, ETH_ALEN);
}else{
memcpy(iap, gmac_addr, ETH_ALEN);
}
#endif

}

Outcomes