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.)
6 * Copyright (c) 2015, Intel Corporation.
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.
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
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>
25 #include <asm/cpu_device_id.h>
26 #include <asm/iosf_mbi.h>
28 /* Power gate status reg */
29 #define PWRGT_STATUS 0x61
30 /* Subsystem config/status Video processor */
31 #define VED_SS_PM0 0x32
32 /* Subsystem config/status ISP (Image Signal Processor) */
33 #define ISP_SS_PM0 0x39
34 /* Subsystem config/status Input/output controller */
35 #define MIO_SS_PM 0x3B
36 /* Shift bits for getting status for video, isp and i/o */
38 /* Shift bits for getting status for graphics rendering */
40 /* Shift bits for getting status for media control */
42 /* Shift bits for getting status for Valley View/Baytrail display */
43 #define VLV_DISPLAY_POS 6
44 /* Subsystem config/status display for Cherry Trail SOC */
45 #define CHT_DSP_SSS 0x36
46 /* Shift bits for getting status for display */
47 #define CHT_DSP_SSS_POS 16
55 static const struct punit_device punit_device_byt[] = {
56 { "GFX RENDER", PWRGT_STATUS, RENDER_POS },
57 { "GFX MEDIA", PWRGT_STATUS, MEDIA_POS },
58 { "DISPLAY", PWRGT_STATUS, VLV_DISPLAY_POS },
59 { "VED", VED_SS_PM0, SSS_SHIFT },
60 { "ISP", ISP_SS_PM0, SSS_SHIFT },
61 { "MIO", MIO_SS_PM, SSS_SHIFT },
65 static const struct punit_device punit_device_cht[] = {
66 { "GFX RENDER", PWRGT_STATUS, RENDER_POS },
67 { "GFX MEDIA", PWRGT_STATUS, MEDIA_POS },
68 { "DISPLAY", CHT_DSP_SSS, CHT_DSP_SSS_POS },
69 { "VED", VED_SS_PM0, SSS_SHIFT },
70 { "ISP", ISP_SS_PM0, SSS_SHIFT },
71 { "MIO", MIO_SS_PM, SSS_SHIFT },
75 static const char * const dstates[] = {"D0", "D0i1", "D0i2", "D0i3"};
77 static int punit_dev_state_show(struct seq_file *seq_file, void *unused)
80 struct punit_device *punit_devp = seq_file->private;
84 seq_puts(seq_file, "\n\nPUNIT NORTH COMPLEX DEVICES :\n");
85 while (punit_devp->name) {
86 status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
87 punit_devp->reg, &punit_pwr_status);
89 seq_printf(seq_file, "%9s : Read Failed\n",
92 index = (punit_pwr_status >> punit_devp->sss_pos) & 3;
93 seq_printf(seq_file, "%9s : %s\n", punit_devp->name,
102 static int punit_dev_state_open(struct inode *inode, struct file *file)
104 return single_open(file, punit_dev_state_show, inode->i_private);
107 static const struct file_operations punit_dev_state_ops = {
108 .open = punit_dev_state_open,
111 .release = single_release,
114 static struct dentry *punit_dbg_file;
116 static int punit_dbgfs_register(struct punit_device *punit_device)
118 static struct dentry *dev_state;
120 punit_dbg_file = debugfs_create_dir("punit_atom", NULL);
124 dev_state = debugfs_create_file("dev_power_state", S_IFREG | S_IRUGO,
125 punit_dbg_file, punit_device,
126 &punit_dev_state_ops);
128 pr_err("punit_dev_state register failed\n");
129 debugfs_remove(punit_dbg_file);
136 static void punit_dbgfs_unregister(void)
138 debugfs_remove_recursive(punit_dbg_file);
141 #define ICPU(model, drv_data) \
142 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT,\
143 (kernel_ulong_t)&drv_data }
145 static const struct x86_cpu_id intel_punit_cpu_ids[] = {
146 ICPU(55, punit_device_byt), /* Valleyview, Bay Trail */
147 ICPU(76, punit_device_cht), /* Braswell, Cherry Trail */
151 MODULE_DEVICE_TABLE(x86cpu, intel_punit_cpu_ids);
153 static int __init punit_atom_debug_init(void)
155 const struct x86_cpu_id *id;
158 id = x86_match_cpu(intel_punit_cpu_ids);
162 ret = punit_dbgfs_register((struct punit_device *)id->driver_data);
169 static void __exit punit_atom_debug_exit(void)
171 punit_dbgfs_unregister();
174 module_init(punit_atom_debug_init);
175 module_exit(punit_atom_debug_exit);
177 MODULE_AUTHOR("Kumar P, Mahesh <mahesh.kumar.p@intel.com>");
178 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
179 MODULE_DESCRIPTION("Driver for Punit devices states debugging");
180 MODULE_LICENSE("GPL v2");