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

Last change on this file since aa57bf7 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
RevLine 
[a202dbb]1/*
[d57ff6f]2 * Copyright (c) 2013 Jan Vesely
[a202dbb]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
[4122410]30/** @addtogroup amdm37x_dispc
[a202dbb]31 * @{
32 */
33/**
34 * @file
35 */
36
[8e4a408]37#include <ddf/driver.h>
[74db5a1]38#include <ddf/log.h>
[a202dbb]39#include <errno.h>
[74db5a1]40#include <str_error.h>
[a202dbb]41#include <stdio.h>
[74db5a1]42#include <graph.h>
[d57ff6f]43
[74db5a1]44#include "amdm37x_dispc.h"
45
[d57ff6f]46#define NAME "amdm37x_dispc"
[a202dbb]47
[984a9ba]48static void graph_vsl_connection(ipc_call_t *icall, void *arg)
[8e4a408]49{
50 visualizer_t *vsl;
[74db5a1]51
[8e4a408]52 vsl = (visualizer_t *) ddf_fun_data_get((ddf_fun_t *)arg);
[984a9ba]53 graph_visualizer_connection(vsl, icall, NULL);
[8e4a408]54}
[74db5a1]55
[b7fd2a0]56static errno_t amdm37x_dispc_dev_add(ddf_dev_t *dev)
[a202dbb]57{
[c7d11a0b]58 assert(dev);
[96228d0]59 /* Visualizer part */
[c7d11a0b]60 ddf_fun_t *fun = ddf_fun_create(dev, fun_exposed, "viz");
[74db5a1]61 if (!fun) {
[4f87a85a]62 ddf_log_error("Failed to create visualizer function.");
[74db5a1]63 return ENOMEM;
64 }
[9cc4b2b4]65
[96228d0]66 visualizer_t *vis = ddf_fun_data_alloc(fun, sizeof(visualizer_t));
67 if (!vis) {
[4f87a85a]68 ddf_log_error("Failed to allocate visualizer structure.");
[96228d0]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
[8e4a408]76 ddf_fun_set_conn_handler(fun, graph_vsl_connection);
[9cc4b2b4]77 /* Hw part */
[74db5a1]78 amdm37x_dispc_t *dispc =
[9cc4b2b4]79 ddf_dev_data_alloc(dev, sizeof(amdm37x_dispc_t));
[74db5a1]80 if (!dispc) {
[4f87a85a]81 ddf_log_error("Failed to allocate dispc structure.");
[74db5a1]82 ddf_fun_destroy(fun);
83 return ENOMEM;
84 }
[9cc4b2b4]85
[4f87a85a]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));
[74db5a1]89 ddf_fun_destroy(fun);
[4f87a85a]90 return rc;
[74db5a1]91 }
[9cc4b2b4]92
[d15797d]93 /* Bind function */
[4f87a85a]94 rc = ddf_fun_bind(fun);
95 if (rc != EOK) {
96 ddf_log_error("Failed to bind function: %s.", str_error(rc));
[74db5a1]97 amdm37x_dispc_fini(dispc);
98 ddf_fun_destroy(fun);
[4f87a85a]99 return rc;
[74db5a1]100 }
[c7d11a0b]101
[4f87a85a]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));
[a202dbb]113 return EOK;
114}
115
[4e3bfab]116static driver_ops_t amdm37x_dispc_driver_ops = {
117 .dev_add = amdm37x_dispc_dev_add,
[a202dbb]118};
119
[4e3bfab]120static driver_t amdm37x_dispc_driver = {
[a202dbb]121 .name = NAME,
[4e3bfab]122 .driver_ops = &amdm37x_dispc_driver_ops
[a202dbb]123};
124
125int main(int argc, char *argv[])
126{
[4e3bfab]127 printf("%s: HelenOS AM/DM37x framebuffer driver\n", NAME);
[74db5a1]128 ddf_log_init(NAME);
[4e3bfab]129 return ddf_driver_main(&amdm37x_dispc_driver);
[a202dbb]130}
131
132/** @}
133 */
Note: See TracBrowser for help on using the repository browser.