paul@0 | 1 | /* |
paul@0 | 2 | * JZ4780 CPM server. |
paul@0 | 3 | * |
paul@152 | 4 | * Copyright (C) 2018, 2020, 2021, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or |
paul@0 | 7 | * modify it under the terms of the GNU General Public License as |
paul@0 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 9 | * the License, or (at your option) any later version. |
paul@0 | 10 | * |
paul@0 | 11 | * This program is distributed in the hope that it will be useful, |
paul@0 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 14 | * GNU General Public License for more details. |
paul@0 | 15 | * |
paul@0 | 16 | * You should have received a copy of the GNU General Public License |
paul@0 | 17 | * along with this program; if not, write to the Free Software |
paul@0 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 19 | * Boston, MA 02110-1301, USA |
paul@0 | 20 | */ |
paul@0 | 21 | |
paul@0 | 22 | #include <l4/devices/cpm-jz4780.h> |
paul@0 | 23 | #include <l4/devices/memory.h> |
paul@113 | 24 | |
paul@113 | 25 | #include <l4/re/env.h> |
paul@0 | 26 | |
paul@113 | 27 | #include <ipc/server.h> |
paul@152 | 28 | |
paul@113 | 29 | #include "cpm_server.h" |
paul@0 | 30 | |
paul@0 | 31 | // Virtual addresses for the CPM and LCD register blocks. |
paul@0 | 32 | |
paul@0 | 33 | static l4_addr_t cpm_virt_base = 0, cpm_virt_base_end = 0; |
paul@0 | 34 | |
paul@0 | 35 | |
paul@0 | 36 | |
paul@0 | 37 | // Access to peripheral memory. |
paul@0 | 38 | |
paul@0 | 39 | static int setup_memory() |
paul@0 | 40 | { |
paul@0 | 41 | if (get_memory("jz4780-cpm", &cpm_virt_base, &cpm_virt_base_end)) |
paul@0 | 42 | return 1; |
paul@0 | 43 | |
paul@0 | 44 | return 0; |
paul@0 | 45 | } |
paul@0 | 46 | |
paul@0 | 47 | |
paul@0 | 48 | |
paul@113 | 49 | /* CPM server. */ |
paul@113 | 50 | |
paul@152 | 51 | class CPM_server : public CPM |
paul@113 | 52 | { |
paul@113 | 53 | Cpm_jz4780_chip *_chip; |
paul@113 | 54 | |
paul@113 | 55 | public: |
paul@152 | 56 | explicit CPM_server(Cpm_jz4780_chip *chip) |
paul@113 | 57 | : _chip(chip) |
paul@113 | 58 | { |
paul@113 | 59 | } |
paul@113 | 60 | |
paul@160 | 61 | long get_frequency(enum Clock_identifiers clock, uint32_t *frequency) |
paul@113 | 62 | { |
paul@133 | 63 | *frequency = _chip->get_frequency(clock); |
paul@113 | 64 | return L4_EOK; |
paul@113 | 65 | } |
paul@113 | 66 | |
paul@160 | 67 | long set_frequency(enum Clock_identifiers clock, uint32_t frequency) |
paul@113 | 68 | { |
paul@133 | 69 | _chip->set_frequency(clock, frequency); |
paul@113 | 70 | return L4_EOK; |
paul@113 | 71 | } |
paul@113 | 72 | |
paul@128 | 73 | long have_clock(enum Clock_identifiers clock, int *enabled) |
paul@113 | 74 | { |
paul@128 | 75 | *enabled = _chip->have_clock(clock); |
paul@113 | 76 | return L4_EOK; |
paul@113 | 77 | } |
paul@113 | 78 | |
paul@128 | 79 | long start_clock(enum Clock_identifiers clock) |
paul@113 | 80 | { |
paul@128 | 81 | _chip->start_clock(clock); |
paul@113 | 82 | return L4_EOK; |
paul@113 | 83 | } |
paul@113 | 84 | |
paul@128 | 85 | long stop_clock(enum Clock_identifiers clock) |
paul@113 | 86 | { |
paul@128 | 87 | _chip->stop_clock(clock); |
paul@113 | 88 | return L4_EOK; |
paul@113 | 89 | } |
paul@113 | 90 | }; |
paul@0 | 91 | |
paul@0 | 92 | |
paul@0 | 93 | |
paul@0 | 94 | /* Main program. */ |
paul@0 | 95 | |
paul@0 | 96 | int main(void) |
paul@0 | 97 | { |
paul@152 | 98 | if (setup_memory()) |
paul@152 | 99 | return 1; |
paul@0 | 100 | |
paul@0 | 101 | /* Initialise the CPM abstraction. */ |
paul@0 | 102 | |
paul@0 | 103 | Cpm_jz4780_chip cpm_device(cpm_virt_base, 48000000, 32768); |
paul@0 | 104 | |
paul@0 | 105 | /* Initialise and register a server object. */ |
paul@0 | 106 | |
paul@152 | 107 | CPM_server obj(&cpm_device); |
paul@113 | 108 | |
paul@152 | 109 | /* Bind and start the IPC server loop. */ |
paul@0 | 110 | |
paul@152 | 111 | if (ipc_server_loop_for(CPM, &obj, "cpm")) |
paul@152 | 112 | return 1; |
paul@0 | 113 | |
paul@0 | 114 | return 0; |
paul@0 | 115 | } |