^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2013 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * CPU Frequency Scaling driver for Freescale QorIQ SoCs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * struct cpu_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @pclk: the parent clock of cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @table: frequency table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct cpu_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct clk **pclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct cpufreq_frequency_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * struct soc_data - SoC specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @flags: SOC_xxx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct soc_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static u32 get_bus_freq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct device_node *soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u32 sysfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct clk *pltclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* get platform freq by searching bus-frequency property */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) soc = of_find_node_by_type(NULL, "soc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (soc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ret = of_property_read_u32(soc, "bus-frequency", &sysfreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) of_node_put(soc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return sysfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* get platform freq by its clock name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) pltclk = clk_get(NULL, "cg-pll0-div1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (IS_ERR(pltclk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) pr_err("%s: can't get bus frequency %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) __func__, PTR_ERR(pltclk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return PTR_ERR(pltclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return clk_get_rate(pltclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static struct clk *cpu_to_clk(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (!cpu_present(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) np = of_get_cpu_node(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) clk = of_clk_get(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* traverse cpu nodes to get cpu mask of sharing clock wire */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static void set_affected_cpus(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct cpumask *dstp = policy->cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) for_each_present_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) clk = cpu_to_clk(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (IS_ERR(clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pr_err("%s: no clock for cpu %d\n", __func__, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (clk_is_match(policy->clk, clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) cpumask_set_cpu(i, dstp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* reduce the duplicated frequencies in frequency table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void freq_table_redup(struct cpufreq_frequency_table *freq_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (i = 1; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for (j = 0; j < i; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (freq_table[j].frequency == CPUFREQ_ENTRY_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) freq_table[j].frequency !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) freq_table[i].frequency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) freq_table[i].frequency = CPUFREQ_ENTRY_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* sort the frequencies in frequency table in descenting order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void freq_table_sort(struct cpufreq_frequency_table *freq_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int i, j, ind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned int freq, max_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct cpufreq_frequency_table table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) for (i = 0; i < count - 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) max_freq = freq_table[i].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ind = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (j = i + 1; j < count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) freq = freq_table[j].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (freq == CPUFREQ_ENTRY_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) freq <= max_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ind = j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) max_freq = freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ind != i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* exchange the frequencies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) table.driver_data = freq_table[i].driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) table.frequency = freq_table[i].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) freq_table[i].driver_data = freq_table[ind].driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) freq_table[i].frequency = freq_table[ind].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) freq_table[ind].driver_data = table.driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) freq_table[ind].frequency = table.frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int i, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u32 freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) const struct clk_hw *hwclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct cpufreq_frequency_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct cpu_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) unsigned int cpu = policy->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u64 u64temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) np = of_get_cpu_node(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) goto err_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) policy->clk = of_clk_get(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (IS_ERR(policy->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) pr_err("%s: no clock information\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) goto err_nomem2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) hwclk = __clk_get_hw(policy->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) count = clk_hw_get_num_parents(hwclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (!data->pclk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) goto err_nomem2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (!table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) goto err_pclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) clk = clk_hw_get_parent_by_index(hwclk, i)->clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) data->pclk[i] = clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) freq = clk_get_rate(clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) table[i].frequency = freq / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) table[i].driver_data = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) freq_table_redup(table, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) freq_table_sort(table, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) table[i].frequency = CPUFREQ_TABLE_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) policy->freq_table = table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) data->table = table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* update ->cpus if we have cluster, no harm if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) set_affected_cpus(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) policy->driver_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Minimum transition latency is 12 platform clocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u64temp = 12ULL * NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) do_div(u64temp, get_bus_freq());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) policy->cpuinfo.transition_latency = u64temp + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) err_pclk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) kfree(data->pclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) err_nomem2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) err_np:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct cpu_data *data = policy->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) kfree(data->pclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) kfree(data->table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) policy->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int qoriq_cpufreq_target(struct cpufreq_policy *policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct clk *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct cpu_data *data = policy->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) parent = data->pclk[data->table[index].driver_data];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return clk_set_parent(policy->clk, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static struct cpufreq_driver qoriq_cpufreq_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .name = "qoriq_cpufreq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .flags = CPUFREQ_CONST_LOOPS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) CPUFREQ_IS_COOLING_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .init = qoriq_cpufreq_cpu_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .exit = qoriq_cpufreq_cpu_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .verify = cpufreq_generic_frequency_table_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .target_index = qoriq_cpufreq_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .get = cpufreq_generic_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .attr = cpufreq_generic_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static const struct of_device_id qoriq_cpufreq_blacklist[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* e6500 cannot use cpufreq due to erratum A-008083 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) { .compatible = "fsl,b4420-clockgen", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) { .compatible = "fsl,b4860-clockgen", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) { .compatible = "fsl,t2080-clockgen", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) { .compatible = "fsl,t4240-clockgen", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int qoriq_cpufreq_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) np = of_find_matching_node(NULL, qoriq_cpufreq_blacklist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) dev_info(&pdev->dev, "Disabling due to erratum A-008083");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ret = cpufreq_register_driver(&qoriq_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_info(&pdev->dev, "Freescale QorIQ CPU frequency scaling driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int qoriq_cpufreq_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) cpufreq_unregister_driver(&qoriq_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static struct platform_driver qoriq_cpufreq_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .name = "qoriq-cpufreq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .probe = qoriq_cpufreq_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .remove = qoriq_cpufreq_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) module_platform_driver(qoriq_cpufreq_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) MODULE_ALIAS("platform:qoriq-cpufreq");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) MODULE_AUTHOR("Tang Yuantian <Yuantian.Tang@freescale.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) MODULE_DESCRIPTION("cpufreq driver for Freescale QorIQ series SoCs");