linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.arm.linux.org.uk,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Luotao Fu <l.fu@pengutronix.de>,
	Hans de Goede <hdegoede@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Eric Piel <eric.piel@tremplin-utc.net>,
	lm-sensors@lm-sensors.org
Subject: [PATCH 3/5] [hwmon] add Freescale MC13783 adc driver
Date: Tue, 11 Aug 2009 11:07:45 +0200	[thread overview]
Message-ID: <1249981667-4366-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1249981667-4366-3-git-send-email-s.hauer@pengutronix.de>

From: Luotao Fu <l.fu@pengutronix.de>

This driver provides support for the ADC integrated into the
Freescale MC13783 PMIC.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Eric Piel <eric.piel@tremplin-utc.net>
Cc: lm-sensors@lm-sensors.org
---
 drivers/hwmon/Kconfig       |    6 ++
 drivers/hwmon/Makefile      |    1 +
 drivers/hwmon/mc13783-adc.c |  181 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 188 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/mc13783-adc.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 2d50166..a7e34fd 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1017,6 +1017,12 @@ config SENSORS_APPLESMC
 	  Say Y here if you have an applicable laptop and want to experience
 	  the awesome power of applesmc.
 
+config SENSORS_MC13783_ADC
+        tristate "Freescale MC13783 ADC"
+        depends on MFD_MC13783
+        help
+          Support for the ad converter on mc13783 pmic.
+
 config HWMON_DEBUG_CHIP
 	bool "Hardware Monitoring Chip debugging messages"
 	default n
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index b793dce..9b4e131 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -89,6 +89,7 @@ obj-$(CONFIG_SENSORS_VT8231)	+= vt8231.o
 obj-$(CONFIG_SENSORS_W83627EHF)	+= w83627ehf.o
 obj-$(CONFIG_SENSORS_W83L785TS)	+= w83l785ts.o
 obj-$(CONFIG_SENSORS_W83L786NG)	+= w83l786ng.o
+obj-$(CONFIG_SENSORS_MC13783_ADC)       += mc13783-adc.o
 
 ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
