paul@160 | 1 | /* |
paul@160 | 2 | * CPM (clock and power management) support for the X1600. |
paul@160 | 3 | * |
paul@160 | 4 | * Copyright (C) 2017, 2018, 2020, 2021, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@160 | 5 | * |
paul@160 | 6 | * This program is free software; you can redistribute it and/or |
paul@160 | 7 | * modify it under the terms of the GNU General Public License as |
paul@160 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@160 | 9 | * the License, or (at your option) any later version. |
paul@160 | 10 | * |
paul@160 | 11 | * This program is distributed in the hope that it will be useful, |
paul@160 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@160 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@160 | 14 | * GNU General Public License for more details. |
paul@160 | 15 | * |
paul@160 | 16 | * You should have received a copy of the GNU General Public License |
paul@160 | 17 | * along with this program; if not, write to the Free Software |
paul@160 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@160 | 19 | * Boston, MA 02110-1301, USA |
paul@160 | 20 | */ |
paul@160 | 21 | |
paul@160 | 22 | #pragma once |
paul@160 | 23 | |
paul@160 | 24 | #include <l4/devices/cpm.h> |
paul@160 | 25 | |
paul@160 | 26 | #include <l4/sys/types.h> |
paul@160 | 27 | #include <stdint.h> |
paul@160 | 28 | |
paul@160 | 29 | |
paul@160 | 30 | |
paul@160 | 31 | #ifdef __cplusplus |
paul@160 | 32 | |
paul@160 | 33 | #include <l4/devices/hw_register_block.h> |
paul@160 | 34 | |
paul@160 | 35 | /* A simple abstraction for accessing the CPM registers. |
paul@160 | 36 | * A proper device could inherit from Hw::Device and use an |
paul@160 | 37 | * Int_property for _exclk_freq. */ |
paul@160 | 38 | |
paul@160 | 39 | class Cpm_x1600_chip : public Cpm_chip |
paul@160 | 40 | { |
paul@160 | 41 | private: |
paul@160 | 42 | Hw::Register_block<32> _regs; |
paul@160 | 43 | uint32_t _exclk_freq; |
paul@160 | 44 | |
paul@160 | 45 | // Utility methods. |
paul@160 | 46 | |
paul@160 | 47 | uint32_t get_field(uint32_t reg, uint32_t mask, uint8_t shift); |
paul@160 | 48 | void set_field(uint32_t reg, uint32_t mask, uint8_t shift, uint32_t value); |
paul@160 | 49 | uint8_t _get_divider(uint32_t reg, uint32_t mask, uint8_t shift); |
paul@160 | 50 | |
paul@160 | 51 | // PLL control. |
paul@160 | 52 | |
paul@160 | 53 | int have_pll(uint32_t pll_reg); |
paul@160 | 54 | int pll_enabled(uint32_t pll_reg); |
paul@160 | 55 | int pll_bypassed(uint32_t pll_reg); |
paul@160 | 56 | void pll_disable(uint32_t pll_reg); |
paul@160 | 57 | void pll_enable(uint32_t pll_reg); |
paul@160 | 58 | |
paul@160 | 59 | // General frequency modifiers. |
paul@160 | 60 | |
paul@160 | 61 | uint16_t get_multiplier(uint32_t pll_reg); |
paul@160 | 62 | void set_multiplier(uint32_t pll_reg, uint16_t multiplier); |
paul@160 | 63 | uint8_t get_input_division(uint32_t pll_reg); |
paul@160 | 64 | void set_input_division(uint32_t pll_reg, uint8_t divider); |
paul@160 | 65 | uint8_t get_output_division(uint32_t pll_reg); |
paul@160 | 66 | void set_output_division(uint32_t pll_reg, uint8_t divider); |
paul@160 | 67 | |
paul@160 | 68 | // Clock dividers. |
paul@160 | 69 | |
paul@160 | 70 | void set_lcd_pixel_divider(uint8_t controller, uint16_t division); |
paul@160 | 71 | |
paul@160 | 72 | // Input frequencies. |
paul@160 | 73 | |
paul@160 | 74 | uint32_t get_pll_frequency(uint32_t pll_reg); |
paul@160 | 75 | |
paul@160 | 76 | // Clock sources. |
paul@160 | 77 | |
paul@160 | 78 | void set_hclock2_source(uint8_t source); |
paul@160 | 79 | void set_lcd_source(uint8_t controller, uint8_t source); |
paul@160 | 80 | |
paul@160 | 81 | // Clock control. |
paul@160 | 82 | |
paul@160 | 83 | uint32_t get_clock_gate_register(enum Clock_identifiers clock); |
paul@160 | 84 | uint32_t get_clock_gate_value(enum Clock_identifiers clock); |
paul@160 | 85 | |
paul@160 | 86 | public: |
paul@160 | 87 | void set_pclock_source(uint8_t source); |
paul@160 | 88 | Cpm_x1600_chip(l4_addr_t addr, uint32_t exclk_freq); |
paul@160 | 89 | |
paul@160 | 90 | int have_clock(enum Clock_identifiers clock); |
paul@160 | 91 | void start_clock(enum Clock_identifiers clock); |
paul@160 | 92 | void stop_clock(enum Clock_identifiers clock); |
paul@160 | 93 | |
paul@160 | 94 | // Clock divider values. |
paul@160 | 95 | |
paul@160 | 96 | uint8_t get_cpu_divider(); |
paul@160 | 97 | uint8_t get_hclock0_divider(); |
paul@160 | 98 | uint8_t get_hclock2_divider(); |
paul@160 | 99 | uint8_t get_pclock_divider(); |
paul@160 | 100 | uint8_t get_lcd_pixel_divider(uint8_t controller = 0); |
paul@160 | 101 | uint8_t get_memory_divider(); |
paul@160 | 102 | |
paul@160 | 103 | // Input frequencies. |
paul@160 | 104 | |
paul@160 | 105 | uint8_t get_main_source(); |
paul@160 | 106 | uint32_t get_main_frequency(); |
paul@160 | 107 | |
paul@160 | 108 | // Clock sources, providing the input frequency. |
paul@160 | 109 | |
paul@160 | 110 | uint8_t get_cpu_source(); |
paul@160 | 111 | uint8_t get_hclock0_source(); |
paul@160 | 112 | uint8_t get_hclock2_source(); |
paul@160 | 113 | uint8_t get_lcd_source(uint8_t controller); |
paul@160 | 114 | uint8_t get_lcd_source() { return get_lcd_source(0); } |
paul@160 | 115 | uint8_t get_memory_source(); |
paul@160 | 116 | uint8_t get_pclock_source(); |
paul@160 | 117 | |
paul@160 | 118 | uint32_t get_cpu_source_frequency(); |
paul@160 | 119 | uint32_t get_hclock0_source_frequency(); |
paul@160 | 120 | uint32_t get_hclock2_source_frequency(); |
paul@160 | 121 | uint32_t get_lcd_source_frequency(uint8_t controller); |
paul@160 | 122 | uint32_t get_lcd_source_frequency() { return get_lcd_source_frequency(0); } |
paul@160 | 123 | uint32_t get_memory_source_frequency(); |
paul@160 | 124 | uint32_t get_pclock_source_frequency(); |
paul@160 | 125 | |
paul@160 | 126 | // Final, calculated frequencies. |
paul@160 | 127 | |
paul@160 | 128 | uint32_t get_cpu_frequency(); |
paul@160 | 129 | uint32_t get_hclock0_frequency(); |
paul@160 | 130 | uint32_t get_hclock2_frequency(); |
paul@160 | 131 | uint32_t get_memory_frequency(); |
paul@160 | 132 | uint32_t get_pclock_frequency(); |
paul@160 | 133 | |
paul@160 | 134 | uint32_t get_apll_frequency(); |
paul@160 | 135 | uint32_t get_epll_frequency(); |
paul@160 | 136 | uint32_t get_mpll_frequency(); |
paul@160 | 137 | |
paul@160 | 138 | void set_pll_parameters(uint32_t pll_reg, uint16_t multiplier, uint8_t in_divider, uint8_t out_divider); |
paul@160 | 139 | |
paul@160 | 140 | uint32_t get_frequency(enum Clock_identifiers clock); |
paul@160 | 141 | void set_frequency(enum Clock_identifiers clock, uint32_t frequency); |
paul@160 | 142 | }; |
paul@160 | 143 | |
paul@160 | 144 | #endif /* __cplusplus */ |
paul@160 | 145 | |
paul@160 | 146 | |
paul@160 | 147 | |
paul@160 | 148 | /* C language interface. */ |
paul@160 | 149 | |
paul@160 | 150 | EXTERN_C_BEGIN |
paul@160 | 151 | |
paul@160 | 152 | void *x1600_cpm_init(l4_addr_t cpm_base); |
paul@160 | 153 | |
paul@160 | 154 | int x1600_cpm_have_clock(void *cpm, enum Clock_identifiers clock); |
paul@160 | 155 | void x1600_cpm_start_clock(void *cpm, enum Clock_identifiers clock); |
paul@160 | 156 | void x1600_cpm_stop_clock(void *cpm, enum Clock_identifiers clock); |
paul@160 | 157 | |
paul@160 | 158 | uint8_t x1600_cpm_get_cpu_divider(void *cpm); |
paul@160 | 159 | uint8_t x1600_cpm_get_hclock0_divider(void *cpm); |
paul@160 | 160 | uint8_t x1600_cpm_get_hclock2_divider(void *cpm); |
paul@160 | 161 | uint8_t x1600_cpm_get_lcd_pixel_divider(void *cpm); |
paul@160 | 162 | uint8_t x1600_cpm_get_memory_divider(void *cpm); |
paul@160 | 163 | uint8_t x1600_cpm_get_pclock_divider(void *cpm); |
paul@160 | 164 | |
paul@160 | 165 | uint8_t x1600_cpm_get_hclock0_source(void *cpm); |
paul@160 | 166 | uint8_t x1600_cpm_get_hclock2_source(void *cpm); |
paul@160 | 167 | uint8_t x1600_cpm_get_lcd_source(void *cpm); |
paul@160 | 168 | uint8_t x1600_cpm_get_memory_source(void *cpm); |
paul@160 | 169 | uint8_t x1600_cpm_get_pclock_source(void *cpm); |
paul@160 | 170 | |
paul@160 | 171 | uint32_t x1600_cpm_get_hclock0_source_frequency(void *cpm); |
paul@160 | 172 | uint32_t x1600_cpm_get_hclock2_source_frequency(void *cpm); |
paul@160 | 173 | uint32_t x1600_cpm_get_lcd_source_frequency(void *cpm); |
paul@160 | 174 | uint32_t x1600_cpm_get_memory_source_frequency(void *cpm); |
paul@160 | 175 | uint32_t x1600_cpm_get_pclock_source_frequency(void *cpm); |
paul@160 | 176 | |
paul@160 | 177 | void x1600_cpm_set_pclock_source(void *cpm, uint8_t source); |
paul@160 | 178 | |
paul@160 | 179 | uint8_t x1600_cpm_get_main_source(void *cpm); |
paul@160 | 180 | uint32_t x1600_cpm_get_main_frequency(void *cpm); |
paul@160 | 181 | |
paul@160 | 182 | uint32_t x1600_cpm_get_cpu_frequency(void *cpm); |
paul@160 | 183 | uint32_t x1600_cpm_get_hclock0_frequency(void *cpm); |
paul@160 | 184 | uint32_t x1600_cpm_get_hclock2_frequency(void *cpm); |
paul@160 | 185 | uint32_t x1600_cpm_get_memory_frequency(void *cpm); |
paul@160 | 186 | uint32_t x1600_cpm_get_pclock_frequency(void *cpm); |
paul@160 | 187 | |
paul@160 | 188 | uint32_t x1600_cpm_get_apll_frequency(void *cpm); |
paul@160 | 189 | uint32_t x1600_cpm_get_epll_frequency(void *cpm); |
paul@160 | 190 | uint32_t x1600_cpm_get_mpll_frequency(void *cpm); |
paul@160 | 191 | |
paul@160 | 192 | uint32_t x1600_cpm_get_frequency(void *cpm, enum Clock_identifiers clock); |
paul@160 | 193 | void x1600_cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint32_t frequency); |
paul@160 | 194 | |
paul@160 | 195 | void x1600_cpm_set_mpll_parameters(void *cpm, uint16_t multiplier, uint8_t in_divider, uint8_t out_divider); |
paul@160 | 196 | |
paul@160 | 197 | EXTERN_C_END |