qe.c 17 KB

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