paul@0 | 1 | /* |
paul@211 | 2 | * Common clock and power management (CPM) abstractions. |
paul@0 | 3 | * |
paul@160 | 4 | * Copyright (C) 2017, 2018, 2020, 2021, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or |
paul@0 | 7 | * modify it under the terms of the GNU General Public License as |
paul@0 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 9 | * the License, or (at your option) any later version. |
paul@0 | 10 | * |
paul@0 | 11 | * This program is distributed in the hope that it will be useful, |
paul@0 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 14 | * GNU General Public License for more details. |
paul@0 | 15 | * |
paul@0 | 16 | * You should have received a copy of the GNU General Public License |
paul@0 | 17 | * along with this program; if not, write to the Free Software |
paul@0 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 19 | * Boston, MA 02110-1301, USA |
paul@0 | 20 | */ |
paul@0 | 21 | |
paul@0 | 22 | #pragma once |
paul@0 | 23 | |
paul@211 | 24 | #include <l4/devices/cpm-common.h> |
paul@0 | 25 | #include <l4/sys/types.h> |
paul@0 | 26 | #include <stdint.h> |
paul@0 | 27 | |
paul@0 | 28 | |
paul@0 | 29 | |
paul@0 | 30 | #ifdef __cplusplus |
paul@0 | 31 | |
paul@211 | 32 | /* A transitional abstraction supporting older CPM abstractions. */ |
paul@0 | 33 | |
paul@211 | 34 | class Cpm_chip_base |
paul@0 | 35 | { |
paul@0 | 36 | public: |
paul@128 | 37 | virtual int have_clock(enum Clock_identifiers clock) = 0; |
paul@128 | 38 | virtual void start_clock(enum Clock_identifiers clock) = 0; |
paul@128 | 39 | virtual void stop_clock(enum Clock_identifiers clock) = 0; |
paul@0 | 40 | }; |
paul@0 | 41 | |
paul@211 | 42 | /* A simple abstraction for accessing the CPM registers. */ |
paul@211 | 43 | |
paul@211 | 44 | class Cpm_chip : public Cpm_chip_base |
paul@211 | 45 | { |
paul@211 | 46 | protected: |
paul@211 | 47 | Clock_base **_clocks; |
paul@211 | 48 | Cpm_regs _cpm_regs; |
paul@211 | 49 | |
paul@211 | 50 | public: |
paul@211 | 51 | explicit Cpm_chip(l4_addr_t addr, Clock_base *clocks[]); |
paul@211 | 52 | |
paul@211 | 53 | const char *clock_type(enum Clock_identifiers clock); |
paul@211 | 54 | |
paul@211 | 55 | // Clock control. |
paul@211 | 56 | |
paul@211 | 57 | int have_clock(enum Clock_identifiers clock); |
paul@211 | 58 | void start_clock(enum Clock_identifiers clock); |
paul@211 | 59 | void stop_clock(enum Clock_identifiers clock); |
paul@211 | 60 | |
paul@211 | 61 | // Clock dividers. |
paul@211 | 62 | |
paul@211 | 63 | int get_parameters(enum Clock_identifiers clock, uint32_t parameters[]); |
paul@211 | 64 | int set_parameters(enum Clock_identifiers clock, int num_parameters, |
paul@211 | 65 | uint32_t parameters[]); |
paul@211 | 66 | |
paul@211 | 67 | // Clock sources. |
paul@211 | 68 | |
paul@211 | 69 | uint8_t get_source(enum Clock_identifiers clock); |
paul@211 | 70 | void set_source(enum Clock_identifiers clock, uint8_t source); |
paul@211 | 71 | enum Clock_identifiers get_source_clock(enum Clock_identifiers clock); |
paul@211 | 72 | void set_source_clock(enum Clock_identifiers clock, enum Clock_identifiers source); |
paul@211 | 73 | |
paul@211 | 74 | // Source frequencies. |
paul@211 | 75 | |
paul@211 | 76 | uint32_t get_source_frequency(enum Clock_identifiers clock); |
paul@211 | 77 | |
paul@211 | 78 | // Output clock frequencies. |
paul@211 | 79 | |
paul@211 | 80 | uint32_t get_frequency(enum Clock_identifiers clock); |
paul@211 | 81 | int set_frequency(enum Clock_identifiers clock, uint32_t frequency); |
paul@211 | 82 | }; |
paul@211 | 83 | |
paul@0 | 84 | #endif /* __cplusplus */ |