summaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorWolfram Sang <wsa@the-dreams.de>2015-03-14 07:08:53 -0400
committerWolfram Sang <wsa@the-dreams.de>2015-03-14 07:08:53 -0400
commit9ed1d862d7244b104c1519b329ec307b46bcf2a3 (patch)
tree8f880cb0b0455815eefefdaa8726bfaa19dbb38a /drivers/i2c
parent58b59e0f2462780ae3978611519f6a5e477e31df (diff)
parentbf07038051ddd6c1e017cd50933e314040a69b11 (diff)
Merge branch 'i2c/quirks' into i2c/for-4.1
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-at91.c32
-rw-r--r--drivers/i2c/busses/i2c-axxia.c11
-rw-r--r--drivers/i2c/busses/i2c-bcm-iproc.c15
-rw-r--r--drivers/i2c/busses/i2c-cpm.c20
-rw-r--r--drivers/i2c/busses/i2c-dln2.c12
-rw-r--r--drivers/i2c/busses/i2c-opal.c24
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c42
-rw-r--r--drivers/i2c/busses/i2c-powermac.c10
-rw-r--r--drivers/i2c/busses/i2c-qup.c21
-rw-r--r--drivers/i2c/busses/i2c-viperboard.c10
-rw-r--r--drivers/i2c/i2c-core.c62
11 files changed, 149 insertions, 110 deletions
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 636fd2efad88..b3a70e8fc653 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -487,30 +487,10 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
487 if (ret < 0) 487 if (ret < 0)
488 goto out; 488 goto out;
489 489
490 /* 490 if (num == 2) {
491 * The hardware can handle at most two messages concatenated by a
492 * repeated start via it's internal address feature.
493 */
494 if (num > 2) {
495 dev_err(dev->dev,
496 "cannot handle more than two concatenated messages.\n");
497 ret = 0;
498 goto out;
499 } else if (num == 2) {
500 int internal_address = 0; 491 int internal_address = 0;
501 int i; 492 int i;
502 493
503 if (msg->flags & I2C_M_RD) {
504 dev_err(dev->dev, "first transfer must be write.\n");
505 ret = -EINVAL;
506 goto out;
507 }
508 if (msg->len > 3) {
509 dev_err(dev->dev, "first message size must be <= 3.\n");
510 ret = -EINVAL;
511 goto out;
512 }
513
514 /* 1st msg is put into the internal address, start with 2nd */ 494 /* 1st msg is put into the internal address, start with 2nd */
515 m_start = &msg[1]; 495 m_start = &msg[1];
516 for (i = 0; i < msg->len; ++i) { 496 for (i = 0; i < msg->len; ++i) {
@@ -540,6 +520,15 @@ out:
540 return ret; 520 return ret;
541} 521}
542 522
523/*
524 * The hardware can handle at most two messages concatenated by a
525 * repeated start via it's internal address feature.
526 */
527static struct i2c_adapter_quirks at91_twi_quirks = {
528 .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR,
529 .max_comb_1st_msg_len = 3,
530};
531
543static u32 at91_twi_func(struct i2c_adapter *adapter) 532static u32 at91_twi_func(struct i2c_adapter *adapter)
544{ 533{
545 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL 534 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL
@@ -777,6 +766,7 @@ static int at91_twi_probe(struct platform_device *pdev)
777 dev->adapter.owner = THIS_MODULE; 766 dev->adapter.owner = THIS_MODULE;
778 dev->adapter.class = I2C_CLASS_DEPRECATED; 767 dev->adapter.class = I2C_CLASS_DEPRECATED;
779 dev->adapter.algo = &at91_twi_algorithm; 768 dev->adapter.algo = &at91_twi_algorithm;
769 dev->adapter.quirks = &at91_twi_quirks;
780 dev->adapter.dev.parent = dev->dev; 770 dev->adapter.dev.parent = dev->dev;
781 dev->adapter.nr = pdev->id; 771 dev->adapter.nr = pdev->id;
782 dev->adapter.timeout = AT91_I2C_TIMEOUT; 772 dev->adapter.timeout = AT91_I2C_TIMEOUT;
diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 768a598d8d03..488c5d3bf9db 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -336,11 +336,6 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
336 u32 addr_1, addr_2; 336 u32 addr_1, addr_2;
337 int ret; 337 int ret;
338 338
339 if (msg->len > 255) {
340 dev_warn(idev->dev, "unsupported length %u\n", msg->len);
341 return -EINVAL;
342 }
343
344 idev->msg = msg; 339 idev->msg = msg;
345 idev->msg_xfrd = 0; 340 idev->msg_xfrd = 0;
346 idev->msg_err = 0; 341 idev->msg_err = 0;
@@ -454,6 +449,11 @@ static const struct i2c_algorithm axxia_i2c_algo = {
454 .functionality = axxia_i2c_func, 449 .functionality = axxia_i2c_func,
455}; 450};
456 451
452static struct i2c_adapter_quirks axxia_i2c_quirks = {
453 .max_read_len = 255,
454 .max_write_len = 255,
455};
456
457static int axxia_i2c_probe(struct platform_device *pdev) 457static int axxia_i2c_probe(struct platform_device *pdev)
458{ 458{
459 struct device_node *np = pdev->dev.of_node; 459 struct device_node *np = pdev->dev.of_node;
@@ -511,6 +511,7 @@ static int axxia_i2c_probe(struct platform_device *pdev)
511 strlcpy(idev->adapter.name, pdev->name, sizeof(idev->adapter.name)); 511 strlcpy(idev->adapter.name, pdev->name, sizeof(idev->adapter.name));
512 idev->adapter.owner = THIS_MODULE; 512 idev->adapter.owner = THIS_MODULE;
513 idev->adapter.algo = &axxia_i2c_algo; 513 idev->adapter.algo = &axxia_i2c_algo;
514 idev->adapter.quirks = &axxia_i2c_quirks;
514 idev->adapter.dev.parent = &pdev->dev; 515 idev->adapter.dev.parent = &pdev->dev;
515 idev->adapter.dev.of_node = pdev->dev.of_node; 516 idev->adapter.dev.of_node = pdev->dev.of_node;
516 517
diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
index d3c89157b337..f9f2c2082151 100644
--- a/drivers/i2c/busses/i2c-bcm-iproc.c
+++ b/drivers/i2c/busses/i2c-bcm-iproc.c
@@ -160,14 +160,6 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c,
160 u32 val; 160 u32 val;
161 unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT_MESC); 161 unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT_MESC);
162 162
163 /* need to reserve one byte in the FIFO for the slave address */
164 if (msg->len > M_TX_RX_FIFO_SIZE - 1) {
165 dev_err(iproc_i2c->device,
166 "only support data length up to %u bytes\n",
167 M_TX_RX_FIFO_SIZE - 1);
168 return -EOPNOTSUPP;
169 }
170
171 /* check if bus is busy */ 163 /* check if bus is busy */
172 if (!!(readl(iproc_i2c->base + M_CMD_OFFSET) & 164 if (!!(readl(iproc_i2c->base + M_CMD_OFFSET) &
173 BIT(M_CMD_START_BUSY_SHIFT))) { 165 BIT(M_CMD_START_BUSY_SHIFT))) {
@@ -287,6 +279,12 @@ static const struct i2c_algorithm bcm_iproc_algo = {
287 .functionality = bcm_iproc_i2c_functionality, 279 .functionality = bcm_iproc_i2c_functionality,
288}; 280};
289 281
282static struct i2c_adapter_quirks bcm_iproc_i2c_quirks = {
283 /* need to reserve one byte in the FIFO for the slave address */
284 .max_read_len = M_TX_RX_FIFO_SIZE - 1,
285 .max_write_len = M_TX_RX_FIFO_SIZE - 1,
286};
287
290static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c) 288static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c)
291{ 289{
292 unsigned int bus_speed; 290 unsigned int bus_speed;
@@ -413,6 +411,7 @@ static int bcm_iproc_i2c_probe(struct platform_device *pdev)
413 i2c_set_adapdata(adap, iproc_i2c); 411 i2c_set_adapdata(adap, iproc_i2c);
414 strlcpy(adap->name, "Broadcom iProc I2C adapter", sizeof(adap->name)); 412 strlcpy(adap->name, "Broadcom iProc I2C adapter", sizeof(adap->name));
415 adap->algo = &bcm_iproc_algo; 413 adap->algo = &bcm_iproc_algo;
414 adap->quirks = &bcm_iproc_i2c_quirks;
416 adap->dev.parent = &pdev->dev; 415 adap->dev.parent = &pdev->dev;
417 adap->dev.of_node = pdev->dev.of_node; 416 adap->dev.of_node = pdev->dev.of_node;
418 417
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 2d466538b2e2..714bdc837769 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -308,22 +308,12 @@ static int cpm_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
308 struct i2c_reg __iomem *i2c_reg = cpm->i2c_reg; 308 struct i2c_reg __iomem *i2c_reg = cpm->i2c_reg;
309 struct i2c_ram __iomem *i2c_ram = cpm->i2c_ram; 309 struct i2c_ram __iomem *i2c_ram = cpm->i2c_ram;
310 struct i2c_msg *pmsg; 310 struct i2c_msg *pmsg;
311 int ret, i; 311 int ret;
312 int tptr; 312 int tptr;
313 int rptr; 313 int rptr;
314 cbd_t __iomem *tbdf; 314 cbd_t __iomem *tbdf;
315 cbd_t __iomem *rbdf; 315 cbd_t __iomem *rbdf;
316 316
317 if (num > CPM_MAXBD)
318 return -EINVAL;
319
320 /* Check if we have any oversized READ requests */
321 for (i = 0; i < num; i++) {
322 pmsg = &msgs[i];
323 if (pmsg->len >= CPM_MAX_READ)
324 return -EINVAL;
325 }
326
327 /* Reset to use first buffer */ 317 /* Reset to use first buffer */
328 out_be16(&i2c_ram->rbptr, in_be16(&i2c_ram->rbase)); 318 out_be16(&i2c_ram->rbptr, in_be16(&i2c_ram->rbase));
329 out_be16(&i2c_ram->tbptr, in_be16(&i2c_ram->tbase)); 319 out_be16(&i2c_ram->tbptr, in_be16(&i2c_ram->tbase));
@@ -424,10 +414,18 @@ static const struct i2c_algorithm cpm_i2c_algo = {
424 .functionality = cpm_i2c_func, 414 .functionality = cpm_i2c_func,
425}; 415};
426 416
417/* CPM_MAX_READ is also limiting writes according to the code! */
418static struct i2c_adapter_quirks cpm_i2c_quirks = {
419 .max_num_msgs = CPM_MAXBD,
420 .max_read_len = CPM_MAX_READ,
421 .max_write_len = CPM_MAX_READ,
422};
423
427static const struct i2c_adapter cpm_ops = { 424static const struct i2c_adapter cpm_ops = {
428 .owner = THIS_MODULE, 425 .owner = THIS_MODULE,
429 .name = "i2c-cpm", 426 .name = "i2c-cpm",
430 .algo = &cpm_i2c_algo, 427 .algo = &cpm_i2c_algo,
428 .quirks = &cpm_i2c_quirks,
431}; 429};
432 430
433static int cpm_i2c_setup(struct cpm_i2c *cpm) 431static int cpm_i2c_setup(struct cpm_i2c *cpm)
diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
index b3fb86af4cbb..b6f9ba7eb175 100644
--- a/drivers/i2c/busses/i2c-dln2.c
+++ b/drivers/i2c/busses/i2c-dln2.c
@@ -144,7 +144,6 @@ static int dln2_i2c_xfer(struct i2c_adapter *adapter,
144{ 144{
145 struct dln2_i2c *dln2 = i2c_get_adapdata(adapter); 145 struct dln2_i2c *dln2 = i2c_get_adapdata(adapter);
146 struct i2c_msg *pmsg; 146 struct i2c_msg *pmsg;
147 struct device *dev = &dln2->adapter.dev;
148 int i; 147 int i;
149 148
150 for (i = 0; i < num; i++) { 149 for (i = 0; i < num; i++) {
@@ -152,11 +151,6 @@ static int dln2_i2c_xfer(struct i2c_adapter *adapter,
152 151
153 pmsg = &msgs[i]; 152 pmsg = &msgs[i];
154 153
155 if (pmsg->len > DLN2_I2C_MAX_XFER_SIZE) {
156 dev_warn(dev, "maximum transfer size exceeded\n");
157 return -EOPNOTSUPP;
158 }
159
160 if (pmsg->flags & I2C_M_RD) { 154 if (pmsg->flags & I2C_M_RD) {
161 ret = dln2_i2c_read(dln2, pmsg->addr, pmsg->buf, 155 ret = dln2_i2c_read(dln2, pmsg->addr, pmsg->buf,
162 pmsg->len); 156 pmsg->len);
@@ -187,6 +181,11 @@ static const struct i2c_algorithm dln2_i2c_usb_algorithm = {
187 .functionality = dln2_i2c_func, 181 .functionality = dln2_i2c_func,
188}; 182};
189 183
184static struct i2c_adapter_quirks dln2_i2c_quirks = {
185 .max_read_len = DLN2_I2C_MAX_XFER_SIZE,
186 .max_write_len = DLN2_I2C_MAX_XFER_SIZE,
187};
188
190static int dln2_i2c_probe(struct platform_device *pdev) 189static int dln2_i2c_probe(struct platform_device *pdev)
191{ 190{
192 int ret; 191 int ret;
@@ -209,6 +208,7 @@ static int dln2_i2c_probe(struct platform_device *pdev)
209 dln2->adapter.owner = THIS_MODULE; 208 dln2->adapter.owner = THIS_MODULE;
210 dln2->adapter.class = I2C_CLASS_HWMON; 209 dln2->adapter.class = I2C_CLASS_HWMON;
211 dln2->adapter.algo = &dln2_i2c_usb_algorithm; 210 dln2->adapter.algo = &dln2_i2c_usb_algorithm;
211 dln2->adapter.quirks = &dln2_i2c_quirks;
212 dln2->adapter.dev.parent = dev; 212 dln2->adapter.dev.parent = dev;
213 i2c_set_adapdata(&dln2->adapter, dln2); 213 i2c_set_adapdata(&dln2->adapter, dln2);
214 snprintf(dln2->adapter.name, sizeof(dln2->adapter.name), "%s-%s-%d", 214 snprintf(dln2->adapter.name, sizeof(dln2->adapter.name), "%s-%s-%d",
diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 16f90b1a7508..75dd6d041241 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -104,18 +104,8 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
104 req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf)); 104 req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf));
105 break; 105 break;
106 case 2: 106 case 2:
107 /* For two messages, we basically support only simple 107 req.type = (msgs[1].flags & I2C_M_RD) ?
108 * smbus transactions of a write plus a read. We might 108 OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE;
109 * want to allow also two writes but we'd have to bounce
110 * the data into a single buffer.
111 */
112 if ((msgs[0].flags & I2C_M_RD) || !(msgs[1].flags & I2C_M_RD))
113 return -EOPNOTSUPP;
114 if (msgs[0].len > 4)
115 return -EOPNOTSUPP;
116 if (msgs[0].addr != msgs[1].addr)
117 return -EOPNOTSUPP;
118 req.type = OPAL_I2C_SM_READ;
119 req.addr = cpu_to_be16(msgs[0].addr); 109 req.addr = cpu_to_be16(msgs[0].addr);
120 req.subaddr_sz = msgs[0].len; 110 req.subaddr_sz = msgs[0].len;
121 for (i = 0; i < msgs[0].len; i++) 111 for (i = 0; i < msgs[0].len; i++)
@@ -210,6 +200,15 @@ static const struct i2c_algorithm i2c_opal_algo = {
210 .functionality = i2c_opal_func, 200 .functionality = i2c_opal_func,
211}; 201};
212 202
203/*
204 * For two messages, we basically support simple smbus transactions of a
205 * write-then-anything.
206 */
207static struct i2c_adapter_quirks i2c_opal_quirks = {
208 .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR,
209 .max_comb_1st_msg_len = 4,
210};
211
213static int i2c_opal_probe(struct platform_device *pdev) 212static int i2c_opal_probe(struct platform_device *pdev)
214{ 213{
215 struct i2c_adapter *adapter; 214 struct i2c_adapter *adapter;
@@ -232,6 +231,7 @@ static int i2c_opal_probe(struct platform_device *pdev)
232 231
233 adapter->algo = &i2c_opal_algo; 232 adapter->algo = &i2c_opal_algo;
234 adapter->algo_data = (void *)(unsigned long)opal_id; 233 adapter->algo_data = (void *)(unsigned long)opal_id;
234 adapter->quirks = &i2c_opal_quirks;
235 adapter->dev.parent = &pdev->dev; 235 adapter->dev.parent = &pdev->dev;
236 adapter->dev.of_node = of_node_get(pdev->dev.of_node); 236 adapter->dev.of_node = of_node_get(pdev->dev.of_node);
237 pname = of_get_property(pdev->dev.of_node, "ibm,port-name", NULL); 237 pname = of_get_property(pdev->dev.of_node, "ibm,port-name", NULL);
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
index d37d9db6681e..2c40edbf6224 100644
--- a/drivers/i2c/busses/i2c-pmcmsp.c
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -456,14 +456,6 @@ static enum pmcmsptwi_xfer_result pmcmsptwi_xfer_cmd(
456 return -EINVAL; 456 return -EINVAL;
457 } 457 }
458 458
459 if (cmd->read_len > MSP_MAX_BYTES_PER_RW ||
460 cmd->write_len > MSP_MAX_BYTES_PER_RW) {
461 dev_err(&pmcmsptwi_adapter.dev,
462 "%s: Cannot transfer more than %d bytes\n",
463 __func__, MSP_MAX_BYTES_PER_RW);
464 return -EINVAL;
465 }
466
467 mutex_lock(&data->lock); 459 mutex_lock(&data->lock);
468 dev_dbg(&pmcmsptwi_adapter.dev, 460 dev_dbg(&pmcmsptwi_adapter.dev,
469 "Setting address to 0x%04x\n", cmd->addr); 461 "Setting address to 0x%04x\n", cmd->addr);
@@ -520,25 +512,14 @@ static int pmcmsptwi_master_xfer(struct i2c_adapter *adap,
520 struct pmcmsptwi_cfg oldcfg, newcfg; 512 struct pmcmsptwi_cfg oldcfg, newcfg;
521 int ret; 513 int ret;
522 514
523 if (num > 2) { 515 if (num == 2) {
524 dev_dbg(&adap->dev, "%d messages unsupported\n", num);
525 return -EINVAL;
526 } else if (num == 2) {
527 /* Check for a dual write-then-read command */
528 struct i2c_msg *nextmsg = msg + 1; 516 struct i2c_msg *nextmsg = msg + 1;
529 if (!(msg->flags & I2C_M_RD) && 517
530 (nextmsg->flags & I2C_M_RD) && 518 cmd.type = MSP_TWI_CMD_WRITE_READ;
531 msg->addr == nextmsg->addr) { 519 cmd.write_len = msg->len;
532 cmd.type = MSP_TWI_CMD_WRITE_READ; 520 cmd.write_data = msg->buf;
533 cmd.write_len = msg->len; 521 cmd.read_len = nextmsg->len;
534 cmd.write_data = msg->buf; 522 cmd.read_data = nextmsg->buf;
535 cmd.read_len = nextmsg->len;
536 cmd.read_data = nextmsg->buf;
537 } else {
538 dev_dbg(&adap->dev,
539 "Non write-read dual messages unsupported\n");
540 return -EINVAL;
541 }
542 } else if (msg->flags & I2C_M_RD) { 523 } else if (msg->flags & I2C_M_RD) {
543 cmd.type = MSP_TWI_CMD_READ; 524 cmd.type = MSP_TWI_CMD_READ;
544 cmd.read_len = msg->len; 525 cmd.read_len = msg->len;
@@ -598,6 +579,14 @@ static u32 pmcmsptwi_i2c_func(struct i2c_adapter *adapter)
598 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_PROC_CALL; 579 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_PROC_CALL;
599} 580}
600 581
582static struct i2c_adapter_quirks pmcmsptwi_i2c_quirks = {
583 .flags = I2C_AQ_COMB_WRITE_THEN_READ,
584 .max_write_len = MSP_MAX_BYTES_PER_RW,
585 .max_read_len = MSP_MAX_BYTES_PER_RW,
586 .max_comb_1st_msg_len = MSP_MAX_BYTES_PER_RW,
587 .max_comb_2nd_msg_len = MSP_MAX_BYTES_PER_RW,
588};
589
601/* -- Initialization -- */ 590/* -- Initialization -- */
602 591
603static struct i2c_algorithm pmcmsptwi_algo = { 592static struct i2c_algorithm pmcmsptwi_algo = {
@@ -609,6 +598,7 @@ static struct i2c_adapter pmcmsptwi_adapter = {
609 .owner = THIS_MODULE, 598 .owner = THIS_MODULE,
610 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 599 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
611 .algo = &pmcmsptwi_algo, 600 .algo = &pmcmsptwi_algo,
601 .quirks = &pmcmsptwi_i2c_quirks,
612 .name = DRV_NAME, 602 .name = DRV_NAME,
613}; 603};
614 604
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 60a53c169ed2..6abcf696e359 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -153,12 +153,6 @@ static int i2c_powermac_master_xfer( struct i2c_adapter *adap,
153 int read; 153 int read;
154 int addrdir; 154 int addrdir;
155 155
156 if (num != 1) {
157 dev_err(&adap->dev,
158 "Multi-message I2C transactions not supported\n");
159 return -EOPNOTSUPP;
160 }
161
162 if (msgs->flags & I2C_M_TEN) 156 if (msgs->flags & I2C_M_TEN)
163 return -EINVAL; 157 return -EINVAL;
164 read = (msgs->flags & I2C_M_RD) != 0; 158 read = (msgs->flags & I2C_M_RD) != 0;
@@ -205,6 +199,9 @@ static const struct i2c_algorithm i2c_powermac_algorithm = {
205 .functionality = i2c_powermac_func, 199 .functionality = i2c_powermac_func,
206}; 200};
207 201
202static struct i2c_adapter_quirks i2c_powermac_quirks = {
203 .max_num_msgs = 1,
204};
208 205
209static int i2c_powermac_remove(struct platform_device *dev) 206static int i2c_powermac_remove(struct platform_device *dev)
210{ 207{
@@ -434,6 +431,7 @@ static int i2c_powermac_probe(struct platform_device *dev)
434 431
435 platform_set_drvdata(dev, adapter); 432 platform_set_drvdata(dev, adapter);
436 adapter->algo = &i2c_powermac_algorithm; 433 adapter->algo = &i2c_powermac_algorithm;
434 adapter->quirks = &i2c_powermac_quirks;
437 i2c_set_adapdata(adapter, bus); 435 i2c_set_adapdata(adapter, bus);
438 adapter->dev.parent = &dev->dev; 436 adapter->dev.parent = &dev->dev;
439 437
diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c
index 4dad23bdffbe..fdcbdab808e9 100644
--- a/drivers/i2c/busses/i2c-qup.c
+++ b/drivers/i2c/busses/i2c-qup.c
@@ -412,17 +412,6 @@ static int qup_i2c_read_one(struct qup_i2c_dev *qup, struct i2c_msg *msg)
412 unsigned long left; 412 unsigned long left;
413 int ret; 413 int ret;
414 414
415 /*
416 * The QUP block will issue a NACK and STOP on the bus when reaching
417 * the end of the read, the length of the read is specified as one byte
418 * which limits the possible read to 256 (QUP_READ_LIMIT) bytes.
419 */
420 if (msg->len > QUP_READ_LIMIT) {
421 dev_err(qup->dev, "HW not capable of reads over %d bytes\n",
422 QUP_READ_LIMIT);
423 return -EINVAL;
424 }
425
426 qup->msg = msg; 415 qup->msg = msg;
427 qup->pos = 0; 416 qup->pos = 0;
428 417
@@ -534,6 +523,15 @@ static const struct i2c_algorithm qup_i2c_algo = {
534 .functionality = qup_i2c_func, 523 .functionality = qup_i2c_func,
535}; 524};
536 525
526/*
527 * The QUP block will issue a NACK and STOP on the bus when reaching
528 * the end of the read, the length of the read is specified as one byte
529 * which limits the possible read to 256 (QUP_READ_LIMIT) bytes.
530 */
531static struct i2c_adapter_quirks qup_i2c_quirks = {
532 .max_read_len = QUP_READ_LIMIT,
533};
534
537static void qup_i2c_enable_clocks(struct qup_i2c_dev *qup) 535static void qup_i2c_enable_clocks(struct qup_i2c_dev *qup)
538{ 536{
539 clk_prepare_enable(qup->clk); 537 clk_prepare_enable(qup->clk);
@@ -670,6 +668,7 @@ static int qup_i2c_probe(struct platform_device *pdev)
670 668
671 i2c_set_adapdata(&qup->adap, qup); 669 i2c_set_adapdata(&qup->adap, qup);
672 qup->adap.algo = &qup_i2c_algo; 670 qup->adap.algo = &qup_i2c_algo;
671 qup->adap.quirks = &qup_i2c_quirks;
673 qup->adap.dev.parent = qup->dev; 672 qup->adap.dev.parent = qup->dev;
674 qup->adap.dev.of_node = pdev->dev.of_node; 673 qup->adap.dev.of_node = pdev->dev.of_node;
675 strlcpy(qup->adap.name, "QUP I2C adapter", sizeof(qup->adap.name)); 674 strlcpy(qup->adap.name, "QUP I2C adapter", sizeof(qup->adap.name));
diff --git a/drivers/i2c/busses/i2c-viperboard.c b/drivers/i2c/busses/i2c-viperboard.c
index 7533fa34d737..47e88adf2011 100644
--- a/drivers/i2c/busses/i2c-viperboard.c
+++ b/drivers/i2c/busses/i2c-viperboard.c
@@ -288,10 +288,6 @@ static int vprbrd_i2c_xfer(struct i2c_adapter *i2c, struct i2c_msg *msgs,
288 i, pmsg->flags & I2C_M_RD ? "read" : "write", 288 i, pmsg->flags & I2C_M_RD ? "read" : "write",
289 pmsg->flags, pmsg->len, pmsg->addr); 289 pmsg->flags, pmsg->len, pmsg->addr);
290 290
291 /* msgs longer than 2048 bytes are not supported by adapter */
292 if (pmsg->len > 2048)
293 return -EINVAL;
294
295 mutex_lock(&vb->lock); 291 mutex_lock(&vb->lock);
296 /* directly send the message */ 292 /* directly send the message */
297 if (pmsg->flags & I2C_M_RD) { 293 if (pmsg->flags & I2C_M_RD) {
@@ -358,6 +354,11 @@ static const struct i2c_algorithm vprbrd_algorithm = {
358 .functionality = vprbrd_i2c_func, 354 .functionality = vprbrd_i2c_func,
359}; 355};
360 356
357static struct i2c_adapter_quirks vprbrd_quirks = {
358 .max_read_len = 2048,
359 .max_write_len = 2048,
360};
361
361static int vprbrd_i2c_probe(struct platform_device *pdev) 362static int vprbrd_i2c_probe(struct platform_device *pdev)
362{ 363{
363 struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent); 364 struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent);
@@ -373,6 +374,7 @@ static int vprbrd_i2c_probe(struct platform_device *pdev)
373 vb_i2c->i2c.owner = THIS_MODULE; 374 vb_i2c->i2c.owner = THIS_MODULE;
374 vb_i2c->i2c.class = I2C_CLASS_HWMON; 375 vb_i2c->i2c.class = I2C_CLASS_HWMON;
375 vb_i2c->i2c.algo = &vprbrd_algorithm; 376 vb_i2c->i2c.algo = &vprbrd_algorithm;
377 vb_i2c->i2c.quirks = &vprbrd_quirks;
376 vb_i2c->i2c.algo_data = vb; 378 vb_i2c->i2c.algo_data = vb;
377 /* save the param in usb capabable memory */ 379 /* save the param in usb capabable memory */
378 vb_i2c->bus_freq_param = i2c_bus_param; 380 vb_i2c->bus_freq_param = i2c_bus_param;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 210cf4874cb7..57a86f4aab43 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1929,6 +1929,65 @@ module_exit(i2c_exit);
1929 * ---------------------------------------------------- 1929 * ----------------------------------------------------
1930 */ 1930 */
1931 1931
1932/* Check if val is exceeding the quirk IFF quirk is non 0 */
1933#define i2c_quirk_exceeded(val, quirk) ((quirk) && ((val) > (quirk)))
1934
1935static int i2c_quirk_error(struct i2c_adapter *adap, struct i2c_msg *msg, char *err_msg)
1936{
1937 dev_err_ratelimited(&adap->dev, "adapter quirk: %s (addr 0x%04x, size %u, %s)\n",
1938 err_msg, msg->addr, msg->len,
1939 msg->flags & I2C_M_RD ? "read" : "write");
1940 return -EOPNOTSUPP;
1941}
1942
1943static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1944{
1945 const struct i2c_adapter_quirks *q = adap->quirks;
1946 int max_num = q->max_num_msgs, i;
1947 bool do_len_check = true;
1948
1949 if (q->flags & I2C_AQ_COMB) {
1950 max_num = 2;
1951
1952 /* special checks for combined messages */
1953 if (num == 2) {
1954 if (q->flags & I2C_AQ_COMB_WRITE_FIRST && msgs[0].flags & I2C_M_RD)
1955 return i2c_quirk_error(adap, &msgs[0], "1st comb msg must be write");
1956
1957 if (q->flags & I2C_AQ_COMB_READ_SECOND && !(msgs[1].flags & I2C_M_RD))
1958 return i2c_quirk_error(adap, &msgs[1], "2nd comb msg must be read");
1959
1960 if (q->flags & I2C_AQ_COMB_SAME_ADDR && msgs[0].addr != msgs[1].addr)
1961 return i2c_quirk_error(adap, &msgs[0], "comb msg only to same addr");
1962
1963 if (i2c_quirk_exceeded(msgs[0].len, q->max_comb_1st_msg_len))
1964 return i2c_quirk_error(adap, &msgs[0], "msg too long");
1965
1966 if (i2c_quirk_exceeded(msgs[1].len, q->max_comb_2nd_msg_len))
1967 return i2c_quirk_error(adap, &msgs[1], "msg too long");
1968
1969 do_len_check = false;
1970 }
1971 }
1972
1973 if (i2c_quirk_exceeded(num, max_num))
1974 return i2c_quirk_error(adap, &msgs[0], "too many messages");
1975
1976 for (i = 0; i < num; i++) {
1977 u16 len = msgs[i].len;
1978
1979 if (msgs[i].flags & I2C_M_RD) {
1980 if (do_len_check && i2c_quirk_exceeded(len, q->max_read_len))
1981 return i2c_quirk_error(adap, &msgs[i], "msg too long");
1982 } else {
1983 if (do_len_check && i2c_quirk_exceeded(len, q->max_write_len))
1984 return i2c_quirk_error(adap, &msgs[i], "msg too long");
1985 }
1986 }
1987
1988 return 0;
1989}
1990
1932/** 1991/**
1933 * __i2c_transfer - unlocked flavor of i2c_transfer 1992 * __i2c_transfer - unlocked flavor of i2c_transfer
1934 * @adap: Handle to I2C bus 1993 * @adap: Handle to I2C bus
@@ -1946,6 +2005,9 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1946 unsigned long orig_jiffies; 2005 unsigned long orig_jiffies;
1947 int ret, try; 2006 int ret, try;
1948 2007
2008 if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
2009 return -EOPNOTSUPP;
2010
1949 /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets 2011 /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets
1950 * enabled. This is an efficient way of keeping the for-loop from 2012 * enabled. This is an efficient way of keeping the for-loop from
1951 * being executed when not needed. 2013 * being executed when not needed.