adc.c 673 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * linux/arch/sh/kernel/adc.c -- SH3 on-chip ADC support
  3. *
  4. * Copyright (C) 2004 Andriy Skulysh <askulysh@image.kiev.ua>
  5. */
  6. #include <linux/module.h>
  7. #include <asm/adc.h>
  8. #include <asm/io.h>
  9. int adc_single(unsigned int channel)
  10. {
  11. int off;
  12. unsigned char csr;
  13. if (channel >= 8) return -1;
  14. off = (channel & 0x03) << 2;
  15. csr = __raw_readb(ADCSR);
  16. csr = channel | ADCSR_ADST | ADCSR_CKS;
  17. __raw_writeb(csr, ADCSR);
  18. do {
  19. csr = __raw_readb(ADCSR);
  20. } while ((csr & ADCSR_ADF) == 0);
  21. csr &= ~(ADCSR_ADF | ADCSR_ADST);
  22. __raw_writeb(csr, ADCSR);
  23. return (((__raw_readb(ADDRAH + off) << 8) |
  24. __raw_readb(ADDRAL + off)) >> 6);
  25. }
  26. EXPORT_SYMBOL(adc_single);