1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#pragma once 6 7#include <ddk/io-buffer.h> 8#include <ddk/protocol/platform-defs.h> 9#include <ddk/protocol/platform-device.h> 10#include <ddktl/protocol/clk.h> 11#include <fbl/unique_ptr.h> 12#include <hwreg/mmio.h> 13#include <soc/aml-s905d2/s905d2-hiu.h> 14 15namespace thermal { 16// This class handles the dynamic changing of 17// CPU frequency. 18class AmlCpuFrequency { 19 20public: 21 DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(AmlCpuFrequency); 22 AmlCpuFrequency(){}; 23 ~AmlCpuFrequency(); 24 zx_status_t SetFrequency(uint32_t rate); 25 zx_status_t Init(zx_device_t* parent); 26 uint32_t GetFrequency(); 27 28private: 29 zx_status_t WaitForBusy(); 30 zx_status_t ConfigureSysPLL(uint32_t new_rate); 31 zx_status_t ConfigureFixedPLL(uint32_t new_rate); 32 33 platform_device_protocol_t pdev_; 34 // Initialize platform stuff. 35 zx_status_t InitPdev(zx_device_t* parent); 36 // Protocols. 37 clk_protocol_t clk_protocol_; 38 fbl::unique_ptr<ddk::ClkProtocolProxy> clk_; 39 // MMIOS. 40 io_buffer_t hiu_mmio_; 41 // BTI handle. 42 zx_handle_t bti_; 43 // HIU Handle. 44 aml_hiu_dev_t hiu_; 45 // Sys PLL. 46 aml_pll_dev_t sys_pll_; 47 // Current Frequency, default is 1.2GHz, 48 // which is set by u-boot while booting up. 49 uint32_t current_rate_ = 1200000000; 50}; 51} // namespace thermal 52