Lines Matching full:smu
3 * PowerMac G5 SMU driver
15 * - maybe avoid some data copies with i2c by directly using the smu cmd
17 * - understand SMU -> CPU events and implement reception of them via
48 #include <asm/smu.h>
64 * This is the command buffer passed to the SMU hardware
96 * I don't think there will ever be more than one SMU, so
100 static struct smu_device *smu; variable
108 * SMU driver low level stuff
116 if (list_empty(&smu->cmd_list)) in smu_start_cmd()
120 cmd = list_entry(smu->cmd_list.next, struct smu_cmd, link); in smu_start_cmd()
121 smu->cmd_cur = cmd; in smu_start_cmd()
124 DPRINTK("SMU: starting cmd %x, %d bytes data\n", cmd->cmd, in smu_start_cmd()
126 DPRINTK("SMU: data buffer: %8ph\n", cmd->data_buf); in smu_start_cmd()
128 /* Fill the SMU command buffer */ in smu_start_cmd()
129 smu->cmd_buf->cmd = cmd->cmd; in smu_start_cmd()
130 smu->cmd_buf->length = cmd->data_len; in smu_start_cmd()
131 memcpy(smu->cmd_buf->data, cmd->data_buf, cmd->data_len); in smu_start_cmd()
134 faddr = (unsigned long)smu->cmd_buf; in smu_start_cmd()
135 fend = faddr + smu->cmd_buf->length + 2; in smu_start_cmd()
144 * whole duration of the command prevents the SMU from fetching it in smu_start_cmd()
146 * mechanism the SMU uses to access memory. in smu_start_cmd()
148 if (smu->broken_nap) in smu_start_cmd()
152 * the SMU is actually communicating with us via i2c to the in smu_start_cmd()
155 writel(smu->cmd_buf_abs, smu->db_buf); in smu_start_cmd()
157 /* Ring the SMU doorbell */ in smu_start_cmd()
158 pmac_do_feature_call(PMAC_FTR_WRITE_GPIO, NULL, smu->doorbell, 4); in smu_start_cmd()
171 /* SMU completed the command, well, we hope, let's make sure in smu_db_intr()
174 spin_lock_irqsave(&smu->lock, flags); in smu_db_intr()
176 gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell); in smu_db_intr()
178 spin_unlock_irqrestore(&smu->lock, flags); in smu_db_intr()
182 cmd = smu->cmd_cur; in smu_db_intr()
183 smu->cmd_cur = NULL; in smu_db_intr()
193 * to flush again before peeking at the SMU response. We in smu_db_intr()
197 faddr = (unsigned long)smu->cmd_buf; in smu_db_intr()
202 if (ack != smu->cmd_buf->cmd) { in smu_db_intr()
203 DPRINTK("SMU: incorrect ack, want %x got %x\n", in smu_db_intr()
204 ack, smu->cmd_buf->cmd); in smu_db_intr()
207 reply_len = rc == 0 ? smu->cmd_buf->length : 0; in smu_db_intr()
208 DPRINTK("SMU: reply len: %d\n", reply_len); in smu_db_intr()
210 printk(KERN_WARNING "SMU: reply buffer too small," in smu_db_intr()
217 memcpy(cmd->reply_buf, smu->cmd_buf->data, reply_len); in smu_db_intr()
229 if (smu->broken_nap) in smu_db_intr()
234 spin_unlock_irqrestore(&smu->lock, flags); in smu_db_intr()
248 * receive it, so I suspect we have to arm it someway in the SMU in smu_msg_intr()
252 printk(KERN_INFO "SMU: message interrupt !\n"); in smu_msg_intr()
268 if (smu == NULL) in smu_queue_cmd()
275 spin_lock_irqsave(&smu->lock, flags); in smu_queue_cmd()
276 list_add_tail(&cmd->link, &smu->cmd_list); in smu_queue_cmd()
277 if (smu->cmd_cur == NULL) in smu_queue_cmd()
279 spin_unlock_irqrestore(&smu->lock, flags); in smu_queue_cmd()
282 if (!smu_irq_inited || !smu->db_irq) in smu_queue_cmd()
325 if (smu == NULL) in smu_poll()
328 gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell); in smu_poll()
330 smu_db_intr(smu->db_irq, smu); in smu_poll()
386 if (smu == NULL) in smu_get_rtc_time()
413 if (smu == NULL) in smu_set_rtc_time()
437 if (smu == NULL) in smu_shutdown()
453 if (smu == NULL) in smu_restart()
467 return smu != NULL; in smu_present()
478 np = of_find_node_by_type(NULL, "smu"); in smu_init()
482 printk(KERN_INFO "SMU: Driver %s %s\n", VERSION, AUTHOR); in smu_init()
485 * SMU based G5s need some memory below 2Gb. Thankfully this is in smu_init()
490 printk(KERN_ERR "SMU: Command buffer allocation failed !\n"); in smu_init()
495 smu = memblock_alloc(sizeof(struct smu_device), SMP_CACHE_BYTES); in smu_init()
496 if (!smu) in smu_init()
500 spin_lock_init(&smu->lock); in smu_init()
501 INIT_LIST_HEAD(&smu->cmd_list); in smu_init()
502 INIT_LIST_HEAD(&smu->cmd_i2c_list); in smu_init()
503 smu->of_node = np; in smu_init()
504 smu->db_irq = 0; in smu_init()
505 smu->msg_irq = 0; in smu_init()
510 smu->cmd_buf_abs = (u32)smu_cmdbuf_abs; in smu_init()
511 smu->cmd_buf = __va(smu_cmdbuf_abs); in smu_init()
513 smu->db_node = of_find_node_by_name(NULL, "smu-doorbell"); in smu_init()
514 if (smu->db_node == NULL) { in smu_init()
515 printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n"); in smu_init()
519 if (of_property_read_reg(smu->db_node, 0, &data, NULL)) { in smu_init()
520 printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n"); in smu_init()
529 smu->doorbell = data; in smu_init()
530 if (smu->doorbell < 0x50) in smu_init()
531 smu->doorbell += 0x50; in smu_init()
533 /* Now look for the smu-interrupt GPIO */ in smu_init()
535 smu->msg_node = of_find_node_by_name(NULL, "smu-interrupt"); in smu_init()
536 if (smu->msg_node == NULL) in smu_init()
538 if (of_property_read_reg(smu->msg_node, 0, &data, NULL)) { in smu_init()
539 of_node_put(smu->msg_node); in smu_init()
540 smu->msg_node = NULL; in smu_init()
543 smu->msg = data; in smu_init()
544 if (smu->msg < 0x50) in smu_init()
545 smu->msg += 0x50; in smu_init()
552 smu->db_buf = ioremap(0x8000860c, 0x1000); in smu_init()
553 if (smu->db_buf == NULL) { in smu_init()
554 printk(KERN_ERR "SMU: Can't map doorbell buffer pointer !\n"); in smu_init()
559 /* U3 has an issue with NAP mode when issuing SMU commands */ in smu_init()
560 smu->broken_nap = pmac_get_uninorth_variant() < 4; in smu_init()
561 if (smu->broken_nap) in smu_init()
562 printk(KERN_INFO "SMU: using NAP mode workaround\n"); in smu_init()
568 of_node_put(smu->msg_node); in smu_init()
570 of_node_put(smu->db_node); in smu_init()
572 memblock_free(smu, sizeof(struct smu_device)); in smu_init()
573 smu = NULL; in smu_init()
582 if (!smu) in smu_late_init()
585 timer_setup(&smu->i2c_timer, smu_i2c_retry, 0); in smu_late_init()
587 if (smu->db_node) { in smu_late_init()
588 smu->db_irq = irq_of_parse_and_map(smu->db_node, 0); in smu_late_init()
589 if (!smu->db_irq) in smu_late_init()
590 printk(KERN_ERR "smu: failed to map irq for node %pOF\n", in smu_late_init()
591 smu->db_node); in smu_late_init()
593 if (smu->msg_node) { in smu_late_init()
594 smu->msg_irq = irq_of_parse_and_map(smu->msg_node, 0); in smu_late_init()
595 if (!smu->msg_irq) in smu_late_init()
596 printk(KERN_ERR "smu: failed to map irq for node %pOF\n", in smu_late_init()
597 smu->msg_node); in smu_late_init()
604 if (smu->db_irq) { in smu_late_init()
605 if (request_irq(smu->db_irq, smu_db_intr, in smu_late_init()
606 IRQF_SHARED, "SMU doorbell", smu) < 0) { in smu_late_init()
607 printk(KERN_WARNING "SMU: can't " in smu_late_init()
609 smu->db_irq); in smu_late_init()
610 smu->db_irq = 0; in smu_late_init()
614 if (smu->msg_irq) { in smu_late_init()
615 if (request_irq(smu->msg_irq, smu_msg_intr, in smu_late_init()
616 IRQF_SHARED, "SMU message", smu) < 0) { in smu_late_init()
617 printk(KERN_WARNING "SMU: can't " in smu_late_init()
619 smu->msg_irq); in smu_late_init()
620 smu->msg_irq = 0; in smu_late_init()
640 for_each_child_of_node(smu->of_node, np) in smu_expose_childs()
641 if (of_device_is_compatible(np, "smu-sensors")) in smu_expose_childs()
642 of_platform_device_create(np, "smu-sensors", in smu_expose_childs()
643 &smu->of_dev->dev); in smu_expose_childs()
650 if (!smu) in smu_platform_probe()
652 smu->of_dev = dev; in smu_platform_probe()
666 .type = "smu",
674 .name = "smu",
683 * For now, we don't power manage machines with an SMU chip, in smu_init_sysfs()
695 if (!smu) in smu_get_ofdev()
697 return smu->of_dev; in smu_get_ofdev()
721 DPRINTK("SMU: completing, success: %d\n", !fail); in smu_i2c_complete_command()
727 spin_lock_irqsave(&smu->lock, flags); in smu_i2c_complete_command()
728 smu->cmd_i2c_cur = NULL; in smu_i2c_complete_command()
733 if (!list_empty(&smu->cmd_i2c_list)) { in smu_i2c_complete_command()
737 newcmd = list_entry(smu->cmd_i2c_list.next, in smu_i2c_complete_command()
739 smu->cmd_i2c_cur = newcmd; in smu_i2c_complete_command()
742 /* Queue with low level smu */ in smu_i2c_complete_command()
743 list_add_tail(&cmd->scmd.link, &smu->cmd_list); in smu_i2c_complete_command()
744 if (smu->cmd_cur == NULL) in smu_i2c_complete_command()
747 spin_unlock_irqrestore(&smu->lock, flags); in smu_i2c_complete_command()
758 struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur; in smu_i2c_retry()
760 DPRINTK("SMU: i2c failure, requeuing...\n"); in smu_i2c_retry()
774 DPRINTK("SMU: i2c compl. stage=%d status=%x pdata[0]=%x rlen: %x\n", in smu_i2c_low_completion()
792 DPRINTK("SMU: i2c failure, starting timer...\n"); in smu_i2c_low_completion()
793 BUG_ON(cmd != smu->cmd_i2c_cur); in smu_i2c_low_completion()
799 mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5)); in smu_i2c_low_completion()
809 DPRINTK("SMU: going to stage 1\n"); in smu_i2c_low_completion()
827 if (smu == NULL) in smu_queue_i2c()
877 DPRINTK("SMU: i2c enqueuing command\n"); in smu_queue_i2c()
878 DPRINTK("SMU: %s, len=%d bus=%x addr=%x sub0=%x type=%x\n", in smu_queue_i2c()
887 spin_lock_irqsave(&smu->lock, flags); in smu_queue_i2c()
888 if (smu->cmd_i2c_cur == NULL) { in smu_queue_i2c()
889 smu->cmd_i2c_cur = cmd; in smu_queue_i2c()
890 list_add_tail(&cmd->scmd.link, &smu->cmd_list); in smu_queue_i2c()
891 if (smu->cmd_cur == NULL) in smu_queue_i2c()
894 list_add_tail(&cmd->link, &smu->cmd_i2c_list); in smu_queue_i2c()
895 spin_unlock_irqrestore(&smu->lock, flags); in smu_queue_i2c()
913 * SMU firmware version and use bigger sizes though in smu_read_datablock()
939 printk(KERN_DEBUG "SMU: short read in " in smu_read_datablock()
960 DPRINTK("SMU: Query partition infos ... (irq=%d)\n", smu->db_irq); in smu_create_sdb_partition()
965 DPRINTK("SMU: done, status: %d, reply_len: %d\n", in smu_create_sdb_partition()
992 printk(KERN_DEBUG "SMU: datablock read failed while reading " in smu_create_sdb_partition()
999 printk(KERN_DEBUG "SMU: Reading partition %02x and got " in smu_create_sdb_partition()
1003 if (of_add_property(smu->of_node, prop)) { in smu_create_sdb_partition()
1004 printk(KERN_DEBUG "SMU: Failed creating sdb-partition-%02x " in smu_create_sdb_partition()
1024 if (!smu) in __smu_get_sdb_partition()
1039 part = of_get_property(smu->of_node, pname, size); in __smu_get_sdb_partition()
1041 DPRINTK("trying to extract from SMU ...\n"); in __smu_get_sdb_partition()
1325 MISC_DYNAMIC_MINOR, "smu", &smu_device_fops
1330 if (!smu) in smu_device_init()