Commit | Line | Data |
---|---|---|
fd1478cd NM |
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> | |
20 | #include <linux/opp.h> | |
24d7b40a | 21 | #include <linux/cpu.h> |
fd1478cd | 22 | |
25c7d49e | 23 | #include "omap_device.h" |
fd1478cd NM |
24 | |
25 | #include "omap_opp_data.h" | |
26 | ||
27 | /* Temp variable to allow multiple calls */ | |
28 | static u8 __initdata omap_table_init; | |
29 | ||
30 | /** | |
31 | * omap_init_opp_table() - Initialize opp table as per the CPU type | |
32 | * @opp_def: opp default list for this silicon | |
33 | * @opp_def_size: number of opp entries for this silicon | |
34 | * | |
35 | * Register the initial OPP table with the OPP library based on the CPU | |
36 | * type. This is meant to be used only by SoC specific registration. | |
37 | */ | |
38 | int __init omap_init_opp_table(struct omap_opp_def *opp_def, | |
39 | u32 opp_def_size) | |
40 | { | |
41 | int i, r; | |
42 | ||
43 | if (!opp_def || !opp_def_size) { | |
44 | pr_err("%s: invalid params!\n", __func__); | |
45 | return -EINVAL; | |
46 | } | |
47 | ||
48 | /* | |
49 | * Initialize only if not already initialized even if the previous | |
50 | * call failed, because, no reason we'd succeed again. | |
51 | */ | |
52 | if (omap_table_init) | |
53 | return -EEXIST; | |
54 | omap_table_init = 1; | |
55 | ||
56 | /* Lets now register with OPP library */ | |
b110547e | 57 | for (i = 0; i < opp_def_size; i++, opp_def++) { |
fd1478cd NM |
58 | struct omap_hwmod *oh; |
59 | struct device *dev; | |
60 | ||
61 | if (!opp_def->hwmod_name) { | |
62 | pr_err("%s: NULL name of omap_hwmod, failing [%d].\n", | |
63 | __func__, i); | |
64 | return -EINVAL; | |
65 | } | |
24d7b40a KH |
66 | |
67 | if (!strncmp(opp_def->hwmod_name, "mpu", 3)) { | |
68 | /* | |
69 | * All current OMAPs share voltage rail and | |
70 | * clock source, so CPU0 is used to represent | |
71 | * the MPU-SS. | |
72 | */ | |
73 | dev = get_cpu_device(0); | |
74 | } else { | |
75 | oh = omap_hwmod_lookup(opp_def->hwmod_name); | |
76 | if (!oh || !oh->od) { | |
77 | pr_debug("%s: no hwmod or odev for %s, [%d] cannot add OPPs.\n", | |
78 | __func__, opp_def->hwmod_name, i); | |
79 | continue; | |
80 | } | |
81 | dev = &oh->od->pdev->dev; | |
fd1478cd | 82 | } |
fd1478cd NM |
83 | |
84 | r = opp_add(dev, opp_def->freq, opp_def->u_volt); | |
85 | if (r) { | |
7852ec05 PW |
86 | dev_err(dev, "%s: add OPP %ld failed for %s [%d] result=%d\n", |
87 | __func__, opp_def->freq, | |
88 | opp_def->hwmod_name, i, r); | |
fd1478cd NM |
89 | } else { |
90 | if (!opp_def->default_available) | |
91 | r = opp_disable(dev, opp_def->freq); | |
92 | if (r) | |
7852ec05 | 93 | dev_err(dev, "%s: disable %ld failed for %s [%d] result=%d\n", |
fd1478cd NM |
94 | __func__, opp_def->freq, |
95 | opp_def->hwmod_name, i, r); | |
96 | } | |
fd1478cd NM |
97 | } |
98 | ||
99 | return 0; | |
100 | } |