]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/i2c/busses/i2c-at91.c
i2c: at91: print error messages in case of failed dma_request_slave_channel_reason()
[karo-tx-linux.git] / drivers / i2c / busses / i2c-at91.c
index 636fd2efad8850be3d028e940cae2667149ac4dc..0353599f2fdac455d2874f2fbe003a12c96d03f3 100644 (file)
@@ -185,7 +185,7 @@ static void at91_twi_dma_cleanup(struct at91_twi_dev *dev)
        }
        if (dma->buf_mapped) {
                dma_unmap_single(dev->dev, sg_dma_address(&dma->sg),
-                                dev->buf_len, dma->direction);
+                               sg_dma_len(&dma->sg), dma->direction);
                dma->buf_mapped = false;
        }
 
@@ -213,7 +213,7 @@ static void at91_twi_write_data_dma_callback(void *data)
        struct at91_twi_dev *dev = (struct at91_twi_dev *)data;
 
        dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg),
-                        dev->buf_len, DMA_TO_DEVICE);
+                       sg_dma_len(&dev->dma.sg), DMA_TO_DEVICE);
 
        at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
 }
@@ -304,7 +304,7 @@ static void at91_twi_read_data_dma_callback(void *data)
        struct at91_twi_dev *dev = (struct at91_twi_dev *)data;
 
        dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg),
-                        dev->buf_len, DMA_FROM_DEVICE);
+                       sg_dma_len(&dev->dma.sg), DMA_FROM_DEVICE);
 
        /* The last two bytes have to be read without using dma */
        dev->buf += dev->buf_len - 2;
@@ -381,6 +381,7 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id)
 static int at91_do_twi_transfer(struct at91_twi_dev *dev)
 {
        int ret;
+       unsigned long time_left;
        bool has_unre_flag = dev->pdata->has_unre_flag;
 
        dev_dbg(dev->dev, "transfer: %s %d bytes.\n",
@@ -436,9 +437,9 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
                }
        }
 
-       ret = wait_for_completion_timeout(&dev->cmd_complete,
-                                            dev->adapter.timeout);
-       if (ret == 0) {
+       time_left = wait_for_completion_timeout(&dev->cmd_complete,
+                                             dev->adapter.timeout);
+       if (time_left == 0) {
                dev_err(dev->dev, "controller timed out\n");
                at91_init_twi_bus(dev);
                ret = -ETIMEDOUT;
@@ -487,30 +488,10 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
        if (ret < 0)
                goto out;
 
-       /*
-        * The hardware can handle at most two messages concatenated by a
-        * repeated start via it's internal address feature.
-        */
-       if (num > 2) {
-               dev_err(dev->dev,
-                       "cannot handle more than two concatenated messages.\n");
-               ret = 0;
-               goto out;
-       } else if (num == 2) {
+       if (num == 2) {
                int internal_address = 0;
                int i;
 
-               if (msg->flags & I2C_M_RD) {
-                       dev_err(dev->dev, "first transfer must be write.\n");
-                       ret = -EINVAL;
-                       goto out;
-               }
-               if (msg->len > 3) {
-                       dev_err(dev->dev, "first message size must be <= 3.\n");
-                       ret = -EINVAL;
-                       goto out;
-               }
-
                /* 1st msg is put into the internal address, start with 2nd */
                m_start = &msg[1];
                for (i = 0; i < msg->len; ++i) {
@@ -540,6 +521,15 @@ out:
        return ret;
 }
 
+/*
+ * The hardware can handle at most two messages concatenated by a
+ * repeated start via it's internal address feature.
+ */
+static struct i2c_adapter_quirks at91_twi_quirks = {
+       .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR,
+       .max_comb_1st_msg_len = 3,
+};
+
 static u32 at91_twi_func(struct i2c_adapter *adapter)
 {
        return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL
@@ -653,6 +643,7 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr)
        dma->chan_tx = dma_request_slave_channel_reason(dev->dev, "tx");
        if (IS_ERR(dma->chan_tx)) {
                ret = PTR_ERR(dma->chan_tx);
+               dev_err(dev->dev, "Failed to get tx DMA: %d\n", ret);
                dma->chan_tx = NULL;
                goto error;
        }
@@ -660,6 +651,7 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr)
        dma->chan_rx = dma_request_slave_channel_reason(dev->dev, "rx");
        if (IS_ERR(dma->chan_rx)) {
                ret = PTR_ERR(dma->chan_rx);
+               dev_err(dev->dev, "Failed to get rx DMA: %d\n", ret);
                dma->chan_rx = NULL;
                goto error;
        }
@@ -777,6 +769,7 @@ static int at91_twi_probe(struct platform_device *pdev)
        dev->adapter.owner = THIS_MODULE;
        dev->adapter.class = I2C_CLASS_DEPRECATED;
        dev->adapter.algo = &at91_twi_algorithm;
+       dev->adapter.quirks = &at91_twi_quirks;
        dev->adapter.dev.parent = dev->dev;
        dev->adapter.nr = pdev->id;
        dev->adapter.timeout = AT91_I2C_TIMEOUT;