drm: sti: allow to change hdmi ddc i2c adapter
authorBenjamin Gaignard <benjamin.gaignard@linaro.org>
Mon, 8 Sep 2014 13:52:08 +0000 (15:52 +0200)
committerBenjamin Gaignard <benjamin.gaignard@linaro.org>
Thu, 11 Dec 2014 12:57:59 +0000 (13:57 +0100)
Depending of the board configuration i2c for ddc could change,
this patch allow to use a phandle to specify which i2c controller to use.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Documentation/devicetree/bindings/gpu/st,stih4xx.txt
drivers/gpu/drm/sti/sti_hdmi.c
drivers/gpu/drm/sti/sti_hdmi.h

index 2d150c311a0539e0caa9ab302bf9943c18eb0fc1..8885d9e203fcb298dce24a0d534e347628495e9e 100644 (file)
@@ -69,6 +69,7 @@ STMicroelectronics stih4xx platforms
   - clock-names: names of the clocks listed in clocks property in the same
     order.
   - hdmi,hpd-gpio: gpio id to detect if an hdmi cable is plugged or not.
+  - ddc: phandle of an I2C controller used for DDC EDID probing
 
 sti-hda:
   Required properties:
index b22968c08d1fb7babe739939992a060eb9756cd3..fed1b5fe4842d72da235626f8162006d7061fda9 100644 (file)
@@ -480,17 +480,15 @@ static const struct drm_bridge_funcs sti_hdmi_bridge_funcs = {
 
 static int sti_hdmi_connector_get_modes(struct drm_connector *connector)
 {
-       struct i2c_adapter *i2c_adap;
+       struct sti_hdmi_connector *hdmi_connector
+               = to_sti_hdmi_connector(connector);
+       struct sti_hdmi *hdmi = hdmi_connector->hdmi;
        struct edid *edid;
        int count;
 
        DRM_DEBUG_DRIVER("\n");
 
-       i2c_adap = i2c_get_adapter(1);
-       if (!i2c_adap)
-               goto fail;
-
-       edid = drm_get_edid(connector, i2c_adap);
+       edid = drm_get_edid(connector, hdmi->ddc_adapt);
        if (!edid)
                goto fail;
 
@@ -603,29 +601,38 @@ static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
        struct sti_hdmi_connector *connector;
        struct drm_connector *drm_connector;
        struct drm_bridge *bridge;
-       struct i2c_adapter *i2c_adap;
+       struct device_node *ddc;
        int err;
 
-       i2c_adap = i2c_get_adapter(1);
-       if (!i2c_adap)
-               return -EPROBE_DEFER;
+       ddc = of_parse_phandle(dev->of_node, "ddc", 0);
+       if (ddc) {
+               hdmi->ddc_adapt = of_find_i2c_adapter_by_node(ddc);
+               if (!hdmi->ddc_adapt) {
+                       err = -EPROBE_DEFER;
+                       of_node_put(ddc);
+                       return err;
+               }
+
+               of_node_put(ddc);
+       }
 
        /* Set the drm device handle */
        hdmi->drm_dev = drm_dev;
 
        encoder = sti_hdmi_find_encoder(drm_dev);
        if (!encoder)
-               return -ENOMEM;
+               goto err_adapt;
 
        connector = devm_kzalloc(dev, sizeof(*connector), GFP_KERNEL);
        if (!connector)
-               return -ENOMEM;
+               goto err_adapt;
+
 
        connector->hdmi = hdmi;
 
        bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL);
        if (!bridge)
-               return -ENOMEM;
+               goto err_adapt;
 
        bridge->driver_private = hdmi;
        drm_bridge_init(drm_dev, bridge, &sti_hdmi_bridge_funcs);
@@ -662,6 +669,8 @@ err_sysfs:
 err_connector:
        drm_bridge_cleanup(bridge);
        drm_connector_cleanup(drm_connector);
+err_adapt:
+       put_device(&hdmi->ddc_adapt->dev);
        return -EINVAL;
 }
 
@@ -788,6 +797,11 @@ static int sti_hdmi_probe(struct platform_device *pdev)
 
 static int sti_hdmi_remove(struct platform_device *pdev)
 {
+       struct sti_hdmi *hdmi = dev_get_drvdata(&pdev->dev);
+
+       if (hdmi->ddc_adapt)
+               put_device(&hdmi->ddc_adapt->dev);
+
        component_del(&pdev->dev, &sti_hdmi_ops);
        return 0;
 }
index 61bec6557cebc7709654e816b02d2901f72edec8..d00a3e0d807f16e5aaa70537f984c50febc42975 100644 (file)
@@ -62,6 +62,7 @@ struct sti_hdmi {
        wait_queue_head_t wait_event;
        bool event_received;
        struct reset_control *reset;
+       struct i2c_adapter *ddc_adapt;
 };
 
 u32 hdmi_read(struct sti_hdmi *hdmi, int offset);