Meizu: update backlight brightness curve so backlight is still on at the minimum...
[kugel-rb.git] / bootloader / samsung_yps3.c
blobba9f2d70e5f0eabf854cc4a27c194de820cf6de0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 by Bertrik Sikken
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <string.h>
27 #include "config.h"
29 #include "inttypes.h"
30 #include "cpu.h"
31 #include "system.h"
32 #include "lcd.h"
33 #include "kernel.h"
34 #include "thread.h"
35 #include "backlight.h"
36 #include "backlight-target.h"
37 #include "button.h"
38 #include "panic.h"
39 #include "power.h"
40 #include "common.h"
41 #include "usb.h"
42 #include "bitmaps/rockboxlogo.h"
44 #include "adc.h"
45 #include "adc-target.h"
47 #include "timer.h"
49 #include "i2c-s5l8700.h"
50 #include "dma-target.h"
51 #include "pcm.h"
52 #include "audiohw.h"
53 #include "rtc.h"
54 #include "tuner.h"
55 #include "si4700.h"
56 #include "fmradio_i2c.h"
58 char version[] = APPSVERSION;
59 #define LONG_DELAY 200000
60 #define SHORT_DELAY 50000
61 #define PAUSE_DELAY 50000
63 static inline void delay(unsigned int duration)
65 volatile unsigned int i;
66 for(i=0;i<duration;i++);
69 // forward declaration
70 static int rds_decode(int line, struct si4700_dbg_info *nfo);
72 static int count = 0;
74 static void timer_callback(void)
76 count++;
79 void main(void)
81 char mystring[64];
82 int line, col;
83 unsigned char read_data[16];
84 int i;
85 struct si4700_dbg_info si4700_info;
87 line = 1;
89 // enable all peripherals
90 PWRCON = 0;
92 // disable all interrupts
93 INTMSK = 0;
95 // start with all GPIOs as input
96 PCON0 = 0;
97 PCON1 = 0;
98 PCON2 = 0;
99 PCON3 = 0;
100 PCON4 = 0;
101 PCON5 = 0;
102 PCON6 = 0;
103 PCON7 = 0;
105 system_init();
106 kernel_init();
108 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
110 lcd_init();
112 lcd_clear_display();
113 lcd_bitmap(rockboxlogo, 0, 160, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
114 lcd_update();
116 power_init();
118 i2c_init();
119 fmradio_i2c_init();
120 adc_init();
121 _backlight_init();
123 timer_register(1, NULL, 3 * TIMER_FREQ, timer_callback);
125 // LED outputs
126 PCON3 = (PCON3 & ~(0x0000FF00)) | 0x00001100;
127 PDAT3 |= (1 << 2) | (1 << 3);
129 // FM power
130 si4700_init();
131 tuner_power(true);
132 si4700_set(RADIO_SLEEP, 0);
133 si4700_set(RADIO_MUTE, 0);
134 si4700_set(RADIO_FREQUENCY, 100700000);
136 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
138 while (true)
140 line = 1;
142 #if 1 /* enable to see GPIOs */
143 snprintf(mystring, 64, "%02X %02X %02X %02X %02X %02X %02X %02X", PDAT0, PDAT1, PDAT2, PDAT3, PDAT4, PDAT5, PDAT6, PDAT7);
144 lcd_puts(0, line++, mystring);
145 #endif
147 #if 1 /* enable this to see info about the RTC */
148 rtc_read_datetime(read_data);
149 snprintf(mystring, 64, "RTC:");
150 for (i = 0; i < 7; i++) {
151 snprintf(mystring + 2 * i + 4, 64, "%02X", read_data[i]);
153 lcd_puts(0, line++, mystring);
154 #endif
156 #if 0 /* enable this so see info about the codec */
157 memset(read_data, 0, sizeof(read_data));
158 for (i = 0; i < 1; i++) {
159 i2c_read(0x34, i, 2, read_data);
160 data = read_data[0] << 8 | read_data[1];
161 snprintf(mystring + 4 * i, 64, "%04X", data);
163 lcd_puts(0, line++, mystring);
164 #endif
166 #if 1 /* enable this to see radio debug info */
167 si4700_dbg_info(&si4700_info);
168 col = snprintf(mystring, 64, "FM: ");
169 for (i = 0; i < 16; i++) {
170 col += snprintf(mystring + col, 64, "%04X ", si4700_info.regs[i]);
171 if (((i + 1) % 4) == 0) {
172 lcd_puts(0, line++, mystring);
173 col = 4;
176 line = rds_decode(line, &si4700_info);
177 #endif
179 #if 1 /* enable this to see ADC info */
180 snprintf(mystring, 64, "%04X %04X %04X %04X", adc_read(0), adc_read(1), adc_read(2), adc_read(3));
181 lcd_puts(0, line++, mystring);
182 snprintf(mystring, 64, "ADC:USB %4d mV BAT %4d mV",
183 (adc_read(0) * 6000) >> 10, (adc_read(2) * 4650) >> 10);
184 lcd_puts(0, line++, mystring);
185 #endif
187 #if 1 /* enable this so see USB info */
188 snprintf(mystring, 64, "CLK %08X CLK2 %08X", CLKCON, CLKCON2);
189 lcd_puts(0, line++, mystring);
191 snprintf(mystring, 64, "%04X %04X %04X %04X", PHYCTRL, PHYPWR, URSTCON, UCLKCON);
192 lcd_puts(0, line++, mystring);
194 snprintf(mystring, 64, "SCR %04X SSR %04X EIR %04X", SCR, SSR, EIR);
195 lcd_puts(0, line++, mystring);
197 snprintf(mystring, 64, "FAR %04X FNR %04X EP0 %04X", FAR, FNR, EP0SR);
198 lcd_puts(0, line++, mystring);
199 #endif
201 #if 1 /* enable to see timer/counter info */
202 snprintf(mystring, 64, "TIMER: %08X", count);
203 lcd_puts(0, line++, mystring);
204 snprintf(mystring, 64, "current_tick: %08X", current_tick);
205 lcd_puts(0, line++, mystring);
206 snprintf(mystring, 64, "TIMER %04X %04X %04X", TDCON, TDPRE, TDDATA0);
207 lcd_puts(0, line++, mystring);
208 #endif
210 #if 1 /* enable this to control backlight brightness with the hold switch */
211 if (PDAT4 & (1 << 3)) {
212 _backlight_set_brightness(10);
213 PDAT3 &= ~(1 << 4);
215 else {
216 _backlight_set_brightness(15);
217 PDAT3 |= (1 << 4);
219 #endif
221 lcd_update();
226 static int rds_decode(int line, struct si4700_dbg_info *nfo)
228 unsigned short rdsdata[4];
229 unsigned int pi, group, tp, pty, segment, abflag;
230 static unsigned int af1 = 0, af2 = 0;
231 static unsigned int day = 0, hour = 0, minute = 0;
232 static unsigned int abflag_prev = -1;
233 static char mystring[64];
235 /* big RDS arrays */
236 static char ps[9];
237 static char rt[65];
239 rdsdata[0] = nfo->regs[12];
240 rdsdata[1] = nfo->regs[13];
241 rdsdata[2] = nfo->regs[14];
242 rdsdata[3] = nfo->regs[15];
244 pi = rdsdata[0];
245 group = (rdsdata[1] >> 11) & 0x1F;
246 tp = (rdsdata[1] >> 10) & 1;
247 pty = (rdsdata[1] >> 5) & 0x1F;
249 switch (group) {
251 case 0: /* group 0A: basic info */
252 af1 = (rdsdata[2] >> 8) & 0xFF;
253 af2 = (rdsdata[2] >> 0) & 0xFF;
254 /* fall through */
255 case 1: /* group 0B: basic info */
256 segment = rdsdata[1] & 3;
257 ps[segment * 2 + 0] = (rdsdata[3] >> 8) & 0xFF;
258 ps[segment * 2 + 1] = (rdsdata[3] >> 0) & 0xFF;
259 break;
261 case 2: /* group 1A: programme item */
262 case 3: /* group 1B: programme item */
263 day = (rdsdata[3] >> 11) & 0x1F;
264 hour = (rdsdata[3] >> 6) & 0x1F;
265 minute = (rdsdata[3] >> 0) & 0x3F;
266 break;
268 case 4: /* group 2A: radio text */
269 segment = rdsdata[1] & 0xF;
270 abflag = (rdsdata[1] >> 4) & 1;
271 if (abflag != abflag_prev) {
272 memset(rt, '.', 64);
273 abflag_prev = abflag;
275 rt[segment * 4 + 0] = (rdsdata[2] >> 8) & 0xFF;
276 rt[segment * 4 + 1] = (rdsdata[2] >> 0) & 0xFF;
277 rt[segment * 4 + 2] = (rdsdata[3] >> 8) & 0xFF;
278 rt[segment * 4 + 3] = (rdsdata[3] >> 0) & 0xFF;
279 break;
281 case 5: /* group 2B: radio text */
282 segment = rdsdata[1] & 0xF;
283 abflag = (rdsdata[1] >> 4) & 1;
284 if (abflag != abflag_prev) {
285 memset(rt, '.', 64);
286 abflag_prev = abflag;
288 rt[segment * 2 + 0] = (rdsdata[3] >> 8) & 0xFF;
289 rt[segment * 2 + 1] = (rdsdata[3] >> 0) & 0xFF;
290 break;
292 default:
293 break;
296 snprintf(mystring, 64, "PI:%04X,TP:%d,PTY:%2d,AF:%02X/%02X", pi, tp, pty, af1, af2);
297 lcd_puts(0, line++, mystring);
298 snprintf(mystring, 64, "PS:%s,ITEM:%02d-%02d:%02d", ps, day, hour, minute);
299 lcd_puts(0, line++, mystring);
300 snprintf(mystring, 64, "RT:%s", rt);
301 lcd_puts(0, line++, mystring);
303 return line;