Skip to content

Commit 871dda4

Browse files
committed
Merge branch 'i2c/for-mergewindow' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "I2C has a smaller pull reuest this time: - new driver for I2C virtio - removal of PMC SMP driver because platform is already gone - IRQ probing and DMAENGINE API cleanups - add SI metric prefix definitions to units.h - beginning of i801 refactorization - a few driver improvements" * 'i2c/for-mergewindow' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (28 commits) i2c: cadence: Implement save restore i2c: xlp9xx: fix main IRQ check i2c: mt65xx: fix IRQ check i2c: virtio: add a virtio i2c frontend driver i2c: hix5hd2: fix IRQ check i2c: s3c2410: fix IRQ check i2c: iop3xx: fix deferred probing i2c: synquacer: fix deferred probing i2c: sun6i-pw2i: Prefer strscpy over strlcpy i2c: remove dead PMC MSP TWI/SMBus/I2C driver i2c: dev: Use sysfs_emit() in "show" functions i2c: dev: Define pr_fmt() and drop duplication substrings i2c: designware: Fix indentation in the header i2c: designware: Use DIV_ROUND_CLOSEST() macro units: Add SI metric prefix definitions i2c: at91: mark PM ops as __maybe unused i2c: sh_mobile: : use proper DMAENGINE API for termination i2c: qup: : use proper DMAENGINE API for termination i2c: mxs: : use proper DMAENGINE API for termination i2c: imx: : use proper DMAENGINE API for termination ...
2 parents 359f3d7 + 8b51a8e commit 871dda4

29 files changed

