* [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic JZ4740
@ 2010-06-19 5:08 Lars-Peter Clausen
2010-06-19 5:08 ` [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver Lars-Peter Clausen
2010-06-20 9:26 ` [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic Thomas Bogendoerfer
0 siblings, 2 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2010-06-19 5:08 UTC (permalink / raw)
To: Ralf Baechle
Cc: linux-mips, linux-kernel, Lars-Peter Clausen, Alessandro Zummo,
Andrew Morton, Anton Vorontsov, David Brownell, David Woodhouse,
Greg Kroah-Hartman, Liam Girdwood, Mark Brown, Paul Gortmaker,
Samuel Ortiz, alsa-devel, linux-fbdev, linux-mmc, linux-mtd,
linux-usb, lm-sensors, rtc-linux
Foreword:
Ralf suggested that it might be a good idea in order to allow for reasonable
testing and to avoid build failures due to two-way dependencies in different
parts of the kernel, that he applies all the patches once they have been acked
by their respective maintainers, feeds them into -next and eventually sends the
whole series to Linus. One exception will be the ASoC patches which will, due to
major changes in the ASoC subsystem, go through the ASoC tree.
So if you are a maintainer for one of the subsystem touched by this series and
would rather see the patch going through your tree (given the patch is ok)
please tell.
This patch series adds support for the Ingenic JZ4740 System-on-a-Chip.
The JZ4740 has a mostly MIPS32 compatible core (no on cpu timers) and many on
chip peripherals like RTC, NAND, MMC, OHCI, UDC, ADC, I2C, SPI, AC97, I2S, I2S
Codec, UART and LCD controller.
The JZ4740 is mostly used in eBooks, PMPs and hand-held consoles.
This series contains patches for the Qi Ben NanoNote clamshell device as the
inital supported device.
Changes since v1:
There have been some minor changes since v1, mostly code cleanup and some
functional changes. One bigger change is that there is now a MFD driver for
the ADC core which does IRQ demultiplexing for the ADC unit and synchronizes
access to shared registers between the different users of the ADC core.
The patch adding a defconfig for the Qi LB60 has been dropped.
A detailed list of changes is present in each patch.
- Lars
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Anton Vorontsov <cbouatmailru@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Liam Girdwood <lrg@slimlogic.co.uk>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Paul Gortmaker <p_gortmaker@yahoo.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: alsa-devel@alsa-project.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-mmc@vger.kernel.org
Cc: linux-mtd@lists.infradead.org
Cc: linux-usb@vger.kernel.org
Cc: lm-sensors@lm-sensors.org
Cc: rtc-linux@googlegroups.com
Lars-Peter Clausen (26):
MIPS: Add base support for Ingenic JZ4740 System-on-a-Chip
MIPS: jz4740: Add IRQ handler code
MIPS: JZ4740: Add clock API support.
MIPS: JZ4740: Add timer support
MIPS: JZ4740: Add clocksource/clockevent support.
MIPS: JZ4740: Add power-management and system reset support
MIPS: JZ4740: Add setup code
MIPS: JZ4740: Add gpio support
MIPS: JZ4740: Add DMA support.
MIPS: JZ4740: Add PWM support
MIPS: JZ4740: Add serial support
MIPS: JZ4740: Add prom support
MIPS: JZ4740: Add platform devices
MIPS: JZ4740: Add Kbuild files
RTC: Add JZ4740 RTC driver
fbdev: Add JZ4740 framebuffer driver
MTD: Nand: Add JZ4740 NAND driver
MMC: Add JZ4740 mmc driver
USB: Add JZ4740 ohci support
alsa: ASoC: Add JZ4740 codec driver
alsa: ASoC: Add JZ4740 ASoC support
MFD: Add JZ4740 ADC driver
hwmon: Add JZ4740 ADC driver
power: Add JZ4740 battery driver.
MIPS: JZ4740: Add qi_lb60 board support
alsa: ASoC: JZ4740: Add qi_lb60 board driver
arch/mips/Kbuild.platforms | 1 +
arch/mips/Kconfig | 13 +
arch/mips/include/asm/bootinfo.h | 6 +
arch/mips/include/asm/cpu.h | 9 +-
arch/mips/include/asm/mach-jz4740/base.h | 26 +
arch/mips/include/asm/mach-jz4740/clock.h | 28 +
arch/mips/include/asm/mach-jz4740/dma.h | 90 +++
arch/mips/include/asm/mach-jz4740/gpio.h | 398 +++++++++++
arch/mips/include/asm/mach-jz4740/irq.h | 57 ++
arch/mips/include/asm/mach-jz4740/platform.h | 36 +
arch/mips/include/asm/mach-jz4740/timer.h | 22 +
arch/mips/include/asm/mach-jz4740/war.h | 25 +
arch/mips/jz4740/Kconfig | 12 +
arch/mips/jz4740/Makefile | 20 +
arch/mips/jz4740/Platform | 5 +
arch/mips/jz4740/board-qi_lb60.c | 483 +++++++++++++
arch/mips/jz4740/clock-debugfs.c | 109 +++
arch/mips/jz4740/clock.c | 920 ++++++++++++++++++++++++
arch/mips/jz4740/clock.h | 76 ++
arch/mips/jz4740/dma.c | 289 ++++++++
arch/mips/jz4740/gpio.c | 601 ++++++++++++++++
arch/mips/jz4740/irq.c | 169 +++++
arch/mips/jz4740/irq.h | 21 +
arch/mips/jz4740/platform.c | 284 ++++++++
arch/mips/jz4740/pm.c | 56 ++
arch/mips/jz4740/prom.c | 68 ++
arch/mips/jz4740/pwm.c | 169 +++++
arch/mips/jz4740/reset.c | 79 ++
arch/mips/jz4740/reset.h | 7 +
arch/mips/jz4740/serial.c | 33 +
arch/mips/jz4740/serial.h | 21 +
arch/mips/jz4740/setup.c | 29 +
arch/mips/jz4740/time.c | 144 ++++
arch/mips/jz4740/timer.c | 48 ++
arch/mips/jz4740/timer.h | 136 ++++
arch/mips/kernel/cpu-probe.c | 20 +
arch/mips/mm/tlbex.c | 5 +
drivers/hwmon/Kconfig | 11 +
drivers/hwmon/Makefile | 1 +
drivers/hwmon/jz4740-hwmon.c | 206 ++++++
drivers/mfd/Kconfig | 8 +
drivers/mfd/Makefile | 1 +
drivers/mfd/jz4740-adc.c | 392 ++++++++++
drivers/mmc/host/Kconfig | 8 +
drivers/mmc/host/Makefile | 1 +
drivers/mmc/host/jz4740_mmc.c | 993 ++++++++++++++++++++++++++
drivers/mtd/nand/Kconfig | 6 +
drivers/mtd/nand/Makefile | 1 +
drivers/mtd/nand/jz4740_nand.c | 474 ++++++++++++
drivers/power/Kconfig | 11 +
drivers/power/Makefile | 1 +
drivers/power/jz4740-battery.c | 445 ++++++++++++
drivers/rtc/Kconfig | 11 +
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-jz4740.c | 341 +++++++++
drivers/usb/Kconfig | 1 +
drivers/usb/host/ohci-hcd.c | 5 +
drivers/usb/host/ohci-jz4740.c | 276 +++++++
drivers/video/Kconfig | 9 +
drivers/video/Makefile | 1 +
drivers/video/jz4740_fb.c | 817 +++++++++++++++++++++
include/linux/jz4740-adc.h | 32 +
include/linux/jz4740_fb.h | 58 ++
include/linux/mmc/jz4740_mmc.h | 15 +
include/linux/mtd/jz4740_nand.h | 34 +
include/linux/power/jz4740-battery.h | 24 +
sound/soc/Kconfig | 1 +
sound/soc/Makefile | 1 +
sound/soc/codecs/Kconfig | 4 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/jz4740-codec.c | 514 +++++++++++++
sound/soc/codecs/jz4740-codec.h | 20 +
sound/soc/jz4740/Kconfig | 23 +
sound/soc/jz4740/Makefile | 13 +
sound/soc/jz4740/jz4740-i2s.c | 540 ++++++++++++++
sound/soc/jz4740/jz4740-i2s.h | 18 +
sound/soc/jz4740/jz4740-pcm.c | 373 ++++++++++
sound/soc/jz4740/jz4740-pcm.h | 22 +
sound/soc/jz4740/qi_lb60.c | 167 +++++
79 files changed, 10396 insertions(+), 1 deletions(-)
create mode 100644 arch/mips/include/asm/mach-jz4740/base.h
create mode 100644 arch/mips/include/asm/mach-jz4740/clock.h
create mode 100644 arch/mips/include/asm/mach-jz4740/dma.h
create mode 100644 arch/mips/include/asm/mach-jz4740/gpio.h
create mode 100644 arch/mips/include/asm/mach-jz4740/irq.h
create mode 100644 arch/mips/include/asm/mach-jz4740/platform.h
create mode 100644 arch/mips/include/asm/mach-jz4740/timer.h
create mode 100644 arch/mips/include/asm/mach-jz4740/war.h
create mode 100644 arch/mips/jz4740/Kconfig
create mode 100644 arch/mips/jz4740/Makefile
create mode 100644 arch/mips/jz4740/Platform
create mode 100644 arch/mips/jz4740/board-qi_lb60.c
create mode 100644 arch/mips/jz4740/clock-debugfs.c
create mode 100644 arch/mips/jz4740/clock.c
create mode 100644 arch/mips/jz4740/clock.h
create mode 100644 arch/mips/jz4740/dma.c
create mode 100644 arch/mips/jz4740/gpio.c
create mode 100644 arch/mips/jz4740/irq.c
create mode 100644 arch/mips/jz4740/irq.h
create mode 100644 arch/mips/jz4740/platform.c
create mode 100644 arch/mips/jz4740/pm.c
create mode 100644 arch/mips/jz4740/prom.c
create mode 100644 arch/mips/jz4740/pwm.c
create mode 100644 arch/mips/jz4740/reset.c
create mode 100644 arch/mips/jz4740/reset.h
create mode 100644 arch/mips/jz4740/serial.c
create mode 100644 arch/mips/jz4740/serial.h
create mode 100644 arch/mips/jz4740/setup.c
create mode 100644 arch/mips/jz4740/time.c
create mode 100644 arch/mips/jz4740/timer.c
create mode 100644 arch/mips/jz4740/timer.h
create mode 100644 drivers/hwmon/jz4740-hwmon.c
create mode 100644 drivers/mfd/jz4740-adc.c
create mode 100644 drivers/mmc/host/jz4740_mmc.c
create mode 100644 drivers/mtd/nand/jz4740_nand.c
create mode 100644 drivers/power/jz4740-battery.c
create mode 100644 drivers/rtc/rtc-jz4740.c
create mode 100644 drivers/usb/host/ohci-jz4740.c
create mode 100644 drivers/video/jz4740_fb.c
create mode 100644 include/linux/jz4740-adc.h
create mode 100644 include/linux/jz4740_fb.h
create mode 100644 include/linux/mmc/jz4740_mmc.h
create mode 100644 include/linux/mtd/jz4740_nand.h
create mode 100644 include/linux/power/jz4740-battery.h
create mode 100644 sound/soc/codecs/jz4740-codec.c
create mode 100644 sound/soc/codecs/jz4740-codec.h
create mode 100644 sound/soc/jz4740/Kconfig
create mode 100644 sound/soc/jz4740/Makefile
create mode 100644 sound/soc/jz4740/jz4740-i2s.c
create mode 100644 sound/soc/jz4740/jz4740-i2s.h
create mode 100644 sound/soc/jz4740/jz4740-pcm.c
create mode 100644 sound/soc/jz4740/jz4740-pcm.h
create mode 100644 sound/soc/jz4740/qi_lb60.c
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver
2010-06-19 5:08 [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic JZ4740 Lars-Peter Clausen
@ 2010-06-19 5:08 ` Lars-Peter Clausen
2010-06-19 8:36 ` Jean Delvare
2010-06-19 14:47 ` [lm-sensors] [PATCH v3] " Lars-Peter Clausen
2010-06-20 9:26 ` [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic Thomas Bogendoerfer
1 sibling, 2 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2010-06-19 5:08 UTC (permalink / raw)
To: Ralf Baechle
Cc: linux-mips, linux-kernel, Lars-Peter Clausen, Jonathan Cameron,
lm-sensors
This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <kernel@jic23.retrosnub.co.uk>
Cc: lm-sensors@lm-sensors.org
---
Changes since v1
- Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
ADC driver now only reads the adcin value.
---
drivers/hwmon/Kconfig | 11 +++
drivers/hwmon/Makefile | 1 +
drivers/hwmon/jz4740-hwmon.c | 206 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 218 insertions(+), 0 deletions(-)
create mode 100644 drivers/hwmon/jz4740-hwmon.c
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 569082c..51fc2f6 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -446,6 +446,17 @@ config SENSORS_IT87
This driver can also be built as a module. If so, the module
will be called it87.
+config SENSORS_JZ4740
+ tristate "Ingenic JZ4740 SoC ADC driver"
+ depends on MACH_JZ4740
+ help
+ If you say yes here you get support for the Ingenic JZ4740 SoC ADC core.
+ It is required for the JZ4740 battery and touchscreen driver and is used
+ to synchronize access to the adc module between those two.
+
+ This driver can also be build as a module. If so, the module will be
+ called jz4740-adc.
+
config SENSORS_LM63
tristate "National Semiconductor LM63 and LM64"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index bca0d45..dffbdff 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
obj-$(CONFIG_SENSORS_IT87) += it87.o
+obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
new file mode 100644
index 0000000..f53d15e
--- /dev/null
+++ b/drivers/hwmon/jz4740-hwmon.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
+ * JZ4740 SoC HWMON driver
+ *
+ * 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.
+ *
+ * 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.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <linux/mfd/core.h>
+
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+
+struct jz4740_hwmon {
+ struct resource *mem;
+ void __iomem *base;
+
+ int irq;
+
+ struct mfd_cell *cell;
+ struct device *hwmon;
+
+ struct completion read_completion;
+
+ struct mutex lock;
+};
+
+static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
+{
+ struct jz4740_hwmon *hwmon = data;
+
+ complete(&hwmon->read_completion);
+ return IRQ_HANDLED;
+}
+
+static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+ struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
+ unsigned long t;
+ uint16_t val;
+ int ret;
+
+ mutex_lock(&hwmon->lock);
+
+ INIT_COMPLETION(hwmon->read_completion);
+
+ enable_irq(hwmon->irq);
+ hwmon->cell->enable(to_platform_device(dev));
+
+ t = wait_for_completion_interruptible_timeout(&hwmon->read_completion, HZ);
+
+ if (t > 0) {
+ val = readw(hwmon->base);
+ ret = sprintf(buf, "%d\n", val);
+ } else {
+ ret = t ? t : -ETIMEDOUT;
+ }
+
+ hwmon->cell->disable(to_platform_device(dev));
+ disable_irq(hwmon->irq);
+
+ mutex_unlock(&hwmon->lock);
+
+ return ret;
+}
+
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL, 0);
+
+static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct jz4740_hwmon *hwmon;
+
+ hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
+
+ hwmon->cell = pdev->dev.platform_data;
+
+ hwmon->irq = platform_get_irq(pdev, 0);
+ if (hwmon->irq < 0) {
+ ret = hwmon->irq;
+ dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
+ goto err_free;
+ }
+
+ hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!hwmon->mem) {
+ ret = -ENOENT;
+ dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
+ goto err_free;
+ }
+
+ hwmon->mem = request_mem_region(hwmon->mem->start,
+ resource_size(hwmon->mem), pdev->name);
+ if (!hwmon->mem) {
+ ret = -EBUSY;
+ dev_err(&pdev->dev, "Failed to request mmio memory region\n");
+ goto err_free;
+ }
+
+ hwmon->base = ioremap_nocache(hwmon->mem->start, resource_size(hwmon->mem));
+ if (!hwmon->base) {
+ ret = -EBUSY;
+ dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
+ goto err_release_mem_region;
+ }
+
+ init_completion(&hwmon->read_completion);
+ mutex_init(&hwmon->lock);
+
+ platform_set_drvdata(pdev, hwmon);
+
+ ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
+ goto err_iounmap;
+ }
+ disable_irq(hwmon->irq);
+
+ ret = device_create_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to create sysfs file: %d\n", ret);
+ goto err_free_irq;
+ }
+
+ hwmon->hwmon = hwmon_device_register(&pdev->dev);
+ if (IS_ERR(hwmon->hwmon)) {
+ ret = PTR_ERR(hwmon->hwmon);
+ goto err_remove_file;
+ }
+
+ return 0;
+
+err_remove_file:
+ device_remove_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
+err_free_irq:
+ free_irq(hwmon->irq, hwmon);
+err_iounmap:
+ platform_set_drvdata(pdev, NULL);
+ iounmap(hwmon->base);
+err_release_mem_region:
+ release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
+err_free:
+ kfree(hwmon);
+
+ return ret;
+}
+
+static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
+{
+ struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
+
+ hwmon_device_unregister(hwmon->hwmon);
+ device_remove_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
+
+ free_irq(hwmon->irq, hwmon);
+
+ iounmap(hwmon->base);
+ release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
+
+ platform_set_drvdata(pdev, NULL);
+ kfree(hwmon);
+
+ return 0;
+}
+
+struct platform_driver jz4740_hwmon_driver = {
+ .probe = jz4740_hwmon_probe,
+ .remove = __devexit_p(jz4740_hwmon_remove),
+ .driver = {
+ .name = "jz4740-hwmon",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init jz4740_hwmon_init(void)
+{
+ return platform_driver_register(&jz4740_hwmon_driver);
+}
+module_init(jz4740_hwmon_init);
+
+static void __exit jz4740_hwmon_exit(void)
+{
+ platform_driver_unregister(&jz4740_hwmon_driver);
+}
+module_exit(jz4740_hwmon_exit);
+
+MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:jz4740-hwmon");
--
1.5.6.5
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver
2010-06-19 5:08 ` [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver Lars-Peter Clausen
@ 2010-06-19 8:36 ` Jean Delvare
2010-06-19 12:58 ` Lars-Peter Clausen
2010-06-19 14:47 ` [lm-sensors] [PATCH v3] " Lars-Peter Clausen
1 sibling, 1 reply; 11+ messages in thread
From: Jean Delvare @ 2010-06-19 8:36 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Ralf Baechle, linux-mips, Jonathan Cameron, Lars-Peter Clausen,
linux-kernel, lm-sensors
On Sat, 19 Jun 2010 07:08:28 +0200, Lars-Peter Clausen wrote:
> This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Cc: Jonathan Cameron <kernel@jic23.retrosnub.co.uk>
> Cc: lm-sensors@lm-sensors.org
>
> ---
> Changes since v1
> - Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
> ADC driver now only reads the adcin value.
> ---
> drivers/hwmon/Kconfig | 11 +++
> drivers/hwmon/Makefile | 1 +
> drivers/hwmon/jz4740-hwmon.c | 206 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 218 insertions(+), 0 deletions(-)
> create mode 100644 drivers/hwmon/jz4740-hwmon.c
>
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 569082c..51fc2f6 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -446,6 +446,17 @@ config SENSORS_IT87
> This driver can also be built as a module. If so, the module
> will be called it87.
>
> +config SENSORS_JZ4740
> + tristate "Ingenic JZ4740 SoC ADC driver"
> + depends on MACH_JZ4740
> + help
> + If you say yes here you get support for the Ingenic JZ4740 SoC ADC core.
> + It is required for the JZ4740 battery and touchscreen driver and is used
> + to synchronize access to the adc module between those two.
> +
> + This driver can also be build as a module. If so, the module will be
> + called jz4740-adc.
> +
> config SENSORS_LM63
> tristate "National Semiconductor LM63 and LM64"
> depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index bca0d45..dffbdff 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
> obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
> obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
> obj-$(CONFIG_SENSORS_IT87) += it87.o
> +obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
> obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
> obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
> obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
> diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
> new file mode 100644
> index 0000000..f53d15e
> --- /dev/null
> +++ b/drivers/hwmon/jz4740-hwmon.c
> @@ -0,0 +1,206 @@
> +/*
> + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
> + * JZ4740 SoC HWMON driver
> + *
> + * 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.
> + *
> + * 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.,
> + * 675 Mass Ave, Cambridge, MA 02139, USA.
> + *
> + */
> +
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +#include <linux/mfd/core.h>
> +
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +
> +struct jz4740_hwmon {
> + struct resource *mem;
> + void __iomem *base;
> +
> + int irq;
> +
> + struct mfd_cell *cell;
> + struct device *hwmon;
> +
> + struct completion read_completion;
> +
> + struct mutex lock;
> +};
> +
> +static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
> +{
> + struct jz4740_hwmon *hwmon = data;
> +
> + complete(&hwmon->read_completion);
> + return IRQ_HANDLED;
> +}
> +
> +static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
> + struct device_attribute *dev_attr, char *buf)
> +{
> + struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
> + unsigned long t;
> + uint16_t val;
> + int ret;
> +
> + mutex_lock(&hwmon->lock);
> +
> + INIT_COMPLETION(hwmon->read_completion);
> +
> + enable_irq(hwmon->irq);
> + hwmon->cell->enable(to_platform_device(dev));
> +
> + t = wait_for_completion_interruptible_timeout(&hwmon->read_completion, HZ);
> +
> + if (t > 0) {
> + val = readw(hwmon->base);
> + ret = sprintf(buf, "%d\n", val);
What is the unit of "val"? The value returned to userspace must be in
mV, so in most cases a simple conversion is needed in the driver.
> + } else {
> + ret = t ? t : -ETIMEDOUT;
> + }
> +
> + hwmon->cell->disable(to_platform_device(dev));
> + disable_irq(hwmon->irq);
> +
> + mutex_unlock(&hwmon->lock);
> +
> + return ret;
> +}
> +
> +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL, 0);
> +
> +static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
> +{
> + int ret;
> + struct jz4740_hwmon *hwmon;
> +
> + hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
> +
> + hwmon->cell = pdev->dev.platform_data;
> +
> + hwmon->irq = platform_get_irq(pdev, 0);
> + if (hwmon->irq < 0) {
> + ret = hwmon->irq;
> + dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
> + goto err_free;
> + }
> +
> + hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!hwmon->mem) {
> + ret = -ENOENT;
> + dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
> + goto err_free;
> + }
> +
> + hwmon->mem = request_mem_region(hwmon->mem->start,
> + resource_size(hwmon->mem), pdev->name);
> + if (!hwmon->mem) {
> + ret = -EBUSY;
> + dev_err(&pdev->dev, "Failed to request mmio memory region\n");
> + goto err_free;
> + }
> +
> + hwmon->base = ioremap_nocache(hwmon->mem->start, resource_size(hwmon->mem));
> + if (!hwmon->base) {
> + ret = -EBUSY;
> + dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
> + goto err_release_mem_region;
> + }
> +
> + init_completion(&hwmon->read_completion);
> + mutex_init(&hwmon->lock);
> +
> + platform_set_drvdata(pdev, hwmon);
> +
> + ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
> + goto err_iounmap;
> + }
> + disable_irq(hwmon->irq);
> +
> + ret = device_create_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to create sysfs file: %d\n", ret);
> + goto err_free_irq;
> + }
You must create a name attribute as well, if you want your device to be
supported by libsensors.
> +
> + hwmon->hwmon = hwmon_device_register(&pdev->dev);
> + if (IS_ERR(hwmon->hwmon)) {
> + ret = PTR_ERR(hwmon->hwmon);
> + goto err_remove_file;
> + }
> +
> + return 0;
> +
> +err_remove_file:
> + device_remove_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
> +err_free_irq:
> + free_irq(hwmon->irq, hwmon);
> +err_iounmap:
> + platform_set_drvdata(pdev, NULL);
> + iounmap(hwmon->base);
> +err_release_mem_region:
> + release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
> +err_free:
> + kfree(hwmon);
> +
> + return ret;
> +}
> +
> +static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
> +{
> + struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
> +
> + hwmon_device_unregister(hwmon->hwmon);
> + device_remove_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
> +
> + free_irq(hwmon->irq, hwmon);
> +
> + iounmap(hwmon->base);
> + release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
> +
> + platform_set_drvdata(pdev, NULL);
> + kfree(hwmon);
> +
> + return 0;
> +}
> +
> +struct platform_driver jz4740_hwmon_driver = {
> + .probe = jz4740_hwmon_probe,
> + .remove = __devexit_p(jz4740_hwmon_remove),
> + .driver = {
> + .name = "jz4740-hwmon",
> + .owner = THIS_MODULE,
> + },
> +};
> +
> +static int __init jz4740_hwmon_init(void)
> +{
> + return platform_driver_register(&jz4740_hwmon_driver);
> +}
> +module_init(jz4740_hwmon_init);
> +
> +static void __exit jz4740_hwmon_exit(void)
> +{
> + platform_driver_unregister(&jz4740_hwmon_driver);
> +}
> +module_exit(jz4740_hwmon_exit);
> +
> +MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
> +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:jz4740-hwmon");
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver
2010-06-19 8:36 ` Jean Delvare
@ 2010-06-19 12:58 ` Lars-Peter Clausen
0 siblings, 0 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2010-06-19 12:58 UTC (permalink / raw)
To: Jean Delvare
Cc: Ralf Baechle, linux-mips, Jonathan Cameron, linux-kernel,
lm-sensors
Jean Delvare wrote:
> On Sat, 19 Jun 2010 07:08:28 +0200, Lars-Peter Clausen wrote:
>
>> This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> Cc: Jonathan Cameron <kernel@jic23.retrosnub.co.uk>
>> Cc: lm-sensors@lm-sensors.org
>>
>> ---
>> Changes since v1
>> - Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
>> ADC driver now only reads the adcin value.
>> ---
>> drivers/hwmon/Kconfig | 11 +++
>> drivers/hwmon/Makefile | 1 +
>> drivers/hwmon/jz4740-hwmon.c | 206 ++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 218 insertions(+), 0 deletions(-)
>> create mode 100644 drivers/hwmon/jz4740-hwmon.c
>>
>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>> index 569082c..51fc2f6 100644
>> --- a/drivers/hwmon/Kconfig
>> +++ b/drivers/hwmon/Kconfig
>> @@ -446,6 +446,17 @@ config SENSORS_IT87
>> This driver can also be built as a module. If so, the module
>> will be called it87.
>>
>> +config SENSORS_JZ4740
>> + tristate "Ingenic JZ4740 SoC ADC driver"
>> + depends on MACH_JZ4740
>> + help
>> + If you say yes here you get support for the Ingenic JZ4740 SoC ADC core.
>> + It is required for the JZ4740 battery and touchscreen driver and is used
>> + to synchronize access to the adc module between those two.
>> +
>> + This driver can also be build as a module. If so, the module will be
>> + called jz4740-adc.
>> +
>> config SENSORS_LM63
>> tristate "National Semiconductor LM63 and LM64"
>> depends on I2C
>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>> index bca0d45..dffbdff 100644
>> --- a/drivers/hwmon/Makefile
>> +++ b/drivers/hwmon/Makefile
>> @@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
>> obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
>> obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
>> obj-$(CONFIG_SENSORS_IT87) += it87.o
>> +obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
>> obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
>> obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
>> obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
>> diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
>> new file mode 100644
>> index 0000000..f53d15e
>> --- /dev/null
>> +++ b/drivers/hwmon/jz4740-hwmon.c
>> @@ -0,0 +1,206 @@
>> +/*
>> + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
>> + * JZ4740 SoC HWMON driver
>> + *
>> + * 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.
>> + *
>> + * 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.,
>> + * 675 Mass Ave, Cambridge, MA 02139, USA.
>> + *
>> + */
>> +
>> +#include <linux/err.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/slab.h>
>> +
>> +#include <linux/mfd/core.h>
>> +
>> +#include <linux/hwmon.h>
>> +#include <linux/hwmon-sysfs.h>
>> +
>> +struct jz4740_hwmon {
>> + struct resource *mem;
>> + void __iomem *base;
>> +
>> + int irq;
>> +
>> + struct mfd_cell *cell;
>> + struct device *hwmon;
>> +
>> + struct completion read_completion;
>> +
>> + struct mutex lock;
>> +};
>> +
>> +static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
>> +{
>> + struct jz4740_hwmon *hwmon = data;
>> +
>> + complete(&hwmon->read_completion);
>> + return IRQ_HANDLED;
>> +}
>> +
>> +static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
>> + struct device_attribute *dev_attr, char *buf)
>> +{
>> + struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
>> + unsigned long t;
>> + uint16_t val;
>> + int ret;
>> +
>> + mutex_lock(&hwmon->lock);
>> +
>> + INIT_COMPLETION(hwmon->read_completion);
>> +
>> + enable_irq(hwmon->irq);
>> + hwmon->cell->enable(to_platform_device(dev));
>> +
>> + t = wait_for_completion_interruptible_timeout(&hwmon->read_completion, HZ);
>> +
>> + if (t > 0) {
>> + val = readw(hwmon->base);
>> + ret = sprintf(buf, "%d\n", val);
>>
>
> What is the unit of "val"? The value returned to userspace must be in
> mV, so in most cases a simple conversion is needed in the driver.
>
>
Right, forgot about to change it, sorry.
>> + } else {
>> + ret = t ? t : -ETIMEDOUT;
>> + }
>> +
>> + hwmon->cell->disable(to_platform_device(dev));
>> + disable_irq(hwmon->irq);
>> +
>> + mutex_unlock(&hwmon->lock);
>> +
>> + return ret;
>> +}
>> +
>> +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL, 0);
>> +
>> +static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
>> +{
>> + int ret;
>> + struct jz4740_hwmon *hwmon;
>> +
>> + hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
>> +
>> + hwmon->cell = pdev->dev.platform_data;
>> +
>> + hwmon->irq = platform_get_irq(pdev, 0);
>> + if (hwmon->irq < 0) {
>> + ret = hwmon->irq;
>> + dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
>> + goto err_free;
>> + }
>> +
>> + hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> + if (!hwmon->mem) {
>> + ret = -ENOENT;
>> + dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
>> + goto err_free;
>> + }
>> +
>> + hwmon->mem = request_mem_region(hwmon->mem->start,
>> + resource_size(hwmon->mem), pdev->name);
>> + if (!hwmon->mem) {
>> + ret = -EBUSY;
>> + dev_err(&pdev->dev, "Failed to request mmio memory region\n");
>> + goto err_free;
>> + }
>> +
>> + hwmon->base = ioremap_nocache(hwmon->mem->start, resource_size(hwmon->mem));
>> + if (!hwmon->base) {
>> + ret = -EBUSY;
>> + dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
>> + goto err_release_mem_region;
>> + }
>> +
>> + init_completion(&hwmon->read_completion);
>> + mutex_init(&hwmon->lock);
>> +
>> + platform_set_drvdata(pdev, hwmon);
>> +
>> + ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
>> + if (ret) {
>> + dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
>> + goto err_iounmap;
>> + }
>> + disable_irq(hwmon->irq);
>> +
>> + ret = device_create_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
>> + if (ret) {
>> + dev_err(&pdev->dev, "Failed to create sysfs file: %d\n", ret);
>> + goto err_free_irq;
>> + }
>>
>
> You must create a name attribute as well, if you want your device to be
> supported by libsensors.
>
Ok.
>
>> +
>> + hwmon->hwmon = hwmon_device_register(&pdev->dev);
>> + if (IS_ERR(hwmon->hwmon)) {
>> + ret = PTR_ERR(hwmon->hwmon);
>> + goto err_remove_file;
>> + }
>> +
>> + return 0;
>> +
>> +err_remove_file:
>> + device_remove_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
>> +err_free_irq:
>> + free_irq(hwmon->irq, hwmon);
>> +err_iounmap:
>> + platform_set_drvdata(pdev, NULL);
>> + iounmap(hwmon->base);
>> +err_release_mem_region:
>> + release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
>> +err_free:
>> + kfree(hwmon);
>> +
>> + return ret;
>> +}
>> +
>> +static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
>> +{
>> + struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
>> +
>> + hwmon_device_unregister(hwmon->hwmon);
>> + device_remove_file(&pdev->dev, &sensor_dev_attr_in0_input.dev_attr);
>> +
>> + free_irq(hwmon->irq, hwmon);
>> +
>> + iounmap(hwmon->base);
>> + release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
>> +
>> + platform_set_drvdata(pdev, NULL);
>> + kfree(hwmon);
>> +
>> + return 0;
>> +}
>> +
>> +struct platform_driver jz4740_hwmon_driver = {
>> + .probe = jz4740_hwmon_probe,
>> + .remove = __devexit_p(jz4740_hwmon_remove),
>> + .driver = {
>> + .name = "jz4740-hwmon",
>> + .owner = THIS_MODULE,
>> + },
>> +};
>> +
>> +static int __init jz4740_hwmon_init(void)
>> +{
>> + return platform_driver_register(&jz4740_hwmon_driver);
>> +}
>> +module_init(jz4740_hwmon_init);
>> +
>> +static void __exit jz4740_hwmon_exit(void)
>> +{
>> + platform_driver_unregister(&jz4740_hwmon_driver);
>> +}
>> +module_exit(jz4740_hwmon_exit);
>> +
>> +MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
>> +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
>> +MODULE_LICENSE("GPL");
>> +MODULE_ALIAS("platform:jz4740-hwmon");
>>
>
>
Thanks for reviewing
-Lars
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* [lm-sensors] [PATCH v3] hwmon: Add JZ4740 ADC driver
2010-06-19 5:08 ` [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver Lars-Peter Clausen
2010-06-19 8:36 ` Jean Delvare
@ 2010-06-19 14:47 ` Lars-Peter Clausen
2010-06-19 16:24 ` Jean Delvare
2010-06-19 19:32 ` [lm-sensors] [PATCH v4] " Lars-Peter Clausen
1 sibling, 2 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2010-06-19 14:47 UTC (permalink / raw)
To: Ralf Baechle; +Cc: linux-mips, linux-kernel, Lars-Peter Clausen, lm-sensors
This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: lm-sensors@lm-sensors.org
--
Changes since v1
- Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
ADC driver now only reads the adcin value.
Changes since v2
- Add name sysfs attribute
- Report adcin in value in millivolts
---
drivers/hwmon/Kconfig | 11 ++
drivers/hwmon/Makefile | 1 +
drivers/hwmon/jz4740-hwmon.c | 224 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 236 insertions(+), 0 deletions(-)
create mode 100644 drivers/hwmon/jz4740-hwmon.c
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 569082c..51fc2f6 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -446,6 +446,17 @@ config SENSORS_IT87
This driver can also be built as a module. If so, the module
will be called it87.
+config SENSORS_JZ4740
+ tristate "Ingenic JZ4740 SoC ADC driver"
+ depends on MACH_JZ4740
+ help
+ If you say yes here you get support for the Ingenic JZ4740 SoC ADC core.
+ It is required for the JZ4740 battery and touchscreen driver and is used
+ to synchronize access to the adc module between those two.
+
+ This driver can also be build as a module. If so, the module will be
+ called jz4740-adc.
+
config SENSORS_LM63
tristate "National Semiconductor LM63 and LM64"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index bca0d45..dffbdff 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
obj-$(CONFIG_SENSORS_IT87) += it87.o
+obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
new file mode 100644
index 0000000..a448d78
--- /dev/null
+++ b/drivers/hwmon/jz4740-hwmon.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
+ * JZ4740 SoC HWMON driver
+ *
+ * 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.
+ *
+ * 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.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <linux/mfd/core.h>
+
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+
+struct jz4740_hwmon {
+ struct resource *mem;
+ void __iomem *base;
+
+ int irq;
+
+ struct mfd_cell *cell;
+ struct device *hwmon;
+
+ struct completion read_completion;
+
+ struct mutex lock;
+};
+
+static ssize_t jz4740_hwmon_show_name(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+ return sprintf(buf, "jz4740\n");
+}
+
+static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
+{
+ struct jz4740_hwmon *hwmon = data;
+
+ complete(&hwmon->read_completion);
+ return IRQ_HANDLED;
+}
+
+static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+ struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
+ unsigned long t;
+ unsigned long val;
+ int ret;
+
+ mutex_lock(&hwmon->lock);
+
+ INIT_COMPLETION(hwmon->read_completion);
+
+ enable_irq(hwmon->irq);
+ hwmon->cell->enable(to_platform_device(dev));
+
+ t = wait_for_completion_interruptible_timeout(&hwmon->read_completion, HZ);
+
+ if (t > 0) {
+ val = readw(hwmon->base) & 0xfff;
+ val = (val * 3300) >> 12;
+ ret = sprintf(buf, "%lu\n", val);
+ } else {
+ ret = t ? t : -ETIMEDOUT;
+ }
+
+ hwmon->cell->disable(to_platform_device(dev));
+ disable_irq(hwmon->irq);
+
+ mutex_unlock(&hwmon->lock);
+
+ return ret;
+}
+
+static DEVICE_ATTR(name, S_IRUGO, jz4740_hwmon_show_name, NULL);
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL, 0);
+
+static struct attribute jz4740_hwmon_attributes[] = {
+ &dev_attr_name.attr,
+ &sensor_dev_attr_in0_input.dev_attr.attr,
+ NULL
+};
+
+static const struct attribute_group jz4740_hwmon_attr_group = {
+ .attrs = jz4740_hwmon_attributes,
+};
+
+static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct jz4740_hwmon *hwmon;
+
+ hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
+
+ hwmon->cell = pdev->dev.platform_data;
+
+ hwmon->irq = platform_get_irq(pdev, 0);
+ if (hwmon->irq < 0) {
+ ret = hwmon->irq;
+ dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
+ goto err_free;
+ }
+
+ hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!hwmon->mem) {
+ ret = -ENOENT;
+ dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
+ goto err_free;
+ }
+
+ hwmon->mem = request_mem_region(hwmon->mem->start,
+ resource_size(hwmon->mem), pdev->name);
+ if (!hwmon->mem) {
+ ret = -EBUSY;
+ dev_err(&pdev->dev, "Failed to request mmio memory region\n");
+ goto err_free;
+ }
+
+ hwmon->base = ioremap_nocache(hwmon->mem->start, resource_size(hwmon->mem));
+ if (!hwmon->base) {
+ ret = -EBUSY;
+ dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
+ goto err_release_mem_region;
+ }
+
+ init_completion(&hwmon->read_completion);
+ mutex_init(&hwmon->lock);
+
+ platform_set_drvdata(pdev, hwmon);
+
+ ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
+ goto err_iounmap;
+ }
+ disable_irq(hwmon->irq);
+
+ ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret);
+ goto err_free_irq;
+ }
+
+ hwmon->hwmon = hwmon_device_register(&pdev->dev);
+ if (IS_ERR(hwmon->hwmon)) {
+ ret = PTR_ERR(hwmon->hwmon);
+ goto err_remove_file;
+ }
+
+ return 0;
+
+err_remove_file:
+ sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
+err_free_irq:
+ free_irq(hwmon->irq, hwmon);
+err_iounmap:
+ platform_set_drvdata(pdev, NULL);
+ iounmap(hwmon->base);
+err_release_mem_region:
+ release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
+err_free:
+ kfree(hwmon);
+
+ return ret;
+}
+
+static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
+{
+ struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
+
+ hwmon_device_unregister(hwmon->hwmon);
+ sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
+
+ free_irq(hwmon->irq, hwmon);
+
+ iounmap(hwmon->base);
+ release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
+
+ platform_set_drvdata(pdev, NULL);
+ kfree(hwmon);
+
+ return 0;
+}
+
+struct platform_driver jz4740_hwmon_driver = {
+ .probe = jz4740_hwmon_probe,
+ .remove = __devexit_p(jz4740_hwmon_remove),
+ .driver = {
+ .name = "jz4740-hwmon",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init jz4740_hwmon_init(void)
+{
+ return platform_driver_register(&jz4740_hwmon_driver);
+}
+module_init(jz4740_hwmon_init);
+
+static void __exit jz4740_hwmon_exit(void)
+{
+ platform_driver_unregister(&jz4740_hwmon_driver);
+}
+module_exit(jz4740_hwmon_exit);
+
+MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:jz4740-hwmon");
--
1.5.6.5
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v3] hwmon: Add JZ4740 ADC driver
2010-06-19 14:47 ` [lm-sensors] [PATCH v3] " Lars-Peter Clausen
@ 2010-06-19 16:24 ` Jean Delvare
2010-06-19 17:59 ` Lars-Peter Clausen
2010-06-19 19:32 ` [lm-sensors] [PATCH v4] " Lars-Peter Clausen
1 sibling, 1 reply; 11+ messages in thread
From: Jean Delvare @ 2010-06-19 16:24 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Ralf Baechle, linux-mips, linux-kernel, lm-sensors
Hi Lars-Peter,
On Sat, 19 Jun 2010 16:47:00 +0200, Lars-Peter Clausen wrote:
> This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Cc: lm-sensors@lm-sensors.org
>
> --
> Changes since v1
> - Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
> ADC driver now only reads the adcin value.
> Changes since v2
> - Add name sysfs attribute
> - Report adcin in value in millivolts
Changes look good. A few more comments below; other than these, your
driver look good, and I can add it to my hwmon tree and schedule it for
2.6.36 if you want.
> ---
> drivers/hwmon/Kconfig | 11 ++
> drivers/hwmon/Makefile | 1 +
> drivers/hwmon/jz4740-hwmon.c | 224 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 236 insertions(+), 0 deletions(-)
> create mode 100644 drivers/hwmon/jz4740-hwmon.c
>
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 569082c..51fc2f6 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -446,6 +446,17 @@ config SENSORS_IT87
> This driver can also be built as a module. If so, the module
> will be called it87.
>
> +config SENSORS_JZ4740
> + tristate "Ingenic JZ4740 SoC ADC driver"
> + depends on MACH_JZ4740
> + help
> + If you say yes here you get support for the Ingenic JZ4740 SoC ADC core.
> + It is required for the JZ4740 battery and touchscreen driver and is used
> + to synchronize access to the adc module between those two.
> +
> + This driver can also be build as a module. If so, the module will be
> + called jz4740-adc.
Actually not. And please use tabs for the first indentation level.
> +
> config SENSORS_LM63
> tristate "National Semiconductor LM63 and LM64"
> depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index bca0d45..dffbdff 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
> obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
> obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
> obj-$(CONFIG_SENSORS_IT87) += it87.o
> +obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
> obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
> obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
> obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
> diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
> new file mode 100644
> index 0000000..a448d78
> --- /dev/null
> +++ b/drivers/hwmon/jz4740-hwmon.c
> @@ -0,0 +1,224 @@
> +/*
> + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
> + * JZ4740 SoC HWMON driver
> + *
> + * 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.
> + *
> + * 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.,
> + * 675 Mass Ave, Cambridge, MA 02139, USA.
> + *
> + */
> +
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +#include <linux/mfd/core.h>
> +
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +
> +struct jz4740_hwmon {
> + struct resource *mem;
> + void __iomem *base;
> +
> + int irq;
> +
> + struct mfd_cell *cell;
> + struct device *hwmon;
> +
> + struct completion read_completion;
You must include <linux/completion.h> for this.
> +
> + struct mutex lock;
> +};
> +
> +static ssize_t jz4740_hwmon_show_name(struct device *dev,
> + struct device_attribute *dev_attr, char *buf)
> +{
> + return sprintf(buf, "jz4740\n");
> +}
> +
> +static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
> +{
> + struct jz4740_hwmon *hwmon = data;
> +
> + complete(&hwmon->read_completion);
> + return IRQ_HANDLED;
> +}
> +
> +static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
> + struct device_attribute *dev_attr, char *buf)
> +{
> + struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
> + unsigned long t;
> + unsigned long val;
> + int ret;
> +
> + mutex_lock(&hwmon->lock);
> +
> + INIT_COMPLETION(hwmon->read_completion);
> +
> + enable_irq(hwmon->irq);
> + hwmon->cell->enable(to_platform_device(dev));
> +
> + t = wait_for_completion_interruptible_timeout(&hwmon->read_completion, HZ);
Line over 80 characters.
> +
> + if (t > 0) {
> + val = readw(hwmon->base) & 0xfff;
> + val = (val * 3300) >> 12;
> + ret = sprintf(buf, "%lu\n", val);
> + } else {
> + ret = t ? t : -ETIMEDOUT;
> + }
> +
> + hwmon->cell->disable(to_platform_device(dev));
> + disable_irq(hwmon->irq);
> +
> + mutex_unlock(&hwmon->lock);
> +
> + return ret;
> +}
> +
> +static DEVICE_ATTR(name, S_IRUGO, jz4740_hwmon_show_name, NULL);
> +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL, 0);
Unless you plan to add support for devices with more than 1 voltage
input, you can use DEVICE_ATTR() instead of SENSOR_DEVICE_ATTR(), it's
cheaper. If you do, you no longer need to include <linux/hwmon-sysfs.h>.
> +
> +static struct attribute jz4740_hwmon_attributes[] = {
> + &dev_attr_name.attr,
> + &sensor_dev_attr_in0_input.dev_attr.attr,
> + NULL
> +};
> +
> +static const struct attribute_group jz4740_hwmon_attr_group = {
> + .attrs = jz4740_hwmon_attributes,
> +};
> +
> +static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
> +{
> + int ret;
> + struct jz4740_hwmon *hwmon;
> +
> + hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
> +
> + hwmon->cell = pdev->dev.platform_data;
> +
> + hwmon->irq = platform_get_irq(pdev, 0);
> + if (hwmon->irq < 0) {
> + ret = hwmon->irq;
> + dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
> + goto err_free;
> + }
> +
> + hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!hwmon->mem) {
> + ret = -ENOENT;
> + dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
> + goto err_free;
> + }
> +
> + hwmon->mem = request_mem_region(hwmon->mem->start,
> + resource_size(hwmon->mem), pdev->name);
> + if (!hwmon->mem) {
> + ret = -EBUSY;
> + dev_err(&pdev->dev, "Failed to request mmio memory region\n");
> + goto err_free;
> + }
> +
> + hwmon->base = ioremap_nocache(hwmon->mem->start, resource_size(hwmon->mem));
Line over 80 characters.
> + if (!hwmon->base) {
> + ret = -EBUSY;
> + dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
> + goto err_release_mem_region;
> + }
> +
> + init_completion(&hwmon->read_completion);
> + mutex_init(&hwmon->lock);
> +
> + platform_set_drvdata(pdev, hwmon);
> +
> + ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
> + goto err_iounmap;
> + }
> + disable_irq(hwmon->irq);
> +
> + ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret);
> + goto err_free_irq;
> + }
> +
> + hwmon->hwmon = hwmon_device_register(&pdev->dev);
> + if (IS_ERR(hwmon->hwmon)) {
> + ret = PTR_ERR(hwmon->hwmon);
> + goto err_remove_file;
> + }
> +
> + return 0;
> +
> +err_remove_file:
> + sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
> +err_free_irq:
> + free_irq(hwmon->irq, hwmon);
> +err_iounmap:
> + platform_set_drvdata(pdev, NULL);
> + iounmap(hwmon->base);
> +err_release_mem_region:
> + release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
> +err_free:
> + kfree(hwmon);
> +
> + return ret;
> +}
> +
> +static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
> +{
> + struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
> +
> + hwmon_device_unregister(hwmon->hwmon);
> + sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
> +
> + free_irq(hwmon->irq, hwmon);
> +
> + iounmap(hwmon->base);
> + release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
> +
> + platform_set_drvdata(pdev, NULL);
> + kfree(hwmon);
> +
> + return 0;
> +}
> +
> +struct platform_driver jz4740_hwmon_driver = {
> + .probe = jz4740_hwmon_probe,
> + .remove = __devexit_p(jz4740_hwmon_remove),
> + .driver = {
> + .name = "jz4740-hwmon",
> + .owner = THIS_MODULE,
> + },
> +};
> +
> +static int __init jz4740_hwmon_init(void)
> +{
> + return platform_driver_register(&jz4740_hwmon_driver);
> +}
> +module_init(jz4740_hwmon_init);
> +
> +static void __exit jz4740_hwmon_exit(void)
> +{
> + platform_driver_unregister(&jz4740_hwmon_driver);
> +}
> +module_exit(jz4740_hwmon_exit);
> +
> +MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
> +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:jz4740-hwmon");
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v3] hwmon: Add JZ4740 ADC driver
2010-06-19 16:24 ` Jean Delvare
@ 2010-06-19 17:59 ` Lars-Peter Clausen
0 siblings, 0 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2010-06-19 17:59 UTC (permalink / raw)
To: Jean Delvare; +Cc: Ralf Baechle, linux-mips, linux-kernel, lm-sensors
Hi
Jean Delvare wrote:
> Hi Lars-Peter,
>
> On Sat, 19 Jun 2010 16:47:00 +0200, Lars-Peter Clausen wrote:
>
>> This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> Cc: lm-sensors@lm-sensors.org
>>
>> --
>> Changes since v1
>> - Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
>> ADC driver now only reads the adcin value.
>> Changes since v2
>> - Add name sysfs attribute
>> - Report adcin in value in millivolts
>>
>
> Changes look good. A few more comments below; other than these, your
> driver look good, and I can add it to my hwmon tree and schedule it for
> 2.6.36 if you want.
>
Great thanks :)
As written in the introduction mail to this thread it would be good if
the majority of the patches could go through Ralfs tree. So if you don't
see any problems doing this, it would be nice if you could give your
Acked-By once I sent a updated patch.
- Lars
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* [lm-sensors] [PATCH v4] hwmon: Add JZ4740 ADC driver
2010-06-19 14:47 ` [lm-sensors] [PATCH v3] " Lars-Peter Clausen
2010-06-19 16:24 ` Jean Delvare
@ 2010-06-19 19:32 ` Lars-Peter Clausen
2010-06-20 6:32 ` Jean Delvare
1 sibling, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2010-06-19 19:32 UTC (permalink / raw)
To: Ralf Baechle; +Cc: linux-mips, linux-kernel, Lars-Peter Clausen, lm-sensors
This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: lm-sensors@lm-sensors.org
--
Changes since v1
- Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
ADC driver now only reads the adcin value.
Changes since v2
- Add name sysfs attribute
- Report adcin in value in millivolts
Changes since v3
- Fix Kconfig entry
- Add include to completion.h
- Break overlong lines
- Use DEVICE_ATTR instead of SENSOR_DEVICE_ATTR for the adcin sys file.
---
drivers/hwmon/Kconfig | 10 ++
drivers/hwmon/Makefile | 1 +
drivers/hwmon/jz4740-hwmon.c | 226 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 237 insertions(+), 0 deletions(-)
create mode 100644 drivers/hwmon/jz4740-hwmon.c
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 569082c..a01f32f 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -446,6 +446,16 @@ config SENSORS_IT87
This driver can also be built as a module. If so, the module
will be called it87.
+config SENSORS_JZ4740
+ tristate "Ingenic JZ4740 SoC ADC driver"
+ depends on MACH_JZ4740 && MFD_JZ4740_ADC
+ help
+ If you say yes here you get support for reading adc values from the ADCIN
+ pin on Ingenic JZ4740 SoC based boards.
+
+ This driver can also be build as a module. If so, the module will be
+ called jz4740-hwmon.
+
config SENSORS_LM63
tristate "National Semiconductor LM63 and LM64"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index bca0d45..dffbdff 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
obj-$(CONFIG_SENSORS_IT87) += it87.o
+obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
new file mode 100644
index 0000000..72a4335
--- /dev/null
+++ b/drivers/hwmon/jz4740-hwmon.c
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
+ * JZ4740 SoC HWMON driver
+ *
+ * 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.
+ *
+ * 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.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <linux/completion.h>
+#include <linux/mfd/core.h>
+
+#include <linux/hwmon.h>
+
+struct jz4740_hwmon {
+ struct resource *mem;
+ void __iomem *base;
+
+ int irq;
+
+ struct mfd_cell *cell;
+ struct device *hwmon;
+
+ struct completion read_completion;
+
+ struct mutex lock;
+};
+
+static ssize_t jz4740_hwmon_show_name(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+ return sprintf(buf, "jz4740\n");
+}
+
+static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
+{
+ struct jz4740_hwmon *hwmon = data;
+
+ complete(&hwmon->read_completion);
+ return IRQ_HANDLED;
+}
+
+static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+ struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
+ struct completion *completion = &hwmon->read_completion;
+ unsigned long t;
+ unsigned long val;
+ int ret;
+
+ mutex_lock(&hwmon->lock);
+
+ INIT_COMPLETION(*completion);
+
+ enable_irq(hwmon->irq);
+ hwmon->cell->enable(to_platform_device(dev));
+
+ t = wait_for_completion_interruptible_timeout(completion, HZ);
+
+ if (t > 0) {
+ val = readw(hwmon->base) & 0xfff;
+ val = (val * 3300) >> 12;
+ ret = sprintf(buf, "%lu\n", val);
+ } else {
+ ret = t ? t : -ETIMEDOUT;
+ }
+
+ hwmon->cell->disable(to_platform_device(dev));
+ disable_irq(hwmon->irq);
+
+ mutex_unlock(&hwmon->lock);
+
+ return ret;
+}
+
+static DEVICE_ATTR(name, S_IRUGO, jz4740_hwmon_show_name, NULL);
+static DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL);
+
+static struct attribute *jz4740_hwmon_attributes[] = {
+ &dev_attr_name.attr,
+ &dev_attr_in0_input.attr,
+ NULL
+};
+
+static const struct attribute_group jz4740_hwmon_attr_group = {
+ .attrs = jz4740_hwmon_attributes,
+};
+
+static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct jz4740_hwmon *hwmon;
+
+ hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
+
+ hwmon->cell = pdev->dev.platform_data;
+
+ hwmon->irq = platform_get_irq(pdev, 0);
+ if (hwmon->irq < 0) {
+ ret = hwmon->irq;
+ dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
+ goto err_free;
+ }
+
+ hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!hwmon->mem) {
+ ret = -ENOENT;
+ dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
+ goto err_free;
+ }
+
+ hwmon->mem = request_mem_region(hwmon->mem->start,
+ resource_size(hwmon->mem), pdev->name);
+ if (!hwmon->mem) {
+ ret = -EBUSY;
+ dev_err(&pdev->dev, "Failed to request mmio memory region\n");
+ goto err_free;
+ }
+
+ hwmon->base = ioremap_nocache(hwmon->mem->start,
+ resource_size(hwmon->mem));
+ if (!hwmon->base) {
+ ret = -EBUSY;
+ dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
+ goto err_release_mem_region;
+ }
+
+ init_completion(&hwmon->read_completion);
+ mutex_init(&hwmon->lock);
+
+ platform_set_drvdata(pdev, hwmon);
+
+ ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
+ goto err_iounmap;
+ }
+ disable_irq(hwmon->irq);
+
+ ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret);
+ goto err_free_irq;
+ }
+
+ hwmon->hwmon = hwmon_device_register(&pdev->dev);
+ if (IS_ERR(hwmon->hwmon)) {
+ ret = PTR_ERR(hwmon->hwmon);
+ goto err_remove_file;
+ }
+
+ return 0;
+
+err_remove_file:
+ sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
+err_free_irq:
+ free_irq(hwmon->irq, hwmon);
+err_iounmap:
+ platform_set_drvdata(pdev, NULL);
+ iounmap(hwmon->base);
+err_release_mem_region:
+ release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
+err_free:
+ kfree(hwmon);
+
+ return ret;
+}
+
+static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
+{
+ struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
+
+ hwmon_device_unregister(hwmon->hwmon);
+ sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
+
+ free_irq(hwmon->irq, hwmon);
+
+ iounmap(hwmon->base);
+ release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
+
+ platform_set_drvdata(pdev, NULL);
+ kfree(hwmon);
+
+ return 0;
+}
+
+struct platform_driver jz4740_hwmon_driver = {
+ .probe = jz4740_hwmon_probe,
+ .remove = __devexit_p(jz4740_hwmon_remove),
+ .driver = {
+ .name = "jz4740-hwmon",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init jz4740_hwmon_init(void)
+{
+ return platform_driver_register(&jz4740_hwmon_driver);
+}
+module_init(jz4740_hwmon_init);
+
+static void __exit jz4740_hwmon_exit(void)
+{
+ platform_driver_unregister(&jz4740_hwmon_driver);
+}
+module_exit(jz4740_hwmon_exit);
+
+MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:jz4740-hwmon");
--
1.5.6.5
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v4] hwmon: Add JZ4740 ADC driver
2010-06-19 19:32 ` [lm-sensors] [PATCH v4] " Lars-Peter Clausen
@ 2010-06-20 6:32 ` Jean Delvare
0 siblings, 0 replies; 11+ messages in thread
From: Jean Delvare @ 2010-06-20 6:32 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Ralf Baechle, linux-mips, Lars-Peter Clausen, linux-kernel,
lm-sensors
On Sat, 19 Jun 2010 21:32:58 +0200, Lars-Peter Clausen wrote:
> This patch adds support for reading the ADCIN pin of ADC unit on JZ4740 SoCs.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Cc: lm-sensors@lm-sensors.org
>
> --
> Changes since v1
> - Move ADC core access synchronizing from the HWMON driver to a MFD driver. The
> ADC driver now only reads the adcin value.
>
> Changes since v2
> - Add name sysfs attribute
> - Report adcin in value in millivolts
>
> Changes since v3
> - Fix Kconfig entry
> - Add include to completion.h
> - Break overlong lines
> - Use DEVICE_ATTR instead of SENSOR_DEVICE_ATTR for the adcin sys file.
> ---
> drivers/hwmon/Kconfig | 10 ++
> drivers/hwmon/Makefile | 1 +
> drivers/hwmon/jz4740-hwmon.c | 226 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 237 insertions(+), 0 deletions(-)
> create mode 100644 drivers/hwmon/jz4740-hwmon.c
> (...)
Acked-by: Jean Delvare <khali@linux-fr.org>
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic
2010-06-19 5:08 [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic JZ4740 Lars-Peter Clausen
2010-06-19 5:08 ` [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver Lars-Peter Clausen
@ 2010-06-20 9:26 ` Thomas Bogendoerfer
2010-06-21 2:56 ` Xiangfu Liu
1 sibling, 1 reply; 11+ messages in thread
From: Thomas Bogendoerfer @ 2010-06-20 9:26 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Ralf Baechle, linux-mips, linux-kernel, Alessandro Zummo,
Andrew Morton, Anton Vorontsov, David Brownell, David Woodhouse,
Greg Kroah-Hartman, Liam Girdwood, Mark Brown, Paul Gortmaker,
Samuel Ortiz, alsa-devel, linux-fbdev, linux-mmc, linux-mtd,
linux-usb, lm-sensors, rtc-linux
On Sat, Jun 19, 2010 at 07:08:05AM +0200, Lars-Peter Clausen wrote:
> This patch series adds support for the Ingenic JZ4740 System-on-a-Chip.
great stuff. I have a JZ4730 based netbook, for which I started magling
the provided sources quite some time ago, but I didn't reach the
point of submitting patches... there are a lot of common stuff between
JZ4730 and JZ4740 so IMHO it would be a good thing not to nail
everthing to JZ4740 namewise. It might also a good idea to select
something like arch/mips/jzrisc as base directory, put the
factored out code there and add JZ4730/JZ4740 in either seperate
files or directories.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea. [ RFC1925, 2.3 ]
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic
2010-06-20 9:26 ` [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic Thomas Bogendoerfer
@ 2010-06-21 2:56 ` Xiangfu Liu
0 siblings, 0 replies; 11+ messages in thread
From: Xiangfu Liu @ 2010-06-21 2:56 UTC (permalink / raw)
To: Thomas Bogendoerfer
Cc: Lars-Peter Clausen, Ralf Baechle, linux-mips, linux-kernel,
Alessandro Zummo, Andrew Morton, Anton Vorontsov, David Brownell,
David Woodhouse, Greg Kroah-Hartman, Liam Girdwood, Mark Brown,
Paul Gortmaker, Samuel Ortiz, alsa-devel, linux-fbdev, linux-mmc,
linux-mtd, linux-usb, lm-sensors, rtc-linux
On 06/20/2010 05:26 PM, Thomas Bogendoerfer wrote:
> great stuff. I have a JZ4730 based netbook, for which I started magling
> the provided sources quite some time ago, but I didn't reach the
> point of submitting patches... there are a lot of common stuff between
> JZ4730 and JZ4740 so IMHO it would be a good thing not to nail
> everthing to JZ4740 namewise. It might also a good idea to select
> something like arch/mips/jzrisc as base directory, put the
Hi Thomas
I would advice "xburst" instead jzrisc. because the Ingenic call
their cpu "XBurst" series. like: XBurst JZ4740, XBurst JZ4750 ...
> factored out code there and add JZ4730/JZ4740 in either seperate
> files or directories.
--
Best Regards
Xiangfu Liu
http://www.openmobilefree.net
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-06-21 2:56 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-19 5:08 [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic JZ4740 Lars-Peter Clausen
2010-06-19 5:08 ` [lm-sensors] [PATCH v2 23/26] hwmon: Add JZ4740 ADC driver Lars-Peter Clausen
2010-06-19 8:36 ` Jean Delvare
2010-06-19 12:58 ` Lars-Peter Clausen
2010-06-19 14:47 ` [lm-sensors] [PATCH v3] " Lars-Peter Clausen
2010-06-19 16:24 ` Jean Delvare
2010-06-19 17:59 ` Lars-Peter Clausen
2010-06-19 19:32 ` [lm-sensors] [PATCH v4] " Lars-Peter Clausen
2010-06-20 6:32 ` Jean Delvare
2010-06-20 9:26 ` [lm-sensors] [PATCH v2 00/26] Add support for the Ingenic Thomas Bogendoerfer
2010-06-21 2:56 ` Xiangfu Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox