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