Jelajahi Sumber

projects/usb_amr/fw: Implement ring detect and notification

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Sylvain Munaut 1 tahun lalu
induk
melakukan
dfdd15fa98
2 mengubah file dengan 16 tambahan dan 5 penghapusan
  1. 11 4
      projects/usb_amr/fw/cdc-dlm.c
  2. 5 1
      projects/usb_amr/fw/mc97.c

+ 11 - 4
projects/usb_amr/fw/cdc-dlm.c

@@ -183,12 +183,19 @@ cdc_dlm_init(void)
 void
 cdc_dlm_poll(void)
 {
-	/* Nothing to do for now */
+	/* Ring detection */
+	static bool ring;
+
+	if (mc97_get_ring_detect()) {
+		if (!ring) {
+			dlm_send_notif_ring_detect();
+			ring = true;
+		}
+	} else {
+		ring = false;
+	}
 
 	/* TODO:
 	 *  - Pulse timing when pulse is implemented
-	 *  - Ring detection (note that it's not simply calling
-	 *    mc97_get_ring_detect(), it must be analyzed to see if the
-	 *    ringing frequency matches something between 10 and 100 Hz)
 	 */
 }

+ 5 - 1
projects/usb_amr/fw/mc97.c

@@ -28,6 +28,7 @@ struct wb_mc97 {
 	uint32_t fifo_csr;
 } __attribute__((packed,aligned(4)));
 
+#define MC97_CSR_RFI			(1 <<  3)
 #define MC97_CSR_GPIO_ENA		(1 <<  2)
 #define MC97_CSR_RESET_N		(1 <<  1)
 #define MC97_CSR_RUN			(1 <<  0)
@@ -187,7 +188,10 @@ mc97_set_hook(enum mc97_hook_state s)
 bool
 mc97_get_ring_detect(void)
 {
-	return (mc97_regs->gpio_in & (1 << 5)) ? true : false;
+	return (
+		(mc97_regs->gpio_in & (1 << 5)) &&
+		(mc97_regs->csr & MC97_CSR_RFI)
+	) ? true : false;
 }
 
 void