xref: /OK3568_Linux_fs/kernel/drivers/macintosh/windfarm_mpu.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Windfarm PowerMac thermal control
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2012 Benjamin Herrenschmidt, IBM Corp.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __WINDFARM_MPU_H
9*4882a593Smuzhiyun #define __WINDFARM_MPU_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun typedef unsigned short fu16;
12*4882a593Smuzhiyun typedef int fs32;
13*4882a593Smuzhiyun typedef short fs16;
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /* Definition of the MPU data structure which contains per CPU
16*4882a593Smuzhiyun  * calibration information (among others) for the G5 machines
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun struct mpu_data
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun 	u8	signature;		/* 0x00 - EEPROM sig. */
21*4882a593Smuzhiyun 	u8	bytes_used;		/* 0x01 - Bytes used in eeprom (160 ?) */
22*4882a593Smuzhiyun 	u8	size;			/* 0x02 - EEPROM size (256 ?) */
23*4882a593Smuzhiyun 	u8	version;		/* 0x03 - EEPROM version */
24*4882a593Smuzhiyun 	u32	data_revision;		/* 0x04 - Dataset revision */
25*4882a593Smuzhiyun 	u8	processor_bin_code[3];	/* 0x08 - Processor BIN code */
26*4882a593Smuzhiyun 	u8	bin_code_expansion;	/* 0x0b - ??? (padding ?) */
27*4882a593Smuzhiyun 	u8	processor_num;		/* 0x0c - Number of CPUs on this MPU */
28*4882a593Smuzhiyun 	u8	input_mul_bus_div;	/* 0x0d - Clock input multiplier/bus divider */
29*4882a593Smuzhiyun 	u8	reserved1[2];		/* 0x0e - */
30*4882a593Smuzhiyun 	u32	input_clk_freq_high;	/* 0x10 - Input clock frequency high */
31*4882a593Smuzhiyun 	u8	cpu_nb_target_cycles;	/* 0x14 - ??? */
32*4882a593Smuzhiyun 	u8	cpu_statlat;		/* 0x15 - ??? */
33*4882a593Smuzhiyun 	u8	cpu_snooplat;		/* 0x16 - ??? */
34*4882a593Smuzhiyun 	u8	cpu_snoopacc;		/* 0x17 - ??? */
35*4882a593Smuzhiyun 	u8	nb_paamwin;		/* 0x18 - ??? */
36*4882a593Smuzhiyun 	u8	nb_statlat;		/* 0x19 - ??? */
37*4882a593Smuzhiyun 	u8	nb_snooplat;		/* 0x1a - ??? */
38*4882a593Smuzhiyun 	u8	nb_snoopwin;		/* 0x1b - ??? */
39*4882a593Smuzhiyun 	u8	api_bus_mode;		/* 0x1c - ??? */
40*4882a593Smuzhiyun 	u8	reserved2[3];		/* 0x1d - */
41*4882a593Smuzhiyun 	u32	input_clk_freq_low;	/* 0x20 - Input clock frequency low */
42*4882a593Smuzhiyun 	u8	processor_card_slot;	/* 0x24 - Processor card slot number */
43*4882a593Smuzhiyun 	u8	reserved3[2];		/* 0x25 - */
44*4882a593Smuzhiyun 	u8	padjmax;       		/* 0x27 - Max power adjustment (Not in OF!) */
45*4882a593Smuzhiyun 	u8	ttarget;		/* 0x28 - Target temperature */
46*4882a593Smuzhiyun 	u8	tmax;			/* 0x29 - Max temperature */
47*4882a593Smuzhiyun 	u8	pmaxh;			/* 0x2a - Max power */
48*4882a593Smuzhiyun 	u8	tguardband;		/* 0x2b - Guardband temp ??? Hist. len in OSX */
49*4882a593Smuzhiyun 	fs32	pid_gp;			/* 0x2c - PID proportional gain */
50*4882a593Smuzhiyun 	fs32	pid_gr;			/* 0x30 - PID reset gain */
51*4882a593Smuzhiyun 	fs32	pid_gd;			/* 0x34 - PID derivative gain */
52*4882a593Smuzhiyun 	fu16	voph;			/* 0x38 - Vop High */
53*4882a593Smuzhiyun 	fu16	vopl;			/* 0x3a - Vop Low */
54*4882a593Smuzhiyun 	fs16	nactual_die;		/* 0x3c - nActual Die */
55*4882a593Smuzhiyun 	fs16	nactual_heatsink;	/* 0x3e - nActual Heatsink */
56*4882a593Smuzhiyun 	fs16	nactual_system;		/* 0x40 - nActual System */
57*4882a593Smuzhiyun 	u16	calibration_flags;	/* 0x42 - Calibration flags */
58*4882a593Smuzhiyun 	fu16	mdiode;			/* 0x44 - Diode M value (scaling factor) */
59*4882a593Smuzhiyun 	fs16	bdiode;			/* 0x46 - Diode B value (offset) */
60*4882a593Smuzhiyun 	fs32	theta_heat_sink;	/* 0x48 - Theta heat sink */
61*4882a593Smuzhiyun 	u16	rminn_intake_fan;	/* 0x4c - Intake fan min RPM */
62*4882a593Smuzhiyun 	u16	rmaxn_intake_fan;	/* 0x4e - Intake fan max RPM */
63*4882a593Smuzhiyun 	u16	rminn_exhaust_fan;	/* 0x50 - Exhaust fan min RPM */
64*4882a593Smuzhiyun 	u16	rmaxn_exhaust_fan;	/* 0x52 - Exhaust fan max RPM */
65*4882a593Smuzhiyun 	u8	processor_part_num[8];	/* 0x54 - Processor part number XX pumps min/max */
66*4882a593Smuzhiyun 	u32	processor_lot_num;	/* 0x5c - Processor lot number */
67*4882a593Smuzhiyun 	u8	orig_card_sernum[0x10];	/* 0x60 - Card original serial number */
68*4882a593Smuzhiyun 	u8	curr_card_sernum[0x10];	/* 0x70 - Card current serial number */
69*4882a593Smuzhiyun 	u8	mlb_sernum[0x18];	/* 0x80 - MLB serial number */
70*4882a593Smuzhiyun 	u32	checksum1;		/* 0x98 - */
71*4882a593Smuzhiyun 	u32	checksum2;		/* 0x9c - */
72*4882a593Smuzhiyun }; /* Total size = 0xa0 */
73*4882a593Smuzhiyun 
wf_get_mpu(int cpu)74*4882a593Smuzhiyun static inline const struct mpu_data *wf_get_mpu(int cpu)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun 	struct device_node *np;
77*4882a593Smuzhiyun 	char nodename[64];
78*4882a593Smuzhiyun 	const void *data;
79*4882a593Smuzhiyun 	int len;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	/*
82*4882a593Smuzhiyun 	 * prom.c routine for finding a node by path is a bit brain dead
83*4882a593Smuzhiyun 	 * and requires exact @xxx unit numbers. This is a bit ugly but
84*4882a593Smuzhiyun 	 * will work for these machines
85*4882a593Smuzhiyun 	 */
86*4882a593Smuzhiyun 	sprintf(nodename, "/u3@0,f8000000/i2c@f8001000/cpuid@a%d", cpu ? 2 : 0);
87*4882a593Smuzhiyun 	np = of_find_node_by_path(nodename);
88*4882a593Smuzhiyun 	if (!np)
89*4882a593Smuzhiyun 		return NULL;
90*4882a593Smuzhiyun 	data = of_get_property(np, "cpuid", &len);
91*4882a593Smuzhiyun 	of_node_put(np);
92*4882a593Smuzhiyun 	if (!data)
93*4882a593Smuzhiyun 		return NULL;
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/*
96*4882a593Smuzhiyun 	 * We are naughty, we have dropped the reference to the device
97*4882a593Smuzhiyun 	 * node and still return a pointer to the content. We know we
98*4882a593Smuzhiyun 	 * can do that though as this is only ever called on PowerMac
99*4882a593Smuzhiyun 	 * which cannot remove those nodes
100*4882a593Smuzhiyun 	 */
101*4882a593Smuzhiyun 	return data;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #endif /*  __WINDFARM_MPU_H */
105