summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_jz47xx/onda_vx767
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/onda_vx767')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/onda_vx767/backlight-ondavx767.c80
-rw-r--r--firmware/target/mips/ingenic_jz47xx/onda_vx767/button-onda_vx767.c (renamed from firmware/target/mips/ingenic_jz47xx/onda_vx767/button-ondavx767.c)0
-rw-r--r--firmware/target/mips/ingenic_jz47xx/onda_vx767/lcd-onda_vx767.c (renamed from firmware/target/mips/ingenic_jz47xx/onda_vx767/lcd-ondavx767.c)7
-rw-r--r--firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c127
4 files changed, 133 insertions, 81 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx767/backlight-ondavx767.c b/firmware/target/mips/ingenic_jz47xx/onda_vx767/backlight-ondavx767.c
deleted file mode 100644
index 9deab7712a..0000000000
--- a/firmware/target/mips/ingenic_jz47xx/onda_vx767/backlight-ondavx767.c
+++ /dev/null
@@ -1,80 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
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 "jz4740.h"
24#include "backlight-target.h"
25
26#define GPIO_PWM 123
27#define PWM_CHN 7
28#define PWM_FULL 101
29
30static void set_backlight(int unk, int val)
31{
32 if(val == 0)
33 __gpio_as_pwm7();
34 else
35 {
36 REG_TCU_TCSR(7) |= 2;
37 REG_TCU_TCSR(7) &= ~0x100;
38 int tmp;
39 tmp = (unk/2 + __cpm_get_rtcclk()) / unk;
40 if(tmp > 0xFFFF)
41 tmp = 0xFFFF;
42
43 __tcu_set_half_data(7, (tmp * unk * 1374389535) >> 5);
44 __tcu_set_full_data(7, tmp);
45
46 REG_TCU_TSCR = (1 << 7);
47 REG_TCU_TESR = (1 << 7);
48
49 __tcu_enable_pwm_output(7);
50 }
51 __tcu_set_count(7, 0);
52}
53
54bool _backlight_init(void)
55{
56 __gpio_as_pwm7();
57
58 __tcu_stop_counter(7);
59 __tcu_disable_pwm_output(7);
60
61 set_backlight(300, 7);
62
63 return true;
64}
65void _backlight_on(void)
66{
67 set_backlight(300, 7);
68}
69void _backlight_off(void)
70{
71 set_backlight(300, 0);
72}
73
74#ifdef HAVE_BACKLIGHT_BRIGHTNESS
75void _backlight_set_brightness(int brightness)
76{
77 (void)brightness;
78 return;
79}
80#endif
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx767/button-ondavx767.c b/firmware/target/mips/ingenic_jz47xx/onda_vx767/button-onda_vx767.c
index d98df9c42d..d98df9c42d 100644
--- a/firmware/target/mips/ingenic_jz47xx/onda_vx767/button-ondavx767.c
+++ b/firmware/target/mips/ingenic_jz47xx/onda_vx767/button-onda_vx767.c
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx767/lcd-ondavx767.c b/firmware/target/mips/ingenic_jz47xx/onda_vx767/lcd-onda_vx767.c
index c8288a4450..3cf2586d46 100644
--- a/firmware/target/mips/ingenic_jz47xx/onda_vx767/lcd-ondavx767.c
+++ b/firmware/target/mips/ingenic_jz47xx/onda_vx767/lcd-onda_vx767.c
@@ -23,7 +23,7 @@
23#include "jz4740.h" 23#include "jz4740.h"
24#include "lcd-target.h" 24#include "lcd-target.h"
25 25
26#define PIN_CS_N (32*1+17) /* Chip select */ 26#define PIN_CS_N (32*1+17) /* Chip select */
27#define PIN_RESET_N (32*1+18) /* Reset */ 27#define PIN_RESET_N (32*1+18) /* Reset */
28#define PIN_UNK_N (32*2+19) 28#define PIN_UNK_N (32*2+19)
29 29
@@ -208,3 +208,8 @@ void lcd_off(void)
208{ 208{
209 _display_off(); 209 _display_off();
210} 210}
211
212void lcd_set_contrast(int val)
213{
214 (void)val;
215}
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c b/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c
new file mode 100644
index 0000000000..67c6a90631
--- /dev/null
+++ b/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c
@@ -0,0 +1,127 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Maurus Cuelenaere
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 "jz4740.h"
25#include "powermgmt.h"
26#include "kernel.h"
27#include "logf.h"
28
29#define SADC_CFG_INIT ( \
30 (2 << SADC_CFG_CLKOUT_NUM_BIT) | \
31 (1 << SADC_CFG_CLKDIV_BIT) | \
32 SADC_CFG_PBAT_HIGH | \
33 SADC_CFG_CMD_INT_PEN \
34 )
35
36static volatile unsigned short bat_val;
37static struct mutex battery_mtx;
38
39const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
40{
41 /* TODO */
42 1000
43};
44
45const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
46{
47 /* TODO */
48 900
49};
50
51/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
52const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
53{
54 /* TODO */
55 { 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000 },
56};
57
58/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
59const unsigned short percent_to_volt_charge[11] =
60{
61 /* TODO */
62 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000
63};
64
65/* VBAT = (BDATA/4096) * 7.5V */
66#define BATTERY_SCALE_FACTOR 1875
67
68/* Returns battery voltage from ADC [millivolts] */
69unsigned int battery_adc_voltage(void)
70{
71 unsigned int dummy, timeout=HZ/4;
72
73 mutex_lock(&battery_mtx);
74
75 dummy = REG_SADC_BATDAT;
76 dummy = REG_SADC_BATDAT;
77
78 REG_SADC_ENA |= SADC_ENA_PBATEN;
79 bat_val = 0;
80
81 /* primitive wakeup event */
82 while(bat_val == 0 && timeout--)
83 sleep(0);
84
85 logf("%d %d", bat_val, (bat_val*BATTERY_SCALE_FACTOR)>>10);
86
87 mutex_unlock(&battery_mtx);
88
89 return (bat_val*BATTERY_SCALE_FACTOR)>>10;
90}
91
92void adc_init(void)
93{
94 __cpm_start_sadc();
95 REG_SADC_ENA = 0;
96 REG_SADC_STATE &= ~REG_SADC_STATE;
97 REG_SADC_CTRL = 0x1F;
98
99 REG_SADC_CFG = SADC_CFG_INIT;
100
101 system_enable_irq(IRQ_SADC);
102
103 REG_SADC_SAMETIME = 10;
104 REG_SADC_WAITTIME = 100;
105 REG_SADC_STATE &= ~REG_SADC_STATE;
106 REG_SADC_CTRL = ~SADC_CTRL_PBATRDYM;
107 REG_SADC_ENA = 0;
108
109 mutex_init(&battery_mtx);
110}
111
112/* Interrupt handler */
113void SADC(void)
114{
115 unsigned char state;
116 unsigned char sadcstate;
117
118 sadcstate = REG_SADC_STATE;
119 state = REG_SADC_STATE & (~REG_SADC_CTRL);
120 REG_SADC_STATE &= sadcstate;
121
122 if(state & SADC_CTRL_PBATRDYM)
123 {
124 bat_val = REG_SADC_BATDAT;
125 /* Battery AD IRQ */
126 }
127}