Skip to content

Commit f8a52af

Browse files
committed
Merge tag 'i2c-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "Only driver updates for 5.19. Bigger changes are for Meson, NPCM, and R-Car, but there are also changes all over the place" * tag 'i2c-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (34 commits) i2c: meson: fix typo in comment i2c: rcar: use flags instead of atomic_xfer i2c: rcar: REP_AFTER_RD is not a persistent flag i2c: rcar: use BIT macro consistently i2c: qcom-geni: remove unnecessary conditions i2c: mt7621: Use devm_platform_get_and_ioremap_resource() i2c: rcar: refactor handling of first message i2c: rcar: avoid race condition with SMIs i2c: xiic: Correct the datatype for rx_watermark i2c: rcar: fix PM ref counts in probe error paths i2c: npcm: Handle spurious interrupts i2c: npcm: Correct register access width i2c: npcm: Add tx complete counter i2c: npcm: Fix timeout calculation i2c: npcm: Remove unused variable clk_regmap i2c: npcm: Change the way of getting GCR regmap i2c: xiic: Fix Tx Interrupt path for grouped messages i2c: xiic: Fix coding style issues i2c: xiic: return value of xiic_reinit i2c: cadence: Increase timeout per message if necessary ...
2 parents 35b51af + 3cd4030 commit f8a52af

File tree

15 files changed

+380
-238
lines changed

15 files changed

+380
-238
lines changed

Documentation/devicetree/bindings/i2c/renesas,rcar-i2c.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ properties:
4646
- renesas,i2c-r8a77980 # R-Car V3H
4747
- renesas,i2c-r8a77990 # R-Car E3
4848
- renesas,i2c-r8a77995 # R-Car D3
49-
- renesas,i2c-r8a779a0 # R-Car V3U
5049
- const: renesas,rcar-gen3-i2c # R-Car Gen3 and RZ/G2
5150

5251
- items:
5352
- enum:
53+
- renesas,i2c-r8a779a0 # R-Car V3U
5454
- renesas,i2c-r8a779f0 # R-Car S4-8
5555
- const: renesas,rcar-gen4-i2c # R-Car Gen4
5656

Documentation/i2c/writing-clients.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ driver model device node, and its I2C address.
4646
},
4747

4848
.id_table = foo_idtable,
49-
.probe = foo_probe,
49+
.probe_new = foo_probe,
5050
.remove = foo_remove,
5151
/* if device autodetection is needed: */
5252
.class = I2C_CLASS_SOMETHING,
@@ -155,8 +155,7 @@ those devices, and a remove() method to unbind.
155155

156156
::
157157

158-
static int foo_probe(struct i2c_client *client,
159-
const struct i2c_device_id *id);
158+
static int foo_probe(struct i2c_client *client);
160159
static int foo_remove(struct i2c_client *client);
161160

162161
Remember that the i2c_driver does not create those client handles. The
@@ -165,8 +164,12 @@ handle may be used during foo_probe(). If foo_probe() reports success
165164
foo_remove() returns. That binding model is used by most Linux drivers.
166165

167166
The probe function is called when an entry in the id_table name field
168-
matches the device's name. It is passed the entry that was matched so
169-
the driver knows which one in the table matched.
167+
matches the device's name. If the probe function needs that entry, it
168+
can retrieve it using
169+
170+
::
171+
172+
const struct i2c_device_id *id = i2c_match_id(foo_idtable, client);
170173

171174

172175
Device Creation

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
656656
unsigned int_addr_flag = 0;
657657
struct i2c_msg *m_start = msg;
658658
bool is_read;
659+
u8 *dma_buf = NULL;
659660

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

@@ -703,7 +704,17 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
703704
dev->msg = m_start;
704705
dev->recv_len_abort = false;
705706

707+
if (dev->use_dma) {
708+
dma_buf = i2c_get_dma_safe_msg_buf(m_start, 1);
709+
if (!dma_buf) {
710+
ret = -ENOMEM;
711+
goto out;
712+
}
713+
dev->buf = dma_buf;
714+
}
715+
706716
ret = at91_do_twi_transfer(dev);
717+
i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret);
707718

708719
ret = (ret < 0) ? ret : num;
709720
out:

