/* Blow timer clock frequency in Mhz */ #define QFPROM_BLOW_TIMER_OFFSET 0x03c
/* Amount of time required to hold charge to blow fuse in micro-seconds */ #define QFPROM_FUSE_BLOW_POLL_US 100 #define QFPROM_FUSE_BLOW_TIMEOUT_US 10000
staticbool read_raw_data;
module_param(read_raw_data, bool, 0644);
MODULE_PARM_DESC(read_raw_data, "Read raw instead of corrected data");
/** * struct qfprom_soc_data - config that varies from SoC to SoC. * * @accel_value: Should contain qfprom accel value. * @qfprom_blow_timer_value: The timer value of qfprom when doing efuse blow. * @qfprom_blow_set_freq: The frequency required to set when we start the * fuse blowing. * @qfprom_blow_uV: LDO voltage to be set when doing efuse blow
*/ struct qfprom_soc_data {
u32 accel_value;
u32 qfprom_blow_timer_value;
u32 qfprom_blow_set_freq; int qfprom_blow_uV;
};
/** * struct qfprom_priv - structure holding qfprom attributes * * @qfpraw: iomapped memory space for qfprom-efuse raw address space. * @qfpconf: iomapped memory space for qfprom-efuse configuration address * space. * @qfpcorrected: iomapped memory space for qfprom corrected address space. * @qfpsecurity: iomapped memory space for qfprom security control space. * @dev: qfprom device structure. * @secclk: Clock supply. * @vcc: Regulator supply. * @soc_data: Data that for things that varies from SoC to SoC.
*/ struct qfprom_priv { void __iomem *qfpraw; void __iomem *qfpconf; void __iomem *qfpcorrected; void __iomem *qfpsecurity; struct device *dev; struct clk *secclk; struct regulator *vcc; conststruct qfprom_soc_data *soc_data;
};
/** * struct qfprom_touched_values - saved values to restore after blowing * * @clk_rate: The rate the clock was at before blowing. * @accel_val: The value of the accel reg before blowing. * @timer_val: The value of the timer before blowing.
*/ struct qfprom_touched_values { unsignedlong clk_rate;
u32 accel_val;
u32 timer_val;
};
/** * struct qfprom_soc_compatible_data - Data matched against the SoC * compatible string. * * @keepout: Array of keepout regions for this SoC. * @nkeepout: Number of elements in the keepout array.
*/ struct qfprom_soc_compatible_data { conststruct nvmem_keepout *keepout; unsignedint nkeepout;
};
/** * qfprom_disable_fuse_blowing() - Undo enabling of fuse blowing. * @priv: Our driver data. * @old: The data that was stashed from before fuse blowing. * * Resets the value of the blow timer, accel register and the clock * and voltage settings. * * Prints messages if there are errors but doesn't return an error code * since there's not much we can do upon failure.
*/ staticvoid qfprom_disable_fuse_blowing(conststruct qfprom_priv *priv, conststruct qfprom_touched_values *old)
{ int ret;
/* * This may be a shared rail and may be able to run at a lower rate * when we're not blowing fuses. At the moment, the regulator framework * applies voltage constraints even on disabled rails, so remove our * constraints and allow the rail to be adjusted by other users.
*/
ret = regulator_set_voltage(priv->vcc, 0, INT_MAX); if (ret)
dev_warn(priv->dev, "Failed to set 0 voltage (ignoring)\n");
ret = regulator_disable(priv->vcc); if (ret)
dev_warn(priv->dev, "Failed to disable regulator (ignoring)\n");
ret = clk_set_rate(priv->secclk, old->clk_rate); if (ret)
dev_warn(priv->dev, "Failed to set clock rate for disable (ignoring)\n");
clk_disable_unprepare(priv->secclk);
}
/** * qfprom_enable_fuse_blowing() - Enable fuse blowing. * @priv: Our driver data. * @old: We'll stash stuff here to use when disabling. * * Sets the value of the blow timer, accel register and the clock * and voltage settings. * * Prints messages if there are errors so caller doesn't need to. * * Return: 0 or -err.
*/ staticint qfprom_enable_fuse_blowing(conststruct qfprom_priv *priv, struct qfprom_touched_values *old)
{ int ret; int qfprom_blow_uV = priv->soc_data->qfprom_blow_uV;
ret = clk_prepare_enable(priv->secclk); if (ret) {
dev_err(priv->dev, "Failed to enable clock\n"); return ret;
}
old->clk_rate = clk_get_rate(priv->secclk);
ret = clk_set_rate(priv->secclk, priv->soc_data->qfprom_blow_set_freq); if (ret) {
dev_err(priv->dev, "Failed to set clock rate for enable\n"); goto err_clk_prepared;
}
/* * Hardware requires a minimum voltage for fuse blowing. * This may be a shared rail so don't specify a maximum. * Regulator constraints will cap to the actual maximum.
*/
ret = regulator_set_voltage(priv->vcc, qfprom_blow_uV, INT_MAX); if (ret) {
dev_err(priv->dev, "Failed to set %duV\n", qfprom_blow_uV); goto err_clk_rate_set;
}
ret = regulator_enable(priv->vcc); if (ret) {
dev_err(priv->dev, "Failed to enable regulator\n"); goto err_clk_rate_set;
}
ret = pm_runtime_resume_and_get(priv->dev); if (ret < 0) {
dev_err(priv->dev, "Failed to enable power-domain\n"); goto err_reg_enable;
}
dev_pm_genpd_set_performance_state(priv->dev, INT_MAX);
/** * qfprom_reg_write() - Write to fuses. * @context: Our driver data. * @reg: The offset to write at. * @_val: Pointer to data to write. * @bytes: The number of bytes to write. * * Writes to fuses. WARNING: THIS IS PERMANENT. * * Return: 0 or -err.
*/ staticint qfprom_reg_write(void *context, unsignedint reg, void *_val,
size_t bytes)
{ struct qfprom_priv *priv = context; struct qfprom_touched_values old; int words = bytes / 4;
u32 *value = _val;
u32 blow_status; int ret; int i;
dev_dbg(priv->dev, "Writing to raw qfprom region : %#010x of size: %zu\n",
reg, bytes);
/* * The hardware only allows us to write word at a time, but we can * read byte at a time. Until the nvmem framework allows a separate * word_size and stride for reading vs. writing, we'll enforce here.
*/ if (bytes % 4) {
dev_err(priv->dev, "%zu is not an integral number of words\n", bytes); return -EINVAL;
} if (reg % 4) {
dev_err(priv->dev, "Invalid offset: %#x. Must be word aligned\n", reg); return -EINVAL;
}
ret = qfprom_enable_fuse_blowing(priv, &old); if (ret) return ret;
/* * If more than one region is provided then the OS has the ability * to write.
*/
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); if (res) {
u32 version; int major_version, minor_version;
priv->qfpraw = devm_ioremap_resource(dev, res); if (IS_ERR(priv->qfpraw)) return PTR_ERR(priv->qfpraw);
priv->qfpconf = devm_platform_ioremap_resource(pdev, 2); if (IS_ERR(priv->qfpconf)) return PTR_ERR(priv->qfpconf);
priv->qfpsecurity = devm_platform_ioremap_resource(pdev, 3); if (IS_ERR(priv->qfpsecurity)) return PTR_ERR(priv->qfpsecurity);
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.