]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libvbus/lib/src/vbus_gpio.cc
update
[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_pull(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
27                         unsigned pin, unsigned mode)
28 {
29   L4::Ipc::Iostream s(l4_utcb());
30   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_CONFIG_PULL, s);
31   s << pin << mode;
32   return l4_error(s.call(vbus));
33 }
34
35 int L4_CV
36 l4vbus_gpio_config_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
37                        unsigned pin, unsigned func, unsigned value)
38 {
39   L4::Ipc::Iostream s(l4_utcb());
40   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_CONFIG_PAD, s);
41   s << pin << func << value;
42   return l4_error(s.call(vbus));
43 }
44
45 int L4_CV
46 l4vbus_gpio_config_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
47                        unsigned pin, unsigned func, unsigned *value)
48 {
49   L4::Ipc::Iostream s(l4_utcb());
50   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_CONFIG_GET, s);
51   s << pin << func;
52   int r = l4_error(s.call(vbus));
53   if (r)
54     return r;
55
56   s >> *value;
57
58   return 0;
59 }
60
61 int L4_CV
62 l4vbus_gpio_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
63 {
64   L4::Ipc::Iostream s(l4_utcb());
65   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_GET, s);
66   s << pin;
67   return l4_error(s.call(vbus));
68 }
69
70 int L4_CV
71 l4vbus_gpio_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, int value)
72 {
73   L4::Ipc::Iostream s(l4_utcb());
74   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_SET, s);
75   s << pin << value;
76   return l4_error(s.call(vbus));
77 }
78
79 int L4_CV
80 l4vbus_gpio_multi_setup(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
81                         unsigned offset, unsigned mask,
82                         unsigned mode, unsigned outvalues)
83 {
84   L4::Ipc::Iostream s(l4_utcb());
85   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_SETUP, s);
86   s << offset << mask << mode << outvalues;
87   return l4_error(s.call(vbus));
88 }
89
90 int L4_CV
91 l4vbus_gpio_multi_config_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
92                              unsigned offset, unsigned mask,
93                              unsigned func, unsigned value)
94 {
95   L4::Ipc::Iostream s(l4_utcb());
96   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_CONFIG_PAD, s);
97   s << offset << mask << func << value;
98   return l4_error(s.call(vbus));
99 }
100
101 int L4_CV
102 l4vbus_gpio_multi_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
103                       unsigned offset, unsigned *data)
104 {
105   L4::Ipc::Iostream s(l4_utcb());
106   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_GET, s);
107   s << offset;
108   int err = l4_error(s.call(vbus));
109   if (err >= 0 && data)
110     s >> *data;
111   return err;
112 }
113
114 int L4_CV
115 l4vbus_gpio_multi_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
116                       unsigned offset, unsigned mask, unsigned data)
117 {
118   L4::Ipc::Iostream s(l4_utcb());
119   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_MULTI_SET, s);
120   s << offset << mask << data;
121   return l4_error(s.call(vbus));
122 }
123
124 int L4_CV
125 l4vbus_gpio_to_irq(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
126 {
127   L4::Ipc::Iostream s(l4_utcb());
128   l4vbus_device_msg(handle, L4VBUS_GPIO_OP_TO_IRQ, s);
129   s << pin;
130   return l4_error(s.call(vbus));
131 }
132