drivers/i2c/busses/i2c-cadence.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static void cdns_i2c_master_reset(struct i2c_adapter *adap)
760760
static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
761761
struct i2c_adapter *adap)
762762
{
763-
unsigned long time_left;
763+
unsigned long time_left, msg_timeout;
764764
u32 reg;
765765

766766
id->p_msg = msg;
@@ -785,8 +785,16 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
785785
else
786786
cdns_i2c_msend(id);
787787

788+
/* Minimal time to execute this message */
789+
msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk);
790+
/* Plus some wiggle room */
791+
msg_timeout += msecs_to_jiffies(500);
792+
793+
if (msg_timeout < adap->timeout)
794+
msg_timeout = adap->timeout;
795+
788796
/* Wait for the signal of completion */
789-
time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout);
797+
time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout);
790798
if (time_left == 0) {
791799
cdns_i2c_master_reset(adap);
792800
dev_err(id->adap.dev.parent,

drivers/i2c/busses/i2c-davinci.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,9 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
539539

540540
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
541541

542-
ret = pm_runtime_get_sync(dev->dev);
542+
ret = pm_runtime_resume_and_get(dev->dev);
543543
if (ret < 0) {
544544
dev_err(dev->dev, "Failed to runtime_get device: %d\n", ret);
545-
pm_runtime_put_noidle(dev->dev);
546545
return ret;
547546
}
548547

@@ -821,10 +820,9 @@ static int davinci_i2c_probe(struct platform_device *pdev)
821820

822821
pm_runtime_enable(dev->dev);
823822

824-
r = pm_runtime_get_sync(dev->dev);
823+
r = pm_runtime_resume_and_get(dev->dev);
825824
if (r < 0) {
826825
dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
827-
pm_runtime_put_noidle(dev->dev);
828826
return r;
829827
}
830828

@@ -898,11 +896,9 @@ static int davinci_i2c_remove(struct platform_device *pdev)
898896

899897
i2c_del_adapter(&dev->adapter);
900898

901-
ret = pm_runtime_get_sync(&pdev->dev);
902-
if (ret < 0) {
903-
pm_runtime_put_noidle(&pdev->dev);
899+
ret = pm_runtime_resume_and_get(&pdev->dev);
900+
if (ret < 0)
904901
return ret;
905-
}
906902

907903
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
908904

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#define PSP_CMD_TIMEOUT_US (500 * USEC_PER_MSEC)
1717

1818
#define PSP_I2C_REQ_BUS_CMD 0x64
19-
#define PSP_I2C_REQ_RETRY_CNT 10
20-
#define PSP_I2C_REQ_RETRY_DELAY_US (50 * USEC_PER_MSEC)
19+
#define PSP_I2C_REQ_RETRY_CNT 400
20+
#define PSP_I2C_REQ_RETRY_DELAY_US (25 * USEC_PER_MSEC)
2121
#define PSP_I2C_REQ_STS_OK 0x0
2222
#define PSP_I2C_REQ_STS_BUS_BUSY 0x1
2323
#define PSP_I2C_REQ_STS_INV_PARAM 0x3

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ int i2c_dw_acpi_configure(struct device *device)
266266
* selected speed modes.
267267
*/
268268
i2c_dw_acpi_params(device, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt, &ss_ht);
269+
i2c_dw_acpi_params(device, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht);
269270
i2c_dw_acpi_params(device, "FPCN", &dev->fp_hcnt, &dev->fp_lcnt, &fp_ht);
270271
i2c_dw_acpi_params(device, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt, &hs_ht);
271-
i2c_dw_acpi_params(device, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht);
272272

273273
switch (t->bus_freq_hz) {
274274
case I2C_MAX_STANDARD_MODE_FREQ:

drivers/i2c/busses/i2c-meson.c

Lines changed: 85 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@
3030
#define REG_TOK_RDATA1 0x1c
3131

3232
/* Control register fields */
33-
#define REG_CTRL_START BIT(0)
34-
#define REG_CTRL_ACK_IGNORE BIT(1)
35-
#define REG_CTRL_STATUS BIT(2)
36-
#define REG_CTRL_ERROR BIT(3)
37-
#define REG_CTRL_CLKDIV GENMASK(21, 12)
38-
#define REG_CTRL_CLKDIVEXT GENMASK(29, 28)
39-
40-
#define REG_SLV_ADDR GENMASK(7, 0)
41-
#define REG_SLV_SDA_FILTER GENMASK(10, 8)
42-
#define REG_SLV_SCL_FILTER GENMASK(13, 11)
43-
#define REG_SLV_SCL_LOW GENMASK(27, 16)
44-
#define REG_SLV_SCL_LOW_EN BIT(28)
33+
#define REG_CTRL_START BIT(0)
34+
#define REG_CTRL_ACK_IGNORE BIT(1)
35+
#define REG_CTRL_STATUS BIT(2)
36+
#define REG_CTRL_ERROR BIT(3)
37+
#define REG_CTRL_CLKDIV_SHIFT 12
38+
#define REG_CTRL_CLKDIV_MASK GENMASK(21, REG_CTRL_CLKDIV_SHIFT)
39+
#define REG_CTRL_CLKDIVEXT_SHIFT 28
40+
#define REG_CTRL_CLKDIVEXT_MASK GENMASK(29, REG_CTRL_CLKDIVEXT_SHIFT)
41+
42+
#define REG_SLV_ADDR_MASK GENMASK(7, 0)
43+
#define REG_SLV_SDA_FILTER_MASK GENMASK(10, 8)
44+
#define REG_SLV_SCL_FILTER_MASK GENMASK(13, 11)
45+
#define REG_SLV_SCL_LOW_SHIFT 16
46+
#define REG_SLV_SCL_LOW_MASK GENMASK(27, REG_SLV_SCL_LOW_SHIFT)
47+
#define REG_SLV_SCL_LOW_EN BIT(28)
4548

4649
#define I2C_TIMEOUT_MS 500
4750
#define FILTER_DELAY 15
@@ -62,10 +65,6 @@ enum {
6265
STATE_WRITE,
6366
};
6467

65-
struct meson_i2c_data {
66-
unsigned char div_factor;
67-
};
68-
6968
/**
7069
* struct meson_i2c - Meson I2C device private data
7170
*
@@ -83,7 +82,7 @@ struct meson_i2c_data {
8382
* @done: Completion used to wait for transfer termination
8483
* @tokens: Sequence of tokens to be written to the device
8584
* @num_tokens: Number of tokens
86-
* @data: Pointer to the controlller's platform data
85+
* @data: Pointer to the controller's platform data
8786
*/
8887
struct meson_i2c {
8988
struct i2c_adapter adap;
@@ -106,6 +105,10 @@ struct meson_i2c {
106105
const struct meson_i2c_data *data;
107106
};
108107

108+
struct meson_i2c_data {
109+
void (*set_clk_div)(struct meson_i2c *i2c, unsigned int freq);
110+
};
111+
109112
static void meson_i2c_set_mask(struct meson_i2c *i2c, int reg, u32 mask,
110113
u32 val)
111114
{
@@ -134,26 +137,74 @@ static void meson_i2c_add_token(struct meson_i2c *i2c, int token)
134137
i2c->num_tokens++;
135138
}
136139

137-
static void meson_i2c_set_clk_div(struct meson_i2c *i2c, unsigned int freq)
140+
static void meson_gxbb_axg_i2c_set_clk_div(struct meson_i2c *i2c, unsigned int freq)
141+
{
142+
unsigned long clk_rate = clk_get_rate(i2c->clk);
143+
unsigned int div_h, div_l;
144+
145+
/* According to I2C-BUS Spec 2.1, in FAST-MODE, the minimum LOW period is 1.3uS, and
146+
* minimum HIGH is least 0.6us.
147+
* For 400000 freq, the period is 2.5us. To keep within the specs, give 40% of period to
148+
* HIGH and 60% to LOW. This means HIGH at 1.0us and LOW 1.5us.
149+
* The same applies for Fast-mode plus, where LOW is 0.5us and HIGH is 0.26us.
150+
* Duty = H/(H + L) = 2/5
151+
*/
152+
if (freq <= I2C_MAX_STANDARD_MODE_FREQ) {
153+
div_h = DIV_ROUND_UP(clk_rate, freq);
154+
div_l = DIV_ROUND_UP(div_h, 4);
155+
div_h = DIV_ROUND_UP(div_h, 2) - FILTER_DELAY;
156+
} else {
157+
div_h = DIV_ROUND_UP(clk_rate * 2, freq * 5) - FILTER_DELAY;
158+
div_l = DIV_ROUND_UP(clk_rate * 3, freq * 5 * 2);
159+
}
160+
161+
/* clock divider has 12 bits */
162+
if (div_h > GENMASK(11, 0)) {
163+
dev_err(i2c->dev, "requested bus frequency too low\n");
164+
div_h = GENMASK(11, 0);
165+
}
166+
if (div_l > GENMASK(11, 0)) {
167+
dev_err(i2c->dev, "requested bus frequency too low\n");
168+
div_l = GENMASK(11, 0);
169+
}
170+
171+
meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV_MASK,
172+
FIELD_PREP(REG_CTRL_CLKDIV_MASK, div_h & GENMASK(9, 0)));
173+
174+
meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT_MASK,
175+
FIELD_PREP(REG_CTRL_CLKDIVEXT_MASK, div_h >> 10));
176+
177+
/* set SCL low delay */
178+
meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_SCL_LOW_MASK,
179+
FIELD_PREP(REG_SLV_SCL_LOW_MASK, div_l));
180+
181+
/* Enable HIGH/LOW mode */
182+
meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_SCL_LOW_EN, REG_SLV_SCL_LOW_EN);
183+
184+
dev_dbg(i2c->dev, "%s: clk %lu, freq %u, divh %u, divl %u\n", __func__,
185+
clk_rate, freq, div_h, div_l);
186+
}
187+
188+
static void meson6_i2c_set_clk_div(struct meson_i2c *i2c, unsigned int freq)
138189
{
139190
unsigned long clk_rate = clk_get_rate(i2c->clk);
140191
unsigned int div;
141192

142193
div = DIV_ROUND_UP(clk_rate, freq);
143194
div -= FILTER_DELAY;
144-
div = DIV_ROUND_UP(div, i2c->data->div_factor);
195+
div = DIV_ROUND_UP(div, 4);
145196

146197
/* clock divider has 12 bits */
147198
if (div > GENMASK(11, 0)) {
148199
dev_err(i2c->dev, "requested bus frequency too low\n");
149200
div = GENMASK(11, 0);
150201
}
151202

152-
meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV,
153-
FIELD_PREP(REG_CTRL_CLKDIV, div & GENMASK(9, 0)));
203+
meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV_MASK,
204+
FIELD_PREP(REG_CTRL_CLKDIV_MASK, div & GENMASK(9, 0)));
154205

