[v3,07/35] drm/sti: Stop using drm_bridge->driver_private
diff mbox series

Message ID 20191224173408.25624-8-mihail.atanassov@arm.com
State New
Headers show
Series
  • drm/bridge: Consolidate initialization
Related show

Commit Message

Mihail Atanassov Dec. 24, 2019, 5:34 p.m. UTC
Instead, embed the drm_bridge structure in the originally-pointed-to
struct and use a container_of wrapper to access it.

Signed-off-by: Mihail Atanassov <mihail.atanassov@arm.com>
---
 drivers/gpu/drm/sti/sti_dvo.c  | 20 ++++++++------------
 drivers/gpu/drm/sti/sti_hda.c  | 17 ++++++++---------
 drivers/gpu/drm/sti/sti_hdmi.c | 13 ++++---------
 drivers/gpu/drm/sti/sti_hdmi.h |  5 +++++
 4 files changed, 25 insertions(+), 30 deletions(-)

Patch
diff mbox series

diff --git a/drivers/gpu/drm/sti/sti_dvo.c b/drivers/gpu/drm/sti/sti_dvo.c
index df2ee86cd4c1..194491231de2 100644
--- a/drivers/gpu/drm/sti/sti_dvo.c
+++ b/drivers/gpu/drm/sti/sti_dvo.c
@@ -96,9 +96,11 @@  struct sti_dvo {
 	struct dvo_config *config;
 	bool enabled;
 	struct drm_encoder *encoder;
-	struct drm_bridge *bridge;
+	struct drm_bridge bridge;
 };
 
