Skip to content

Commit 754cf4b

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: - regression fixes for i801 and designware - better API and leak fix for releasing DMA safe buffers - better greppable strings for the bitbang algorithm * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: sh_mobile: fix leak when using DMA bounce buffer i2c: sh_mobile: define start_ch() void as it only returns 0 anyhow i2c: refactor function to release a DMA safe buffer i2c: algos: bit: make the error messages grepable i2c: designware: Re-init controllers with pm_disabled set on resume i2c: i801: Allow ACPI AML access I/O ports not reserved for SMBus
2 parents 4658aff + cebc07d commit 754cf4b

File tree

8 files changed

+66
-44
lines changed

8 files changed

+66
-44
lines changed

Documentation/i2c/DMA-considerations

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ bounce buffer. But you don't need to care about that detail, just use the
5050
returned buffer. If NULL is returned, the threshold was not met or a bounce
5151
buffer could not be allocated. Fall back to PIO in that case.
5252

53-
In any case, a buffer obtained from above needs to be released. It ensures data
54-
is copied back to the message and a potentially used bounce buffer is freed::
53+
In any case, a buffer obtained from above needs to be released. Another helper
54+
function ensures a potentially used bounce buffer is freed::
5555

56-
i2c_release_dma_safe_msg_buf(msg, dma_buf);
56+
i2c_put_dma_safe_msg_buf(dma_buf, msg, xferred);
57+
58+
The last argument 'xferred' controls if the buffer is synced back to the
59+
message or not. No syncing is needed in cases setting up DMA had an error and
60+
there was no data transferred.
5761

5862
The bounce buffer handling from the core is generic and simple. It will always
5963
allocate a new bounce buffer. If you want a more sophisticated handling (e.g.

drivers/i2c/algos/i2c-algo-bit.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ static int sclhi(struct i2c_algo_bit_data *adap)
110110
}
111111
#ifdef DEBUG
112112
if (jiffies != start && i2c_debug >= 3)
113-
pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go "
114-
"high\n", jiffies - start);
113+
pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go high\n",
114+
jiffies - start);
115115
#endif
116116

117117
done:
@@ -171,8 +171,9 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
171171
setsda(adap, sb);
172172
udelay((adap->udelay + 1) / 2);
173173
if (sclhi(adap) < 0) { /* timed out */
174-
bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
175-
"timeout at bit #%d\n", (int)c, i);
174+
bit_dbg(1, &i2c_adap->dev,
175+
"i2c_outb: 0x%02x, timeout at bit #%d\n",
176+
(int)c, i);
176177
return -ETIMEDOUT;
177178
}
178179
/* FIXME do arbitration here:
@@ -185,8 +186,8 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
185186
}
186187
sdahi(adap);
187188
if (sclhi(adap) < 0) { /* timeout */
188-
bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
189-
"timeout at ack\n", (int)c);
189+
bit_dbg(1, &i2c_adap->dev,
190+
"i2c_outb: 0x%02x, timeout at ack\n", (int)c);
190191
return -ETIMEDOUT;
191192
}
192193

@@ -215,8 +216,9 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
215216
sdahi(adap);
216217
for (i = 0; i < 8; i++) {
217218
if (sclhi(adap) < 0) { /* timeout */
218-
bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit "
219-
"#%d\n", 7 - i);
219+
bit_dbg(1, &i2c_adap->dev,
220+
"i2c_inb: timeout at bit #%d\n",
221+
7 - i);
220222
return -ETIMEDOUT;
221223
}
222224
indata *= 2;
@@ -265,8 +267,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
265267
goto bailout;
266268
}
267269
if (!scl) {
268-
printk(KERN_WARNING "%s: SCL unexpected low "
269-
"while pulling SDA low!\n", name);
270+
printk(KERN_WARNING
271+
"%s: SCL unexpected low while pulling SDA low!\n",
272+
name);
270273
goto bailout;
271274
}
272275

