123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831 |
- /*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Copyright (c) 2004 Arnaud Patard <arnaud.patard@rtp-net.org>
- * iPAQ H1940 touchscreen support
- *
- * ChangeLog
- *
- * 2004-09-05: Herbert Pötzl <herbert@13thfloor.at>
- * - added clock (de-)allocation code
- *
- * 2005-03-06: Arnaud Patard <arnaud.patard@rtp-net.org>
- * - h1940_ -> s3c24xx (this driver is now also used on the n30
- * machines :P)
- * - Debug messages are now enabled with the config option
- * TOUCHSCREEN_S3C_DEBUG
- * - Changed the way the value are read
- * - Input subsystem should now work
- * - Use ioremap and readl/writel
- *
- * 2005-03-23: Arnaud Patard <arnaud.patard@rtp-net.org>
- * - Make use of some undocumented features of the touchscreen
- * controller
- *
- */
- #include <linux/errno.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/input.h>
- #include <linux/init.h>
- #include <linux/serio.h>
- #include <linux/delay.h>
- #include <linux/platform_device.h>
- #include <linux/miscdevice.h>
- #include <linux/clk.h>
- #include <linux/mutex.h>
- #include <asm/io.h>
- #include <asm/irq.h>
- #include <asm/hardware.h>
- #include <asm/uaccess.h>
- #include <asm/arch/regs-adc.h>
- #include <asm/arch/irqs.h>
- #include <asm/arch/regs-s3c2416-clock.h>
- #include <asm/arch/regs-gpio.h>
- //#define USE_12BITS_ADC
- //#define USE_10BITS_ADC
- #define LEVEL0_MIN 2980 /*0%~25%*/
- #define LEVEL0_MAX 3581
- #define LEVEL1_MIN 3582 /*25%~50%*/ /*3.67V*/ /*3582*/
- #define LEVEL1_MAX 3666
- #define LEVEL2_MIN 3667 /*50%~75%*/ /*3.78V*/ /*3692*/ /*-25*/
- #define LEVEL2_MAX 3778
- #define LEVEL3_MIN 3779 /*75%~99%*/ /*3.92V*/ /*3829*/ /*-50*/
- #define LEVEL3_MAX 4004
- #define BATTERY_FULL 4005 /*100%*/ /*4.1V*/ /*4005*/
- #define ADC_sample_count 100 //25 /*joey modify ADC read method to catch top 5 low value 2009/12/21*/
- #define ADC_jig_voltage 3700 /*joey for ENV ADC to voltage 2010/01/15*/
- #define ADC_READ_LEVEL_VAULE _IOR('S', 0x01, unsigned long)
- #define ADC_READ_INPUT_SOURCE_STATUS _IOR('S', 0x02, unsigned long)
- #define ADC_SET_PM_WKUP_SOURCE _IOW('S', 0x03, unsigned long)
- #define ADC_READ_RAW_VAULE _IOR('S', 0x04, unsigned long)
- #define ADC_POWER_OFF _IO ('S', 0x05)
- #define ADC_READ_INPUT_POWER_STATUS _IOR('S', 0x06, unsigned long)
- #define ADC_READ_CHARGING_STATUS _IOR('S', 0x07, unsigned long)
- #define ADC_SET_PM_FUNCTION_POWER _IOW('S', 0x08, unsigned long)
- #ifdef CONFIG_PM_CPU_MODE
- #define ADC_SET_CPU_PM_MODE _IOW('S', 0x09, unsigned long)
- #endif
- #define ADC_READ_WAKEUP_SOURCE _IOR('S', 0x0A, unsigned long)
- #define ADC_READ_POWER_FAIL_STATUS _IOR('S', 0x0B, unsigned long)
- #define ADC_READ_LEVEL_VAULE_TOOL _IOR('S', 0x10, unsigned long) /*qisda joey add for tool read 20091207*/
- #define ADC_READ_RAW_VAULE_TOOL _IOR('S', 0x11, unsigned long) /*qisda joey add for tool read 20091207*/
- #define HIGH_LOW_PULSE _IOR('S', 0x12, unsigned long)
- #define ADC_READ_ENV _IOR('S', 0x13, unsigned long) /*joey for ENV ADC read/write 2010/01/13*/
- #define ADC_GET_ENV _IOR('S', 0x14, unsigned long) /*joey for ENV ADC read/write 2010/01/13*/
- #define ADC_READ_VOLTAGE _IOR('S', 0x15, unsigned long) /*joey for ENV ADC to voltage 2010/01/15*/
- /* 2010/1/21, weichen, for handling events during suspend */
- #if defined (CONFIG_PM_PLATFORM_POWER_SAVING)
- #define ADC_CLEAR_WAKEUP_EVENT _IOW('S', 0x20, unsigned long)
- #endif
- //#define ADC_INPUT_PIN _IOW('S', 0x0c, unsigned long)
- /*Qisda Qube 20091103 for Smart card power control*/
- #define ADC_SMARTCARD_PWR _IOR('S', 0x8F, unsigned long)
- /*Qisda Qube 20091103 for Smart card power control*/
- #define NON_ZERO_VALUE 0xFF
- #define INPUT_SOURCE_USB 0
- #define INPUT_SOURCE_CHARGER 1
- #define INPUT_SOURCE_NOTHING 2
- unsigned int wkup_srce = NON_ZERO_VALUE;
- #ifdef CONFIG_PM_CPU_MODE
- unsigned char pm_cpu_mode = 0;
- #endif
- /* 2010/1/21, weichen, for handling events during suspend */
- #if defined (CONFIG_PM_PLATFORM_POWER_SAVING)
- unsigned int g_wakeup_event_occurs = 0;
- #endif
- #define ADC_PM_DEBUG_PORT (0x00000003)
- #define ADC_PM_WIFI (0x0000000C)
- #define ADC_PM_AUDIO (0x00000030)
- #define ADC_PM_SD (0x000000C0)
- #define ADC_PM_TCON (0x00000300)
- #define ADC_PM_USB (0x00000C00)
- #define ADC_PM_TOUCH (0x0000F000)
- #define ADC_PM_SMART_CARD (0x00030000)
- #define ADC_PM_3G_MODULE (0x000C0000)
- #define ADC_PM_I2C (0x00300000)
- extern int IsWallCharger(void);
- /* Qisda, ShiYong Lin, 2009/10/27, Modify for exception in IsWallCharger function {*/
- extern int charging_source;
- /* } Qisda, ShiYong Lin, 2009/10/27, Modify for exception in IsWallCharger function */
- // Qisda, 2010/02/18, TN Wei, sleep mode wakes up for usb event {
- //extern int sleeping_cha_event;
- // Qisda, 2010/02/18, TN Wei, sleep mode wakes up for usb event }
- #define ADC_MINOR 131
- #if defined(CONFIG_CPU_S3C2443)
- #define ADC_ENV(x) (S3C2410_ADCCON_PRSCVL(49))
- #else
- #define ADC_ENV(x) (S3C2410_ADCCON_PRSCVL(49) | S3C2410_ADCCON_SELMUX(x))
- #endif
- struct s3c_adc_mach_info {
- int delay;
- int presc;
- int resol_bit;
- };
- /* ADC default configuration */
- struct s3c_adc_mach_info s3c_adc_cfg __initdata = {
- .delay = 10000,
- .presc = 49,
- //#if defined(CONFIG_CPU_S3C2450) || defined(CONFIG_CPU_S3C2416) || defined(CONFIG_CPU_S3C6410)
- //.resol_bit = 12,
- //#else
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status {*/
- .resol_bit = 12,
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status }*/
- //#endif
- };
- int average_adc_value_keep1 = 9999; /*joey add to keep ADC will always return lower one 2009/12/28*/
- int average_adc_value_keep2 = 9999; /*joey add to keep ADC will always return lower one 2009/12/28*/
- static struct clk *adc_clock;
- static void __iomem *base_addr;
- static DEFINE_MUTEX(adc_mutex);
- static unsigned long data_for_ADCCON;
- static unsigned long data_for_ADCTSC;
- static int adc_port = 0;
- static unsigned long env_adc_value; /*joey for ENV ADC to voltage 2010/01/15*/
- static void s3c_adc_save_SFR_on_ADC(void) {
-
- data_for_ADCCON = readl(base_addr+S3C2410_ADCCON);
- data_for_ADCTSC = readl(base_addr+S3C2410_ADCTSC);
- }
- static void s3c_adc_restore_SFR_on_ADC(void) {
-
- writel(data_for_ADCCON, base_addr+S3C2410_ADCCON);
- writel(data_for_ADCTSC, base_addr+S3C2410_ADCTSC);
- }
- static int s3c_adc_open(struct inode *inode, struct file *file)
- {
- return 0;
- }
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status {*/
- #ifdef USE_10BITS_ADC
- static ssize_t
- s3c_adc_read(struct file *file, char __user * buffer,
- size_t size, loff_t * pos)
- {
- unsigned long data0;
- unsigned long data1;
- int adc_value = 0;
- // printk(KERN_INFO " s3c_adc_read() entered\n");
-
- mutex_lock(&adc_mutex);
- s3c_adc_save_SFR_on_ADC();
-
- writel(0x0, base_addr+S3C2410_ADCCON);
- writel(0x58, base_addr+S3C2410_ADCTSC);
-
- udelay(10);
- writel(ADC_ENV(adc_port)|S3C2410_ADCCON_STDBM, base_addr+S3C2410_ADCCON);
-
- #if defined(CONFIG_CPU_S3C2443)
- writel(S3C2410_ADCCON_SELMUX(adc_port), base_addr+S3C2410_ADCMUX);
- #endif
- udelay(10);
- writel(S3C2410_ADCCON_PRSCEN|ADC_ENV(adc_port)|S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
-
- do{
- data0 = readl(base_addr+S3C2410_ADCCON);
- }
- while(!(data0 & S3C2410_ADCCON_ECFLG));
-
- data1 = readl(base_addr+S3C2410_ADCDAT0);
-
- adc_value = data1 & S3C2410_ADCDAT0_XPDATA_MASK;
-
- s3c_adc_restore_SFR_on_ADC();
- mutex_unlock(&adc_mutex);
- // printk(KERN_INFO " Converted Value: %03d\n", adc_value);
- if (copy_to_user(buffer, &adc_value, sizeof(unsigned int))) {
- return -EFAULT;
- }
- return sizeof(unsigned int);
- }
- #else
- unsigned long
- s3c_adc_read(void)
- {
- unsigned long data0;
- unsigned long data1;
- int adc_value = 0;
- // printk("s3c_adc_read entered\n");
-
- mutex_lock(&adc_mutex);
- s3c_adc_save_SFR_on_ADC();
-
- writel(0x0, base_addr+S3C2410_ADCCON);
- writel(0x58, base_addr+S3C2410_ADCTSC);
-
- udelay(10);
- writel(ADC_ENV(adc_port)|S3C2410_ADCCON_STDBM, base_addr+S3C2410_ADCCON);
- #if defined(CONFIG_CPU_S3C2443)
- writel(S3C2410_ADCCON_SELMUX(adc_port), base_addr+S3C2410_ADCMUX);
- #else
- writel(0, base_addr+0x18);
- #endif
- udelay(10);
- writel(S3C2410_ADCCON_PRSCEN|ADC_ENV(adc_port)|S3C2410_ADCCON_ENABLE_START|S3C2450_ADCCON_RESSEL_12BIT, base_addr+S3C2410_ADCCON);
- do{
- data0 = readl(base_addr+S3C2410_ADCCON);
- }
- while(!(data0 & S3C2410_ADCCON_ECFLG));
-
- data1 = readl(base_addr+S3C2410_ADCDAT0);
- adc_value = data1 & S3C_ADCDAT1_YPDATA_MASK_12BIT;
- s3c_adc_restore_SFR_on_ADC();
- mutex_unlock(&adc_mutex);
- // printk("Converted Value: %05d\n", adc_value);
- return adc_value;
- }
- #endif
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status }*/
- void bubblesort(int *data, int n) /*joey modify ADC read method to catch top 5 low value 2009/12/21*/
- {
- int i, j, temp;
- for (i = n - 1; i > 0; i--)
- {
- for (j = 0; j <= i - 1; j++)
- {
- if (data[j] > data[j + 1])
- {
- temp = data[j];
- data[j] = data[j + 1];
- data[j + 1] = temp;
- }
- }
- }
- }
- static int s3c_adc_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
- {
- int i = 0;
- int average_adc_value = 0;
- int env_adc_voltage; /*joey for ENV ADC to voltage 2010/01/15*/
- #ifdef CONFIG_PM_PLATFORM_POWER_SAVING
- unsigned long data_mask = 0; /* BenQ, weichen, 2009/12/22, check the wakeup source of 2416 for MMI */
- #else
- int data_mask = 0;
- #endif
- unsigned int ret = -ENOIOCTLCMD;
- unsigned long level = NON_ZERO_VALUE;
- unsigned long input_source = NON_ZERO_VALUE;
- int ADC_raw_data[ADC_sample_count]; /*joey modify ADC read method to catch top 5 low value 2009/12/21*/
- #ifdef CONFIG_PM_PLATFORM_POWER_SAVING
- /* BenQ, weichen, 2009/12/22, check the wakeup source of 2416 for MMI */
- void __user *uarg = (void __user *) arg;
- #endif
-
- switch (cmd) {
- /*Qisda Qube 20091103 for Smart card power control*/
- case ADC_SMARTCARD_PWR:
- if(arg==0)
- {
- printk("Enable smard card power\n");
- s3c2410_gpio_cfgpin(S3C2410_GPC3, S3C2410_GPC3_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPC3,1);
- s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPH2_TXD0);
- s3c2410_gpio_cfgpin(S3C2410_GPH3, S3C2410_GPH3_RXD0);
- }
- else if(arg==3)
- {
- printk("Disable smard card power\n");
- s3c2410_gpio_cfgpin(S3C2410_GPC3, S3C2410_GPC3_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPC3,0);
- s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPH2_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPH2,0);
- s3c2410_gpio_cfgpin(S3C2410_GPH3, S3C2410_GPH3_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPH3,0);
- }
- return 0;
- /*Qisda Qube 20091103 for Smart card power control*/
- /*
- case ADC_INPUT_PIN:
- adc_port = (unsigned int) arg;
- if (adc_port >= 4)
- printk(" %d is already reserved for TouchScreen\n", adc_port);
- return 0;
- */
- case ADC_READ_INPUT_SOURCE_STATUS:
- //Read the level data from GPG1
- //CHG_STA: 0 => no andy insertion source
- // 1 => There is an insertion existing in GPG
- /* Qisda, ShiYong Lin, 2009/10/27, Modify for exception in IsWallCharger function {*/
- input_source = charging_source;
- put_user(input_source, (unsigned long __user *)arg);
- ret = 0;
- /* } Qisda, ShiYong Lin, 2009/10/27, Modify for exception in IsWallCharger function */
- break;
- case ADC_SET_PM_WKUP_SOURCE:
- wkup_srce = (unsigned long) arg;
- printk("Wakeup parameter = %d\n", wkup_srce);
- /* Qisda, ShiYong Lin, 2009/09/28, Add the sleep event message when sleep {*/
- //s3c_keypad_pm_sleep_message_to_ap(1);
- /* } Qisda, ShiYong Lin, 2009/09/28, Add the sleep event message when sleep */
- ret = 0;
- break;
- case ADC_READ_LEVEL_VAULE:
- for(i=0; i<ADC_sample_count ;i++)
- {
- //udelay(1000);
- msleep(1); /*joey modify for asus request 2009/12/18*/
- average_adc_value += s3c_adc_read(); /*old*/
- ////ADC_raw_data[i] = s3c_adc_read(); /*joey modify ADC read method to catch top 5 low value 2009/12/21*/ /*new*/
- }
- average_adc_value = average_adc_value/ADC_sample_count; /*old*/
-
- //for(i=0; i<ADC_sample_count ;i++)
- // printk("Before ADC data = %d\n", (int)ADC_raw_data[i]);
- ////bubblesort(ADC_raw_data, ADC_sample_count); /*new*/
- //for(i=0; i<ADC_sample_count ;i++)
- // printk("After ADC data = %d\n", (int)ADC_raw_data[i]);
- ////average_adc_value = (ADC_raw_data[1]+ADC_raw_data[2]+ADC_raw_data[3]+ADC_raw_data[4]+ADC_raw_data[5])/5; /*new*/
-
- // if((readl(S3C2410_GPGDAT)&(1<<1)) == 0) /*no usb charger */
- // {
- // if(average_adc_value > average_adc_value_keep1) /*joey add to keep ADC will always return lower one 2009/12/28*/
- // average_adc_value = average_adc_value_keep1;
- // }
-
- if (average_adc_value <= LEVEL0_MAX)
- {
- level = 0;
- }
- else if (average_adc_value <= LEVEL1_MAX && average_adc_value >= LEVEL1_MIN)
- {
- level = 1;
- }
- else if (average_adc_value <= LEVEL2_MAX && average_adc_value >= LEVEL2_MIN)
- {
- level = 2;
- }
- else if(average_adc_value <= LEVEL3_MAX && average_adc_value >= LEVEL3_MIN)
- {
- level = 3;
- }
- else if(average_adc_value >= BATTERY_FULL)
- {
- level = 4;
- }
- // printk("level = %d, ADC data = %d\n", (int)level, (int)average_adc_value);
- put_user(level, (unsigned long __user *)arg);
-
- // if((readl(S3C2410_GPGDAT)&(1<<1)) == 0) /*no usb charger */
- // average_adc_value_keep1 = average_adc_value; /*joey add to keep ADC will always return lower one 2009/12/28*/
-
- ret = 0;
- break;
- case ADC_READ_RAW_VAULE:
- for(i=0; i<ADC_sample_count ;i++)
- {
- //udelay(1000);
- msleep(1); /*joey modify for asus request 2009/12/18*/
- average_adc_value += s3c_adc_read();/*old*/
- ////ADC_raw_data[i] = s3c_adc_read(); /*joey modify ADC read method to catch top 5 low value 2009/12/21*/ /*new*/
- }
- average_adc_value = average_adc_value / ADC_sample_count; /*old*/
- //for(i=0; i<ADC_sample_count ;i++)
- // printk("Before ADC data = %d\n", (int)ADC_raw_data[i]);
- ////bubblesort(ADC_raw_data, ADC_sample_count); /*new*/
- //for(i=0; i<ADC_sample_count ;i++)
- // printk("After ADC data = %d\n", (int)ADC_raw_data[i]);
- ////average_adc_value = (ADC_raw_data[1]+ADC_raw_data[2]+ADC_raw_data[3]+ADC_raw_data[4]+ADC_raw_data[5])/5; /*new*/
- // if((readl(S3C2410_GPGDAT)&(1<<1)) == 0) /*no usb charger */
- // {
- // if(average_adc_value > average_adc_value_keep2) /*joey add to keep ADC will always return lower one 2009/12/28*/
- // average_adc_value = average_adc_value_keep2;
- // }
- printk("ADC data = %d\n", (int)average_adc_value);
- put_user(average_adc_value, (unsigned long __user *)arg);
- // if((readl(S3C2410_GPGDAT)&(1<<1)) == 0) /*no usb charger */
- // average_adc_value_keep2 = average_adc_value; /*joey add to keep ADC will always return lower one 2009/12/28*/
- ret = 0;
- break;
- case ADC_READ_LEVEL_VAULE_TOOL: /*qisda joey add for tool read 20091207*/
- for(i=0; i<1000 ;i++) /*qisda joey modify from 20 to 1000 20091202*/
- {
- udelay(1000);
- average_adc_value += s3c_adc_read();
- }
- average_adc_value = average_adc_value/1000; /*qisda joey modify from 20 to 1000 20091202*/
- if (average_adc_value <= LEVEL0_MAX)
- {
- level = 0;
- }
- else if (average_adc_value <= LEVEL1_MAX && average_adc_value >= LEVEL1_MIN)
- {
- level = 1;
- }
- else if (average_adc_value <= LEVEL2_MAX && average_adc_value >= LEVEL2_MIN)
- {
- level = 2;
- }
- else if(average_adc_value <= LEVEL3_MAX && average_adc_value >= LEVEL3_MIN)
- {
- level = 3;
- }
- else if(average_adc_value >= BATTERY_FULL)
- {
- level = 4;
- }
- // printk("level = %d, ADC data = %d\n", (int)level, (int)average_adc_value);
- put_user(level, (unsigned long __user *)arg);
- ret = 0;
- break;
- case ADC_READ_RAW_VAULE_TOOL: /*qisda joey add for tool read 20091207*/
- for(i=0; i<1000 ;i++) /*qisda joey modify from 20 to 1000 20091202*/
- {
- udelay(1000);
- average_adc_value += s3c_adc_read();
- }
- average_adc_value = average_adc_value / 1000; /*qisda joey modify from 20 to 1000 20091202*/
- printk("ADC data = %d\n", (int)average_adc_value);
- put_user(average_adc_value, (unsigned long __user *)arg);
- ret = 0;
- break;
- case ADC_POWER_OFF:
- printk("power off\n");
- //writeb(0x0, 0xc8a30029); /*joey shut down SD bus power before p_keep pull low 2010/01/06*/
- s3c_moviNAND_power_off();
- msleep(100);
- #ifdef CONFIG_QISDA_BK060B00
- s3c2410_gpio_cfgpin(S3C2410_GPD14, S3C2410_GPD14_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPD14, 0);
- #else
- s3c2410_gpio_cfgpin(S3C2410_GPG0, S3C2410_GPG0_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPG0, 0);
- #endif
- ret = 0;
- break;
- #ifdef CONFIG_QISDA_AS090B00_EVT1
- case ADC_READ_INPUT_POWER_STATUS:
- data_mask = readl(S3C2410_GPHDAT);
- data_mask &= 0x1<<5;
- printk("GPH5 = %d\n", data_mask);
- ret = put_user(data_mask, (unsigned long __user *)arg);
- break;
- #endif
- case ADC_READ_CHARGING_STATUS:
- data_mask = readl(S3C2410_GPFDAT);
- data_mask &= 0x1<<6;
- if(data_mask) /*shiyong joey for asus 2009/12/15*/
- data_mask = 1;
- else
- data_mask = 0;
- printk("GPF6 = %d\n", data_mask);
- ret = put_user(data_mask, (unsigned long __user *)arg);
- break;
- case ADC_SET_PM_FUNCTION_POWER:
-
- break;
- #ifdef CONFIG_PM_CPU_MODE
- case ADC_SET_CPU_PM_MODE:
- // 0 ADC_CPU_DEVICE_SLEEP:
- // 1 ADC_CPU_STOP:
- // 2 ADC_CPU_DEEP_STOP:
- // 3 ADC_CPU_IDLE:
- // 4 ADC_CPU_SLEEP:
- pm_cpu_mode = (unsigned char) arg;
- // s3c2410_sleep_enter();
- printk("cpu_pm_mode parameter = %d\n", pm_cpu_mode);
- ret = 0;
- break;
- #endif
- /* BenQ, weichen, 2009/12/22, check the wakeup source of 2416 for MMI */
- case ADC_READ_WAKEUP_SOURCE:
- data_mask = readl(S3C2443_WKUPSTAT);
- printk("Wakeup source =0x%08lx\n", data_mask);
- #ifdef CONFIG_PM_PLATFORM_POWER_SAVING
- if (copy_to_user(uarg, &data_mask, sizeof(data_mask)))
- return -EFAULT;
- /* BenQ, weichen, 2010/1/28, clear the wakeup source of 2416 for MMI */
- #if defined (CONFIG_PM_PLATFORM_POWER_SAVING)
- writel(0x33, S3C2443_WKUPSTAT);
- data_mask = readl(S3C2443_WKUPSTAT);
- printk("Wakeup source2 =0x%08lx\n", data_mask);
- #endif
- #endif
- ret = 0;
- break;
- /* BenQ, weichen, 2009/12/22, check the wakeup source of 2416 for MMI */
- case ADC_READ_POWER_FAIL_STATUS:
- data_mask = readl(S3C2410_GPGDAT) & (1<<5);
- printk("ADC_READ_POWER_FAIL_STATUS GPG5 = %d\n", data_mask);
- ret = put_user(data_mask, (unsigned long __user *)arg);
- break;
-
- case HIGH_LOW_PULSE: /*joey add for high/low pulse 2010/01/08*/
- {
- unsigned long percent[3]={0, 0, 0}; /*1:high sec 2:low msec 3:times*/
- int i;
-
- copy_from_user(percent, (unsigned long) arg, sizeof(unsigned long)*3);
- printk("1st=%d, 2nd=%d, 3rd=%d\n", percent[0], percent[1], percent[2]);
- s3c2410_gpio_cfgpin(S3C2410_GPH11, S3C2410_GPH11_OUTP);
- s3c2410_gpio_pullup(S3C2410_GPH11, 2);
- for(i=0; i<percent[2]; i++)
- {
- s3c2410_gpio_setpin(S3C2410_GPH11, 0);
- printk("GPH11 pull low\n");
- msleep(percent[1]);
- s3c2410_gpio_setpin(S3C2410_GPH11, 1);
- printk("GPH11 pull high\n");
- msleep(percent[0]);
- }
- //ret = put_user(data_mask, (unsigned long __user *)arg);
- break;
- }
- case ADC_GET_ENV: /*joey for ENV ADC read/write 2010/01/13*/
- copy_from_user(&env_adc_value, (unsigned long) arg, sizeof(unsigned long));
- printk("env_adc_value=%d\n", env_adc_value);
- //ret = put_user(data_mask, (unsigned long __user *)arg);
- break;
- case ADC_READ_ENV: /*joey for ENV ADC read/write 2010/01/13*/
- ret = put_user(env_adc_value, (unsigned long __user *)arg);
- printk("env_adc_value=%d\n", env_adc_value);
- break;
- case ADC_READ_VOLTAGE: /*joey for ENV ADC to voltage 2010/01/15*/
- if(env_adc_value > 3711 || env_adc_value < 3511)
- env_adc_value = 3611;
- printk("env_adc_value=%d\n", env_adc_value);
-
- for(i=0; i<ADC_sample_count ;i++)
- {
- msleep(1); /*joey modify for asus request 2009/12/18*/
- average_adc_value += s3c_adc_read();
- }
- average_adc_value = average_adc_value / ADC_sample_count;
- printk("average_adc_value=%d\n", average_adc_value);
- if(average_adc_value >= env_adc_value)
- env_adc_voltage = ADC_jig_voltage + (average_adc_value-env_adc_value)*100/97;
- else
- env_adc_voltage = ADC_jig_voltage - (env_adc_value-average_adc_value)*100/97;
- ret = put_user(env_adc_voltage, (unsigned long __user *)arg);
- printk("env_adc_voltage=%d\n", env_adc_voltage);
- break;
- #if defined (CONFIG_PM_PLATFORM_POWER_SAVING)
- case ADC_CLEAR_WAKEUP_EVENT:
- g_wakeup_event_occurs = 0;
- // Qisda, 2010/02/18, TN Wei, sleep mode wakes up for usb event {
- //sleeping_cha_event = 0;
- // Qisda, 2010/02/18, TN Wei, sleep mode wakes up for usb event }
- printk("ADC_CLEAR_WAKEUP_EVENT: g_wakeup_event_occurs=%d\n", g_wakeup_event_occurs);
- ret = 0;
- break;
- #endif
- default:
- ret = -ENOIOCTLCMD;
- break;
- }
- return ret;
- }
- static struct file_operations s3c_adc_fops = {
- .owner = THIS_MODULE,
- .read = s3c_adc_read,
- .open = s3c_adc_open,
- .ioctl = s3c_adc_ioctl,
- };
- static struct miscdevice s3c_adc_miscdev = {
- .minor = ADC_MINOR,
- .name = "adc",
- .fops = &s3c_adc_fops,
- };
- /*
- * The functions for inserting/removing us as a module.
- */
- static int __init s3c_adc_probe(struct platform_device *pdev)
- {
- int ret;
- printk(KERN_INFO "s3c_adc_probe\n");
- adc_clock = clk_get(NULL, "adc");
- if (!adc_clock) {
- printk(KERN_ERR "failed to get adc clock source\n");
- return -ENOENT;
- }
- clk_enable(adc_clock);
- base_addr=ioremap(S3C24XX_PA_ADC, 0x20);
- if (base_addr == NULL) {
- printk(KERN_ERR "Failed to remap register block\n");
- return -ENOMEM;
- }
- if ((s3c_adc_cfg.presc&0xff) > 0)
- writel(S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(s3c_adc_cfg.presc&0xFF), base_addr+S3C2410_ADCCON);
- else
- writel(0, base_addr+S3C2410_ADCCON);
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status {*/
- #ifdef ADC_TEST //open for debug
- tmp = readl(base_addr+S3C2410_ADCCON);
- printk("tmp = %04X!\n", tmp);
- tmp = tmp | 0x0080;
- printk("tmp = %04X!\n", tmp);
- writel(tmp, base_addr+S3C2410_ADCCON);
- #endif
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status }*/
- /* Initialise registers */
- if ((s3c_adc_cfg.delay&0xffff) > 0)
- writel(s3c_adc_cfg.delay & 0xffff, base_addr+S3C2410_ADCDLY);
-
- ret = misc_register(&s3c_adc_miscdev);
- if (ret) {
- printk (KERN_ERR "cannot register miscdev on minor=%d (%d)\n",
- ADC_MINOR, ret);
- return ret;
- }
-
- printk(KERN_INFO "S3C ADC driver successfully probed !\n");
-
- return 0;
- }
- static int s3c_adc_remove(struct device *dev)
- {
- printk(KERN_INFO "s3c_adc_remove() of TS called !\n");
- return 0;
- }
- #define s3c_adc_suspend NULL
- #define s3c_adc_resume NULL
- static struct platform_driver s3c_adc_driver = {
- .probe = s3c_adc_probe,
- .remove = s3c_adc_remove,
- .suspend = s3c_adc_suspend,
- .resume = s3c_adc_resume,
- .driver = {
- .owner = THIS_MODULE,
- .name = "s3c2410-adc",
- },
- };
- static char banner[] __initdata = KERN_INFO "S3C ADC driver, (c) 2007 Samsung Electronics\n";
- int __init s3c_adc_init(void)
- {
- int ireturn = 0;
- int read_pin = -99;
- int i = 0;
- printk(banner);
- ireturn = platform_driver_register(&s3c_adc_driver);
- #ifdef CONFIG_QISDA_AS090B00_EVT1
- /* Qisda, ShiYong Lin, 2009/09/12, Indication for /PGOOD pin {*/
- s3c2410_gpio_cfgpin(S3C2410_GPH5, 0);
- s3c2410_gpio_pullup(S3C2410_GPH5, 2);
- /* Qisda, ShiYong Lin, 2009/09/12, Indication for /PGOOD pin }*/
- #endif
- /* Qisda, ShiYong Lin, 2009/10/27, Modify for exception in IsWallCharger function {*/
- /* Qisda, ShiYong Lin, 2009/09/29, Set En1 and En2 {*/
- for(i=0;i<10;++i)
- {
- read_pin = readl(S3C2410_GPGDAT) & (1<<1);
- if(read_pin != 0){
- if(IsWallCharger()==0){
- charging_source = 0;
- //EN2
- s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPB0_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPB0, 0);
- //EN1
- s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPB4_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPB4, 1);
- }
- else
- {
- charging_source = 1;
- //EN2
- s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPB0_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPB0, 1);
- //EN1
- s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPB4_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPB4, 0);
- }
- }
- else{
- charging_source = 2;
- //EN2
- s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPB0_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPB0, 0);
- //EN1
- s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPB4_OUTP);
- s3c2410_gpio_setpin(S3C2410_GPB4, 1);
- }
- }
- /*}, Qisda, ShiYong Lin, 2009/09/29, Set En1 and En2 */
- /*}, Qisda, ShiYong Lin, 2009/10/27, Modify for exception in IsWallCharger function */
- /* Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status {*/
- #ifdef ADC_TEST
- {
- int i=0;
- for(i=0; i<10 ;i++)
- {
- udelay(1000);
- s3c_adc_read();
- }
- printk("Read ADC times = %d\n",i);
- }
- #else
- s3c_adc_read();
- #endif
- /*}, Qisda, ShiYong Lin, 2009/07/18, ADC and Battery Status */
- return ireturn;
- }
- void __exit s3c_adc_exit(void)
- {
- platform_driver_unregister(&s3c_adc_driver);
- }
- module_init(s3c_adc_init);
- module_exit(s3c_adc_exit);
- MODULE_AUTHOR("alinuxguy@samsung.com>");
- MODULE_DESCRIPTION("s3c adc driver");
- MODULE_LICENSE("GPL");
|