+467
-730
lines changed

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19736,6 +19736,15 @@ S: Maintained
1973619736
F: include/uapi/linux/virtio_snd.h
1973719737
F: sound/virtio/*
1973819738

19739+
VIRTIO I2C DRIVER
19740+
M: Jie Deng <[email protected]>
19741+
M: Viresh Kumar <[email protected]>
19742+
19743+
19744+
S: Maintained
19745+
F: drivers/i2c/busses/i2c-virtio.c
19746+
F: include/uapi/linux/virtio_i2c.h
19747+
1973919748
VIRTUAL BOX GUEST DEVICE DRIVER
1974019749
M: Hans de Goede <[email protected]>
1974119750
M: Arnd Bergmann <[email protected]>

drivers/i2c/busses/Kconfig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,6 @@ config I2C_PCA_PLATFORM
866866
This driver can also be built as a module. If so, the module
867867
will be called i2c-pca-platform.
868868

869-
config I2C_PMCMSP
870-
tristate "PMC MSP I2C TWI Controller"
871-
depends on PMC_MSP || COMPILE_TEST
872-
help
873-
This driver supports the PMC TWI controller on MSP devices.
874-
875-
This driver can also be built as module. If so, the module
876-
will be called i2c-pmcmsp.
877-
878869
config I2C_PNX
879870
tristate "I2C bus support for Philips PNX and NXP LPC targets"
880871
depends on ARCH_LPC32XX || COMPILE_TEST
@@ -1402,4 +1393,15 @@ config I2C_FSI
14021393
This driver can also be built as a module. If so, the module will be
14031394
called as i2c-fsi.
14041395

1396+
config I2C_VIRTIO
1397+
tristate "Virtio I2C Adapter"
1398+
select VIRTIO
1399+
help
1400+
If you say yes to this option, support will be included for the virtio
1401+
I2C adapter driver. The hardware can be emulated by any device model
1402+
software according to the virtio protocol.
1403+
1404+
This driver can also be built as a module. If so, the module
1405+
will be called i2c-virtio.
1406+
14051407
endmenu

drivers/i2c/busses/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ obj-$(CONFIG_I2C_OMAP) += i2c-omap.o
8686
obj-$(CONFIG_I2C_OWL) += i2c-owl.o
8787
obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
8888
obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o
89-
obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o
9089
obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
9190
obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
9291
obj-$(CONFIG_I2C_PXA_PCI) += i2c-pxa-pci.o
@@ -146,5 +145,6 @@ obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
146145
obj-$(CONFIG_I2C_XGENE_SLIMPRO) += i2c-xgene-slimpro.o
147146
obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
148147
obj-$(CONFIG_I2C_FSI) += i2c-fsi.o
148+
obj-$(CONFIG_I2C_VIRTIO) += i2c-virtio.o
149149

150150
ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG

drivers/i2c/busses/i2c-at91-core.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ static int at91_twi_remove(struct platform_device *pdev)
286286
return 0;
287287
}
288288

289-
#ifdef CONFIG_PM
290-
291-
static int at91_twi_runtime_suspend(struct device *dev)
289+
static int __maybe_unused at91_twi_runtime_suspend(struct device *dev)
292290
{
293291
struct at91_twi_dev *twi_dev = dev_get_drvdata(dev);
294292

@@ -299,7 +297,7 @@ static int at91_twi_runtime_suspend(struct device *dev)
299297
return 0;
300298
}
301299

302-
static int at91_twi_runtime_resume(struct device *dev)
300+
static int __maybe_unused at91_twi_runtime_resume(struct device *dev)
303301
{
304302
struct at91_twi_dev *twi_dev = dev_get_drvdata(dev);
305303

@@ -308,15 +306,15 @@ static int at91_twi_runtime_resume(struct device *dev)
308306
return clk_prepare_enable(twi_dev->clk);
309307
}
310308

311-
static int at91_twi_suspend_noirq(struct device *dev)
309+
static int __maybe_unused at91_twi_suspend_noirq(struct device *dev)
312310
{
313311
if (!pm_runtime_status_suspended(dev))
314312
at91_twi_runtime_suspend(dev);
315313

316314
return 0;
317315
}
318316

319-
static int at91_twi_resume_noirq(struct device *dev)
317+
static int __maybe_unused at91_twi_resume_noirq(struct device *dev)
320318
{
321319
struct at91_twi_dev *twi_dev = dev_get_drvdata(dev);
322320
int ret;
@@ -335,26 +333,21 @@ static int at91_twi_resume_noirq(struct device *dev)
335333
return 0;
336334
}
337335

338-
static const struct dev_pm_ops at91_twi_pm = {
336+
static const struct dev_pm_ops __maybe_unused at91_twi_pm = {
339337
.suspend_noirq = at91_twi_suspend_noirq,
340338
.resume_noirq = at91_twi_resume_noirq,
341339
.runtime_suspend = at91_twi_runtime_suspend,
342340
.runtime_resume = at91_twi_runtime_resume,
343341
};
344342

345-
#define at91_twi_pm_ops (&at91_twi_pm)
346-
#else
347-
#define at91_twi_pm_ops NULL
348-
#endif
349-
350343
static struct platform_driver at91_twi_driver = {
351344
.probe = at91_twi_probe,
352345
.remove = at91_twi_remove,
353346
.id_table = at91_twi_devtypes,
354347
.driver = {
355348
.name = "at91_i2c",
356349
.of_match_table = of_match_ptr(atmel_twi_dt_ids),
357-
.pm = at91_twi_pm_ops,
350+
.pm = pm_ptr(&at91_twi_pm),
358351
},
359352
};
360353

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ static void at91_twi_dma_cleanup(struct at91_twi_dev *dev)
138138

139139
if (dma->xfer_in_progress) {
140140
if (dma->direction == DMA_FROM_DEVICE)
141-
dmaengine_terminate_all(dma->chan_rx);
141+
dmaengine_terminate_sync(dma->chan_rx);
142142
else
143-
dmaengine_terminate_all(dma->chan_tx);
143+
dmaengine_terminate_sync(dma->chan_tx);
144144
dma->xfer_in_progress = false;
145145
}
146146
if (dma->buf_mapped) {

drivers/i2c/busses/i2c-cadence.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ enum cdns_i2c_slave_state {
178178
* @clk: Pointer to struct clk
179179
* @clk_rate_change_nb: Notifier block for clock rate changes
180180
* @quirks: flag for broken hold bit usage in r1p10
181+
* @ctrl_reg: Cached value of the control register.
181182
* @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
182183
* @slave: Registered slave instance.
183184
* @dev_mode: I2C operating role(master/slave).
@@ -202,6 +203,7 @@ struct cdns_i2c {
202203
struct clk *clk;
203204
struct notifier_block clk_rate_change_nb;
204205
u32 quirks;
206+
u32 ctrl_reg;
205207
#if IS_ENABLED(CONFIG_I2C_SLAVE)
206208
u16 ctrl_reg_diva_divb;
207209
struct i2c_client *slave;
@@ -1071,10 +1073,11 @@ static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id)
10711073
if (ret)
10721074
return ret;
10731075

1074-
ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
1076+
ctrl_reg = id->ctrl_reg;
10751077
ctrl_reg &= ~(CDNS_I2C_CR_DIVA_MASK | CDNS_I2C_CR_DIVB_MASK);
10761078
ctrl_reg |= ((div_a << CDNS_I2C_CR_DIVA_SHIFT) |
10771079
(div_b << CDNS_I2C_CR_DIVB_SHIFT));
1080+
id->ctrl_reg = ctrl_reg;
10781081
cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET);
10791082
#if IS_ENABLED(CONFIG_I2C_SLAVE)
10801083
id->ctrl_reg_diva_divb = ctrl_reg & (CDNS_I2C_CR_DIVA_MASK |
@@ -1162,6 +1165,26 @@ static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev)
11621165
return 0;
11631166
}
11641167

1168+
/**
1169+
* cdns_i2c_init - Controller initialisation
1170+
* @id: Device private data structure
1171+
*
1172+
* Initialise the i2c controller.
1173+
*
1174+
*/
1175+
static void cdns_i2c_init(struct cdns_i2c *id)
1176+
{
1177+
cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET);
1178+
/*
1179+
* Cadence I2C controller has a bug wherein it generates
1180+
* invalid read transaction after HW timeout in master receiver mode.
1181+
* HW timeout is not used by this driver and the interrupt is disabled.
1182+
* But the feature itself cannot be disabled. Hence maximum value
1183+
* is written to this register to reduce the chances of error.
1184+
*/
1185+
cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET);
1186+
}
1187+
11651188
/**
11661189
* cdns_i2c_runtime_resume - Runtime resume
11671190
* @dev: Address of the platform_device structure
@@ -1180,6 +1203,7 @@ static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev)
11801203
dev_err(dev, "Cannot enable clock.\n");
11811204
return ret;
11821205
}
1206+
cdns_i2c_init(xi2c);
11831207

11841208
return 0;
11851209
}
@@ -1279,7 +1303,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
12791303
id->dev_mode = CDNS_I2C_MODE_MASTER;
12801304
id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE;
12811305
#endif
1282-
cdns_i2c_writereg(CDNS_I2C_CR_MASTER_EN_MASK, CDNS_I2C_CR_OFFSET);
1306+
id->ctrl_reg = CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS;
12831307

12841308
ret = cdns_i2c_setclk(id->input_clk, id);
12851309
if (ret) {
@@ -1294,15 +1318,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
12941318
dev_err(&pdev->dev, "cannot get irq %d\n", id->irq);
12951319
goto err_clk_dis;
12961320
}
1297-
1298-
/*
1299-
* Cadence I2C controller has a bug wherein it generates
1300-
* invalid read transaction after HW timeout in master receiver mode.
1301-
* HW timeout is not used by this driver and the interrupt is disabled.
1302-
* But the feature itself cannot be disabled. Hence maximum value
1303-
* is written to this register to reduce the chances of error.
1304-
*/
1305-
cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET);
1321+
cdns_i2c_init(id);
13061322

