Advertisement
Guest User

adc

a guest
Apr 9th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. /***************************************************************************
  2. * __________ __ ___.
  3. * Open \______ \ ____ ____ | | _\_ |__ _______ ___
  4. * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
  5. * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
  6. * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
  7. * \/ \/ \/ \/ \/
  8. * $Id$
  9. *
  10. * Copyright (C) 2006 by Barry Wardell
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  18. * KIND, either express or implied.
  19. *
  20. ****************************************************************************/
  21. #include "config.h"
  22. #include "cpu.h"
  23. #include "system.h"
  24. #include "kernel.h"
  25. #include "thread.h"
  26. #include "adc.h"
  27.  
  28. #define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00))
  29. #define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04))
  30. #define ADC_CFG (*(volatile unsigned long*)(0x7000ad0C)) ///??
  31. #define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20))
  32. #define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24))
  33. #define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c))
  34.  
  35. #if defined(PBELL_VIBE500)
  36. #define ADC_UNK (*(volatile unsigned long*)(0x7000002c))
  37. #endif
  38.  
  39. static unsigned short adcdata[NUM_ADC_CHANNELS];
  40.  
  41. /* Scan ADC so that adcdata[channel] gets updated. */
  42. unsigned short adc_scan(int channel)
  43. {
  44. unsigned int adc_data_1;
  45. unsigned int adc_data_2;
  46.  
  47. if (channel >= NUM_ADC_CHANNELS)
  48. return 0;
  49.  
  50. /* Start conversion */
  51. ADC_ADDR |= 0x80000000;
  52.  
  53. /* Wait for conversion to complete */
  54. while((ADC_STATUS & (0x40<<8*channel))==0);
  55.  
  56. /* Stop conversion */
  57. ADC_ADDR &=~ 0x80000000;
  58.  
  59. /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
  60. For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
  61. 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
  62. adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff);
  63. adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3);
  64.  
  65. adcdata[channel] = (adc_data_1<<2 | adc_data_2);
  66.  
  67. #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330) ||\
  68. defined(SAMSUNG_YH820) || defined(SAMSUNG_YH920) ||\
  69. defined(SAMSUNG_YH925))
  70. /* ADC values read low if PLL is enabled */
  71. if(PLL_CONTROL & 0x80000000){
  72. adcdata[channel] += 0x14;
  73. if(adcdata[channel] > 0x400)
  74. adcdata[channel] = 0x400;
  75. }
  76. #endif
  77.  
  78. return adcdata[channel];
  79. }
  80.  
  81. /* Read 10-bit channel data */
  82. unsigned short adc_read(int channel)
  83. {
  84. return adcdata[channel];
  85. }
  86.  
  87. static int adc_counter;
  88.  
  89. static void adc_tick(void)
  90. {
  91. if(++adc_counter == HZ)
  92. {
  93. adc_counter = 0;
  94. adc_scan(0);
  95. adc_scan(1);
  96. adc_scan(2);
  97. adc_scan(3);
  98. }
  99. }
  100.  
  101. /* Figured out from how the OF does things */
  102. void adc_init(void)
  103. {
  104. #if defined(PBELL_VIBE500)
  105. ADC_UNK |= 0x1000;
  106. #endif
  107.  
  108. #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
  109. ADC_INIT = 0;
  110. #else
  111. ADC_INIT |= 1;
  112. ADC_INIT |= 0x40000000;
  113. #endif
  114. udelay(100);
  115.  
  116. /* Reset ADC */
  117. DEV_RS2 |= 0x20;
  118. udelay(100);
  119.  
  120. DEV_RS2 &=~ 0x20;
  121. udelay(100);
  122.  
  123. /* Enable ADC */
  124. DEV_EN2 |= 0x20;
  125. udelay(100);
  126.  
  127. ADC_CLOCK_SRC |= 0x3;
  128. udelay(100);
  129.  
  130. ADC_ADDR = 0;
  131. ADC_ADDR |= 0x40;
  132.  
  133. #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330))
  134. ADC_ADDR |= 0x20000000;
  135. udelay(100);
  136.  
  137. ADC_INIT;
  138. ADC_INIT = 0;
  139. udelay(100);
  140. #endif
  141.  
  142. ADC_STATUS = 0;
  143.  
  144. /* Enable channel 0 (battery) */
  145. DEV_INIT1 &=~0x3;
  146. ADC_ADDR |= 0x1000000;
  147. ADC_STATUS |= 0x20;
  148.  
  149. /* Enable channel 1 (unknown) */
  150. DEV_INIT1 &=~30;
  151. ADC_ADDR |= 0x2000000;
  152. ADC_STATUS |= 0x2000;
  153. ADC_CFG |= 0x2000; //??
  154.  
  155. #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || \
  156. defined(MROBE_100)
  157. /* Enable channel 2 (H10:remote) */
  158. DEV_INIT1 &=~0x300;
  159. DEV_INIT1 |= 0x100;
  160. ADC_ADDR |= 0x4000000;
  161. ADC_STATUS |= 0x200000;
  162.  
  163. /* Enable channel 3 (H10:scroll pad) */
  164. DEV_INIT1 &=~0x3000;
  165. DEV_INIT1 |= 0x1000;
  166. ADC_ADDR |= 0x8000000;
  167. ADC_STATUS |= 0x20000000;
  168. #endif
  169.  
  170. #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
  171. ADC_INIT |= 0x80000000;
  172. udelay(100);
  173. ADC_INIT = 0;
  174. #endif
  175.  
  176. /* Force a scan of all channels to get initial values */
  177. adc_scan(0);
  178. adc_scan(1);
  179. adc_scan(2);
  180. adc_scan(3);
  181.  
  182. tick_add_task(adc_tick);
  183. }
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement