qe.c 17 KB

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