drm/rockchip: dw_hdmi: store rockchip_hdmi reference in phy_data object
authorHeiko Stuebner <heiko@sntech.de>
Wed, 12 Sep 2018 12:47:39 +0000 (14:47 +0200)
committerHeiko Stuebner <heiko@sntech.de>
Fri, 28 Sep 2018 10:23:44 +0000 (12:23 +0200)
When using special phy handling operations we'll often need access to
the rockchip_hdmi struct.

As the chip-data that occupies the phy_data pointer initially gets
assigned to the rockchip_hdmi struct, we can now re-use this phy_data
pointer to hold the reference to the rockchip_hdmi struct and use this
reference later on.

Inspiration for this comes from meson and sunxi dw-hdmi, which are using
the same method.

changes in v3:
- reword commit message

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Zheng Yang <zhengyang@rock-chips.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180912124740.20343-6-heiko@sntech.de
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c

index 57e76df..19f002f 100644 (file)
@@ -335,7 +335,7 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
                                 void *data)
 {
        struct platform_device *pdev = to_platform_device(dev);
-       const struct dw_hdmi_plat_data *plat_data;
+       struct dw_hdmi_plat_data *plat_data;
        const struct of_device_id *match;
        struct drm_device *drm = data;
        struct drm_encoder *encoder;
@@ -350,9 +350,14 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
                return -ENOMEM;
 
        match = of_match_node(dw_hdmi_rockchip_dt_ids, pdev->dev.of_node);
-       plat_data = match->data;
+       plat_data = devm_kmemdup(&pdev->dev, match->data,
+                                            sizeof(*plat_data), GFP_KERNEL);
+       if (!plat_data)
+               return -ENOMEM;
+
        hdmi->dev = &pdev->dev;
        hdmi->chip_data = plat_data->phy_data;
+       plat_data->phy_data = hdmi;
        encoder = &hdmi->encoder;
 
        encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);