qe.c 17 KB

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