new file mode 100644
index 0000000..885c009
--- /dev/null
+++ b/drivers/hwmon/mc13783-adc.c
@@ -0,0 +1,181 @@
+/*
+ * 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
+ */
+
+#include <linux/mfd/mc13783-private.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/completion.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/hwmon.h>
+#include <linux/input.h>
+#include <linux/mutex.h>
+#include <linux/sched.h>
+#include <linux/init.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 ssize_t mc13783_adc_read(struct device *dev,
+		struct device_attribute *devattr, char *buf)
+{
+	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 res;
+	unsigned int sample[4];
+
+	mc13783_adc_do_conversion(priv->mc13783, MC13783_ADC_MODE_MULT_CHAN,
+			channel, sample);
+
+	channel &= 0x7;
+
+	res = (sample[channel % 4] >> (channel > 3 ? 14 : 2)) & 0x3ff;
+
+	return sprintf(buf, "%u\n", res);
+}
+
+static struct sensor_device_attribute mc13783_adc_ctl[] = {
+	SENSOR_ATTR(name, S_IRUGO, mc13783_adc_show_name, NULL, 0),
+	SENSOR_ATTR(in0_input, S_IRUGO, mc13783_adc_read, NULL, 0),
+	SENSOR_ATTR(in1_input, S_IRUGO, mc13783_adc_read, NULL, 1),
+	SENSOR_ATTR(in2_input, S_IRUGO, mc13783_adc_read, NULL, 2),
+	SENSOR_ATTR(in3_input, S_IRUGO, mc13783_adc_read, NULL, 3),
+	SENSOR_ATTR(in4_input, S_IRUGO, mc13783_adc_read, NULL, 4),
+	SENSOR_ATTR(in5_input, S_IRUGO, mc13783_adc_read, NULL, 5),
+	SENSOR_ATTR(in6_input, S_IRUGO, mc13783_adc_read, NULL, 6),
+	SENSOR_ATTR(in7_input, S_IRUGO, mc13783_adc_read, NULL, 7),
+	SENSOR_ATTR(in8_input, S_IRUGO, mc13783_adc_read, NULL, 8),
+	SENSOR_ATTR(in9_input, S_IRUGO, mc13783_adc_read, NULL, 9),
+	SENSOR_ATTR(in10_input, S_IRUGO, mc13783_adc_read, NULL, 10),
+	SENSOR_ATTR(in11_input, S_IRUGO, mc13783_adc_read, NULL, 11),
+	SENSOR_ATTR(in12_input, S_IRUGO, mc13783_adc_read, NULL, 12),
+	SENSOR_ATTR(in13_input, S_IRUGO, mc13783_adc_read, NULL, 13),
+	SENSOR_ATTR(in14_input, S_IRUGO, mc13783_adc_read, NULL, 14),
+	SENSOR_ATTR(in15_input, S_IRUGO, mc13783_adc_read, NULL, 15),
+};
+
+static int __init mc13783_adc_probe(struct platform_device *pdev)
+{
+	struct mc13783_adc_priv *priv;
+	int ret, i;
+	int entries;
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->mc13783 = pdev->dev.platform_data;
+
+	entries = ARRAY_SIZE(mc13783_adc_ctl);
+
+	/* last four channels may be occupied by the touchscreen */
+	if (priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)
+		entries -= 4;
+
+	for (i = 0; i < entries; i++) {
+		ret = device_create_file(&pdev->dev,
+				&mc13783_adc_ctl[i].dev_attr);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"device_create_file failed with %d.\n", ret);
+			goto out_err;
+		}
+	}
+
+	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;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	return 0;
+
+out_err:
+	for (i--; i >= 0; i--)
+		device_remove_file(&pdev->dev, &mc13783_adc_ctl[i].dev_attr);
+
+	kfree(priv);
+
+	return ret;
+}
+
+static int __devexit mc13783_adc_remove(struct platform_device *pdev)
+{
+	struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
+	int entries;
+	int i;
+
+	hwmon_device_unregister(&pdev->dev);
+
+	entries = ARRAY_SIZE(mc13783_adc_ctl);
+
+	if (priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)
+		entries -= 4;
+
+	for (i = 0; i < entries; i++)
+		device_remove_file(&pdev->dev, &mc13783_adc_ctl[i].dev_attr);
+
+	kfree(priv);
+
+	return 0;
+}
+
+static struct platform_driver mc13783_adc_driver = {
+	.probe		= mc13783_adc_probe,
+	.remove 	= __devexit_p(mc13783_adc_remove),
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= MC13783_ADC_NAME,
+	},
+};
+
+static int __init mc13783_adc_init(void)
+{
+	return platform_driver_register(&mc13783_adc_driver);
+}
+
+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 input touchscreen driver");
+MODULE_AUTHOR("Luotao Fu, <l.fu@pengutronix.de>");
+MODULE_LICENSE("GPL");
-- 
1.6.3.3


  reply	other threads:[~2009-08-11 12:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-11  9:07 [RFC] Freescale MC13783 PMIC support Sascha Hauer
2009-08-11  9:07 ` [PATCH 1/5] drivers/mfd: Add Freescale MC13783 driver Sascha Hauer
2009-08-11  9:07   ` [PATCH 2/5] [input] add mc13783 touchscreen driver Sascha Hauer
2009-08-11  9:07     ` Sascha Hauer [this message]
2009-08-11  9:07       ` [PATCH 4/5] [RTC] Add Freescale MC13783 RTC driver Sascha Hauer
2009-08-11  9:07         ` [PATCH 5/5] [regulator] Add a Freescale MC13783 regulator driver Sascha Hauer
2009-08-11 10:19           ` Mark Brown
2009-08-12  2:15     ` [PATCH 2/5] [input] add mc13783 touchscreen driver Dmitry Torokhov
2009-08-12 11:10       ` Sascha Hauer
2009-08-12 11:16         ` Mark Brown
2009-08-12 11:34           ` Sascha Hauer
2009-08-12 16:01         ` Dmitry Torokhov
2009-08-11 10:12   ` [PATCH 1/5] drivers/mfd: Add Freescale MC13783 driver Mark Brown
2009-08-11 11:38     ` Sascha Hauer
2009-08-11 10:15   ` Mark Brown
2009-08-11 12:05 ` [RFC] Freescale MC13783 PMIC support Antonio Ospite
2009-08-11 12:28   ` Mark Brown
2009-08-15  1:17     ` Daniel Ribeiro
2009-08-11 13:57   ` Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2009-08-12 15:05 [PATCH V2] " Sascha Hauer
2009-08-12 15:05 ` [PATCH 1/5] drivers/mfd: Add Freescale MC13783 driver Sascha Hauer
2009-08-12 15:05   ` [PATCH 2/5] [input] add mc13783 touchscreen driver Sascha Hauer
2009-08-12 15:05     ` [PATCH 3/5] [hwmon] add Freescale MC13783 adc driver Sascha Hauer
     [not found] <1249981166-4210-1-git-send-email-s.hauer@pengutronix.de>
2009-08-11  8:59 ` [PATCH 2/5] [input] add mc13783 touchscreen driver Sascha Hauer
2009-08-11  8:59   ` [PATCH 3/5] [hwmon] add Freescale MC13783 adc driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1249981667-4366-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=eric.piel@tremplin-utc.net \
    --cc=hdegoede@redhat.com \
    --cc=l.fu@pengutronix.de \
    --cc=linux-arm-kernel@lists.arm.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).