summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 16:09:46 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 16:10:52 +0200
commit12c64a4b79e043d8e8d77a278b340310f867a588 (patch)
treeb34b56131d6eb0e06340a8a6d7e32843027d0f59 /firmware/target
parente09c1e3d43665d04ae0ce2f288ba695b5abc3622 (diff)
downloadrockbox-12c64a4b79e043d8e8d77a278b340310f867a588.tar.gz
rockbox-12c64a4b79e043d8e8d77a278b340310f867a588.zip
Initial commit for the Creative ZEN X-Fi2 and X-Fi3 ports
These are really similar devices so one commit for both is ok. Change-Id: I8bd1d3fef1eb6d00aaadfb7af56c771f62d0c9c3
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/adc-target.h32
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c40
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/audio-zenxfi2.c55
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/backlight-target.h29
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c58
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/button-target.h59
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c119
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/debug-zenxfi2.c28
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/lcd-target.h24
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/lcd-zenxfi2.c512
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c42
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/powermgmt-target.h60
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/powermgmt-zenxfi2.c46
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/adc-target.h32
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c40
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/audio-zenxfi3.c61
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/backlight-target.h33
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c85
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/button-target.h54
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/button-zenxfi3.c171
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/debug-zenxfi3.c28
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/lcd-target.h24
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/lcd-zenxfi3.c490
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c42
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/powermgmt-target.h58
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/powermgmt-zenxfi3.c46
-rw-r--r--firmware/target/arm/imx233/sd-imx233.c22
-rw-r--r--firmware/target/arm/system-arm.c2
-rw-r--r--firmware/target/hosted/sdl/sim-ui-defines.h7
29 files changed, 2298 insertions, 1 deletions
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/adc-target.h b/firmware/target/arm/imx233/creative-zenxfi2/adc-target.h
new file mode 100644
index 0000000000..79b281b892
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/adc-target.h
@@ -0,0 +1,32 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 _ADC_TARGET_H_
22#define _ADC_TARGET_H_
23
24#define NUM_ADC_CHANNELS 5
25
26#define ADC_BATTERY 0
27#define ADC_DIE_TEMP 1
28#define ADC_VDDIO 2
29#define ADC_5V 3
30#define ADC_BATT_TEMP 4
31
32#endif
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c
new file mode 100644
index 0000000000..50ed498cc6
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 "adc-target.h"
22#include "adc-imx233.h"
23
24int imx233_adc_mapping[] =
25{
26 [ADC_BATTERY] = IMX233_ADC_BATTERY,
27 [ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
28 [ADC_VDDIO] = IMX233_ADC_VDDIO,
29 [ADC_5V] = HW_LRADC_CHANNEL_5V,
30 [ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
31};
32
33const char *imx233_adc_channel_name[] =
34{
35 "Battery(raw)",
36 "Die temperature(°C)",
37 "VddIO",
38 "Vdd5V",
39 "Battery temperature(raw)",
40};
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/audio-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/audio-zenxfi2.c
new file mode 100644
index 0000000000..810f1c156f
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/audio-zenxfi2.c
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 "system.h"
23#include "audiohw.h"
24#include "audio.h"
25#include "audioout-imx233.h"
26#include "audioin-imx233.h"
27
28static int input_source = AUDIO_SRC_PLAYBACK;
29static unsigned input_flags = 0;
30static int output_source = AUDIO_SRC_PLAYBACK;
31
32static void select_audio_path(void)
33{
34 if(input_source == AUDIO_SRC_PLAYBACK)
35 imx233_audioout_select_hp_input(false);
36 else
37 imx233_audioout_select_hp_input(true);
38}
39
40void audio_input_mux(int source, unsigned flags)
41{
42 (void) source;
43 (void) flags;
44 input_source = source;
45 input_flags = flags;
46 select_audio_path();
47}
48
49void audio_set_output_source(int source)
50{
51 (void) source;
52 output_source = source;
53 select_audio_path();
54}
55
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/backlight-target.h b/firmware/target/arm/imx233/creative-zenxfi2/backlight-target.h
new file mode 100644
index 0000000000..e3766965d8
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/backlight-target.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 BACKLIGHT_TARGET_H
22#define BACKLIGHT_TARGET_H
23
24bool _backlight_init(void);
25void _backlight_on(void);
26void _backlight_off(void);
27void _backlight_set_brightness(int brightness);
28
29#endif /* BACKLIGHT_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c
new file mode 100644
index 0000000000..8fcdd8ba32
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c
@@ -0,0 +1,58 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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
22#include "config.h"
23#include "system.h"
24#include "lcd.h"
25#include "backlight.h"
26#include "backlight-target.h"
27#include "pwm-imx233.h"
28
29void _backlight_set_brightness(int brightness)
30{
31 imx233_pwm_setup_channel(4, 1024, HW_PWM_PERIODx__CDIV__DIV_1,
32 0, HW_PWM_PERIODx__STATE__HIGH,
33 (brightness * 1024) / 100, HW_PWM_PERIODx__STATE__LOW);
34 imx233_pwm_enable_channel(4, true);
35}
36
37bool _backlight_init(void)
38{
39 _backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING);
40 return true;
41}
42
43void _backlight_on(void)
44{
45#ifdef HAVE_LCD_ENABLE
46 lcd_enable(true); /* power on lcd + visible display */
47#endif
48 /* don't do anything special, the core will set the brightness */
49}
50
51void _backlight_off(void)
52{
53 /* there is no real on/off but we can set to 0 brightness */
54 _backlight_set_brightness(0);
55#ifdef HAVE_LCD_ENABLE
56 lcd_enable(false); /* power off visible display */
57#endif
58}
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/button-target.h b/firmware/target/arm/imx233/creative-zenxfi2/button-target.h
new file mode 100644
index 0000000000..8f4cda85d8
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/button-target.h
@@ -0,0 +1,59 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 _BUTTON_TARGET_H_
22#define _BUTTON_TARGET_H_
23
24#include <stdbool.h>
25#include "config.h"
26
27void button_init_device(void);
28int button_read_device(int *data);
29bool button_debug_screen(void);
30
31/* Main unit's buttons */
32#define BUTTON_POWER 0x00000001
33#define BUTTON_MENU 0x00000002
34/* For compatibility */
35#define BUTTON_LEFT BUTTON_MIDLEFT
36#define BUTTON_RIGHT BUTTON_MIDRIGHT
37#define BUTTON_UP BUTTON_TOPMIDDLE
38#define BUTTON_DOWN BUTTON_BOTTOMMIDDLE
39
40/* Touch Screen Area Buttons */
41#define BUTTON_TOPLEFT 0x00000010
42#define BUTTON_TOPMIDDLE 0x00000020
43#define BUTTON_TOPRIGHT 0x00000040
44#define BUTTON_MIDLEFT 0x00000080
45#define BUTTON_CENTER 0x00000100
46#define BUTTON_MIDRIGHT 0x00000200
47#define BUTTON_BOTTOMLEFT 0x00000400
48#define BUTTON_BOTTOMMIDDLE 0x00000800
49#define BUTTON_BOTTOMRIGHT 0x00001000
50
51#define BUTTON_MAIN 0x1fff
52
53#define BUTTON_REMOTE 0
54
55/* Software power-off */
56#define POWEROFF_BUTTON BUTTON_POWER
57#define POWEROFF_COUNT 10
58
59#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c
new file mode 100644
index 0000000000..d6a4209292
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c
@@ -0,0 +1,119 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 "button-target.h"
22#include "system.h"
23#include "system-target.h"
24#include "pinctrl-imx233.h"
25#include "power-imx233.h"
26#include "string.h"
27#include "usb.h"
28#include "touchscreen.h"
29#include "touchscreen-imx233.h"
30
31struct touch_calibration_point
32{
33 short px_x; /* known pixel value */
34 short px_y;
35 short val_x; /* touchscreen value at the known pixel */
36 short val_y;
37};
38
39static struct touch_calibration_point topleft, bottomright;
40
41/* Amaury Pouly: values on my device
42 * Portait: (x and y are swapped)
43 * (0,0) = 200, 300
44 * (240,400) = 3900, 3800
45 * Landscape:
46 * (0,0) = 200, 3800
47 * (400,240) = 3900, 300
48*/
49void button_init_device(void)
50{
51#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
52 topleft.val_x = 300;
53 topleft.val_y = 200;
54
55 bottomright.val_x = 3800;
56 bottomright.val_y = 3900;
57#else
58 topleft.val_x = 300;
59 topleft.val_y = 3900;
60
61 bottomright.val_x = 3800;
62 bottomright.val_y = 200;
63#endif
64 topleft.px_x = 0;
65 topleft.px_y = 0;
66
67 bottomright.px_x = LCD_WIDTH;
68 bottomright.px_y = LCD_HEIGHT;
69
70 imx233_touchscreen_init();
71 imx233_touchscreen_enable(true);
72}
73
74static int touch_to_pixels(int *val_x, int *val_y)
75{
76 short x,y;
77
78#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
79 x = *val_y;
80 y = *val_x;
81#else
82 x = *val_x;
83 y = *val_y;
84#endif
85
86 x = (x - topleft.val_x) * (bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x;
87 y = (y - topleft.val_y) * (bottomright.px_y - topleft.px_y) / (bottomright.val_y - topleft.val_y) + topleft.px_y;
88
89 x = MAX(0, MIN(x, LCD_WIDTH - 1));
90 y = MAX(0, MIN(y, LCD_HEIGHT - 1));
91
92 *val_x = x;
93 *val_y = y;
94
95 return (x<<16)|y;
96}
97
98static int touchscreen_read_device(int *data)
99{
100 int x, y;
101 if(!imx233_touchscreen_get_touch(&x, &y))
102 return 0;
103 if(data)
104 *data = touch_to_pixels(&x, &y);
105 return touchscreen_to_pixels(x, y, data);
106}
107
108int button_read_device(int *data)
109{
110 int res = 0;
111 /* B0P11: #power
112 * B0P14: #select */
113 uint32_t mask = imx233_get_gpio_input_mask(0, 0x4800);
114 if(!(mask & 0x800))
115 res |= BUTTON_POWER;
116 if(!(mask & 0x4000))
117 res |= BUTTON_MENU;
118 return res | touchscreen_read_device(data);
119}
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/debug-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/debug-zenxfi2.c
new file mode 100644
index 0000000000..a18704243e
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/debug-zenxfi2.c
@@ -0,0 +1,28 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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
22#include "system.h"
23#include "button-target.h"
24
25bool dbg_hw_target_info(void)
26{
27 return false;
28}
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/lcd-target.h b/firmware/target/arm/imx233/creative-zenxfi2/lcd-target.h
new file mode 100644
index 0000000000..5c1ecdd406
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/lcd-target.h
@@ -0,0 +1,24 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2011 by Amaury Pouly
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 LCD_TARGET_H
22#define LCD_TARGET_H
23
24#endif /* LCD_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/lcd-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/lcd-zenxfi2.c
new file mode 100644
index 0000000000..277c7120e1
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/lcd-zenxfi2.c
@@ -0,0 +1,512 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2011 by Amaury Pouly
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 <sys/types.h> /* off_t */
22#include <string.h>
23#include "cpu.h"
24#include "system.h"
25#include "backlight-target.h"
26#include "lcd.h"
27#include "lcdif-imx233.h"
28#include "clkctrl-imx233.h"
29#include "pinctrl-imx233.h"
30#include "logf.h"
31
32#ifdef HAVE_LCD_ENABLE
33static bool lcd_on;
34#endif
35static unsigned lcd_yuv_options = 0;
36
37static void setup_parameters(void)
38{
39 imx233_lcdif_reset();
40 imx233_lcdif_set_lcd_databus_width(HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_18_BIT);
41 imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_18_BIT);
42 imx233_lcdif_set_timings(2, 2, 3, 3);
43}
44
45static void setup_lcd_pins(bool use_lcdif)
46{
47 if(use_lcdif)
48 {
49 imx233_set_pin_function(1, 25, PINCTRL_FUNCTION_MAIN); /* lcd_vsync */
50 imx233_set_pin_function(1, 21, PINCTRL_FUNCTION_MAIN); /* lcd_cs */
51 imx233_set_pin_function(1, 22, PINCTRL_FUNCTION_MAIN); /* lcd_dotclk */
52 imx233_set_pin_function(1, 23, PINCTRL_FUNCTION_MAIN); /* lcd_enable */
53 imx233_set_pin_function(1, 24, PINCTRL_FUNCTION_MAIN); /* lcd_hsync */
54 imx233_set_pin_function(1, 18, PINCTRL_FUNCTION_MAIN); /* lcd_reset */
55 imx233_set_pin_function(1, 19, PINCTRL_FUNCTION_MAIN); /* lcd_rs */
56 imx233_set_pin_function(1, 16, PINCTRL_FUNCTION_MAIN); /* lcd_d16 */
57 imx233_set_pin_function(1, 17, PINCTRL_FUNCTION_MAIN); /* lcd_d17 */
58 imx233_set_pin_function(1, 20, PINCTRL_FUNCTION_MAIN); /* lcd_wr */
59 __REG_CLR(HW_PINCTRL_MUXSEL(2)) = 0xffffffff; /* lcd_d{0-15} */
60 }
61 else
62 {
63 __REG_SET(HW_PINCTRL_MUXSEL(2)) = 0xffffffff; /* lcd_d{0-15} */
64 imx233_enable_gpio_output_mask(1, 0x3ffffff, false); /* lcd_{d{0-17},reset,rs,wr,cs,dotclk,enable,hsync,vsync} */
65 imx233_set_pin_function(1, 16, PINCTRL_FUNCTION_GPIO); /* lcd_d16 */
66 imx233_set_pin_function(1, 17, PINCTRL_FUNCTION_GPIO); /* lcd_d17 */
67 imx233_set_pin_function(1, 19, PINCTRL_FUNCTION_GPIO); /* lcd_rs */
68 imx233_set_pin_function(1, 20, PINCTRL_FUNCTION_GPIO); /* lcd_wr */
69 imx233_set_pin_function(1, 21, PINCTRL_FUNCTION_GPIO); /* lcd_cs */
70 imx233_set_pin_function(1, 22, PINCTRL_FUNCTION_GPIO); /* lcd_dotclk */
71 imx233_set_pin_function(1, 23, PINCTRL_FUNCTION_GPIO); /* lcd_enable */
72 imx233_set_pin_function(1, 24, PINCTRL_FUNCTION_GPIO); /* lcd_hsync */
73 imx233_set_pin_function(1, 25, PINCTRL_FUNCTION_GPIO); /* lcd_vsync */
74 }
75}
76
77static void common_lcd_enable(bool enable)
78{
79 imx233_lcdif_enable(enable);
80 setup_lcd_pins(enable); /* use GPIO pins when disable */
81}
82
83static void setup_lcdif(void)
84{
85 setup_parameters();
86 common_lcd_enable(true);
87 imx233_lcdif_enable_bus_master(true);
88}
89
90static inline uint32_t encode_16_to_18(uint32_t a)
91{
92 return ((a & 0xff) << 1) | (((a >> 8) & 0xff) << 10);
93}
94
95static inline uint32_t decode_18_to_16(uint32_t a)
96{
97 return ((a >> 1) & 0xff) | ((a >> 2) & 0xff00);
98}
99
100static void setup_lcdif_clock(void)
101{
102 /* the LCD seems to work at 24Mhz, so use the xtal clock with no divider */
103 imx233_clkctrl_enable_clock(CLK_PIX, false);
104 imx233_clkctrl_set_clock_divisor(CLK_PIX, 1);
105 imx233_clkctrl_set_bypass_pll(CLK_PIX, true); /* use XTAL */
106 imx233_clkctrl_enable_clock(CLK_PIX, true);
107}
108
109static void lcd_write_reg(uint32_t reg, uint32_t data)
110{
111 uint32_t old_reg = reg;
112 /* get back to 18-bit word length */
113 imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_18_BIT);
114 reg = encode_16_to_18(reg);
115 data = encode_16_to_18(data);
116
117 imx233_lcdif_pio_send(false, 2, &reg);
118 if(old_reg != 0 && old_reg != 0x202)
119 imx233_lcdif_pio_send(true, 2, &data);
120}
121
122#define REG_MDELAY 0xffffffff
123struct lcd_sequence_entry_t
124{
125 uint32_t reg, data;
126};
127
128static void lcd_send_sequence(struct lcd_sequence_entry_t *seq, unsigned count)
129{
130 for(;count-- > 0; seq++)
131 {
132 if(seq->reg == REG_MDELAY)
133 mdelay(seq->data);
134 else
135 lcd_write_reg(seq->reg, seq->data);
136 }
137}
138
139#define _begin_seq() static struct lcd_sequence_entry_t __seq[] = {
140#define _mdelay(a) {REG_MDELAY, a},
141#define _lcd_write_reg(a, b) {a, b},
142#define _end_seq() }; lcd_send_sequence(__seq, sizeof(__seq) / sizeof(__seq[0]));
143
144static void lcd_init_seq(void)
145{
146 _begin_seq()
147 _lcd_write_reg(0, 0)
148 _lcd_write_reg(0, 0)
149 _lcd_write_reg(0, 0)
150 _lcd_write_reg(0, 0)
151 _mdelay(100)
152 _lcd_write_reg(8, 0x808)
153 _lcd_write_reg(0x10, 0x10)
154 _lcd_write_reg(0x400, 0x6200)
155 _lcd_write_reg(0x300, 0xc0a)
156 _lcd_write_reg(0x301, 0x4c11)
157 _lcd_write_reg(0x302, 0x906)
158 _lcd_write_reg(0x303, 0x1417)
159 _lcd_write_reg(0x304, 0x3333)
160 _lcd_write_reg(0x305, 0x150d)
161 _lcd_write_reg(0x306, 0x740a)
162 _lcd_write_reg(0x307, 0x100c)
163 _lcd_write_reg(0x308, 0x60c)
164 _lcd_write_reg(0x309, 0)
165 _lcd_write_reg(0x100, 0x730)
166 _lcd_write_reg(0x101, 0x237)
167 _lcd_write_reg(0x103, 0x2b00)
168 _lcd_write_reg(0x280, 0x4000)
169 _lcd_write_reg(0x102, 0x81b0)
170 _mdelay(400)
171 _lcd_write_reg(1, 0x100)
172 _lcd_write_reg(2, 0x100)
173 _lcd_write_reg(3, 0x5028)
174 _lcd_write_reg(9, 1)
175 _lcd_write_reg(0xc, 0)
176 _lcd_write_reg(0x11, 0x202)
177 _lcd_write_reg(0x12, 0x101)
178 _lcd_write_reg(0x13, 1)
179 _lcd_write_reg(0x90, 0x8000)
180 _lcd_write_reg(0x210, 0)
181 _lcd_write_reg(0x211, 0xef)
182 _lcd_write_reg(0x212, 0)
183 _lcd_write_reg(0x213, 0x18f)
184 _lcd_write_reg(0x200, 0)
185 _lcd_write_reg(0x201, 0)
186 _lcd_write_reg(0x401, 1)
187 _lcd_write_reg(0x404, 0)
188 _mdelay(400)
189 _lcd_write_reg(7, 0x100)
190 _mdelay(400)
191 _lcd_write_reg(3, 0x1030)
192 _end_seq()
193}
194
195void lcd_init_device(void)
196{
197 setup_lcdif();
198 setup_lcdif_clock();
199
200 // reset device
201 __REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
202 mdelay(50);
203 __REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
204 mdelay(10);
205 __REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
206
207 lcd_init_seq();
208#ifdef HAVE_LCD_ENABLE
209 lcd_on = true;
210#endif
211}
212
213#ifdef HAVE_LCD_ENABLE
214bool lcd_active(void)
215{
216 return lcd_on;
217}
218
219static void lcd_enable_seq(bool enable)
220{
221 if(!enable)
222 {
223 _begin_seq()
224 _end_seq()
225 }
226 else
227 {
228 _begin_seq()
229 _end_seq()
230 }
231}
232
233void lcd_enable(bool enable)
234{
235 if(lcd_on == enable)
236 return;
237
238 lcd_on = enable;
239
240 if(enable)
241 common_lcd_enable(true);
242 lcd_enable_seq(enable);
243 if(!enable)
244 common_lcd_enable(false);
245}
246#endif
247
248void lcd_update(void)
249{
250 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
251}
252
253void lcd_update_rect(int x, int y, int w, int h)
254{
255#ifdef HAVE_LCD_ENABLE
256 if(!lcd_on)
257 return;
258#endif
259 /* make sure the rectangle is included in the screen */
260 x = MIN(x, LCD_WIDTH);
261 y = MIN(y, LCD_HEIGHT);
262 w = MIN(w, LCD_WIDTH - x);
263 h = MIN(h, LCD_HEIGHT - y);
264
265 imx233_lcdif_wait_ready();
266 lcd_write_reg(0x210, x);
267 lcd_write_reg(0x211, x + w - 1);
268 lcd_write_reg(0x212, y);
269 lcd_write_reg(0x213, y + h - 1);
270 lcd_write_reg(0x200, 0);
271 lcd_write_reg(0x201, 0);
272 lcd_write_reg(0x202, 0);
273 imx233_lcdif_wait_ready();
274 imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
275 imx233_lcdif_set_byte_packing_format(0xf); /* two pixels per 32-bit word */
276 imx233_lcdif_set_data_format(false, false, false); /* RGB565, don't care, don't care */
277
278 /* there are two cases here:
279 * - either width = LCD_WIDTH and we can directly memcopy a part of lcd_framebuffer to FRAME
280 * and send it
281 * - either width != LCD_WIDTH and we have to build a contiguous copy of the rectangular area
282 * into FRAME before sending it (which is slower and doesn't use the hardware)
283 * In all cases, FRAME just acts as a temporary buffer.
284 * NOTE It's more interesting to do a copy to FRAME in all cases since in system mode
285 * the clock runs at 24MHz which provides barely 10MB/s bandwidth compared to >100MB/s
286 * for memcopy operations
287 */
288 if(w == LCD_WIDTH)
289 {
290 memcpy((void *)FRAME, FBADDR(x,y), w * h * sizeof(fb_data));
291 }
292 else
293 {
294 for(int i = 0; i < h; i++)
295 memcpy((fb_data *)FRAME + i * w, FBADDR(x,y + i), w * sizeof(fb_data));
296 }
297 /* WARNING The LCDIF has a limitation on the vertical count ! In 16-bit packed mode
298 * (which we used, ie 16-bit per pixel, 2 pixels per 32-bit words), the v_count
299 * field must be a multiple of 2. Furthermore, it seems the lcd controller doesn't
300 * really like when both w and h are even, probably because the writes to the GRAM
301 * are done on several words and the controller requires dummy writes.
302 * The workaround is to always make sure that we send a number of pixels which is
303 * a multiple of 4 so that both the lcdif and the controller are happy. If any
304 * of w or h is odd, we will send a copy of the first pixels as dummy writes. We will
305 * send at most 3 bytes. We then send (w * h + 3) / 4 x 4 bytes.
306 */
307 if(w % 2 == 1 || h % 2 == 1)
308 {
309 /* copy three pixel after the last one */
310 for(int i = 0; i < 3; i++)
311 *((fb_data *)FRAME + w * h + i) = *((fb_data *)FRAME + i);
312 /* WARNING we need to update w and h to reflect the pixel count BUT it
313 * has no relation to w * h (it can even be 2 * prime). Hopefully, w <= 240 and
314 * h <= 320 so w * h <= 76800 and (w * h + 3) / 4 <= 38400 which fits into
315 * a 16-bit integer (horizontal count). */
316 h = (w * h + 3) / 4;
317 w = 4;
318 }
319 imx233_lcdif_dma_send((void *)FRAME_PHYS_ADDR, w, h);
320}
321
322void lcd_yuv_set_options(unsigned options)
323{
324 lcd_yuv_options = options;
325}
326
327#define YFAC (74)
328#define RVFAC (101)
329#define GUFAC (-24)
330#define GVFAC (-51)
331#define BUFAC (128)
332
333static inline int clamp(int val, int min, int max)
334{
335 if (val < min)
336 val = min;
337 else if (val > max)
338 val = max;
339 return val;
340}
341
342void lcd_blit_yuv(unsigned char * const src[3],
343 int src_x, int src_y, int stride,
344 int x, int y, int width, int height)
345{
346 const unsigned char *ysrc, *usrc, *vsrc;
347 int linecounter;
348 fb_data *dst, *row_end;
349 long z;
350
351 /* width and height must be >= 2 and an even number */
352 width &= ~1;
353 linecounter = height >> 1;
354
355 #if LCD_WIDTH >= LCD_HEIGHT
356 dst = FBADDR(x,y);
357 row_end = dst + width;
358 #else
359 dst = FBADDR(LCD_WIDTH - y - 1,x);
360 row_end = dst + LCD_WIDTH * width;
361 #endif
362
363 z = stride * src_y;
364 ysrc = src[0] + z + src_x;
365 usrc = src[1] + (z >> 2) + (src_x >> 1);
366 vsrc = src[2] + (usrc - src[1]);
367
368 /* stride => amount to jump from end of last row to start of next */
369 stride -= width;
370
371 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
372
373 do
374 {
375 do
376 {
377 int y, cb, cr, rv, guv, bu, r, g, b;
378
379 y = YFAC*(*ysrc++ - 16);
380 cb = *usrc++ - 128;
381 cr = *vsrc++ - 128;
382
383 rv = RVFAC*cr;
384 guv = GUFAC*cb + GVFAC*cr;
385 bu = BUFAC*cb;
386
387 r = y + rv;
388 g = y + guv;
389 b = y + bu;
390
391 if ((unsigned)(r | g | b) > 64*256-1)
392 {
393 r = clamp(r, 0, 64*256-1);
394 g = clamp(g, 0, 64*256-1);
395 b = clamp(b, 0, 64*256-1);
396 }
397
398 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
399
400 #if LCD_WIDTH >= LCD_HEIGHT
401 dst++;
402 #else
403 dst += LCD_WIDTH;
404 #endif
405
406 y = YFAC*(*ysrc++ - 16);
407 r = y + rv;
408 g = y + guv;
409 b = y + bu;
410
411 if ((unsigned)(r | g | b) > 64*256-1)
412 {
413 r = clamp(r, 0, 64*256-1);
414 g = clamp(g, 0, 64*256-1);
415 b = clamp(b, 0, 64*256-1);
416 }
417
418 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
419
420 #if LCD_WIDTH >= LCD_HEIGHT
421 dst++;
422 #else
423 dst += LCD_WIDTH;
424 #endif
425 }
426 while (dst < row_end);
427
428 ysrc += stride;
429 usrc -= width >> 1;
430 vsrc -= width >> 1;
431
432 #if LCD_WIDTH >= LCD_HEIGHT
433 row_end += LCD_WIDTH;
434 dst += LCD_WIDTH - width;
435 #else
436 row_end -= 1;
437 dst -= LCD_WIDTH*width + 1;
438 #endif
439
440 do
441 {
442 int y, cb, cr, rv, guv, bu, r, g, b;
443
444 y = YFAC*(*ysrc++ - 16);
445 cb = *usrc++ - 128;
446 cr = *vsrc++ - 128;
447
448 rv = RVFAC*cr;
449 guv = GUFAC*cb + GVFAC*cr;
450 bu = BUFAC*cb;
451
452 r = y + rv;
453 g = y + guv;
454 b = y + bu;
455
456 if ((unsigned)(r | g | b) > 64*256-1)
457 {
458 r = clamp(r, 0, 64*256-1);
459 g = clamp(g, 0, 64*256-1);
460 b = clamp(b, 0, 64*256-1);
461 }
462
463 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
464
465 #if LCD_WIDTH >= LCD_HEIGHT
466 dst++;
467 #else
468 dst += LCD_WIDTH;
469 #endif
470
471 y = YFAC*(*ysrc++ - 16);
472 r = y + rv;
473 g = y + guv;
474 b = y + bu;
475
476 if ((unsigned)(r | g | b) > 64*256-1)
477 {
478 r = clamp(r, 0, 64*256-1);
479 g = clamp(g, 0, 64*256-1);
480 b = clamp(b, 0, 64*256-1);
481 }
482
483 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
484
485 #if LCD_WIDTH >= LCD_HEIGHT
486 dst++;
487 #else
488 dst += LCD_WIDTH;
489 #endif
490 }
491 while (dst < row_end);
492
493 ysrc += stride;
494 usrc += stride >> 1;
495 vsrc += stride >> 1;
496
497 #if LCD_WIDTH >= LCD_HEIGHT
498 row_end += LCD_WIDTH;
499 dst += LCD_WIDTH - width;
500 #else
501 row_end -= 1;
502 dst -= LCD_WIDTH*width + 1;
503 #endif
504 }
505 while (--linecounter > 0);
506
507 #if LCD_WIDTH >= LCD_HEIGHT
508 lcd_update_rect(x, y, width, height);
509 #else
510 lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
511 #endif
512}
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c
new file mode 100644
index 0000000000..180b7f9d4c
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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
22#include "system.h"
23#include "power.h"
24#include "tuner.h"
25#include "fmradio_i2c.h"
26#include "pinctrl-imx233.h"
27
28static bool tuner_enable = false;
29
30bool tuner_power(bool enable)
31{
32 if(enable != tuner_enable)
33 {
34 tuner_enable = enable;
35 }
36 return tuner_enable;
37}
38
39bool tuner_powered(void)
40{
41 return tuner_enable;
42}
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/powermgmt-target.h b/firmware/target/arm/imx233/creative-zenxfi2/powermgmt-target.h
new file mode 100644
index 0000000000..6790772704
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/powermgmt-target.h
@@ -0,0 +1,60 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 POWERMGMT_TARGET_H
22#define POWERMGMT_TARGET_H
23
24#include "config.h"
25#include "powermgmt-imx233.h"
26
27/* Creative ZEN X-Fi2 OF settings:
28 * - current ramp slope: 100 mA/s
29 * - conditioning threshold voltage: 3 V
30 * - conditioning max voltage: 3.1 V
31 * - conditioning current: 60 mA
32 * - conditioning timeout: 1 h
33 * - charging voltage: 4.2 V
34 * - charging current: 550 mA
35 * - charging threshold current: 60 mA
36 * - charging timeout: 4 h
37 * - top off period: 30 min
38 * - high die temperature: 74 °C
39 * - low die temperature: 56 °C
40 * - safe die temperature current: 30 mA
41 * - battery temperature channel: 1
42 * - high battery temperature: 440
43 * - low battery temperature: 605
44 * - safe battery temperature current: 0 mA
45 * - low DCDC battery voltage: 3.9 V
46 *
47 * FIXME is this an OF bug that low batt temp > high batt temp ?
48 */
49
50#define IMX233_CHARGE_CURRENT 550
51#define IMX233_STOP_CURRENT 60
52#define IMX233_TOPOFF_TIMEOUT (30 * 60 * HZ)
53#define IMX233_CHARGING_TIMEOUT (4 * 3600 * HZ)
54#define IMX233_DIE_TEMP_HIGH 74
55#define IMX233_DIE_TEMP_LOW 56
56#define IMX233_BATT_TEMP_SENSOR 1
57#define IMX233_BATT_TEMP_HIGH 440
58#define IMX233_BATT_TEMP_LOW 605
59
60#endif /* POWERMGMT_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/powermgmt-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/powermgmt-zenxfi2.c
new file mode 100644
index 0000000000..3e068f007d
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi2/powermgmt-zenxfi2.c
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 "powermgmt-target.h"
23
24const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
25{
26 3659
27};
28
29const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
30{
31 3630
32};
33
34/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
35const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
36{
37 /* Toshiba Gigabeat S Li Ion 700mAH figured from discharge curve */
38 { 3659, 3719, 3745, 3761, 3785, 3813, 3856, 3926, 3984, 4040, 4121 },
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
42const unsigned short percent_to_volt_charge[11] =
43{
44 /* Toshiba Gigabeat S Li Ion 700mAH figured from charge curve */
45 4028, 4063, 4087, 4111, 4135, 4156, 4173, 4185, 4194, 4202, 4208
46};
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/adc-target.h b/firmware/target/arm/imx233/creative-zenxfi3/adc-target.h
new file mode 100644
index 0000000000..d946989c1c
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/adc-target.h
@@ -0,0 +1,32 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 _ADC_TARGET_H_
22#define _ADC_TARGET_H_
23
24#define NUM_ADC_CHANNELS 5
25
26#define ADC_BATTERY 0
27#define ADC_DIE_TEMP 1
28#define ADC_VDDIO 2
29#define ADC_5V 3
30#define ADC_BATT_TEMP 4
31
32#endif
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c
new file mode 100644
index 0000000000..6671c7202e
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 "adc-target.h"
22#include "adc-imx233.h"
23
24int imx233_adc_mapping[] =
25{
26 [ADC_BATTERY] = IMX233_ADC_BATTERY,
27 [ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
28 [ADC_VDDIO] = IMX233_ADC_VDDIO,
29 [ADC_5V] = HW_LRADC_CHANNEL_5V,
30 [ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
31};
32
33const char *imx233_adc_channel_name[] =
34{
35 "Battery(raw)",
36 "Die temperature(°C)",
37 "VddIO",
38 "Vdd5V",
39 "Battery temperature(raw)",
40};
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/audio-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/audio-zenxfi3.c
new file mode 100644
index 0000000000..faf15242ab
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/audio-zenxfi3.c
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 "system.h"
23#include "audiohw.h"
24#include "audio.h"
25#include "audioout-imx233.h"
26#include "audioin-imx233.h"
27#include "pinctrl-imx233.h"
28
29static int input_source = AUDIO_SRC_PLAYBACK;
30static unsigned input_flags = 0;
31static int output_source = AUDIO_SRC_PLAYBACK;
32
33static void select_audio_path(void)
34{
35 /* route audio to HP */
36 imx233_set_pin_function(1, 30, PINCTRL_FUNCTION_GPIO);
37 imx233_enable_gpio_output(1, 30, true);
38 imx233_set_gpio_output(1, 30, true);
39
40 if(input_source == AUDIO_SRC_PLAYBACK)
41 imx233_audioout_select_hp_input(false);
42 else
43 imx233_audioout_select_hp_input(true);
44}
45
46void audio_input_mux(int source, unsigned flags)
47{
48 (void) source;
49 (void) flags;
50 input_source = source;
51 input_flags = flags;
52 select_audio_path();
53}
54
55void audio_set_output_source(int source)
56{
57 (void) source;
58 output_source = source;
59 select_audio_path();
60}
61
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/backlight-target.h b/firmware/target/arm/imx233/creative-zenxfi3/backlight-target.h
new file mode 100644
index 0000000000..c7508c87a3
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/backlight-target.h
@@ -0,0 +1,33 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 BACKLIGHT_TARGET_H
22#define BACKLIGHT_TARGET_H
23
24bool _backlight_init(void);
25void _backlight_on(void);
26void _backlight_off(void);
27void _backlight_set_brightness(int brightness);
28
29void _buttonlight_on(void);
30void _buttonlight_off(void);
31void _buttonlight_set_brightness(int brightness);
32
33#endif /* BACKLIGHT_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c
new file mode 100644
index 0000000000..59c3c133aa
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c
@@ -0,0 +1,85 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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
22#include "config.h"
23#include "system.h"
24#include "lcd.h"
25#include "backlight.h"
26#include "backlight-target.h"
27#include "pwm-imx233.h"
28#include "mpr121.h"
29
30void _backlight_set_brightness(int brightness)
31{
32 imx233_pwm_setup_channel(2, 1024, HW_PWM_PERIODx__CDIV__DIV_1,
33 0, HW_PWM_PERIODx__STATE__HIGH,
34 (brightness * 1024) / 100, HW_PWM_PERIODx__STATE__LOW);
35 imx233_pwm_enable_channel(2, true);
36}
37
38bool _backlight_init(void)
39{
40 _backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING);
41 return true;
42}
43
44void _backlight_on(void)
45{
46#ifdef HAVE_LCD_ENABLE
47 lcd_enable(true); /* power on lcd + visible display */
48#endif
49 /* don't do anything special, the core will set the brightness */
50}
51
52void _backlight_off(void)
53{
54 /* there is no real on/off but we can set to 0 brightness */
55 _backlight_set_brightness(0);
56#ifdef HAVE_LCD_ENABLE
57 lcd_enable(false); /* power off visible display */
58#endif
59}
60
61/* ELE8 is the button light GPIO */
62void _buttonlight_on(void)
63{
64 /* assume mpr121 was initialized by button-zenxfi3.c */
65 mpr121_set_gpio_output(8, ELE_GPIO_SET);
66}
67
68void _buttonlight_off(void)
69{
70 /* assume mpr121 was initialized by button-zenxfi3.c */
71 mpr121_set_gpio_output(8, ELE_GPIO_CLR);
72}
73
74void _buttonlight_set_brightness(int brightness)
75{
76 /* assume mpr121 was initialized by button-zenxfi3.c */
77 /* since backlight brightness is the same for the screen and the button light,
78 * map [MIN_BRIGHTNESS_SETTING,MAX_BRIGHTNESS_SETTING] to
79 * [ELE_PWM_MIN_DUTY,ELE_PWM_MAX_DUTY] */
80 brightness = ELE_PWM_MIN_DUTY + (brightness - MIN_BRIGHTNESS_SETTING) *
81 (ELE_PWM_MAX_DUTY - ELE_PWM_MIN_DUTY + 1) /
82 (MAX_BRIGHTNESS_SETTING - MIN_BRIGHTNESS_SETTING + 1);
83 brightness = MIN(brightness, ELE_PWM_MAX_DUTY);
84 mpr121_set_gpio_pwm(8, brightness);
85}
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/button-target.h b/firmware/target/arm/imx233/creative-zenxfi3/button-target.h
new file mode 100644
index 0000000000..202e695eb3
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/button-target.h
@@ -0,0 +1,54 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 _BUTTON_TARGET_H_
22#define _BUTTON_TARGET_H_
23
24#include <stdbool.h>
25#include "config.h"
26
27void button_init_device(void);
28int button_read_device(void);
29bool button_debug_screen(void);
30
31#define HAS_BUTTON_HOLD
32
33/* Main unit's buttons */
34#define BUTTON_POWER 0x00000001
35#define BUTTON_MENU 0x00000002
36#define BUTTON_BACK 0x00000004
37#define BUTTON_PLAY 0x00000008
38#define BUTTON_UP 0x00000010
39#define BUTTON_DOWN 0x00000020
40#define BUTTON_VOL_UP 0x00000040
41#define BUTTON_VOL_DOWN 0x00000080
42/* For compatibility */
43#define BUTTON_LEFT BUTTON_BACK
44#define BUTTON_RIGHT BUTTON_PLAY
45
46#define BUTTON_MAIN 0xff
47
48#define BUTTON_REMOTE 0
49
50/* Software power-off */
51#define POWEROFF_BUTTON BUTTON_POWER
52#define POWEROFF_COUNT 10
53
54#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/button-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/button-zenxfi3.c
new file mode 100644
index 0000000000..174ddc217c
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/button-zenxfi3.c
@@ -0,0 +1,171 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 "button-target.h"
22#include "system.h"
23#include "system-target.h"
24#include "pinctrl-imx233.h"
25#include "power-imx233.h"
26#include "string.h"
27#include "usb.h"
28#include "backlight.h"
29#include "mpr121.h"
30
31static struct mpr121_config_t config =
32{
33 .ele =
34 {
35 [0] = {.tth = 5, .rth = 4 },
36 [1] = {.tth = 5, .rth = 4 },
37 [2] = {.tth = 5, .rth = 4 },
38 [3] = {.tth = 5, .rth = 4 },
39 [4] = {.tth = 4, .rth = 3 },
40 [5] = {.tth = 4, .rth = 3 },
41 [6] = {.tth = 5, .rth = 4 },
42 [7] = {.tth = 5, .rth = 4 },
43 [8] = {.gpio = ELE_GPIO_OUTPUT_OPEN_LED },
44 },
45 .filters =
46 {
47 .ele =
48 {
49 .rising = {.mhd = 1, .nhd = 1, .ncl = 1, .fdl = 1 },
50 .falling = {.mhd = 1, .nhd = 1, .ncl = 0xff, .fdl = 2 },
51 }
52 },
53 .autoconf =
54 {
55 .en = true, .ren = true, .retry = RETRY_NEVER,
56 .usl = 0xc4, .lsl = 0x7f, .tl = 0xb0
57 },
58 .ele_en = ELE_EN0_x(7),
59 .cal_lock = CL_TRACK
60};
61
62#define MPR121_INTERRUPT 1
63
64static int touchpad_btns = 0;
65static long mpr121_stack[DEFAULT_STACK_SIZE/sizeof(long)];
66static const char mpr121_thread_name[] = "mpr121";
67static struct event_queue mpr121_queue;
68
69static void mpr121_irq_cb(int bank, int pin)
70{
71 (void) bank;
72 (void) pin;
73 /* the callback will not be fired until interrupt is enabled back so
74 * the queue will not overflow or contain multiple MPR121_INTERRUPT events */
75 queue_post(&mpr121_queue, MPR121_INTERRUPT, 0);
76}
77
78static void mpr121_thread(void)
79{
80 struct queue_event ev;
81
82 while(1)
83 {
84 queue_wait(&mpr121_queue, &ev);
85 /* handle usb connect and ignore all messages except rmi interrupts */
86 if(ev.id == SYS_USB_CONNECTED)
87 {
88 usb_acknowledge(SYS_USB_CONNECTED_ACK);
89 continue;
90 }
91 else if(ev.id != MPR121_INTERRUPT)
92 continue;
93 /* clear interrupt and get status */
94 unsigned status;
95 touchpad_btns = 0;
96 if(!mpr121_get_touch_status(&status))
97 {
98 /* ELE3: up
99 * ELE4: back
100 * ELE5: menu
101 * ELE6: down
102 * ELE7: play */
103 if(status & 0x8) touchpad_btns |= BUTTON_UP;
104 if(status & 0x10) touchpad_btns |= BUTTON_BACK;
105 if(status & 0x20) touchpad_btns |= BUTTON_MENU;
106 if(status & 0x40) touchpad_btns |= BUTTON_DOWN;
107 if(status & 0x80) touchpad_btns |= BUTTON_PLAY;
108 }
109 /* enable interrupt */
110 imx233_setup_pin_irq(0, 18, true, true, false, &mpr121_irq_cb);
111 }
112}
113
114/* B0P18 is #IRQ line of the touchpad */
115void button_init_device(void)
116{
117 mpr121_init(0xb4);
118 mpr121_soft_reset();
119 mpr121_set_config(&config);
120
121 queue_init(&mpr121_queue, true);
122 create_thread(mpr121_thread, mpr121_stack, sizeof(mpr121_stack), 0,
123 mpr121_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE) IF_COP(, CPU));
124 /* enable interrupt */
125 imx233_set_pin_function(0, 18, PINCTRL_FUNCTION_GPIO);
126 imx233_enable_gpio_output(0, 18, false);
127 imx233_setup_pin_irq(0, 18, true, true, false, &mpr121_irq_cb);
128}
129
130bool button_hold(void)
131{
132 /* B0P04: #hold */
133 return !imx233_get_gpio_input_mask(0, 0x10);
134}
135
136int button_read_device(void)
137{
138 /* since sliding hold will usually trigger power, ignore power button
139 * for one second after hold is released */
140 static int power_ignore_counter = 0;
141 static bool old_hold;
142 /* light handling */
143 bool hold = button_hold();
144 if(hold != old_hold)
145 {
146 old_hold = hold;
147#ifndef BOOTLOADER
148 backlight_hold_changed(hold);
149#endif /* BOOTLOADER */
150 if(!hold)
151 power_ignore_counter = HZ;
152 }
153
154 if(power_ignore_counter)
155 power_ignore_counter--;
156
157 int res = 0;
158 /* B2P07: #volume-
159 * B2P08: #volume+
160 * PSWITCH: power */
161 uint32_t mask = imx233_get_gpio_input_mask(2, 0x180);
162 if(!(mask & 0x80))
163 res |= BUTTON_VOL_DOWN;
164 if(!(mask & 0x100))
165 res |= BUTTON_VOL_UP;
166 /* WARNING: it seems that the voltage on PSWITCH depends on whether
167 * usb is connected or not ! Thus the value of this field can be 1 or 3 */
168 if(__XTRACT(HW_POWER_STS, PSWITCH) != 0 && power_ignore_counter == 0)
169 res |= BUTTON_POWER;
170 return res | touchpad_btns;
171}
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/debug-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/debug-zenxfi3.c
new file mode 100644
index 0000000000..0f003bcd1e
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/debug-zenxfi3.c
@@ -0,0 +1,28 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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
22#include "system.h"
23#include "button-target.h"
24
25bool dbg_hw_target_info(void)
26{
27 return false;
28}
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/lcd-target.h b/firmware/target/arm/imx233/creative-zenxfi3/lcd-target.h
new file mode 100644
index 0000000000..931fcb32a0
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/lcd-target.h
@@ -0,0 +1,24 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2012 by Amaury Pouly
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 LCD_TARGET_H
22#define LCD_TARGET_H
23
24#endif /* LCD_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/lcd-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/lcd-zenxfi3.c
new file mode 100644
index 0000000000..3579f8306e
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/lcd-zenxfi3.c
@@ -0,0 +1,490 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2012 by Amaury Pouly
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 <sys/types.h> /* off_t */
22#include <string.h>
23#include "cpu.h"
24#include "system.h"
25#include "backlight-target.h"
26#include "lcd.h"
27#include "lcdif-imx233.h"
28#include "clkctrl-imx233.h"
29#include "pinctrl-imx233.h"
30#include "logf.h"
31
32#ifdef HAVE_LCD_ENABLE
33static bool lcd_on;
34#endif
35static unsigned lcd_yuv_options = 0;
36
37static void setup_parameters(void)
38{
39 imx233_lcdif_reset();
40 imx233_lcdif_set_lcd_databus_width(HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_16_BIT);
41 imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
42 imx233_lcdif_set_timings(2, 2, 3, 3);
43}
44
45static void setup_lcd_pins(bool use_lcdif)
46{
47 if(use_lcdif)
48 {
49 imx233_set_pin_function(1, 25, PINCTRL_FUNCTION_MAIN); /* lcd_vsync */
50 imx233_set_pin_function(1, 21, PINCTRL_FUNCTION_MAIN); /* lcd_cs */
51 imx233_set_pin_function(1, 22, PINCTRL_FUNCTION_MAIN); /* lcd_dotclk */
52 imx233_set_pin_function(1, 23, PINCTRL_FUNCTION_MAIN); /* lcd_enable */
53 imx233_set_pin_function(1, 24, PINCTRL_FUNCTION_MAIN); /* lcd_hsync */
54 imx233_set_pin_function(1, 18, PINCTRL_FUNCTION_MAIN); /* lcd_reset */
55 imx233_set_pin_function(1, 19, PINCTRL_FUNCTION_MAIN); /* lcd_rs */
56 imx233_set_pin_function(1, 16, PINCTRL_FUNCTION_MAIN); /* lcd_d16 */
57 imx233_set_pin_function(1, 17, PINCTRL_FUNCTION_MAIN); /* lcd_d17 */
58 imx233_set_pin_function(1, 20, PINCTRL_FUNCTION_MAIN); /* lcd_wr */
59 __REG_CLR(HW_PINCTRL_MUXSEL(2)) = 0xffffffff; /* lcd_d{0-15} */
60 }
61 else
62 {
63 __REG_SET(HW_PINCTRL_MUXSEL(2)) = 0xffffffff; /* lcd_d{0-15} */
64 imx233_enable_gpio_output_mask(1, 0x3ffffff, false); /* lcd_{d{0-17},reset,rs,wr,cs,dotclk,enable,hsync,vsync} */
65 imx233_set_pin_function(1, 16, PINCTRL_FUNCTION_GPIO); /* lcd_d16 */
66 imx233_set_pin_function(1, 17, PINCTRL_FUNCTION_GPIO); /* lcd_d17 */
67 imx233_set_pin_function(1, 19, PINCTRL_FUNCTION_GPIO); /* lcd_rs */
68 imx233_set_pin_function(1, 20, PINCTRL_FUNCTION_GPIO); /* lcd_wr */
69 imx233_set_pin_function(1, 21, PINCTRL_FUNCTION_GPIO); /* lcd_cs */
70 imx233_set_pin_function(1, 22, PINCTRL_FUNCTION_GPIO); /* lcd_dotclk */
71 imx233_set_pin_function(1, 23, PINCTRL_FUNCTION_GPIO); /* lcd_enable */
72 imx233_set_pin_function(1, 24, PINCTRL_FUNCTION_GPIO); /* lcd_hsync */
73 imx233_set_pin_function(1, 25, PINCTRL_FUNCTION_GPIO); /* lcd_vsync */
74 }
75}
76
77static void common_lcd_enable(bool enable)
78{
79 imx233_lcdif_enable(enable);
80 setup_lcd_pins(enable); /* use GPIO pins when disable */
81}
82
83static void setup_lcdif(void)
84{
85 setup_parameters();
86 common_lcd_enable(true);
87 imx233_lcdif_enable_bus_master(true);
88}
89
90static void setup_lcdif_clock(void)
91{
92 /* the LCD seems to work at 24Mhz, so use the xtal clock with no divider */
93 imx233_clkctrl_enable_clock(CLK_PIX, false);
94 imx233_clkctrl_set_clock_divisor(CLK_PIX, 1);
95 imx233_clkctrl_set_bypass_pll(CLK_PIX, true); /* use XTAL */
96 imx233_clkctrl_enable_clock(CLK_PIX, true);
97}
98
99static void lcd_write_reg(uint32_t reg, uint32_t data)
100{
101 imx233_lcdif_pio_send(false, 2, &reg);
102 if(reg != 0x22)
103 imx233_lcdif_pio_send(true, 2, &data);
104}
105
106#define REG_UDELAY 0xffffffff
107struct lcd_sequence_entry_t
108{
109 uint32_t reg, data;
110};
111
112static void lcd_send_sequence(struct lcd_sequence_entry_t *seq, unsigned count)
113{
114 for(;count-- > 0; seq++)
115 {
116 if(seq->reg == REG_UDELAY)
117 udelay(seq->data);
118 else
119 lcd_write_reg(seq->reg, seq->data);
120 }
121}
122
123#define _begin_seq() static struct lcd_sequence_entry_t __seq[] = {
124#define _udelay(a) {REG_UDELAY, a},
125#define _lcd_write_reg(a, b) {a, b},
126#define _end_seq() }; lcd_send_sequence(__seq, sizeof(__seq) / sizeof(__seq[0]));
127
128static void lcd_init_seq(void)
129{
130 _begin_seq()
131 _lcd_write_reg(1, 0x11c)
132 _lcd_write_reg(2, 0x100)
133 _lcd_write_reg(3, 0x1030)
134 _lcd_write_reg(8, 0x808)
135 _lcd_write_reg(0xc, 0)
136 _lcd_write_reg(0xf, 0xc01)
137 _lcd_write_reg(0x20, 0)
138 _lcd_write_reg(0x21, 0)
139 _udelay(30)
140 _lcd_write_reg(0x10, 0xa00)
141 _lcd_write_reg(0x11, 0x1038)
142 _udelay(30)
143 _lcd_write_reg(0x12, 0x1010)
144 _lcd_write_reg(0x13, 0x50)
145 _lcd_write_reg(0x14, 0x4f58)
146 _lcd_write_reg(0x30, 0)
147 _lcd_write_reg(0x31, 0xdb)
148 _lcd_write_reg(0x32, 0)
149 _lcd_write_reg(0x33, 0)
150 _lcd_write_reg(0x34, 0xdb)
151 _lcd_write_reg(0x35, 0)
152 _lcd_write_reg(0x36, 0xaf)
153 _lcd_write_reg(0x37, 0)
154 _lcd_write_reg(0x38, 0xdb)
155 _lcd_write_reg(0x39, 0)
156 _lcd_write_reg(0x50, 0)
157 _lcd_write_reg(0x51, 0x705)
158 _lcd_write_reg(0x52, 0xe0a)
159 _lcd_write_reg(0x53, 0x300)
160 _lcd_write_reg(0x54, 0xa0e)
161 _lcd_write_reg(0x55, 0x507)
162 _lcd_write_reg(0x56, 0)
163 _lcd_write_reg(0x57, 3)
164 _lcd_write_reg(0x58, 0x90a)
165 _lcd_write_reg(0x59, 0xa09)
166 _udelay(30)
167 _lcd_write_reg(7, 0x1017)
168 _udelay(40)
169 _end_seq()
170}
171
172void lcd_init_device(void)
173{
174 setup_lcdif();
175 setup_lcdif_clock();
176
177 // reset device
178 __REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
179 mdelay(50);
180 __REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
181 mdelay(10);
182 __REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
183
184 lcd_init_seq();
185#ifdef HAVE_LCD_ENABLE
186 lcd_on = true;
187#endif
188}
189
190#ifdef HAVE_LCD_ENABLE
191bool lcd_active(void)
192{
193 return lcd_on;
194}
195
196static void lcd_enable_seq(bool enable)
197{
198 if(!enable)
199 {
200 _begin_seq()
201 _end_seq()
202 }
203 else
204 {
205 _begin_seq()
206 _end_seq()
207 }
208}
209
210void lcd_enable(bool enable)
211{
212 if(lcd_on == enable)
213 return;
214
215 lcd_on = enable;
216
217 if(enable)
218 common_lcd_enable(true);
219 lcd_enable_seq(enable);
220 if(!enable)
221 common_lcd_enable(false);
222}
223#endif
224
225void lcd_update(void)
226{
227 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
228}
229
230void lcd_update_rect(int x, int y, int w, int h)
231{
232#ifdef HAVE_LCD_ENABLE
233 if(!lcd_on)
234 return;
235#endif
236 /* make sure the rectangle is included in the screen */
237 x = MIN(x, LCD_WIDTH);
238 y = MIN(y, LCD_HEIGHT);
239 w = MIN(w, LCD_WIDTH - x);
240 h = MIN(h, LCD_HEIGHT - y);
241
242 imx233_lcdif_wait_ready();
243 lcd_write_reg(0x37, x);
244 lcd_write_reg(0x36, x + w - 1);
245 lcd_write_reg(0x39, y);
246 lcd_write_reg(0x38, y + h - 1);
247 lcd_write_reg(0x20, x);
248 lcd_write_reg(0x21, y);
249 lcd_write_reg(0x22, 0);
250
251 imx233_lcdif_wait_ready();
252 imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
253 imx233_lcdif_set_byte_packing_format(0xf); /* two pixels per 32-bit word */
254 imx233_lcdif_set_data_format(false, false, false); /* RGB565, don't care, don't care */
255
256 /* there are two cases here:
257 * - either width = LCD_WIDTH and we can directly memcopy a part of lcd_framebuffer to FRAME
258 * and send it
259 * - either width != LCD_WIDTH and we have to build a contiguous copy of the rectangular area
260 * into FRAME before sending it (which is slower and doesn't use the hardware)
261 * In all cases, FRAME just acts as a temporary buffer.
262 * NOTE It's more interesting to do a copy to FRAME in all cases since in system mode
263 * the clock runs at 24MHz which provides barely 10MB/s bandwidth compared to >100MB/s
264 * for memcopy operations
265 */
266 if(w == LCD_WIDTH)
267 {
268 memcpy((void *)FRAME, FBADDR(x,y), w * h * sizeof(fb_data));
269 }
270 else
271 {
272 for(int i = 0; i < h; i++)
273 memcpy((fb_data *)FRAME + i * w, FBADDR(x,y + i), w * sizeof(fb_data));
274 }
275 /* WARNING The LCDIF has a limitation on the vertical count ! In 16-bit packed mode
276 * (which we used, ie 16-bit per pixel, 2 pixels per 32-bit words), the v_count
277 * field must be a multiple of 2. Furthermore, it seems the lcd controller doesn't
278 * really like when both w and h are even, probably because the writes to the GRAM
279 * are done on several words and the controller requires dummy writes.
280 * The workaround is to always make sure that we send a number of pixels which is
281 * a multiple of 4 so that both the lcdif and the controller are happy. If any
282 * of w or h is odd, we will send a copy of the first pixels as dummy writes. We will
283 * send at most 3 bytes. We then send (w * h + 3) / 4 x 4 bytes.
284 */
285 if(w % 2 == 1 || h % 2 == 1)
286 {
287 /* copy three pixel after the last one */
288 for(int i = 0; i < 3; i++)
289 *((fb_data *)FRAME + w * h + i) = *((fb_data *)FRAME + i);
290 /* WARNING we need to update w and h to reflect the pixel count BUT it
291 * has no relation to w * h (it can even be 2 * prime). Hopefully, w <= 240 and
292 * h <= 320 so w * h <= 76800 and (w * h + 3) / 4 <= 38400 which fits into
293 * a 16-bit integer (horizontal count). */
294 h = (w * h + 3) / 4;
295 w = 4;
296 }
297 imx233_lcdif_dma_send((void *)FRAME_PHYS_ADDR, w, h);
298}
299
300void lcd_yuv_set_options(unsigned options)
301{
302 lcd_yuv_options = options;
303}
304
305#define YFAC (74)
306#define RVFAC (101)
307#define GUFAC (-24)
308#define GVFAC (-51)
309#define BUFAC (128)
310
311static inline int clamp(int val, int min, int max)
312{
313 if (val < min)
314 val = min;
315 else if (val > max)
316 val = max;
317 return val;
318}
319
320void lcd_blit_yuv(unsigned char * const src[3],
321 int src_x, int src_y, int stride,
322 int x, int y, int width, int height)
323{
324 const unsigned char *ysrc, *usrc, *vsrc;
325 int linecounter;
326 fb_data *dst, *row_end;
327 long z;
328
329 /* width and height must be >= 2 and an even number */
330 width &= ~1;
331 linecounter = height >> 1;
332
333 #if LCD_WIDTH >= LCD_HEIGHT
334 dst = FBADDR(x,y);
335 row_end = dst + width;
336 #else
337 dst = FBADDR(LCD_WIDTH - y - 1,x);
338 row_end = dst + LCD_WIDTH * width;
339 #endif
340
341 z = stride * src_y;
342 ysrc = src[0] + z + src_x;
343 usrc = src[1] + (z >> 2) + (src_x >> 1);
344 vsrc = src[2] + (usrc - src[1]);
345
346 /* stride => amount to jump from end of last row to start of next */
347 stride -= width;
348
349 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
350
351 do
352 {
353 do
354 {
355 int y, cb, cr, rv, guv, bu, r, g, b;
356
357 y = YFAC*(*ysrc++ - 16);
358 cb = *usrc++ - 128;
359 cr = *vsrc++ - 128;
360
361 rv = RVFAC*cr;
362 guv = GUFAC*cb + GVFAC*cr;
363 bu = BUFAC*cb;
364
365 r = y + rv;
366 g = y + guv;
367 b = y + bu;
368
369 if ((unsigned)(r | g | b) > 64*256-1)
370 {
371 r = clamp(r, 0, 64*256-1);
372 g = clamp(g, 0, 64*256-1);
373 b = clamp(b, 0, 64*256-1);
374 }
375
376 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
377
378 #if LCD_WIDTH >= LCD_HEIGHT
379 dst++;
380 #else
381 dst += LCD_WIDTH;
382 #endif
383
384 y = YFAC*(*ysrc++ - 16);
385 r = y + rv;
386 g = y + guv;
387 b = y + bu;
388
389 if ((unsigned)(r | g | b) > 64*256-1)
390 {
391 r = clamp(r, 0, 64*256-1);
392 g = clamp(g, 0, 64*256-1);
393 b = clamp(b, 0, 64*256-1);
394 }
395
396 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
397
398 #if LCD_WIDTH >= LCD_HEIGHT
399 dst++;
400 #else
401 dst += LCD_WIDTH;
402 #endif
403 }
404 while (dst < row_end);
405
406 ysrc += stride;
407 usrc -= width >> 1;
408 vsrc -= width >> 1;
409
410 #if LCD_WIDTH >= LCD_HEIGHT
411 row_end += LCD_WIDTH;
412 dst += LCD_WIDTH - width;
413 #else
414 row_end -= 1;
415 dst -= LCD_WIDTH*width + 1;
416 #endif
417
418 do
419 {
420 int y, cb, cr, rv, guv, bu, r, g, b;
421
422 y = YFAC*(*ysrc++ - 16);
423 cb = *usrc++ - 128;
424 cr = *vsrc++ - 128;
425
426 rv = RVFAC*cr;
427 guv = GUFAC*cb + GVFAC*cr;
428 bu = BUFAC*cb;
429
430 r = y + rv;
431 g = y + guv;
432 b = y + bu;
433
434 if ((unsigned)(r | g | b) > 64*256-1)
435 {
436 r = clamp(r, 0, 64*256-1);
437 g = clamp(g, 0, 64*256-1);
438 b = clamp(b, 0, 64*256-1);
439 }
440
441 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
442
443 #if LCD_WIDTH >= LCD_HEIGHT
444 dst++;
445 #else
446 dst += LCD_WIDTH;
447 #endif
448
449 y = YFAC*(*ysrc++ - 16);
450 r = y + rv;
451 g = y + guv;
452 b = y + bu;
453
454 if ((unsigned)(r | g | b) > 64*256-1)
455 {
456 r = clamp(r, 0, 64*256-1);
457 g = clamp(g, 0, 64*256-1);
458 b = clamp(b, 0, 64*256-1);
459 }
460
461 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
462
463 #if LCD_WIDTH >= LCD_HEIGHT
464 dst++;
465 #else
466 dst += LCD_WIDTH;
467 #endif
468 }
469 while (dst < row_end);
470
471 ysrc += stride;
472 usrc += stride >> 1;
473 vsrc += stride >> 1;
474
475 #if LCD_WIDTH >= LCD_HEIGHT
476 row_end += LCD_WIDTH;
477 dst += LCD_WIDTH - width;
478 #else
479 row_end -= 1;
480 dst -= LCD_WIDTH*width + 1;
481 #endif
482 }
483 while (--linecounter > 0);
484
485 #if LCD_WIDTH >= LCD_HEIGHT
486 lcd_update_rect(x, y, width, height);
487 #else
488 lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
489 #endif
490}
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c
new file mode 100644
index 0000000000..26f2159cec
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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
22#include "system.h"
23#include "power.h"
24#include "tuner.h"
25#include "fmradio_i2c.h"
26#include "pinctrl-imx233.h"
27
28static bool tuner_enable = false;
29
30bool tuner_power(bool enable)
31{
32 if(enable != tuner_enable)
33 {
34 tuner_enable = enable;
35 }
36 return tuner_enable;
37}
38
39bool tuner_powered(void)
40{
41 return tuner_enable;
42}
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/powermgmt-target.h b/firmware/target/arm/imx233/creative-zenxfi3/powermgmt-target.h
new file mode 100644
index 0000000000..6c010a72d3
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/powermgmt-target.h
@@ -0,0 +1,58 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 POWERMGMT_TARGET_H
22#define POWERMGMT_TARGET_H
23
24#include "config.h"
25#include "powermgmt-imx233.h"
26
27/* Creative ZEN X-Fi3 OF settings:
28 * - current ramp slope: 10 mA/s
29 * - conditioning threshold voltage: 3 V
30 * - conditioning max voltage: 3.1 V
31 * - conditioning current: 60 mA
32 * - conditioning timeout: 1 h
33 * - charging voltage: 4.2 V
34 * - charging current: 260 mA
35 * - charging threshold current: 20 mA
36 * - charging timeout: 4 h
37 * - top off period: 30 min
38 * - high die temperature: 91 °C
39 * - low die temperature: 56 °C
40 * - safe die temperature current: 30 mA
41 * - battery temperature channel: 0
42 * - high battery temperature: 2400
43 * - low battery temperature: 2300
44 * - safe battery temperature current: 0 mA
45 * - low DCDC battery voltage: 3.9 V
46 */
47
48#define IMX233_CHARGE_CURRENT 260
49#define IMX233_STOP_CURRENT 20
50#define IMX233_TOPOFF_TIMEOUT (30 * 60 * HZ)
51#define IMX233_CHARGING_TIMEOUT (4 * 3600 * HZ)
52#define IMX233_DIE_TEMP_HIGH 91
53#define IMX233_DIE_TEMP_LOW 56
54#define IMX233_BATT_TEMP_SENSOR 0
55#define IMX233_BATT_TEMP_HIGH 2400
56#define IMX233_BATT_TEMP_LOW 2300
57
58#endif /* POWERMGMT_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/powermgmt-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/powermgmt-zenxfi3.c
new file mode 100644
index 0000000000..2951df5f58
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/powermgmt-zenxfi3.c
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 by Amaury Pouly
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 "powermgmt-target.h"
23
24const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
25{
26 3659
27};
28
29const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
30{
31 3630
32};
33
34/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
35const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
36{
37 /* Toshiba Gigabeat S Li Ion 700mAH figured from discharge curve */
38 { 3659, 3719, 3745, 3761, 3785, 3813, 3856, 3926, 3984, 4040, 4121 },
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
42const unsigned short percent_to_volt_charge[11] =
43{
44 /* Toshiba Gigabeat S Li Ion 700mAH figured from charge curve */
45 4028, 4063, 4087, 4111, 4135, 4156, 4173, 4185, 4194, 4202, 4208
46};
diff --git a/firmware/target/arm/imx233/sd-imx233.c b/firmware/target/arm/imx233/sd-imx233.c
index d3c29ee5be..8928faf3f9 100644
--- a/firmware/target/arm/imx233/sd-imx233.c
+++ b/firmware/target/arm/imx233/sd-imx233.c
@@ -62,6 +62,28 @@ struct sd_config_t sd_config[] =
62 .power_pin = PIN(0, 8), 62 .power_pin = PIN(0, 8),
63 .ssp = 1 63 .ssp = 1
64 }, 64 },
65#elif defined(CREATIVE_ZENXFI2)
66 /* The Zen X-Fi2 uses pin B1P29 for power*/
67 {
68 .name = "microSD",
69 .flags = POWER_PIN | REMOVABLE | DETECT_INVERTED,
70 .power_pin = PIN(1, 29),
71 .ssp = 1,
72 },
73#elif defined(CREATIVE_ZENXFI3)
74 {
75 .name = "internal/SD",
76 .flags = WINDOW,
77 .ssp = 2
78 },
79 /* The Zen X-Fi3 uses pin #B0P07 for power*/
80 {
81 .name = "microSD",
82 .flags = POWER_PIN | POWER_INVERTED | REMOVABLE | POWER_DELAY,
83 .power_pin = PIN(0, 7),
84 .power_delay = HZ / 10, /* extra delay, to ramp up voltage? */
85 .ssp = 1
86 },
65#else 87#else
66#error You need to write the sd config! 88#error You need to write the sd config!
67#endif 89#endif
diff --git a/firmware/target/arm/system-arm.c b/firmware/target/arm/system-arm.c
index e687e1d82b..c8d12e296a 100644
--- a/firmware/target/arm/system-arm.c
+++ b/firmware/target/arm/system-arm.c
@@ -148,7 +148,7 @@ void NORETURN_ATTR UIE(unsigned int pc, unsigned int num)
148 if (!triggered) 148 if (!triggered)
149 { 149 {
150 triggered = true; 150 triggered = true;
151 backtrace(pc, __get_sp(), &line); 151 //backtrace(pc, __get_sp(), &line);
152 } 152 }
153 153
154 lcd_update(); 154 lcd_update();
diff --git a/firmware/target/hosted/sdl/sim-ui-defines.h b/firmware/target/hosted/sdl/sim-ui-defines.h
index b5667ec72a..38e3b10441 100644
--- a/firmware/target/hosted/sdl/sim-ui-defines.h
+++ b/firmware/target/hosted/sdl/sim-ui-defines.h
@@ -431,6 +431,13 @@
431#define UI_LCD_POSX 68 431#define UI_LCD_POSX 68
432#define UI_LCD_POSY 77 432#define UI_LCD_POSY 77
433 433
434#elif defined(CREATIVE_ZENXFI3)
435#define UI_TITLE "Creative ZEN X-Fi3"
436#define UI_WIDTH 262 /* width of GUI window */
437#define UI_HEIGHT 350 /* height of GUI window */
438#define UI_LCD_POSX 43
439#define UI_LCD_POSY 65
440
434#elif defined(APPLICATION) 441#elif defined(APPLICATION)
435#define UI_TITLE "Rockbox" 442#define UI_TITLE "Rockbox"
436#define UI_LCD_POSX 0 443#define UI_LCD_POSX 0