1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2018 HabanaLabs, Ltd.
9 #include "../include/gaudi/gaudi_fw_if.h"
11 void gaudi_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq)
13 struct gaudi_device *gaudi = hdev->asic_specific;
16 hl_set_frequency(hdev, MME_PLL, gaudi->max_freq_value);
19 int gaudi_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk)
23 if (hl_device_disabled_or_in_reset(hdev))
26 value = hl_get_frequency(hdev, MME_PLL, false);
29 dev_err(hdev->dev, "Failed to retrieve device max clock %ld\n",
34 *max_clk = (value / 1000 / 1000);
36 value = hl_get_frequency(hdev, MME_PLL, true);
40 "Failed to retrieve device current clock %ld\n",
45 *cur_clk = (value / 1000 / 1000);
50 static ssize_t clk_max_freq_mhz_show(struct device *dev,
51 struct device_attribute *attr, char *buf)
53 struct hl_device *hdev = dev_get_drvdata(dev);
54 struct gaudi_device *gaudi = hdev->asic_specific;
57 if (hl_device_disabled_or_in_reset(hdev))
60 value = hl_get_frequency(hdev, MME_PLL, false);
62 gaudi->max_freq_value = value;
64 return sprintf(buf, "%lu\n", (value / 1000 / 1000));
67 static ssize_t clk_max_freq_mhz_store(struct device *dev,
68 struct device_attribute *attr, const char *buf, size_t count)
70 struct hl_device *hdev = dev_get_drvdata(dev);
71 struct gaudi_device *gaudi = hdev->asic_specific;
75 if (hl_device_disabled_or_in_reset(hdev)) {
80 rc = kstrtoull(buf, 0, &value);
86 gaudi->max_freq_value = value * 1000 * 1000;
88 hl_set_frequency(hdev, MME_PLL, gaudi->max_freq_value);
94 static ssize_t clk_cur_freq_mhz_show(struct device *dev,
95 struct device_attribute *attr, char *buf)
97 struct hl_device *hdev = dev_get_drvdata(dev);
100 if (hl_device_disabled_or_in_reset(hdev))
103 value = hl_get_frequency(hdev, MME_PLL, true);
105 return sprintf(buf, "%lu\n", (value / 1000 / 1000));
108 static DEVICE_ATTR_RW(clk_max_freq_mhz);
109 static DEVICE_ATTR_RO(clk_cur_freq_mhz);
111 static struct attribute *gaudi_dev_attrs[] = {
112 &dev_attr_clk_max_freq_mhz.attr,
113 &dev_attr_clk_cur_freq_mhz.attr,
117 void gaudi_add_device_attr(struct hl_device *hdev,
118 struct attribute_group *dev_attr_grp)
120 dev_attr_grp->attrs = gaudi_dev_attrs;