1 /* 2 * Export Letux 400 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-jz4730.h> 23 #include <l4/devices/memory.h> 24 25 #include <l4/re/env.h> 26 27 #include <ipc/server.h> 28 #include "activation_client.h" 29 #include "activation_server.h" 30 31 /* Virtual address for the GPIO register block. */ 32 33 static l4_addr_t gpio_virt_base = 0, gpio_virt_base_end = 0; 34 35 /* GPIO abstraction. */ 36 37 static Gpio_jz4730_chip *gpio_port_b = 0, *gpio_port_c = 0; 38 39 40 41 /* GPIO pin definitions. */ 42 43 enum Jz4730_lcd_gpio_mask 44 { 45 Jz4730_lcd_gpio_func1 = 0xf8ffff00, 46 Jz4730_lcd_gpio_func2 = 0x07000000, 47 }; 48 49 enum Jz4730_lcd_gpio 50 { 51 Jz4730_lcd_gpio_led_enable = 28, 52 Jz4730_lcd_gpio_display_enable = 29, 53 }; 54 55 56 57 static int setup_memory(void) 58 { 59 if (get_memory("jz4730-gpio", &gpio_virt_base, &gpio_virt_base_end)) 60 return 1; 61 62 return 0; 63 } 64 65 66 67 /* Display device only implementing the activation interface. */ 68 69 class server_DisplayObject : public Activation 70 { 71 Pin_slice lcd_mask1 = {.offset=0, .mask=Jz4730_lcd_gpio_func1}; 72 Pin_slice lcd_mask2 = {.offset=0, .mask=Jz4730_lcd_gpio_func2}; 73 74 Activation *_backlight; 75 76 public: 77 explicit server_DisplayObject(Activation *backlight) 78 : _backlight(backlight) 79 { 80 /* Set functions for the LCD pins. */ 81 82 gpio_port_b->multi_config_pad(lcd_mask1, Hw::Gpio_chip::Function_alt, 1); 83 gpio_port_b->multi_config_pad(lcd_mask2, Hw::Gpio_chip::Function_alt, 2); 84 85 /* Enable LED, disable display. */ 86 87 gpio_port_c->setup(Jz4730_lcd_gpio_led_enable, Hw::Gpio_chip::Output, 1); 88 gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 0); 89 } 90 91 /* Switch the display off. */ 92 93 long disable(void) 94 { 95 gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 0); 96 _backlight->disable(); 97 return L4_EOK; 98 } 99 100 /* Switch the display on. */ 101 102 long enable(void) 103 { 104 gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 1); 105 _backlight->enable(); 106 return L4_EOK; 107 } 108 }; 109 110 111 112 int main(void) 113 { 114 if (setup_memory()) return 1; 115 116 /* Initialise the GPIO abstractions. */ 117 118 Gpio_jz4730_chip gpb(gpio_virt_base + (1 * 0x30), gpio_virt_base + (2 * 0x30), 32); 119 Gpio_jz4730_chip gpc(gpio_virt_base + (2 * 0x30), gpio_virt_base + (3 * 0x30), 32); 120 121 gpio_port_b = &gpb; 122 gpio_port_c = &gpc; 123 124 /* Obtain a reference to the backlight device. */ 125 126 l4_cap_idx_t backlight = l4re_env_get_cap("backlight"); 127 if (!l4_is_valid_cap(backlight)) return 1; 128 129 /* Use the activation interface with the backlight. */ 130 131 client_Activation backlight_obj(backlight); 132 133 /* Initialise and register a new server object. */ 134 135 server_DisplayObject obj(&backlight_obj); 136 l4_cap_idx_t server; 137 138 if (ipc_server_bind("display", (l4_umword_t) &obj, &server)) return 1; 139 140 /* Enter the IPC server loop. */ 141 142 ipc_server_loop(Activation_expected_items, &obj, 143 (ipc_server_handler_type) handle_Activation); 144 return 0; 145 }