]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/gma500: Make oaktrail lvds use ddc adapter from drm_connector
authorPatrik Jakobsson <patrik.r.jakobsson@gmail.com>
Wed, 1 Jun 2022 09:23:10 +0000 (11:23 +0200)
committerPatrik Jakobsson <patrik.r.jakobsson@gmail.com>
Thu, 2 Jun 2022 08:06:47 +0000 (10:06 +0200)
We're moving all uses of ddc_bus to drm_connector where they belong.
The initialization of the gma_i2c_chan for Oaktrail is a bit backwards
so it required improvements. Also cleanup the error handling in
oaktrail_lvds_init(). Since this is the last user of
gma_encoder->ddc_bus we can remove it.

Signed-off-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20220601092311.22648-8-patrik.r.jakobsson@gmail.com
drivers/gpu/drm/gma500/oaktrail_lvds.c
drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
drivers/gpu/drm/gma500/psb_intel_drv.h

index 8609f6249c4ce6ee00ee37c3797d73222f8150ab..9c9ebf8e29c465a7de68a0aee08c861d19802457 100644 (file)
@@ -293,12 +293,14 @@ void oaktrail_lvds_init(struct drm_device *dev,
 {
        struct gma_encoder *gma_encoder;
        struct gma_connector *gma_connector;
+       struct gma_i2c_chan *ddc_bus;
        struct drm_connector *connector;
        struct drm_encoder *encoder;
        struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
        struct edid *edid;
        struct i2c_adapter *i2c_adap;
        struct drm_display_mode *scan;  /* *modes, *bios_mode; */
+       int ret;
 
        gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
        if (!gma_encoder)
@@ -306,16 +308,20 @@ void oaktrail_lvds_init(struct drm_device *dev,
 
        gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL);
        if (!gma_connector)
-               goto failed_connector;
+               goto err_free_encoder;
 
        connector = &gma_connector->base;
        encoder = &gma_encoder->base;
        dev_priv->is_lvds_on = true;
-       drm_connector_init(dev, connector,
-                          &psb_intel_lvds_connector_funcs,
-                          DRM_MODE_CONNECTOR_LVDS);
+       ret = drm_connector_init(dev, connector,
+                                &psb_intel_lvds_connector_funcs,
+                                DRM_MODE_CONNECTOR_LVDS);
+       if (ret)
+               goto err_free_connector;
 
-       drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_LVDS);
+       ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_LVDS);
+       if (ret)
+               goto err_connector_cleanup;
 
        gma_connector_attach_encoder(gma_connector, gma_encoder);
        gma_encoder->type = INTEL_OUTPUT_LVDS;
@@ -353,16 +359,26 @@ void oaktrail_lvds_init(struct drm_device *dev,
 
        edid = NULL;
        mutex_lock(&dev->mode_config.mutex);
+
        i2c_adap = i2c_get_adapter(dev_priv->ops->i2c_bus);
        if (i2c_adap)
                edid = drm_get_edid(connector, i2c_adap);
+
        if (edid == NULL && dev_priv->lpc_gpio_base) {
-               oaktrail_lvds_i2c_init(encoder);
-               if (gma_encoder->ddc_bus != NULL) {
-                       i2c_adap = &gma_encoder->ddc_bus->base;
+               ddc_bus = oaktrail_lvds_i2c_init(dev);
+               if (!IS_ERR(ddc_bus)) {
+                       i2c_adap = &ddc_bus->base;
                        edid = drm_get_edid(connector, i2c_adap);
                }
        }
+
+       /*
+        * Due to the logic in probing for i2c buses above we do not know the
+        * i2c_adap until now. Hence we cannot use drm_connector_init_with_ddc()
+        * but must instead set connector->ddc manually here.
+        */
+       connector->ddc = i2c_adap;
+
        /*
         * Attempt to get the fixed panel mode from DDC.  Assume that the
         * preferred mode is the right one.
@@ -395,7 +411,7 @@ void oaktrail_lvds_init(struct drm_device *dev,
        /* If we still don't have a mode after all that, give up. */
        if (!mode_dev->panel_fixed_mode) {
                dev_err(dev->dev, "Found no modes on the lvds, ignoring the LVDS\n");
-               goto failed_find;
+               goto err_unlock;
        }
 
 out:
@@ -403,21 +419,15 @@ out:
 
        return;
 
-failed_find:
+err_unlock:
        mutex_unlock(&dev->mode_config.mutex);
-
-       dev_dbg(dev->dev, "No LVDS modes found, disabling.\n");
-       if (gma_encoder->ddc_bus) {
-               gma_i2c_destroy(gma_encoder->ddc_bus);
-               gma_encoder->ddc_bus = NULL;
-       }
-
-/* failed_ddc: */
-
+       gma_i2c_destroy(to_gma_i2c_chan(connector->ddc));
        drm_encoder_cleanup(encoder);
+err_connector_cleanup:
        drm_connector_cleanup(connector);
+err_free_connector:
        kfree(gma_connector);
-failed_connector:
+err_free_encoder:
        kfree(gma_encoder);
 }
 
index ee163fb972d9836770ce551d19d1319f58622288..06b5b2d70d48425fba86b6d7e289974b9451901a 100644 (file)
@@ -129,16 +129,15 @@ static void set_data(void *data, int state_high)
        }
 }
 
-void oaktrail_lvds_i2c_init(struct drm_encoder *encoder)
+struct gma_i2c_chan *oaktrail_lvds_i2c_init(struct drm_device *dev)
 {
-       struct drm_device *dev = encoder->dev;
-       struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
        struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
        struct gma_i2c_chan *chan;
+       int ret;
 
        chan = kzalloc(sizeof(struct gma_i2c_chan), GFP_KERNEL);
        if (!chan)
-               return;
+               return ERR_PTR(-ENOMEM);
 
        chan->drm_dev = dev;
        chan->reg = dev_priv->lpc_gpio_base;
@@ -160,10 +159,11 @@ void oaktrail_lvds_i2c_init(struct drm_encoder *encoder)
        set_clock(chan, 1);
        udelay(50);
 
-       if (i2c_bit_add_bus(&chan->base)) {
+       ret = i2c_bit_add_bus(&chan->base);
+       if (ret < 0) {
                kfree(chan);
-               return;
+               return ERR_PTR(ret);
        }
 
-       gma_encoder->ddc_bus = chan;
+       return chan;
 }
index 1c28288f36a064427d92e6bbc003086dcb077054..8ccba116821b54d0e76aff66882749a3e9f4f898 100644 (file)
@@ -105,7 +105,6 @@ struct gma_encoder {
        /* FIXME: Either make SDVO and LVDS store it's i2c here or give CDV it's
           own set of output privates */
        struct gma_i2c_chan *i2c_bus;
-       struct gma_i2c_chan *ddc_bus;
 };
 
 struct gma_connector {
@@ -200,7 +199,7 @@ extern void oaktrail_lvds_init(struct drm_device *dev,
 extern void oaktrail_wait_for_INTR_PKT_SENT(struct drm_device *dev);
 extern void oaktrail_dsi_init(struct drm_device *dev,
                           struct psb_intel_mode_device *mode_dev);
-extern void oaktrail_lvds_i2c_init(struct drm_encoder *encoder);
+struct gma_i2c_chan *oaktrail_lvds_i2c_init(struct drm_device *dev);
 extern void mid_dsi_init(struct drm_device *dev,
                    struct psb_intel_mode_device *mode_dev, int dsi_num);