diff options
author | Rob Purchase <shotofadds@rockbox.org> | 2009-10-10 17:35:02 +0000 |
---|---|---|
committer | Rob Purchase <shotofadds@rockbox.org> | 2009-10-10 17:35:02 +0000 |
commit | 16ada4cb81c70c1a151c69aa08da13e55aba0081 (patch) | |
tree | c92dda004a162cea1d2ded3188cffe1ca6f04077 /firmware/target/arm | |
parent | 31464f7930cd8857ef8d00ed75534087057058e2 (diff) | |
download | rockbox-16ada4cb81c70c1a151c69aa08da13e55aba0081.tar.gz rockbox-16ada4cb81c70c1a151c69aa08da13e55aba0081.zip |
Initial support for runtime detection of the PMU used in newer D2+ models (PCF50635). The backlight and battery monitoring should work, but the RTC and touchscreen are not yet implemented.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23078 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm')
4 files changed, 117 insertions, 26 deletions
diff --git a/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c b/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c index 39a9abf073..d417687804 100644 --- a/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c | |||
@@ -22,7 +22,9 @@ | |||
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "backlight.h" | 23 | #include "backlight.h" |
24 | #include "pcf50606.h" | 24 | #include "pcf50606.h" |
25 | #include "pcf50635.h" | ||
25 | #include "tcc780x.h" | 26 | #include "tcc780x.h" |
27 | #include "power-target.h" | ||
26 | 28 | ||
27 | int _backlight_init(void) | 29 | int _backlight_init(void) |
28 | { | 30 | { |
@@ -35,17 +37,49 @@ int _backlight_init(void) | |||
35 | void _backlight_set_brightness(int brightness) | 37 | void _backlight_set_brightness(int brightness) |
36 | { | 38 | { |
37 | int level = disable_irq_save(); | 39 | int level = disable_irq_save(); |
38 | pcf50606_write(PCF5060X_PWMC1, 0xe1 | (MAX_BRIGHTNESS_SETTING-brightness)<<1); | 40 | |
39 | pcf50606_write(PCF5060X_GPOC1, 0x3); | 41 | if (get_pmu_type() == PCF50606) |
42 | { | ||
43 | pcf50606_write(PCF5060X_PWMC1, | ||
44 | 0xe1 | (MAX_BRIGHTNESS_SETTING-brightness)<<1); | ||
45 | pcf50606_write(PCF5060X_GPOC1, 0x3); | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | static const int brightness_lookup[MAX_BRIGHTNESS_SETTING+1] = | ||
50 | {0x1, 0x8, 0xa, 0xe, 0x12, 0x16, 0x19, 0x1b, 0x1e, | ||
51 | 0x21, 0x24, 0x26, 0x28, 0x2a, 0x2c}; | ||
52 | |||
53 | pcf50635_write(PCF5063X_REG_LEDOUT, brightness_lookup[brightness]); | ||
54 | } | ||
55 | |||
40 | restore_irq(level); | 56 | restore_irq(level); |
41 | } | 57 | } |
42 | 58 | ||
43 | void _backlight_on(void) | 59 | void _backlight_on(void) |
44 | { | 60 | { |
45 | GPIOA_SET = (1<<6); | 61 | if (get_pmu_type() == PCF50606) |
62 | { | ||
63 | GPIOA_SET = (1<<6); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | int level = disable_irq_save(); | ||
68 | pcf50635_write(PCF5063X_REG_LEDENA, 1); | ||
69 | restore_irq(level); | ||
70 | } | ||
46 | } | 71 | } |
47 | 72 | ||
48 | void _backlight_off(void) | 73 | void _backlight_off(void) |
49 | { | 74 | { |
50 | GPIOA_CLEAR = (1<<6); | 75 | if (get_pmu_type() == PCF50606) |
76 | { | ||
77 | GPIOA_CLEAR = (1<<6); | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | int level = disable_irq_save(); | ||
82 | pcf50635_write(PCF5063X_REG_LEDENA, 0); | ||
83 | restore_irq(level); | ||
84 | } | ||
51 | } | 85 | } |
diff --git a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c index 8190108dd4..d5f4ec9768 100644 --- a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c | |||
@@ -23,31 +23,51 @@ | |||
23 | #include "system.h" | 23 | #include "system.h" |
24 | #include "power.h" | 24 | #include "power.h" |
25 | #include "pcf50606.h" | 25 | #include "pcf50606.h" |
26 | #include "pcf50635.h" | ||
26 | #include "button-target.h" | 27 | #include "button-target.h" |
27 | #include "tuner.h" | 28 | #include "tuner.h" |
28 | #include "backlight-target.h" | 29 | #include "backlight-target.h" |
29 | #include "powermgmt.h" | 30 | #include "powermgmt.h" |
31 | #include "power-target.h" | ||
32 | |||
33 | static enum pmu_type pmu; | ||
34 | |||
35 | enum pmu_type get_pmu_type() | ||
36 | { | ||
37 | return pmu; | ||
38 | } | ||
30 | 39 | ||
31 | void power_init(void) | 40 | void power_init(void) |
32 | { | 41 | { |
33 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ | 42 | /* Configure GPA6 as input and wait a short while */ |
43 | GPIOA_DIR &= ~(1<<6); | ||
34 | 44 | ||
35 | /* Clear pending interrupts from pcf50606 */ | 45 | udelay(10); |
36 | pcf50606_read_multiple(0x02, data, 3); | 46 | |
37 | 47 | /* Value of GPA6 determines PMU chip type */ | |
38 | /* Set outputs as per OF - further investigation required. */ | 48 | if (GPIOA & (1<<6)) |
39 | pcf50606_write(PCF5060X_DCDEC1, 0xe4); | 49 | { |
40 | pcf50606_write(PCF5060X_IOREGC, 0xf5); | 50 | pmu = PCF50635; |
41 | pcf50606_write(PCF5060X_D1REGC1, 0xf5); | 51 | |
42 | pcf50606_write(PCF5060X_D2REGC1, 0xe9); | 52 | pcf50635_init(); |
43 | pcf50606_write(PCF5060X_D3REGC1, 0xf8); /* WM8985 3.3v */ | 53 | } |
44 | pcf50606_write(PCF5060X_DCUDC1, 0xe7); | 54 | else |
45 | pcf50606_write(PCF5060X_LPREGC1, 0x0); | 55 | { |
46 | pcf50606_write(PCF5060X_LPREGC2, 0x2); | 56 | pmu = PCF50606; |
57 | |||
58 | /* Configure GPA6 for output (backlight enable) */ | ||
59 | GPIOA_DIR |= (1<<6); | ||
60 | |||
61 | pcf50606_init(); | ||
62 | |||
63 | /* Clear pending interrupts */ | ||
64 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ | ||
65 | pcf50606_read_multiple(0x02, data, 3); | ||
47 | 66 | ||
48 | #ifndef BOOTLOADER | 67 | #ifndef BOOTLOADER |
49 | IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */ | 68 | IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */ |
50 | #endif | 69 | #endif |
70 | } | ||
51 | } | 71 | } |
52 | 72 | ||
53 | void power_off(void) | 73 | void power_off(void) |
@@ -55,7 +75,7 @@ void power_off(void) | |||
55 | /* Turn the backlight off first to avoid a bright stripe on power-off */ | 75 | /* Turn the backlight off first to avoid a bright stripe on power-off */ |
56 | _backlight_off(); | 76 | _backlight_off(); |
57 | sleep(HZ/10); | 77 | sleep(HZ/10); |
58 | 78 | ||
59 | /* Power off the player using the same mechanism as the OF */ | 79 | /* Power off the player using the same mechanism as the OF */ |
60 | GPIOA_CLEAR = (1<<7); | 80 | GPIOA_CLEAR = (1<<7); |
61 | while(true); | 81 | while(true); |
@@ -114,15 +134,15 @@ bool tuner_power(bool status) | |||
114 | in host read mode: */ | 134 | in host read mode: */ |
115 | 135 | ||
116 | /* 1. Set direction of the DATA-line to input-mode. */ | 136 | /* 1. Set direction of the DATA-line to input-mode. */ |
117 | GPIOC_DIR &= ~(1 << 30); | 137 | GPIOC_DIR &= ~(1 << 30); |
118 | 138 | ||
119 | /* 2. Drive NR_W low */ | 139 | /* 2. Drive NR_W low */ |
120 | GPIOC_CLEAR = (1 << 31); | 140 | GPIOC_CLEAR = (1 << 31); |
121 | GPIOC_DIR |= (1 << 31); | 141 | GPIOC_DIR |= (1 << 31); |
122 | 142 | ||
123 | /* 3. Drive CLOCK high */ | 143 | /* 3. Drive CLOCK high */ |
124 | GPIOC_SET = (1 << 29); | 144 | GPIOC_SET = (1 << 29); |
125 | GPIOC_DIR |= (1 << 29); | 145 | GPIOC_DIR |= (1 << 29); |
126 | 146 | ||
127 | lv24020lp_power(true); | 147 | lv24020lp_power(true); |
128 | } | 148 | } |
diff --git a/firmware/target/arm/tcc780x/cowond2/power-target.h b/firmware/target/arm/tcc780x/cowond2/power-target.h new file mode 100644 index 0000000000..38288f38c8 --- /dev/null +++ b/firmware/target/arm/tcc780x/cowond2/power-target.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 Rob Purchase | ||
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 | #ifndef _POWER_TARGET_H | ||
22 | #define _POWER_TARGET_H | ||
23 | |||
24 | enum pmu_type | ||
25 | { | ||
26 | PCF50606, | ||
27 | PCF50635 | ||
28 | }; | ||
29 | |||
30 | enum pmu_type get_pmu_type(void); | ||
31 | |||
32 | #endif /* _POWER_TARGET_H */ | ||
diff --git a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c index b52d5c46ba..9b2320b7cf 100644 --- a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c | |||
@@ -23,7 +23,9 @@ | |||
23 | #include "adc.h" | 23 | #include "adc.h" |
24 | #include "powermgmt.h" | 24 | #include "powermgmt.h" |
25 | #include "kernel.h" | 25 | #include "kernel.h" |
26 | #include "power-target.h" | ||
26 | #include "pcf50606.h" | 27 | #include "pcf50606.h" |
28 | #include "pcf50635.h" | ||
27 | 29 | ||
28 | unsigned short current_voltage = 3910; | 30 | unsigned short current_voltage = 3910; |
29 | 31 | ||
@@ -66,7 +68,11 @@ unsigned int battery_adc_voltage(void) | |||
66 | if (TIME_BEFORE(last_tick+HZ, current_tick)) | 68 | if (TIME_BEFORE(last_tick+HZ, current_tick)) |
67 | { | 69 | { |
68 | short adc_val; | 70 | short adc_val; |
69 | pcf50606_read_adc(PCF5060X_ADC_BATVOLT_RES, &adc_val, NULL); | 71 | |
72 | if (get_pmu_type() == PCF50606) | ||
73 | pcf50606_read_adc(PCF5060X_ADC_BATVOLT_RES, &adc_val, NULL); | ||
74 | else | ||
75 | pcf50635_read_adc(PCF5063X_ADCC1_MUX_BATSNS_RES, &adc_val, NULL); | ||
70 | 76 | ||
71 | current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10; | 77 | current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10; |
72 | 78 | ||
@@ -75,4 +81,3 @@ unsigned int battery_adc_voltage(void) | |||
75 | 81 | ||
76 | return current_voltage; | 82 | return current_voltage; |
77 | } | 83 | } |
78 | |||