9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 1) // SPDX-License-Identifier: GPL-2.0
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 2) /*
0e510bf1b881e (Alexander A. Klimov 2020-07-13 20:05:16 +0200 3) * Copyright (C) 2016-2017 Texas Instruments Incorporated - https://www.ti.com/
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 4) * Nishanth Menon <nm@ti.com>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 5) * Dave Gerlach <d-gerlach@ti.com>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 6) *
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 7) * TI OPP supply driver that provides override into the regulator control
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 8) * for generic opp core to handle devices with ABB regulator and/or
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 9) * SmartReflex Class0.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 10) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 11) #include <linux/clk.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 12) #include <linux/cpufreq.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 13) #include <linux/device.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 14) #include <linux/io.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 15) #include <linux/module.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 16) #include <linux/notifier.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 17) #include <linux/of_device.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 18) #include <linux/of.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 19) #include <linux/platform_device.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 20) #include <linux/pm_opp.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 21) #include <linux/regulator/consumer.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 22) #include <linux/slab.h>
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 23)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 24) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 25) * struct ti_opp_supply_optimum_voltage_table - optimized voltage table
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 26) * @reference_uv: reference voltage (usually Nominal voltage)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 27) * @optimized_uv: Optimized voltage from efuse
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 28) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 29) struct ti_opp_supply_optimum_voltage_table {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 30) unsigned int reference_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 31) unsigned int optimized_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 32) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 33)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 34) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 35) * struct ti_opp_supply_data - OMAP specific opp supply data
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 36) * @vdd_table: Optimized voltage mapping table
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 37) * @num_vdd_table: number of entries in vdd_table
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 38) * @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the supply
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 39) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 40) struct ti_opp_supply_data {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 41) struct ti_opp_supply_optimum_voltage_table *vdd_table;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 42) u32 num_vdd_table;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 43) u32 vdd_absolute_max_voltage_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 44) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 45)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 46) static struct ti_opp_supply_data opp_data;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 47)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 48) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 49) * struct ti_opp_supply_of_data - device tree match data
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 50) * @flags: specific type of opp supply
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 51) * @efuse_voltage_mask: mask required for efuse register representing voltage
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 52) * @efuse_voltage_uv: Are the efuse entries in micro-volts? if not, assume
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 53) * milli-volts.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 54) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 55) struct ti_opp_supply_of_data {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 56) #define OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE BIT(1)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 57) #define OPPDM_HAS_NO_ABB BIT(2)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 58) const u8 flags;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 59) const u32 efuse_voltage_mask;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 60) const bool efuse_voltage_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 61) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 62)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 63) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 64) * _store_optimized_voltages() - store optimized voltages
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 65) * @dev: ti opp supply device for which we need to store info
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 66) * @data: data specific to the device
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 67) *
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 68) * Picks up efuse based optimized voltages for VDD unique per device and
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 69) * stores it in internal data structure for use during transition requests.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 70) *
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 71) * Return: If successful, 0, else appropriate error value.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 72) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 73) static int _store_optimized_voltages(struct device *dev,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 74) struct ti_opp_supply_data *data)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 75) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 76) void __iomem *base;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 77) struct property *prop;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 78) struct resource *res;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 79) const __be32 *val;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 80) int proplen, i;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 81) int ret = 0;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 82) struct ti_opp_supply_optimum_voltage_table *table;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 83) const struct ti_opp_supply_of_data *of_data = dev_get_drvdata(dev);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 84)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 85) /* pick up Efuse based voltages */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 86) res = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 0);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 87) if (!res) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 88) dev_err(dev, "Unable to get IO resource\n");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 89) ret = -ENODEV;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 90) goto out_map;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 91) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 92)
4bdc0d676a643 (Christoph Hellwig 2020-01-06 09:43:50 +0100 93) base = ioremap(res->start, resource_size(res));
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 94) if (!base) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 95) dev_err(dev, "Unable to map Efuse registers\n");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 96) ret = -ENOMEM;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 97) goto out_map;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 98) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 99)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 100) /* Fetch efuse-settings. */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 101) prop = of_find_property(dev->of_node, "ti,efuse-settings", NULL);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 102) if (!prop) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 103) dev_err(dev, "No 'ti,efuse-settings' property found\n");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 104) ret = -EINVAL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 105) goto out;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 106) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 107)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 108) proplen = prop->length / sizeof(int);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 109) data->num_vdd_table = proplen / 2;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 110) /* Verify for corrupted OPP entries in dt */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 111) if (data->num_vdd_table * 2 * sizeof(int) != prop->length) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 112) dev_err(dev, "Invalid 'ti,efuse-settings'\n");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 113) ret = -EINVAL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 114) goto out;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 115) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 116)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 117) ret = of_property_read_u32(dev->of_node, "ti,absolute-max-voltage-uv",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 118) &data->vdd_absolute_max_voltage_uv);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 119) if (ret) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 120) dev_err(dev, "ti,absolute-max-voltage-uv is missing\n");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 121) ret = -EINVAL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 122) goto out;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 123) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 124)
6396bb221514d (Kees Cook 2018-06-12 14:03:40 -0700 125) table = kcalloc(data->num_vdd_table, sizeof(*data->vdd_table),
6396bb221514d (Kees Cook 2018-06-12 14:03:40 -0700 126) GFP_KERNEL);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 127) if (!table) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 128) ret = -ENOMEM;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 129) goto out;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 130) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 131) data->vdd_table = table;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 132)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 133) val = prop->value;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 134) for (i = 0; i < data->num_vdd_table; i++, table++) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 135) u32 efuse_offset;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 136) u32 tmp;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 137)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 138) table->reference_uv = be32_to_cpup(val++);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 139) efuse_offset = be32_to_cpup(val++);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 140)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 141) tmp = readl(base + efuse_offset);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 142) tmp &= of_data->efuse_voltage_mask;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 143) tmp >>= __ffs(of_data->efuse_voltage_mask);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 144)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 145) table->optimized_uv = of_data->efuse_voltage_uv ? tmp :
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 146) tmp * 1000;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 147)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 148) dev_dbg(dev, "[%d] efuse=0x%08x volt_table=%d vset=%d\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 149) i, efuse_offset, table->reference_uv,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 150) table->optimized_uv);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 151)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 152) /*
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 153) * Some older samples might not have optimized efuse
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 154) * Use reference voltage for those - just add debug message
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 155) * for them.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 156) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 157) if (!table->optimized_uv) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 158) dev_dbg(dev, "[%d] efuse=0x%08x volt_table=%d:vset0\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 159) i, efuse_offset, table->reference_uv);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 160) table->optimized_uv = table->reference_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 161) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 162) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 163) out:
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 164) iounmap(base);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 165) out_map:
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 166) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 167) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 168)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 169) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 170) * _free_optimized_voltages() - free resources for optvoltages
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 171) * @dev: device for which we need to free info
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 172) * @data: data specific to the device
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 173) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 174) static void _free_optimized_voltages(struct device *dev,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 175) struct ti_opp_supply_data *data)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 176) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 177) kfree(data->vdd_table);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 178) data->vdd_table = NULL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 179) data->num_vdd_table = 0;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 180) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 181)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 182) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 183) * _get_optimal_vdd_voltage() - Finds optimal voltage for the supply
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 184) * @dev: device for which we need to find info
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 185) * @data: data specific to the device
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 186) * @reference_uv: reference voltage (OPP voltage) for which we need value
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 187) *
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 188) * Return: if a match is found, return optimized voltage, else return
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 189) * reference_uv, also return reference_uv if no optimization is needed.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 190) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 191) static int _get_optimal_vdd_voltage(struct device *dev,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 192) struct ti_opp_supply_data *data,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 193) int reference_uv)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 194) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 195) int i;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 196) struct ti_opp_supply_optimum_voltage_table *table;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 197)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 198) if (!data->num_vdd_table)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 199) return reference_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 200)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 201) table = data->vdd_table;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 202) if (!table)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 203) return -EINVAL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 204)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 205) /* Find a exact match - this list is usually very small */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 206) for (i = 0; i < data->num_vdd_table; i++, table++)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 207) if (table->reference_uv == reference_uv)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 208) return table->optimized_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 209)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 210) /* IF things are screwed up, we'd make a mess on console.. ratelimit */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 211) dev_err_ratelimited(dev, "%s: Failed optimized voltage match for %d\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 212) __func__, reference_uv);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 213) return reference_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 214) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 215)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 216) static int _opp_set_voltage(struct device *dev,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 217) struct dev_pm_opp_supply *supply,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 218) int new_target_uv, struct regulator *reg,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 219) char *reg_name)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 220) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 221) int ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 222) unsigned long vdd_uv, uv_max;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 223)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 224) if (new_target_uv)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 225) vdd_uv = new_target_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 226) else
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 227) vdd_uv = supply->u_volt;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 228)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 229) /*
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 230) * If we do have an absolute max voltage specified, then we should
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 231) * use that voltage instead to allow for cases where the voltage rails
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 232) * are ganged (example if we set the max for an opp as 1.12v, and
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 233) * the absolute max is 1.5v, for another rail to get 1.25v, it cannot
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 234) * be achieved if the regulator is constrainted to max of 1.12v, even
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 235) * if it can function at 1.25v
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 236) */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 237) if (opp_data.vdd_absolute_max_voltage_uv)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 238) uv_max = opp_data.vdd_absolute_max_voltage_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 239) else
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 240) uv_max = supply->u_volt_max;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 241)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 242) if (vdd_uv > uv_max ||
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 243) vdd_uv < supply->u_volt_min ||
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 244) supply->u_volt_min > uv_max) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 245) dev_warn(dev,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 246) "Invalid range voltages [Min:%lu target:%lu Max:%lu]\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 247) supply->u_volt_min, vdd_uv, uv_max);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 248) return -EINVAL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 249) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 250)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 251) dev_dbg(dev, "%s scaling to %luuV[min %luuV max %luuV]\n", reg_name,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 252) vdd_uv, supply->u_volt_min,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 253) uv_max);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 254)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 255) ret = regulator_set_voltage_triplet(reg,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 256) supply->u_volt_min,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 257) vdd_uv,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 258) uv_max);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 259) if (ret) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 260) dev_err(dev, "%s failed for %luuV[min %luuV max %luuV]\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 261) reg_name, vdd_uv, supply->u_volt_min,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 262) uv_max);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 263) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 264) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 265)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 266) return 0;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 267) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 268)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 269) /**
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 270) * ti_opp_supply_set_opp() - do the opp supply transition
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 271) * @data: information on regulators and new and old opps provided by
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 272) * opp core to use in transition
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 273) *
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 274) * Return: If successful, 0, else appropriate error value.
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 275) */
3eff5f67a2199 (Wei Yongjun 2017-12-20 05:44:40 +0000 276) static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 277) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 278) struct dev_pm_opp_supply *old_supply_vdd = &data->old_opp.supplies[0];
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 279) struct dev_pm_opp_supply *old_supply_vbb = &data->old_opp.supplies[1];
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 280) struct dev_pm_opp_supply *new_supply_vdd = &data->new_opp.supplies[0];
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 281) struct dev_pm_opp_supply *new_supply_vbb = &data->new_opp.supplies[1];
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 282) struct device *dev = data->dev;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 283) unsigned long old_freq = data->old_opp.rate, freq = data->new_opp.rate;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 284) struct clk *clk = data->clk;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 285) struct regulator *vdd_reg = data->regulators[0];
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 286) struct regulator *vbb_reg = data->regulators[1];
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 287) int vdd_uv;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 288) int ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 289)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 290) vdd_uv = _get_optimal_vdd_voltage(dev, &opp_data,
622fecbccfe86 (Keerthy 2018-11-07 10:04:23 +0530 291) new_supply_vdd->u_volt);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 292)
ba038546ff9e1 (Keerthy 2018-11-07 10:04:22 +0530 293) if (new_supply_vdd->u_volt_min < vdd_uv)
ba038546ff9e1 (Keerthy 2018-11-07 10:04:22 +0530 294) new_supply_vdd->u_volt_min = vdd_uv;
ba038546ff9e1 (Keerthy 2018-11-07 10:04:22 +0530 295)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 296) /* Scaling up? Scale voltage before frequency */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 297) if (freq > old_freq) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 298) ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 299) "vdd");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 300) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 301) goto restore_voltage;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 302)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 303) ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 304) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 305) goto restore_voltage;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 306) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 307)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 308) /* Change frequency */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 309) dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 310) __func__, old_freq, freq);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 311)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 312) ret = clk_set_rate(clk, freq);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 313) if (ret) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 314) dev_err(dev, "%s: failed to set clock rate: %d\n", __func__,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 315) ret);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 316) goto restore_voltage;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 317) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 318)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 319) /* Scaling down? Scale voltage after frequency */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 320) if (freq < old_freq) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 321) ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 322) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 323) goto restore_freq;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 324)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 325) ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 326) "vdd");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 327) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 328) goto restore_freq;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 329) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 330)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 331) return 0;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 332)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 333) restore_freq:
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 334) ret = clk_set_rate(clk, old_freq);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 335) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 336) dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 337) __func__, old_freq);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 338) restore_voltage:
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 339) /* This shouldn't harm even if the voltages weren't updated earlier */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 340) if (old_supply_vdd->u_volt) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 341) ret = _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 342) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 343) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 344)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 345) ret = _opp_set_voltage(dev, old_supply_vdd, 0, vdd_reg,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 346) "vdd");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 347) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 348) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 349) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 350)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 351) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 352) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 353)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 354) static const struct ti_opp_supply_of_data omap_generic_of_data = {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 355) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 356)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 357) static const struct ti_opp_supply_of_data omap_omap5_of_data = {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 358) .flags = OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 359) .efuse_voltage_mask = 0xFFF,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 360) .efuse_voltage_uv = false,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 361) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 362)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 363) static const struct ti_opp_supply_of_data omap_omap5core_of_data = {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 364) .flags = OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE | OPPDM_HAS_NO_ABB,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 365) .efuse_voltage_mask = 0xFFF,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 366) .efuse_voltage_uv = false,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 367) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 368)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 369) static const struct of_device_id ti_opp_supply_of_match[] = {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 370) {.compatible = "ti,omap-opp-supply", .data = &omap_generic_of_data},
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 371) {.compatible = "ti,omap5-opp-supply", .data = &omap_omap5_of_data},
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 372) {.compatible = "ti,omap5-core-opp-supply",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 373) .data = &omap_omap5core_of_data},
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 374) {},
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 375) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 376) MODULE_DEVICE_TABLE(of, ti_opp_supply_of_match);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 377)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 378) static int ti_opp_supply_probe(struct platform_device *pdev)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 379) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 380) struct device *dev = &pdev->dev;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 381) struct device *cpu_dev = get_cpu_device(0);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 382) const struct of_device_id *match;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 383) const struct ti_opp_supply_of_data *of_data;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 384) int ret = 0;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 385)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 386) match = of_match_device(ti_opp_supply_of_match, dev);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 387) if (!match) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 388) /* We do not expect this to happen */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 389) dev_err(dev, "%s: Unable to match device\n", __func__);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 390) return -ENODEV;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 391) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 392) if (!match->data) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 393) /* Again, unlikely.. but mistakes do happen */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 394) dev_err(dev, "%s: Bad data in match\n", __func__);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 395) return -EINVAL;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 396) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 397) of_data = match->data;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 398)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 399) dev_set_drvdata(dev, (void *)of_data);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 400)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 401) /* If we need optimized voltage */
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 402) if (of_data->flags & OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE) {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 403) ret = _store_optimized_voltages(dev, &opp_data);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 404) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 405) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 406) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 407)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 408) ret = PTR_ERR_OR_ZERO(dev_pm_opp_register_set_opp_helper(cpu_dev,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 409) ti_opp_supply_set_opp));
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 410) if (ret)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 411) _free_optimized_voltages(dev, &opp_data);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 412)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 413) return ret;
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 414) }
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 415)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 416) static struct platform_driver ti_opp_supply_driver = {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 417) .probe = ti_opp_supply_probe,
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 418) .driver = {
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 419) .name = "ti_opp_supply",
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 420) .of_match_table = of_match_ptr(ti_opp_supply_of_match),
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 421) },
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 422) };
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 423) module_platform_driver(ti_opp_supply_driver);
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 424)
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 425) MODULE_DESCRIPTION("Texas Instruments OMAP OPP Supply driver");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 426) MODULE_AUTHOR("Texas Instruments Inc.");
9a835fa6e47f2 (Dave Gerlach 2017-12-14 22:25:28 -0600 427) MODULE_LICENSE("GPL v2");