staging: ti dspbridge: add resource manager
[deliverable/linux.git] / drivers / staging / tidspbridge / rmgr / pwr.c
1 /*
2 * pwr.c
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * PWR API for controlling DSP power states.
7 *
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
9 *
10 * This package 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 PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19 /* ----------------------------------- Host OS */
20 #include <dspbridge/host_os.h>
21
22 /* ----------------------------------- This */
23 #include <dspbridge/pwr.h>
24
25 /* ----------------------------------- Resource Manager */
26 #include <dspbridge/devdefs.h>
27 #include <dspbridge/drv.h>
28
29 /* ----------------------------------- Platform Manager */
30 #include <dspbridge/dev.h>
31
32 /* ----------------------------------- Link Driver */
33 #include <dspbridge/dspioctl.h>
34
35 /*
36 * ======== pwr_sleep_dsp ========
37 * Send command to DSP to enter sleep state.
38 */
39 int pwr_sleep_dsp(IN CONST u32 sleepCode, IN CONST u32 timeout)
40 {
41 struct bridge_drv_interface *intf_fxns;
42 struct bridge_dev_context *dw_context;
43 int status = -EPERM;
44 struct dev_object *hdev_obj = NULL;
45 u32 ioctlcode = 0;
46 u32 arg = timeout;
47
48 for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
49 hdev_obj != NULL;
50 hdev_obj =
51 (struct dev_object *)drv_get_next_dev_object((u32) hdev_obj)) {
52 if (DSP_FAILED(dev_get_bridge_context(hdev_obj,
53 (struct bridge_dev_context **)
54 &dw_context))) {
55 continue;
56 }
57 if (DSP_FAILED(dev_get_intf_fxns(hdev_obj,
58 (struct bridge_drv_interface **)
59 &intf_fxns))) {
60 continue;
61 }
62 if (sleepCode == PWR_DEEPSLEEP)
63 ioctlcode = BRDIOCTL_DEEPSLEEP;
64 else if (sleepCode == PWR_EMERGENCYDEEPSLEEP)
65 ioctlcode = BRDIOCTL_EMERGENCYSLEEP;
66 else
67 status = -EINVAL;
68
69 if (status != -EINVAL) {
70 status = (*intf_fxns->pfn_dev_cntrl) (dw_context,
71 ioctlcode,
72 (void *)&arg);
73 }
74 }
75 return status;
76 }
77
78 /*
79 * ======== pwr_wake_dsp ========
80 * Send command to DSP to wake it from sleep.
81 */
82 int pwr_wake_dsp(IN CONST u32 timeout)
83 {
84 struct bridge_drv_interface *intf_fxns;
85 struct bridge_dev_context *dw_context;
86 int status = -EPERM;
87 struct dev_object *hdev_obj = NULL;
88 u32 arg = timeout;
89
90 for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
91 hdev_obj != NULL;
92 hdev_obj = (struct dev_object *)drv_get_next_dev_object
93 ((u32) hdev_obj)) {
94 if (DSP_SUCCEEDED(dev_get_bridge_context(hdev_obj,
95 (struct bridge_dev_context
96 **)&dw_context))) {
97 if (DSP_SUCCEEDED
98 (dev_get_intf_fxns
99 (hdev_obj,
100 (struct bridge_drv_interface **)&intf_fxns))) {
101 status =
102 (*intf_fxns->pfn_dev_cntrl) (dw_context,
103 BRDIOCTL_WAKEUP,
104 (void *)&arg);
105 }
106 }
107 }
108 return status;
109 }
110
111 /*
112 * ======== pwr_pm_pre_scale========
113 * Sends pre-notification message to DSP.
114 */
115 int pwr_pm_pre_scale(IN u16 voltage_domain, u32 level)
116 {
117 struct bridge_drv_interface *intf_fxns;
118 struct bridge_dev_context *dw_context;
119 int status = -EPERM;
120 struct dev_object *hdev_obj = NULL;
121 u32 arg[2];
122
123 arg[0] = voltage_domain;
124 arg[1] = level;
125
126 for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
127 hdev_obj != NULL;
128 hdev_obj = (struct dev_object *)drv_get_next_dev_object
129 ((u32) hdev_obj)) {
130 if (DSP_SUCCEEDED(dev_get_bridge_context(hdev_obj,
131 (struct bridge_dev_context
132 **)&dw_context))) {
133 if (DSP_SUCCEEDED
134 (dev_get_intf_fxns
135 (hdev_obj,
136 (struct bridge_drv_interface **)&intf_fxns))) {
137 status =
138 (*intf_fxns->pfn_dev_cntrl) (dw_context,
139 BRDIOCTL_PRESCALE_NOTIFY,
140 (void *)&arg);
141 }
142 }
143 }
144 return status;
145 }
146
147 /*
148 * ======== pwr_pm_post_scale========
149 * Sends post-notification message to DSP.
150 */
151 int pwr_pm_post_scale(IN u16 voltage_domain, u32 level)
152 {
153 struct bridge_drv_interface *intf_fxns;
154 struct bridge_dev_context *dw_context;
155 int status = -EPERM;
156 struct dev_object *hdev_obj = NULL;
157 u32 arg[2];
158
159 arg[0] = voltage_domain;
160 arg[1] = level;
161
162 for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
163 hdev_obj != NULL;
164 hdev_obj = (struct dev_object *)drv_get_next_dev_object
165 ((u32) hdev_obj)) {
166 if (DSP_SUCCEEDED(dev_get_bridge_context(hdev_obj,
167 (struct bridge_dev_context
168 **)&dw_context))) {
169 if (DSP_SUCCEEDED
170 (dev_get_intf_fxns
171 (hdev_obj,
172 (struct bridge_drv_interface **)&intf_fxns))) {
173 status =
174 (*intf_fxns->pfn_dev_cntrl) (dw_context,
175 BRDIOCTL_POSTSCALE_NOTIFY,
176 (void *)&arg);
177 }
178 }
179 }
180 return status;
181
182 }
This page took 0.046222 seconds and 5 git commands to generate.