| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2009-2010 Intel Corporation |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 5 | | - * under the terms and conditions of the GNU General Public License, |
|---|
| 6 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 9 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 10 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 11 | | - * more details. |
|---|
| 12 | | - * |
|---|
| 13 | | - * The full GNU General Public License is included in this distribution in |
|---|
| 14 | | - * the file called "COPYING". |
|---|
| 15 | 4 | * |
|---|
| 16 | 5 | * Authors: |
|---|
| 17 | 6 | * Jesse Barnes <jbarnes@virtuousgeek.org> |
|---|
| .. | .. |
|---|
| 1221 | 1210 | |
|---|
| 1222 | 1211 | /* Expose current state and limits in debugfs if possible */ |
|---|
| 1223 | 1212 | |
|---|
| 1224 | | -struct ips_debugfs_node { |
|---|
| 1225 | | - struct ips_driver *ips; |
|---|
| 1226 | | - char *name; |
|---|
| 1227 | | - int (*show)(struct seq_file *m, void *data); |
|---|
| 1228 | | -}; |
|---|
| 1229 | | - |
|---|
| 1230 | | -static int show_cpu_temp(struct seq_file *m, void *data) |
|---|
| 1213 | +static int cpu_temp_show(struct seq_file *m, void *data) |
|---|
| 1231 | 1214 | { |
|---|
| 1232 | 1215 | struct ips_driver *ips = m->private; |
|---|
| 1233 | 1216 | |
|---|
| .. | .. |
|---|
| 1236 | 1219 | |
|---|
| 1237 | 1220 | return 0; |
|---|
| 1238 | 1221 | } |
|---|
| 1222 | +DEFINE_SHOW_ATTRIBUTE(cpu_temp); |
|---|
| 1239 | 1223 | |
|---|
| 1240 | | -static int show_cpu_power(struct seq_file *m, void *data) |
|---|
| 1224 | +static int cpu_power_show(struct seq_file *m, void *data) |
|---|
| 1241 | 1225 | { |
|---|
| 1242 | 1226 | struct ips_driver *ips = m->private; |
|---|
| 1243 | 1227 | |
|---|
| .. | .. |
|---|
| 1245 | 1229 | |
|---|
| 1246 | 1230 | return 0; |
|---|
| 1247 | 1231 | } |
|---|
| 1232 | +DEFINE_SHOW_ATTRIBUTE(cpu_power); |
|---|
| 1248 | 1233 | |
|---|
| 1249 | | -static int show_cpu_clamp(struct seq_file *m, void *data) |
|---|
| 1234 | +static int cpu_clamp_show(struct seq_file *m, void *data) |
|---|
| 1250 | 1235 | { |
|---|
| 1251 | 1236 | u64 turbo_override; |
|---|
| 1252 | 1237 | int tdp, tdc; |
|---|
| .. | .. |
|---|
| 1266 | 1251 | |
|---|
| 1267 | 1252 | return 0; |
|---|
| 1268 | 1253 | } |
|---|
| 1254 | +DEFINE_SHOW_ATTRIBUTE(cpu_clamp); |
|---|
| 1269 | 1255 | |
|---|
| 1270 | | -static int show_mch_temp(struct seq_file *m, void *data) |
|---|
| 1256 | +static int mch_temp_show(struct seq_file *m, void *data) |
|---|
| 1271 | 1257 | { |
|---|
| 1272 | 1258 | struct ips_driver *ips = m->private; |
|---|
| 1273 | 1259 | |
|---|
| .. | .. |
|---|
| 1276 | 1262 | |
|---|
| 1277 | 1263 | return 0; |
|---|
| 1278 | 1264 | } |
|---|
| 1265 | +DEFINE_SHOW_ATTRIBUTE(mch_temp); |
|---|
| 1279 | 1266 | |
|---|
| 1280 | | -static int show_mch_power(struct seq_file *m, void *data) |
|---|
| 1267 | +static int mch_power_show(struct seq_file *m, void *data) |
|---|
| 1281 | 1268 | { |
|---|
| 1282 | 1269 | struct ips_driver *ips = m->private; |
|---|
| 1283 | 1270 | |
|---|
| .. | .. |
|---|
| 1285 | 1272 | |
|---|
| 1286 | 1273 | return 0; |
|---|
| 1287 | 1274 | } |
|---|
| 1288 | | - |
|---|
| 1289 | | -static struct ips_debugfs_node ips_debug_files[] = { |
|---|
| 1290 | | - { NULL, "cpu_temp", show_cpu_temp }, |
|---|
| 1291 | | - { NULL, "cpu_power", show_cpu_power }, |
|---|
| 1292 | | - { NULL, "cpu_clamp", show_cpu_clamp }, |
|---|
| 1293 | | - { NULL, "mch_temp", show_mch_temp }, |
|---|
| 1294 | | - { NULL, "mch_power", show_mch_power }, |
|---|
| 1295 | | -}; |
|---|
| 1296 | | - |
|---|
| 1297 | | -static int ips_debugfs_open(struct inode *inode, struct file *file) |
|---|
| 1298 | | -{ |
|---|
| 1299 | | - struct ips_debugfs_node *node = inode->i_private; |
|---|
| 1300 | | - |
|---|
| 1301 | | - return single_open(file, node->show, node->ips); |
|---|
| 1302 | | -} |
|---|
| 1303 | | - |
|---|
| 1304 | | -static const struct file_operations ips_debugfs_ops = { |
|---|
| 1305 | | - .owner = THIS_MODULE, |
|---|
| 1306 | | - .open = ips_debugfs_open, |
|---|
| 1307 | | - .read = seq_read, |
|---|
| 1308 | | - .llseek = seq_lseek, |
|---|
| 1309 | | - .release = single_release, |
|---|
| 1310 | | -}; |
|---|
| 1275 | +DEFINE_SHOW_ATTRIBUTE(mch_power); |
|---|
| 1311 | 1276 | |
|---|
| 1312 | 1277 | static void ips_debugfs_cleanup(struct ips_driver *ips) |
|---|
| 1313 | 1278 | { |
|---|
| 1314 | | - if (ips->debug_root) |
|---|
| 1315 | | - debugfs_remove_recursive(ips->debug_root); |
|---|
| 1316 | | - return; |
|---|
| 1279 | + debugfs_remove_recursive(ips->debug_root); |
|---|
| 1317 | 1280 | } |
|---|
| 1318 | 1281 | |
|---|
| 1319 | 1282 | static void ips_debugfs_init(struct ips_driver *ips) |
|---|
| 1320 | 1283 | { |
|---|
| 1321 | | - int i; |
|---|
| 1322 | | - |
|---|
| 1323 | 1284 | ips->debug_root = debugfs_create_dir("ips", NULL); |
|---|
| 1324 | | - if (!ips->debug_root) { |
|---|
| 1325 | | - dev_err(ips->dev, "failed to create debugfs entries: %ld\n", |
|---|
| 1326 | | - PTR_ERR(ips->debug_root)); |
|---|
| 1327 | | - return; |
|---|
| 1328 | | - } |
|---|
| 1329 | 1285 | |
|---|
| 1330 | | - for (i = 0; i < ARRAY_SIZE(ips_debug_files); i++) { |
|---|
| 1331 | | - struct dentry *ent; |
|---|
| 1332 | | - struct ips_debugfs_node *node = &ips_debug_files[i]; |
|---|
| 1333 | | - |
|---|
| 1334 | | - node->ips = ips; |
|---|
| 1335 | | - ent = debugfs_create_file(node->name, S_IFREG | S_IRUGO, |
|---|
| 1336 | | - ips->debug_root, node, |
|---|
| 1337 | | - &ips_debugfs_ops); |
|---|
| 1338 | | - if (!ent) { |
|---|
| 1339 | | - dev_err(ips->dev, "failed to create debug file: %ld\n", |
|---|
| 1340 | | - PTR_ERR(ent)); |
|---|
| 1341 | | - goto err_cleanup; |
|---|
| 1342 | | - } |
|---|
| 1343 | | - } |
|---|
| 1344 | | - |
|---|
| 1345 | | - return; |
|---|
| 1346 | | - |
|---|
| 1347 | | -err_cleanup: |
|---|
| 1348 | | - ips_debugfs_cleanup(ips); |
|---|
| 1349 | | - return; |
|---|
| 1286 | + debugfs_create_file("cpu_temp", 0444, ips->debug_root, ips, &cpu_temp_fops); |
|---|
| 1287 | + debugfs_create_file("cpu_power", 0444, ips->debug_root, ips, &cpu_power_fops); |
|---|
| 1288 | + debugfs_create_file("cpu_clamp", 0444, ips->debug_root, ips, &cpu_clamp_fops); |
|---|
| 1289 | + debugfs_create_file("mch_temp", 0444, ips->debug_root, ips, &mch_temp_fops); |
|---|
| 1290 | + debugfs_create_file("mch_power", 0444, ips->debug_root, ips, &mch_power_fops); |
|---|
| 1350 | 1291 | } |
|---|
| 1351 | 1292 | #endif /* CONFIG_DEBUG_FS */ |
|---|
| 1352 | 1293 | |
|---|
| .. | .. |
|---|
| 1657 | 1598 | struct ips_driver *ips = pci_get_drvdata(dev); |
|---|
| 1658 | 1599 | u64 turbo_override; |
|---|
| 1659 | 1600 | |
|---|
| 1660 | | - if (!ips) |
|---|
| 1661 | | - return; |
|---|
| 1662 | | - |
|---|
| 1663 | 1601 | ips_debugfs_cleanup(ips); |
|---|
| 1664 | 1602 | |
|---|
| 1665 | 1603 | /* Release i915 driver */ |
|---|
| .. | .. |
|---|
| 1697 | 1635 | |
|---|
| 1698 | 1636 | module_pci_driver(ips_pci_driver); |
|---|
| 1699 | 1637 | |
|---|
| 1700 | | -MODULE_LICENSE("GPL"); |
|---|
| 1638 | +MODULE_LICENSE("GPL v2"); |
|---|
| 1701 | 1639 | MODULE_AUTHOR("Jesse Barnes <jbarnes@virtuousgeek.org>"); |
|---|
| 1702 | 1640 | MODULE_DESCRIPTION("Intelligent Power Sharing Driver"); |
|---|