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/gpio.h>
9 #include <ddk/protocol/scpi.h>
10 #include <ddk/debug.h>
11 #include <ddk/device.h>
12 #include <ddk/platform-defs.h>
13 #include <zircon/device/thermal.h>
14 #include <ddk/protocol/platform/bus.h>
15 #include <ddk/protocol/platform/device.h>
16 #include <threads.h>
17 
18 #define THERMAL_ERROR(fmt, ...) zxlogf(ERROR, "[%s %d]" fmt, __func__, __LINE__, ##__VA_ARGS__)
19 #define THERMAL_INFO(fmt, ...) zxlogf(INFO, "[%s %d]" fmt, __func__, __LINE__, ##__VA_ARGS__)
20 
21 // GPIO Indexes
22 enum {
23     FAN_CTL0,
24     FAN_CTL1,
25     FAN_CTL_COUNT,
26 };
27 
28 typedef struct {
29     zx_device_t*                        zxdev;
30     pdev_protocol_t          pdev;
31 
32     gpio_protocol_t                     gpios[FAN_CTL_COUNT];
33     scpi_protocol_t                     scpi;
34 
35     zx_handle_t                         port;
36 
37     thrd_t                              notify_thread;
38 
39     thermal_device_info_t               *device;
40 
41     uint32_t                            temp_sensor_id;
42 
43     uint32_t                            current_trip_idx;
44     uint32_t                            current_temperature;
45     uint32_t                            current_fan_level;
46     uint32_t                            current_big_cluster_opp_idx;
47     uint32_t                            current_little_cluster_opp_idx;
48 } aml_thermal_t;
49