# HG changeset patch # User Paul Boddie # Date 1609430036 -3600 # Node ID a7e13175b11aa0ef072196560e7b4e1ab993b27d # Parent 4ec7afff2072717094696a79d428b9ed87cb8bb4 Converted the SPI device to use interface descriptions and generated components. This affects the Ben NanoNote backlight device. diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/Control --- a/pkg/devices/Control Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/Control Thu Dec 31 16:53:56 2020 +0100 @@ -30,7 +30,6 @@ provides: libdevice-lcd provides: libdevice-lcd-jz4740 provides: libdevice-pwm-client -provides: libdevice-spi-client provides: libdevice-util provides: libdrivers-common provides: libdrivers-cpm diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/backlight/src/spi-ili8960/Makefile --- a/pkg/devices/backlight/src/spi-ili8960/Makefile Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/backlight/src/spi-ili8960/Makefile Thu Dec 31 16:53:56 2020 +0100 @@ -23,23 +23,27 @@ # Individual interfaces. +CLIENT_INTERFACES_CC = spi + SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC)) # Generated and plain source files. +CLIENT_INTERFACES_SRC_CC = $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC)) + SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC)) PLAIN_SRC_CC = backlight-spi-ili8960.cc # Normal definitions. -SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) +SRC_CC = $(CLIENT_INTERFACES_SRC_CC) $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) -REQUIRES_LIBS = l4re_c l4re_c-util libdevice-spi-client libipc +REQUIRES_LIBS = l4re_c l4re_c-util libipc PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) include $(L4DIR)/mk/prog.mk include $(IDL_MK_DIR)/interface_rules.mk -$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC) +$(PLAIN_SRC_CC): $(CLIENT_INTERFACES_SRC_CC) $(SERVER_INTERFACES_SRC_CC) diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc --- a/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Thu Dec 31 16:53:56 2020 +0100 @@ -23,17 +23,11 @@ * Boston, MA 02110-1301, USA */ -#include -#include - -#include +#include #include #include "backlight_object_server.h" - -/* SPI access abstractions. */ - -static L4::Cap spi_device; +#include "spi_client.h" @@ -41,6 +35,7 @@ class server_BacklightObject : public BacklightObject { + SPI *_spi; int _min = 55, _max = 90, _start = 70; void set_duty(int level) @@ -51,19 +46,24 @@ int duty = ((level - _min) / 5) << 3; - spi_device->send(16, 0x0516 | duty); /* R05h: GRB=0 (reset); PWM_DUTY=duty; SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */ - spi_device->send(16, 0x0546 | duty); /* R05h: GRB=1 (normal operation); ... */ - spi_device->send(16, 0x078d); /* R07h: HBLK=141 (horizontal blanking period from start of hsync pulse to data start) */ - spi_device->send(16, 0x1301); /* R13h: IN_SEL=1 (alignment mode) */ - spi_device->send(16, 0x0547 | duty); /* R05h: ...; STB=1 (not standby) */ + _spi->send(16, 0x0516 | duty); /* R05h: GRB=0 (reset); PWM_DUTY=duty; SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */ + _spi->send(16, 0x0546 | duty); /* R05h: GRB=1 (normal operation); ... */ + _spi->send(16, 0x078d); /* R07h: HBLK=141 (horizontal blanking period from start of hsync pulse to data start) */ + _spi->send(16, 0x1301); /* R13h: IN_SEL=1 (alignment mode) */ + _spi->send(16, 0x0547 | duty); /* R05h: ...; STB=1 (not standby) */ } public: + explicit server_BacklightObject(SPI *spi) + : _spi(spi) + { + } + /* Disable the backlight. */ long disable() { - spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */ + _spi->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */ return L4_EOK; } @@ -80,7 +80,7 @@ long set_brightness(int level) { level = level < _min ? _min : (level > _max ? _max : level); - spi_device->send(16, 0x0300 | level); /* R03h: brightness */ + _spi->send(16, 0x0300 | level); /* R03h: brightness */ return L4_EOK; } }; @@ -91,12 +91,14 @@ { /* Obtain a reference to the SPI device. */ - spi_device = L4Re::Env::env()->get_cap("spi"); - if (!spi_device.is_valid()) return 1; + l4_cap_idx_t spi = l4re_env_get_cap("spi"); + if (!l4_is_valid_cap(spi)) return 1; + + client_SPI spi_obj(spi); /* Initialise and register a new server object. */ - server_BacklightObject obj; + server_BacklightObject obj(&spi_obj); l4_cap_idx_t server; if (ipc_server_bind("backlight", (l4_umword_t) &obj, &server)) return 1; diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/idl/spi.idl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/devices/idl/spi.idl Thu Dec 31 16:53:56 2020 +0100 @@ -0,0 +1,7 @@ +#include + +[protocol(LANDFALL_SPI)] +interface SPI +{ + void send(in int bits, in int data); +}; diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/include/protocols.h --- a/pkg/devices/include/protocols.h Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/include/protocols.h Thu Dec 31 16:53:56 2020 +0100 @@ -23,3 +23,4 @@ #define LANDFALL_ACTIVATION 0x1f01 #define LANDFALL_BACKLIGHT 0x1f02 +#define LANDFALL_SPI 0x1f13 diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/Makefile --- a/pkg/devices/spi/Makefile Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/spi/Makefile Thu Dec 31 16:53:56 2020 +0100 @@ -1,8 +1,6 @@ PKGDIR ?= .. L4DIR ?= $(PKGDIR)/../.. -TARGET := include src +TARGET := src include $(L4DIR)/mk/subdir.mk - -src: include diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/include/Makefile --- a/pkg/devices/spi/include/Makefile Thu Dec 31 01:11:34 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -PKGDIR = ../.. -L4DIR ?= $(PKGDIR)/../.. - -include $(L4DIR)/mk/include.mk diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/include/spi-client.h --- a/pkg/devices/spi/include/spi-client.h Thu Dec 31 01:11:34 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * SPI client to access SPI servers. - * - * Copyright (C) 2018 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#pragma once - -#ifdef __cplusplus - -#include -#include "spi-ops.h" - -/* SPI device interface. */ - -class Spi_device_interface : public L4::Kobject_t -{ - L4_KOBJECT(Spi_device_interface) - -public: - int send(int bits, int data) throw(); -}; - -#endif diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/include/spi-ops.h --- a/pkg/devices/spi/include/spi-ops.h Thu Dec 31 01:11:34 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* - * SPI server operations. - * - * Copyright (C) 2018 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#pragma once - -enum { Spi_op_send }; diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/src/client/Makefile --- a/pkg/devices/spi/src/client/Makefile Thu Dec 31 01:11:34 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -PKGDIR ?= ../../.. -L4DIR ?= $(PKGDIR)/../.. - -TARGET = libdevice_spi_client.o.a -PC_FILENAME := libdevice-spi-client - -SRC_CC := spi-client.cc - -PRIVATE_INCDIR += $(PKGDIR)/spi/include - -REQUIRES_LIBS := l4re_c l4re_c-util - -include $(L4DIR)/mk/lib.mk diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/src/client/spi-client.cc --- a/pkg/devices/spi/src/client/spi-client.cc Thu Dec 31 01:11:34 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * SPI client library to access SPI servers. - * - * Copyright (C) 2018 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#include -#include - -#include "spi-client.h" - -/* SPI device interface. */ - -int -Spi_device_interface::send(int bits, int data) throw() -{ - L4::Ipc::Iostream s(l4_utcb()); - - s << bits << data; - return l4_error(s.call(cap(), Spi_op_send)); -} diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/src/jz4740/Makefile --- a/pkg/devices/spi/src/jz4740/Makefile Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/spi/src/jz4740/Makefile Thu Dec 31 16:53:56 2020 +0100 @@ -2,12 +2,37 @@ L4DIR ?= $(PKGDIR)/../.. TARGET = dev_spi_jz4740 -PC_FILENAME := devices-spi-jz4740 +PC_FILENAME = devices-spi-jz4740 + +# Locations for interface input and generated output. -SRC_CC := spi-jz4740.cc +IDL_DIR = $(PKGDIR)/idl +IDL_MK_DIR = $(L4DIR)/idl4re/mk +IDL_BUILD_DIR = . +IDL_EXPORT_DIR = . + +include $(IDL_MK_DIR)/idl.mk + +# Individual interfaces. + +SERVER_INTERFACES_CC = spi -PRIVATE_INCDIR += $(PKGDIR)/spi/include $(PKGDIR)/util/include +# Generated and plain source files. + +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC)) + +PLAIN_SRC_CC = spi-jz4740.cc -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-util libdrivers-gpio # to use GPIO device +# Normal definitions. + +SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) + +REQUIRES_LIBS = l4re_c l4re_c-util libdevice-util libdrivers-gpio libipc + +PRIVATE_INCDIR = $(PKGDIR)/spi/include $(PKGDIR)/util/include \ + $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) include $(L4DIR)/mk/prog.mk +include $(IDL_MK_DIR)/interface_rules.mk + +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC) diff -r 4ec7afff2072 -r a7e13175b11a pkg/devices/spi/src/jz4740/spi-jz4740.cc --- a/pkg/devices/spi/src/jz4740/spi-jz4740.cc Thu Dec 31 01:11:34 2020 +0100 +++ b/pkg/devices/spi/src/jz4740/spi-jz4740.cc Thu Dec 31 16:53:56 2020 +0100 @@ -1,7 +1,7 @@ /* * Export JZ4740 GPIO pins as a SPI server. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2018, 2020 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,17 +20,16 @@ */ #include +#include -#include -#include -#include +#include #include #include #include -#include "spi-ops.h" -#include "memory.h" +#include +#include "spi_server.h" /* Virtual addresses for the GPIO register block. */ @@ -50,7 +49,7 @@ /* SPI peripheral device. */ -class Spi_device_server : public L4::Server_object_t +class server_SPI : public SPI { Gpio_jz4740_chip *_clock_device = 0, *_data_device = 0, *_enable_device = 0; int _clock_pin, _data_pin, _enable_pin; @@ -58,10 +57,10 @@ public: /* Associate the device with a particular memory region. */ - explicit Spi_device_server(Gpio_jz4740_chip *clock_device, - Gpio_jz4740_chip *data_device, - Gpio_jz4740_chip *enable_device, - int clock_pin, int data_pin, int enable_pin) + explicit server_SPI(Gpio_jz4740_chip *clock_device, + Gpio_jz4740_chip *data_device, + Gpio_jz4740_chip *enable_device, + int clock_pin, int data_pin, int enable_pin) : _clock_device(clock_device), _data_device(data_device), _enable_device(enable_device), @@ -69,32 +68,9 @@ { } - /* Dispatch incoming requests. */ - - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) - { - l4_msgtag_t tag; - int bits, data; - - (void) obj; - ios >> tag; - - switch (tag.label()) - { - case Spi_op_send: - ios >> bits; - ios >> data; - send(bits, data); - return L4_EOK; - - default: - return -L4_EBADPROTO; - } - } - /* Send a SPI command. */ - void send(int bits, int data) + long send(int bits, int data) { uint32_t mask = 1 << (bits - 1); int bit; @@ -120,11 +96,11 @@ } _enable_device->set(_enable_pin, 1); + + return L4_EOK; } }; -static L4Re::Util::Registry_server<> server; - /* @@ -200,13 +176,16 @@ /* Initialise and register a new server object. */ - Spi_device_server server_obj(&gpio_port_clock, &gpio_port_data, &gpio_port_enable, - clock_pin, data_pin, enable_pin); + server_SPI obj(&gpio_port_clock, &gpio_port_data, &gpio_port_enable, + clock_pin, data_pin, enable_pin); + l4_cap_idx_t server; - server.registry()->register_obj(&server_obj, "spi"); + if (ipc_server_bind("spi", (l4_umword_t) &obj, &server)) return 1; /* Enter the IPC server loop. */ - server.loop(); + ipc_server_loop(SPI_expected_items, &obj, + (ipc_server_handler_type) handle_SPI); + return 0; }