source: mainline/uspace/drv/platform/ski/ski.c@ 35f2bb1b

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

Move receiving side of ski console support to a separate driver, ski-con. Add ski platform driver.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2017 Jiri Svoboda
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 ski platform driver.
31 * @brief Ski platform driver.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <assert.h>
39#include <stdio.h>
40#include <errno.h>
41#include <stdlib.h>
42
43#include <ddf/driver.h>
44#include <ddf/log.h>
45
46#define NAME "ski"
47
48static int ski_dev_add(ddf_dev_t *dev);
49
50static driver_ops_t ski_ops = {
51 .dev_add = &ski_dev_add
52};
53
54static driver_t ski_driver = {
55 .name = NAME,
56 .driver_ops = &ski_ops
57};
58
59static int ski_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id)
60{
61 ddf_msg(LVL_NOTE, "Adding function '%s'.", name);
62
63 ddf_fun_t *fnode = NULL;
64 int rc;
65
66 /* Create new device. */
67 fnode = ddf_fun_create(dev, fun_inner, name);
68 if (fnode == NULL) {
69 ddf_msg(LVL_ERROR, "Error creating function '%s'", name);
70 rc = ENOMEM;
71 goto error;
72 }
73
74 /* Add match ID */
75 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
76 if (rc != EOK) {
77 ddf_msg(LVL_ERROR, "Error adding match ID");
78 goto error;
79 }
80
81 /* Register function. */
82 if (ddf_fun_bind(fnode) != EOK) {
83 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
84 goto error;
85 }
86
87 return EOK;
88
89error:
90 if (fnode != NULL)
91 ddf_fun_destroy(fnode);
92
93 return rc;
94}
95
96static int ski_add_functions(ddf_dev_t *dev)
97{
98 int rc;
99
100 rc = ski_add_fun(dev, "console", "ski/console");
101 if (rc != EOK)
102 return rc;
103
104 return EOK;
105}
106
107/** Add device. */
108static int ski_dev_add(ddf_dev_t *dev)
109{
110 ddf_msg(LVL_NOTE, "ski_dev_add, device handle = %d",
111 (int)ddf_dev_get_handle(dev));
112
113 /* Register functions. */
114 if (ski_add_functions(dev)) {
115 ddf_msg(LVL_ERROR, "Failed to add functions for ski platform.");
116 }
117
118 return EOK;
119}
120
121int main(int argc, char *argv[])
122{
123 int rc;
124
125 printf(NAME ": Ski platform driver\n");
126
127 rc = ddf_log_init(NAME);
128 if (rc != EOK) {
129 printf(NAME ": Failed initializing logging service");
130 return 1;
131 }
132
133 return ddf_driver_main(&ski_driver);
134}
135
136/**
137 * @}
138 */
Note: See TracBrowser for help on using the repository browser.