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
47 #include <asm/smu.h>
63 * This is the command buffer passed to the SMU hardware
95 * I don't think there will ever be more than one SMU, so
99 static struct smu_device *smu; variable
107 * SMU driver low level stuff
115 if (list_empty(&smu->cmd_list)) in smu_start_cmd()
119 cmd = list_entry(smu->cmd_list.next, struct smu_cmd, link); in smu_start_cmd()
120 smu->cmd_cur = cmd; in smu_start_cmd()
123 DPRINTK("SMU: starting cmd %x, %d bytes data\n", cmd->cmd, in smu_start_cmd()
125 DPRINTK("SMU: data buffer: %8ph\n", cmd->data_buf); in smu_start_cmd()
127 /* Fill the SMU command buffer */ in smu_start_cmd()
128 smu->cmd_buf->cmd = cmd->cmd; in smu_start_cmd()
129 smu->cmd_buf->length = cmd->data_len; in smu_start_cmd()
130 memcpy(smu->cmd_buf->data, cmd->data_buf, cmd->data_len); in smu_start_cmd()
133 faddr = (unsigned long)smu->cmd_buf; in smu_start_cmd()
134 fend = faddr + smu->cmd_buf->length + 2; in smu_start_cmd()
143 * whole duration of the command prevents the SMU from fetching it in smu_start_cmd()
145 * mechanism the SMU uses to access memory. in smu_start_cmd()
147 if (smu->broken_nap) in smu_start_cmd()
151 * the SMU is actually communicating with us via i2c to the in smu_start_cmd()
154 writel(smu->cmd_buf_abs, smu->db_buf); in smu_start_cmd()
156 /* Ring the SMU doorbell */ in smu_start_cmd()
157 pmac_do_feature_call(PMAC_FTR_WRITE_GPIO, NULL, smu->doorbell, 4); in smu_start_cmd()
170 /* SMU completed the command, well, we hope, let's make sure in smu_db_intr()
173 spin_lock_irqsave(&smu->lock, flags); in smu_db_intr()
175 gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell); in smu_db_intr()
177 spin_unlock_irqrestore(&smu->lock, flags); in smu_db_intr()
181 cmd = smu->cmd_cur; in smu_db_intr()
182 smu->cmd_cur = NULL; in smu_db_intr()
192 * to flush again before peeking at the SMU response. We in smu_db_intr()
196 faddr = (unsigned long)smu->cmd_buf; in smu_db_intr()
201 if (ack != smu->cmd_buf->cmd) { in smu_db_intr()
202 DPRINTK("SMU: incorrect ack, want %x got %x\n", in smu_db_intr()
203 ack, smu->cmd_buf->cmd); in smu_db_intr()
206 reply_len = rc == 0 ? smu->cmd_buf->length : 0; in smu_db_intr()
207 DPRINTK("SMU: reply len: %d\n", reply_len); in smu_db_intr()
209 printk(KERN_WARNING "SMU: reply buffer too small," in smu_db_intr()
216 memcpy(cmd->reply_buf, smu->cmd_buf->data, reply_len); in smu_db_intr()
228 if (smu->broken_nap) in smu_db_intr()
233 spin_unlock_irqrestore(&smu->lock, flags); in smu_db_intr()
247 * receive it, so I suspect we have to arm it someway in the SMU in smu_msg_intr()
251 printk(KERN_INFO "SMU: message interrupt !\n"); in smu_msg_intr()
267 if (smu == NULL) in smu_queue_cmd()
274 spin_lock_irqsave(&smu->lock, flags); in smu_queue_cmd()
275 list_add_tail(&cmd->link, &smu->cmd_list); in smu_queue_cmd()
276 if (smu->cmd_cur == NULL) in smu_queue_cmd()
278 spin_unlock_irqrestore(&smu->lock, flags); in smu_queue_cmd()
281 if (!smu_irq_inited || !smu->db_irq) in smu_queue_cmd()
324 if (smu == NULL) in smu_poll()
327 gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell); in smu_poll()
329 smu_db_intr(smu->db_irq, smu); in smu_poll()
385 if (smu == NULL) in smu_get_rtc_time()
412 if (smu == NULL) in smu_set_rtc_time()
436 if (smu == NULL) in smu_shutdown()
452 if (smu == NULL) in smu_restart()
466 return smu != NULL; in smu_present()
477 np = of_find_node_by_type(NULL, "smu"); in smu_init()
481 printk(KERN_INFO "SMU: Driver %s %s\n", VERSION, AUTHOR); in smu_init()
484 * SMU based G5s need some memory below 2Gb. Thankfully this is in smu_init()
489 printk(KERN_ERR "SMU: Command buffer allocation failed !\n"); in smu_init()
494 smu = memblock_alloc(sizeof(struct smu_device), SMP_CACHE_BYTES); in smu_init()
495 if (!smu) in smu_init()
499 spin_lock_init(&smu->lock); in smu_init()
500 INIT_LIST_HEAD(&smu->cmd_list); in smu_init()
501 INIT_LIST_HEAD(&smu->cmd_i2c_list); in smu_init()
502 smu->of_node = np; in smu_init()
503 smu->db_irq = 0; in smu_init()
504 smu->msg_irq = 0; in smu_init()
509 smu->cmd_buf_abs = (u32)smu_cmdbuf_abs; in smu_init()
510 smu->cmd_buf = __va(smu_cmdbuf_abs); in smu_init()
512 smu->db_node = of_find_node_by_name(NULL, "smu-doorbell"); in smu_init()
513 if (smu->db_node == NULL) { in smu_init()
514 printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n"); in smu_init()
518 data = of_get_property(smu->db_node, "reg", 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 data = of_get_property(smu->msg_node, "reg", NULL); in smu_init()
540 of_node_put(smu->msg_node); in smu_init()
541 smu->msg_node = NULL; in smu_init()
544 smu->msg = *data; in smu_init()
545 if (smu->msg < 0x50) in smu_init()
546 smu->msg += 0x50; in smu_init()
553 smu->db_buf = ioremap(0x8000860c, 0x1000); in smu_init()
554 if (smu->db_buf == NULL) { in smu_init()
555 printk(KERN_ERR "SMU: Can't map doorbell buffer pointer !\n"); in smu_init()
560 /* U3 has an issue with NAP mode when issuing SMU commands */ in smu_init()
561 smu->broken_nap = pmac_get_uninorth_variant() < 4; in smu_init()
562 if (smu->broken_nap) in smu_init()
563 printk(KERN_INFO "SMU: using NAP mode workaround\n"); in smu_init()
569 of_node_put(smu->msg_node); in smu_init()
571 of_node_put(smu->db_node); in smu_init()
573 memblock_free_ptr(smu, sizeof(struct smu_device)); in smu_init()
574 smu = NULL; in smu_init()
583 if (!smu) in smu_late_init()
586 timer_setup(&smu->i2c_timer, smu_i2c_retry, 0); in smu_late_init()
588 if (smu->db_node) { in smu_late_init()
589 smu->db_irq = irq_of_parse_and_map(smu->db_node, 0); in smu_late_init()
590 if (!smu->db_irq) in smu_late_init()
591 printk(KERN_ERR "smu: failed to map irq for node %pOF\n", in smu_late_init()
592 smu->db_node); in smu_late_init()
594 if (smu->msg_node) { in smu_late_init()
595 smu->msg_irq = irq_of_parse_and_map(smu->msg_node, 0); in smu_late_init()
596 if (!smu->msg_irq) in smu_late_init()
597 printk(KERN_ERR "smu: failed to map irq for node %pOF\n", in smu_late_init()
598 smu->msg_node); in smu_late_init()
605 if (smu->db_irq) { in smu_late_init()
606 if (request_irq(smu->db_irq, smu_db_intr, in smu_late_init()
607 IRQF_SHARED, "SMU doorbell", smu) < 0) { in smu_late_init()
608 printk(KERN_WARNING "SMU: can't " in smu_late_init()
610 smu->db_irq); in smu_late_init()
611 smu->db_irq = 0; in smu_late_init()
615 if (smu->msg_irq) { in smu_late_init()
616 if (request_irq(smu->msg_irq, smu_msg_intr, in smu_late_init()
617 IRQF_SHARED, "SMU message", smu) < 0) { in smu_late_init()
618 printk(KERN_WARNING "SMU: can't " in smu_late_init()
620 smu->msg_irq); in smu_late_init()
621 smu->msg_irq = 0; in smu_late_init()
641 for_each_child_of_node(smu->of_node, np) in smu_expose_childs()
642 if (of_device_is_compatible(np, "smu-sensors")) in smu_expose_childs()
643 of_platform_device_create(np, "smu-sensors", in smu_expose_childs()
644 &smu->of_dev->dev); in smu_expose_childs()
651 if (!smu) in smu_platform_probe()
653 smu->of_dev = dev; in smu_platform_probe()
667 .type = "smu",
675 .name = "smu",
684 * For now, we don't power manage machines with an SMU chip, in smu_init_sysfs()
696 if (!smu) in smu_get_ofdev()
698 return smu->of_dev; in smu_get_ofdev()
722 DPRINTK("SMU: completing, success: %d\n", !fail); in smu_i2c_complete_command()
728 spin_lock_irqsave(&smu->lock, flags); in smu_i2c_complete_command()
729 smu->cmd_i2c_cur = NULL; in smu_i2c_complete_command()
734 if (!list_empty(&smu->cmd_i2c_list)) { in smu_i2c_complete_command()
738 newcmd = list_entry(smu->cmd_i2c_list.next, in smu_i2c_complete_command()
740 smu->cmd_i2c_cur = newcmd; in smu_i2c_complete_command()
743 /* Queue with low level smu */ in smu_i2c_complete_command()
744 list_add_tail(&cmd->scmd.link, &smu->cmd_list); in smu_i2c_complete_command()
745 if (smu->cmd_cur == NULL) in smu_i2c_complete_command()
748 spin_unlock_irqrestore(&smu->lock, flags); in smu_i2c_complete_command()
759 struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur; in smu_i2c_retry()
761 DPRINTK("SMU: i2c failure, requeuing...\n"); in smu_i2c_retry()
775 DPRINTK("SMU: i2c compl. stage=%d status=%x pdata[0]=%x rlen: %x\n", in smu_i2c_low_completion()
793 DPRINTK("SMU: i2c failure, starting timer...\n"); in smu_i2c_low_completion()
794 BUG_ON(cmd != smu->cmd_i2c_cur); in smu_i2c_low_completion()
800 mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5)); in smu_i2c_low_completion()
810 DPRINTK("SMU: going to stage 1\n"); in smu_i2c_low_completion()
828 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()
1326 MISC_DYNAMIC_MINOR, "smu", &smu_device_fops
1331 if (!smu) in smu_device_init()