soc: rockchip: opp_select: Export rockchip_nvmem_cell_read_u8/u16()

Change-Id: I1c231afce31da9f42cd92839540d8dcb675778ce
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
This commit is contained in:
Finley Xiao
2021-06-30 15:13:47 +08:00
parent 01243dd90a
commit 7f0e1711ed
5 changed files with 55 additions and 66 deletions

View File

@@ -58,14 +58,15 @@ static LIST_HEAD(cluster_info_list);
static int px30_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
int ret = 0, value = -EINVAL;
int ret = 0;
u8 value = 0;
if (!bin)
return 0;
if (of_property_match_string(np, "nvmem-cell-names",
"performance") >= 0) {
ret = rockchip_get_efuse_value(np, "performance", &value);
ret = rockchip_nvmem_cell_read_u8(np, "performance", &value);
if (ret) {
dev_err(dev, "Failed to get soc performance value\n");
return ret;
@@ -81,13 +82,14 @@ static int px30_get_soc_info(struct device *dev, struct device_node *np,
static int rk3288_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
int ret = 0, value = -EINVAL;
int ret = 0;
u8 value = 0;
char *name;
if (!bin)
goto next;
if (of_property_match_string(np, "nvmem-cell-names", "special") >= 0) {
ret = rockchip_get_efuse_value(np, "special", &value);
ret = rockchip_nvmem_cell_read_u8(np, "special", &value);
if (ret) {
dev_err(dev, "Failed to get soc special value\n");
goto out;
@@ -104,7 +106,7 @@ static int rk3288_get_soc_info(struct device *dev, struct device_node *np,
name = "performance";
if (of_property_match_string(np, "nvmem-cell-names", name) >= 0) {
ret = rockchip_get_efuse_value(np, name, &value);
ret = rockchip_nvmem_cell_read_u8(np, name, &value);
if (ret) {
dev_err(dev, "Failed to get soc performance value\n");
goto out;
@@ -122,7 +124,7 @@ next:
goto out;
if (of_property_match_string(np, "nvmem-cell-names",
"process") >= 0) {
ret = rockchip_get_efuse_value(np, "process", &value);
ret = rockchip_nvmem_cell_read_u8(np, "process", &value);
if (ret) {
dev_err(dev, "Failed to get soc process version\n");
goto out;
@@ -140,16 +142,17 @@ out:
static int rk3399_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
int ret = 0, value = -EINVAL;
int ret = 0;
u8 value = 0;
if (!bin)
return 0;
if (of_property_match_string(np, "nvmem-cell-names",
"specification_serial_number") >= 0) {
ret = rockchip_get_efuse_value(np,
"specification_serial_number",
&value);
ret = rockchip_nvmem_cell_read_u8(np,
"specification_serial_number",
&value);
if (ret) {
dev_err(dev,
"Failed to get specification_serial_number\n");
@@ -161,9 +164,9 @@ static int rk3399_get_soc_info(struct device *dev, struct device_node *np,
} else if (value == 0x1) {
if (of_property_match_string(np, "nvmem-cell-names",
"customer_demand") >= 0) {
ret = rockchip_get_efuse_value(np,
"customer_demand",
&value);
ret = rockchip_nvmem_cell_read_u8(np,
"customer_demand",
&value);
if (ret) {
dev_err(dev, "Failed to get customer_demand\n");
goto out;
@@ -188,10 +191,11 @@ out:
static int rv1126_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
int ret = 0, value = -EINVAL;
int ret = 0;
u8 value = 0;
if (of_property_match_string(np, "nvmem-cell-names", "performance") >= 0) {
ret = rockchip_get_efuse_value(np, "performance", &value);
ret = rockchip_nvmem_cell_read_u8(np, "performance", &value);
if (ret) {
dev_err(dev, "Failed to get soc performance value\n");
return ret;

View File

@@ -434,7 +434,8 @@ static void kbase_platform_rk_remove_sysfs_files(struct device *dev)
static int rk3288_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
int ret = -EINVAL, value = -EINVAL;
int ret = -EINVAL;
u8 value = 0;
char *name;
if (!bin)
@@ -445,7 +446,7 @@ static int rk3288_get_soc_info(struct device *dev, struct device_node *np,
else
name = "performance";
if (of_property_match_string(np, "nvmem-cell-names", name) >= 0) {
ret = rockchip_get_efuse_value(np, name, &value);
ret = rockchip_nvmem_cell_read_u8(np, name, &value);
if (ret) {
dev_err(dev, "Failed to get soc performance value\n");
goto out;

View File

@@ -22,7 +22,6 @@
#define MAX_PROP_NAME_LEN 6
#define SEL_TABLE_END ~1
#define LEAKAGE_INVALID 0xff
#define AVS_DELETE_OPP 0
#define AVS_SCALING_RATE 1
@@ -120,35 +119,6 @@ static const struct lkg_conversion_table conv_table[] = {
{ 400, 53 },
};
int rockchip_get_efuse_value(struct device_node *np, char *porp_name,
int *value)
{
struct nvmem_cell *cell;
unsigned char *buf;
size_t len;
cell = of_nvmem_cell_get(np, porp_name);
if (IS_ERR(cell))
return PTR_ERR(cell);
buf = (unsigned char *)nvmem_cell_read(cell, &len);
nvmem_cell_put(cell);
if (IS_ERR(buf))
return PTR_ERR(buf);
if (buf[0] == LEAKAGE_INVALID)
return -EINVAL;
*value = buf[0];
kfree(buf);
return 0;
}
EXPORT_SYMBOL(rockchip_get_efuse_value);
static int rockchip_nvmem_cell_read_common(struct device_node *np,
const char *cell_id,
void *val, size_t count)
@@ -178,19 +148,19 @@ static int rockchip_nvmem_cell_read_common(struct device_node *np,
return 0;
}
static int rockchip_nvmem_cell_read_u8(struct device_node *np,
const char *cell_id,
u8 *val)
int rockchip_nvmem_cell_read_u8(struct device_node *np, const char *cell_id,
u8 *val)
{
return rockchip_nvmem_cell_read_common(np, cell_id, val, sizeof(*val));
}
EXPORT_SYMBOL(rockchip_nvmem_cell_read_u8);
static int rockchip_nvmem_cell_read_u16(struct device_node *np,
const char *cell_id,
u16 *val)
int rockchip_nvmem_cell_read_u16(struct device_node *np, const char *cell_id,
u16 *val)
{
return rockchip_nvmem_cell_read_common(np, cell_id, val, sizeof(*val));
}
EXPORT_SYMBOL(rockchip_nvmem_cell_read_u16);
static int rockchip_get_sel_table(struct device_node *np, char *porp_name,
struct sel_table **table)
@@ -503,7 +473,8 @@ static int rockchip_adjust_leakage(struct device *dev, struct device_node *np,
int *leakage)
{
struct nvmem_cell *cell;
u32 value = 0, temp;
u8 value = 0;
u32 temp;
int conversion;
int ret;
@@ -511,7 +482,7 @@ static int rockchip_adjust_leakage(struct device *dev, struct device_node *np,
if (IS_ERR(cell))
goto next;
nvmem_cell_put(cell);
ret = rockchip_get_efuse_value(np, "leakage_temp", &value);
ret = rockchip_nvmem_cell_read_u8(np, "leakage_temp", &value);
if (ret) {
dev_err(dev, "Failed to get leakage temp\n");
return -EINVAL;
@@ -523,7 +494,8 @@ static int rockchip_adjust_leakage(struct device *dev, struct device_node *np,
* The ambient temp : temp = (temp_efuse / 63) * (40 - 20) + 20
* Reserves a decimal point : temp = temp * 10
*/
temp = mul_frac((int_to_frac(value) / 63 * 20 + int_to_frac(20)),
temp = value;
temp = mul_frac((int_to_frac(temp) / 63 * 20 + int_to_frac(20)),
int_to_frac(10));
conversion = temp_to_conversion_rate(frac_to_int(temp));
*leakage = *leakage * conversion / 100;
@@ -533,7 +505,7 @@ next:
if (IS_ERR(cell))
return 0;
nvmem_cell_put(cell);
ret = rockchip_get_efuse_value(np, "leakage_volt", &value);
ret = rockchip_nvmem_cell_read_u8(np, "leakage_volt", &value);
if (ret) {
dev_err(dev, "Failed to get leakage volt\n");
return -EINVAL;
@@ -569,16 +541,19 @@ static int rockchip_get_leakage_v1(struct device *dev, struct device_node *np,
{
struct nvmem_cell *cell;
int ret = 0;
u8 value = 0;
cell = of_nvmem_cell_get(np, "leakage");
if (IS_ERR(cell)) {
ret = rockchip_get_efuse_value(np, lkg_name, leakage);
ret = rockchip_nvmem_cell_read_u8(np, lkg_name, &value);
} else {
nvmem_cell_put(cell);
ret = rockchip_get_efuse_value(np, "leakage", leakage);
ret = rockchip_nvmem_cell_read_u8(np, "leakage", &value);
}
if (ret)
dev_err(dev, "Failed to get %s\n", lkg_name);
else
*leakage = value;
return ret;
}

View File

@@ -964,10 +964,11 @@ static struct monitor_dev_profile enc_mdevp = {
static int rv1126_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
int ret = 0, value = -EINVAL;
int ret = 0;
u8 value = 0;
if (of_property_match_string(np, "nvmem-cell-names", "performance") >= 0) {
ret = rockchip_get_efuse_value(np, "performance", &value);
ret = rockchip_nvmem_cell_read_u8(np, "performance", &value);
if (ret) {
dev_err(dev, "Failed to get soc performance value\n");
return ret;

View File

@@ -18,8 +18,10 @@ void rockchip_of_get_bin_sel(struct device *dev, struct device_node *np,
int bin, int *scale_sel);
void rockchip_of_get_bin_volt_sel(struct device *dev, struct device_node *np,
int bin, int *bin_volt_sel);
int rockchip_get_efuse_value(struct device_node *np, char *porp_name,
int *value);
int rockchip_nvmem_cell_read_u8(struct device_node *np, const char *cell_id,
u8 *val);
int rockchip_nvmem_cell_read_u16(struct device_node *np, const char *cell_id,
u16 *val);
void rockchip_get_soc_info(struct device *dev,
const struct of_device_id *matches,
int *bin, int *process);
@@ -65,10 +67,16 @@ static inline void rockchip_of_get_bin_volt_sel(struct device *dev,
{
}
static inline int rockchip_get_efuse_value(struct device_node *np,
char *porp_name, int *value)
static inline int rockchip_nvmem_cell_read_u8(struct device_node *np,
const char *cell_id, u8 *val)
{
return -ENOTSUPP;
return -EOPNOTSUPP;
}
static inline int rockchip_nvmem_cell_read_u16(struct device_node *np,
const char *cell_id, u16 *val)
{
return -EOPNOTSUPP;
}
static inline void rockchip_get_soc_info(struct device *dev,