staging: ti dspbridge: add services
[platform/adaptation/renesas_rcar/renesas_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 /*  ----------------------------------- DSP/BIOS Bridge */
20 #include <dspbridge/std.h>
21 #include <dspbridge/dbdefs.h>
22
23 /*  ----------------------------------- Trace & Debug */
24 #include <dspbridge/dbc.h>
25
26 /*  ----------------------------------- OS Adaptation Layer */
27
28 /*  ----------------------------------- This */
29 #include <dspbridge/cfg.h>
30 #include <dspbridge/drv.h>
31
32 struct drv_ext {
33         struct list_head link;
34         char sz_string[MAXREGPATHLENGTH];
35 };
36
37 /*
38  *  ======== cfg_exit ========
39  *  Purpose:
40  *      Discontinue usage of the CFG module.
41  */
42 void cfg_exit(void)
43 {
44         /* Do nothing */
45 }
46
47 /*
48  *  ======== cfg_get_auto_start ========
49  *  Purpose:
50  *      Retreive the autostart mask, if any, for this board.
51  */
52 int cfg_get_auto_start(struct cfg_devnode *dev_node_obj,
53                               OUT u32 *pdwAutoStart)
54 {
55         int status = 0;
56         u32 dw_buf_size;
57         struct drv_data *drv_datap = dev_get_drvdata(bridge);
58
59         dw_buf_size = sizeof(*pdwAutoStart);
60         if (!dev_node_obj)
61                 status = -EFAULT;
62         if (!pdwAutoStart || !drv_datap)
63                 status = -EFAULT;
64         if (DSP_SUCCEEDED(status))
65                 *pdwAutoStart = (drv_datap->base_img) ? 1 : 0;
66
67         DBC_ENSURE((status == 0 &&
68                     (*pdwAutoStart == 0 || *pdwAutoStart == 1))
69                    || status != 0);
70         return status;
71 }
72
73 /*
74  *  ======== cfg_get_dev_object ========
75  *  Purpose:
76  *      Retrieve the Device Object handle for a given devnode.
77  */
78 int cfg_get_dev_object(struct cfg_devnode *dev_node_obj,
79                               OUT u32 *pdwValue)
80 {
81         int status = 0;
82         u32 dw_buf_size;
83         struct drv_data *drv_datap = dev_get_drvdata(bridge);
84
85         if (!drv_datap)
86                 status = -EPERM;
87
88         if (!dev_node_obj)
89                 status = -EFAULT;
90
91         if (!pdwValue)
92                 status = -EFAULT;
93
94         dw_buf_size = sizeof(pdwValue);
95         if (DSP_SUCCEEDED(status)) {
96
97                 /* check the device string and then store dev object */
98                 if (!
99                     (strcmp
100                      ((char *)((struct drv_ext *)dev_node_obj)->sz_string,
101                       "TIOMAP1510")))
102                         *pdwValue = (u32)drv_datap->dev_object;
103         }
104         if (DSP_FAILED(status))
105                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
106         return status;
107 }
108
109 /*
110  *  ======== cfg_get_exec_file ========
111  *  Purpose:
112  *      Retreive the default executable, if any, for this board.
113  */
114 int cfg_get_exec_file(struct cfg_devnode *dev_node_obj, u32 ul_buf_size,
115                              OUT char *pstrExecFile)
116 {
117         int status = 0;
118         struct drv_data *drv_datap = dev_get_drvdata(bridge);
119
120         if (!dev_node_obj)
121                 status = -EFAULT;
122
123         else if (!pstrExecFile || !drv_datap)
124                 status = -EFAULT;
125
126         if (strlen(drv_datap->base_img) > ul_buf_size)
127                 status = -EINVAL;
128
129         if (DSP_SUCCEEDED(status) && drv_datap->base_img)
130                 strcpy(pstrExecFile, drv_datap->base_img);
131
132         if (DSP_FAILED(status))
133                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
134         DBC_ENSURE(((status == 0) &&
135                     (strlen(pstrExecFile) <= ul_buf_size))
136                    || (status != 0));
137         return status;
138 }
139
140 /*
141  *  ======== cfg_get_object ========
142  *  Purpose:
143  *      Retrieve the Object handle from the Registry
144  */
145 int cfg_get_object(OUT u32 *pdwValue, u8 dw_type)
146 {
147         int status = -EINVAL;
148         struct drv_data *drv_datap = dev_get_drvdata(bridge);
149
150         DBC_REQUIRE(pdwValue != NULL);
151
152         if (!drv_datap)
153                 return -EPERM;
154
155         switch (dw_type) {
156         case (REG_DRV_OBJECT):
157                 if (drv_datap->drv_object) {
158                         *pdwValue = (u32)drv_datap->drv_object;
159                         status = 0;
160                 } else {
161                         status = -ENODATA;
162                 }
163                 break;
164         case (REG_MGR_OBJECT):
165                 if (drv_datap->mgr_object) {
166                         *pdwValue = (u32)drv_datap->mgr_object;
167                         status = 0;
168                 } else {
169                         status = -ENODATA;
170                 }
171                 break;
172
173         default:
174                 break;
175         }
176         if (DSP_FAILED(status)) {
177                 *pdwValue = 0;
178                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
179         }
180         DBC_ENSURE((DSP_SUCCEEDED(status) && *pdwValue != 0) ||
181                    (DSP_FAILED(status) && *pdwValue == 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 dwValue)
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 (DSP_SUCCEEDED(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 *) dwValue;
218         }
219         if (DSP_FAILED(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 dwValue, 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 *)dwValue;
241                 status = 0;
242                 break;
243         case (REG_MGR_OBJECT):
244                 drv_datap->mgr_object = (void *)dwValue;
245                 status = 0;
246                 break;
247         default:
248                 break;
249         }
250         if (DSP_FAILED(status))
251                 pr_err("%s: Failed, status 0x%x\n", __func__, status);
252         return status;
253 }