17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
21 #include <linux/string.h>
26 #include <linux/module.h>
34 #include <asm/pgtable.h>
40 static void qe_snums_init(
void);
41 static int qe_sdma_init(
void);
65 static struct qe_snum snums[QE_NUM_OF_SNUM];
66 static unsigned int qe_num_of_snum;
87 if (prop && size >=
sizeof(*prop))
104 QE_CR_PROTOCOL_UNSPECIFIED, 0);
110 panic(
"sdma init failed!");
116 u8 mcn_shift = 0, dev_shift = 0;
120 if (cmd == QE_RESET) {
123 if (cmd == QE_ASSIGN_PAGE) {
125 dev_shift = QE_CR_SNUM_SHIFT;
126 }
else if (cmd == QE_ASSIGN_RISC) {
129 dev_shift = QE_CR_SNUM_SHIFT;
130 mcn_shift = QE_CR_MCN_RISC_ASSIGN_SHIFT;
132 if (device == QE_CR_SUBBLOCK_USB)
133 mcn_shift = QE_CR_MCN_USB_SHIFT;
135 mcn_shift = QE_CR_MCN_NORMAL_SHIFT;
140 (cmd | QE_CR_FLG | ((
u32) device << dev_shift) | (
u32)
141 mcn_protocol << mcn_shift));
145 ret = spin_event_timeout((
in_be32(&
qe_immr->cp.cecr) & QE_CR_FLG) == 0,
149 spin_unlock_irqrestore(&qe_lock, flags);
165 static unsigned int brg_clk = 0;
184 if (prop && size ==
sizeof(*prop))
201 int qe_setbrg(
enum qe_clock brg,
unsigned int rate,
unsigned int multiplier)
206 if ((brg < QE_BRG1) || (brg > QE_BRG16))
211 if (divisor > QE_BRGC_DIVISOR_MAX + 1) {
212 div16 = QE_BRGC_DIV16;
219 if (!div16 && (divisor & 1) && (divisor > 3))
222 tempval = ((divisor - 1) << QE_BRGC_DIVISOR_SHIFT) |
223 QE_BRGC_ENABLE |
div16;
245 if ((i >= 1) && (i <= 16))
246 return (QE_BRG1 - 1) +
i;
253 if ((i >= 1) && (i <= 24))
254 return (QE_CLK1 - 1) +
i;
266 static void qe_snums_init(
void)
269 static const u8 snum_init_76[] = {
270 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
271 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
272 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
273 0xD8, 0xD9, 0xE8, 0xE9, 0x44, 0x45, 0x4C, 0x4D,
274 0x54, 0x55, 0x5C, 0x5D, 0x64, 0x65, 0x6C, 0x6D,
275 0x74, 0x75, 0x7C, 0x7D, 0x84, 0x85, 0x8C, 0x8D,
276 0x94, 0x95, 0x9C, 0x9D, 0xA4, 0xA5, 0xAC, 0xAD,
277 0xB4, 0xB5, 0xBC, 0xBD, 0xC4, 0xC5, 0xCC, 0xCD,
278 0xD4, 0xD5, 0xDC, 0xDD, 0xE4, 0xE5, 0xEC, 0xED,
279 0xF4, 0xF5, 0xFC, 0xFD,
281 static const u8 snum_init_46[] = {
282 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
283 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
284 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
285 0xD8, 0xD9, 0xE8, 0xE9, 0x08, 0x09, 0x18, 0x19,
286 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
287 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
289 static const u8 *snum_init;
293 if (qe_num_of_snum == 76)
294 snum_init = snum_init_76;
296 snum_init = snum_init_46;
298 for (i = 0; i < qe_num_of_snum; i++) {
299 snums[
i].num = snum_init[
i];
311 for (i = 0; i < qe_num_of_snum; i++) {
318 spin_unlock_irqrestore(&qe_lock, flags);
328 for (i = 0; i < qe_num_of_snum; i++) {
329 if (snums[i].
num == snum) {
337 static int qe_sdma_init(
void)
340 static unsigned long sdma_buf_offset = (
unsigned long)-
ENOMEM;
348 sdma_buf_offset = qe_muram_alloc(512 * 2, 4096);
353 out_be32(&sdma->sdebcr, (
u32) sdma_buf_offset & QE_SDEBCR_BA_MASK);
354 out_be32(&sdma->sdmr, (QE_SDMR_GLB_1_MSK |
355 (0x1 << QE_SDMR_CEN_SHIFT)));
361 #define MAX_QE_RISC 4
364 static struct qe_firmware_info qe_firmware_info;
370 static int qe_firmware_uploaded;
378 static void qe_upload_microcode(
const void *base,
379 const struct qe_microcode *ucode)
384 if (ucode->major || ucode->minor || ucode->revision)
386 "uploading microcode '%s' version %u.%u.%u\n",
387 ucode->id, ucode->major, ucode->minor, ucode->revision);
390 "uploading microcode '%s'\n", ucode->id);
394 QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
425 size_t calc_size =
sizeof(
struct qe_firmware);
427 const struct qe_header *
hdr;
434 hdr = &firmware->header;
438 if ((hdr->magic[0] !=
'Q') || (hdr->magic[1] !=
'E') ||
439 (hdr->magic[2] !=
'F')) {
445 if (hdr->version != 1) {
451 if ((firmware->count < 1) || (firmware->count >
MAX_QE_RISC)) {
457 calc_size += (firmware->count - 1) *
sizeof(
struct qe_microcode);
459 for (i = 0; i < firmware->count; i++)
465 calc_size +=
sizeof(
__be32) *
469 if (length != calc_size +
sizeof(
__be32)) {
476 if (crc !=
crc32(0, firmware, calc_size)) {
484 if (!firmware->split)
485 setbits16(&
qe_immr->cp.cercr, QE_CP_CERCR_CIR);
487 if (firmware->soc.model)
489 "qe-firmware: firmware '%s' for %u V%u.%u\n",
491 firmware->soc.major, firmware->soc.minor);
500 memset(&qe_firmware_info, 0,
sizeof(qe_firmware_info));
501 strcpy(qe_firmware_info.id, firmware->id);
502 qe_firmware_info.extended_modes = firmware->extended_modes;
503 memcpy(qe_firmware_info.vtraps, firmware->vtraps,
504 sizeof(firmware->vtraps));
507 for (i = 0; i < firmware->count; i++) {
508 const struct qe_microcode *ucode = &firmware->microcode[
i];
511 if (ucode->code_offset)
512 qe_upload_microcode(firmware, ucode);
515 for (j = 0; j < 16; j++) {
526 qe_firmware_uploaded = 1;
551 if (qe_firmware_uploaded)
552 return &qe_firmware_info;
582 qe_firmware_uploaded = 1;
587 strncpy(qe_firmware_info.id, sprop,
588 sizeof(qe_firmware_info.id) - 1);
591 if (prop && (prop->
length ==
sizeof(
u64))) {
594 qe_firmware_info.extended_modes = *iprop;
598 if (prop && (prop->
length == 32)) {
601 for (i = 0; i <
ARRAY_SIZE(qe_firmware_info.vtraps); i++)
602 qe_firmware_info.vtraps[i] = iprop[i];
607 return &qe_firmware_info;
615 unsigned int num_of_risc = 0;
630 if (prop && size ==
sizeof(*prop))
643 unsigned int num_of_snums;
659 if (prop && size ==
sizeof(*prop)) {
660 num_of_snums = *prop;
661 if ((num_of_snums < 28) || (num_of_snums > QE_NUM_OF_SNUM)) {
663 pr_err(
"QE: number of snum is invalid\n");
675 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC_85xx)
678 if (!qe_alive_during_sleep())
697 .of_match_table = qe_ids,
703 static int __init qe_drv_init(
void)