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 #include <ddk/debug.h>
6 #include <ddk/platform-defs.h>
7 #include <soc/mt8167/mt8167-clk.h>
8 #include <soc/mt8167/mt8167-hw.h>
9 #include <zircon/device/thermal.h>
10 
11 #include "mt8167.h"
12 
13 namespace {
14 
15 constexpr pbus_mmio_t thermal_mmios[] = {
16     {
17         .base = MT8167_THERMAL_BASE,
18         .length = MT8167_THERMAL_SIZE
19     },
20     {
21         .base = MT8167_FUSE_BASE,
22         .length = MT8167_FUSE_SIZE
23     },
24     {
25         .base = MT8167_AP_MIXED_SYS_BASE,
26         .length = MT8167_AP_MIXED_SYS_SIZE
27     },
28     {
29         .base = MT8167_PMIC_WRAP_BASE,
30         .length = MT8167_PMIC_WRAP_SIZE
31     }
32 };
33 
34 constexpr pbus_clk_t thermal_clks[] = {
35     {
36         .clk = board_mt8167::kClkThermal
37     },
38     {
39         .clk = board_mt8167::kClkAuxAdc
40     },
41     {
42         .clk = board_mt8167::kClkPmicWrapAp
43     },
44     {
45         .clk = board_mt8167::kClkPmicWrap26M
46     }
47 };
48 
49 constexpr thermal_device_info_t thermal_dev_info = {
50     .active_cooling = false,
51     .passive_cooling = true,
52     .gpu_throttling = true,
53     .num_trip_points = 0,
54     .big_little = false,
55     .critical_temp = 0,
56     .trip_point_info = {},
57     .opps = {
58         [BIG_CLUSTER_POWER_DOMAIN] = {
59             // See section 3.6 (MTCMOS Domains) of the functional specification document.
60             .opp = {
61                 [0] = {
62                     .freq_hz = 598000000,
63                     .volt_mv = 1150000
64                 },
65                 [1] = {
66                     .freq_hz = 747500000,
67                     .volt_mv = 1150000
68                 },
69                 [2] = {
70                     .freq_hz = 1040000000,
71                     .volt_mv = 1200000
72                 },
73                 [3] = {
74                     .freq_hz = 1196000000,
75                     .volt_mv = 1250000
76                 },
77                 [4] = {
78                     .freq_hz = 1300000000,
79                     .volt_mv = 1300000
80                 },
81             },
82             .latency = 0,
83             .count = 5
84         },
85         [LITTLE_CLUSTER_POWER_DOMAIN] = {
86             .opp = {},
87             .latency = 0,
88             .count = 0
89         }
90     }
91 };
92 
93 constexpr pbus_metadata_t thermal_metadata[] = {
94     {
95         .type = THERMAL_CONFIG_METADATA,
96         .data_buffer = &thermal_dev_info,
97         .data_size = sizeof(thermal_dev_info)
98     },
99 };
100 
__anonb03319db0202() 101 const pbus_dev_t thermal_dev = []() {
102     pbus_dev_t thermal_dev = {};
103     thermal_dev.name = "thermal";
104     thermal_dev.vid = PDEV_VID_MEDIATEK;
105     thermal_dev.did = PDEV_DID_MEDIATEK_THERMAL;
106     thermal_dev.mmio_list = thermal_mmios;
107     thermal_dev.mmio_count = countof(thermal_mmios);
108     thermal_dev.clk_list = thermal_clks;
109     thermal_dev.clk_count = countof(thermal_clks);
110     thermal_dev.metadata_list = thermal_metadata;
111     thermal_dev.metadata_count = countof(thermal_metadata);
112     thermal_dev.bti_count = 0;
113     thermal_dev.irq_count = 0;
114     thermal_dev.gpio_count = 0;
115     return thermal_dev;
116 }();
117 
118 }  // namespace
119 
120 namespace board_mt8167 {
121 
ThermalInit()122 zx_status_t Mt8167::ThermalInit() {
123     zx_status_t status = pbus_.DeviceAdd(&thermal_dev);
124     if (status != ZX_OK) {
125         zxlogf(ERROR, "%s: DeviceAdd thermal failed: %d\n", __FUNCTION__, status);
126     }
127 
128     return status;
129 }
130 
131 }  // namespace board_mt8167
132