13071323
ret = i2c_add_adapter(&id->adap);
13081324
if (ret < 0)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/regmap.h>
2525
#include <linux/swab.h>
2626
#include <linux/types.h>
27+
#include <linux/units.h>
2728

2829
#include "i2c-designware-core.h"
2930

@@ -350,7 +351,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
350351
*
351352
* If your hardware is free from tHD;STA issue, try this one.
352353
*/
353-
return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset;
354+
return DIV_ROUND_CLOSEST(ic_clk * tSYMBOL, MICRO) - 8 + offset;
354355
else
355356
/*
356357
* Conditional expression:
@@ -366,8 +367,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
366367
* The reason why we need to take into account "tf" here,
367368
* is the same as described in i2c_dw_scl_lcnt().
368369
*/
369-
return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000
370-
- 3 + offset;
370+
return DIV_ROUND_CLOSEST(ic_clk * (tSYMBOL + tf), MICRO) - 3 + offset;
371371
}
372372

373373
u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
@@ -383,7 +383,7 @@ u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
383383
* account the fall time of SCL signal (tf). Default tf value
384384
* should be 0.3 us, for safety.
385385
*/
386-
return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset;
386+
return DIV_ROUND_CLOSEST(ic_clk * (tLOW + tf), MICRO) - 1 + offset;
387387
}
388388

389389
int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)

drivers/i2c/busses/i2c-designware-core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117

118118
#define DW_IC_ERR_TX_ABRT 0x1
119119

120-
#define DW_IC_TAR_10BITADDR_MASTER BIT(12)
120+
#define DW_IC_TAR_10BITADDR_MASTER BIT(12)
121121

122122
#define DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH (BIT(2) | BIT(3))
123123
#define DW_IC_COMP_PARAM_1_SPEED_MODE_MASK GENMASK(3, 2)
@@ -245,7 +245,7 @@ struct dw_i2c_dev {
245245
struct clk *clk;
246246
struct clk *pclk;
247247
struct reset_control *rst;
248-
struct i2c_client *slave;
248+
struct i2c_client *slave;
249249
u32 (*get_clk_rate_khz) (struct dw_i2c_dev *dev);
250250
int cmd_err;
251251
struct i2c_msg *msgs;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
#include <linux/sched.h>
3232
#include <linux/slab.h>
3333
#include <linux/suspend.h>
34+
#include <linux/units.h>
3435

3536
#include "i2c-designware-core.h"
3637

3738
static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
3839
{
39-
return clk_get_rate(dev->clk)/1000;
40+
return clk_get_rate(dev->clk) / KILO;
4041
}
4142

4243
#ifdef CONFIG_ACPI
@@ -270,7 +271,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
270271

271272
if (!dev->sda_hold_time && t->sda_hold_ns)
272273
dev->sda_hold_time =
273-
div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
274+
DIV_S64_ROUND_CLOSEST(clk_khz * t->sda_hold_ns, MICRO);
274275
}
275276

276277
adap = &dev->adapter;

drivers/i2c/busses/i2c-highlander.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static int highlander_i2c_probe(struct platform_device *pdev)
379379
platform_set_drvdata(pdev, dev);
380380

381381
dev->irq = platform_get_irq(pdev, 0);
382-
if (iic_force_poll)
382+
if (dev->irq < 0 || iic_force_poll)
383383
dev->irq = 0;
384384

385385
if (dev->irq) {

0 commit comments

Comments
 (0)