mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-09 20:32:04 +09:00
This commit is contained in:
@@ -5,6 +5,6 @@ obj-y += vreg.o
|
||||
obj-y += clock.o
|
||||
obj-$(CONFIG_CPU_FREQ) += cpufreq.o
|
||||
obj-y += dma.o
|
||||
obj-$(CONFIG_RK28_ADC) += rk2818_adc.o
|
||||
obj-$(CONFIG_RK28_ADC) += adc.o
|
||||
obj-$(CONFIG_MACH_RK2818MID) += board-midsdk.o
|
||||
|
||||
|
||||
463
arch/arm/mach-rk2818/adc.c
Normal file
463
arch/arm/mach-rk2818/adc.c
Normal file
@@ -0,0 +1,463 @@
|
||||
/* arm/arch/mach-rk2818/adc.c
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/io.h>
|
||||
|
||||
#include <mach/rk2818_iomap.h>
|
||||
#include <mach/adc.h>
|
||||
|
||||
/* This driver is designed to control the usage of the ADC block between
|
||||
* the keyboard and any other drivers that may need to use it.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
struct rk28_adc_client {
|
||||
struct platform_device *pdev;
|
||||
struct list_head pend;
|
||||
wait_queue_head_t *wait;
|
||||
|
||||
unsigned int nr_samples;
|
||||
int result;
|
||||
unsigned char is_ts;
|
||||
unsigned char channel;
|
||||
|
||||
void (*select_cb)(struct rk28_adc_client *c, unsigned selected);
|
||||
void (*convert_cb)(struct rk28_adc_client *c,
|
||||
unsigned val1, unsigned val2,
|
||||
unsigned *samples_left);
|
||||
};
|
||||
|
||||
struct adc_device {
|
||||
struct platform_device *pdev;
|
||||
struct platform_device *owner;
|
||||
struct clk *clk;
|
||||
struct rk28_adc_client *cur;
|
||||
struct rk28_adc_client *ts_pend;
|
||||
void __iomem *regs;
|
||||
|
||||
unsigned int pre_con;
|
||||
int irq;
|
||||
};
|
||||
|
||||
static struct adc_device *pAdcDev;
|
||||
|
||||
static LIST_HEAD(adc_pending);
|
||||
|
||||
#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg)
|
||||
|
||||
static inline void rk28_adc_int_enable(struct adc_device *adc)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
con |= RK28_ADC_INT_ENABLE;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static inline void rk28_adc_int_disable(struct adc_device *adc)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
con &= RK28_ADC_INT_DISABLE;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static inline void rk28_adc_int_clear(struct adc_device *adc)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
con &= RK28_ADC_INT_CLEAR;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static inline void rk28_adc_power_up(struct adc_device *adc)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
con |= RK28_ADC_POWER_UP;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static inline void rk28_adc_power_down(struct adc_device *adc)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
con &= RK28_ADC_POWER_DOWN;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static inline void rk28_adc_convert(struct adc_device *adc)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
con |= RK28_ADC_POWER_UP | RK28_ADC_CONV_START | RK28_ADC_INT_ENABLE;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static inline void rk28_adc_select(struct adc_device *adc,
|
||||
struct rk28_adc_client *client)
|
||||
{
|
||||
unsigned con = readl(adc->regs + RK28_ADCCON);
|
||||
|
||||
client->select_cb(client, 1);
|
||||
|
||||
con &= RK28_ADC_MASK_CH;
|
||||
con &= RK28_ADC_CONV_STOP;
|
||||
|
||||
if (!client->is_ts)
|
||||
con |= RK28_ADC_SEL_CH(client->channel);
|
||||
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
}
|
||||
|
||||
static void rk28_adc_dbgshow(struct adc_device *adc)
|
||||
{
|
||||
adc_dbg(adc, "CON=0x%x, STAS=0x%x, DATA=0x%x\n",
|
||||
readl(adc->regs + RK28_ADCCON),
|
||||
readl(adc->regs + RK28_ADCSTAS),
|
||||
readl(adc->regs + RK28_ADCDAT));
|
||||
}
|
||||
|
||||
static void rk28_adc_try(struct adc_device *adc)
|
||||
{
|
||||
struct rk28_adc_client *next = adc->ts_pend;
|
||||
|
||||
if (!next && !list_empty(&adc_pending)) {
|
||||
next = list_first_entry(&adc_pending,
|
||||
struct rk28_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;
|
||||
rk28_adc_select(adc, next);
|
||||
rk28_adc_convert(adc);
|
||||
rk28_adc_dbgshow(adc);
|
||||
}
|
||||
}
|
||||
|
||||
int rk28_adc_start(struct rk28_adc_client *client,
|
||||
unsigned int channel, unsigned int nr_samples)
|
||||
{
|
||||
struct adc_device *adc = pAdcDev;
|
||||
unsigned long flags;
|
||||
|
||||
if (!adc) {
|
||||
printk(KERN_ERR "%s: failed to find adc\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (client->is_ts && adc->ts_pend)
|
||||
return -EAGAIN;
|
||||
|
||||
local_irq_save(flags);
|
||||
|
||||
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)
|
||||
rk28_adc_try(adc);
|
||||
local_irq_restore(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rk28_adc_start);
|
||||
|
||||
static void rk28_convert_done(struct rk28_adc_client *client,
|
||||
unsigned v, unsigned u, unsigned *left)
|
||||
{
|
||||
client->result = v;
|
||||
wake_up(client->wait);
|
||||
}
|
||||
|
||||
int rk28_adc_read(struct rk28_adc_client *client, unsigned int ch)
|
||||
{
|
||||
DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wake);
|
||||
int ret;
|
||||
|
||||
client->convert_cb = rk28_convert_done;
|
||||
client->wait = &wake;
|
||||
client->result = -1;
|
||||
|
||||
ret = rk28_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;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rk28_adc_read);
|
||||
|
||||
static void rk28_adc_default_select(struct rk28_adc_client *client,
|
||||
unsigned select)
|
||||
{
|
||||
}
|
||||
|
||||
struct rk28_adc_client *rk28_adc_register(struct platform_device *pdev,
|
||||
void (*select)(struct rk28_adc_client *client,
|
||||
unsigned int selected),
|
||||
void (*conv)(struct rk28_adc_client *client,
|
||||
unsigned d0, unsigned d1,
|
||||
unsigned *samples_left),
|
||||
unsigned int is_ts)
|
||||
{
|
||||
struct rk28_adc_client *client;
|
||||
|
||||
WARN_ON(!pdev);
|
||||
|
||||
if (!select)
|
||||
select = rk28_adc_default_select;
|
||||
|
||||
if (!pdev)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
client = kzalloc(sizeof(struct rk28_adc_client), GFP_KERNEL);
|
||||
if (!client) {
|
||||
dev_err(&pdev->dev, "no memory for adc client\n");
|
||||
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(rk28_adc_register);
|
||||
|
||||
void rk28_adc_release(struct rk28_adc_client *client)
|
||||
{
|
||||
/* We should really check that nothing is in progress. */
|
||||
if (pAdcDev->cur == client)
|
||||
pAdcDev->cur = NULL;
|
||||
if (pAdcDev->ts_pend == client)
|
||||
pAdcDev->ts_pend = NULL;
|
||||
else {
|
||||
struct list_head *p, *n;
|
||||
struct rk28_adc_client *tmp;
|
||||
|
||||
list_for_each_safe(p, n, &adc_pending) {
|
||||
tmp = list_entry(p, struct rk28_adc_client, pend);
|
||||
if (tmp == client)
|
||||
list_del(&tmp->pend);
|
||||
}
|
||||
}
|
||||
|
||||
if (pAdcDev->cur == NULL)
|
||||
rk28_adc_try(pAdcDev);
|
||||
kfree(client);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rk28_adc_release);
|
||||
|
||||
static irqreturn_t rk28_adc_irq(int irq, void *pw)
|
||||
{
|
||||
struct adc_device *adc = pw;
|
||||
struct rk28_adc_client *client = adc->cur;
|
||||
unsigned long flags;
|
||||
unsigned data0, data1 = 0;
|
||||
rk28_adc_int_disable(adc);
|
||||
rk28_adc_int_clear(adc);
|
||||
|
||||
if (!client) {
|
||||
dev_warn(&adc->pdev->dev, "%s: no adc pending\n", __func__);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
data0 = readl(adc->regs + RK28_ADCDAT);
|
||||
|
||||
adc_dbg(adc, "read %d: 0x%x\n", client->nr_samples, data0);
|
||||
|
||||
client->nr_samples--;
|
||||
|
||||
if (client->convert_cb)
|
||||
(client->convert_cb)(client, data0 & 0x3ff, data1 & 0x3ff,
|
||||
&client->nr_samples);
|
||||
|
||||
if (client->nr_samples > 0) {
|
||||
/* fire another conversion for this */
|
||||
|
||||
client->select_cb(client, 1);
|
||||
rk28_adc_convert(adc);
|
||||
} else {
|
||||
local_irq_save(flags);
|
||||
(client->select_cb)(client, 0);
|
||||
adc->cur = NULL;
|
||||
|
||||
rk28_adc_try(adc);
|
||||
local_irq_restore(flags);
|
||||
}
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int rk28_adc_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct adc_device *adc;
|
||||
struct resource *regs;
|
||||
int ret;
|
||||
|
||||
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, rk28_adc_irq, 0, dev_name(dev), adc);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "failed to attach adc irq\n");
|
||||
goto err_alloc;
|
||||
}
|
||||
|
||||
adc->clk = clk_get(dev, "lsadc");
|
||||
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;
|
||||
goto err_clk;
|
||||
}
|
||||
|
||||
clk_enable(adc->clk);
|
||||
|
||||
dev_info(dev, "attached adc driver\n");
|
||||
|
||||
platform_set_drvdata(pdev, adc);
|
||||
|
||||
rk28_adc_int_disable(adc);
|
||||
pAdcDev = adc;
|
||||
printk("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);
|
||||
return 0;
|
||||
|
||||
err_clk:
|
||||
clk_put(adc->clk);
|
||||
|
||||
err_irq:
|
||||
free_irq(adc->irq, adc);
|
||||
|
||||
err_alloc:
|
||||
kfree(adc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rk28_adc_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct adc_device *adc = platform_get_drvdata(pdev);
|
||||
rk28_adc_power_down(adc);
|
||||
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 rk28_adc_suspend(struct platform_device *pdev, pm_message_t state)
|
||||
{
|
||||
struct adc_device *adc = platform_get_drvdata(pdev);
|
||||
u32 con;
|
||||
|
||||
con = readl(adc->regs + RK28_ADCCON);
|
||||
adc->pre_con = con;
|
||||
con &= RK28_ADC_POWER_DOWN;
|
||||
writel(con, adc->regs + RK28_ADCCON);
|
||||
|
||||
clk_disable(adc->clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rk28_adc_resume(struct platform_device *pdev)
|
||||
{
|
||||
struct adc_device *adc = platform_get_drvdata(pdev);
|
||||
|
||||
clk_enable(adc->clk);
|
||||
|
||||
writel(adc->pre_con, adc->regs + RK28_ADCCON);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#define rk28_adc_suspend NULL
|
||||
#define rk28_adc_resume NULL
|
||||
#endif
|
||||
|
||||
static struct platform_driver rk28_adc_driver = {
|
||||
.driver = {
|
||||
.name = "rk2818-adc",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.probe = rk28_adc_probe,
|
||||
.remove = __devexit_p(rk28_adc_remove),
|
||||
.suspend = rk28_adc_suspend,
|
||||
.resume = rk28_adc_resume,
|
||||
};
|
||||
|
||||
static int __init adc_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = platform_driver_register(&rk28_adc_driver);
|
||||
if (ret)
|
||||
printk(KERN_ERR "%s: failed to add adc driver\n", __func__);
|
||||
printk("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
module_init(adc_init);
|
||||
MODULE_DESCRIPTION("rk28xx adc driver");
|
||||
MODULE_AUTHOR("luowei lw@rock-chips.com");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
57
arch/arm/mach-rk2818/include/mach/adc.h
Normal file
57
arch/arm/mach-rk2818/include/mach/adc.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* arch/arm/mach-rk28418/include/mach/adc.h
|
||||
*
|
||||
* Copyright (c) 2010 luowei <lw@rock-chips.com>
|
||||
*
|
||||
* This program is free software; yosu 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
|
||||
|
||||
#define RK28_ADCREG(x) (x)
|
||||
#define RK28_ADCDAT RK28_ADCREG(0x00)
|
||||
#define RK28_ADCSTAS RK28_ADCREG(0x04)
|
||||
#define RK28_ADCCON RK28_ADCREG(0x08)
|
||||
|
||||
//ADC_DATA
|
||||
#define RK28_ADC_DATA_MASK (0x3ff)
|
||||
|
||||
//ADC_STAS
|
||||
#define RK28_ADC_STAS_STOP (0)
|
||||
|
||||
//ADC_CTRL
|
||||
#define RK28_ADC_INT_END (1<<6)
|
||||
#define RK28_ADC_INT_CLEAR (~(1<<6))
|
||||
#define RK28_ADC_INT_ENABLE (1<<5)
|
||||
#define RK28_ADC_INT_DISABLE (~(1<<5))
|
||||
#define RK28_ADC_CONV_START (1<<4)
|
||||
#define RK28_ADC_CONV_STOP (~(1<<4))
|
||||
#define RK28_ADC_POWER_UP (1<<3)
|
||||
#define RK28_ADC_POWER_DOWN (~(1<<3))
|
||||
#define RK28_ADC_SEL_CH(x) ((x)&0x03)
|
||||
#define RK28_ADC_MASK_CH (~(0x03))
|
||||
|
||||
struct rk28_adc_client;
|
||||
|
||||
extern volatile int gAdcValue[4]; //start adc in rk2818_adckey.c
|
||||
extern int rk28_adc_start(struct rk28_adc_client *client,
|
||||
unsigned int channel, unsigned int nr_samples);
|
||||
|
||||
extern int rk28_adc_read(struct rk28_adc_client *client, unsigned int ch);
|
||||
|
||||
extern struct rk28_adc_client *
|
||||
rk28_adc_register(struct platform_device *pdev,
|
||||
void (*select)(struct rk28_adc_client *client,
|
||||
unsigned selected),
|
||||
void (*conv)(struct rk28_adc_client *client,
|
||||
unsigned d0, unsigned d1,
|
||||
unsigned *samples_left),
|
||||
unsigned int is_ts);
|
||||
|
||||
extern void rk28_adc_release(struct rk28_adc_client *client);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include <asm/mach/arch.h>
|
||||
#include <asm/mach/map.h>
|
||||
|
||||
#include <mach/rk2818_adc.h>
|
||||
#include <mach/adc.h>
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
#define DBG(x...) printk(x)
|
||||
#else
|
||||
#define DBG(x...)
|
||||
@@ -41,17 +41,25 @@
|
||||
#define AD2KEY5 KEY_0
|
||||
#define AD2KEY6 KEY_W
|
||||
|
||||
#define KEYMENU AD2KEY6
|
||||
#define ENDCALL 62
|
||||
|
||||
#define Valuedrift 50
|
||||
#define ADEmpty 1000
|
||||
#define ADKEYNum 6
|
||||
#define ADInvalid 20
|
||||
#define ADKEYNUM 6
|
||||
|
||||
#define ADKEYCH 1 //ADͨ<44><CDA8>
|
||||
|
||||
#define KEY_PHYS_NAME "rk2818 adc key"
|
||||
#define KEY_PHYS_NAME "rk2818_adckey/input0"
|
||||
|
||||
volatile int ADSampleTimes = 0;
|
||||
volatile int ADC_Chanel = 0;
|
||||
volatile int ADC_Value[4]={ADEmpty+1, ADEmpty+1, ADEmpty+1, ADEmpty+1}; //0->ch0 1->ch1 2->ch2 3->ch3
|
||||
volatile int gADSampleTimes = 0;
|
||||
volatile int gAdcChanel = 0;
|
||||
volatile int gAdcValue[4]={0, 0, 0, 0}; //0->ch0 1->ch1 2->ch2 3->ch3
|
||||
|
||||
volatile unsigned int gCodeCount = 0;
|
||||
volatile unsigned int gThisCode = 0;
|
||||
volatile unsigned int gLastCode = 0;
|
||||
|
||||
//ADC Registers
|
||||
typedef struct tagADC_keyst
|
||||
@@ -61,7 +69,7 @@ typedef struct tagADC_keyst
|
||||
}ADC_keyst,*pADC_keyst;
|
||||
|
||||
// adc ---> key
|
||||
static ADC_keyst advaluetab[] =
|
||||
static ADC_keyst gAdcValueTab[] =
|
||||
{
|
||||
{95, AD2KEY1},
|
||||
{249, AD2KEY2},
|
||||
@@ -73,7 +81,7 @@ static ADC_keyst advaluetab[] =
|
||||
};
|
||||
|
||||
//key code tab
|
||||
static unsigned char initkey_code[6] =
|
||||
static unsigned char gInitKeyCode[ADKEYNUM] =
|
||||
{
|
||||
AD2KEY1,AD2KEY2,AD2KEY3,AD2KEY4,AD2KEY5,AD2KEY6
|
||||
};
|
||||
@@ -85,13 +93,12 @@ struct rk28_adckey
|
||||
struct rk28_adc_client *client;
|
||||
struct input_dev *input_dev;
|
||||
struct timer_list timer;
|
||||
unsigned char keycodes[6];
|
||||
|
||||
unsigned char keycodes[ADKEYNUM];
|
||||
struct clk *clk;
|
||||
void __iomem *mmio_base;
|
||||
};
|
||||
|
||||
struct rk28_adckey *prk28_adckey;
|
||||
struct rk28_adckey *pRk28AdcKey;
|
||||
|
||||
unsigned int rk28_get_keycode(unsigned int advalue,pADC_keyst ptab)
|
||||
{
|
||||
@@ -156,11 +163,11 @@ static int rk28_read_adc(struct rk28_adckey *adckey)
|
||||
ret = down_interruptible(&adckey->lock);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if(ADC_Chanel > 3)
|
||||
ADC_Chanel = 0;
|
||||
ADC_Value[ADC_Chanel] = rk28_adc_read(adckey->client, ADC_Chanel);
|
||||
DBG("Enter::%s,LINE=%d,ADC_Value[%d]=%d\n",__FUNCTION__,__LINE__,ADC_Chanel,ADC_Value[ADC_Chanel]);
|
||||
ADC_Chanel++;
|
||||
if(gAdcChanel > 3)
|
||||
gAdcChanel = 0;
|
||||
gAdcValue[gAdcChanel] = rk28_adc_read(adckey->client, gAdcChanel);
|
||||
//DBG("Enter::%s,LINE=%d,gAdcValue[%d]=%d\n",__FUNCTION__,__LINE__,gAdcChanel,gAdcValue[gAdcChanel]);
|
||||
gAdcChanel++;
|
||||
up(&adckey->lock);
|
||||
return ret;
|
||||
}
|
||||
@@ -169,58 +176,74 @@ static void rk28_adkeyscan_timer(unsigned long data)
|
||||
{
|
||||
unsigned int adcvalue = -1, code;
|
||||
|
||||
prk28_adckey->timer.expires = jiffies+2;
|
||||
add_timer(&prk28_adckey->timer);
|
||||
#if 1
|
||||
if (ADSampleTimes < 2)
|
||||
pRk28AdcKey->timer.expires = jiffies + msecs_to_jiffies(10);
|
||||
add_timer(&pRk28AdcKey->timer);
|
||||
|
||||
if (gADSampleTimes < 4)
|
||||
{
|
||||
ADSampleTimes ++;
|
||||
gADSampleTimes ++;
|
||||
return;
|
||||
}
|
||||
|
||||
ADSampleTimes = 0;
|
||||
#endif
|
||||
gADSampleTimes = 0;
|
||||
|
||||
rk28_read_adc(prk28_adckey);
|
||||
adcvalue = ADC_Value[ADKEYCH];
|
||||
if(adcvalue > ADEmpty)
|
||||
return;
|
||||
printk("adcvalue=0x%x\n",adcvalue);
|
||||
rk28_read_adc(pRk28AdcKey);
|
||||
adcvalue = gAdcValue[ADKEYCH];
|
||||
if((adcvalue > ADEmpty) || (adcvalue < ADInvalid))
|
||||
{
|
||||
if(gLastCode == 0)
|
||||
return;
|
||||
else
|
||||
{
|
||||
if(gLastCode == KEYMENU)
|
||||
{
|
||||
if(gCodeCount > 31)
|
||||
{
|
||||
input_report_key(pRk28AdcKey->input_dev,ENDCALL,0);
|
||||
input_sync(pRk28AdcKey->input_dev);
|
||||
DBG("Enter::%s,LINE=%d,code=%d,ENDCALL,0\n",__FUNCTION__,__LINE__,gLastCode);
|
||||
}
|
||||
input_report_key(pRk28AdcKey->input_dev,gLastCode,1);
|
||||
input_sync(pRk28AdcKey->input_dev);
|
||||
DBG("Enter::%s,LINE=%d,code=%d,1\n",__FUNCTION__,__LINE__,gLastCode);
|
||||
}
|
||||
|
||||
input_report_key(pRk28AdcKey->input_dev,gLastCode,0);
|
||||
input_sync(pRk28AdcKey->input_dev);
|
||||
DBG("Enter::%s,LINE=%d,code=%d,0\n",__FUNCTION__,__LINE__,gLastCode);
|
||||
gLastCode = 0;
|
||||
gCodeCount = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
code=rk28_get_keycode(adcvalue,advaluetab);
|
||||
DBG("adcvalue=0x%x\n",adcvalue);
|
||||
|
||||
code=rk28_get_keycode(adcvalue,gAdcValueTab);
|
||||
if(code)
|
||||
{
|
||||
switch(code)
|
||||
if(code == KEYMENU)
|
||||
{
|
||||
case AD2KEY1:
|
||||
printk("KEY1\n");
|
||||
break;
|
||||
case AD2KEY2:
|
||||
printk("KEY2\n");
|
||||
break;
|
||||
case AD2KEY3:
|
||||
printk("KEY3\n");
|
||||
break;
|
||||
case AD2KEY4:
|
||||
printk("KEY4\n");
|
||||
break;
|
||||
case AD2KEY5:
|
||||
printk("KEY5\n");
|
||||
break;
|
||||
case AD2KEY6:
|
||||
printk("KEY6\n");
|
||||
break;
|
||||
default:
|
||||
printk("unknow\n");
|
||||
break;
|
||||
gLastCode = code;
|
||||
if(++gCodeCount == 31)//40ms * 30 =1.2s
|
||||
{
|
||||
input_report_key(pRk28AdcKey->input_dev,ENDCALL,1);
|
||||
input_sync(pRk28AdcKey->input_dev);
|
||||
DBG("Enter::%s,LINE=%d,code=%d,ENDCALL,1\n",__FUNCTION__,__LINE__,code);
|
||||
}
|
||||
}
|
||||
input_report_key(prk28_adckey->input_dev,code,1);
|
||||
input_sync(prk28_adckey->input_dev);
|
||||
input_report_key(prk28_adckey->input_dev,code,0);
|
||||
input_sync(prk28_adckey->input_dev);
|
||||
return;
|
||||
else
|
||||
{
|
||||
gLastCode = code;
|
||||
if(++gCodeCount == 2)//only one event once one touch
|
||||
{
|
||||
input_report_key(pRk28AdcKey->input_dev,code,1);
|
||||
input_sync(pRk28AdcKey->input_dev);
|
||||
DBG("Enter::%s,LINE=%d,code=%d,1\n",__FUNCTION__,__LINE__,code);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -237,7 +260,7 @@ static int __devinit rk28_adckey_probe(struct platform_device *pdev)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(adckey->keycodes, initkey_code, sizeof(adckey->keycodes));
|
||||
memcpy(adckey->keycodes, gInitKeyCode, sizeof(adckey->keycodes));
|
||||
|
||||
/* Create and register the input driver. */
|
||||
input_dev = input_allocate_device();
|
||||
@@ -259,9 +282,9 @@ static int __devinit rk28_adckey_probe(struct platform_device *pdev)
|
||||
|
||||
input_dev->keycode = adckey->keycodes;
|
||||
input_dev->keycodesize = sizeof(unsigned char);
|
||||
input_dev->keycodemax = ARRAY_SIZE(initkey_code);
|
||||
for (i = 0; i < ARRAY_SIZE(initkey_code); i++)
|
||||
set_bit(initkey_code[i], input_dev->keybit);
|
||||
input_dev->keycodemax = ARRAY_SIZE(gInitKeyCode);
|
||||
for (i = 0; i < ARRAY_SIZE(gInitKeyCode); i++)
|
||||
set_bit(gInitKeyCode[i], input_dev->keybit);
|
||||
clear_bit(0, input_dev->keybit);
|
||||
|
||||
adckey->input_dev = input_dev;
|
||||
@@ -282,7 +305,7 @@ static int __devinit rk28_adckey_probe(struct platform_device *pdev)
|
||||
goto failed_free;
|
||||
}
|
||||
|
||||
prk28_adckey = adckey;
|
||||
pRk28AdcKey = adckey;
|
||||
|
||||
/* Register the input device */
|
||||
error = input_register_device(input_dev);
|
||||
@@ -292,10 +315,9 @@ static int __devinit rk28_adckey_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
setup_timer(&adckey->timer, rk28_adkeyscan_timer, (unsigned long)adckey);
|
||||
//mod_timer(&adckey->timer, 100);
|
||||
adckey->timer.expires = jiffies+30;
|
||||
adckey->timer.expires = jiffies+50;
|
||||
add_timer(&adckey->timer);
|
||||
printk("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);
|
||||
DBG("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);
|
||||
return 0;
|
||||
|
||||
failed_free_dev:
|
||||
@@ -334,7 +356,7 @@ static struct platform_driver rk28_adckey_driver =
|
||||
|
||||
int __init rk28_adckey_init(void)
|
||||
{
|
||||
printk("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);
|
||||
DBG("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);
|
||||
return platform_driver_register(&rk28_adckey_driver);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user