summaryrefslogtreecommitdiffstats
path: root/arch/ppc/kernel/feature.c
blob: 25ee3424bf1c1702b65c619e626e220009d42f17 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
 *  arch/ppc/kernel/feature.c
 *
 *  Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version
 *  2 of the License, or (at your option) any later version.
 *
 */
#include <linux/types.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <asm/errno.h>
#include <asm/ohare.h>
#include <asm/io.h>
#include <asm/prom.h>
#include <asm/feature.h>

#define MAX_FEATURE_REGS		2
#undef DEBUG_FEATURE

static u32 feature_bits_pbook[] = {
	0,			/* FEATURE_null */
	OH_SCC_RESET,		/* FEATURE_Serial_reset */
	OH_SCC_ENABLE,		/* FEATURE_Serial_enable */
	OH_SCCA_IO,		/* FEATURE_Serial_IO_A */
	OH_SCCB_IO,		/* FEATURE_Serial_IO_B */
	OH_FLOPPY_ENABLE,	/* FEATURE_SWIM3_enable */
	OH_MESH_ENABLE,		/* FEATURE_MESH_enable */
	OH_IDE_ENABLE,		/* FEATURE_IDE_enable */
	OH_VIA_ENABLE,		/* FEATURE_VIA_enable */
	OH_IDECD_POWER,		/* FEATURE_CD_power */
	OH_BAY_RESET,		/* FEATURE_Mediabay_reset */
	OH_BAY_ENABLE,		/* FEATURE_Mediabay_enable */
	OH_BAY_PCI_ENABLE,	/* FEATURE_Mediabay_PCI_enable */
	OH_BAY_IDE_ENABLE,	/* FEATURE_Mediabay_IDE_enable */
	OH_BAY_FLOPPY_ENABLE,	/* FEATURE_Mediabay_floppy_enable */
	0,			/* FEATURE_BMac_reset */
	0,			/* FEATURE_BMac_IO_enable */
	0			/* FEATURE_Modem_Reset -> guess...*/
};

/* assume these are the same as the ohare until proven otherwise */
static u32 feature_bits_heathrow[] = {
	0,			/* FEATURE_null */
	OH_SCC_RESET,		/* FEATURE_Serial_reset */
	OH_SCC_ENABLE,		/* FEATURE_Serial_enable */
	OH_SCCA_IO,		/* FEATURE_Serial_IO_A */
	OH_SCCB_IO,		/* FEATURE_Serial_IO_B */
	OH_FLOPPY_ENABLE,	/* FEATURE_SWIM3_enable */
	OH_MESH_ENABLE,		/* FEATURE_MESH_enable */
	OH_IDE_ENABLE,		/* FEATURE_IDE_enable */
	OH_VIA_ENABLE,		/* FEATURE_VIA_enable */
	OH_IDECD_POWER,		/* FEATURE_CD_power */
	OH_BAY_RESET,		/* FEATURE_Mediabay_reset */
	OH_BAY_ENABLE,		/* FEATURE_Mediabay_enable */
	OH_BAY_PCI_ENABLE,	/* FEATURE_Mediabay_PCI_enable */
	OH_BAY_IDE_ENABLE,	/* FEATURE_Mediabay_IDE_enable */
	OH_BAY_FLOPPY_ENABLE,	/* FEATURE_Mediabay_floppy_enable */
	0x80000000,		/* FEATURE_BMac_reset */
	0x60000000,		/* FEATURE_BMac_IO_enable */
	0x02000000		/* FEATURE_Modem_Reset -> guess...*/
};

/* definition of a feature controller object */
struct feature_controller
{
	u32*			bits;
	volatile u32*		reg;
	struct device_node*	device;
};

/* static functions */
static void
feature_add_controller(struct device_node *controller_device, u32* bits);

static int
feature_lookup_controller(struct device_node *device);

