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 root_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 "rootamdm37x"
|
---|
48 |
|
---|
49 | typedef struct {
|
---|
50 | hw_resource_list_t hw_resources;
|
---|
51 | } rootamdm37x_fun_t;
|
---|
52 |
|
---|
53 | /* See amdm37x TRM page. 3316 for these values */
|
---|
54 | #define OHCI_BASE_ADDRESS 0x48064400
|
---|
55 | #define OHCI_SIZE 1024
|
---|
56 | #define EHCI_BASE_ADDRESS 0x48064800
|
---|
57 | #define EHCI_SIZE 1024
|
---|
58 |
|
---|
59 | static hw_resource_t ohci_res[] = {
|
---|
60 | {
|
---|
61 | .type = MEM_RANGE,
|
---|
62 | .res.io_range = {
|
---|
63 | .address = OHCI_BASE_ADDRESS,
|
---|
64 | .size = OHCI_SIZE,
|
---|
65 | .endianness = LITTLE_ENDIAN
|
---|
66 | },
|
---|
67 | },
|
---|
68 | {
|
---|
69 | .type = INTERRUPT,
|
---|
70 | .res.interrupt = { .irq = 76 },
|
---|
71 | },
|
---|
72 | };
|
---|
73 |
|
---|
74 | static hw_resource_t ehci_res[] = {
|
---|
75 | {
|
---|
76 | .type = MEM_RANGE,
|
---|
77 | /* See amdm37x TRM page. 3316 for these values */
|
---|
78 | .res.io_range = {
|
---|
79 | .address = EHCI_BASE_ADDRESS,
|
---|
80 | .size = EHCI_SIZE,
|
---|
81 | .endianness = LITTLE_ENDIAN
|
---|
82 | },
|
---|
83 | },
|
---|
84 | {
|
---|
85 | .type = INTERRUPT,
|
---|
86 | .res.interrupt = { .irq = 77 },
|
---|
87 | },
|
---|
88 | };
|
---|
89 |
|
---|
90 | static const rootamdm37x_fun_t ohci = {
|
---|
91 | .hw_resources = {
|
---|
92 | .resources = ohci_res,
|
---|
93 | .count = sizeof(ohci_res)/sizeof(ohci_res[0]),
|
---|
94 | }
|
---|
95 | };
|
---|
96 |
|
---|
97 | static const rootamdm37x_fun_t ehci = {
|
---|
98 | .hw_resources = {
|
---|
99 | .resources = ehci_res,
|
---|
100 | .count = sizeof(ehci_res) / sizeof(ehci_res[0]),
|
---|
101 | }
|
---|
102 | };
|
---|
103 |
|
---|
104 | static hw_resource_list_t *rootamdm37x_get_resources(ddf_fun_t *fnode);
|
---|
105 | static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun);
|
---|
106 |
|
---|
107 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
108 | .get_resource_list = &rootamdm37x_get_resources,
|
---|
109 | .enable_interrupt = &rootamdm37x_enable_interrupt,
|
---|
110 | };
|
---|
111 |
|
---|
112 | static ddf_dev_ops_t rootamdm37x_fun_ops = {
|
---|
113 | .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops
|
---|
114 | };
|
---|
115 |
|
---|
116 | static int rootamdm37x_add_fun(ddf_dev_t *dev, const char *name,
|
---|
117 | const char *str_match_id, const rootamdm37x_fun_t *fun)
|
---|
118 | {
|
---|
119 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
120 |
|
---|
121 | /* Create new device function. */
|
---|
122 | ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
123 | if (fnode == NULL)
|
---|
124 | return ENOMEM;
|
---|
125 |
|
---|
126 | /* Add match id */
|
---|
127 | int ret = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
128 | if (ret != EOK) {
|
---|
129 | ddf_fun_destroy(fnode);
|
---|
130 | return ret;
|
---|
131 | }
|
---|
132 |
|
---|
133 | /* Alloc needed data */
|
---|
134 | rootamdm37x_fun_t *rf =
|
---|
135 | ddf_fun_data_alloc(fnode, sizeof(rootamdm37x_fun_t));
|
---|
136 | if (!rf) {
|
---|
137 | ddf_fun_destroy(fnode);
|
---|
138 | return ENOMEM;
|
---|
139 | }
|
---|
140 | *rf = *fun;
|
---|
141 |
|
---|
142 | /* Set provided operations to the device. */
|
---|
143 | ddf_fun_set_ops(fnode, &rootamdm37x_fun_ops);
|
---|
144 |
|
---|
145 | /* Register function. */
|
---|
146 | ret = ddf_fun_bind(fnode);
|
---|
147 | if (ret != EOK) {
|
---|
148 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
149 | ddf_fun_destroy(fnode);
|
---|
150 | return ret;
|
---|
151 | }
|
---|
152 |
|
---|
153 | return EOK;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /** Add the root device.
|
---|
157 | *
|
---|
158 | * @param dev Device which is root of the whole device tree
|
---|
159 | * (both of HW and pseudo devices).
|
---|
160 | *
|
---|
161 | * @return Zero on success, negative error number otherwise.
|
---|
162 | *
|
---|
163 | */
|
---|
164 | static int rootamdm37x_dev_add(ddf_dev_t *dev)
|
---|
165 | {
|
---|
166 | assert(dev);
|
---|
167 | amdm37x_t *device = ddf_dev_data_alloc(dev, sizeof(amdm37x_t));
|
---|
168 | if (!device)
|
---|
169 | return ENOMEM;
|
---|
170 | int ret = amdm37x_init(device, DEBUG_CM);
|
---|
171 | if (ret != EOK) {
|
---|
172 | ddf_msg(LVL_FATAL, "Failed to setup hw access!.\n");
|
---|
173 | return ret;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /* Set dplls to ON and automatic */
|
---|
177 | amdm37x_setup_dpll_on_autoidle(device);
|
---|
178 |
|
---|
179 | /* Enable function and interface clocks */
|
---|
180 | amdm37x_usb_clocks_set(device, true);
|
---|
181 |
|
---|
182 | /* Init TLL */
|
---|
183 | ret = amdm37x_usb_tll_init(device);
|
---|
184 | if (ret != EOK) {
|
---|
185 | ddf_msg(LVL_FATAL, "Failed to init USB TLL!.\n");
|
---|
186 | amdm37x_usb_clocks_set(device, false);
|
---|
187 | return ret;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /* Register functions */
|
---|
191 | if (rootamdm37x_add_fun(dev, "ohci", "usb/host=ohci", &ohci) != EOK)
|
---|
192 | ddf_msg(LVL_ERROR, "Failed to add OHCI function for "
|
---|
193 | "BeagleBoard-xM platform.");
|
---|
194 | if (rootamdm37x_add_fun(dev, "ehci", "usb/host=ehci", &ehci) != EOK)
|
---|
195 | ddf_msg(LVL_ERROR, "Failed to add EHCI function for "
|
---|
196 | "BeagleBoard-xM platform.");
|
---|
197 |
|
---|
198 | return EOK;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /** The root device driver's standard operations. */
|
---|
202 | static driver_ops_t rootamdm37x_ops = {
|
---|
203 | .dev_add = &rootamdm37x_dev_add
|
---|
204 | };
|
---|
205 |
|
---|
206 | /** The root device driver structure. */
|
---|
207 | static driver_t rootamdm37x_driver = {
|
---|
208 | .name = NAME,
|
---|
209 | .driver_ops = &rootamdm37x_ops
|
---|
210 | };
|
---|
211 |
|
---|
212 | static hw_resource_list_t * rootamdm37x_get_resources(ddf_fun_t *fnode)
|
---|
213 | {
|
---|
214 | rootamdm37x_fun_t *fun = ddf_fun_data_get(fnode);
|
---|
215 | assert(fun != NULL);
|
---|
216 | return &fun->hw_resources;
|
---|
217 | }
|
---|
218 |
|
---|
219 | static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun)
|
---|
220 | {
|
---|
221 | //TODO: Implement
|
---|
222 | return false;
|
---|
223 | }
|
---|
224 |
|
---|
225 | int main(int argc, char *argv[])
|
---|
226 | {
|
---|
227 | printf("%s: HelenOS AM/DM37x(OMAP37x) platform driver\n", NAME);
|
---|
228 | ddf_log_init(NAME);
|
---|
229 | return ddf_driver_main(&rootamdm37x_driver);
|
---|
230 | }
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * @}
|
---|
234 | */
|
---|