paul@82 | 1 | /* |
paul@82 | 2 | * Export MIPS Creator CI20 HDMI display operations as a server. |
paul@82 | 3 | * |
paul@82 | 4 | * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk> |
paul@82 | 5 | * |
paul@82 | 6 | * This program is free software; you can redistribute it and/or |
paul@82 | 7 | * modify it under the terms of the GNU General Public License as |
paul@82 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@82 | 9 | * the License, or (at your option) any later version. |
paul@82 | 10 | * |
paul@82 | 11 | * This program is distributed in the hope that it will be useful, |
paul@82 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@82 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@82 | 14 | * GNU General Public License for more details. |
paul@82 | 15 | * |
paul@82 | 16 | * You should have received a copy of the GNU General Public License |
paul@82 | 17 | * along with this program; if not, write to the Free Software |
paul@82 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@82 | 19 | * Boston, MA 02110-1301, USA |
paul@82 | 20 | */ |
paul@82 | 21 | |
paul@82 | 22 | #include <l4/devices/cpm-client.h> |
paul@82 | 23 | #include <l4/devices/hdmi-jz4780.h> |
paul@82 | 24 | #include <l4/devices/lcd-jz4740-config.h> |
paul@82 | 25 | #include <l4/devices/lcd-jz4740-panel.h> |
paul@82 | 26 | #include <l4/devices/panel-loader.h> |
paul@82 | 27 | #include <l4/devices/memory.h> |
paul@82 | 28 | |
paul@82 | 29 | #include <l4/cxx/ipc_server> |
paul@82 | 30 | #include <l4/re/env> |
paul@82 | 31 | #include <l4/re/util/object_registry> |
paul@82 | 32 | #include <l4/sys/capability> |
paul@82 | 33 | #include <l4/sys/factory> |
paul@82 | 34 | #include <l4/sys/icu.h> |
paul@82 | 35 | |
paul@82 | 36 | #include "display-ops.h" |
paul@82 | 37 | |
paul@82 | 38 | /* Virtual addresses for the HDMI register block plus interrupt capability. */ |
paul@82 | 39 | |
paul@82 | 40 | static l4_addr_t hdmi_virt_base = 0, hdmi_virt_base_end = 0; |
paul@82 | 41 | static l4_uint32_t hdmi_irq_start, hdmi_irq_end; |
paul@82 | 42 | static L4::Cap<L4::Irq> hdmi_irq; |
paul@82 | 43 | static L4::Cap<L4::Icu> icu; |
paul@82 | 44 | |
paul@82 | 45 | /* CPM device abstractions. */ |
paul@82 | 46 | |
paul@82 | 47 | static Hdmi_jz4780_chip *hdmi = 0; |
paul@82 | 48 | static L4::Cap<Cpm_device_interface> cpm_device; |
paul@82 | 49 | |
paul@82 | 50 | |
paul@82 | 51 | |
paul@82 | 52 | static int setup_memory(void) |
paul@82 | 53 | { |
paul@82 | 54 | if (get_memory("jz4780-hdmi", &hdmi_virt_base, &hdmi_virt_base_end)) |
paul@82 | 55 | return 1; |
paul@82 | 56 | |
paul@82 | 57 | if (get_irq("jz4780-hdmi", &hdmi_irq_start, &hdmi_irq_end)) |
paul@82 | 58 | return 1; |
paul@82 | 59 | |
paul@82 | 60 | /* Obtain a reference to the CPM device. */ |
paul@82 | 61 | |
paul@82 | 62 | cpm_device = L4Re::Env::env()->get_cap<Cpm_device_interface>("cpm"); |
paul@82 | 63 | if (!cpm_device.is_valid()) return 1; |
paul@82 | 64 | |
paul@82 | 65 | /* Start the HDMI peripheral. */ |
paul@82 | 66 | |
paul@82 | 67 | cpm_device->stop_hdmi(); |
paul@82 | 68 | cpm_device->set_hdmi_frequency(27000000); |
paul@82 | 69 | cpm_device->start_hdmi(); |
paul@82 | 70 | |
paul@82 | 71 | /* Load the panel data from the configured library. */ |
paul@82 | 72 | |
paul@82 | 73 | struct Jz4740_lcd_panel *panel = (struct Jz4740_lcd_panel *) load_panel(); |
paul@82 | 74 | if (!panel) return 1; |
paul@82 | 75 | |
paul@82 | 76 | /* Obtain access to the HDMI interrupt using the ICU. */ |
paul@82 | 77 | |
paul@82 | 78 | icu = L4Re::Env::env()->get_cap<L4::Icu>("icu"); |
paul@82 | 79 | |
paul@82 | 80 | hdmi_irq = L4Re::Util::cap_alloc.alloc<L4::Irq>(); |
paul@82 | 81 | L4Re::Env::env()->factory()->create(hdmi_irq); |
paul@82 | 82 | |
paul@82 | 83 | if (!hdmi_irq.is_valid() || !icu.is_valid()) return 1; |
paul@82 | 84 | |
paul@82 | 85 | /* Bind the IRQ object to the interrupt in this thread. */ |
paul@82 | 86 | |
paul@82 | 87 | int err = l4_error(icu->bind(hdmi_irq_start, hdmi_irq)); |
paul@82 | 88 | if (err) return err; |
paul@82 | 89 | |
paul@82 | 90 | hdmi_irq->bind_thread(L4Re::Env::env()->main_thread(), 0); |
paul@82 | 91 | |
paul@82 | 92 | /* Obtain an abstraction for the HDMI peripheral. */ |
paul@82 | 93 | |
paul@82 | 94 | hdmi = new Hdmi_jz4780_chip(hdmi_virt_base, hdmi_virt_base_end, hdmi_irq.cap(), panel); |
paul@82 | 95 | |
paul@82 | 96 | return 0; |
paul@82 | 97 | } |
paul@82 | 98 | |
paul@82 | 99 | |
paul@82 | 100 | |
paul@82 | 101 | /* Display device. */ |
paul@82 | 102 | |
paul@82 | 103 | class Display_device_server : public L4::Server_object_t<L4::Kobject> |
paul@82 | 104 | { |
paul@82 | 105 | public: |
paul@82 | 106 | /* Dispatch incoming requests. */ |
paul@82 | 107 | |
paul@82 | 108 | int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) |
paul@82 | 109 | { |
paul@82 | 110 | l4_msgtag_t tag; |
paul@82 | 111 | |
paul@82 | 112 | (void) obj; |
paul@82 | 113 | ios >> tag; |
paul@82 | 114 | |
paul@82 | 115 | switch (tag.label()) |
paul@82 | 116 | { |
paul@82 | 117 | case Display_op_disable: |
paul@82 | 118 | disable(); |
paul@82 | 119 | return L4_EOK; |
paul@82 | 120 | |
paul@82 | 121 | case Display_op_enable: |
paul@82 | 122 | enable(); |
paul@82 | 123 | return L4_EOK; |
paul@82 | 124 | |
paul@82 | 125 | default: |
paul@82 | 126 | return -L4_EBADPROTO; |
paul@82 | 127 | } |
paul@82 | 128 | } |
paul@82 | 129 | |
paul@82 | 130 | /* Switch the display off. */ |
paul@82 | 131 | |
paul@82 | 132 | void disable(void) |
paul@82 | 133 | { |
paul@82 | 134 | } |
paul@82 | 135 | |
paul@82 | 136 | /* Switch the display on. */ |
paul@82 | 137 | |
paul@82 | 138 | void enable(void) |
paul@82 | 139 | { |
paul@82 | 140 | uint32_t frequency; |
paul@82 | 141 | |
paul@82 | 142 | // NOTE: Should test to see if it is connected. |
paul@82 | 143 | |
paul@82 | 144 | if (!cpm_device->get_lcd_pixel_frequency(&frequency)) |
paul@82 | 145 | { |
paul@82 | 146 | hdmi->enable(frequency); |
paul@82 | 147 | } |
paul@82 | 148 | } |
paul@82 | 149 | }; |
paul@82 | 150 | |
paul@82 | 151 | static L4Re::Util::Registry_server<> server; |
paul@82 | 152 | |
paul@82 | 153 | |
paul@82 | 154 | |
paul@82 | 155 | int main(void) |
paul@82 | 156 | { |
paul@82 | 157 | if (setup_memory()) return 1; |
paul@82 | 158 | |
paul@82 | 159 | /* Initialise and register a new server object. */ |
paul@82 | 160 | |
paul@82 | 161 | Display_device_server server_obj; |
paul@82 | 162 | server.registry()->register_obj(&server_obj, "display"); |
paul@82 | 163 | |
paul@82 | 164 | /* Enter the IPC server loop. */ |
paul@82 | 165 | |
paul@82 | 166 | server.loop(); |
paul@82 | 167 | return 0; |
paul@82 | 168 | } |