diff mbox series

[3/3] usb: typec: fsa4480: add support for Audio Accessory Mode

Message ID 20230614-topic-sm8550-upstream-type-c-audio-v1-3-15a92565146b@linaro.org (mailing list archive)
State Accepted
Commit ef1e29c6f6ad1e327d07b078e37a1eddd832e8e4
Headers show
Series typec: support Audio Accessory mode on FSA4480 | expand

Commit Message

Neil Armstrong June 14, 2023, 1:10 p.m. UTC
The FSA4480 Type-C switch supports switching the Audio R/L,
AGND and MIC signals to the USB-C DP/DM and SBU1/2 to support
the Audio Accessory Mode.

The FSA4480 has an integrated Audio jack detection mechanism
to automatically mux the AGND, MIX and Sense to the correct
SBU lines to support 3 pole and both 4 pole TRRS pinouts.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/typec/mux/fsa4480.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Krzysztof Kozlowski June 14, 2023, 1:12 p.m. UTC | #1
On 14/06/2023 15:10, Neil Armstrong wrote:
> The FSA4480 Type-C switch supports switching the Audio R/L,
> AGND and MIC signals to the USB-C DP/DM and SBU1/2 to support
> the Audio Accessory Mode.
> 
> The FSA4480 has an integrated Audio jack detection mechanism
> to automatically mux the AGND, MIX and Sense to the correct
> SBU lines to support 3 pole and both 4 pole TRRS pinouts.
> 
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> ---


Tested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof
Heikki Krogerus June 26, 2023, 8:32 a.m. UTC | #2
On Wed, Jun 14, 2023 at 03:10:41PM +0200, Neil Armstrong wrote:
> The FSA4480 Type-C switch supports switching the Audio R/L,
> AGND and MIC signals to the USB-C DP/DM and SBU1/2 to support
> the Audio Accessory Mode.
> 
> The FSA4480 has an integrated Audio jack detection mechanism
> to automatically mux the AGND, MIX and Sense to the correct
> SBU lines to support 3 pole and both 4 pole TRRS pinouts.
> 
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/mux/fsa4480.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c
> index b2913594a58f..45f5683b7d81 100644
> --- a/drivers/usb/typec/mux/fsa4480.c
> +++ b/drivers/usb/typec/mux/fsa4480.c
> @@ -25,15 +25,24 @@
>  #define FSA4480_DELAY_L_MIC	0x0e
>  #define FSA4480_DELAY_L_SENSE	0x0f
>  #define FSA4480_DELAY_L_AGND	0x10
> +#define FSA4480_FUNCTION_ENABLE	0x12
>  #define FSA4480_RESET		0x1e
>  #define FSA4480_MAX_REGISTER	0x1f
>  
>  #define FSA4480_ENABLE_DEVICE	BIT(7)
>  #define FSA4480_ENABLE_SBU	GENMASK(6, 5)
>  #define FSA4480_ENABLE_USB	GENMASK(4, 3)
> +#define FSA4480_ENABLE_SENSE	BIT(2)
> +#define FSA4480_ENABLE_MIC	BIT(1)
> +#define FSA4480_ENABLE_AGND	BIT(0)
>  
>  #define FSA4480_SEL_SBU_REVERSE	GENMASK(6, 5)
>  #define FSA4480_SEL_USB		GENMASK(4, 3)
> +#define FSA4480_SEL_SENSE	BIT(2)
> +#define FSA4480_SEL_MIC		BIT(1)
> +#define FSA4480_SEL_AGND	BIT(0)
> +
> +#define FSA4480_ENABLE_AUTO_JACK_DETECT	BIT(0)
>  
>  struct fsa4480 {
>  	struct i2c_client *client;
> @@ -95,6 +104,9 @@ static int fsa4480_set(struct fsa4480 *fsa)
>  		default:
>  			return -EOPNOTSUPP;
>  		}
> +	} else if (fsa->mode == TYPEC_MODE_AUDIO) {
> +		/* Audio Accessory Mode, setup to auto Jack Detection */
> +		enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_AGND;
>  	} else
>  		return -EOPNOTSUPP;
>  
> @@ -110,6 +122,11 @@ static int fsa4480_set(struct fsa4480 *fsa)
>  	regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, sel);
>  	regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, enable);
>  
> +	/* Start AUDIO JACK DETECTION to setup MIC, AGND & Sense muxes */
> +	if (enable & FSA4480_ENABLE_AGND)
> +		regmap_write(fsa->regmap, FSA4480_FUNCTION_ENABLE,
> +			     FSA4480_ENABLE_AUTO_JACK_DETECT);
> +
>  	if (enable & FSA4480_ENABLE_SBU) {
>  		/* 15us to allow the SBU switch to turn on again */
>  		usleep_range(15, 1000);

thanks,
diff mbox series

Patch

diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c
index b2913594a58f..45f5683b7d81 100644
--- a/drivers/usb/typec/mux/fsa4480.c
+++ b/drivers/usb/typec/mux/fsa4480.c
@@ -25,15 +25,24 @@ 
 #define FSA4480_DELAY_L_MIC	0x0e
 #define FSA4480_DELAY_L_SENSE	0x0f
 #define FSA4480_DELAY_L_AGND	0x10
+#define FSA4480_FUNCTION_ENABLE	0x12
 #define FSA4480_RESET		0x1e
 #define FSA4480_MAX_REGISTER	0x1f
 
 #define FSA4480_ENABLE_DEVICE	BIT(7)
 #define FSA4480_ENABLE_SBU	GENMASK(6, 5)
 #define FSA4480_ENABLE_USB	GENMASK(4, 3)
+#define FSA4480_ENABLE_SENSE	BIT(2)
+#define FSA4480_ENABLE_MIC	BIT(1)
+#define FSA4480_ENABLE_AGND	BIT(0)
 
 #define FSA4480_SEL_SBU_REVERSE	GENMASK(6, 5)
 #define FSA4480_SEL_USB		GENMASK(4, 3)
+#define FSA4480_SEL_SENSE	BIT(2)
+#define FSA4480_SEL_MIC		BIT(1)
+#define FSA4480_SEL_AGND	BIT(0)
+
+#define FSA4480_ENABLE_AUTO_JACK_DETECT	BIT(0)
 
 struct fsa4480 {
 	struct i2c_client *client;
@@ -95,6 +104,9 @@  static int fsa4480_set(struct fsa4480 *fsa)
 		default:
 			return -EOPNOTSUPP;
 		}
+	} else if (fsa->mode == TYPEC_MODE_AUDIO) {
+		/* Audio Accessory Mode, setup to auto Jack Detection */
+		enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_AGND;
 	} else
 		return -EOPNOTSUPP;
 
@@ -110,6 +122,11 @@  static int fsa4480_set(struct fsa4480 *fsa)
 	regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, sel);
 	regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, enable);
 
+	/* Start AUDIO JACK DETECTION to setup MIC, AGND & Sense muxes */
+	if (enable & FSA4480_ENABLE_AGND)
+		regmap_write(fsa->regmap, FSA4480_FUNCTION_ENABLE,
+			     FSA4480_ENABLE_AUTO_JACK_DETECT);
+
 	if (enable & FSA4480_ENABLE_SBU) {
 		/* 15us to allow the SBU switch to turn on again */
 		usleep_range(15, 1000);