s5pc210: universal: support ADC read
authorDonggeun Kim <dg77.kim@samsung.com>
Fri, 20 Aug 2010 10:05:01 +0000 (19:05 +0900)
committerDonggeun Kim <dg77.kim@samsung.com>
Fri, 20 Aug 2010 10:05:01 +0000 (19:05 +0900)
Signed-off-by: Donggeun Kim <dg77.kim@samsung.com>
arch/arm/include/asm/arch-s5pc2xx/adc.h [new file with mode: 0644]
arch/arm/include/asm/arch-s5pc2xx/cpu.h
board/samsung/universal_c210/universal.c

diff --git a/arch/arm/include/asm/arch-s5pc2xx/adc.h b/arch/arm/include/asm/arch-s5pc2xx/adc.h
new file mode 100644 (file)
index 0000000..0a4642b
--- /dev/null
@@ -0,0 +1,40 @@
+/*                                      
+ * (C) Copyright 2009                   
+ * Samsung Electronics, <www.samsung.com/sec>
+ * MyungJoo Ham <myungjoo.ham@samsung.com>
+ *              
+ * 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
+ *                      
+ */
+
+#ifndef __ASM_ARM_ARCH_ADC_H_
+#define __ASM_ARM_ARCH_ADC_H_
+
+#ifndef __ASSEMBLY__
+struct s5pc210_adc {
+       unsigned int adccon; /* starts at 0x13910000 */
+       unsigned int adctsc;
+       unsigned int adcdly;
+       unsigned int adcdat0;
+       unsigned int adcdat1; /* 0x13910010 */
+       unsigned int adcupdn;
+       unsigned int adcclrint;
+       unsigned int adcmux;
+       unsigned int adcclrintpndnup;
+};
+#endif
+
+#endif /* __ASM_ARM_ARCH_ADC_H_ */
index a76b626..4a27071 100644 (file)
@@ -40,6 +40,7 @@
 #define S5PC210_SROMC_BASE     0x12570000
 #define S5PC210_USBPHY_BASE    0x125B0000
 #define S5PC210_UART_BASE      0x13800000
+#define S5PC210_ADC_BASE       0x13910000
 #define S5PC210_PWMTIMER_BASE  0x139D0000
 
 #ifndef __ASSEMBLY__
index 6572112..ee0e2f2 100644 (file)
@@ -25,6 +25,7 @@
 #include <common.h>
 #include <i2c.h>
 #include <asm/arch/gpio.h>
+#include <asm/arch/adc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -328,6 +329,38 @@ static void init_pmic_max8952(void)
        /* RAMP: As Fast As Possible: Default: Do Nothing */
 }
 
+static unsigned short get_adc_value(int channel)
+{
+       struct s5pc210_adc *adc = (struct s5pc210_adc *) S5PC210_ADC_BASE;
+       unsigned short ret = 0;
+       unsigned int reg;
+       int ldonum = 4;
+       char buf[64];
+       unsigned int loop = 0;
+
+       sprintf(buf, "pmic ldo %d on", ldonum);
+       run_command(buf, 0);
+
+       writel(channel & 0xF, &adc->adcmux);
+       writel((1 << 14) | (49 << 6), &adc->adccon);
+       writel(1000 & 0xffff, &adc->adcdly);
+       writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
+       udelay(10);
+       writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
+       udelay(10);
+
+       do {
+               udelay(1);
+               reg = readl(&adc->adccon);
+       } while (!(reg & (1 << 15)) && (loop++ < 1000));
+
+       ret = readl(&adc->adcdat0) & 0xFFF;
+       sprintf(buf, "pmic ldo %d off", ldonum);
+       run_command(buf, 0);
+
+       return ret;
+}
+
 #ifdef CONFIG_MISC_INIT_R
 int misc_init_r(void)
 {
@@ -545,3 +578,4 @@ U_BOOT_CMD(
        "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
 );
 #endif
+