1 /* drivers/gpu/t6xx/kbase/src/platform/rk/mali_kbase_platform.c
3 * Rockchip SoC Mali-T764 platform-dependent codes
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software FoundatIon.
11 * @file mali_kbase_platform.c
12 * Platform-dependent init.
14 #include <mali_kbase.h>
15 #include <mali_kbase_pm.h>
16 #include <mali_kbase_uku.h>
17 #include <mali_kbase_mem.h>
18 #include <mali_midg_regmap.h>
19 #include <mali_kbase_mem_linux.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/poll.h>
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/platform_device.h>
27 #include <linux/pci.h>
28 #include <linux/miscdevice.h>
29 #include <linux/list.h>
30 #include <linux/semaphore.h>
32 #include <linux/uaccess.h>
33 #include <linux/interrupt.h>
37 #include <linux/clk.h>
38 #include <linux/delay.h>
39 #include <platform/rk/mali_kbase_platform.h>
40 #include <platform/rk/mali_kbase_dvfs.h>
42 #include <mali_kbase_gator.h>
44 #include <linux/rockchip/dvfs.h>
46 #define MALI_T7XX_DEFAULT_CLOCK 100000
49 static int mali_clk_status = 0;
50 static int mali_pd_status = 0;
52 int mali_dvfs_clk_set(struct dvfs_node *node,unsigned long rate)
57 printk("clk_get_dvfs_node error \r\n");
60 ret = dvfs_clk_set_rate(node,rate * MALI_KHZ);
63 printk("dvfs_clk_set_rate error \r\n");
67 static int kbase_platform_power_clock_init(kbase_device *kbdev)
69 //struct device *dev = kbdev->dev;
70 struct rk_context *platform;
72 platform = (struct rk_context *)kbdev->platform_context;
76 /* enable mali t760 powerdomain*/
77 platform->mali_pd_node = clk_get_dvfs_node("mali_pd");
78 if(IS_ERR_OR_NULL(platform->mali_pd_node))
80 platform->mali_pd_node = NULL;
81 printk(KERN_ERR "%s, %s(): failed to get [platform->mali_pd_node]\n", __FILE__, __func__);
86 //dvfs_clk_prepare_enable(platform->mali_pd_node);
87 printk("pd not enable\n");
91 /* enable mali t760 clock */
92 platform->mali_clk_node = clk_get_dvfs_node("clk_gpu");
93 if (IS_ERR_OR_NULL(platform->mali_clk_node))
95 platform->mali_clk_node = NULL;
96 printk(KERN_ERR "%s, %s(): failed to get [platform->mali_clk_node]\n", __FILE__, __func__);
101 dvfs_clk_prepare_enable(platform->mali_clk_node);
102 printk("clk enabled\n");
104 mali_dvfs_clk_set(platform->mali_clk_node,MALI_T7XX_DEFAULT_CLOCK);
110 if(platform->mali_pd_node)
111 clk_put_dvfs_node(platform->mali_pd_node);
116 int kbase_platform_clock_off(struct kbase_device *kbdev)
118 struct rk_context *platform;
122 platform = (struct rk_context *)kbdev->platform_context;
126 if (mali_clk_status == 0)
129 if((platform->mali_clk_node))
130 dvfs_clk_disable_unprepare(platform->mali_clk_node);
137 int kbase_platform_clock_on(struct kbase_device *kbdev)
139 struct rk_context *platform;
143 platform = (struct rk_context *)kbdev->platform_context;
147 if (mali_clk_status == 1)
150 if(platform->mali_clk_node)
151 dvfs_clk_prepare_enable(platform->mali_clk_node);
157 int kbase_platform_is_power_on(void)
159 return mali_pd_status;
162 /*turn on power domain*/
163 static int kbase_platform_power_on(struct kbase_device *kbdev)
165 struct rk_context *platform;
169 platform = (struct rk_context *)kbdev->platform_context;
173 if (mali_pd_status == 1)
176 if(platform->mali_pd_node)
177 dvfs_clk_prepare_enable(platform->mali_pd_node);
180 KBASE_TIMELINE_GPU_POWER(kbdev, 1);
185 /*turn off power domain*/
186 static int kbase_platform_power_off(struct kbase_device *kbdev)
188 struct rk_context *platform;
192 platform = (struct rk_context *)kbdev->platform_context;
196 if (mali_pd_status== 0)
199 if(platform->mali_pd_node)
200 dvfs_clk_disable_unprepare(platform->mali_pd_node);
203 KBASE_TIMELINE_GPU_POWER(kbdev, 0);
208 int kbase_platform_cmu_pmu_control(struct kbase_device *kbdev, int control)
211 struct rk_context *platform;
215 platform = (struct rk_context *)kbdev->platform_context;
219 spin_lock_irqsave(&platform->cmu_pmu_lock, flags);
224 if (platform->cmu_pmu_status == 0)
226 spin_unlock_irqrestore(&platform->cmu_pmu_lock, flags);
230 if (kbase_platform_power_off(kbdev))
231 panic("failed to turn off mali power domain\n");
232 if (kbase_platform_clock_off(kbdev))
233 panic("failed to turn off mali clock\n");
235 platform->cmu_pmu_status = 0;
236 printk("turn off mali power \n");
241 if (platform->cmu_pmu_status == 1)
243 spin_unlock_irqrestore(&platform->cmu_pmu_lock, flags);
247 if (kbase_platform_power_on(kbdev))
248 panic("failed to turn on mali power domain\n");
249 if (kbase_platform_clock_on(kbdev))
250 panic("failed to turn on mali clock\n");
252 platform->cmu_pmu_status = 1;
253 printk(KERN_ERR "turn on mali power\n");
256 spin_unlock_irqrestore(&platform->cmu_pmu_lock, flags);
261 #ifdef CONFIG_MALI_MIDGARD_DEBUG_SYS
262 static ssize_t show_clock(struct device *dev, struct device_attribute *attr, char *buf)
264 struct kbase_device *kbdev;
265 struct rk_context *platform;
267 unsigned int clkrate;
269 kbdev = dev_get_drvdata(dev);
274 platform = (struct rk_context *)kbdev->platform_context;
278 if (!platform->mali_clk_node)
280 printk("mali_clk_node not init\n");
283 clkrate = dvfs_clk_get_rate(platform->mali_clk_node);
284 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Current clk mali = %dMhz", clkrate / 1000000);
287 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\nPossible settings:");
288 for(i=0;i<MALI_DVFS_STEP;i++)
289 ret += snprintf(buf + ret, PAGE_SIZE - ret, "%d ",p_mali_dvfs_infotbl[i].clock/1000);
290 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Mhz");
292 if (ret < PAGE_SIZE - 1)
293 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
295 buf[PAGE_SIZE - 2] = '\n';
296 buf[PAGE_SIZE - 1] = '\0';
303 static ssize_t set_clock(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
305 struct kbase_device *kbdev;
306 struct rk_context *platform;
307 unsigned int tmp = 0, freq = 0;
308 kbdev = dev_get_drvdata(dev);
313 platform = (struct rk_context *)kbdev->platform_context;
317 if (!platform->mali_clk_node)
320 if (sysfs_streq("500", buf)) {
322 } else if (sysfs_streq("400", buf)) {
324 } else if (sysfs_streq("350", buf)) {
326 } else if (sysfs_streq("266", buf)) {
328 } else if (sysfs_streq("160", buf)) {
330 } else if (sysfs_streq("100", buf)) {
333 dev_err(dev, "set_clock: invalid value\n");
337 freq = simple_strtoul(buf, NULL, 10);
339 kbase_platform_dvfs_set_level(kbdev, kbase_platform_dvfs_get_level(freq));
343 static ssize_t show_fbdev(struct device *dev, struct device_attribute *attr, char *buf)
345 struct kbase_device *kbdev;
349 kbdev = dev_get_drvdata(dev);
354 for (i = 0; i < num_registered_fb; i++)
355 ret += snprintf(buf + ret, PAGE_SIZE - ret, "fb[%d] xres=%d, yres=%d, addr=0x%lx\n", i, registered_fb[i]->var.xres, registered_fb[i]->var.yres, registered_fb[i]->fix.smem_start);
357 if (ret < PAGE_SIZE - 1)
358 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
360 buf[PAGE_SIZE - 2] = '\n';
361 buf[PAGE_SIZE - 1] = '\0';
370 L1_I_data_RAM = 0x01,
374 L1_I_indirect_predictor_RAM = 0x05,
376 L1_D_data_RAM = 0x09,
377 L1_D_load_TLB_array = 0x0A,
378 L1_D_store_TLB_array = 0x0B,
381 L2_snoop_tag_RAM = 0x12,
382 L2_data_ECC_RAM = 0x13,
387 static inline void asm_ramindex_mrc(u32 *DL1Data0, u32 *DL1Data1, u32 *DL1Data2, u32 *DL1Data3)
392 asm volatile ("mrc p15, 0, %0, c15, c1, 0" : "=r" (val));
396 asm volatile ("mrc p15, 0, %0, c15, c1, 1" : "=r" (val));
400 asm volatile ("mrc p15, 0, %0, c15, c1, 2" : "=r" (val));
404 asm volatile ("mrc p15, 0, %0, c15, c1, 3" : "=r" (val));
409 static inline void asm_ramindex_mcr(u32 val)
411 asm volatile ("mcr p15, 0, %0, c15, c4, 0" : : "r" (val));
412 asm volatile ("dsb");
413 asm volatile ("isb");
416 static void get_tlb_array(u32 val, u32 *DL1Data0, u32 *DL1Data1, u32 *DL1Data2, u32 *DL1Data3)
418 asm_ramindex_mcr(val);
419 asm_ramindex_mrc(DL1Data0, DL1Data1, DL1Data2, DL1Data3);
422 static RAMID_type ramindex = L1_D_load_TLB_array;
423 static ssize_t show_dtlb(struct device *dev, struct device_attribute *attr, char *buf)
425 struct kbase_device *kbdev;
428 u32 DL1Data0 = 0, DL1Data1 = 0, DL1Data2 = 0, DL1Data3 = 0;
430 kbdev = dev_get_drvdata(dev);
436 if (ramindex == L1_I_tag_RAM)
437 printk(KERN_DEBUG "Not implemented yet\n");
439 else if (ramindex == L1_I_data_RAM)
440 printk(KERN_DEBUG "Not implemented yet\n");
442 else if (ramindex == L1_I_BTB_RAM)
443 printk(KERN_DEBUG "Not implemented yet\n");
445 else if (ramindex == L1_I_GHB_RAM)
446 printk(KERN_DEBUG "Not implemented yet\n");
448 else if (ramindex == L1_I_TLB_RAM) {
449 printk(KERN_DEBUG "L1-I TLB RAM\n");
450 for (entries = 0; entries < 32; entries++) {
451 get_tlb_array((((u8) ramindex) << 24) + entries, &DL1Data0, &DL1Data1, &DL1Data2, NULL);
452 printk(KERN_DEBUG "entries[%d], DL1Data0=%08x, DL1Data1=%08x DL1Data2=%08x\n", entries, DL1Data0, DL1Data1 & 0xffff, 0x0);
455 /* L1-I indirect predictor RAM */
456 else if (ramindex == L1_I_indirect_predictor_RAM)
457 printk(KERN_DEBUG "Not implemented yet\n");
459 else if (ramindex == L1_D_tag_RAM)
460 printk(KERN_DEBUG "Not implemented yet\n");
462 else if (ramindex == L1_D_data_RAM)
463 printk(KERN_DEBUG "Not implemented yet\n");
464 /* L1-D load TLB array */
465 else if (ramindex == L1_D_load_TLB_array) {
466 printk(KERN_DEBUG "L1-D load TLB array\n");
467 for (entries = 0; entries < 32; entries++) {
468 get_tlb_array((((u8) ramindex) << 24) + entries, &DL1Data0, &DL1Data1, &DL1Data2, &DL1Data3);
469 printk(KERN_DEBUG "entries[%d], DL1Data0=%08x, DL1Data1=%08x, DL1Data2=%08x, DL1Data3=%08x\n", entries, DL1Data0, DL1Data1, DL1Data2, DL1Data3 & 0x3f);
472 /* L1-D store TLB array */
473 else if (ramindex == L1_D_store_TLB_array) {
474 printk(KERN_DEBUG "\nL1-D store TLB array\n");
475 for (entries = 0; entries < 32; entries++) {
476 get_tlb_array((((u8) ramindex) << 24) + entries, &DL1Data0, &DL1Data1, &DL1Data2, &DL1Data3);
477 printk(KERN_DEBUG "entries[%d], DL1Data0=%08x, DL1Data1=%08x, DL1Data2=%08x, DL1Data3=%08x\n", entries, DL1Data0, DL1Data1, DL1Data2, DL1Data3 & 0x3f);
481 else if (ramindex == L2_tag_RAM)
482 printk(KERN_DEBUG "Not implemented yet\n");
484 else if (ramindex == L2_data_RAM)
485 printk(KERN_DEBUG "Not implemented yet\n");
486 /* L2 snoop tag RAM */
487 else if (ramindex == L2_snoop_tag_RAM)
488 printk(KERN_DEBUG "Not implemented yet\n");
489 /* L2 data ECC RAM */
490 else if (ramindex == L2_data_ECC_RAM)
491 printk(KERN_DEBUG "Not implemented yet\n");
493 else if (ramindex == L2_dirty_RAM)
494 printk(KERN_DEBUG "Not implemented yet\n");
497 else if (ramindex == L2_TLB_RAM) {
498 printk(KERN_DEBUG "\nL2 TLB array\n");
499 for (ways = 0; ways < 4; ways++) {
500 for (entries = 0; entries < 512; entries++) {
501 get_tlb_array((ramindex << 24) + (ways << 18) + entries, &DL1Data0, &DL1Data1, &DL1Data2, &DL1Data3);
502 printk(KERN_DEBUG "ways[%d]:entries[%d], DL1Data0=%08x, DL1Data1=%08x, DL1Data2=%08x, DL1Data3=%08x\n", ways, entries, DL1Data0, DL1Data1, DL1Data2, DL1Data3);
508 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Succeeded...\n");
510 if (ret < PAGE_SIZE - 1)
511 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
513 buf[PAGE_SIZE - 2] = '\n';
514 buf[PAGE_SIZE - 1] = '\0';
520 static ssize_t set_dtlb(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
522 struct kbase_device *kbdev;
523 kbdev = dev_get_drvdata(dev);
528 if (sysfs_streq("L1_I_tag_RAM", buf)) {
529 ramindex = L1_I_tag_RAM;
530 } else if (sysfs_streq("L1_I_data_RAM", buf)) {
531 ramindex = L1_I_data_RAM;
532 } else if (sysfs_streq("L1_I_BTB_RAM", buf)) {
533 ramindex = L1_I_BTB_RAM;
534 } else if (sysfs_streq("L1_I_GHB_RAM", buf)) {
535 ramindex = L1_I_GHB_RAM;
536 } else if (sysfs_streq("L1_I_TLB_RAM", buf)) {
537 ramindex = L1_I_TLB_RAM;
538 } else if (sysfs_streq("L1_I_indirect_predictor_RAM", buf)) {
539 ramindex = L1_I_indirect_predictor_RAM;
540 } else if (sysfs_streq("L1_D_tag_RAM", buf)) {
541 ramindex = L1_D_tag_RAM;
542 } else if (sysfs_streq("L1_D_data_RAM", buf)) {
543 ramindex = L1_D_data_RAM;
544 } else if (sysfs_streq("L1_D_load_TLB_array", buf)) {
545 ramindex = L1_D_load_TLB_array;
546 } else if (sysfs_streq("L1_D_store_TLB_array", buf)) {
547 ramindex = L1_D_store_TLB_array;
548 } else if (sysfs_streq("L2_tag_RAM", buf)) {
549 ramindex = L2_tag_RAM;
550 } else if (sysfs_streq("L2_data_RAM", buf)) {
551 ramindex = L2_data_RAM;
552 } else if (sysfs_streq("L2_snoop_tag_RAM", buf)) {
553 ramindex = L2_snoop_tag_RAM;
554 } else if (sysfs_streq("L2_data_ECC_RAM", buf)) {
555 ramindex = L2_data_ECC_RAM;
556 } else if (sysfs_streq("L2_dirty_RAM", buf)) {
557 ramindex = L2_dirty_RAM;
558 } else if (sysfs_streq("L2_TLB_RAM", buf)) {
559 ramindex = L2_TLB_RAM;
561 printk(KERN_DEBUG "Invalid value....\n\n");
562 printk(KERN_DEBUG "Available options are one of below\n");
563 printk(KERN_DEBUG "L1_I_tag_RAM, L1_I_data_RAM, L1_I_BTB_RAM\n");
564 printk(KERN_DEBUG "L1_I_GHB_RAM, L1_I_TLB_RAM, L1_I_indirect_predictor_RAM\n");
565 printk(KERN_DEBUG "L1_D_tag_RAM, L1_D_data_RAM, L1_D_load_TLB_array, L1_D_store_TLB_array\n");
566 printk(KERN_DEBUG "L2_tag_RAM, L2_data_RAM, L2_snoop_tag_RAM, L2_data_ECC_RAM\n");
567 printk(KERN_DEBUG "L2_dirty_RAM, L2_TLB_RAM\n");
573 static ssize_t show_dvfs(struct device *dev, struct device_attribute *attr, char *buf)
575 struct kbase_device *kbdev;
578 kbdev = dev_get_drvdata(dev);
583 #ifdef CONFIG_MALI_MIDGARD_DVFS
584 if (kbase_platform_dvfs_get_enable_status())
585 ret += snprintf(buf + ret, PAGE_SIZE - ret, "mali DVFS is on\nutilisation:%d", kbase_platform_dvfs_get_utilisation());
587 ret += snprintf(buf + ret, PAGE_SIZE - ret, "mali DVFS is off");
589 ret += snprintf(buf + ret, PAGE_SIZE - ret, "mali DVFS is disabled");
592 if (ret < PAGE_SIZE - 1)
593 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
595 buf[PAGE_SIZE - 2] = '\n';
596 buf[PAGE_SIZE - 1] = '\0';
603 static ssize_t set_dvfs(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
605 struct kbase_device *kbdev = dev_get_drvdata(dev);
606 #ifdef CONFIG_MALI_MIDGARD_DVFS
607 struct rk_context *platform;
613 #ifdef CONFIG_MALI_MIDGARD_DVFS
614 platform = (struct rk_context *)kbdev->platform_context;
615 if (sysfs_streq("off", buf)) {
616 //kbase_platform_dvfs_enable(false, MALI_DVFS_BL_CONFIG_FREQ);
617 kbase_platform_dvfs_enable(false, p_mali_dvfs_infotbl[MALI_DVFS_STEP-1].clock);
618 platform->dvfs_enabled = false;
619 } else if (sysfs_streq("on", buf)) {
620 //kbase_platform_dvfs_enable(true, MALI_DVFS_START_FREQ);
621 kbase_platform_dvfs_enable(true, p_mali_dvfs_infotbl[0].clock);
622 platform->dvfs_enabled = true;
624 printk(KERN_DEBUG "invalid val -only [on, off] is accepted\n");
627 printk(KERN_DEBUG "mali DVFS is disabled\n");
632 static ssize_t show_upper_lock_dvfs(struct device *dev, struct device_attribute *attr, char *buf)
634 struct kbase_device *kbdev;
637 #ifdef CONFIG_MALI_MIDGARD_DVFS
638 int locked_level = -1;
641 kbdev = dev_get_drvdata(dev);
646 #ifdef CONFIG_MALI_MIDGARD_DVFS
647 locked_level = mali_get_dvfs_upper_locked_freq();
648 if (locked_level > 0)
649 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Current Upper Lock Level = %dMhz", locked_level);
651 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Unset the Upper Lock Level");
652 //ret += snprintf(buf + ret, PAGE_SIZE - ret, "\nPossible settings : 400, 350,266, 160, 100, If you want to unlock : 600 or off");
653 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\nPossible settings :");
654 for(i=0;i<MALI_DVFS_STEP;i++)
655 ret += snprintf(buf + ret, PAGE_SIZE - ret, "%d ",p_mali_dvfs_infotbl[i].clock/1000);
656 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Mhz");
657 ret += snprintf(buf + ret, PAGE_SIZE - ret, ", If you want to unlock : off");
660 ret += snprintf(buf + ret, PAGE_SIZE - ret, "mali DVFS is disabled. You can not set");
663 if (ret < PAGE_SIZE - 1)
664 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
666 buf[PAGE_SIZE - 2] = '\n';
667 buf[PAGE_SIZE - 1] = '\0';
674 static ssize_t set_upper_lock_dvfs(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
676 struct kbase_device *kbdev;
679 kbdev = dev_get_drvdata(dev);
685 freq = simple_strtoul(buf, NULL, 10);
687 #ifdef CONFIG_MALI_MIDGARD_DVFS
688 if (sysfs_streq("off", buf))
690 mali_dvfs_freq_unlock();
694 for(i=0;i<MALI_DVFS_STEP;i++)
696 if (p_mali_dvfs_infotbl[i].clock == freq)
698 mali_dvfs_freq_lock(i);
701 if(i==MALI_DVFS_STEP)
703 dev_err(dev, "set_clock: invalid value\n");
708 #else /* CONFIG_MALI_MIDGARD_DVFS */
709 printk(KERN_DEBUG "mali DVFS is disabled. You can not set\n");
715 static ssize_t show_under_lock_dvfs(struct device *dev, struct device_attribute *attr, char *buf)
717 struct kbase_device *kbdev;
720 #ifdef CONFIG_MALI_MIDGARD_DVFS
721 int locked_level = -1;
724 kbdev = dev_get_drvdata(dev);
729 #ifdef CONFIG_MALI_MIDGARD_DVFS
730 locked_level = mali_get_dvfs_under_locked_freq();
731 if (locked_level > 0)
732 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Current Under Lock Level = %dMhz", locked_level);
734 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Unset the Under Lock Level");
735 //ret += snprintf(buf + ret, PAGE_SIZE - ret, "\nPossible settings : 600, 400, 350,266, 160, If you want to unlock : 100 or off");
736 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\nPossible settings :");
737 for(i=0;i<MALI_DVFS_STEP;i++)
738 ret += snprintf(buf + ret, PAGE_SIZE - ret, "%d ",p_mali_dvfs_infotbl[i].clock/1000);
739 ret += snprintf(buf + ret, PAGE_SIZE - ret, "Mhz");
740 ret += snprintf(buf + ret, PAGE_SIZE - ret, ", If you want to unlock : off");
743 ret += snprintf(buf + ret, PAGE_SIZE - ret, "mali DVFS is disabled. You can not set");
746 if (ret < PAGE_SIZE - 1)
747 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
749 buf[PAGE_SIZE - 2] = '\n';
750 buf[PAGE_SIZE - 1] = '\0';
757 static ssize_t set_under_lock_dvfs(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
761 struct kbase_device *kbdev;
762 kbdev = dev_get_drvdata(dev);
768 #ifdef CONFIG_MALI_MIDGARD_DVFS
769 if (sysfs_streq("off", buf))
771 mali_dvfs_freq_unlock();
775 for(i=0;i<MALI_DVFS_STEP;i++)
777 if (p_mali_dvfs_infotbl[i].clock == freq)
779 mali_dvfs_freq_lock(i);
782 if(i==MALI_DVFS_STEP)
784 dev_err(dev, "set_clock: invalid value\n");
789 #else /* CONFIG_MALI_MIDGARD_DVFS */
790 printk(KERN_DEBUG "mali DVFS is disabled. You can not set\n");
795 /** The sysfs file @c clock, fbdev.
797 * This is used for obtaining information about the mali t6xx operating clock & framebuffer address,
799 DEVICE_ATTR(clock, S_IRUGO | S_IWUSR, show_clock, set_clock);
800 DEVICE_ATTR(fbdev, S_IRUGO, show_fbdev, NULL);
801 DEVICE_ATTR(dtlb, S_IRUGO | S_IWUSR, show_dtlb, set_dtlb);
802 DEVICE_ATTR(dvfs, S_IRUGO | S_IWUSR, show_dvfs, set_dvfs);
803 DEVICE_ATTR(dvfs_upper_lock, S_IRUGO | S_IWUSR, show_upper_lock_dvfs, set_upper_lock_dvfs);
804 DEVICE_ATTR(dvfs_under_lock, S_IRUGO | S_IWUSR, show_under_lock_dvfs, set_under_lock_dvfs);
805 DEVICE_ATTR(time_in_state, S_IRUGO | S_IWUSR, show_time_in_state, set_time_in_state);
807 int kbase_platform_create_sysfs_file(struct device *dev)
809 if (device_create_file(dev, &dev_attr_clock)) {
810 dev_err(dev, "Couldn't create sysfs file [clock]\n");
814 if (device_create_file(dev, &dev_attr_fbdev)) {
815 dev_err(dev, "Couldn't create sysfs file [fbdev]\n");
819 if (device_create_file(dev, &dev_attr_dtlb)) {
820 dev_err(dev, "Couldn't create sysfs file [dtlb]\n");
824 if (device_create_file(dev, &dev_attr_dvfs)) {
825 dev_err(dev, "Couldn't create sysfs file [dvfs]\n");
829 if (device_create_file(dev, &dev_attr_dvfs_upper_lock)) {
830 dev_err(dev, "Couldn't create sysfs file [dvfs_upper_lock]\n");
834 if (device_create_file(dev, &dev_attr_dvfs_under_lock)) {
835 dev_err(dev, "Couldn't create sysfs file [dvfs_under_lock]\n");
839 if (device_create_file(dev, &dev_attr_time_in_state)) {
840 dev_err(dev, "Couldn't create sysfs file [time_in_state]\n");
848 void kbase_platform_remove_sysfs_file(struct device *dev)
850 device_remove_file(dev, &dev_attr_clock);
851 device_remove_file(dev, &dev_attr_fbdev);
852 device_remove_file(dev, &dev_attr_dtlb);
853 device_remove_file(dev, &dev_attr_dvfs);
854 device_remove_file(dev, &dev_attr_dvfs_upper_lock);
855 device_remove_file(dev, &dev_attr_dvfs_under_lock);
856 device_remove_file(dev, &dev_attr_time_in_state);
858 #endif /* CONFIG_MALI_MIDGARD_DEBUG_SYS */
860 mali_error kbase_platform_init(struct kbase_device *kbdev)
862 struct rk_context *platform;
864 platform = kmalloc(sizeof(struct rk_context), GFP_KERNEL);
866 if (NULL == platform)
867 return MALI_ERROR_OUT_OF_MEMORY;
869 kbdev->platform_context = (void *)platform;
871 platform->cmu_pmu_status = 0;
872 #ifdef CONFIG_MALI_MIDGARD_DVFS
873 platform->utilisation = 0;
874 platform->time_busy = 0;
875 platform->time_idle = 0;
876 platform->time_tick = 0;
877 platform->dvfs_enabled = true;
880 spin_lock_init(&platform->cmu_pmu_lock);
882 if (kbase_platform_power_clock_init(kbdev))
883 goto clock_init_fail;
885 #ifdef CONFIG_MALI_MIDGARD_DVFS
886 kbase_platform_dvfs_init(kbdev);
887 #endif /* CONFIG_MALI_MIDGARD_DVFS */
890 kbase_platform_cmu_pmu_control(kbdev, 1);
891 return MALI_ERROR_NONE;
896 return MALI_ERROR_FUNCTION_FAILED;
899 void kbase_platform_term(kbase_device *kbdev)
901 struct rk_context *platform;
903 platform = (struct rk_context *)kbdev->platform_context;
905 #ifdef CONFIG_MALI_MIDGARD_DVFS
906 kbase_platform_dvfs_term();
907 #endif /* CONFIG_MALI_MIDGARD_DVFS */
910 kbase_platform_cmu_pmu_control(kbdev, 0);
911 kfree(kbdev->platform_context);
912 kbdev->platform_context = 0;