u-boot pinctrl_select_state函数

//

 

 

/**
 * pinctrl_select_state_full() - full implementation of pinctrl_select_state
 *
 * @dev: peripheral device
 * @statename: state name, like "default"
 * @return: 0 on success, or negative error code on failure
 */
static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
{
    char propname[32]; /* long enough */
    const fdt32_t *list;
    uint32_t phandle;
    struct udevice *config;
    int state, size, i, ret;

    state = dev_read_stringlist_search(dev, "pinctrl-names", statename);
    if (state < 0) {
        char *end;
        /*
         * If statename is not found in "pinctrl-names",
         * assume statename is just the integer state ID.
         */
        state = dectoul(statename, &end);
        if (*end)
            return -EINVAL;
    }

    snprintf(propname, sizeof(propname), "pinctrl-%d", state);
    list = dev_read_prop(dev, propname, &size);
    if (!list)
        return -EINVAL;

    size /= sizeof(*list);
    for (i = 0; i < size; i++) {
        phandle = fdt32_to_cpu(*list++);
        ret = uclass_get_device_by_phandle_id(UCLASS_PINCONFIG, phandle,
                              &config);
        if (ret) {
            dev_warn(dev, "%s: uclass_get_device_by_phandle_id: err=%d\n",
                __func__, ret);
            continue;
        }

        ret = pinctrl_config_one(config);
        if (ret) {
            dev_warn(dev, "%s: pinctrl_config_one: err=%d\n",
                __func__, ret);
            continue;
        }
    }

    return 0;
}
 
 
 
/**
 * pinctrl_select_state_simple() - simple implementation of pinctrl_select_state
 *
 * @dev: peripheral device
 * @return: 0 on success, or negative error code on failure
 */
static int pinctrl_select_state_simple(struct udevice *dev)
{
    struct udevice *pctldev;
    struct pinctrl_ops *ops;
    int ret;

    /*
     * For most system, there is only one pincontroller device. But in
     * case of multiple pincontroller devices, probe the one with sequence
     * number 0 (defined by alias) to avoid race condition.
     */
    ret = uclass_get_device_by_seq(UCLASS_PINCTRL, 0, &pctldev);
    if (ret)
        /* if not found, get the first one */
        ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev);
    if (ret)
        return ret;

    ops = pinctrl_get_ops(pctldev);
    if (!ops->set_state_simple) {
        dev_dbg(dev, "set_state_simple op missing\n");
        return -ENOSYS;
    }

    return ops->set_state_simple(pctldev, dev);
}
 
 
 
 
 
posted @ 2022-02-22 15:35  liujunhuasd  阅读(391)  评论(0编辑  收藏  举报