source: mainline/uspace/drv/platform/amdm37x/main.c@ 4122410

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4122410 was 4122410, checked in by Jakub Jermar <jakub@…>, 7 years ago

Improve Doxygen documentaion

This is stil WiP. A number of libraries, drivers and services were
converted to using a more hierarchical and decentralized scheme when it
comes to specifying to which doxygen group they belong.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Copyright (c) 2012 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @addtogroup amdm37x
31 * @{
32 */
33
34/** @file
35 */
36
37#define DEBUG_CM 0
38
39#include <ddf/log.h>
40#include <errno.h>
41#include <ops/hw_res.h>
42#include <stdio.h>
43
44#include "amdm37x.h"
45
46#define NAME "amdm37x"
47
48typedef struct {
49 const char *name;
50 const char *id;
51 int score;
52 hw_resource_list_t hw_resources;
53} amdm37x_fun_t;
54
55/* See amdm37x TRM page 3316 for these values */
56#define OHCI_BASE_ADDRESS 0x48064400
57#define OHCI_SIZE 1024
58#define EHCI_BASE_ADDRESS 0x48064800
59#define EHCI_SIZE 1024
60
61/* See amdm37x TRM page 1813 for these values */
62#define DSS_BASE_ADDRESS 0x48050000
63#define DSS_SIZE 512
64#define DISPC_BASE_ADDRESS 0x48050400
65#define DISPC_SIZE 1024
66#define VIDEO_ENC_BASE_ADDRESS 0x48050C00
67#define VIDEO_ENC_SIZE 256
68
69
70static hw_resource_t ohci_res[] = {
71 {
72 .type = MEM_RANGE,
73 .res.io_range = {
74 .address = OHCI_BASE_ADDRESS,
75 .size = OHCI_SIZE,
76 .endianness = LITTLE_ENDIAN
77 },
78 },
79 {
80 .type = INTERRUPT,
81 .res.interrupt = { .irq = 76 },
82 },
83};
84
85static hw_resource_t ehci_res[] = {
86 {
87 .type = MEM_RANGE,
88 /* See amdm37x TRM page. 3316 for these values */
89 .res.io_range = {
90 .address = EHCI_BASE_ADDRESS,
91 .size = EHCI_SIZE,
92 .endianness = LITTLE_ENDIAN
93 },
94 },
95 {
96 .type = INTERRUPT,
97 .res.interrupt = { .irq = 77 },
98 },
99};
100
101static hw_resource_t disp_res[] = {
102 {
103 .type = MEM_RANGE,
104 .res.io_range = {
105 .address = DSS_BASE_ADDRESS,
106 .size = DSS_SIZE,
107 .endianness = LITTLE_ENDIAN
108 },
109 },
110 {
111 .type = MEM_RANGE,
112 .res.io_range = {
113 .address = DISPC_BASE_ADDRESS,
114 .size = DISPC_SIZE,
115 .endianness = LITTLE_ENDIAN
116 },
117 },
118 {
119 .type = MEM_RANGE,
120 .res.io_range = {
121 .address = VIDEO_ENC_BASE_ADDRESS,
122 .size = VIDEO_ENC_SIZE,
123 .endianness = LITTLE_ENDIAN
124 },
125 },
126 {
127 .type = INTERRUPT,
128 .res.interrupt = { .irq = 25 },
129 },
130};
131
132static const amdm37x_fun_t amdm37x_funcs[] = {
133 {
134 .name = "ohci",
135 .id = "usb/host=ohci",
136 .score = 90,
137 .hw_resources = { .resources = ohci_res, .count = ARRAY_SIZE(ohci_res) }
138 },
139 {
140 .name = "ehci",
141 .id = "usb/host=ehci",
142 .score = 90,
143 .hw_resources = { .resources = ehci_res, .count = ARRAY_SIZE(ehci_res) }
144 },
145 {
146 .name = "fb",
147 .id = "amdm37x&dispc",
148 .score = 90,
149 .hw_resources = { .resources = disp_res, .count = ARRAY_SIZE(disp_res) }
150 },
151};
152
153
154static hw_resource_list_t *amdm37x_get_resources(ddf_fun_t *fnode);
155static errno_t amdm37x_enable_interrupt(ddf_fun_t *fun, int);
156
157static hw_res_ops_t fun_hw_res_ops = {
158 .get_resource_list = &amdm37x_get_resources,
159 .enable_interrupt = &amdm37x_enable_interrupt,
160};
161
162static ddf_dev_ops_t amdm37x_fun_ops = {
163 .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops
164};
165
166static errno_t amdm37x_add_fun(ddf_dev_t *dev, const amdm37x_fun_t *fun)
167{
168 assert(dev);
169 assert(fun);
170
171 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", fun->name);
172
173 /* Create new device function. */
174 ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, fun->name);
175 if (fnode == NULL)
176 return ENOMEM;
177
178 /* Add match id */
179 errno_t ret = ddf_fun_add_match_id(fnode, fun->id, fun->score);
180 if (ret != EOK) {
181 ddf_fun_destroy(fnode);
182 return ret;
183 }
184
185 /* Alloc needed data */
186 amdm37x_fun_t *rf =
187 ddf_fun_data_alloc(fnode, sizeof(amdm37x_fun_t));
188 if (!rf) {
189 ddf_fun_destroy(fnode);
190 return ENOMEM;
191 }
192 *rf = *fun;
193
194 /* Set provided operations to the device. */
195 ddf_fun_set_ops(fnode, &amdm37x_fun_ops);
196
197 /* Register function. */
198 ret = ddf_fun_bind(fnode);
199 if (ret != EOK) {
200 ddf_msg(LVL_ERROR, "Failed binding function %s.", fun->name);
201 ddf_fun_destroy(fnode);
202 return ret;
203 }
204
205 return EOK;
206}
207
208/** Add the root device.
209 *
210 * @param dev Device which is root of the whole device tree
211 * (both of HW and pseudo devices).
212 *
213 * @return Zero on success, error number otherwise.
214 *
215 */
216static errno_t amdm37x_dev_add(ddf_dev_t *dev)
217{
218 assert(dev);
219 amdm37x_t *device = ddf_dev_data_alloc(dev, sizeof(amdm37x_t));
220 if (!device)
221 return ENOMEM;
222 errno_t ret = amdm37x_init(device, DEBUG_CM);
223 if (ret != EOK) {
224 ddf_msg(LVL_FATAL, "Failed to setup hw access!.\n");
225 return ret;
226 }
227
228 /* Set dplls to ON and automatic */
229 amdm37x_setup_dpll_on_autoidle(device);
230
231 /* Enable function and interface clocks */
232 amdm37x_usb_clocks_set(device, true);
233
234 /* Init TLL */
235 ret = amdm37x_usb_tll_init(device);
236 if (ret != EOK) {
237 ddf_msg(LVL_FATAL, "Failed to init USB TLL!.\n");
238 amdm37x_usb_clocks_set(device, false);
239 return ret;
240 }
241
242 /* Register functions */
243 for (unsigned i = 0; i < ARRAY_SIZE(amdm37x_funcs); ++i) {
244 if (amdm37x_add_fun(dev, &amdm37x_funcs[i]) != EOK)
245 ddf_msg(LVL_ERROR, "Failed to add %s function for "
246 "BeagleBoard-xM platform.", amdm37x_funcs[i].name);
247 }
248 return EOK;
249}
250
251/** The root device driver's standard operations. */
252static driver_ops_t amdm37x_ops = {
253 .dev_add = &amdm37x_dev_add
254};
255
256/** The root device driver structure. */
257static driver_t amdm37x_driver = {
258 .name = NAME,
259 .driver_ops = &amdm37x_ops
260};
261
262static hw_resource_list_t *amdm37x_get_resources(ddf_fun_t *fnode)
263{
264 amdm37x_fun_t *fun = ddf_fun_data_get(fnode);
265 assert(fun != NULL);
266 return &fun->hw_resources;
267}
268
269static errno_t amdm37x_enable_interrupt(ddf_fun_t *fun, int irq)
270{
271 //TODO: Implement
272 return false;
273}
274
275int main(int argc, char *argv[])
276{
277 printf("%s: HelenOS AM/DM37x(OMAP37x) platform driver\n", NAME);
278 ddf_log_init(NAME);
279 return ddf_driver_main(&amdm37x_driver);
280}
281
282/**
283 * @}
284 */
Note: See TracBrowser for help on using the repository browser.