EP93XX: Add ADC support
Subsystems (5)
RFC PATCH 1/1 EP93XX: Add ADC support
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)
This is a first draft. Comments and criticism welcome.
---
arch/arm/mach-ep93xx/Makefile | 2 arch/arm/mach-ep93xx/adc.c | 415 +++++++++++++++++++++++ arch/arm/mach-ep93xx/clock.c | 7 arch/arm/mach-ep93xx/core.c | 31 ++ arch/arm/mach-ep93xx/include/mach/adc.h | 54 +++ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | 21 + arch/arm/mach-ep93xx/include/mach/hwmon.h | 43 ++ arch/arm/mach-ep93xx/ts72xx.c | 78 ++++ drivers/hwmon/Kconfig | 17 + drivers/hwmon/Makefile | 1 drivers/hwmon/ep93xx-hwmon.c | 416 +++++++++++++++++++++++ 11 files changed, 1083 insertions(+), 2 deletions(-) create mode 100644 arch/arm/mach-ep93xx/adc.c create mode 100644 arch/arm/mach-ep93xx/include/mach/adc.h create mode 100644 arch/arm/mach-ep93xx/include/mach/hwmon.h create mode 100644 drivers/hwmon/ep93xx-hwmon.c
arch/arm/mach-ep93xx/Makefile +2 -0
@@ -6,6 +6,8 @@ obj-m := obj-n := obj- := +obj-$(CONFIG_EP93XX_ADC) += adc.o + obj-$(CONFIG_MACH_ADSSPHERE) += adssphere.o obj-$(CONFIG_MACH_EDB93XX) += edb93xx.o obj-$(CONFIG_MACH_GESBC9312) += gesbc9312.o
arch/arm/mach-ep93xx/adc.c new file +415 -0
415 lines not on this page · raw message
arch/arm/mach-ep93xx/clock.c +7 -0
@@ -72,6 +72,12 @@ static struct clk clk_keypad = { .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_KEN, .set_rate = set_keytchclk_rate, }; +static struct clk clk_analog = { + .sw_locked =1 , + .enable_reg =EP93XX_SYSCON_KEYTCHCLKDIV , + .enable_mask =EP93XX_SYSCON_KEYTCHCLKDIV_TSEN , + .set_rate = set_keytchclk_rate, +};static struct clk clk_pwm = { .rate =EP93XX_EXT_CLK_RATE , };
@@ -147,6 +153,7 @@ static struct clk_lookup clocks[] = {INIT_CK (NULL ,"pll2" , &clk_pll2),INIT_CK ("ep93xx-ohci" ,NULL , &clk_usb_host),INIT_CK ("ep93xx-keypad" ,NULL , &clk_keypad), +INIT_CK ("ep93xx-analog" ,NULL , &clk_analog),INIT_CK ("ep93xx-fb" ,NULL , &clk_video),INIT_CK (NULL ,"pwm_clk" , &clk_pwm), INIT_CK(NULL, "m2p0", &clk_m2p0),
arch/arm/mach-ep93xx/core.c +31 -0
@@ -684,6 +684,37 @@ EXPORT_SYMBOL(ep93xx_pwm_release_gpio);/************************************************************************* +* EP93xx Analog Touch Screen Interface peripheral handling. +* Note: TS and ADC share the same resource +*************************************************************************/ +static struct resource ep93xx_analog_resource[] = { + [0 ] = { + .start =EP93XX_TS_PHYS_BASE , + .end =EP93XX_TS_PHYS_BASE +0x24 -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =IRQ_EP93XX_TOUCH , + .end =IRQ_EP93XX_TOUCH , + .flags =IORESOURCE_IRQ , + }, +}; + +struct platform_device ep93xx_analog_device = { + .name ="ep93xx-analog" , + .id =-1 , + .num_resources =ARRAY_SIZE (ep93xx_analog_resource), + .resource = ep93xx_analog_resource, +}; + +/* HWMON */ +struct platform_device ep93xx_hwmon_device = { + .name ="ep93xx-hwmon" , + .id =-1 , + .dev.parent = &ep93xx_analog_device.dev, +}; + +/************************************************************************* * EP93xx video peripheral handling *************************************************************************/ static struct ep93xxfb_mach_info ep93xxfb_data;
arch/arm/mach-ep93xx/include/mach/adc.h new file +54 -0
54 lines not on this page · raw message
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +19 -2
@@ -145,8 +145,25 @@#define EP93XX_KEY_MATRIX_BASE EP93XX_APB_IOMEM(0x000f0000) -#define EP93XX_ADC_BASE EP93XX_APB_IOMEM(0x00100000) -#define EP93XX_TOUCHSCREEN_BASE EP93XX_APB_IOMEM(0x00100000) +/* Note: +* The EP9301 and EP9302 processors support a general 12-bit ADC, but +* no touchscreen, the EP9307, EP9312 and EP9315 processors each +* support up to an 8-wire touch screen or a general 12-bit ADC +*/ +#define EP93XX_TS_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00100000) +#define EP93XX_TS_BASE EP93XX_APB_IOMEM(0x00100000) +#define EP93XX_TS_REG (x) (EP93XX_TS_BASE + (x)) +#define EP93XX_TS_SETUP EP93XX_TS_REG(0x00) +#define EP93XX_TS_SETUP_ENABLE (1<<15) +#define EP93XX_TS_XYRESULT EP93XX_TS_REG(0x08) +#define EP93XX_TS_XYRESULT_SDR (1<<31) +#define EP93XX_TS_DIRECT EP93XX_TS_REG(0x18) +#define EP93XX_TS_SWLOCK EP93XX_TS_REG(0x20) +#define EP93XX_TS_SWLOCK_UNLOCK 0x000000AA +#define EP93XX_TS_SETUP2 EP93XX_TS_REG(0x24) +#define EP93XX_TS_SETUP2_RINTEN (1<<11) +#define EP93XX_TS_SETUP2_NSIGND (1<<9) +#define EP93XX_PWM_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00110000)#define EP93XX_PWM_BASE EP93XX_APB_IOMEM(0x00110000)
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +43 -0
43 lines not on this page · raw message
arch/arm/mach-ep93xx/ts72xx.c +78 -0
108 lines not on this page · raw message
drivers/hwmon/Kconfig +17 -0
@@ -690,6 +690,23 @@ config SENSORS_S3C_RAW Say Y here if you want to include raw copies of all the ADC channels in sysfs. +config SENSORS_EP93XX + tristate "EP93XX on-chip ADC" + depends on ARCH_EP93XX + help + If you say yes here you get support for the on-board ADCs of + the Cirrus Logic EP93XX series of SoC + + This driver can also be built as a module. If so, the module + will be called ep93xx-hwmo. + +config SENSORS_EP93XX_RAW + bool "Include raw channel attributes in sysfs" + depends on SENSORS_EP93XX + help + Say Y here if you want to include raw copies of all the ADC + channels in sysfs. + config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on PCI
drivers/hwmon/Makefile +1 -0
@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o +obj-$(CONFIG_SENSORS_EP93XX) += ep93xx-hwmon.o obj-$(CONFIG_SENSORS_SHT15) += sht15.o obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
drivers/hwmon/ep93xx-hwmon.c new file +416 -0
416 lines not on this page · raw message
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 18 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)
Quoted 1 line
This is a first draft. Comments and criticism welcome.
Hi Christian, some comments below.
Quoted 102 lines
Signed-off-by Christian Gagneraud <[email protected]>---
arch/arm/mach-ep93xx/Makefile | 2 arch/arm/mach-ep93xx/adc.c | 415 +++++++++++++++++++++++ arch/arm/mach-ep93xx/clock.c | 7 arch/arm/mach-ep93xx/core.c | 31 ++ arch/arm/mach-ep93xx/include/mach/adc.h | 54 +++ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | 21 + arch/arm/mach-ep93xx/include/mach/hwmon.h | 43 ++ arch/arm/mach-ep93xx/ts72xx.c | 78 ++++ drivers/hwmon/Kconfig | 17 + drivers/hwmon/Makefile | 1 drivers/hwmon/ep93xx-hwmon.c | 416 +++++++++++++++++++++++ 11 files changed, 1083 insertions(+), 2 deletions(-) create mode 100644 arch/arm/mach-ep93xx/adc.c create mode 100644 arch/arm/mach-ep93xx/include/mach/adc.h create mode 100644 arch/arm/mach-ep93xx/include/mach/hwmon.h create mode 100644 drivers/hwmon/ep93xx-hwmon.carch/arm/mach-ep93xx/Makefile +2
-0@@ -6,6 +6,8 @@ obj-m := obj-n := obj- := +obj-$(CONFIG_EP93XX_ADC) += adc.o + obj-$(CONFIG_MACH_ADSSPHERE) += adssphere.o obj-$(CONFIG_MACH_EDB93XX) += edb93xx.o obj-$(CONFIG_MACH_GESBC9312) += gesbc9312.oarch/arm/mach-ep93xx/adc.c new file +62
-0@@ -0,0 +1,415 @@ +/* +* arch/arm/mach-ep93xx/adc.c +* +* ADC support for Cirrus EP93xx chips. +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c24xx/adc.c by Simtec Electronics +* +* 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. +*/ + +/* +* Touchscreen and Direct ADC: +* +* +------------------------+-----+-----+-----+-----+ +* |ADC/TS driver in use | n/n | y/n | n/y | y/y | +* +------------------------+-----+-----+-----+-----+ +* |SYSCON_DEVCFG_ADCPD | 1 | 0 | 0 | 0 | +* |SYSCON_DEVCFG_TIN | X | 1 | 0 | 1/0 | +* |SYSCON_KEYTCHCLKDIV_TSEN| 0 | 1 | 1 | 1 | +* |TS_SETUP_ENABLE (*) | 0 | 0 | 1 | 0/1 | +* +------------------------+-----+-----+-----+-----+ +* (*) +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/platform_device.h> +#include <linux/list.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/sched.h> + +#include <mach/hardware.h> + +static inline void ep93xx_adc_set_reg (void __iomem *reg, +unsigned long val) +{ +__raw_writel (EP93XX_TS_SWLOCK_UNLOCK ,EP93XX_TS_SWLOCK ); +__raw_writel (val, reg); +} + +static inline void ep93xx_adc_clr_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val &= ~bits; +ep93xx_adc_set_reg (reg,val); +} + +static inline void ep93xx_adc_set_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val |= bits;
arch/arm/mach-ep93xx/adc.c line 72
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ep93xx_adc_set_reg (reg,val); +} + +struct ep93xx_adc_client { +struct platform_device *pdev; +struct list_head pend; +wait_queue_head_t *wait; +unsigned int nr_samples; +int result; +unsigned int channel;
Tab delimiting can make these easier to read, ie:
struct ep93xx_adc_client {
struct platform_device *pdev;
struct list_head pend;
wait_queue_head_t *wait;
...
};Quoted 8 lines
arch/arm/mach-ep93xx/adc.c new file +8
-0+}; + +struct adc_device { +struct platform_device *pdev; +struct platform_device *owner; +struct clk *clk; +struct ep93xx_adc_client *cur; +void __iomem *regs;
arch/arm/mach-ep93xx/adc.c line 90
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+int irq; +unsigned int refm;/* Reading when Vin = Vref- */ +unsigned int refp;/* Reading when Vin = Vref+ */ +}; + +static struct adc_device *adc_dev; + +static LIST_HEAD (adc_pending); + +#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg)
Bit of a nitpick, but can you move the structure definitions and variable declarations above the first functions in this file.
Quoted 7 lines
arch/arm/mach-ep93xx/adc.c new file +7
-0+ +static inline void ep93xx_adc_convert (struct adc_device *adc) +{ +unsigned long prev_switch; +unsigned long next_switch; + +/* Configure the switches */
arch/arm/mach-ep93xx/adc.c line 107
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ prev_switch =__raw_readl (EP93XX_TS_DIRECT ); + next_switch = adc->cur->channel; +if (next_switch != prev_switch) { +ep93xx_adc_set_reg (EP93XX_TS_DIRECT , next_switch); +/* Channel switch settling time */ +/* TODO: depends on clock speed (500us or 2ms) */ +/* FIXME: the caller has disabled interrupts and the +* caller can even be the irq handler. Should we +* better fire a timer? */ +mdelay (2 );
Perhaps make the mdelay value a platform data in the meantime then?
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+ } + +/* Fire ADC engine with Sync Data Ready IRQ enabled */ +ep93xx_adc_set_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_RINTEN ); +__raw_readl (EP93XX_TS_XYRESULT );
arch/arm/mach-ep93xx/adc.c line 122
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+} + +static void ep93xx_adc_try (struct adc_device *adc) +{ +struct ep93xx_adc_client *next; + +if (!list_empty (&adc_pending)) { + next =list_first_entry (&adc_pending, + struct ep93xx_adc_client, pend); +list_del (&next->pend);
Are all of the callers of ep93xx_adc_try safely locked?
Quoted 4 lines
arch/arm/mach-ep93xx/adc.c new file +4
-0+adc_dbg (adc,"new client is %p\n" , next); + adc->cur = next; +ep93xx_adc_convert (adc); + }
arch/arm/mach-ep93xx/adc.c line 136
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+} + +int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned long channel,unsigned int nr_samples) +{ +struct adc_device *adc = adc_dev; +unsigned long flags; + +if (!adc) { +printk (KERN_ERR "%s: failed to find adc\n" , __func__);
Change to:
pr_error("ep93xx_adc: %s: Failed to find adc\n", __func__);Quoted 39 lines
arch/arm/mach-ep93xx/adc.c new file +39
-0+return -EINVAL ; + } + +local_irq_save (flags); + + client->channel = channel; + client->nr_samples = nr_samples; + +list_add_tail (&client->pend, &adc_pending); + +if (!adc->cur) +ep93xx_adc_try (adc); +local_irq_restore (flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (ep93xx_adc_start); + +static void ep93xx_convert_done (struct ep93xx_adc_client *client, +unsigned val,unsigned *left) +{ + client->result = val; +wake_up (client->wait); +} + +int ep93xx_adc_read (struct ep93xx_adc_client *client,unsigned int ch) +{ +DECLARE_WAIT_QUEUE_HEAD_ONSTACK (wake); +int ret; + + client->wait = &wake; + client->result =-1 ; + + ret =ep93xx_adc_start (client, ch,1 ); +if (ret <0 ) + goto err; + + ret =wait_event_timeout (wake, client->result >=0 ,HZ /2 ); +if (client->result <0 ) {
arch/arm/mach-ep93xx/adc.c line 185
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ ret = -ETIMEDOUT ; + goto err; + } + +return client->result; + err: +return ret; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_convert);
The function ep93xx_adc_convert is static inline, so this doesn't make sense (unless I'm missing something). The s3c code also looks broken is this regard (s3c_adc_convert isn't used anywhere but the driver). I think this should be exporting ep93xx_adc_read?
arch/arm/mach-ep93xx/adc.c line 191
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+ +struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device *pdev) +{ +struct ep93xx_adc_client *client; + +printk ("adc_register: %s\n" , pdev->name);
Do we need to print this? Maybe use pr_debug or dev_dbg?
arch/arm/mach-ep93xx/adc.c line 193
Quoted 2 lines
arch/arm/mach-ep93xx/adc.c new file +2
-0+ +WARN_ON (!pdev);
You dereference pdev above this line so you will have already bugged :-).
Quoted 45 lines
arch/arm/mach-ep93xx/adc.c new file +45
-0+ +if (!pdev) +return ERR_PTR (-EINVAL ); + + client =kzalloc (sizeof (struct ep93xx_adc_client ),GFP_KERNEL ); +if (!client) { +dev_err (&pdev->dev,"no memory for adc client\n" ); +return ERR_PTR (-ENOMEM ); + } + + client->pdev = pdev; + +return client; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_register); + +void ep93xx_adc_release (struct ep93xx_adc_client *client) +{ +struct list_head *p, *n; +struct ep93xx_adc_client *tmp; + +/* We should really check that nothing is in progress. */ +if (adc_dev->cur == client) + adc_dev->cur =NULL ; + +list_for_each_safe (p, n, &adc_pending) { + tmp = list_entry(p, struct ep93xx_adc_client, pend); +if (tmp == client) +list_del (&tmp->pend); + } + +if (adc_dev->cur ==NULL ) +ep93xx_adc_try (adc_dev); +kfree (client); +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_release); + +static irqreturn_t ep93xx_adc_irq (int irq,void *pw) +{ +struct adc_device *adc = pw; +struct ep93xx_adc_client *client = adc->cur; +unsigned long flags; +unsigned long data;
arch/arm/mach-ep93xx/adc.c line 248
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ +if (!client) { +dev_warn (&adc->pdev->dev,"%s: no adc pending\n" , + __func__); +return IRQ_HANDLED ; + } + +/* Read and convert data */ + data =__raw_readl (EP93XX_TS_XYRESULT ); + data &=0x0000FFFF ;
data &= 0xffff; is fine.
arch/arm/mach-ep93xx/adc.c line 250
Quoted 2 lines
arch/arm/mach-ep93xx/adc.c new file +2
-0+if (data <0x7000 ) + data +=0x10000 ;
Nitpick: data |= 0x10000 is a bit more clear.
arch/arm/mach-ep93xx/adc.c line 258
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c new file +8
-0+ data -= adc->refm; + + client->nr_samples--; + +ep93xx_convert_done (client, data, &client->nr_samples); + +/* If all samples are done, disable IRQ, and kick start the next +* one if any. */
This comment doesn't make sense. If all samples are done, kick start the next one? Am I missing something?
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+if (client->nr_samples ==0 ) { +local_irq_save (flags); + adc->cur =NULL ; +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 , +EP93XX_TS_SETUP2_RINTEN ); +ep93xx_adc_try (adc); +local_irq_restore (flags); + } + +return IRQ_HANDLED ;
arch/arm/mach-ep93xx/adc.c line 278
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+} + +static int ep93xx_adc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct adc_device *adc; +struct resource *regs; +int ret; + +printk ("adc_probe: %s\n" , pdev->name);
pr_debug.
Quoted 37 lines
arch/arm/mach-ep93xx/adc.c new file +37
-0+ + adc =kzalloc (sizeof (struct adc_device ),GFP_KERNEL ); +if (adc ==NULL ) { +dev_err (dev,"failed to allocate adc_device\n" ); +return -ENOMEM ; + } + + adc->pdev = pdev; + + adc->irq =platform_get_irq (pdev,0 ); +if (adc->irq <=0 ) { +dev_err (dev,"failed to get adc irq\n" ); + ret = -ENOENT ; + goto err_alloc; + } + + ret =request_irq (adc->irq, ep93xx_adc_irq,IRQF_DISABLED , +dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"failed to attach adc irq\n" ); + goto err_alloc; + } + + adc->clk =clk_get (dev,"ep93xx-analog" ); +if (IS_ERR (adc->clk)) { +dev_err (dev,"failed to get ADC clock\n" ); + ret =PTR_ERR (adc->clk); + goto err_irq; + } + + regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!regs) { +dev_err (dev,"failed to find registers\n" ); + ret = -ENXIO ; + goto err_clk; + } +
arch/arm/mach-ep93xx/adc.c line 325
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ adc->regs =ioremap (regs->start,resource_size (regs)); +if (!adc->regs) { +dev_err (dev,"failed to map registers\n" ); + ret = -ENXIO ; + goto err_clk; + } + +clk_enable (adc->clk); + +// Enable ADC, inactivate TS controller
/* */ comments please.
arch/arm/mach-ep93xx/adc.c line 333
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c new file +8
-0+ep93xx_devcfg_set_clear (EP93XX_SYSCON_DEVCFG_TIN , +EP93XX_SYSCON_DEVCFG_ADCPD ); +// Disable TS engine +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP ,EP93XX_TS_SETUP_ENABLE ); +// Set ADC to signed mode +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_NSIGND ); + +dev_info (dev,"attached adc driver\n" );
Don't really need to pollute the dmesg output.
arch/arm/mach-ep93xx/adc.c line 338
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+ +platform_set_drvdata (pdev, adc); + +/* Defaults from datasheet (approximated values) */ + adc->refm =0xFFFF -25000 ;
Erk, why two different bases? Can we just #define these values somewhere.
arch/arm/mach-ep93xx/adc.c line 345
Quoted 7 lines
arch/arm/mach-ep93xx/adc.c new file +7
-0+ adc->refp =25000 ; + adc_dev = adc; + +return 0 ; + + err_clk: +clk_put (adc->clk);
clk_disable?
Quoted 39 lines
arch/arm/mach-ep93xx/adc.c new file +39
-0+ + err_irq: +free_irq (adc->irq, adc); + + err_alloc: +kfree (adc); +return ret; + +} + +static int ep93xx_adc_remove (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); + +iounmap (adc->regs); +free_irq (adc->irq, adc); +clk_disable (adc->clk); +clk_put (adc->clk); +kfree (adc); + +return 0 ; +} + +#ifdef CONFIG_PM +static int ep93xx_adc_suspend (struct platform_device *pdev, +pm_message_t state) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +ep93xx_devcfg_clear (EP93XX_SYSCON_DEVCFG_ADCPD ); +clk_disable (adc->clk); +return 0 ; +} + +static int ep93xx_adc_resume (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +clk_enable (adc->clk); +ep93xx_devcfg_set (EP93XX_SYSCON_DEVCFG_ADCPD ); +return 0 ;
arch/arm/mach-ep93xx/adc.c line 394
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+} + +#else +#define ep93xx_adc_suspend NULL +#define ep93xx_adc_resume NULL +#endif + +static struct platform_driver ep93xx_adc_driver = { + .driver = { + .name ="ep93xx-analog" ,
Why not ep93xx-adc?
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+ .owner = THIS_MODULE, + }, + .probe = ep93xx_adc_probe, + .remove = __devexit_p(ep93xx_adc_remove), + .suspend = ep93xx_adc_suspend, + .resume = ep93xx_adc_resume,
arch/arm/mach-ep93xx/adc.c line 410
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+}; + +static int __init adc_init (void ) +{ +int ret; + + ret =platform_driver_register (&ep93xx_adc_driver); +if (ret) +printk (KERN_ERR "%s: failed to add adc driver\n" , + __func__);
pr_error.
Quoted 102 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+ +return ret; +} + +arch_initcall (adc_init);arch/arm/mach-ep93xx/clock.c +7
-0@@ -72,6 +72,12 @@ static struct clk clk_keypad = { .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_KEN, .set_rate = set_keytchclk_rate, }; +static struct clk clk_analog = { + .sw_locked =1 , + .enable_reg =EP93XX_SYSCON_KEYTCHCLKDIV , + .enable_mask =EP93XX_SYSCON_KEYTCHCLKDIV_TSEN , + .set_rate = set_keytchclk_rate, +};static struct clk clk_pwm = { .rate =EP93XX_EXT_CLK_RATE , };@@ -147,6 +153,7 @@ static struct clk_lookup clocks[] = {INIT_CK (NULL ,"pll2" , &clk_pll2),INIT_CK ("ep93xx-ohci" ,NULL , &clk_usb_host),INIT_CK ("ep93xx-keypad" ,NULL , &clk_keypad), +INIT_CK ("ep93xx-analog" ,NULL , &clk_analog),INIT_CK ("ep93xx-fb" ,NULL , &clk_video),INIT_CK (NULL ,"pwm_clk" , &clk_pwm), INIT_CK(NULL, "m2p0", &clk_m2p0),arch/arm/mach-ep93xx/core.c +31
-0@@ -684,6 +684,37 @@ EXPORT_SYMBOL(ep93xx_pwm_release_gpio);/************************************************************************* +* EP93xx Analog Touch Screen Interface peripheral handling. +* Note: TS and ADC share the same resource +*************************************************************************/ +static struct resource ep93xx_analog_resource[] = { + [0 ] = { + .start =EP93XX_TS_PHYS_BASE , + .end =EP93XX_TS_PHYS_BASE +0x24 -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =IRQ_EP93XX_TOUCH , + .end =IRQ_EP93XX_TOUCH , + .flags =IORESOURCE_IRQ , + }, +}; + +struct platform_device ep93xx_analog_device = { + .name ="ep93xx-analog" , + .id =-1 , + .num_resources =ARRAY_SIZE (ep93xx_analog_resource), + .resource = ep93xx_analog_resource, +}; + +/* HWMON */ +struct platform_device ep93xx_hwmon_device = { + .name ="ep93xx-hwmon" , + .id =-1 , + .dev.parent = &ep93xx_analog_device.dev, +}; + +/************************************************************************* * EP93xx video peripheral handling *************************************************************************/ static struct ep93xxfb_mach_info ep93xxfb_data;arch/arm/mach-ep93xx/include/mach/adc.h new file +24
-0@@ -0,0 +1,54 @@ +/* arch/arm/mach-ep93xx/include/arch/adc.h +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c/include/plat/adc.h by Simtec Electronics +* +* EP93XX ADC driver information +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_ADC_H +#define __ASM_ARCH_ADC_H __FILE__ + +/* ADC Channels definition (switches) */ +#define ADC_SW_XP_IN (1<<0) +#define ADC_SW_XM_IN (1<<1) +#define ADC_SW_YP_IN (1<<2) +#define ADC_SW_YM_IN (1<<3) +#define ADC_SW_SXP_IN (1<<4) +#define ADC_SW_SXM_IN (1<<5) +#define ADC_SW_SYP_IN (1<<6)
arch/arm/mach-ep93xx/include/mach/adc.h line 34
Quoted 10 lines
arch/arm/mach-ep93xx/include/mach/adc.h new file +10
-0+#define ADC_SW_SYM_IN (1<<7) +#define ADC_SW_VBAT_IN (1<<8) +#define ADC_SW_AVDD_REFP (1<<9) +#define ADC_SW_AGND_REFM (1<<10) +#define ADC_SW_SXP_REFP (1<<24) +#define ADC_SW_SXM_REFM (1<<25) +#define ADC_SW_SYP_REFP (1<<26) +#define ADC_SW_SYM_REFM (1<<27) +#define ADC_SW_DAC_IN (1<<29) +#define ADC_SW_IN_LOAD (1<<30)
Nitpick, spaces around <<
arch/arm/mach-ep93xx/include/mach/adc.h line 37
Quoted 3 lines
arch/arm/mach-ep93xx/include/mach/adc.h new file +3
-0+ +/* AGND as VREF-, AVDD as VREF+ */ +#define ADC_SW_APWR_REF (ADC_SW_AVDD_REFP|ADC_SW_AGND_REFM)
Spaces around |
Quoted 60 lines
arch/arm/mach-ep93xx/include/mach/adc.h new file +17
-0+ +struct ep93xx_adc_client ; + +extern struct platform_device ep93xx_analog_device; + +extern int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned int channel,unsigned int nr_samples); + +extern int ep93xx_adc_read (struct ep93xx_adc_client *client, +unsigned int ch); + +extern struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device + *pdev); + +extern void ep93xx_adc_release (struct ep93xx_adc_client *client); + +#endif /* __ASM_ARCH_ADC_H */ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +19
-2@@ -145,8 +145,25 @@#define EP93XX_KEY_MATRIX_BASE EP93XX_APB_IOMEM(0x000f0000) -#define EP93XX_ADC_BASE EP93XX_APB_IOMEM(0x00100000) -#define EP93XX_TOUCHSCREEN_BASE EP93XX_APB_IOMEM(0x00100000) +/* Note: +* The EP9301 and EP9302 processors support a general 12-bit ADC, but +* no touchscreen, the EP9307, EP9312 and EP9315 processors each +* support up to an 8-wire touch screen or a general 12-bit ADC +*/ +#define EP93XX_TS_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00100000) +#define EP93XX_TS_BASE EP93XX_APB_IOMEM(0x00100000) +#define EP93XX_TS_REG (x) (EP93XX_TS_BASE + (x)) +#define EP93XX_TS_SETUP EP93XX_TS_REG(0x00) +#define EP93XX_TS_SETUP_ENABLE (1<<15) +#define EP93XX_TS_XYRESULT EP93XX_TS_REG(0x08) +#define EP93XX_TS_XYRESULT_SDR (1<<31) +#define EP93XX_TS_DIRECT EP93XX_TS_REG(0x18) +#define EP93XX_TS_SWLOCK EP93XX_TS_REG(0x20) +#define EP93XX_TS_SWLOCK_UNLOCK 0x000000AA +#define EP93XX_TS_SETUP2 EP93XX_TS_REG(0x24) +#define EP93XX_TS_SETUP2_RINTEN (1<<11) +#define EP93XX_TS_SETUP2_NSIGND (1<<9) +#define EP93XX_PWM_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00110000)#define EP93XX_PWM_BASE EP93XX_APB_IOMEM(0x00110000)arch/arm/mach-ep93xx/include/mach/hwmon.h new file +5
-0@@ -0,0 +1,43 @@ +/* linux/arch/arm/mach-ep93xx/include/arch/hwmon.h +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on linux/arch/arm/plat-s3c/include/plat/hwmon.h by Simtec Electronics
arch/arm/mach-ep93xx/include/mach/hwmon.h line 15
Quoted 10 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +10
-0+* +* EP93XX - HWMon interface for ADC +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_HWMON_H +#define __ASM_ARCH_HWMON_H __FILE__
Stray __FILE__?
Quoted 68 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +28
-0+ +extern struct platform_device ep93xx_hwmon_device; + +/** +* ep93xx_hwmon_chcfg - channel configuration +* @name: The name to give this channel. +* @mult: Multiply the ADC value read by this. +* @div: Divide the value from the ADC by this. +* +* The value read from the ADC is converted to a value that +* hwmon expects (mV) by result = (value_read * @mult) / @div. +*/ +struct ep93xx_hwmon_chcfg { +const char *name; +unsigned long channel; +unsigned long mult; +unsigned long div; +}; + +/** +* ep93xx_hwmon_pdata - HWMON platform data +* @in: One configuration for each possible channel used. +*/ +struct ep93xx_hwmon_data { +struct ep93xx_hwmon_chcfg *in[7 ]; +}; + +#endif /* __ASM_ARCH_HWMON_H */ arch/arm/mach-ep93xx/ts72xx.c +11
-0@@ -18,6 +18,8 @@#include <linux/mtd/physmap.h> #include <mach/hardware.h> +#include <mach/adc.h> +#include <mach/hwmon.h> #include <mach/ts72xx.h> #include <asm/mach-types.h> @@ -92,6 +94,8 @@ static struct map_desc ts72xx_alternate_nand_io_desc[] __initdata = { } }; +static struct ep93xx_hwmon_data ts72xx_hwmon_info; +static void __init ts72xx_map_io (void ) {ep93xx_map_io ();@@ -109,6 +113,8 @@ static void __init ts72xx_map_io(void) ARRAY_SIZE(ts72xx_nand_io_desc)); } } + + ep93xx_hwmon_device.dev.platform_data = &ts72xx_hwmon_info; }/************************************************************************* @@ -170,6 +176,74 @@ static struct ep93xx_eth_data ts72xx_eth_data = { .phy_id = 1, }; + +#define TS72XX_ADC0 (ADC_SW_YM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC1 (ADC_SW_SXP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC2 (ADC_SW_SXM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC3 (ADC_SW_SYP_IN | ADC_SW_APWR_REF)
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 193
Quoted 10 lines
arch/arm/mach-ep93xx/ts72xx.c +10
-0+#define TS72XX_ADC4 (ADC_SW_SYM_IN | ADC_SW_APWR_REF) + +// TODO: board dependant +// TS-7200: ADC0, ADC4 +// TS-7250: ADC0 to ADC4 +// TS-7260: Vin, 5V_104, ADC2, Vcore, ADC4 +// TS-7300: 5V, 1.2V, ADC2, 1.8V, ADC4 + +// 0V gives 0, 3.3V gives c. 50000 +// TODO: self calibrate by using VBAT and Load resistor switches
/* */ comments please.
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 196
Quoted 3 lines
arch/arm/mach-ep93xx/ts72xx.c +3
-0+static struct ep93xx_hwmon_data ts72xx_hwmon_info = { +/* POWER_IN*10K/150K (4.5-20V) */ + .in[0 ] = &(struct ep93xx_hwmon_chcfg ) {
That cast looks really ugly, is there a better way?
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 200
Quoted 4 lines
arch/arm/mach-ep93xx/ts72xx.c +4
-0+ .name = "ts72xx-vin", + .channel = TS72XX_ADC0, + .mult = 33*(15+1), + .div = 500*1,
Spaces around operators please. Also why the explict multiplies (especially by 1)?
Quoted 528 lines
arch/arm/mach-ep93xx/ts72xx.c +50
-0+ }, + /* PC104_5V*10K/54.9K (5V) */ + .in[1] = &(struct ep93xx_hwmon_chcfg) { + .name ="ts72xx-v5" , + .channel =TS72XX_ADC4 , + .mult =33 *(549 +100 ), + .div =500 *100 , + }, +/* Vcore (1.8V) */ + .in[2 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-vcore" , + .channel =TS72XX_ADC2 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.8 (0-3.3V) */ + .in[3 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.8" , + .channel =TS72XX_ADC3 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.10 (0-3.3V) */ + .in[4 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.10" , + .channel =TS72XX_ADC1 , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.VBAT (1.8V) */ + .in[5 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vbat" , + .channel =ADC_SW_VBAT_IN |ADC_SW_APWR_REF , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.DAC (?) */ + .in[6 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vdac" , + .channel =ADC_SW_DAC_IN |ADC_SW_APWR_REF , + .mult =33 *1 , + .div =500 *1 , + }, +}; + +static void __init ts72xx_init_machine (void ) {ep93xx_init_devices ();@@ -177,6 +251,10 @@ static void __init ts72xx_init_machine(void)platform_device_register (&ts72xx_rtc_device);ep93xx_register_eth (&ts72xx_eth_data,1 ); + +platform_device_register (&ep93xx_analog_device); + +platform_device_register (&ep93xx_hwmon_device); }MACHINE_START (TS72XX ,"Technologic Systems TS-72xx SBC" )drivers/hwmon/Kconfig +17
-0@@ -690,6 +690,23 @@ config SENSORS_S3C_RAW Say Y here if you want to include raw copies of all the ADC channels in sysfs. +config SENSORS_EP93XX + tristate "EP93XX on-chip ADC" + depends on ARCH_EP93XX + help + If you say yes here you get support for the on-board ADCs of + the Cirrus Logic EP93XX series of SoC + + This driver can also be built as a module. If so, the module + will be called ep93xx-hwmo. + +config SENSORS_EP93XX_RAW + bool "Include raw channel attributes in sysfs" + depends on SENSORS_EP93XX + help + Say Y here if you want to include raw copies of all the ADC + channels in sysfs. + config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on PCIdrivers/hwmon/Makefile +1
-0@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o +obj-$(CONFIG_SENSORS_EP93XX) += ep93xx-hwmon.o obj-$(CONFIG_SENSORS_SHT15) += sht15.o obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.odrivers/hwmon/ep93xx-hwmon.c new file +416
-0@@ -0,0 +1,416 @@ +/* linux/drivers/hwmon/ep93xx-hwmon.c +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on linux/drivers/hwmon/s3c-hwmon.c by Simtec Electronics +* +* EP93XX ADC hwmon support +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> + +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> + +#include <mach/adc.h> +#include <mach/hwmon.h> + +struct ep93xx_hwmon_attr { +struct sensor_device_attribute in; +struct sensor_device_attribute label; +char in_name[12 ]; +char label_name[12 ]; +}; + +/** +* struct ep93xx_hwmon - ADC hwmon client information +* @lock: Access lock to serialise the conversions. +* @client: The client we registered with the EP93XX ADC core. +* @hwmon_dev: The hwmon device we created. +* @attr: The holders for the channel attributes. +*/ +struct ep93xx_hwmon { +struct semaphore lock; +struct ep93xx_adc_client *client; +struct device *hwmon_dev; +struct ep93xx_hwmon_attr attrs[7 ]; +}; + +/** +* ep93xx_hwmon_read_ch - read a value from a given adc channel. +* @dev: The device. +* @hwmon: Our state. +* @channel: The channel we're reading from. +* +* Read a value from the @channel with the proper locking and sleep until +* either the read completes or we timeout awaiting the ADC core to get +* back to us. +*/ +static int ep93xx_hwmon_read_ch (struct device *dev, +struct ep93xx_hwmon *hwmon,int channel) +{ +int ret; + + ret =down_interruptible (&hwmon->lock); +if (ret <0 ) +return ret; + +dev_dbg (dev,"reading channel %d\n" , channel); + + ret =ep93xx_adc_read (hwmon->client, channel); +up (&hwmon->lock); + +return ret; +} + +#ifdef CONFIG_SENSORS_EP93XX_RAW +/** +* ep93xx_hwmon_show_raw - show a conversion from the raw channel number. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* This show deals with the raw attribute, registered for each possible +* ADC channel. This does a conversion and returns the raw (un-scaled) +* value returned from the hardware. +*/ +static ssize_t ep93xx_hwmon_show_raw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ep93xx_hwmon *adc = +platform_get_drvdata (to_platform_device (dev)); +struct sensor_device_attribute *sa =to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sa->index]; + + ret =ep93xx_hwmon_read_ch (dev, adc, cfg->channel); + +return (ret <0 ) ? ret :snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +#define DEF_ADC_ATTR (x) \ + static SENSOR_DEVICE_ATTR(adc##x##_raw, S_IRUGO, ep93xx_hwmon_show_raw, NULL, x) + +DEF_ADC_ATTR (0 ); +DEF_ADC_ATTR (1 ); +DEF_ADC_ATTR (2 ); +DEF_ADC_ATTR (3 ); +DEF_ADC_ATTR (4 ); +DEF_ADC_ATTR (5 ); +DEF_ADC_ATTR (6 ); + +static struct attribute *ep93xx_hwmon_attrs[8 ] = { + &sensor_dev_attr_adc0_raw.dev_attr.attr, + &sensor_dev_attr_adc1_raw.dev_attr.attr, + &sensor_dev_attr_adc2_raw.dev_attr.attr, + &sensor_dev_attr_adc3_raw.dev_attr.attr, + &sensor_dev_attr_adc4_raw.dev_attr.attr, + &sensor_dev_attr_adc5_raw.dev_attr.attr, + &sensor_dev_attr_adc6_raw.dev_attr.attr, +NULL , +}; + +static struct attribute_group ep93xx_hwmon_attrgroup = { + .attrs = ep93xx_hwmon_attrs, +}; + +static inline int ep93xx_hwmon_add_raw (struct device *dev) +{ +return sysfs_create_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +sysfs_remove_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +#else + +static inline void ep93xx_hwmon_add_raw (struct device *dev) +{ +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +} + +#endif /* CONFIG_SENSORS_EP93XX_RAW */ + +/** +* ep93xx_hwmon_ch_show - show value of a given channel +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Read a value from the ADC and scale it before returning it to the +* caller. The scale factor is gained from the channel configuration +* passed via the platform data when the device was registered. +*/ +static ssize_t ep93xx_hwmon_ch_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon *hwmon = +platform_get_drvdata (to_platform_device (dev)); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sen_attr->index]; + + ret =ep93xx_hwmon_read_ch (dev, hwmon, cfg->channel); +if (ret <0 ) +return ret; + + ret *= cfg->mult; + ret =DIV_ROUND_CLOSEST (ret, cfg->div); + +return snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +/** +* ep93xx_hwmon_label_show - show label name of the given channel. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Return the label name of a given channel +*/ +static ssize_t ep93xx_hwmon_label_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; + + cfg = pdata->in[sen_attr->index]; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , cfg->name); +} + +/** +* ep93xx_hwmon_create_attr - create hwmon attribute for given channel. +* @dev: The device to create the attribute on. +* @cfg: The channel configuration passed from the platform data. +* @channel: The ADC channel number to process. +* +* Create the scaled attribute for use with hwmon from the specified +* platform data in @pdata. The sysfs entry is handled by the routine +* ep93xx_hwmon_ch_show(). +* +* The attribute name is taken from the configuration data if present +* otherwise the name is taken by concatenating in_ with the channel +* number. +*/ +static int ep93xx_hwmon_create_attr (struct device *dev, +struct ep93xx_hwmon_chcfg *cfg, +struct ep93xx_hwmon_attr *attrs, +int channel) +{ +struct sensor_device_attribute *attr; +int ret; + +snprintf (attrs->in_name,sizeof (attrs->in_name),"in%d_input" , + channel); + + attr = &attrs->in; + attr->index = channel; + attr->dev_attr.attr.name = attrs->in_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_ch_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +dev_err (dev,"failed to create input attribute\n" ); +return ret; + } + +/* if this has a name, add a label */ +if (cfg->name) { +snprintf (attrs->label_name,sizeof (attrs->label_name), +"in%d_label" , channel); + + attr = &attrs->label; + attr->index = channel; + attr->dev_attr.attr.name = attrs->label_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_label_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +device_remove_file (dev, &attrs->in.dev_attr); +dev_err (dev,"failed to create label attribute\n" ); + } + } + +return ret; +} + +static void ep93xx_hwmon_remove_attr (struct device *dev, +struct ep93xx_hwmon_attr *attrs) +{ +device_remove_file (dev, &attrs->in.dev_attr); +device_remove_file (dev, &attrs->label.dev_attr); +} + +/** +* ep93xx_hwmon_probe - device probe entry. +* @dev: The device being probed. +*/ +static int __devinit ep93xx_hwmon_probe (struct platform_device *dev) +{ +struct ep93xx_hwmon_data *pdata = dev->dev.platform_data; +struct ep93xx_hwmon *hwmon; +int ret =0 ; +int i; + +if (!pdata) { +dev_err (&dev->dev,"no platform data supplied\n" ); +return -EINVAL ; + } + + hwmon =kzalloc (sizeof (struct ep93xx_hwmon ),GFP_KERNEL ); +if (hwmon ==NULL ) { +dev_err (&dev->dev,"no memory\n" ); +return -ENOMEM ; + } + +platform_set_drvdata (dev, hwmon); + +init_MUTEX (&hwmon->lock); + +/* Register with the core ADC driver. */ + + hwmon->client =ep93xx_adc_register (dev); +if (IS_ERR (hwmon->client)) { +dev_err (&dev->dev,"cannot register adc\n" ); + ret =PTR_ERR (hwmon->client); + goto err_mem; + } + +/* add attributes for our adc devices. */ + + ret =ep93xx_hwmon_add_raw (&dev->dev); +if (ret) + goto err_registered; + +/* register with the hwmon core */ + + hwmon->hwmon_dev =hwmon_device_register (&dev->dev); +if (IS_ERR (hwmon->hwmon_dev)) { +dev_err (&dev->dev,"error registering with hwmon\n" ); + ret =PTR_ERR (hwmon->hwmon_dev); + goto err_raw_attribute; + } + +for (i =0 ; i <ARRAY_SIZE (pdata->in); i++) { +if (!pdata->in[i]) +continue ; + +if (pdata->in[i]->mult >=0x10000 ) +dev_warn (&dev->dev, +"channel %d multiplier too large\n" , i); + + ret =ep93xx_hwmon_create_attr (&dev->dev, pdata->in[i], + &hwmon->attrs[i], i); +if (ret) { +dev_err (&dev->dev, +"error creating channel %d\n" , i); + +for (i--; i >=0 ; i--) +ep93xx_hwmon_remove_attr (&dev->dev, + &hwmon->attrs[i]); + + goto err_hwmon_register; + } + } + +return 0 ; + + err_hwmon_register: +hwmon_device_unregister (hwmon->hwmon_dev); + + err_raw_attribute: +ep93xx_hwmon_remove_raw (&dev->dev); + + err_registered: +ep93xx_adc_release (hwmon->client); + + err_mem: +kfree (hwmon); +return ret; +} + +static int __devexit ep93xx_hwmon_remove(struct platform_device *dev) +{ +struct ep93xx_hwmon *hwmon =platform_get_drvdata (dev); +int i; + +ep93xx_hwmon_remove_raw (&dev->dev); + +for (i =0 ; i <ARRAY_SIZE (hwmon->attrs); i++) +ep93xx_hwmon_remove_attr (&dev->dev, &hwmon->attrs[i]); + +hwmon_device_unregister (hwmon->hwmon_dev); +ep93xx_adc_release (hwmon->client); + +return 0 ; +} + +static struct platform_driver ep93xx_hwmon_driver = { + .driver = { + .name ="ep93xx-hwmon" , + .owner =THIS_MODULE , + }, + .probe = ep93xx_hwmon_probe, + .remove =__devexit_p (ep93xx_hwmon_remove), +}; + +static int __init ep93xx_hwmon_init (void ) +{ +return platform_driver_register (&ep93xx_hwmon_driver); +} + +static void __exit ep93xx_hwmon_exit(void) +{ +platform_driver_unregister (&ep93xx_hwmon_driver); +} + +module_init (ep93xx_hwmon_init); +module_exit (ep93xx_hwmon_exit); + +MODULE_AUTHOR ("Christian Gagneraud <[email protected]>" ); +MODULE_DESCRIPTION ("EP93XX ADC HWMon driver" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:ep93xx-hwmon" );_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre Ryan Mallon 5 Amuri Park, 404 Barbadoes St ryan at bluewatersys.com PO Box 13 889, Christchurch 8013 http://www.bluewatersys.com New Zealand Phone: +64 3 3779127 Freecall: Australia 1800 148 751 Fax: +64 3 3779135 USA 1800 261 2934
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 137 lines · Ryan Mallon
Quoted 18 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)Quoted 1 line
This is a first draft. Comments and criticism welcome.
Hi Christian, some comments below.
Quoted 101 lines
Signed-off-by Christian Gagneraud <[email protected]>---
arch/arm/mach-ep93xx/Makefile | 2 arch/arm/mach-ep93xx/adc.c | 415 +++++++++++++++++++++++ arch/arm/mach-ep93xx/clock.c | 7 arch/arm/mach-ep93xx/core.c | 31 ++ arch/arm/mach-ep93xx/include/mach/adc.h | 54 +++ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | 21 + arch/arm/mach-ep93xx/include/mach/hwmon.h | 43 ++ arch/arm/mach-ep93xx/ts72xx.c | 78 ++++ drivers/hwmon/Kconfig | 17 + drivers/hwmon/Makefile | 1 drivers/hwmon/ep93xx-hwmon.c | 416 +++++++++++++++++++++++ 11 files changed, 1083 insertions(+), 2 deletions(-) create mode 100644 arch/arm/mach-ep93xx/adc.c create mode 100644 arch/arm/mach-ep93xx/include/mach/adc.h create mode 100644 arch/arm/mach-ep93xx/include/mach/hwmon.h create mode 100644 drivers/hwmon/ep93xx-hwmon.carch/arm/mach-ep93xx/Makefile +2
-0@@ -6,6 +6,8 @@ obj-m := obj-n := obj- := +obj-$(CONFIG_EP93XX_ADC) += adc.o + obj-$(CONFIG_MACH_ADSSPHERE) += adssphere.o obj-$(CONFIG_MACH_EDB93XX) += edb93xx.o obj-$(CONFIG_MACH_GESBC9312) += gesbc9312.oarch/arm/mach-ep93xx/adc.c new file +62
-0@@ -0,0 +1,415 @@ +/* +* arch/arm/mach-ep93xx/adc.c +* +* ADC support for Cirrus EP93xx chips. +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c24xx/adc.c by Simtec Electronics +* +* 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. +*/ + +/* +* Touchscreen and Direct ADC: +* +* +------------------------+-----+-----+-----+-----+ +* |ADC/TS driver in use | n/n | y/n | n/y | y/y | +* +------------------------+-----+-----+-----+-----+ +* |SYSCON_DEVCFG_ADCPD | 1 | 0 | 0 | 0 | +* |SYSCON_DEVCFG_TIN | X | 1 | 0 | 1/0 | +* |SYSCON_KEYTCHCLKDIV_TSEN| 0 | 1 | 1 | 1 | +* |TS_SETUP_ENABLE (*) | 0 | 0 | 1 | 0/1 | +* +------------------------+-----+-----+-----+-----+ +* (*) +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/platform_device.h> +#include <linux/list.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/sched.h> + +#include <mach/hardware.h> + +static inline void ep93xx_adc_set_reg (void __iomem *reg, +unsigned long val) +{ +__raw_writel (EP93XX_TS_SWLOCK_UNLOCK ,EP93XX_TS_SWLOCK ); +__raw_writel (val, reg); +} + +static inline void ep93xx_adc_clr_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val &= ~bits; +ep93xx_adc_set_reg (reg,val); +} + +static inline void ep93xx_adc_set_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val |= bits;arch/arm/mach-ep93xx/adc.c line 72
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ep93xx_adc_set_reg (reg,val); +} + +struct ep93xx_adc_client { +struct platform_device *pdev; +struct list_head pend; +wait_queue_head_t *wait; +unsigned int nr_samples; +int result; +unsigned int channel;Tab delimiting can make these easier to read, ie:
Quoted 6 lines
struct ep93xx_adc_client {
struct platform_device *pdev;
struct list_head pend;
wait_queue_head_t *wait;
...
};OK.
Quoted 14 lines
Quoted 14 lines
arch/arm/mach-ep93xx/adc.c new file +13
-0+}; + +struct adc_device { +struct platform_device *pdev; +struct platform_device *owner; +struct clk *clk; +struct ep93xx_adc_client *cur; +void __iomem *regs; +int irq; +unsigned int refm;/* Reading when Vin = Vref- */ +unsigned int refp;/* Reading when Vin = Vref+ */ +}; +
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 90
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+static struct adc_device *adc_dev; + +static LIST_HEAD (adc_pending); + +#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg)Bit of a nitpick, but can you move the structure definitions and
above the first functions in this file.
Bit of nitpick, but I will move the first functions _below_ the structure definitions and variable declarations. :)
Quoted 12 lines
Quoted 12 lines
arch/arm/mach-ep93xx/adc.c new file +11
-0+ +static inline void ep93xx_adc_convert (struct adc_device *adc) +{ +unsigned long prev_switch; +unsigned long next_switch; + +/* Configure the switches */ + prev_switch =__raw_readl (EP93XX_TS_DIRECT ); + next_switch = adc->cur->channel; +if (next_switch != prev_switch) { +ep93xx_adc_set_reg (EP93XX_TS_DIRECT , next_switch);
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 107
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+/* Channel switch settling time */ +/* TODO: depends on clock speed (500us or 2ms) */ +/* FIXME: the caller has disabled interrupts and the +* caller can even be the irq handler. Should we +* better fire a timer? */ +mdelay (2 );Perhaps make the mdelay value a platform data in the meantime then?
Actually I need to use clock_get_rate I think. But yes, why not putting the clock configuration in the platform data in the meantime.
Any particular comment about using mdelay within local_irq_save/restore context (used to protect the list), and within an interrupt handler (needed to fire the next operation).
Quoted 10 lines
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +9
-0+ } + +/* Fire ADC engine with Sync Data Ready IRQ enabled */ +ep93xx_adc_set_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_RINTEN ); +__raw_readl (EP93XX_TS_XYRESULT ); +} + +static void ep93xx_adc_try (struct adc_device *adc) +{
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 122
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+struct ep93xx_adc_client *next; + +if (!list_empty (&adc_pending)) { + next =list_first_entry (&adc_pending, + struct ep93xx_adc_client, pend); +list_del (&next->pend);Are all of the callers of
ep93xx_adc_trysafely locked?
I think they are this function is called only by ep93xx_adc_start() and the interrupt handler, both use local_irq_save/restore.
Quoted 17 lines
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +4
-0+adc_dbg (adc,"new client is %p\n" , next); + adc->cur = next; +ep93xx_adc_convert (adc); + }arch/arm/mach-ep93xx/adc.c line 136
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+} + +int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned long channel,unsigned int nr_samples) +{ +struct adc_device *adc = adc_dev; +unsigned long flags; + +if (!adc) { +printk (KERN_ERR "%s: failed to find adc\n" , __func__);Change to:
Quoted 1 line
pr_error("ep93xx_adc: %s: Failed to find adc\n", __func__);Will do.
Quoted 47 lines
Quoted 47 lines
arch/arm/mach-ep93xx/adc.c new file +46
-0+return -EINVAL ; + } + +local_irq_save (flags); + + client->channel = channel; + client->nr_samples = nr_samples; + +list_add_tail (&client->pend, &adc_pending); + +if (!adc->cur) +ep93xx_adc_try (adc); +local_irq_restore (flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (ep93xx_adc_start); + +static void ep93xx_convert_done (struct ep93xx_adc_client *client, +unsigned val,unsigned *left) +{ + client->result = val; +wake_up (client->wait); +} + +int ep93xx_adc_read (struct ep93xx_adc_client *client,unsigned int ch) +{ +DECLARE_WAIT_QUEUE_HEAD_ONSTACK (wake); +int ret; + + client->wait = &wake; + client->result =-1 ; + + ret =ep93xx_adc_start (client, ch,1 ); +if (ret <0 ) + goto err; + + ret =wait_event_timeout (wake, client->result >=0 ,HZ /2 ); +if (client->result <0 ) { + ret = -ETIMEDOUT ; + goto err; + } + +return client->result; + err: +return ret;
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 185
Quoted 3 lines
arch/arm/mach-ep93xx/adc.c new file +3
-0+} + +EXPORT_SYMBOL_GPL (ep93xx_adc_convert);The function
ep93xx_adc_convertis static inline, so this doesn't make sense (unless I'm missing something). The s3c code also looks broken is this regard (s3c_adc_convertisn't used anywhere but the driver). I think this should be exportingep93xx_adc_read?
Yes, it was a typo. I removed as well theEXPORT_SYMBOL_GPL(ep93xx_adc_start).
Quoted 9 lines
arch/arm/mach-ep93xx/adc.c line 191
Quoted 7 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+ +struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device *pdev) +{ +struct ep93xx_adc_client *client; + +printk ("adc_register: %s\n" , pdev->name);Do we need to print this? Maybe use
pr_debugordev_dbg?
Yes, it was a quick debug thingy that I forgot to remove.
Quoted 64 lines
arch/arm/mach-ep93xx/adc.c line 193
Quoted 3 lines
arch/arm/mach-ep93xx/adc.c new file +2
-0+ +WARN_ON (!pdev);You dereference pdev above this line so you will have already bugged :-).
Quoted 45 lines
arch/arm/mach-ep93xx/adc.c new file +45
-0+ +if (!pdev) +return ERR_PTR (-EINVAL ); + + client =kzalloc (sizeof (struct ep93xx_adc_client ),GFP_KERNEL ); +if (!client) { +dev_err (&pdev->dev,"no memory for adc client\n" ); +return ERR_PTR (-ENOMEM ); + } + + client->pdev = pdev; + +return client; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_register); + +void ep93xx_adc_release (struct ep93xx_adc_client *client) +{ +struct list_head *p, *n; +struct ep93xx_adc_client *tmp; + +/* We should really check that nothing is in progress. */ +if (adc_dev->cur == client) + adc_dev->cur =NULL ; + +list_for_each_safe (p, n, &adc_pending) { + tmp = list_entry(p, struct ep93xx_adc_client, pend); +if (tmp == client) +list_del (&tmp->pend); + } + +if (adc_dev->cur ==NULL ) +ep93xx_adc_try (adc_dev); +kfree (client); +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_release); + +static irqreturn_t ep93xx_adc_irq (int irq,void *pw) +{ +struct adc_device *adc = pw; +struct ep93xx_adc_client *client = adc->cur; +unsigned long flags; +unsigned long data;arch/arm/mach-ep93xx/adc.c line 248
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ +if (!client) { +dev_warn (&adc->pdev->dev,"%s: no adc pending\n" , + __func__); +return IRQ_HANDLED ; + } + +/* Read and convert data */ + data =__raw_readl (EP93XX_TS_XYRESULT ); + data &=0x0000FFFF ;data &=
0xffff; is fine.
Quoted 4 lines
arch/arm/mach-ep93xx/adc.c line 250
Quoted 2 lines
arch/arm/mach-ep93xx/adc.c new file +2
-0+if (data <0x7000 ) + data +=0x10000 ;Nitpick: data |=
0x10000is a bit more clear.
OK, no problem.
Quoted 12 lines
arch/arm/mach-ep93xx/adc.c line 258
Quoted 9 lines
arch/arm/mach-ep93xx/adc.c new file +8
-0+ data -= adc->refm; + + client->nr_samples--; + +ep93xx_convert_done (client, data, &client->nr_samples); + +/* If all samples are done, disable IRQ, and kick start the next +* one if any. */ This comment doesn't make sense. If all samples are done, kick start the next one? Am I missing something?
I will clarify the comment, actually I meant:
If all samples are done for this client (channel), disable IRQ, and kick start the next client (channel) if any.
Quoted 15 lines
Quoted 15 lines
arch/arm/mach-ep93xx/adc.c new file +14
-0+if (client->nr_samples ==0 ) { +local_irq_save (flags); + adc->cur =NULL ; +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 , +EP93XX_TS_SETUP2_RINTEN ); +ep93xx_adc_try (adc); +local_irq_restore (flags); + } + +return IRQ_HANDLED ; +} + +static int ep93xx_adc_probe (struct platform_device *pdev) +{
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 278
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+struct device *dev = &pdev->dev; +struct adc_device *adc; +struct resource *regs; +int ret; + +printk ("adc_probe: %s\n" , pdev->name);
pr_debug.
OK, will do.
Quoted 42 lines
Quoted 42 lines
arch/arm/mach-ep93xx/adc.c new file +41
-0+ + adc =kzalloc (sizeof (struct adc_device ),GFP_KERNEL ); +if (adc ==NULL ) { +dev_err (dev,"failed to allocate adc_device\n" ); +return -ENOMEM ; + } + + adc->pdev = pdev; + + adc->irq =platform_get_irq (pdev,0 ); +if (adc->irq <=0 ) { +dev_err (dev,"failed to get adc irq\n" ); + ret = -ENOENT ; + goto err_alloc; + } + + ret =request_irq (adc->irq, ep93xx_adc_irq,IRQF_DISABLED , +dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"failed to attach adc irq\n" ); + goto err_alloc; + } + + adc->clk =clk_get (dev,"ep93xx-analog" ); +if (IS_ERR (adc->clk)) { +dev_err (dev,"failed to get ADC clock\n" ); + ret =PTR_ERR (adc->clk); + goto err_irq; + } + + regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!regs) { +dev_err (dev,"failed to find registers\n" ); + ret = -ENXIO ; + goto err_clk; + } + + adc->regs =ioremap (regs->start,resource_size (regs)); +if (!adc->regs) { +dev_err (dev,"failed to map registers\n" ); + ret = -ENXIO ;
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 325
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+ goto err_clk; + } + +clk_enable (adc->clk); + +// Enable ADC, inactivate TS controller /* */ comments please.
Sure!
Quoted 11 lines
arch/arm/mach-ep93xx/adc.c line 333
Quoted 9 lines
arch/arm/mach-ep93xx/adc.c new file +8
-0+ep93xx_devcfg_set_clear (EP93XX_SYSCON_DEVCFG_TIN , +EP93XX_SYSCON_DEVCFG_ADCPD ); +// Disable TS engine +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP ,EP93XX_TS_SETUP_ENABLE ); +// Set ADC to signed mode +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_NSIGND ); + +dev_info (dev,"attached adc driver\n" );Don't really need to pollute the dmesg output.
OK, I will remove that.
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 338
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+ +platform_set_drvdata (pdev, adc); + +/* Defaults from datasheet (approximated values) */ + adc->refm =0xFFFF -25000 ;Erk, why two different bases? Can we just #define these values somewhere.
I think I still need to find the best way to cope with that, 0xFFFF is because we're manipulating 16bits data and 25000 is the value for Vref/2 (from datasheet).
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c line 345
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c new file +7
-0+ adc->refp =25000 ; + adc_dev = adc; + +return 0 ; + + err_clk: +clk_put (adc->clk);
clk_disable?
Why? isn't clk_put() the reverse of clk_get()?
Quoted 44 lines
Quoted 44 lines
arch/arm/mach-ep93xx/adc.c new file +43
-0+ + err_irq: +free_irq (adc->irq, adc); + + err_alloc: +kfree (adc); +return ret; + +} + +static int ep93xx_adc_remove (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); + +iounmap (adc->regs); +free_irq (adc->irq, adc); +clk_disable (adc->clk); +clk_put (adc->clk); +kfree (adc); + +return 0 ; +} + +#ifdef CONFIG_PM +static int ep93xx_adc_suspend (struct platform_device *pdev, +pm_message_t state) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +ep93xx_devcfg_clear (EP93XX_SYSCON_DEVCFG_ADCPD ); +clk_disable (adc->clk); +return 0 ; +} + +static int ep93xx_adc_resume (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +clk_enable (adc->clk); +ep93xx_devcfg_set (EP93XX_SYSCON_DEVCFG_ADCPD ); +return 0 ; +} + +#else +#define ep93xx_adc_suspend NULL
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 394
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+#define ep93xx_adc_resume NULL +#endif + +static struct platform_driver ep93xx_adc_driver = { + .driver = { + .name ="ep93xx-analog" ,Why not ep93xx-adc?
As I said in a previous email, there's ADC stuff and there's touchscreen stuff, both use the same ressource, so I chossed a "neutral" name for these shared ressource (it's not ADC, it's not TS, it's "analog").
I'm really thinking about to make everything ADC centric.
Quoted 11 lines
Quoted 11 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ .owner = THIS_MODULE, + }, + .probe = ep93xx_adc_probe, + .remove = __devexit_p(ep93xx_adc_remove), + .suspend = ep93xx_adc_suspend, + .resume = ep93xx_adc_resume, +}; + +static int __init adc_init (void ) +{
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 410
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+int ret; + + ret =platform_driver_register (&ep93xx_adc_driver); +if (ret) +printk (KERN_ERR "%s: failed to add adc driver\n" , + __func__);
pr_error.
OK.
Quoted 107 lines
Quoted 107 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+ +return ret; +} + +arch_initcall (adc_init);arch/arm/mach-ep93xx/clock.c +7
-0@@ -72,6 +72,12 @@ static struct clk clk_keypad = { .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_KEN, .set_rate = set_keytchclk_rate, }; +static struct clk clk_analog = { + .sw_locked =1 , + .enable_reg =EP93XX_SYSCON_KEYTCHCLKDIV , + .enable_mask =EP93XX_SYSCON_KEYTCHCLKDIV_TSEN , + .set_rate = set_keytchclk_rate, +};static struct clk clk_pwm = { .rate =EP93XX_EXT_CLK_RATE , };@@ -147,6 +153,7 @@ static struct clk_lookup clocks[] = {INIT_CK (NULL ,"pll2" , &clk_pll2),INIT_CK ("ep93xx-ohci" ,NULL , &clk_usb_host),INIT_CK ("ep93xx-keypad" ,NULL , &clk_keypad), +INIT_CK ("ep93xx-analog" ,NULL , &clk_analog),INIT_CK ("ep93xx-fb" ,NULL , &clk_video),INIT_CK (NULL ,"pwm_clk" , &clk_pwm), INIT_CK(NULL, "m2p0", &clk_m2p0),arch/arm/mach-ep93xx/core.c +31
-0@@ -684,6 +684,37 @@ EXPORT_SYMBOL(ep93xx_pwm_release_gpio);/************************************************************************* +* EP93xx Analog Touch Screen Interface peripheral handling. +* Note: TS and ADC share the same resource +*************************************************************************/ +static struct resource ep93xx_analog_resource[] = { + [0 ] = { + .start =EP93XX_TS_PHYS_BASE , + .end =EP93XX_TS_PHYS_BASE +0x24 -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =IRQ_EP93XX_TOUCH , + .end =IRQ_EP93XX_TOUCH , + .flags =IORESOURCE_IRQ , + }, +}; + +struct platform_device ep93xx_analog_device = { + .name ="ep93xx-analog" , + .id =-1 , + .num_resources =ARRAY_SIZE (ep93xx_analog_resource), + .resource = ep93xx_analog_resource, +}; + +/* HWMON */ +struct platform_device ep93xx_hwmon_device = { + .name ="ep93xx-hwmon" , + .id =-1 , + .dev.parent = &ep93xx_analog_device.dev, +}; + +/************************************************************************* * EP93xx video peripheral handling *************************************************************************/ static struct ep93xxfb_mach_info ep93xxfb_data;arch/arm/mach-ep93xx/include/mach/adc.h new file +28
-0@@ -0,0 +1,54 @@ +/* arch/arm/mach-ep93xx/include/arch/adc.h +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c/include/plat/adc.h by Simtec Electronics +* +* EP93XX ADC driver information +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_ADC_H +#define __ASM_ARCH_ADC_H __FILE__ + +/* ADC Channels definition (switches) */ +#define ADC_SW_XP_IN (1<<0) +#define ADC_SW_XM_IN (1<<1) +#define ADC_SW_YP_IN (1<<2) +#define ADC_SW_YM_IN (1<<3) +#define ADC_SW_SXP_IN (1<<4) +#define ADC_SW_SXM_IN (1<<5) +#define ADC_SW_SYP_IN (1<<6) +#define ADC_SW_SYM_IN (1<<7) +#define ADC_SW_VBAT_IN (1<<8) +#define ADC_SW_AVDD_REFP (1<<9) +#define ADC_SW_AGND_REFM (1<<10)
Quoted 8 lines
arch/arm/mach-ep93xx/include/mach/adc.h line 34
Quoted 6 lines
arch/arm/mach-ep93xx/include/mach/adc.h new file +6
-0+#define ADC_SW_SXP_REFP (1<<24) +#define ADC_SW_SXM_REFM (1<<25) +#define ADC_SW_SYP_REFP (1<<26) +#define ADC_SW_SYM_REFM (1<<27) +#define ADC_SW_DAC_IN (1<<29) +#define ADC_SW_IN_LOAD (1<<30)Nitpick, spaces around <<
Yeah, I have to fix all these space issue, and I have to fix my emacs settings.
Quoted 71 lines
arch/arm/mach-ep93xx/include/mach/adc.h line 37
Quoted 4 lines
arch/arm/mach-ep93xx/include/mach/adc.h new file +3
-0+ +/* AGND as VREF-, AVDD as VREF+ */ +#define ADC_SW_APWR_REF (ADC_SW_AVDD_REFP|ADC_SW_AGND_REFM)Spaces around |
Quoted 64 lines
arch/arm/mach-ep93xx/include/mach/adc.h new file +17
-0+ +struct ep93xx_adc_client ; + +extern struct platform_device ep93xx_analog_device; + +extern int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned int channel,unsigned int nr_samples); + +extern int ep93xx_adc_read (struct ep93xx_adc_client *client, +unsigned int ch); + +extern struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device + *pdev); + +extern void ep93xx_adc_release (struct ep93xx_adc_client *client); + +#endif /* __ASM_ARCH_ADC_H */ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +19
-2@@ -145,8 +145,25 @@#define EP93XX_KEY_MATRIX_BASE EP93XX_APB_IOMEM(0x000f0000) -#define EP93XX_ADC_BASE EP93XX_APB_IOMEM(0x00100000) -#define EP93XX_TOUCHSCREEN_BASE EP93XX_APB_IOMEM(0x00100000) +/* Note: +* The EP9301 and EP9302 processors support a general 12-bit ADC, but +* no touchscreen, the EP9307, EP9312 and EP9315 processors each +* support up to an 8-wire touch screen or a general 12-bit ADC +*/ +#define EP93XX_TS_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00100000) +#define EP93XX_TS_BASE EP93XX_APB_IOMEM(0x00100000) +#define EP93XX_TS_REG (x) (EP93XX_TS_BASE + (x)) +#define EP93XX_TS_SETUP EP93XX_TS_REG(0x00) +#define EP93XX_TS_SETUP_ENABLE (1<<15) +#define EP93XX_TS_XYRESULT EP93XX_TS_REG(0x08) +#define EP93XX_TS_XYRESULT_SDR (1<<31) +#define EP93XX_TS_DIRECT EP93XX_TS_REG(0x18) +#define EP93XX_TS_SWLOCK EP93XX_TS_REG(0x20) +#define EP93XX_TS_SWLOCK_UNLOCK 0x000000AA +#define EP93XX_TS_SETUP2 EP93XX_TS_REG(0x24) +#define EP93XX_TS_SETUP2_RINTEN (1<<11) +#define EP93XX_TS_SETUP2_NSIGND (1<<9) +#define EP93XX_PWM_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00110000)#define EP93XX_PWM_BASE EP93XX_APB_IOMEM(0x00110000)arch/arm/mach-ep93xx/include/mach/hwmon.h new file +9
-0@@ -0,0 +1,43 @@ +/* linux/arch/arm/mach-ep93xx/include/arch/hwmon.h +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on linux/arch/arm/plat-s3c/include/plat/hwmon.h by Simtec Electronics +* +* EP93XX - HWMon interface for ADC +* +* This program is free software; you can redistribute it and/or modify
Quoted 8 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h line 15
Quoted 6 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +6
-0+* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_HWMON_H +#define __ASM_ARCH_HWMON_H __FILE__Stray
__FILE__?
Yes, I saw that as well, but as I said in another email, I first tried not to do cosmetic changes, so i leaved this guy as it was.
Quoted 73 lines
Quoted 73 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +28
-0+ +extern struct platform_device ep93xx_hwmon_device; + +/** +* ep93xx_hwmon_chcfg - channel configuration +* @name: The name to give this channel. +* @mult: Multiply the ADC value read by this. +* @div: Divide the value from the ADC by this. +* +* The value read from the ADC is converted to a value that +* hwmon expects (mV) by result = (value_read * @mult) / @div. +*/ +struct ep93xx_hwmon_chcfg { +const char *name; +unsigned long channel; +unsigned long mult; +unsigned long div; +}; + +/** +* ep93xx_hwmon_pdata - HWMON platform data +* @in: One configuration for each possible channel used. +*/ +struct ep93xx_hwmon_data { +struct ep93xx_hwmon_chcfg *in[7 ]; +}; + +#endif /* __ASM_ARCH_HWMON_H */ arch/arm/mach-ep93xx/ts72xx.c +15
-0@@ -18,6 +18,8 @@#include <linux/mtd/physmap.h> #include <mach/hardware.h> +#include <mach/adc.h> +#include <mach/hwmon.h> #include <mach/ts72xx.h> #include <asm/mach-types.h> @@ -92,6 +94,8 @@ static struct map_desc ts72xx_alternate_nand_io_desc[] __initdata = { } }; +static struct ep93xx_hwmon_data ts72xx_hwmon_info; +static void __init ts72xx_map_io (void ) {ep93xx_map_io ();@@ -109,6 +113,8 @@ static void __init ts72xx_map_io(void) ARRAY_SIZE(ts72xx_nand_io_desc)); } } + + ep93xx_hwmon_device.dev.platform_data = &ts72xx_hwmon_info; }/************************************************************************* @@ -170,6 +176,74 @@ static struct ep93xx_eth_data ts72xx_eth_data = { .phy_id = 1, }; + +#define TS72XX_ADC0 (ADC_SW_YM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC1 (ADC_SW_SXP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC2 (ADC_SW_SXM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC3 (ADC_SW_SYP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC4 (ADC_SW_SYM_IN | ADC_SW_APWR_REF) + +// TODO: board dependant +// TS-7200: ADC0, ADC4
Quoted 8 lines
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 193
Quoted 6 lines
arch/arm/mach-ep93xx/ts72xx.c +6
-0+// TS-7250: ADC0 to ADC4 +// TS-7260: Vin, 5V_104, ADC2, Vcore, ADC4 +// TS-7300: 5V, 1.2V, ADC2, 1.8V, ADC4 + +// 0V gives 0, 3.3V gives c. 50000 +// TODO: self calibrate by using VBAT and Load resistor switches /* */ comments please.
Sure.
Quoted 7 lines
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 196
Quoted 4 lines
arch/arm/mach-ep93xx/ts72xx.c +3
-0+static struct ep93xx_hwmon_data ts72xx_hwmon_info = { +/* POWER_IN*10K/150K (4.5-20V) */ + .in[0 ] = &(struct ep93xx_hwmon_chcfg ) {That cast looks really ugly, is there a better way?
Quoted 7 lines
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 200
Quoted 4 lines
arch/arm/mach-ep93xx/ts72xx.c +4
-0+ .name = "ts72xx-vin", + .channel = TS72XX_ADC0, + .mult = 33*(15+1), + .div = 500*1,Spaces around operators please. Also why the explict multiplies (especially by 1)?
I didn't want to put any magic numbers here, so it means 3.3V multiplied by 150K resistor in serie with 10K resistor, divided by a 10K resistor multiplied by the full scale value.
Quoted 515 lines
Quoted 515 lines
arch/arm/mach-ep93xx/ts72xx.c +50
-0+ }, + /* PC104_5V*10K/54.9K (5V) */ + .in[1] = &(struct ep93xx_hwmon_chcfg) { + .name ="ts72xx-v5" , + .channel =TS72XX_ADC4 , + .mult =33 *(549 +100 ), + .div =500 *100 , + }, +/* Vcore (1.8V) */ + .in[2 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-vcore" , + .channel =TS72XX_ADC2 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.8 (0-3.3V) */ + .in[3 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.8" , + .channel =TS72XX_ADC3 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.10 (0-3.3V) */ + .in[4 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.10" , + .channel =TS72XX_ADC1 , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.VBAT (1.8V) */ + .in[5 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vbat" , + .channel =ADC_SW_VBAT_IN |ADC_SW_APWR_REF , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.DAC (?) */ + .in[6 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vdac" , + .channel =ADC_SW_DAC_IN |ADC_SW_APWR_REF , + .mult =33 *1 , + .div =500 *1 , + }, +}; + +static void __init ts72xx_init_machine (void ) {ep93xx_init_devices ();@@ -177,6 +251,10 @@ static void __init ts72xx_init_machine(void)platform_device_register (&ts72xx_rtc_device);ep93xx_register_eth (&ts72xx_eth_data,1 ); + +platform_device_register (&ep93xx_analog_device); + +platform_device_register (&ep93xx_hwmon_device); }MACHINE_START (TS72XX ,"Technologic Systems TS-72xx SBC" )drivers/hwmon/Kconfig +17
-0@@ -690,6 +690,23 @@ config SENSORS_S3C_RAW Say Y here if you want to include raw copies of all the ADC channels in sysfs. +config SENSORS_EP93XX + tristate "EP93XX on-chip ADC" + depends on ARCH_EP93XX + help + If you say yes here you get support for the on-board ADCs of + the Cirrus Logic EP93XX series of SoC + + This driver can also be built as a module. If so, the module + will be called ep93xx-hwmo. + +config SENSORS_EP93XX_RAW + bool "Include raw channel attributes in sysfs" + depends on SENSORS_EP93XX + help + Say Y here if you want to include raw copies of all the ADC + channels in sysfs. + config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on PCIdrivers/hwmon/Makefile +1
-0@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o +obj-$(CONFIG_SENSORS_EP93XX) += ep93xx-hwmon.o obj-$(CONFIG_SENSORS_SHT15) += sht15.o obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.odrivers/hwmon/ep93xx-hwmon.c new file +408
-0@@ -0,0 +1,416 @@ +/* linux/drivers/hwmon/ep93xx-hwmon.c +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on linux/drivers/hwmon/s3c-hwmon.c by Simtec Electronics +* +* EP93XX ADC hwmon support +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> + +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> + +#include <mach/adc.h> +#include <mach/hwmon.h> + +struct ep93xx_hwmon_attr { +struct sensor_device_attribute in; +struct sensor_device_attribute label; +char in_name[12 ]; +char label_name[12 ]; +}; + +/** +* struct ep93xx_hwmon - ADC hwmon client information +* @lock: Access lock to serialise the conversions. +* @client: The client we registered with the EP93XX ADC core. +* @hwmon_dev: The hwmon device we created. +* @attr: The holders for the channel attributes. +*/ +struct ep93xx_hwmon { +struct semaphore lock; +struct ep93xx_adc_client *client; +struct device *hwmon_dev; +struct ep93xx_hwmon_attr attrs[7 ]; +}; + +/** +* ep93xx_hwmon_read_ch - read a value from a given adc channel. +* @dev: The device. +* @hwmon: Our state. +* @channel: The channel we're reading from. +* +* Read a value from the @channel with the proper locking and sleep until +* either the read completes or we timeout awaiting the ADC core to get +* back to us. +*/ +static int ep93xx_hwmon_read_ch (struct device *dev, +struct ep93xx_hwmon *hwmon,int channel) +{ +int ret; + + ret =down_interruptible (&hwmon->lock); +if (ret <0 ) +return ret; + +dev_dbg (dev,"reading channel %d\n" , channel); + + ret =ep93xx_adc_read (hwmon->client, channel); +up (&hwmon->lock); + +return ret; +} + +#ifdef CONFIG_SENSORS_EP93XX_RAW +/** +* ep93xx_hwmon_show_raw - show a conversion from the raw channel number. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* This show deals with the raw attribute, registered for each possible +* ADC channel. This does a conversion and returns the raw (un-scaled) +* value returned from the hardware. +*/ +static ssize_t ep93xx_hwmon_show_raw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ep93xx_hwmon *adc = +platform_get_drvdata (to_platform_device (dev)); +struct sensor_device_attribute *sa =to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sa->index]; + + ret =ep93xx_hwmon_read_ch (dev, adc, cfg->channel); + +return (ret <0 ) ? ret :snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +#define DEF_ADC_ATTR (x) \ + static SENSOR_DEVICE_ATTR(adc##x##_raw, S_IRUGO, ep93xx_hwmon_show_raw, NULL, x) + +DEF_ADC_ATTR (0 ); +DEF_ADC_ATTR (1 ); +DEF_ADC_ATTR (2 ); +DEF_ADC_ATTR (3 ); +DEF_ADC_ATTR (4 ); +DEF_ADC_ATTR (5 ); +DEF_ADC_ATTR (6 ); + +static struct attribute *ep93xx_hwmon_attrs[8 ] = { + &sensor_dev_attr_adc0_raw.dev_attr.attr, + &sensor_dev_attr_adc1_raw.dev_attr.attr, + &sensor_dev_attr_adc2_raw.dev_attr.attr, + &sensor_dev_attr_adc3_raw.dev_attr.attr, + &sensor_dev_attr_adc4_raw.dev_attr.attr, + &sensor_dev_attr_adc5_raw.dev_attr.attr, + &sensor_dev_attr_adc6_raw.dev_attr.attr, +NULL , +}; + +static struct attribute_group ep93xx_hwmon_attrgroup = { + .attrs = ep93xx_hwmon_attrs, +}; + +static inline int ep93xx_hwmon_add_raw (struct device *dev) +{ +return sysfs_create_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +sysfs_remove_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +#else + +static inline void ep93xx_hwmon_add_raw (struct device *dev) +{ +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +} + +#endif /* CONFIG_SENSORS_EP93XX_RAW */ + +/** +* ep93xx_hwmon_ch_show - show value of a given channel +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Read a value from the ADC and scale it before returning it to the +* caller. The scale factor is gained from the channel configuration +* passed via the platform data when the device was registered. +*/ +static ssize_t ep93xx_hwmon_ch_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon *hwmon = +platform_get_drvdata (to_platform_device (dev)); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sen_attr->index]; + + ret =ep93xx_hwmon_read_ch (dev, hwmon, cfg->channel); +if (ret <0 ) +return ret; + + ret *= cfg->mult; + ret =DIV_ROUND_CLOSEST (ret, cfg->div); + +return snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +/** +* ep93xx_hwmon_label_show - show label name of the given channel. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Return the label name of a given channel +*/ +static ssize_t ep93xx_hwmon_label_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; + + cfg = pdata->in[sen_attr->index]; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , cfg->name); +} + +/** +* ep93xx_hwmon_create_attr - create hwmon attribute for given channel. +* @dev: The device to create the attribute on. +* @cfg: The channel configuration passed from the platform data. +* @channel: The ADC channel number to process. +* +* Create the scaled attribute for use with hwmon from the specified +* platform data in @pdata. The sysfs entry is handled by the routine +* ep93xx_hwmon_ch_show(). +* +* The attribute name is taken from the configuration data if present +* otherwise the name is taken by concatenating in_ with the channel +* number. +*/ +static int ep93xx_hwmon_create_attr (struct device *dev, +struct ep93xx_hwmon_chcfg *cfg, +struct ep93xx_hwmon_attr *attrs, +int channel) +{ +struct sensor_device_attribute *attr; +int ret; + +snprintf (attrs->in_name,sizeof (attrs->in_name),"in%d_input" , + channel); + + attr = &attrs->in; + attr->index = channel; + attr->dev_attr.attr.name = attrs->in_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_ch_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +dev_err (dev,"failed to create input attribute\n" ); +return ret; + } + +/* if this has a name, add a label */ +if (cfg->name) { +snprintf (attrs->label_name,sizeof (attrs->label_name), +"in%d_label" , channel); + + attr = &attrs->label; + attr->index = channel; + attr->dev_attr.attr.name = attrs->label_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_label_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +device_remove_file (dev, &attrs->in.dev_attr); +dev_err (dev,"failed to create label attribute\n" ); + } + } + +return ret; +} + +static void ep93xx_hwmon_remove_attr (struct device *dev, +struct ep93xx_hwmon_attr *attrs) +{ +device_remove_file (dev, &attrs->in.dev_attr); +device_remove_file (dev, &attrs->label.dev_attr); +} + +/** +* ep93xx_hwmon_probe - device probe entry. +* @dev: The device being probed. +*/ +static int __devinit ep93xx_hwmon_probe (struct platform_device *dev) +{ +struct ep93xx_hwmon_data *pdata = dev->dev.platform_data; +struct ep93xx_hwmon *hwmon; +int ret =0 ; +int i; + +if (!pdata) { +dev_err (&dev->dev,"no platform data supplied\n" ); +return -EINVAL ; + } + + hwmon =kzalloc (sizeof (struct ep93xx_hwmon ),GFP_KERNEL ); +if (hwmon ==NULL ) { +dev_err (&dev->dev,"no memory\n" ); +return -ENOMEM ; + } + +platform_set_drvdata (dev, hwmon); + +init_MUTEX (&hwmon->lock); + +/* Register with the core ADC driver. */ + + hwmon->client =ep93xx_adc_register (dev); +if (IS_ERR (hwmon->client)) { +dev_err (&dev->dev,"cannot register adc\n" ); + ret =PTR_ERR (hwmon->client); + goto err_mem; + } + +/* add attributes for our adc devices. */ + + ret =ep93xx_hwmon_add_raw (&dev->dev); +if (ret) + goto err_registered; + +/* register with the hwmon core */ + + hwmon->hwmon_dev =hwmon_device_register (&dev->dev); +if (IS_ERR (hwmon->hwmon_dev)) { +dev_err (&dev->dev,"error registering with hwmon\n" ); + ret =PTR_ERR (hwmon->hwmon_dev); + goto err_raw_attribute; + } + +for (i =0 ; i <ARRAY_SIZE (pdata->in); i++) { +if (!pdata->in[i]) +continue ; + +if (pdata->in[i]->mult >=0x10000 ) +dev_warn (&dev->dev, +"channel %d multiplier too large\n" , i); + + ret =ep93xx_hwmon_create_attr (&dev->dev, pdata->in[i], + &hwmon->attrs[i], i); +if (ret) { +dev_err (&dev->dev, +"error creating channel %d\n" , i); + +for (i--; i >=0 ; i--) +ep93xx_hwmon_remove_attr (&dev->dev, + &hwmon->attrs[i]); + + goto err_hwmon_register; + } + } + +return 0 ; + + err_hwmon_register: +hwmon_device_unregister (hwmon->hwmon_dev); + + err_raw_attribute: +ep93xx_hwmon_remove_raw (&dev->dev); + + err_registered: +ep93xx_adc_release (hwmon->client); + + err_mem: +kfree (hwmon); +return ret; +} + +static int __devexit ep93xx_hwmon_remove(struct platform_device *dev) +{ +struct ep93xx_hwmon *hwmon =platform_get_drvdata (dev); +int i; + +ep93xx_hwmon_remove_raw (&dev->dev); + +for (i =0 ; i <ARRAY_SIZE (hwmon->attrs); i++) +ep93xx_hwmon_remove_attr (&dev->dev, &hwmon->attrs[i]); + +hwmon_device_unregister (hwmon->hwmon_dev); +ep93xx_adc_release (hwmon->client); + +return 0 ; +} + +static struct platform_driver ep93xx_hwmon_driver = { + .driver = { + .name ="ep93xx-hwmon" , + .owner =THIS_MODULE , + }, + .probe = ep93xx_hwmon_probe, + .remove =__devexit_p (ep93xx_hwmon_remove), +}; + +static int __init ep93xx_hwmon_init (void ) +{ +return platform_driver_register (&ep93xx_hwmon_driver); +} + +static void __exit ep93xx_hwmon_exit(void) +{ +platform_driver_unregister (&ep93xx_hwmon_driver); +}
Quoted 8 lines
drivers/hwmon/ep93xx-hwmon.c line 416
Quoted 8 lines
drivers/hwmon/ep93xx-hwmon.c new file +8
-0+ +module_init (ep93xx_hwmon_init); +module_exit (ep93xx_hwmon_exit); + +MODULE_AUTHOR ("Christian Gagneraud <[email protected]>" ); +MODULE_DESCRIPTION ("EP93XX ADC HWMon driver" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:ep93xx-hwmon" );
Thanks for the comments,
Chris
Quoted 8 lines
Quoted 6 lines
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 27 lines · Christian Gagneraud
Quoted 17 lines · Ryan Mallon
Quoted 16 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
arch/arm/mach-ep93xx/adc.c new file +13
-0+}; + +struct adc_device { +struct platform_device *pdev; +struct platform_device *owner; +struct clk *clk; +struct ep93xx_adc_client *cur; +void __iomem *regs; +int irq; +unsigned int refm;/* Reading when Vin = Vref- */ +unsigned int refp;/* Reading when Vin = Vref+ */ +}; +Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 90
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+static struct adc_device *adc_dev; + +static LIST_HEAD (adc_pending); + +#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg)Bit of a nitpick, but can you move the structure definitions and
above the first functions in this file.
Quoted 2 lines
Bit of nitpick, but I will move the first functions _below_ the structure definitions and variable declarations. :)
Heh, fair enough :-).
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
arch/arm/mach-ep93xx/adc.c new file +11
-0+ +static inline void ep93xx_adc_convert (struct adc_device *adc) +{ +unsigned long prev_switch; +unsigned long next_switch; + +/* Configure the switches */ + prev_switch =__raw_readl (EP93XX_TS_DIRECT ); + next_switch = adc->cur->channel; +if (next_switch != prev_switch) { +ep93xx_adc_set_reg (EP93XX_TS_DIRECT , next_switch);Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 107
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+/* Channel switch settling time */ +/* TODO: depends on clock speed (500us or 2ms) */ +/* FIXME: the caller has disabled interrupts and the +* caller can even be the irq handler. Should we +* better fire a timer? */ +mdelay (2 );Perhaps make the mdelay value a platform data in the meantime then?
Quoted 6 lines
Actually I need to use
clock_get_rateI think. But yes, why not putting the clock configuration in the platform data in the meantime.Any particular comment about using mdelay within local_irq_save/restore context (used to protect the list), and within an interrupt handler (needed to fire the next operation).
udelay and mdelay are busy wait loops, and are okay to use inside interrupt context.
Quoted 14 lines
Quoted 13 lines
arch/arm/mach-ep93xx/adc.c line 258
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +8
-0+ data -= adc->refm; + + client->nr_samples--; + +ep93xx_convert_done (client, data, &client->nr_samples); + +/* If all samples are done, disable IRQ, and kick start the next +* one if any. */ This comment doesn't make sense. If all samples are done, kick start the next one? Am I missing something?
Quoted 3 lines
I will clarify the comment, actually I meant:
If all samples are done for this client (channel), disable IRQ, and kick start the next client (channel) if any.
Okay, that makes sense. Can you change the comment to reflect this.
Quoted 9 lines
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 338
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+ +platform_set_drvdata (pdev, adc); + +/* Defaults from datasheet (approximated values) */ + adc->refm =0xFFFF -25000 ;Erk, why two different bases? Can we just #define these values somewhere.
Quoted 3 lines
I think I still need to find the best way to cope with that,
0xFFFFis because we're manipulating 16bits data and 25000 is the value for Vref/2 (from datasheet).
Okay, makes sense. Can we make a #define with a comment then?
Quoted 11 lines
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c line 345
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c new file +7
-0+ adc->refp =25000 ; + adc_dev = adc; + +return 0 ; + + err_clk: +clk_put (adc->clk);
clk_disable?
Quoted 1 line
Why? isn't
clk_put()the reverse ofclk_get()?
Sorry, I misread the code. I though you could error exit after the clk_enable above. Your error path is okay.
Quoted 7 lines
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c line 394
Quoted 4 lines
arch/arm/mach-ep93xx/adc.c new file +4
-0+ +static struct platform_driver ep93xx_adc_driver = { + .driver = { + .name ="ep93xx-analog" ,Why not ep93xx-adc?
Quoted 5 lines
As I said in a previous email, there's ADC stuff and there's touchscreen stuff, both use the same ressource, so I chossed a "neutral" name for these shared ressource (it's not ADC, it's not TS, it's "analog").
I'm really thinking about to make everything ADC centric.
As Hartley mentioned, if this is the interface to the ADC, and the touchscreen driver uses ep93xx_adc_register, then this driver is the only one which needs the clock.
I have a touchscreen driver lying around which needs to be ported to the mainline. I will add getting it work with this driver to my list of things to do.
Quoted 8 lines
Quoted 5 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h line 15
Quoted 3 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +3
-0+ +#ifndef __ASM_ARCH_HWMON_H +#define __ASM_ARCH_HWMON_H __FILE__Stray
__FILE__?Yes, I saw that as well, but as I said in another email, I first tried not to do cosmetic changes, so i leaved this guy as it was.
It shouldn't be there, just remove it.
Quoted 12 lines
Quoted 12 lines
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 196
Quoted 4 lines
arch/arm/mach-ep93xx/ts72xx.c +3
-0+static struct ep93xx_hwmon_data ts72xx_hwmon_info = { +/* POWER_IN*10K/150K (4.5-20V) */ + .in[0 ] = &(struct ep93xx_hwmon_chcfg ) {That cast looks really ugly, is there a better way?
Quoted 4 lines
arch/arm/mach-ep93xx/ts72xx.c +4
-0+ .name = "ts72xx-vin", + .channel = TS72XX_ADC0, + .mult = 33*(15+1), + .div = 500*1,
Quoted 6 lines
Quoted 2 lines
Spaces around operators please. Also why the explict multiplies (especially by 1)?
I didn't want to put any magic numbers here, so it means 3.3V multiplied by 150K resistor in serie with 10K resistor, divided by a 10K resistor multiplied by the full scale value.
Perhaps a comment explaining this then?
One last thing. It might be an idea to split this into a few patches. At least into one for the adc driver and one for the hwmon part. As it stands the patch is quite large.
~Ryan
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre Ryan Mallon 5 Amuri Park, 404 Barbadoes St ryan at bluewatersys.com PO Box 13 889, Christchurch 8013 http://www.bluewatersys.com New Zealand Phone: +64 3 3779127 Freecall: Australia 1800 148 751 Fax: +64 3 3779135 USA 1800 261 2934
RFC PATCH 1/1 EP93XX: Add ADC support
In reply to Christian GagneraudQuoted 18 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)
Quoted 4 lines
This is a first draft. Comments and criticism welcome.
Signed-off-by Christian Gagneraud <[email protected]>---
Hello Christian,
I see Ryan already sent you some comments so I'll just add mine.
Run this thru checkpatch.pl please. There are a number of whitespace issues in this patch.
Quoted 53 lines
arch/arm/mach-ep93xx/Makefile | 2 arch/arm/mach-ep93xx/adc.c | 415 +++++++++++++++++++++++ arch/arm/mach-ep93xx/clock.c | 7 arch/arm/mach-ep93xx/core.c | 31 ++ arch/arm/mach-ep93xx/include/mach/adc.h | 54 +++ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | 21 + arch/arm/mach-ep93xx/include/mach/hwmon.h | 43 ++ arch/arm/mach-ep93xx/ts72xx.c | 78 ++++ drivers/hwmon/Kconfig | 17 + drivers/hwmon/Makefile | 1 drivers/hwmon/ep93xx-hwmon.c | 416 +++++++++++++++++++++++ 11 files changed, 1083 insertions(+), 2 deletions(-) create mode 100644 arch/arm/mach-ep93xx/adc.c create mode 100644 arch/arm/mach-ep93xx/include/mach/adc.h create mode 100644 arch/arm/mach-ep93xx/include/mach/hwmon.h create mode 100644 drivers/hwmon/ep93xx-hwmon.carch/arm/mach-ep93xx/Makefile +2
-0@@ -6,6 +6,8 @@ obj-m := obj-n := obj- := +obj-$(CONFIG_EP93XX_ADC) += adc.o + obj-$(CONFIG_MACH_ADSSPHERE) += adssphere.o obj-$(CONFIG_MACH_EDB93XX) += edb93xx.o obj-$(CONFIG_MACH_GESBC9312) += gesbc9312.oarch/arm/mach-ep93xx/adc.c new file +17
-0@@ -0,0 +1,415 @@ +/* +* arch/arm/mach-ep93xx/adc.c +* +* ADC support for Cirrus EP93xx chips. +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c24xx/adc.c by Simtec Electronics +* +* 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. +*/ + +/* +* Touchscreen and Direct ADC:
arch/arm/mach-ep93xx/adc.c line 27
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+* +* +------------------------+-----+-----+-----+-----+ +* |ADC/TS driver in use | n/n | y/n | n/y | y/y | +* +------------------------+-----+-----+-----+-----+ +* |SYSCON_DEVCFG_ADCPD | 1 | 0 | 0 | 0 | +* |SYSCON_DEVCFG_TIN | X | 1 | 0 | 1/0 | +* |SYSCON_KEYTCHCLKDIV_TSEN| 0 | 1 | 1 | 1 | +* |TS_SETUP_ENABLE (*) | 0 | 0 | 1 | 0/1 | +* +------------------------+-----+-----+-----+-----+ +* (*)
Are you missing a comment about (*)?
Is it the intention that this i/o wrapper will allow BOTH the adc and the touchscreen to work at the same time? I don't think that is possible.
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/platform_device.h>
arch/arm/mach-ep93xx/adc.c line 42
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+#include <linux/list.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/sched.h> + +#include <mach/hardware.h> +
Please remove the register definitions from ep93xx-regs.h and just put the defines locally in this file. They are not used anywhere else and belong here. See drivers/misc/ep93xx_pwm.c as an example.
Quoted 12 lines
arch/arm/mach-ep93xx/adc.c new file +12
-0+static inline void ep93xx_adc_set_reg (void __iomem *reg, +unsigned long val) +{ +__raw_writel (EP93XX_TS_SWLOCK_UNLOCK ,EP93XX_TS_SWLOCK ); +__raw_writel (val, reg); +} + +static inline void ep93xx_adc_clr_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val &= ~bits;
arch/arm/mach-ep93xx/adc.c line 64
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ep93xx_adc_set_reg (reg,val); +} + +static inline void ep93xx_adc_set_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val |= bits; +ep93xx_adc_set_reg (reg,val); +}
These I/O access functions should be using the __iomem address that you ioremap'ed in the probe. Again, see drivers/misc/ep93xx_pwm.c.
Quoted 228 lines
arch/arm/mach-ep93xx/adc.c new file +228
-0+ +struct ep93xx_adc_client { +struct platform_device *pdev; +struct list_head pend; +wait_queue_head_t *wait; +unsigned int nr_samples; +int result; +unsigned int channel; +}; + +struct adc_device { +struct platform_device *pdev; +struct platform_device *owner; +struct clk *clk; +struct ep93xx_adc_client *cur; +void __iomem *regs; +int irq; +unsigned int refm;/* Reading when Vin = Vref- */ +unsigned int refp;/* Reading when Vin = Vref+ */ +}; + +static struct adc_device *adc_dev; + +static LIST_HEAD (adc_pending); + +#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg) + +static inline void ep93xx_adc_convert (struct adc_device *adc) +{ +unsigned long prev_switch; +unsigned long next_switch; + +/* Configure the switches */ + prev_switch =__raw_readl (EP93XX_TS_DIRECT ); + next_switch = adc->cur->channel; +if (next_switch != prev_switch) { +ep93xx_adc_set_reg (EP93XX_TS_DIRECT , next_switch); +/* Channel switch settling time */ +/* TODO: depends on clock speed (500us or 2ms) */ +/* FIXME: the caller has disabled interrupts and the +* caller can even be the irq handler. Should we +* better fire a timer? */ +mdelay (2 ); + } + +/* Fire ADC engine with Sync Data Ready IRQ enabled */ +ep93xx_adc_set_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_RINTEN ); +__raw_readl (EP93XX_TS_XYRESULT ); +} + +static void ep93xx_adc_try (struct adc_device *adc) +{ +struct ep93xx_adc_client *next; + +if (!list_empty (&adc_pending)) { + next =list_first_entry (&adc_pending, + struct ep93xx_adc_client, pend); +list_del (&next->pend); +adc_dbg (adc,"new client is %p\n" , next); + adc->cur = next; +ep93xx_adc_convert (adc); + } +} + +int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned long channel,unsigned int nr_samples) +{ +struct adc_device *adc = adc_dev; +unsigned long flags; + +if (!adc) { +printk (KERN_ERR "%s: failed to find adc\n" , __func__); +return -EINVAL ; + } + +local_irq_save (flags); + + client->channel = channel; + client->nr_samples = nr_samples; + +list_add_tail (&client->pend, &adc_pending); + +if (!adc->cur) +ep93xx_adc_try (adc); +local_irq_restore (flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (ep93xx_adc_start); + +static void ep93xx_convert_done (struct ep93xx_adc_client *client, +unsigned val,unsigned *left) +{ + client->result = val; +wake_up (client->wait); +} + +int ep93xx_adc_read (struct ep93xx_adc_client *client,unsigned int ch) +{ +DECLARE_WAIT_QUEUE_HEAD_ONSTACK (wake); +int ret; + + client->wait = &wake; + client->result =-1 ; + + ret =ep93xx_adc_start (client, ch,1 ); +if (ret <0 ) + goto err; + + ret =wait_event_timeout (wake, client->result >=0 ,HZ /2 ); +if (client->result <0 ) { + ret = -ETIMEDOUT ; + goto err; + } + +return client->result; + err: +return ret; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_convert); + +struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device *pdev) +{ +struct ep93xx_adc_client *client; + +printk ("adc_register: %s\n" , pdev->name); + +WARN_ON (!pdev); + +if (!pdev) +return ERR_PTR (-EINVAL ); + + client =kzalloc (sizeof (struct ep93xx_adc_client ),GFP_KERNEL ); +if (!client) { +dev_err (&pdev->dev,"no memory for adc client\n" ); +return ERR_PTR (-ENOMEM ); + } + + client->pdev = pdev; + +return client; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_register); + +void ep93xx_adc_release (struct ep93xx_adc_client *client) +{ +struct list_head *p, *n; +struct ep93xx_adc_client *tmp; + +/* We should really check that nothing is in progress. */ +if (adc_dev->cur == client) + adc_dev->cur =NULL ; + +list_for_each_safe (p, n, &adc_pending) { + tmp = list_entry(p, struct ep93xx_adc_client, pend); +if (tmp == client) +list_del (&tmp->pend); + } + +if (adc_dev->cur ==NULL ) +ep93xx_adc_try (adc_dev); +kfree (client); +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_release); + +static irqreturn_t ep93xx_adc_irq (int irq,void *pw) +{ +struct adc_device *adc = pw; +struct ep93xx_adc_client *client = adc->cur; +unsigned long flags; +unsigned long data; + +if (!client) { +dev_warn (&adc->pdev->dev,"%s: no adc pending\n" , + __func__); +return IRQ_HANDLED ; + } + +/* Read and convert data */ + data =__raw_readl (EP93XX_TS_XYRESULT ); + data &=0x0000FFFF ; +if (data <0x7000 ) + data +=0x10000 ; + data -= adc->refm; + + client->nr_samples--; + +ep93xx_convert_done (client, data, &client->nr_samples); + +/* If all samples are done, disable IRQ, and kick start the next +* one if any. */ +if (client->nr_samples ==0 ) { +local_irq_save (flags); + adc->cur =NULL ; +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 , +EP93XX_TS_SETUP2_RINTEN ); +ep93xx_adc_try (adc); +local_irq_restore (flags); + } + +return IRQ_HANDLED ; +} + +static int ep93xx_adc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct adc_device *adc; +struct resource *regs; +int ret; + +printk ("adc_probe: %s\n" , pdev->name); + + adc =kzalloc (sizeof (struct adc_device ),GFP_KERNEL ); +if (adc ==NULL ) { +dev_err (dev,"failed to allocate adc_device\n" ); +return -ENOMEM ; + } + + adc->pdev = pdev; + + adc->irq =platform_get_irq (pdev,0 ); +if (adc->irq <=0 ) { +dev_err (dev,"failed to get adc irq\n" ); + ret = -ENOENT ; + goto err_alloc;
arch/arm/mach-ep93xx/adc.c line 302
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ } + + ret =request_irq (adc->irq, ep93xx_adc_irq,IRQF_DISABLED , +dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"failed to attach adc irq\n" ); + goto err_alloc; + } + + adc->clk =clk_get (dev,"ep93xx-analog" );
Did you try:
adc->clk = clk_get(dev, NULL);
arch/arm/mach-ep93xx/adc.c line 314
Quoted 12 lines
arch/arm/mach-ep93xx/adc.c new file +12
-0+if (IS_ERR (adc->clk)) { +dev_err (dev,"failed to get ADC clock\n" ); + ret =PTR_ERR (adc->clk); + goto err_irq; + } + + regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!regs) { +dev_err (dev,"failed to find registers\n" ); + ret = -ENXIO ; + goto err_clk; + }
request_mem_region() before ioremap().
Quoted 20 lines
arch/arm/mach-ep93xx/adc.c new file +20
-0+ + adc->regs =ioremap (regs->start,resource_size (regs)); +if (!adc->regs) { +dev_err (dev,"failed to map registers\n" ); + ret = -ENXIO ; + goto err_clk; + } + +clk_enable (adc->clk); + +// Enable ADC, inactivate TS controller +ep93xx_devcfg_set_clear (EP93XX_SYSCON_DEVCFG_TIN , +EP93XX_SYSCON_DEVCFG_ADCPD ); +// Disable TS engine +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP ,EP93XX_TS_SETUP_ENABLE ); +// Set ADC to signed mode +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_NSIGND ); + +dev_info (dev,"attached adc driver\n" ); +
arch/arm/mach-ep93xx/adc.c line 344
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+platform_set_drvdata (pdev, adc); + +/* Defaults from datasheet (approximated values) */ + adc->refm =0xFFFF -25000 ; + adc->refp =25000 ; + adc_dev = adc; + +return 0 ; + + err_clk:
Please remove whitespace before the goto labels.
Quoted 76 lines
arch/arm/mach-ep93xx/adc.c new file +71
-0+clk_put (adc->clk); + + err_irq: +free_irq (adc->irq, adc); + + err_alloc: +kfree (adc); +return ret; + +} + +static int ep93xx_adc_remove (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); + +iounmap (adc->regs); +free_irq (adc->irq, adc); +clk_disable (adc->clk); +clk_put (adc->clk); +kfree (adc); + +return 0 ; +} + +#ifdef CONFIG_PM +static int ep93xx_adc_suspend (struct platform_device *pdev, +pm_message_t state) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +ep93xx_devcfg_clear (EP93XX_SYSCON_DEVCFG_ADCPD ); +clk_disable (adc->clk); +return 0 ; +} + +static int ep93xx_adc_resume (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +clk_enable (adc->clk); +ep93xx_devcfg_set (EP93XX_SYSCON_DEVCFG_ADCPD ); +return 0 ; +} + +#else +#define ep93xx_adc_suspend NULL +#define ep93xx_adc_resume NULL +#endif + +static struct platform_driver ep93xx_adc_driver = { + .driver = { + .name ="ep93xx-analog" , + .owner =THIS_MODULE , + }, + .probe = ep93xx_adc_probe, + .remove =__devexit_p (ep93xx_adc_remove), + .suspend = ep93xx_adc_suspend, + .resume = ep93xx_adc_resume, +}; + +static int __init adc_init (void ) +{ +int ret; + + ret =platform_driver_register (&ep93xx_adc_driver); +if (ret) +printk (KERN_ERR "%s: failed to add adc driver\n" , + __func__); + +return ret; +} + +arch_initcall (adc_init);arch/arm/mach-ep93xx/clock.c +0
-0
arch/arm/mach-ep93xx/clock.c static struct clk clk_keypad = { · line 75
Quoted 4 lines
arch/arm/mach-ep93xx/clock.c +1
-0@@ -72,6 +72,12 @@ static struct clk clk_keypad = { .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_KEN, .set_rate = set_keytchclk_rate, }; +static struct clk clk_analog = {
.parent = &clk_xtali,
Quoted 29 lines
arch/arm/mach-ep93xx/clock.c +6
-0+ .sw_locked = 1, + .enable_reg = EP93XX_SYSCON_KEYTCHCLKDIV, + .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_TSEN, + .set_rate = set_keytchclk_rate, +};static struct clk clk_pwm = { .rate =EP93XX_EXT_CLK_RATE , };@@ -147,6 +153,7 @@ static struct clk_lookup clocks[] = {INIT_CK (NULL ,"pll2" , &clk_pll2),INIT_CK ("ep93xx-ohci" ,NULL , &clk_usb_host),INIT_CK ("ep93xx-keypad" ,NULL , &clk_keypad), +INIT_CK ("ep93xx-analog" ,NULL , &clk_analog),INIT_CK ("ep93xx-fb" ,NULL , &clk_video),INIT_CK (NULL ,"pwm_clk" , &clk_pwm), INIT_CK(NULL, "m2p0", &clk_m2p0),arch/arm/mach-ep93xx/core.c +5
-0@@ -684,6 +684,37 @@ EXPORT_SYMBOL(ep93xx_pwm_release_gpio);/************************************************************************* +* EP93xx Analog Touch Screen Interface peripheral handling. +* Note: TS and ADC share the same resource +*************************************************************************/ +static struct resource ep93xx_analog_resource[] = { + [0 ] = {
arch/arm/mach-ep93xx/core.c EXPORT_SYMBOL(ep93xx_pwm_release_gpio); · line 701
Quoted 10 lines
arch/arm/mach-ep93xx/core.c +10
-0+ .start = EP93XX_TS_PHYS_BASE, + .end = EP93XX_TS_PHYS_BASE + 0x24 - 1, + .flags = IORESOURCE_MEM, + }, + [1] = { + .start = IRQ_EP93XX_TOUCH, + .end = IRQ_EP93XX_TOUCH, + .flags = IORESOURCE_IRQ, + }, +};
The [0] = and [1] = are not needed.
Quoted 4 lines
arch/arm/mach-ep93xx/core.c +4
-0+ +struct platform_device ep93xx_analog_device = { + .name ="ep93xx-analog" , + .id =-1 ,
arch/arm/mach-ep93xx/core.c EXPORT_SYMBOL(ep93xx_pwm_release_gpio); · line 715
Quoted 10 lines
arch/arm/mach-ep93xx/core.c +10
-0+ .num_resources = ARRAY_SIZE(ep93xx_analog_resource), + .resource = ep93xx_analog_resource, +}; + +/* HWMON */ +struct platform_device ep93xx_hwmon_device = { + .name ="ep93xx-hwmon" , + .id =-1 , + .dev.parent = &ep93xx_analog_device.dev, +};
Please make both of these struct's static and just add the necessary ep93xx_register_*() functions for the platform init to call.
Quoted 70 lines
arch/arm/mach-ep93xx/core.c +2
-0+ +/************************************************************************* * EP93xx video peripheral handling *************************************************************************/ static struct ep93xxfb_mach_info ep93xxfb_data;arch/arm/mach-ep93xx/include/mach/adc.h new file +54
-0@@ -0,0 +1,54 @@ +/* arch/arm/mach-ep93xx/include/arch/adc.h +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c/include/plat/adc.h by Simtec Electronics +* +* EP93XX ADC driver information +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_ADC_H +#define __ASM_ARCH_ADC_H __FILE__ + +/* ADC Channels definition (switches) */ +#define ADC_SW_XP_IN (1<<0) +#define ADC_SW_XM_IN (1<<1) +#define ADC_SW_YP_IN (1<<2) +#define ADC_SW_YM_IN (1<<3) +#define ADC_SW_SXP_IN (1<<4) +#define ADC_SW_SXM_IN (1<<5) +#define ADC_SW_SYP_IN (1<<6) +#define ADC_SW_SYM_IN (1<<7) +#define ADC_SW_VBAT_IN (1<<8) +#define ADC_SW_AVDD_REFP (1<<9) +#define ADC_SW_AGND_REFM (1<<10) +#define ADC_SW_SXP_REFP (1<<24) +#define ADC_SW_SXM_REFM (1<<25) +#define ADC_SW_SYP_REFP (1<<26) +#define ADC_SW_SYM_REFM (1<<27) +#define ADC_SW_DAC_IN (1<<29) +#define ADC_SW_IN_LOAD (1<<30) + +/* AGND as VREF-, AVDD as VREF+ */ +#define ADC_SW_APWR_REF (ADC_SW_AVDD_REFP|ADC_SW_AGND_REFM) + +struct ep93xx_adc_client ; + +extern struct platform_device ep93xx_analog_device; + +extern int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned int channel,unsigned int nr_samples); + +extern int ep93xx_adc_read (struct ep93xx_adc_client *client, +unsigned int ch); + +extern struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device + *pdev); + +extern void ep93xx_adc_release (struct ep93xx_adc_client *client); + +#endif /* __ASM_ARCH_ADC_H */ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +0
-0
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 152
Quoted 10 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +5
-2@@ -145,8 +145,25 @@#define EP93XX_KEY_MATRIX_BASE EP93XX_APB_IOMEM(0x000f0000) -#define EP93XX_ADC_BASE EP93XX_APB_IOMEM(0x00100000) -#define EP93XX_TOUCHSCREEN_BASE EP93XX_APB_IOMEM(0x00100000) +/* Note: +* The EP9301 and EP9302 processors support a general 12-bit ADC, but +* no touchscreen, the EP9307, EP9312 and EP9315 processors each +* support up to an 8-wire touch screen or a general 12-bit ADC +*/
Please remove this comment and put it in the driver file.
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 153
Quoted 1 line
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +1
-0+#define EP93XX_TS_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00100000)
Should be:
#define EP93XX_TS_PHYS_BASE EP93XX_APB_PHYS(0x00100000)
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 165
Quoted 12 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +12
-0+#define EP93XX_TS_BASE EP93XX_APB_IOMEM(0x00100000) +#define EP93XX_TS_REG (x) (EP93XX_TS_BASE + (x)) +#define EP93XX_TS_SETUP EP93XX_TS_REG(0x00) +#define EP93XX_TS_SETUP_ENABLE (1<<15) +#define EP93XX_TS_XYRESULT EP93XX_TS_REG(0x08) +#define EP93XX_TS_XYRESULT_SDR (1<<31) +#define EP93XX_TS_DIRECT EP93XX_TS_REG(0x18) +#define EP93XX_TS_SWLOCK EP93XX_TS_REG(0x20) +#define EP93XX_TS_SWLOCK_UNLOCK 0x000000AA +#define EP93XX_TS_SETUP2 EP93XX_TS_REG(0x24) +#define EP93XX_TS_SETUP2_RINTEN (1<<11) +#define EP93XX_TS_SETUP2_NSIGND (1<<9)
None of these registers should be defined here. Just put the offsets in the adc driver.
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 166
Quoted 1 line
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +1
-0+
Remove this extra blank line.
Quoted 40 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +0
-0#define EP93XX_PWM_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00110000)#define EP93XX_PWM_BASE EP93XX_APB_IOMEM(0x00110000)arch/arm/mach-ep93xx/include/mach/hwmon.h new file +32
-0@@ -0,0 +1,43 @@ +/* linux/arch/arm/mach-ep93xx/include/arch/hwmon.h +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on linux/arch/arm/plat-s3c/include/plat/hwmon.h by Simtec Electronics +* +* EP93XX - HWMon interface for ADC +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_HWMON_H +#define __ASM_ARCH_HWMON_H __FILE__ + +extern struct platform_device ep93xx_hwmon_device; + +/** + * ep93xx_hwmon_chcfg - channel configuration + * @name: The name to give this channel. + * @mult: Multiply the ADC value read by this. + * @div: Divide the value from the ADC by this. + * + * The value read from the ADC is converted to a value that + * hwmon expects (mV) by result = (value_read * @mult) / @div. + */ +struct ep93xx_hwmon_chcfg { + const char *name; + unsigned long channel; + unsigned long mult; + unsigned long div;
arch/arm/mach-ep93xx/include/mach/hwmon.h line 42
Quoted 10 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +10
-0+}; + +/** +* ep93xx_hwmon_pdata - HWMON platform data +* @in: One configuration for each possible channel used. +*/ +struct ep93xx_hwmon_data { +struct ep93xx_hwmon_chcfg *in[7 ]; +}; +
The extra ep93xx_hwmon_data struct probably isn't needed. See below.
arch/arm/mach-ep93xx/ts72xx.c line 22
Quoted 11 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +1
-0+#endif /* __ASM_ARCH_HWMON_H */ arch/arm/mach-ep93xx/ts72xx.c +2
-0@@ -18,6 +18,8 @@#include <linux/mtd/physmap.h> #include <mach/hardware.h> +#include <mach/adc.h> +#include <mach/hwmon.h>
Please put these two after the tx72xx.h header.
Quoted 13 lines
arch/arm/mach-ep93xx/ts72xx.c +2
-0#include <mach/ts72xx.h> #include <asm/mach-types.h> @@ -92,6 +94,8 @@ static struct map_desc ts72xx_alternate_nand_io_desc[] __initdata = { } }; +static struct ep93xx_hwmon_data ts72xx_hwmon_info; +static void __init ts72xx_map_io (void ) {ep93xx_map_io ();
arch/arm/mach-ep93xx/ts72xx.c static void __init ts72xx_map_io(void) · line 118
Quoted 6 lines
arch/arm/mach-ep93xx/ts72xx.c +2
-0@@ -109,6 +113,8 @@ static void __init ts72xx_map_io(void) ARRAY_SIZE(ts72xx_nand_io_desc)); } } + + ep93xx_hwmon_device.dev.platform_data = &ts72xx_hwmon_info; }
Ugly... You shouldn't be setting up any type of device data in (*map_io).
Quoted 62 lines
arch/arm/mach-ep93xx/ts72xx.c +56
-0/************************************************************************* @@ -170,6 +176,74 @@ static struct ep93xx_eth_data ts72xx_eth_data = { .phy_id = 1, }; + +#define TS72XX_ADC0 (ADC_SW_YM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC1 (ADC_SW_SXP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC2 (ADC_SW_SXM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC3 (ADC_SW_SYP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC4 (ADC_SW_SYM_IN | ADC_SW_APWR_REF) + +// TODO: board dependant +// TS-7200: ADC0, ADC4 +// TS-7250: ADC0 to ADC4 +// TS-7260: Vin, 5V_104, ADC2, Vcore, ADC4 +// TS-7300: 5V, 1.2V, ADC2, 1.8V, ADC4 + +// 0V gives 0, 3.3V gives c. 50000 +// TODO: self calibrate by using VBAT and Load resistor switches +static struct ep93xx_hwmon_data ts72xx_hwmon_info = { +/* POWER_IN*10K/150K (4.5-20V) */ + .in[0 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-vin" , + .channel =TS72XX_ADC0 , + .mult =33 *(15 +1 ), + .div =500 *1 , + }, +/* PC104_5V*10K/54.9K (5V) */ + .in[1 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-v5" , + .channel =TS72XX_ADC4 , + .mult =33 *(549 +100 ), + .div =500 *100 , + }, +/* Vcore (1.8V) */ + .in[2 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-vcore" , + .channel =TS72XX_ADC2 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.8 (0-3.3V) */ + .in[3 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.8" , + .channel =TS72XX_ADC3 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.10 (0-3.3V) */ + .in[4 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.10" , + .channel =TS72XX_ADC1 , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.VBAT (1.8V) */ + .in[5 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vbat" , + .channel =ADC_SW_VBAT_IN |ADC_SW_APWR_REF , + .mult =33 *1 ,
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 244
Quoted 10 lines
arch/arm/mach-ep93xx/ts72xx.c +10
-0+ .div = 500*1, + }, +/* EP93XX.DAC (?) */ + .in[6 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vdac" , + .channel =ADC_SW_DAC_IN |ADC_SW_APWR_REF , + .mult =33 *1 , + .div =500 *1 , + }, +};
Can you just use struct ep93xx_hwmon_chcfg directly without using the struct ep93xx_hwmon_data as a container? Something like:
static struct ep93xx_hwmon_chcfg ts72xx_hwmon_info[] = {
{ /* POWER_IN*10K/150K (4.5-20V) */
.name = "ts72xx-vin",
.channel = TS72XX_ADC0,
.mult = 33*(15+1),
.div = 500*1,
}, { /* PC104_5V*10K/54.9K (5V) */
.name = "ts72xx-v5",
.channel = TS72XX_ADC4,
.mult = 33*(549+100),
.div = 500*100,
}, { /* Vcore (1.8V) */
.name = "ts72xx-vcore",
.channel = TS72XX_ADC2,
.mult = 33*1,
.div = 500*1,
}, { /* User ADC on DIO2.8 (0-3.3V) */
.name = "ts72xx-dio2.8",
.channel = TS72XX_ADC3,
.mult = 33*1,
.div = 500*1,
}, { /* User ADC on DIO2.10 (0-3.3V) */
.name = "ts72xx-dio2.10",
.channel = TS72XX_ADC1,
.mult = 33*1,
.div = 500*1,
}, { /* EP93XX.VBAT (1.8V) */
.name = "ep93xx-vbat",
.channel = ADC_SW_VBAT_IN|ADC_SW_APWR_REF,
.mult = 33*1,
.div = 500*1,
}, { /* EP93XX.DAC (?) */
.name = "ep93xx-vdac",
.channel = ADC_SW_DAC_IN|ADC_SW_APWR_REF,
.mult = 33*1,
.div = 500*1,
},
};arch/arm/mach-ep93xx/ts72xx.c static void __init ts72xx_init_machine(void) · line 256
Quoted 12 lines
arch/arm/mach-ep93xx/ts72xx.c +5
-0+ +static void __init ts72xx_init_machine (void ) {ep93xx_init_devices ();@@ -177,6 +251,10 @@ static void __init ts72xx_init_machine(void)platform_device_register (&ts72xx_rtc_device);ep93xx_register_eth (&ts72xx_eth_data,1 ); + +platform_device_register (&ep93xx_analog_device); +
Just put the device data setup here:
ep93xx_hwmon_device.dev.platform_data = &ts72xx_hwmon_info;
Quoted 92 lines
arch/arm/mach-ep93xx/ts72xx.c +1
-0+platform_device_register (&ep93xx_hwmon_device); }MACHINE_START (TS72XX ,"Technologic Systems TS-72xx SBC" )drivers/hwmon/Kconfig +17
-0@@ -690,6 +690,23 @@ config SENSORS_S3C_RAW Say Y here if you want to include raw copies of all the ADC channels in sysfs. +config SENSORS_EP93XX + tristate "EP93XX on-chip ADC" + depends on ARCH_EP93XX + help + If you say yes here you get support for the on-board ADCs of + the Cirrus Logic EP93XX series of SoC + + This driver can also be built as a module. If so, the module + will be called ep93xx-hwmo. + +config SENSORS_EP93XX_RAW + bool "Include raw channel attributes in sysfs" + depends on SENSORS_EP93XX + help + Say Y here if you want to include raw copies of all the ADC + channels in sysfs. + config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on PCIdrivers/hwmon/Makefile +1
-0@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o +obj-$(CONFIG_SENSORS_EP93XX) += ep93xx-hwmon.o obj-$(CONFIG_SENSORS_SHT15) += sht15.o obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.odrivers/hwmon/ep93xx-hwmon.c new file +42
-0@@ -0,0 +1,416 @@ +/* linux/drivers/hwmon/ep93xx-hwmon.c +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on linux/drivers/hwmon/s3c-hwmon.c by Simtec Electronics +* +* EP93XX ADC hwmon support +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> + +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> + +#include <mach/adc.h> +#include <mach/hwmon.h> + +struct ep93xx_hwmon_attr { +struct sensor_device_attribute in; +struct sensor_device_attribute label; +char in_name[12 ];
drivers/hwmon/ep93xx-hwmon.c line 52
Quoted 10 lines
drivers/hwmon/ep93xx-hwmon.c new file +10
-0+char label_name[12 ]; +}; + +/** +* struct ep93xx_hwmon - ADC hwmon client information +* @lock: Access lock to serialise the conversions. +* @client: The client we registered with the EP93XX ADC core. +* @hwmon_dev: The hwmon device we created. +* @attr: The holders for the channel attributes. +*/
A lot of the comments in this file are just noise. Also, they really shouldn't be in kerneldoc format since they are private to this file and not exported in any way.
Quoted 355 lines
drivers/hwmon/ep93xx-hwmon.c new file +354
-0+struct ep93xx_hwmon { +struct semaphore lock; +struct ep93xx_adc_client *client; +struct device *hwmon_dev; +struct ep93xx_hwmon_attr attrs[7 ]; +}; + +/** +* ep93xx_hwmon_read_ch - read a value from a given adc channel. +* @dev: The device. +* @hwmon: Our state. +* @channel: The channel we're reading from. +* +* Read a value from the @channel with the proper locking and sleep until +* either the read completes or we timeout awaiting the ADC core to get +* back to us. +*/ +static int ep93xx_hwmon_read_ch (struct device *dev, +struct ep93xx_hwmon *hwmon,int channel) +{ +int ret; + + ret =down_interruptible (&hwmon->lock); +if (ret <0 ) +return ret; + +dev_dbg (dev,"reading channel %d\n" , channel); + + ret =ep93xx_adc_read (hwmon->client, channel); +up (&hwmon->lock); + +return ret; +} + +#ifdef CONFIG_SENSORS_EP93XX_RAW +/** +* ep93xx_hwmon_show_raw - show a conversion from the raw channel number. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* This show deals with the raw attribute, registered for each possible +* ADC channel. This does a conversion and returns the raw (un-scaled) +* value returned from the hardware. +*/ +static ssize_t ep93xx_hwmon_show_raw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ep93xx_hwmon *adc = +platform_get_drvdata (to_platform_device (dev)); +struct sensor_device_attribute *sa =to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sa->index]; + + ret =ep93xx_hwmon_read_ch (dev, adc, cfg->channel); + +return (ret <0 ) ? ret :snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +#define DEF_ADC_ATTR (x) \ + static SENSOR_DEVICE_ATTR(adc##x##_raw, S_IRUGO, ep93xx_hwmon_show_raw, NULL, x) + +DEF_ADC_ATTR (0 ); +DEF_ADC_ATTR (1 ); +DEF_ADC_ATTR (2 ); +DEF_ADC_ATTR (3 ); +DEF_ADC_ATTR (4 ); +DEF_ADC_ATTR (5 ); +DEF_ADC_ATTR (6 ); + +static struct attribute *ep93xx_hwmon_attrs[8 ] = { + &sensor_dev_attr_adc0_raw.dev_attr.attr, + &sensor_dev_attr_adc1_raw.dev_attr.attr, + &sensor_dev_attr_adc2_raw.dev_attr.attr, + &sensor_dev_attr_adc3_raw.dev_attr.attr, + &sensor_dev_attr_adc4_raw.dev_attr.attr, + &sensor_dev_attr_adc5_raw.dev_attr.attr, + &sensor_dev_attr_adc6_raw.dev_attr.attr, +NULL , +}; + +static struct attribute_group ep93xx_hwmon_attrgroup = { + .attrs = ep93xx_hwmon_attrs, +}; + +static inline int ep93xx_hwmon_add_raw (struct device *dev) +{ +return sysfs_create_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +sysfs_remove_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +#else + +static inline void ep93xx_hwmon_add_raw (struct device *dev) +{ +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +} + +#endif /* CONFIG_SENSORS_EP93XX_RAW */ + +/** +* ep93xx_hwmon_ch_show - show value of a given channel +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Read a value from the ADC and scale it before returning it to the +* caller. The scale factor is gained from the channel configuration +* passed via the platform data when the device was registered. +*/ +static ssize_t ep93xx_hwmon_ch_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon *hwmon = +platform_get_drvdata (to_platform_device (dev)); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sen_attr->index]; + + ret =ep93xx_hwmon_read_ch (dev, hwmon, cfg->channel); +if (ret <0 ) +return ret; + + ret *= cfg->mult; + ret =DIV_ROUND_CLOSEST (ret, cfg->div); + +return snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +/** +* ep93xx_hwmon_label_show - show label name of the given channel. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Return the label name of a given channel +*/ +static ssize_t ep93xx_hwmon_label_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; + + cfg = pdata->in[sen_attr->index]; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , cfg->name); +} + +/** +* ep93xx_hwmon_create_attr - create hwmon attribute for given channel. +* @dev: The device to create the attribute on. +* @cfg: The channel configuration passed from the platform data. +* @channel: The ADC channel number to process. +* +* Create the scaled attribute for use with hwmon from the specified +* platform data in @pdata. The sysfs entry is handled by the routine +* ep93xx_hwmon_ch_show(). +* +* The attribute name is taken from the configuration data if present +* otherwise the name is taken by concatenating in_ with the channel +* number. +*/ +static int ep93xx_hwmon_create_attr (struct device *dev, +struct ep93xx_hwmon_chcfg *cfg, +struct ep93xx_hwmon_attr *attrs, +int channel) +{ +struct sensor_device_attribute *attr; +int ret; + +snprintf (attrs->in_name,sizeof (attrs->in_name),"in%d_input" , + channel); + + attr = &attrs->in; + attr->index = channel; + attr->dev_attr.attr.name = attrs->in_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_ch_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +dev_err (dev,"failed to create input attribute\n" ); +return ret; + } + +/* if this has a name, add a label */ +if (cfg->name) { +snprintf (attrs->label_name,sizeof (attrs->label_name), +"in%d_label" , channel); + + attr = &attrs->label; + attr->index = channel; + attr->dev_attr.attr.name = attrs->label_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_label_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +device_remove_file (dev, &attrs->in.dev_attr); +dev_err (dev,"failed to create label attribute\n" ); + } + } + +return ret; +} + +static void ep93xx_hwmon_remove_attr (struct device *dev, +struct ep93xx_hwmon_attr *attrs) +{ +device_remove_file (dev, &attrs->in.dev_attr); +device_remove_file (dev, &attrs->label.dev_attr); +} + +/** +* ep93xx_hwmon_probe - device probe entry. +* @dev: The device being probed. +*/ +static int __devinit ep93xx_hwmon_probe (struct platform_device *dev) +{ +struct ep93xx_hwmon_data *pdata = dev->dev.platform_data; +struct ep93xx_hwmon *hwmon; +int ret =0 ; +int i; + +if (!pdata) { +dev_err (&dev->dev,"no platform data supplied\n" ); +return -EINVAL ; + } + + hwmon =kzalloc (sizeof (struct ep93xx_hwmon ),GFP_KERNEL ); +if (hwmon ==NULL ) { +dev_err (&dev->dev,"no memory\n" ); +return -ENOMEM ; + } + +platform_set_drvdata (dev, hwmon); + +init_MUTEX (&hwmon->lock); + +/* Register with the core ADC driver. */ + + hwmon->client =ep93xx_adc_register (dev); +if (IS_ERR (hwmon->client)) { +dev_err (&dev->dev,"cannot register adc\n" ); + ret =PTR_ERR (hwmon->client); + goto err_mem; + } + +/* add attributes for our adc devices. */ + + ret =ep93xx_hwmon_add_raw (&dev->dev); +if (ret) + goto err_registered; + +/* register with the hwmon core */ + + hwmon->hwmon_dev =hwmon_device_register (&dev->dev); +if (IS_ERR (hwmon->hwmon_dev)) { +dev_err (&dev->dev,"error registering with hwmon\n" ); + ret =PTR_ERR (hwmon->hwmon_dev); + goto err_raw_attribute; + } + +for (i =0 ; i <ARRAY_SIZE (pdata->in); i++) { +if (!pdata->in[i]) +continue ; + +if (pdata->in[i]->mult >=0x10000 ) +dev_warn (&dev->dev, +"channel %d multiplier too large\n" , i); + + ret =ep93xx_hwmon_create_attr (&dev->dev, pdata->in[i], + &hwmon->attrs[i], i); +if (ret) { +dev_err (&dev->dev, +"error creating channel %d\n" , i); + +for (i--; i >=0 ; i--) +ep93xx_hwmon_remove_attr (&dev->dev, + &hwmon->attrs[i]); + + goto err_hwmon_register; + } + } + +return 0 ; + + err_hwmon_register: +hwmon_device_unregister (hwmon->hwmon_dev); + + err_raw_attribute: +ep93xx_hwmon_remove_raw (&dev->dev); + + err_registered: +ep93xx_adc_release (hwmon->client); + + err_mem: +kfree (hwmon); +return ret; +} + +static int __devexit ep93xx_hwmon_remove(struct platform_device *dev) +{ +struct ep93xx_hwmon *hwmon =platform_get_drvdata (dev); +int i; + +ep93xx_hwmon_remove_raw (&dev->dev); + +for (i =0 ; i <ARRAY_SIZE (hwmon->attrs); i++) +ep93xx_hwmon_remove_attr (&dev->dev, &hwmon->attrs[i]); + +hwmon_device_unregister (hwmon->hwmon_dev); +ep93xx_adc_release (hwmon->client); + +return 0 ; +} + +static struct platform_driver ep93xx_hwmon_driver = { + .driver = { + .name ="ep93xx-hwmon" , + .owner =THIS_MODULE , + }, + .probe = ep93xx_hwmon_probe, + .remove =__devexit_p (ep93xx_hwmon_remove), +}; + +static int __init ep93xx_hwmon_init (void ) +{ +return platform_driver_register (&ep93xx_hwmon_driver); +} + +static void __exit ep93xx_hwmon_exit(void) +{
drivers/hwmon/ep93xx-hwmon.c line 416
Quoted 10 lines
drivers/hwmon/ep93xx-hwmon.c new file +10
-0+platform_driver_unregister (&ep93xx_hwmon_driver); +} + +module_init (ep93xx_hwmon_init); +module_exit (ep93xx_hwmon_exit); + +MODULE_AUTHOR ("Christian Gagneraud <[email protected]>" ); +MODULE_DESCRIPTION ("EP93XX ADC HWMon driver" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:ep93xx-hwmon" );
Regards,
Hartley
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 24 lines · H Hartley Sweeten
Quoted 18 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)Quoted 4 lines
This is a first draft. Comments and criticism welcome.
Signed-off-by Christian Gagneraud <[email protected]>---
Quoted 6 lines
Hello Christian,
I see Ryan already sent you some comments so I'll just add mine.
Run this thru checkpatch.pl please. There are a number of whitespace issues in this patch.
Hi Hartley,
Quoted 58 lines
Quoted 58 lines
arch/arm/mach-ep93xx/Makefile | 2 arch/arm/mach-ep93xx/adc.c | 415 +++++++++++++++++++++++ arch/arm/mach-ep93xx/clock.c | 7 arch/arm/mach-ep93xx/core.c | 31 ++ arch/arm/mach-ep93xx/include/mach/adc.h | 54 +++ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | 21 + arch/arm/mach-ep93xx/include/mach/hwmon.h | 43 ++ arch/arm/mach-ep93xx/ts72xx.c | 78 ++++ drivers/hwmon/Kconfig | 17 + drivers/hwmon/Makefile | 1 drivers/hwmon/ep93xx-hwmon.c | 416 +++++++++++++++++++++++ 11 files changed, 1083 insertions(+), 2 deletions(-) create mode 100644 arch/arm/mach-ep93xx/adc.c create mode 100644 arch/arm/mach-ep93xx/include/mach/adc.h create mode 100644 arch/arm/mach-ep93xx/include/mach/hwmon.h create mode 100644 drivers/hwmon/ep93xx-hwmon.carch/arm/mach-ep93xx/Makefile +2
-0@@ -6,6 +6,8 @@ obj-m := obj-n := obj- := +obj-$(CONFIG_EP93XX_ADC) += adc.o + obj-$(CONFIG_MACH_ADSSPHERE) += adssphere.o obj-$(CONFIG_MACH_EDB93XX) += edb93xx.o obj-$(CONFIG_MACH_GESBC9312) += gesbc9312.oarch/arm/mach-ep93xx/adc.c new file +21
-0@@ -0,0 +1,415 @@ +/* +* arch/arm/mach-ep93xx/adc.c +* +* ADC support for Cirrus EP93xx chips. +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c24xx/adc.c by Simtec Electronics +* +* 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. +*/ + +/* +* Touchscreen and Direct ADC: +* +* +------------------------+-----+-----+-----+-----+ +* |ADC/TS driver in use | n/n | y/n | n/y | y/y | +* +------------------------+-----+-----+-----+-----+
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 27
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+* |SYSCON_DEVCFG_ADCPD | 1 | 0 | 0 | 0 | +* |SYSCON_DEVCFG_TIN | X | 1 | 0 | 1/0 | +* |SYSCON_KEYTCHCLKDIV_TSEN| 0 | 1 | 1 | 1 | +* |TS_SETUP_ENABLE (*) | 0 | 0 | 1 | 0/1 | +* +------------------------+-----+-----+-----+-----+ +* (*) Are you missing a comment about (*)?
Yes I do, and I'm still missing it! The datasheet is so unclear that I have the feeling there's something to take care of here, but I still don't know what...
Quoted 4 lines
Is it the intention that this i/o wrapper will allow BOTH the adc and the touchscreen to work at the same time? I don't think that is possible.
For now there's no touchscreen driver mainline, and I don't have a clear picture yet on how to make the 2 drivers collaborate. I think this is doable but as all my boards are EP9302 based (which doesn't have the touchscreen controller, just the ADC engine) I can't test anything!
Quoted 12 lines
Quoted 12 lines
arch/arm/mach-ep93xx/adc.c new file +11
-0+*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/platform_device.h> +#include <linux/list.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/delay.h>
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 42
Quoted 4 lines
arch/arm/mach-ep93xx/adc.c new file +4
-0+#include <linux/sched.h> + +#include <mach/hardware.h> +Please remove the register definitions from
ep93xx-regs.hand just put the defines locally in this file. They are not used anywhere else and belong here. Seedrivers/misc/ep93xx_pwm.cas an example.
OK, will do.
Quoted 18 lines
Quoted 18 lines
arch/arm/mach-ep93xx/adc.c new file +17
-0+static inline void ep93xx_adc_set_reg (void __iomem *reg, +unsigned long val) +{ +__raw_writel (EP93XX_TS_SWLOCK_UNLOCK ,EP93XX_TS_SWLOCK ); +__raw_writel (val, reg); +} + +static inline void ep93xx_adc_clr_reg_bits (void __iomem *reg, +unsigned long bits) +{ +unsigned long val =__raw_readl (reg); + val &= ~bits; +ep93xx_adc_set_reg (reg,val); +} + +static inline void ep93xx_adc_set_reg_bits (void __iomem *reg, +unsigned long bits)
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 64
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +5
-0+{ +unsigned long val =__raw_readl (reg); + val |= bits; +ep93xx_adc_set_reg (reg,val); +}These I/O access functions should be using the
__iomemaddress that you ioremap'ed in the probe. Again, seedrivers/misc/ep93xx_pwm.c.
Will do.
Quoted 241 lines
Quoted 229 lines
arch/arm/mach-ep93xx/adc.c new file +228
-0+ +struct ep93xx_adc_client { +struct platform_device *pdev; +struct list_head pend; +wait_queue_head_t *wait; +unsigned int nr_samples; +int result; +unsigned int channel; +}; + +struct adc_device { +struct platform_device *pdev; +struct platform_device *owner; +struct clk *clk; +struct ep93xx_adc_client *cur; +void __iomem *regs; +int irq; +unsigned int refm;/* Reading when Vin = Vref- */ +unsigned int refp;/* Reading when Vin = Vref+ */ +}; + +static struct adc_device *adc_dev; + +static LIST_HEAD (adc_pending); + +#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg) + +static inline void ep93xx_adc_convert (struct adc_device *adc) +{ +unsigned long prev_switch; +unsigned long next_switch; + +/* Configure the switches */ + prev_switch =__raw_readl (EP93XX_TS_DIRECT ); + next_switch = adc->cur->channel; +if (next_switch != prev_switch) { +ep93xx_adc_set_reg (EP93XX_TS_DIRECT , next_switch); +/* Channel switch settling time */ +/* TODO: depends on clock speed (500us or 2ms) */ +/* FIXME: the caller has disabled interrupts and the +* caller can even be the irq handler. Should we +* better fire a timer? */ +mdelay (2 ); + } + +/* Fire ADC engine with Sync Data Ready IRQ enabled */ +ep93xx_adc_set_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_RINTEN ); +__raw_readl (EP93XX_TS_XYRESULT ); +} + +static void ep93xx_adc_try (struct adc_device *adc) +{ +struct ep93xx_adc_client *next; + +if (!list_empty (&adc_pending)) { + next =list_first_entry (&adc_pending, + struct ep93xx_adc_client, pend); +list_del (&next->pend); +adc_dbg (adc,"new client is %p\n" , next); + adc->cur = next; +ep93xx_adc_convert (adc); + } +} + +int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned long channel,unsigned int nr_samples) +{ +struct adc_device *adc = adc_dev; +unsigned long flags; + +if (!adc) { +printk (KERN_ERR "%s: failed to find adc\n" , __func__); +return -EINVAL ; + } + +local_irq_save (flags); + + client->channel = channel; + client->nr_samples = nr_samples; + +list_add_tail (&client->pend, &adc_pending); + +if (!adc->cur) +ep93xx_adc_try (adc); +local_irq_restore (flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (ep93xx_adc_start); + +static void ep93xx_convert_done (struct ep93xx_adc_client *client, +unsigned val,unsigned *left) +{ + client->result = val; +wake_up (client->wait); +} + +int ep93xx_adc_read (struct ep93xx_adc_client *client,unsigned int ch) +{ +DECLARE_WAIT_QUEUE_HEAD_ONSTACK (wake); +int ret; + + client->wait = &wake; + client->result =-1 ; + + ret =ep93xx_adc_start (client, ch,1 ); +if (ret <0 ) + goto err; + + ret =wait_event_timeout (wake, client->result >=0 ,HZ /2 ); +if (client->result <0 ) { + ret = -ETIMEDOUT ; + goto err; + } + +return client->result; + err: +return ret; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_convert); + +struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device *pdev) +{ +struct ep93xx_adc_client *client; + +printk ("adc_register: %s\n" , pdev->name); + +WARN_ON (!pdev); + +if (!pdev) +return ERR_PTR (-EINVAL ); + + client =kzalloc (sizeof (struct ep93xx_adc_client ),GFP_KERNEL ); +if (!client) { +dev_err (&pdev->dev,"no memory for adc client\n" ); +return ERR_PTR (-ENOMEM ); + } + + client->pdev = pdev; + +return client; +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_register); + +void ep93xx_adc_release (struct ep93xx_adc_client *client) +{ +struct list_head *p, *n; +struct ep93xx_adc_client *tmp; + +/* We should really check that nothing is in progress. */ +if (adc_dev->cur == client) + adc_dev->cur =NULL ; + +list_for_each_safe (p, n, &adc_pending) { + tmp = list_entry(p, struct ep93xx_adc_client, pend); +if (tmp == client) +list_del (&tmp->pend); + } + +if (adc_dev->cur ==NULL ) +ep93xx_adc_try (adc_dev); +kfree (client); +} + +EXPORT_SYMBOL_GPL (ep93xx_adc_release); + +static irqreturn_t ep93xx_adc_irq (int irq,void *pw) +{ +struct adc_device *adc = pw; +struct ep93xx_adc_client *client = adc->cur; +unsigned long flags; +unsigned long data; + +if (!client) { +dev_warn (&adc->pdev->dev,"%s: no adc pending\n" , + __func__); +return IRQ_HANDLED ; + } + +/* Read and convert data */ + data =__raw_readl (EP93XX_TS_XYRESULT ); + data &=0x0000FFFF ; +if (data <0x7000 ) + data +=0x10000 ; + data -= adc->refm; + + client->nr_samples--; + +ep93xx_convert_done (client, data, &client->nr_samples); + +/* If all samples are done, disable IRQ, and kick start the next +* one if any. */ +if (client->nr_samples ==0 ) { +local_irq_save (flags); + adc->cur =NULL ; +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 , +EP93XX_TS_SETUP2_RINTEN ); +ep93xx_adc_try (adc); +local_irq_restore (flags); + } + +return IRQ_HANDLED ; +} + +static int ep93xx_adc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct adc_device *adc; +struct resource *regs; +int ret; + +printk ("adc_probe: %s\n" , pdev->name); + + adc =kzalloc (sizeof (struct adc_device ),GFP_KERNEL ); +if (adc ==NULL ) { +dev_err (dev,"failed to allocate adc_device\n" ); +return -ENOMEM ; + } + + adc->pdev = pdev; + + adc->irq =platform_get_irq (pdev,0 ); +if (adc->irq <=0 ) { +dev_err (dev,"failed to get adc irq\n" ); + ret = -ENOENT ; + goto err_alloc;arch/arm/mach-ep93xx/adc.c line 302
Quoted 10 lines
arch/arm/mach-ep93xx/adc.c new file +10
-0+ } + + ret =request_irq (adc->irq, ep93xx_adc_irq,IRQF_DISABLED , +dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"failed to attach adc irq\n" ); + goto err_alloc; + } + + adc->clk =clk_get (dev,"ep93xx-analog" );Did you try:
Quoted 1 line
adc->clk = clk_get(dev, NULL);
No I didn't, I guess that it will work if the names match. The goal was to define the clock "analog", and the two devices "adc" and "touchscreen", I don't know what's the best strategy to adopt here. I know that ADC and TS share the same ressources (regs, clock, irq, ...) but as I said above I don't have the proper hardware to make any tests.
So perhaps in the mean time, I should define everything as ADC centric and forget completely the touchscreen controller.
Quoted 15 lines
arch/arm/mach-ep93xx/adc.c line 314
Quoted 13 lines
arch/arm/mach-ep93xx/adc.c new file +12
-0+if (IS_ERR (adc->clk)) { +dev_err (dev,"failed to get ADC clock\n" ); + ret =PTR_ERR (adc->clk); + goto err_irq; + } + + regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!regs) { +dev_err (dev,"failed to find registers\n" ); + ret = -ENXIO ; + goto err_clk; + }
request_mem_region()beforeioremap().
Oops, didn't spot that one, thanks.
BTW, doesn't platform_get_resource() do it automatically?
Quoted 25 lines
Quoted 25 lines
arch/arm/mach-ep93xx/adc.c new file +24
-0+ + adc->regs =ioremap (regs->start,resource_size (regs)); +if (!adc->regs) { +dev_err (dev,"failed to map registers\n" ); + ret = -ENXIO ; + goto err_clk; + } + +clk_enable (adc->clk); + +// Enable ADC, inactivate TS controller +ep93xx_devcfg_set_clear (EP93XX_SYSCON_DEVCFG_TIN , +EP93XX_SYSCON_DEVCFG_ADCPD ); +// Disable TS engine +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP ,EP93XX_TS_SETUP_ENABLE ); +// Set ADC to signed mode +ep93xx_adc_clr_reg_bits (EP93XX_TS_SETUP2 ,EP93XX_TS_SETUP2_NSIGND ); + +dev_info (dev,"attached adc driver\n" ); + +platform_set_drvdata (pdev, adc); + +/* Defaults from datasheet (approximated values) */ + adc->refm =0xFFFF -25000 ;
Quoted 8 lines
arch/arm/mach-ep93xx/adc.c line 344
Quoted 6 lines
arch/arm/mach-ep93xx/adc.c new file +6
-0+ adc->refp =25000 ; + adc_dev = adc; + +return 0 ; + + err_clk:Please remove whitespace before the goto labels.
Will do.
Quoted 75 lines
Quoted 75 lines
arch/arm/mach-ep93xx/adc.c new file +71
-0+clk_put (adc->clk); + + err_irq: +free_irq (adc->irq, adc); + + err_alloc: +kfree (adc); +return ret; + +} + +static int ep93xx_adc_remove (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); + +iounmap (adc->regs); +free_irq (adc->irq, adc); +clk_disable (adc->clk); +clk_put (adc->clk); +kfree (adc); + +return 0 ; +} + +#ifdef CONFIG_PM +static int ep93xx_adc_suspend (struct platform_device *pdev, +pm_message_t state) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +ep93xx_devcfg_clear (EP93XX_SYSCON_DEVCFG_ADCPD ); +clk_disable (adc->clk); +return 0 ; +} + +static int ep93xx_adc_resume (struct platform_device *pdev) +{ +struct adc_device *adc =platform_get_drvdata (pdev); +clk_enable (adc->clk); +ep93xx_devcfg_set (EP93XX_SYSCON_DEVCFG_ADCPD ); +return 0 ; +} + +#else +#define ep93xx_adc_suspend NULL +#define ep93xx_adc_resume NULL +#endif + +static struct platform_driver ep93xx_adc_driver = { + .driver = { + .name ="ep93xx-analog" , + .owner =THIS_MODULE , + }, + .probe = ep93xx_adc_probe, + .remove =__devexit_p (ep93xx_adc_remove), + .suspend = ep93xx_adc_suspend, + .resume = ep93xx_adc_resume, +}; + +static int __init adc_init (void ) +{ +int ret; + + ret =platform_driver_register (&ep93xx_adc_driver); +if (ret) +printk (KERN_ERR "%s: failed to add adc driver\n" , + __func__); + +return ret; +} + +arch_initcall (adc_init);arch/arm/mach-ep93xx/clock.c +0
-1--- a/arch/arm/mach-ep93xx/clock.c
Quoted 8 lines
arch/arm/mach-ep93xx/clock.c static struct clk clk_keypad = { · line 75
Quoted 6 lines
+++
b/arch/arm/mach-ep93xx/clock.carch/arm/mach-ep93xx/clock.c +1
-0@@ -72,6 +72,12 @@ static struct clk clk_keypad = { .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_KEN, .set_rate = set_keytchclk_rate, }; +static struct clk clk_analog = {.parent = &clk_xtali,
The parent clock patch is still not in Linus tree.
Quoted 34 lines
Quoted 34 lines
arch/arm/mach-ep93xx/clock.c +6
-0+ .sw_locked = 1, + .enable_reg = EP93XX_SYSCON_KEYTCHCLKDIV, + .enable_mask = EP93XX_SYSCON_KEYTCHCLKDIV_TSEN, + .set_rate = set_keytchclk_rate, +};static struct clk clk_pwm = { .rate =EP93XX_EXT_CLK_RATE , };@@ -147,6 +153,7 @@ static struct clk_lookup clocks[] = {INIT_CK (NULL ,"pll2" , &clk_pll2),INIT_CK ("ep93xx-ohci" ,NULL , &clk_usb_host),INIT_CK ("ep93xx-keypad" ,NULL , &clk_keypad), +INIT_CK ("ep93xx-analog" ,NULL , &clk_analog),INIT_CK ("ep93xx-fb" ,NULL , &clk_video),INIT_CK (NULL ,"pwm_clk" , &clk_pwm), INIT_CK(NULL, "m2p0", &clk_m2p0),arch/arm/mach-ep93xx/core.c +9
-0@@ -684,6 +684,37 @@ EXPORT_SYMBOL(ep93xx_pwm_release_gpio);/************************************************************************* +* EP93xx Analog Touch Screen Interface peripheral handling. +* Note: TS and ADC share the same resource +*************************************************************************/ +static struct resource ep93xx_analog_resource[] = { + [0 ] = { + .start =EP93XX_TS_PHYS_BASE , + .end =EP93XX_TS_PHYS_BASE +0x24 -1 , + .flags =IORESOURCE_MEM , + },
Quoted 8 lines
arch/arm/mach-ep93xx/core.c EXPORT_SYMBOL(ep93xx_pwm_release_gpio); · line 701
Quoted 6 lines
arch/arm/mach-ep93xx/core.c +6
-0+ [1 ] = { + .start =IRQ_EP93XX_TOUCH , + .end =IRQ_EP93XX_TOUCH , + .flags =IORESOURCE_IRQ , + }, +};The [0] = and [1] = are not needed.
OK
Quoted 10 lines
Quoted 10 lines
arch/arm/mach-ep93xx/core.c +9
-0+ +struct platform_device ep93xx_analog_device = { + .name ="ep93xx-analog" , + .id =-1 , + .num_resources =ARRAY_SIZE (ep93xx_analog_resource), + .resource = ep93xx_analog_resource, +}; + +/* HWMON */
Quoted 8 lines
arch/arm/mach-ep93xx/core.c EXPORT_SYMBOL(ep93xx_pwm_release_gpio); · line 715
Quoted 5 lines
arch/arm/mach-ep93xx/core.c +5
-0+struct platform_device ep93xx_hwmon_device = { + .name ="ep93xx-hwmon" , + .id =-1 , + .dev.parent = &ep93xx_analog_device.dev, +};Please make both of these struct's static and just add the necessary ep93xx_register_*() functions for the platform init to call.
OK, I see what you mean. Will do!
Quoted 84 lines
Quoted 71 lines
arch/arm/mach-ep93xx/core.c +2
-0+ +/************************************************************************* * EP93xx video peripheral handling *************************************************************************/ static struct ep93xxfb_mach_info ep93xxfb_data;arch/arm/mach-ep93xx/include/mach/adc.h new file +54
-0@@ -0,0 +1,54 @@ +/* arch/arm/mach-ep93xx/include/arch/adc.h +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on arch/arm/plat-s3c/include/plat/adc.h by Simtec Electronics +* +* EP93XX ADC driver information +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_ADC_H +#define __ASM_ARCH_ADC_H __FILE__ + +/* ADC Channels definition (switches) */ +#define ADC_SW_XP_IN (1<<0) +#define ADC_SW_XM_IN (1<<1) +#define ADC_SW_YP_IN (1<<2) +#define ADC_SW_YM_IN (1<<3) +#define ADC_SW_SXP_IN (1<<4) +#define ADC_SW_SXM_IN (1<<5) +#define ADC_SW_SYP_IN (1<<6) +#define ADC_SW_SYM_IN (1<<7) +#define ADC_SW_VBAT_IN (1<<8) +#define ADC_SW_AVDD_REFP (1<<9) +#define ADC_SW_AGND_REFM (1<<10) +#define ADC_SW_SXP_REFP (1<<24) +#define ADC_SW_SXM_REFM (1<<25) +#define ADC_SW_SYP_REFP (1<<26) +#define ADC_SW_SYM_REFM (1<<27) +#define ADC_SW_DAC_IN (1<<29) +#define ADC_SW_IN_LOAD (1<<30) + +/* AGND as VREF-, AVDD as VREF+ */ +#define ADC_SW_APWR_REF (ADC_SW_AVDD_REFP|ADC_SW_AGND_REFM) + +struct ep93xx_adc_client ; + +extern struct platform_device ep93xx_analog_device; + +extern int ep93xx_adc_start (struct ep93xx_adc_client *client, +unsigned int channel,unsigned int nr_samples); + +extern int ep93xx_adc_read (struct ep93xx_adc_client *client, +unsigned int ch); + +extern struct ep93xx_adc_client *ep93xx_adc_register (struct platform_device + *pdev); + +extern void ep93xx_adc_release (struct ep93xx_adc_client *client); + +#endif /* __ASM_ARCH_ADC_H */ arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +0
-0arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 152
Quoted 10 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +5
-2@@ -145,8 +145,25 @@#define EP93XX_KEY_MATRIX_BASE EP93XX_APB_IOMEM(0x000f0000) -#define EP93XX_ADC_BASE EP93XX_APB_IOMEM(0x00100000) -#define EP93XX_TOUCHSCREEN_BASE EP93XX_APB_IOMEM(0x00100000) +/* Note: +* The EP9301 and EP9302 processors support a general 12-bit ADC, but +* no touchscreen, the EP9307, EP9312 and EP9315 processors each +* support up to an 8-wire touch screen or a general 12-bit ADC +*/ Please remove this comment and put it in the driver file.
Quoted 5 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 153
Quoted 1 line
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +1
-0+#define EP93XX_TS_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00100000)Should be:
#define
EP93XX_TS_PHYS_BASEEP93XX_APB_PHYS(0x00100000)
My current version (linus rc4) doesn't have EP93XX_APB_PHYS().
Quoted 17 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 165
Quoted 13 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +12
-0+#define EP93XX_TS_BASE EP93XX_APB_IOMEM(0x00100000) +#define EP93XX_TS_REG (x) (EP93XX_TS_BASE + (x)) +#define EP93XX_TS_SETUP EP93XX_TS_REG(0x00) +#define EP93XX_TS_SETUP_ENABLE (1<<15) +#define EP93XX_TS_XYRESULT EP93XX_TS_REG(0x08) +#define EP93XX_TS_XYRESULT_SDR (1<<31) +#define EP93XX_TS_DIRECT EP93XX_TS_REG(0x18) +#define EP93XX_TS_SWLOCK EP93XX_TS_REG(0x20) +#define EP93XX_TS_SWLOCK_UNLOCK 0x000000AA +#define EP93XX_TS_SETUP2 EP93XX_TS_REG(0x24) +#define EP93XX_TS_SETUP2_RINTEN (1<<11) +#define EP93XX_TS_SETUP2_NSIGND (1<<9)None of these registers should be defined here. Just put the offsets in the adc driver.
Quoted 3 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h line 166
Quoted 1 line
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +1
-0+Remove this extra blank line.
Will do.
Quoted 62 lines
Quoted 41 lines
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +0
-0#define EP93XX_PWM_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00110000)#define EP93XX_PWM_BASE EP93XX_APB_IOMEM(0x00110000)arch/arm/mach-ep93xx/include/mach/hwmon.h new file +32
-0@@ -0,0 +1,43 @@ +/* linux/arch/arm/mach-ep93xx/include/arch/hwmon.h +* +* Copyright (C) 2009 Christian Gagneraud <[email protected]> +* +* Based on linux/arch/arm/plat-s3c/include/plat/hwmon.h by Simtec Electronics +* +* EP93XX - HWMon interface for ADC +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_ARCH_HWMON_H +#define __ASM_ARCH_HWMON_H __FILE__ + +extern struct platform_device ep93xx_hwmon_device; + +/** + * ep93xx_hwmon_chcfg - channel configuration + * @name: The name to give this channel. + * @mult: Multiply the ADC value read by this. + * @div: Divide the value from the ADC by this. + * + * The value read from the ADC is converted to a value that + * hwmon expects (mV) by result = (value_read * @mult) / @div. + */ +struct ep93xx_hwmon_chcfg { + const char *name; + unsigned long channel; + unsigned long mult; + unsigned long div;arch/arm/mach-ep93xx/include/mach/hwmon.h line 42
Quoted 10 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +10
-0+}; + +/** +* ep93xx_hwmon_pdata - HWMON platform data +* @in: One configuration for each possible channel used. +*/ +struct ep93xx_hwmon_data { +struct ep93xx_hwmon_chcfg *in[7 ]; +}; +The extra
ep93xx_hwmon_datastruct probably isn't needed. See below.Quoted 8 lines
arch/arm/mach-ep93xx/include/mach/hwmon.h new file +1
-0+#endif /* __ASM_ARCH_HWMON_H */ arch/arm/mach-ep93xx/ts72xx.c +0
-0@@ -18,6 +18,8 @@#include <linux/mtd/physmap.h>
Quoted 5 lines
arch/arm/mach-ep93xx/ts72xx.c line 22
Quoted 3 lines
arch/arm/mach-ep93xx/ts72xx.c +2
-0#include <mach/hardware.h> +#include <mach/adc.h> +#include <mach/hwmon.h> Please put these two after the
tx72xx.hheader.
OK.
Quoted 8 lines
Quoted 8 lines
arch/arm/mach-ep93xx/ts72xx.c +0
-0#include <mach/ts72xx.h> #include <asm/mach-types.h> @@ -92,6 +94,8 @@ static struct map_desc ts72xx_alternate_nand_io_desc[] __initdata = { } };
Quoted 14 lines
arch/arm/mach-ep93xx/ts72xx.c static void __init ts72xx_map_io(void) · line 118
Quoted 12 lines
arch/arm/mach-ep93xx/ts72xx.c +4
-0+static struct ep93xx_hwmon_data ts72xx_hwmon_info; +static void __init ts72xx_map_io (void ) {ep93xx_map_io ();@@ -109,6 +113,8 @@ static void __init ts72xx_map_io(void) ARRAY_SIZE(ts72xx_nand_io_desc)); } } + + ep93xx_hwmon_device.dev.platform_data = &ts72xx_hwmon_info; }Ugly... You shouldn't be setting up any type of device data in (
*map_io).
Yes, I don't remember the details but I think I ran into a problem of runtime order dependency, and doing this here have solved it. I will try to fix it.
Well, the whole story is that it's what the S3c code is doing, I tried to move it somewhere else for the same reason (it's ugly) and it didn't work so ...
Quoted 68 lines
Quoted 68 lines
arch/arm/mach-ep93xx/ts72xx.c +61
-0/************************************************************************* @@ -170,6 +176,74 @@ static struct ep93xx_eth_data ts72xx_eth_data = { .phy_id = 1, }; + +#define TS72XX_ADC0 (ADC_SW_YM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC1 (ADC_SW_SXP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC2 (ADC_SW_SXM_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC3 (ADC_SW_SYP_IN | ADC_SW_APWR_REF) +#define TS72XX_ADC4 (ADC_SW_SYM_IN | ADC_SW_APWR_REF) + +// TODO: board dependant +// TS-7200: ADC0, ADC4 +// TS-7250: ADC0 to ADC4 +// TS-7260: Vin, 5V_104, ADC2, Vcore, ADC4 +// TS-7300: 5V, 1.2V, ADC2, 1.8V, ADC4 + +// 0V gives 0, 3.3V gives c. 50000 +// TODO: self calibrate by using VBAT and Load resistor switches +static struct ep93xx_hwmon_data ts72xx_hwmon_info = { +/* POWER_IN*10K/150K (4.5-20V) */ + .in[0 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-vin" , + .channel =TS72XX_ADC0 , + .mult =33 *(15 +1 ), + .div =500 *1 , + }, +/* PC104_5V*10K/54.9K (5V) */ + .in[1 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-v5" , + .channel =TS72XX_ADC4 , + .mult =33 *(549 +100 ), + .div =500 *100 , + }, +/* Vcore (1.8V) */ + .in[2 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-vcore" , + .channel =TS72XX_ADC2 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.8 (0-3.3V) */ + .in[3 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.8" , + .channel =TS72XX_ADC3 , + .mult =33 *1 , + .div =500 *1 , + }, +/* User ADC on DIO2.10 (0-3.3V) */ + .in[4 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ts72xx-dio2.10" , + .channel =TS72XX_ADC1 , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.VBAT (1.8V) */ + .in[5 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vbat" , + .channel =ADC_SW_VBAT_IN |ADC_SW_APWR_REF , + .mult =33 *1 , + .div =500 *1 , + }, +/* EP93XX.DAC (?) */ + .in[6 ] = &(struct ep93xx_hwmon_chcfg ) { + .name ="ep93xx-vdac" ,
Quoted 8 lines
arch/arm/mach-ep93xx/ts72xx.c static struct ep93xx_eth_data ts72xx_eth_data = { · line 244
Quoted 5 lines
arch/arm/mach-ep93xx/ts72xx.c +5
-0+ .channel = ADC_SW_DAC_IN|ADC_SW_APWR_REF, + .mult = 33*1, + .div = 500*1, + }, +};Can you just use struct
ep93xx_hwmon_chcfgdirectly without using the structep93xx_hwmon_dataas a container? Something like:
Yes, actually i copied the S3c code and try to avoid to make any cosmetic change to keep both similar so that it will help if someday someone want to make the adc code ARM generic.
I will change that.
Quoted 48 lines
static struct ep93xx_hwmon_chcfg ts72xx_hwmon_info[] = { { /* POWER_IN*10K/150K (4.5-20V) */ .name = "ts72xx-vin", .channel = TS72XX_ADC0, .mult = 33*(15+1), .div = 500*1, }, { /* PC104_5V*10K/54.9K (5V) */ .name = "ts72xx-v5", .channel = TS72XX_ADC4, .mult = 33*(549+100), .div = 500*100, }, { /* Vcore (1.8V) */ .name = "ts72xx-vcore", .channel = TS72XX_ADC2, .mult = 33*1, .div = 500*1, }, { /* User ADC on DIO2.8 (0-3.3V) */ .name = "ts72xx-dio2.8", .channel = TS72XX_ADC3, .mult = 33*1, .div = 500*1, }, { /* User ADC on DIO2.10 (0-3.3V) */ .name = "ts72xx-dio2.10", .channel = TS72XX_ADC1, .mult = 33*1, .div = 500*1, }, { /* EP93XX.VBAT (1.8V) */ .name = "ep93xx-vbat", .channel = ADC_SW_VBAT_IN|ADC_SW_APWR_REF, .mult = 33*1, .div = 500*1, }, { /* EP93XX.DAC (?) */ .name = "ep93xx-vdac", .channel = ADC_SW_DAC_IN|ADC_SW_APWR_REF, .mult = 33*1, .div = 500*1, }, };Quoted 8 lines
arch/arm/mach-ep93xx/ts72xx.c +2
-0+ +static void __init ts72xx_init_machine (void ) {ep93xx_init_devices ();@@ -177,6 +251,10 @@ static void __init ts72xx_init_machine(void)platform_device_register (&ts72xx_rtc_device);
Quoted 8 lines
arch/arm/mach-ep93xx/ts72xx.c static void __init ts72xx_init_machine(void) · line 256
Quoted 4 lines
arch/arm/mach-ep93xx/ts72xx.c +3
-0ep93xx_register_eth (&ts72xx_eth_data,1 ); + +platform_device_register (&ep93xx_analog_device); +Just put the device data setup here:
ep93xx_hwmon_device.dev.platform_data = &ts72xx_hwmon_info;
Will try.
Quoted 99 lines
Quoted 99 lines
arch/arm/mach-ep93xx/ts72xx.c +1
-0+platform_device_register (&ep93xx_hwmon_device); }MACHINE_START (TS72XX ,"Technologic Systems TS-72xx SBC" )drivers/hwmon/Kconfig +17
-0@@ -690,6 +690,23 @@ config SENSORS_S3C_RAW Say Y here if you want to include raw copies of all the ADC channels in sysfs. +config SENSORS_EP93XX + tristate "EP93XX on-chip ADC" + depends on ARCH_EP93XX + help + If you say yes here you get support for the on-board ADCs of + the Cirrus Logic EP93XX series of SoC + + This driver can also be built as a module. If so, the module + will be called ep93xx-hwmo. + +config SENSORS_EP93XX_RAW + bool "Include raw channel attributes in sysfs" + depends on SENSORS_EP93XX + help + Say Y here if you want to include raw copies of all the ADC + channels in sysfs. + config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on PCIdrivers/hwmon/Makefile +1
-0@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o +obj-$(CONFIG_SENSORS_EP93XX) += ep93xx-hwmon.o obj-$(CONFIG_SENSORS_SHT15) += sht15.o obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.odrivers/hwmon/ep93xx-hwmon.c new file +48
-0@@ -0,0 +1,416 @@ +/* linux/drivers/hwmon/ep93xx-hwmon.c +* +* Copyright 2009, Christian Gagneraud <[email protected]> +* +* Based on linux/drivers/hwmon/s3c-hwmon.c by Simtec Electronics +* +* EP93XX ADC hwmon support +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> + +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> + +#include <mach/adc.h> +#include <mach/hwmon.h> + +struct ep93xx_hwmon_attr { +struct sensor_device_attribute in; +struct sensor_device_attribute label; +char in_name[12 ]; +char label_name[12 ]; +}; + +/** +* struct ep93xx_hwmon - ADC hwmon client information +* @lock: Access lock to serialise the conversions.
Quoted 8 lines
drivers/hwmon/ep93xx-hwmon.c line 52
Quoted 4 lines
drivers/hwmon/ep93xx-hwmon.c new file +4
-0+* @client: The client we registered with the EP93XX ADC core. +* @hwmon_dev: The hwmon device we created. +* @attr: The holders for the channel attributes. +*/ A lot of the comments in this file are just noise. Also, they really shouldn't be in kerneldoc format since they are private to this file and not exported in any way.
Same, this is from the S3C code, i didn't want to do cosmetic changes. I will remove them.
Quoted 361 lines
Quoted 361 lines
drivers/hwmon/ep93xx-hwmon.c new file +360
-0+struct ep93xx_hwmon { +struct semaphore lock; +struct ep93xx_adc_client *client; +struct device *hwmon_dev; +struct ep93xx_hwmon_attr attrs[7 ]; +}; + +/** +* ep93xx_hwmon_read_ch - read a value from a given adc channel. +* @dev: The device. +* @hwmon: Our state. +* @channel: The channel we're reading from. +* +* Read a value from the @channel with the proper locking and sleep until +* either the read completes or we timeout awaiting the ADC core to get +* back to us. +*/ +static int ep93xx_hwmon_read_ch (struct device *dev, +struct ep93xx_hwmon *hwmon,int channel) +{ +int ret; + + ret =down_interruptible (&hwmon->lock); +if (ret <0 ) +return ret; + +dev_dbg (dev,"reading channel %d\n" , channel); + + ret =ep93xx_adc_read (hwmon->client, channel); +up (&hwmon->lock); + +return ret; +} + +#ifdef CONFIG_SENSORS_EP93XX_RAW +/** +* ep93xx_hwmon_show_raw - show a conversion from the raw channel number. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* This show deals with the raw attribute, registered for each possible +* ADC channel. This does a conversion and returns the raw (un-scaled) +* value returned from the hardware. +*/ +static ssize_t ep93xx_hwmon_show_raw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ep93xx_hwmon *adc = +platform_get_drvdata (to_platform_device (dev)); +struct sensor_device_attribute *sa =to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sa->index]; + + ret =ep93xx_hwmon_read_ch (dev, adc, cfg->channel); + +return (ret <0 ) ? ret :snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +#define DEF_ADC_ATTR (x) \ + static SENSOR_DEVICE_ATTR(adc##x##_raw, S_IRUGO, ep93xx_hwmon_show_raw, NULL, x) + +DEF_ADC_ATTR (0 ); +DEF_ADC_ATTR (1 ); +DEF_ADC_ATTR (2 ); +DEF_ADC_ATTR (3 ); +DEF_ADC_ATTR (4 ); +DEF_ADC_ATTR (5 ); +DEF_ADC_ATTR (6 ); + +static struct attribute *ep93xx_hwmon_attrs[8 ] = { + &sensor_dev_attr_adc0_raw.dev_attr.attr, + &sensor_dev_attr_adc1_raw.dev_attr.attr, + &sensor_dev_attr_adc2_raw.dev_attr.attr, + &sensor_dev_attr_adc3_raw.dev_attr.attr, + &sensor_dev_attr_adc4_raw.dev_attr.attr, + &sensor_dev_attr_adc5_raw.dev_attr.attr, + &sensor_dev_attr_adc6_raw.dev_attr.attr, +NULL , +}; + +static struct attribute_group ep93xx_hwmon_attrgroup = { + .attrs = ep93xx_hwmon_attrs, +}; + +static inline int ep93xx_hwmon_add_raw (struct device *dev) +{ +return sysfs_create_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +sysfs_remove_group (&dev->kobj, &ep93xx_hwmon_attrgroup); +} + +#else + +static inline void ep93xx_hwmon_add_raw (struct device *dev) +{ +} + +static inline void ep93xx_hwmon_remove_raw (struct device *dev) +{ +} + +#endif /* CONFIG_SENSORS_EP93XX_RAW */ + +/** +* ep93xx_hwmon_ch_show - show value of a given channel +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Read a value from the ADC and scale it before returning it to the +* caller. The scale factor is gained from the channel configuration +* passed via the platform data when the device was registered. +*/ +static ssize_t ep93xx_hwmon_ch_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon *hwmon = +platform_get_drvdata (to_platform_device (dev)); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; +int ret; + + cfg = pdata->in[sen_attr->index]; + + ret =ep93xx_hwmon_read_ch (dev, hwmon, cfg->channel); +if (ret <0 ) +return ret; + + ret *= cfg->mult; + ret =DIV_ROUND_CLOSEST (ret, cfg->div); + +return snprintf (buf,PAGE_SIZE ,"%d\n" , ret); +} + +/** +* ep93xx_hwmon_label_show - show label name of the given channel. +* @dev: The device that the attribute belongs to. +* @attr: The attribute being read. +* @buf: The result buffer. +* +* Return the label name of a given channel +*/ +static ssize_t ep93xx_hwmon_label_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sen_attr = +to_sensor_dev_attr (attr); +struct ep93xx_hwmon_data *pdata = dev->platform_data; +struct ep93xx_hwmon_chcfg *cfg; + + cfg = pdata->in[sen_attr->index]; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , cfg->name); +} + +/** +* ep93xx_hwmon_create_attr - create hwmon attribute for given channel. +* @dev: The device to create the attribute on. +* @cfg: The channel configuration passed from the platform data. +* @channel: The ADC channel number to process. +* +* Create the scaled attribute for use with hwmon from the specified +* platform data in @pdata. The sysfs entry is handled by the routine +* ep93xx_hwmon_ch_show(). +* +* The attribute name is taken from the configuration data if present +* otherwise the name is taken by concatenating in_ with the channel +* number. +*/ +static int ep93xx_hwmon_create_attr (struct device *dev, +struct ep93xx_hwmon_chcfg *cfg, +struct ep93xx_hwmon_attr *attrs, +int channel) +{ +struct sensor_device_attribute *attr; +int ret; + +snprintf (attrs->in_name,sizeof (attrs->in_name),"in%d_input" , + channel); + + attr = &attrs->in; + attr->index = channel; + attr->dev_attr.attr.name = attrs->in_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_ch_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +dev_err (dev,"failed to create input attribute\n" ); +return ret; + } + +/* if this has a name, add a label */ +if (cfg->name) { +snprintf (attrs->label_name,sizeof (attrs->label_name), +"in%d_label" , channel); + + attr = &attrs->label; + attr->index = channel; + attr->dev_attr.attr.name = attrs->label_name; + attr->dev_attr.attr.mode =S_IRUGO ; + attr->dev_attr.attr.owner =THIS_MODULE ; + attr->dev_attr.show = ep93xx_hwmon_label_show; + + ret =device_create_file (dev, &attr->dev_attr); +if (ret <0 ) { +device_remove_file (dev, &attrs->in.dev_attr); +dev_err (dev,"failed to create label attribute\n" ); + } + } + +return ret; +} + +static void ep93xx_hwmon_remove_attr (struct device *dev, +struct ep93xx_hwmon_attr *attrs) +{ +device_remove_file (dev, &attrs->in.dev_attr); +device_remove_file (dev, &attrs->label.dev_attr); +} + +/** +* ep93xx_hwmon_probe - device probe entry. +* @dev: The device being probed. +*/ +static int __devinit ep93xx_hwmon_probe (struct platform_device *dev) +{ +struct ep93xx_hwmon_data *pdata = dev->dev.platform_data; +struct ep93xx_hwmon *hwmon; +int ret =0 ; +int i; + +if (!pdata) { +dev_err (&dev->dev,"no platform data supplied\n" ); +return -EINVAL ; + } + + hwmon =kzalloc (sizeof (struct ep93xx_hwmon ),GFP_KERNEL ); +if (hwmon ==NULL ) { +dev_err (&dev->dev,"no memory\n" ); +return -ENOMEM ; + } + +platform_set_drvdata (dev, hwmon); + +init_MUTEX (&hwmon->lock); + +/* Register with the core ADC driver. */ + + hwmon->client =ep93xx_adc_register (dev); +if (IS_ERR (hwmon->client)) { +dev_err (&dev->dev,"cannot register adc\n" ); + ret =PTR_ERR (hwmon->client); + goto err_mem; + } + +/* add attributes for our adc devices. */ + + ret =ep93xx_hwmon_add_raw (&dev->dev); +if (ret) + goto err_registered; + +/* register with the hwmon core */ + + hwmon->hwmon_dev =hwmon_device_register (&dev->dev); +if (IS_ERR (hwmon->hwmon_dev)) { +dev_err (&dev->dev,"error registering with hwmon\n" ); + ret =PTR_ERR (hwmon->hwmon_dev); + goto err_raw_attribute; + } + +for (i =0 ; i <ARRAY_SIZE (pdata->in); i++) { +if (!pdata->in[i]) +continue ; + +if (pdata->in[i]->mult >=0x10000 ) +dev_warn (&dev->dev, +"channel %d multiplier too large\n" , i); + + ret =ep93xx_hwmon_create_attr (&dev->dev, pdata->in[i], + &hwmon->attrs[i], i); +if (ret) { +dev_err (&dev->dev, +"error creating channel %d\n" , i); + +for (i--; i >=0 ; i--) +ep93xx_hwmon_remove_attr (&dev->dev, + &hwmon->attrs[i]); + + goto err_hwmon_register; + } + } + +return 0 ; + + err_hwmon_register: +hwmon_device_unregister (hwmon->hwmon_dev); + + err_raw_attribute: +ep93xx_hwmon_remove_raw (&dev->dev); + + err_registered: +ep93xx_adc_release (hwmon->client); + + err_mem: +kfree (hwmon); +return ret; +} + +static int __devexit ep93xx_hwmon_remove(struct platform_device *dev) +{ +struct ep93xx_hwmon *hwmon =platform_get_drvdata (dev); +int i; + +ep93xx_hwmon_remove_raw (&dev->dev); + +for (i =0 ; i <ARRAY_SIZE (hwmon->attrs); i++) +ep93xx_hwmon_remove_attr (&dev->dev, &hwmon->attrs[i]); + +hwmon_device_unregister (hwmon->hwmon_dev); +ep93xx_adc_release (hwmon->client); + +return 0 ; +} + +static struct platform_driver ep93xx_hwmon_driver = { + .driver = { + .name ="ep93xx-hwmon" , + .owner =THIS_MODULE , + }, + .probe = ep93xx_hwmon_probe, + .remove =__devexit_p (ep93xx_hwmon_remove), +}; + +static int __init ep93xx_hwmon_init (void ) +{ +return platform_driver_register (&ep93xx_hwmon_driver); +} + +static void __exit ep93xx_hwmon_exit(void) +{ +platform_driver_unregister (&ep93xx_hwmon_driver); +} + +module_init (ep93xx_hwmon_init); +module_exit (ep93xx_hwmon_exit); +
Quoted 8 lines
drivers/hwmon/ep93xx-hwmon.c line 416
Quoted 5 lines
drivers/hwmon/ep93xx-hwmon.c new file +4
-0+MODULE_AUTHOR ("Christian Gagneraud <[email protected]>" ); +MODULE_DESCRIPTION ("EP93XX ADC HWMon driver" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:ep93xx-hwmon" );Regards,
Hartley
Thanks for all the comments.
Chris
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 13 lines · Christian Gagneraud
Quoted 13 lines
Quoted 12 lines
+/*
+ * Touchscreen and Direct ADC:
+ *
+ * +------------------------+-----+-----+-----+-----+
+ * |ADC/TS driver in use | n/n | y/n | n/y | y/y |
+ * +------------------------+-----+-----+-----+-----++ * |SYSCON_DEVCFG_ADCPD | 1 | 0 | 0 | 0 | + * |SYSCON_DEVCFG_TIN | X | 1 | 0 | 1/0 | + * |SYSCON_KEYTCHCLKDIV_TSEN| 0 | 1 | 1 | 1 | + * |TS_SETUP_ENABLE (*) | 0 | 0 | 1 | 0/1 |+ * +------------------------+-----+-----+-----+-----+
+ * (*)
Quoted 5 lines
Quoted 1 line
Are you missing a comment about (*)?
Yes I do, and I'm still missing it! The datasheet is so unclear that I have the feeling there's something to take care of here, but I still don't know what...
Yeah, the Analog Touch Screen Interface section of the User's Guide is pretty confusing.
Quoted 9 lines
Quoted 3 lines
Is it the intention that this i/o wrapper will allow BOTH the adc and the touchscreen to work at the same time? I don't think that is possible.
For now there's no touchscreen driver mainline, and I don't have a clear picture yet on how to make the 2 drivers collaborate. I think this is doable but as all my boards are EP9302 based (which doesn't have the touchscreen controller, just the ADC engine) I can't test anything!
RFC PATCH 1/1 EP93XX: Add ADC support
In reply to Christian GagneraudQuoted 22 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)This is a first draft. Comments and criticism welcome.
Signed-off-by Christian Gagneraud <[email protected]>---
[snip]
arch/arm/mach-ep93xx/Makefile obj-m := · line 9
Quoted 9 lines
arch/arm/mach-ep93xx/Makefile +1
-0@@ -6,6 +6,8 @@ obj-m := obj-n := obj- := +obj-$(CONFIG_EP93XX_ADC) += adc.o
This Kconfig option is not defined in the patch.
Regards,
Hartley
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 34 lines · H Hartley Sweeten
Quoted 22 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)This is a first draft. Comments and criticism welcome.
Signed-off-by Christian Gagneraud <[email protected]>---
[snip]
Quoted 8 lines
arch/arm/mach-ep93xx/Makefile +0
-0@@ -6,6 +6,8 @@ obj-m := obj-n := obj- :=
Quoted 3 lines
arch/arm/mach-ep93xx/Makefile obj-m := · line 9
Quoted 1 line
arch/arm/mach-ep93xx/Makefile +1
-0+obj-$(CONFIG_EP93XX_ADC) += adc.oThis
Kconfigoption is not defined in the patch.
Oops, it has vanished into a black hole! ;)
Thanks
Chris
Quoted 8 lines
Regards,
Hartley_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC PATCH 1/1 EP93XX: Add ADC support
In reply to Christian GagneraudQuoted 22 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)This is a first draft. Comments and criticism welcome.
Signed-off-by Christian Gagneraud <[email protected]>---
[snip]
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +0
-0
[snip]
arch/arm/mach-ep93xx/adc.c line 300
Quoted 13 lines
arch/arm/mach-ep93xx/adc.c new file +13
-0+ adc->irq =platform_get_irq (pdev,0 ); +if (adc->irq <=0 ) { +dev_err (dev,"failed to get adc irq\n" ); + ret = -ENOENT ; + goto err_alloc; + } + + ret =request_irq (adc->irq, ep93xx_adc_irq,IRQF_DISABLED , +dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"failed to attach adc irq\n" ); + goto err_alloc; + }
The interrupt should be the last thing you request. If an interrupt occurs before the device is completely ready will crash the kernel.
Most of these dev_err messages are not needed. The upper layers will print the error code. You can keep them around for early debugging but they should be removed before the driver is finally merged.
Regards,
Hartley
RFC PATCH 1/1 EP93XX: Add ADC support
Quoted 34 lines · H Hartley Sweeten
Quoted 22 lines · Christian Gagneraud
This patch add support for the ADC found in the EP93XX.
This work is based on S3C platform ADC, apart from hardware related stuff, the following modifications have been done:
- Remove touchscreen support:
On S3C the TS is a "normal" ADC client, but it has priority over all other clients. On EP93XX the TS controller is built-in and offer advanced features.
- Remove convert and select callbacks:
This was done for the shake of simplicity, it can be added easily.
- Channel definition:
On S3c, channel is just an index (unsigned char). On EP93xx channel is the analog switch configuration (unsigned long), it gives the client full freedom on how to make the analog conversion (including routing VRef+ and VRef-, activationg PU/PD resistors, connecting pins to VDD/GND, ...)This is a first draft. Comments and criticism welcome.
Signed-off-by Christian Gagneraud <[email protected]>---
[snip]
Quoted 5 lines
arch/arm/mach-ep93xx/adc.c new file +0
-0[snip]
Quoted 16 lines
arch/arm/mach-ep93xx/adc.c line 300
Quoted 13 lines
arch/arm/mach-ep93xx/adc.c new file +13
-0+ adc->irq =platform_get_irq (pdev,0 ); +if (adc->irq <=0 ) { +dev_err (dev,"failed to get adc irq\n" ); + ret = -ENOENT ; + goto err_alloc; + } + + ret =request_irq (adc->irq, ep93xx_adc_irq,IRQF_DISABLED , +dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"failed to attach adc irq\n" ); + goto err_alloc; + }The interrupt should be the last thing you request. If an interrupt occurs before the device is completely ready will crash the kernel.
OK, will do. Actually now that you pointed me this out, there's even more things to do to ensure everything is initialized correctly, same
for ep93xx_adc_remove()
Quoted 4 lines
Most of these
dev_errmessages are not needed. The upper layers will print the error code. You can keep them around for early debugging but they should be removed before the driver is finally merged.
OK, will do.
Quoted 3 lines
Regards,
Hartley
Thanks,
Chris
RFC PATCH 1/1 EP93XX: Add ADC support
Hello,
I'm new in Linux kernel drivers, so i was wondering if you can tell me where i can find the last version of the driver that you made. Thanks,
Blagoj