1 /* 2 * CPM (clock and power management) support for the X1600. 3 * 4 * Copyright (C) 2017, 2018, 2020, 2021, 2023 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 #include <l4/sys/types.h> 26 #include <stdint.h> 27 28 29 30 #ifdef __cplusplus 31 32 #include <l4/devices/hw_register_block.h> 33 #include <l4/devices/cpm-common.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_x1600_chip : public Cpm_chip 40 { 41 private: 42 Hw::Register_block<32> _regs; 43 uint32_t _exclk_freq; 44 Cpm_regs _cpm_regs; 45 46 public: 47 Cpm_x1600_chip(l4_addr_t addr, uint32_t exclk_freq); 48 49 const char *clock_type(enum Clock_identifiers clock); 50 51 int have_clock(enum Clock_identifiers clock); 52 void start_clock(enum Clock_identifiers clock); 53 void stop_clock(enum Clock_identifiers clock); 54 55 // Clock dividers. 56 57 int get_parameters(enum Clock_identifiers clock, uint32_t parameters[]); 58 int set_parameters(enum Clock_identifiers clock, int num_parameters, 59 uint32_t parameters[]); 60 61 // Clock sources. 62 63 uint8_t get_source(enum Clock_identifiers clock); 64 void set_source(enum Clock_identifiers clock, uint8_t source); 65 enum Clock_identifiers get_source_clock(enum Clock_identifiers clock); 66 void set_source_clock(enum Clock_identifiers clock, enum Clock_identifiers source); 67 68 // Source frequencies. 69 70 uint32_t get_source_frequency(enum Clock_identifiers clock); 71 72 // Output clock frequencies. 73 74 uint32_t get_frequency(enum Clock_identifiers clock); 75 int set_frequency(enum Clock_identifiers clock, uint32_t frequency); 76 }; 77 78 #endif /* __cplusplus */ 79 80 81 82 /* C language interface. */ 83 84 EXTERN_C_BEGIN 85 86 void *x1600_cpm_init(l4_addr_t cpm_base); 87 88 const char *x1600_cpm_clock_type(void *cpm, enum Clock_identifiers clock); 89 90 int x1600_cpm_have_clock(void *cpm, enum Clock_identifiers clock); 91 void x1600_cpm_start_clock(void *cpm, enum Clock_identifiers clock); 92 void x1600_cpm_stop_clock(void *cpm, enum Clock_identifiers clock); 93 94 int x1600_cpm_get_parameters(void *cpm, enum Clock_identifiers clock, 95 uint32_t parameters[]); 96 int x1600_cpm_set_parameters(void *cpm, enum Clock_identifiers clock, 97 int num_parameters, uint32_t parameters[]); 98 99 uint8_t x1600_cpm_get_source(void *cpm, enum Clock_identifiers clock); 100 void x1600_cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source); 101 enum Clock_identifiers x1600_cpm_get_source_clock(void *cpm, enum Clock_identifiers clock); 102 void x1600_cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, enum Clock_identifiers source); 103 104 uint32_t x1600_cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock); 105 106 uint32_t x1600_cpm_get_frequency(void *cpm, enum Clock_identifiers clock); 107 int x1600_cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint32_t frequency); 108 109 EXTERN_C_END