summaryrefslogtreecommitdiff
path: root/firmware/target/arm/philips/hdd6330
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/philips/hdd6330')
-rw-r--r--firmware/target/arm/philips/hdd6330/adc-target.h35
-rw-r--r--firmware/target/arm/philips/hdd6330/button-hdd6330.c125
-rw-r--r--firmware/target/arm/philips/hdd6330/button-target.h63
-rw-r--r--firmware/target/arm/philips/hdd6330/lcd-hdd6330.c159
-rw-r--r--firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c72
5 files changed, 454 insertions, 0 deletions
diff --git a/firmware/target/arm/philips/hdd6330/adc-target.h b/firmware/target/arm/philips/hdd6330/adc-target.h
new file mode 100644
index 0000000000..bf97081e35
--- /dev/null
+++ b/firmware/target/arm/philips/hdd6330/adc-target.h
@@ -0,0 +1,35 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Barry Wardell
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 2
25
26#define ADC_BATTERY 0
27#define ADC_UNKNOWN_1 1
28#define ADC_UNKNOWN_2 2
29#define ADC_UNKNOWN_3 3
30#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
31
32/* Force a scan now */
33unsigned short adc_scan(int channel);
34
35#endif
diff --git a/firmware/target/arm/philips/hdd6330/button-hdd6330.c b/firmware/target/arm/philips/hdd6330/button-hdd6330.c
new file mode 100644
index 0000000000..ab06c0cf1a
--- /dev/null
+++ b/firmware/target/arm/philips/hdd6330/button-hdd6330.c
@@ -0,0 +1,125 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Mark Arigo
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.h"
24#include "backlight.h"
25#include "synaptics-mep.h"
26
27/*#define LOGF_ENABLE*/
28#include "logf.h"
29
30static int int_btn = BUTTON_NONE;
31
32/*
33 * Generate a click sound from the player (not in headphones yet)
34 * TODO: integrate this with the "key click" option
35 */
36void button_click(void)
37{
38 GPO32_ENABLE |= 0x2000;
39 GPO32_VAL |= 0x2000;
40 udelay(1000);
41 GPO32_VAL &= ~0x2000;
42}
43
44#ifndef BOOTLOADER
45void button_init_device(void)
46{
47 /* The touchpad is powered on and initialized in power-hdd1630.c
48 since it needs to be ready for both buttons and button lights. */
49}
50
51/*
52 * Button interrupt handler
53 */
54void button_int(void)
55{
56 char data[4];
57 int val;
58
59 int_btn = BUTTON_NONE;
60
61 val = touchpad_read_device(data, 4);
62
63 if (val == MEP_BUTTON_HEADER)
64 {
65 /* Buttons packet */
66 if (data[1] & 0x1)
67 int_btn |= BUTTON_LEFT;
68 if (data[1] & 0x2)
69 int_btn |= BUTTON_RIGHT;
70 }
71 else if (val == MEP_ABSOLUTE_HEADER)
72 {
73 /* Absolute packet - the finger is on the vertical strip.
74 Position ranges from 1-4095, with 1 at the bottom. */
75 val = ((data[1] >> 4) << 8) | data[2]; /* position */
76
77 if ((val > 0) && (val <= 1365))
78 int_btn |= BUTTON_DOWN;
79 else if ((val > 1365) && (val <= 2730))
80 int_btn |= BUTTON_SELECT;
81 else if ((val > 2730) && (val <= 4095))
82 int_btn |= BUTTON_UP;
83 }
84}
85#else
86void button_init_device(void){}
87#endif /* bootloader */
88
89bool button_hold(void)
90{
91 return !(GPIOJ_INPUT_VAL & 0x8);
92}
93
94/*
95 * Get button pressed from hardware
96 */
97int button_read_device(void)
98{
99 static int btn_old = BUTTON_NONE;
100 int btn = int_btn;
101
102 /* Hold */
103 if(button_hold())
104 return BUTTON_NONE;
105
106 /* Device buttons */
107 if (!(GPIOA_INPUT_VAL & 0x01)) btn |= BUTTON_MENU;
108 if (!(GPIOA_INPUT_VAL & 0x02)) btn |= BUTTON_VOL_UP;
109 if (!(GPIOA_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
110 if (!(GPIOA_INPUT_VAL & 0x08)) btn |= BUTTON_VIEW;
111 if (!(GPIOD_INPUT_VAL & 0x20)) btn |= BUTTON_PLAYLIST;
112 if (!(GPIOD_INPUT_VAL & 0x40)) btn |= BUTTON_POWER;
113
114 if ((btn != btn_old) && (btn != BUTTON_NONE))
115 button_click();
116
117 btn_old = btn;
118
119 return btn;
120}
121
122bool headphones_inserted(void)
123{
124 return (GPIOE_INPUT_VAL & 0x80) ? true : false;
125}
diff --git a/firmware/target/arm/philips/hdd6330/button-target.h b/firmware/target/arm/philips/hdd6330/button-target.h
new file mode 100644
index 0000000000..b7fc21aca2
--- /dev/null
+++ b/firmware/target/arm/philips/hdd6330/button-target.h
@@ -0,0 +1,63 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Mark Arigo
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#ifndef _BUTTON_TARGET_H_
23#define _BUTTON_TARGET_H_
24
25#include <stdbool.h>
26#include "config.h"
27
28#define MEP_BUTTON_HEADER 0x19
29#define MEP_BUTTON_ID 0x9
30#define MEP_ABSOLUTE_HEADER 0x0b
31
32#define HAS_BUTTON_HOLD
33
34bool button_hold(void);
35void button_init_device(void);
36int button_read_device(void);
37
38#ifndef BOOTLOADER
39void button_int(void);
40#endif
41
42/* Main unit's buttons */
43#define BUTTON_POWER 0x00000001
44#define BUTTON_PLAYLIST 0x00000002
45#define BUTTON_MENU 0x00000004
46#define BUTTON_VIEW 0x00000008
47#define BUTTON_VOL_UP 0x00000010
48#define BUTTON_VOL_DOWN 0x00000020
49#define BUTTON_SELECT 0x00000040
50#define BUTTON_LEFT 0x00000080
51#define BUTTON_RIGHT 0x00000100
52#define BUTTON_UP 0x00000200
53#define BUTTON_DOWN 0x00000400
54
55#define BUTTON_MAIN 0x00000fff
56
57/* No Remote control */
58#define BUTTON_REMOTE 0
59
60#define POWEROFF_BUTTON BUTTON_POWER
61#define POWEROFF_COUNT 10
62
63#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/philips/hdd6330/lcd-hdd6330.c b/firmware/target/arm/philips/hdd6330/lcd-hdd6330.c
new file mode 100644
index 0000000000..3d9cb036f1
--- /dev/null
+++ b/firmware/target/arm/philips/hdd6330/lcd-hdd6330.c
@@ -0,0 +1,159 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Mark Arigo
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 "cpu.h"
23#include "lcd.h"
24#include "kernel.h"
25#include "system.h"
26
27/* Display status */
28static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
29
30/* wait for LCD */
31static inline void lcd_wait_write(void)
32{
33 int i = 0;
34 while (LCD2_PORT & LCD2_BUSY_MASK)
35 {
36 if (i < 2000)
37 i++;
38 else
39 LCD2_PORT &= ~LCD2_BUSY_MASK;
40 }
41}
42
43/* send LCD data */
44static void lcd_send_data(unsigned data)
45{
46 lcd_wait_write();
47 LCD2_PORT = LCD2_DATA_MASK | (data & 0xff);
48}
49
50/* send LCD command */
51static void lcd_send_cmd(unsigned cmd)
52{
53 lcd_wait_write();
54 LCD2_PORT = LCD2_CMD_MASK | (cmd & 0xff);
55 lcd_wait_write();
56}
57
58static inline void lcd_send_pixel(unsigned pixel)
59{
60 lcd_send_data(pixel >> 8);
61 lcd_send_data(pixel);
62}
63
64void lcd_init_device(void)
65{
66 /* init handled by the OF bootloader */
67}
68
69/*** hardware configuration ***/
70int lcd_default_contrast(void)
71{
72 return DEFAULT_CONTRAST_SETTING;
73}
74
75void lcd_set_contrast(int val)
76{
77 (void)val;
78}
79
80void lcd_set_invert_display(bool yesno)
81{
82 (void)yesno;
83}
84
85/* turn the display upside down (call lcd_update() afterwards) */
86void lcd_set_flip(bool yesno)
87{
88 (void)yesno;
89}
90
91void lcd_yuv_set_options(unsigned options)
92{
93 lcd_yuv_options = options;
94}
95
96/* Performance function to blit a YUV bitmap directly to the LCD */
97void lcd_blit_yuv(unsigned char * const src[3],
98 int src_x, int src_y, int stride,
99 int x, int y, int width, int height)
100{
101 (void)src;
102 (void)src_x;
103 (void)src_y;
104 (void)stride;
105 (void)x;
106 (void)y;
107 (void)width;
108 (void)height;
109}
110
111/* Update the display.
112 This must be called after all other LCD functions that change the display. */
113void lcd_update(void)
114{
115 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
116}
117
118/* Update a fraction of the display. */
119void lcd_update_rect(int x, int y, int width, int height)
120{
121 const fb_data *addr;
122
123 if (x + width >= LCD_WIDTH)
124 width = LCD_WIDTH - x;
125 if (y + height >= LCD_HEIGHT)
126 height = LCD_HEIGHT - y;
127
128 if ((width <= 0) || (height <= 0))
129 return; /* Nothing left to do. */
130
131 addr = &lcd_framebuffer[y][x];
132
133 lcd_send_cmd(0x01);
134 lcd_send_data(0x48);
135
136 lcd_send_cmd(0x05);
137 lcd_send_data(0x0f);
138
139 lcd_send_cmd(0x08);
140 lcd_send_data(y);
141
142 lcd_send_cmd(0x09);
143 lcd_send_data(y + height - 1);
144
145 lcd_send_cmd(0x0a);
146 lcd_send_data(x + 16);
147
148 lcd_send_cmd(0x0b);
149 lcd_send_data(x + width - 1 + 16);
150
151 lcd_send_cmd(0x06);
152 do {
153 int w = width;
154 do {
155 lcd_send_pixel(*addr++);
156 } while (--w > 0);
157 addr += LCD_WIDTH - width;
158 } while (--height > 0);
159}
diff --git a/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c b/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
new file mode 100644
index 0000000000..33bbb6af48
--- /dev/null
+++ b/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
@@ -0,0 +1,72 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
11 * Revisions copyright (C) 2005 by Gerald Van Baren
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include "config.h"
24#include "adc.h"
25#include "powermgmt.h"
26
27#define SMLAL(lo, hi, x, y) \
28 asm volatile ("smlal %0, %1, %2, %3" \
29 : "+r" (lo), "+r" (hi) \
30 : "%r" (x), "r" (y))
31
32const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
33{
34 3550
35};
36
37const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
38{
39 3500
40};
41
42/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
43const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
44{
45 { 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990 },
46};
47
48#if CONFIG_CHARGING
49/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
50const unsigned short percent_to_volt_charge[11] =
51{
52 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990
53};
54#endif /* CONFIG_CHARGING */
55
56#define BATTERY_SCALE_FACTOR 4200
57/* full-scale ADC readout (2^10) in millivolt */
58
59/* Returns battery voltage from ADC [millivolts] */
60unsigned int battery_adc_voltage(void)
61{
62 /* return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; */
63
64 /* This may be overly complicated (pulled from the OF) */
65 int lo = 0;
66 int val = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR;
67
68 SMLAL(lo, val, 0x8a42f871, val);
69 val>>= 9;
70 val -= (val >> 31);
71 return val;
72}