@@ -278,8 +281,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
278281
goto bailout;
279282
}
280283
if (!scl) {
281-
printk(KERN_WARNING "%s: SCL unexpected low "
282-
"while pulling SDA high!\n", name);
284+
printk(KERN_WARNING
285+
"%s: SCL unexpected low while pulling SDA high!\n",
286+
name);
283287
goto bailout;
284288
}
285289

@@ -291,8 +295,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
291295
goto bailout;
292296
}
293297
if (!sda) {
294-
printk(KERN_WARNING "%s: SDA unexpected low "
295-
"while pulling SCL low!\n", name);
298+
printk(KERN_WARNING
299+
"%s: SDA unexpected low while pulling SCL low!\n",
300+
name);
296301
goto bailout;
297302
}
298303

@@ -304,8 +309,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
304309
goto bailout;
305310
}
306311
if (!sda) {
307-
printk(KERN_WARNING "%s: SDA unexpected low "
308-
"while pulling SCL high!\n", name);
312+
printk(KERN_WARNING
313+
"%s: SDA unexpected low while pulling SCL high!\n",
314+
name);
309315
goto bailout;
310316
}
311317

@@ -352,8 +358,8 @@ static int try_address(struct i2c_adapter *i2c_adap,
352358
i2c_start(adap);
353359
}
354360
if (i && ret)
355-
bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at "
356-
"0x%02x: %s\n", i + 1,
361+
bit_dbg(1, &i2c_adap->dev,
362+
"Used %d tries to %s client at 0x%02x: %s\n", i + 1,
357363
addr & 1 ? "read from" : "write to", addr >> 1,
358364
ret == 1 ? "success" : "failed, timeout?");
359365
return ret;
@@ -442,8 +448,9 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
442448
if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) {
443449
if (!(flags & I2C_M_NO_RD_ACK))
444450
acknak(i2c_adap, 0);
445-
dev_err(&i2c_adap->dev, "readbytes: invalid "
446-
"block length (%d)\n", inval);
451+
dev_err(&i2c_adap->dev,
452+
"readbytes: invalid block length (%d)\n",
453+
inval);
447454
return -EPROTO;
448455
}
449456
/* The original count value accounts for the extra
@@ -506,8 +513,8 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
506513
return -ENXIO;
507514
}
508515
if (flags & I2C_M_RD) {
509-
bit_dbg(3, &i2c_adap->dev, "emitting repeated "
510-
"start condition\n");
516+
bit_dbg(3, &i2c_adap->dev,
517+
"emitting repeated start condition\n");
511518
i2c_repstart(adap);
512519
/* okay, now switch into reading mode */
513520
addr |= 0x01;
@@ -564,8 +571,8 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
564571
}
565572
ret = bit_doAddress(i2c_adap, pmsg);
566573
if ((ret != 0) && !nak_ok) {
567-
bit_dbg(1, &i2c_adap->dev, "NAK from "
568-
"device addr 0x%02x msg #%d\n",
574+
bit_dbg(1, &i2c_adap->dev,
575+
"NAK from device addr 0x%02x msg #%d\n",
569576
msgs[i].addr, i);
570577
goto bailout;
571578
}

drivers/i2c/busses/i2c-designware-master.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
708708
i2c_set_adapdata(adap, dev);
709709

710710
if (dev->pm_disabled) {
711-
dev_pm_syscore_device(dev->dev, true);
712711
irq_flags = IRQF_NO_SUSPEND;
713712
} else {
714713
irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;

drivers/i2c/busses/i2c-designware-platdrv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ static int dw_i2c_plat_suspend(struct device *dev)
434434
{
435435
struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);
436436

437+
if (i_dev->pm_disabled)
438+
return 0;
439+
437440
i_dev->disable(i_dev);
438441
i2c_dw_prepare_clk(i_dev, false);
439442

@@ -444,7 +447,9 @@ static int dw_i2c_plat_resume(struct device *dev)
444447
{
445448
struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);
446449

447-
i2c_dw_prepare_clk(i_dev, true);
450+
if (!i_dev->pm_disabled)
451+
i2c_dw_prepare_clk(i_dev, true);
452+
448453
i_dev->init(i_dev);
449454

450455
return 0;

drivers/i2c/busses/i2c-i801.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,13 @@ static void i801_add_tco(struct i801_priv *priv)
14151415
}
14161416

14171417
#ifdef CONFIG_ACPI
1418+
static bool i801_acpi_is_smbus_ioport(const struct i801_priv *priv,
1419+
acpi_physical_address address)
1420+
{
1421+
return address >= priv->smba &&
1422+
address <= pci_resource_end(priv->pci_dev, SMBBAR);
1423+
}
1424+
14181425
static acpi_status
14191426
i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
14201427
u64 *value, void *handler_context, void *region_context)
@@ -1430,7 +1437,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
14301437
*/
14311438
mutex_lock(&priv->acpi_lock);
14321439

