1.1 --- a/pkg/devices/Control Thu Dec 31 16:58:39 2020 +0100
1.2 +++ b/pkg/devices/Control Thu Dec 31 17:59:03 2020 +0100
1.3 @@ -29,7 +29,6 @@
1.4 provides: libdevice-keypad-server
1.5 provides: libdevice-lcd
1.6 provides: libdevice-lcd-jz4740
1.7 -provides: libdevice-pwm-client
1.8 provides: libdevice-util
1.9 provides: libdrivers-common
1.10 provides: libdrivers-cpm
2.1 --- a/pkg/devices/backlight/src/pwm/Makefile Thu Dec 31 16:58:39 2020 +0100
2.2 +++ b/pkg/devices/backlight/src/pwm/Makefile Thu Dec 31 17:59:03 2020 +0100
2.3 @@ -23,23 +23,27 @@
2.4
2.5 # Individual interfaces.
2.6
2.7 +CLIENT_INTERFACES_CC = activation pwm
2.8 +
2.9 SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC))
2.10
2.11 # Generated and plain source files.
2.12
2.13 +CLIENT_INTERFACES_SRC_CC = $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC))
2.14 +
2.15 SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC))
2.16
2.17 PLAIN_SRC_CC = backlight-pwm.cc
2.18
2.19 # Normal definitions.
2.20
2.21 -SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC)
2.22 +SRC_CC = $(CLIENT_INTERFACES_SRC_CC) $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC)
2.23
2.24 -REQUIRES_LIBS = l4re_c l4re_c-util libdevice-pwm-client libipc
2.25 +REQUIRES_LIBS = l4re_c l4re_c-util libipc
2.26
2.27 PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
2.28
2.29 include $(L4DIR)/mk/prog.mk
2.30 include $(IDL_MK_DIR)/interface_rules.mk
2.31
2.32 -$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC)
2.33 +$(PLAIN_SRC_CC): $(CLIENT_INTERFACES_SRC_CC) $(SERVER_INTERFACES_SRC_CC)
3.1 --- a/pkg/devices/backlight/src/pwm/backlight-pwm.cc Thu Dec 31 16:58:39 2020 +0100
3.2 +++ b/pkg/devices/backlight/src/pwm/backlight-pwm.cc Thu Dec 31 17:59:03 2020 +0100
3.3 @@ -19,19 +19,14 @@
3.4 * Boston, MA 02110-1301, USA
3.5 */
3.6
3.7 -#include <l4/re/env>
3.8 -#include <l4/sys/capability>
3.9 +#include <l4/re/env.h>
3.10
3.11 #include <stdlib.h>
3.12
3.13 -#include <l4/devices/pwm-client.h>
3.14 -
3.15 #include <ipc/server.h>
3.16 #include "backlight_object_server.h"
3.17 -
3.18 -/* PWM access abstractions. */
3.19 -
3.20 -static L4::Cap<Pwm_device_interface> pwm_device;
3.21 +#include "activation_client.h"
3.22 +#include "pwm_client.h"
3.23
3.24
3.25
3.26 @@ -39,11 +34,14 @@
3.27
3.28 class server_BacklightObject : public BacklightObject
3.29 {
3.30 + Activation *_activation;
3.31 + PWM *_pwm;
3.32 int _min, _max;
3.33
3.34 public:
3.35 - explicit server_BacklightObject(int min, int max)
3.36 - : _min(min), _max(max)
3.37 + explicit server_BacklightObject(Activation *activation, PWM *pwm,
3.38 + int min, int max)
3.39 + : _activation(activation), _pwm(pwm), _min(min), _max(max)
3.40 {
3.41 }
3.42
3.43 @@ -51,7 +49,7 @@
3.44
3.45 long disable()
3.46 {
3.47 - pwm_device->disable();
3.48 + _activation->disable();
3.49 return L4_EOK;
3.50 }
3.51
3.52 @@ -59,7 +57,7 @@
3.53
3.54 long enable()
3.55 {
3.56 - pwm_device->enable();
3.57 + _activation->enable();
3.58 return L4_EOK;
3.59 }
3.60
3.61 @@ -67,7 +65,7 @@
3.62
3.63 long set_brightness(int level)
3.64 {
3.65 - pwm_device->set_duty(level);
3.66 + _pwm->set_duty(level);
3.67 return L4_EOK;
3.68 }
3.69 };
3.70 @@ -85,15 +83,18 @@
3.71
3.72 /* Obtain a reference to the PWM device. */
3.73
3.74 - pwm_device = L4Re::Env::env()->get_cap<Pwm_device_interface>("pwm");
3.75 - if (!pwm_device.is_valid()) return 1;
3.76 + l4_cap_idx_t pwm = l4re_env_get_cap("pwm");
3.77 + if (!l4_is_valid_cap(pwm)) return 1;
3.78 +
3.79 + client_Activation activation_obj(pwm);
3.80 + client_PWM pwm_obj(pwm);
3.81
3.82 /* Initialise and register a new server object. */
3.83
3.84 min = atoi(argv[1]);
3.85 max = atoi(argv[2]);
3.86
3.87 - server_BacklightObject obj(min, max);
3.88 + server_BacklightObject obj(&activation_obj, &pwm_obj, min, max);
3.89 l4_cap_idx_t server;
3.90
3.91 if (ipc_server_bind("backlight", (l4_umword_t) &obj, &server)) return 1;
4.1 --- a/pkg/devices/include/protocols.h Thu Dec 31 16:58:39 2020 +0100
4.2 +++ b/pkg/devices/include/protocols.h Thu Dec 31 17:59:03 2020 +0100
4.3 @@ -23,4 +23,5 @@
4.4
4.5 #define LANDFALL_ACTIVATION 0x1f01
4.6 #define LANDFALL_BACKLIGHT 0x1f02
4.7 +#define LANDFALL_PWM 0x1f10
4.8 #define LANDFALL_SPI 0x1f13
5.1 --- a/pkg/devices/pwm/include/Makefile Thu Dec 31 16:58:39 2020 +0100
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,4 +0,0 @@
5.4 -PKGDIR = ../..
5.5 -L4DIR ?= $(PKGDIR)/../..
5.6 -
5.7 -include $(L4DIR)/mk/include.mk
6.1 --- a/pkg/devices/pwm/include/pwm-client.h Thu Dec 31 16:58:39 2020 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,43 +0,0 @@
6.4 -/*
6.5 - * PWM client to access PWM servers.
6.6 - *
6.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
6.8 - *
6.9 - * This program is free software; you can redistribute it and/or
6.10 - * modify it under the terms of the GNU General Public License as
6.11 - * published by the Free Software Foundation; either version 2 of
6.12 - * the License, or (at your option) any later version.
6.13 - *
6.14 - * This program is distributed in the hope that it will be useful,
6.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 - * GNU General Public License for more details.
6.18 - *
6.19 - * You should have received a copy of the GNU General Public License
6.20 - * along with this program; if not, write to the Free Software
6.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
6.22 - * Boston, MA 02110-1301, USA
6.23 - */
6.24 -
6.25 -#pragma once
6.26 -
6.27 -#ifdef __cplusplus
6.28 -
6.29 -#include <l4/re/env>
6.30 -#include "pwm-ops.h"
6.31 -
6.32 -/* PWM device interface. */
6.33 -
6.34 -class Pwm_device_interface : public L4::Kobject_t<Pwm_device_interface, L4::Kobject>
6.35 -{
6.36 - L4_KOBJECT(Pwm_device_interface)
6.37 -
6.38 -public:
6.39 - int disable() throw();
6.40 - int enable() throw();
6.41 - int set_control(int control) throw();
6.42 - int set_duty(int duty) throw();
6.43 - int set_period(int period) throw();
6.44 -};
6.45 -
6.46 -#endif
7.1 --- a/pkg/devices/pwm/include/pwm-ops.h Thu Dec 31 16:58:39 2020 +0100
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,24 +0,0 @@
7.4 -/*
7.5 - * PWM server operations.
7.6 - *
7.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
7.8 - *
7.9 - * This program is free software; you can redistribute it and/or
7.10 - * modify it under the terms of the GNU General Public License as
7.11 - * published by the Free Software Foundation; either version 2 of
7.12 - * the License, or (at your option) any later version.
7.13 - *
7.14 - * This program is distributed in the hope that it will be useful,
7.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 - * GNU General Public License for more details.
7.18 - *
7.19 - * You should have received a copy of the GNU General Public License
7.20 - * along with this program; if not, write to the Free Software
7.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 - * Boston, MA 02110-1301, USA
7.23 - */
7.24 -
7.25 -#pragma once
7.26 -
7.27 -enum { Pwm_op_disable, Pwm_op_enable, Pwm_op_set_control, Pwm_op_set_duty, Pwm_op_set_period };
8.1 --- a/pkg/devices/pwm/src/Makefile Thu Dec 31 16:58:39 2020 +0100
8.2 +++ b/pkg/devices/pwm/src/Makefile Thu Dec 31 17:59:03 2020 +0100
8.3 @@ -1,6 +1,6 @@
8.4 PKGDIR ?= ../..
8.5 L4DIR ?= $(PKGDIR)/../..
8.6
8.7 -TARGET := client jz4730
8.8 +TARGET := jz4730
8.9
8.10 include $(L4DIR)/mk/subdir.mk
9.1 --- a/pkg/devices/pwm/src/client/Makefile Thu Dec 31 16:58:39 2020 +0100
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,13 +0,0 @@
9.4 -PKGDIR ?= ../../..
9.5 -L4DIR ?= $(PKGDIR)/../..
9.6 -
9.7 -TARGET = libdevice_pwm_client.o.a libdevice_pwm_client.o.so
9.8 -PC_FILENAME := libdevice-pwm-client
9.9 -
9.10 -SRC_CC := pwm-client.cc
9.11 -
9.12 -PRIVATE_INCDIR += $(PKGDIR)/pwm/include
9.13 -
9.14 -REQUIRES_LIBS := l4re_c l4re_c-util
9.15 -
9.16 -include $(L4DIR)/mk/lib.mk
10.1 --- a/pkg/devices/pwm/src/client/pwm-client.cc Thu Dec 31 16:58:39 2020 +0100
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,70 +0,0 @@
10.4 -/*
10.5 - * PWM client library to access PWM servers.
10.6 - *
10.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
10.8 - *
10.9 - * This program is free software; you can redistribute it and/or
10.10 - * modify it under the terms of the GNU General Public License as
10.11 - * published by the Free Software Foundation; either version 2 of
10.12 - * the License, or (at your option) any later version.
10.13 - *
10.14 - * This program is distributed in the hope that it will be useful,
10.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.17 - * GNU General Public License for more details.
10.18 - *
10.19 - * You should have received a copy of the GNU General Public License
10.20 - * along with this program; if not, write to the Free Software
10.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
10.22 - * Boston, MA 02110-1301, USA
10.23 - */
10.24 -
10.25 -#include <l4/cxx/ipc_stream>
10.26 -#include <l4/re/env>
10.27 -
10.28 -#include "pwm-client.h"
10.29 -
10.30 -/* PWM device interface. */
10.31 -
10.32 -int
10.33 -Pwm_device_interface::disable() throw()
10.34 -{
10.35 - L4::Ipc::Iostream s(l4_utcb());
10.36 -
10.37 - return l4_error(s.call(cap(), Pwm_op_disable));
10.38 -}
10.39 -
10.40 -int
10.41 -Pwm_device_interface::enable() throw()
10.42 -{
10.43 - L4::Ipc::Iostream s(l4_utcb());
10.44 -
10.45 - return l4_error(s.call(cap(), Pwm_op_enable));
10.46 -}
10.47 -
10.48 -int
10.49 -Pwm_device_interface::set_control(int control) throw()
10.50 -{
10.51 - L4::Ipc::Iostream s(l4_utcb());
10.52 -
10.53 - s << control;
10.54 - return l4_error(s.call(cap(), Pwm_op_set_control));
10.55 -}
10.56 -
10.57 -int
10.58 -Pwm_device_interface::set_duty(int duty) throw()
10.59 -{
10.60 - L4::Ipc::Iostream s(l4_utcb());
10.61 -
10.62 - s << duty;
10.63 - return l4_error(s.call(cap(), Pwm_op_set_duty));
10.64 -}
10.65 -
10.66 -int
10.67 -Pwm_device_interface::set_period(int period) throw()
10.68 -{
10.69 - L4::Ipc::Iostream s(l4_utcb());
10.70 -
10.71 - s << period;
10.72 - return l4_error(s.call(cap(), Pwm_op_set_period));
10.73 -}
11.1 --- a/pkg/devices/pwm/src/jz4730/Makefile Thu Dec 31 16:58:39 2020 +0100
11.2 +++ b/pkg/devices/pwm/src/jz4730/Makefile Thu Dec 31 17:59:03 2020 +0100
11.3 @@ -3,12 +3,43 @@
11.4
11.5 TARGET = dev_pwm_jz4730
11.6 MODE = shared
11.7 -PC_FILENAME := devices-pwm-jz4730
11.8 +PC_FILENAME = devices-pwm-jz4730
11.9 +
11.10 +# Locations for interface input and generated output.
11.11 +
11.12 +IDL_DIR = $(PKGDIR)/idl
11.13 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
11.14 +IDL_BUILD_DIR = .
11.15 +IDL_EXPORT_DIR = .
11.16
11.17 -SRC_CC := pwm-jz4730.cc
11.18 +include $(IDL_MK_DIR)/idl.mk
11.19 +
11.20 +# Compound interface definitions.
11.21 +
11.22 +pwm_object_NAME = PWMObject
11.23 +pwm_object_INTERFACES = activation pwm
11.24 +
11.25 +COMP_INTERFACES_CC = pwm_object
11.26
11.27 -PRIVATE_INCDIR += $(PKGDIR)/pwm/include $(PKGDIR)/util/include
11.28 +# Individual interfaces.
11.29 +
11.30 +SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC))
11.31 +
11.32 +# Generated and plain source files.
11.33 +
11.34 +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC))
11.35
11.36 -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-util libdrivers-pwm libdrivers-gpio # to use GPIO device
11.37 +PLAIN_SRC_CC = pwm-jz4730.cc
11.38 +
11.39 +# Normal definitions.
11.40 +
11.41 +SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC)
11.42 +
11.43 +REQUIRES_LIBS = l4re_c l4re_c-util libdevice-util libdrivers-pwm libdrivers-gpio libipc
11.44 +
11.45 +PRIVATE_INCDIR = $(PKGDIR)/pwm/include $(PKGDIR)/util/include $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
11.46
11.47 include $(L4DIR)/mk/prog.mk
11.48 +include $(IDL_MK_DIR)/interface_rules.mk
11.49 +
11.50 +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC)
12.1 --- a/pkg/devices/pwm/src/jz4730/pwm-jz4730.cc Thu Dec 31 16:58:39 2020 +0100
12.2 +++ b/pkg/devices/pwm/src/jz4730/pwm-jz4730.cc Thu Dec 31 17:59:03 2020 +0100
12.3 @@ -1,7 +1,7 @@
12.4 /*
12.5 * Export a JZ4730 PWM peripheral as a server.
12.6 *
12.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
12.8 + * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
12.9 *
12.10 * This program is free software; you can redistribute it and/or
12.11 * modify it under the terms of the GNU General Public License as
12.12 @@ -21,16 +21,15 @@
12.13
12.14 #include <l4/devices/gpio-jz4730.h>
12.15 #include <l4/devices/pwm-jz4730.h>
12.16 +#include <l4/devices/memory.h>
12.17
12.18 -#include <l4/cxx/ipc_server>
12.19 -#include <l4/re/env>
12.20 -#include <l4/re/util/object_registry>
12.21 +#include <l4/re/env.h>
12.22
12.23 #include <stdint.h>
12.24 #include <stdlib.h>
12.25
12.26 -#include "pwm-ops.h"
12.27 -#include "memory.h"
12.28 +#include <ipc/server.h>
12.29 +#include "pwm_object_server.h"
12.30
12.31 /* Virtual addresses for the GPIO and PWM register blocks. */
12.32
12.33 @@ -54,7 +53,7 @@
12.34
12.35 /* PWM peripheral device. */
12.36
12.37 -class Pwm_device_server : public L4::Server_object_t<L4::Kobject>
12.38 +class server_PWMObject : public PWMObject
12.39 {
12.40 Pwm_jz4730_chip *_device = 0;
12.41 int _duty, _period, _prescale;
12.42 @@ -62,94 +61,62 @@
12.43 public:
12.44 /* Associate the device with a particular memory region. */
12.45
12.46 - explicit Pwm_device_server(Pwm_jz4730_chip *device, int duty, int period, int prescale)
12.47 + explicit server_PWMObject(Pwm_jz4730_chip *device, int duty, int period,
12.48 + int prescale)
12.49 : _device(device), _duty(duty), _period(period), _prescale(prescale)
12.50 {
12.51 }
12.52
12.53 - /* Dispatch incoming requests. */
12.54 -
12.55 - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
12.56 - {
12.57 - l4_msgtag_t tag;
12.58 - int arg;
12.59 -
12.60 - (void) obj;
12.61 - ios >> tag;
12.62 -
12.63 - switch (tag.label())
12.64 - {
12.65 - case Pwm_op_disable:
12.66 - disable();
12.67 - return L4_EOK;
12.68 + /* Disable the device. */
12.69
12.70 - case Pwm_op_enable:
12.71 - enable();
12.72 - return L4_EOK;
12.73 -
12.74 - case Pwm_op_set_control:
12.75 - ios >> arg;
12.76 - set_control(arg);
12.77 - return L4_EOK;
12.78 -
12.79 - case Pwm_op_set_duty:
12.80 - ios >> arg;
12.81 - set_duty(arg);
12.82 - return L4_EOK;
12.83 -
12.84 - case Pwm_op_set_period:
12.85 - ios >> arg;
12.86 - set_period(arg);
12.87 - return L4_EOK;
12.88 -
12.89 - default:
12.90 - return -L4_EBADPROTO;
12.91 - }
12.92 + long disable()
12.93 + {
12.94 + _device->disable();
12.95 + return L4_EOK;
12.96 }
12.97
12.98 - void disable()
12.99 - {
12.100 - _device->disable();
12.101 - }
12.102 + /* Enable the device. */
12.103
12.104 - void enable()
12.105 + long enable()
12.106 {
12.107 set_duty(_duty);
12.108 set_period(_period);
12.109 set_control(0x80 | _prescale); /* enable | prescale */
12.110 + return L4_EOK;
12.111 }
12.112
12.113 /* Set the control register. */
12.114
12.115 - void set_control(uint8_t control)
12.116 + long set_control(uint8_t control)
12.117 {
12.118 _device->set_control(control);
12.119 + return L4_EOK;
12.120 }
12.121
12.122 /* Set the PWM duty cycle. */
12.123
12.124 - void set_duty(uint16_t duty)
12.125 + long set_duty(uint16_t duty)
12.126 {
12.127 _duty = duty;
12.128 _device->set_duty(duty);
12.129 + return L4_EOK;
12.130 }
12.131
12.132 /* Set the PWM period. */
12.133
12.134 - void set_period(uint16_t period)
12.135 + long set_period(uint16_t period)
12.136 {
12.137 _period = period;
12.138 _device->set_period(period);
12.139 + return L4_EOK;
12.140 }
12.141 };
12.142
12.143 -static L4Re::Util::Registry_server<> server;
12.144 -
12.145
12.146
12.147 /* Initialise devices and start the server. */
12.148
12.149 -static void run(int number, int duty, int period, int prescale)
12.150 +static int run(int number, int duty, int period, int prescale)
12.151 {
12.152 Pwm_jz4730_chip pwm_device(pwm_virt_base + number * 0x1000,
12.153 pwm_virt_base + (number + 1) * 0x1000);
12.154 @@ -163,12 +130,16 @@
12.155
12.156 /* Initialise and register a new server object. */
12.157
12.158 - Pwm_device_server server_obj(&pwm_device, duty, period, prescale);
12.159 - server.registry()->register_obj(&server_obj, "pwm");
12.160 + server_PWMObject obj(&pwm_device, duty, period, prescale);
12.161 + l4_cap_idx_t server;
12.162 +
12.163 + if (ipc_server_bind("pwm", (l4_umword_t) &obj, &server)) return 1;
12.164
12.165 /* Enter the IPC server loop. */
12.166
12.167 - server.loop();
12.168 + ipc_server_loop(PWMObject_expected_items, &obj,
12.169 + (ipc_server_handler_type) handle_PWMObject);
12.170 + return 0;
12.171 }
12.172
12.173
12.174 @@ -197,6 +168,5 @@
12.175
12.176 if (setup_memory()) return 1;
12.177
12.178 - run(number, duty, period, prescale);
12.179 - return 0;
12.180 + return run(number, duty, period, prescale);
12.181 }