Add HDMI jack support on RK3288
Subsystems (6)
v3 cover Add HDMI jack support on RK3288
This patch series supports HDMI jack reporting on RK3288, which uses DRM dw-hdmi driver and hdmi-codec codec driver.
The previous discussion about reporting jack status using hdmi-notifier and drm_audio_component is at
https://lore.kernel.org/patchwork/patch/1083027/
The new approach is to use a callback mechanism that is specific to hdmi-codec.
Changes from v2 to v3:
- dw-hdmi-i2s-audio.c: Use fixed ID instead of auto ID.
- rk3288_hdmi_analog.c: Use the fixed name hdmi-audio-codec for codec device.
- rockchip_max98090: Use the fixed name hdmi-audio-codec for codec device.
- rockchip_max98090: Fix the dependency of hdmi-codec in Kconfig.
Cheng-Yi Chiang (5):
ASoC: hdmi-codec: Add an op to set callback function for plug event
drm: bridge: dw-hdmi: Report connector status using callback
drm: dw-hdmi-i2s: Use fixed id for codec device
ASoC: rockchip_max98090: Add dai_link for HDMI
FROMLIST: ASoC: rockchip_max98090: Add HDMI jack support
.../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 + .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 12 +- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++++++++- include/sound/hdmi-codec.h | 16 +++ sound/soc/codecs/hdmi-codec.c | 45 +++++++ sound/soc/rockchip/Kconfig | 3 +- sound/soc/rockchip/rk3288_hdmi_analog.c | 3 +- sound/soc/rockchip/rockchip_max98090.c | 116 ++++++++++++++---- 8 files changed, 226 insertions(+), 27 deletions(-)
Signature · 1 line
2.22.0.510.g264f2c817a-goog
PATCH v3 1/5 ASoC: hdmi-codec: Add an op to set callback function for plug event
Add an op in hdmi_codec_ops so codec driver can register callback function to handle plug event.
Driver in DRM can use this callback function to report connector status.
--- include/sound/hdmi-codec.h | 16 +++++++++++++ sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
include/sound/hdmi-codec.h +16 -0
@@ -47,6 +47,9 @@ struct hdmi_codec_params {int channels; }; +typedef void (*hdmi_codec_plugged_cb )(struct device *dev, +bool plugged); +struct hdmi_codec_pdata ;struct hdmi_codec_ops {/*
@@ -88,6 +91,13 @@ struct hdmi_codec_ops {*/ int (*get_dai_id)(struct snd_soc_component *comment,struct device_node *endpoint); + +/* +* Hook callback function to handle connector plug event. +* Optional +*/ +int (*hook_plugged_cb)(struct device *dev,void *data, +hdmi_codec_plugged_cb fn); };/* HDMI codec initalization data */
@@ -99,6 +109,12 @@ struct hdmi_codec_pdata { void *data; }; +struct snd_soc_component ; +struct snd_soc_jack ; + +int hdmi_codec_set_jack_detect (struct snd_soc_component *component, +struct snd_soc_jack *jack); +#define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"#endif /* __HDMI_CODEC_H__ */
sound/soc/codecs/hdmi-codec.c +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.22.0.510.g264f2c817a-goog
Re: [PATCH v3 1/5] ASoC: hdmi-codec: Add an op to set callback function for plug event
Quoted 16 lines · Cheng-Yi Chiang
Add an op in
hdmi_codec_opsso codec driver can register callback function to handle plug event.Driver in DRM can use this callback function to report connector status.
Signed-off-by Cheng-Yi Chiang <[email protected]>--- include/sound/hdmi-codec.h | 16 +++++++++++++ sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/sound/hdmi-codec.h +0
-0
include/sound/hdmi-codec.h struct hdmi_codec_params { · line 52
Quoted 6 lines
include/sound/hdmi-codec.h +3
-0@@ -47,6 +47,9 @@ struct hdmi_codec_params {int channels; }; +typedef void (*hdmi_codec_plugged_cb )(struct device *dev, +bool plugged); +
I'd like to pose a question for people to think about.
Firstly, typedefs are generally shunned in the kernel. However, for these cases it seems to make sense.
However, should the "pointer"-ness be part of the typedef or not? To see what I mean, consider:
typedef void (*hdmi_foo)(void); int register_foo(hdmi_foo foo);
vs
typedef void hdmi_foo(void); int register_foo(hdmi_foo *foo);
which is more in keeping with how we code non-typedef'd code - it's obvious that foo is a pointer while reading the code.
It seems to me that the latter better matches what is in the kernel's coding style, which states:
In general, a pointer, or a struct that has elements that can reasonably be directly accessed should **never** be a typedef.
or maybe Documentation/process/coding-style.rst needs updating?
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Re: [PATCH v3 1/5] ASoC: hdmi-codec: Add an op to set callback function for plug event
Quoted 37 lines · Russell King - ARM Linux admin
Quoted 16 lines · Cheng-Yi Chiang
Add an op in
hdmi_codec_opsso codec driver can register callback function to handle plug event.Driver in DRM can use this callback function to report connector status.
Signed-off-by Cheng-Yi Chiang <[email protected]>--- include/sound/hdmi-codec.h | 16 +++++++++++++ sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/sound/hdmi-codec.h +0
-0include/sound/hdmi-codec.h struct hdmi_codec_params { · line 52
Quoted 6 lines
include/sound/hdmi-codec.h +3
-0@@ -47,6 +47,9 @@ struct hdmi_codec_params {int channels; }; +typedef void (*hdmi_codec_plugged_cb )(struct device *dev, +bool plugged); +I'd like to pose a question for people to think about.
Firstly, typedefs are generally shunned in the kernel. However, for these cases it seems to make sense.
However, should the "pointer"-ness be part of the typedef or not? To see what I mean, consider:
typedef void (*hdmi_foo)(void); int register_foo(hdmi_foo foo);
Quoted 8 lines
vs
typedef void hdmi_foo(void); int register_foo(hdmi_foo *foo);which is more in keeping with how we code non-typedef'd code - it's obvious that foo is a pointer while reading the code.
I have a different opinion. Its suffix "_cb" self-described it is a callback function. Since function and function pointer are equivalent in the language, I think we don't need to emphasize that it is a function "pointer".
Quoted 7 lines
It seems to me that the latter better matches what is in the kernel's coding style, which states:
In general, a pointer, or a struct that has elements that can reasonably be directly accessed should **never** be a typedef.
or maybe
Documentation/process/coding-style.rstneeds updating?
Re: [PATCH v3 1/5] ASoC: hdmi-codec: Add an op to set callback function for plug event
Quoted 44 lines · Tzung-Bi Shih
Quoted 41 lines · Russell King - ARM Linux admin
Quoted 16 lines · Cheng-Yi Chiang
Add an op in
hdmi_codec_opsso codec driver can register callback function to handle plug event.Driver in DRM can use this callback function to report connector status.
Signed-off-by Cheng-Yi Chiang <[email protected]>--- include/sound/hdmi-codec.h | 16 +++++++++++++ sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/sound/hdmi-codec.h +0
-0include/sound/hdmi-codec.h struct hdmi_codec_params { · line 52
Quoted 6 lines
include/sound/hdmi-codec.h +3
-0@@ -47,6 +47,9 @@ struct hdmi_codec_params {int channels; }; +typedef void (*hdmi_codec_plugged_cb )(struct device *dev, +bool plugged); +I'd like to pose a question for people to think about.
Firstly, typedefs are generally shunned in the kernel. However, for these cases it seems to make sense.
However, should the "pointer"-ness be part of the typedef or not? To see what I mean, consider:
typedef void (*hdmi_foo)(void); int register_foo(hdmi_foo foo);vs
typedef void hdmi_foo(void);
Quoted 10 lines
Quoted 4 lines
int register_foo(hdmi_foo *foo);which is more in keeping with how we code non-typedef'd code - it's obvious that foo is a pointer while reading the code.
I have a different opinion. Its suffix "
_cb" self-described it is a callback function. Since function and function pointer are equivalent in the language, I think we don't need to emphasize that it is a function "pointer".
Hi Russell and Tzungbi, thank you for the review. Regarding this typedef of callback function, I found a thread discussing this very long time ago:
https://yarchive.net/comp/linux/typedefs.html
Quoted 1 line
From that thread, Linus gave an example of using typedef for function
pointer that is following to this pattern.
I also looked around how other driver use it:
$ git grep typedef | grep _cb | less | wc -l 138 $ git grep typedef | grep _cb | grep "(\*" | wc -l 115 Most of the typedef of callback function use this pattern. So I think this should be fine. Thanks!
Quoted 7 lines
Quoted 7 lines
It seems to me that the latter better matches what is in the kernel's coding style, which states:
In general, a pointer, or a struct that has elements that can reasonably be directly accessed should **never** be a typedef.
or maybe
Documentation/process/coding-style.rstneeds updating?
PATCH v3 2/5 drm: bridge: dw-hdmi: Report connector status using callback
In reply to Cheng-Yi ChiangAllow codec driver register callback function for plug event.
The callback registration flow:
dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codec
dw-hdmi-i2s-audio implements hook_plugged_cb op
so codec driver can register the callback.
dw-hdmi implements set_plugged_cb op so platform device can register the callback.
When connector plug/unplug event happens, report this event using the callback.
Make sure that audio and drm are using the single source of truth for connector status.
--- .../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 + .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 10 ++++ drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h +3 -0
@@ -2,6 +2,8 @@#ifndef DW_HDMI_AUDIO_H #define DW_HDMI_AUDIO_H +#include <sound/hdmi-codec.h> +struct dw_hdmi ; struct dw_hdmi_audio_data {
@@ -17,6 +19,7 @@ struct dw_hdmi_i2s_audio_data {void (*write)(struct dw_hdmi *hdmi,u8 val,int offset);u8 (*read)(struct dw_hdmi *hdmi,int offset); + int (*set_plugged_cb)(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn); };#endif
drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +10 -0
@@ -104,10 +104,20 @@ static int dw_hdmi_i2s_get_dai_id(struct snd_soc_component *component,return -EINVAL ; } +static int dw_hdmi_i2s_hook_plugged_cb (struct device *dev,void *data, +hdmi_codec_plugged_cb fn) +{ +struct dw_hdmi_i2s_audio_data *audio = data; +struct dw_hdmi *hdmi = audio->hdmi; + +return audio->set_plugged_cb (hdmi, fn); +} +static struct hdmi_codec_ops dw_hdmi_i2s_ops = { .hw_params = dw_hdmi_i2s_hw_params, .audio_shutdown = dw_hdmi_i2s_audio_shutdown, .get_dai_id = dw_hdmi_i2s_get_dai_id, + .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb, };static int snd_dw_hdmi_probe (struct platform_device *pdev)
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +54 -1
97 lines not on this page · raw message
Signature · 1 line
2.22.0.510.g264f2c817a-goog
Re: [PATCH v3 2/5] drm: bridge: dw-hdmi: Report connector status using callback
Quoted 96 lines · Cheng-Yi Chiang
Allow codec driver register callback function for plug event.
The callback registration flow:
dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codecdw-hdmi-i2s-audio implements
hook_plugged_cbop
so codec driver can register the callback.dw-hdmi implements
set_plugged_cbop so platform device can register the callback.When connector plug/unplug event happens, report this event using the callback.
Make sure that audio and drm are using the single source of truth for connector status.
Signed-off-by Cheng-Yi Chiang <[email protected]>--- .../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 + .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 10 ++++ drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h +3
-0@@ -2,6 +2,8 @@#ifndef DW_HDMI_AUDIO_H #define DW_HDMI_AUDIO_H +#include <sound/hdmi-codec.h> +struct dw_hdmi ; struct dw_hdmi_audio_data {@@ -17,6 +19,7 @@ struct dw_hdmi_i2s_audio_data {void (*write)(struct dw_hdmi *hdmi,u8 val,int offset);u8 (*read)(struct dw_hdmi *hdmi,int offset); + int (*set_plugged_cb)(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn); };#endif drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +10
-0@@ -104,10 +104,20 @@ static int dw_hdmi_i2s_get_dai_id(struct snd_soc_component *component,return -EINVAL ; } +static int dw_hdmi_i2s_hook_plugged_cb (struct device *dev,void *data, +hdmi_codec_plugged_cb fn) +{ +struct dw_hdmi_i2s_audio_data *audio = data; +struct dw_hdmi *hdmi = audio->hdmi; + +return audio->set_plugged_cb (hdmi, fn); +} +static struct hdmi_codec_ops dw_hdmi_i2s_ops = { .hw_params = dw_hdmi_i2s_hw_params, .audio_shutdown = dw_hdmi_i2s_audio_shutdown, .get_dai_id = dw_hdmi_i2s_get_dai_id, + .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb, };static int snd_dw_hdmi_probe (struct platform_device *pdev)drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +5
-0@@ -26,6 +26,8 @@#include <drm/drm_probe_helper.h> #include <drm/bridge/dw_hdmi.h> +#include <sound/hdmi-codec.h> +#include <uapi/linux/media-bus-format.h> #include <uapi/linux/videodev2.h> @@ -185,6 +187,9 @@ struct dw_hdmi {void (*disable_audio)(struct dw_hdmi *hdmi);struct cec_notifier *cec_notifier; + +hdmi_codec_plugged_cb plugged_cb; +enum drm_connector_status last_connector_result; };#define HDMI_IH_PHY_STAT0_RX_SENSE \@@ -209,6 +214,40 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset)return val; }
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 225
Quoted 10 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +9
-0+static void handle_plugged_change (struct dw_hdmi *hdmi,bool plugged) +{ +struct platform_device *codec_pdev; + +if (!hdmi->audio ||IS_ERR (hdmi->audio)) +return ; + codec_pdev =platform_get_drvdata (hdmi->audio); +if (!codec_pdev ||IS_ERR (codec_pdev)) +return ;
This looks fragile to me, poking about in another device's driver data from another driver is really not a good design decision. I think this can be simplified if the registration function took the function pointer and the struct device pointer, and then you only need one test below:
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 238
Quoted 13 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +13
-0+if (!hdmi->plugged_cb) +return ; + + hdmi->plugged_cb (&codec_pdev->dev, plugged); +} + +static int hdmi_set_plugged_cb (struct dw_hdmi *hdmi,hdmi_codec_plugged_cb fn) +{ +bool plugged; +struct platform_device *codec_pdev; + +if (!hdmi->audio ||IS_ERR (hdmi->audio)) +return -EINVAL ;
Given the current code structure, how can this ever be true when the function is called?
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 238
Quoted 3 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3
-0+ codec_pdev =platform_get_drvdata (hdmi->audio); +if (!codec_pdev ||IS_ERR (codec_pdev)) +return -EINVAL ;
This doesn't seem like a good idea as I've pointed out above.
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 247
Quoted 6 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +6
-0+ +mutex_lock (&hdmi->mutex); + hdmi->plugged_cb = fn; + plugged = hdmi->last_connector_result == connector_status_connected; +handle_plugged_change (hdmi, plugged); +mutex_unlock (&hdmi->mutex);
Should be a blank line here for readability.
Quoted 43 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +17
-1+return 0 ; +} +static void hdmi_modb (struct dw_hdmi *hdmi,u8 data,u8 mask,unsigned reg) {regmap_update_bits (hdmi->regm, reg << hdmi->reg_shift, mask, data);@@ -2044,6 +2083,7 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force) { struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, connector); +enum drm_connector_status result;mutex_lock (&hdmi->mutex); hdmi->force =DRM_FORCE_UNSPECIFIED ;@@ -2051,7 +2091,18 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force)dw_hdmi_update_phy_mask (hdmi);mutex_unlock (&hdmi->mutex); -return hdmi->phy.ops->read_hpd (hdmi, hdmi->phy.data); + result = hdmi->phy.ops->read_hpd (hdmi, hdmi->phy.data); + +mutex_lock (&hdmi->mutex); +if (result != hdmi->last_connector_result) { +dev_dbg (hdmi->dev,"read_hpd result: %d" , result); +handle_plugged_change (hdmi, + result == connector_status_connected); + hdmi->last_connector_result = result; + } +mutex_unlock (&hdmi->mutex); + +return result; }static int dw_hdmi_connector_get_modes (struct drm_connector *connector)@@ -2460,6 +2511,7 @@ __dw_hdmi_probe(struct platform_device *pdev, hdmi->rxsense = true; hdmi->phy_mask = (u8 )~(HDMI_PHY_HPD |HDMI_PHY_RX_SENSE ); hdmi->mc_clkdis =0x7f ; + hdmi->last_connector_result = connector_status_disconnected;mutex_init (&hdmi->mutex);mutex_init (&hdmi->audio_mutex);
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c __dw_hdmi_probe(struct platform_device *pdev, · line 2708
Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +1
-0@@ -2653,6 +2705,7 @@ __dw_hdmi_probe(struct platform_device *pdev, audio.hdmi = hdmi; audio.write = hdmi_writeb; audio.read = hdmi_readb; + audio.set_plugged_cb = hdmi_set_plugged_cb;
Why is this necessary?
The I2S audio driver already depends on the dw-hdmi module through its use of functions already exported. Indirecting this through the platform data makes no sense.
Just rename hdmi_set_plugged_cb to dw_hdmi_set_plugged_cb() and export it for dw-hdmi-i2s-audio.c to use.
Thanks.
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Re: [PATCH v3 2/5] drm: bridge: dw-hdmi: Report connector status using callback
Quoted 99 lines · Russell King - ARM Linux admin
Quoted 97 lines · Cheng-Yi Chiang
Allow codec driver register callback function for plug event.
The callback registration flow:
dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codecdw-hdmi-i2s-audio implements
hook_plugged_cbop
so codec driver can register the callback.dw-hdmi implements
set_plugged_cbop so platform device can register the callback.When connector plug/unplug event happens, report this event using the callback.
Make sure that audio and drm are using the single source of truth for connector status.
Signed-off-by Cheng-Yi Chiang <[email protected]>--- .../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 + .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 10 ++++ drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h +3
-0@@ -2,6 +2,8 @@#ifndef DW_HDMI_AUDIO_H #define DW_HDMI_AUDIO_H +#include <sound/hdmi-codec.h> +struct dw_hdmi ; struct dw_hdmi_audio_data {@@ -17,6 +19,7 @@ struct dw_hdmi_i2s_audio_data {void (*write)(struct dw_hdmi *hdmi,u8 val,int offset);u8 (*read)(struct dw_hdmi *hdmi,int offset); + int (*set_plugged_cb)(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn); };#endif drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +10
-0@@ -104,10 +104,20 @@ static int dw_hdmi_i2s_get_dai_id(struct snd_soc_component *component,return -EINVAL ; } +static int dw_hdmi_i2s_hook_plugged_cb (struct device *dev,void *data, +hdmi_codec_plugged_cb fn) +{ +struct dw_hdmi_i2s_audio_data *audio = data; +struct dw_hdmi *hdmi = audio->hdmi; + +return audio->set_plugged_cb (hdmi, fn); +} +static struct hdmi_codec_ops dw_hdmi_i2s_ops = { .hw_params = dw_hdmi_i2s_hw_params, .audio_shutdown = dw_hdmi_i2s_audio_shutdown, .get_dai_id = dw_hdmi_i2s_get_dai_id, + .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb, };static int snd_dw_hdmi_probe (struct platform_device *pdev)drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +5
-0@@ -26,6 +26,8 @@#include <drm/drm_probe_helper.h> #include <drm/bridge/dw_hdmi.h> +#include <sound/hdmi-codec.h> +#include <uapi/linux/media-bus-format.h> #include <uapi/linux/videodev2.h> @@ -185,6 +187,9 @@ struct dw_hdmi {void (*disable_audio)(struct dw_hdmi *hdmi);struct cec_notifier *cec_notifier; + +hdmi_codec_plugged_cb plugged_cb; +enum drm_connector_status last_connector_result; };#define HDMI_IH_PHY_STAT0_RX_SENSE \@@ -209,6 +214,40 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset)return val; }
Quoted 16 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 225
Quoted 9 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +9
-0+static void handle_plugged_change (struct dw_hdmi *hdmi,bool plugged) +{ +struct platform_device *codec_pdev; + +if (!hdmi->audio ||IS_ERR (hdmi->audio)) +return ; + codec_pdev =platform_get_drvdata (hdmi->audio); +if (!codec_pdev ||IS_ERR (codec_pdev)) +return ;This looks fragile to me, poking about in another device's driver data from another driver is really not a good design decision. I think this can be simplified if the registration function took the function pointer and the struct device pointer, and then you only need one test below:
Hi Russell, Thank you for the detailed review.
ACK to this suggestion.
I have updated the registration function following your suggestion in v4. It looks much cleaner.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +8
-0+if (!hdmi->plugged_cb) +return ; + + hdmi->plugged_cb (&codec_pdev->dev, plugged); +} + +static int hdmi_set_plugged_cb (struct dw_hdmi *hdmi,hdmi_codec_plugged_cb fn) +{
Quoted 9 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 238
Quoted 5 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +5
-0+bool plugged; +struct platform_device *codec_pdev; + +if (!hdmi->audio ||IS_ERR (hdmi->audio)) +return -EINVAL ;Given the current code structure, how can this ever be true when the function is called?
ACK
Removed in v4.
Quoted 6 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 238
Quoted 3 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3
-0+ codec_pdev =platform_get_drvdata (hdmi->audio); +if (!codec_pdev ||IS_ERR (codec_pdev)) +return -EINVAL ;This doesn't seem like a good idea as I've pointed out above.
ACK
Fixed in v4.
Quoted 9 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) · line 247
Quoted 6 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +6
-0+ +mutex_lock (&hdmi->mutex); + hdmi->plugged_cb = fn; + plugged = hdmi->last_connector_result == connector_status_connected; +handle_plugged_change (hdmi, plugged); +mutex_unlock (&hdmi->mutex);Should be a blank line here for readability.
ACK
Fixed in v4.
Quoted 50 lines
Quoted 43 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +17
-1+return 0 ; +} +static void hdmi_modb (struct dw_hdmi *hdmi,u8 data,u8 mask,unsigned reg) {regmap_update_bits (hdmi->regm, reg << hdmi->reg_shift, mask, data);@@ -2044,6 +2083,7 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force) { struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, connector); +enum drm_connector_status result;mutex_lock (&hdmi->mutex); hdmi->force =DRM_FORCE_UNSPECIFIED ;@@ -2051,7 +2091,18 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force)dw_hdmi_update_phy_mask (hdmi);mutex_unlock (&hdmi->mutex); -return hdmi->phy.ops->read_hpd (hdmi, hdmi->phy.data); + result = hdmi->phy.ops->read_hpd (hdmi, hdmi->phy.data); + +mutex_lock (&hdmi->mutex); +if (result != hdmi->last_connector_result) { +dev_dbg (hdmi->dev,"read_hpd result: %d" , result); +handle_plugged_change (hdmi, + result == connector_status_connected); + hdmi->last_connector_result = result; + } +mutex_unlock (&hdmi->mutex); + +return result; }static int dw_hdmi_connector_get_modes (struct drm_connector *connector)@@ -2460,6 +2511,7 @@ __dw_hdmi_probe(struct platform_device *pdev, hdmi->rxsense = true; hdmi->phy_mask = (u8 )~(HDMI_PHY_HPD |HDMI_PHY_RX_SENSE ); hdmi->mc_clkdis =0x7f ; + hdmi->last_connector_result = connector_status_disconnected;mutex_init (&hdmi->mutex);mutex_init (&hdmi->audio_mutex);drivers/gpu/drm/bridge/synopsys/dw-hdmi.c __dw_hdmi_probe(struct platform_device *pdev, · line 2708
Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +1
-0@@ -2653,6 +2705,7 @@ __dw_hdmi_probe(struct platform_device *pdev, audio.hdmi = hdmi; audio.write = hdmi_writeb; audio.read = hdmi_readb; + audio.set_plugged_cb = hdmi_set_plugged_cb;Why is this necessary?
Quoted 6 lines
The I2S audio driver already depends on the dw-hdmi module through its use of functions already exported. Indirecting this through the platform data makes no sense.
Just rename
hdmi_set_plugged_cbtodw_hdmi_set_plugged_cb()and export it fordw-hdmi-i2s-audio.cto use.
ACK.
Your suggestion makes sense.
Removed in v4.
Quoted 2 lines
Thanks.
Thanks so much!
Quoted 5 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
PATCH v3 3/5 drm: dw-hdmi-i2s: Use fixed id for codec device
In reply to Cheng-Yi ChiangThe problem of using auto ID is that the device name will be like hdmi-audio-codec.<id number>.auto.
The number might be changed when there are other platform devices being created before hdmi-audio-codec device.
Use a fixed name so machine driver can set codec name on the DAI link.
Using the fixed name should be fine because there will only be one hdmi-audio-codec device.
Fix the codec name in rockchip rk3288_hdmi_analog machine driver.
--- drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 2 +- sound/soc/rockchip/rk3288_hdmi_analog.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +1 -1
@@ -134,7 +134,7 @@ static int snd_dw_hdmi_probe(struct platform_device *pdev)memset (&pdevinfo,0 ,sizeof (pdevinfo)); pdevinfo.parent = pdev->dev.parent; - pdevinfo.id =PLATFORM_DEVID_AUTO ; + pdevinfo.id =PLATFORM_DEVID_NONE ; pdevinfo.name =HDMI_CODEC_DRV_NAME ; pdevinfo.data = &pdata; pdevinfo.size_data =sizeof (pdata);
sound/soc/rockchip/rk3288_hdmi_analog.c +2 -1
@@ -15,6 +15,7 @@#include <linux/gpio.h> #include <linux/of_gpio.h> #include <sound/core.h> +#include <sound/hdmi-codec.h> #include <sound/jack.h> #include <sound/pcm.h> #include <sound/pcm_params.h>
@@ -142,7 +143,7 @@ static const struct snd_soc_ops rk_ops = {SND_SOC_DAILINK_DEFS (audio,DAILINK_COMP_ARRAY (COMP_EMPTY ()),DAILINK_COMP_ARRAY (COMP_CODEC (NULL ,NULL ), -COMP_CODEC ("hdmi-audio-codec.2.auto" ,"i2s-hifi" )), +COMP_CODEC (HDMI_CODEC_DRV_NAME ,"i2s-hifi" )),DAILINK_COMP_ARRAY (COMP_EMPTY ()));static struct snd_soc_dai_link rk_dailink = {
Signature · 1 line
2.22.0.510.g264f2c817a-goog
PATCH v3 4/5 ASoC: rockchip_max98090: Add dai_link for HDMI
In reply to Cheng-Yi ChiangUse two dai_links. One for HDMI and one for max98090. With this setup, audio can play to speaker and HDMI selectively.
--- sound/soc/rockchip/Kconfig | 3 +- sound/soc/rockchip/rockchip_max98090.c | 96 ++++++++++++++++++++------ 2 files changed, 75 insertions(+), 24 deletions(-)
sound/soc/rockchip/Kconfig +2 -1
@@ -40,9 +40,10 @@ config SND_SOC_ROCKCHIP_MAX98090 select SND_SOC_ROCKCHIP_I2S select SND_SOC_MAX98090 select SND_SOC_TS3A227E + select SND_SOC_HDMI_CODEC help Say Y or M here if you want to add support for SoC audio on Rockchip - boards using the MAX98090 codec, such as Veyron. + boards using the MAX98090 codec and HDMI codec, such as Veyron. config SND_SOC_ROCKCHIP_RT5645 tristate "ASoC support for Rockchip boards using a RT5645/RT5650 codec"
sound/soc/rockchip/rockchip_max98090.c +73 -23
170 lines not on this page · raw message
Signature · 1 line
2.22.0.510.g264f2c817a-goog
PATCH v3 5/5 FROMLIST: ASoC: rockchip_max98090: Add HDMI jack support
In reply to Cheng-Yi ChiangIn machine driver, create a jack and let hdmi-codec report jack status.
--- sound/soc/rockchip/rockchip_max98090.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
sound/soc/rockchip/rockchip_max98090.c +20 -0
@@ -134,6 +134,25 @@ enum { DAILINK_HDMI, }; +static struct snd_soc_jack rk_hdmi_jack; + +static int rk_hdmi_init (struct snd_soc_pcm_runtime *runtime) +{ +struct snd_soc_card *card = runtime->card; +struct snd_soc_component *component = runtime->codec_dai->component; +int ret; + +/* enable jack detection */ + ret =snd_soc_card_jack_new (card,"HDMI Jack" ,SND_JACK_LINEOUT , + &rk_hdmi_jack,NULL ,0 ); +if (ret) { +dev_err (card->dev,"Can't new HDMI Jack %d\n" , ret); +return ret; + } + +return hdmi_codec_set_jack_detect (component, &rk_hdmi_jack); +} +/* max98090 and HDMI codec dai_link */ static struct snd_soc_dai_link rk_dailinks[] = { [DAILINK_MAX98090 ] = {
@@ -151,6 +170,7 @@ static struct snd_soc_dai_link rk_dailinks[] = { .ops = &rk_aif1_ops, .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS, + .init = rk_hdmi_init, SND_SOC_DAILINK_REG(hdmi), } };
Signature · 1 line
2.22.0.510.g264f2c817a-goog
Re: [PATCH v3 5/5] FROMLIST: ASoC: rockchip_max98090: Add HDMI jack support
Quoted 47 lines · Cheng-Yi Chiang
In machine driver, create a jack and let hdmi-codec report jack status.
Signed-off-by Cheng-Yi Chiang <[email protected]>--- sound/soc/rockchip/rockchip_max98090.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)sound/soc/rockchip/rockchip_max98090.c +20
-1@@ -134,6 +134,25 @@ enum { DAILINK_HDMI, }; +static struct snd_soc_jack rk_hdmi_jack; + +static int rk_hdmi_init (struct snd_soc_pcm_runtime *runtime) +{ +struct snd_soc_card *card = runtime->card; +struct snd_soc_component *component = runtime->codec_dai->component; +int ret; + +/* enable jack detection */ + ret =snd_soc_card_jack_new (card,"HDMI Jack" ,SND_JACK_LINEOUT , + &rk_hdmi_jack,NULL ,0 ); +if (ret) { +dev_err (card->dev,"Can't new HDMI Jack %d\n" , ret); +return ret; + } + +return hdmi_codec_set_jack_detect (component, &rk_hdmi_jack); +} +/* max98090 and HDMI codec dai_link */ static struct snd_soc_dai_link rk_dailinks[] = { [DAILINK_MAX98090 ] = {@@ -151,6 +170,7 @@ static struct snd_soc_dai_link rk_dailinks[] = { .ops = &rk_aif1_ops, .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS, + .init = rk_hdmi_init, SND_SOC_DAILINK_REG(hdmi), } }; --
Quoted 2 lines
2.22.0.510.g264f2c817a-goog
Sorry for the wrong title.
I forgot to remove FROMLIST in the title.
I'll wait for comments on other patches and fix the title in v4. Thanks!