Skip to content

Commit a7a55e2

Browse files
committed
Merge tag 'i2c-for-6.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "Just two driver fixes" * tag 'i2c-for-6.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: ocores: generate stop condition after timeout in polling mode i2c: mchp-pci1xxxx: Update Timing registers
2 parents 9772f14 + f8160d3 commit a7a55e2

2 files changed

Lines changed: 49 additions & 46 deletions

File tree

drivers/i2c/busses/i2c-mchp-pci1xxxx.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
* SR_HOLD_TIME_XK_TICKS field will indicate the number of ticks of the
4949
* baud clock required to program 'Hold Time' at X KHz.
5050
*/
51-
#define SR_HOLD_TIME_100K_TICKS 133
52-
#define SR_HOLD_TIME_400K_TICKS 20
53-
#define SR_HOLD_TIME_1000K_TICKS 11
51+
#define SR_HOLD_TIME_100K_TICKS 150
52+
#define SR_HOLD_TIME_400K_TICKS 20
53+
#define SR_HOLD_TIME_1000K_TICKS 12
5454

5555
#define SMB_CORE_COMPLETION_REG_OFF3 (SMBUS_MAST_CORE_ADDR_BASE + 0x23)
5656

@@ -65,17 +65,17 @@
6565
* the baud clock required to program 'fair idle delay' at X KHz. Fair idle
6666
* delay establishes the MCTP T(IDLE_DELAY) period.
6767
*/
68-
#define FAIR_BUS_IDLE_MIN_100K_TICKS 969
69-
#define FAIR_BUS_IDLE_MIN_400K_TICKS 157
70-
#define FAIR_BUS_IDLE_MIN_1000K_TICKS 157
68+
#define FAIR_BUS_IDLE_MIN_100K_TICKS 992
69+
#define FAIR_BUS_IDLE_MIN_400K_TICKS 500
70+
#define FAIR_BUS_IDLE_MIN_1000K_TICKS 500
7171

7272
/*
7373
* FAIR_IDLE_DELAY_XK_TICKS field will indicate the number of ticks of the
7474
* baud clock required to satisfy the fairness protocol at X KHz.
7575
*/
76-
#define FAIR_IDLE_DELAY_100K_TICKS 1000
77-
#define FAIR_IDLE_DELAY_400K_TICKS 500
78-
#define FAIR_IDLE_DELAY_1000K_TICKS 500
76+
#define FAIR_IDLE_DELAY_100K_TICKS 963
77+
#define FAIR_IDLE_DELAY_400K_TICKS 156
78+
#define FAIR_IDLE_DELAY_1000K_TICKS 156
7979

8080
#define SMB_IDLE_SCALING_100K \
8181
((FAIR_IDLE_DELAY_100K_TICKS << 16) | FAIR_BUS_IDLE_MIN_100K_TICKS)
@@ -105,7 +105,7 @@
105105
*/
106106
#define BUS_CLK_100K_LOW_PERIOD_TICKS 156
107107
#define BUS_CLK_400K_LOW_PERIOD_TICKS 41
108-
#define BUS_CLK_1000K_LOW_PERIOD_TICKS 15
108+
#define BUS_CLK_1000K_LOW_PERIOD_TICKS 15
109109

110110
/*
111111
* BUS_CLK_XK_HIGH_PERIOD_TICKS field defines the number of I2C Baud Clock
@@ -131,7 +131,7 @@
131131
*/
132132
#define CLK_SYNC_100K 4
133133
#define CLK_SYNC_400K 4
134-
#define CLK_SYNC_1000K 4
134+
#define CLK_SYNC_1000K 4
135135

136136
#define SMB_CORE_DATA_TIMING_REG_OFF (SMBUS_MAST_CORE_ADDR_BASE + 0x40)
137137

