Advertisement
Guest User

adc2

a guest
Apr 9th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 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. static unsigned long addrcount = 0
  45. if(channel == 1 && addrcount < 80000000)
  46. {
  47. DEV_INIT1 &=~0x30;
  48. DEV_INIT1 |=0x10;
  49. //DEV_INIT1 |=0x20;
  50. //DEV_INIT1 |=0x30;
  51. ADC_CFG = addrcount
  52. ADC_ADDR |= 0x2000000;
  53. ADC_STATUS |= 0x2000;
  54. udelay(100);
  55. addrcount ++;
  56. }
  57.  
  58.  
  59.  
  60. unsigned int adc_data_1;
  61. unsigned int adc_data_2;
  62.  
  63. if (channel >= NUM_ADC_CHANNELS)
  64. return 0;
  65.  
  66. /* Start conversion */
  67. ADC_ADDR |= 0x80000000;
  68.  
  69. /* Wait for conversion to complete */
  70. while((ADC_STATUS & (0x40<<8*channel))==0);
  71.  
  72. /* Stop conversion */
  73. ADC_ADDR &=~ 0x80000000;
  74.  
  75. /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
  76. For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
  77. 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
  78. adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff);
  79. adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3);
  80.  
  81. adcdata[channel] = (adc_data_1<<2 | adc_data_2);
  82.  
  83. #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330) ||\
  84. defined(SAMSUNG_YH820) || defined(SAMSUNG_YH920) ||\
  85. defined(SAMSUNG_YH925))
  86. /* ADC values read low if PLL is enabled */
  87. if(PLL_CONTROL & 0x80000000){
  88. adcdata[channel] += 0x14;
  89. if(adcdata[channel] > 0x400)
  90. adcdata[channel] = 0x400;
  91. }
  92. #endif
  93.  
  94. if (channel == 1)
  95. {
  96. if (adcdata[channel] < 3f0)
  97. {
  98. splash(1000, "%x", addrcount);
  99. addrcount = 80000000;
  100. }
  101. }
  102.  
  103. return adcdata[channel];
  104. }
  105.  
  106. /* Read 10-bit channel data */
  107. unsigned short adc_read(int channel)
  108. {
  109. return adcdata[channel];
  110. }
  111.  
  112. static int adc_counter;
  113.  
  114. static void adc_tick(void)
  115. {
  116. if(++adc_counter == HZ)
  117. {
  118. adc_counter = 0;
  119. adc_scan(0);
  120. adc_scan(1);
  121. adc_scan(2);
  122. adc_scan(3);
  123. }
  124. }
  125.  
  126. /* Figured out from how the OF does things */
  127. void adc_init(void)
  128. {
  129. #if defined(PBELL_VIBE500)
  130. ADC_UNK |= 0x1000;
  131. #endif
  132.  
  133. #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
  134. ADC_INIT = 0;
  135. #else
  136. ADC_INIT |= 1;
  137. ADC_INIT |= 0x40000000;
  138. #endif
  139. udelay(100);
  140.  
  141. /* Reset ADC */
  142. DEV_RS2 |= 0x20;
  143. udelay(100);
  144.  
  145. DEV_RS2 &=~ 0x20;
  146. udelay(100);
  147.  
  148. /* Enable ADC */
  149. DEV_EN2 |= 0x20;
  150. udelay(100);
  151.  
  152. ADC_CLOCK_SRC |= 0x3;
  153. udelay(100);
  154.  
  155. ADC_ADDR = 0;
  156. ADC_ADDR |= 0x40;
  157.  
  158. #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330))
  159. ADC_ADDR |= 0x20000000;
  160. udelay(100);
  161.  
  162. ADC_INIT;
  163. ADC_INIT = 0;
  164. udelay(100);
  165. #endif
  166.  
  167. ADC_STATUS = 0;
  168.  
  169. /* Enable channel 0 (battery) */
  170. DEV_INIT1 &=~0x3;
  171. ADC_ADDR |= 0x1000000;
  172. ADC_STATUS |= 0x20;
  173.  
  174. /* Enable channel 1 (unknown) */
  175. DEV_INIT1 &=~0x30;
  176. DEV_INIT1 |=0x10;
  177. //DEV_INIT1 |=0x20;
  178. //DEV_INIT1 |=0x30;
  179. ADC_ADDR |= 0x2000000;
  180. ADC_STATUS |= 0x2000;
  181. //ADC_CFG |= 0x2000; //??
  182.  
  183. #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || \
  184. defined(MROBE_100)
  185. /* Enable channel 2 (H10:remote) */
  186. DEV_INIT1 &=~0x300;
  187. DEV_INIT1 |= 0x100;
  188. ADC_ADDR |= 0x4000000;
  189. ADC_STATUS |= 0x200000;
  190.  
  191. /* Enable channel 3 (H10:scroll pad) */
  192. DEV_INIT1 &=~0x3000;
  193. DEV_INIT1 |= 0x1000;
  194. ADC_ADDR |= 0x8000000;
  195. ADC_STATUS |= 0x20000000;
  196. #endif
  197.  
  198. #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
  199. ADC_INIT |= 0x80000000;
  200. udelay(100);
  201. ADC_INIT = 0;
  202. #endif
  203.  
  204. /* Force a scan of all channels to get initial values */
  205. adc_scan(0);
  206. adc_scan(1);
  207. adc_scan(2);
  208. adc_scan(3);
  209.  
  210. tick_add_task(adc_tick);
  211. }
  212.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement