Merge back earlier cpufreq changes for v4.8.
[cascardo/linux.git] / arch / x86 / platform / atom / punit_atom_debug.c
1 /*
2  * Intel SOC Punit device state debug driver
3  * Punit controls power management for North Complex devices (Graphics
4  * blocks, Image Signal Processing, video processing, display, DSP etc.)
5  *
6  * Copyright (c) 2015, Intel Corporation.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  */
18
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/device.h>
22 #include <linux/debugfs.h>
23 #include <linux/seq_file.h>
24 #include <linux/io.h>
25 #include <asm/cpu_device_id.h>
26 #include <asm/intel-family.h>
27 #include <asm/iosf_mbi.h>
28
29 /* Power gate status reg */
30 #define PWRGT_STATUS            0x61
31 /* Subsystem config/status Video processor */
32 #define VED_SS_PM0              0x32
33 /* Subsystem config/status ISP (Image Signal Processor) */
34 #define ISP_SS_PM0              0x39
35 /* Subsystem config/status Input/output controller */
36 #define MIO_SS_PM               0x3B
37 /* Shift bits for getting status for video, isp and i/o */
38 #define SSS_SHIFT               24
39 /* Shift bits for getting status for graphics rendering */
40 #define RENDER_POS              0
41 /* Shift bits for getting status for media control */
42 #define MEDIA_POS               2
43 /* Shift bits for getting status for Valley View/Baytrail display */
44 #define VLV_DISPLAY_POS         6
45 /* Subsystem config/status display for Cherry Trail SOC */
46 #define CHT_DSP_SSS             0x36
47 /* Shift bits for getting status for display */
48 #define CHT_DSP_SSS_POS         16
49
50 struct punit_device {
51         char *name;
52         int reg;
53         int sss_pos;
54 };
55
56 static const struct punit_device punit_device_byt[] = {
57         { "GFX RENDER", PWRGT_STATUS,   RENDER_POS },
58         { "GFX MEDIA",  PWRGT_STATUS,   MEDIA_POS },
59         { "DISPLAY",    PWRGT_STATUS,   VLV_DISPLAY_POS },
60         { "VED",        VED_SS_PM0,     SSS_SHIFT },
61         { "ISP",        ISP_SS_PM0,     SSS_SHIFT },
62         { "MIO",        MIO_SS_PM,      SSS_SHIFT },
63         { NULL }
64 };
65
66 static const struct punit_device punit_device_cht[] = {
67         { "GFX RENDER", PWRGT_STATUS,   RENDER_POS },
68         { "GFX MEDIA",  PWRGT_STATUS,   MEDIA_POS },
69         { "DISPLAY",    CHT_DSP_SSS,    CHT_DSP_SSS_POS },
70         { "VED",        VED_SS_PM0,     SSS_SHIFT },
71         { "ISP",        ISP_SS_PM0,     SSS_SHIFT },
72         { "MIO",        MIO_SS_PM,      SSS_SHIFT },
73         { NULL }
74 };
75
76 static const char * const dstates[] = {"D0", "D0i1", "D0i2", "D0i3"};
77
78 static int punit_dev_state_show(struct seq_file *seq_file, void *unused)
79 {
80         u32 punit_pwr_status;
81         struct punit_device *punit_devp = seq_file->private;
82         int index;
83         int status;
84
85         seq_puts(seq_file, "\n\nPUNIT NORTH COMPLEX DEVICES :\n");
86         while (punit_devp->name) {
87                 status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
88                                        punit_devp->reg, &punit_pwr_status);
89                 if (status) {
90                         seq_printf(seq_file, "%9s : Read Failed\n",
91                                    punit_devp->name);
92                 } else  {
93                         index = (punit_pwr_status >> punit_devp->sss_pos) & 3;
94                         seq_printf(seq_file, "%9s : %s\n", punit_devp->name,
95                                    dstates[index]);
96                 }
97                 punit_devp++;
98         }
99
100         return 0;
101 }
102
103 static int punit_dev_state_open(struct inode *inode, struct file *file)
104 {
105         return single_open(file, punit_dev_state_show, inode->i_private);
106 }
107
108 static const struct file_operations punit_dev_state_ops = {
109         .open           = punit_dev_state_open,
110         .read           = seq_read,
111         .llseek         = seq_lseek,
112         .release        = single_release,
113 };
114
115 static struct dentry *punit_dbg_file;
116
117 static int punit_dbgfs_register(struct punit_device *punit_device)
118 {
119         static struct dentry *dev_state;
120
121         punit_dbg_file = debugfs_create_dir("punit_atom", NULL);
122         if (!punit_dbg_file)
123                 return -ENXIO;
124
125         dev_state = debugfs_create_file("dev_power_state", S_IFREG | S_IRUGO,
126                                         punit_dbg_file, punit_device,
127                                         &punit_dev_state_ops);
128         if (!dev_state) {
129                 pr_err("punit_dev_state register failed\n");
130                 debugfs_remove(punit_dbg_file);
131                 return -ENXIO;
132         }
133
134         return 0;
135 }
136
137 static void punit_dbgfs_unregister(void)
138 {
139         debugfs_remove_recursive(punit_dbg_file);
140 }
141
142 #define ICPU(model, drv_data) \
143         { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT,\
144           (kernel_ulong_t)&drv_data }
145
146 static const struct x86_cpu_id intel_punit_cpu_ids[] = {
147         ICPU(INTEL_FAM6_ATOM_SILVERMONT1, punit_device_byt),
148         ICPU(INTEL_FAM6_ATOM_AIRMONT,     punit_device_cht),
149         {}
150 };
151
152 MODULE_DEVICE_TABLE(x86cpu, intel_punit_cpu_ids);
153
154 static int __init punit_atom_debug_init(void)
155 {
156         const struct x86_cpu_id *id;
157         int ret;
158
159         id = x86_match_cpu(intel_punit_cpu_ids);
160         if (!id)
161                 return -ENODEV;
162
163         ret = punit_dbgfs_register((struct punit_device *)id->driver_data);
164         if (ret < 0)
165                 return ret;
166
167         return 0;
168 }
169
170 static void __exit punit_atom_debug_exit(void)
171 {
172         punit_dbgfs_unregister();
173 }
174
175 module_init(punit_atom_debug_init);
176 module_exit(punit_atom_debug_exit);
177
178 MODULE_AUTHOR("Kumar P, Mahesh <mahesh.kumar.p@intel.com>");
179 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
180 MODULE_DESCRIPTION("Driver for Punit devices states debugging");
181 MODULE_LICENSE("GPL v2");