source: mainline/uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c@ 712a10b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 712a10b was 712a10b, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

amdm37,root: Enable USB host clock before launching drivers.

Makes device registers accessible.

  • Property mode set to 100644
File size: 5.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 root_amdm37x TI AM/DM37x platform driver.
31 * @brief HelenOS TI AM/DM37x platform driver.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <ddf/driver.h>
39#include <ddf/log.h>
40#include <errno.h>
41#include <ops/hw_res.h>
42#include <stdio.h>
43#include <ddi.h>
44
45#define NAME "rootamdm37x"
46
47/** Obtain function soft-state from DDF function node */
48#define ROOTMAC_FUN(fnode) \
49 ((rootamdm37x_fun_t *) (fnode)->driver_data)
50
51typedef struct {
52 hw_resource_list_t hw_resources;
53} rootamdm37x_fun_t;
54
55static hw_resource_t ohci_res[] = {
56 {
57 .type = MEM_RANGE,
58 /* See amdm37x TRM page. 3316 for these values */
59 .res.io_range = {
60 .address = 0x48064400,
61 .size = 1024,
62 .endianness = LITTLE_ENDIAN
63 },
64 },
65 {
66 .type = INTERRUPT,
67 .res.interrupt = { .irq = 76 },
68 },
69};
70
71static hw_resource_t ehci_res[] = {
72 {
73 .type = MEM_RANGE,
74 /* See amdm37x TRM page. 3316 for these values */
75 .res.io_range = {
76 .address = 0x48064800,
77 .size = 1024,
78 .endianness = LITTLE_ENDIAN
79 },
80 },
81 {
82 .type = INTERRUPT,
83 .res.interrupt = { .irq = 77 },
84 },
85};
86
87static const rootamdm37x_fun_t ohci = {
88 .hw_resources = {
89 .resources = ohci_res,
90 .count = sizeof(ohci_res)/sizeof(ohci_res[0]),
91 }
92};
93
94static const rootamdm37x_fun_t ehci = {
95 .hw_resources = {
96 .resources = ehci_res,
97 .count = sizeof(ehci_res)/sizeof(ehci_res[0]),
98 }
99};
100
101
102static ddf_dev_ops_t rootamdm37x_fun_ops;
103
104static bool rootamdm37x_add_fun(ddf_dev_t *dev, const char *name,
105 const char *str_match_id, const rootamdm37x_fun_t *fun)
106{
107 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
108
109 ddf_fun_t *fnode = NULL;
110 match_id_t *match_id = NULL;
111
112 /* Create new device. */
113 fnode = ddf_fun_create(dev, fun_inner, name);
114 if (fnode == NULL)
115 goto failure;
116
117 fnode->driver_data = (void*)fun;
118
119 /* Initialize match id list */
120 match_id = create_match_id();
121 if (match_id == NULL)
122 goto failure;
123
124 match_id->id = str_match_id;
125 match_id->score = 100;
126 add_match_id(&fnode->match_ids, match_id);
127
128 /* Set provided operations to the device. */
129 fnode->ops = &rootamdm37x_fun_ops;
130
131 /* Register function. */
132 if (ddf_fun_bind(fnode) != EOK) {
133 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
134 goto failure;
135 }
136
137 return true;
138
139failure:
140 if (match_id != NULL)
141 match_id->id = NULL;
142
143 if (fnode != NULL) {
144 fnode->driver_data = NULL;
145 ddf_fun_destroy(fnode);
146 }
147
148 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
149
150 return false;
151}
152
153/** Get the root device.
154 *
155 * @param dev Device which is root of the whole device tree
156 * (both of HW and pseudo devices).
157 *
158 * @return Zero on success, negative error number otherwise.
159 *
160 */
161static int rootamdm37x_dev_add(ddf_dev_t *dev)
162{
163 {
164 /* Enable USB host clocks */
165 uint32_t *reg = NULL;
166 const int ret = pio_enable((void*)0x48005400, 8192, (void**)&reg);
167 assert(ret == EOK);
168 assert(reg);
169 /* offset 0x10 (0x4 int32)[0] enables fclk,
170 * offset 0x00 (0x0 int32)[0 and 1] enables iclk,
171 * offset 0x30 (0xc int32)[0] enables autoidle
172 */
173 reg[0x4] = 0x1;
174 reg[0x0] = 0x3;
175 reg[0xc] = 0x1;
176 }
177
178 /* Register functions */
179 if (!rootamdm37x_add_fun(dev, "ohci", "usb/host=ohci", &ohci))
180 ddf_msg(LVL_ERROR, "Failed to add OHCI function for "
181 "BeagleBoard-xM platform.");
182 if (!rootamdm37x_add_fun(dev, "ehci", "usb/host=ehci", &ehci))
183 ddf_msg(LVL_ERROR, "Failed to add EHCI function for "
184 "BeagleBoard-xM platform.");
185
186 return EOK;
187}
188
189/** The root device driver's standard operations. */
190static driver_ops_t rootamdm37x_ops = {
191 .dev_add = &rootamdm37x_dev_add
192};
193
194/** The root device driver structure. */
195static driver_t rootamdm37x_driver = {
196 .name = NAME,
197 .driver_ops = &rootamdm37x_ops
198};
199
200static hw_resource_list_t *rootamdm37x_get_resources(ddf_fun_t *fnode)
201{
202 rootamdm37x_fun_t *fun = ROOTMAC_FUN(fnode);
203 assert(fun != NULL);
204
205 return &fun->hw_resources;
206}
207
208static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun)
209{
210 /* TODO */
211
212 return false;
213}
214
215static hw_res_ops_t fun_hw_res_ops = {
216 .get_resource_list = &rootamdm37x_get_resources,
217 .enable_interrupt = &rootamdm37x_enable_interrupt
218};
219
220int main(int argc, char *argv[])
221{
222 printf("%s: HelenOS AM/DM37x(OMAP37x) platform driver\n", NAME);
223 ddf_log_init(NAME, LVL_ERROR);
224 rootamdm37x_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
225 return ddf_driver_main(&rootamdm37x_driver);
226}
227
228/**
229 * @}
230 */
Note: See TracBrowser for help on using the repository browser.