1 /* 2 * JZ4730 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-jz4730.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("jz4730-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_jz4730_chip *_chip; 54 55 public: 56 explicit CPM_server(Cpm_jz4730_chip *chip) 57 : _chip(chip) 58 { 59 } 60 61 long set_frequency(enum Clock_identifiers clock, uint32_t frequency) 62 { 63 _chip->set_frequency(clock, frequency); 64 return L4_EOK; 65 } 66 67 long have_clock(enum Clock_identifiers clock, int *enabled) 68 { 69 *enabled = _chip->have_clock(clock); 70 return L4_EOK; 71 } 72 73 long start_clock(enum Clock_identifiers clock) 74 { 75 _chip->start_clock(clock); 76 return L4_EOK; 77 } 78 79 long stop_clock(enum Clock_identifiers clock) 80 { 81 _chip->stop_clock(clock); 82 return L4_EOK; 83 } 84 }; 85 86 87 88 /* Main program. */ 89 90 int main(void) 91 { 92 if (setup_memory()) 93 return 1; 94 95 /* Initialise the CPM abstraction. */ 96 97 Cpm_jz4730_chip cpm_device(cpm_virt_base); 98 99 /* Initialise and register a server object. */ 100 101 CPM_server obj(&cpm_device); 102 103 /* Bind and start the IPC server loop. */ 104 105 if (ipc_server_loop_for(CPM, &obj, "cpm")) 106 return 1; 107 108 return 0; 109 }