/* * find_voltage_set_register: Find new voltage configuration register * (VSET) id. * The finding of the new VSET register will be based on the LRU mechanism. * Each VSET register will have different voltage configured . This * Function will look if any of the VSET register have requested voltage set * or not. * - If it is already there then it will make that register as most * recently used and return as found so that caller need not to set * the VSET register but need to set the proper gpios to select this * VSET register. * - If requested voltage is not found then it will use the least * recently mechanism to get new VSET register for new configuration * and will return not_found so that caller need to set new VSET * register and then gpios (both).
*/ staticbool find_voltage_set_register(struct tps62360_chip *tps, int req_vsel, int *vset_reg_id)
{ int i; bool found = false; int new_vset_reg = tps->lru_index[3]; int found_index = 3;
for (i = 0; i < 4; ++i) { if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) {
new_vset_reg = tps->lru_index[i];
found_index = i;
found = true; goto update_lru_index;
}
}
update_lru_index: for (i = found_index; i > 0; i--)
tps->lru_index[i] = tps->lru_index[i - 1];
staticint tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev, unsigned selector)
{ struct tps62360_chip *tps = rdev_get_drvdata(dev); int ret; bool found = false; int new_vset_id = tps->curr_vset_id;
/* * If gpios are available to select the VSET register then least * recently used register for new configuration.
*/ if (tps->valid_gpios)
found = find_voltage_set_register(tps, selector, &new_vset_id);
if (!found) {
ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
tps->voltage_reg_mask, selector); if (ret < 0) {
dev_err(tps->dev, "%s(): register %d update failed with err %d\n",
__func__, REG_VSET0 + new_vset_id, ret); return ret;
}
tps->curr_vset_id = new_vset_id;
tps->curr_vset_vsel[new_vset_id] = selector;
}
staticint tps62360_set_mode(struct regulator_dev *rdev, unsignedint mode)
{ struct tps62360_chip *tps = rdev_get_drvdata(rdev); int i; int val; int ret;
/* Enable force PWM mode in FAST mode only. */ switch (mode) { case REGULATOR_MODE_FAST:
val = FORCE_PWM_ENABLE; break;
case REGULATOR_MODE_NORMAL:
val = 0; break;
default: return -EINVAL;
}
if (!tps->valid_gpios) {
ret = regmap_update_bits(tps->regmap,
REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val); if (ret < 0)
dev_err(tps->dev, "%s(): register %d update failed with err %d\n",
__func__, REG_VSET0 + tps->curr_vset_id, ret); return ret;
}
/* If gpios are valid then all register set need to be control */ for (i = 0; i < 4; ++i) {
ret = regmap_update_bits(tps->regmap,
REG_VSET0 + i, FORCE_PWM_ENABLE, val); if (ret < 0) {
dev_err(tps->dev, "%s(): register %d update failed with err %d\n",
__func__, REG_VSET0 + i, ret); return ret;
}
} return ret;
}
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return NULL;
pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node,
desc); if (!pdata->reg_init_data) {
dev_err(dev, "Not able to get OF regulator init data\n"); return NULL;
}
if (client->dev.of_node) { conststruct of_device_id *match;
match = of_match_device(of_match_ptr(tps62360_of_match),
&client->dev); if (!match) {
dev_err(&client->dev, "Error: No device match found\n"); return -ENODEV;
}
chip_id = (int)(long)match->data; if (!pdata)
pdata = of_get_tps62360_platform_data(&client->dev,
&tps->desc);
} elseif (id) {
chip_id = id->driver_data;
} else {
dev_err(&client->dev, "No device tree match or id table match found\n"); return -ENODEV;
}
if (!pdata) {
dev_err(&client->dev, "%s(): Platform data not found\n",
__func__); return -EIO;
}
/* * Initialize the lru index with vset_reg id * The index 0 will be most recently used and
* set with the tps->curr_vset_id */ for (i = 0; i < 4; ++i)
tps->lru_index[i] = i;
tps->lru_index[0] = tps->curr_vset_id;
tps->lru_index[tps->curr_vset_id] = 0;
}
ret = tps62360_init_dcdc(tps, pdata); if (ret < 0) {
dev_err(tps->dev, "%s(): Init failed with err = %d\n",
__func__, ret); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.