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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1a9174e was 1433ecda, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Fix cstyle: make ccheck-fix and commit only files where all the changes are good.

  • 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 * @defgroup amdm37x TI AM/DM37x platform driver.
31 * @brief HelenOS TI AM/DM37x platform driver.
32 * @{
33 */
34
35/** @file
36 */
37
38#define DEBUG_CM 0
39
40#include <ddf/log.h>
41#include <errno.h>
42#include <ops/hw_res.h>
43#include <stdio.h>
44
45#include "amdm37x.h"
46
47#define NAME "amdm37x"
48
49typedef struct {
50 const char *name;
51 const char *id;
52 int score;
53 hw_resource_list_t hw_resources;
54} amdm37x_fun_t;
55
56/* See amdm37x TRM page 3316 for these values */
57#define OHCI_BASE_ADDRESS 0x48064400
58#define OHCI_SIZE 1024
59#define EHCI_BASE_ADDRESS 0x48064800
60#define EHCI_SIZE 1024
61
62/* See amdm37x TRM page 1813 for these values */
63#define DSS_BASE_ADDRESS 0x48050000
64#define DSS_SIZE 512
65#define DISPC_BASE_ADDRESS 0x48050400
66#define DISPC_SIZE 1024
67#define VIDEO_ENC_BASE_ADDRESS 0x48050C00
68#define VIDEO_ENC_SIZE 256
69
70
71static hw_resource_t ohci_res[] = {
72 {
73 .type = MEM_RANGE,
74 .res.io_range = {
75 .address = OHCI_BASE_ADDRESS,
76 .size = OHCI_SIZE,
77 .endianness = LITTLE_ENDIAN
78 },
79 },
80 {
81 .type = INTERRUPT,
82 .res.interrupt = { .irq = 76 },
83 },
84};
85
86static hw_resource_t ehci_res[] = {
87 {
88 .type = MEM_RANGE,
89 /* See amdm37x TRM page. 3316 for these values */
90 .res.io_range = {
91 .address = EHCI_BASE_ADDRESS,
92 .size = EHCI_SIZE,
93 .endianness = LITTLE_ENDIAN
94 },
95 },
96 {
97 .type = INTERRUPT,
98 .res.interrupt = { .irq = 77 },
99 },
100};
101
102static hw_resource_t disp_res[] = {
103 {
104 .type = MEM_RANGE,
105 .res.io_range = {
106 .address = DSS_BASE_ADDRESS,
107 .size = DSS_SIZE,
108 .endianness = LITTLE_ENDIAN
109 },
110 },
111 {
112 .type = MEM_RANGE,
113 .res.io_range = {
114 .address = DISPC_BASE_ADDRESS,
115 .size = DISPC_SIZE,
116 .endianness = LITTLE_ENDIAN
117 },
118 },
119 {
120 .type = MEM_RANGE,
121 .res.io_range = {
122 .address = VIDEO_ENC_BASE_ADDRESS,
123 .size = VIDEO_ENC_SIZE,
124 .endianness = LITTLE_ENDIAN
125 },
126 },
127 {
128 .type = INTERRUPT,
129 .res.interrupt = { .irq = 25 },
130 },
131};
132
133static const amdm37x_fun_t amdm37x_funcs[] = {
134 {
135 .name = "ohci",
136 .id = "usb/host=ohci",
137 .score = 90,
138 .hw_resources = { .resources = ohci_res, .count = ARRAY_SIZE(ohci_res) }
139 },
140 {
141 .name = "ehci",
142 .id = "usb/host=ehci",
143 .score = 90,
144 .hw_resources = { .resources = ehci_res, .count = ARRAY_SIZE(ehci_res) }
145 },
146 {
147 .name = "fb",
148 .id = "amdm37x&dispc",
149 .score = 90,
150 .hw_resources = { .resources = disp_res, .count = ARRAY_SIZE(disp_res) }
151 },
152};
153
154
155static hw_resource_list_t *amdm37x_get_resources(ddf_fun_t *fnode);
156static errno_t amdm37x_enable_interrupt(ddf_fun_t *fun, int);
157
158static hw_res_ops_t fun_hw_res_ops = {
159 .get_resource_list = &amdm37x_get_resources,
160 .enable_interrupt = &amdm37x_enable_interrupt,
161};
162
163static ddf_dev_ops_t amdm37x_fun_ops = {
164 .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops
165};
166
167static errno_t amdm37x_add_fun(ddf_dev_t *dev, const amdm37x_fun_t *fun)
168{
169 assert(dev);
170 assert(fun);
171
172 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", fun->name);
173
174 /* Create new device function. */
175 ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, fun->name);
176 if (fnode == NULL)
177 return ENOMEM;
178
179 /* Add match id */
180 errno_t ret = ddf_fun_add_match_id(fnode, fun->id, fun->score);
181 if (ret != EOK) {
182 ddf_fun_destroy(fnode);
183 return ret;
184 }
185
186 /* Alloc needed data */
187 amdm37x_fun_t *rf =
188 ddf_fun_data_alloc(fnode, sizeof(amdm37x_fun_t));
189 if (!rf) {
190 ddf_fun_destroy(fnode);
191 return ENOMEM;
192 }
193 *rf = *fun;
194
195 /* Set provided operations to the device. */
196 ddf_fun_set_ops(fnode, &amdm37x_fun_ops);
197
198 /* Register function. */
199 ret = ddf_fun_bind(fnode);
200 if (ret != EOK) {
201 ddf_msg(LVL_ERROR, "Failed binding function %s.", fun->name);
202 ddf_fun_destroy(fnode);
203 return ret;
204 }
205
206 return EOK;
207}
208
209/** Add the root device.
210 *
211 * @param dev Device which is root of the whole device tree
212 * (both of HW and pseudo devices).
213 *
214 * @return Zero on success, error number otherwise.
215 *
216 */
217static errno_t amdm37x_dev_add(ddf_dev_t *dev)
218{
219 assert(dev);
220 amdm37x_t *device = ddf_dev_data_alloc(dev, sizeof(amdm37x_t));
221 if (!device)
222 return ENOMEM;
223 errno_t ret = amdm37x_init(device, DEBUG_CM);
224 if (ret != EOK) {
225 ddf_msg(LVL_FATAL, "Failed to setup hw access!.\n");
226 return ret;
227 }
228
229 /* Set dplls to ON and automatic */
230 amdm37x_setup_dpll_on_autoidle(device);
231
232 /* Enable function and interface clocks */
233 amdm37x_usb_clocks_set(device, true);
234
235 /* Init TLL */
236 ret = amdm37x_usb_tll_init(device);
237 if (ret != EOK) {
238 ddf_msg(LVL_FATAL, "Failed to init USB TLL!.\n");
239 amdm37x_usb_clocks_set(device, false);
240 return ret;
241 }
242
243 /* Register functions */
244 for (unsigned i = 0; i < ARRAY_SIZE(amdm37x_funcs); ++i) {
245 if (amdm37x_add_fun(dev, &amdm37x_funcs[i]) != EOK)
246 ddf_msg(LVL_ERROR, "Failed to add %s function for "
247 "BeagleBoard-xM platform.", amdm37x_funcs[i].name);
248 }
249 return EOK;
250}
251
252/** The root device driver's standard operations. */
253static driver_ops_t amdm37x_ops = {
254 .dev_add = &amdm37x_dev_add
255};
256
257/** The root device driver structure. */
258static driver_t amdm37x_driver = {
259 .name = NAME,
260 .driver_ops = &amdm37x_ops
261};
262
263static hw_resource_list_t *amdm37x_get_resources(ddf_fun_t *fnode)
264{
265 amdm37x_fun_t *fun = ddf_fun_data_get(fnode);
266 assert(fun != NULL);
267 return &fun->hw_resources;
268}
269
270static errno_t amdm37x_enable_interrupt(ddf_fun_t *fun, int irq)
271{
272 //TODO: Implement
273 return false;
274}
275
276int main(int argc, char *argv[])
277{
278 printf("%s: HelenOS AM/DM37x(OMAP37x) platform driver\n", NAME);
279 ddf_log_init(NAME);
280 return ddf_driver_main(&amdm37x_driver);
281}
282
283/**
284 * @}
285 */
Note: See TracBrowser for help on using the repository browser.