source: mainline/uspace/drv/fb/amdm37x_dispc/main.c@ e1f2079

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

Check return code from ddf_add_fun_to_category

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2013 Jan Vesely
3 * Copyright (c) 2011 Petr Koupy
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup amdm37x_dispc
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <ddf/driver.h>
38#include <ddf/log.h>
39#include <errno.h>
40#include <str_error.h>
41#include <stdio.h>
42#include <graph.h>
43
44#include "amdm37x_dispc.h"
45
46#define NAME "amdm37x_dispc"
47
48static void graph_vsl_connection(ipc_call_t *icall, void *arg)
49{
50 visualizer_t *vsl;
51
52 vsl = (visualizer_t *) ddf_fun_data_get((ddf_fun_t *)arg);
53 graph_visualizer_connection(vsl, icall, NULL);
54}
55
56static errno_t amdm37x_dispc_dev_add(ddf_dev_t *dev)
57{
58 assert(dev);
59 /* Visualizer part */
60 ddf_fun_t *fun = ddf_fun_create(dev, fun_exposed, "viz");
61 if (!fun) {
62 ddf_log_error("Failed to create visualizer function.");
63 return ENOMEM;
64 }
65
66 visualizer_t *vis = ddf_fun_data_alloc(fun, sizeof(visualizer_t));
67 if (!vis) {
68 ddf_log_error("Failed to allocate visualizer structure.");
69 ddf_fun_destroy(fun);
70 return ENOMEM;
71 }
72
73 graph_init_visualizer(vis);
74 vis->reg_svc_handle = ddf_fun_get_handle(fun);
75
76 ddf_fun_set_conn_handler(fun, graph_vsl_connection);
77 /* Hw part */
78 amdm37x_dispc_t *dispc =
79 ddf_dev_data_alloc(dev, sizeof(amdm37x_dispc_t));
80 if (!dispc) {
81 ddf_log_error("Failed to allocate dispc structure.");
82 ddf_fun_destroy(fun);
83 return ENOMEM;
84 }
85
86 errno_t rc = amdm37x_dispc_init(dispc, vis);
87 if (rc != EOK) {
88 ddf_log_error("Failed to init dispc: %s.", str_error(rc));
89 ddf_fun_destroy(fun);
90 return rc;
91 }
92
93 /* Bind function */
94 rc = ddf_fun_bind(fun);
95 if (rc != EOK) {
96 ddf_log_error("Failed to bind function: %s.", str_error(rc));
97 amdm37x_dispc_fini(dispc);
98 ddf_fun_destroy(fun);
99 return rc;
100 }
101
102 rc = ddf_fun_add_to_category(fun, "visualizer");
103 if (rc != EOK) {
104 ddf_log_error("Failed to add function: %s to visualizer "
105 "category.", str_error(rc));
106 amdm37x_dispc_fini(dispc);
107 ddf_fun_unbind(fun);
108 ddf_fun_destroy(fun);
109 return rc;
110 }
111
112 ddf_log_note("Added device `%s'", ddf_dev_get_name(dev));
113 return EOK;
114}
115
116static driver_ops_t amdm37x_dispc_driver_ops = {
117 .dev_add = amdm37x_dispc_dev_add,
118};
119
120static driver_t amdm37x_dispc_driver = {
121 .name = NAME,
122 .driver_ops = &amdm37x_dispc_driver_ops
123};
124
125int main(int argc, char *argv[])
126{
127 printf("%s: HelenOS AM/DM37x framebuffer driver\n", NAME);
128 ddf_log_init(NAME);
129 return ddf_driver_main(&amdm37x_dispc_driver);
130}
131
132/** @}
133 */
Note: See TracBrowser for help on using the repository browser.