2009-12-10 02:35:58 +07:00
|
|
|
/*
|
|
|
|
* Driver for the Freescale Semiconductor MC13783 adc.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
|
|
|
|
* Copyright (C) 2009 Sascha Hauer, Pengutronix
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2010-08-02 16:14:18 +07:00
|
|
|
#include <linux/mfd/mc13783.h>
|
2009-12-10 02:35:58 +07:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/hwmon-sysfs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/hwmon.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
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>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-12-10 02:35:58 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
|
|
|
|
#define MC13783_ADC_NAME "mc13783-adc"
|
|
|
|
|
|
|
|
struct mc13783_adc_priv {
|
|
|
|
struct mc13783 *mc13783;
|
|
|
|
struct device *hwmon_dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute
|
|
|
|
*devattr, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "mc13783_adc\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mc13783_adc_read(struct device *dev,
|
|
|
|
struct device_attribute *devattr, unsigned int *val)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
|
unsigned int channel = attr->index;
|
|
|
|
unsigned int sample[4];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mc13783_adc_do_conversion(priv->mc13783,
|
|
|
|
MC13783_ADC_MODE_MULT_CHAN,
|
|
|
|
channel, sample);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
channel &= 0x7;
|
|
|
|
|
|
|
|
*val = (sample[channel % 4] >> (channel > 3 ? 14 : 2)) & 0x3ff;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mc13783_adc_read_bp(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned val;
|
|
|
|
int ret = mc13783_adc_read(dev, devattr, &val);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BP (channel 2) reports with offset 2.4V to the actual value to fit
|
|
|
|
* the input range of the ADC. unit = 2.25mV = 9/4 mV.
|
|
|
|
*/
|
|
|
|
val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400;
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mc13783_adc_read_gp(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned val;
|
|
|
|
int ret = mc13783_adc_read(dev, devattr, &val);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* input range is [0, 2.3V], val has 10 bits, so each bit
|
|
|
|
* is worth 9/4 mV.
|
|
|
|
*/
|
|
|
|
val = DIV_ROUND_CLOSEST(val * 9, 4);
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(name, S_IRUGO, mc13783_adc_show_name, NULL);
|
|
|
|
static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, mc13783_adc_read_bp, NULL, 2);
|
|
|
|
static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, mc13783_adc_read_gp, NULL, 5);
|
|
|
|
static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, mc13783_adc_read_gp, NULL, 6);
|
|
|
|
static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, mc13783_adc_read_gp, NULL, 7);
|
|
|
|
static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, mc13783_adc_read_gp, NULL, 8);
|
|
|
|
static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, mc13783_adc_read_gp, NULL, 9);
|
|
|
|
static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, mc13783_adc_read_gp, NULL, 10);
|
|
|
|
static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, mc13783_adc_read_gp, NULL, 11);
|
|
|
|
static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, mc13783_adc_read_gp, NULL, 12);
|
|
|
|
static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, mc13783_adc_read_gp, NULL, 13);
|
|
|
|
static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, mc13783_adc_read_gp, NULL, 14);
|
|
|
|
static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, mc13783_adc_read_gp, NULL, 15);
|
|
|
|
|
|
|
|
static struct attribute *mc13783_attr[] = {
|
|
|
|
&dev_attr_name.attr,
|
|
|
|
&sensor_dev_attr_in2_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in5_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in6_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in7_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in8_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in9_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in10_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in11_input.dev_attr.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group mc13783_group = {
|
|
|
|
.attrs = mc13783_attr,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* last four channels may be occupied by the touchscreen */
|
|
|
|
static struct attribute *mc13783_attr_ts[] = {
|
|
|
|
&sensor_dev_attr_in12_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in13_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in14_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in15_input.dev_attr.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group mc13783_group_ts = {
|
|
|
|
.attrs = mc13783_attr_ts,
|
|
|
|
};
|
|
|
|
|
2010-08-02 16:14:18 +07:00
|
|
|
static int mc13783_adc_use_touchscreen(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
unsigned flags = mc13783_get_flags(priv->mc13783);
|
|
|
|
|
|
|
|
return flags & MC13783_USE_TOUCHSCREEN;
|
|
|
|
}
|
|
|
|
|
2009-12-10 02:35:58 +07:00
|
|
|
static int __init mc13783_adc_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct mc13783_adc_priv *priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv->mc13783 = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
|
|
|
|
/* Register sysfs hooks */
|
|
|
|
ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group);
|
|
|
|
if (ret)
|
|
|
|
goto out_err_create1;
|
|
|
|
|
2010-08-02 16:14:18 +07:00
|
|
|
if (!mc13783_adc_use_touchscreen(pdev)) {
|
2009-12-10 02:35:58 +07:00
|
|
|
ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts);
|
|
|
|
if (ret)
|
|
|
|
goto out_err_create2;
|
2010-08-02 16:14:18 +07:00
|
|
|
}
|
2009-12-10 02:35:58 +07:00
|
|
|
|
|
|
|
priv->hwmon_dev = hwmon_device_register(&pdev->dev);
|
|
|
|
if (IS_ERR(priv->hwmon_dev)) {
|
|
|
|
ret = PTR_ERR(priv->hwmon_dev);
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"hwmon_device_register failed with %d.\n", ret);
|
|
|
|
goto out_err_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err_register:
|
|
|
|
|
2010-08-02 16:14:18 +07:00
|
|
|
if (!mc13783_adc_use_touchscreen(pdev))
|
2009-12-10 02:35:58 +07:00
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
|
|
|
|
out_err_create2:
|
|
|
|
|
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
|
|
|
|
out_err_create1:
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
kfree(priv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit mc13783_adc_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
hwmon_device_unregister(priv->hwmon_dev);
|
|
|
|
|
2010-08-02 16:14:18 +07:00
|
|
|
if (!mc13783_adc_use_touchscreen(pdev))
|
2009-12-10 02:35:58 +07:00
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
|
|
|
|
|
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
kfree(priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver mc13783_adc_driver = {
|
|
|
|
.remove = __devexit_p(mc13783_adc_remove),
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = MC13783_ADC_NAME,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mc13783_adc_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_probe(&mc13783_adc_driver, mc13783_adc_probe);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mc13783_adc_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&mc13783_adc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mc13783_adc_init);
|
|
|
|
module_exit(mc13783_adc_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("MC13783 ADC driver");
|
|
|
|
MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:" MC13783_ADC_NAME);
|