drm/vc4: hdmi: rework connectors and encoders

the vc4_hdmi driver has some custom structures to hold the data it needs to
associate with the drm_encoder and drm_connector structures.

However, it allocates them separately from the vc4_hdmi structure which
makes it more complicated than it needs to be.

Move those structures to be contained by vc4_hdmi and update the code
accordingly.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
This commit is contained in:
Maxime Ripard
2020-01-06 17:17:29 +01:00
committed by popcornmix
parent e5edd91523
commit 74ff04e280
2 changed files with 84 additions and 92 deletions

View File

@@ -190,20 +190,14 @@ static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs =
.get_modes = vc4_hdmi_connector_get_modes, .get_modes = vc4_hdmi_connector_get_modes,
}; };
static struct drm_connector *vc4_hdmi_connector_init(struct drm_device *dev, static int vc4_hdmi_connector_init(struct drm_device *dev,
struct drm_encoder *encoder, struct vc4_hdmi *vc4_hdmi)
struct i2c_adapter *ddc)
{ {
struct drm_connector *connector; struct vc4_hdmi_connector *hdmi_connector = &vc4_hdmi->connector;
struct vc4_hdmi_connector *hdmi_connector; struct drm_connector *connector = &hdmi_connector->base;
struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base;
int ret; int ret;
hdmi_connector = devm_kzalloc(dev->dev, sizeof(*hdmi_connector),
GFP_KERNEL);
if (!hdmi_connector)
return ERR_PTR(-ENOMEM);
connector = &hdmi_connector->base;
hdmi_connector->encoder = encoder; hdmi_connector->encoder = encoder;
drm_connector_init_with_ddc(dev, connector, drm_connector_init_with_ddc(dev, connector,
@@ -215,7 +209,7 @@ static struct drm_connector *vc4_hdmi_connector_init(struct drm_device *dev,
/* Create and attach TV margin props to this connector. */ /* Create and attach TV margin props to this connector. */
ret = drm_mode_create_tv_margin_properties(dev); ret = drm_mode_create_tv_margin_properties(dev);
if (ret) if (ret)
return ERR_PTR(ret); return ret;
drm_connector_attach_tv_margin_properties(connector); drm_connector_attach_tv_margin_properties(connector);
@@ -227,7 +221,7 @@ static struct drm_connector *vc4_hdmi_connector_init(struct drm_device *dev,
drm_connector_attach_encoder(connector, encoder); drm_connector_attach_encoder(connector, encoder);
return connector; return 0;
} }
static void vc4_hdmi_encoder_destroy(struct drm_encoder *encoder) static void vc4_hdmi_encoder_destroy(struct drm_encoder *encoder)
@@ -306,21 +300,22 @@ static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
struct vc4_dev *vc4 = encoder->dev->dev_private; struct vc4_dev *vc4 = encoder->dev->dev_private;
struct vc4_hdmi *hdmi = vc4->hdmi; struct vc4_hdmi *hdmi = vc4->hdmi;
struct drm_connector_state *cstate = hdmi->connector->state; struct drm_connector *connector = &hdmi->connector.base;
struct drm_connector_state *cstate = connector->state;
struct drm_crtc *crtc = encoder->crtc; struct drm_crtc *crtc = encoder->crtc;
const struct drm_display_mode *mode = &crtc->state->adjusted_mode; const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
union hdmi_infoframe frame; union hdmi_infoframe frame;
int ret; int ret;
ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi, ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
hdmi->connector, mode); connector, mode);
if (ret < 0) { if (ret < 0) {
DRM_ERROR("couldn't fill AVI infoframe\n"); DRM_ERROR("couldn't fill AVI infoframe\n");
return; return;
} }
drm_hdmi_avi_infoframe_quant_range(&frame.avi, drm_hdmi_avi_infoframe_quant_range(&frame.avi,
hdmi->connector, mode, connector, mode,
vc4_encoder->limited_rgb_range ? vc4_encoder->limited_rgb_range ?
HDMI_QUANTIZATION_RANGE_LIMITED : HDMI_QUANTIZATION_RANGE_LIMITED :
HDMI_QUANTIZATION_RANGE_FULL); HDMI_QUANTIZATION_RANGE_FULL);
@@ -636,7 +631,8 @@ static const struct drm_encoder_helper_funcs vc4_hdmi_encoder_helper_funcs = {
/* HDMI audio codec callbacks */ /* HDMI audio codec callbacks */
static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *hdmi) static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *hdmi)
{ {
struct drm_device *drm = hdmi->encoder->dev; struct drm_encoder *encoder = &hdmi->encoder.base.base;
struct drm_device *drm = encoder->dev;
struct vc4_dev *vc4 = to_vc4_dev(drm); struct vc4_dev *vc4 = to_vc4_dev(drm);
u32 hsm_clock = clk_get_rate(hdmi->hsm_clock); u32 hsm_clock = clk_get_rate(hdmi->hsm_clock);
unsigned long n, m; unsigned long n, m;
@@ -655,7 +651,7 @@ static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *hdmi)
static void vc4_hdmi_set_n_cts(struct vc4_hdmi *hdmi) static void vc4_hdmi_set_n_cts(struct vc4_hdmi *hdmi)
{ {
struct drm_encoder *encoder = hdmi->encoder; struct drm_encoder *encoder = &hdmi->encoder.base.base;
struct drm_crtc *crtc = encoder->crtc; struct drm_crtc *crtc = encoder->crtc;
struct drm_device *drm = encoder->dev; struct drm_device *drm = encoder->dev;
struct vc4_dev *vc4 = to_vc4_dev(drm); struct vc4_dev *vc4 = to_vc4_dev(drm);
@@ -693,7 +689,8 @@ static int vc4_hdmi_audio_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai) struct snd_soc_dai *dai)
{ {
struct vc4_hdmi *hdmi = dai_to_hdmi(dai); struct vc4_hdmi *hdmi = dai_to_hdmi(dai);
struct drm_encoder *encoder = hdmi->encoder; struct drm_encoder *encoder = &hdmi->encoder.base.base;
struct drm_connector *connector = &hdmi->connector.base;
struct vc4_dev *vc4 = to_vc4_dev(encoder->dev); struct vc4_dev *vc4 = to_vc4_dev(encoder->dev);
int ret; int ret;
@@ -710,8 +707,7 @@ static int vc4_hdmi_audio_startup(struct snd_pcm_substream *substream,
VC4_HDMI_RAM_PACKET_ENABLE)) VC4_HDMI_RAM_PACKET_ENABLE))
return -ENODEV; return -ENODEV;
ret = snd_pcm_hw_constraint_eld(substream->runtime, ret = snd_pcm_hw_constraint_eld(substream->runtime, connector->eld);
hdmi->connector->eld);
if (ret) if (ret)
return ret; return ret;
@@ -725,7 +721,7 @@ static int vc4_hdmi_audio_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
static void vc4_hdmi_audio_reset(struct vc4_hdmi *hdmi) static void vc4_hdmi_audio_reset(struct vc4_hdmi *hdmi)
{ {
struct drm_encoder *encoder = hdmi->encoder; struct drm_encoder *encoder = &hdmi->encoder.base.base;
struct drm_device *drm = encoder->dev; struct drm_device *drm = encoder->dev;
struct device *dev = &hdmi->pdev->dev; struct device *dev = &hdmi->pdev->dev;
struct vc4_dev *vc4 = to_vc4_dev(drm); struct vc4_dev *vc4 = to_vc4_dev(drm);
@@ -759,7 +755,7 @@ static int vc4_hdmi_audio_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai) struct snd_soc_dai *dai)
{ {
struct vc4_hdmi *hdmi = dai_to_hdmi(dai); struct vc4_hdmi *hdmi = dai_to_hdmi(dai);
struct drm_encoder *encoder = hdmi->encoder; struct drm_encoder *encoder = &hdmi->encoder.base.base;
struct drm_device *drm = encoder->dev; struct drm_device *drm = encoder->dev;
struct device *dev = &hdmi->pdev->dev; struct device *dev = &hdmi->pdev->dev;
struct vc4_dev *vc4 = to_vc4_dev(drm); struct vc4_dev *vc4 = to_vc4_dev(drm);
@@ -832,7 +828,7 @@ static int vc4_hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd,
struct snd_soc_dai *dai) struct snd_soc_dai *dai)
{ {
struct vc4_hdmi *hdmi = dai_to_hdmi(dai); struct vc4_hdmi *hdmi = dai_to_hdmi(dai);
struct drm_encoder *encoder = hdmi->encoder; struct drm_encoder *encoder = &hdmi->encoder.base.base;
struct drm_device *drm = encoder->dev; struct drm_device *drm = encoder->dev;
struct vc4_dev *vc4 = to_vc4_dev(drm); struct vc4_dev *vc4 = to_vc4_dev(drm);
@@ -876,9 +872,10 @@ static int vc4_hdmi_audio_eld_ctl_info(struct snd_kcontrol *kcontrol,
{ {
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct vc4_hdmi *hdmi = snd_component_to_hdmi(component); struct vc4_hdmi *hdmi = snd_component_to_hdmi(component);
struct drm_connector *connector = &hdmi->connector.base;
uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
uinfo->count = sizeof(hdmi->connector->eld); uinfo->count = sizeof(connector->eld);
return 0; return 0;
} }
@@ -888,9 +885,10 @@ static int vc4_hdmi_audio_eld_ctl_get(struct snd_kcontrol *kcontrol,
{ {
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct vc4_hdmi *hdmi = snd_component_to_hdmi(component); struct vc4_hdmi *hdmi = snd_component_to_hdmi(component);
struct drm_connector *connector = &hdmi->connector.base;
memcpy(ucontrol->value.bytes.data, hdmi->connector->eld, memcpy(ucontrol->value.bytes.data, connector->eld,
sizeof(hdmi->connector->eld)); sizeof(connector->eld));
return 0; return 0;
} }
@@ -1230,7 +1228,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
struct drm_device *drm = dev_get_drvdata(master); struct drm_device *drm = dev_get_drvdata(master);
struct vc4_dev *vc4 = drm->dev_private; struct vc4_dev *vc4 = drm->dev_private;
struct vc4_hdmi *hdmi; struct vc4_hdmi *hdmi;
struct vc4_hdmi_encoder *vc4_hdmi_encoder; struct drm_encoder *encoder;
struct device_node *ddc_node; struct device_node *ddc_node;
u32 value; u32 value;
int ret; int ret;
@@ -1239,14 +1237,10 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
if (!hdmi) if (!hdmi)
return -ENOMEM; return -ENOMEM;
vc4_hdmi_encoder = devm_kzalloc(dev, sizeof(*vc4_hdmi_encoder),
GFP_KERNEL);
if (!vc4_hdmi_encoder)
return -ENOMEM;
vc4_hdmi_encoder->base.type = VC4_ENCODER_TYPE_HDMI0;
hdmi->encoder = &vc4_hdmi_encoder->base.base;
hdmi->pdev = pdev; hdmi->pdev = pdev;
encoder = &hdmi->encoder.base.base;
encoder->base.type = VC4_ENCODER_TYPE_HDMI0;
hdmi->hdmicore_regs = vc4_ioremap_regs(pdev, 0); hdmi->hdmicore_regs = vc4_ioremap_regs(pdev, 0);
if (IS_ERR(hdmi->hdmicore_regs)) if (IS_ERR(hdmi->hdmicore_regs))
return PTR_ERR(hdmi->hdmicore_regs); return PTR_ERR(hdmi->hdmicore_regs);
@@ -1332,16 +1326,14 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
} }
pm_runtime_enable(dev); pm_runtime_enable(dev);
drm_encoder_init(drm, hdmi->encoder, &vc4_hdmi_encoder_funcs, drm_encoder_init(drm, encoder, &vc4_hdmi_encoder_funcs,
DRM_MODE_ENCODER_TMDS, NULL); DRM_MODE_ENCODER_TMDS, NULL);
drm_encoder_helper_add(hdmi->encoder, &vc4_hdmi_encoder_helper_funcs); drm_encoder_helper_add(encoder, &vc4_hdmi_encoder_helper_funcs);
hdmi->connector = ret = vc4_hdmi_connector_init(drm, hdmi);
vc4_hdmi_connector_init(drm, hdmi->encoder, hdmi->ddc); if (ret)
if (IS_ERR(hdmi->connector)) {
ret = PTR_ERR(hdmi->connector);
goto err_destroy_encoder; goto err_destroy_encoder;
}
#ifdef CONFIG_DRM_VC4_HDMI_CEC #ifdef CONFIG_DRM_VC4_HDMI_CEC
hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops, hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
vc4, "vc4", vc4, "vc4",
@@ -1351,7 +1343,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
if (ret < 0) if (ret < 0)
goto err_destroy_conn; goto err_destroy_conn;
cec_fill_conn_info_from_drm(&conn_info, hdmi->connector); cec_fill_conn_info_from_drm(&conn_info, &hdmi->connector.base);
cec_s_conn_info(hdmi->cec_adap, &conn_info); cec_s_conn_info(hdmi->cec_adap, &conn_info);
HDMI_WRITE(VC4_HDMI_CPU_MASK_SET, 0xffffffff); HDMI_WRITE(VC4_HDMI_CPU_MASK_SET, 0xffffffff);
@@ -1388,10 +1380,10 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
err_delete_cec_adap: err_delete_cec_adap:
cec_delete_adapter(hdmi->cec_adap); cec_delete_adapter(hdmi->cec_adap);
err_destroy_conn: err_destroy_conn:
vc4_hdmi_connector_destroy(hdmi->connector); vc4_hdmi_connector_destroy(&hdmi->connector.base);
#endif #endif
err_destroy_encoder: err_destroy_encoder:
vc4_hdmi_encoder_destroy(hdmi->encoder); vc4_hdmi_encoder_destroy(encoder);
err_unprepare_hsm: err_unprepare_hsm:
clk_disable_unprepare(hdmi->hsm_clock); clk_disable_unprepare(hdmi->hsm_clock);
pm_runtime_disable(dev); pm_runtime_disable(dev);
@@ -1409,8 +1401,8 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master,
struct vc4_hdmi *hdmi = vc4->hdmi; struct vc4_hdmi *hdmi = vc4->hdmi;
cec_unregister_adapter(hdmi->cec_adap); cec_unregister_adapter(hdmi->cec_adap);
vc4_hdmi_connector_destroy(hdmi->connector); vc4_hdmi_connector_destroy(&hdmi->connector.base);
vc4_hdmi_encoder_destroy(hdmi->encoder); vc4_hdmi_encoder_destroy(&hdmi->encoder.base.base);
clk_disable_unprepare(hdmi->hsm_clock); clk_disable_unprepare(hdmi->hsm_clock);
pm_runtime_disable(dev); pm_runtime_disable(dev);

View File

@@ -8,51 +8,6 @@
#include "vc4_drv.h" #include "vc4_drv.h"
/* HDMI audio information */
struct vc4_hdmi_audio {
struct snd_soc_card card;
struct snd_soc_dai_link link;
struct snd_soc_dai_link_component cpu;
struct snd_soc_dai_link_component codec;
struct snd_soc_dai_link_component platform;
int samplerate;
int channels;
struct snd_dmaengine_dai_dma_data dma_data;
struct snd_pcm_substream *substream;
};
/* General HDMI hardware state. */
struct vc4_hdmi {
struct platform_device *pdev;
struct drm_encoder *encoder;
struct drm_connector *connector;
struct vc4_hdmi_audio audio;
struct i2c_adapter *ddc;
void __iomem *hdmicore_regs;
void __iomem *hd_regs;
int hpd_gpio;
bool hpd_active_low;
struct cec_adapter *cec_adap;
struct cec_msg cec_rx_msg;
bool cec_tx_ok;
bool cec_irq_was_rx;
struct clk *pixel_clock;
struct clk *hsm_clock;
struct debugfs_regset32 hdmi_regset;
struct debugfs_regset32 hd_regset;
};
#define HDMI_READ(offset) readl(vc4->hdmi->hdmicore_regs + offset)
#define HDMI_WRITE(offset, val) writel(val, vc4->hdmi->hdmicore_regs + offset)
#define HD_READ(offset) readl(vc4->hdmi->hd_regs + offset)
#define HD_WRITE(offset, val) writel(val, vc4->hdmi->hd_regs + offset)
/* VC4 HDMI encoder KMS struct */ /* VC4 HDMI encoder KMS struct */
struct vc4_hdmi_encoder { struct vc4_hdmi_encoder {
struct vc4_encoder base; struct vc4_encoder base;
@@ -83,4 +38,49 @@ to_vc4_hdmi_connector(struct drm_connector *connector)
return container_of(connector, struct vc4_hdmi_connector, base); return container_of(connector, struct vc4_hdmi_connector, base);
} }
/* HDMI audio information */
struct vc4_hdmi_audio {
struct snd_soc_card card;
struct snd_soc_dai_link link;
struct snd_soc_dai_link_component cpu;
struct snd_soc_dai_link_component codec;
struct snd_soc_dai_link_component platform;
int samplerate;
int channels;
struct snd_dmaengine_dai_dma_data dma_data;
struct snd_pcm_substream *substream;
};
/* General HDMI hardware state. */
struct vc4_hdmi {
struct platform_device *pdev;
struct vc4_hdmi_encoder encoder;
struct vc4_hdmi_connector connector;
struct vc4_hdmi_audio audio;
struct i2c_adapter *ddc;
void __iomem *hdmicore_regs;
void __iomem *hd_regs;
int hpd_gpio;
bool hpd_active_low;
struct cec_adapter *cec_adap;
struct cec_msg cec_rx_msg;
bool cec_tx_ok;
bool cec_irq_was_rx;
struct clk *pixel_clock;
struct clk *hsm_clock;
struct debugfs_regset32 hdmi_regset;
struct debugfs_regset32 hd_regset;
};
#define HDMI_READ(offset) readl(vc4->hdmi->hdmicore_regs + offset)
#define HDMI_WRITE(offset, val) writel(val, vc4->hdmi->hdmicore_regs + offset)
#define HD_READ(offset) readl(vc4->hdmi->hd_regs + offset)
#define HD_WRITE(offset, val) writel(val, vc4->hdmi->hd_regs + offset)
#endif /* _VC4_HDMI_H_ */ #endif /* _VC4_HDMI_H_ */