source: mainline/uspace/drv/platform/amdm37x/main.c@ c20cccb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c20cccb was 1433ecda, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Fix cstyle: make ccheck-fix and commit only files where all the changes are good.

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