diff options
Diffstat (limited to 'firmware/target/arm/imx233/creative-zenxfi2')
13 files changed, 1104 insertions, 0 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 | |||
24 | int 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 | |||
33 | const 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 | |||
28 | static int input_source = AUDIO_SRC_PLAYBACK; | ||
29 | static unsigned input_flags = 0; | ||
30 | static int output_source = AUDIO_SRC_PLAYBACK; | ||
31 | |||
32 | static 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 | |||
40 | void 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 | |||
49 | void 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 | |||
24 | bool _backlight_init(void); | ||
25 | void _backlight_on(void); | ||
26 | void _backlight_off(void); | ||
27 | void _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 | |||
29 | void _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 | |||
37 | bool _backlight_init(void) | ||
38 | { | ||
39 | _backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING); | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | void _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 | |||
51 | void _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 | |||
27 | void button_init_device(void); | ||
28 | int button_read_device(int *data); | ||
29 | bool 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 | |||
31 | struct 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 | |||
39 | static 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 | */ | ||
49 | void 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 | |||
74 | static 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 | |||
98 | static 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 | |||
108 | int 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 | |||
25 | bool 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 | ||
33 | static bool lcd_on; | ||
34 | #endif | ||
35 | static unsigned lcd_yuv_options = 0; | ||
36 | |||
37 | static 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 | |||
45 | static 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 | |||
77 | static void common_lcd_enable(bool enable) | ||
78 | { | ||
79 | imx233_lcdif_enable(enable); | ||
80 | setup_lcd_pins(enable); /* use GPIO pins when disable */ | ||
81 | } | ||
82 | |||
83 | static void setup_lcdif(void) | ||
84 | { | ||
85 | setup_parameters(); | ||
86 | common_lcd_enable(true); | ||
87 | imx233_lcdif_enable_bus_master(true); | ||
88 | } | ||
89 | |||
90 | static inline uint32_t encode_16_to_18(uint32_t a) | ||
91 | { | ||
92 | return ((a & 0xff) << 1) | (((a >> 8) & 0xff) << 10); | ||
93 | } | ||
94 | |||
95 | static inline uint32_t decode_18_to_16(uint32_t a) | ||
96 | { | ||
97 | return ((a >> 1) & 0xff) | ((a >> 2) & 0xff00); | ||
98 | } | ||
99 | |||
100 | static 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 | |||
109 | static 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, ®); | ||
118 | if(old_reg != 0 && old_reg != 0x202) | ||
119 | imx233_lcdif_pio_send(true, 2, &data); | ||
120 | } | ||
121 | |||
122 | #define REG_MDELAY 0xffffffff | ||
123 | struct lcd_sequence_entry_t | ||
124 | { | ||
125 | uint32_t reg, data; | ||
126 | }; | ||
127 | |||
128 | static 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 | |||
144 | static 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 | |||
195 | void 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 | ||
214 | bool lcd_active(void) | ||
215 | { | ||
216 | return lcd_on; | ||
217 | } | ||
218 | |||
219 | static 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 | |||
233 | void 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 | |||
248 | void lcd_update(void) | ||
249 | { | ||
250 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); | ||
251 | } | ||
252 | |||
253 | void 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 | |||
322 | void 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 | |||
333 | static 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 | |||
342 | void 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 | |||
28 | static bool tuner_enable = false; | ||
29 | |||
30 | bool tuner_power(bool enable) | ||
31 | { | ||
32 | if(enable != tuner_enable) | ||
33 | { | ||
34 | tuner_enable = enable; | ||
35 | } | ||
36 | return tuner_enable; | ||
37 | } | ||
38 | |||
39 | bool 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 | |||
24 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
25 | { | ||
26 | 3659 | ||
27 | }; | ||
28 | |||
29 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
30 | { | ||
31 | 3630 | ||
32 | }; | ||
33 | |||
34 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
35 | const 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 */ | ||
42 | const 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 | }; | ||