MALI: midgard: RK: add separate src dir of Midgard driver for RK Linux device
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard_for_linux / platform / juno_soc / juno_mali_opp.c
1 /*
2  *
3  * (C) COPYRIGHT 2014 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 #include <linux/module.h>
19 #include <linux/of_platform.h>
20 #include <linux/platform_device.h>
21 #include <linux/scpi_protocol.h>
22 #include <linux/version.h>
23 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
24 #include <linux/pm_opp.h>
25 #else /* Linux >= 3.13 */
26 /* In 3.13 the OPP include header file, types, and functions were all
27  * renamed. Use the old filename for the include, and define the new names to
28  * the old, when an old kernel is detected.
29  */
30 #include <linux/opp.h>
31 #define dev_pm_opp_add opp_add
32 #endif /* Linux >= 3.13 */
33
34
35 static int init_juno_opps_from_scpi(struct device *dev)
36 {
37         struct scpi_opp *sopp;
38         int i;
39
40         /* Hard coded for Juno. 2 is GPU domain */
41         sopp = scpi_dvfs_get_opps(2);
42         if (IS_ERR_OR_NULL(sopp))
43                 return PTR_ERR(sopp);
44
45         for (i = 0; i < sopp->count; i++) {
46                 struct scpi_opp_entry *e = &sopp->opp[i];
47
48                 dev_info(dev, "Mali OPP from SCPI: %u Hz @ %u mV\n",
49                                 e->freq_hz, e->volt_mv);
50
51                 dev_pm_opp_add(dev, e->freq_hz, e->volt_mv * 1000);
52         }
53
54         return 0;
55 }
56
57 static int juno_setup_opps(void)
58 {
59         struct device_node *np;
60         struct platform_device *pdev;
61         int err;
62
63         np = of_find_node_by_name(NULL, "gpu");
64         if (!np) {
65                 pr_err("Failed to find DT entry for Mali\n");
66                 return -EFAULT;
67         }
68
69         pdev = of_find_device_by_node(np);
70         if (!pdev) {
71                 pr_err("Failed to find device for Mali\n");
72                 of_node_put(np);
73                 return -EFAULT;
74         }
75
76         err = init_juno_opps_from_scpi(&pdev->dev);
77
78         of_node_put(np);
79
80         return err;
81 }
82
83 module_init(juno_setup_opps);
84 MODULE_LICENSE("GPL");