aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/sysdev/qe_lib
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/sysdev/qe_lib')
-rw-r--r--arch/powerpc/sysdev/qe_lib/Kconfig2
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe.c247
-rw-r--r--arch/powerpc/sysdev/qe_lib/ucc_slow.c10
3 files changed, 257 insertions, 2 deletions
diff --git a/arch/powerpc/sysdev/qe_lib/Kconfig b/arch/powerpc/sysdev/qe_lib/Kconfig
index f611d344a126..adc66212a419 100644
--- a/arch/powerpc/sysdev/qe_lib/Kconfig
+++ b/arch/powerpc/sysdev/qe_lib/Kconfig
@@ -4,7 +4,7 @@
4 4
5config UCC_SLOW 5config UCC_SLOW
6 bool 6 bool
7 default n 7 default y if SERIAL_QE
8 help 8 help
9 This option provides qe_lib support to UCC slow 9 This option provides qe_lib support to UCC slow
10 protocols: UART, BISYNC, QMC 10 protocols: UART, BISYNC, QMC
diff --git a/arch/powerpc/sysdev/qe_lib/qe.c b/arch/powerpc/sysdev/qe_lib/qe.c
index 21e01061aca9..3925eae9b0f5 100644
--- a/arch/powerpc/sysdev/qe_lib/qe.c
+++ b/arch/powerpc/sysdev/qe_lib/qe.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <linux/crc32.h>
28#include <asm/irq.h> 29#include <asm/irq.h>
29#include <asm/page.h> 30#include <asm/page.h>
30#include <asm/pgtable.h> 31#include <asm/pgtable.h>
@@ -394,3 +395,249 @@ void *qe_muram_addr(unsigned long offset)
394 return (void *)&qe_immr->muram[offset]; 395 return (void *)&qe_immr->muram[offset];
395} 396}
396EXPORT_SYMBOL(qe_muram_addr); 397EXPORT_SYMBOL(qe_muram_addr);
398
399/* The maximum number of RISCs we support */
400#define MAX_QE_RISC 2
401
402/* Firmware information stored here for qe_get_firmware_info() */
403static struct qe_firmware_info qe_firmware_info;
404
405/*
406 * Set to 1 if QE firmware has been uploaded, and therefore
407 * qe_firmware_info contains valid data.
408 */
409static int qe_firmware_uploaded;
410
411/*
412 * Upload a QE microcode
413 *
414 * This function is a worker function for qe_upload_firmware(). It does
415 * the actual uploading of the microcode.
416 */
417static void qe_upload_microcode(const void *base,
418 const struct qe_microcode *ucode)
419{
420 const __be32 *code = base + be32_to_cpu(ucode->code_offset);
421 unsigned int i;
422
423 if (ucode->major || ucode->minor || ucode->revision)
424 printk(KERN_INFO "qe-firmware: "
425 "uploading microcode '%s' version %u.%u.%u\n",
426 ucode->id, ucode->major, ucode->minor, ucode->revision);
427 else
428 printk(KERN_INFO "qe-firmware: "
429 "uploading microcode '%s'\n", ucode->id);
430
431 /* Use auto-increment */
432 out_be32(&qe_immr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
433 QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
434
435 for (i = 0; i < be32_to_cpu(ucode->count); i++)
436 out_be32(&qe_immr->iram.idata, be32_to_cpu(code[i]));
437}
438
439/*
440 * Upload a microcode to the I-RAM at a specific address.
441 *
442 * See Documentation/powerpc/qe-firmware.txt for information on QE microcode
443 * uploading.
444 *
445 * Currently, only version 1 is supported, so the 'version' field must be
446 * set to 1.
447 *
448 * The SOC model and revision are not validated, they are only displayed for
449 * informational purposes.
450 *
451 * 'calc_size' is the calculated size, in bytes, of the firmware structure and
452 * all of the microcode structures, minus the CRC.
453 *
454 * 'length' is the size that the structure says it is, including the CRC.
455 */
456int qe_upload_firmware(const struct qe_firmware *firmware)
457{
458 unsigned int i;
459 unsigned int j;
460 u32 crc;
461 size_t calc_size = sizeof(struct qe_firmware);
462 size_t length;
463 const struct qe_header *hdr;
464
465 if (!firmware) {
466 printk(KERN_ERR "qe-firmware: invalid pointer\n");
467 return -EINVAL;
468 }
469
470 hdr = &firmware->header;
471 length = be32_to_cpu(hdr->length);
472
473 /* Check the magic */
474 if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
475 (hdr->magic[2] != 'F')) {
476 printk(KERN_ERR "qe-firmware: not a microcode\n");
477 return -EPERM;
478 }
479
480 /* Check the version */
481 if (hdr->version != 1) {
482 printk(KERN_ERR "qe-firmware: unsupported version\n");
483 return -EPERM;
484 }
485
486 /* Validate some of the fields */
487 if ((firmware->count < 1) || (firmware->count >= MAX_QE_RISC)) {
488 printk(KERN_ERR "qe-firmware: invalid data\n");
489 return -EINVAL;
490 }
491
492 /* Validate the length and check if there's a CRC */
493 calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
494
495 for (i = 0; i < firmware->count; i++)
496 /*
497 * For situations where the second RISC uses the same microcode
498 * as the first, the 'code_offset' and 'count' fields will be
499 * zero, so it's okay to add those.
500 */
501 calc_size += sizeof(__be32) *
502 be32_to_cpu(firmware->microcode[i].count);
503
504 /* Validate the length */
505 if (length != calc_size + sizeof(__be32)) {
506 printk(KERN_ERR "qe-firmware: invalid length\n");
507 return -EPERM;
508 }
509
510 /* Validate the CRC */
511 crc = be32_to_cpu(*(__be32 *)((void *)firmware + calc_size));
512 if (crc != crc32(0, firmware, calc_size)) {
513 printk(KERN_ERR "qe-firmware: firmware CRC is invalid\n");
514 return -EIO;
515 }
516
517 /*
518 * If the microcode calls for it, split the I-RAM.
519 */
520 if (!firmware->split)
521 setbits16(&qe_immr->cp.cercr, QE_CP_CERCR_CIR);
522
523 if (firmware->soc.model)
524 printk(KERN_INFO
525 "qe-firmware: firmware '%s' for %u V%u.%u\n",
526 firmware->id, be16_to_cpu(firmware->soc.model),
527 firmware->soc.major, firmware->soc.minor);
528 else
529 printk(KERN_INFO "qe-firmware: firmware '%s'\n",
530 firmware->id);
531
532 /*
533 * The QE only supports one microcode per RISC, so clear out all the
534 * saved microcode information and put in the new.
535 */
536 memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
537 strcpy(qe_firmware_info.id, firmware->id);
538 qe_firmware_info.extended_modes = firmware->extended_modes;
539 memcpy(qe_firmware_info.vtraps, firmware->vtraps,
540 sizeof(firmware->vtraps));
541
542 /* Loop through each microcode. */
543 for (i = 0; i < firmware->count; i++) {
544 const struct qe_microcode *ucode = &firmware->microcode[i];
545
546 /* Upload a microcode if it's present */
547 if (ucode->code_offset)
548 qe_upload_microcode(firmware, ucode);
549
550 /* Program the traps for this processor */
551 for (j = 0; j < 16; j++) {
552 u32 trap = be32_to_cpu(ucode->traps[j]);
553
554 if (trap)
555 out_be32(&qe_immr->rsp[i].tibcr[j], trap);
556 }
557
558 /* Enable traps */
559 out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
560 }
561
562 qe_firmware_uploaded = 1;
563
564 return 0;
565}
566EXPORT_SYMBOL(qe_upload_firmware);
567
568/*
569 * Get info on the currently-loaded firmware
570 *
571 * This function also checks the device tree to see if the boot loader has
572 * uploaded a firmware already.
573 */
574struct qe_firmware_info *qe_get_firmware_info(void)
575{
576 static int initialized;
577 struct property *prop;
578 struct device_node *qe;
579 struct device_node *fw = NULL;
580 const char *sprop;
581 unsigned int i;
582
583 /*
584 * If we haven't checked yet, and a driver hasn't uploaded a firmware
585 * yet, then check the device tree for information.
586 */
587 if (initialized || qe_firmware_uploaded)
588 return NULL;
589
590 initialized = 1;
591
592 /*
593 * Newer device trees have an "fsl,qe" compatible property for the QE
594 * node, but we still need to support older device trees.
595 */
596 qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
597 if (!qe) {
598 qe = of_find_node_by_type(NULL, "qe");
599 if (!qe)
600 return NULL;
601 }
602
603 /* Find the 'firmware' child node */
604 for_each_child_of_node(qe, fw) {
605 if (strcmp(fw->name, "firmware") == 0)
606 break;
607 }
608
609 of_node_put(qe);
610
611 /* Did we find the 'firmware' node? */
612 if (!fw)
613 return NULL;
614
615 qe_firmware_uploaded = 1;
616
617 /* Copy the data into qe_firmware_info*/
618 sprop = of_get_property(fw, "id", NULL);
619 if (sprop)
620 strncpy(qe_firmware_info.id, sprop,
621 sizeof(qe_firmware_info.id) - 1);
622
623 prop = of_find_property(fw, "extended-modes", NULL);
624 if (prop && (prop->length == sizeof(u64))) {
625 const u64 *iprop = prop->value;
626
627 qe_firmware_info.extended_modes = *iprop;
628 }
629
630 prop = of_find_property(fw, "virtual-traps", NULL);
631 if (prop && (prop->length == 32)) {
632 const u32 *iprop = prop->value;
633
634 for (i = 0; i < ARRAY_SIZE(qe_firmware_info.vtraps); i++)
635 qe_firmware_info.vtraps[i] = iprop[i];
636 }
637
638 of_node_put(fw);
639
640 return &qe_firmware_info;
641}
642EXPORT_SYMBOL(qe_get_firmware_info);
643
diff --git a/arch/powerpc/sysdev/qe_lib/ucc_slow.c b/arch/powerpc/sysdev/qe_lib/ucc_slow.c
index 0174b3aeef8f..b2870b208ddb 100644
--- a/arch/powerpc/sysdev/qe_lib/ucc_slow.c
+++ b/arch/powerpc/sysdev/qe_lib/ucc_slow.c
@@ -19,6 +19,7 @@
19#include <linux/stddef.h> 19#include <linux/stddef.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/module.h>
22 23
23#include <asm/io.h> 24#include <asm/io.h>
24#include <asm/immap_qe.h> 25#include <asm/immap_qe.h>
@@ -41,6 +42,7 @@ u32 ucc_slow_get_qe_cr_subblock(int uccs_num)
41 default: return QE_CR_SUBBLOCK_INVALID; 42 default: return QE_CR_SUBBLOCK_INVALID;
42 } 43 }
43} 44}
45EXPORT_SYMBOL(ucc_slow_get_qe_cr_subblock);
44 46
45void ucc_slow_poll_transmitter_now(struct ucc_slow_private * uccs) 47void ucc_slow_poll_transmitter_now(struct ucc_slow_private * uccs)
46{ 48{
@@ -56,6 +58,7 @@ void ucc_slow_graceful_stop_tx(struct ucc_slow_private * uccs)
56 qe_issue_cmd(QE_GRACEFUL_STOP_TX, id, 58 qe_issue_cmd(QE_GRACEFUL_STOP_TX, id,
57 QE_CR_PROTOCOL_UNSPECIFIED, 0); 59 QE_CR_PROTOCOL_UNSPECIFIED, 0);
58} 60}
61EXPORT_SYMBOL(ucc_slow_graceful_stop_tx);
59 62
60void ucc_slow_stop_tx(struct ucc_slow_private * uccs) 63void ucc_slow_stop_tx(struct ucc_slow_private * uccs)
61{ 64{
@@ -65,6 +68,7 @@ void ucc_slow_stop_tx(struct ucc_slow_private * uccs)
65 id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num); 68 id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num);
66 qe_issue_cmd(QE_STOP_TX, id, QE_CR_PROTOCOL_UNSPECIFIED, 0); 69 qe_issue_cmd(QE_STOP_TX, id, QE_CR_PROTOCOL_UNSPECIFIED, 0);
67} 70}
71EXPORT_SYMBOL(ucc_slow_stop_tx);
68 72
69void ucc_slow_restart_tx(struct ucc_slow_private * uccs) 73void ucc_slow_restart_tx(struct ucc_slow_private * uccs)
70{ 74{
@@ -74,6 +78,7 @@ void ucc_slow_restart_tx(struct ucc_slow_private * uccs)
74 id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num); 78 id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num);
75 qe_issue_cmd(QE_RESTART_TX, id, QE_CR_PROTOCOL_UNSPECIFIED, 0); 79 qe_issue_cmd(QE_RESTART_TX, id, QE_CR_PROTOCOL_UNSPECIFIED, 0);
76} 80}
81EXPORT_SYMBOL(ucc_slow_restart_tx);
77 82
78void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode) 83void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode)
79{ 84{
@@ -94,6 +99,7 @@ void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode)
94 } 99 }
95 out_be32(&us_regs->gumr_l, gumr_l); 100 out_be32(&us_regs->gumr_l, gumr_l);
96} 101}
102EXPORT_SYMBOL(ucc_slow_enable);
97 103
98void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode) 104void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode)
99{ 105{
@@ -114,6 +120,7 @@ void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode)
114 } 120 }
115 out_be32(&us_regs->gumr_l, gumr_l); 121 out_be32(&us_regs->gumr_l, gumr_l);
116} 122}
123EXPORT_SYMBOL(ucc_slow_disable);
117 124
118/* Initialize the UCC for Slow operations 125/* Initialize the UCC for Slow operations
119 * 126 *
@@ -347,6 +354,7 @@ int ucc_slow_init(struct ucc_slow_info * us_info, struct ucc_slow_private ** ucc
347 *uccs_ret = uccs; 354 *uccs_ret = uccs;
348 return 0; 355 return 0;
349} 356}
357EXPORT_SYMBOL(ucc_slow_init);
350 358
351void ucc_slow_free(struct ucc_slow_private * uccs) 359void ucc_slow_free(struct ucc_slow_private * uccs)
352{ 360{
@@ -366,5 +374,5 @@ void ucc_slow_free(struct ucc_slow_private * uccs)
366 374
367 kfree(uccs); 375 kfree(uccs);
368} 376}
369 377EXPORT_SYMBOL(ucc_slow_free);
370 378