summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/creative-zen
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-10-22 00:30:43 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-10-22 00:34:45 +0200
commita0728672bf07f626049f8dc0007772794ae95ee1 (patch)
treebb8ca610c9d0c8fb441a99ccf33102964cafd003 /firmware/target/arm/imx233/creative-zen
parentd3bc64833c76adca4d6300e5b5880ee8ea63de02 (diff)
Initial commit for the Creative ZEN and ZEN X-Fi
Change-Id: Ibd7b1b0b957ef11c200cb63eff7da53f11774748
Diffstat (limited to 'firmware/target/arm/imx233/creative-zen')
-rw-r--r--firmware/target/arm/imx233/creative-zen/adc-target.h29
-rw-r--r--firmware/target/arm/imx233/creative-zen/adc-zen.c34
-rw-r--r--firmware/target/arm/imx233/creative-zen/audio-target.h25
-rw-r--r--firmware/target/arm/imx233/creative-zen/backlight-target.h29
-rw-r--r--firmware/target/arm/imx233/creative-zen/backlight-zen.c69
-rw-r--r--firmware/target/arm/imx233/creative-zen/button-target.h60
-rw-r--r--firmware/target/arm/imx233/creative-zen/button-zen.c88
-rw-r--r--firmware/target/arm/imx233/creative-zen/debug-zen.c29
-rw-r--r--firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c40
-rw-r--r--firmware/target/arm/imx233/creative-zen/lcd-target.h26
-rw-r--r--firmware/target/arm/imx233/creative-zen/lcd-zen.c347
-rw-r--r--firmware/target/arm/imx233/creative-zen/power-zen.c43
-rw-r--r--firmware/target/arm/imx233/creative-zen/powermgmt-target.h55
-rw-r--r--firmware/target/arm/imx233/creative-zen/powermgmt-zen.c49
14 files changed, 923 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/creative-zen/adc-target.h b/firmware/target/arm/imx233/creative-zen/adc-target.h
new file mode 100644
index 0000000000..5a525152f6
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/adc-target.h
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _ADC_TARGET_H_
+#define _ADC_TARGET_H_
+
+#define NUM_ADC_CHANNELS 2
+
+#define ADC_BATTERY 0
+#define ADC_DIE_TEMP 1
+
+#endif
diff --git a/firmware/target/arm/imx233/creative-zen/adc-zen.c b/firmware/target/arm/imx233/creative-zen/adc-zen.c
new file mode 100644
index 0000000000..92c1063c24
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/adc-zen.c
@@ -0,0 +1,34 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "adc-target.h"
+#include "adc-imx233.h"
+
+int imx233_adc_mapping[] =
+{
+ [ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
+ [ADC_BATTERY] = IMX233_ADC_BATTERY,
+};
+
+const char *imx233_adc_channel_name[] =
+{
+ "Die temperature(°C)",
+ "Battery(raw)",
+};
diff --git a/firmware/target/arm/imx233/creative-zen/audio-target.h b/firmware/target/arm/imx233/creative-zen/audio-target.h
new file mode 100644
index 0000000000..4ee2e2f402
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/audio-target.h
@@ -0,0 +1,25 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef __audio_target__
+#define __audio_target__
+
+#endif /* __audio_target__ */
+
diff --git a/firmware/target/arm/imx233/creative-zen/backlight-target.h b/firmware/target/arm/imx233/creative-zen/backlight-target.h
new file mode 100644
index 0000000000..78a0a72d85
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/backlight-target.h
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef BACKLIGHT_TARGET_H
+#define BACKLIGHT_TARGET_H
+
+bool _backlight_init(void);
+void _backlight_on(void);
+void _backlight_off(void);
+void _backlight_set_brightness(int brightness);
+
+#endif /* BACKLIGHT_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zen/backlight-zen.c b/firmware/target/arm/imx233/creative-zen/backlight-zen.c
new file mode 100644
index 0000000000..0d223b52e9
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/backlight-zen.c
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "config.h"
+#include "system.h"
+#include "backlight.h"
+#include "lcd.h"
+#include "backlight-target.h"
+#include "uartdbg-imx233.h"
+#include "pinctrl-imx233.h"
+
+void _backlight_set_brightness(int level)
+{
+ unsigned val = (level + 200) * level / 1000;
+ if(level != 0)
+ {
+ for(unsigned mask = 0x10; mask; mask >>= 1)
+ imx233_uartdbg_send((val & mask) ? 0xff : 0xf8);
+ imx233_uartdbg_send(0);
+ imx233_pinctrl_set_gpio(1, 12, true);
+ }
+ else
+ imx233_pinctrl_set_gpio(1, 12, false);
+}
+
+bool _backlight_init(void)
+{
+ imx233_pinctrl_acquire(1, 12, "backlight_enable");
+ imx233_pinctrl_set_function(1, 12, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_enable_gpio(1, 12, true);
+ imx233_uartdbg_init(BAUD_38400);
+ return true;
+}
+
+void _backlight_on(void)
+{
+#ifdef HAVE_LCD_ENABLE
+ lcd_enable(true); /* power on lcd + visible display */
+#endif
+ /* restore the previous backlight level */
+ _backlight_set_brightness(backlight_brightness);
+}
+
+void _backlight_off(void)
+{
+ /* there is no real on/off but we can set to 0 brightness */
+ _backlight_set_brightness(0);
+#ifdef HAVE_LCD_ENABLE
+ lcd_enable(false); /* power off visible display */
+#endif
+}
diff --git a/firmware/target/arm/imx233/creative-zen/button-target.h b/firmware/target/arm/imx233/creative-zen/button-target.h
new file mode 100644
index 0000000000..33ba7a9db5
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/button-target.h
@@ -0,0 +1,60 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _BUTTON_TARGET_H_
+#define _BUTTON_TARGET_H_
+
+#include <stdbool.h>
+
+bool button_debug_screen(void);
+
+#define HAS_BUTTON_HOLD
+#ifdef CREATIVE_ZENXFI
+#define HAVE_HEADPHONE_DETECTION
+#endif
+
+#define IMX233_BUTTON_LRADC_CHANNEL 0
+#define IMX233_BUTTON_LRADC_HOLD_DET BLH_ADC
+
+/* Main unit's buttons */
+#define BUTTON_POWER 0x00000001
+#define BUTTON_LEFT 0x00000002
+#define BUTTON_UP 0x00000004
+#define BUTTON_RIGHT 0x00000008
+#define BUTTON_DOWN 0x00000010
+#define BUTTON_SELECT 0x00000020
+#define BUTTON_PLAYPAUSE 0x00000040
+#define BUTTON_BACK 0x00000080
+#define BUTTON_MENU 0x00000100
+#define BUTTON_SHORTCUT 0x00000200
+#ifdef CREATIVE_ZENXFI
+#define BUTTON_BOTTOMLEFT 0x00000400
+#define BUTTON_BOTTOMRIGHT 0x00000800
+#define BUTTON_TOPLEFT 0x00001000
+#define BUTTON_TOPRIGHT 0x00002000
+#endif
+
+#define BUTTON_MAIN 0x00003fff
+
+/* Software power-off */
+#define POWEROFF_BUTTON BUTTON_POWER
+#define POWEROFF_COUNT 10
+
+#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/imx233/creative-zen/button-zen.c b/firmware/target/arm/imx233/creative-zen/button-zen.c
new file mode 100644
index 0000000000..cacc47d448
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/button-zen.c
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "button-target.h"
+#include "system.h"
+#include "system-target.h"
+#include "pinctrl-imx233.h"
+#include "power-imx233.h"
+#include "button-lradc-imx233.h"
+
+struct imx233_button_lradc_mapping_t imx233_button_lradc_mapping[] =
+{
+#if defined(CREATIVE_ZEN)
+ {200, IMX233_BUTTON_LRADC_HOLD},
+ {250, BUTTON_MENU},
+ {520, BUTTON_SHORTCUT},
+ {1490, BUTTON_UP},
+ {1740, BUTTON_SELECT},
+ {2015, BUTTON_LEFT},
+ {2255, BUTTON_RIGHT},
+ {2485, BUTTON_DOWN},
+ {2700, BUTTON_BACK},
+ {2945, BUTTON_PLAYPAUSE},
+ {3400, 0},
+ {0, IMX233_BUTTON_LRADC_END},
+#elif defined(CREATIVE_ZENXFI)
+ {0, IMX233_BUTTON_LRADC_HOLD},
+ {200, BUTTON_MENU},
+ {445, BUTTON_SHORTCUT},
+ {645, BUTTON_UP},
+ {860, BUTTON_LEFT},
+ {1060, BUTTON_RIGHT},
+ {1260, BUTTON_DOWN},
+ {1480, BUTTON_SELECT},
+ {1700, BUTTON_TOPRIGHT},
+ {1920, BUTTON_BOTTOMLEFT},
+ {2145, BUTTON_TOPLEFT},
+ {2460, BUTTON_BOTTOMRIGHT},
+ {2700, BUTTON_BACK},
+ {2945, BUTTON_PLAYPAUSE},
+ {3400, 0},
+ {0, IMX233_BUTTON_LRADC_END},
+#else
+#error wrong target
+#endif
+};
+
+void button_init_device(void)
+{
+ imx233_button_lradc_init();
+}
+
+bool button_hold(void)
+{
+ return imx233_button_lradc_hold();
+}
+
+#ifdef CREATIVE_ZENXFI
+bool headphones_inserted(void)
+{
+ return !imx233_pinctrl_get_gpio(2, 8);
+}
+#endif
+
+int button_read_device(void)
+{
+ int btn = 0;
+ if(BF_RD(POWER_STS, PSWITCH) == 1)
+ btn |= BUTTON_POWER;
+ return imx233_button_lradc_read(btn);
+}
diff --git a/firmware/target/arm/imx233/creative-zen/debug-zen.c b/firmware/target/arm/imx233/creative-zen/debug-zen.c
new file mode 100644
index 0000000000..a350d0ae62
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/debug-zen.c
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "system.h"
+#include "button-target.h"
+#include "lcd-target.h"
+
+bool dbg_hw_target_info(void)
+{
+ return false;
+}
diff --git a/firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c b/firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c
new file mode 100644
index 0000000000..a1377ce1f2
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "config.h"
+#include "system.h"
+#include "fmradio_i2c.h"
+#include "pinctrl-imx233.h"
+#include "i2c.h"
+
+void fmradio_i2c_init(void)
+{
+}
+
+int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count)
+{
+ return i2c_write(address, buf, count);
+}
+
+int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
+{
+ return i2c_read(address, buf, count);
+}
diff --git a/firmware/target/arm/imx233/creative-zen/lcd-target.h b/firmware/target/arm/imx233/creative-zen/lcd-target.h
new file mode 100644
index 0000000000..b28bda347a
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/lcd-target.h
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (c) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef LCD_TARGET_H
+#define LCD_TARGET_H
+
+bool lcd_debug_screen(void);
+
+#endif /* LCD_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zen/lcd-zen.c b/firmware/target/arm/imx233/creative-zen/lcd-zen.c
new file mode 100644
index 0000000000..8390d192c8
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/lcd-zen.c
@@ -0,0 +1,347 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (c) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include <sys/types.h> /* off_t */
+#include <string.h>
+#include "cpu.h"
+#include "system.h"
+#include "backlight-target.h"
+#include "lcd.h"
+#include "lcdif-imx233.h"
+#include "clkctrl-imx233.h"
+#include "pinctrl-imx233.h"
+#include "dma-imx233.h"
+#include "regs/regs-uartdbg.h"
+#include "logf.h"
+#ifndef BOOTLOADER
+#include "button.h"
+#include "font.h"
+#include "action.h"
+#endif
+
+#ifdef HAVE_LCD_ENABLE
+static bool lcd_on;
+#endif
+
+/**
+ * DMA
+ */
+
+/* Used for DMA */
+struct lcdif_dma_command_t
+{
+ struct apb_dma_command_t dma;
+ uint32_t pad;
+} __attribute__((packed)) CACHEALIGN_ATTR;
+
+__ENSURE_STRUCT_CACHE_FRIENDLY(struct lcdif_dma_command_t)
+
+#define NR_CMDS ((IMX233_FRAMEBUFFER_SIZE + IMX233_MAX_SINGLE_DMA_XFER_SIZE - 1) / IMX233_MAX_SINGLE_DMA_XFER_SIZE)
+
+struct lcdif_dma_command_t lcdif_dma[NR_CMDS];
+
+/**
+ * Utils
+ */
+static int g_wait_nr_frame = 0;
+static struct semaphore g_wait_sema;
+
+static void wait_frames_cb(void)
+{
+ if(--g_wait_nr_frame == 0)
+ semaphore_release(&g_wait_sema);
+}
+
+static void wait_nr_frames(int nr)
+{
+ g_wait_nr_frame = 1 + nr; // +1 because we want entire frames
+ imx233_lcdif_set_vsync_edge_cb(wait_frames_cb);
+ imx233_lcdif_enable_vsync_edge_irq(true);
+ semaphore_wait(&g_wait_sema, TIMEOUT_BLOCK);
+ imx233_lcdif_enable_vsync_edge_irq(false);
+}
+
+/**
+ * SPI
+ */
+
+#define SPI_CS(v) imx233_pinctrl_set_gpio(1, 11, v)
+#define SPI_SCL(v) imx233_pinctrl_set_gpio(1, 10, v)
+#define SPI_SDO(v) imx233_pinctrl_set_gpio(1, 9, v)
+
+#define DEV_ID 0x74
+#define RS 0x2
+#define RW 0x1
+
+static void spi_init(void)
+{
+ imx233_pinctrl_acquire(1, 9, "lcd_spi_sdo");
+ imx233_pinctrl_acquire(1, 10, "lcd_spi_scl");
+ imx233_pinctrl_acquire(1, 11, "lcd_spi_cs");
+ imx233_pinctrl_set_function(1, 9, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_set_function(1, 10, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_set_function(1, 11, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_set_gpio(1, 9, true);
+ imx233_pinctrl_set_gpio(1, 10, true);
+ imx233_pinctrl_set_gpio(1, 11, true);
+ imx233_pinctrl_enable_gpio(1, 9, true);
+ imx233_pinctrl_enable_gpio(1, 10, true);
+ imx233_pinctrl_enable_gpio(1, 11, true);
+}
+
+static void spi_delay(void)
+{
+ udelay(1);
+}
+
+static void spi_begin(void)
+{
+ SPI_CS(false);
+ spi_delay();
+}
+
+static void spi_write(unsigned char b)
+{
+ for(int i = 7; i >= 0; i--)
+ {
+ SPI_SCL(false);
+ spi_delay();
+ SPI_SDO((b >> i) & 1);
+ spi_delay();
+ SPI_SCL(true);
+ spi_delay();
+ }
+}
+
+static void spi_end(void)
+{
+ SPI_CS(true);
+ spi_delay();
+}
+
+static void spi_write_reg(uint8_t reg, uint16_t value)
+{
+ spi_begin();
+ spi_write(DEV_ID);
+ spi_write(0);
+ spi_write(reg);
+ spi_end();
+ spi_begin();
+ spi_write(DEV_ID | RS);
+ spi_write(value >> 8);
+ spi_write(value & 0xff);
+ spi_end();
+}
+
+/**
+ * LCD control
+ */
+
+static void lcd_power(bool en)
+{
+ imx233_pinctrl_set_gpio(1, 8, en);
+ mdelay(10);
+}
+
+static void lcd_power_seq(void)
+{
+ spi_write_reg(0x7, 0);
+ mdelay(10);
+ spi_write_reg(0x12, 0x1618);
+ spi_write_reg(0x11, 0x2227);
+ spi_write_reg(0x13, 0x61d1);
+ spi_write_reg(0x10, 0x550c);
+ wait_nr_frames(5);
+ spi_write_reg(0x12, 0x0c58);
+}
+
+static void lcd_init_seq(void)
+{
+ /* NOTE I don't understand why I have to use BGR, logic would say I should not */
+ spi_write_reg(0x1, 0x2b1d);// inversion
+ spi_write_reg(0x2, 0x300);
+ /* NOTE by default stmp3700 has vsync/hsync active low and data launch
+ * at negative edge of dotclk, reflect this in the polarity settings */
+ spi_write_reg(0x3, 0xd040);// polarity (OF uses 0xc040, seems incorrect)
+ spi_write_reg(0x8, 0); // vsync back porch (0=3H)
+ spi_write_reg(0x9, 0); // hsync back porhc (0=24clk)
+ spi_write_reg(0x76, 0x2213);
+ spi_write_reg(0xb, 0x33e1);
+ spi_write_reg(0xc, 0x23);
+ spi_write_reg(0x76, 0);
+ spi_write_reg(0xd, 7);
+ spi_write_reg(0xe, 0);
+ spi_write_reg(0x15, 0x803);
+ spi_write_reg(0x14, 0);
+ spi_write_reg(0x16, 0);
+ spi_write_reg(0x30, 0x706);
+ spi_write_reg(0x31, 0x406);
+ spi_write_reg(0x32, 0xc09);
+ spi_write_reg(0x33, 0x606);
+ spi_write_reg(0x34, 0x706);
+ spi_write_reg(0x35, 0x406);
+ spi_write_reg(0x36, 0xc06);
+ spi_write_reg(0x37, 0x601);
+ spi_write_reg(0x38, 0x504);
+ spi_write_reg(0x39, 0x504);
+}
+
+static void lcd_display_on_seq(void)
+{
+ spi_write_reg(0x7, 1);
+ wait_nr_frames(1);
+ spi_write_reg(0x7, 0x101);
+ wait_nr_frames(2);
+ spi_write_reg(0x76, 0x2213);
+ spi_write_reg(0x1c, 0x6650);
+ spi_write_reg(0xb, 0x33e1);
+ spi_write_reg(0x76, 0);
+ spi_write_reg(0x7, 0x103);
+}
+
+static void lcd_display_off_seq(void)
+{
+ spi_write_reg(0xb, 0x30e1);
+ spi_write_reg(0x7, 0x102);
+ wait_nr_frames(2);
+ spi_write_reg(0x7, 0);
+ spi_write_reg(0x12, 0);
+ spi_write_reg(0x10, 0x100);
+}
+
+static void lcd_standby_in_seq(void)
+{
+ lcd_display_off_seq();
+ spi_write_reg(0x10, 0x1);
+}
+
+static void lcd_standby_out_seq(void)
+{
+ spi_write_reg(0x10, 0);
+ lcd_power_seq();
+ lcd_display_on_seq();
+}
+
+/**
+ * Rockbox
+ */
+
+void lcd_init_device(void)
+{
+ semaphore_init(&g_wait_sema, 1, 0);
+#ifdef HAVE_LCD_ENABLE
+ lcd_on = true;
+#endif
+ /** lcd is 320x240, data bus is 8-bit, depth is 24-bit so we need 3clk/pix
+ * by running PIX clock at 24MHz we can sustain ~100 fps */
+ imx233_clkctrl_enable(CLK_PIX, false);
+ imx233_clkctrl_set_div(CLK_PIX, 2);
+ imx233_clkctrl_set_bypass(CLK_PIX, true); /* use XTAL */
+ imx233_clkctrl_enable(CLK_PIX, true);
+ imx233_dma_reset_channel(APB_LCDIF);
+ imx233_dma_clkgate_channel(APB_LCDIF, true);
+ imx233_lcdif_init();
+ imx233_lcdif_setup_dotclk_pins(8, false);
+ imx233_lcdif_set_word_length(8);
+ /** Datasheet states:
+ * 257H >= VBP >= 3H, VBP > VLW, VFP > 1H
+ * 1533clk >= HBP >= 24clk, HBP > HLW, HFP >= 4clk
+ *
+ * Take VLW=1H, VBP=3H, VFP=2H, HLW=8, HBP=24, HFP=4
+ * Take 3clk/pix because we send 24-bit/pix with 8-bit data bus
+ * Keep consistent with register setting in lcd_init_seq
+ */
+ imx233_lcdif_setup_dotclk_ex(/*v_pulse_width*/1, /*v_back_porch*/3,
+ /*v_front_porch*/1, /*h_pulse_width*/8, /*h_back_porch*/24,
+ /*h_front_porch*/4, LCD_WIDTH, LCD_HEIGHT, /*clk_per_pix*/3,
+ /*enable_present*/false);
+ imx233_lcdif_set_byte_packing_format(0xf);
+ // prepare pins
+ spi_init();
+ imx233_pinctrl_acquire(1, 8, "lcd_power");
+ imx233_pinctrl_set_function(1, 8, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_enable_gpio(1, 8, true);
+ // power up
+ lcd_power(true);
+ // reset lcd
+ imx233_lcdif_reset_lcd(true);
+ mdelay(1);
+ imx233_lcdif_reset_lcd(false);
+ mdelay(1);
+ imx233_lcdif_reset_lcd(true);
+ mdelay(1);
+ // setup registers
+ imx233_lcdif_enable_sync_signals(true); // we need frame signals during init
+ lcd_power_seq();
+ lcd_init_seq();
+ lcd_display_on_seq();
+ // setup refresh
+ unsigned size = IMX233_FRAMEBUFFER_SIZE;
+ uint8_t *frame_p = FRAME;
+ for(int i = 0; i < NR_CMDS; i++)
+ {
+ unsigned xfer = MIN(IMX233_MAX_SINGLE_DMA_XFER_SIZE, size);
+ lcdif_dma[i].dma.next = &lcdif_dma[(i + 1) % NR_CMDS].dma;
+ lcdif_dma[i].dma.cmd = BF_OR3(APB_CHx_CMD, CHAIN(1),
+ COMMAND(BV_APB_CHx_CMD_COMMAND__READ), XFER_COUNT(xfer));
+ lcdif_dma[i].dma.buffer = frame_p;
+ size -= xfer;
+ frame_p += xfer;
+ }
+ imx233_dma_start_command(APB_LCDIF, &lcdif_dma[0].dma);
+ BF_SET(LCDIF_CTRL, RUN);
+}
+
+#ifdef HAVE_LCD_ENABLE
+bool lcd_active(void)
+{
+ return lcd_on;
+}
+
+void lcd_enable(bool enable)
+{
+ if(lcd_on == enable)
+ return;
+
+ lcd_on = enable;
+}
+#endif
+
+void lcd_update(void)
+{
+ lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
+}
+
+void lcd_update_rect(int x, int y, int w, int h)
+{
+ #ifdef HAVE_LCD_ENABLE
+ if(!lcd_on)
+ return;
+ #endif
+ uint8_t *p = FRAME;
+ for(int y = 0; y < LCD_HEIGHT; y++)
+ for(int x = 0; x < LCD_WIDTH; x++)
+ {
+ uint16_t pix = *FBADDR(x,y);
+ *p++ = RGB_UNPACK_RED(pix);
+ *p++ = RGB_UNPACK_GREEN(pix);
+ *p++ = RGB_UNPACK_BLUE(pix);
+ }
+}
diff --git a/firmware/target/arm/imx233/creative-zen/power-zen.c b/firmware/target/arm/imx233/creative-zen/power-zen.c
new file mode 100644
index 0000000000..81157da511
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/power-zen.c
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "system.h"
+#include "power.h"
+#include "tuner.h"
+#include "fmradio_i2c.h"
+#include "pinctrl-imx233.h"
+#include "power-imx233.h"
+
+static bool tuner_enable = false;
+
+bool tuner_power(bool enable)
+{
+ if(enable != tuner_enable)
+ {
+ tuner_enable = enable;
+ }
+ return tuner_enable;
+}
+
+bool tuner_powered(void)
+{
+ return tuner_enable;
+} \ No newline at end of file
diff --git a/firmware/target/arm/imx233/creative-zen/powermgmt-target.h b/firmware/target/arm/imx233/creative-zen/powermgmt-target.h
new file mode 100644
index 0000000000..716ee4dac3
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/powermgmt-target.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef POWERMGMT_TARGET_H
+#define POWERMGMT_TARGET_H
+
+#include "config.h"
+#include "powermgmt-imx233.h"
+
+/* ZEN X-Fi OF settings:
+ * - current ramp slope:
+ * - conditioning threshold voltage:
+ * - conditioning max voltage:
+ * - conditioning current:
+ * - conditioning timeout:
+ * - charging voltage:
+ * - charging current:
+ * - charging threshold current:
+ * - charging timeout:
+ * - top off period:
+ * - high die temperature:
+ * - low die temperature:
+ * - safe die temperature current:
+ * - battery temperature channel:
+ * - high battery temperature:
+ * - low battery temperature:
+ * - safe battery temperature current:
+ * - low DCDC battery voltage:
+ */
+
+#define IMX233_CHARGE_CURRENT 200
+#define IMX233_STOP_CURRENT 30
+#define IMX233_TOPOFF_TIMEOUT (30 * 60 * HZ)
+#define IMX233_CHARGING_TIMEOUT (4 * 3600 * HZ)
+#define IMX233_DIE_TEMP_HIGH 71
+#define IMX233_DIE_TEMP_LOW 56
+
+#endif /* POWERMGMT_TARGET_H */
diff --git a/firmware/target/arm/imx233/creative-zen/powermgmt-zen.c b/firmware/target/arm/imx233/creative-zen/powermgmt-zen.c
new file mode 100644
index 0000000000..1e986813f9
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zen/powermgmt-zen.c
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include "powermgmt-target.h"
+#include "power-imx233.h"
+
+#warning FIXME calibrate
+
+const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
+{
+ 0
+};
+
+const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
+{
+ 0
+};
+
+/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
+const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
+{
+ /* Sansa Fuze+ Li Ion 600mAH figured from discharge curve */
+ { 3100, 3650, 3720, 3750, 3780, 3820, 3880, 4000, 4040, 4125, 4230 },
+};
+
+/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
+const unsigned short percent_to_volt_charge[11] =
+{
+ /* Sansa Fuze+ Li Ion 600mAH figured from charge curve */
+ 3480, 3790, 3845, 3880, 3900, 3935, 4005, 4070, 4150, 4250, 4335
+}; \ No newline at end of file