@@ -142,25 +142,25 @@
142142
* determines the SCLK hold time following SDAT driven low during the first
143143
* START bit in a transfer.
144144
*/
145-
#define FIRST_START_HOLD_100K_TICKS 22
146-
#define FIRST_START_HOLD_400K_TICKS 16
147-
#define FIRST_START_HOLD_1000K_TICKS 6
145+
#define FIRST_START_HOLD_100K_TICKS 23
146+
#define FIRST_START_HOLD_400K_TICKS 8
147+
#define FIRST_START_HOLD_1000K_TICKS 12
148148

149149
/*
150150
* STOP_SETUP_XK_TICKS will indicate the number of ticks of the baud clock
151151
* required to program 'STOP_SETUP' timer at X KHz. This timer determines the
152152
* SDAT setup time from the rising edge of SCLK for a STOP condition.
153153
*/
154-
#define STOP_SETUP_100K_TICKS 157
154+
#define STOP_SETUP_100K_TICKS 150
155155
#define STOP_SETUP_400K_TICKS 20
156-
#define STOP_SETUP_1000K_TICKS 12
156+
#define STOP_SETUP_1000K_TICKS 12
157157

158158
/*
159159
* RESTART_SETUP_XK_TICKS will indicate the number of ticks of the baud clock
160160
* required to program 'RESTART_SETUP' timer at X KHz. This timer determines the
161161
* SDAT setup time from the rising edge of SCLK for a repeated START condition.
162162
*/
163-
#define RESTART_SETUP_100K_TICKS 157
163+
#define RESTART_SETUP_100K_TICKS 156
164164
#define RESTART_SETUP_400K_TICKS 20
165165
#define RESTART_SETUP_1000K_TICKS 12
166166

@@ -169,7 +169,7 @@
169169
* required to program 'DATA_HOLD' timer at X KHz. This timer determines the
170170
* SDAT hold time following SCLK driven low.
171171
*/
172-
#define DATA_HOLD_100K_TICKS 2
172+
#define DATA_HOLD_100K_TICKS 12
173173
#define DATA_HOLD_400K_TICKS 2
174174
#define DATA_HOLD_1000K_TICKS 2
175175

@@ -190,35 +190,35 @@
190190
* Bus Idle Minimum time = BUS_IDLE_MIN[7:0] x Baud_Clock_Period x
191191
* (BUS_IDLE_MIN_XK_TICKS[7] ? 4,1)
192192
*/
193-
#define BUS_IDLE_MIN_100K_TICKS 167UL
194-
#define BUS_IDLE_MIN_400K_TICKS 139UL
195-
#define BUS_IDLE_MIN_1000K_TICKS 133UL
193+
#define BUS_IDLE_MIN_100K_TICKS 36UL
194+
#define BUS_IDLE_MIN_400K_TICKS 10UL
195+
#define BUS_IDLE_MIN_1000K_TICKS 4UL
196196

197197
/*
198198
* CTRL_CUM_TIME_OUT_XK_TICKS defines SMBus Controller Cumulative Time-Out.
199199
* SMBus Controller Cumulative Time-Out duration =
200200
* CTRL_CUM_TIME_OUT_XK_TICKS[7:0] x Baud_Clock_Period x 2048
201201
*/
202-
#define CTRL_CUM_TIME_OUT_100K_TICKS 159
203-
#define CTRL_CUM_TIME_OUT_400K_TICKS 159
204-
#define CTRL_CUM_TIME_OUT_1000K_TICKS 159
202+
#define CTRL_CUM_TIME_OUT_100K_TICKS 76
203+
#define CTRL_CUM_TIME_OUT_400K_TICKS 76
204+
#define CTRL_CUM_TIME_OUT_1000K_TICKS 76
205205