155-
meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT,
156-
FIELD_PREP(REG_CTRL_CLKDIVEXT, div >> 10));
206+
meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT_MASK,
207+
FIELD_PREP(REG_CTRL_CLKDIVEXT_MASK, div >> 10));
157208

158209
/* Disable HIGH/LOW mode */
159210
meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_SCL_LOW_EN, 0);
@@ -292,8 +343,8 @@ static void meson_i2c_do_start(struct meson_i2c *i2c, struct i2c_msg *msg)
292343
TOKEN_SLAVE_ADDR_WRITE;
293344

294345

295-
meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_ADDR,
296-
FIELD_PREP(REG_SLV_ADDR, msg->addr << 1));
346+
meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_ADDR_MASK,
347+
FIELD_PREP(REG_SLV_ADDR_MASK, msg->addr << 1));
297348

298349
meson_i2c_add_token(i2c, TOKEN_START);
299350
meson_i2c_add_token(i2c, token);
@@ -467,9 +518,13 @@ static int meson_i2c_probe(struct platform_device *pdev)
467518

468519
/* Disable filtering */
469520
meson_i2c_set_mask(i2c, REG_SLAVE_ADDR,
470-
REG_SLV_SDA_FILTER | REG_SLV_SCL_FILTER, 0);
521+
REG_SLV_SDA_FILTER_MASK | REG_SLV_SCL_FILTER_MASK, 0);
471522

472-
meson_i2c_set_clk_div(i2c, timings.bus_freq_hz);
523+
if (!i2c->data->set_clk_div) {
524+
clk_disable_unprepare(i2c->clk);
525+
return -EINVAL;
526+
}
527+
i2c->data->set_clk_div(i2c, timings.bus_freq_hz);
473528

474529
ret = i2c_add_adapter(&i2c->adap);
475530
if (ret < 0) {
@@ -491,15 +546,15 @@ static int meson_i2c_remove(struct platform_device *pdev)
491546
}
492547

493548
static const struct meson_i2c_data i2c_meson6_data = {
494-
.div_factor = 4,
549+
.set_clk_div = meson6_i2c_set_clk_div,
495550
};
496551

497552
static const struct meson_i2c_data i2c_gxbb_data = {
498-
.div_factor = 4,
553+
.set_clk_div = meson_gxbb_axg_i2c_set_clk_div,
499554
};
500555

501556
static const struct meson_i2c_data i2c_axg_data = {
502-
.div_factor = 3,
557+
.set_clk_div = meson_gxbb_axg_i2c_set_clk_div,
503558
};
504559

505560
static const struct of_device_id meson_i2c_match[] = {

0 commit comments

Comments
 (0)