paul@0 | 1 | /* |
paul@0 | 2 | * Export Letux 400 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-jz4730.h> |
paul@0 | 23 | #include <l4/devices/backlight-client.h> |
paul@0 | 24 | #include <l4/devices/memory.h> |
paul@0 | 25 | |
paul@0 | 26 | #include <l4/cxx/ipc_server> |
paul@0 | 27 | #include <l4/re/env> |
paul@0 | 28 | #include <l4/re/util/object_registry> |
paul@0 | 29 | #include <l4/sys/capability> |
paul@0 | 30 | |
paul@0 | 31 | #include "display-ops.h" |
paul@0 | 32 | |
paul@0 | 33 | /* Virtual address for the GPIO register block. */ |
paul@0 | 34 | |
paul@0 | 35 | static l4_addr_t gpio_virt_base = 0, gpio_virt_base_end = 0; |
paul@0 | 36 | |
paul@0 | 37 | /* GPIO and backlight device abstractions. */ |
paul@0 | 38 | |
paul@0 | 39 | static Gpio_jz4730_chip *gpio_port_b = 0, *gpio_port_c = 0; |
paul@0 | 40 | static L4::Cap<Backlight_device_interface> backlight_device; |
paul@0 | 41 | |
paul@0 | 42 | |
paul@0 | 43 | |
paul@0 | 44 | /* GPIO pin definitions. */ |
paul@0 | 45 | |
paul@0 | 46 | enum Jz4730_lcd_gpio_mask |
paul@0 | 47 | { |
paul@0 | 48 | Jz4730_lcd_gpio_func1 = 0xf8ffff00, |
paul@0 | 49 | Jz4730_lcd_gpio_func2 = 0x07000000, |
paul@0 | 50 | }; |
paul@0 | 51 | |
paul@0 | 52 | enum Jz4730_lcd_gpio |
paul@0 | 53 | { |
paul@0 | 54 | Jz4730_lcd_gpio_led_enable = 28, |
paul@0 | 55 | Jz4730_lcd_gpio_display_enable = 29, |
paul@0 | 56 | }; |
paul@0 | 57 | |
paul@0 | 58 | |
paul@0 | 59 | |
paul@0 | 60 | static int setup_memory(void) |
paul@0 | 61 | { |
paul@0 | 62 | if (get_memory("jz4730-gpio", &gpio_virt_base, &gpio_virt_base_end)) |
paul@0 | 63 | return 1; |
paul@0 | 64 | |
paul@0 | 65 | return 0; |
paul@0 | 66 | } |
paul@0 | 67 | |
paul@0 | 68 | |
paul@0 | 69 | |
paul@0 | 70 | /* Display device. */ |
paul@0 | 71 | |
paul@0 | 72 | class Display_device_server : public L4::Server_object_t<L4::Kobject> |
paul@0 | 73 | { |
paul@0 | 74 | Pin_slice lcd_mask1 = {.offset=0, .mask=Jz4730_lcd_gpio_func1}; |
paul@0 | 75 | Pin_slice lcd_mask2 = {.offset=0, .mask=Jz4730_lcd_gpio_func2}; |
paul@0 | 76 | |
paul@0 | 77 | public: |
paul@0 | 78 | explicit Display_device_server() |
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 | /* Dispatch incoming requests. */ |
paul@0 | 92 | |
paul@0 | 93 | int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) |
paul@0 | 94 | { |
paul@0 | 95 | l4_msgtag_t tag; |
paul@0 | 96 | |
paul@0 | 97 | (void) obj; |
paul@0 | 98 | ios >> tag; |
paul@0 | 99 | |
paul@0 | 100 | switch (tag.label()) |
paul@0 | 101 | { |
paul@0 | 102 | case Display_op_disable: |
paul@0 | 103 | disable(); |
paul@0 | 104 | return L4_EOK; |
paul@0 | 105 | |
paul@0 | 106 | case Display_op_enable: |
paul@0 | 107 | enable(); |
paul@0 | 108 | return L4_EOK; |
paul@0 | 109 | |
paul@0 | 110 | default: |
paul@0 | 111 | return -L4_EBADPROTO; |
paul@0 | 112 | } |
paul@0 | 113 | } |
paul@0 | 114 | |
paul@0 | 115 | /* Switch the display off. */ |
paul@0 | 116 | |
paul@0 | 117 | void disable(void) |
paul@0 | 118 | { |
paul@0 | 119 | gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 0); |
paul@0 | 120 | backlight_device->disable(); |
paul@0 | 121 | } |
paul@0 | 122 | |
paul@0 | 123 | /* Switch the display on. */ |
paul@0 | 124 | |
paul@0 | 125 | void enable(void) |
paul@0 | 126 | { |
paul@0 | 127 | gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 1); |
paul@0 | 128 | backlight_device->enable(); |
paul@0 | 129 | } |
paul@0 | 130 | }; |
paul@0 | 131 | |
paul@0 | 132 | static L4Re::Util::Registry_server<> server; |
paul@0 | 133 | |
paul@0 | 134 | |
paul@0 | 135 | |
paul@0 | 136 | int main(void) |
paul@0 | 137 | { |
paul@0 | 138 | if (setup_memory()) return 1; |
paul@0 | 139 | |
paul@0 | 140 | /* Initialise the GPIO abstractions. */ |
paul@0 | 141 | |
paul@0 | 142 | Gpio_jz4730_chip gpb(gpio_virt_base + (1 * 0x30), gpio_virt_base + (2 * 0x30), 32); |
paul@0 | 143 | Gpio_jz4730_chip gpc(gpio_virt_base + (2 * 0x30), gpio_virt_base + (3 * 0x30), 32); |
paul@0 | 144 | |
paul@0 | 145 | gpio_port_b = &gpb; |
paul@0 | 146 | gpio_port_c = &gpc; |
paul@0 | 147 | |
paul@0 | 148 | /* Obtain a reference to the backlight device. */ |
paul@0 | 149 | |
paul@0 | 150 | backlight_device = L4Re::Env::env()->get_cap<Backlight_device_interface>("backlight"); |
paul@0 | 151 | if (!backlight_device.is_valid()) return 1; |
paul@0 | 152 | |
paul@0 | 153 | /* Initialise and register a new server object. */ |
paul@0 | 154 | |
paul@0 | 155 | Display_device_server server_obj; |
paul@0 | 156 | server.registry()->register_obj(&server_obj, "display"); |
paul@0 | 157 | |
paul@0 | 158 | /* Enter the IPC server loop. */ |
paul@0 | 159 | |
paul@0 | 160 | server.loop(); |
paul@0 | 161 | return 0; |
paul@0 | 162 | } |