Merge branch 'topic/aloop' into topic/misc
[pandora-kernel.git] / drivers / staging / tidspbridge / services / cfg.c
1 /*
2  * cfg.c
3  *
4  * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5  *
6  * Implementation of platform specific config services.
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 #include <linux/types.h>
20
21 /*  ----------------------------------- DSP/BIOS Bridge */
22 #include <dspbridge/dbdefs.h>
23
24 /*  ----------------------------------- Trace & Debug */
25 #include <dspbridge/dbc.h>
26
27 /*  ----------------------------------- OS Adaptation Layer */
28
29 /*  ----------------------------------- This */
30 #include <dspbridge/cfg.h>
31 #include <dspbridge/drv.h>
32
33 struct drv_ext {
34         struct list_head link;
35         char sz_string[MAXREGPATHLENGTH];
36 };
37
38 /*
39  *  ======== cfg_exit ========
40  *  Purpose:
41  *      Discontinue usage of the CFG module.
42  */
43 void cfg_exit(void)
44 {
45         /* Do nothing */
46 }
47
48 /*
49  *  ======== cfg_get_auto_start ========
50  *  Purpose:
51  *      Retreive the autostart mask, if any, for this board.
52  */
53 int cfg_get_auto_start(struct cfg_devnode *dev_node_obj,
54                               u32 *auto_start)
55 {
56         int status = 0;
57         u32 dw_buf_size;
58         struct drv_data *drv_datap = dev_get_drvdata(bridge);
59
60         dw_buf_size = sizeof(*auto_start);
61         if (!dev_node_obj)
62                 status = -EFAULT;
63         if (!auto_start || !drv_datap)
64                 status = -EFAULT;
65         if (!status)
66                 *auto_start = (drv_datap->base_img) ? 1 : 0;
67
68         DBC_ENSURE((status == 0 &&
69                     (*auto_start == 0 || *auto_start == 1))
70                    || status != 0);
71         return status;
72 }
73
74 /*
75  *  ======== cfg_get_dev_object ========
76  *  Purpose:
77  *      Retrieve the Device Object handle for a given devnode.
78  */
79 int cfg_get_dev_object(struct cfg_devnode *dev_node_obj,
80                               u32 *value)
81 {
82         int status = 0;
83         u32 dw_buf_size;
84         struct drv_data *drv_datap = dev_get_drvdata(bridge);
85
86         if (!drv_datap)
87                 status = -EPERM;
88
89         if (!dev_node_obj)
90                 status = -EFAULT;
91
92         if (!value)
93                 status = -EFAULT;
94
95         dw_buf_size = sizeof(value);
96         if (!status) {
97
98                 /* check the device string and then store dev object */
99                 if (!
100                     (strcmp
101                      ((char *)((struct drv_ext *)dev_node_obj)->sz_string,
102                       "TIOMAP1510")))
103                         *value = (u32)drv_datap->dev_object;
104         }
105         if (status)
106                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
107         return status;
108 }
109
110 /*
111  *  ======== cfg_get_exec_file ========
112  *  Purpose:
113  *      Retreive the default executable, if any, for this board.
114  */
115 int cfg_get_exec_file(struct cfg_devnode *dev_node_obj, u32 buf_size,
116                              char *str_exec_file)
117 {
118         int status = 0;
119         struct drv_data *drv_datap = dev_get_drvdata(bridge);
120
121         if (!dev_node_obj)
122                 status = -EFAULT;
123
124         else if (!str_exec_file || !drv_datap)
125                 status = -EFAULT;
126
127         if (strlen(drv_datap->base_img) > buf_size)
128                 status = -EINVAL;
129
130         if (!status && drv_datap->base_img)
131                 strcpy(str_exec_file, drv_datap->base_img);
132
133         if (status)
134                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
135         DBC_ENSURE(((status == 0) &&
136                     (strlen(str_exec_file) <= buf_size))
137                    || (status != 0));
138         return status;
139 }
140
141 /*
142  *  ======== cfg_get_object ========
143  *  Purpose:
144  *      Retrieve the Object handle from the Registry
145  */
146 int cfg_get_object(u32 *value, u8 dw_type)
147 {
148         int status = -EINVAL;
149         struct drv_data *drv_datap = dev_get_drvdata(bridge);
150
151         DBC_REQUIRE(value != NULL);
152
153         if (!drv_datap)
154                 return -EPERM;
155
156         switch (dw_type) {
157         case (REG_DRV_OBJECT):
158                 if (drv_datap->drv_object) {
159                         *value = (u32)drv_datap->drv_object;
160                         status = 0;
161                 } else {
162                         status = -ENODATA;
163                 }
164                 break;
165         case (REG_MGR_OBJECT):
166                 if (drv_datap->mgr_object) {
167                         *value = (u32)drv_datap->mgr_object;
168                         status = 0;
169                 } else {
170                         status = -ENODATA;
171                 }
172                 break;
173
174         default:
175                 break;
176         }
177         if (status) {
178                 *value = 0;
179                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
180         }
181         DBC_ENSURE((!status && *value != 0) || (status && *value == 0));
182         return status;
183 }
184
185 /*
186  *  ======== cfg_init ========
187  *  Purpose:
188  *      Initialize the CFG module's private state.
189  */
190 bool cfg_init(void)
191 {
192         return true;
193 }
194
195 /*
196  *  ======== cfg_set_dev_object ========
197  *  Purpose:
198  *      Store the Device Object handle and dev_node pointer for a given devnode.
199  */
200 int cfg_set_dev_object(struct cfg_devnode *dev_node_obj, u32 value)
201 {
202         int status = 0;
203         struct drv_data *drv_datap = dev_get_drvdata(bridge);
204
205         if (!drv_datap) {
206                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
207                 return -EPERM;
208         }
209
210         if (!dev_node_obj)
211                 status = -EFAULT;
212
213         if (!status) {
214                 /* Store the Bridge device object in the Registry */
215
216                 if (!(strcmp((char *)dev_node_obj, "TIOMAP1510")))
217                         drv_datap->dev_object = (void *) value;
218         }
219         if (status)
220                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
221
222         return status;
223 }
224
225 /*
226  *  ======== cfg_set_object ========
227  *  Purpose:
228  *      Store the Driver Object handle
229  */
230 int cfg_set_object(u32 value, u8 dw_type)
231 {
232         int status = -EINVAL;
233         struct drv_data *drv_datap = dev_get_drvdata(bridge);
234
235         if (!drv_datap)
236                 return -EPERM;
237
238         switch (dw_type) {
239         case (REG_DRV_OBJECT):
240                 drv_datap->drv_object = (void *)value;
241                 status = 0;
242                 break;
243         case (REG_MGR_OBJECT):
244                 drv_datap->mgr_object = (void *)value;
245                 status = 0;
246                 break;
247         default:
248                 break;
249         }
250         if (status)
251                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
252         return status;
253 }