1 /* 2 * JZ4730 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-jz4730.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("jz4730-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_jz4730_chip *_chip; 53 54 public: 55 explicit server_CPM(Cpm_jz4730_chip *chip) 56 : _chip(chip) 57 { 58 } 59 60 long set_lcd_frequencies(uint32_t pclk, uint8_t multiplier) 61 { 62 _chip->set_lcd_frequencies(pclk, multiplier); 63 return L4_EOK; 64 } 65 66 long start_lcd() 67 { 68 _chip->start_lcd(); 69 return L4_EOK; 70 } 71 72 long stop_lcd() 73 { 74 _chip->stop_lcd(); 75 return L4_EOK; 76 } 77 78 long update_output_frequency() 79 { 80 _chip->update_output_frequency(); 81 return L4_EOK; 82 } 83 }; 84 85 86 87 /* Main program. */ 88 89 int main(void) 90 { 91 if (setup_memory()) return 1; 92 93 /* Initialise the CPM abstraction. */ 94 95 Cpm_jz4730_chip cpm_device(cpm_virt_base, 3686400); 96 97 /* Initialise and register a server object. */ 98 99 server_CPM obj(&cpm_device); 100 l4_cap_idx_t server; 101 102 if (ipc_server_bind("cpm", (l4_umword_t) &obj, &server)) return 1; 103 104 /* Enter the IPC server loop. */ 105 106 ipc_server_loop(CPM_expected_items, &obj, 107 (ipc_server_handler_type) handle_CPM); 108 return 0; 109 }