qe.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved.
  3. *
  4. * Authors: Shlomi Gridish <gridish@freescale.com>
  5. * Li Yang <leoli@freescale.com>
  6. * Based on cpm2_common.c from Dan Malek (dmalek@jlc.net)
  7. *
  8. * Description:
  9. * General Purpose functions for the global management of the
  10. * QUICC Engine (QE).
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/param.h>
  21. #include <linux/string.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/mm.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/module.h>
  27. #include <linux/delay.h>
  28. #include <linux/ioport.h>
  29. #include <linux/crc32.h>
  30. #include <linux/mod_devicetable.h>
  31. #include <linux/of_platform.h>
  32. #include <asm/irq.h>
  33. #include <asm/page.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/immap_qe.h>
  36. #include <asm/qe.h>
  37. #include <asm/prom.h>
  38. #include <asm/rheap.h>
  39. static void qe_snums_init(void);
  40. static int qe_sdma_init(void);
  41. static DEFINE_SPINLOCK(qe_lock);
  42. DEFINE_SPINLOCK(cmxgcr_lock);
  43. EXPORT_SYMBOL(cmxgcr_lock);
  44. /* QE snum state */
  45. enum qe_snum_state {
  46. QE_SNUM_STATE_USED,
  47. QE_SNUM_STATE_FREE
  48. };
  49. /* QE snum */
  50. struct qe_snum {
  51. u8 num;
  52. enum qe_snum_state state;
  53. };
  54. /* We allocate this here because it is used almost exclusively for
  55. * the communication processor devices.
  56. */
  57. struct qe_immap __iomem *qe_immr;
  58. EXPORT_SYMBOL(qe_immr);
  59. static struct qe_snum snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */
  60. static unsigned int qe_num_of_snum;
  61. static phys_addr_t qebase = -1;
  62. phys_addr_t get_qe_base(void)
  63. {
  64. struct device_node *qe;
  65. int size;
  66. const u32 *prop;
  67. if (qebase != -1)
  68. return qebase;
  69. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  70. if (!qe) {
  71. qe = of_find_node_by_type(NULL, "qe");
  72. if (!qe)
  73. return qebase;
  74. }
  75. prop = of_get_property(qe, "reg", &size);
  76. if (prop && size >= sizeof(*prop))
  77. qebase = of_translate_address(qe, prop);
  78. of_node_put(qe);
  79. return qebase;
  80. }
  81. EXPORT_SYMBOL(get_qe_base);
  82. void qe_reset(void)
  83. {
  84. if (qe_immr == NULL)
  85. qe_immr = ioremap(get_qe_base(), QE_IMMAP_SIZE);
  86. qe_snums_init();
  87. qe_issue_cmd(QE_RESET, QE_CR_SUBBLOCK_INVALID,
  88. QE_CR_PROTOCOL_UNSPECIFIED, 0);
  89. /* Reclaim the MURAM memory for our use. */
  90. qe_muram_init();
  91. if (qe_sdma_init())
  92. panic("sdma init failed!");
  93. }
  94. int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input)
  95. {
  96. unsigned long flags;
  97. u8 mcn_shift = 0, dev_shift = 0;
  98. u32 ret;
  99. spin_lock_irqsave(&qe_lock, flags);
  100. if (cmd == QE_RESET) {
  101. out_be32(&qe_immr->cp.cecr, (u32) (cmd | QE_CR_FLG));
  102. } else {
  103. if (cmd == QE_ASSIGN_PAGE) {
  104. /* Here device is the SNUM, not sub-block */
  105. dev_shift = QE_CR_SNUM_SHIFT;
  106. } else if (cmd == QE_ASSIGN_RISC) {
  107. /* Here device is the SNUM, and mcnProtocol is
  108. * e_QeCmdRiscAssignment value */
  109. dev_shift = QE_CR_SNUM_SHIFT;
  110. mcn_shift = QE_CR_MCN_RISC_ASSIGN_SHIFT;
  111. } else {
  112. if (device == QE_CR_SUBBLOCK_USB)
  113. mcn_shift = QE_CR_MCN_USB_SHIFT;
  114. else
  115. mcn_shift = QE_CR_MCN_NORMAL_SHIFT;
  116. }
  117. out_be32(&qe_immr->cp.cecdr, cmd_input);
  118. out_be32(&qe_immr->cp.cecr,
  119. (cmd | QE_CR_FLG | ((u32) device << dev_shift) | (u32)
  120. mcn_protocol << mcn_shift));
  121. }
  122. /* wait for the QE_CR_FLG to clear */
  123. ret = spin_event_timeout((in_be32(&qe_immr->cp.cecr) & QE_CR_FLG) == 0,
  124. 100, 0);
  125. /* On timeout (e.g. failure), the expression will be false (ret == 0),
  126. otherwise it will be true (ret == 1). */
  127. spin_unlock_irqrestore(&qe_lock, flags);
  128. return ret == 1;
  129. }
  130. EXPORT_SYMBOL(qe_issue_cmd);
  131. /* Set a baud rate generator. This needs lots of work. There are
  132. * 16 BRGs, which can be connected to the QE channels or output
  133. * as clocks. The BRGs are in two different block of internal
  134. * memory mapped space.
  135. * The BRG clock is the QE clock divided by 2.
  136. * It was set up long ago during the initial boot phase and is
  137. * is given to us.
  138. * Baud rate clocks are zero-based in the driver code (as that maps
  139. * to port numbers). Documentation uses 1-based numbering.
  140. */
  141. static unsigned int brg_clk = 0;
  142. unsigned int qe_get_brg_clk(void)
  143. {
  144. struct device_node *qe;
  145. int size;
  146. const u32 *prop;
  147. if (brg_clk)
  148. return brg_clk;
  149. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  150. if (!qe) {
  151. qe = of_find_node_by_type(NULL, "qe");
  152. if (!qe)
  153. return brg_clk;
  154. }
  155. prop = of_get_property(qe, "brg-frequency", &size);
  156. if (prop && size == sizeof(*prop))
  157. brg_clk = *prop;
  158. of_node_put(qe);
  159. return brg_clk;
  160. }
  161. EXPORT_SYMBOL(qe_get_brg_clk);
  162. /* Program the BRG to the given sampling rate and multiplier
  163. *
  164. * @brg: the BRG, QE_BRG1 - QE_BRG16
  165. * @rate: the desired sampling rate
  166. * @multiplier: corresponds to the value programmed in GUMR_L[RDCR] or
  167. * GUMR_L[TDCR]. E.g., if this BRG is the RX clock, and GUMR_L[RDCR]=01,
  168. * then 'multiplier' should be 8.
  169. */
  170. int qe_setbrg(enum qe_clock brg, unsigned int rate, unsigned int multiplier)
  171. {
  172. u32 divisor, tempval;
  173. u32 div16 = 0;
  174. if ((brg < QE_BRG1) || (brg > QE_BRG16))
  175. return -EINVAL;
  176. divisor = qe_get_brg_clk() / (rate * multiplier);
  177. if (divisor > QE_BRGC_DIVISOR_MAX + 1) {
  178. div16 = QE_BRGC_DIV16;
  179. divisor /= 16;
  180. }
  181. /* Errata QE_General4, which affects some MPC832x and MPC836x SOCs, says
  182. that the BRG divisor must be even if you're not using divide-by-16
  183. mode. */
  184. if (!div16 && (divisor & 1))
  185. divisor++;
  186. tempval = ((divisor - 1) << QE_BRGC_DIVISOR_SHIFT) |
  187. QE_BRGC_ENABLE | div16;
  188. out_be32(&qe_immr->brg.brgc[brg - QE_BRG1], tempval);
  189. return 0;
  190. }
  191. EXPORT_SYMBOL(qe_setbrg);
  192. /* Convert a string to a QE clock source enum
  193. *
  194. * This function takes a string, typically from a property in the device
  195. * tree, and returns the corresponding "enum qe_clock" value.
  196. */
  197. enum qe_clock qe_clock_source(const char *source)
  198. {
  199. unsigned int i;
  200. if (strcasecmp(source, "none") == 0)
  201. return QE_CLK_NONE;
  202. if (strncasecmp(source, "brg", 3) == 0) {
  203. i = simple_strtoul(source + 3, NULL, 10);
  204. if ((i >= 1) && (i <= 16))
  205. return (QE_BRG1 - 1) + i;
  206. else
  207. return QE_CLK_DUMMY;
  208. }
  209. if (strncasecmp(source, "clk", 3) == 0) {
  210. i = simple_strtoul(source + 3, NULL, 10);
  211. if ((i >= 1) && (i <= 24))
  212. return (QE_CLK1 - 1) + i;
  213. else
  214. return QE_CLK_DUMMY;
  215. }
  216. return QE_CLK_DUMMY;
  217. }
  218. EXPORT_SYMBOL(qe_clock_source);
  219. /* Initialize SNUMs (thread serial numbers) according to
  220. * QE Module Control chapter, SNUM table
  221. */
  222. static void qe_snums_init(void)
  223. {
  224. int i;
  225. static const u8 snum_init[] = {
  226. 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
  227. 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
  228. 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
  229. 0xD8, 0xD9, 0xE8, 0xE9, 0x08, 0x09, 0x18, 0x19,
  230. 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
  231. 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
  232. };
  233. qe_num_of_snum = qe_get_num_of_snums();
  234. for (i = 0; i < qe_num_of_snum; i++) {
  235. snums[i].num = snum_init[i];
  236. snums[i].state = QE_SNUM_STATE_FREE;
  237. }
  238. }
  239. int qe_get_snum(void)
  240. {
  241. unsigned long flags;
  242. int snum = -EBUSY;
  243. int i;
  244. spin_lock_irqsave(&qe_lock, flags);
  245. for (i = 0; i < qe_num_of_snum; i++) {
  246. if (snums[i].state == QE_SNUM_STATE_FREE) {
  247. snums[i].state = QE_SNUM_STATE_USED;
  248. snum = snums[i].num;
  249. break;
  250. }
  251. }
  252. spin_unlock_irqrestore(&qe_lock, flags);
  253. return snum;
  254. }
  255. EXPORT_SYMBOL(qe_get_snum);
  256. void qe_put_snum(u8 snum)
  257. {
  258. int i;
  259. for (i = 0; i < qe_num_of_snum; i++) {
  260. if (snums[i].num == snum) {
  261. snums[i].state = QE_SNUM_STATE_FREE;
  262. break;
  263. }
  264. }
  265. }
  266. EXPORT_SYMBOL(qe_put_snum);
  267. static int qe_sdma_init(void)
  268. {
  269. struct sdma __iomem *sdma = &qe_immr->sdma;
  270. static unsigned long sdma_buf_offset = (unsigned long)-ENOMEM;
  271. if (!sdma)
  272. return -ENODEV;
  273. /* allocate 2 internal temporary buffers (512 bytes size each) for
  274. * the SDMA */
  275. if (IS_ERR_VALUE(sdma_buf_offset)) {
  276. sdma_buf_offset = qe_muram_alloc(512 * 2, 4096);
  277. if (IS_ERR_VALUE(sdma_buf_offset))
  278. return -ENOMEM;
  279. }
  280. out_be32(&sdma->sdebcr, (u32) sdma_buf_offset & QE_SDEBCR_BA_MASK);
  281. out_be32(&sdma->sdmr, (QE_SDMR_GLB_1_MSK |
  282. (0x1 << QE_SDMR_CEN_SHIFT)));
  283. return 0;
  284. }
  285. /* The maximum number of RISCs we support */
  286. #define MAX_QE_RISC 4
  287. /* Firmware information stored here for qe_get_firmware_info() */
  288. static struct qe_firmware_info qe_firmware_info;
  289. /*
  290. * Set to 1 if QE firmware has been uploaded, and therefore
  291. * qe_firmware_info contains valid data.
  292. */
  293. static int qe_firmware_uploaded;
  294. /*
  295. * Upload a QE microcode
  296. *
  297. * This function is a worker function for qe_upload_firmware(). It does
  298. * the actual uploading of the microcode.
  299. */
  300. static void qe_upload_microcode(const void *base,
  301. const struct qe_microcode *ucode)
  302. {
  303. const __be32 *code = base + be32_to_cpu(ucode->code_offset);
  304. unsigned int i;
  305. if (ucode->major || ucode->minor || ucode->revision)
  306. printk(KERN_INFO "qe-firmware: "
  307. "uploading microcode '%s' version %u.%u.%u\n",
  308. ucode->id, ucode->major, ucode->minor, ucode->revision);
  309. else
  310. printk(KERN_INFO "qe-firmware: "
  311. "uploading microcode '%s'\n", ucode->id);
  312. /* Use auto-increment */
  313. out_be32(&qe_immr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
  314. QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
  315. for (i = 0; i < be32_to_cpu(ucode->count); i++)
  316. out_be32(&qe_immr->iram.idata, be32_to_cpu(code[i]));
  317. }
  318. /*
  319. * Upload a microcode to the I-RAM at a specific address.
  320. *
  321. * See Documentation/powerpc/qe-firmware.txt for information on QE microcode
  322. * uploading.
  323. *
  324. * Currently, only version 1 is supported, so the 'version' field must be
  325. * set to 1.
  326. *
  327. * The SOC model and revision are not validated, they are only displayed for
  328. * informational purposes.
  329. *
  330. * 'calc_size' is the calculated size, in bytes, of the firmware structure and
  331. * all of the microcode structures, minus the CRC.
  332. *
  333. * 'length' is the size that the structure says it is, including the CRC.
  334. */
  335. int qe_upload_firmware(const struct qe_firmware *firmware)
  336. {
  337. unsigned int i;
  338. unsigned int j;
  339. u32 crc;
  340. size_t calc_size = sizeof(struct qe_firmware);
  341. size_t length;
  342. const struct qe_header *hdr;
  343. if (!firmware) {
  344. printk(KERN_ERR "qe-firmware: invalid pointer\n");
  345. return -EINVAL;
  346. }
  347. hdr = &firmware->header;
  348. length = be32_to_cpu(hdr->length);
  349. /* Check the magic */
  350. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  351. (hdr->magic[2] != 'F')) {
  352. printk(KERN_ERR "qe-firmware: not a microcode\n");
  353. return -EPERM;
  354. }
  355. /* Check the version */
  356. if (hdr->version != 1) {
  357. printk(KERN_ERR "qe-firmware: unsupported version\n");
  358. return -EPERM;
  359. }
  360. /* Validate some of the fields */
  361. if ((firmware->count < 1) || (firmware->count > MAX_QE_RISC)) {
  362. printk(KERN_ERR "qe-firmware: invalid data\n");
  363. return -EINVAL;
  364. }
  365. /* Validate the length and check if there's a CRC */
  366. calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
  367. for (i = 0; i < firmware->count; i++)
  368. /*
  369. * For situations where the second RISC uses the same microcode
  370. * as the first, the 'code_offset' and 'count' fields will be
  371. * zero, so it's okay to add those.
  372. */
  373. calc_size += sizeof(__be32) *
  374. be32_to_cpu(firmware->microcode[i].count);
  375. /* Validate the length */
  376. if (length != calc_size + sizeof(__be32)) {
  377. printk(KERN_ERR "qe-firmware: invalid length\n");
  378. return -EPERM;
  379. }
  380. /* Validate the CRC */
  381. crc = be32_to_cpu(*(__be32 *)((void *)firmware + calc_size));
  382. if (crc != crc32(0, firmware, calc_size)) {
  383. printk(KERN_ERR "qe-firmware: firmware CRC is invalid\n");
  384. return -EIO;
  385. }
  386. /*
  387. * If the microcode calls for it, split the I-RAM.
  388. */
  389. if (!firmware->split)
  390. setbits16(&qe_immr->cp.cercr, QE_CP_CERCR_CIR);
  391. if (firmware->soc.model)
  392. printk(KERN_INFO
  393. "qe-firmware: firmware '%s' for %u V%u.%u\n",
  394. firmware->id, be16_to_cpu(firmware->soc.model),
  395. firmware->soc.major, firmware->soc.minor);
  396. else
  397. printk(KERN_INFO "qe-firmware: firmware '%s'\n",
  398. firmware->id);
  399. /*
  400. * The QE only supports one microcode per RISC, so clear out all the
  401. * saved microcode information and put in the new.
  402. */
  403. memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
  404. strcpy(qe_firmware_info.id, firmware->id);
  405. qe_firmware_info.extended_modes = firmware->extended_modes;
  406. memcpy(qe_firmware_info.vtraps, firmware->vtraps,
  407. sizeof(firmware->vtraps));
  408. /* Loop through each microcode. */
  409. for (i = 0; i < firmware->count; i++) {
  410. const struct qe_microcode *ucode = &firmware->microcode[i];
  411. /* Upload a microcode if it's present */
  412. if (ucode->code_offset)
  413. qe_upload_microcode(firmware, ucode);
  414. /* Program the traps for this processor */
  415. for (j = 0; j < 16; j++) {
  416. u32 trap = be32_to_cpu(ucode->traps[j]);
  417. if (trap)
  418. out_be32(&qe_immr->rsp[i].tibcr[j], trap);
  419. }
  420. /* Enable traps */
  421. out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
  422. }
  423. qe_firmware_uploaded = 1;
  424. return 0;
  425. }
  426. EXPORT_SYMBOL(qe_upload_firmware);
  427. /*
  428. * Get info on the currently-loaded firmware
  429. *
  430. * This function also checks the device tree to see if the boot loader has
  431. * uploaded a firmware already.
  432. */
  433. struct qe_firmware_info *qe_get_firmware_info(void)
  434. {
  435. static int initialized;
  436. struct property *prop;
  437. struct device_node *qe;
  438. struct device_node *fw = NULL;
  439. const char *sprop;
  440. unsigned int i;
  441. /*
  442. * If we haven't checked yet, and a driver hasn't uploaded a firmware
  443. * yet, then check the device tree for information.
  444. */
  445. if (qe_firmware_uploaded)
  446. return &qe_firmware_info;
  447. if (initialized)
  448. return NULL;
  449. initialized = 1;
  450. /*
  451. * Newer device trees have an "fsl,qe" compatible property for the QE
  452. * node, but we still need to support older device trees.
  453. */
  454. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  455. if (!qe) {
  456. qe = of_find_node_by_type(NULL, "qe");
  457. if (!qe)
  458. return NULL;
  459. }
  460. /* Find the 'firmware' child node */
  461. for_each_child_of_node(qe, fw) {
  462. if (strcmp(fw->name, "firmware") == 0)
  463. break;
  464. }
  465. of_node_put(qe);
  466. /* Did we find the 'firmware' node? */
  467. if (!fw)
  468. return NULL;
  469. qe_firmware_uploaded = 1;
  470. /* Copy the data into qe_firmware_info*/
  471. sprop = of_get_property(fw, "id", NULL);
  472. if (sprop)
  473. strncpy(qe_firmware_info.id, sprop,
  474. sizeof(qe_firmware_info.id) - 1);
  475. prop = of_find_property(fw, "extended-modes", NULL);
  476. if (prop && (prop->length == sizeof(u64))) {
  477. const u64 *iprop = prop->value;
  478. qe_firmware_info.extended_modes = *iprop;
  479. }
  480. prop = of_find_property(fw, "virtual-traps", NULL);
  481. if (prop && (prop->length == 32)) {
  482. const u32 *iprop = prop->value;
  483. for (i = 0; i < ARRAY_SIZE(qe_firmware_info.vtraps); i++)
  484. qe_firmware_info.vtraps[i] = iprop[i];
  485. }
  486. of_node_put(fw);
  487. return &qe_firmware_info;
  488. }
  489. EXPORT_SYMBOL(qe_get_firmware_info);
  490. unsigned int qe_get_num_of_risc(void)
  491. {
  492. struct device_node *qe;
  493. int size;
  494. unsigned int num_of_risc = 0;
  495. const u32 *prop;
  496. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  497. if (!qe) {
  498. /* Older devices trees did not have an "fsl,qe"
  499. * compatible property, so we need to look for
  500. * the QE node by name.
  501. */
  502. qe = of_find_node_by_type(NULL, "qe");
  503. if (!qe)
  504. return num_of_risc;
  505. }
  506. prop = of_get_property(qe, "fsl,qe-num-riscs", &size);
  507. if (prop && size == sizeof(*prop))
  508. num_of_risc = *prop;
  509. of_node_put(qe);
  510. return num_of_risc;
  511. }
  512. EXPORT_SYMBOL(qe_get_num_of_risc);
  513. unsigned int qe_get_num_of_snums(void)
  514. {
  515. struct device_node *qe;
  516. int size;
  517. unsigned int num_of_snums;
  518. const u32 *prop;
  519. num_of_snums = 28; /* The default number of snum for threads is 28 */
  520. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  521. if (!qe) {
  522. /* Older devices trees did not have an "fsl,qe"
  523. * compatible property, so we need to look for
  524. * the QE node by name.
  525. */
  526. qe = of_find_node_by_type(NULL, "qe");
  527. if (!qe)
  528. return num_of_snums;
  529. }
  530. prop = of_get_property(qe, "fsl,qe-num-snums", &size);
  531. if (prop && size == sizeof(*prop)) {
  532. num_of_snums = *prop;
  533. if ((num_of_snums < 28) || (num_of_snums > QE_NUM_OF_SNUM)) {
  534. /* No QE ever has fewer than 28 SNUMs */
  535. pr_err("QE: number of snum is invalid\n");
  536. return -EINVAL;
  537. }
  538. }
  539. of_node_put(qe);
  540. return num_of_snums;
  541. }
  542. EXPORT_SYMBOL(qe_get_num_of_snums);
  543. #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC_85xx)
  544. static int qe_resume(struct platform_device *ofdev)
  545. {
  546. if (!qe_alive_during_sleep())
  547. qe_reset();
  548. return 0;
  549. }
  550. static int qe_probe(struct platform_device *ofdev,
  551. const struct of_device_id *id)
  552. {
  553. return 0;
  554. }
  555. static const struct of_device_id qe_ids[] = {
  556. { .compatible = "fsl,qe", },
  557. { },
  558. };
  559. static struct of_platform_driver qe_driver = {
  560. .driver = {
  561. .name = "fsl-qe",
  562. .owner = THIS_MODULE,
  563. .of_match_table = qe_ids,
  564. },
  565. .probe = qe_probe,
  566. .resume = qe_resume,
  567. };
  568. static int __init qe_drv_init(void)
  569. {
  570. return of_register_platform_driver(&qe_driver);
  571. }
  572. device_initcall(qe_drv_init);
  573. #endif /* defined(CONFIG_SUSPEND) && defined(CONFIG_PPC_85xx) */