+#define bridge_to_sti_dvo(b) container_of((b), struct sti_dvo, bridge)
+
 struct sti_dvo_connector {
 	struct drm_connector drm_connector;
 	struct drm_encoder *encoder;
@@ -210,7 +212,7 @@  static int dvo_debugfs_init(struct sti_dvo *dvo, struct drm_minor *minor)
 
 static void sti_dvo_disable(struct drm_bridge *bridge)
 {
-	struct sti_dvo *dvo = bridge->driver_private;
+	struct sti_dvo *dvo = bridge_to_sti_dvo(bridge);
 
 	if (!dvo->enabled)
 		return;
@@ -233,7 +235,7 @@  static void sti_dvo_disable(struct drm_bridge *bridge)
 
 static void sti_dvo_pre_enable(struct drm_bridge *bridge)
 {
-	struct sti_dvo *dvo = bridge->driver_private;
+	struct sti_dvo *dvo = bridge_to_sti_dvo(bridge);
 	struct dvo_config *config = dvo->config;
 	u32 val;
 
@@ -280,7 +282,7 @@  static void sti_dvo_set_mode(struct drm_bridge *bridge,
 			     const struct drm_display_mode *mode,
 			     const struct drm_display_mode *adjusted_mode)
 {
-	struct sti_dvo *dvo = bridge->driver_private;
+	struct sti_dvo *dvo = bridge_to_sti_dvo(bridge);
 	struct sti_mixer *mixer = to_sti_mixer(dvo->encoder->crtc);
 	int rate = mode->clock * 1000;
 	struct clk *clkp;
@@ -438,11 +440,11 @@  static struct drm_encoder *sti_dvo_find_encoder(struct drm_device *dev)
 static int sti_dvo_bind(struct device *dev, struct device *master, void *data)
 {
 	struct sti_dvo *dvo = dev_get_drvdata(dev);
+	struct drm_bridge *bridge = &dvo->bridge;
 	struct drm_device *drm_dev = data;
 	struct drm_encoder *encoder;
 	struct sti_dvo_connector *connector;
 	struct drm_connector *drm_connector;
-	struct drm_bridge *bridge;
 	int err;
 
 	/* Set the drm device handle */
@@ -458,11 +460,6 @@  static int sti_dvo_bind(struct device *dev, struct device *master, void *data)
 
 	connector->dvo = dvo;
 
-	bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL);
-	if (!bridge)
-		return -ENOMEM;
-
-	bridge->driver_private = dvo;
 	bridge->funcs = &sti_dvo_bridge_funcs;
 	bridge->of_node = dvo->dev.of_node;
 	drm_bridge_add(bridge);
@@ -473,7 +470,6 @@  static int sti_dvo_bind(struct device *dev, struct device *master, void *data)
 		return err;
 	}
 
-	dvo->bridge = bridge;
 	connector->encoder = encoder;
 	dvo->encoder = encoder;
 
@@ -504,7 +500,7 @@  static void sti_dvo_unbind(struct device *dev,
 {
 	struct sti_dvo *dvo = dev_get_drvdata(dev);
 
-	drm_bridge_remove(dvo->bridge);
+	drm_bridge_remove(&dvo->bridge);
 }
 
 static const struct component_ops sti_dvo_ops = {
diff --git a/drivers/gpu/drm/sti/sti_hda.c b/drivers/gpu/drm/sti/sti_hda.c
index 8f7bf33815fd..d5b569ce93d0 100644
--- a/drivers/gpu/drm/sti/sti_hda.c
+++ b/drivers/gpu/drm/sti/sti_hda.c
@@ -236,6 +236,7 @@  static const struct sti_hda_video_config hda_supported_modes[] = {
  *
  * @dev: driver device
  * @drm_dev: pointer to drm device
+ * @bridge: drm bridge for encoder->connector link
  * @mode: current display mode selected
  * @regs: HD analog register
  * @video_dacs_ctrl: video DACS control register
@@ -244,6 +245,7 @@  static const struct sti_hda_video_config hda_supported_modes[] = {
 struct sti_hda {
 	struct device dev;
 	struct drm_device *drm_dev;
+	struct drm_bridge bridge;
 	struct drm_display_mode mode;
 	void __iomem *regs;
 	void __iomem *video_dacs_ctrl;
@@ -252,6 +254,8 @@  struct sti_hda {
 	bool enabled;
 };
 
+#define bridge_to_sti_hda(b) container_of((b), struct sti_hda, bridge)
+
 struct sti_hda_connector {
 	struct drm_connector drm_connector;
 	struct drm_encoder *encoder;
@@ -400,7 +404,7 @@  static void sti_hda_configure_awg(struct sti_hda *hda, u32 *awg_instr, int nb)
 
 static void sti_hda_disable(struct drm_bridge *bridge)
 {
-	struct sti_hda *hda = bridge->driver_private;
+	struct sti_hda *hda = bridge_to_sti_hda(bridge);
 	u32 val;
 
 	if (!hda->enabled)
@@ -425,7 +429,7 @@  static void sti_hda_disable(struct drm_bridge *bridge)
 
 static void sti_hda_pre_enable(struct drm_bridge *bridge)
 {
-	struct sti_hda *hda = bridge->driver_private;
+	struct sti_hda *hda = bridge_to_sti_hda(bridge);
 	u32 val, i, mode_idx;
 	u32 src_filter_y, src_filter_c;
 	u32 *coef_y, *coef_c;
@@ -516,7 +520,7 @@  static void sti_hda_set_mode(struct drm_bridge *bridge,
 			     const struct drm_display_mode *mode,
 			     const struct drm_display_mode *adjusted_mode)
 {
-	struct sti_hda *hda = bridge->driver_private;
+	struct sti_hda *hda = bridge_to_sti_hda(bridge);
 	u32 mode_idx;
 	int hddac_rate;
 	int ret;
@@ -676,10 +680,10 @@  static int sti_hda_bind(struct device *dev, struct device *master, void *data)
 {
 	struct sti_hda *hda = dev_get_drvdata(dev);
 	struct drm_device *drm_dev = data;
+	struct drm_bridge *bridge = &hda->bridge;
 	struct drm_encoder *encoder;
 	struct sti_hda_connector *connector;
 	struct drm_connector *drm_connector;
-	struct drm_bridge *bridge;
 	int err;
 
 	/* Set the drm device handle */
@@ -695,11 +699,6 @@  static int sti_hda_bind(struct device *dev, struct device *master, void *data)
 
 	connector->hda = hda;
 
-		bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL);
-	if (!bridge)
-		return -ENOMEM;
-
-	bridge->driver_private = hda;
 	bridge->funcs = &sti_hda_bridge_funcs;
 	drm_bridge_attach(encoder, bridge, NULL);
 
diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c
index 814560ead4e1..7a7b0ce7bb14 100644
--- a/drivers/gpu/drm/sti/sti_hdmi.c
+++ b/drivers/gpu/drm/sti/sti_hdmi.c
@@ -741,7 +741,7 @@  static int hdmi_debugfs_init(struct sti_hdmi *hdmi, struct drm_minor *minor)
 
 static void sti_hdmi_disable(struct drm_bridge *bridge)
 {
-	struct sti_hdmi *hdmi = bridge->driver_private;
+	struct sti_hdmi *hdmi = bridge_to_sti_hdmi(bridge);
 
 	u32 val = hdmi_read(hdmi, HDMI_CFG);
 
@@ -873,7 +873,7 @@  static int hdmi_audio_configure(struct sti_hdmi *hdmi)
 
 static void sti_hdmi_pre_enable(struct drm_bridge *bridge)
 {
-	struct sti_hdmi *hdmi = bridge->driver_private;
+	struct sti_hdmi *hdmi = bridge_to_sti_hdmi(bridge);
 
 	DRM_DEBUG_DRIVER("\n");
 
@@ -928,7 +928,7 @@  static void sti_hdmi_set_mode(struct drm_bridge *bridge,
 			      const struct drm_display_mode *mode,
 			      const struct drm_display_mode *adjusted_mode)
 {
-	struct sti_hdmi *hdmi = bridge->driver_private;
+	struct sti_hdmi *hdmi = bridge_to_sti_hdmi(bridge);
 	int ret;
 
 	DRM_DEBUG_DRIVER("\n");
@@ -1255,11 +1255,11 @@  static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
 {
 	struct sti_hdmi *hdmi = dev_get_drvdata(dev);
 	struct drm_device *drm_dev = data;
+	struct drm_bridge *bridge = &hdmi->bridge;
 	struct drm_encoder *encoder;
 	struct sti_hdmi_connector *connector;
 	struct cec_connector_info conn_info;
 	struct drm_connector *drm_connector;
-	struct drm_bridge *bridge;
 	int err;
 
 	/* Set the drm device handle */
@@ -1275,11 +1275,6 @@  static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
 
 	connector->hdmi = hdmi;
 
-	bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL);
-	if (!bridge)
-		return -EINVAL;
-
-	bridge->driver_private = hdmi;
 	bridge->funcs = &sti_hdmi_bridge_funcs;
 	drm_bridge_attach(encoder, bridge, NULL);
 
diff --git a/drivers/gpu/drm/sti/sti_hdmi.h b/drivers/gpu/drm/sti/sti_hdmi.h
index 1f6dc90b5d83..4e33cbd7cbca 100644
--- a/drivers/gpu/drm/sti/sti_hdmi.h
+++ b/drivers/gpu/drm/sti/sti_hdmi.h
@@ -12,6 +12,7 @@ 
 
 #include <media/cec-notifier.h>
 
+#include <drm/drm_bridge.h>
 #include <drm/drm_modes.h>
 #include <drm/drm_property.h>
 
@@ -46,6 +47,7 @@  static const struct drm_prop_enum_list colorspace_mode_names[] = {
  *
  * @dev: driver device
  * @drm_dev: pointer to drm device
+ * @bridge: drm bridge for encoder->connector link
  * @mode: current display mode selected
  * @regs: hdmi register
  * @syscfg: syscfg register for pll rejection configuration
@@ -72,6 +74,7 @@  static const struct drm_prop_enum_list colorspace_mode_names[] = {
 struct sti_hdmi {
 	struct device dev;
 	struct drm_device *drm_dev;
+	struct drm_bridge bridge;
 	struct drm_display_mode mode;
 	void __iomem *regs;
 	void __iomem *syscfg;
@@ -96,6 +99,8 @@  struct sti_hdmi {
 	struct cec_notifier *notifier;
 };
 
+#define bridge_to_sti_hdmi(b) container_of((b), struct sti_hdmi, bridge)
+
 u32 hdmi_read(struct sti_hdmi *hdmi, int offset);
 void hdmi_write(struct sti_hdmi *hdmi, u32 val, int offset);