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