From a9c20f5789c13b486d217024a020f9d6163e2d51 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 21 May 2008 08:42:11 +0000 Subject: Gigabeat S: 1) Rework event handling and static registration mechanism. No target- specific code in mc13783 driver. GPIO event driver interfaces more cleanly. 2) Somewhat related - enable thread priority for bootloader which is desireable here (ffs is used for GPIO event enabling anyway and that goes along with priority). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17593 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/imx31/gigabeat-s/button-imx31.c | 123 +++++++++++---------- 1 file changed, 67 insertions(+), 56 deletions(-) (limited to 'firmware/target/arm/imx31/gigabeat-s/button-imx31.c') diff --git a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c index 746883d010..ad1e2b7e49 100644 --- a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c @@ -26,6 +26,7 @@ #include "backlight-target.h" #include "avic-imx31.h" #include "clkctl-imx31.h" +#include "mc13783.h" /* Most code in here is taken from the Linux BSP provided by Freescale * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved. */ @@ -119,56 +120,6 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void) int_btn = button; } -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 */ - imx31_clkctl_module_clock_gating(CG_KPP, CGM_ON_ALL); - - /* 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. */ - KPP_KPSR = KPP_KPSR_KDIE | KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD; - - /* KPP IRQ at priority 3 */ - avic_enable_int(KPP, IRQ, 3, KPP_HANDLER); -} - -#ifdef BUTTON_DRIVER_CLOSE -void button_close_device(void) -{ - int oldlevel = disable_irq_save(); - - avic_disable_int(KPP); - KPP_KPSR &= ~(KPP_KPSR_KRIE | KPP_KPSR_KDIE); - int_btn = BUTTON_NONE; - - restore_irq(oldlevel); -} -#endif /* BUTTON_DRIVER_CLOSE */ - bool button_hold(void) { return _button_hold(); @@ -199,8 +150,11 @@ int button_read_device(void) } /* This is called from the mc13783 interrupt thread */ -void button_power_set_state(bool pressed) +void button_power_event(void) { + bool pressed = + (mc13783_read(MC13783_INTERRUPT_SENSE1) & MC13783_ONOFD1S) == 0; + /* Prevent KPP_HANDLER from changing things */ int oldlevel = disable_irq_save(); @@ -218,16 +172,73 @@ void button_power_set_state(bool pressed) #ifdef HAVE_HEADPHONE_DETECTION /* This is called from the mc13783 interrupt thread */ -void set_headphones_inserted(bool inserted) +void headphone_detect_event(void) { - headphones_detect = inserted; + /* FIXME: Not really the correct method */ + headphones_detect = + (mc13783_read(MC13783_INTERRUPT_SENSE1) & MC13783_ONOFD2S) == 0; } -/* This is called from the mc13783 interrupt thread */ -/* TODO: Just do a post to the button queue directly - implement the - * appropriate variant in the driver. */ bool headphones_inserted(void) { return headphones_detect; } #endif /* HAVE_HEADPHONE_DETECTION */ + +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 */ + imx31_clkctl_module_clock_gating(CG_KPP, CGM_ON_ALL); + + /* 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. */ + KPP_KPSR = KPP_KPSR_KDIE | KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD; + + /* KPP IRQ at priority 3 */ + avic_enable_int(KPP, IRQ, 3, KPP_HANDLER); + + button_power_event(); + mc13783_enable_event(MC13783_ONOFD1_EVENT); + +#ifdef HAVE_HEADPHONE_DETECTION + headphone_detect_event(); + mc13783_enable_event(MC13783_ONOFD2_EVENT); +#endif +} + +#ifdef BUTTON_DRIVER_CLOSE +void button_close_device(void) +{ + int oldlevel = disable_irq_save(); + + avic_disable_int(KPP); + KPP_KPSR &= ~(KPP_KPSR_KRIE | KPP_KPSR_KDIE); + int_btn = BUTTON_NONE; + + restore_irq(oldlevel); +} +#endif /* BUTTON_DRIVER_CLOSE */ -- cgit v1.2.3