@@ -176,10 +176,6 @@ struct imx9_lpi2c_config_s
176
176
uint8_t filtsda ; /* Glitch Filter for SDA pin */
177
177
iomux_cfg_t scl_pin ; /* Peripheral configuration for SCL as SCL */
178
178
iomux_cfg_t sda_pin ; /* Peripheral configuration for SDA as SDA */
179
- #if defined(CONFIG_I2C_RESET )
180
- gpio_pinset_t reset_scl_pin ; /* GPIO configuration for SCL as GPIO */
181
- gpio_pinset_t reset_sda_pin ; /* GPIO configuration for SDA as GPIO */
182
- #endif
183
179
uint8_t mode ; /* Master or Slave mode */
184
180
#ifndef CONFIG_I2C_POLLED
185
181
uint32_t irq ; /* Event IRQ */
@@ -338,10 +334,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c1_config =
338
334
.filtsda = CONFIG_IMX9_LPI2C1_FILTSDA ,
339
335
.scl_pin = MUX_LPI2C1_SCL ,
340
336
.sda_pin = MUX_LPI2C1_SDA ,
341
- #if defined(CONFIG_I2C_RESET )
342
- .reset_scl_pin = GPIO_LPI2C1_SCL_RESET ,
343
- .reset_sda_pin = GPIO_LPI2C1_SDA_RESET ,
344
- #endif
345
337
#ifndef CONFIG_I2C_SLAVE
346
338
.mode = LPI2C_MASTER ,
347
339
#else
@@ -386,10 +378,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c2_config =
386
378
.filtsda = CONFIG_IMX9_LPI2C2_FILTSDA ,
387
379
.scl_pin = MUX_LPI2C2_SCL ,
388
380
.sda_pin = MUX_LPI2C2_SDA ,
389
- #if defined(CONFIG_I2C_RESET )
390
- .reset_scl_pin = GPIO_LPI2C2_SCL_RESET ,
391
- .reset_sda_pin = GPIO_LPI2C2_SDA_RESET ,
392
- #endif
393
381
#ifndef CONFIG_I2C_SLAVE
394
382
.mode = LPI2C_MASTER ,
395
383
#else
@@ -434,10 +422,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c3_config =
434
422
.filtsda = CONFIG_IMX9_LPI2C3_FILTSDA ,
435
423
.scl_pin = MUX_LPI2C3_SCL ,
436
424
.sda_pin = MUX_LPI2C3_SDA ,
437
- #if defined(CONFIG_I2C_RESET )
438
- .reset_scl_pin = GPIO_LPI2C3_SCL_RESET ,
439
- .reset_sda_pin = GPIO_LPI2C3_SDA_RESET ,
440
- #endif
441
425
#ifndef CONFIG_I2C_SLAVE
442
426
.mode = LPI2C_MASTER ,
443
427
#else
@@ -482,10 +466,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c4_config =
482
466
.filtsda = CONFIG_IMX9_LPI2C4_FILTSDA ,
483
467
.scl_pin = MUX_LPI2C4_SCL ,
484
468
.sda_pin = MUX_LPI2C4_SDA ,
485
- #if defined(CONFIG_I2C_RESET )
486
- .reset_scl_pin = GPIO_LPI2C4_SCL_RESET ,
487
- .reset_sda_pin = GPIO_LPI2C4_SDA_RESET ,
488
- #endif
489
469
#ifndef CONFIG_I2C_SLAVE
490
470
.mode = LPI2C_MASTER ,
491
471
#else
@@ -530,10 +510,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c5_config =
530
510
.filtsda = CONFIG_IMX9_LPI2C5_FILTSDA ,
531
511
.scl_pin = MUX_LPI2C5_SCL ,
532
512
.sda_pin = MUX_LPI2C5_SDA ,
533
- #if defined(CONFIG_I2C_RESET )
534
- .reset_scl_pin = GPIO_LPI2C5_SCL_RESET ,
535
- .reset_sda_pin = GPIO_LPI2C5_SDA_RESET ,
536
- #endif
537
513
#ifndef CONFIG_I2C_SLAVE
538
514
.mode = LPI2C_MASTER ,
539
515
#else
@@ -578,10 +554,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c6_config =
578
554
.filtsda = CONFIG_IMX9_LPI2C6_FILTSDA ,
579
555
.scl_pin = MUX_LPI2C6_SCL ,
580
556
.sda_pin = MUX_LPI2C6_SDA ,
581
- #if defined(CONFIG_I2C_RESET )
582
- .reset_scl_pin = GPIO_LPI2C6_SCL_RESET ,
583
- .reset_sda_pin = GPIO_LPI2C6_SDA_RESET ,
584
- #endif
585
557
#ifndef CONFIG_I2C_SLAVE
586
558
.mode = LPI2C_MASTER ,
587
559
#else
@@ -626,10 +598,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c7_config =
626
598
.filtsda = CONFIG_IMX9_LPI2C7_FILTSDA ,
627
599
.scl_pin = MUX_LPI2C7_SCL ,
628
600
.sda_pin = MUX_LPI2C7_SDA ,
629
- #if defined(CONFIG_I2C_RESET )
630
- .reset_scl_pin = GPIO_LPI2C7_SCL_RESET ,
631
- .reset_sda_pin = GPIO_LPI2C7_SDA_RESET ,
632
- #endif
633
601
#ifndef CONFIG_I2C_SLAVE
634
602
.mode = LPI2C_MASTER ,
635
603
#else
@@ -674,10 +642,6 @@ static const struct imx9_lpi2c_config_s imx9_lpi2c8_config =
674
642
.filtsda = CONFIG_IMX9_LPI2C8_FILTSDA ,
675
643
.scl_pin = MUX_LPI2C8_SCL ,
676
644
.sda_pin = MUX_LPI2C8_SDA ,
677
- #if defined(CONFIG_I2C_RESET )
678
- .reset_scl_pin = GPIO_LPI2C8_SCL_RESET ,
679
- .reset_sda_pin = GPIO_LPI2C8_SDA_RESET ,
680
- #endif
681
645
#ifndef CONFIG_I2C_SLAVE
682
646
.mode = LPI2C_MASTER ,
683
647
#else
@@ -2187,11 +2151,8 @@ static int imx9_lpi2c_transfer(struct i2c_master_s *dev,
2187
2151
static int imx9_lpi2c_reset (struct i2c_master_s * dev )
2188
2152
{
2189
2153
struct imx9_lpi2c_priv_s * priv = (struct imx9_lpi2c_priv_s * )dev ;
2190
- unsigned int clock_count ;
2191
- unsigned int stretch_count ;
2192
- uint32_t scl_gpio ;
2193
- uint32_t sda_gpio ;
2194
- uint32_t frequency ;
2154
+ uint32_t status ;
2155
+ unsigned count ;
2195
2156
int ret ;
2196
2157
2197
2158
DEBUGASSERT (dev );
@@ -2208,95 +2169,42 @@ static int imx9_lpi2c_reset(struct i2c_master_s *dev)
2208
2169
return ret ;
2209
2170
}
2210
2171
2211
- ret = - EIO ;
2212
-
2213
- /* Save the current frequency */
2214
-
2215
- frequency = priv -> frequency ;
2216
-
2217
2172
/* De-init the port */
2218
2173
2219
2174
imx9_lpi2c_deinit (priv );
2220
2175
2221
- /* Use GPIO configuration to un-wedge the bus */
2222
-
2223
- imx9_iomux_gpio (priv -> config -> scl_pin , true);
2224
- imx9_iomux_gpio (priv -> config -> sda_pin , true);
2225
-
2226
- scl_gpio = priv -> config -> reset_scl_pin ;
2227
- sda_gpio = priv -> config -> reset_sda_pin ;
2176
+ /* Re-init the port */
2228
2177
2229
- imx9_config_gpio (scl_gpio );
2230
- imx9_config_gpio (sda_gpio );
2178
+ imx9_lpi2c_init (priv );
2231
2179
2232
- /* Let SDA go high */
2180
+ /* Set bus to relaxed mode - this allows clocking the bus even when it
2181
+ * is busy
2182
+ */
2233
2183
2234
- imx9_gpio_write (sda_gpio , 1 );
2184
+ imx9_lpi2c_modifyreg (priv , IMX9_LPI2C_MCFGR0_OFFSET ,
2185
+ 0 , LPI2C_MCFG0_RELAX );
2235
2186
2236
- /* Clock the bus until any slaves currently driving it let it go. */
2187
+ /* Clock the bus until it gets freed (max 10 times) */
2237
2188
2238
- clock_count = 0 ;
2239
- while (!imx9_gpio_read (sda_gpio ))
2189
+ count = 0 ;
2190
+ status = imx9_lpi2c_getstatus (priv );
2191
+ while ((status & LPI2C_MSR_BBF ) != 0 && count ++ < 10 )
2240
2192
{
2241
- /* Give up if we have tried too hard */
2242
-
2243
- if (clock_count ++ > 10 )
2244
- {
2245
- goto out ;
2246
- }
2247
-
2248
- /* Sniff to make sure that clock stretching has finished.
2249
- *
2250
- * If the bus never relaxes, the reset has failed.
2251
- */
2252
-
2253
- stretch_count = 0 ;
2254
- while (!imx9_gpio_read (scl_gpio ))
2255
- {
2256
- /* Give up if we have tried too hard */
2257
-
2258
- if (stretch_count ++ > 10 )
2259
- {
2260
- goto out ;
2261
- }
2262
-
2263
- up_udelay (10 );
2264
- }
2265
-
2266
- /* Drive SCL low */
2267
-
2268
- imx9_gpio_write (scl_gpio , 0 );
2269
- up_udelay (10 );
2270
-
2271
- /* Drive SCL high again */
2272
-
2273
- imx9_gpio_write (scl_gpio , 1 );
2274
- up_udelay (10 );
2193
+ i2cerr ("Bus %d busy!\n" , priv -> config -> clk_root - CCM_CR_LPI2C1 + 1 );
2194
+ imx9_lpi2c_sendstart (priv , 0 );
2195
+ imx9_lpi2c_sendstop (priv );
2196
+ usleep (1000 );
2197
+ status = imx9_lpi2c_getstatus (priv );
2275
2198
}
2276
2199
2277
- /* Generate a start followed by a stop to reset slave
2278
- * state machines.
2279
- */
2280
-
2281
- imx9_gpio_write (sda_gpio , 0 );
2282
- up_udelay (10 );
2283
- imx9_gpio_write (scl_gpio , 0 );
2284
- up_udelay (10 );
2285
- imx9_gpio_write (scl_gpio , 1 );
2286
- up_udelay (10 );
2287
- imx9_gpio_write (sda_gpio , 1 );
2288
- up_udelay (10 );
2200
+ /* Check that the bus is now free */
2289
2201
2290
- /* Re-init the port */
2291
-
2292
- imx9_lpi2c_init (priv );
2202
+ ret = (status & LPI2C_MSR_BBF ) == 0 ? OK : - EIO ;
2293
2203
2294
- /* Restore the frequency */
2204
+ /* Exit relaxed mode */
2295
2205
2296
- imx9_lpi2c_setclock (priv , frequency );
2297
- ret = OK ;
2298
-
2299
- out :
2206
+ imx9_lpi2c_modifyreg (priv , IMX9_LPI2C_MCFGR0_OFFSET ,
2207
+ LPI2C_MCFG0_RELAX , 0 );
2300
2208
2301
2209
/* Release the port for re-use by other clients */
2302
2210
0 commit comments