]> Git Repo - linux.git/commitdiff
Merge branch 'for-2638/i2c/omap' into for-linus/i2c-2638
authorBen Dooks <[email protected]>
Wed, 12 Jan 2011 22:24:36 +0000 (22:24 +0000)
committerBen Dooks <[email protected]>
Wed, 12 Jan 2011 22:24:36 +0000 (22:24 +0000)
1  2 
drivers/i2c/busses/i2c-omap.c

index 9d090833e245a7a6cbe48dceedb2de60343ef58a,3e9323effc7ce3a9a51c53432aa5eb0c477c11c5..b605ff3a1fa05703d8fbbaf12df90aaa1c125813
@@@ -39,7 -39,6 +39,7 @@@
  #include <linux/io.h>
  #include <linux/slab.h>
  #include <linux/i2c-omap.h>
 +#include <linux/pm_runtime.h>
  
  /* I2C controller revisions */
  #define OMAP_I2C_REV_2                        0x20
@@@ -176,6 -175,8 +176,6 @@@ struct omap_i2c_dev 
        void __iomem            *base;          /* virtual */
        int                     irq;
        int                     reg_shift;      /* bit shift for I2C register addresses */
 -      struct clk              *iclk;          /* Interface clock */
 -      struct clk              *fclk;          /* Functional clock */
        struct completion       cmd_complete;
        struct resource         *ioarea;
        u32                     latency;        /* maximum mpu wkup latency */
@@@ -264,18 -265,45 +264,18 @@@ static inline u16 omap_i2c_read_reg(str
                                (i2c_dev->regs[reg] << i2c_dev->reg_shift));
  }
  
 -static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev)
 +static void omap_i2c_unidle(struct omap_i2c_dev *dev)
  {
 -      int ret;
 +      struct platform_device *pdev;
 +      struct omap_i2c_bus_platform_data *pdata;
  
 -      dev->iclk = clk_get(dev->dev, "ick");
 -      if (IS_ERR(dev->iclk)) {
 -              ret = PTR_ERR(dev->iclk);
 -              dev->iclk = NULL;
 -              return ret;
 -      }
 +      WARN_ON(!dev->idle);
  
 -      dev->fclk = clk_get(dev->dev, "fck");
 -      if (IS_ERR(dev->fclk)) {
 -              ret = PTR_ERR(dev->fclk);
 -              if (dev->iclk != NULL) {
 -                      clk_put(dev->iclk);
 -                      dev->iclk = NULL;
 -              }
 -              dev->fclk = NULL;
 -              return ret;
 -      }
 +      pdev = to_platform_device(dev->dev);
 +      pdata = pdev->dev.platform_data;
  
 -      return 0;
 -}
 +      pm_runtime_get_sync(&pdev->dev);
  
 -static void omap_i2c_put_clocks(struct omap_i2c_dev *dev)
 -{
 -      clk_put(dev->fclk);
 -      dev->fclk = NULL;
 -      clk_put(dev->iclk);
 -      dev->iclk = NULL;
 -}
 -
 -static void omap_i2c_unidle(struct omap_i2c_dev *dev)
 -{
 -      WARN_ON(!dev->idle);
 -
 -      clk_enable(dev->iclk);
 -      clk_enable(dev->fclk);
        if (cpu_is_omap34xx()) {
                omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
                omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate);
  
  static void omap_i2c_idle(struct omap_i2c_dev *dev)
  {
 +      struct platform_device *pdev;
 +      struct omap_i2c_bus_platform_data *pdata;
        u16 iv;
  
        WARN_ON(dev->idle);
  
 +      pdev = to_platform_device(dev->dev);
 +      pdata = pdev->dev.platform_data;
 +
        dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
        if (dev->rev >= OMAP_I2C_REV_ON_4430)
                omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1);
                omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
        }
        dev->idle = 1;
 -      clk_disable(dev->fclk);
 -      clk_disable(dev->iclk);
 +
 +      pm_runtime_put_sync(&pdev->dev);
  }
  
  static int omap_i2c_init(struct omap_i2c_dev *dev)
        unsigned long fclk_rate = 12000000;
        unsigned long timeout;
        unsigned long internal_clk = 0;
 +      struct clk *fclk;
  
        if (dev->rev >= OMAP_I2C_REV_2) {
                /* Disable I2C controller before soft reset */
                 * always returns 12MHz for the functional clock, we can
                 * do this bit unconditionally.
                 */
 -              fclk_rate = clk_get_rate(dev->fclk);
 +              fclk = clk_get(dev->dev, "fck");
 +              fclk_rate = clk_get_rate(fclk);
 +              clk_put(fclk);
  
                /* TRM for 5912 says the I2C clock must be prescaled to be
                 * between 7 - 12 MHz. The XOR input clock is typically
                        internal_clk = 9600;
                else
                        internal_clk = 4000;
 -              fclk_rate = clk_get_rate(dev->fclk) / 1000;
 +              fclk = clk_get(dev->dev, "fck");
 +              fclk_rate = clk_get_rate(fclk) / 1000;
 +              clk_put(fclk);
  
                /* Compute prescaler divisor */
                psc = fclk_rate / internal_clk;
@@@ -598,12 -616,8 +598,8 @@@ static int omap_i2c_xfer_msg(struct i2c
         * REVISIT: We should abort the transfer on signals, but the bus goes
         * into arbitration and we're currently unable to recover from it.
         */
-       if (dev->set_mpu_wkup_lat != NULL)
-               dev->set_mpu_wkup_lat(dev->dev, dev->latency);
        r = wait_for_completion_timeout(&dev->cmd_complete,
                                        OMAP_I2C_TIMEOUT);
-       if (dev->set_mpu_wkup_lat != NULL)
-               dev->set_mpu_wkup_lat(dev->dev, -1);
        dev->buf_len = 0;
        if (r < 0)
                return r;
@@@ -654,12 -668,18 +650,18 @@@ omap_i2c_xfer(struct i2c_adapter *adap
        if (r < 0)
                goto out;
  
+       if (dev->set_mpu_wkup_lat != NULL)
+               dev->set_mpu_wkup_lat(dev->dev, dev->latency);
        for (i = 0; i < num; i++) {
                r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1)));
                if (r != 0)
                        break;
        }
  
