Landfall

Annotated pkg/devices/lib/cpm/include/cpm-jz4740.h

31:bab304c3775e
2018-05-30 Paul Boddie Fixed copyright notices to actually use the word "Copyright".
paul@0 1
/*
paul@31 2
 * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
paul@0 3
 *
paul@0 4
 * This program is free software; you can redistribute it and/or
paul@0 5
 * modify it under the terms of the GNU General Public License as
paul@0 6
 * published by the Free Software Foundation; either version 2 of
paul@0 7
 * the License, or (at your option) any later version.
paul@0 8
 *
paul@0 9
 * This program is distributed in the hope that it will be useful,
paul@0 10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@0 11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@0 12
 * GNU General Public License for more details.
paul@0 13
 *
paul@0 14
 * You should have received a copy of the GNU General Public License
paul@0 15
 * along with this program; if not, write to the Free Software
paul@0 16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@0 17
 * Boston, MA  02110-1301, USA
paul@0 18
 */
paul@0 19
paul@0 20
#pragma once
paul@0 21
paul@0 22
#include "cpm.h"
paul@0 23
paul@0 24
#include <l4/sys/types.h>
paul@0 25
#include <stdint.h>
paul@0 26
paul@0 27
paul@0 28
paul@0 29
#ifdef __cplusplus
paul@0 30
paul@0 31
#include <l4/devices/hw_register_block.h>
paul@0 32
paul@0 33
/* A simple abstraction for accessing the CPM registers.
paul@0 34
 * A proper device could inherit from Hw::Device and use an
paul@0 35
 * Int_property for _exclk_freq. */
paul@0 36
paul@0 37
class Cpm_jz4740_chip : public Cpm_chip
paul@0 38
{
paul@0 39
private:
paul@0 40
  Hw::Register_block<32> _regs;
paul@0 41
  uint32_t _exclk_freq;
paul@0 42
paul@0 43
  int pll_enabled();
paul@0 44
  int pll_bypassed();
paul@0 45
paul@0 46
public:
paul@0 47
  Cpm_jz4740_chip(l4_addr_t addr, uint32_t exclk_freq);
paul@0 48
paul@0 49
  int have_clock();
paul@0 50
  void start_clock();
paul@0 51
paul@0 52
  int have_pll();
paul@0 53
paul@0 54
  uint16_t get_multiplier();
paul@0 55
  uint8_t get_input_division();
paul@0 56
  uint8_t get_output_division();
paul@0 57
paul@0 58
  uint8_t _get_divider(uint32_t reg, uint32_t mask, uint8_t shift);
paul@0 59
  uint8_t get_cpu_divider();
paul@0 60
  uint8_t get_hclock_divider();
paul@0 61
  uint8_t get_pclock_divider();
paul@0 62
  uint8_t get_memory_divider();
paul@0 63
  uint8_t get_source_divider();
paul@0 64
paul@0 65
  uint16_t get_lcd_pixel_divider();
paul@0 66
  uint32_t get_lcd_pixel_frequency();
paul@0 67
paul@0 68
  void set_lcd_device_divider(uint8_t division);
paul@0 69
  void set_lcd_pixel_divider(uint16_t division);
paul@0 70
  void set_lcd_frequencies(uint32_t pclk, uint8_t ratio);
paul@0 71
paul@0 72
  void start_lcd();
paul@0 73
  void stop_lcd();
paul@0 74
paul@0 75
  uint32_t get_pll_frequency();
paul@0 76
  uint32_t get_output_frequency();
paul@0 77
  void update_output_frequency();
paul@0 78
paul@0 79
  uint32_t get_cpu_frequency();
paul@0 80
  uint32_t get_hclock_frequency();
paul@0 81
  uint32_t get_pclock_frequency();
paul@0 82
  uint32_t get_memory_frequency();
paul@0 83
};
paul@0 84
paul@0 85
#endif /* __cplusplus */
paul@0 86
paul@0 87
paul@0 88
paul@0 89
/* C language interface. */
paul@0 90
paul@0 91
EXTERN_C_BEGIN
paul@0 92
paul@0 93
void *jz4740_cpm_init(l4_addr_t cpm_base);
paul@0 94
paul@0 95
int jz4740_cpm_have_pll(void *cpm);
paul@0 96
paul@0 97
int jz4740_cpm_have_clock(void *cpm);
paul@0 98
void jz4740_cpm_start_clock(void *cpm);
paul@0 99
paul@0 100
void jz4740_cpm_start_lcd(void *cpm);
paul@0 101
void jz4740_cpm_stop_lcd(void *cpm);
paul@0 102
paul@0 103
uint16_t jz4740_cpm_get_lcd_pixel_divider(void *cpm);
paul@0 104
uint32_t jz4740_cpm_get_lcd_pixel_frequency(void *cpm);
paul@0 105
paul@0 106
void jz4740_cpm_set_lcd_frequencies(void *cpm, uint32_t pclk, uint8_t ratio);
paul@0 107
void jz4740_cpm_update_output_frequency(void *cpm);
paul@0 108
paul@0 109
uint32_t jz4740_cpm_get_cpu_frequency(void *cpm);
paul@0 110
uint32_t jz4740_cpm_get_hclock_frequency(void *cpm);
paul@0 111
uint32_t jz4740_cpm_get_output_frequency(void *cpm);
paul@0 112
uint32_t jz4740_cpm_get_pclock_frequency(void *cpm);
paul@0 113
uint32_t jz4740_cpm_get_memory_frequency(void *cpm);
paul@0 114
paul@0 115
EXTERN_C_END