1 /* 2 * CPM (clock and power management) support for the JZ4740. 3 * 4 * Copyright (C) 2017, 2018, 2020, 2021 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 #pragma once 23 24 #include <l4/devices/cpm.h> 25 26 #include <l4/sys/types.h> 27 #include <stdint.h> 28 29 30 31 #ifdef __cplusplus 32 33 #include <l4/devices/hw_register_block.h> 34 35 /* A simple abstraction for accessing the CPM registers. 36 * A proper device could inherit from Hw::Device and use an 37 * Int_property for _exclk_freq. */ 38 39 class Cpm_jz4740_chip : public Cpm_chip 40 { 41 private: 42 Hw::Register_block<32> _regs; 43 uint32_t _exclk_freq; 44 45 int pll_enabled(); 46 int pll_bypassed(); 47 48 // Clock control. 49 50 uint32_t get_clock_gate_value(enum Clock_identifiers clock); 51 52 public: 53 Cpm_jz4740_chip(l4_addr_t addr, uint32_t exclk_freq); 54 55 int have_clock(enum Clock_identifiers clock); 56 void start_clock(enum Clock_identifiers clock); 57 void stop_clock(enum Clock_identifiers clock); 58 59 int have_pll(); 60 61 uint16_t get_multiplier(); 62 uint8_t get_input_division(); 63 uint8_t get_output_division(); 64 65 uint8_t _get_divider(uint32_t reg, uint32_t mask, uint8_t shift); 66 uint8_t get_cpu_divider(); 67 uint8_t get_hclock_divider(); 68 uint8_t get_pclock_divider(); 69 uint8_t get_memory_divider(); 70 uint8_t get_source_divider(); 71 72 uint16_t get_lcd_pixel_divider(); 73 74 void set_lcd_device_divider(uint8_t division); 75 void set_lcd_pixel_divider(uint16_t division); 76 77 uint32_t get_frequency(enum Clock_frequency_identifiers clock); 78 void set_frequency(enum Clock_frequency_identifiers clock, uint32_t frequency); 79 80 uint32_t get_pll_frequency(); 81 uint32_t get_output_frequency(); 82 void update_output_frequency(); 83 84 uint32_t get_cpu_frequency(); 85 uint32_t get_hclock_frequency(); 86 uint32_t get_pclock_frequency(); 87 uint32_t get_memory_frequency(); 88 }; 89 90 #endif /* __cplusplus */ 91 92 93 94 /* C language interface. */ 95 96 EXTERN_C_BEGIN 97 98 void *jz4740_cpm_init(l4_addr_t cpm_base); 99 100 int jz4740_cpm_have_pll(void *cpm); 101 102 int jz4740_cpm_have_clock(void *cpm, enum Clock_identifiers clock); 103 void jz4740_cpm_start_clock(void *cpm, enum Clock_identifiers clock); 104 void jz4740_cpm_stop_clock(void *cpm, enum Clock_identifiers clock); 105 106 uint16_t jz4740_cpm_get_lcd_pixel_divider(void *cpm); 107 108 uint32_t jz4740_cpm_get_frequency(void *cpm, enum Clock_frequency_identifiers clock); 109 void jz4740_cpm_set_frequency(void *cpm, enum Clock_frequency_identifiers clock, uint32_t frequency); 110 111 void jz4740_cpm_update_output_frequency(void *cpm); 112 113 uint32_t jz4740_cpm_get_cpu_frequency(void *cpm); 114 uint32_t jz4740_cpm_get_hclock_frequency(void *cpm); 115 uint32_t jz4740_cpm_get_output_frequency(void *cpm); 116 uint32_t jz4740_cpm_get_pclock_frequency(void *cpm); 117 uint32_t jz4740_cpm_get_memory_frequency(void *cpm); 118 119 EXTERN_C_END