]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libvbus/lib/src/vbus_gpio.cc
1ea5f163bafc585ff6f80fc370cebdf6833f16d0
[l4.git] / l4 / pkg / libvbus / lib / src / vbus_gpio.cc
1 /*
2  * (c) 2009 Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #include <l4/cxx/ipc_stream>
10 #include <l4/vbus/vbus_generic>
11 #include <l4/vbus/vbus_gpio.h>
12 #include <l4/vbus/vdevice-ops.h>
13 #include <l4/vbus/vbus_gpio-ops.h>
14
15 int L4_CV
16 l4vbus_gpio_setup(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
17                   unsigned pin, unsigned mode, int outvalue)
18 {
19   L4::Ipc::Iostream s(l4_utcb());
20   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_SETUP, s);
21   s << pin << mode << outvalue;
22   return l4_error(s.call(vbus));
23 }
24
25 int L4_CV
26 l4vbus_gpio_config_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
27                        unsigned pin, unsigned func, unsigned value)
28 {
29   L4::Ipc::Iostream s(l4_utcb());
30   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_CONFIG_PAD, s);
31   s << pin << func << value;
32   return l4_error(s.call(vbus));
33 }
34
35 int L4_CV
36 l4vbus_gpio_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
37 {
38   L4::Ipc::Iostream s(l4_utcb());
39   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_GET, s);
40   s << pin;
41   return l4_error(s.call(vbus));
42 }
43
44 int L4_CV
45 l4vbus_gpio_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, int value)
46 {
47   L4::Ipc::Iostream s(l4_utcb());
48   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_SET, s);
49   s << pin << value;
50   return l4_error(s.call(vbus));
51 }
52
53 int L4_CV
54 l4vbus_gpio_multi_setup(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
55                         unsigned mask, unsigned mode, unsigned outvalues)
56 {
57   L4::Ipc::Iostream s(l4_utcb());
58   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_SETUP, s);
59   s << mask << mode << outvalues;
60   return l4_error(s.call(vbus));
61 }
62
63 int L4_CV
64 l4vbus_gpio_multi_config_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
65                               unsigned mask, unsigned func, unsigned value)
66 {
67   L4::Ipc::Iostream s(l4_utcb());
68   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_CONFIG_PAD, s);
69   s << mask << func << value;
70   return l4_error(s.call(vbus));
71 }
72
73 int L4_CV
74 l4vbus_gpio_multi_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned *data)
75 {
76   L4::Ipc::Iostream s(l4_utcb());
77   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_GET, s);
78   int err = l4_error(s.call(vbus));
79   if (err >= 0 && data)
80     s >> *data;
81   return err;
82 }
83
84 int L4_CV
85 l4vbus_gpio_multi_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned mask, unsigned data)
86 {
87   L4::Ipc::Iostream s(l4_utcb());
88   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_SET, s);
89   s << mask << data;
90   return l4_error(s.call(vbus));
91 }
92
93 int L4_CV
94 l4vbus_gpio_to_irq(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
95 {
96   L4::Ipc::Iostream s(l4_utcb());
97   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_TO_IRQ, s);
98   s << pin;
99   return l4_error(s.call(vbus));
100 }
101