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