From f27de46472e55a54aceae042f2b3a9ced68491a2 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Fri, 25 Jul 2025 07:56:06 -0400 Subject: [PATCH] PP502x: Hacky technique to switch UARTs based on which IRQ was triggered This lets us have multiple serial ports enabled, which will help with 4th-gen ipods that have a serial port in the HP jack as well in the dock. Change-Id: I6a00a776020848a6908413e05a6f27bad65b2d8e --- firmware/target/arm/pp/system-pp502x.c | 9 ++++++--- firmware/target/arm/pp/uart-pp.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/firmware/target/arm/pp/system-pp502x.c b/firmware/target/arm/pp/system-pp502x.c index fb6fe28d91..860e17957c 100644 --- a/firmware/target/arm/pp/system-pp502x.c +++ b/firmware/target/arm/pp/system-pp502x.c @@ -47,7 +47,7 @@ #if !defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE) extern void TIMER1(void); extern void TIMER2(void); -extern void SERIAL_ISR(void); +extern void SERIAL_ISR(int port); #if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1) static struct corelock cpufreq_cl SHAREDBSS_ATTR; @@ -187,8 +187,11 @@ void __attribute__((interrupt("IRQ"))) irq_handler(void) /* end PBELL_VIBE500 */ #endif #ifdef IPOD_ACCESSORY_PROTOCOL - else if (CPU_HI_INT_STAT & (SER0_MASK | SER1_MASK)) { - SERIAL_ISR(); + else if (CPU_HI_INT_STAT & SER0_MASK) { + SERIAL_ISR(0); + } + else if (CPU_HI_INT_STAT & SER1_MASK) { + SERIAL_ISR(1); } #endif } else { diff --git a/firmware/target/arm/pp/uart-pp.c b/firmware/target/arm/pp/uart-pp.c index 2820db0e88..9eadc81bd6 100644 --- a/firmware/target/arm/pp/uart-pp.c +++ b/firmware/target/arm/pp/uart-pp.c @@ -188,12 +188,26 @@ static unsigned char rx_readc(void) return (*base_RBR & 0xFF); } -void SERIAL_ISR(void) +void SERIAL_ISR(int port) { static int badbaud = 0; static bool newpkt = true; char temp; + if (port && base_RBR != &SER1_RBR) { + base_RBR = &SER1_RBR; + base_THR = &SER1_THR; + base_LCR = &SER1_LCR; + base_LSR = &SER1_LSR; + base_DLL = &SER1_DLL; + } else if (!port && base_RBR != &SER0_RBR) { + base_RBR = &SER0_RBR; + base_THR = &SER0_THR; + base_LCR = &SER0_LCR; + base_LSR = &SER0_LSR; + base_DLL = &SER0_DLL; + } + while(rx_rdy()) { temp = rx_readc();