1 /* 2 * JZ4780 CPM 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/cpm-jz4780.h> 23 #include <l4/devices/memory.h> 24 25 #include <l4/re/env.h> 26 27 #include <ipc/server.h> 28 #include "cpm_server.h" 29 30 // Virtual addresses for the CPM and LCD register blocks. 31 32 static l4_addr_t cpm_virt_base = 0, cpm_virt_base_end = 0; 33 34 35 36 // Access to peripheral memory. 37 38 static int setup_memory() 39 { 40 if (get_memory("jz4780-cpm", &cpm_virt_base, &cpm_virt_base_end)) 41 return 1; 42 43 return 0; 44 } 45 46 47 48 /* CPM server. */ 49 50 class server_CPM : public CPM 51 { 52 Cpm_jz4780_chip *_chip; 53 54 public: 55 explicit server_CPM(Cpm_jz4780_chip *chip) 56 : _chip(chip) 57 { 58 } 59 60 long get_lcd_pixel_frequency(uint8_t controller, uint32_t *frequency) 61 { 62 *frequency = _chip->get_lcd_pixel_frequency(controller); 63 return L4_EOK; 64 } 65 66 long set_hdmi_frequency(uint32_t frequency) 67 { 68 _chip->set_hdmi_frequency(frequency); 69 return L4_EOK; 70 } 71 72 long set_lcd_frequencies(uint32_t pclk, uint8_t multiplier) 73 { 74 _chip->set_lcd_frequencies(pclk, multiplier); 75 return L4_EOK; 76 } 77 78 long start_hdmi() 79 { 80 _chip->start_hdmi(); 81 return L4_EOK; 82 } 83 84 long stop_hdmi() 85 { 86 _chip->stop_hdmi(); 87 return L4_EOK; 88 } 89 90 long start_lcd() 91 { 92 _chip->start_lcd(); 93 return L4_EOK; 94 } 95 96 long stop_lcd() 97 { 98 _chip->stop_lcd(); 99 return L4_EOK; 100 } 101 102 long update_output_frequency() 103 { 104 _chip->update_output_frequency(); 105 return L4_EOK; 106 } 107 }; 108 109 110 111 /* Main program. */ 112 113 int main(void) 114 { 115 if (setup_memory()) return 1; 116 117 /* Initialise the CPM abstraction. */ 118 119 Cpm_jz4780_chip cpm_device(cpm_virt_base, 48000000, 32768); 120 121 /* Initialise and register a server object. */ 122 123 server_CPM obj(&cpm_device); 124 l4_cap_idx_t server; 125 126 if (ipc_server_bind("cpm", (l4_umword_t) &obj, &server)) return 1; 127 128 /* Enter the IPC server loop. */ 129 130 ipc_server_loop(CPM_expected_items, &obj, 131 (ipc_server_handler_type) handle_CPM); 132 return 0; 133 }