Blame view

arch/arm/mach-omap2/opp.c 3.22 KB
fd1478cd6   Nishanth Menon   omap: opp: add OM...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*
   * OMAP SoC specific OPP wrapper function
   *
   * Copyright (C) 2009-2010 Texas Instruments Incorporated - http://www.ti.com/
   *	Nishanth Menon
   *	Kevin Hilman
   * Copyright (C) 2010 Nokia Corporation.
   *      Eduardo Valentin
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   * This program is distributed "as is" WITHOUT ANY WARRANTY of any
   * kind, whether express or implied; without even the implied warranty
   * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   */
  #include <linux/module.h>
  #include <linux/opp.h>
afa54fe7c   Rajendra Nayak   OMAP: OPP: Do a r...
21
  #include <linux/clk.h>
fd1478cd6   Nishanth Menon   omap: opp: add OM...
22
23
  
  #include <plat/omap_device.h>
536a4c8bb   Afzal Mohammed   arm: omap: am33x:...
24
  #include <plat/dvfs.h>
afa54fe7c   Rajendra Nayak   OMAP: OPP: Do a r...
25
  #include <plat/clock.h>
fd1478cd6   Nishanth Menon   omap: opp: add OM...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  
  #include "omap_opp_data.h"
  
  /* Temp variable to allow multiple calls */
  static u8 __initdata omap_table_init;
  
  /**
   * omap_init_opp_table() - Initialize opp table as per the CPU type
   * @opp_def:		opp default list for this silicon
   * @opp_def_size:	number of opp entries for this silicon
   *
   * Register the initial OPP table with the OPP library based on the CPU
   * type. This is meant to be used only by SoC specific registration.
   */
  int __init omap_init_opp_table(struct omap_opp_def *opp_def,
  		u32 opp_def_size)
  {
  	int i, r;
afa54fe7c   Rajendra Nayak   OMAP: OPP: Do a r...
44
45
  	struct clk *clk;
  	long round_rate;
fd1478cd6   Nishanth Menon   omap: opp: add OM...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  
  	if (!opp_def || !opp_def_size) {
  		pr_err("%s: invalid params!
  ", __func__);
  		return -EINVAL;
  	}
  
  	/*
  	 * Initialize only if not already initialized even if the previous
  	 * call failed, because, no reason we'd succeed again.
  	 */
  	if (omap_table_init)
  		return -EEXIST;
  	omap_table_init = 1;
  
  	/* Lets now register with OPP library */
  	for (i = 0; i < opp_def_size; i++) {
  		struct omap_hwmod *oh;
  		struct device *dev;
  
  		if (!opp_def->hwmod_name) {
e3c57087c   Rajendra Nayak   OMAP2+: OPP: Do n...
67
68
69
70
  			WARN(1, "%s: NULL name of omap_hwmod, failing"
  				" [%d].
  ", __func__, i);
  			goto next;
fd1478cd6   Nishanth Menon   omap: opp: add OM...
71
72
73
  		}
  		oh = omap_hwmod_lookup(opp_def->hwmod_name);
  		if (!oh || !oh->od) {
e3c57087c   Rajendra Nayak   OMAP2+: OPP: Do n...
74
  			WARN(1, "%s: no hwmod or odev for %s, [%d] "
fd1478cd6   Nishanth Menon   omap: opp: add OM...
75
76
77
  				"cannot add OPPs.
  ", __func__,
  				opp_def->hwmod_name, i);
e3c57087c   Rajendra Nayak   OMAP2+: OPP: Do n...
78
  			goto next;
fd1478cd6   Nishanth Menon   omap: opp: add OM...
79
  		}
d66b3fe43   Kevin Hilman   OMAP: omap_device...
80
  		dev = &oh->od->pdev->dev;
fd1478cd6   Nishanth Menon   omap: opp: add OM...
81

afa54fe7c   Rajendra Nayak   OMAP: OPP: Do a r...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  		clk = omap_clk_get_by_name(opp_def->clk_name);
  		if (clk) {
  			round_rate = clk_round_rate(clk, opp_def->freq);
  			if (round_rate > 0) {
  				opp_def->freq = round_rate;
  			} else {
  				WARN(1, "%s: round_rate for clock %s failed
  ",
  					__func__, opp_def->clk_name);
  				goto next; /* skip Bad OPP */
  			}
  		} else {
  			WARN(1, "%s: No clock by name %s found
  ", __func__,
  				opp_def->clk_name);
  			goto next; /* skip Bad OPP */
  		}
fd1478cd6   Nishanth Menon   omap: opp: add OM...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  		r = opp_add(dev, opp_def->freq, opp_def->u_volt);
  		if (r) {
  			dev_err(dev, "%s: add OPP %ld failed for %s [%d] "
  				"result=%d
  ",
  			       __func__, opp_def->freq,
  			       opp_def->hwmod_name, i, r);
  		} else {
  			if (!opp_def->default_available)
  				r = opp_disable(dev, opp_def->freq);
  			if (r)
  				dev_err(dev, "%s: disable %ld failed for %s "
  					"[%d] result=%d
  ",
  					__func__, opp_def->freq,
  					opp_def->hwmod_name, i, r);
90cdb1c23   Nishanth Menon   OMAP3+: OPP: regi...
115
116
117
118
119
120
121
  
  			r  = omap_dvfs_register_device(dev,
  				opp_def->voltdm_name, opp_def->clk_name);
  			if (r)
  				dev_err(dev, "%s:%s:err dvfs register %d %d
  ",
  					__func__, opp_def->hwmod_name, r, i);
fd1478cd6   Nishanth Menon   omap: opp: add OM...
122
  		}
e3c57087c   Rajendra Nayak   OMAP2+: OPP: Do n...
123
  next:
fd1478cd6   Nishanth Menon   omap: opp: add OM...
124
125
126
127
128
  		opp_def++;
  	}
  
  	return 0;
  }