summaryrefslogtreecommitdiff
path: root/drivers/dsp/bridge/rmgr/pwr.c
blob: 50a3f7948a449a356b8ee5f0d63e43b71f1b7e12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * pwr.c
 *
 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
 *
 * Copyright (C) 2005-2006 Texas Instruments, Inc.
 *
 * This package 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 PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */


/*
 *  ======== PWR.c ========
 *  PWR API for controlling DSP power states.
 *
 *  Public Functions:
 *      PWR_SleepDSP
 *      PWR_WakeDSP
 *
 *! Revision History
 *! ================
 *! 18-Feb-2003 vp  Code review updates.
 *! 18-Oct-2002 vp  Ported to Linux platform.
 *! 22-May-2002 sg  Do PWR-to-IOCTL code mapping in PWR_SleepDSP.
 *! 29-Apr-2002 sg  Initial.
 */

/*  ----------------------------------- Host OS */
#include <dspbridge/host_os.h>

/*  ----------------------------------- This */
#include <dspbridge/pwr.h>

/*  ----------------------------------- Resource Manager */
#include <dspbridge/devdefs.h>
#include <dspbridge/drv.h>

/*  ----------------------------------- Platform Manager */
#include <dspbridge/dev.h>

/*  ----------------------------------- Link Driver */
#include <dspbridge/wmdioctl.h>

/*
 *  ======== PWR_SleepDSP ========
 *    Send command to DSP to enter sleep state.
 */
DSP_STATUS PWR_SleepDSP(IN CONST u32 sleepCode, IN CONST u32 timeout)
{
	struct WMD_DRV_INTERFACE *pIntfFxns;
	struct WMD_DEV_CONTEXT *dwContext;
	DSP_STATUS status = DSP_EFAIL;
	struct DEV_OBJECT *hDevObject = NULL;
	u32 ioctlcode = 0;
	u32 arg = timeout;

	for (hDevObject = (struct DEV_OBJECT *)DRV_GetFirstDevObject();
			  hDevObject != NULL;
			hDevObject =
				(struct DEV_OBJECT *)DRV_GetNextDevObject
				((u32)hDevObject)) {
		if (DSP_FAILED(DEV_GetWMDContext(hDevObject,
		   (struct WMD_DEV_CONTEXT **)&dwContext))) {
			continue;
		}
		if (DSP_FAILED(DEV_GetIntfFxns(hDevObject,
		   (struct WMD_DRV_INTERFACE **)&pIntfFxns))) {
			continue;
		}
		if (sleepCode == PWR_DEEPSLEEP)
			ioctlcode = WMDIOCTL_DEEPSLEEP;
		else if (sleepCode == PWR_EMERGENCYDEEPSLEEP)
			ioctlcode = WMDIOCTL_EMERGENCYSLEEP;
		else
			status = DSP_EINVALIDARG;

		if (status != DSP_EINVALIDARG) {
			status = (*pIntfFxns->pfnDevCntrl)(dwContext,
				 ioctlcode, (void *)&arg);
		}
	}
	return status;
}

/*
 *  ======== PWR_WakeDSP ========
 *    Send command to DSP to wake it from sleep.
 */
DSP_STATUS PWR_WakeDSP(IN CONST u32 timeout)
{
	struct WMD_DRV_INTERFACE *pIntfFxns;
	struct WMD_DEV_CONTEXT *dwContext;
	DSP_STATUS status = DSP_EFAIL;
	struct DEV_OBJECT *hDevObject = NULL;
	u32 arg = timeout;

	for (hDevObject = (struct DEV_OBJECT *)DRV_GetFirstDevObject();
	     hDevObject != NULL;
	     hDevObject = (struct DEV_OBJECT *)DRV_GetNextDevObject
			  ((u32)hDevObject)) {
		if (DSP_SUCCEEDED(DEV_GetWMDContext(hDevObject,
		   (struct WMD_DEV_CONTEXT **)&dwContext))) {
			if (DSP_SUCCEEDED(DEV_GetIntfFxns(hDevObject,
			   (struct WMD_DRV_INTERFACE **)&pIntfFxns))) {
				status = (*pIntfFxns->pfnDevCntrl)(dwContext,
					 WMDIOCTL_WAKEUP, (void *)&arg);
			}
		}
	}
	return status;
}

/*
 *  ======== PWR_PM_PreScale========
 *    Sends pre-notification message to DSP.
 */
DSP_STATUS PWR_PM_PreScale(IN u16 voltage_domain, u32 level)
{
	struct WMD_DRV_INTERFACE *pIntfFxns;
	struct WMD_DEV_CONTEXT *dwContext;
	DSP_STATUS status = DSP_EFAIL;
	struct DEV_OBJECT *hDevObject = NULL;
	u32 arg[2];

	arg[0] = voltage_domain;
	arg[1] = level;

	for (hDevObject = (struct DEV_OBJECT *)DRV_GetFirstDevObject();
	    hDevObject != NULL;
	    hDevObject = (struct DEV_OBJECT *)DRV_GetNextDevObject
			 ((u32)hDevObject)) {
		if (DSP_SUCCEEDED(DEV_GetWMDContext(hDevObject,
		   (struct WMD_DEV_CONTEXT **)&dwContext))) {
			if (DSP_SUCCEEDED(DEV_GetIntfFxns(hDevObject,
			   (struct WMD_DRV_INTERFACE **)&pIntfFxns))) {
				status = (*pIntfFxns->pfnDevCntrl)(dwContext,
					 WMDIOCTL_PRESCALE_NOTIFY,
					 (void *)&arg);
			}
		}
	}
	return status;
}

/*
 *  ======== PWR_PM_PostScale========
 *    Sends post-notification message to DSP.
 */
DSP_STATUS PWR_PM_PostScale(IN u16 voltage_domain, u32 level)
{
	struct WMD_DRV_INTERFACE *pIntfFxns;
	struct WMD_DEV_CONTEXT *dwContext;
	DSP_STATUS status = DSP_EFAIL;
	struct DEV_OBJECT *hDevObject = NULL;
	u32 arg[2];

	arg[0] = voltage_domain;
	arg[1] = level;

	for (hDevObject = (struct DEV_OBJECT *)DRV_GetFirstDevObject();
	     hDevObject != NULL;
	     hDevObject = (struct DEV_OBJECT *)DRV_GetNextDevObject
			  ((u32)hDevObject)) {
		if (DSP_SUCCEEDED(DEV_GetWMDContext(hDevObject,
		   (struct WMD_DEV_CONTEXT **)&dwContext))) {
			if (DSP_SUCCEEDED(DEV_GetIntfFxns(hDevObject,
			   (struct WMD_DRV_INTERFACE **)&pIntfFxns))) {
				status = (*pIntfFxns->pfnDevCntrl)(dwContext,
					WMDIOCTL_POSTSCALE_NOTIFY,
					(void *)&arg);
			}
		}
	}
	return status;

}