diff options
Diffstat (limited to 'firmware/target/arm/iriver')
-rw-r--r-- | firmware/target/arm/iriver/h10/adc-h10.c | 90 | ||||
-rw-r--r-- | firmware/target/arm/iriver/h10/adc-target.h | 3 | ||||
-rw-r--r-- | firmware/target/arm/iriver/h10/button-h10.c | 12 | ||||
-rw-r--r-- | firmware/target/arm/iriver/h10/powermgmt-h10.c | 18 |
4 files changed, 79 insertions, 44 deletions
diff --git a/firmware/target/arm/iriver/h10/adc-h10.c b/firmware/target/arm/iriver/h10/adc-h10.c index df9b16359b..f63e8b8013 100644 --- a/firmware/target/arm/iriver/h10/adc-h10.c +++ b/firmware/target/arm/iriver/h10/adc-h10.c | |||
@@ -25,29 +25,21 @@ | |||
25 | 25 | ||
26 | static unsigned short adcdata[NUM_ADC_CHANNELS]; | 26 | static unsigned short adcdata[NUM_ADC_CHANNELS]; |
27 | 27 | ||
28 | /* Scan ADC so that adcdata[channel] gets updated */ | 28 | /* Scan ADC so that adcdata[channel] gets updated. */ |
29 | unsigned short adc_scan(int channel) | 29 | unsigned short adc_scan(int channel) |
30 | { | 30 | { |
31 | unsigned int adc_data_1; | 31 | unsigned int adc_data_1; |
32 | unsigned int adc_data_2; | 32 | unsigned int adc_data_2; |
33 | 33 | ||
34 | /* Initialise */ | 34 | /* Start conversion */ |
35 | ADC_ADDR=0x130; | 35 | ADC_ADDR |= 0x80000000; |
36 | ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is | ||
37 | off, 0x40 if the channel is on */ | ||
38 | 36 | ||
39 | /* Enable Channel */ | 37 | /* Wait for conversion to complete */ |
40 | ADC_ADDR |= (0x1000000<<channel); | 38 | while((ADC_STATUS & (0x40<<8*channel))==0); |
39 | |||
40 | /* Stop conversion */ | ||
41 | ADC_ADDR &=~ 0x80000000; | ||
41 | 42 | ||
42 | /* Start? */ | ||
43 | ADC_ADDR |= 0x20000000; | ||
44 | ADC_ADDR |= 0x80000000; | ||
45 | |||
46 | #if 0 | ||
47 | /* wait for ADC ready. THIS IS NOT WORKING (locks up) */ | ||
48 | while(ADC_STATUS & (0x40 << (channel*8))); /* add loop protection here */ | ||
49 | #endif | ||
50 | |||
51 | /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel. | 43 | /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel. |
52 | For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the | 44 | For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the |
53 | 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */ | 45 | 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */ |
@@ -56,6 +48,13 @@ unsigned short adc_scan(int channel) | |||
56 | 48 | ||
57 | adcdata[channel] = (adc_data_1<<2 | adc_data_2); | 49 | adcdata[channel] = (adc_data_1<<2 | adc_data_2); |
58 | 50 | ||
51 | /* ADC values read low if PLL is enabled */ | ||
52 | if(PLL_CONTROL & 0x80000000){ | ||
53 | adcdata[channel] += 0x14; | ||
54 | if(adcdata[channel] > 0x400) | ||
55 | adcdata[channel] = 0x400; | ||
56 | } | ||
57 | |||
59 | return adcdata[channel]; | 58 | return adcdata[channel]; |
60 | } | 59 | } |
61 | 60 | ||
@@ -79,25 +78,64 @@ static void adc_tick(void) | |||
79 | } | 78 | } |
80 | } | 79 | } |
81 | 80 | ||
81 | /* Figured out from how the OF does things */ | ||
82 | void adc_init(void) | 82 | void adc_init(void) |
83 | { | 83 | { |
84 | /* Enable ADC */ | 84 | ADC_INIT |= 1; |
85 | ADC_ENABLE_ADDR |= ADC_ENABLE; | 85 | ADC_INIT |= 0x40000000; |
86 | udelay(100); | ||
87 | |||
88 | /* Reset ADC */ | ||
89 | DEV_RS2 |= 0x20; | ||
90 | udelay(100); | ||
91 | |||
92 | DEV_RS2 &=~ 0x20; | ||
93 | udelay(100); | ||
86 | 94 | ||
87 | /* Initialise */ | 95 | /* Enable ADC */ |
88 | ADC_INIT=0; | 96 | DEV_EN2 |= 0x20; |
97 | udelay(100); | ||
98 | |||
99 | ADC_CLOCK_SRC |= 0x3; | ||
100 | udelay(100); | ||
101 | |||
102 | ADC_ADDR |= 0x40; | ||
103 | ADC_ADDR |= 0x20000000; | ||
104 | udelay(100); | ||
105 | |||
106 | ADC_INIT; | ||
107 | ADC_INIT = 0; | ||
108 | udelay(100); | ||
109 | |||
110 | ADC_STATUS = 0; | ||
111 | |||
112 | /* Enable channel 0 (battery) */ | ||
113 | DEV_INIT1 &=~0x3; | ||
114 | ADC_ADDR |= 0x1000000; | ||
115 | ADC_STATUS |= 0x20; | ||
116 | |||
117 | /* Enable channel 1 (unknown, temperature?) */ | ||
118 | DEV_INIT1 &=~30; | ||
119 | ADC_ADDR |= 0x2000000; | ||
120 | ADC_STATUS |= 0x2000; | ||
121 | |||
122 | /* Enable channel 2 (remote) */ | ||
123 | DEV_INIT1 &=~0x300; | ||
124 | DEV_INIT1 |= 0x100; | ||
125 | ADC_ADDR |= 0x4000000; | ||
126 | ADC_STATUS |= 0x200000; | ||
127 | |||
128 | /* Enable channel 3 (scroll pad) */ | ||
129 | DEV_INIT1 &=~0x3000; | ||
130 | DEV_INIT1 |= 0x1000; | ||
131 | ADC_ADDR |= 0x8000000; | ||
132 | ADC_STATUS |= 0x20000000; | ||
89 | 133 | ||
90 | /* Force a scan of all channels to get initial values */ | 134 | /* Force a scan of all channels to get initial values */ |
91 | adc_scan(ADC_BATTERY); | 135 | adc_scan(ADC_BATTERY); |
92 | adc_scan(ADC_UNKNOWN_1); | 136 | adc_scan(ADC_UNKNOWN_1); |
93 | adc_scan(ADC_REMOTE); | 137 | adc_scan(ADC_REMOTE); |
94 | adc_scan(ADC_SCROLLPAD); | 138 | adc_scan(ADC_SCROLLPAD); |
95 | |||
96 | /* FIXME: The ADC sometimes reads 0 for the battery | ||
97 | voltage for the first few seconds. It would be better to fix this by | ||
98 | figuring out how to use the ADC properly. Until then, work around the | ||
99 | problem by waiting until it reads a proper value*/ | ||
100 | while(adc_scan(ADC_UNREG_POWER)==0); | ||
101 | 139 | ||
102 | tick_add_task(adc_tick); | 140 | tick_add_task(adc_tick); |
103 | } | 141 | } |
diff --git a/firmware/target/arm/iriver/h10/adc-target.h b/firmware/target/arm/iriver/h10/adc-target.h index 741c293baa..f761e761ef 100644 --- a/firmware/target/arm/iriver/h10/adc-target.h +++ b/firmware/target/arm/iriver/h10/adc-target.h | |||
@@ -19,9 +19,6 @@ | |||
19 | #ifndef _ADC_TARGET_H_ | 19 | #ifndef _ADC_TARGET_H_ |
20 | #define _ADC_TARGET_H_ | 20 | #define _ADC_TARGET_H_ |
21 | 21 | ||
22 | #define ADC_ENABLE_ADDR (*(volatile unsigned long*)(0x70000010)) | ||
23 | #define ADC_ENABLE 0x1100 | ||
24 | |||
25 | #define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00)) | 22 | #define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00)) |
26 | #define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04)) | 23 | #define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04)) |
27 | #define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20)) | 24 | #define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20)) |
diff --git a/firmware/target/arm/iriver/h10/button-h10.c b/firmware/target/arm/iriver/h10/button-h10.c index d8a82cf170..ac09d245e6 100644 --- a/firmware/target/arm/iriver/h10/button-h10.c +++ b/firmware/target/arm/iriver/h10/button-h10.c | |||
@@ -52,7 +52,7 @@ bool button_hold(void) | |||
52 | 52 | ||
53 | bool remote_button_hold(void) | 53 | bool remote_button_hold(void) |
54 | { | 54 | { |
55 | return adc_scan(ADC_REMOTE) < 0x17; | 55 | return adc_scan(ADC_REMOTE) < 0x2B; |
56 | } | 56 | } |
57 | 57 | ||
58 | /* | 58 | /* |
@@ -102,7 +102,7 @@ int button_read_device(void) | |||
102 | data = adc_scan(ADC_SCROLLPAD); | 102 | data = adc_scan(ADC_SCROLLPAD); |
103 | GPIOD_OUTPUT_VAL |= 0x40; | 103 | GPIOD_OUTPUT_VAL |= 0x40; |
104 | 104 | ||
105 | if(data < 0x210) | 105 | if(data < 0x224) |
106 | { | 106 | { |
107 | btn |= BUTTON_SCROLL_DOWN; | 107 | btn |= BUTTON_SCROLL_DOWN; |
108 | } else { | 108 | } else { |
@@ -115,7 +115,7 @@ int button_read_device(void) | |||
115 | remote_hold_button_old = remote_hold_button; | 115 | remote_hold_button_old = remote_hold_button; |
116 | 116 | ||
117 | data = adc_scan(ADC_REMOTE); | 117 | data = adc_scan(ADC_REMOTE); |
118 | remote_hold_button = data < 0x17; | 118 | remote_hold_button = data < 0x2B; |
119 | 119 | ||
120 | #ifndef BOOTLOADER | 120 | #ifndef BOOTLOADER |
121 | if (remote_hold_button != remote_hold_button_old) | 121 | if (remote_hold_button != remote_hold_button_old) |
@@ -126,13 +126,13 @@ int button_read_device(void) | |||
126 | { | 126 | { |
127 | if (data < 0x3FF) | 127 | if (data < 0x3FF) |
128 | { | 128 | { |
129 | if(data < 0x1F0) | 129 | if(data < 0x204) |
130 | if(data < 0x141) | 130 | if(data < 0x155) |
131 | btn |= BUTTON_RC_FF; | 131 | btn |= BUTTON_RC_FF; |
132 | else | 132 | else |
133 | btn |= BUTTON_RC_REW; | 133 | btn |= BUTTON_RC_REW; |
134 | else | 134 | else |
135 | if(data < 0x2BC) | 135 | if(data < 0x2D0) |
136 | btn |= BUTTON_RC_VOL_DOWN; | 136 | btn |= BUTTON_RC_VOL_DOWN; |
137 | else | 137 | else |
138 | btn |= BUTTON_RC_VOL_UP; | 138 | btn |= BUTTON_RC_VOL_UP; |
diff --git a/firmware/target/arm/iriver/h10/powermgmt-h10.c b/firmware/target/arm/iriver/h10/powermgmt-h10.c index 18e3879c43..6f8cd12276 100644 --- a/firmware/target/arm/iriver/h10/powermgmt-h10.c +++ b/firmware/target/arm/iriver/h10/powermgmt-h10.c | |||
@@ -25,18 +25,18 @@ | |||
25 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | 25 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = |
26 | { | 26 | { |
27 | #ifdef IRIVER_H10 | 27 | #ifdef IRIVER_H10 |
28 | 3760 | 28 | 3733 |
29 | #elif defined IRIVER_H10_5GB | 29 | #elif defined IRIVER_H10_5GB |
30 | 3720 | 30 | 3695 |
31 | #endif | 31 | #endif |
32 | }; | 32 | }; |
33 | 33 | ||
34 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | 34 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = |
35 | { | 35 | { |
36 | #ifdef IRIVER_H10 | 36 | #ifdef IRIVER_H10 |
37 | 3650 | 37 | 3627 |
38 | #elif defined IRIVER_H10_5GB | 38 | #elif defined IRIVER_H10_5GB |
39 | 3650 | 39 | 3627 |
40 | #endif | 40 | #endif |
41 | }; | 41 | }; |
42 | 42 | ||
@@ -44,9 +44,9 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | |||
44 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | 44 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = |
45 | { | 45 | { |
46 | #ifdef IRIVER_H10 | 46 | #ifdef IRIVER_H10 |
47 | { 3760, 3800, 3850, 3870, 3900, 3950, 4020, 4070, 4110, 4180, 4240 } | 47 | { 3733, 3772, 3821, 3840, 3869, 3917, 3985, 4034, 4072, 4140, 4198 } |
48 | #elif defined IRIVER_H10_5GB | 48 | #elif defined IRIVER_H10_5GB |
49 | { 3720, 3740, 3800, 3820, 3840, 3880, 3940, 4020, 4060, 4150, 4240 } | 49 | { 3695, 3714, 3772, 3791, 3811, 3850, 3908, 3985, 4024, 4111, 4198 } |
50 | #endif | 50 | #endif |
51 | }; | 51 | }; |
52 | 52 | ||
@@ -54,14 +54,14 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | |||
54 | const unsigned short percent_to_volt_charge[11] = | 54 | const unsigned short percent_to_volt_charge[11] = |
55 | { | 55 | { |
56 | #ifdef IRIVER_H10 | 56 | #ifdef IRIVER_H10 |
57 | 3990, 4030, 4060, 4080, 4100, 4120, 4150, 4180, 4220, 4260, 4310 | 57 | 3956, 3995, 4024, 4043, 4063, 4082, 4111, 4140, 4179, 4218, 4266 |
58 | #elif defined IRIVER_H10_5GB | 58 | #elif defined IRIVER_H10_5GB |
59 | /* TODO: Not yet calibrated */ | 59 | /* TODO: Not yet calibrated */ |
60 | 3880, 3920, 3960, 4000, 4060, 4100, 4150, 4190, 4240, 4280, 4330 | 60 | 3850, 3888, 3927, 3966, 4024, 4063, 4111, 4150, 4198, 4237, 4286 |
61 | #endif | 61 | #endif |
62 | }; | 62 | }; |
63 | 63 | ||
64 | #define BATTERY_SCALE_FACTOR 4800 | 64 | #define BATTERY_SCALE_FACTOR 4650 |
65 | /* full-scale ADC readout (2^10) in millivolt */ | 65 | /* full-scale ADC readout (2^10) in millivolt */ |
66 | 66 | ||
67 | /* Returns battery voltage from ADC [millivolts] */ | 67 | /* Returns battery voltage from ADC [millivolts] */ |