mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 20:23:57 +08:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
228 lines
6.2 KiB
C
228 lines
6.2 KiB
C
/*
|
|
* drivers/hwmon/wm831x-hwmon.c - Wolfson Microelectronics WM831x PMIC
|
|
* hardware monitoring features.
|
|
*
|
|
* Copyright (C) 2009 Wolfson Microelectronics plc
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License v2 as published by the
|
|
* Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/hwmon.h>
|
|
#include <linux/hwmon-sysfs.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mfd/wm831x/core.h>
|
|
#include <linux/mfd/wm831x/auxadc.h>
|
|
|
|
struct wm831x_hwmon {
|
|
struct wm831x *wm831x;
|
|
struct device *classdev;
|
|
};
|
|
|
|
static ssize_t show_name(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return sprintf(buf, "wm831x\n");
|
|
}
|
|
|
|
static const char *input_names[] = {
|
|
[WM831X_AUX_SYSVDD] = "SYSVDD",
|
|
[WM831X_AUX_USB] = "USB",
|
|
[WM831X_AUX_BKUP_BATT] = "Backup battery",
|
|
[WM831X_AUX_BATT] = "Battery",
|
|
[WM831X_AUX_WALL] = "WALL",
|
|
[WM831X_AUX_CHIP_TEMP] = "PMIC",
|
|
[WM831X_AUX_BATT_TEMP] = "Battery",
|
|
};
|
|
|
|
|
|
static ssize_t show_voltage(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct wm831x_hwmon *hwmon = dev_get_drvdata(dev);
|
|
int channel = to_sensor_dev_attr(attr)->index;
|
|
int ret;
|
|
|
|
ret = wm831x_auxadc_read_uv(hwmon->wm831x, channel);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
return sprintf(buf, "%d\n", DIV_ROUND_CLOSEST(ret, 1000));
|
|
}
|
|
|
|
static ssize_t show_chip_temp(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct wm831x_hwmon *hwmon = dev_get_drvdata(dev);
|
|
int channel = to_sensor_dev_attr(attr)->index;
|
|
int ret;
|
|
|
|
ret = wm831x_auxadc_read(hwmon->wm831x, channel);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
/* Degrees celsius = (512.18-ret) / 1.0983 */
|
|
ret = 512180 - (ret * 1000);
|
|
ret = DIV_ROUND_CLOSEST(ret * 10000, 10983);
|
|
|
|
return sprintf(buf, "%d\n", ret);
|
|
}
|
|
|
|
static ssize_t show_label(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
int channel = to_sensor_dev_attr(attr)->index;
|
|
|
|
return sprintf(buf, "%s\n", input_names[channel]);
|
|
}
|
|
|
|
#define WM831X_VOLTAGE(id, name) \
|
|
static SENSOR_DEVICE_ATTR(in##id##_input, S_IRUGO, show_voltage, \
|
|
NULL, name)
|
|
|
|
#define WM831X_NAMED_VOLTAGE(id, name) \
|
|
WM831X_VOLTAGE(id, name); \
|
|
static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \
|
|
NULL, name)
|
|
|
|
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
|
|
|
|
WM831X_VOLTAGE(0, WM831X_AUX_AUX1);
|
|
WM831X_VOLTAGE(1, WM831X_AUX_AUX2);
|
|
WM831X_VOLTAGE(2, WM831X_AUX_AUX3);
|
|
WM831X_VOLTAGE(3, WM831X_AUX_AUX4);
|
|
|
|
WM831X_NAMED_VOLTAGE(4, WM831X_AUX_SYSVDD);
|
|
WM831X_NAMED_VOLTAGE(5, WM831X_AUX_USB);
|
|
WM831X_NAMED_VOLTAGE(6, WM831X_AUX_BATT);
|
|
WM831X_NAMED_VOLTAGE(7, WM831X_AUX_WALL);
|
|
WM831X_NAMED_VOLTAGE(8, WM831X_AUX_BKUP_BATT);
|
|
|
|
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_chip_temp, NULL,
|
|
WM831X_AUX_CHIP_TEMP);
|
|
static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_label, NULL,
|
|
WM831X_AUX_CHIP_TEMP);
|
|
/* Report as a voltage since conversion depends on external components
|
|
* and that's what the ABI wants. */
|
|
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_voltage, NULL,
|
|
WM831X_AUX_BATT_TEMP);
|
|
static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL,
|
|
WM831X_AUX_BATT_TEMP);
|
|
|
|
static struct attribute *wm831x_attributes[] = {
|
|
&dev_attr_name.attr,
|
|
|
|
&sensor_dev_attr_in0_input.dev_attr.attr,
|
|
&sensor_dev_attr_in1_input.dev_attr.attr,
|
|
&sensor_dev_attr_in2_input.dev_attr.attr,
|
|
&sensor_dev_attr_in3_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in4_input.dev_attr.attr,
|
|
&sensor_dev_attr_in4_label.dev_attr.attr,
|
|
&sensor_dev_attr_in5_input.dev_attr.attr,
|
|
&sensor_dev_attr_in5_label.dev_attr.attr,
|
|
&sensor_dev_attr_in6_input.dev_attr.attr,
|
|
&sensor_dev_attr_in6_label.dev_attr.attr,
|
|
&sensor_dev_attr_in7_input.dev_attr.attr,
|
|
&sensor_dev_attr_in7_label.dev_attr.attr,
|
|
&sensor_dev_attr_in8_input.dev_attr.attr,
|
|
&sensor_dev_attr_in8_label.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
|
&sensor_dev_attr_temp1_label.dev_attr.attr,
|
|
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
|
&sensor_dev_attr_temp2_label.dev_attr.attr,
|
|
|
|
NULL
|
|
};
|
|
|
|
static const struct attribute_group wm831x_attr_group = {
|
|
.attrs = wm831x_attributes,
|
|
};
|
|
|
|
static int __devinit wm831x_hwmon_probe(struct platform_device *pdev)
|
|
{
|
|
struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
|
|
struct wm831x_hwmon *hwmon;
|
|
int ret;
|
|
|
|
hwmon = kzalloc(sizeof(struct wm831x_hwmon), GFP_KERNEL);
|
|
if (!hwmon)
|
|
return -ENOMEM;
|
|
|
|
hwmon->wm831x = wm831x;
|
|
|
|
ret = sysfs_create_group(&pdev->dev.kobj, &wm831x_attr_group);
|
|
if (ret)
|
|
goto err;
|
|
|
|
hwmon->classdev = hwmon_device_register(&pdev->dev);
|
|
if (IS_ERR(hwmon->classdev)) {
|
|
ret = PTR_ERR(hwmon->classdev);
|
|
goto err_sysfs;
|
|
}
|
|
|
|
platform_set_drvdata(pdev, hwmon);
|
|
|
|
return 0;
|
|
|
|
err_sysfs:
|
|
sysfs_remove_group(&pdev->dev.kobj, &wm831x_attr_group);
|
|
err:
|
|
kfree(hwmon);
|
|
return ret;
|
|
}
|
|
|
|
static int __devexit wm831x_hwmon_remove(struct platform_device *pdev)
|
|
{
|
|
struct wm831x_hwmon *hwmon = platform_get_drvdata(pdev);
|
|
|
|
hwmon_device_unregister(hwmon->classdev);
|
|
sysfs_remove_group(&pdev->dev.kobj, &wm831x_attr_group);
|
|
platform_set_drvdata(pdev, NULL);
|
|
kfree(hwmon);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver wm831x_hwmon_driver = {
|
|
.probe = wm831x_hwmon_probe,
|
|
.remove = __devexit_p(wm831x_hwmon_remove),
|
|
.driver = {
|
|
.name = "wm831x-hwmon",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
};
|
|
|
|
static int __init wm831x_hwmon_init(void)
|
|
{
|
|
return platform_driver_register(&wm831x_hwmon_driver);
|
|
}
|
|
module_init(wm831x_hwmon_init);
|
|
|
|
static void __exit wm831x_hwmon_exit(void)
|
|
{
|
|
platform_driver_unregister(&wm831x_hwmon_driver);
|
|
}
|
|
module_exit(wm831x_hwmon_exit);
|
|
|
|
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
|
|
MODULE_DESCRIPTION("WM831x Hardware Monitoring");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:wm831x-hwmon");
|