1433-
if (!priv->acpi_reserved) {
1440+
if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) {
14341441
priv->acpi_reserved = true;
14351442

14361443
dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n");

drivers/i2c/busses/i2c-sh_mobile.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,6 @@ static void sh_mobile_i2c_dma_callback(void *data)
507507
pd->pos = pd->msg->len;
508508
pd->stop_after_dma = true;
509509

510-
i2c_release_dma_safe_msg_buf(pd->msg, pd->dma_buf);
511-
512510
iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
513511
}
514512

@@ -602,8 +600,8 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
602600
dma_async_issue_pending(chan);
603601
}
604602

605-
static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
606-
bool do_init)
603+
static void start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
604+
bool do_init)
607605
{
608606
if (do_init) {
609607
/* Initialize channel registers */
@@ -627,7 +625,6 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
627625

628626
/* Enable all interrupts to begin with */
629627
iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
630-
return 0;
631628
}
632629

633630
static int poll_dte(struct sh_mobile_i2c_data *pd)
@@ -698,9 +695,7 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
698695
pd->send_stop = i == num - 1 || msg->flags & I2C_M_STOP;
699696
pd->stop_after_dma = false;
700697

701-
err = start_ch(pd, msg, do_start);
702-
if (err)
703-
break;
698+
start_ch(pd, msg, do_start);
704699

705700
if (do_start)
706701
i2c_op(pd, OP_START, 0);
@@ -709,6 +704,10 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
709704
timeout = wait_event_timeout(pd->wait,
710705
pd->sr & (ICSR_TACK | SW_DONE),
711706
adapter->timeout);
707+
708+
/* 'stop_after_dma' tells if DMA transfer was complete */
709+
i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg, pd->stop_after_dma);
710+
712711
if (!timeout) {
713712
dev_err(pd->dev, "Transfer request timed out\n");
714713
if (pd->dma_direction != DMA_NONE)

drivers/i2c/i2c-core-base.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,21 +2293,22 @@ u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
22932293
EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf);
22942294

22952295
/**
2296-
* i2c_release_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg
2297-
* @msg: the message to be synced with
2296+
* i2c_put_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg
22982297
* @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL.
2298+
* @msg: the message which the buffer corresponds to
2299+
* @xferred: bool saying if the message was transferred
22992300
*/
2300-
void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf)
2301+
void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred)
23012302
{
23022303
if (!buf || buf == msg->buf)
23032304
return;
23042305

2305-
if (msg->flags & I2C_M_RD)
2306+
if (xferred && msg->flags & I2C_M_RD)
23062307
memcpy(msg->buf, buf, msg->len);
23072308

23082309
kfree(buf);
23092310
}
2310-
EXPORT_SYMBOL_GPL(i2c_release_dma_safe_msg_buf);
2311+
EXPORT_SYMBOL_GPL(i2c_put_dma_safe_msg_buf);
23112312

23122313
MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
23132314
MODULE_DESCRIPTION("I2C-Bus main module");

include/linux/i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
855855
}
856856

857857
u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
858-
void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf);
858+
void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
859859

860860
int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
861861
/**

0 commit comments

Comments
 (0)