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