SPL 阶段识别设备

1.需求在SPL阶段识别I2C和PMIC的驱动,并对PMIC进行配置.

1.1 I2C的识别

 /*1. 可以通过设备树文件扫到I2 Cdevice*/
int pmic_i2c_init(void)
{
    int ret = 0;

    struct udevice *dev;
    
    printk("%s entry\n", __func__);
    ret = uclass_get_device_by_driver(UCLASS_I2C, DM_GET_DRIVER(i2c_designware), &dev);
    if (ret) {
        printk("%s  find no I2C \n", __func__);
        /* No PMIC on board */
        return 0;
    }    
    printk("%s find I2C\n", __func__);

    return ret;
}

 

/*2 this way could scan i2c master*/
if (uclass_get_device(UCLASS_I2C, 0, &i2c_dev))
        printf("I2C master: Not found!\n");

 

1.2 PMIC的识别

int power_init_board(struct udevice **dev_pmic)
{
    
    struct udevice *pdev;
    int ret;
    u32 dev_id = 0;

    *dev_pmic = NULL;

    ret = uclass_get_device_by_driver(UCLASS_PMIC, DM_GET_DRIVER(pmic_pca9450c), &pdev);
    if (ret) {
        printk("%s  find no PMIC \n", __func__);
        /* No PMIC on board */
        return 0;
    }    
    printk("%s find PMIC\n", __func__);

    dev_id = pmic_reg_read(pdev, PCA9450_REG_DEV_ID);
    printf("PMIC: PCA9450! DEV_ID=0x%x\n", dev_id);
    
    /*BUCKxOUT_DVS0/1 control BUCK123 output */
    pmic_reg_write(pdev, PCA9450_BUCK123_DVS, 0x29);
    return 0;
}

 

 但是有个非常非常重要的参数需要在dts中配置:u-boot,dm-spl;

1.3 当然还有一些方法

寻找node--->node 有效寻找I2C外设的设备地址---->依据子设备找到父设备---->dm_i2c_probe, 成功之后,dm_i2c_read/write 就可以对I2C连接的外设进行访问。

int power_init_board(struct udevice **dev_pmic)
{
    struct udevice *pdev, *bus;
    int ret;
    u32 dev_id = 0;
    ofnode node;
    u32 chip_addr;

    *dev_pmic = NULL;
    node = ofnode_by_compatible(ofnode_null(), "nxp,pca9450c");
    if (!ofnode_valid(node)) {
        printf("%s: uclass_get_device_by_ofnode failed.\n", __func__);
        return -ENODEV;
    }
    printf("%s:find the node.\n", __func__);

    /*when node valid, get reg*/
    ret = ofnode_read_u32(node, "reg", &chip_addr);
    if (ret)
        return -EINVAL;
    printf("reg check done 0x%x.\n", chip_addr);

    ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node), &bus);
    if (ret) {
        printf("i2c bus for pmic not found\n");
        return -ENODEV;
    }

    ret = dm_i2c_probe(bus, chip_addr, 0, &pdev);
    printf("%s ret 0x%x.\n", __func__, ret);
    if (!ret)
        *dev_pmic = pdev;
    return 0;
}

 

posted @ 2020-11-09 17:22  马蜂窝  阅读(715)  评论(0)    收藏  举报