i2c-designware: Move checking of IP core version to i2c_dw_init()
authorDirk Brandewie <dirk.brandewie@gmail.com>
Thu, 6 Oct 2011 18:26:28 +0000 (11:26 -0700)
committerBen Dooks <ben-linux@fluff.org>
Sat, 29 Oct 2011 10:00:52 +0000 (11:00 +0100)
Move checking IP core version to i2c_dw_init() in preparation for
splitting i2c-designware.c into core and bus specific portions.

Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
drivers/i2c/busses/i2c-designware.c

index 934dfe1e6ce97b11253960150e51bea3c490b777..a7abbcd3d80540e158b2b787ba357ab2d93e4e46 100644 (file)
@@ -305,10 +305,24 @@ static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
  * This function is called during I2C init function, and in case of timeout at
  * run time.
  */
-static void i2c_dw_init(struct dw_i2c_dev *dev)
+static int i2c_dw_init(struct dw_i2c_dev *dev)
 {
        u32 input_clock_khz = clk_get_rate(dev->clk) / 1000;
        u32 ic_con, hcnt, lcnt;
+       u32 reg;
+
+       /* Configure register endianess access */
+       reg = dw_readl(dev, DW_IC_COMP_TYPE);
+       if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
+               dev->swab = 1;
+               reg = DW_IC_COMP_TYPE_VALUE;
+       }
+
+       if (reg != DW_IC_COMP_TYPE_VALUE) {
+               dev_err(dev->dev, "Unknown Synopsys component type: "
+                       "0x%08x\n", reg);
+               return -ENODEV;
+       }
 
        /* Disable the adapter */
        dw_writel(dev, 0, DW_IC_ENABLE);
@@ -351,6 +365,7 @@ static void i2c_dw_init(struct dw_i2c_dev *dev)
        ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
                DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
        dw_writel(dev, ic_con, DW_IC_CON);
+       return 0;
 }
 
 /*
@@ -770,21 +785,14 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
                goto err_unuse_clocks;
        }
 
-       reg = dw_readl(dev, DW_IC_COMP_TYPE);
-       if (reg == ___constant_swab32(0x44570140))
-               dev->swab = 1;
-       else if (reg != 0x44570140) {
-               dev_err(&pdev->dev, "Unknown Synopsys component type: "
-                               "0x%08x\n",     reg);
-               r = -ENODEV;
-               goto err_iounmap;
-       }
+       r = i2c_dw_init(dev);
+       if (r)
+               goto err_unuse_clocks;
 
        reg = dw_readl(dev, DW_IC_COMP_PARAM_1);
        dev->tx_fifo_depth = ((reg >> 16) & 0xff) + 1;
        dev->rx_fifo_depth = ((reg >> 8)  & 0xff) + 1;
 
-       i2c_dw_init(dev);
 
        dw_writel(dev, 0, DW_IC_INTR_MASK); /* disable IRQ */
        r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev);