qe.c 17 KB

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