2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2007-09-21 15:51:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "backlight-target.h"
|
2008-02-09 07:59:53 +00:00
|
|
|
#include "avic-imx31.h"
|
2009-03-22 02:13:27 +00:00
|
|
|
#include "ccm-imx31.h"
|
2008-05-21 08:42:11 +00:00
|
|
|
#include "mc13783.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
|
|
|
|
/* Most code in here is taken from the Linux BSP provided by Freescale
|
|
|
|
* Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved. */
|
2008-05-10 18:00:11 +00:00
|
|
|
#ifdef BOOTLOADER
|
|
|
|
static bool initialized = false;
|
2010-12-29 18:20:31 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
static unsigned long ext_btn = BUTTON_NONE; /* Buttons not on KPP */
|
2010-12-29 18:20:31 +00:00
|
|
|
static bool hold_button = false;
|
|
|
|
#ifndef BOOTLOADER
|
2008-02-09 07:59:53 +00:00
|
|
|
static bool hold_button_old = false;
|
2008-05-10 18:00:11 +00:00
|
|
|
#endif
|
2010-12-29 18:20:31 +00:00
|
|
|
|
2008-02-09 07:59:53 +00:00
|
|
|
#define _button_hold() (GPIO3_DR & 0x10)
|
|
|
|
|
2010-12-29 18:20:31 +00:00
|
|
|
/* Scan the keypad port and return the pressed buttons */
|
|
|
|
static int kpp_scan(void)
|
2008-02-09 07:59:53 +00:00
|
|
|
{
|
2008-05-09 21:19:58 +00:00
|
|
|
static const struct key_mask_shift
|
2008-02-09 07:59:53 +00:00
|
|
|
{
|
2008-05-09 21:19:58 +00:00
|
|
|
uint8_t mask;
|
|
|
|
uint8_t shift;
|
|
|
|
} kms[3] =
|
|
|
|
{
|
|
|
|
{ 0x1f, 0 }, /* BUTTON_LEFT...BUTTON_SELECT */
|
|
|
|
{ 0x03, 5 }, /* BUTTON_BACK...BUTTON_MENU */
|
|
|
|
{ 0x1f, 7 }, /* BUTTON_VOL_UP...BUTTON_NEXT */
|
2008-02-09 07:59:53 +00:00
|
|
|
};
|
|
|
|
|
2010-12-29 18:20:31 +00:00
|
|
|
int button = BUTTON_NONE;
|
2008-04-24 20:18:41 +00:00
|
|
|
int oldlevel = disable_irq_save();
|
2010-12-29 18:20:31 +00:00
|
|
|
int col;
|
2008-02-09 07:59:53 +00:00
|
|
|
|
|
|
|
for (col = 0; col < 3; col++) /* Col */
|
|
|
|
{
|
|
|
|
/* 2. Write 1s to KPDR[10:8] setting column data to 1s */
|
|
|
|
KPP_KPDR |= (0x7 << 8);
|
|
|
|
|
|
|
|
/* 3. Configure columns as totem pole outputs(for quick
|
|
|
|
* discharging of keypad capacitance) */
|
|
|
|
KPP_KPCR &= ~(0x7 << 8);
|
|
|
|
|
|
|
|
/* Give the columns time to discharge */
|
2009-01-23 01:23:25 +00:00
|
|
|
udelay(2);
|
2008-02-09 07:59:53 +00:00
|
|
|
|
|
|
|
/* 4. Configure columns as open-drain */
|
|
|
|
KPP_KPCR |= (0x7 << 8);
|
|
|
|
|
|
|
|
/* 5. Write a single column to 0, others to 1.
|
|
|
|
* 6. Sample row inputs and save data. Multiple key presses
|
|
|
|
* can be detected on a single column.
|
|
|
|
* 7. Repeat steps 2 - 6 for remaining columns. */
|
|
|
|
|
|
|
|
/* Col bit starts at 8th bit in KPDR */
|
2008-05-09 21:19:58 +00:00
|
|
|
KPP_KPDR &= ~(0x100 << col);
|
2008-02-09 07:59:53 +00:00
|
|
|
|
|
|
|
/* Delay added to avoid propagating the 0 from column to row
|
|
|
|
* when scanning. */
|
2009-01-23 01:23:25 +00:00
|
|
|
udelay(2);
|
2008-02-09 07:59:53 +00:00
|
|
|
|
|
|
|
/* Read row input */
|
2008-05-09 21:19:58 +00:00
|
|
|
button |= (~KPP_KPDR & kms[col].mask) << kms[col].shift;
|
2008-02-09 07:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 8. Return all columns to 0 in preparation for standby mode. */
|
|
|
|
KPP_KPDR &= ~(0x7 << 8);
|
|
|
|
|
|
|
|
/* 9. Clear KPKD and KPKR status bit(s) by writing to a .1.,
|
|
|
|
* set the KPKR synchronizer chain by writing "1" to KRSS register,
|
|
|
|
* clear the KPKD synchronizer chain by writing "1" to KDSC register */
|
|
|
|
KPP_KPSR = KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKR | KPP_KPSR_KPKD;
|
|
|
|
|
2009-02-03 10:55:30 +00:00
|
|
|
restore_irq(oldlevel);
|
2010-12-29 18:20:31 +00:00
|
|
|
|
|
|
|
return button;
|
2008-02-09 07:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool button_hold(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-02-09 07:59:53 +00:00
|
|
|
return _button_hold();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 20:55:17 +00:00
|
|
|
#ifdef HAVE_HEADPHONE_DETECTION
|
|
|
|
/* Headphone driver pushes the data here */
|
|
|
|
void button_headphone_set(int button)
|
|
|
|
{
|
|
|
|
int oldstatus = disable_irq_save();
|
2010-12-29 18:20:31 +00:00
|
|
|
ext_btn = (ext_btn & ~BUTTON_REMOTE) | button;
|
2009-01-23 20:55:17 +00:00
|
|
|
restore_irq(oldstatus);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2008-02-09 07:59:53 +00:00
|
|
|
/* Simple poll of GPIO status */
|
|
|
|
hold_button = _button_hold();
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
#ifndef BOOTLOADER
|
2008-02-09 07:59:53 +00:00
|
|
|
/* Backlight hold handling */
|
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
{
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
backlight_hold_changed(hold_button);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
2008-05-10 18:00:11 +00:00
|
|
|
#endif
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2010-12-29 18:20:31 +00:00
|
|
|
int button = ext_btn;
|
|
|
|
|
|
|
|
/* Check status for key down flag and scan port if so indicated. */
|
|
|
|
if (KPP_KPSR & KPP_KPSR_KPKD)
|
|
|
|
button |= kpp_scan();
|
2008-04-24 20:18:41 +00:00
|
|
|
|
2009-01-23 22:45:33 +00:00
|
|
|
#ifdef HAVE_HEADPHONE_DETECTION
|
|
|
|
/* If hold, ignore any pressed button. Remote has its own hold
|
|
|
|
* switch, so return state regardless. */
|
2010-12-29 18:20:31 +00:00
|
|
|
return hold_button ? (button & BUTTON_REMOTE) : button;
|
2009-01-23 22:45:33 +00:00
|
|
|
#else
|
|
|
|
/* If hold, ignore any pressed button. */
|
2010-12-29 18:20:31 +00:00
|
|
|
return hold_button ? BUTTON_NONE : button;
|
2009-01-23 22:45:33 +00:00
|
|
|
#endif
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Helper to update the power button status */
|
|
|
|
static void power_button_update(bool pressed)
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2012-01-02 18:32:35 +00:00
|
|
|
bitmod32(&ext_btn, pressed ? BUTTON_POWER : 0, BUTTON_POWER);
|
|
|
|
}
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Power button event - called from PMIC ISR */
|
|
|
|
void button_power_event(void)
|
|
|
|
{
|
|
|
|
power_button_update(!mc13783_event_sense(MC13783_ONOFD1_EVENT));
|
2008-04-12 16:56:45 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
|
|
|
#ifdef BOOTLOADER
|
|
|
|
/* Can be called more than once in the bootloader */
|
|
|
|
if (initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Enable keypad clock */
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_KPP, CGM_ON_RUN_WAIT);
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
/* 1. Enable number of rows in keypad (KPCR[4:0])
|
|
|
|
*
|
|
|
|
* Configure the rows/cols in KPP
|
|
|
|
* LSB nybble in KPP is for 5 rows
|
|
|
|
* MSB nybble in KPP is for 3 cols */
|
|
|
|
KPP_KPCR |= 0x1f;
|
|
|
|
|
|
|
|
/* 2. Write 0's to KPDR[10:8] */
|
|
|
|
KPP_KPDR &= ~(0x7 << 8);
|
|
|
|
|
|
|
|
/* 3. Configure the keypad columns as open-drain (KPCR[10:8]). */
|
|
|
|
KPP_KPCR |= (0x7 << 8);
|
|
|
|
|
|
|
|
/* 4. Configure columns as output, rows as input (KDDR[10:8,4:0]) */
|
|
|
|
KPP_KDDR = (KPP_KDDR | (0x7 << 8)) & ~0x1f;
|
|
|
|
|
|
|
|
/* 5. Clear the KPKD Status Flag and Synchronizer chain.
|
|
|
|
* 6. Set the KDIE control bit bit. */
|
2010-12-29 18:20:31 +00:00
|
|
|
KPP_KPSR = KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
power_button_update(!(mc13783_read(MC13783_INTERRUPT_SENSE1)
|
|
|
|
& MC13783_ONOFD1S));
|
|
|
|
mc13783_enable_event(MC13783_ONOFD1_EVENT, true);
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_HEADPHONE_DETECTION
|
2009-01-23 20:55:17 +00:00
|
|
|
headphone_init();
|
2008-05-21 08:42:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BUTTON_DRIVER_CLOSE
|
|
|
|
void button_close_device(void)
|
|
|
|
{
|
2010-12-29 18:20:31 +00:00
|
|
|
if (!initialized)
|
|
|
|
return;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2010-12-29 18:20:31 +00:00
|
|
|
/* Assumes HP detection is not available */
|
|
|
|
initialized = false;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2012-01-03 06:13:59 +00:00
|
|
|
mc13783_enable_event(MC13783_ONOFD1_EVENT, false);
|
2010-12-29 18:20:31 +00:00
|
|
|
ext_btn = BUTTON_NONE;
|
2008-05-21 08:42:11 +00:00
|
|
|
}
|
|
|
|
#endif /* BUTTON_DRIVER_CLOSE */
|