Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 1 | /* |
| 2 | * OMAP SoC specific OPP wrapper function |
| 3 | * |
| 4 | * Copyright (C) 2009-2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 5 | * Nishanth Menon |
| 6 | * Kevin Hilman |
| 7 | * Copyright (C) 2010 Nokia Corporation. |
| 8 | * Eduardo Valentin |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 15 | * kind, whether express or implied; without even the implied warranty |
| 16 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | */ |
| 19 | #include <linux/module.h> |
Nishanth Menon | 92d5185 | 2013-10-16 10:39:01 -0500 | [diff] [blame] | 20 | #include <linux/of.h> |
Nishanth Menon | e4db1c7 | 2013-09-19 16:03:52 -0500 | [diff] [blame] | 21 | #include <linux/pm_opp.h> |
Kevin Hilman | 24d7b40 | 2012-09-06 14:03:08 -0700 | [diff] [blame] | 22 | #include <linux/cpu.h> |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 23 | |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 24 | #include "omap_device.h" |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 25 | |
| 26 | #include "omap_opp_data.h" |
| 27 | |
| 28 | /* Temp variable to allow multiple calls */ |
| 29 | static u8 __initdata omap_table_init; |
| 30 | |
| 31 | /** |
| 32 | * omap_init_opp_table() - Initialize opp table as per the CPU type |
| 33 | * @opp_def: opp default list for this silicon |
| 34 | * @opp_def_size: number of opp entries for this silicon |
| 35 | * |
| 36 | * Register the initial OPP table with the OPP library based on the CPU |
| 37 | * type. This is meant to be used only by SoC specific registration. |
| 38 | */ |
| 39 | int __init omap_init_opp_table(struct omap_opp_def *opp_def, |
| 40 | u32 opp_def_size) |
| 41 | { |
| 42 | int i, r; |
| 43 | |
Nishanth Menon | 92d5185 | 2013-10-16 10:39:01 -0500 | [diff] [blame] | 44 | if (of_have_populated_dt()) |
| 45 | return -EINVAL; |
| 46 | |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 47 | if (!opp_def || !opp_def_size) { |
| 48 | pr_err("%s: invalid params!\n", __func__); |
| 49 | return -EINVAL; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Initialize only if not already initialized even if the previous |
| 54 | * call failed, because, no reason we'd succeed again. |
| 55 | */ |
| 56 | if (omap_table_init) |
| 57 | return -EEXIST; |
| 58 | omap_table_init = 1; |
| 59 | |
| 60 | /* Lets now register with OPP library */ |
Nishanth Menon | b110547 | 2012-05-18 12:26:19 -0500 | [diff] [blame] | 61 | for (i = 0; i < opp_def_size; i++, opp_def++) { |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 62 | struct omap_hwmod *oh; |
| 63 | struct device *dev; |
| 64 | |
| 65 | if (!opp_def->hwmod_name) { |
| 66 | pr_err("%s: NULL name of omap_hwmod, failing [%d].\n", |
| 67 | __func__, i); |
| 68 | return -EINVAL; |
| 69 | } |
Kevin Hilman | 24d7b40 | 2012-09-06 14:03:08 -0700 | [diff] [blame] | 70 | |
| 71 | if (!strncmp(opp_def->hwmod_name, "mpu", 3)) { |
| 72 | /* |
| 73 | * All current OMAPs share voltage rail and |
| 74 | * clock source, so CPU0 is used to represent |
| 75 | * the MPU-SS. |
| 76 | */ |
| 77 | dev = get_cpu_device(0); |
| 78 | } else { |
| 79 | oh = omap_hwmod_lookup(opp_def->hwmod_name); |
| 80 | if (!oh || !oh->od) { |
| 81 | pr_debug("%s: no hwmod or odev for %s, [%d] cannot add OPPs.\n", |
| 82 | __func__, opp_def->hwmod_name, i); |
| 83 | continue; |
| 84 | } |
| 85 | dev = &oh->od->pdev->dev; |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 86 | } |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 87 | |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 88 | r = dev_pm_opp_add(dev, opp_def->freq, opp_def->u_volt); |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 89 | if (r) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 90 | dev_err(dev, "%s: add OPP %ld failed for %s [%d] result=%d\n", |
| 91 | __func__, opp_def->freq, |
| 92 | opp_def->hwmod_name, i, r); |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 93 | } else { |
| 94 | if (!opp_def->default_available) |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 95 | r = dev_pm_opp_disable(dev, opp_def->freq); |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 96 | if (r) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 97 | dev_err(dev, "%s: disable %ld failed for %s [%d] result=%d\n", |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 98 | __func__, opp_def->freq, |
| 99 | opp_def->hwmod_name, i, r); |
| 100 | } |
Nishanth Menon | fd1478c | 2010-12-09 09:13:46 -0600 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |