Skip to content

Commit 8cc9ddd

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "I2C has some pretty standard driver bugfixes and one minor cleanup" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: meson: Use complete() instead of complete_all() i2c: brcmstb: Use complete() instead of complete_all() i2c: bcm-kona: Use complete() instead of complete_all() i2c: bcm-iproc: Use complete() instead of complete_all() i2c: at91: fix support of the "alternative command" feature i2c: ocores: add missed clk_disable_unprepare() on failure paths i2c: cros-ec-tunnel: Fix usage of cros_ec_cmd_xfer() i2c: mux: demux-pinctrl: properly roll back when adding adapter fails
2 parents 43f4d36 + 0268263 commit 8cc9ddd

File tree

8 files changed

+34
-22
lines changed

8 files changed

+34
-22
lines changed

drivers/i2c/busses/i2c-at91.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */
3939
#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */
4040
#define AUTOSUSPEND_TIMEOUT 2000
41+
#define AT91_I2C_MAX_ALT_CMD_DATA_SIZE 256
4142

4243
/* AT91 TWI register definitions */
4344
#define AT91_TWI_CR 0x0000 /* Control Register */
@@ -141,6 +142,7 @@ struct at91_twi_dev {
141142
unsigned twi_cwgr_reg;
142143
struct at91_twi_pdata *pdata;
143144
bool use_dma;
145+
bool use_alt_cmd;
144146
bool recv_len_abort;
145147
u32 fifo_size;
146148
struct at91_twi_dma dma;
@@ -269,7 +271,7 @@ static void at91_twi_write_next_byte(struct at91_twi_dev *dev)
269271

270272
/* send stop when last byte has been written */
271273
if (--dev->buf_len == 0)
272-
if (!dev->pdata->has_alt_cmd)
274+
if (!dev->use_alt_cmd)
273275
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
274276

275277
dev_dbg(dev->dev, "wrote 0x%x, to go %d\n", *dev->buf, dev->buf_len);
@@ -292,7 +294,7 @@ static void at91_twi_write_data_dma_callback(void *data)
292294
* we just have to enable TXCOMP one.
293295
*/
294296
at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP);
295-
if (!dev->pdata->has_alt_cmd)
297+
if (!dev->use_alt_cmd)
296298
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
297299
}
298300

@@ -410,7 +412,7 @@ static void at91_twi_read_next_byte(struct at91_twi_dev *dev)
410412
}
411413

412414
/* send stop if second but last byte has been read */
413-
if (!dev->pdata->has_alt_cmd && dev->buf_len == 1)
415+
if (!dev->use_alt_cmd && dev->buf_len == 1)
414416
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
415417

416418
dev_dbg(dev->dev, "read 0x%x, to go %d\n", *dev->buf, dev->buf_len);
@@ -426,7 +428,7 @@ static void at91_twi_read_data_dma_callback(void *data)
426428
dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg[0]),
427429
dev->buf_len, DMA_FROM_DEVICE);
428430

429-
if (!dev->pdata->has_alt_cmd) {
431+
if (!dev->use_alt_cmd) {
430432
/* The last two bytes have to be read without using dma */
431433
dev->buf += dev->buf_len - 2;
432434
dev->buf_len = 2;
@@ -443,7 +445,7 @@ static void at91_twi_read_data_dma(struct at91_twi_dev *dev)
443445
struct dma_chan *chan_rx = dma->chan_rx;
444446
size_t buf_len;
445447

446-
buf_len = (dev->pdata->has_alt_cmd) ? dev->buf_len : dev->buf_len - 2;
448+
buf_len = (dev->use_alt_cmd) ? dev->buf_len : dev->buf_len - 2;
447449
dma->direction = DMA_FROM_DEVICE;
448450

449451
/* Keep in mind that we won't use dma to read the last two bytes */
@@ -651,7 +653,7 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
651653
unsigned start_flags = AT91_TWI_START;
652654

653655
/* if only one byte is to be read, immediately stop transfer */
654-
if (!has_alt_cmd && dev->buf_len <= 1 &&
656+
if (!dev->use_alt_cmd && dev->buf_len <= 1 &&
655657
!(dev->msg->flags & I2C_M_RECV_LEN))
656658
start_flags |= AT91_TWI_STOP;
657659
at91_twi_write(dev, AT91_TWI_CR, start_flags);
@@ -745,7 +747,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
745747
int ret;
746748
unsigned int_addr_flag = 0;
747749
struct i2c_msg *m_start = msg;
748-
bool is_read, use_alt_cmd = false;
750+
bool is_read;
749751

750752
dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num);
751753

@@ -768,14 +770,16 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
768770
at91_twi_write(dev, AT91_TWI_IADR, internal_address);
769771
}
770772

773+
dev->use_alt_cmd = false;
771774
is_read = (m_start->flags & I2C_M_RD);
772775
if (dev->pdata->has_alt_cmd) {
773-
if (m_start->len > 0) {
776+
if (m_start->len > 0 &&
777+
m_start->len < AT91_I2C_MAX_ALT_CMD_DATA_SIZE) {
774778
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMEN);
775779
at91_twi_write(dev, AT91_TWI_ACR,
776780
AT91_TWI_ACR_DATAL(m_start->len) |
777781
((is_read) ? AT91_TWI_ACR_DIR : 0));
778-
use_alt_cmd = true;
782+
dev->use_alt_cmd = true;
779783
} else {
780784
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMDIS);
781785
}
@@ -784,7 +788,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
784788
at91_twi_write(dev, AT91_TWI_MMR,
785789
(m_start->addr << 16) |
786790
int_addr_flag |
787-
((!use_alt_cmd && is_read) ? AT91_TWI_MREAD : 0));
791+
((!dev->use_alt_cmd && is_read) ? AT91_TWI_MREAD : 0));
788792

