From d76f734f68eeea32c94de6ad4979a94ca8e320db Mon Sep 17 00:00:00 2001 From: Jon Smirl Date: Thu, 21 Oct 2004 16:58:28 +0000 Subject: [PATCH] Fix up the radeon i2c error handing --- linux-2.6/radeon_i2c.c | 33 +++++++++++-------------- linux-core/radeon_i2c.c | 55 +++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/linux-2.6/radeon_i2c.c b/linux-2.6/radeon_i2c.c index 9fdb2b4f..d116b381 100644 --- a/linux-2.6/radeon_i2c.c +++ b/linux-2.6/radeon_i2c.c @@ -82,10 +82,11 @@ static int gpio_getsda(void* data) return (val & VGA_DDC_DATA_INPUT) ? 1 : 0; } -static int setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name) +static int setup_i2c_bus(drm_device_t * dev, struct radeon_i2c_chan *chan, const char *name) { int rc; + chan->dev = dev; strcpy(chan->adapter.name, name); chan->adapter.owner = THIS_MODULE; chan->adapter.id = I2C_ALGO_ATI; @@ -106,39 +107,33 @@ static int setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name) gpio_setscl(chan, 1); udelay(20); - rc = i2c_bit_add_bus(&chan->adapter); - if (rc == 0) - DRM_DEBUG("I2C bus %s registered.\n", name); - else + if ((rc = i2c_bit_add_bus(&chan->adapter))) { + i2c_set_adapdata(&chan->adapter, NULL); + chan->dev = NULL; DRM_ERROR("Failed to register I2C bus %s.\n", name); - return rc; + return rc; + } + DRM_DEBUG("I2C bus %s registered.\n", name); + return 0; } int radeon_create_i2c_busses(drm_device_t * dev) { drm_radeon_private_t *dev_priv = dev->dev_private; - dev_priv->i2c[0].dev = dev; dev_priv->i2c[0].ddc_reg = GPIO_MONID; /* Don't return the error from setup. It is not fatal */ /* if the bus can not be initialized */ - if (!setup_i2c_bus(&dev_priv->i2c[0], "monid")) - dev_priv->i2c[0].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[0], "monid"); - dev_priv->i2c[1].dev = dev; dev_priv->i2c[1].ddc_reg = GPIO_DVI_DDC; - if (!setup_i2c_bus(&dev_priv->i2c[1], "dvi")) - dev_priv->i2c[1].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[1], "dvi"); - dev_priv->i2c[2].dev = dev; dev_priv->i2c[2].ddc_reg = GPIO_VGA_DDC; - if (!setup_i2c_bus(&dev_priv->i2c[2], "vga")) - dev_priv->i2c[2].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[2], "vga"); - dev_priv->i2c[3].dev = dev; dev_priv->i2c[3].ddc_reg = GPIO_CRT2_DDC; - if (!setup_i2c_bus(&dev_priv->i2c[3], "crt2")) - dev_priv->i2c[0].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[3], "crt2"); return 0; } @@ -151,8 +146,8 @@ void radeon_delete_i2c_busses(drm_device_t *dev) for (i = 0; i < 4; i++) { if (dev_priv->i2c[i].dev) { ret = i2c_bit_del_bus(&dev_priv->i2c[i].adapter); + dev_priv->i2c[i].dev = NULL; } - dev_priv->i2c[i].dev = NULL; } } diff --git a/linux-core/radeon_i2c.c b/linux-core/radeon_i2c.c index 32b68a2a..df369d6b 100644 --- a/linux-core/radeon_i2c.c +++ b/linux-core/radeon_i2c.c @@ -81,22 +81,23 @@ static int gpio_getsda(void *data) return (val & VGA_DDC_DATA_INPUT) ? 1 : 0; } -static int setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name) +static int setup_i2c_bus(drm_device_t * dev, struct radeon_i2c_chan *chan, const char *name) { int rc; + chan->dev = dev; strcpy(chan->adapter.name, name); - chan->adapter.owner = THIS_MODULE; - chan->adapter.id = I2C_ALGO_ATI; - chan->adapter.algo_data = &chan->algo; - chan->adapter.dev.parent = &chan->dev->pdev->dev; - chan->algo.setsda = gpio_setsda; - chan->algo.setscl = gpio_setscl; - chan->algo.getsda = gpio_getsda; - chan->algo.getscl = gpio_getscl; - chan->algo.udelay = 40; - chan->algo.timeout = 20; - chan->algo.data = chan; + chan->adapter.owner = THIS_MODULE; + chan->adapter.id = I2C_ALGO_ATI; + chan->adapter.algo_data = &chan->algo; + chan->adapter.dev.parent = &chan->dev->pdev->dev; + chan->algo.setsda = gpio_setsda; + chan->algo.setscl = gpio_setscl; + chan->algo.getsda = gpio_getsda; + chan->algo.getscl = gpio_getscl; + chan->algo.udelay = 40; + chan->algo.timeout = 20; + chan->algo.data = chan; i2c_set_adapdata(&chan->adapter, chan); @@ -105,39 +106,33 @@ static int setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name) gpio_setscl(chan, 1); udelay(20); - rc = i2c_bit_add_bus(&chan->adapter); - if (rc == 0) - DRM_DEBUG("I2C bus %s registered.\n", name); - else + if ((rc = i2c_bit_add_bus(&chan->adapter))) { + i2c_set_adapdata(&chan->adapter, NULL); + chan->dev = NULL; DRM_ERROR("Failed to register I2C bus %s.\n", name); - return rc; + return rc; + } + DRM_DEBUG("I2C bus %s registered.\n", name); + return 0; } int radeon_create_i2c_busses(drm_device_t * dev) { drm_radeon_private_t *dev_priv = dev->dev_private; - dev_priv->i2c[0].dev = dev; dev_priv->i2c[0].ddc_reg = GPIO_MONID; /* Don't return the error from setup. It is not fatal */ /* if the bus can not be initialized */ - if (!setup_i2c_bus(&dev_priv->i2c[0], "monid")) - dev_priv->i2c[0].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[0], "monid"); - dev_priv->i2c[1].dev = dev; dev_priv->i2c[1].ddc_reg = GPIO_DVI_DDC; - if (!setup_i2c_bus(&dev_priv->i2c[1], "dvi")) - dev_priv->i2c[1].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[1], "dvi"); - dev_priv->i2c[2].dev = dev; dev_priv->i2c[2].ddc_reg = GPIO_VGA_DDC; - if (!setup_i2c_bus(&dev_priv->i2c[2], "vga")) - dev_priv->i2c[2].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[2], "vga"); - dev_priv->i2c[3].dev = dev; dev_priv->i2c[3].ddc_reg = GPIO_CRT2_DDC; - if (!setup_i2c_bus(&dev_priv->i2c[3], "crt2")) - dev_priv->i2c[0].dev = NULL; + setup_i2c_bus(dev, &dev_priv->i2c[3], "crt2"); return 0; } @@ -150,8 +145,8 @@ void radeon_delete_i2c_busses(drm_device_t * dev) for (i = 0; i < 4; i++) { if (dev_priv->i2c[i].dev) { ret = i2c_bit_del_bus(&dev_priv->i2c[i].adapter); + dev_priv->i2c[i].dev = NULL; } - dev_priv->i2c[i].dev = NULL; } }