+       if (dev->set_mpu_wkup_lat != NULL)
+               dev->set_mpu_wkup_lat(dev->dev, -1);
        if (r == 0)
                r = num;
  
@@@ -1030,12 -1050,14 +1032,12 @@@ omap_i2c_probe(struct platform_device *
        else
                dev->reg_shift = 2;
  
 -      if ((r = omap_i2c_get_clocks(dev)) != 0)
 -              goto err_iounmap;
 -
        if (cpu_is_omap44xx())
                dev->regs = (u8 *) omap4_reg_map;
        else
                dev->regs = (u8 *) reg_map;
  
 +      pm_runtime_enable(&pdev->dev);
        omap_i2c_unidle(dev);
  
        dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
@@@ -1107,6 -1129,8 +1109,6 @@@ err_free_irq
  err_unuse_clocks:
        omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
        omap_i2c_idle(dev);
 -      omap_i2c_put_clocks(dev);
 -err_iounmap:
        iounmap(dev->base);
  err_free_mem:
        platform_set_drvdata(pdev, NULL);
@@@ -1128,6 -1152,7 +1130,6 @@@ omap_i2c_remove(struct platform_device 
        free_irq(dev->irq, dev);
        i2c_del_adapter(&dev->adapter);
        omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
 -      omap_i2c_put_clocks(dev);
        iounmap(dev->base);
        kfree(dev);
        mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@@ -1139,7 -1164,7 +1141,7 @@@ static struct platform_driver omap_i2c_
        .probe          = omap_i2c_probe,
        .remove         = omap_i2c_remove,
        .driver         = {
 -              .name   = "i2c_omap",
 +              .name   = "omap_i2c",
                .owner  = THIS_MODULE,
        },
  };
@@@ -1161,4 -1186,4 +1163,4 @@@ module_exit(omap_i2c_exit_driver)
  MODULE_AUTHOR("MontaVista Software, Inc. (and others)");
  MODULE_DESCRIPTION("TI OMAP I2C bus adapter");
  MODULE_LICENSE("GPL");
 -MODULE_ALIAS("platform:i2c_omap");
 +MODULE_ALIAS("platform:omap_i2c");
This page took 0.104429 seconds and 4 git commands to generate.