18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
48c2ecf20Sopenharmony_ci *  and                       Markus Demleitner <msdemlei@cl.uni-heidelberg.de>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This driver adds basic cpufreq support for SMU & 970FX based G5 Macs,
78c2ecf20Sopenharmony_ci * that is iMac G5 and latest single CPU desktop.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#undef DEBUG
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/types.h>
168c2ecf20Sopenharmony_ci#include <linux/errno.h>
178c2ecf20Sopenharmony_ci#include <linux/kernel.h>
188c2ecf20Sopenharmony_ci#include <linux/delay.h>
198c2ecf20Sopenharmony_ci#include <linux/sched.h>
208c2ecf20Sopenharmony_ci#include <linux/cpufreq.h>
218c2ecf20Sopenharmony_ci#include <linux/init.h>
228c2ecf20Sopenharmony_ci#include <linux/completion.h>
238c2ecf20Sopenharmony_ci#include <linux/mutex.h>
248c2ecf20Sopenharmony_ci#include <linux/of_device.h>
258c2ecf20Sopenharmony_ci#include <asm/prom.h>
268c2ecf20Sopenharmony_ci#include <asm/machdep.h>
278c2ecf20Sopenharmony_ci#include <asm/irq.h>
288c2ecf20Sopenharmony_ci#include <asm/sections.h>
298c2ecf20Sopenharmony_ci#include <asm/cputable.h>
308c2ecf20Sopenharmony_ci#include <asm/time.h>
318c2ecf20Sopenharmony_ci#include <asm/smu.h>
328c2ecf20Sopenharmony_ci#include <asm/pmac_pfunc.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define DBG(fmt...) pr_debug(fmt)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* see 970FX user manual */
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define SCOM_PCR 0x0aa001			/* PCR scom addr */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define PCR_HILO_SELECT		0x80000000U	/* 1 = PCR, 0 = PCRH */
418c2ecf20Sopenharmony_ci#define PCR_SPEED_FULL		0x00000000U	/* 1:1 speed value */
428c2ecf20Sopenharmony_ci#define PCR_SPEED_HALF		0x00020000U	/* 1:2 speed value */
438c2ecf20Sopenharmony_ci#define PCR_SPEED_QUARTER	0x00040000U	/* 1:4 speed value */
448c2ecf20Sopenharmony_ci#define PCR_SPEED_MASK		0x000e0000U	/* speed mask */
458c2ecf20Sopenharmony_ci#define PCR_SPEED_SHIFT		17
468c2ecf20Sopenharmony_ci#define PCR_FREQ_REQ_VALID	0x00010000U	/* freq request valid */
478c2ecf20Sopenharmony_ci#define PCR_VOLT_REQ_VALID	0x00008000U	/* volt request valid */
488c2ecf20Sopenharmony_ci#define PCR_TARGET_TIME_MASK	0x00006000U	/* target time */
498c2ecf20Sopenharmony_ci#define PCR_STATLAT_MASK	0x00001f00U	/* STATLAT value */
508c2ecf20Sopenharmony_ci#define PCR_SNOOPLAT_MASK	0x000000f0U	/* SNOOPLAT value */
518c2ecf20Sopenharmony_ci#define PCR_SNOOPACC_MASK	0x0000000fU	/* SNOOPACC value */
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define SCOM_PSR 0x408001			/* PSR scom addr */
548c2ecf20Sopenharmony_ci/* warning: PSR is a 64 bits register */
558c2ecf20Sopenharmony_ci#define PSR_CMD_RECEIVED	0x2000000000000000U   /* command received */
568c2ecf20Sopenharmony_ci#define PSR_CMD_COMPLETED	0x1000000000000000U   /* command completed */
578c2ecf20Sopenharmony_ci#define PSR_CUR_SPEED_MASK	0x0300000000000000U   /* current speed */
588c2ecf20Sopenharmony_ci#define PSR_CUR_SPEED_SHIFT	(56)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/*
618c2ecf20Sopenharmony_ci * The G5 only supports two frequencies (Quarter speed is not supported)
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ci#define CPUFREQ_HIGH                  0
648c2ecf20Sopenharmony_ci#define CPUFREQ_LOW                   1
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic struct cpufreq_frequency_table g5_cpu_freqs[] = {
678c2ecf20Sopenharmony_ci	{0, CPUFREQ_HIGH,	0},
688c2ecf20Sopenharmony_ci	{0, CPUFREQ_LOW,	0},
698c2ecf20Sopenharmony_ci	{0, 0,			CPUFREQ_TABLE_END},
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Power mode data is an array of the 32 bits PCR values to use for
738c2ecf20Sopenharmony_ci * the various frequencies, retrieved from the device-tree
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cistatic int g5_pmode_cur;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic void (*g5_switch_volt)(int speed_mode);
788c2ecf20Sopenharmony_cistatic int (*g5_switch_freq)(int speed_mode);
798c2ecf20Sopenharmony_cistatic int (*g5_query_freq)(void);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic unsigned long transition_latency;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#ifdef CONFIG_PMAC_SMU
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic const u32 *g5_pmode_data;
868c2ecf20Sopenharmony_cistatic int g5_pmode_max;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic struct smu_sdbp_fvt *g5_fvt_table;	/* table of op. points */
898c2ecf20Sopenharmony_cistatic int g5_fvt_count;			/* number of op. points */
908c2ecf20Sopenharmony_cistatic int g5_fvt_cur;				/* current op. point */
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * SMU based voltage switching for Neo2 platforms
948c2ecf20Sopenharmony_ci */
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic void g5_smu_switch_volt(int speed_mode)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	struct smu_simple_cmd	cmd;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	DECLARE_COMPLETION_ONSTACK(comp);
1018c2ecf20Sopenharmony_ci	smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 8, smu_done_complete,
1028c2ecf20Sopenharmony_ci			 &comp, 'V', 'S', 'L', 'E', 'W',
1038c2ecf20Sopenharmony_ci			 0xff, g5_fvt_cur+1, speed_mode);
1048c2ecf20Sopenharmony_ci	wait_for_completion(&comp);
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/*
1088c2ecf20Sopenharmony_ci * Platform function based voltage/vdnap switching for Neo2
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_set_vdnap0;
1128c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_vdnap0_complete;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic void g5_vdnap_switch_volt(int speed_mode)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	struct pmf_args args;
1178c2ecf20Sopenharmony_ci	u32 slew, done = 0;
1188c2ecf20Sopenharmony_ci	unsigned long timeout;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	slew = (speed_mode == CPUFREQ_LOW) ? 1 : 0;
1218c2ecf20Sopenharmony_ci	args.count = 1;
1228c2ecf20Sopenharmony_ci	args.u[0].p = &slew;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	pmf_call_one(pfunc_set_vdnap0, &args);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	/* It's an irq GPIO so we should be able to just block here,
1278c2ecf20Sopenharmony_ci	 * I'll do that later after I've properly tested the IRQ code for
1288c2ecf20Sopenharmony_ci	 * platform functions
1298c2ecf20Sopenharmony_ci	 */
1308c2ecf20Sopenharmony_ci	timeout = jiffies + HZ/10;
1318c2ecf20Sopenharmony_ci	while(!time_after(jiffies, timeout)) {
1328c2ecf20Sopenharmony_ci		args.count = 1;
1338c2ecf20Sopenharmony_ci		args.u[0].p = &done;
1348c2ecf20Sopenharmony_ci		pmf_call_one(pfunc_vdnap0_complete, &args);
1358c2ecf20Sopenharmony_ci		if (done)
1368c2ecf20Sopenharmony_ci			break;
1378c2ecf20Sopenharmony_ci		usleep_range(1000, 1000);
1388c2ecf20Sopenharmony_ci	}
1398c2ecf20Sopenharmony_ci	if (done == 0)
1408c2ecf20Sopenharmony_ci		pr_warn("Timeout in clock slewing !\n");
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/*
1458c2ecf20Sopenharmony_ci * SCOM based frequency switching for 970FX rev3
1468c2ecf20Sopenharmony_ci */
1478c2ecf20Sopenharmony_cistatic int g5_scom_switch_freq(int speed_mode)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	unsigned long flags;
1508c2ecf20Sopenharmony_ci	int to;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	/* If frequency is going up, first ramp up the voltage */
1538c2ecf20Sopenharmony_ci	if (speed_mode < g5_pmode_cur)
1548c2ecf20Sopenharmony_ci		g5_switch_volt(speed_mode);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	local_irq_save(flags);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	/* Clear PCR high */
1598c2ecf20Sopenharmony_ci	scom970_write(SCOM_PCR, 0);
1608c2ecf20Sopenharmony_ci	/* Clear PCR low */
1618c2ecf20Sopenharmony_ci       	scom970_write(SCOM_PCR, PCR_HILO_SELECT | 0);
1628c2ecf20Sopenharmony_ci	/* Set PCR low */
1638c2ecf20Sopenharmony_ci	scom970_write(SCOM_PCR, PCR_HILO_SELECT |
1648c2ecf20Sopenharmony_ci		      g5_pmode_data[speed_mode]);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	/* Wait for completion */
1678c2ecf20Sopenharmony_ci	for (to = 0; to < 10; to++) {
1688c2ecf20Sopenharmony_ci		unsigned long psr = scom970_read(SCOM_PSR);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci		if ((psr & PSR_CMD_RECEIVED) == 0 &&
1718c2ecf20Sopenharmony_ci		    (((psr >> PSR_CUR_SPEED_SHIFT) ^
1728c2ecf20Sopenharmony_ci		      (g5_pmode_data[speed_mode] >> PCR_SPEED_SHIFT)) & 0x3)
1738c2ecf20Sopenharmony_ci		    == 0)
1748c2ecf20Sopenharmony_ci			break;
1758c2ecf20Sopenharmony_ci		if (psr & PSR_CMD_COMPLETED)
1768c2ecf20Sopenharmony_ci			break;
1778c2ecf20Sopenharmony_ci		udelay(100);
1788c2ecf20Sopenharmony_ci	}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	local_irq_restore(flags);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	/* If frequency is going down, last ramp the voltage */
1838c2ecf20Sopenharmony_ci	if (speed_mode > g5_pmode_cur)
1848c2ecf20Sopenharmony_ci		g5_switch_volt(speed_mode);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	g5_pmode_cur = speed_mode;
1878c2ecf20Sopenharmony_ci	ppc_proc_freq = g5_cpu_freqs[speed_mode].frequency * 1000ul;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	return 0;
1908c2ecf20Sopenharmony_ci}
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistatic int g5_scom_query_freq(void)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	unsigned long psr = scom970_read(SCOM_PSR);
1958c2ecf20Sopenharmony_ci	int i;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	for (i = 0; i <= g5_pmode_max; i++)
1988c2ecf20Sopenharmony_ci		if ((((psr >> PSR_CUR_SPEED_SHIFT) ^
1998c2ecf20Sopenharmony_ci		      (g5_pmode_data[i] >> PCR_SPEED_SHIFT)) & 0x3) == 0)
2008c2ecf20Sopenharmony_ci			break;
2018c2ecf20Sopenharmony_ci	return i;
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/*
2058c2ecf20Sopenharmony_ci * Fake voltage switching for platforms with missing support
2068c2ecf20Sopenharmony_ci */
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic void g5_dummy_switch_volt(int speed_mode)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci}
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci#endif /* CONFIG_PMAC_SMU */
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/*
2158c2ecf20Sopenharmony_ci * Platform function based voltage switching for PowerMac7,2 & 7,3
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu0_volt_high;
2198c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu0_volt_low;
2208c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu1_volt_high;
2218c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu1_volt_low;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cistatic void g5_pfunc_switch_volt(int speed_mode)
2248c2ecf20Sopenharmony_ci{
2258c2ecf20Sopenharmony_ci	if (speed_mode == CPUFREQ_HIGH) {
2268c2ecf20Sopenharmony_ci		if (pfunc_cpu0_volt_high)
2278c2ecf20Sopenharmony_ci			pmf_call_one(pfunc_cpu0_volt_high, NULL);
2288c2ecf20Sopenharmony_ci		if (pfunc_cpu1_volt_high)
2298c2ecf20Sopenharmony_ci			pmf_call_one(pfunc_cpu1_volt_high, NULL);
2308c2ecf20Sopenharmony_ci	} else {
2318c2ecf20Sopenharmony_ci		if (pfunc_cpu0_volt_low)
2328c2ecf20Sopenharmony_ci			pmf_call_one(pfunc_cpu0_volt_low, NULL);
2338c2ecf20Sopenharmony_ci		if (pfunc_cpu1_volt_low)
2348c2ecf20Sopenharmony_ci			pmf_call_one(pfunc_cpu1_volt_low, NULL);
2358c2ecf20Sopenharmony_ci	}
2368c2ecf20Sopenharmony_ci	usleep_range(10000, 10000); /* should be faster , to fix */
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci/*
2408c2ecf20Sopenharmony_ci * Platform function based frequency switching for PowerMac7,2 & 7,3
2418c2ecf20Sopenharmony_ci */
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu_setfreq_high;
2448c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu_setfreq_low;
2458c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_cpu_getfreq;
2468c2ecf20Sopenharmony_cistatic struct pmf_function *pfunc_slewing_done;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic int g5_pfunc_switch_freq(int speed_mode)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci	struct pmf_args args;
2518c2ecf20Sopenharmony_ci	u32 done = 0;
2528c2ecf20Sopenharmony_ci	unsigned long timeout;
2538c2ecf20Sopenharmony_ci	int rc;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	DBG("g5_pfunc_switch_freq(%d)\n", speed_mode);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	/* If frequency is going up, first ramp up the voltage */
2588c2ecf20Sopenharmony_ci	if (speed_mode < g5_pmode_cur)
2598c2ecf20Sopenharmony_ci		g5_switch_volt(speed_mode);
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	/* Do it */
2628c2ecf20Sopenharmony_ci	if (speed_mode == CPUFREQ_HIGH)
2638c2ecf20Sopenharmony_ci		rc = pmf_call_one(pfunc_cpu_setfreq_high, NULL);
2648c2ecf20Sopenharmony_ci	else
2658c2ecf20Sopenharmony_ci		rc = pmf_call_one(pfunc_cpu_setfreq_low, NULL);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	if (rc)
2688c2ecf20Sopenharmony_ci		pr_warn("pfunc switch error %d\n", rc);
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/* It's an irq GPIO so we should be able to just block here,
2718c2ecf20Sopenharmony_ci	 * I'll do that later after I've properly tested the IRQ code for
2728c2ecf20Sopenharmony_ci	 * platform functions
2738c2ecf20Sopenharmony_ci	 */
2748c2ecf20Sopenharmony_ci	timeout = jiffies + HZ/10;
2758c2ecf20Sopenharmony_ci	while(!time_after(jiffies, timeout)) {
2768c2ecf20Sopenharmony_ci		args.count = 1;
2778c2ecf20Sopenharmony_ci		args.u[0].p = &done;
2788c2ecf20Sopenharmony_ci		pmf_call_one(pfunc_slewing_done, &args);
2798c2ecf20Sopenharmony_ci		if (done)
2808c2ecf20Sopenharmony_ci			break;
2818c2ecf20Sopenharmony_ci		usleep_range(500, 500);
2828c2ecf20Sopenharmony_ci	}
2838c2ecf20Sopenharmony_ci	if (done == 0)
2848c2ecf20Sopenharmony_ci		pr_warn("Timeout in clock slewing !\n");
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	/* If frequency is going down, last ramp the voltage */
2878c2ecf20Sopenharmony_ci	if (speed_mode > g5_pmode_cur)
2888c2ecf20Sopenharmony_ci		g5_switch_volt(speed_mode);
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	g5_pmode_cur = speed_mode;
2918c2ecf20Sopenharmony_ci	ppc_proc_freq = g5_cpu_freqs[speed_mode].frequency * 1000ul;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	return 0;
2948c2ecf20Sopenharmony_ci}
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistatic int g5_pfunc_query_freq(void)
2978c2ecf20Sopenharmony_ci{
2988c2ecf20Sopenharmony_ci	struct pmf_args args;
2998c2ecf20Sopenharmony_ci	u32 val = 0;
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	args.count = 1;
3028c2ecf20Sopenharmony_ci	args.u[0].p = &val;
3038c2ecf20Sopenharmony_ci	pmf_call_one(pfunc_cpu_getfreq, &args);
3048c2ecf20Sopenharmony_ci	return val ? CPUFREQ_HIGH : CPUFREQ_LOW;
3058c2ecf20Sopenharmony_ci}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci/*
3098c2ecf20Sopenharmony_ci * Common interface to the cpufreq core
3108c2ecf20Sopenharmony_ci */
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_cistatic int g5_cpufreq_target(struct cpufreq_policy *policy, unsigned int index)
3138c2ecf20Sopenharmony_ci{
3148c2ecf20Sopenharmony_ci	return g5_switch_freq(index);
3158c2ecf20Sopenharmony_ci}
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_cistatic unsigned int g5_cpufreq_get_speed(unsigned int cpu)
3188c2ecf20Sopenharmony_ci{
3198c2ecf20Sopenharmony_ci	return g5_cpu_freqs[g5_pmode_cur].frequency;
3208c2ecf20Sopenharmony_ci}
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_cistatic int g5_cpufreq_cpu_init(struct cpufreq_policy *policy)
3238c2ecf20Sopenharmony_ci{
3248c2ecf20Sopenharmony_ci	cpufreq_generic_init(policy, g5_cpu_freqs, transition_latency);
3258c2ecf20Sopenharmony_ci	return 0;
3268c2ecf20Sopenharmony_ci}
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cistatic struct cpufreq_driver g5_cpufreq_driver = {
3298c2ecf20Sopenharmony_ci	.name		= "powermac",
3308c2ecf20Sopenharmony_ci	.flags		= CPUFREQ_CONST_LOOPS,
3318c2ecf20Sopenharmony_ci	.init		= g5_cpufreq_cpu_init,
3328c2ecf20Sopenharmony_ci	.verify		= cpufreq_generic_frequency_table_verify,
3338c2ecf20Sopenharmony_ci	.target_index	= g5_cpufreq_target,
3348c2ecf20Sopenharmony_ci	.get		= g5_cpufreq_get_speed,
3358c2ecf20Sopenharmony_ci	.attr 		= cpufreq_generic_attr,
3368c2ecf20Sopenharmony_ci};
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci#ifdef CONFIG_PMAC_SMU
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_cistatic int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
3428c2ecf20Sopenharmony_ci{
3438c2ecf20Sopenharmony_ci	unsigned int psize, ssize;
3448c2ecf20Sopenharmony_ci	unsigned long max_freq;
3458c2ecf20Sopenharmony_ci	char *freq_method, *volt_method;
3468c2ecf20Sopenharmony_ci	const u32 *valp;
3478c2ecf20Sopenharmony_ci	u32 pvr_hi;
3488c2ecf20Sopenharmony_ci	int use_volts_vdnap = 0;
3498c2ecf20Sopenharmony_ci	int use_volts_smu = 0;
3508c2ecf20Sopenharmony_ci	int rc = -ENODEV;
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	/* Check supported platforms */
3538c2ecf20Sopenharmony_ci	if (of_machine_is_compatible("PowerMac8,1") ||
3548c2ecf20Sopenharmony_ci	    of_machine_is_compatible("PowerMac8,2") ||
3558c2ecf20Sopenharmony_ci	    of_machine_is_compatible("PowerMac9,1") ||
3568c2ecf20Sopenharmony_ci	    of_machine_is_compatible("PowerMac12,1"))
3578c2ecf20Sopenharmony_ci		use_volts_smu = 1;
3588c2ecf20Sopenharmony_ci	else if (of_machine_is_compatible("PowerMac11,2"))
3598c2ecf20Sopenharmony_ci		use_volts_vdnap = 1;
3608c2ecf20Sopenharmony_ci	else
3618c2ecf20Sopenharmony_ci		return -ENODEV;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	/* Check 970FX for now */
3648c2ecf20Sopenharmony_ci	valp = of_get_property(cpunode, "cpu-version", NULL);
3658c2ecf20Sopenharmony_ci	if (!valp) {
3668c2ecf20Sopenharmony_ci		DBG("No cpu-version property !\n");
3678c2ecf20Sopenharmony_ci		goto bail_noprops;
3688c2ecf20Sopenharmony_ci	}
3698c2ecf20Sopenharmony_ci	pvr_hi = (*valp) >> 16;
3708c2ecf20Sopenharmony_ci	if (pvr_hi != 0x3c && pvr_hi != 0x44) {
3718c2ecf20Sopenharmony_ci		pr_err("Unsupported CPU version\n");
3728c2ecf20Sopenharmony_ci		goto bail_noprops;
3738c2ecf20Sopenharmony_ci	}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	/* Look for the powertune data in the device-tree */
3768c2ecf20Sopenharmony_ci	g5_pmode_data = of_get_property(cpunode, "power-mode-data",&psize);
3778c2ecf20Sopenharmony_ci	if (!g5_pmode_data) {
3788c2ecf20Sopenharmony_ci		DBG("No power-mode-data !\n");
3798c2ecf20Sopenharmony_ci		goto bail_noprops;
3808c2ecf20Sopenharmony_ci	}
3818c2ecf20Sopenharmony_ci	g5_pmode_max = psize / sizeof(u32) - 1;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	if (use_volts_smu) {
3848c2ecf20Sopenharmony_ci		const struct smu_sdbp_header *shdr;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci		/* Look for the FVT table */
3878c2ecf20Sopenharmony_ci		shdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);
3888c2ecf20Sopenharmony_ci		if (!shdr)
3898c2ecf20Sopenharmony_ci			goto bail_noprops;
3908c2ecf20Sopenharmony_ci		g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
3918c2ecf20Sopenharmony_ci		ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
3928c2ecf20Sopenharmony_ci		g5_fvt_count = ssize / sizeof(*g5_fvt_table);
3938c2ecf20Sopenharmony_ci		g5_fvt_cur = 0;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci		/* Sanity checking */
3968c2ecf20Sopenharmony_ci		if (g5_fvt_count < 1 || g5_pmode_max < 1)
3978c2ecf20Sopenharmony_ci			goto bail_noprops;
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci		g5_switch_volt = g5_smu_switch_volt;
4008c2ecf20Sopenharmony_ci		volt_method = "SMU";
4018c2ecf20Sopenharmony_ci	} else if (use_volts_vdnap) {
4028c2ecf20Sopenharmony_ci		struct device_node *root;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci		root = of_find_node_by_path("/");
4058c2ecf20Sopenharmony_ci		if (root == NULL) {
4068c2ecf20Sopenharmony_ci			pr_err("Can't find root of device tree\n");
4078c2ecf20Sopenharmony_ci			goto bail_noprops;
4088c2ecf20Sopenharmony_ci		}
4098c2ecf20Sopenharmony_ci		pfunc_set_vdnap0 = pmf_find_function(root, "set-vdnap0");
4108c2ecf20Sopenharmony_ci		pfunc_vdnap0_complete =
4118c2ecf20Sopenharmony_ci			pmf_find_function(root, "slewing-done");
4128c2ecf20Sopenharmony_ci		of_node_put(root);
4138c2ecf20Sopenharmony_ci		if (pfunc_set_vdnap0 == NULL ||
4148c2ecf20Sopenharmony_ci		    pfunc_vdnap0_complete == NULL) {
4158c2ecf20Sopenharmony_ci			pr_err("Can't find required platform function\n");
4168c2ecf20Sopenharmony_ci			goto bail_noprops;
4178c2ecf20Sopenharmony_ci		}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci		g5_switch_volt = g5_vdnap_switch_volt;
4208c2ecf20Sopenharmony_ci		volt_method = "GPIO";
4218c2ecf20Sopenharmony_ci	} else {
4228c2ecf20Sopenharmony_ci		g5_switch_volt = g5_dummy_switch_volt;
4238c2ecf20Sopenharmony_ci		volt_method = "none";
4248c2ecf20Sopenharmony_ci	}
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	/*
4278c2ecf20Sopenharmony_ci	 * From what I see, clock-frequency is always the maximal frequency.
4288c2ecf20Sopenharmony_ci	 * The current driver can not slew sysclk yet, so we really only deal
4298c2ecf20Sopenharmony_ci	 * with powertune steps for now. We also only implement full freq and
4308c2ecf20Sopenharmony_ci	 * half freq in this version. So far, I haven't yet seen a machine
4318c2ecf20Sopenharmony_ci	 * supporting anything else.
4328c2ecf20Sopenharmony_ci	 */
4338c2ecf20Sopenharmony_ci	valp = of_get_property(cpunode, "clock-frequency", NULL);
4348c2ecf20Sopenharmony_ci	if (!valp)
4358c2ecf20Sopenharmony_ci		return -ENODEV;
4368c2ecf20Sopenharmony_ci	max_freq = (*valp)/1000;
4378c2ecf20Sopenharmony_ci	g5_cpu_freqs[0].frequency = max_freq;
4388c2ecf20Sopenharmony_ci	g5_cpu_freqs[1].frequency = max_freq/2;
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	/* Set callbacks */
4418c2ecf20Sopenharmony_ci	transition_latency = 12000;
4428c2ecf20Sopenharmony_ci	g5_switch_freq = g5_scom_switch_freq;
4438c2ecf20Sopenharmony_ci	g5_query_freq = g5_scom_query_freq;
4448c2ecf20Sopenharmony_ci	freq_method = "SCOM";
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	/* Force apply current frequency to make sure everything is in
4478c2ecf20Sopenharmony_ci	 * sync (voltage is right for example). Firmware may leave us with
4488c2ecf20Sopenharmony_ci	 * a strange setting ...
4498c2ecf20Sopenharmony_ci	 */
4508c2ecf20Sopenharmony_ci	g5_switch_volt(CPUFREQ_HIGH);
4518c2ecf20Sopenharmony_ci	msleep(10);
4528c2ecf20Sopenharmony_ci	g5_pmode_cur = -1;
4538c2ecf20Sopenharmony_ci	g5_switch_freq(g5_query_freq());
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci	pr_info("Registering G5 CPU frequency driver\n");
4568c2ecf20Sopenharmony_ci	pr_info("Frequency method: %s, Voltage method: %s\n",
4578c2ecf20Sopenharmony_ci		freq_method, volt_method);
4588c2ecf20Sopenharmony_ci	pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
4598c2ecf20Sopenharmony_ci		g5_cpu_freqs[1].frequency/1000,
4608c2ecf20Sopenharmony_ci		g5_cpu_freqs[0].frequency/1000,
4618c2ecf20Sopenharmony_ci		g5_cpu_freqs[g5_pmode_cur].frequency/1000);
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	rc = cpufreq_register_driver(&g5_cpufreq_driver);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	/* We keep the CPU node on hold... hopefully, Apple G5 don't have
4668c2ecf20Sopenharmony_ci	 * hotplug CPU with a dynamic device-tree ...
4678c2ecf20Sopenharmony_ci	 */
4688c2ecf20Sopenharmony_ci	return rc;
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci bail_noprops:
4718c2ecf20Sopenharmony_ci	of_node_put(cpunode);
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	return rc;
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci#endif /* CONFIG_PMAC_SMU */
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_cistatic int __init g5_pm72_cpufreq_init(struct device_node *cpunode)
4808c2ecf20Sopenharmony_ci{
4818c2ecf20Sopenharmony_ci	struct device_node *cpuid = NULL, *hwclock = NULL;
4828c2ecf20Sopenharmony_ci	const u8 *eeprom = NULL;
4838c2ecf20Sopenharmony_ci	const u32 *valp;
4848c2ecf20Sopenharmony_ci	u64 max_freq, min_freq, ih, il;
4858c2ecf20Sopenharmony_ci	int has_volt = 1, rc = 0;
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	DBG("cpufreq: Initializing for PowerMac7,2, PowerMac7,3 and"
4888c2ecf20Sopenharmony_ci	    " RackMac3,1...\n");
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci	/* Lookup the cpuid eeprom node */
4918c2ecf20Sopenharmony_ci        cpuid = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/cpuid@a0");
4928c2ecf20Sopenharmony_ci	if (cpuid != NULL)
4938c2ecf20Sopenharmony_ci		eeprom = of_get_property(cpuid, "cpuid", NULL);
4948c2ecf20Sopenharmony_ci	if (eeprom == NULL) {
4958c2ecf20Sopenharmony_ci		pr_err("Can't find cpuid EEPROM !\n");
4968c2ecf20Sopenharmony_ci		rc = -ENODEV;
4978c2ecf20Sopenharmony_ci		goto bail;
4988c2ecf20Sopenharmony_ci	}
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci	/* Lookup the i2c hwclock */
5018c2ecf20Sopenharmony_ci	for_each_node_by_name(hwclock, "i2c-hwclock") {
5028c2ecf20Sopenharmony_ci		const char *loc = of_get_property(hwclock,
5038c2ecf20Sopenharmony_ci				"hwctrl-location", NULL);
5048c2ecf20Sopenharmony_ci		if (loc == NULL)
5058c2ecf20Sopenharmony_ci			continue;
5068c2ecf20Sopenharmony_ci		if (strcmp(loc, "CPU CLOCK"))
5078c2ecf20Sopenharmony_ci			continue;
5088c2ecf20Sopenharmony_ci		if (!of_get_property(hwclock, "platform-get-frequency", NULL))
5098c2ecf20Sopenharmony_ci			continue;
5108c2ecf20Sopenharmony_ci		break;
5118c2ecf20Sopenharmony_ci	}
5128c2ecf20Sopenharmony_ci	if (hwclock == NULL) {
5138c2ecf20Sopenharmony_ci		pr_err("Can't find i2c clock chip !\n");
5148c2ecf20Sopenharmony_ci		rc = -ENODEV;
5158c2ecf20Sopenharmony_ci		goto bail;
5168c2ecf20Sopenharmony_ci	}
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	DBG("cpufreq: i2c clock chip found: %pOF\n", hwclock);
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci	/* Now get all the platform functions */
5218c2ecf20Sopenharmony_ci	pfunc_cpu_getfreq =
5228c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "get-frequency");
5238c2ecf20Sopenharmony_ci	pfunc_cpu_setfreq_high =
5248c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "set-frequency-high");
5258c2ecf20Sopenharmony_ci	pfunc_cpu_setfreq_low =
5268c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "set-frequency-low");
5278c2ecf20Sopenharmony_ci	pfunc_slewing_done =
5288c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "slewing-done");
5298c2ecf20Sopenharmony_ci	pfunc_cpu0_volt_high =
5308c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "set-voltage-high-0");
5318c2ecf20Sopenharmony_ci	pfunc_cpu0_volt_low =
5328c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "set-voltage-low-0");
5338c2ecf20Sopenharmony_ci	pfunc_cpu1_volt_high =
5348c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "set-voltage-high-1");
5358c2ecf20Sopenharmony_ci	pfunc_cpu1_volt_low =
5368c2ecf20Sopenharmony_ci		pmf_find_function(hwclock, "set-voltage-low-1");
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci	/* Check we have minimum requirements */
5398c2ecf20Sopenharmony_ci	if (pfunc_cpu_getfreq == NULL || pfunc_cpu_setfreq_high == NULL ||
5408c2ecf20Sopenharmony_ci	    pfunc_cpu_setfreq_low == NULL || pfunc_slewing_done == NULL) {
5418c2ecf20Sopenharmony_ci		pr_err("Can't find platform functions !\n");
5428c2ecf20Sopenharmony_ci		rc = -ENODEV;
5438c2ecf20Sopenharmony_ci		goto bail;
5448c2ecf20Sopenharmony_ci	}
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	/* Check that we have complete sets */
5478c2ecf20Sopenharmony_ci	if (pfunc_cpu0_volt_high == NULL || pfunc_cpu0_volt_low == NULL) {
5488c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu0_volt_high);
5498c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu0_volt_low);
5508c2ecf20Sopenharmony_ci		pfunc_cpu0_volt_high = pfunc_cpu0_volt_low = NULL;
5518c2ecf20Sopenharmony_ci		has_volt = 0;
5528c2ecf20Sopenharmony_ci	}
5538c2ecf20Sopenharmony_ci	if (!has_volt ||
5548c2ecf20Sopenharmony_ci	    pfunc_cpu1_volt_high == NULL || pfunc_cpu1_volt_low == NULL) {
5558c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu1_volt_high);
5568c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu1_volt_low);
5578c2ecf20Sopenharmony_ci		pfunc_cpu1_volt_high = pfunc_cpu1_volt_low = NULL;
5588c2ecf20Sopenharmony_ci	}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci	/* Note: The device tree also contains a "platform-set-values"
5618c2ecf20Sopenharmony_ci	 * function for which I haven't quite figured out the usage. It
5628c2ecf20Sopenharmony_ci	 * might have to be called on init and/or wakeup, I'm not too sure
5638c2ecf20Sopenharmony_ci	 * but things seem to work fine without it so far ...
5648c2ecf20Sopenharmony_ci	 */
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	/* Get max frequency from device-tree */
5678c2ecf20Sopenharmony_ci	valp = of_get_property(cpunode, "clock-frequency", NULL);
5688c2ecf20Sopenharmony_ci	if (!valp) {
5698c2ecf20Sopenharmony_ci		pr_err("Can't find CPU frequency !\n");
5708c2ecf20Sopenharmony_ci		rc = -ENODEV;
5718c2ecf20Sopenharmony_ci		goto bail;
5728c2ecf20Sopenharmony_ci	}
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	max_freq = (*valp)/1000;
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci	/* Now calculate reduced frequency by using the cpuid input freq
5778c2ecf20Sopenharmony_ci	 * ratio. This requires 64 bits math unless we are willing to lose
5788c2ecf20Sopenharmony_ci	 * some precision
5798c2ecf20Sopenharmony_ci	 */
5808c2ecf20Sopenharmony_ci	ih = *((u32 *)(eeprom + 0x10));
5818c2ecf20Sopenharmony_ci	il = *((u32 *)(eeprom + 0x20));
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	/* Check for machines with no useful settings */
5848c2ecf20Sopenharmony_ci	if (il == ih) {
5858c2ecf20Sopenharmony_ci		pr_warn("No low frequency mode available on this model !\n");
5868c2ecf20Sopenharmony_ci		rc = -ENODEV;
5878c2ecf20Sopenharmony_ci		goto bail;
5888c2ecf20Sopenharmony_ci	}
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	min_freq = 0;
5918c2ecf20Sopenharmony_ci	if (ih != 0 && il != 0)
5928c2ecf20Sopenharmony_ci		min_freq = (max_freq * il) / ih;
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	/* Sanity check */
5958c2ecf20Sopenharmony_ci	if (min_freq >= max_freq || min_freq < 1000) {
5968c2ecf20Sopenharmony_ci		pr_err("Can't calculate low frequency !\n");
5978c2ecf20Sopenharmony_ci		rc = -ENXIO;
5988c2ecf20Sopenharmony_ci		goto bail;
5998c2ecf20Sopenharmony_ci	}
6008c2ecf20Sopenharmony_ci	g5_cpu_freqs[0].frequency = max_freq;
6018c2ecf20Sopenharmony_ci	g5_cpu_freqs[1].frequency = min_freq;
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	/* Based on a measurement on Xserve G5, rounded up. */
6048c2ecf20Sopenharmony_ci	transition_latency = 10 * NSEC_PER_MSEC;
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci	/* Set callbacks */
6078c2ecf20Sopenharmony_ci	g5_switch_volt = g5_pfunc_switch_volt;
6088c2ecf20Sopenharmony_ci	g5_switch_freq = g5_pfunc_switch_freq;
6098c2ecf20Sopenharmony_ci	g5_query_freq = g5_pfunc_query_freq;
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	/* Force apply current frequency to make sure everything is in
6128c2ecf20Sopenharmony_ci	 * sync (voltage is right for example). Firmware may leave us with
6138c2ecf20Sopenharmony_ci	 * a strange setting ...
6148c2ecf20Sopenharmony_ci	 */
6158c2ecf20Sopenharmony_ci	g5_switch_volt(CPUFREQ_HIGH);
6168c2ecf20Sopenharmony_ci	msleep(10);
6178c2ecf20Sopenharmony_ci	g5_pmode_cur = -1;
6188c2ecf20Sopenharmony_ci	g5_switch_freq(g5_query_freq());
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci	pr_info("Registering G5 CPU frequency driver\n");
6218c2ecf20Sopenharmony_ci	pr_info("Frequency method: i2c/pfunc, Voltage method: %s\n",
6228c2ecf20Sopenharmony_ci		has_volt ? "i2c/pfunc" : "none");
6238c2ecf20Sopenharmony_ci	pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
6248c2ecf20Sopenharmony_ci		g5_cpu_freqs[1].frequency/1000,
6258c2ecf20Sopenharmony_ci		g5_cpu_freqs[0].frequency/1000,
6268c2ecf20Sopenharmony_ci		g5_cpu_freqs[g5_pmode_cur].frequency/1000);
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci	rc = cpufreq_register_driver(&g5_cpufreq_driver);
6298c2ecf20Sopenharmony_ci bail:
6308c2ecf20Sopenharmony_ci	if (rc != 0) {
6318c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu_getfreq);
6328c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu_setfreq_high);
6338c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu_setfreq_low);
6348c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_slewing_done);
6358c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu0_volt_high);
6368c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu0_volt_low);
6378c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu1_volt_high);
6388c2ecf20Sopenharmony_ci		pmf_put_function(pfunc_cpu1_volt_low);
6398c2ecf20Sopenharmony_ci	}
6408c2ecf20Sopenharmony_ci	of_node_put(hwclock);
6418c2ecf20Sopenharmony_ci	of_node_put(cpuid);
6428c2ecf20Sopenharmony_ci	of_node_put(cpunode);
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci	return rc;
6458c2ecf20Sopenharmony_ci}
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_cistatic int __init g5_cpufreq_init(void)
6488c2ecf20Sopenharmony_ci{
6498c2ecf20Sopenharmony_ci	struct device_node *cpunode;
6508c2ecf20Sopenharmony_ci	int rc = 0;
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci	/* Get first CPU node */
6538c2ecf20Sopenharmony_ci	cpunode = of_cpu_device_node_get(0);
6548c2ecf20Sopenharmony_ci	if (cpunode == NULL) {
6558c2ecf20Sopenharmony_ci		pr_err("Can't find any CPU node\n");
6568c2ecf20Sopenharmony_ci		return -ENODEV;
6578c2ecf20Sopenharmony_ci	}
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci	if (of_machine_is_compatible("PowerMac7,2") ||
6608c2ecf20Sopenharmony_ci	    of_machine_is_compatible("PowerMac7,3") ||
6618c2ecf20Sopenharmony_ci	    of_machine_is_compatible("RackMac3,1"))
6628c2ecf20Sopenharmony_ci		rc = g5_pm72_cpufreq_init(cpunode);
6638c2ecf20Sopenharmony_ci#ifdef CONFIG_PMAC_SMU
6648c2ecf20Sopenharmony_ci	else
6658c2ecf20Sopenharmony_ci		rc = g5_neo2_cpufreq_init(cpunode);
6668c2ecf20Sopenharmony_ci#endif /* CONFIG_PMAC_SMU */
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	return rc;
6698c2ecf20Sopenharmony_ci}
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_cimodule_init(g5_cpufreq_init);
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
675