Landfall

Annotated pkg/devices/cpm/src/jz4780/cpm-jz4780.cc

113:8fd418104ecd
2021-01-01 Paul Boddie Converted the CPM device to use interface descriptions and generated components. This affects the CI20 display device and the LCD device. idl4re-libipc-libsystypes
paul@0 1
/*
paul@0 2
 * JZ4780 CPM server.
paul@0 3
 *
paul@113 4
 * Copyright (C) 2018, 2020 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@113 28
#include "cpm_server.h"
paul@0 29
paul@0 30
// Virtual addresses for the CPM and LCD register blocks.
paul@0 31
paul@0 32
static l4_addr_t cpm_virt_base = 0, cpm_virt_base_end = 0;
paul@0 33
paul@0 34
paul@0 35
paul@0 36
// Access to peripheral memory.
paul@0 37
paul@0 38
static int setup_memory()
paul@0 39
{
paul@0 40
  if (get_memory("jz4780-cpm", &cpm_virt_base, &cpm_virt_base_end))
paul@0 41
    return 1;
paul@0 42
paul@0 43
  return 0;
paul@0 44
}
paul@0 45
paul@0 46
paul@0 47
paul@113 48
/* CPM server. */
paul@113 49
paul@113 50
class server_CPM : public CPM
paul@113 51
{
paul@113 52
  Cpm_jz4780_chip *_chip;
paul@113 53
paul@113 54
public:
paul@113 55
  explicit server_CPM(Cpm_jz4780_chip *chip)
paul@113 56
  : _chip(chip)
paul@113 57
  {
paul@113 58
  }
paul@113 59
paul@113 60
  long get_lcd_pixel_frequency(uint8_t controller, uint32_t *frequency)
paul@113 61
  {
paul@113 62
    *frequency = _chip->get_lcd_pixel_frequency(controller);
paul@113 63
    return L4_EOK;
paul@113 64
  }
paul@113 65
paul@113 66
  long set_hdmi_frequency(uint32_t frequency)
paul@113 67
  {
paul@113 68
    _chip->set_hdmi_frequency(frequency);
paul@113 69
    return L4_EOK;
paul@113 70
  }
paul@113 71
paul@113 72
  long set_lcd_frequencies(uint32_t pclk, uint8_t multiplier)
paul@113 73
  {
paul@113 74
    _chip->set_lcd_frequencies(pclk, multiplier);
paul@113 75
    return L4_EOK;
paul@113 76
  }
paul@113 77
paul@113 78
  long start_hdmi()
paul@113 79
  {
paul@113 80
    _chip->start_hdmi();
paul@113 81
    return L4_EOK;
paul@113 82
  }
paul@113 83
paul@113 84
  long stop_hdmi()
paul@113 85
  {
paul@113 86
    _chip->stop_hdmi();
paul@113 87
    return L4_EOK;
paul@113 88
  }
paul@113 89
paul@113 90
  long start_lcd()
paul@113 91
  {
paul@113 92
    _chip->start_lcd();
paul@113 93
    return L4_EOK;
paul@113 94
  }
paul@113 95
paul@113 96
  long stop_lcd()
paul@113 97
  {
paul@113 98
    _chip->stop_lcd();
paul@113 99
    return L4_EOK;
paul@113 100
  }
paul@113 101
paul@113 102
  long update_output_frequency()
paul@113 103
  {
paul@113 104
    _chip->update_output_frequency();
paul@113 105
    return L4_EOK;
paul@113 106
  }
paul@113 107
};
paul@0 108
paul@0 109
paul@0 110
paul@0 111
/* Main program. */
paul@0 112
paul@0 113
int main(void)
paul@0 114
{
paul@0 115
  if (setup_memory()) return 1;
paul@0 116
paul@0 117
  /* Initialise the CPM abstraction. */
paul@0 118
paul@0 119
  Cpm_jz4780_chip cpm_device(cpm_virt_base, 48000000, 32768);
paul@0 120
paul@0 121
  /* Initialise and register a server object. */
paul@0 122
paul@113 123
  server_CPM obj(&cpm_device);
paul@113 124
  l4_cap_idx_t server;
paul@113 125
paul@113 126
  if (ipc_server_bind("cpm", (l4_umword_t) &obj, &server)) return 1;
paul@0 127
paul@0 128
  /* Enter the IPC server loop. */
paul@0 129
paul@113 130
  ipc_server_loop(CPM_expected_items, &obj,
paul@113 131
                  (ipc_server_handler_type) handle_CPM);
paul@0 132
  return 0;
paul@0 133
}