summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sparmann <theseven@rockbox.org>2009-10-11 18:20:56 +0000
committerMichael Sparmann <theseven@rockbox.org>2009-10-11 18:20:56 +0000
commitb729a7d75ec5b2fb73aa67c8f986e2793f8efcaf (patch)
tree8cb993512eff44090b8db093c985ee3ecb9a0f28
parent4ecc5a1e9babe84d815fcf77328a18b86f6edda1 (diff)
downloadrockbox-b729a7d75ec5b2fb73aa67c8f986e2793f8efcaf.tar.gz
rockbox-b729a7d75ec5b2fb73aa67c8f986e2793f8efcaf.zip
iPod Nano 2G PMU rework, added backlight brightness setting and USB charging speed setting
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23114 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/config-ipodnano2g.h12
-rw-r--r--firmware/export/s5l8700.h4
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c2
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c80
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h10
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c42
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c1
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c4
8 files changed, 104 insertions, 51 deletions
diff --git a/firmware/export/config-ipodnano2g.h b/firmware/export/config-ipodnano2g.h
index 5e92ea889a..cca87aabce 100644
--- a/firmware/export/config-ipodnano2g.h
+++ b/firmware/export/config-ipodnano2g.h
@@ -104,7 +104,7 @@
104 104
105/* Define this for LCD backlight available */ 105/* Define this for LCD backlight available */
106#define HAVE_BACKLIGHT 106#define HAVE_BACKLIGHT
107/* #define HAVE_BACKLIGHT_BRIGHTNESS - not yet */ 107#define HAVE_BACKLIGHT_BRIGHTNESS
108 108
109/* Define this if you have a software controlled poweroff */ 109/* Define this if you have a software controlled poweroff */
110#define HAVE_SW_POWEROFF 110#define HAVE_SW_POWEROFF
@@ -138,6 +138,8 @@
138/* I2C interface */ 138/* I2C interface */
139#define CONFIG_I2C I2C_S5L8700 139#define CONFIG_I2C I2C_S5L8700
140 140
141#define HAVE_USB_CHARGING_ENABLE
142
141/* The size of the flash ROM */ 143/* The size of the flash ROM */
142#define FLASH_SIZE 0x400000 144#define FLASH_SIZE 0x400000
143 145
@@ -187,9 +189,9 @@
187#define MIN_CONTRAST_SETTING 1 189#define MIN_CONTRAST_SETTING 1
188#define MAX_CONTRAST_SETTING 30 190#define MAX_CONTRAST_SETTING 30
189#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ 191#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */
192#endif
190 193
191/* Main LCD backlight brightness range and defaults */ 194/* Main LCD backlight brightness range and defaults */
192#define MIN_BRIGHTNESS_SETTING 0 195#define MIN_BRIGHTNESS_SETTING 1
193#define MAX_BRIGHTNESS_SETTING 31 196#define MAX_BRIGHTNESS_SETTING 0x2e
194#define DEFAULT_BRIGHTNESS_SETTING 20 197#define DEFAULT_BRIGHTNESS_SETTING 0x20
195#endif
diff --git a/firmware/export/s5l8700.h b/firmware/export/s5l8700.h
index e649b92c14..f08abee8ff 100644
--- a/firmware/export/s5l8700.h
+++ b/firmware/export/s5l8700.h
@@ -552,14 +552,14 @@
552#define PDAT7 (*(REG32_PTR_T)(0x3CF00074)) /* The data register for port 7 */ 552#define PDAT7 (*(REG32_PTR_T)(0x3CF00074)) /* The data register for port 7 */
553#define PCON10 (*(REG32_PTR_T)(0x3CF000A0)) /* Configures the pins of port 10 */ 553#define PCON10 (*(REG32_PTR_T)(0x3CF000A0)) /* Configures the pins of port 10 */
554#define PDAT10 (*(REG32_PTR_T)(0x3CF000A4)) /* The data register for port 10 */ 554#define PDAT10 (*(REG32_PTR_T)(0x3CF000A4)) /* The data register for port 10 */
555#define PCON11 (*(REG32_PTR_T)(0x3CF000B0)) /* Configures the pins of port 11 */
556#define PDAT11 (*(REG32_PTR_T)(0x3CF000B4)) /* The data register for port 11 */
555#define PCON13 (*(REG32_PTR_T)(0x3CF000D0)) /* Configures the pins of port 13 */ 557#define PCON13 (*(REG32_PTR_T)(0x3CF000D0)) /* Configures the pins of port 13 */
556#define PDAT13 (*(REG32_PTR_T)(0x3CF000D4)) /* The data register for port 13 */ 558#define PDAT13 (*(REG32_PTR_T)(0x3CF000D4)) /* The data register for port 13 */
557#define PCON14 (*(REG32_PTR_T)(0x3CF000E0)) /* Configures the pins of port 14 */ 559#define PCON14 (*(REG32_PTR_T)(0x3CF000E0)) /* Configures the pins of port 14 */
558#define PDAT14 (*(REG32_PTR_T)(0x3CF000E4)) /* The data register for port 14 */ 560#define PDAT14 (*(REG32_PTR_T)(0x3CF000E4)) /* The data register for port 14 */
559#define PCON_ASRAM (*(REG32_PTR_T)(0x3CF000F0)) /* Configures the pins of port nor flash */ 561#define PCON_ASRAM (*(REG32_PTR_T)(0x3CF000F0)) /* Configures the pins of port nor flash */
560#define PCON_SDRAM (*(REG32_PTR_T)(0x3CF000F4)) /* Configures the pins of port sdram */ 562#define PCON_SDRAM (*(REG32_PTR_T)(0x3CF000F4)) /* Configures the pins of port sdram */
561#define PCON11 (*(REG32_PTR_T)(0x3CF000F8)) /* Configures the pins of port 11 */
562#define PDAT11 (*(REG32_PTR_T)(0x3CF000FC)) /* The data register for port 11 */
563 563
564/* 25. UART */ 564/* 25. UART */
565 565
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c
index 21ba3e0bf0..705b5858bf 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c
@@ -28,7 +28,7 @@
28 28
29void _backlight_set_brightness(int brightness) 29void _backlight_set_brightness(int brightness)
30{ 30{
31 (void)brightness; 31 pmu_write(0x28, brightness);
32} 32}
33 33
34void _backlight_on(void) 34void _backlight_on(void)
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
index ca2b5f2775..be026a8cf4 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
@@ -57,50 +57,84 @@ void pmu_init(void)
57 pmu_initialized = 1; 57 pmu_initialized = 1;
58} 58}
59 59
60int pmu_read_battery_voltage(void) 60int pmu_read_adc(unsigned int adc)
61{ 61{
62 int data = 0; 62 int data = 0;
63 if (!pmu_initialized) pmu_init(); 63 if (!pmu_initialized) pmu_init();
64 mutex_lock(&pmu_adc_mutex); 64 mutex_lock(&pmu_adc_mutex);
65 pmu_write(0x54, 0x05); 65 pmu_write(0x54, 5 | (adc << 4));
66 while ((data & 0x80) == 0) 66 while ((data & 0x80) == 0)
67 { 67 {
68 yield(); 68 yield();
69 data = pmu_read(0x57); 69 data = pmu_read(0x57);
70 } 70 }
71 int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6; 71 int value = (pmu_read(0x55) << 2) | (data & 3);
72 mutex_unlock(&pmu_adc_mutex); 72 mutex_unlock(&pmu_adc_mutex);
73 return millivolts; 73 return value;
74}
75
76/* millivolts */
77int pmu_read_battery_voltage(void)
78{
79 return pmu_read_adc(0) * 6;
74} 80}
75 81
82/* milliamps */
76int pmu_read_battery_current(void) 83int pmu_read_battery_current(void)
77{ 84{
78 int data = 0; 85 return pmu_read_adc(2);
79 if (!pmu_initialized) pmu_init();
80 mutex_lock(&pmu_adc_mutex);
81 pmu_write(0x54, 0x25);
82 while ((data & 0x80) == 0)
83 {
84 yield();
85 data = pmu_read(0x57);
86 }
87 int milliamps = (pmu_read(0x55) << 2) | (data & 3);
88 mutex_unlock(&pmu_adc_mutex);
89 return milliamps;
90} 86}
91 87
92void pmu_switch_power(int gate, int onoff) 88void pmu_ldo_on_in_standby(unsigned int ldo, int onoff)
93{ 89{
94 if (gate < 4) 90 if (ldo < 4)
95 { 91 {
96 unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * gate)); 92 unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo));
97 if (onoff) newval |= 1 << (2 * gate); 93 if (onoff) newval |= 1 << (2 * ldo);
98 pmu_write(0x3B, newval); 94 pmu_write(0x3B, newval);
99 } 95 }
100 else if (gate < 7) 96 else if (ldo < 8)
101 { 97 {
102 unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (gate - 4))); 98 unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (ldo - 4)));
103 if (onoff) newval |= 1 << (2 * (gate - 4)); 99 if (onoff) newval |= 1 << (2 * (ldo - 4));
104 pmu_write(0x3C, newval); 100 pmu_write(0x3C, newval);
105 } 101 }
106} 102}
103
104void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage)
105{
106 if (ldo > 6) return;
107 pmu_write(0x2d + (ldo << 1), voltage);
108}
109
110void pmu_ldo_power_on(unsigned int ldo)
111{
112 if (ldo > 6) return;
113 pmu_write(0x2e + (ldo << 1), 1);
114}
115
116void pmu_ldo_power_off(unsigned int ldo)
117{
118 if (ldo > 6) return;
119 pmu_write(0x2e + (ldo << 1), 0);
120}
121
122void pmu_set_wake_condition(unsigned char condition)
123{
124 pmu_write(0xd, condition);
125}
126
127void pmu_enter_standby(void)
128{
129 pmu_write(0xc, 1);
130}
131
132void pmu_read_rtc(unsigned char* buffer)
133{
134 pmu_read_multiple(0x59, 7, buffer);
135}
136
137void pmu_write_rtc(unsigned char* buffer)
138{
139 pmu_write_multiple(0x59, 7, buffer);
140}
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h b/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h
index 43b0f54308..53f4dacc1b 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h
+++ b/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h
@@ -28,9 +28,17 @@ unsigned char pmu_read(int address);
28void pmu_write(int address, unsigned char val); 28void pmu_write(int address, unsigned char val);
29void pmu_read_multiple(int address, int count, unsigned char* buffer); 29void pmu_read_multiple(int address, int count, unsigned char* buffer);
30void pmu_write_multiple(int address, int count, unsigned char* buffer); 30void pmu_write_multiple(int address, int count, unsigned char* buffer);
31int pmu_read_adc(unsigned int adc);
31int pmu_read_battery_voltage(void); 32int pmu_read_battery_voltage(void);
32int pmu_read_battery_current(void); 33int pmu_read_battery_current(void);
33void pmu_init(void); 34void pmu_init(void);
34void pmu_switch_power(int gate, int onoff); 35void pmu_ldo_on_in_standby(unsigned int ldo, int onoff);
36void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage);
37void pmu_ldo_power_on(unsigned int ldo);
38void pmu_ldo_power_off(unsigned int ldo);
39void pmu_set_wake_condition(unsigned char condition);
40void pmu_enter_standby(void);
41void pmu_read_rtc(unsigned char* buffer);
42void pmu_write_rtc(unsigned char* buffer);
35 43
36#endif 44#endif
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c
index cba1514aad..de3dbed853 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c
@@ -32,18 +32,16 @@
32 32
33void power_off(void) 33void power_off(void)
34{ 34{
35 pmu_switch_power(0, 0); 35 pmu_ldo_on_in_standby(0, 0);
36 pmu_switch_power(2, 0); 36 pmu_ldo_on_in_standby(1, 0);
37 pmu_switch_power(3, 0); 37 pmu_ldo_on_in_standby(2, 0);
38 pmu_switch_power(4, 0); 38 pmu_ldo_on_in_standby(3, 0);
39 pmu_switch_power(6, 0); 39 pmu_ldo_on_in_standby(4, 0);
40 pmu_switch_power(7, 0); 40 pmu_ldo_on_in_standby(5, 0);
41 41 pmu_ldo_on_in_standby(6, 0);
42 pmu_write(0x36, pmu_read(0x36) & 0xF0); 42 pmu_ldo_on_in_standby(7, 0);
43 pmu_write(0x34, pmu_read(0x34) & 0xF0); 43 pmu_set_wake_condition(0x42); /* USB inserted or EXTON1 */
44 pmu_write(0xD, pmu_read(0xD) | 0x40); 44 pmu_enter_standby();
45 pmu_write(0xD, pmu_read(0xD) | 0x02);
46 pmu_write(0xC, 1);
47 45
48 while(1); 46 while(1);
49} 47}
@@ -54,15 +52,27 @@ void power_init(void)
54} 52}
55 53
56#if CONFIG_CHARGING 54#if CONFIG_CHARGING
55
56#ifdef HAVE_USB_CHARGING_ENABLE
57bool usb_charging_enable(bool on)
58{
59 PDAT11 = (PDAT11 & ~1) | (on ? 1 : 0);
60 return on;
61}
62
63bool usb_charging_enabled(void)
64{
65 return PDAT11 & 1;
66}
67#endif
68
57unsigned int power_input_status(void) 69unsigned int power_input_status(void)
58{ 70{
59 /* TODO */ 71 return (PDAT14 & 0x80) ? POWER_INPUT_NONE : POWER_INPUT_MAIN;
60 return POWER_INPUT_NONE;
61} 72}
62 73
63bool charging_state(void) 74bool charging_state(void)
64{ 75{
65 /* TODO */ 76 return (PDAT14 & 0x80) ? false : true;
66 return false;
67} 77}
68#endif /* CONFIG_CHARGING */ 78#endif /* CONFIG_CHARGING */
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c
index 937905f5f4..689e369da2 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c
@@ -61,4 +61,3 @@ unsigned int battery_adc_voltage(void)
61{ 61{
62 return pmu_read_battery_voltage(); 62 return pmu_read_battery_voltage();
63} 63}
64
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
index bad9581d8f..39cecc5291 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
@@ -33,7 +33,7 @@ int rtc_read_datetime(struct tm *tm)
33 unsigned int i; 33 unsigned int i;
34 unsigned char buf[7]; 34 unsigned char buf[7];
35 35
36 pmu_read_multiple(0x59, sizeof(buf), buf); 36 pmu_read_rtc(buf);
37 37
38 for (i = 0; i < sizeof(buf); i++) 38 for (i = 0; i < sizeof(buf); i++)
39 buf[i] = BCD2DEC(buf[i]); 39 buf[i] = BCD2DEC(buf[i]);
@@ -65,7 +65,7 @@ int rtc_write_datetime(const struct tm *tm)
65 for (i = 0; i < sizeof(buf); i++) 65 for (i = 0; i < sizeof(buf); i++)
66 buf[i] = DEC2BCD(buf[i]); 66 buf[i] = DEC2BCD(buf[i]);
67 67
68 pmu_write_multiple(0x59, sizeof(buf), buf); 68 pmu_write_rtc(buf);
69 69
70 return 0; 70 return 0;
71} 71}