summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2010-04-09 01:21:53 +0000
committerMichael Sevakis <jethead71@rockbox.org>2010-04-09 01:21:53 +0000
commit7abf2b53a462612808d46d6d77a7f35261a0e5a3 (patch)
tree241304f7cd2b5d1c2a9e091fe56a33d2d2f8e816 /firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c
parent43304b87b0662d1619ac60e5297a1694aa580310 (diff)
downloadrockbox-7abf2b53a462612808d46d6d77a7f35261a0e5a3.tar.gz
rockbox-7abf2b53a462612808d46d6d77a7f35261a0e5a3.zip
Gigabeat S/i.MX31: Sort files in the /target tree into things that are SoC-generic (into /imx31) and player-specific (into /gigabeat-s, based upon current appearances). Move i2s clock init into the appropriate file. Housekeeping only-- no functional changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25547 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c242
1 files changed, 242 insertions, 0 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c
new file mode 100644
index 0000000000..ae158b811d
--- /dev/null
+++ b/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c
@@ -0,0 +1,242 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
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 "cpu.h"
24#include "system.h"
25#include "button.h"
26#include "backlight.h"
27#include "backlight-target.h"
28#include "avic-imx31.h"
29#include "ccm-imx31.h"
30#include "mc13783.h"
31
32/* Most code in here is taken from the Linux BSP provided by Freescale
33 * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved. */
34static uint32_t int_btn = BUTTON_NONE;
35static bool hold_button = false;
36#ifdef BOOTLOADER
37static bool initialized = false;
38#else
39static bool hold_button_old = false;
40#endif
41#define _button_hold() (GPIO3_DR & 0x10)
42
43static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
44{
45 static const struct key_mask_shift
46 {
47 uint8_t mask;
48 uint8_t shift;
49 } kms[3] =
50 {
51 { 0x1f, 0 }, /* BUTTON_LEFT...BUTTON_SELECT */
52 { 0x03, 5 }, /* BUTTON_BACK...BUTTON_MENU */
53 { 0x1f, 7 }, /* BUTTON_VOL_UP...BUTTON_NEXT */
54 };
55
56 int col;
57 /* Power button is handled separately on PMIC, remote read in headphone
58 * jack driver. */
59#ifdef HAVE_HEADPHONE_DETECTION
60 int button = int_btn & (BUTTON_POWER | BUTTON_REMOTE);
61#else
62 int button = int_btn & BUTTON_POWER;
63#endif
64
65 int oldlevel = disable_irq_save();
66
67 /* 1. Disable both (depress and release) keypad interrupts. */
68 KPP_KPSR &= ~(KPP_KPSR_KRIE | KPP_KPSR_KDIE);
69
70 for (col = 0; col < 3; col++) /* Col */
71 {
72 /* 2. Write 1s to KPDR[10:8] setting column data to 1s */
73 KPP_KPDR |= (0x7 << 8);
74
75 /* 3. Configure columns as totem pole outputs(for quick
76 * discharging of keypad capacitance) */
77 KPP_KPCR &= ~(0x7 << 8);
78
79 /* Give the columns time to discharge */
80 udelay(2);
81
82 /* 4. Configure columns as open-drain */
83 KPP_KPCR |= (0x7 << 8);
84
85 /* 5. Write a single column to 0, others to 1.
86 * 6. Sample row inputs and save data. Multiple key presses
87 * can be detected on a single column.
88 * 7. Repeat steps 2 - 6 for remaining columns. */
89
90 /* Col bit starts at 8th bit in KPDR */
91 KPP_KPDR &= ~(0x100 << col);
92
93 /* Delay added to avoid propagating the 0 from column to row
94 * when scanning. */
95 udelay(2);
96
97 /* Read row input */
98 button |= (~KPP_KPDR & kms[col].mask) << kms[col].shift;
99 }
100
101 /* 8. Return all columns to 0 in preparation for standby mode. */
102 KPP_KPDR &= ~(0x7 << 8);
103
104 /* 9. Clear KPKD and KPKR status bit(s) by writing to a .1.,
105 * set the KPKR synchronizer chain by writing "1" to KRSS register,
106 * clear the KPKD synchronizer chain by writing "1" to KDSC register */
107 KPP_KPSR = KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKR | KPP_KPSR_KPKD;
108
109 /* 10. Re-enable the appropriate keypad interrupt(s) so that the KDIE
110 * detects a key hold condition, or the KRIE detects a key-release
111 * event. */
112 if ((button & ~BUTTON_POWER) != BUTTON_NONE)
113 KPP_KPSR |= KPP_KPSR_KRIE;
114 else
115 KPP_KPSR |= KPP_KPSR_KDIE;
116
117 int_btn = button;
118
119 restore_irq(oldlevel);
120}
121
122bool button_hold(void)
123{
124 return _button_hold();
125}
126
127#ifdef HAVE_HEADPHONE_DETECTION
128/* Headphone driver pushes the data here */
129void button_headphone_set(int button)
130{
131 int oldstatus = disable_irq_save();
132 int_btn = (int_btn & ~BUTTON_REMOTE) | button;
133 restore_irq(oldstatus);
134}
135#endif
136
137int button_read_device(void)
138{
139 /* Simple poll of GPIO status */
140 hold_button = _button_hold();
141
142#ifndef BOOTLOADER
143 /* Backlight hold handling */
144 if (hold_button != hold_button_old)
145 {
146 hold_button_old = hold_button;
147 backlight_hold_changed(hold_button);
148 }
149#endif
150
151 /* Enable the keypad interrupt to cause it to fire if a key is down.
152 * KPP_HANDLER will clear and disable it after the scan. If no key
153 * is depressed then this bit will already be set in waiting for the
154 * first key down event. */
155 KPP_KPSR |= KPP_KPSR_KDIE;
156
157#ifdef HAVE_HEADPHONE_DETECTION
158 /* If hold, ignore any pressed button. Remote has its own hold
159 * switch, so return state regardless. */
160 return hold_button ? (int_btn & BUTTON_REMOTE) : int_btn;
161#else
162 /* If hold, ignore any pressed button. */
163 return hold_button ? BUTTON_NONE : int_btn;
164#endif
165}
166
167/* This is called from the mc13783 interrupt thread */
168void button_power_event(void)
169{
170 bool pressed =
171 (mc13783_read(MC13783_INTERRUPT_SENSE1) & MC13783_ONOFD1S) == 0;
172
173 /* Prevent KPP_HANDLER from changing things */
174 int oldlevel = disable_irq_save();
175
176 if (pressed)
177 {
178 int_btn |= BUTTON_POWER;
179 }
180 else
181 {
182 int_btn &= ~BUTTON_POWER;
183 }
184
185 restore_irq(oldlevel);
186}
187
188void button_init_device(void)
189{
190#ifdef BOOTLOADER
191 /* Can be called more than once in the bootloader */
192 if (initialized)
193 return;
194
195 initialized = true;
196#endif
197
198 /* Enable keypad clock */
199 ccm_module_clock_gating(CG_KPP, CGM_ON_RUN_WAIT);
200
201 /* 1. Enable number of rows in keypad (KPCR[4:0])
202 *
203 * Configure the rows/cols in KPP
204 * LSB nybble in KPP is for 5 rows
205 * MSB nybble in KPP is for 3 cols */
206 KPP_KPCR |= 0x1f;
207
208 /* 2. Write 0's to KPDR[10:8] */
209 KPP_KPDR &= ~(0x7 << 8);
210
211 /* 3. Configure the keypad columns as open-drain (KPCR[10:8]). */
212 KPP_KPCR |= (0x7 << 8);
213
214 /* 4. Configure columns as output, rows as input (KDDR[10:8,4:0]) */
215 KPP_KDDR = (KPP_KDDR | (0x7 << 8)) & ~0x1f;
216
217 /* 5. Clear the KPKD Status Flag and Synchronizer chain.
218 * 6. Set the KDIE control bit bit. */
219 KPP_KPSR = KPP_KPSR_KDIE | KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD;
220
221 avic_enable_int(INT_KPP, INT_TYPE_IRQ, INT_PRIO_DEFAULT, KPP_HANDLER);
222
223 button_power_event();
224 mc13783_enable_event(MC13783_ONOFD1_EVENT);
225
226#ifdef HAVE_HEADPHONE_DETECTION
227 headphone_init();
228#endif
229}
230
231#ifdef BUTTON_DRIVER_CLOSE
232void button_close_device(void)
233{
234 int oldlevel = disable_irq_save();
235
236 avic_disable_int(INT_KPP);
237 KPP_KPSR &= ~(KPP_KPSR_KRIE | KPP_KPSR_KDIE);
238 int_btn = BUTTON_NONE;
239
240 restore_irq(oldlevel);
241}
242#endif /* BUTTON_DRIVER_CLOSE */