19a835fa6SDave Gerlach // SPDX-License-Identifier: GPL-2.0
29a835fa6SDave Gerlach /*
30e510bf1SAlexander A. Klimov * Copyright (C) 2016-2017 Texas Instruments Incorporated - https://www.ti.com/
49a835fa6SDave Gerlach * Nishanth Menon <nm@ti.com>
59a835fa6SDave Gerlach * Dave Gerlach <d-gerlach@ti.com>
69a835fa6SDave Gerlach *
79a835fa6SDave Gerlach * TI OPP supply driver that provides override into the regulator control
89a835fa6SDave Gerlach * for generic opp core to handle devices with ABB regulator and/or
99a835fa6SDave Gerlach * SmartReflex Class0.
109a835fa6SDave Gerlach */
119a835fa6SDave Gerlach #include <linux/clk.h>
129a835fa6SDave Gerlach #include <linux/cpufreq.h>
139a835fa6SDave Gerlach #include <linux/device.h>
149a835fa6SDave Gerlach #include <linux/io.h>
159a835fa6SDave Gerlach #include <linux/module.h>
169a835fa6SDave Gerlach #include <linux/notifier.h>
179a835fa6SDave Gerlach #include <linux/of_device.h>
189a835fa6SDave Gerlach #include <linux/of.h>
199a835fa6SDave Gerlach #include <linux/platform_device.h>
209a835fa6SDave Gerlach #include <linux/pm_opp.h>
219a835fa6SDave Gerlach #include <linux/regulator/consumer.h>
229a835fa6SDave Gerlach #include <linux/slab.h>
239a835fa6SDave Gerlach
249a835fa6SDave Gerlach /**
259a835fa6SDave Gerlach * struct ti_opp_supply_optimum_voltage_table - optimized voltage table
269a835fa6SDave Gerlach * @reference_uv: reference voltage (usually Nominal voltage)
279a835fa6SDave Gerlach * @optimized_uv: Optimized voltage from efuse
289a835fa6SDave Gerlach */
299a835fa6SDave Gerlach struct ti_opp_supply_optimum_voltage_table {
309a835fa6SDave Gerlach unsigned int reference_uv;
319a835fa6SDave Gerlach unsigned int optimized_uv;
329a835fa6SDave Gerlach };
339a835fa6SDave Gerlach
349a835fa6SDave Gerlach /**
359a835fa6SDave Gerlach * struct ti_opp_supply_data - OMAP specific opp supply data
369a835fa6SDave Gerlach * @vdd_table: Optimized voltage mapping table
379a835fa6SDave Gerlach * @num_vdd_table: number of entries in vdd_table
389a835fa6SDave Gerlach * @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the supply
396baee034SViresh Kumar * @old_supplies: Placeholder for supplies information for old OPP.
406baee034SViresh Kumar * @new_supplies: Placeholder for supplies information for new OPP.
419a835fa6SDave Gerlach */
429a835fa6SDave Gerlach struct ti_opp_supply_data {
439a835fa6SDave Gerlach struct ti_opp_supply_optimum_voltage_table *vdd_table;
449a835fa6SDave Gerlach u32 num_vdd_table;
459a835fa6SDave Gerlach u32 vdd_absolute_max_voltage_uv;
466baee034SViresh Kumar struct dev_pm_opp_supply old_supplies[2];
476baee034SViresh Kumar struct dev_pm_opp_supply new_supplies[2];
489a835fa6SDave Gerlach };
499a835fa6SDave Gerlach
509a835fa6SDave Gerlach static struct ti_opp_supply_data opp_data;
519a835fa6SDave Gerlach
529a835fa6SDave Gerlach /**
539a835fa6SDave Gerlach * struct ti_opp_supply_of_data - device tree match data
549a835fa6SDave Gerlach * @flags: specific type of opp supply
559a835fa6SDave Gerlach * @efuse_voltage_mask: mask required for efuse register representing voltage
569a835fa6SDave Gerlach * @efuse_voltage_uv: Are the efuse entries in micro-volts? if not, assume
579a835fa6SDave Gerlach * milli-volts.
589a835fa6SDave Gerlach */
599a835fa6SDave Gerlach struct ti_opp_supply_of_data {
609a835fa6SDave Gerlach #define OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE BIT(1)
619a835fa6SDave Gerlach #define OPPDM_HAS_NO_ABB BIT(2)
629a835fa6SDave Gerlach const u8 flags;
639a835fa6SDave Gerlach const u32 efuse_voltage_mask;
649a835fa6SDave Gerlach const bool efuse_voltage_uv;
659a835fa6SDave Gerlach };
669a835fa6SDave Gerlach
679a835fa6SDave Gerlach /**
689a835fa6SDave Gerlach * _store_optimized_voltages() - store optimized voltages
699a835fa6SDave Gerlach * @dev: ti opp supply device for which we need to store info
709a835fa6SDave Gerlach * @data: data specific to the device
719a835fa6SDave Gerlach *
729a835fa6SDave Gerlach * Picks up efuse based optimized voltages for VDD unique per device and
739a835fa6SDave Gerlach * stores it in internal data structure for use during transition requests.
749a835fa6SDave Gerlach *
759a835fa6SDave Gerlach * Return: If successful, 0, else appropriate error value.
769a835fa6SDave Gerlach */
_store_optimized_voltages(struct device * dev,struct ti_opp_supply_data * data)779a835fa6SDave Gerlach static int _store_optimized_voltages(struct device *dev,
789a835fa6SDave Gerlach struct ti_opp_supply_data *data)
799a835fa6SDave Gerlach {
809a835fa6SDave Gerlach void __iomem *base;
819a835fa6SDave Gerlach struct property *prop;
829a835fa6SDave Gerlach struct resource *res;
839a835fa6SDave Gerlach const __be32 *val;
849a835fa6SDave Gerlach int proplen, i;
859a835fa6SDave Gerlach int ret = 0;
869a835fa6SDave Gerlach struct ti_opp_supply_optimum_voltage_table *table;
879a835fa6SDave Gerlach const struct ti_opp_supply_of_data *of_data = dev_get_drvdata(dev);
889a835fa6SDave Gerlach
899a835fa6SDave Gerlach /* pick up Efuse based voltages */
909a835fa6SDave Gerlach res = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 0);
919a835fa6SDave Gerlach if (!res) {
929a835fa6SDave Gerlach dev_err(dev, "Unable to get IO resource\n");
939a835fa6SDave Gerlach ret = -ENODEV;
949a835fa6SDave Gerlach goto out_map;
959a835fa6SDave Gerlach }
969a835fa6SDave Gerlach
974bdc0d67SChristoph Hellwig base = ioremap(res->start, resource_size(res));
989a835fa6SDave Gerlach if (!base) {
999a835fa6SDave Gerlach dev_err(dev, "Unable to map Efuse registers\n");
1009a835fa6SDave Gerlach ret = -ENOMEM;
1019a835fa6SDave Gerlach goto out_map;
1029a835fa6SDave Gerlach }
1039a835fa6SDave Gerlach
1049a835fa6SDave Gerlach /* Fetch efuse-settings. */
1059a835fa6SDave Gerlach prop = of_find_property(dev->of_node, "ti,efuse-settings", NULL);
1069a835fa6SDave Gerlach if (!prop) {
1079a835fa6SDave Gerlach dev_err(dev, "No 'ti,efuse-settings' property found\n");
1089a835fa6SDave Gerlach ret = -EINVAL;
1099a835fa6SDave Gerlach goto out;
1109a835fa6SDave Gerlach }
1119a835fa6SDave Gerlach
1129a835fa6SDave Gerlach proplen = prop->length / sizeof(int);
1139a835fa6SDave Gerlach data->num_vdd_table = proplen / 2;
1149a835fa6SDave Gerlach /* Verify for corrupted OPP entries in dt */
1159a835fa6SDave Gerlach if (data->num_vdd_table * 2 * sizeof(int) != prop->length) {
1169a835fa6SDave Gerlach dev_err(dev, "Invalid 'ti,efuse-settings'\n");
1179a835fa6SDave Gerlach ret = -EINVAL;
1189a835fa6SDave Gerlach goto out;
1199a835fa6SDave Gerlach }
1209a835fa6SDave Gerlach
1219a835fa6SDave Gerlach ret = of_property_read_u32(dev->of_node, "ti,absolute-max-voltage-uv",
1229a835fa6SDave Gerlach &data->vdd_absolute_max_voltage_uv);
1239a835fa6SDave Gerlach if (ret) {
1249a835fa6SDave Gerlach dev_err(dev, "ti,absolute-max-voltage-uv is missing\n");
1259a835fa6SDave Gerlach ret = -EINVAL;
1269a835fa6SDave Gerlach goto out;
1279a835fa6SDave Gerlach }
1289a835fa6SDave Gerlach
1296396bb22SKees Cook table = kcalloc(data->num_vdd_table, sizeof(*data->vdd_table),
1306396bb22SKees Cook GFP_KERNEL);
1319a835fa6SDave Gerlach if (!table) {
1329a835fa6SDave Gerlach ret = -ENOMEM;
1339a835fa6SDave Gerlach goto out;
1349a835fa6SDave Gerlach }
1359a835fa6SDave Gerlach data->vdd_table = table;
1369a835fa6SDave Gerlach
1379a835fa6SDave Gerlach val = prop->value;
1389a835fa6SDave Gerlach for (i = 0; i < data->num_vdd_table; i++, table++) {
1399a835fa6SDave Gerlach u32 efuse_offset;
1409a835fa6SDave Gerlach u32 tmp;
1419a835fa6SDave Gerlach
1429a835fa6SDave Gerlach table->reference_uv = be32_to_cpup(val++);
1439a835fa6SDave Gerlach efuse_offset = be32_to_cpup(val++);
1449a835fa6SDave Gerlach
1459a835fa6SDave Gerlach tmp = readl(base + efuse_offset);
1469a835fa6SDave Gerlach tmp &= of_data->efuse_voltage_mask;
1479a835fa6SDave Gerlach tmp >>= __ffs(of_data->efuse_voltage_mask);
1489a835fa6SDave Gerlach
1499a835fa6SDave Gerlach table->optimized_uv = of_data->efuse_voltage_uv ? tmp :
1509a835fa6SDave Gerlach tmp * 1000;
1519a835fa6SDave Gerlach
1529a835fa6SDave Gerlach dev_dbg(dev, "[%d] efuse=0x%08x volt_table=%d vset=%d\n",
1539a835fa6SDave Gerlach i, efuse_offset, table->reference_uv,
1549a835fa6SDave Gerlach table->optimized_uv);
1559a835fa6SDave Gerlach
1569a835fa6SDave Gerlach /*
1579a835fa6SDave Gerlach * Some older samples might not have optimized efuse
1589a835fa6SDave Gerlach * Use reference voltage for those - just add debug message
1599a835fa6SDave Gerlach * for them.
1609a835fa6SDave Gerlach */
1619a835fa6SDave Gerlach if (!table->optimized_uv) {
1629a835fa6SDave Gerlach dev_dbg(dev, "[%d] efuse=0x%08x volt_table=%d:vset0\n",
1639a835fa6SDave Gerlach i, efuse_offset, table->reference_uv);
1649a835fa6SDave Gerlach table->optimized_uv = table->reference_uv;
1659a835fa6SDave Gerlach }
1669a835fa6SDave Gerlach }
1679a835fa6SDave Gerlach out:
1689a835fa6SDave Gerlach iounmap(base);
1699a835fa6SDave Gerlach out_map:
1709a835fa6SDave Gerlach return ret;
1719a835fa6SDave Gerlach }
1729a835fa6SDave Gerlach
1739a835fa6SDave Gerlach /**
1749a835fa6SDave Gerlach * _free_optimized_voltages() - free resources for optvoltages
1759a835fa6SDave Gerlach * @dev: device for which we need to free info
1769a835fa6SDave Gerlach * @data: data specific to the device
1779a835fa6SDave Gerlach */
_free_optimized_voltages(struct device * dev,struct ti_opp_supply_data * data)1789a835fa6SDave Gerlach static void _free_optimized_voltages(struct device *dev,
1799a835fa6SDave Gerlach struct ti_opp_supply_data *data)
1809a835fa6SDave Gerlach {
1819a835fa6SDave Gerlach kfree(data->vdd_table);
1829a835fa6SDave Gerlach data->vdd_table = NULL;
1839a835fa6SDave Gerlach data->num_vdd_table = 0;
1849a835fa6SDave Gerlach }
1859a835fa6SDave Gerlach
1869a835fa6SDave Gerlach /**
1879a835fa6SDave Gerlach * _get_optimal_vdd_voltage() - Finds optimal voltage for the supply
1889a835fa6SDave Gerlach * @dev: device for which we need to find info
1899a835fa6SDave Gerlach * @data: data specific to the device
1909a835fa6SDave Gerlach * @reference_uv: reference voltage (OPP voltage) for which we need value
1919a835fa6SDave Gerlach *
1929a835fa6SDave Gerlach * Return: if a match is found, return optimized voltage, else return
1939a835fa6SDave Gerlach * reference_uv, also return reference_uv if no optimization is needed.
1949a835fa6SDave Gerlach */
_get_optimal_vdd_voltage(struct device * dev,struct ti_opp_supply_data * data,int reference_uv)1959a835fa6SDave Gerlach static int _get_optimal_vdd_voltage(struct device *dev,
1969a835fa6SDave Gerlach struct ti_opp_supply_data *data,
1979a835fa6SDave Gerlach int reference_uv)
1989a835fa6SDave Gerlach {
1999a835fa6SDave Gerlach int i;
2009a835fa6SDave Gerlach struct ti_opp_supply_optimum_voltage_table *table;
2019a835fa6SDave Gerlach
2029a835fa6SDave Gerlach if (!data->num_vdd_table)
2039a835fa6SDave Gerlach return reference_uv;
2049a835fa6SDave Gerlach
2059a835fa6SDave Gerlach table = data->vdd_table;
2069a835fa6SDave Gerlach if (!table)
2079a835fa6SDave Gerlach return -EINVAL;
2089a835fa6SDave Gerlach
2099a835fa6SDave Gerlach /* Find a exact match - this list is usually very small */
2109a835fa6SDave Gerlach for (i = 0; i < data->num_vdd_table; i++, table++)
2119a835fa6SDave Gerlach if (table->reference_uv == reference_uv)
2129a835fa6SDave Gerlach return table->optimized_uv;
2139a835fa6SDave Gerlach
2149a835fa6SDave Gerlach /* IF things are screwed up, we'd make a mess on console.. ratelimit */
2159a835fa6SDave Gerlach dev_err_ratelimited(dev, "%s: Failed optimized voltage match for %d\n",
2169a835fa6SDave Gerlach __func__, reference_uv);
2179a835fa6SDave Gerlach return reference_uv;
2189a835fa6SDave Gerlach }
2199a835fa6SDave Gerlach
_opp_set_voltage(struct device * dev,struct dev_pm_opp_supply * supply,int new_target_uv,struct regulator * reg,char * reg_name)2209a835fa6SDave Gerlach static int _opp_set_voltage(struct device *dev,
2219a835fa6SDave Gerlach struct dev_pm_opp_supply *supply,
2229a835fa6SDave Gerlach int new_target_uv, struct regulator *reg,
2239a835fa6SDave Gerlach char *reg_name)
2249a835fa6SDave Gerlach {
2259a835fa6SDave Gerlach int ret;
2269a835fa6SDave Gerlach unsigned long vdd_uv, uv_max;
2279a835fa6SDave Gerlach
2289a835fa6SDave Gerlach if (new_target_uv)
2299a835fa6SDave Gerlach vdd_uv = new_target_uv;
2309a835fa6SDave Gerlach else
2319a835fa6SDave Gerlach vdd_uv = supply->u_volt;
2329a835fa6SDave Gerlach
2339a835fa6SDave Gerlach /*
2349a835fa6SDave Gerlach * If we do have an absolute max voltage specified, then we should
2359a835fa6SDave Gerlach * use that voltage instead to allow for cases where the voltage rails
2369a835fa6SDave Gerlach * are ganged (example if we set the max for an opp as 1.12v, and
2379a835fa6SDave Gerlach * the absolute max is 1.5v, for another rail to get 1.25v, it cannot
2389a835fa6SDave Gerlach * be achieved if the regulator is constrainted to max of 1.12v, even
2399a835fa6SDave Gerlach * if it can function at 1.25v
2409a835fa6SDave Gerlach */
2419a835fa6SDave Gerlach if (opp_data.vdd_absolute_max_voltage_uv)
2429a835fa6SDave Gerlach uv_max = opp_data.vdd_absolute_max_voltage_uv;
2439a835fa6SDave Gerlach else
2449a835fa6SDave Gerlach uv_max = supply->u_volt_max;
2459a835fa6SDave Gerlach
2469a835fa6SDave Gerlach if (vdd_uv > uv_max ||
2479a835fa6SDave Gerlach vdd_uv < supply->u_volt_min ||
2489a835fa6SDave Gerlach supply->u_volt_min > uv_max) {
2499a835fa6SDave Gerlach dev_warn(dev,
2509a835fa6SDave Gerlach "Invalid range voltages [Min:%lu target:%lu Max:%lu]\n",
2519a835fa6SDave Gerlach supply->u_volt_min, vdd_uv, uv_max);
2529a835fa6SDave Gerlach return -EINVAL;
2539a835fa6SDave Gerlach }
2549a835fa6SDave Gerlach
2559a835fa6SDave Gerlach dev_dbg(dev, "%s scaling to %luuV[min %luuV max %luuV]\n", reg_name,
2569a835fa6SDave Gerlach vdd_uv, supply->u_volt_min,
2579a835fa6SDave Gerlach uv_max);
2589a835fa6SDave Gerlach
2599a835fa6SDave Gerlach ret = regulator_set_voltage_triplet(reg,
2609a835fa6SDave Gerlach supply->u_volt_min,
2619a835fa6SDave Gerlach vdd_uv,
2629a835fa6SDave Gerlach uv_max);
2639a835fa6SDave Gerlach if (ret) {
2649a835fa6SDave Gerlach dev_err(dev, "%s failed for %luuV[min %luuV max %luuV]\n",
2659a835fa6SDave Gerlach reg_name, vdd_uv, supply->u_volt_min,
2669a835fa6SDave Gerlach uv_max);
2679a835fa6SDave Gerlach return ret;
2689a835fa6SDave Gerlach }
2699a835fa6SDave Gerlach
2709a835fa6SDave Gerlach return 0;
2719a835fa6SDave Gerlach }
2729a835fa6SDave Gerlach
2736baee034SViresh Kumar /* Do the opp supply transition */
ti_opp_config_regulators(struct device * dev,struct dev_pm_opp * old_opp,struct dev_pm_opp * new_opp,struct regulator ** regulators,unsigned int count)2746baee034SViresh Kumar static int ti_opp_config_regulators(struct device *dev,
2756baee034SViresh Kumar struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
2766baee034SViresh Kumar struct regulator **regulators, unsigned int count)
2779a835fa6SDave Gerlach {
2786baee034SViresh Kumar struct dev_pm_opp_supply *old_supply_vdd = &opp_data.old_supplies[0];
2796baee034SViresh Kumar struct dev_pm_opp_supply *old_supply_vbb = &opp_data.old_supplies[1];
2806baee034SViresh Kumar struct dev_pm_opp_supply *new_supply_vdd = &opp_data.new_supplies[0];
2816baee034SViresh Kumar struct dev_pm_opp_supply *new_supply_vbb = &opp_data.new_supplies[1];
2826baee034SViresh Kumar struct regulator *vdd_reg = regulators[0];
2836baee034SViresh Kumar struct regulator *vbb_reg = regulators[1];
2846baee034SViresh Kumar unsigned long old_freq, freq;
2859a835fa6SDave Gerlach int vdd_uv;
2869a835fa6SDave Gerlach int ret;
2879a835fa6SDave Gerlach
2886baee034SViresh Kumar /* We must have two regulators here */
2896baee034SViresh Kumar WARN_ON(count != 2);
2906baee034SViresh Kumar
2916baee034SViresh Kumar /* Fetch supplies and freq information from OPP core */
2926baee034SViresh Kumar ret = dev_pm_opp_get_supplies(new_opp, opp_data.new_supplies);
2936baee034SViresh Kumar WARN_ON(ret);
2946baee034SViresh Kumar
2956baee034SViresh Kumar old_freq = dev_pm_opp_get_freq(old_opp);
2966baee034SViresh Kumar freq = dev_pm_opp_get_freq(new_opp);
2976baee034SViresh Kumar WARN_ON(!old_freq || !freq);
2986baee034SViresh Kumar
2999a835fa6SDave Gerlach vdd_uv = _get_optimal_vdd_voltage(dev, &opp_data,
300622fecbcSKeerthy new_supply_vdd->u_volt);
3019a835fa6SDave Gerlach
302ba038546SKeerthy if (new_supply_vdd->u_volt_min < vdd_uv)
303ba038546SKeerthy new_supply_vdd->u_volt_min = vdd_uv;
304ba038546SKeerthy
3059a835fa6SDave Gerlach /* Scaling up? Scale voltage before frequency */
3069a835fa6SDave Gerlach if (freq > old_freq) {
3079a835fa6SDave Gerlach ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
3089a835fa6SDave Gerlach "vdd");
3099a835fa6SDave Gerlach if (ret)
3109a835fa6SDave Gerlach goto restore_voltage;
3119a835fa6SDave Gerlach
3129a835fa6SDave Gerlach ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
3139a835fa6SDave Gerlach if (ret)
3149a835fa6SDave Gerlach goto restore_voltage;
3156baee034SViresh Kumar } else {
3169a835fa6SDave Gerlach ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
3179a835fa6SDave Gerlach if (ret)
3186baee034SViresh Kumar goto restore_voltage;
3199a835fa6SDave Gerlach
3209a835fa6SDave Gerlach ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
3219a835fa6SDave Gerlach "vdd");
3229a835fa6SDave Gerlach if (ret)
3236baee034SViresh Kumar goto restore_voltage;
3249a835fa6SDave Gerlach }
3259a835fa6SDave Gerlach
3269a835fa6SDave Gerlach return 0;
3279a835fa6SDave Gerlach
3289a835fa6SDave Gerlach restore_voltage:
3296baee034SViresh Kumar /* Fetch old supplies information only if required */
3306baee034SViresh Kumar ret = dev_pm_opp_get_supplies(old_opp, opp_data.old_supplies);
3316baee034SViresh Kumar WARN_ON(ret);
3326baee034SViresh Kumar
3339a835fa6SDave Gerlach /* This shouldn't harm even if the voltages weren't updated earlier */
3349a835fa6SDave Gerlach if (old_supply_vdd->u_volt) {
3359a835fa6SDave Gerlach ret = _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb");
3369a835fa6SDave Gerlach if (ret)
3379a835fa6SDave Gerlach return ret;
3389a835fa6SDave Gerlach
3399a835fa6SDave Gerlach ret = _opp_set_voltage(dev, old_supply_vdd, 0, vdd_reg,
3409a835fa6SDave Gerlach "vdd");
3419a835fa6SDave Gerlach if (ret)
3429a835fa6SDave Gerlach return ret;
3439a835fa6SDave Gerlach }
3449a835fa6SDave Gerlach
3459a835fa6SDave Gerlach return ret;
3469a835fa6SDave Gerlach }
3479a835fa6SDave Gerlach
3489a835fa6SDave Gerlach static const struct ti_opp_supply_of_data omap_generic_of_data = {
3499a835fa6SDave Gerlach };
3509a835fa6SDave Gerlach
3519a835fa6SDave Gerlach static const struct ti_opp_supply_of_data omap_omap5_of_data = {
3529a835fa6SDave Gerlach .flags = OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE,
3539a835fa6SDave Gerlach .efuse_voltage_mask = 0xFFF,
3549a835fa6SDave Gerlach .efuse_voltage_uv = false,
3559a835fa6SDave Gerlach };
3569a835fa6SDave Gerlach
3579a835fa6SDave Gerlach static const struct ti_opp_supply_of_data omap_omap5core_of_data = {
3589a835fa6SDave Gerlach .flags = OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE | OPPDM_HAS_NO_ABB,
3599a835fa6SDave Gerlach .efuse_voltage_mask = 0xFFF,
3609a835fa6SDave Gerlach .efuse_voltage_uv = false,
3619a835fa6SDave Gerlach };
3629a835fa6SDave Gerlach
3639a835fa6SDave Gerlach static const struct of_device_id ti_opp_supply_of_match[] = {
3649a835fa6SDave Gerlach {.compatible = "ti,omap-opp-supply", .data = &omap_generic_of_data},
3659a835fa6SDave Gerlach {.compatible = "ti,omap5-opp-supply", .data = &omap_omap5_of_data},
3669a835fa6SDave Gerlach {.compatible = "ti,omap5-core-opp-supply",
3679a835fa6SDave Gerlach .data = &omap_omap5core_of_data},
3689a835fa6SDave Gerlach {},
3699a835fa6SDave Gerlach };
3709a835fa6SDave Gerlach MODULE_DEVICE_TABLE(of, ti_opp_supply_of_match);
3719a835fa6SDave Gerlach
ti_opp_supply_probe(struct platform_device * pdev)3729a835fa6SDave Gerlach static int ti_opp_supply_probe(struct platform_device *pdev)
3739a835fa6SDave Gerlach {
3749a835fa6SDave Gerlach struct device *dev = &pdev->dev;
3759a835fa6SDave Gerlach struct device *cpu_dev = get_cpu_device(0);
3769a835fa6SDave Gerlach const struct of_device_id *match;
3779a835fa6SDave Gerlach const struct ti_opp_supply_of_data *of_data;
3789a835fa6SDave Gerlach int ret = 0;
3799a835fa6SDave Gerlach
3809a835fa6SDave Gerlach match = of_match_device(ti_opp_supply_of_match, dev);
3819a835fa6SDave Gerlach if (!match) {
3829a835fa6SDave Gerlach /* We do not expect this to happen */
3839a835fa6SDave Gerlach dev_err(dev, "%s: Unable to match device\n", __func__);
3849a835fa6SDave Gerlach return -ENODEV;
3859a835fa6SDave Gerlach }
3869a835fa6SDave Gerlach if (!match->data) {
3879a835fa6SDave Gerlach /* Again, unlikely.. but mistakes do happen */
3889a835fa6SDave Gerlach dev_err(dev, "%s: Bad data in match\n", __func__);
3899a835fa6SDave Gerlach return -EINVAL;
3909a835fa6SDave Gerlach }
3919a835fa6SDave Gerlach of_data = match->data;
3929a835fa6SDave Gerlach
3939a835fa6SDave Gerlach dev_set_drvdata(dev, (void *)of_data);
3949a835fa6SDave Gerlach
3959a835fa6SDave Gerlach /* If we need optimized voltage */
3969a835fa6SDave Gerlach if (of_data->flags & OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE) {
3979a835fa6SDave Gerlach ret = _store_optimized_voltages(dev, &opp_data);
3989a835fa6SDave Gerlach if (ret)
3999a835fa6SDave Gerlach return ret;
4009a835fa6SDave Gerlach }
4019a835fa6SDave Gerlach
4026baee034SViresh Kumar ret = dev_pm_opp_set_config_regulators(cpu_dev, ti_opp_config_regulators);
403*21dec022SPrimoz Fiser if (ret < 0) {
4049a835fa6SDave Gerlach _free_optimized_voltages(dev, &opp_data);
4059a835fa6SDave Gerlach return ret;
4069a835fa6SDave Gerlach }
4079a835fa6SDave Gerlach
408*21dec022SPrimoz Fiser return 0;
409*21dec022SPrimoz Fiser }
410*21dec022SPrimoz Fiser
4119a835fa6SDave Gerlach static struct platform_driver ti_opp_supply_driver = {
4129a835fa6SDave Gerlach .probe = ti_opp_supply_probe,
4139a835fa6SDave Gerlach .driver = {
4149a835fa6SDave Gerlach .name = "ti_opp_supply",
4159a835fa6SDave Gerlach .of_match_table = of_match_ptr(ti_opp_supply_of_match),
4169a835fa6SDave Gerlach },
4179a835fa6SDave Gerlach };
4189a835fa6SDave Gerlach module_platform_driver(ti_opp_supply_driver);
4199a835fa6SDave Gerlach
4209a835fa6SDave Gerlach MODULE_DESCRIPTION("Texas Instruments OMAP OPP Supply driver");
4219a835fa6SDave Gerlach MODULE_AUTHOR("Texas Instruments Inc.");
4229a835fa6SDave Gerlach MODULE_LICENSE("GPL v2");
423