789793
dev->buf_len = m_start->len;
790794
dev->buf = m_start->buf;

drivers/i2c/busses/i2c-bcm-iproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static irqreturn_t bcm_iproc_i2c_isr(int irq, void *data)
158158

159159
if (status & BIT(IS_M_START_BUSY_SHIFT)) {
160160
iproc_i2c->xfer_is_done = 1;
161-
complete_all(&iproc_i2c->done);
161+
complete(&iproc_i2c->done);
162162
}
163163

164164
writel(status, iproc_i2c->base + IS_OFFSET);

drivers/i2c/busses/i2c-bcm-kona.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static irqreturn_t bcm_kona_i2c_isr(int irq, void *devid)
229229
dev->base + TXFCR_OFFSET);
230230

231231
writel(status & ~ISR_RESERVED_MASK, dev->base + ISR_OFFSET);
232-
complete_all(&dev->done);
232+
complete(&dev->done);
233233

234234
return IRQ_HANDLED;
235235
}

drivers/i2c/busses/i2c-brcmstb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static irqreturn_t brcmstb_i2c_isr(int irq, void *devid)
228228
return IRQ_NONE;
229229

230230
brcmstb_i2c_enable_disable_irq(dev, INT_DISABLE);
231-
complete_all(&dev->done);
231+
complete(&dev->done);
232232

233233
dev_dbg(dev->device, "isr handled");
234234
return IRQ_HANDLED;

drivers/i2c/busses/i2c-cros-ec-tunnel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[],
215215
msg->outsize = request_len;
216216
msg->insize = response_len;
217217

218-
result = cros_ec_cmd_xfer(bus->ec, msg);
218+
result = cros_ec_cmd_xfer_status(bus->ec, msg);
219219
if (result < 0) {
220220
dev_err(dev, "Error transferring EC i2c message %d\n", result);
221221
goto exit;

drivers/i2c/busses/i2c-meson.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void meson_i2c_stop(struct meson_i2c *i2c)
211211
meson_i2c_add_token(i2c, TOKEN_STOP);
212212
} else {
213213
i2c->state = STATE_IDLE;
214-
complete_all(&i2c->done);
214+
complete(&i2c->done);
215215
}
216216
}
217217

@@ -238,7 +238,7 @@ static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
238238
dev_dbg(i2c->dev, "error bit set\n");
239239
i2c->error = -ENXIO;
240240
i2c->state = STATE_IDLE;
241-
complete_all(&i2c->done);
241+
complete(&i2c->done);
242242
goto out;
243243
}
244244

@@ -269,7 +269,7 @@ static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
269269
break;
270270
case STATE_STOP:
271271
i2c->state = STATE_IDLE;
272-
complete_all(&i2c->done);
272+
complete(&i2c->done);
273273
break;
274274
case STATE_IDLE:
275275
break;

drivers/i2c/busses/i2c-ocores.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
379379
if (!clock_frequency_present) {
380380
dev_err(&pdev->dev,
381381
"Missing required parameter 'opencores,ip-clock-frequency'\n");
382+
clk_disable_unprepare(i2c->clk);
382383
return -ENODEV;
383384
}
384385
i2c->ip_clock_khz = clock_frequency / 1000;
@@ -467,20 +468,21 @@ static int ocores_i2c_probe(struct platform_device *pdev)
467468
default:
468469
dev_err(&pdev->dev, "Unsupported I/O width (%d)\n",
469470
i2c->reg_io_width);
470-
return -EINVAL;
471+
ret = -EINVAL;
472+
goto err_clk;
471473
}
472474
}
473475

474476
ret = ocores_init(&pdev->dev, i2c);
475477
if (ret)
476-
return ret;
478+
goto err_clk;
477479

478480
init_waitqueue_head(&i2c->wait);
479481
ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0,
480482
pdev->name, i2c);
481483
if (ret) {
482484
dev_err(&pdev->dev, "Cannot claim IRQ\n");
483-
return ret;
485+
goto err_clk;
484486
}
485487

486488
/* hook up driver to tree */
@@ -494,7 +496,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
494496
ret = i2c_add_adapter(&i2c->adap);
495497
if (ret) {
496498
dev_err(&pdev->dev, "Failed to add adapter\n");
497-
return ret;
499+
goto err_clk;
498500
}
499501

500502
/* add in known devices to the bus */
@@ -504,6 +506,10 @@ static int ocores_i2c_probe(struct platform_device *pdev)
504506
}
505507

506508
return 0;
509+
510+
err_clk:
511+
clk_disable_unprepare(i2c->clk);
512+
return ret;
507513
}
508514

509515
static int ocores_i2c_remove(struct platform_device *pdev)

drivers/i2c/muxes/i2c-demux-pinctrl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
6868
adap = of_find_i2c_adapter_by_node(priv->chan[new_chan].parent_np);
6969
if (!adap) {
7070
ret = -ENODEV;
71-
goto err;
71+
goto err_with_revert;
7272
}
7373

7474
p = devm_pinctrl_get_select(adap->dev.parent, priv->bus_name);
@@ -103,6 +103,8 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
103103

104104
err_with_put:
105105
i2c_put_adapter(adap);
106+
err_with_revert:
107+
of_changeset_revert(&priv->chan[new_chan].chgset);
106108
err:
107109
dev_err(priv->dev, "failed to setup demux-adapter %d (%d)\n", new_chan, ret);
108110
return ret;

0 commit comments

Comments
 (0)