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/protocol/platform-device-lib.h>
8 #include <ddk/protocol/platform/device.h>
9 #include <ddktl/device.h>
10 #include <ddktl/mmio.h>
11 #include <fbl/mutex.h>
12 #include <hwreg/mmio.h>
13 
14 #include <optional>
15 
16 namespace thermal {
17 
18 // This class represents a generic PWM
19 // which provides interface to set the
20 // period and configure to appropriate
21 // duty cycle.
22 class AmlPwm {
23 
24 public:
25     DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(AmlPwm);
AmlPwm(uint32_t period,uint32_t hwpwm)26     AmlPwm(uint32_t period, uint32_t hwpwm)
27         : period_(period), hwpwm_(hwpwm){};
28     zx_status_t Init(zx_device_t* parent);
29     zx_status_t Configure(uint32_t duty_cycle);
30     ~AmlPwm() = default;
31 
32 private:
33     uint32_t period_;
34     uint32_t duty_cycle_;
35     uint32_t hwpwm_;
36     uint32_t pwm_duty_cycle_offset_;
37     uint32_t enable_bit_;
38     uint32_t clk_enable_bit_;
39     pdev_protocol_t pdev_;
40     std::optional<ddk::MmioBuffer> pwm_mmio_;
41     fbl::Mutex pwm_lock_;
42 };
43 } // namespace thermal
44