source: mainline/uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c@ bebf97d

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

rootamdm37x: Don't use data implant.

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[09a0a8f0]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
[bf815c8]38#define DEBUG_CM 0
[7290ca0]39
[09a0a8f0]40#include <ddf/log.h>
41#include <errno.h>
42#include <ops/hw_res.h>
43#include <stdio.h>
44
[7a6d91b]45#include "amdm37x.h"
[063ae706]46
[09a0a8f0]47#define NAME "rootamdm37x"
48
[f25f1e6]49typedef struct {
50 hw_resource_list_t hw_resources;
51} rootamdm37x_fun_t;
52
[bebf97d]53/* See amdm37x TRM page. 3316 for these values */
[f25f1e6]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 .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
74static 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
[bebf97d]90static const rootamdm37x_fun_t ohci = {
91 .hw_resources = {
92 .resources = ohci_res,
93 .count = sizeof(ohci_res)/sizeof(ohci_res[0]),
94 }
95};
96
[f25f1e6]97static const rootamdm37x_fun_t ehci = {
98 .hw_resources = {
99 .resources = ehci_res,
100 .count = sizeof(ehci_res) / sizeof(ehci_res[0]),
101 }
102};
103
104static hw_resource_list_t *rootamdm37x_get_resources(ddf_fun_t *fnode);
105static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun);
106
107static hw_res_ops_t fun_hw_res_ops = {
108 .get_resource_list = &rootamdm37x_get_resources,
109 .enable_interrupt = &rootamdm37x_enable_interrupt,
110};
111
[bebf97d]112static ddf_dev_ops_t rootamdm37x_fun_ops = {
[f25f1e6]113 .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops
114};
115
[878b764]116static int rootamdm37x_add_fun(ddf_dev_t *dev, const char *name,
[09a0a8f0]117 const char *str_match_id, const rootamdm37x_fun_t *fun)
118{
119 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
120
[2be2506a]121 /* Create new device function. */
122 ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, name);
[09a0a8f0]123 if (fnode == NULL)
[2be2506a]124 return ENOMEM;
[09a0a8f0]125
[2be2506a]126 /* Add match id */
[878b764]127 int ret = ddf_fun_add_match_id(fnode, str_match_id, 100);
128 if (ret != EOK) {
[2be2506a]129 ddf_fun_destroy(fnode);
[878b764]130 return ret;
[2be2506a]131 }
[09a0a8f0]132
[bebf97d]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
[09a0a8f0]142 /* Set provided operations to the device. */
[2be2506a]143 ddf_fun_set_ops(fnode, &rootamdm37x_fun_ops);
[09a0a8f0]144
145 /* Register function. */
[878b764]146 ret = ddf_fun_bind(fnode);
147 if (ret != EOK) {
[09a0a8f0]148 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
149 ddf_fun_destroy(fnode);
[878b764]150 return ret;
[09a0a8f0]151 }
152
[878b764]153 return EOK;
[09a0a8f0]154}
155
[063ae706]156/** Add the root device.
[09a0a8f0]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 */
164static int rootamdm37x_dev_add(ddf_dev_t *dev)
165{
[f25f1e6]166 assert(dev);
167 amdm37x_t *device = ddf_dev_data_alloc(dev, sizeof(amdm37x_t));
168 if (!device)
169 return ENOMEM;
[7a6d91b]170 int ret = amdm37x_init(device, DEBUG_CM);
[f25f1e6]171 if (ret != EOK) {
172 ddf_msg(LVL_FATAL, "Failed to setup hw access!.\n");
173 return ret;
174 }
175
[52e020b]176 /* Set dplls to ON and automatic */
[7a6d91b]177 amdm37x_setup_dpll_on_autoidle(device);
[e5e2d73]178
179 /* Enable function and interface clocks */
[7a6d91b]180 amdm37x_usb_clocks_set(device, true);
[063ae706]181
[e5e2d73]182 /* Init TLL */
[7a6d91b]183 ret = amdm37x_usb_tll_init(device);
[063ae706]184 if (ret != EOK) {
185 ddf_msg(LVL_FATAL, "Failed to init USB TLL!.\n");
[7a6d91b]186 amdm37x_usb_clocks_set(device, false);
[063ae706]187 return ret;
[712a10b]188 }
189
[09a0a8f0]190 /* Register functions */
[878b764]191 if (rootamdm37x_add_fun(dev, "ohci", "usb/host=ohci", &ohci) != EOK)
[09a0a8f0]192 ddf_msg(LVL_ERROR, "Failed to add OHCI function for "
193 "BeagleBoard-xM platform.");
[878b764]194 if (rootamdm37x_add_fun(dev, "ehci", "usb/host=ehci", &ehci) != EOK)
[09a0a8f0]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. */
202static driver_ops_t rootamdm37x_ops = {
203 .dev_add = &rootamdm37x_dev_add
204};
205
206/** The root device driver structure. */
207static driver_t rootamdm37x_driver = {
208 .name = NAME,
209 .driver_ops = &rootamdm37x_ops
210};
211
[7a6d91b]212static hw_resource_list_t * rootamdm37x_get_resources(ddf_fun_t *fnode)
[09a0a8f0]213{
[2be2506a]214 rootamdm37x_fun_t *fun = ddf_fun_data_get(fnode);
[09a0a8f0]215 assert(fun != NULL);
216 return &fun->hw_resources;
217}
218
219static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun)
220{
[7a6d91b]221 //TODO: Implement
[09a0a8f0]222 return false;
223}
224
225int main(int argc, char *argv[])
226{
227 printf("%s: HelenOS AM/DM37x(OMAP37x) platform driver\n", NAME);
[f25f1e6]228 ddf_log_init(NAME);
[09a0a8f0]229 return ddf_driver_main(&rootamdm37x_driver);
230}
231
232/**
233 * @}
234 */
Note: See TracBrowser for help on using the repository browser.