Skip to content

Commit df2294f

Browse files
andy-shevdvhart
authored andcommitted
intel_pmc_core: Convert to DEFINE_DEBUGFS_ATTRIBUTE
Refactor the code to use the recently introduced DEFINE_DEBUGFS_ATTRIBUTE() macro to eliminate boilerplate code. Make the absence of DEBUG_FS a non-fatal error. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-and-tested-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
1 parent 6967893 commit df2294f

File tree

2 files changed

+11
-37
lines changed

2 files changed

+11
-37
lines changed

drivers/platform/x86/intel_pmc_core.c

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/init.h>
2424
#include <linux/io.h>
2525
#include <linux/pci.h>
26-
#include <linux/seq_file.h>
2726

2827
#include <asm/cpu_device_id.h>
2928
#include <asm/pmc_core.h>
@@ -77,30 +76,18 @@ int intel_pmc_slp_s0_counter_read(u32 *data)
7776
}
7877
EXPORT_SYMBOL_GPL(intel_pmc_slp_s0_counter_read);
7978

80-
#if IS_ENABLED(CONFIG_DEBUG_FS)
81-
static int pmc_core_dev_state_show(struct seq_file *s, void *unused)
79+
static int pmc_core_dev_state_get(void *data, u64 *val)
8280
{
83-
struct pmc_dev *pmcdev = s->private;
84-
u32 counter_val;
81+
struct pmc_dev *pmcdev = data;
82+
u32 value;
8583

86-
counter_val = pmc_core_reg_read(pmcdev,
87-
SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
88-
seq_printf(s, "%u\n", pmc_core_adjust_slp_s0_step(counter_val));
84+
value = pmc_core_reg_read(pmcdev, SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
85+
*val = pmc_core_adjust_slp_s0_step(value);
8986

9087
return 0;
9188
}
9289

93-
static int pmc_core_dev_state_open(struct inode *inode, struct file *file)
94-
{
95-
return single_open(file, pmc_core_dev_state_show, inode->i_private);
96-
}
97-
98-
static const struct file_operations pmc_core_dev_state_ops = {
99-
.open = pmc_core_dev_state_open,
100-
.read = seq_read,
101-
.llseek = seq_lseek,
102-
.release = single_release,
103-
};
90+
DEFINE_DEBUGFS_ATTRIBUTE(pmc_core_dev_state, pmc_core_dev_state_get, NULL, "%llu\n");
10491

10592
static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
10693
{
@@ -112,12 +99,12 @@ static int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
11299
struct dentry *dir, *file;
113100

114101
dir = debugfs_create_dir("pmc_core", NULL);
115-
if (!dir)
102+
if (IS_ERR_OR_NULL(dir))
116103
return -ENOMEM;
117104

118105
pmcdev->dbgfs_dir = dir;
119106
file = debugfs_create_file("slp_s0_residency_usec", S_IFREG | S_IRUGO,
120-
dir, pmcdev, &pmc_core_dev_state_ops);
107+
dir, pmcdev, &pmc_core_dev_state);
121108

122109
if (!file) {
123110
pmc_core_dbgfs_unregister(pmcdev);
@@ -126,16 +113,6 @@ static int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
126113

127114
return 0;
128115
}
129-
#else
130-
static inline int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
131-
{
132-
return 0;
133-
}
134-
135-
static inline void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
136-
{
137-
}
138-
#endif /* CONFIG_DEBUG_FS */
139116

140117
static const struct x86_cpu_id intel_pmc_core_ids[] = {
141118
{ X86_VENDOR_INTEL, 6, 0x4e, X86_FEATURE_MWAIT,
@@ -182,10 +159,8 @@ static int pmc_core_probe(struct pci_dev *dev, const struct pci_device_id *id)
182159
}
183160

184161
err = pmc_core_dbgfs_register(pmcdev);
185-
if (err < 0) {
186-
dev_err(&dev->dev, "PMC Core: debugfs register failed.\n");
187-
return err;
188-
}
162+
if (err < 0)
163+
dev_warn(&dev->dev, "PMC Core: debugfs register failed.\n");
189164

190165
pmc.has_slp_s0_res = true;
191166
return 0;

drivers/platform/x86/intel_pmc_core.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/* Sunrise Point Power Management Controller PCI Device ID */
2525
#define SPT_PMC_PCI_DEVICE_ID 0x9d21
26+
2627
#define SPT_PMC_BASE_ADDR_OFFSET 0x48
2728
#define SPT_PMC_SLP_S0_RES_COUNTER_OFFSET 0x13c
2829
#define SPT_PMC_MMIO_REG_LEN 0x100
@@ -42,9 +43,7 @@
4243
struct pmc_dev {
4344
u32 base_addr;
4445
void __iomem *regbase;
45-
#if IS_ENABLED(CONFIG_DEBUG_FS)
4646
struct dentry *dbgfs_dir;
47-
#endif /* CONFIG_DEBUG_FS */
4847
bool has_slp_s0_res;
4948
};
5049

0 commit comments

Comments
 (0)