From b60712deb674ee6809966538176f4bb182b8c50b Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Thu, 26 Sep 2013 20:19:30 +0200 Subject: sonynwz: rework dualboot mechanism Now boot to RB if play/pause is pressed during 1 second, and to OF if back is pressed 1 second. Otherwise power off. If hold is on, also power off. In USB and alarm context, always boot and back determines OF vs RB. Change-Id: Ie1d6c971901d6473255461cc7d71a5ee3177ecad --- rbutil/mkimxboot/dualboot.c | 64 ++++++++++++++++++++++++++++++------ rbutil/mkimxboot/dualboot.h | 4 +-- rbutil/mkimxboot/dualboot/dualboot.c | 64 ++++++++++++++++++++++++++++++++++-- 3 files changed, 117 insertions(+), 15 deletions(-) diff --git a/rbutil/mkimxboot/dualboot.c b/rbutil/mkimxboot/dualboot.c index 8b5ca5b2b6..e2bbdae8a9 100644 --- a/rbutil/mkimxboot/dualboot.c +++ b/rbutil/mkimxboot/dualboot.c @@ -33,15 +33,59 @@ unsigned char dualboot_zenxfi3[56] = { 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x40, 0x04, 0x80, 0x00, 0x80, 0x01, 0x80 }; -unsigned char dualboot_nwze370[52] = { - 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x1c, 0x30, 0x9f, 0xe5, - 0xc0, 0x20, 0x93, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x03, 0x36, 0x03, 0xe2, 0x01, 0x06, 0x53, 0xe3, - 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1, - 0x00, 0x40, 0x04, 0x80 +unsigned char dualboot_nwze370[416] = { + 0x10, 0x40, 0x2d, 0xe9, 0x1e, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x68, 0x30, 0x9f, 0xe5, + 0x01, 0x20, 0xa0, 0xe3, 0x18, 0x20, 0x83, 0xe5, 0x04, 0x20, 0x83, 0xe5, 0x03, 0x20, 0xa0, 0xe1, + 0x10, 0x30, 0x92, 0xe5, 0x01, 0x00, 0x13, 0xe3, 0xfc, 0xff, 0xff, 0x0a, 0x48, 0x30, 0x9f, 0xe5, + 0x50, 0x30, 0x93, 0xe5, 0x44, 0x20, 0x9f, 0xe5, 0x00, 0x26, 0x92, 0xe5, 0x02, 0x0c, 0x12, 0xe3, + 0x00, 0x00, 0xa0, 0x03, 0x1e, 0xff, 0x2f, 0x01, 0xff, 0x34, 0xc3, 0xe3, 0x3f, 0x37, 0xc3, 0xe3, + 0x41, 0x2e, 0x43, 0xe2, 0x0a, 0x20, 0x42, 0xe2, 0x63, 0x00, 0x52, 0xe3, 0x02, 0x00, 0xa0, 0x93, + 0x1e, 0xff, 0x2f, 0x91, 0x16, 0x3d, 0x43, 0xe2, 0x0c, 0x30, 0x43, 0xe2, 0x63, 0x00, 0x53, 0xe3, + 0x00, 0x00, 0xa0, 0x83, 0x01, 0x00, 0xa0, 0x93, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x00, 0x05, 0x80, + 0x00, 0x80, 0x01, 0x80, 0xf0, 0x41, 0x2d, 0xe9, 0x00, 0x70, 0xa0, 0xe1, 0x01, 0x60, 0xa0, 0xe1, + 0xf8, 0x30, 0x9f, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x3f, 0x34, 0x03, 0xe2, 0x23, 0x3c, 0xa0, 0xe1, + 0x20, 0x00, 0x13, 0xe3, 0x01, 0x00, 0x00, 0x1a, 0x10, 0x00, 0x13, 0xe3, 0x23, 0x00, 0x00, 0x0a, + 0xdc, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, + 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, + 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, + 0xc9, 0xff, 0xff, 0xeb, 0x00, 0x40, 0x50, 0xe2, 0x06, 0x00, 0x00, 0x1a, 0x0a, 0x00, 0x00, 0xea, + 0xc5, 0xff, 0xff, 0xeb, 0x00, 0x00, 0x54, 0xe1, 0x0a, 0x00, 0x00, 0x1a, 0xc0, 0x30, 0x98, 0xe5, + 0x03, 0x00, 0x55, 0xe1, 0xf9, 0xff, 0xff, 0x8a, 0x01, 0x00, 0x54, 0xe3, 0x02, 0x00, 0x00, 0x0a, + 0x02, 0x00, 0x54, 0xe3, 0x03, 0x00, 0x00, 0x1a, 0x06, 0x00, 0x00, 0xea, 0x00, 0x70, 0x86, 0xe5, + 0x01, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, 0x68, 0x20, 0x9f, 0xe5, 0x5c, 0x30, 0x9f, 0xe5, + 0x00, 0x21, 0x83, 0xe5, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, + 0x4c, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, + 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, + 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, + 0xa5, 0xff, 0xff, 0xeb, 0x00, 0x40, 0xa0, 0xe1, 0x1c, 0x30, 0x9f, 0xe5, 0xc0, 0x50, 0x93, 0xe5, + 0x3d, 0x59, 0x85, 0xe2, 0x09, 0x5d, 0x85, 0xe2, 0x03, 0x80, 0xa0, 0xe1, 0xda, 0xff, 0xff, 0xea, + 0x00, 0x40, 0x04, 0x80, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xff, 0xff, 0x00, 0xc0, 0x01, 0x80 }; -unsigned char dualboot_nwze360[52] = { - 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x1c, 0x30, 0x9f, 0xe5, - 0xc0, 0x20, 0x93, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x03, 0x36, 0x03, 0xe2, 0x01, 0x06, 0x53, 0xe3, - 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1, - 0x00, 0x40, 0x04, 0x80 +unsigned char dualboot_nwze360[416] = { + 0x10, 0x40, 0x2d, 0xe9, 0x1e, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x68, 0x30, 0x9f, 0xe5, + 0x01, 0x20, 0xa0, 0xe3, 0x18, 0x20, 0x83, 0xe5, 0x04, 0x20, 0x83, 0xe5, 0x03, 0x20, 0xa0, 0xe1, + 0x10, 0x30, 0x92, 0xe5, 0x01, 0x00, 0x13, 0xe3, 0xfc, 0xff, 0xff, 0x0a, 0x48, 0x30, 0x9f, 0xe5, + 0x50, 0x30, 0x93, 0xe5, 0x44, 0x20, 0x9f, 0xe5, 0x00, 0x26, 0x92, 0xe5, 0x02, 0x0c, 0x12, 0xe3, + 0x00, 0x00, 0xa0, 0x03, 0x1e, 0xff, 0x2f, 0x01, 0xff, 0x34, 0xc3, 0xe3, 0x3f, 0x37, 0xc3, 0xe3, + 0x41, 0x2e, 0x43, 0xe2, 0x0a, 0x20, 0x42, 0xe2, 0x63, 0x00, 0x52, 0xe3, 0x02, 0x00, 0xa0, 0x93, + 0x1e, 0xff, 0x2f, 0x91, 0x16, 0x3d, 0x43, 0xe2, 0x0c, 0x30, 0x43, 0xe2, 0x63, 0x00, 0x53, 0xe3, + 0x00, 0x00, 0xa0, 0x83, 0x01, 0x00, 0xa0, 0x93, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x00, 0x05, 0x80, + 0x00, 0x80, 0x01, 0x80, 0xf0, 0x41, 0x2d, 0xe9, 0x00, 0x70, 0xa0, 0xe1, 0x01, 0x60, 0xa0, 0xe1, + 0xf8, 0x30, 0x9f, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x3f, 0x34, 0x03, 0xe2, 0x23, 0x3c, 0xa0, 0xe1, + 0x20, 0x00, 0x13, 0xe3, 0x01, 0x00, 0x00, 0x1a, 0x10, 0x00, 0x13, 0xe3, 0x23, 0x00, 0x00, 0x0a, + 0xdc, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, + 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, + 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, + 0xc9, 0xff, 0xff, 0xeb, 0x00, 0x40, 0x50, 0xe2, 0x06, 0x00, 0x00, 0x1a, 0x0a, 0x00, 0x00, 0xea, + 0xc5, 0xff, 0xff, 0xeb, 0x00, 0x00, 0x54, 0xe1, 0x0a, 0x00, 0x00, 0x1a, 0xc0, 0x30, 0x98, 0xe5, + 0x03, 0x00, 0x55, 0xe1, 0xf9, 0xff, 0xff, 0x8a, 0x01, 0x00, 0x54, 0xe3, 0x02, 0x00, 0x00, 0x0a, + 0x02, 0x00, 0x54, 0xe3, 0x03, 0x00, 0x00, 0x1a, 0x06, 0x00, 0x00, 0xea, 0x00, 0x70, 0x86, 0xe5, + 0x01, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, 0x68, 0x20, 0x9f, 0xe5, 0x5c, 0x30, 0x9f, 0xe5, + 0x00, 0x21, 0x83, 0xe5, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, + 0x4c, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, + 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, + 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, + 0xa5, 0xff, 0xff, 0xeb, 0x00, 0x40, 0xa0, 0xe1, 0x1c, 0x30, 0x9f, 0xe5, 0xc0, 0x50, 0x93, 0xe5, + 0x3d, 0x59, 0x85, 0xe2, 0x09, 0x5d, 0x85, 0xe2, 0x03, 0x80, 0xa0, 0xe1, 0xda, 0xff, 0xff, 0xea, + 0x00, 0x40, 0x04, 0x80, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xff, 0xff, 0x00, 0xc0, 0x01, 0x80 }; diff --git a/rbutil/mkimxboot/dualboot.h b/rbutil/mkimxboot/dualboot.h index 9bf271299a..17ee1979fb 100644 --- a/rbutil/mkimxboot/dualboot.h +++ b/rbutil/mkimxboot/dualboot.h @@ -3,5 +3,5 @@ extern unsigned char dualboot_fuzeplus[228]; extern unsigned char dualboot_zenxfi2[96]; extern unsigned char dualboot_zenxfi3[56]; -extern unsigned char dualboot_nwze370[52]; -extern unsigned char dualboot_nwze360[52]; +extern unsigned char dualboot_nwze370[416]; +extern unsigned char dualboot_nwze360[416]; diff --git a/rbutil/mkimxboot/dualboot/dualboot.c b/rbutil/mkimxboot/dualboot/dualboot.c index f75673efbe..3cca59bb8a 100644 --- a/rbutil/mkimxboot/dualboot/dualboot.c +++ b/rbutil/mkimxboot/dualboot/dualboot.c @@ -20,6 +20,8 @@ ****************************************************************************/ #include "regs-pinctrl.h" #include "regs-power.h" +#include "regs-lradc.h" +#include "regs-digctl.h" #define BOOT_ROM_CONTINUE 0 /* continue boot */ #define BOOT_ROM_SECTION 1 /* switch to new section *result_id */ @@ -59,6 +61,28 @@ static inline int __attribute__((always_inline)) read_pswitch(void) #endif } +/* only works for channels <=7, always divide by 2, never accumulates */ +static inline void __attribute__((always_inline)) setup_lradc(int src) +{ + BF_CLR(LRADC_CTRL0, SFTRST); + BF_CLR(LRADC_CTRL0, CLKGATE); + /* don't bother changing the source, we are early enough at boot so that + * channel x is mapped to source x */ + HW_LRADC_CHn_CLR(src) = BM_OR2(LRADC_CHn, NUM_SAMPLES, ACCUMULATE); + BF_SETV(LRADC_CTRL2, DIVIDE_BY_TWO, 1 << src); +} + +#define BP_LRADC_CTRL1_LRADCx_IRQ(x) (x) +#define BM_LRADC_CTRL1_LRADCx_IRQ(x) (1 << (x)) + +static inline int __attribute__((always_inline)) read_lradc(int src) +{ + BF_CLR(LRADC_CTRL1, LRADCx_IRQ(src)); + BF_SETV(LRADC_CTRL0, SCHEDULE, 1 << src); + while(!BF_RD(LRADC_CTRL1, LRADCx_IRQ(src))); + return BF_RDn(LRADC_CHn, src, VALUE); +} + static inline void __attribute__((noreturn)) power_down() { #ifdef SANSA_FUZEPLUS @@ -120,11 +144,45 @@ static int boot_decision(int context) return !read_gpio(2, 7) ? BOOT_OF : BOOT_ROCK; } #elif defined(SONY_NWZE360) || defined(SONY_NWZE370) +static int local_decision(void) +{ + /* read keys and pswitch */ + int val = read_lradc(0); + /* if hold is on, power off + * if back is pressed, boot to OF + * if play is pressed, boot RB + * otherwise power off */ + if(read_gpio(0, 9) == 0) + return BOOT_STOP; + if(val >= 1050 && val < 1150) + return BOOT_OF; + if(val >= 1420 && val < 1520) + return BOOT_ROCK; + return BOOT_STOP; +} + static int boot_decision(int context) { - /* Power button set PSWITCH to 3, all other buttons to 1. So any - * button press will boot OF */ - return read_pswitch() == 1 ? BOOT_OF : BOOT_ROCK; + setup_lradc(0); // setup LRADC channel 0 to read keys + HW_PINCTRL_PULLn_SET(0) = 1 << 9; // enable pullup on hold key (B0P09) + /* make a decision */ + int decision = local_decision(); + /* in USB or alarm context, stick to it */ + if(context == CONTEXT_USB || context == CONTEXT_RTC) + { + /* never power down so replace power off decision by rockbox */ + return decision == BOOT_STOP ? BOOT_ROCK : decision; + } + /* otherwise start a 1 second timeout. Any decision change + * will result in power down */ + uint32_t tmo = HW_DIGCTL_MICROSECONDS + 1000000; + while(HW_DIGCTL_MICROSECONDS < tmo) + { + int new_dec = local_decision(); + if(new_dec != decision) + return BOOT_STOP; + } + return decision; } #else #warning You should define a target specific boot decision function -- cgit v1.2.3