forked from Minki/linux
30304e5a79
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJPcXgCAAoJEIqAPN1PVmxKh2oP/2Ns+dr4oOF8z+uqYG1oisJd CxBTC1Bi9gYBtpiMztPiHZWiQtVXoDgLbLkx6ooWH5dpwCdvU6TVBZUJp4wpELtx mMk5vJy4/INHgI0nk5wUOr76rNlQfIcK04f+LHBSG1iljUkoVR3FefVKgoyIP+Wv oiCeuCyQcYIUmG1pVt1x43OoS+2xgjWQA67AalLLRj1DOA5OkvUL7NGsrZ1iZTUh YHQJsK6ER3MgbFFEImtn10NNFwAEG04o6vi42DFW1O0awm6kmVoLjo46wS+UiKoh Vx8t5ZGvlYOZ1ZM9N5ETgQnihBt7cOhA3ivZar8h+WiYVTRJs1ZSkpmnlpmM4YY9 RCZ5DRw3N39R0ezkNVGSr1Xn1vkysIiZI82frrJiPUYLKihsrBzj2Jq3O25iILCf Iyv7HBEJxAb3x0zlF6kPhaA8OW4dssaHTLNx5IJSOKwiwVLdm4RPyOHh9QVz++p/ p0hvSQWK1MUruBbBrjF/FN+FidgK2iU0iDW/GoDwI7OKymSxg7sauLtp0cZpo6nT F+Ep6yl/uR5vxih4LSYFJOjoeKuwIo/x92H0qJ3UroaUs9DNJ7UCKchXXiQ1Wtnz tAAsWP1YsMxMzlMxqW5J9w4LJynJ8bqrC0L8+HWzIUwikA8wv8/47Pmc/vPW0Y3N 5L7KMS8/iFCsS8rPmGeP =onDl -----END PGP SIGNATURE----- Merge tag 'mfd_3.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6 Pull MFD changes from Samuel Ortiz: - 4 new drivers: Freescale i.MX on-chip Anatop, Ricoh's RC5T583 and TI's TPS65090 and TPS65217. - New variants support (8420, 8520 ab9540), cleanups and bug fixes for the abx500 and db8500 ST-E chipsets. - Some minor fixes and update for the wm8994 from Mark. - The beginning of a long term TWL cleanup effort coming from the TI folks. - Various fixes and cleanups for the s5m, TPS659xx, pm860x, and MAX8997 drivers. Fix up trivial conflicts due to duplicate patches and header file cleanups (<linux/device.h> removal etc). * tag 'mfd_3.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6: (97 commits) gpio/twl: Add DT support to gpio-twl4030 driver gpio/twl: Allocate irq_desc dynamically for SPARSE_IRQ support mfd: Detach twl6040 from the pmic mfd driver mfd: Replace twl-* pr_ macros by the dev_ equivalent and do various cleanups mfd: Micro-optimization on twl4030 IRQ handler mfd: Make twl4030 SIH SPARSE_IRQ capable mfd: Move twl-core IRQ allocation into twl[4030|6030]-irq files mfd: Remove references already defineid in header file from twl-core mfd: Remove unneeded header from twl-core mfd: Make twl-core not depend on pdata->irq_base/end ARM: OMAP2+: board-omap4-*: Do not use anymore TWL6030_IRQ_BASE in board files mfd: Return twl6030_mmc_card_detect IRQ for board setup Revert "mfd: Add platform data for MAX8997 haptic driver" mfd: Add support for TPS65090 mfd: Add some da9052-i2c section annotations mfd: Build rtc5t583 only if I2C config is selected to y. mfd: Add anatop mfd driver mfd: Fix compilation error in tps65910.h mfd: Add 8420 variant to db8500-prcmu mfd: Add 8520 PRCMU variant to db8500-prcmu ...
300 lines
8.3 KiB
C
300 lines
8.3 KiB
C
/*
|
|
* Driver for the ADC on Freescale Semiconductor MC13783 and MC13892 PMICs.
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
#include <linux/mfd/mc13xxx.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/hwmon-sysfs.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/hwmon.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/init.h>
|
|
#include <linux/err.h>
|
|
|
|
#define DRIVER_NAME "mc13783-adc"
|
|
|
|
/* platform device id driver data */
|
|
#define MC13783_ADC_16CHANS 1
|
|
#define MC13783_ADC_BPDIV2 2
|
|
|
|
struct mc13783_adc_priv {
|
|
struct mc13xxx *mc13xxx;
|
|
struct device *hwmon_dev;
|
|
char name[10];
|
|
};
|
|
|
|
static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute
|
|
*devattr, char *buf)
|
|
{
|
|
struct mc13783_adc_priv *priv = dev_get_drvdata(dev);
|
|
|
|
return sprintf(buf, "%s\n", priv->name);
|
|
}
|
|
|
|
static int mc13783_adc_read(struct device *dev,
|
|
struct device_attribute *devattr, unsigned int *val)
|
|
{
|
|
struct mc13783_adc_priv *priv = dev_get_drvdata(dev);
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
unsigned int channel = attr->index;
|
|
unsigned int sample[4];
|
|
int ret;
|
|
|
|
ret = mc13xxx_adc_do_conversion(priv->mc13xxx,
|
|
MC13XXX_ADC_MODE_MULT_CHAN,
|
|
channel, 0, 0, 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;
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data;
|
|
int ret = mc13783_adc_read(dev, devattr, &val);
|
|
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (driver_data & MC13783_ADC_BPDIV2)
|
|
val = DIV_ROUND_CLOSEST(val * 9, 2);
|
|
else
|
|
/*
|
|
* 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_base[] = {
|
|
&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,
|
|
NULL
|
|
};
|
|
|
|
static const struct attribute_group mc13783_group_base = {
|
|
.attrs = mc13783_attr_base,
|
|
};
|
|
|
|
/* these are only used if MC13783_ADC_16CHANS is provided in driver data */
|
|
static struct attribute *mc13783_attr_16chans[] = {
|
|
&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_16chans = {
|
|
.attrs = mc13783_attr_16chans,
|
|
};
|
|
|
|
/* 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,
|
|
};
|
|
|
|
static int mc13783_adc_use_touchscreen(struct platform_device *pdev)
|
|
{
|
|
struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
|
|
unsigned flags = mc13xxx_get_flags(priv->mc13xxx);
|
|
|
|
return flags & MC13XXX_USE_TOUCHSCREEN;
|
|
}
|
|
|
|
static int __init mc13783_adc_probe(struct platform_device *pdev)
|
|
{
|
|
struct mc13783_adc_priv *priv;
|
|
int ret;
|
|
const struct platform_device_id *id = platform_get_device_id(pdev);
|
|
char *dash;
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
priv->mc13xxx = dev_get_drvdata(pdev->dev.parent);
|
|
snprintf(priv->name, ARRAY_SIZE(priv->name), "%s", id->name);
|
|
dash = strchr(priv->name, '-');
|
|
if (dash)
|
|
*dash = '\0';
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
/* Register sysfs hooks */
|
|
ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_base);
|
|
if (ret)
|
|
goto out_err_create_base;
|
|
|
|
if (id->driver_data & MC13783_ADC_16CHANS) {
|
|
ret = sysfs_create_group(&pdev->dev.kobj,
|
|
&mc13783_group_16chans);
|
|
if (ret)
|
|
goto out_err_create_16chans;
|
|
}
|
|
|
|
if (!mc13783_adc_use_touchscreen(pdev)) {
|
|
ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts);
|
|
if (ret)
|
|
goto out_err_create_ts;
|
|
}
|
|
|
|
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:
|
|
|
|
if (!mc13783_adc_use_touchscreen(pdev))
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
|
|
out_err_create_ts:
|
|
|
|
if (id->driver_data & MC13783_ADC_16CHANS)
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_16chans);
|
|
out_err_create_16chans:
|
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_base);
|
|
out_err_create_base:
|
|
|
|
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);
|
|
kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data;
|
|
|
|
hwmon_device_unregister(priv->hwmon_dev);
|
|
|
|
if (!mc13783_adc_use_touchscreen(pdev))
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
|
|
|
|
if (driver_data & MC13783_ADC_16CHANS)
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_16chans);
|
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_base);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
kfree(priv);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct platform_device_id mc13783_adc_idtable[] = {
|
|
{
|
|
.name = "mc13783-adc",
|
|
.driver_data = MC13783_ADC_16CHANS,
|
|
}, {
|
|
.name = "mc13892-adc",
|
|
.driver_data = MC13783_ADC_BPDIV2,
|
|
}, {
|
|
/* sentinel */
|
|
}
|
|
};
|
|
MODULE_DEVICE_TABLE(platform, mc13783_adc_idtable);
|
|
|
|
static struct platform_driver mc13783_adc_driver = {
|
|
.remove = __devexit_p(mc13783_adc_remove),
|
|
.driver = {
|
|
.owner = THIS_MODULE,
|
|
.name = DRIVER_NAME,
|
|
},
|
|
.id_table = mc13783_adc_idtable,
|
|
};
|
|
|
|
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");
|