qe.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. * Copyright (C) 2006-2010 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) && (divisor > 3))
  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_76[] = {
  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, 0x44, 0x45, 0x4C, 0x4D,
  230. 0x54, 0x55, 0x5C, 0x5D, 0x64, 0x65, 0x6C, 0x6D,
  231. 0x74, 0x75, 0x7C, 0x7D, 0x84, 0x85, 0x8C, 0x8D,
  232. 0x94, 0x95, 0x9C, 0x9D, 0xA4, 0xA5, 0xAC, 0xAD,
  233. 0xB4, 0xB5, 0xBC, 0xBD, 0xC4, 0xC5, 0xCC, 0xCD,
  234. 0xD4, 0xD5, 0xDC, 0xDD, 0xE4, 0xE5, 0xEC, 0xED,
  235. 0xF4, 0xF5, 0xFC, 0xFD,
  236. };
  237. static const u8 snum_init_46[] = {
  238. 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
  239. 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
  240. 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
  241. 0xD8, 0xD9, 0xE8, 0xE9, 0x08, 0x09, 0x18, 0x19,
  242. 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
  243. 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
  244. };
  245. static const u8 *snum_init;
  246. qe_num_of_snum = qe_get_num_of_snums();
  247. if (qe_num_of_snum == 76)
  248. snum_init = snum_init_76;
  249. else
  250. snum_init = snum_init_46;
  251. for (i = 0; i < qe_num_of_snum; i++) {
  252. snums[i].num = snum_init[i];
  253. snums[i].state = QE_SNUM_STATE_FREE;
  254. }
  255. }
  256. int qe_get_snum(void)
  257. {
  258. unsigned long flags;
  259. int snum = -EBUSY;
  260. int i;
  261. spin_lock_irqsave(&qe_lock, flags);
  262. for (i = 0; i < qe_num_of_snum; i++) {
  263. if (snums[i].state == QE_SNUM_STATE_FREE) {
  264. snums[i].state = QE_SNUM_STATE_USED;
  265. snum = snums[i].num;
  266. break;
  267. }
  268. }
  269. spin_unlock_irqrestore(&qe_lock, flags);
  270. return snum;
  271. }
  272. EXPORT_SYMBOL(qe_get_snum);
  273. void qe_put_snum(u8 snum)
  274. {
  275. int i;
  276. for (i = 0; i < qe_num_of_snum; i++) {
  277. if (snums[i].num == snum) {
  278. snums[i].state = QE_SNUM_STATE_FREE;
  279. break;
  280. }
  281. }
  282. }
  283. EXPORT_SYMBOL(qe_put_snum);
  284. static int qe_sdma_init(void)
  285. {
  286. struct sdma __iomem *sdma = &qe_immr->sdma;
  287. static unsigned long sdma_buf_offset = (unsigned long)-ENOMEM;
  288. if (!sdma)
  289. return -ENODEV;
  290. /* allocate 2 internal temporary buffers (512 bytes size each) for
  291. * the SDMA */
  292. if (IS_ERR_VALUE(sdma_buf_offset)) {
  293. sdma_buf_offset = qe_muram_alloc(512 * 2, 4096);
  294. if (IS_ERR_VALUE(sdma_buf_offset))
  295. return -ENOMEM;
  296. }
  297. out_be32(&sdma->sdebcr, (u32) sdma_buf_offset & QE_SDEBCR_BA_MASK);
  298. out_be32(&sdma->sdmr, (QE_SDMR_GLB_1_MSK |
  299. (0x1 << QE_SDMR_CEN_SHIFT)));
  300. return 0;
  301. }
  302. /* The maximum number of RISCs we support */
  303. #define MAX_QE_RISC 4
  304. /* Firmware information stored here for qe_get_firmware_info() */
  305. static struct qe_firmware_info qe_firmware_info;
  306. /*
  307. * Set to 1 if QE firmware has been uploaded, and therefore
  308. * qe_firmware_info contains valid data.
  309. */
  310. static int qe_firmware_uploaded;
  311. /*
  312. * Upload a QE microcode
  313. *
  314. * This function is a worker function for qe_upload_firmware(). It does
  315. * the actual uploading of the microcode.
  316. */
  317. static void qe_upload_microcode(const void *base,
  318. const struct qe_microcode *ucode)
  319. {
  320. const __be32 *code = base + be32_to_cpu(ucode->code_offset);
  321. unsigned int i;
  322. if (ucode->major || ucode->minor || ucode->revision)
  323. printk(KERN_INFO "qe-firmware: "
  324. "uploading microcode '%s' version %u.%u.%u\n",
  325. ucode->id, ucode->major, ucode->minor, ucode->revision);
  326. else
  327. printk(KERN_INFO "qe-firmware: "
  328. "uploading microcode '%s'\n", ucode->id);
  329. /* Use auto-increment */
  330. out_be32(&qe_immr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
  331. QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
  332. for (i = 0; i < be32_to_cpu(ucode->count); i++)
  333. out_be32(&qe_immr->iram.idata, be32_to_cpu(code[i]));
  334. }
  335. /*
  336. * Upload a microcode to the I-RAM at a specific address.
  337. *
  338. * See Documentation/powerpc/qe_firmware.txt for information on QE microcode
  339. * uploading.
  340. *
  341. * Currently, only version 1 is supported, so the 'version' field must be
  342. * set to 1.
  343. *
  344. * The SOC model and revision are not validated, they are only displayed for
  345. * informational purposes.
  346. *
  347. * 'calc_size' is the calculated size, in bytes, of the firmware structure and
  348. * all of the microcode structures, minus the CRC.
  349. *
  350. * 'length' is the size that the structure says it is, including the CRC.
  351. */
  352. int qe_upload_firmware(const struct qe_firmware *firmware)
  353. {
  354. unsigned int i;
  355. unsigned int j;
  356. u32 crc;
  357. size_t calc_size = sizeof(struct qe_firmware);
  358. size_t length;
  359. const struct qe_header *hdr;
  360. if (!firmware) {
  361. printk(KERN_ERR "qe-firmware: invalid pointer\n");
  362. return -EINVAL;
  363. }
  364. hdr = &firmware->header;
  365. length = be32_to_cpu(hdr->length);
  366. /* Check the magic */
  367. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  368. (hdr->magic[2] != 'F')) {
  369. printk(KERN_ERR "qe-firmware: not a microcode\n");
  370. return -EPERM;
  371. }
  372. /* Check the version */
  373. if (hdr->version != 1) {
  374. printk(KERN_ERR "qe-firmware: unsupported version\n");
  375. return -EPERM;
  376. }
  377. /* Validate some of the fields */
  378. if ((firmware->count < 1) || (firmware->count > MAX_QE_RISC)) {
  379. printk(KERN_ERR "qe-firmware: invalid data\n");
  380. return -EINVAL;
  381. }
  382. /* Validate the length and check if there's a CRC */
  383. calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
  384. for (i = 0; i < firmware->count; i++)
  385. /*
  386. * For situations where the second RISC uses the same microcode
  387. * as the first, the 'code_offset' and 'count' fields will be
  388. * zero, so it's okay to add those.
  389. */
  390. calc_size += sizeof(__be32) *
  391. be32_to_cpu(firmware->microcode[i].count);
  392. /* Validate the length */
  393. if (length != calc_size + sizeof(__be32)) {
  394. printk(KERN_ERR "qe-firmware: invalid length\n");
  395. return -EPERM;
  396. }
  397. /* Validate the CRC */
  398. crc = be32_to_cpu(*(__be32 *)((void *)firmware + calc_size));
  399. if (crc != crc32(0, firmware, calc_size)) {
  400. printk(KERN_ERR "qe-firmware: firmware CRC is invalid\n");
  401. return -EIO;
  402. }
  403. /*
  404. * If the microcode calls for it, split the I-RAM.
  405. */
  406. if (!firmware->split)
  407. setbits16(&qe_immr->cp.cercr, QE_CP_CERCR_CIR);
  408. if (firmware->soc.model)
  409. printk(KERN_INFO
  410. "qe-firmware: firmware '%s' for %u V%u.%u\n",
  411. firmware->id, be16_to_cpu(firmware->soc.model),
  412. firmware->soc.major, firmware->soc.minor);
  413. else
  414. printk(KERN_INFO "qe-firmware: firmware '%s'\n",
  415. firmware->id);
  416. /*
  417. * The QE only supports one microcode per RISC, so clear out all the
  418. * saved microcode information and put in the new.
  419. */
  420. memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
  421. strcpy(qe_firmware_info.id, firmware->id);
  422. qe_firmware_info.extended_modes = firmware->extended_modes;
  423. memcpy(qe_firmware_info.vtraps, firmware->vtraps,
  424. sizeof(firmware->vtraps));
  425. /* Loop through each microcode. */
  426. for (i = 0; i < firmware->count; i++) {
  427. const struct qe_microcode *ucode = &firmware->microcode[i];
  428. /* Upload a microcode if it's present */
  429. if (ucode->code_offset)
  430. qe_upload_microcode(firmware, ucode);
  431. /* Program the traps for this processor */
  432. for (j = 0; j < 16; j++) {
  433. u32 trap = be32_to_cpu(ucode->traps[j]);
  434. if (trap)
  435. out_be32(&qe_immr->rsp[i].tibcr[j], trap);
  436. }
  437. /* Enable traps */
  438. out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
  439. }
  440. qe_firmware_uploaded = 1;
  441. return 0;
  442. }
  443. EXPORT_SYMBOL(qe_upload_firmware);
  444. /*
  445. * Get info on the currently-loaded firmware
  446. *
  447. * This function also checks the device tree to see if the boot loader has
  448. * uploaded a firmware already.
  449. */
  450. struct qe_firmware_info *qe_get_firmware_info(void)
  451. {
  452. static int initialized;
  453. struct property *prop;
  454. struct device_node *qe;
  455. struct device_node *fw = NULL;
  456. const char *sprop;
  457. unsigned int i;
  458. /*
  459. * If we haven't checked yet, and a driver hasn't uploaded a firmware
  460. * yet, then check the device tree for information.
  461. */
  462. if (qe_firmware_uploaded)
  463. return &qe_firmware_info;
  464. if (initialized)
  465. return NULL;
  466. initialized = 1;
  467. /*
  468. * Newer device trees have an "fsl,qe" compatible property for the QE
  469. * node, but we still need to support older device trees.
  470. */
  471. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  472. if (!qe) {
  473. qe = of_find_node_by_type(NULL, "qe");
  474. if (!qe)
  475. return NULL;
  476. }
  477. /* Find the 'firmware' child node */
  478. for_each_child_of_node(qe, fw) {
  479. if (strcmp(fw->name, "firmware") == 0)
  480. break;
  481. }
  482. of_node_put(qe);
  483. /* Did we find the 'firmware' node? */
  484. if (!fw)
  485. return NULL;
  486. qe_firmware_uploaded = 1;
  487. /* Copy the data into qe_firmware_info*/
  488. sprop = of_get_property(fw, "id", NULL);
  489. if (sprop)
  490. strncpy(qe_firmware_info.id, sprop,
  491. sizeof(qe_firmware_info.id) - 1);
  492. prop = of_find_property(fw, "extended-modes", NULL);
  493. if (prop && (prop->length == sizeof(u64))) {
  494. const u64 *iprop = prop->value;
  495. qe_firmware_info.extended_modes = *iprop;
  496. }
  497. prop = of_find_property(fw, "virtual-traps", NULL);
  498. if (prop && (prop->length == 32)) {
  499. const u32 *iprop = prop->value;
  500. for (i = 0; i < ARRAY_SIZE(qe_firmware_info.vtraps); i++)
  501. qe_firmware_info.vtraps[i] = iprop[i];
  502. }
  503. of_node_put(fw);
  504. return &qe_firmware_info;
  505. }
  506. EXPORT_SYMBOL(qe_get_firmware_info);
  507. unsigned int qe_get_num_of_risc(void)
  508. {
  509. struct device_node *qe;
  510. int size;
  511. unsigned int num_of_risc = 0;
  512. const u32 *prop;
  513. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  514. if (!qe) {
  515. /* Older devices trees did not have an "fsl,qe"
  516. * compatible property, so we need to look for
  517. * the QE node by name.
  518. */
  519. qe = of_find_node_by_type(NULL, "qe");
  520. if (!qe)
  521. return num_of_risc;
  522. }
  523. prop = of_get_property(qe, "fsl,qe-num-riscs", &size);
  524. if (prop && size == sizeof(*prop))
  525. num_of_risc = *prop;
  526. of_node_put(qe);
  527. return num_of_risc;
  528. }
  529. EXPORT_SYMBOL(qe_get_num_of_risc);
  530. unsigned int qe_get_num_of_snums(void)
  531. {
  532. struct device_node *qe;
  533. int size;
  534. unsigned int num_of_snums;
  535. const u32 *prop;
  536. num_of_snums = 28; /* The default number of snum for threads is 28 */
  537. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  538. if (!qe) {
  539. /* Older devices trees did not have an "fsl,qe"
  540. * compatible property, so we need to look for
  541. * the QE node by name.
  542. */
  543. qe = of_find_node_by_type(NULL, "qe");
  544. if (!qe)
  545. return num_of_snums;
  546. }
  547. prop = of_get_property(qe, "fsl,qe-num-snums", &size);
  548. if (prop && size == sizeof(*prop)) {
  549. num_of_snums = *prop;
  550. if ((num_of_snums < 28) || (num_of_snums > QE_NUM_OF_SNUM)) {
  551. /* No QE ever has fewer than 28 SNUMs */
  552. pr_err("QE: number of snum is invalid\n");
  553. of_node_put(qe);
  554. return -EINVAL;
  555. }
  556. }
  557. of_node_put(qe);
  558. return num_of_snums;
  559. }
  560. EXPORT_SYMBOL(qe_get_num_of_snums);
  561. #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC_85xx)
  562. static int qe_resume(struct platform_device *ofdev)
  563. {
  564. if (!qe_alive_during_sleep())
  565. qe_reset();
  566. return 0;
  567. }
  568. static int qe_probe(struct platform_device *ofdev)
  569. {
  570. return 0;
  571. }
  572. static const struct of_device_id qe_ids[] = {
  573. { .compatible = "fsl,qe", },
  574. { },
  575. };
  576. static struct platform_driver qe_driver = {
  577. .driver = {
  578. .name = "fsl-qe",
  579. .owner = THIS_MODULE,
  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) */