206206
/*
207207
* TARGET_CUM_TIME_OUT_XK_TICKS defines SMBus Target Cumulative Time-Out duration.
208208
* SMBus Target Cumulative Time-Out duration = TARGET_CUM_TIME_OUT_XK_TICKS[7:0] x
209209
* Baud_Clock_Period x 4096
210210
*/
211-
#define TARGET_CUM_TIME_OUT_100K_TICKS 199
212-
#define TARGET_CUM_TIME_OUT_400K_TICKS 199
213-
#define TARGET_CUM_TIME_OUT_1000K_TICKS 199
211+
#define TARGET_CUM_TIME_OUT_100K_TICKS 95
212+
#define TARGET_CUM_TIME_OUT_400K_TICKS 95
213+
#define TARGET_CUM_TIME_OUT_1000K_TICKS 95
214214

215215
/*
216216
* CLOCK_HIGH_TIME_OUT_XK defines Clock High time out period.
217217
* Clock High time out period = CLOCK_HIGH_TIME_OUT_XK[7:0] x Baud_Clock_Period x 8
218218
*/
219-
#define CLOCK_HIGH_TIME_OUT_100K_TICKS 204
220-
#define CLOCK_HIGH_TIME_OUT_400K_TICKS 204
221-
#define CLOCK_HIGH_TIME_OUT_1000K_TICKS 204
219+
#define CLOCK_HIGH_TIME_OUT_100K_TICKS 97
220+
#define CLOCK_HIGH_TIME_OUT_400K_TICKS 97
221+
#define CLOCK_HIGH_TIME_OUT_1000K_TICKS 97
222222

223223
#define TO_SCALING_100K \
224224
((BUS_IDLE_MIN_100K_TICKS << 24) | (CTRL_CUM_TIME_OUT_100K_TICKS << 16) | \

drivers/i2c/busses/i2c-ocores.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,18 @@ static int ocores_poll_wait(struct ocores_i2c *i2c)
342342
* ocores_isr(), we just add our polling code around it.
343343
*
344344
* It can run in atomic context
345+
*
346+
* Return: 0 on success, -ETIMEDOUT on timeout
345347
*/
346-
static void ocores_process_polling(struct ocores_i2c *i2c)
348+
static int ocores_process_polling(struct ocores_i2c *i2c)
347349
{
348-
while (1) {
349-
irqreturn_t ret;
350-
int err;
350+
irqreturn_t ret;
351+
int err = 0;
351352

353+
while (1) {
352354
err = ocores_poll_wait(i2c);
353-
if (err) {
354-
i2c->state = STATE_ERROR;
355+
if (err)
355356
break; /* timeout */
356-
}
357357

358358
ret = ocores_isr(-1, i2c);
359359
if (ret == IRQ_NONE)
@@ -364,13 +364,15 @@ static void ocores_process_polling(struct ocores_i2c *i2c)
364364
break;
365365
}
366366
}
367+
368+
return err;
367369
}
368370

369371
static int ocores_xfer_core(struct ocores_i2c *i2c,
370372
struct i2c_msg *msgs, int num,
371373
bool polling)
372374
{
373-
int ret;
375+
int ret = 0;
374376
u8 ctrl;
375377

376378
ctrl = oc_getreg(i2c, OCI2C_CONTROL);
@@ -388,15 +390,16 @@ static int ocores_xfer_core(struct ocores_i2c *i2c,
388390
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
389391

390392
if (polling) {
391-
ocores_process_polling(i2c);
393+
ret = ocores_process_polling(i2c);
392394
} else {
393-
ret = wait_event_timeout(i2c->wait,
394-
(i2c->state == STATE_ERROR) ||
395-
(i2c->state == STATE_DONE), HZ);
396-
if (ret == 0) {
397-
ocores_process_timeout(i2c);
398-
return -ETIMEDOUT;
399-
}
395+
if (wait_event_timeout(i2c->wait,
396+
(i2c->state == STATE_ERROR) ||
397+
(i2c->state == STATE_DONE), HZ) == 0)
398+
ret = -ETIMEDOUT;
399+
}
400+
if (ret) {
401+
ocores_process_timeout(i2c);
402+
return ret;
400403
}
401404

402405
return (i2c->state == STATE_DONE) ? num : -EIO;

0 commit comments

Comments
 (0)