paul@0 | 1 | /* |
paul@0 | 2 | * Export Ben NanoNote display operations as a server. |
paul@0 | 3 | * |
paul@0 | 4 | * (c) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or |
paul@0 | 7 | * modify it under the terms of the GNU General Public License as |
paul@0 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 9 | * the License, or (at your option) any later version. |
paul@0 | 10 | * |
paul@0 | 11 | * This program is distributed in the hope that it will be useful, |
paul@0 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 14 | * GNU General Public License for more details. |
paul@0 | 15 | * |
paul@0 | 16 | * You should have received a copy of the GNU General Public License |
paul@0 | 17 | * along with this program; if not, write to the Free Software |
paul@0 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 19 | * Boston, MA 02110-1301, USA |
paul@0 | 20 | */ |
paul@0 | 21 | |
paul@0 | 22 | #include <l4/devices/gpio-jz4740.h> |
paul@0 | 23 | #include <l4/devices/backlight-client.h> |
paul@0 | 24 | #include <l4/devices/lcd-jz4740-config.h> |
paul@0 | 25 | #include <l4/devices/lcd-jz4740-panel.h> |
paul@0 | 26 | #include <l4/devices/memory.h> |
paul@0 | 27 | |
paul@0 | 28 | #include <l4/cxx/ipc_server> |
paul@0 | 29 | #include <l4/re/env> |
paul@0 | 30 | #include <l4/re/util/object_registry> |
paul@0 | 31 | #include <l4/sys/capability> |
paul@0 | 32 | |
paul@0 | 33 | #include "display-ops.h" |
paul@0 | 34 | |
paul@0 | 35 | /* Virtual address for the GPIO register block. */ |
paul@0 | 36 | |
paul@0 | 37 | static l4_addr_t gpio_virt_base = 0, gpio_virt_base_end = 0; |
paul@0 | 38 | |
paul@0 | 39 | /* GPIO and backlight device abstractions. */ |
paul@0 | 40 | |
paul@0 | 41 | static Gpio_jz4740_chip *gpio_port_c = 0; |
paul@0 | 42 | static L4::Cap<Backlight_device_interface> backlight_device; |
paul@0 | 43 | |
paul@0 | 44 | |
paul@0 | 45 | |
paul@0 | 46 | /* GPIO pin definitions. */ |
paul@0 | 47 | |
paul@0 | 48 | enum Jz4740_lcd_gpio_mask |
paul@0 | 49 | { |
paul@0 | 50 | Jz4740_lcd_gpio_d0_d7 = 0xff, |
paul@0 | 51 | }; |
paul@0 | 52 | |
paul@0 | 53 | enum Jz4740_lcd_gpio |
paul@0 | 54 | { |
paul@0 | 55 | Jz4740_lcd_gpio_clk = 18, /* pixel clock */ |
paul@0 | 56 | Jz4740_lcd_gpio_rs = 19, /* hsync; command/data select */ |
paul@0 | 57 | Jz4740_lcd_gpio_cs = 20, /* vsync; chip select */ |
paul@0 | 58 | }; |
paul@0 | 59 | |
paul@0 | 60 | |
paul@0 | 61 | |
paul@0 | 62 | static int setup_memory(void) |
paul@0 | 63 | { |
paul@0 | 64 | if (get_memory("jz4740-gpio", &gpio_virt_base, &gpio_virt_base_end)) |
paul@0 | 65 | return 1; |
paul@0 | 66 | |
paul@0 | 67 | return 0; |
paul@0 | 68 | } |
paul@0 | 69 | |
paul@0 | 70 | |
paul@0 | 71 | |
paul@0 | 72 | /* Display device. */ |
paul@0 | 73 | |
paul@0 | 74 | class Display_device_server : public L4::Server_object_t<L4::Kobject> |
paul@0 | 75 | { |
paul@0 | 76 | Pin_slice slcd8_mask = {.offset=0, .mask=(1 << Jz4740_lcd_gpio_cs) | (1 << Jz4740_lcd_gpio_rs) | |
paul@0 | 77 | (1 << Jz4740_lcd_gpio_clk) | Jz4740_lcd_gpio_d0_d7}; |
paul@0 | 78 | |
paul@0 | 79 | public: |
paul@0 | 80 | /* Dispatch incoming requests. */ |
paul@0 | 81 | |
paul@0 | 82 | int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) |
paul@0 | 83 | { |
paul@0 | 84 | l4_msgtag_t tag; |
paul@0 | 85 | |
paul@0 | 86 | (void) obj; |
paul@0 | 87 | ios >> tag; |
paul@0 | 88 | |
paul@0 | 89 | switch (tag.label()) |
paul@0 | 90 | { |
paul@0 | 91 | case Display_op_disable: |
paul@0 | 92 | disable(); |
paul@0 | 93 | return L4_EOK; |
paul@0 | 94 | |
paul@0 | 95 | case Display_op_enable: |
paul@0 | 96 | enable(); |
paul@0 | 97 | return L4_EOK; |
paul@0 | 98 | |
paul@0 | 99 | default: |
paul@0 | 100 | return -L4_EBADPROTO; |
paul@0 | 101 | } |
paul@0 | 102 | } |
paul@0 | 103 | |
paul@0 | 104 | /* Switch the display off. */ |
paul@0 | 105 | |
paul@0 | 106 | void disable(void) |
paul@0 | 107 | { |
paul@0 | 108 | /* Configure SLCD8 pins. */ |
paul@0 | 109 | |
paul@0 | 110 | gpio_port_c->multi_setup(slcd8_mask, Hw::Gpio_chip::Input, 0); |
paul@0 | 111 | backlight_device->disable(); |
paul@0 | 112 | } |
paul@0 | 113 | |
paul@0 | 114 | /* Switch the display on. */ |
paul@0 | 115 | |
paul@0 | 116 | void enable(void) |
paul@0 | 117 | { |
paul@0 | 118 | /* Configure SLCD8 pins. */ |
paul@0 | 119 | |
paul@0 | 120 | gpio_port_c->multi_config_pad(slcd8_mask, Hw::Gpio_chip::Function_alt, 0); |
paul@0 | 121 | backlight_device->enable(); |
paul@0 | 122 | } |
paul@0 | 123 | }; |
paul@0 | 124 | |
paul@0 | 125 | static L4Re::Util::Registry_server<> server; |
paul@0 | 126 | |
paul@0 | 127 | |
paul@0 | 128 | |
paul@0 | 129 | int main(void) |
paul@0 | 130 | { |
paul@0 | 131 | if (setup_memory()) return 1; |
paul@0 | 132 | |
paul@0 | 133 | /* Initialise the GPIO abstraction. */ |
paul@0 | 134 | |
paul@0 | 135 | Gpio_jz4740_chip gpio_port(gpio_virt_base + 0x200, gpio_virt_base + 0x300, 32); |
paul@0 | 136 | |
paul@0 | 137 | gpio_port_c = &gpio_port; |
paul@0 | 138 | |
paul@0 | 139 | /* Obtain a reference to the backlight device. */ |
paul@0 | 140 | |
paul@0 | 141 | backlight_device = L4Re::Env::env()->get_cap<Backlight_device_interface>("backlight"); |
paul@0 | 142 | if (!backlight_device.is_valid()) return 1; |
paul@0 | 143 | |
paul@0 | 144 | /* Initialise and register a new server object. */ |
paul@0 | 145 | |
paul@0 | 146 | Display_device_server server_obj; |
paul@0 | 147 | server.registry()->register_obj(&server_obj, "display"); |
paul@0 | 148 | |
paul@0 | 149 | /* Enter the IPC server loop. */ |
paul@0 | 150 | |
paul@0 | 151 | server.loop(); |
paul@0 | 152 | return 0; |
paul@0 | 153 | } |