paul@82 | 1 | /* |
paul@82 | 2 | * Export MIPS Creator CI20 HDMI display operations as a server. |
paul@82 | 3 | * |
paul@133 | 4 | * Copyright (C) 2018, 2020, 2021 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/hdmi-jz4780.h> |
paul@82 | 23 | #include <l4/devices/lcd-jz4740-config.h> |
paul@82 | 24 | #include <l4/devices/lcd-jz4740-panel.h> |
paul@82 | 25 | #include <l4/devices/panel-loader.h> |
paul@82 | 26 | #include <l4/devices/memory.h> |
paul@82 | 27 | |
paul@113 | 28 | #include <l4/re/env.h> |
paul@82 | 29 | |
paul@113 | 30 | #include <ipc/irq.h> |
paul@113 | 31 | #include <ipc/server.h> |
paul@113 | 32 | #include "activation_server.h" |
paul@113 | 33 | #include "cpm_client.h" |
paul@113 | 34 | #include "icu_client.h" |
paul@82 | 35 | |
paul@82 | 36 | /* Virtual addresses for the HDMI register block plus interrupt capability. */ |
paul@82 | 37 | |
paul@82 | 38 | static l4_addr_t hdmi_virt_base = 0, hdmi_virt_base_end = 0; |
paul@82 | 39 | static l4_uint32_t hdmi_irq_start, hdmi_irq_end; |
paul@113 | 40 | static l4_cap_idx_t hdmi_irq, icu; |
paul@82 | 41 | |
paul@113 | 42 | /* Device abstractions. */ |
paul@82 | 43 | |
paul@82 | 44 | static Hdmi_jz4780_chip *hdmi = 0; |
paul@113 | 45 | static CPM *cpm_device; |
paul@82 | 46 | |
paul@82 | 47 | |
paul@82 | 48 | |
paul@82 | 49 | static int setup_memory(void) |
paul@82 | 50 | { |
paul@82 | 51 | if (get_memory("jz4780-hdmi", &hdmi_virt_base, &hdmi_virt_base_end)) |
paul@82 | 52 | return 1; |
paul@82 | 53 | |
paul@82 | 54 | if (get_irq("jz4780-hdmi", &hdmi_irq_start, &hdmi_irq_end)) |
paul@82 | 55 | return 1; |
paul@82 | 56 | |
paul@82 | 57 | /* Obtain a reference to the CPM device. */ |
paul@82 | 58 | |
paul@113 | 59 | l4_cap_idx_t cpm = l4re_env_get_cap("cpm"); |
paul@113 | 60 | if (!l4_is_valid_cap(cpm)) return 1; |
paul@113 | 61 | |
paul@113 | 62 | static client_CPM cpm_obj(cpm); |
paul@113 | 63 | cpm_device = &cpm_obj; |
paul@82 | 64 | |
paul@82 | 65 | /* Start the HDMI peripheral. */ |
paul@82 | 66 | |
paul@128 | 67 | cpm_device->stop_clock(Clock_hdmi); |
paul@133 | 68 | cpm_device->set_frequency(Clock_frequency_hdmi, 27000000); |
paul@128 | 69 | cpm_device->start_clock(Clock_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@113 | 78 | icu = l4re_env_get_cap("icu"); |
paul@113 | 79 | if (!l4_is_valid_cap(icu)) return 1; |
paul@82 | 80 | |
paul@113 | 81 | if (ipc_create_irq(&hdmi_irq)) return 1; |
paul@82 | 82 | |
paul@82 | 83 | /* Bind the IRQ object to the interrupt in this thread. */ |
paul@82 | 84 | |
paul@113 | 85 | client_ICU icu_obj(icu); |
paul@113 | 86 | |
paul@113 | 87 | long err = icu_obj.bind(hdmi_irq_start, hdmi_irq); |
paul@82 | 88 | if (err) return err; |
paul@82 | 89 | |
paul@113 | 90 | err = ipc_bind_irq(hdmi_irq, 0, l4re_env()->main_thread); |
paul@113 | 91 | if (err) return err; |
paul@82 | 92 | |
paul@82 | 93 | /* Obtain an abstraction for the HDMI peripheral. */ |
paul@82 | 94 | |
paul@113 | 95 | hdmi = new Hdmi_jz4780_chip(hdmi_virt_base, hdmi_virt_base_end, hdmi_irq, panel); |
paul@82 | 96 | |
paul@82 | 97 | return 0; |
paul@82 | 98 | } |
paul@82 | 99 | |
paul@82 | 100 | |
paul@82 | 101 | |
paul@82 | 102 | /* Display device. */ |
paul@82 | 103 | |
paul@113 | 104 | class server_DisplayObject : public Activation |
paul@82 | 105 | { |
paul@82 | 106 | public: |
paul@82 | 107 | /* Switch the display off. */ |
paul@82 | 108 | |
paul@113 | 109 | long disable(void) |
paul@82 | 110 | { |
paul@113 | 111 | return L4_EOK; |
paul@82 | 112 | } |
paul@82 | 113 | |
paul@82 | 114 | /* Switch the display on. */ |
paul@82 | 115 | |
paul@113 | 116 | long enable(void) |
paul@82 | 117 | { |
paul@82 | 118 | uint32_t frequency; |
paul@82 | 119 | |
paul@82 | 120 | // NOTE: Should test to see if it is connected. |
paul@82 | 121 | |
paul@133 | 122 | if (!cpm_device->get_frequency(Clock_frequency_lcd_pixel, &frequency)) |
paul@82 | 123 | { |
paul@82 | 124 | hdmi->enable(frequency); |
paul@82 | 125 | } |
paul@113 | 126 | |
paul@113 | 127 | return L4_EOK; |
paul@82 | 128 | } |
paul@82 | 129 | }; |
paul@82 | 130 | |
paul@82 | 131 | |
paul@82 | 132 | |
paul@82 | 133 | int main(void) |
paul@82 | 134 | { |
paul@82 | 135 | if (setup_memory()) return 1; |
paul@82 | 136 | |
paul@82 | 137 | /* Initialise and register a new server object. */ |
paul@82 | 138 | |
paul@113 | 139 | server_DisplayObject obj; |
paul@113 | 140 | l4_cap_idx_t server; |
paul@113 | 141 | |
paul@113 | 142 | if (ipc_server_bind("display", (l4_umword_t) &obj, &server)) return 1; |
paul@82 | 143 | |
paul@82 | 144 | /* Enter the IPC server loop. */ |
paul@82 | 145 | |
paul@113 | 146 | ipc_server_loop(Activation_expected_items, &obj, |
paul@113 | 147 | (ipc_server_handler_type) handle_Activation); |
paul@82 | 148 | return 0; |
paul@82 | 149 | } |