xref: /linux/drivers/soc/fsl/qe/qe.c (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2006-2010 Freescale Semiconductor, Inc. All rights reserved.
4  *
5  * Authors: 	Shlomi Gridish <gridish@freescale.com>
6  * 		Li Yang <leoli@freescale.com>
7  * Based on cpm2_common.c from Dan Malek (dmalek@jlc.net)
8  *
9  * Description:
10  * General Purpose functions for the global management of the
11  * QUICC Engine (QE).
12  */
13 #include <linux/bitmap.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/param.h>
18 #include <linux/string.h>
19 #include <linux/spinlock.h>
20 #include <linux/mm.h>
21 #include <linux/interrupt.h>
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/ioport.h>
25 #include <linux/iopoll.h>
26 #include <linux/crc32.h>
27 #include <linux/mod_devicetable.h>
28 #include <linux/of.h>
29 #include <linux/platform_device.h>
30 #include <soc/fsl/qe/immap_qe.h>
31 #include <soc/fsl/qe/qe.h>
32 
33 static void qe_snums_init(void);
34 static int qe_sdma_init(void);
35 
36 static DEFINE_SPINLOCK(qe_lock);
37 DEFINE_SPINLOCK(cmxgcr_lock);
38 EXPORT_SYMBOL(cmxgcr_lock);
39 
40 /* We allocate this here because it is used almost exclusively for
41  * the communication processor devices.
42  */
43 struct qe_immap __iomem *qe_immr;
44 EXPORT_SYMBOL(qe_immr);
45 
46 static u8 snums[QE_NUM_OF_SNUM];	/* Dynamically allocated SNUMs */
47 static DECLARE_BITMAP(snum_state, QE_NUM_OF_SNUM);
48 static unsigned int qe_num_of_snum;
49 
50 static phys_addr_t qebase = -1;
51 
52 static struct device_node *qe_get_device_node(void)
53 {
54 	struct device_node *qe;
55 
56 	/*
57 	 * Newer device trees have an "fsl,qe" compatible property for the QE
58 	 * node, but we still need to support older device trees.
59 	 */
60 	qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
61 	if (qe)
62 		return qe;
63 	return of_find_node_by_type(NULL, "qe");
64 }
65 
66 static phys_addr_t get_qe_base(void)
67 {
68 	struct device_node *qe;
69 	int ret;
70 	struct resource res;
71 
72 	if (qebase != -1)
73 		return qebase;
74 
75 	qe = qe_get_device_node();
76 	if (!qe)
77 		return qebase;
78 
79 	ret = of_address_to_resource(qe, 0, &res);
80 	if (!ret)
81 		qebase = res.start;
82 	of_node_put(qe);
83 
84 	return qebase;
85 }
86 
87 void qe_reset(void)
88 {
89 	if (qe_immr == NULL)
90 		qe_immr = ioremap(get_qe_base(), QE_IMMAP_SIZE);
91 
92 	if (!qe_immr)
93 		panic("QE:ioremap failed!");
94 
95 	qe_snums_init();
96 
97 	qe_issue_cmd(QE_RESET, QE_CR_SUBBLOCK_INVALID,
98 		     QE_CR_PROTOCOL_UNSPECIFIED, 0);
99 
100 	/* Reclaim the MURAM memory for our use. */
101 	qe_muram_init();
102 
103 	if (qe_sdma_init())
104 		panic("sdma init failed!");
105 }
106 
107 int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input)
108 {
109 	unsigned long flags;
110 	u8 mcn_shift = 0, dev_shift = 0;
111 	u32 val;
112 	int ret;
113 
114 	spin_lock_irqsave(&qe_lock, flags);
115 	if (cmd == QE_RESET) {
116 		iowrite32be((u32)(cmd | QE_CR_FLG), &qe_immr->cp.cecr);
117 	} else {
118 		if (cmd == QE_ASSIGN_PAGE) {
119 			/* Here device is the SNUM, not sub-block */
120 			dev_shift = QE_CR_SNUM_SHIFT;
121 		} else if (cmd == QE_ASSIGN_RISC) {
122 			/* Here device is the SNUM, and mcnProtocol is
123 			 * e_QeCmdRiscAssignment value */
124 			dev_shift = QE_CR_SNUM_SHIFT;
125 			mcn_shift = QE_CR_MCN_RISC_ASSIGN_SHIFT;
126 		} else {
127 			if (device == QE_CR_SUBBLOCK_USB)
128 				mcn_shift = QE_CR_MCN_USB_SHIFT;
129 			else
130 				mcn_shift = QE_CR_MCN_NORMAL_SHIFT;
131 		}
132 
133 		iowrite32be(cmd_input, &qe_immr->cp.cecdr);
134 		iowrite32be((cmd | QE_CR_FLG | ((u32)device << dev_shift) | (u32)mcn_protocol << mcn_shift),
135 			       &qe_immr->cp.cecr);
136 	}
137 
138 	/* wait for the QE_CR_FLG to clear */
139 	ret = readx_poll_timeout_atomic(ioread32be, &qe_immr->cp.cecr, val,
140 					(val & QE_CR_FLG) == 0, 0, 100);
141 	/* On timeout, ret is -ETIMEDOUT, otherwise it will be 0. */
142 	spin_unlock_irqrestore(&qe_lock, flags);
143 
144 	return ret == 0;
145 }
146 EXPORT_SYMBOL(qe_issue_cmd);
147 
148 /* Set a baud rate generator. This needs lots of work. There are
149  * 16 BRGs, which can be connected to the QE channels or output
150  * as clocks. The BRGs are in two different block of internal
151  * memory mapped space.
152  * The BRG clock is the QE clock divided by 2.
153  * It was set up long ago during the initial boot phase and is
154  * given to us.
155  * Baud rate clocks are zero-based in the driver code (as that maps
156  * to port numbers). Documentation uses 1-based numbering.
157  */
158 static unsigned int brg_clk = 0;
159 
160 #define CLK_GRAN	(1000)
161 #define CLK_GRAN_LIMIT	(5)
162 
163 unsigned int qe_get_brg_clk(void)
164 {
165 	struct device_node *qe;
166 	u32 brg;
167 	unsigned int mod;
168 
169 	if (brg_clk)
170 		return brg_clk;
171 
172 	qe = qe_get_device_node();
173 	if (!qe)
174 		return brg_clk;
175 
176 	if (!of_property_read_u32(qe, "brg-frequency", &brg))
177 		brg_clk = brg;
178 
179 	of_node_put(qe);
180 
181 	/* round this if near to a multiple of CLK_GRAN */
182 	mod = brg_clk % CLK_GRAN;
183 	if (mod) {
184 		if (mod < CLK_GRAN_LIMIT)
185 			brg_clk -= mod;
186 		else if (mod > (CLK_GRAN - CLK_GRAN_LIMIT))
187 			brg_clk += CLK_GRAN - mod;
188 	}
189 
190 	return brg_clk;
191 }
192 EXPORT_SYMBOL(qe_get_brg_clk);
193 
194 #define PVR_VER_836x	0x8083
195 #define PVR_VER_832x	0x8084
196 
197 static bool qe_general4_errata(void)
198 {
199 #ifdef CONFIG_PPC32
200 	return pvr_version_is(PVR_VER_836x) || pvr_version_is(PVR_VER_832x);
201 #endif
202 	return false;
203 }
204 
205 /* Program the BRG to the given sampling rate and multiplier
206  *
207  * @brg: the BRG, QE_BRG1 - QE_BRG16
208  * @rate: the desired sampling rate
209  * @multiplier: corresponds to the value programmed in GUMR_L[RDCR] or
210  * GUMR_L[TDCR].  E.g., if this BRG is the RX clock, and GUMR_L[RDCR]=01,
211  * then 'multiplier' should be 8.
212  */
213 int qe_setbrg(enum qe_clock brg, unsigned int rate, unsigned int multiplier)
214 {
215 	u32 divisor, tempval;
216 	u32 div16 = 0;
217 
218 	if ((brg < QE_BRG1) || (brg > QE_BRG16))
219 		return -EINVAL;
220 
221 	divisor = qe_get_brg_clk() / (rate * multiplier);
222 
223 	if (divisor > QE_BRGC_DIVISOR_MAX + 1) {
224 		div16 = QE_BRGC_DIV16;
225 		divisor /= 16;
226 	}
227 
228 	/* Errata QE_General4, which affects some MPC832x and MPC836x SOCs, says
229 	   that the BRG divisor must be even if you're not using divide-by-16
230 	   mode. */
231 	if (qe_general4_errata())
232 		if (!div16 && (divisor & 1) && (divisor > 3))
233 			divisor++;
234 
235 	tempval = ((divisor - 1) << QE_BRGC_DIVISOR_SHIFT) |
236 		QE_BRGC_ENABLE | div16;
237 
238 	iowrite32be(tempval, &qe_immr->brg.brgc[brg - QE_BRG1]);
239 
240 	return 0;
241 }
242 EXPORT_SYMBOL(qe_setbrg);
243 
244 /* Convert a string to a QE clock source enum
245  *
246  * This function takes a string, typically from a property in the device
247  * tree, and returns the corresponding "enum qe_clock" value.
248 */
249 enum qe_clock qe_clock_source(const char *source)
250 {
251 	unsigned int i;
252 
253 	if (strcasecmp(source, "none") == 0)
254 		return QE_CLK_NONE;
255 
256 	if (strcmp(source, "tsync_pin") == 0)
257 		return QE_TSYNC_PIN;
258 
259 	if (strcmp(source, "rsync_pin") == 0)
260 		return QE_RSYNC_PIN;
261 
262 	if (strncasecmp(source, "brg", 3) == 0) {
263 		i = simple_strtoul(source + 3, NULL, 10);
264 		if ((i >= 1) && (i <= 16))
265 			return (QE_BRG1 - 1) + i;
266 		else
267 			return QE_CLK_DUMMY;
268 	}
269 
270 	if (strncasecmp(source, "clk", 3) == 0) {
271 		i = simple_strtoul(source + 3, NULL, 10);
272 		if ((i >= 1) && (i <= 24))
273 			return (QE_CLK1 - 1) + i;
274 		else
275 			return QE_CLK_DUMMY;
276 	}
277 
278 	return QE_CLK_DUMMY;
279 }
280 EXPORT_SYMBOL(qe_clock_source);
281 
282 /* Initialize SNUMs (thread serial numbers) according to
283  * QE Module Control chapter, SNUM table
284  */
285 static void qe_snums_init(void)
286 {
287 	static const u8 snum_init_76[] = {
288 		0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
289 		0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
290 		0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
291 		0xD8, 0xD9, 0xE8, 0xE9, 0x44, 0x45, 0x4C, 0x4D,
292 		0x54, 0x55, 0x5C, 0x5D, 0x64, 0x65, 0x6C, 0x6D,
293 		0x74, 0x75, 0x7C, 0x7D, 0x84, 0x85, 0x8C, 0x8D,
294 		0x94, 0x95, 0x9C, 0x9D, 0xA4, 0xA5, 0xAC, 0xAD,
295 		0xB4, 0xB5, 0xBC, 0xBD, 0xC4, 0xC5, 0xCC, 0xCD,
296 		0xD4, 0xD5, 0xDC, 0xDD, 0xE4, 0xE5, 0xEC, 0xED,
297 		0xF4, 0xF5, 0xFC, 0xFD,
298 	};
299 	static const u8 snum_init_46[] = {
300 		0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
301 		0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
302 		0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
303 		0xD8, 0xD9, 0xE8, 0xE9, 0x08, 0x09, 0x18, 0x19,
304 		0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
305 		0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
306 	};
307 	struct device_node *qe;
308 	const u8 *snum_init;
309 	int i;
310 
311 	bitmap_zero(snum_state, QE_NUM_OF_SNUM);
312 	qe_num_of_snum = 28; /* The default number of snum for threads is 28 */
313 	qe = qe_get_device_node();
314 	if (qe) {
315 		i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
316 						       snums, 1, QE_NUM_OF_SNUM);
317 		if (i > 0) {
318 			of_node_put(qe);
319 			qe_num_of_snum = i;
320 			return;
321 		}
322 		/*
323 		 * Fall back to legacy binding of using the value of
324 		 * fsl,qe-num-snums to choose one of the static arrays
325 		 * above.
326 		 */
327 		of_property_read_u32(qe, "fsl,qe-num-snums", &qe_num_of_snum);
328 		of_node_put(qe);
329 	}
330 
331 	if (qe_num_of_snum == 76) {
332 		snum_init = snum_init_76;
333 	} else if (qe_num_of_snum == 28 || qe_num_of_snum == 46) {
334 		snum_init = snum_init_46;
335 	} else {
336 		pr_err("QE: unsupported value of fsl,qe-num-snums: %u\n", qe_num_of_snum);
337 		return;
338 	}
339 	memcpy(snums, snum_init, qe_num_of_snum);
340 }
341 
342 int qe_get_snum(void)
343 {
344 	unsigned long flags;
345 	int snum = -EBUSY;
346 	int i;
347 
348 	spin_lock_irqsave(&qe_lock, flags);
349 	i = find_first_zero_bit(snum_state, qe_num_of_snum);
350 	if (i < qe_num_of_snum) {
351 		set_bit(i, snum_state);
352 		snum = snums[i];
353 	}
354 	spin_unlock_irqrestore(&qe_lock, flags);
355 
356 	return snum;
357 }
358 EXPORT_SYMBOL(qe_get_snum);
359 
360 void qe_put_snum(u8 snum)
361 {
362 	const u8 *p = memchr(snums, snum, qe_num_of_snum);
363 
364 	if (p)
365 		clear_bit(p - snums, snum_state);
366 }
367 EXPORT_SYMBOL(qe_put_snum);
368 
369 static int qe_sdma_init(void)
370 {
371 	struct sdma __iomem *sdma = &qe_immr->sdma;
372 	static s32 sdma_buf_offset = -ENOMEM;
373 
374 	/* allocate 2 internal temporary buffers (512 bytes size each) for
375 	 * the SDMA */
376 	if (sdma_buf_offset < 0) {
377 		sdma_buf_offset = qe_muram_alloc(512 * 2, 4096);
378 		if (sdma_buf_offset < 0)
379 			return -ENOMEM;
380 	}
381 
382 	iowrite32be((u32)sdma_buf_offset & QE_SDEBCR_BA_MASK,
383 		       &sdma->sdebcr);
384 	iowrite32be((QE_SDMR_GLB_1_MSK | (0x1 << QE_SDMR_CEN_SHIFT)),
385 		       &sdma->sdmr);
386 
387 	return 0;
388 }
389 
390 /* The maximum number of RISCs we support */
391 #define MAX_QE_RISC     4
392 
393 /* Firmware information stored here for qe_get_firmware_info() */
394 static struct qe_firmware_info qe_firmware_info;
395 
396 /*
397  * Set to 1 if QE firmware has been uploaded, and therefore
398  * qe_firmware_info contains valid data.
399  */
400 static int qe_firmware_uploaded;
401 
402 /*
403  * Upload a QE microcode
404  *
405  * This function is a worker function for qe_upload_firmware().  It does
406  * the actual uploading of the microcode.
407  */
408 static void qe_upload_microcode(const void *base,
409 	const struct qe_microcode *ucode)
410 {
411 	const __be32 *code = base + be32_to_cpu(ucode->code_offset);
412 	unsigned int i;
413 
414 	if (ucode->major || ucode->minor || ucode->revision)
415 		printk(KERN_INFO "qe-firmware: "
416 			"uploading microcode '%s' version %u.%u.%u\n",
417 			ucode->id, ucode->major, ucode->minor, ucode->revision);
418 	else
419 		printk(KERN_INFO "qe-firmware: "
420 			"uploading microcode '%s'\n", ucode->id);
421 
422 	/* Use auto-increment */
423 	iowrite32be(be32_to_cpu(ucode->iram_offset) | QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR,
424 		       &qe_immr->iram.iadd);
425 
426 	for (i = 0; i < be32_to_cpu(ucode->count); i++)
427 		iowrite32be(be32_to_cpu(code[i]), &qe_immr->iram.idata);
428 
429 	/* Set I-RAM Ready Register */
430 	iowrite32be(QE_IRAM_READY, &qe_immr->iram.iready);
431 }
432 
433 /*
434  * Upload a microcode to the I-RAM at a specific address.
435  *
436  * See Documentation/arch/powerpc/qe_firmware.rst for information on QE microcode
437  * uploading.
438  *
439  * Currently, only version 1 is supported, so the 'version' field must be
440  * set to 1.
441  *
442  * The SOC model and revision are not validated, they are only displayed for
443  * informational purposes.
444  *
445  * 'calc_size' is the calculated size, in bytes, of the firmware structure and
446  * all of the microcode structures, minus the CRC.
447  *
448  * 'length' is the size that the structure says it is, including the CRC.
449  */
450 int qe_upload_firmware(const struct qe_firmware *firmware)
451 {
452 	unsigned int i;
453 	unsigned int j;
454 	u32 crc;
455 	size_t calc_size;
456 	size_t length;
457 	const struct qe_header *hdr;
458 
459 	if (!firmware) {
460 		printk(KERN_ERR "qe-firmware: invalid pointer\n");
461 		return -EINVAL;
462 	}
463 
464 	hdr = &firmware->header;
465 	length = be32_to_cpu(hdr->length);
466 
467 	/* Check the magic */
468 	if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
469 	    (hdr->magic[2] != 'F')) {
470 		printk(KERN_ERR "qe-firmware: not a microcode\n");
471 		return -EPERM;
472 	}
473 
474 	/* Check the version */
475 	if (hdr->version != 1) {
476 		printk(KERN_ERR "qe-firmware: unsupported version\n");
477 		return -EPERM;
478 	}
479 
480 	/* Validate some of the fields */
481 	if ((firmware->count < 1) || (firmware->count > MAX_QE_RISC)) {
482 		printk(KERN_ERR "qe-firmware: invalid data\n");
483 		return -EINVAL;
484 	}
485 
486 	/* Validate the length and check if there's a CRC */
487 	calc_size = struct_size(firmware, microcode, firmware->count);
488 
489 	for (i = 0; i < firmware->count; i++)
490 		/*
491 		 * For situations where the second RISC uses the same microcode
492 		 * as the first, the 'code_offset' and 'count' fields will be
493 		 * zero, so it's okay to add those.
494 		 */
495 		calc_size += sizeof(__be32) *
496 			be32_to_cpu(firmware->microcode[i].count);
497 
498 	/* Validate the length */
499 	if (length != calc_size + sizeof(__be32)) {
500 		printk(KERN_ERR "qe-firmware: invalid length\n");
501 		return -EPERM;
502 	}
503 
504 	/* Validate the CRC */
505 	crc = be32_to_cpu(*(__be32 *)((void *)firmware + calc_size));
506 	if (crc != crc32(0, firmware, calc_size)) {
507 		printk(KERN_ERR "qe-firmware: firmware CRC is invalid\n");
508 		return -EIO;
509 	}
510 
511 	/*
512 	 * If the microcode calls for it, split the I-RAM.
513 	 */
514 	if (!firmware->split)
515 		qe_setbits_be16(&qe_immr->cp.cercr, QE_CP_CERCR_CIR);
516 
517 	if (firmware->soc.model)
518 		printk(KERN_INFO
519 			"qe-firmware: firmware '%s' for %u V%u.%u\n",
520 			firmware->id, be16_to_cpu(firmware->soc.model),
521 			firmware->soc.major, firmware->soc.minor);
522 	else
523 		printk(KERN_INFO "qe-firmware: firmware '%s'\n",
524 			firmware->id);
525 
526 	/*
527 	 * The QE only supports one microcode per RISC, so clear out all the
528 	 * saved microcode information and put in the new.
529 	 */
530 	memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
531 	strscpy(qe_firmware_info.id, firmware->id, sizeof(qe_firmware_info.id));
532 	qe_firmware_info.extended_modes = be64_to_cpu(firmware->extended_modes);
533 	memcpy(qe_firmware_info.vtraps, firmware->vtraps,
534 		sizeof(firmware->vtraps));
535 
536 	/* Loop through each microcode. */
537 	for (i = 0; i < firmware->count; i++) {
538 		const struct qe_microcode *ucode = &firmware->microcode[i];
539 
540 		/* Upload a microcode if it's present */
541 		if (ucode->code_offset)
542 			qe_upload_microcode(firmware, ucode);
543 
544 		/* Program the traps for this processor */
545 		for (j = 0; j < 16; j++) {
546 			u32 trap = be32_to_cpu(ucode->traps[j]);
547 
548 			if (trap)
549 				iowrite32be(trap,
550 					       &qe_immr->rsp[i].tibcr[j]);
551 		}
552 
553 		/* Enable traps */
554 		iowrite32be(be32_to_cpu(ucode->eccr),
555 			       &qe_immr->rsp[i].eccr);
556 	}
557 
558 	qe_firmware_uploaded = 1;
559 
560 	return 0;
561 }
562 EXPORT_SYMBOL(qe_upload_firmware);
563 
564 /*
565  * Get info on the currently-loaded firmware
566  *
567  * This function also checks the device tree to see if the boot loader has
568  * uploaded a firmware already.
569  */
570 struct qe_firmware_info *qe_get_firmware_info(void)
571 {
572 	static int initialized;
573 	struct device_node *qe;
574 	struct device_node *fw = NULL;
575 	const char *sprop;
576 
577 	/*
578 	 * If we haven't checked yet, and a driver hasn't uploaded a firmware
579 	 * yet, then check the device tree for information.
580 	 */
581 	if (qe_firmware_uploaded)
582 		return &qe_firmware_info;
583 
584 	if (initialized)
585 		return NULL;
586 
587 	initialized = 1;
588 
589 	qe = qe_get_device_node();
590 	if (!qe)
591 		return NULL;
592 
593 	/* Find the 'firmware' child node */
594 	fw = of_get_child_by_name(qe, "firmware");
595 	of_node_put(qe);
596 
597 	/* Did we find the 'firmware' node? */
598 	if (!fw)
599 		return NULL;
600 
601 	qe_firmware_uploaded = 1;
602 
603 	/* Copy the data into qe_firmware_info*/
604 	sprop = of_get_property(fw, "id", NULL);
605 	if (sprop)
606 		strscpy(qe_firmware_info.id, sprop,
607 			sizeof(qe_firmware_info.id));
608 
609 	of_property_read_u64(fw, "extended-modes",
610 			     &qe_firmware_info.extended_modes);
611 
612 	of_property_read_u32_array(fw, "virtual-traps", qe_firmware_info.vtraps,
613 				   ARRAY_SIZE(qe_firmware_info.vtraps));
614 
615 	of_node_put(fw);
616 
617 	return &qe_firmware_info;
618 }
619 EXPORT_SYMBOL(qe_get_firmware_info);
620 
621 unsigned int qe_get_num_of_risc(void)
622 {
623 	struct device_node *qe;
624 	unsigned int num_of_risc = 0;
625 
626 	qe = qe_get_device_node();
627 	if (!qe)
628 		return num_of_risc;
629 
630 	of_property_read_u32(qe, "fsl,qe-num-riscs", &num_of_risc);
631 
632 	of_node_put(qe);
633 
634 	return num_of_risc;
635 }
636 EXPORT_SYMBOL(qe_get_num_of_risc);
637 
638 unsigned int qe_get_num_of_snums(void)
639 {
640 	return qe_num_of_snum;
641 }
642 EXPORT_SYMBOL(qe_get_num_of_snums);
643 
644 static int __init qe_init(void)
645 {
646 	struct device_node *np;
647 
648 	np = of_find_compatible_node(NULL, NULL, "fsl,qe");
649 	if (!np)
650 		return -ENODEV;
651 	qe_reset();
652 	of_node_put(np);
653 	return 0;
654 }
655 subsys_initcall(qe_init);
656 
657 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC_85xx)
658 static int qe_resume(struct platform_device *ofdev)
659 {
660 	if (!qe_alive_during_sleep())
661 		qe_reset();
662 	return 0;
663 }
664 
665 static int qe_probe(struct platform_device *ofdev)
666 {
667 	return 0;
668 }
669 
670 static const struct of_device_id qe_ids[] = {
671 	{ .compatible = "fsl,qe", },
672 	{ },
673 };
674 
675 static struct platform_driver qe_driver = {
676 	.driver = {
677 		.name = "fsl-qe",
678 		.of_match_table = qe_ids,
679 	},
680 	.probe = qe_probe,
681 	.resume = qe_resume,
682 };
683 
684 builtin_platform_driver(qe_driver);
685 #endif /* defined(CONFIG_SUSPEND) && defined(CONFIG_PPC_85xx) */
686