1/*
2 * Definition of platform feature hooks for PowerMacs
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License.  See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1998 Paul Mackerras &
9 *                    Ben. Herrenschmidt.
10 *
11 *
12 * Note: I removed media-bay details from the feature stuff, I believe it's
13 *       not worth it, the media-bay driver can directly use the mac-io
14 *       ASIC registers.
15 *
16 * Implementation note: Currently, none of these functions will block.
17 * However, they may internally protect themselves with a spinlock
18 * for way too long. Be prepared for at least some of these to block
19 * in the future.
20 *
21 * Unless specifically defined, the result code is assumed to be an
22 * error when negative, 0 is the default success result. Some functions
23 * may return additional positive result values.
24 *
25 * To keep implementation simple, all feature calls are assumed to have
26 * the prototype parameters (struct device_node* node, int value).
27 * When either is not used, pass 0.
28 */
29
30#ifdef __KERNEL__
31#ifndef __ASM_POWERPC_PMAC_FEATURE_H
32#define __ASM_POWERPC_PMAC_FEATURE_H
33
34#include <asm/macio.h>
35#include <asm/machdep.h>
36
37/*
38 * Known Mac motherboard models
39 *
40 * Please, report any error here to benh@kernel.crashing.org, thanks !
41 *
42 * Note that I don't fully maintain this list for Core99 & MacRISC2
43 * and I'm considering removing all NewWorld entries from it and
44 * entirely rely on the model string.
45 */
46
47/* PowerSurge are the first generation of PCI Pmacs. This include
48 * all of the Grand-Central based machines. We currently don't
49 * differenciate most of them.
50 */
51#define PMAC_TYPE_PSURGE		0x10	/* PowerSurge */
52#define PMAC_TYPE_ANS			0x11	/* Apple Network Server */
53
54/* Here is the infamous serie of OHare based machines
55 */
56#define PMAC_TYPE_COMET			0x20	/* Beleived to be PowerBook 2400 */
57#define PMAC_TYPE_HOOPER		0x21	/* Beleived to be PowerBook 3400 */
58#define PMAC_TYPE_KANGA			0x22	/* PowerBook 3500 (first G3) */
59#define PMAC_TYPE_ALCHEMY		0x23	/* Alchemy motherboard base */
60#define PMAC_TYPE_GAZELLE		0x24	/* Spartacus, some 5xxx/6xxx */
61#define PMAC_TYPE_UNKNOWN_OHARE		0x2f	/* Unknown, but OHare based */
62
63#define PMAC_TYPE_GOSSAMER		0x30	/* Gossamer motherboard */
64#define PMAC_TYPE_SILK			0x31	/* Desktop PowerMac G3 */
65#define PMAC_TYPE_WALLSTREET		0x32	/* Wallstreet/Mainstreet PowerBook*/
66#define PMAC_TYPE_UNKNOWN_HEATHROW	0x3f	/* Unknown but heathrow based */
67
68/* Here are newworld machines based on Paddington (heathrow derivative)
69 */
70#define PMAC_TYPE_101_PBOOK		0x40	/* 101 PowerBook (aka Lombard) */
71#define PMAC_TYPE_ORIG_IMAC		0x41	/* First generation iMac */
72#define PMAC_TYPE_YOSEMITE		0x42	/* B&W G3 */
73#define PMAC_TYPE_YIKES			0x43	/* Yikes G4 (PCI graphics) */
74#define PMAC_TYPE_UNKNOWN_PADDINGTON	0x4f	/* Unknown but paddington based */
75
76/* Core99 machines based on UniNorth 1.0 and 1.5
77 *
78 * Note: A single entry here may cover several actual models according
79 * to the device-tree. (Sawtooth is most tower G4s, FW_IMAC is most
80 * FireWire based iMacs, etc...). Those machines are too similar to be
81 * distinguished here, when they need to be differencied, use the
82 * device-tree "model" or "compatible" property.
83 */
84#define PMAC_TYPE_ORIG_IBOOK		0x40	/* First iBook model (no firewire) */
85#define PMAC_TYPE_SAWTOOTH		0x41	/* Desktop G4s */
86#define PMAC_TYPE_FW_IMAC		0x42	/* FireWire iMacs (except Pangea based) */
87#define PMAC_TYPE_FW_IBOOK		0x43	/* FireWire iBooks (except iBook2) */
88#define PMAC_TYPE_CUBE			0x44	/* Cube PowerMac */
89#define PMAC_TYPE_QUICKSILVER		0x45	/* QuickSilver G4s */
90#define PMAC_TYPE_PISMO			0x46	/* Pismo PowerBook */
91#define PMAC_TYPE_TITANIUM		0x47	/* Titanium PowerBook */
92#define PMAC_TYPE_TITANIUM2		0x48	/* Titanium II PowerBook (no L3, M6) */
93#define PMAC_TYPE_TITANIUM3		0x49	/* Titanium III PowerBook (with L3 & M7) */
94#define PMAC_TYPE_TITANIUM4		0x50	/* Titanium IV PowerBook (with L3 & M9) */
95#define PMAC_TYPE_EMAC			0x50	/* eMac */
96#define PMAC_TYPE_UNKNOWN_CORE99	0x5f
97
98/* MacRisc2 with UniNorth 2.0 */
99#define PMAC_TYPE_RACKMAC		0x80	/* XServe */
100#define PMAC_TYPE_WINDTUNNEL		0x81
101
102/* MacRISC2 machines based on the Pangea chipset
103 */
104#define PMAC_TYPE_PANGEA_IMAC		0x100	/* Flower Power iMac */
105#define PMAC_TYPE_IBOOK2		0x101	/* iBook2 (polycarbonate) */
106#define PMAC_TYPE_FLAT_PANEL_IMAC	0x102	/* Flat panel iMac */
107#define PMAC_TYPE_UNKNOWN_PANGEA	0x10f
108
109/* MacRISC2 machines based on the Intrepid chipset
110 */
111#define PMAC_TYPE_UNKNOWN_INTREPID	0x11f	/* Generic */
112
113/* MacRISC4 / G5 machines. We don't have per-machine selection here anymore,
114 * but rather machine families
115 */
116#define PMAC_TYPE_POWERMAC_G5		0x150	/* U3 & U3H based */
117#define PMAC_TYPE_POWERMAC_G5_U3L	0x151	/* U3L based desktop */
118#define PMAC_TYPE_IMAC_G5		0x152	/* iMac G5 */
119#define PMAC_TYPE_XSERVE_G5		0x153	/* Xserve G5 */
120#define PMAC_TYPE_UNKNOWN_K2		0x19f	/* Any other K2 based */
121#define PMAC_TYPE_UNKNOWN_SHASTA       	0x19e	/* Any other Shasta based */
122
123/*
124 * Motherboard flags
125 */
126
127#define PMAC_MB_CAN_SLEEP		0x00000001
128#define PMAC_MB_HAS_FW_POWER		0x00000002
129#define PMAC_MB_OLD_CORE99		0x00000004
130#define PMAC_MB_MOBILE			0x00000008
131#define PMAC_MB_MAY_SLEEP		0x00000010
132
133/*
134 * Feature calls supported on pmac
135 *
136 */
137
138/*
139 * Use this inline wrapper
140 */
141struct device_node;
142
143static inline long pmac_call_feature(int selector, struct device_node* node,
144					long param, long value)
145{
146	if (!ppc_md.feature_call || !machine_is(powermac))
147		return -ENODEV;
148	return ppc_md.feature_call(selector, node, param, value);
149}
150
151/* PMAC_FTR_SERIAL_ENABLE	(struct device_node* node, int param, int value)
152 * enable/disable an SCC side. Pass the node corresponding to the
153 * channel side as a parameter.
154 * param is the type of port
155 * if param is ored with PMAC_SCC_FLAG_XMON, then the SCC is locked enabled
156 * for use by xmon.
157 */
158#define PMAC_FTR_SCC_ENABLE		PMAC_FTR_DEF(0)
159	#define PMAC_SCC_ASYNC		0
160	#define PMAC_SCC_IRDA		1
161	#define PMAC_SCC_I2S1		2
162	#define PMAC_SCC_FLAG_XMON	0x00001000
163
164/* PMAC_FTR_MODEM_ENABLE	(struct device_node* node, 0, int value)
165 * enable/disable the internal modem.
166 */
167#define PMAC_FTR_MODEM_ENABLE		PMAC_FTR_DEF(1)
168
169/* PMAC_FTR_SWIM3_ENABLE	(struct device_node* node, 0,int value)
170 * enable/disable the swim3 (floppy) cell of a mac-io ASIC
171 */
172#define PMAC_FTR_SWIM3_ENABLE		PMAC_FTR_DEF(2)
173
174/* PMAC_FTR_MESH_ENABLE		(struct device_node* node, 0, int value)
175 * enable/disable the mesh (scsi) cell of a mac-io ASIC
176 */
177#define PMAC_FTR_MESH_ENABLE		PMAC_FTR_DEF(3)
178
179/* PMAC_FTR_IDE_ENABLE		(struct device_node* node, int busID, int value)
180 * enable/disable an IDE port of a mac-io ASIC
181 * pass the busID parameter
182 */
183#define PMAC_FTR_IDE_ENABLE		PMAC_FTR_DEF(4)
184
185/* PMAC_FTR_IDE_RESET		(struct device_node* node, int busID, int value)
186 * assert(1)/release(0) an IDE reset line (mac-io IDE only)
187 */
188#define PMAC_FTR_IDE_RESET		PMAC_FTR_DEF(5)
189
190/* PMAC_FTR_BMAC_ENABLE		(struct device_node* node, 0, int value)
191 * enable/disable the bmac (ethernet) cell of a mac-io ASIC, also drive
192 * it's reset line
193 */
194#define PMAC_FTR_BMAC_ENABLE		PMAC_FTR_DEF(6)
195
196/* PMAC_FTR_GMAC_ENABLE		(struct device_node* node, 0, int value)
197 * enable/disable the gmac (ethernet) cell of an uninorth ASIC. This
198 * control the cell's clock.
199 */
200#define PMAC_FTR_GMAC_ENABLE		PMAC_FTR_DEF(7)
201
202/* PMAC_FTR_GMAC_PHY_RESET	(struct device_node* node, 0, 0)
203 * Perform a HW reset of the PHY connected to a gmac controller.
204 * Pass the gmac device node, not the PHY node.
205 */
206#define PMAC_FTR_GMAC_PHY_RESET		PMAC_FTR_DEF(8)
207
208/* PMAC_FTR_SOUND_CHIP_ENABLE	(struct device_node* node, 0, int value)
209 * enable/disable the sound chip, whatever it is and provided it can
210 * acually be controlled
211 */
212#define PMAC_FTR_SOUND_CHIP_ENABLE	PMAC_FTR_DEF(9)
213
214/* -- add various tweaks related to sound routing -- */
215
216/* PMAC_FTR_AIRPORT_ENABLE	(struct device_node* node, 0, int value)
217 * enable/disable the airport card
218 */
219#define PMAC_FTR_AIRPORT_ENABLE		PMAC_FTR_DEF(10)
220
221/* PMAC_FTR_RESET_CPU		(NULL, int cpu_nr, 0)
222 * toggle the reset line of a CPU on an uninorth-based SMP machine
223 */
224#define PMAC_FTR_RESET_CPU		PMAC_FTR_DEF(11)
225
226/* PMAC_FTR_USB_ENABLE		(struct device_node* node, 0, int value)
227 * enable/disable an USB cell, along with the power of the USB "pad"
228 * on keylargo based machines
229 */
230#define PMAC_FTR_USB_ENABLE		PMAC_FTR_DEF(12)
231
232/* PMAC_FTR_1394_ENABLE		(struct device_node* node, 0, int value)
233 * enable/disable the firewire cell of an uninorth ASIC.
234 */
235#define PMAC_FTR_1394_ENABLE		PMAC_FTR_DEF(13)
236
237/* PMAC_FTR_1394_CABLE_POWER	(struct device_node* node, 0, int value)
238 * enable/disable the firewire cable power supply of the uninorth
239 * firewire cell
240 */
241#define PMAC_FTR_1394_CABLE_POWER	PMAC_FTR_DEF(14)
242
243/* PMAC_FTR_SLEEP_STATE		(struct device_node* node, 0, int value)
244 * set the sleep state of the motherboard.
245 *
246 * Pass -1 as value to query for sleep capability
247 * Pass 1 to set IOs to sleep
248 * Pass 0 to set IOs to wake
249 */
250#define PMAC_FTR_SLEEP_STATE		PMAC_FTR_DEF(15)
251
252/* PMAC_FTR_GET_MB_INFO		(NULL, selector, 0)
253 *
254 * returns some motherboard infos.
255 * selector: 0  - model id
256 *           1  - model flags (capabilities)
257 *           2  - model name (cast to const char *)
258 */
259#define PMAC_FTR_GET_MB_INFO		PMAC_FTR_DEF(16)
260#define   PMAC_MB_INFO_MODEL	0
261#define   PMAC_MB_INFO_FLAGS	1
262#define   PMAC_MB_INFO_NAME	2
263
264/* PMAC_FTR_READ_GPIO		(NULL, int index, 0)
265 *
266 * read a GPIO from a mac-io controller of type KeyLargo or Pangea.
267 * the value returned is a byte (positive), or a negative error code
268 */
269#define PMAC_FTR_READ_GPIO		PMAC_FTR_DEF(17)
270
271/* PMAC_FTR_WRITE_GPIO		(NULL, int index, int value)
272 *
273 * write a GPIO of a mac-io controller of type KeyLargo or Pangea.
274 */
275#define PMAC_FTR_WRITE_GPIO		PMAC_FTR_DEF(18)
276
277/* PMAC_FTR_ENABLE_MPIC
278 *
279 * Enable the MPIC cell
280 */
281#define PMAC_FTR_ENABLE_MPIC		PMAC_FTR_DEF(19)
282
283/* PMAC_FTR_AACK_DELAY_ENABLE	(NULL, int enable, 0)
284 *
285 * Enable/disable the AACK delay on the northbridge for systems using DFS
286 */
287#define PMAC_FTR_AACK_DELAY_ENABLE     	PMAC_FTR_DEF(20)
288
289/* PMAC_FTR_DEVICE_CAN_WAKE
290 *
291 * Used by video drivers to inform system that they can actually perform
292 * wakeup from sleep
293 */
294#define PMAC_FTR_DEVICE_CAN_WAKE	PMAC_FTR_DEF(22)
295
296
297/* Don't use those directly, they are for the sake of pmac_setup.c */
298extern long pmac_do_feature_call(unsigned int selector, ...);
299extern void pmac_feature_init(void);
300
301/* Video suspend tweak */
302extern void pmac_set_early_video_resume(void (*proc)(void *data), void *data);
303extern void pmac_call_early_video_resume(void);
304
305#define PMAC_FTR_DEF(x) ((0x6660000) | (x))
306
307/* The AGP driver registers itself here */
308extern void pmac_register_agp_pm(struct pci_dev *bridge,
309				 int (*suspend)(struct pci_dev *bridge),
310				 int (*resume)(struct pci_dev *bridge));
311
312/* Those are meant to be used by video drivers to deal with AGP
313 * suspend resume properly
314 */
315extern void pmac_suspend_agp_for_card(struct pci_dev *dev);
316extern void pmac_resume_agp_for_card(struct pci_dev *dev);
317
318/*
319 * The part below is for use by macio_asic.c only, do not rely
320 * on the data structures or constants below in a normal driver
321 *
322 */
323
324#define MAX_MACIO_CHIPS		2
325
326enum {
327	macio_unknown = 0,
328	macio_grand_central,
329	macio_ohare,
330	macio_ohareII,
331	macio_heathrow,
332	macio_gatwick,
333	macio_paddington,
334	macio_keylargo,
335	macio_pangea,
336	macio_intrepid,
337	macio_keylargo2,
338	macio_shasta,
339};
340
341struct macio_chip
342{
343	struct device_node	*of_node;
344	int			type;
345	const char		*name;
346	int			rev;
347	volatile u32		__iomem *base;
348	unsigned long		flags;
349
350	/* For use by macio_asic PCI driver */
351	struct macio_bus	lbus;
352};
353
354extern struct macio_chip macio_chips[MAX_MACIO_CHIPS];
355
356#define MACIO_FLAG_SCCA_ON	0x00000001
357#define MACIO_FLAG_SCCB_ON	0x00000002
358#define MACIO_FLAG_SCC_LOCKED	0x00000004
359#define MACIO_FLAG_AIRPORT_ON	0x00000010
360#define MACIO_FLAG_FW_SUPPORTED	0x00000020
361
362extern struct macio_chip* macio_find(struct device_node* child, int type);
363
364#define MACIO_FCR32(macio, r)	((macio)->base + ((r) >> 2))
365#define MACIO_FCR8(macio, r)	(((volatile u8 __iomem *)((macio)->base)) + (r))
366
367#define MACIO_IN32(r)		(in_le32(MACIO_FCR32(macio,r)))
368#define MACIO_OUT32(r,v)	(out_le32(MACIO_FCR32(macio,r), (v)))
369#define MACIO_BIS(r,v)		(MACIO_OUT32((r), MACIO_IN32(r) | (v)))
370#define MACIO_BIC(r,v)		(MACIO_OUT32((r), MACIO_IN32(r) & ~(v)))
371#define MACIO_IN8(r)		(in_8(MACIO_FCR8(macio,r)))
372#define MACIO_OUT8(r,v)		(out_8(MACIO_FCR8(macio,r), (v)))
373
374/*
375 * Those are exported by pmac feature for internal use by arch code
376 * only like the platform function callbacks, do not use directly in drivers
377 */
378extern spinlock_t feature_lock;
379extern struct device_node *uninorth_node;
380extern u32 __iomem *uninorth_base;
381
382/*
383 * Uninorth reg. access. Note that Uni-N regs are big endian
384 */
385
386#define UN_REG(r)	(uninorth_base + ((r) >> 2))
387#define UN_IN(r)	(in_be32(UN_REG(r)))
388#define UN_OUT(r,v)	(out_be32(UN_REG(r), (v)))
389#define UN_BIS(r,v)	(UN_OUT((r), UN_IN(r) | (v)))
390#define UN_BIC(r,v)	(UN_OUT((r), UN_IN(r) & ~(v)))
391
392
393#endif /* __ASM_POWERPC_PMAC_FEATURE_H */
394#endif /* __KERNEL__ */
395