summaryrefslogtreecommitdiff
path: root/arch/powerpc/platforms/85xx/common.c
blob: 09978f5c212d1342d0759faa0f6df7191106a958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Routines common to most mpc85xx-based boards.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/of_platform.h>

#include <asm/time.h>

#include <sysdev/cpm2_pic.h>

#include "mpc85xx.h"

#define MAX_BIT				64

#define ALTIVEC_COUNT_OFFSET		16
#define ALTIVEC_IDLE_COUNT_MASK		0x003f0000
#define PW20_COUNT_OFFSET		8
#define PW20_IDLE_COUNT_MASK		0x00003f00

/*
 * FIXME - We don't know the AltiVec application scenarios.
 */
#define ALTIVEC_IDLE_TIME	1000 /* 1ms */

/*
 * FIXME - We don't know, what time should we let the core into PW20 state.
 * because we don't know the current state of the cpu load. And threads are
 * independent, so we can not know the state of different thread has been
 * idle.
 */
#define	PW20_IDLE_TIME		1000 /* 1ms */

static struct of_device_id __initdata mpc85xx_common_ids[] = {
	{ .type = "soc", },
	{ .compatible = "soc", },
	{ .compatible = "simple-bus", },
	{ .name = "cpm", },
	{ .name = "localbus", },
	{ .compatible = "gianfar", },
	{ .compatible = "fsl,qe", },
	{ .compatible = "fsl,cpm2", },
	{ .compatible = "fsl,srio", },
	/* So that the DMA channel nodes can be probed individually: */
	{ .compatible = "fsl,eloplus-dma", },
	/* For the PMC driver */
	{ .compatible = "fsl,mpc8548-guts", },
	/* Probably unnecessary? */
	{ .compatible = "gpio-leds", },
	/* For all PCI controllers */
	{ .compatible = "fsl,mpc8540-pci", },
	{ .compatible = "fsl,mpc8548-pcie", },
	{ .compatible = "fsl,p1022-pcie", },
	{ .compatible = "fsl,p1010-pcie", },
	{ .compatible = "fsl,p1023-pcie", },
	{ .compatible = "fsl,p4080-pcie", },
	{ .compatible = "fsl,qoriq-pcie-v2.4", },
	{ .compatible = "fsl,qoriq-pcie-v2.3", },
	{ .compatible = "fsl,qoriq-pcie-v2.2", },
	/* For the FMan driver */
	{ .compatible = "fsl,dpaa", },
	{},
};

int __init mpc85xx_common_publish_devices(void)
{
	return of_platform_bus_probe(NULL, mpc85xx_common_ids, NULL);
}
#ifdef CONFIG_CPM2
static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
{
	struct irq_chip *chip = irq_desc_get_chip(desc);
	int cascade_irq;

	while ((cascade_irq = cpm2_get_irq()) >= 0)
		generic_handle_irq(cascade_irq);

	chip->irq_eoi(&desc->irq_data);
}


void __init mpc85xx_cpm2_pic_init(void)
{
	struct device_node *np;
	int irq;

	/* Setup CPM2 PIC */
	np = of_find_compatible_node(NULL, NULL, "fsl,cpm2-pic");
	if (np == NULL) {
		printk(KERN_ERR "PIC init: can not find fsl,cpm2-pic node\n");
		return;
	}
	irq = irq_of_parse_and_map(np, 0);
	if (irq == NO_IRQ) {
		of_node_put(np);
		printk(KERN_ERR "PIC init: got no IRQ for cpm cascade\n");
		return;
	}

	cpm2_pic_init(np);
	of_node_put(np);
	irq_set_chained_handler(irq, cpm2_cascade);
}
#endif

static bool has_pw20_altivec_idle(void)
{
	u32 pvr;

	pvr = mfspr(SPRN_PVR);

	/* PW20 & AltiVec idle feature only exists for E6500 */
	if (PVR_VER(pvr) != PVR_VER_E6500)
		return false;

	/* Fix erratum, e6500 rev1 does not support PW20 & AltiVec idle */
	if (PVR_REV(pvr) < 0x20)
		return false;

	return true;
}

static unsigned int get_idle_ticks_bit(unsigned int us)
{
	unsigned int cycle;

	/*
	 * The time control by TB turn over bit, so we need
	 * to be divided by 2.
	 */
	cycle = (us / 2) * tb_ticks_per_usec;

	return ilog2(cycle) + 1;
}

static void setup_altivec_idle(void *unused)
{
	u32 altivec_idle, bit;

	if (!has_pw20_altivec_idle())
		return;

	/* Enable Altivec Idle */
	altivec_idle = mfspr(SPRN_PWRMGTCR0);
	altivec_idle |= PWRMGTCR0_ALTIVEC_IDLE;

	/* Set Automatic AltiVec Idle Count */
	/* clear count */
	altivec_idle &= ~ALTIVEC_IDLE_COUNT_MASK;

	/* set count */
	bit = get_idle_ticks_bit(ALTIVEC_IDLE_TIME);
	altivec_idle |= ((MAX_BIT - bit) << ALTIVEC_COUNT_OFFSET);

	mtspr(SPRN_PWRMGTCR0, altivec_idle);
}

static void setup_pw20_idle(void *unused)
{
	u32 pw20_idle, bit;

	if (!has_pw20_altivec_idle())
		return;

	pw20_idle = mfspr(SPRN_PWRMGTCR0);

	/* set PW20_WAIT bit, enable pw20 */
	pw20_idle |= PWRMGTCR0_PW20_WAIT;

	/* Set Automatic PW20 Core Idle Count */
	/* clear count */
	pw20_idle &= ~PW20_IDLE_COUNT_MASK;

	/* set count */
	bit = get_idle_ticks_bit(PW20_IDLE_TIME);
	pw20_idle |= ((MAX_BIT - bit) << PW20_COUNT_OFFSET);

	mtspr(SPRN_PWRMGTCR0, pw20_idle);
}

static int __init setup_idle_hw_governor(void)
{
	on_each_cpu(setup_altivec_idle, NULL, 1);
	on_each_cpu(setup_pw20_idle, NULL, 1);

	return 0;
}
late_initcall(setup_idle_hw_governor);