Full support for Ginger Console
[linux-ginger.git] / arch / sh / kernel / cpu / adc.c
blobda3d6877f93d571692b2bf8fe420341323daec6f
1 /*
2 * linux/arch/sh/kernel/adc.c -- SH3 on-chip ADC support
4 * Copyright (C) 2004 Andriy Skulysh <askulysh@image.kiev.ua>
5 */
7 #include <linux/module.h>
8 #include <asm/adc.h>
9 #include <asm/io.h>
12 int adc_single(unsigned int channel)
14 int off;
15 unsigned char csr;
17 if (channel >= 8) return -1;
19 off = (channel & 0x03) << 2;
21 csr = ctrl_inb(ADCSR);
22 csr = channel | ADCSR_ADST | ADCSR_CKS;
23 ctrl_outb(csr, ADCSR);
25 do {
26 csr = ctrl_inb(ADCSR);
27 } while ((csr & ADCSR_ADF) == 0);
29 csr &= ~(ADCSR_ADF | ADCSR_ADST);
30 ctrl_outb(csr, ADCSR);
32 return (((ctrl_inb(ADDRAH + off) << 8) |
33 ctrl_inb(ADDRAL + off)) >> 6);
36 EXPORT_SYMBOL(adc_single);