2017-12-26 03:54:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-1.0+
|
|
|
|
//
|
|
|
|
// Copyright (c) 2008 Simtec Electronics
|
|
|
|
// http://armlinux.simtec.co.uk/
|
|
|
|
// Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org>
|
|
|
|
//
|
|
|
|
// Samsung ADC device core
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
2018-07-08 05:03:29 +08:00
|
|
|
#include <linux/mod_devicetable.h>
|
2008-12-18 22:20:04 +08:00
|
|
|
#include <linux/platform_device.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2008-12-18 22:20:04 +08:00
|
|
|
#include <linux/list.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-12-18 22:20:04 +08:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io.h>
|
2011-07-20 20:08:17 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
#include <plat/regs-adc.h>
|
|
|
|
#include <plat/adc.h>
|
|
|
|
|
|
|
|
/* This driver is designed to control the usage of the ADC block between
|
|
|
|
* the touchscreen and any other drivers that may need to use it, such as
|
|
|
|
* the hwmon driver.
|
|
|
|
*
|
|
|
|
* Priority will be given to the touchscreen driver, but as this itself is
|
|
|
|
* rate limited it should not starve other requests which are processed in
|
|
|
|
* order that they are received.
|
|
|
|
*
|
|
|
|
* Each user registers to get a client block which uniquely identifies it
|
|
|
|
* and stores information such as the necessary functions to callback when
|
|
|
|
* action is required.
|
|
|
|
*/
|
|
|
|
|
2010-01-14 07:30:34 +08:00
|
|
|
enum s3c_cpu_type {
|
2011-07-20 20:08:18 +08:00
|
|
|
TYPE_ADCV1, /* S3C24XX */
|
2011-10-12 20:34:12 +08:00
|
|
|
TYPE_ADCV11, /* S3C2443 */
|
2011-10-12 20:34:12 +08:00
|
|
|
TYPE_ADCV12, /* S3C2416, S3C2450 */
|
2014-07-02 06:51:50 +08:00
|
|
|
TYPE_ADCV2, /* S3C64XX */
|
2020-01-04 23:20:51 +08:00
|
|
|
TYPE_ADCV3, /* S5PV210, S5PC110, Exynos4210 */
|
2010-01-14 07:30:34 +08:00
|
|
|
};
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
struct s3c_adc_client {
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct list_head pend;
|
2009-07-18 17:12:27 +08:00
|
|
|
wait_queue_head_t *wait;
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
unsigned int nr_samples;
|
2009-07-18 17:12:27 +08:00
|
|
|
int result;
|
2008-12-18 22:20:04 +08:00
|
|
|
unsigned char is_ts;
|
|
|
|
unsigned char channel;
|
|
|
|
|
2009-07-18 17:12:27 +08:00
|
|
|
void (*select_cb)(struct s3c_adc_client *c, unsigned selected);
|
|
|
|
void (*convert_cb)(struct s3c_adc_client *c,
|
|
|
|
unsigned val1, unsigned val2,
|
2009-05-08 21:10:12 +08:00
|
|
|
unsigned *samples_left);
|
2008-12-18 22:20:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct adc_device {
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct platform_device *owner;
|
|
|
|
struct clk *clk;
|
|
|
|
struct s3c_adc_client *cur;
|
|
|
|
struct s3c_adc_client *ts_pend;
|
|
|
|
void __iomem *regs;
|
2010-05-10 12:31:36 +08:00
|
|
|
spinlock_t lock;
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
unsigned int prescale;
|
|
|
|
|
|
|
|
int irq;
|
2011-07-20 20:08:17 +08:00
|
|
|
struct regulator *vdd;
|
2008-12-18 22:20:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct adc_device *adc_dev;
|
|
|
|
|
2010-05-10 12:31:36 +08:00
|
|
|
static LIST_HEAD(adc_pending); /* protected by adc_device.lock */
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg)
|
|
|
|
|
|
|
|
static inline void s3c_adc_convert(struct adc_device *adc)
|
|
|
|
{
|
|
|
|
unsigned con = readl(adc->regs + S3C2410_ADCCON);
|
|
|
|
|
|
|
|
con |= S3C2410_ADCCON_ENABLE_START;
|
|
|
|
writel(con, adc->regs + S3C2410_ADCCON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void s3c_adc_select(struct adc_device *adc,
|
|
|
|
struct s3c_adc_client *client)
|
|
|
|
{
|
|
|
|
unsigned con = readl(adc->regs + S3C2410_ADCCON);
|
2011-07-20 20:08:18 +08:00
|
|
|
enum s3c_cpu_type cpu = platform_get_device_id(adc->pdev)->driver_data;
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2009-07-18 17:12:27 +08:00
|
|
|
client->select_cb(client, 1);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2011-10-12 20:34:11 +08:00
|
|
|
if (cpu == TYPE_ADCV1 || cpu == TYPE_ADCV2)
|
|
|
|
con &= ~S3C2410_ADCCON_MUXMASK;
|
2008-12-18 22:20:04 +08:00
|
|
|
con &= ~S3C2410_ADCCON_STDBM;
|
|
|
|
con &= ~S3C2410_ADCCON_STARTMASK;
|
|
|
|
|
2011-07-20 20:08:18 +08:00
|
|
|
if (!client->is_ts) {
|
|
|
|
if (cpu == TYPE_ADCV3)
|
|
|
|
writel(client->channel & 0xf, adc->regs + S5P_ADCMUX);
|
2011-10-12 20:34:12 +08:00
|
|
|
else if (cpu == TYPE_ADCV11 || cpu == TYPE_ADCV12)
|
2011-10-12 20:34:12 +08:00
|
|
|
writel(client->channel & 0xf,
|
|
|
|
adc->regs + S3C2443_ADCMUX);
|
2011-07-20 20:08:18 +08:00
|
|
|
else
|
|
|
|
con |= S3C2410_ADCCON_SELMUX(client->channel);
|
|
|
|
}
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
writel(con, adc->regs + S3C2410_ADCCON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void s3c_adc_dbgshow(struct adc_device *adc)
|
|
|
|
{
|
|
|
|
adc_dbg(adc, "CON=%08x, TSC=%08x, DLY=%08x\n",
|
|
|
|
readl(adc->regs + S3C2410_ADCCON),
|
|
|
|
readl(adc->regs + S3C2410_ADCTSC),
|
|
|
|
readl(adc->regs + S3C2410_ADCDLY));
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:36:49 +08:00
|
|
|
static void s3c_adc_try(struct adc_device *adc)
|
2008-12-18 22:20:04 +08:00
|
|
|
{
|
|
|
|
struct s3c_adc_client *next = adc->ts_pend;
|
|
|
|
|
|
|
|
if (!next && !list_empty(&adc_pending)) {
|
|
|
|
next = list_first_entry(&adc_pending,
|
|
|
|
struct s3c_adc_client, pend);
|
|
|
|
list_del(&next->pend);
|
|
|
|
} else
|
|
|
|
adc->ts_pend = NULL;
|
|
|
|
|
|
|
|
if (next) {
|
|
|
|
adc_dbg(adc, "new client is %p\n", next);
|
|
|
|
adc->cur = next;
|
|
|
|
s3c_adc_select(adc, next);
|
|
|
|
s3c_adc_convert(adc);
|
|
|
|
s3c_adc_dbgshow(adc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int s3c_adc_start(struct s3c_adc_client *client,
|
|
|
|
unsigned int 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;
|
|
|
|
}
|
|
|
|
|
2010-05-10 12:31:36 +08:00
|
|
|
spin_lock_irqsave(&adc->lock, flags);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2012-07-13 14:30:48 +08:00
|
|
|
if (client->is_ts && adc->ts_pend) {
|
|
|
|
spin_unlock_irqrestore(&adc->lock, flags);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
client->channel = channel;
|
|
|
|
client->nr_samples = nr_samples;
|
|
|
|
|
|
|
|
if (client->is_ts)
|
|
|
|
adc->ts_pend = client;
|
|
|
|
else
|
|
|
|
list_add_tail(&client->pend, &adc_pending);
|
|
|
|
|
|
|
|
if (!adc->cur)
|
|
|
|
s3c_adc_try(adc);
|
2010-05-10 12:31:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&adc->lock, flags);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(s3c_adc_start);
|
|
|
|
|
2009-07-18 17:12:27 +08:00
|
|
|
static void s3c_convert_done(struct s3c_adc_client *client,
|
|
|
|
unsigned v, unsigned u, unsigned *left)
|
|
|
|
{
|
|
|
|
client->result = v;
|
|
|
|
wake_up(client->wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
int s3c_adc_read(struct s3c_adc_client *client, unsigned int ch)
|
|
|
|
{
|
|
|
|
DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wake);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
client->convert_cb = s3c_convert_done;
|
|
|
|
client->wait = &wake;
|
|
|
|
client->result = -1;
|
|
|
|
|
|
|
|
ret = s3c_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
client->convert_cb = NULL;
|
|
|
|
return client->result;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
2009-10-14 04:18:30 +08:00
|
|
|
EXPORT_SYMBOL_GPL(s3c_adc_read);
|
2009-07-18 17:12:27 +08:00
|
|
|
|
|
|
|
static void s3c_adc_default_select(struct s3c_adc_client *client,
|
|
|
|
unsigned select)
|
2008-12-18 22:20:04 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct s3c_adc_client *s3c_adc_register(struct platform_device *pdev,
|
2009-07-18 17:12:27 +08:00
|
|
|
void (*select)(struct s3c_adc_client *client,
|
|
|
|
unsigned int selected),
|
|
|
|
void (*conv)(struct s3c_adc_client *client,
|
|
|
|
unsigned d0, unsigned d1,
|
2009-05-08 21:10:12 +08:00
|
|
|
unsigned *samples_left),
|
2008-12-18 22:20:04 +08:00
|
|
|
unsigned int is_ts)
|
|
|
|
{
|
|
|
|
struct s3c_adc_client *client;
|
|
|
|
|
|
|
|
WARN_ON(!pdev);
|
|
|
|
|
|
|
|
if (!select)
|
|
|
|
select = s3c_adc_default_select;
|
|
|
|
|
2009-07-18 17:12:27 +08:00
|
|
|
if (!pdev)
|
2008-12-18 22:20:04 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2017-10-04 15:52:33 +08:00
|
|
|
client = kzalloc(sizeof(*client), GFP_KERNEL);
|
2017-10-04 15:33:52 +08:00
|
|
|
if (!client)
|
2008-12-18 22:20:04 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
client->pdev = pdev;
|
|
|
|
client->is_ts = is_ts;
|
|
|
|
client->select_cb = select;
|
|
|
|
client->convert_cb = conv;
|
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(s3c_adc_register);
|
|
|
|
|
|
|
|
void s3c_adc_release(struct s3c_adc_client *client)
|
|
|
|
{
|
2010-05-10 12:31:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&adc_dev->lock, flags);
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
/* We should really check that nothing is in progress. */
|
2009-04-14 23:56:18 +08:00
|
|
|
if (adc_dev->cur == client)
|
|
|
|
adc_dev->cur = NULL;
|
|
|
|
if (adc_dev->ts_pend == client)
|
|
|
|
adc_dev->ts_pend = NULL;
|
|
|
|
else {
|
|
|
|
struct list_head *p, *n;
|
|
|
|
struct s3c_adc_client *tmp;
|
|
|
|
|
|
|
|
list_for_each_safe(p, n, &adc_pending) {
|
|
|
|
tmp = list_entry(p, struct s3c_adc_client, pend);
|
|
|
|
if (tmp == client)
|
|
|
|
list_del(&tmp->pend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adc_dev->cur == NULL)
|
|
|
|
s3c_adc_try(adc_dev);
|
2010-05-10 12:31:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&adc_dev->lock, flags);
|
2008-12-18 22:20:04 +08:00
|
|
|
kfree(client);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(s3c_adc_release);
|
|
|
|
|
|
|
|
static irqreturn_t s3c_adc_irq(int irq, void *pw)
|
|
|
|
{
|
|
|
|
struct adc_device *adc = pw;
|
|
|
|
struct s3c_adc_client *client = adc->cur;
|
2010-01-31 01:01:48 +08:00
|
|
|
enum s3c_cpu_type cpu = platform_get_device_id(adc->pdev)->driver_data;
|
2008-12-18 22:20:04 +08:00
|
|
|
unsigned data0, data1;
|
|
|
|
|
|
|
|
if (!client) {
|
|
|
|
dev_warn(&adc->pdev->dev, "%s: no adc pending\n", __func__);
|
2010-01-14 07:30:34 +08:00
|
|
|
goto exit;
|
2008-12-18 22:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
data0 = readl(adc->regs + S3C2410_ADCDAT0);
|
|
|
|
data1 = readl(adc->regs + S3C2410_ADCDAT1);
|
|
|
|
adc_dbg(adc, "read %d: 0x%04x, 0x%04x\n", client->nr_samples, data0, data1);
|
|
|
|
|
2009-05-08 21:10:12 +08:00
|
|
|
client->nr_samples--;
|
2009-07-18 17:12:27 +08:00
|
|
|
|
2011-10-12 20:34:12 +08:00
|
|
|
if (cpu == TYPE_ADCV1 || cpu == TYPE_ADCV11) {
|
|
|
|
data0 &= 0x3ff;
|
|
|
|
data1 &= 0x3ff;
|
|
|
|
} else {
|
2011-10-12 20:34:12 +08:00
|
|
|
/* S3C2416/S3C64XX/S5P ADC resolution is 12-bit */
|
2010-01-31 01:01:48 +08:00
|
|
|
data0 &= 0xfff;
|
|
|
|
data1 &= 0xfff;
|
|
|
|
}
|
|
|
|
|
2009-07-18 17:12:27 +08:00
|
|
|
if (client->convert_cb)
|
2010-01-31 01:01:48 +08:00
|
|
|
(client->convert_cb)(client, data0, data1, &client->nr_samples);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2009-05-08 21:10:12 +08:00
|
|
|
if (client->nr_samples > 0) {
|
2008-12-18 22:20:04 +08:00
|
|
|
/* fire another conversion for this */
|
|
|
|
|
2009-07-18 17:12:27 +08:00
|
|
|
client->select_cb(client, 1);
|
2008-12-18 22:20:04 +08:00
|
|
|
s3c_adc_convert(adc);
|
|
|
|
} else {
|
2010-05-10 12:31:36 +08:00
|
|
|
spin_lock(&adc->lock);
|
2009-07-18 17:12:27 +08:00
|
|
|
(client->select_cb)(client, 0);
|
2008-12-18 22:20:04 +08:00
|
|
|
adc->cur = NULL;
|
|
|
|
|
|
|
|
s3c_adc_try(adc);
|
2010-05-10 12:31:36 +08:00
|
|
|
spin_unlock(&adc->lock);
|
2008-12-18 22:20:04 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 07:30:34 +08:00
|
|
|
exit:
|
2011-10-12 20:34:12 +08:00
|
|
|
if (cpu == TYPE_ADCV2 || cpu == TYPE_ADCV3) {
|
2010-01-14 07:30:34 +08:00
|
|
|
/* Clear ADC interrupt */
|
|
|
|
writel(0, adc->regs + S3C64XX_ADCCLRINT);
|
|
|
|
}
|
2008-12-18 22:20:04 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s3c_adc_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct adc_device *adc;
|
|
|
|
struct resource *regs;
|
2011-10-12 20:34:12 +08:00
|
|
|
enum s3c_cpu_type cpu = platform_get_device_id(pdev)->driver_data;
|
2008-12-18 22:20:04 +08:00
|
|
|
int ret;
|
2010-01-31 01:01:48 +08:00
|
|
|
unsigned tmp;
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2017-10-04 15:52:33 +08:00
|
|
|
adc = devm_kzalloc(dev, sizeof(*adc), GFP_KERNEL);
|
2017-10-04 15:33:52 +08:00
|
|
|
if (!adc)
|
2008-12-18 22:20:04 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-05-10 12:31:36 +08:00
|
|
|
spin_lock_init(&adc->lock);
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
adc->pdev = pdev;
|
|
|
|
adc->prescale = S3C2410_ADCCON_PRSCVL(49);
|
|
|
|
|
2012-11-20 19:50:54 +08:00
|
|
|
adc->vdd = devm_regulator_get(dev, "vdd");
|
2011-07-20 20:08:17 +08:00
|
|
|
if (IS_ERR(adc->vdd)) {
|
|
|
|
dev_err(dev, "operating without regulator \"vdd\" .\n");
|
2012-11-20 19:50:54 +08:00
|
|
|
return PTR_ERR(adc->vdd);
|
2011-07-20 20:08:17 +08:00
|
|
|
}
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
adc->irq = platform_get_irq(pdev, 1);
|
|
|
|
if (adc->irq <= 0) {
|
|
|
|
dev_err(dev, "failed to get adc irq\n");
|
2012-11-20 19:50:54 +08:00
|
|
|
return -ENOENT;
|
2008-12-18 22:20:04 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 19:50:54 +08:00
|
|
|
ret = devm_request_irq(dev, adc->irq, s3c_adc_irq, 0, dev_name(dev),
|
|
|
|
adc);
|
2008-12-18 22:20:04 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "failed to attach adc irq\n");
|
2012-11-20 19:50:54 +08:00
|
|
|
return ret;
|
2008-12-18 22:20:04 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 19:50:54 +08:00
|
|
|
adc->clk = devm_clk_get(dev, "adc");
|
2008-12-18 22:20:04 +08:00
|
|
|
if (IS_ERR(adc->clk)) {
|
|
|
|
dev_err(dev, "failed to get adc clock\n");
|
2012-11-20 19:50:54 +08:00
|
|
|
return PTR_ERR(adc->clk);
|
2008-12-18 22:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-01-21 18:08:55 +08:00
|
|
|
adc->regs = devm_ioremap_resource(dev, regs);
|
|
|
|
if (IS_ERR(adc->regs))
|
|
|
|
return PTR_ERR(adc->regs);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2011-07-20 20:08:17 +08:00
|
|
|
ret = regulator_enable(adc->vdd);
|
|
|
|
if (ret)
|
2012-11-20 19:50:54 +08:00
|
|
|
return ret;
|
2011-07-20 20:08:17 +08:00
|
|
|
|
2015-04-27 13:29:44 +08:00
|
|
|
clk_prepare_enable(adc->clk);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2010-01-31 01:01:48 +08:00
|
|
|
tmp = adc->prescale | S3C2410_ADCCON_PRSCEN;
|
2011-10-12 20:34:12 +08:00
|
|
|
|
|
|
|
/* Enable 12-bit ADC resolution */
|
|
|
|
if (cpu == TYPE_ADCV12)
|
|
|
|
tmp |= S3C2416_ADCCON_RESSEL;
|
|
|
|
if (cpu == TYPE_ADCV2 || cpu == TYPE_ADCV3)
|
2010-01-31 01:01:48 +08:00
|
|
|
tmp |= S3C64XX_ADCCON_RESSEL;
|
2011-10-12 20:34:12 +08:00
|
|
|
|
2010-01-31 01:01:48 +08:00
|
|
|
writel(tmp, adc->regs + S3C2410_ADCCON);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
dev_info(dev, "attached adc driver\n");
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, adc);
|
|
|
|
adc_dev = adc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:02:24 +08:00
|
|
|
static int s3c_adc_remove(struct platform_device *pdev)
|
2008-12-18 22:20:04 +08:00
|
|
|
{
|
|
|
|
struct adc_device *adc = platform_get_drvdata(pdev);
|
|
|
|
|
2015-04-27 13:29:44 +08:00
|
|
|
clk_disable_unprepare(adc->clk);
|
2011-07-20 20:08:17 +08:00
|
|
|
regulator_disable(adc->vdd);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2011-07-20 20:08:18 +08:00
|
|
|
static int s3c_adc_suspend(struct device *dev)
|
2008-12-18 22:20:04 +08:00
|
|
|
{
|
2018-04-19 22:05:31 +08:00
|
|
|
struct adc_device *adc = dev_get_drvdata(dev);
|
2010-05-10 12:31:36 +08:00
|
|
|
unsigned long flags;
|
2008-12-18 22:20:04 +08:00
|
|
|
u32 con;
|
|
|
|
|
2010-05-10 12:31:36 +08:00
|
|
|
spin_lock_irqsave(&adc->lock, flags);
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
con = readl(adc->regs + S3C2410_ADCCON);
|
|
|
|
con |= S3C2410_ADCCON_STDBM;
|
|
|
|
writel(con, adc->regs + S3C2410_ADCCON);
|
|
|
|
|
2010-02-19 00:32:29 +08:00
|
|
|
disable_irq(adc->irq);
|
2010-05-10 12:31:36 +08:00
|
|
|
spin_unlock_irqrestore(&adc->lock, flags);
|
2008-12-18 22:20:04 +08:00
|
|
|
clk_disable(adc->clk);
|
2011-07-20 20:08:17 +08:00
|
|
|
regulator_disable(adc->vdd);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-20 20:08:18 +08:00
|
|
|
static int s3c_adc_resume(struct device *dev)
|
2008-12-18 22:20:04 +08:00
|
|
|
{
|
2015-12-27 21:17:36 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2008-12-18 22:20:04 +08:00
|
|
|
struct adc_device *adc = platform_get_drvdata(pdev);
|
2011-10-12 20:34:12 +08:00
|
|
|
enum s3c_cpu_type cpu = platform_get_device_id(pdev)->driver_data;
|
2011-07-20 20:08:17 +08:00
|
|
|
int ret;
|
2011-07-20 20:08:18 +08:00
|
|
|
unsigned long tmp;
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2011-07-20 20:08:17 +08:00
|
|
|
ret = regulator_enable(adc->vdd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-12-18 22:20:04 +08:00
|
|
|
clk_enable(adc->clk);
|
2010-02-19 00:32:29 +08:00
|
|
|
enable_irq(adc->irq);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
2011-07-20 20:08:18 +08:00
|
|
|
tmp = adc->prescale | S3C2410_ADCCON_PRSCEN;
|
2011-10-12 20:34:12 +08:00
|
|
|
|
2011-07-20 20:08:18 +08:00
|
|
|
/* Enable 12-bit ADC resolution */
|
2011-10-12 20:34:12 +08:00
|
|
|
if (cpu == TYPE_ADCV12)
|
|
|
|
tmp |= S3C2416_ADCCON_RESSEL;
|
|
|
|
if (cpu == TYPE_ADCV2 || cpu == TYPE_ADCV3)
|
2011-07-20 20:08:18 +08:00
|
|
|
tmp |= S3C64XX_ADCCON_RESSEL;
|
2011-10-12 20:34:12 +08:00
|
|
|
|
2011-07-20 20:08:18 +08:00
|
|
|
writel(tmp, adc->regs + S3C2410_ADCCON);
|
2008-12-18 22:20:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define s3c_adc_suspend NULL
|
|
|
|
#define s3c_adc_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2015-05-01 23:06:35 +08:00
|
|
|
static const struct platform_device_id s3c_adc_driver_ids[] = {
|
2010-01-14 07:30:34 +08:00
|
|
|
{
|
|
|
|
.name = "s3c24xx-adc",
|
2011-07-20 20:08:18 +08:00
|
|
|
.driver_data = TYPE_ADCV1,
|
2011-10-12 20:34:12 +08:00
|
|
|
}, {
|
|
|
|
.name = "s3c2443-adc",
|
|
|
|
.driver_data = TYPE_ADCV11,
|
2011-10-12 20:34:12 +08:00
|
|
|
}, {
|
|
|
|
.name = "s3c2416-adc",
|
|
|
|
.driver_data = TYPE_ADCV12,
|
2010-01-14 07:30:34 +08:00
|
|
|
}, {
|
|
|
|
.name = "s3c64xx-adc",
|
2011-07-20 20:08:18 +08:00
|
|
|
.driver_data = TYPE_ADCV2,
|
|
|
|
}, {
|
|
|
|
.name = "samsung-adc-v3",
|
|
|
|
.driver_data = TYPE_ADCV3,
|
2010-01-14 07:30:34 +08:00
|
|
|
},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, s3c_adc_driver_ids);
|
|
|
|
|
2011-07-20 20:08:18 +08:00
|
|
|
static const struct dev_pm_ops adc_pm_ops = {
|
|
|
|
.suspend = s3c_adc_suspend,
|
|
|
|
.resume = s3c_adc_resume,
|
|
|
|
};
|
|
|
|
|
2008-12-18 22:20:04 +08:00
|
|
|
static struct platform_driver s3c_adc_driver = {
|
2010-01-14 07:30:34 +08:00
|
|
|
.id_table = s3c_adc_driver_ids,
|
2008-12-18 22:20:04 +08:00
|
|
|
.driver = {
|
2010-01-14 07:30:34 +08:00
|
|
|
.name = "s3c-adc",
|
2011-07-20 20:08:18 +08:00
|
|
|
.pm = &adc_pm_ops,
|
2008-12-18 22:20:04 +08:00
|
|
|
},
|
|
|
|
.probe = s3c_adc_probe,
|
2012-12-22 06:02:24 +08:00
|
|
|
.remove = s3c_adc_remove,
|
2008-12-18 22:20:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init adc_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = platform_driver_register(&s3c_adc_driver);
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "%s: failed to add adc driver\n", __func__);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-20 20:08:17 +08:00
|
|
|
module_init(adc_init);
|