Merge tag 'v3.14.25' into backport/v3.14.24-ltsi-rc1+v3.14.25/snapshot-merge.wip
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / i2c / busses / i2c-ismt.c
index 0043ede..acd32d1 100644 (file)
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  * The full GNU General Public License is included in this distribution
  * in the file called LICENSE.GPL.
  *
@@ -62,7 +58,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/kernel.h>
 #include <linux/stddef.h>
@@ -183,7 +178,7 @@ struct ismt_priv {
 /**
  * ismt_ids - PCI device IDs supported by this driver
  */
-static DEFINE_PCI_DEVICE_TABLE(ismt_ids) = {
+static const struct pci_device_id ismt_ids[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) },
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) },
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) },
@@ -344,6 +339,7 @@ static int ismt_process_desc(const struct ismt_desc *desc,
                        data->word = dma_buffer[0] | (dma_buffer[1] << 8);
                        break;
                case I2C_SMBUS_BLOCK_DATA:
+               case I2C_SMBUS_I2C_BLOCK_DATA:
                        memcpy(&data->block[1], dma_buffer, desc->rxbytes);
                        data->block[0] = desc->rxbytes;
                        break;
@@ -497,7 +493,7 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,
                        desc->wr_len_cmd = dma_size;
                        desc->control |= ISMT_DESC_BLK;
                        priv->dma_buffer[0] = command;
-                       memcpy(&priv->dma_buffer[1], &data->block[1], dma_size);
+                       memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1);
                } else {
                        /* Block Read */
                        dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA:  READ\n");
@@ -509,6 +505,41 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,
                }
                break;
 
+       case I2C_SMBUS_I2C_BLOCK_DATA:
+               /* Make sure the length is valid */
+               if (data->block[0] < 1)
+                       data->block[0] = 1;
+
+               if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
+                       data->block[0] = I2C_SMBUS_BLOCK_MAX;
+
+               if (read_write == I2C_SMBUS_WRITE) {
+                       /* i2c Block Write */
+                       dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA:  WRITE\n");
+                       dma_size = data->block[0] + 1;
+                       dma_direction = DMA_TO_DEVICE;
+                       desc->wr_len_cmd = dma_size;
+                       desc->control |= ISMT_DESC_I2C;
+                       priv->dma_buffer[0] = command;
+                       memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1);
+               } else {
+                       /* i2c Block Read */
+                       dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA:  READ\n");
+                       dma_size = data->block[0];
+                       dma_direction = DMA_FROM_DEVICE;
+                       desc->rd_len = dma_size;
+                       desc->wr_len_cmd = command;
+                       desc->control |= (ISMT_DESC_I2C | ISMT_DESC_CWRL);
+                       /*
+                        * Per the "Table 15-15. I2C Commands",
+                        * in the External Design Specification (EDS),
+                        * (Document Number: 508084, Revision: 2.0),
+                        * the _rw bit must be 0
+                        */
+                       desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, 0);
+               }
+               break;
+
        default:
                dev_err(dev, "Unsupported transaction %d\n",
                        size);
@@ -582,6 +613,7 @@ static u32 ismt_func(struct i2c_adapter *adap)
               I2C_FUNC_SMBUS_WORD_DATA         |
               I2C_FUNC_SMBUS_PROC_CALL         |
               I2C_FUNC_SMBUS_BLOCK_DATA        |
+              I2C_FUNC_SMBUS_I2C_BLOCK         |
               I2C_FUNC_SMBUS_PEC;
 }