1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/cpm/include/cpm-generic.h Sat Apr 27 23:46:28 2024 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 + * Common clock and power management (CPM) abstractions.
1.6 + *
1.7 + * Copyright (C) 2017, 2018, 2020, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/devices/cpm-common.h>
1.28 +#include <l4/sys/types.h>
1.29 +#include <stdint.h>
1.30 +
1.31 +
1.32 +
1.33 +#ifdef __cplusplus
1.34 +
1.35 +/* A transitional abstraction supporting older CPM abstractions. */
1.36 +
1.37 +class Cpm_chip_base
1.38 +{
1.39 +public:
1.40 + virtual int have_clock(enum Clock_identifiers clock) = 0;
1.41 + virtual void start_clock(enum Clock_identifiers clock) = 0;
1.42 + virtual void stop_clock(enum Clock_identifiers clock) = 0;
1.43 +};
1.44 +
1.45 +/* A simple abstraction for accessing the CPM registers. */
1.46 +
1.47 +class Cpm_chip : public Cpm_chip_base
1.48 +{
1.49 +protected:
1.50 + Clock_base **_clocks;
1.51 + Cpm_regs _cpm_regs;
1.52 +
1.53 +public:
1.54 + explicit Cpm_chip(l4_addr_t addr, Clock_base *clocks[]);
1.55 +
1.56 + const char *clock_type(enum Clock_identifiers clock);
1.57 +
1.58 + // Clock control.
1.59 +
1.60 + int have_clock(enum Clock_identifiers clock);
1.61 + void start_clock(enum Clock_identifiers clock);
1.62 + void stop_clock(enum Clock_identifiers clock);
1.63 +
1.64 + // Clock dividers.
1.65 +
1.66 + int get_parameters(enum Clock_identifiers clock, uint32_t parameters[]);
1.67 + int set_parameters(enum Clock_identifiers clock, int num_parameters,
1.68 + uint32_t parameters[]);
1.69 +
1.70 + // Clock sources.
1.71 +
1.72 + uint8_t get_source(enum Clock_identifiers clock);
1.73 + void set_source(enum Clock_identifiers clock, uint8_t source);
1.74 + enum Clock_identifiers get_source_clock(enum Clock_identifiers clock);
1.75 + void set_source_clock(enum Clock_identifiers clock, enum Clock_identifiers source);
1.76 +
1.77 + // Source frequencies.
1.78 +
1.79 + uint64_t get_source_frequency(enum Clock_identifiers clock);
1.80 +
1.81 + // Output clock frequencies.
1.82 +
1.83 + uint64_t get_frequency(enum Clock_identifiers clock);
1.84 + int set_frequency(enum Clock_identifiers clock, uint64_t frequency);
1.85 +};
1.86 +
1.87 +/* Generic access to the CPM abstraction. */
1.88 +
1.89 +Cpm_chip *new_cpm_chip(const char *name, l4_addr_t cpm_base);
1.90 +
1.91 +#endif /* __cplusplus */