1.1 --- a/pkg/devices/Control Thu Dec 31 01:11:34 2020 +0100
1.2 +++ b/pkg/devices/Control Thu Dec 31 16:53:56 2020 +0100
1.3 @@ -30,7 +30,6 @@
1.4 provides: libdevice-lcd
1.5 provides: libdevice-lcd-jz4740
1.6 provides: libdevice-pwm-client
1.7 -provides: libdevice-spi-client
1.8 provides: libdevice-util
1.9 provides: libdrivers-common
1.10 provides: libdrivers-cpm
2.1 --- a/pkg/devices/backlight/src/spi-ili8960/Makefile Thu Dec 31 01:11:34 2020 +0100
2.2 +++ b/pkg/devices/backlight/src/spi-ili8960/Makefile Thu Dec 31 16:53:56 2020 +0100
2.3 @@ -23,23 +23,27 @@
2.4
2.5 # Individual interfaces.
2.6
2.7 +CLIENT_INTERFACES_CC = spi
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-spi-ili8960.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-spi-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/spi-ili8960/backlight-spi-ili8960.cc Thu Dec 31 01:11:34 2020 +0100
3.2 +++ b/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Thu Dec 31 16:53:56 2020 +0100
3.3 @@ -23,17 +23,11 @@
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 -
3.10 -#include <l4/devices/spi-client.h>
3.11 +#include <l4/re/env.h>
3.12
3.13 #include <ipc/server.h>
3.14 #include "backlight_object_server.h"
3.15 -
3.16 -/* SPI access abstractions. */
3.17 -
3.18 -static L4::Cap<Spi_device_interface> spi_device;
3.19 +#include "spi_client.h"
3.20
3.21
3.22
3.23 @@ -41,6 +35,7 @@
3.24
3.25 class server_BacklightObject : public BacklightObject
3.26 {
3.27 + SPI *_spi;
3.28 int _min = 55, _max = 90, _start = 70;
3.29
3.30 void set_duty(int level)
3.31 @@ -51,19 +46,24 @@
3.32
3.33 int duty = ((level - _min) / 5) << 3;
3.34
3.35 - spi_device->send(16, 0x0516 | duty); /* R05h: GRB=0 (reset); PWM_DUTY=duty; SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
3.36 - spi_device->send(16, 0x0546 | duty); /* R05h: GRB=1 (normal operation); ... */
3.37 - spi_device->send(16, 0x078d); /* R07h: HBLK=141 (horizontal blanking period from start of hsync pulse to data start) */
3.38 - spi_device->send(16, 0x1301); /* R13h: IN_SEL=1 (alignment mode) */
3.39 - spi_device->send(16, 0x0547 | duty); /* R05h: ...; STB=1 (not standby) */
3.40 + _spi->send(16, 0x0516 | duty); /* R05h: GRB=0 (reset); PWM_DUTY=duty; SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
3.41 + _spi->send(16, 0x0546 | duty); /* R05h: GRB=1 (normal operation); ... */
3.42 + _spi->send(16, 0x078d); /* R07h: HBLK=141 (horizontal blanking period from start of hsync pulse to data start) */
3.43 + _spi->send(16, 0x1301); /* R13h: IN_SEL=1 (alignment mode) */
3.44 + _spi->send(16, 0x0547 | duty); /* R05h: ...; STB=1 (not standby) */
3.45 }
3.46
3.47 public:
3.48 + explicit server_BacklightObject(SPI *spi)
3.49 + : _spi(spi)
3.50 + {
3.51 + }
3.52 +
3.53 /* Disable the backlight. */
3.54
3.55 long disable()
3.56 {
3.57 - spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
3.58 + _spi->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
3.59 return L4_EOK;
3.60 }
3.61
3.62 @@ -80,7 +80,7 @@
3.63 long set_brightness(int level)
3.64 {
3.65 level = level < _min ? _min : (level > _max ? _max : level);
3.66 - spi_device->send(16, 0x0300 | level); /* R03h: brightness */
3.67 + _spi->send(16, 0x0300 | level); /* R03h: brightness */
3.68 return L4_EOK;
3.69 }
3.70 };
3.71 @@ -91,12 +91,14 @@
3.72 {
3.73 /* Obtain a reference to the SPI device. */
3.74
3.75 - spi_device = L4Re::Env::env()->get_cap<Spi_device_interface>("spi");
3.76 - if (!spi_device.is_valid()) return 1;
3.77 + l4_cap_idx_t spi = l4re_env_get_cap("spi");
3.78 + if (!l4_is_valid_cap(spi)) return 1;
3.79 +
3.80 + client_SPI spi_obj(spi);
3.81
3.82 /* Initialise and register a new server object. */
3.83
3.84 - server_BacklightObject obj;
3.85 + server_BacklightObject obj(&spi_obj);
3.86 l4_cap_idx_t server;
3.87
3.88 if (ipc_server_bind("backlight", (l4_umword_t) &obj, &server)) return 1;
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/pkg/devices/idl/spi.idl Thu Dec 31 16:53:56 2020 +0100
4.3 @@ -0,0 +1,7 @@
4.4 +#include <l4/devices/protocols.h>
4.5 +
4.6 +[protocol(LANDFALL_SPI)]
4.7 +interface SPI
4.8 +{
4.9 + void send(in int bits, in int data);
4.10 +};
5.1 --- a/pkg/devices/include/protocols.h Thu Dec 31 01:11:34 2020 +0100
5.2 +++ b/pkg/devices/include/protocols.h Thu Dec 31 16:53:56 2020 +0100
5.3 @@ -23,3 +23,4 @@
5.4
5.5 #define LANDFALL_ACTIVATION 0x1f01
5.6 #define LANDFALL_BACKLIGHT 0x1f02
5.7 +#define LANDFALL_SPI 0x1f13
6.1 --- a/pkg/devices/spi/Makefile Thu Dec 31 01:11:34 2020 +0100
6.2 +++ b/pkg/devices/spi/Makefile Thu Dec 31 16:53:56 2020 +0100
6.3 @@ -1,8 +1,6 @@
6.4 PKGDIR ?= ..
6.5 L4DIR ?= $(PKGDIR)/../..
6.6
6.7 -TARGET := include src
6.8 +TARGET := src
6.9
6.10 include $(L4DIR)/mk/subdir.mk
6.11 -
6.12 -src: include
7.1 --- a/pkg/devices/spi/include/Makefile Thu Dec 31 01:11:34 2020 +0100
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,4 +0,0 @@
7.4 -PKGDIR = ../..
7.5 -L4DIR ?= $(PKGDIR)/../..
7.6 -
7.7 -include $(L4DIR)/mk/include.mk
8.1 --- a/pkg/devices/spi/include/spi-client.h Thu Dec 31 01:11:34 2020 +0100
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,39 +0,0 @@
8.4 -/*
8.5 - * SPI client to access SPI servers.
8.6 - *
8.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
8.8 - *
8.9 - * This program is free software; you can redistribute it and/or
8.10 - * modify it under the terms of the GNU General Public License as
8.11 - * published by the Free Software Foundation; either version 2 of
8.12 - * the License, or (at your option) any later version.
8.13 - *
8.14 - * This program is distributed in the hope that it will be useful,
8.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.17 - * GNU General Public License for more details.
8.18 - *
8.19 - * You should have received a copy of the GNU General Public License
8.20 - * along with this program; if not, write to the Free Software
8.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
8.22 - * Boston, MA 02110-1301, USA
8.23 - */
8.24 -
8.25 -#pragma once
8.26 -
8.27 -#ifdef __cplusplus
8.28 -
8.29 -#include <l4/re/env>
8.30 -#include "spi-ops.h"
8.31 -
8.32 -/* SPI device interface. */
8.33 -
8.34 -class Spi_device_interface : public L4::Kobject_t<Spi_device_interface, L4::Kobject>
8.35 -{
8.36 - L4_KOBJECT(Spi_device_interface)
8.37 -
8.38 -public:
8.39 - int send(int bits, int data) throw();
8.40 -};
8.41 -
8.42 -#endif
9.1 --- a/pkg/devices/spi/include/spi-ops.h Thu Dec 31 01:11:34 2020 +0100
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,24 +0,0 @@
9.4 -/*
9.5 - * SPI server operations.
9.6 - *
9.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
9.8 - *
9.9 - * This program is free software; you can redistribute it and/or
9.10 - * modify it under the terms of the GNU General Public License as
9.11 - * published by the Free Software Foundation; either version 2 of
9.12 - * the License, or (at your option) any later version.
9.13 - *
9.14 - * This program is distributed in the hope that it will be useful,
9.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.17 - * GNU General Public License for more details.
9.18 - *
9.19 - * You should have received a copy of the GNU General Public License
9.20 - * along with this program; if not, write to the Free Software
9.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
9.22 - * Boston, MA 02110-1301, USA
9.23 - */
9.24 -
9.25 -#pragma once
9.26 -
9.27 -enum { Spi_op_send };
10.1 --- a/pkg/devices/spi/src/client/Makefile Thu Dec 31 01:11:34 2020 +0100
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,13 +0,0 @@
10.4 -PKGDIR ?= ../../..
10.5 -L4DIR ?= $(PKGDIR)/../..
10.6 -
10.7 -TARGET = libdevice_spi_client.o.a
10.8 -PC_FILENAME := libdevice-spi-client
10.9 -
10.10 -SRC_CC := spi-client.cc
10.11 -
10.12 -PRIVATE_INCDIR += $(PKGDIR)/spi/include
10.13 -
10.14 -REQUIRES_LIBS := l4re_c l4re_c-util
10.15 -
10.16 -include $(L4DIR)/mk/lib.mk
11.1 --- a/pkg/devices/spi/src/client/spi-client.cc Thu Dec 31 01:11:34 2020 +0100
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,36 +0,0 @@
11.4 -/*
11.5 - * SPI client library to access SPI servers.
11.6 - *
11.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
11.8 - *
11.9 - * This program is free software; you can redistribute it and/or
11.10 - * modify it under the terms of the GNU General Public License as
11.11 - * published by the Free Software Foundation; either version 2 of
11.12 - * the License, or (at your option) any later version.
11.13 - *
11.14 - * This program is distributed in the hope that it will be useful,
11.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.17 - * GNU General Public License for more details.
11.18 - *
11.19 - * You should have received a copy of the GNU General Public License
11.20 - * along with this program; if not, write to the Free Software
11.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
11.22 - * Boston, MA 02110-1301, USA
11.23 - */
11.24 -
11.25 -#include <l4/cxx/ipc_stream>
11.26 -#include <l4/re/env>
11.27 -
11.28 -#include "spi-client.h"
11.29 -
11.30 -/* SPI device interface. */
11.31 -
11.32 -int
11.33 -Spi_device_interface::send(int bits, int data) throw()
11.34 -{
11.35 - L4::Ipc::Iostream s(l4_utcb());
11.36 -
11.37 - s << bits << data;
11.38 - return l4_error(s.call(cap(), Spi_op_send));
11.39 -}
12.1 --- a/pkg/devices/spi/src/jz4740/Makefile Thu Dec 31 01:11:34 2020 +0100
12.2 +++ b/pkg/devices/spi/src/jz4740/Makefile Thu Dec 31 16:53:56 2020 +0100
12.3 @@ -2,12 +2,37 @@
12.4 L4DIR ?= $(PKGDIR)/../..
12.5
12.6 TARGET = dev_spi_jz4740
12.7 -PC_FILENAME := devices-spi-jz4740
12.8 +PC_FILENAME = devices-spi-jz4740
12.9 +
12.10 +# Locations for interface input and generated output.
12.11
12.12 -SRC_CC := spi-jz4740.cc
12.13 +IDL_DIR = $(PKGDIR)/idl
12.14 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
12.15 +IDL_BUILD_DIR = .
12.16 +IDL_EXPORT_DIR = .
12.17 +
12.18 +include $(IDL_MK_DIR)/idl.mk
12.19 +
12.20 +# Individual interfaces.
12.21 +
12.22 +SERVER_INTERFACES_CC = spi
12.23
12.24 -PRIVATE_INCDIR += $(PKGDIR)/spi/include $(PKGDIR)/util/include
12.25 +# Generated and plain source files.
12.26 +
12.27 +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC))
12.28 +
12.29 +PLAIN_SRC_CC = spi-jz4740.cc
12.30
12.31 -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-util libdrivers-gpio # to use GPIO device
12.32 +# Normal definitions.
12.33 +
12.34 +SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC)
12.35 +
12.36 +REQUIRES_LIBS = l4re_c l4re_c-util libdevice-util libdrivers-gpio libipc
12.37 +
12.38 +PRIVATE_INCDIR = $(PKGDIR)/spi/include $(PKGDIR)/util/include \
12.39 + $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
12.40
12.41 include $(L4DIR)/mk/prog.mk
12.42 +include $(IDL_MK_DIR)/interface_rules.mk
12.43 +
12.44 +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC)
13.1 --- a/pkg/devices/spi/src/jz4740/spi-jz4740.cc Thu Dec 31 01:11:34 2020 +0100
13.2 +++ b/pkg/devices/spi/src/jz4740/spi-jz4740.cc Thu Dec 31 16:53:56 2020 +0100
13.3 @@ -1,7 +1,7 @@
13.4 /*
13.5 * Export JZ4740 GPIO pins as a SPI server.
13.6 *
13.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
13.8 + * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
13.9 *
13.10 * This program is free software; you can redistribute it and/or
13.11 * modify it under the terms of the GNU General Public License as
13.12 @@ -20,17 +20,16 @@
13.13 */
13.14
13.15 #include <l4/devices/gpio-jz4740.h>
13.16 +#include <l4/devices/memory.h>
13.17
13.18 -#include <l4/cxx/ipc_server>
13.19 -#include <l4/re/env>
13.20 -#include <l4/re/util/object_registry>
13.21 +#include <l4/re/env.h>
13.22
13.23 #include <errno.h>
13.24 #include <stdint.h>
13.25 #include <stdlib.h>
13.26
13.27 -#include "spi-ops.h"
13.28 -#include "memory.h"
13.29 +#include <ipc/server.h>
13.30 +#include "spi_server.h"
13.31
13.32 /* Virtual addresses for the GPIO register block. */
13.33
13.34 @@ -50,7 +49,7 @@
13.35
13.36 /* SPI peripheral device. */
13.37
13.38 -class Spi_device_server : public L4::Server_object_t<L4::Kobject>
13.39 +class server_SPI : public SPI
13.40 {
13.41 Gpio_jz4740_chip *_clock_device = 0, *_data_device = 0, *_enable_device = 0;
13.42 int _clock_pin, _data_pin, _enable_pin;
13.43 @@ -58,10 +57,10 @@
13.44 public:
13.45 /* Associate the device with a particular memory region. */
13.46
13.47 - explicit Spi_device_server(Gpio_jz4740_chip *clock_device,
13.48 - Gpio_jz4740_chip *data_device,
13.49 - Gpio_jz4740_chip *enable_device,
13.50 - int clock_pin, int data_pin, int enable_pin)
13.51 + explicit server_SPI(Gpio_jz4740_chip *clock_device,
13.52 + Gpio_jz4740_chip *data_device,
13.53 + Gpio_jz4740_chip *enable_device,
13.54 + int clock_pin, int data_pin, int enable_pin)
13.55 : _clock_device(clock_device),
13.56 _data_device(data_device),
13.57 _enable_device(enable_device),
13.58 @@ -69,32 +68,9 @@
13.59 {
13.60 }
13.61
13.62 - /* Dispatch incoming requests. */
13.63 -
13.64 - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
13.65 - {
13.66 - l4_msgtag_t tag;
13.67 - int bits, data;
13.68 -
13.69 - (void) obj;
13.70 - ios >> tag;
13.71 -
13.72 - switch (tag.label())
13.73 - {
13.74 - case Spi_op_send:
13.75 - ios >> bits;
13.76 - ios >> data;
13.77 - send(bits, data);
13.78 - return L4_EOK;
13.79 -
13.80 - default:
13.81 - return -L4_EBADPROTO;
13.82 - }
13.83 - }
13.84 -
13.85 /* Send a SPI command. */
13.86
13.87 - void send(int bits, int data)
13.88 + long send(int bits, int data)
13.89 {
13.90 uint32_t mask = 1 << (bits - 1);
13.91 int bit;
13.92 @@ -120,11 +96,11 @@
13.93 }
13.94
13.95 _enable_device->set(_enable_pin, 1);
13.96 +
13.97 + return L4_EOK;
13.98 }
13.99 };
13.100
13.101 -static L4Re::Util::Registry_server<> server;
13.102 -
13.103
13.104
13.105 /*
13.106 @@ -200,13 +176,16 @@
13.107
13.108 /* Initialise and register a new server object. */
13.109
13.110 - Spi_device_server server_obj(&gpio_port_clock, &gpio_port_data, &gpio_port_enable,
13.111 - clock_pin, data_pin, enable_pin);
13.112 + server_SPI obj(&gpio_port_clock, &gpio_port_data, &gpio_port_enable,
13.113 + clock_pin, data_pin, enable_pin);
13.114 + l4_cap_idx_t server;
13.115
13.116 - server.registry()->register_obj(&server_obj, "spi");
13.117 + if (ipc_server_bind("spi", (l4_umword_t) &obj, &server)) return 1;
13.118
13.119 /* Enter the IPC server loop. */
13.120
13.121 - server.loop();
13.122 + ipc_server_loop(SPI_expected_items, &obj,
13.123 + (ipc_server_handler_type) handle_SPI);
13.124 +
13.125 return 0;
13.126 }