source: mainline/uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c@ 7a6d91b

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

rootamdm37x: Reshuffle.

Put device control in its own file.

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