shithub: riscv

Download patch

ref: 7951f2d29c143cf7bfe06a56539459f5360c2ef7
parent: 5dd6ca6bccb98562b3490acd4201bc092bdeeeae
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Aug 19 23:55:28 EDT 2022

imx8/sai, aux/wm8960: expose jack detect status in #A/audiostat

--- a/sys/src/9/imx8/sai.c
+++ b/sys/src/9/imx8/sai.c
@@ -67,6 +67,7 @@
 struct Ctlr {
 	u32int *reg;
 	Audio *adev;
+	int hp;
 
 	Ring w;
 	int wactive;
@@ -354,6 +355,7 @@
 		(v & TCSR_FWF) ? " fifo_warn" : "",
 		(v & TCSR_FRF) ? " fifo_req" : ""
 	);
+	s = seprint(s, e, "hp %d\n", ctlr->hp);
 
 	return s - (char*)a;
 }
@@ -366,6 +368,14 @@
 	return buffered(&ctlr->w);
 }
 
+static void
+jacksense(uint pin, void *a)
+{
+	Ctlr *ctlr = a;
+
+	ctlr->hp = gpioin(pin);
+}
+
 static int
 saiprobe(Audio *adev)
 {
@@ -390,10 +400,11 @@
 	adev->status = saistatus;
 	adev->ctl = saictl;
 
+	intrenable(IRQsai2, saiinterrupt, ctlr, BUSUNKNOWN, "sai2");
+	ctlr->hp = gpioin(GPIO_PIN(4, 21));
+	gpiointrenable(GPIO_PIN(4, 21), GpioEdge, jacksense, ctlr);
 	saireset(ctlr);
 
-	intrenable(IRQsai2, saiinterrupt, ctlr, BUSUNKNOWN, "sai2");
-
 	return 0;
 }
 
@@ -400,15 +411,14 @@
 void
 sailink(void)
 {
-	iomuxpad("pad_sai2_rxfs", "sai2_rx_sync", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
-	iomuxpad("pad_sai2_rxc", "sai2_rx_bclk", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
-	iomuxpad("pad_sai2_rxd0", "sai2_rx_data0", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
-	iomuxpad("pad_sai2_txfs", "sai2_tx_sync", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
-	iomuxpad("pad_sai2_txc", "sai2_tx_bclk", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
-	iomuxpad("pad_sai2_txd0", "sai2_tx_data0", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
-	iomuxpad("pad_sai2_mclk", "sai2_mclk", "SION ~LVTTL HYS PUE ~ODE FAST 45_OHM VSEL_0");
+	iomuxpad("pad_sai2_rxfs", "gpio4_io21", "SION ~LVTTL HYS ~PUE ~ODE FAST 45_OHM");
+	iomuxpad("pad_sai2_rxc", "sai2_rx_bclk", "~LVTTL HYS PUE ~ODE FAST 45_OHM");
+	iomuxpad("pad_sai2_rxd0", "sai2_rx_data0", "~LVTTL HYS PUE ~ODE FAST 45_OHM");
+	iomuxpad("pad_sai2_txfs", "sai2_tx_sync", "~LVTTL HYS PUE ~ODE FAST 45_OHM");
+	iomuxpad("pad_sai2_txc", "sai2_tx_bclk", "~LVTTL HYS PUE ~ODE FAST 45_OHM");
+	iomuxpad("pad_sai2_txd0", "sai2_tx_data0", "~LVTTL HYS PUE ~ODE FAST 45_OHM");
+	iomuxpad("pad_sai2_mclk", "sai2_mclk", "~LVTTL HYS PUE ~ODE FAST 45_OHM");
 
-	setclkgate("sai2.ipg_clk", 0);
 	setclkrate("sai2.ipg_clk", "audio_pll1_clk", 25*Mhz);
 	setclkgate("sai2.ipg_clk", 1);
 
--- a/sys/src/cmd/aux/wm8960.c
+++ b/sys/src/cmd/aux/wm8960.c
@@ -192,10 +192,7 @@
 	wr(0x1c, 1<<3); /* done with anti-pop */
 	wr(0x19, 1<<7 | 1<<6); /* Vref on */
 
-	/*
-	 * Debounced jack detect output on gpio - no that it is used, but it
-	 * could be soldered to SoC's input and actually become useful.
-	 */
+	wr(0x09, 1<<6); /* adclrc → gpio (for jack detect output) */
 	wr(0x30, 3<<4 | 2<<2 | 1<<1); /* JD2 jack detect in; Tsense on */
 	wr(0x1b, 1<<3); /* HP_[LR] responsive to jack detect */
 	wr(0x18, 1<<6); /* HP switch on; high = HP */