1 /* 2 * JZ4780 CPM server. 3 * 4 * Copyright (C) 2018, 2020, 2021, 2023 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 29 #include "cpm_server.h" 30 31 // Virtual addresses for the CPM and LCD register blocks. 32 33 static l4_addr_t cpm_virt_base = 0, cpm_virt_base_end = 0; 34 35 36 37 // Access to peripheral memory. 38 39 static int setup_memory() 40 { 41 if (get_memory("jz4780-cpm", &cpm_virt_base, &cpm_virt_base_end)) 42 return 1; 43 44 return 0; 45 } 46 47 48 49 /* CPM server. */ 50 51 class CPM_server : public CPM 52 { 53 Cpm_jz4780_chip *_chip; 54 55 public: 56 explicit CPM_server(Cpm_jz4780_chip *chip) 57 : _chip(chip) 58 { 59 } 60 61 long get_frequency(enum Clock_frequency_identifiers clock, uint32_t *frequency) 62 { 63 *frequency = _chip->get_frequency(clock); 64 return L4_EOK; 65 } 66 67 long set_frequency(enum Clock_frequency_identifiers clock, uint32_t frequency) 68 { 69 _chip->set_frequency(clock, frequency); 70 return L4_EOK; 71 } 72 73 long have_clock(enum Clock_identifiers clock, int *enabled) 74 { 75 *enabled = _chip->have_clock(clock); 76 return L4_EOK; 77 } 78 79 long start_clock(enum Clock_identifiers clock) 80 { 81 _chip->start_clock(clock); 82 return L4_EOK; 83 } 84 85 long stop_clock(enum Clock_identifiers clock) 86 { 87 _chip->stop_clock(clock); 88 return L4_EOK; 89 } 90 91 long update_output_frequency() 92 { 93 _chip->update_output_frequency(); 94 return L4_EOK; 95 } 96 }; 97 98 99 100 /* Main program. */ 101 102 int main(void) 103 { 104 if (setup_memory()) 105 return 1; 106 107 /* Initialise the CPM abstraction. */ 108 109 Cpm_jz4780_chip cpm_device(cpm_virt_base, 48000000, 32768); 110 111 /* Initialise and register a server object. */ 112 113 CPM_server obj(&cpm_device); 114 115 /* Bind and start the IPC server loop. */ 116 117 if (ipc_server_loop_for(CPM, &obj, "cpm")) 118 return 1; 119 120 return 0; 121 }