# HG changeset patch # User Paul Boddie # Date 1714322228 -7200 # Node ID f09c2fffc7a8e4b9debf3288758609a48ab2484f # Parent e7c6fdf897063d73caef2af02c510fcf9173b8f3 Moved GPIO pull-up/down configurations into the GPIO library and simplified the GPIO initialisation interface. diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/display/src/letux400/display-letux400.cc --- a/pkg/devices/display/src/letux400/display-letux400.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/display/src/letux400/display-letux400.cc Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Export Letux 400 display operations as a server. * - * Copyright (C) 2018, 2020, 2023 Paul Boddie + * Copyright (C) 2018, 2020, 2023, 2024 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 @@ -119,8 +119,8 @@ /* Initialise the GPIO abstractions. */ - Gpio_jz4730_chip gpb(gpio_virt_base + (1 * 0x30), gpio_virt_base + (2 * 0x30), 32); - Gpio_jz4730_chip gpc(gpio_virt_base + (2 * 0x30), gpio_virt_base + (3 * 0x30), 32); + Gpio_jz4730_chip gpb(gpio_virt_base, 1); + Gpio_jz4730_chip gpc(gpio_virt_base, 2); gpio_port_b = &gpb; gpio_port_c = &gpc; diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/display/src/qi_lb60/display-qi_lb60.cc --- a/pkg/devices/display/src/qi_lb60/display-qi_lb60.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/display/src/qi_lb60/display-qi_lb60.cc Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Export Ben NanoNote display operations as a server. * - * Copyright (C) 2018, 2020, 2023 Paul Boddie + * Copyright (C) 2018, 2020, 2023, 2024 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 @@ -116,7 +116,7 @@ /* Initialise the GPIO abstraction. */ - Gpio_jz4740_chip gpio_port(gpio_virt_base + 0x200, gpio_virt_base + 0x300, 32); + Gpio_jz4740_chip gpio_port(gpio_virt_base, 2); gpio_port_c = &gpio_port; diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/keypad/src/letux400/keypad-letux400.cc --- a/pkg/devices/keypad/src/letux400/keypad-letux400.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/keypad/src/letux400/keypad-letux400.cc Sun Apr 28 18:37:08 2024 +0200 @@ -2,7 +2,7 @@ * Export the keypad GPIOs on the Letux 400 as a data space accessible via the * "keypad" capability. * - * Copyright (C) 2018, 2023 Paul Boddie + * Copyright (C) 2018, 2023, 2024 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 @@ -83,8 +83,8 @@ if (get_memory("jz4730-gpio", &gpio_virt_base, &gpio_virt_base_end) < 0) return 1; - gpio_port_a = jz4730_gpio_init(gpio_virt_base, gpio_virt_base + 0x30, 32); - gpio_port_d = jz4730_gpio_init(gpio_virt_base + 0x90, gpio_virt_base + 0xc0, 32); + gpio_port_a = jz4730_gpio_init(gpio_virt_base, 0); + gpio_port_d = jz4730_gpio_init(gpio_virt_base, 3); return 0; } diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/keypad/src/qi_lb60/keypad-qi_lb60.cc --- a/pkg/devices/keypad/src/qi_lb60/keypad-qi_lb60.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/keypad/src/qi_lb60/keypad-qi_lb60.cc Sun Apr 28 18:37:08 2024 +0200 @@ -2,7 +2,7 @@ * Export the keypad GPIOs on the Ben NanoNote as a data space accessible via * the "keypad" capability. * - * Copyright (C) 2018, 2023 Paul Boddie + * Copyright (C) 2018, 2023, 2024 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 @@ -81,8 +81,8 @@ if (get_memory("jz4740-gpio", &gpio_virt_base, &gpio_virt_base_end) < 0) return 1; - gpio_port_c = jz4740_gpio_init(gpio_virt_base + 0x200, gpio_virt_base + 0x300, 32); - gpio_port_d = jz4740_gpio_init(gpio_virt_base + 0x300, gpio_virt_base + 0x400, 32); + gpio_port_c = jz4740_gpio_init(gpio_virt_base, 2); + gpio_port_d = jz4740_gpio_init(gpio_virt_base, 3); return 0; } diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lcd/src/jz4780/lcd-jz4780-spi-device.cc --- a/pkg/devices/lcd/src/jz4780/lcd-jz4780-spi-device.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lcd/src/jz4780/lcd-jz4780-spi-device.cc Sun Apr 28 18:37:08 2024 +0200 @@ -66,20 +66,6 @@ static Spi_hybrid *spi_channel; static Spi_jz4780_channel *spi_jz4780_channel; -struct gpio_port -{ - uint32_t pull_ups, pull_downs; -}; - -static struct gpio_port gpio_ports[] = { - {0x3fff00ff, 0x00000000}, - {0xfff0f3fc, 0x000f0c03}, - {0x0fffffff, 0x00000000}, - {0xffff4fff, 0x0000b000}, - {0xf0fff37c, 0x00000483}, - {0x7fa7f00f, 0x00580ff0}, -}; - // Disable the display. @@ -227,10 +213,7 @@ dma_chip->enable(); - gpio_chip = new Gpio_jz4780_chip(gpio_virt_base + gpio_port * 0x100, - gpio_virt_base + (gpio_port + 1) * 0x100, - 32, gpio_ports[gpio_port].pull_ups, - gpio_ports[gpio_port].pull_downs); + gpio_chip = new Gpio_jz4780_chip(gpio_virt_base, gpio_port); // Initialise the clocks for the SPI peripheral before obtaining the // peripheral abstraction. diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/include/gpio-jz4730.h --- a/pkg/devices/lib/gpio/include/gpio-jz4730.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/include/gpio-jz4730.h Sun Apr 28 18:37:08 2024 +0200 @@ -2,7 +2,7 @@ * GPIO driver for Ingenic JZ4730. * (See below for additional copyright and licensing notices.) * - * Copyright (C) 2017, 2018, 2023 Paul Boddie + * Copyright (C) 2017, 2018, 2023, 2024 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 @@ -78,8 +78,9 @@ private: Hw::Register_block<32> _regs; - l4_addr_t _start, _end; + l4_addr_t _start; unsigned _nr_pins; + struct gpio_port *_pull_config; // Convenience method for obtaining the bit corresponding to a pin. @@ -123,8 +124,7 @@ unsigned *value); public: - Gpio_jz4730_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins); + Gpio_jz4730_chip(l4_addr_t start, uint8_t port_number); // Obtain the number of pins. @@ -172,7 +172,7 @@ EXTERN_C_BEGIN -void *jz4730_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins); +void *jz4730_gpio_init(l4_addr_t start, uint8_t port_number); void jz4730_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); void jz4730_gpio_config_pull(void *gpio, unsigned pin, unsigned mode); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/include/gpio-jz4740.h --- a/pkg/devices/lib/gpio/include/gpio-jz4740.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/include/gpio-jz4740.h Sun Apr 28 18:37:08 2024 +0200 @@ -70,8 +70,9 @@ private: Hw::Register_block<32> _regs; - l4_addr_t _start, _end; + l4_addr_t _start; unsigned _nr_pins; + struct gpio_port *_pull_config; // Convenience method for obtaining the bit corresponding to a pin. @@ -110,8 +111,7 @@ void _config_pad(unsigned bitmap, unsigned func, unsigned value); public: - Gpio_jz4740_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins); + Gpio_jz4740_chip(l4_addr_t start, uint8_t port_number); // Obtain the number of pins. @@ -159,7 +159,7 @@ EXTERN_C_BEGIN -void *jz4740_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins); +void *jz4740_gpio_init(l4_addr_t start, uint8_t port_number); void jz4740_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); void jz4740_gpio_config_pull(void *gpio, unsigned pin, unsigned mode); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/include/gpio-jz4780.h --- a/pkg/devices/lib/gpio/include/gpio-jz4780.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/include/gpio-jz4780.h Sun Apr 28 18:37:08 2024 +0200 @@ -70,9 +70,9 @@ private: Hw::Register_block<32> _regs; - l4_addr_t _start, _end; + l4_addr_t _start; unsigned _nr_pins; - l4_uint32_t _pull_ups, _pull_downs; + struct gpio_port *_pull_config; // Convenience method for obtaining the bit corresponding to a pin. @@ -99,9 +99,7 @@ } public: - Gpio_jz4780_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs); + Gpio_jz4780_chip(l4_addr_t start, uint8_t port_number); // Obtain the number of pins. @@ -148,8 +146,7 @@ EXTERN_C_BEGIN -void *jz4780_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs); +void *jz4780_gpio_init(l4_addr_t start, uint8_t port_number); void jz4780_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); void jz4780_gpio_config_pull(void *gpio, unsigned pin, unsigned mode); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/include/gpio-x1600.h --- a/pkg/devices/lib/gpio/include/gpio-x1600.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/include/gpio-x1600.h Sun Apr 28 18:37:08 2024 +0200 @@ -81,13 +81,13 @@ Hw::Register_block<32> _regs, _shadow_regs; - l4_addr_t _start, _end; + l4_addr_t _start; unsigned _nr_pins; - l4_uint32_t _pull_ups, _pull_downs; + struct gpio_port *_pull_config; // Optional shadow port configuration. - l4_addr_t _shadow_start, _shadow_end; + l4_addr_t _shadow_start; uint8_t _port_number; bool _shadow; @@ -118,11 +118,7 @@ void write_reg_pin(unsigned reg, unsigned pin); public: - Gpio_x1600_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start = 0, l4_addr_t shadow_end = 0, - uint8_t port_number = 0); + Gpio_x1600_chip(l4_addr_t start, uint8_t port_number, bool shadow = false); // Obtain the number of pins. @@ -169,13 +165,9 @@ EXTERN_C_BEGIN -void *x1600_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs); +void *x1600_gpio_init(l4_addr_t start, uint8_t port_number); -void *x1600_gpio_init_shadow(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start, l4_addr_t shadow_end, - uint8_t port_number); +void *x1600_gpio_init_shadow(l4_addr_t start, uint8_t port_number); void x1600_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); void x1600_gpio_config_pull(void *gpio, unsigned pin, unsigned mode); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/include/gpio.h --- a/pkg/devices/lib/gpio/include/gpio.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/include/gpio.h Sun Apr 28 18:37:08 2024 +0200 @@ -2,7 +2,7 @@ * GPIO driver definitions. * (See below for additional copyright and licensing notices.) * - * Copyright (C) 2017, 2018, 2023 Paul Boddie + * Copyright (C) 2017, 2018, 2023, 2024 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 @@ -31,6 +31,12 @@ #pragma once #include +#include + +struct gpio_port +{ + uint32_t pull_ups, pull_downs; +}; typedef struct Pin_slice { diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/src/jz4730.cc --- a/pkg/devices/lib/gpio/src/jz4730.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/src/jz4730.cc Sun Apr 28 18:37:08 2024 +0200 @@ -2,7 +2,7 @@ * GPIO driver for Ingenic JZ4730. * (See below for additional copyright and licensing notices.) * - * Copyright (C) 2017, 2018, 2023 Paul Boddie + * Copyright (C) 2017, 2018, 2023, 2024 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 @@ -52,6 +52,17 @@ +// JZ4730 pull-up/down configuration. + +static struct gpio_port gpio_ports[] = { + {0x3fa32e0f, 0x000001f0}, + {0xf2000fff, 0x0dfff000}, + {0xffffffff, 0x00000000}, + {0xffffffff, 0x00000000}, +}; + + + // Select the appropriate register and pin where two bits are assigned per pin, // thus requiring two 32-bit registers to hold the configuration of 32 pins. @@ -233,12 +244,12 @@ // Initialise the GPIO controller. -Gpio_jz4730_chip::Gpio_jz4730_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins) -: _start(start), _end(end), - _nr_pins(nr_pins) +Gpio_jz4730_chip::Gpio_jz4730_chip(l4_addr_t start, uint8_t port_number) +: _nr_pins(32) { + _start = start + port_number * 0x30; _regs = new Hw::Mmio_register_block<32>(_start); + _pull_config = &gpio_ports[port_number]; } // Return the value of a pin. @@ -359,8 +370,11 @@ case Pull_none: _regs[Pull_enable] = _regs[Pull_enable] & ~bitmap; break; + case Pull_down: + _regs[Pull_enable] = _regs[Pull_enable] | (bitmap & _pull_config->pull_downs); + break; case Pull_up: - _regs[Pull_enable] = _regs[Pull_enable] | bitmap; + _regs[Pull_enable] = _regs[Pull_enable] | (bitmap & _pull_config->pull_ups); break; default: // Invalid pull-up/down mode for pin. @@ -516,9 +530,9 @@ // C language interface functions. -void *jz4730_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins) +void *jz4730_gpio_init(l4_addr_t start, uint8_t port_number) { - return (void *) new Gpio_jz4730_chip(start, end, pins); + return (void *) new Gpio_jz4730_chip(start, port_number); } void jz4730_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/src/jz4740.cc --- a/pkg/devices/lib/gpio/src/jz4740.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/src/jz4740.cc Sun Apr 28 18:37:08 2024 +0200 @@ -2,7 +2,7 @@ * GPIO driver for Ingenic JZ4740. * (See below for additional copyright and licensing notices.) * - * Copyright (C) 2017, 2018, 2023 Paul Boddie + * Copyright (C) 2017, 2018, 2023, 2024 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 @@ -66,6 +66,17 @@ +// JZ4740 pull-up/down configuration. + +static struct gpio_port gpio_ports[] = { + {0xffffffff, 0x00000000}, + {0xffffffff, 0x00000000}, + {0x7fffffff, 0x00000000}, + {0xdeffffff, 0x00000000}, +}; + + + // IRQ control for each GPIO pin. Gpio_jz4740_irq_pin::Gpio_jz4740_irq_pin(unsigned pin, Hw::Register_block<32> const ®s) @@ -166,12 +177,12 @@ // Initialise the GPIO controller. -Gpio_jz4740_chip::Gpio_jz4740_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins) -: _start(start), _end(end), - _nr_pins(nr_pins) +Gpio_jz4740_chip::Gpio_jz4740_chip(l4_addr_t start, uint8_t port_number) +: _nr_pins(32) { + _start = start + port_number * 0x100; _regs = new Hw::Mmio_register_block<32>(_start); + _pull_config = &gpio_ports[port_number]; } // Return the value of a pin. @@ -285,8 +296,11 @@ case Pull_none: _regs[Pull_disable_set] = bitmap; break; + case Pull_down: + _regs[Pull_disable_clear] = (bitmap & _pull_config->pull_downs); + break; case Pull_up: - _regs[Pull_disable_clear] = bitmap; + _regs[Pull_disable_clear] = (bitmap & _pull_config->pull_ups); break; default: // Invalid pull-up/down mode for pin. @@ -413,9 +427,9 @@ // C language interface functions. -void *jz4740_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins) +void *jz4740_gpio_init(l4_addr_t start, uint8_t port_number) { - return (void *) new Gpio_jz4740_chip(start, end, pins); + return (void *) new Gpio_jz4740_chip(start, port_number); } void jz4740_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/src/jz4780.cc --- a/pkg/devices/lib/gpio/src/jz4780.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/src/jz4780.cc Sun Apr 28 18:37:08 2024 +0200 @@ -91,6 +91,19 @@ +// JZ4780 pull-up/down configuration. + +static struct gpio_port gpio_ports[] = { + {0x3fff00ff, 0x00000000}, + {0xfff0f3fc, 0x000f0c03}, + {0x0fffffff, 0x00000000}, + {0xffff4fff, 0x0000b000}, + {0xf0fff37c, 0x00000483}, + {0x7fa7f00f, 0x00580ff0}, +}; + + + // IRQ control for each GPIO pin. Gpio_jz4780_irq_pin::Gpio_jz4780_irq_pin(unsigned pin, Hw::Register_block<32> const ®s) @@ -187,14 +200,12 @@ // Initialise the GPIO controller. -Gpio_jz4780_chip::Gpio_jz4780_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs) -: _start(start), _end(end), - _nr_pins(nr_pins), - _pull_ups(pull_ups), _pull_downs(pull_downs) +Gpio_jz4780_chip::Gpio_jz4780_chip(l4_addr_t start, uint8_t port_number) +: _nr_pins(32) { + _start = start + port_number * 0x100; _regs = new Hw::Mmio_register_block<32>(_start); + _pull_config = &gpio_ports[port_number]; } // Return the value of a pin. @@ -296,12 +307,12 @@ _regs[Pull_disable_set] = _pin_bit(pin); break; case Pull_down: - if (_pin_bit(pin) & _pull_downs) + if (_pin_bit(pin) & _pull_config->pull_downs) _regs[Pull_disable_clear] = _pin_bit(pin); break; case Pull_up: - if (_pin_bit(pin) & _pull_ups) - _regs[Pull_disable_clear] = _pin_bit(pin); + if (_pin_bit(pin) & _pull_config->pull_ups) + _regs[Pull_disable_clear] = _pin_bit(pin); break; default: // Invalid pull-up/down mode for pin. @@ -430,10 +441,9 @@ // C language interface functions. -void *jz4780_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs) +void *jz4780_gpio_init(l4_addr_t start, uint8_t port_number) { - return (void *) new Gpio_jz4780_chip(start, end, pins, pull_ups, pull_downs); + return (void *) new Gpio_jz4780_chip(start, port_number); } void jz4780_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/lib/gpio/src/x1600.cc --- a/pkg/devices/lib/gpio/src/x1600.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/lib/gpio/src/x1600.cc Sun Apr 28 18:37:08 2024 +0200 @@ -104,6 +104,17 @@ +// X1600 pull-up/down configuration. + +struct gpio_port gpio_ports[] = { + {0xffffffff, 0x00000000}, + {0xdffbf7bf, 0x00000000}, + {0x987e0000, 0x07000007}, + {0x0000003f, 0x00000000} +}; + + + // IRQ control for each GPIO pin. Gpio_x1600_irq_pin::Gpio_x1600_irq_pin(unsigned pin, Hw::Register_block<32> const ®s, @@ -215,23 +226,18 @@ // Initialise the GPIO controller. -Gpio_x1600_chip::Gpio_x1600_chip(l4_addr_t start, l4_addr_t end, - unsigned nr_pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start, l4_addr_t shadow_end, - uint8_t port_number) -: _start(start), _end(end), - _nr_pins(nr_pins), - _pull_ups(pull_ups), _pull_downs(pull_downs), - _shadow_start(shadow_start), _shadow_end(shadow_end), - _port_number(port_number) +Gpio_x1600_chip::Gpio_x1600_chip(l4_addr_t start, uint8_t port_number, + bool shadow) +: _nr_pins(32), _port_number(port_number), _shadow(shadow) { + _start = start + port_number * 0x100; _regs = new Hw::Mmio_register_block<32>(_start); + _pull_config = &gpio_ports[port_number]; - if (_shadow_start) + if (_shadow) { + _shadow_start = start + 0x700; _shadow_regs = new Hw::Mmio_register_block<32>(_shadow_start); - _shadow = true; } else _shadow = false; @@ -351,11 +357,11 @@ _regs[Pull_enable_clear] = _pin_bit(pin); break; case Pull_down: - if (_pin_bit(pin) & _pull_downs) + if (_pin_bit(pin) & _pull_config->pull_downs) _regs[Pull_enable_set] = _pin_bit(pin); break; case Pull_up: - if (_pin_bit(pin) & _pull_ups) + if (_pin_bit(pin) & _pull_config->pull_ups) _regs[Pull_enable_set] = _pin_bit(pin); break; default: @@ -491,19 +497,14 @@ // C language interface functions. -void *x1600_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs) +void *x1600_gpio_init(l4_addr_t start, uint8_t port_number) { - return (void *) new Gpio_x1600_chip(start, end, pins, pull_ups, pull_downs); + return (void *) new Gpio_x1600_chip(start, port_number, false); } -void *x1600_gpio_init_shadow(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start, l4_addr_t shadow_end, - uint8_t port_number) +void *x1600_gpio_init_shadow(l4_addr_t start, uint8_t port_number) { - return (void *) new Gpio_x1600_chip(start, end, pins, pull_ups, pull_downs, - shadow_start, shadow_end, port_number); + return (void *) new Gpio_x1600_chip(start, port_number, true); } void x1600_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/pwm/src/jz4730/pwm-jz4730.cc --- a/pkg/devices/pwm/src/jz4730/pwm-jz4730.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/pwm/src/jz4730/pwm-jz4730.cc Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Export a JZ4730 PWM peripheral as a server. * - * Copyright (C) 2018, 2020, 2023 Paul Boddie + * Copyright (C) 2018, 2020, 2023, 2024 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 @@ -124,8 +124,7 @@ Pwm_jz4730_chip pwm_device(pwm_virt_base + number * 0x1000, pwm_virt_base + (number + 1) * 0x1000); - Gpio_jz4730_chip gpio_port_c(gpio_virt_base + 2 * 0x30, - gpio_virt_base + 3 * 0x30, 32); + Gpio_jz4730_chip gpio_port_c(gpio_virt_base, 2); /* Enable the PWM output for PC30 or PC31. */ diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/devices/spi/src/jz4740/spi-jz4740.cc --- a/pkg/devices/spi/src/jz4740/spi-jz4740.cc Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/devices/spi/src/jz4740/spi-jz4740.cc Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Export JZ4740 GPIO pins as a SPI server. * - * Copyright (C) 2018, 2020, 2023 Paul Boddie + * Copyright (C) 2018, 2020, 2023, 2024 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 @@ -141,22 +141,19 @@ /* Configure the clock pin. */ - Gpio_jz4740_chip gpio_port_clock(gpio_virt_base + clock_port * 0x100, - gpio_virt_base + (clock_port + 1) * 0x100, 32); + Gpio_jz4740_chip gpio_port_clock(gpio_virt_base, clock_port); gpio_port_clock.setup(clock_pin, Hw::Gpio_chip::Output, 0); /* Configure the data pin. */ - Gpio_jz4740_chip gpio_port_data(gpio_virt_base + data_port * 0x100, - gpio_virt_base + (data_port + 1) * 0x100, 32); + Gpio_jz4740_chip gpio_port_data(gpio_virt_base, data_port); gpio_port_data.setup(data_pin, Hw::Gpio_chip::Output, 0); /* Configure the enable pin. */ - Gpio_jz4740_chip gpio_port_enable(gpio_virt_base + enable_port * 0x100, - gpio_virt_base + (enable_port + 1) * 0x100, 32); + Gpio_jz4740_chip gpio_port_enable(gpio_virt_base, enable_port); gpio_port_enable.setup(enable_pin, Hw::Gpio_chip::Output, 0); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/ci20_hdmi_i2c/ci20_hdmi_i2c.c --- a/pkg/landfall-examples/ci20_hdmi_i2c/ci20_hdmi_i2c.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/ci20_hdmi_i2c/ci20_hdmi_i2c.c Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Access the HDMI I2C peripheral on the MIPS Creator CI20 board. * - * Copyright (C) 2020, 2021, 2023 Paul Boddie + * Copyright (C) 2020, 2021, 2023, 2024 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 @@ -138,7 +138,6 @@ l4_addr_t gpio_base = 0, gpio_base_end = 0; l4_addr_t hdmi_base = 0, hdmi_base_end = 0; l4_addr_t lcd_base = 0, lcd_base_end = 0; - l4_addr_t port_f, port_f_end; /* Peripheral abstractions. */ @@ -284,12 +283,9 @@ /* Configure pins. */ - port_f = gpio_base + 0x500; - port_f_end = port_f + 0x100; + printf("PORTF at 0x%lx...0x%lx.\n", gpio_base + 0x500, gpio_base + 0x600); - printf("PORTF at 0x%lx...0x%lx.\n", port_f, port_f_end); - - gpio_port_f = jz4780_gpio_init(port_f, port_f_end, 32, 0x7fa7f00f, 0x00580ff0); + gpio_port_f = jz4780_gpio_init(gpio_base, 5); printf("Set up GPIO pins...\n"); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/ci20_i2c/ci20_i2c.c --- a/pkg/landfall-examples/ci20_i2c/ci20_i2c.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/ci20_i2c/ci20_i2c.c Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,8 @@ /* * (c) 2008-2009 Adam Lackorzynski * economic rights: Technische Universität Dresden (Germany) - * Copyright (C) 2017, 2018, 2019, 2020, 2023 Paul Boddie + * Copyright (C) 2017, 2018, 2019, 2020, 2023, + * 2024 Paul Boddie * * This file is part of TUD:OS and distributed under the terms of the * GNU General Public License 2. @@ -264,8 +265,6 @@ l4_addr_t i2c_base = 0, i2c_base_end = 0; l4_addr_t cpm_base = 0, cpm_base_end = 0; l4_addr_t rtc_base = 0, rtc_base_end = 0; - l4_addr_t port_d, port_d_end; - l4_addr_t port_e, port_e_end; /* Peripheral abstractions. */ @@ -379,16 +378,11 @@ /* Configure pins. */ - port_d = gpio_base + 0x300; - port_d_end = port_d + 0x100; - port_e = gpio_base + 0x400; - port_e_end = port_e + 0x100; + printf("PORTD at 0x%lx...0x%lx.\n", gpio_base + 0x300, gpio_base + 0x400); + printf("PORTE at 0x%lx...0x%lx.\n", gpio_base + 0x400, gpio_base + 0x500); - printf("PORTD at 0x%lx...0x%lx.\n", port_d, port_d_end); - printf("PORTE at 0x%lx...0x%lx.\n", port_e, port_e_end); - - gpio_port_d = jz4780_gpio_init(port_d, port_d_end, 32, 0xffff4fff, 0x0000b000); - gpio_port_e = jz4780_gpio_init(port_e, port_e_end, 32, 0xfffff37c, 0x00000483); + gpio_port_d = jz4780_gpio_init(gpio_base, 3); + gpio_port_e = jz4780_gpio_init(gpio_base, 4); printf("Set up GPIO pins...\n"); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/ci20_leds/ci20_leds.c --- a/pkg/landfall-examples/ci20_leds/ci20_leds.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/ci20_leds/ci20_leds.c Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * (c) 2008-2009 Adam Lackorzynski * economic rights: Technische Universität Dresden (Germany) - * Copyright (C) 2017, 2018, 2023 Paul Boddie + * Copyright (C) 2017, 2018, 2023, 2024 Paul Boddie * * This file is part of TUD:OS and distributed under the terms of the * GNU General Public License 2. @@ -153,7 +153,7 @@ int main(void) { - l4_addr_t gpio_base = 0, gpio_base_end = 0, port_d, port_d_end, port_f, port_f_end; + l4_addr_t gpio_base = 0, gpio_base_end = 0; l4_uint32_t gpio_irq_start = 0, gpio_irq_end = 0, gpio_irq; l4_cap_idx_t irqcap, icucap; l4_msgtag_t tag; @@ -195,17 +195,12 @@ if ((result = gpio_get_memory("jz4780-gpio", &gpio_base, &gpio_base_end)) < 0) return 1; - port_d = gpio_base + 0x300; - port_d_end = port_d + 0x100; - port_f = gpio_base + 0x500; - port_f_end = port_f + 0x100; + printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); + printf("PORTD at 0x%lx...0x%lx.\n", gpio_base + 0x300, gpio_base + 0x400); + printf("PORTF at 0x%lx...0x%lx.\n", gpio_base + 0x500, gpio_base + 0x600); - printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); - printf("PORTD at 0x%lx...0x%lx.\n", port_d, port_d_end); - printf("PORTF at 0x%lx...0x%lx.\n", port_f, port_f_end); - - gpio_port_d = jz4780_gpio_init(port_d, port_d_end, 32, 0xffff4fff, 0x0000b000); - gpio_port_f = jz4780_gpio_init(port_f, port_f_end, 32, 0xffa7f00f, 0x00580ff0); + gpio_port_d = jz4780_gpio_init(gpio_base, 3); + gpio_port_f = jz4780_gpio_init(gpio_base, 5); /* Create an interrupt object. */ diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/hw_info/common.h --- a/pkg/landfall-examples/hw_info/common.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/hw_info/common.h Sun Apr 28 18:37:08 2024 +0200 @@ -101,13 +101,9 @@ /* GPIO adapter functions. */ -void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs); +void *gpio_init(l4_addr_t start, uint8_t port_number); -void *gpio_init_shadow(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start, l4_addr_t shadow_end, - uint8_t port_number); +void *gpio_init_shadow(l4_addr_t start, uint8_t port_number); void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); @@ -316,15 +312,6 @@ -/* GPIO definitions. */ - -struct gpio_port -{ - const uint32_t pull_ups, pull_downs; -}; - - - /* Memory definitions. */ struct memory_region diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/hw_info/defs.h --- a/pkg/landfall-examples/hw_info/defs.h Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/hw_info/defs.h Sun Apr 28 18:37:08 2024 +0200 @@ -65,8 +65,6 @@ extern const unsigned int num_gpio_ports; -extern struct gpio_port gpio_ports[]; - extern const char gpio_port_labels[]; diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/hw_info/hw_info.c --- a/pkg/landfall-examples/hw_info/hw_info.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/hw_info/hw_info.c Sun Apr 28 18:37:08 2024 +0200 @@ -2006,11 +2006,7 @@ printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); for (port = 0; port < num_gpio_ports; port++) - gpio[port] = gpio_init_shadow(gpio_base + port * 0x100, gpio_base + (port + 1) * 0x100, - 32, - gpio_ports[port].pull_ups, gpio_ports[port].pull_downs, - gpio_base + 0x700, gpio_base + 0x800, - port); + gpio[port] = gpio_init_shadow(gpio_base, port); printf("Access I2C...\n"); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/hw_info/jz4780.c --- a/pkg/landfall-examples/hw_info/jz4780.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/hw_info/jz4780.c Sun Apr 28 18:37:08 2024 +0200 @@ -187,19 +187,14 @@ /* GPIO adapter functions. */ -void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs) +void *gpio_init(l4_addr_t start, uint8_t port_number) { - return jz4780_gpio_init(start, end, pins, pull_ups, pull_downs); + return jz4780_gpio_init(start, port_number); } -void *gpio_init_shadow(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start, l4_addr_t shadow_end, - uint8_t port_number) +void *gpio_init_shadow(l4_addr_t start, uint8_t port_number) { - (void) shadow_start; (void) shadow_end; (void) port_number; - return jz4780_gpio_init(start, end, pins, pull_ups, pull_downs); + return jz4780_gpio_init(start, port_number); } void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) @@ -722,15 +717,6 @@ /* GPIO definitions. */ -struct gpio_port gpio_ports[] = { - {0x3fff00ff, 0x00000000}, - {0xfff0f3fc, 0x000f0c03}, - {0x0fffffff, 0x00000000}, - {0xffff4fff, 0x0000b000}, - {0xf0fff37c, 0x00000483}, - {0x7fa7f00f, 0x00580ff0}, -}; - const unsigned int num_gpio_ports = 6; const char gpio_port_labels[] = "ABCDEF"; diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/hw_info/x1600.c --- a/pkg/landfall-examples/hw_info/x1600.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/hw_info/x1600.c Sun Apr 28 18:37:08 2024 +0200 @@ -176,19 +176,14 @@ /* GPIO adapter functions. */ -void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs) +void *gpio_init(l4_addr_t start, uint8_t port_number) { - return x1600_gpio_init(start, end, pins, pull_ups, pull_downs); + return x1600_gpio_init(start, port_number); } -void *gpio_init_shadow(l4_addr_t start, l4_addr_t end, unsigned pins, - l4_uint32_t pull_ups, l4_uint32_t pull_downs, - l4_addr_t shadow_start, l4_addr_t shadow_end, - uint8_t port_number) +void *gpio_init_shadow(l4_addr_t start, uint8_t port_number) { - return x1600_gpio_init_shadow(start, end, pins, pull_ups, pull_downs, - shadow_start, shadow_end, port_number); + return x1600_gpio_init_shadow(start, port_number); } void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) @@ -696,13 +691,6 @@ /* GPIO definitions. */ -struct gpio_port gpio_ports[] = { - {0xffffffff, 0x00000000}, - {0xdffbf7bf, 0x00000000}, - {0x987e0000, 0x07000007}, - {0x0000003f, 0x00000000} -}; - const unsigned int num_gpio_ports = 4; const char gpio_port_labels[] = "ABCD"; diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/letux400_keypad/letux400_keypad.c --- a/pkg/landfall-examples/letux400_keypad/letux400_keypad.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/letux400_keypad/letux400_keypad.c Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Access the keypad GPIOs on the Letux 400 notebook computer. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2018, 2024 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 @@ -190,8 +190,8 @@ if (!(fb = l4re_util_video_goos_fb_attach_buffer(&gfb))) return 1; - gpio_port_a = jz4730_gpio_init(gpio_virt_base, gpio_virt_base + 0x30, 32); - gpio_port_d = jz4730_gpio_init(gpio_virt_base + 0x90, gpio_virt_base + 0xc0, 32); + gpio_port_a = jz4730_gpio_init(gpio_virt_base, 0); + gpio_port_d = jz4730_gpio_init(gpio_virt_base, 3); init_keyscan(); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/letux400_leds/letux400_leds.c --- a/pkg/landfall-examples/letux400_leds/letux400_leds.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/letux400_leds/letux400_leds.c Sun Apr 28 18:37:08 2024 +0200 @@ -6,7 +6,7 @@ * PC22 - Num Lock * PC30 - PWM backlight * - * Copyright (C) 2017, 2018 Paul Boddie + * Copyright (C) 2017, 2018, 2024 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 @@ -133,7 +133,7 @@ int main(void) { - l4_addr_t gpio_base = 0, gpio_base_end = 0, port_a, port_a_end, port_c, port_c_end; + l4_addr_t gpio_base = 0, gpio_base_end = 0; l4_addr_t pwm_base = 0, pwm_base_end = 0; void *gpio_port_a, *gpio_port_c, *pwm0_device; int result = 0; @@ -146,17 +146,12 @@ if ((result = get_memory("jz4730-gpio", &gpio_base, &gpio_base_end)) < 0) return 1; - port_a = gpio_base; - port_a_end = port_a + 0x30; - port_c = gpio_base + 0x60; - port_c_end = port_c + 0x30; + printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); + printf("PORTA at 0x%lx...0x%lx.\n", gpio_base, gpio_base + 0x30); + printf("PORTC at 0x%lx...0x%lx.\n", gpio_base + 0x60, gpio_base + 0x90); - printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); - printf("PORTA at 0x%lx...0x%lx.\n", port_a, port_a_end); - printf("PORTC at 0x%lx...0x%lx.\n", port_c, port_c_end); - - gpio_port_a = jz4730_gpio_init(port_a, port_a_end, 32); - gpio_port_c = jz4730_gpio_init(port_c, port_c_end, 32); + gpio_port_a = jz4730_gpio_init(gpio_base, 0); + gpio_port_c = jz4730_gpio_init(gpio_base, 2); printf("Access PWM...\n"); diff -r e7c6fdf89706 -r f09c2fffc7a8 pkg/landfall-examples/qi_lb60_keypad/qi_lb60_keypad.c --- a/pkg/landfall-examples/qi_lb60_keypad/qi_lb60_keypad.c Sat Apr 27 23:46:28 2024 +0200 +++ b/pkg/landfall-examples/qi_lb60_keypad/qi_lb60_keypad.c Sun Apr 28 18:37:08 2024 +0200 @@ -1,7 +1,7 @@ /* * Access the keypad GPIOs on the Ben NanoNote. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2018, 2024 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 @@ -187,8 +187,8 @@ if (!(fb = l4re_util_video_goos_fb_attach_buffer(&gfb))) return 1; - gpio_port_c = jz4740_gpio_init(gpio_virt_base + 0x200, gpio_virt_base + 0x300, 32); - gpio_port_d = jz4740_gpio_init(gpio_virt_base + 0x300, gpio_virt_base + 0x400, 32); + gpio_port_c = jz4740_gpio_init(gpio_virt_base, 2); + gpio_port_d = jz4740_gpio_init(gpio_virt_base, 3); init_keyscan();