/* static varialbles */
static struct feature_controller	controllers[MAX_FEATURE_REGS];
static int				controller_count = 0;


void
feature_init(void)
{
	struct device_node *np;

	np = find_devices("mac-io");
	while (np != NULL)
	{
		feature_add_controller(np, feature_bits_heathrow);
		np = np->next;
	}
	if (controller_count == 0)
	{
		np = find_devices("ohare");
		if (np)
		{
			if (find_devices("via-pmu") != NULL)
				feature_add_controller(np, feature_bits_pbook);
			else
				/* else not sure; maybe this is a Starmax? */
				feature_add_controller(np, NULL);
		}
	}

	if (controller_count)
		printk(KERN_INFO "Registered %d feature controller(s)\n", controller_count);
}

static void
feature_add_controller(struct device_node *controller_device, u32* bits)
{
	struct feature_controller*	controller;
	
	if (controller_count >= MAX_FEATURE_REGS)
	{
		printk(KERN_INFO "Feature controller %s skipped(MAX:%d)\n",
			controller_device->full_name, MAX_FEATURE_REGS);
		return;
	}
	controller = &controllers[controller_count];

	controller->bits	= bits;
	controller->device	= controller_device;
	if (controller_device->n_addrs == 0) {
		printk(KERN_ERR "No addresses for %s\n",
			controller_device->full_name);
		return;
	}

	controller->reg		= (volatile u32 *)ioremap(
		controller_device->addrs[0].address + OHARE_FEATURE_REG, 4);

	if (bits == NULL) {
		printk(KERN_INFO "Twiddling the magic ohare bits\n");
		out_le32(controller->reg, STARMAX_FEATURES);
		return;
	}

	controller_count++;
}

static int
feature_lookup_controller(struct device_node *device)
{
	int	i;
	
	if (device == NULL)
		return -EINVAL;
		
	while(device)
	{
		for (i=0; i<controller_count; i++)
			if (device == controllers[i].device)
				return i;
		device = device->parent;
	}

#ifdef DEBUG_FEATURE
	printk("feature: <%s> not found on any controller\n",
		device->name);
#endif
	
	return -ENODEV;
}

int
feature_set(struct device_node* device, enum system_feature f)
{
	int		controller;
	unsigned long	flags;

	if (f >= FEATURE_last)
		return -EINVAL;	

	controller = feature_lookup_controller(device);
	if (controller < 0)
		return controller;
	
#ifdef DEBUG_FEATURE
	printk("feature: <%s> setting feature %d in controller @0x%x\n",
		device->name, (int)f, (unsigned int)controllers[controller].reg);
#endif

	save_flags(flags);
	cli();
	st_le32( controllers[controller].reg,
		 ld_le32(controllers[controller].reg) |
		 controllers[controller].bits[f]);
	restore_flags(flags);
	udelay(10);
	
	return 0;
}

int
feature_clear(struct device_node* device, enum system_feature f)
{
	int		controller;
	unsigned long	flags;

	if (f >= FEATURE_last)
		return -EINVAL;	

	controller = feature_lookup_controller(device);
	if (controller < 0)
		return controller;
	
#ifdef DEBUG_FEATURE
	printk("feature: <%s> clearing feature %d in controller @0x%x\n",
		device->name, (int)f, (unsigned int)controllers[controller].reg);
#endif

	save_flags(flags);
	cli();
	st_le32( controllers[controller].reg,
		 ld_le32(controllers[controller].reg) &
		 ~(controllers[controller].bits[f]));
	restore_flags(flags);
	udelay(10);
	
	return 0;
}

int
feature_test(struct device_node* device, enum system_feature f)
{
	int		controller;

	if (f >= FEATURE_last)
		return -EINVAL;	

	controller = feature_lookup_controller(device);
	if (controller < 0)
		return controller;
	
	return (ld_le32(controllers[controller].reg) &
		controllers[controller].bits[f]) != 0;
}