usb: typec: fsa4480: Support reporting hotplug events to a codec
Subsystems (3)
v3 cover usb: typec: fsa4480: Support reporting hotplug events to a codec
Currently the fsa4480 USB-C SBU MUX is not actually used with audio codecs in mainline. I have gotten it to work with the wcd937x codec on sm7325-motorola-dubai (copying the Type-C notification handler code from wcd939x to wcd937x, will be sent after this).
v3:
* Put the codec mux/switch refs after unregistering our mux/switch
in fsa4480_remove (sashiko-bot)
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Thanks,
~val
---
Luca Weiss (1):
usb: typec: fsa4480: Report switch & mux events to codec
Val Packett (1):
dt-bindings: usb: fsa4480: Add an optional audio port/endpoint
.../devicetree/bindings/usb/fcs,fsa4480.yaml | 94 +++++++++++++------ drivers/usb/typec/mux/fsa4480.c | 57 +++++++++-- 2 files changed, 116 insertions(+), 35 deletions(-)
Signature · 1 line
2.55.0
PATCH v3 1/2 dt-bindings: usb: fsa4480: Add an optional audio port/endpoint
The fsa4480 mux is physically connected not only to a Type-C port controller, but also to an audio codec which has to be notified when an analog audio accessory has been plugged in.
Describe a second port intended for the codec. Keep it optional to make sure existing device trees do still validate.
--- .../devicetree/bindings/usb/fcs,fsa4480.yaml | 94 +++++++++++++------ 1 file changed, 66 insertions(+), 28 deletions(-)
Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml +66 -28
@@ -9,31 +9,11 @@ title: ON Semiconductor Analog Audio Switch maintainers: - Bjorn Andersson <[email protected]> -properties: - compatible: - oneOf: - - const: fcs,fsa4480 - - items: - - enum: - - ocs,ocp96011 - - const: fcs,fsa4480 - - reg: - maxItems: 1 - - interrupts: - maxItems: 1 - - vcc-supply: - description: power supply (2.7V-5.5V) - - mode-switch: true - orientation-switch: true - - port: +$defs: + controller-port: $ref: /schemas/graph.yaml#/$defs/port-base description: - A port node to link the FSA4480 to a TypeC controller for the purpose of + A port node to link the FSA4480 to a Type-C controller for the purpose of handling altmode muxing and orientation switching. unevaluatedProperties: false
@@ -69,14 +49,57 @@ properties: - AUX+ connected to SBU2 - AUX- connected to SBU1 +properties: + compatible: + oneOf: + - const: fcs,fsa4480 + - items: + - enum: + - ocs,ocp96011 + - const: fcs,fsa4480 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vcc-supply: + description: power supply (2.7V-5.5V) + + mode-switch: true + orientation-switch: true + + port: + $ref: "#/$defs/controller-port" + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: "#/$defs/controller-port" + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + A port node to link the FSA4480 to an audio codec for the purpose of + handling Audio Accessory Mode muxing and orientation switching. + + required: + - port@0 + required: - compatible - reg - - port allOf: - $ref: usb-switch.yaml# - - $ref: usb-switch-ports.yaml# + +oneOf: + - required: + - port + - required: + - ports additionalProperties: false
@@ -98,9 +121,24 @@ examples: mode-switch; orientation-switch; - port { - fsa4480_ept: endpoint { - remote-endpoint = <&typec_controller>; + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + fsa4480_sbu_mux: endpoint { + remote-endpoint = <&typec_controller>; + }; + }; + + port@1 { + reg = <1>; + + fsa4480_audio: endpoint { + remote-endpoint = <&audio_codec>; + }; }; }; };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 1/2] dt-bindings: usb: fsa4480: Add an optional audio port/endpoint
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
The fsa4480 mux is physically connected not only to a Type-C port controller, but also to an audio codec which has to be notified when an analog audio accessory has been plugged in.
Describe a second port intended for the codec. Keep it optional to make sure existing device trees do still validate.
Signed-off-by Val Packett <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 1/2] dt-bindings: usb: fsa4480: Add an optional audio port/endpoint
In reply to Val PackettQuoted 4 lines · Val Packett
The fsa4480 mux is physically connected not only to a Type-C port controller, but also to an audio codec which has to be notified when an analog audio accessory has been plugged in.
Quoted 8 lines
Describe a second port intended for the codec. Keep it optional to make sure existing device trees do still validate.
Signed-off-by Val Packett <[email protected]>--- .../devicetree/bindings/usb/fcs,fsa4480.yaml | 94 +++++++++++++------ 1 file changed, 66 insertions(+), 28 deletions(-)
PATCH v3 2/2 usb: typec: fsa4480: Report switch & mux events to codec
In reply to Val PackettFrom: Luca Weiss <[email protected]>
In the Type-C graph, the FSA4480 switch is in between the USB-C connector and the audio codec, but the audio codec also needs to receive the switch and mux events from the FSA4480.
Update the driver to get an Type-C mux on the next endpoint and broadcast the recevied mux & switch state to it.
--- drivers/usb/typec/mux/fsa4480.c | 57 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-)
drivers/usb/typec/mux/fsa4480.c +50 -7
@@ -60,6 +60,9 @@ struct fsa4480 {struct regmap *regmap; +struct typec_mux *codec; +struct typec_switch *codec_switch; +enum typec_orientation orientation;unsigned long mode;unsigned int svid;
@@ -115,7 +118,8 @@ static int fsa4480_set(struct fsa4480 *fsa) } }else if (fsa->mode ==TYPEC_MODE_AUDIO ) {/* Audio Accessory Mode, setup to auto Jack Detection */ - enable |=FSA4480_ENABLE_USB |FSA4480_ENABLE_AGND ; + enable |=FSA4480_ENABLE_USB |FSA4480_ENABLE_AGND | +FSA4480_ENABLE_SENSE |FSA4480_ENABLE_MIC ; }else return -EOPNOTSUPP ;
@@ -162,7 +166,11 @@ static int fsa4480_switch_set(struct typec_switch_dev *sw,mutex_unlock (&fsa->lock); -return ret; +if (ret) +return ret; + +/* Report orientation to codec after switch has been done */ +return typec_switch_set (fsa->codec_switch, orientation); }static int fsa4480_mux_set (struct typec_mux_dev *mux,struct typec_mux_state *state)
@@ -185,7 +193,11 @@ static int fsa4480_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *stmutex_unlock (&fsa->lock); -return ret; +if (ret) +return ret; + +/* Report event to codec after switch has been done */ +return typec_mux_set (fsa->codec, state); }enum {
@@ -287,6 +299,19 @@ static int fsa4480_probe(struct i2c_client *client)FIELD_GET (FSA4480_DEVICE_ID_REV_ID , val), FIELD_GET(FSA4480_DEVICE_ID_VENDOR_ID, val)); +/* Get Codec's MUX & Switch devices */ + fsa->codec =fwnode_typec_mux_get (dev->fwnode); +if (IS_ERR (fsa->codec)) +return dev_err_probe (dev,PTR_ERR (fsa->codec), +"failed to acquire codec mode-switch\n" ); + + fsa->codec_switch =fwnode_typec_switch_get (dev->fwnode); +if (IS_ERR (fsa->codec_switch)) { + ret =dev_err_probe (dev,PTR_ERR (fsa->codec_switch), +"failed to acquire codec orientation-switch\n" ); + goto err_put_mux; + } +/* Safe mode */ fsa->cur_enable =FSA4480_ENABLE_DEVICE |FSA4480_ENABLE_USB ; fsa->mode =TYPEC_STATE_SAFE ;
@@ -310,8 +335,11 @@ static int fsa4480_probe(struct i2c_client *client) sw_desc.set = fsa4480_switch_set; fsa->sw =typec_switch_register (dev, &sw_desc); -if (IS_ERR (fsa->sw)) -return dev_err_probe (dev,PTR_ERR (fsa->sw),"failed to register typec switch\n" ); +if (IS_ERR (fsa->sw)) { + ret =dev_err_probe (dev,PTR_ERR (fsa->sw), +"failed to register typec switch\n" ); + goto err_put_switch; + } mux_desc.drvdata = fsa; mux_desc.fwnode =dev_fwnode (dev);
@@ -319,12 +347,24 @@ static int fsa4480_probe(struct i2c_client *client) fsa->mux =typec_mux_register (dev, &mux_desc);if (IS_ERR (fsa->mux)) { -typec_switch_unregister (fsa->sw); -return dev_err_probe (dev,PTR_ERR (fsa->mux),"failed to register typec mux\n" ); + ret =dev_err_probe (dev,PTR_ERR (fsa->mux), +"failed to register typec mux\n" ); + goto err_unregister_switch; }i2c_set_clientdata (client, fsa);return 0 ; + +err_unregister_switch: +typec_switch_unregister (fsa->sw); + +err_put_switch: +typec_switch_put (fsa->codec_switch); + +err_put_mux: +typec_mux_put (fsa->codec); + +return ret; }static void fsa4480_remove (struct i2c_client *client)
@@ -333,6 +373,9 @@ static void fsa4480_remove(struct i2c_client *client)typec_mux_unregister (fsa->mux);typec_switch_unregister (fsa->sw); + +typec_mux_put (fsa->codec); +typec_switch_put (fsa->codec_switch); }static const struct i2c_device_id fsa4480_table[] = {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 2/2] usb: typec: fsa4480: Report switch & mux events to codec
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
From: Luca Weiss <[email protected]>
In the Type-C graph, the FSA4480 switch is in between the USB-C connector and the audio codec, but the audio codec also needs to receive the switch and mux events from the FSA4480.
Quoted 6 lines
Update the driver to get an Type-C mux on the next endpoint and broadcast the recevied mux & switch state to it.
Signed-off-by Luca Weiss <[email protected]>[val: enable the SENSE/MIC bits; put the refs in fsa4480_remove]Signed-off-by Val Packett <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v3 2/2] usb: typec: fsa4480: Report switch & mux events to codec
In reply to Val PackettQuoted 6 lines · Val Packett
From: Luca Weiss <[email protected]>
In the Type-C graph, the FSA4480 switch is in between the USB-C connector and the audio codec, but the audio codec also needs to receive the switch and mux events from the FSA4480.
Quoted 6 lines
Update the driver to get an Type-C mux on the next endpoint and broadcast the recevied mux & switch state to it.
Signed-off-by Luca Weiss <[email protected]>[val: enable the SENSE/MIC bits; put the refs in fsa4480_remove]Signed-off-by Val Packett <[email protected]>
Quoted 127 lines
--- drivers/usb/typec/mux/fsa4480.c | 57 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-)drivers/usb/typec/mux/fsa4480.c +50
-7@@ -60,6 +60,9 @@ struct fsa4480 {struct regmap *regmap; +struct typec_mux *codec; +struct typec_switch *codec_switch; +enum typec_orientation orientation;unsigned long mode;unsigned int svid;@@ -115,7 +118,8 @@ static int fsa4480_set(struct fsa4480 *fsa) } }else if (fsa->mode ==TYPEC_MODE_AUDIO ) {/* Audio Accessory Mode, setup to auto Jack Detection */ - enable |=FSA4480_ENABLE_USB |FSA4480_ENABLE_AGND ; + enable |=FSA4480_ENABLE_USB |FSA4480_ENABLE_AGND | +FSA4480_ENABLE_SENSE |FSA4480_ENABLE_MIC ; }else return -EOPNOTSUPP ;@@ -162,7 +166,11 @@ static int fsa4480_switch_set(struct typec_switch_dev *sw,mutex_unlock (&fsa->lock); -return ret; +if (ret) +return ret; + +/* Report orientation to codec after switch has been done */ +return typec_switch_set (fsa->codec_switch, orientation); }static int fsa4480_mux_set (struct typec_mux_dev *mux,struct typec_mux_state *state)@@ -185,7 +193,11 @@ static int fsa4480_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *stmutex_unlock (&fsa->lock); -return ret; +if (ret) +return ret; + +/* Report event to codec after switch has been done */ +return typec_mux_set (fsa->codec, state); }enum {@@ -287,6 +299,19 @@ static int fsa4480_probe(struct i2c_client *client)FIELD_GET (FSA4480_DEVICE_ID_REV_ID , val), FIELD_GET(FSA4480_DEVICE_ID_VENDOR_ID, val)); +/* Get Codec's MUX & Switch devices */ + fsa->codec =fwnode_typec_mux_get (dev->fwnode); +if (IS_ERR (fsa->codec)) +return dev_err_probe (dev,PTR_ERR (fsa->codec), +"failed to acquire codec mode-switch\n" ); + + fsa->codec_switch =fwnode_typec_switch_get (dev->fwnode); +if (IS_ERR (fsa->codec_switch)) { + ret =dev_err_probe (dev,PTR_ERR (fsa->codec_switch), +"failed to acquire codec orientation-switch\n" ); + goto err_put_mux; + } +/* Safe mode */ fsa->cur_enable =FSA4480_ENABLE_DEVICE |FSA4480_ENABLE_USB ; fsa->mode =TYPEC_STATE_SAFE ;@@ -310,8 +335,11 @@ static int fsa4480_probe(struct i2c_client *client) sw_desc.set = fsa4480_switch_set; fsa->sw =typec_switch_register (dev, &sw_desc); -if (IS_ERR (fsa->sw)) -return dev_err_probe (dev,PTR_ERR (fsa->sw),"failed to register typec switch\n" ); +if (IS_ERR (fsa->sw)) { + ret =dev_err_probe (dev,PTR_ERR (fsa->sw), +"failed to register typec switch\n" ); + goto err_put_switch; + } mux_desc.drvdata = fsa; mux_desc.fwnode =dev_fwnode (dev);@@ -319,12 +347,24 @@ static int fsa4480_probe(struct i2c_client *client) fsa->mux =typec_mux_register (dev, &mux_desc);if (IS_ERR (fsa->mux)) { -typec_switch_unregister (fsa->sw); -return dev_err_probe (dev,PTR_ERR (fsa->mux),"failed to register typec mux\n" ); + ret =dev_err_probe (dev,PTR_ERR (fsa->mux), +"failed to register typec mux\n" ); + goto err_unregister_switch; }i2c_set_clientdata (client, fsa);return 0 ; + +err_unregister_switch: +typec_switch_unregister (fsa->sw); + +err_put_switch: +typec_switch_put (fsa->codec_switch); + +err_put_mux: +typec_mux_put (fsa->codec); + +return ret; }static void fsa4480_remove (struct i2c_client *client)@@ -333,6 +373,9 @@ static void fsa4480_remove(struct i2c_client *client)typec_mux_unregister (fsa->mux);typec_switch_unregister (fsa->sw); + +typec_mux_put (fsa->codec); +typec_switch_put (fsa->codec_switch); }static const struct i2c_device_id fsa4480_table[] = {Signature · 1 line
2.55.0
Signature · 1 line
heikki