Linux Audio

Check our new training course

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