1 /* 2 * JZ4780 CPM server. 3 * 4 * Copyright (C) 2018, 2020, 2021 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_frequency(enum Clock_frequency_identifiers clock, uint32_t *frequency) 61 { 62 *frequency = _chip->get_frequency(clock); 63 return L4_EOK; 64 } 65 66 long set_frequency(enum Clock_frequency_identifiers clock, uint32_t frequency) 67 { 68 _chip->set_frequency(clock, frequency); 69 return L4_EOK; 70 } 71 72 long have_clock(enum Clock_identifiers clock, int *enabled) 73 { 74 *enabled = _chip->have_clock(clock); 75 return L4_EOK; 76 } 77 78 long start_clock(enum Clock_identifiers clock) 79 { 80 _chip->start_clock(clock); 81 return L4_EOK; 82 } 83 84 long stop_clock(enum Clock_identifiers clock) 85 { 86 _chip->stop_clock(clock); 87 return L4_EOK; 88 } 89 90 long update_output_frequency() 91 { 92 _chip->update_output_frequency(); 93 return L4_EOK; 94 } 95 }; 96 97 98 99 /* Main program. */ 100 101 int main(void) 102 { 103 if (setup_memory()) return 1; 104 105 /* Initialise the CPM abstraction. */ 106 107 Cpm_jz4780_chip cpm_device(cpm_virt_base, 48000000, 32768); 108 109 /* Initialise and register a server object. */ 110 111 server_CPM obj(&cpm_device); 112 l4_cap_idx_t server; 113 114 if (ipc_server_bind("cpm", (l4_umword_t) &obj, &server)) return 1; 115 116 /* Enter the IPC server loop. */ 117 118 ipc_server_loop(CPM_expected_items, &obj, 119 (ipc_server_handler_type) handle_CPM); 120 return 0; 121 }