@@ -2160,7 +2160,11 @@ static bool rt5640_jack_inserted(struct snd_soc_component *component)
2160
2160
struct rt5640_priv * rt5640 = snd_soc_component_get_drvdata (component );
2161
2161
int val ;
2162
2162
2163
- val = snd_soc_component_read (component , RT5640_INT_IRQ_ST );
2163
+ if (rt5640 -> jd_gpio )
2164
+ val = gpiod_get_value (rt5640 -> jd_gpio ) ? RT5640_JD_STATUS : 0 ;
2165
+ else
2166
+ val = snd_soc_component_read (component , RT5640_INT_IRQ_ST );
2167
+
2164
2168
dev_dbg (component -> dev , "irq status %#04x\n" , val );
2165
2169
2166
2170
if (rt5640 -> jd_inverted )
@@ -2395,6 +2399,16 @@ static irqreturn_t rt5640_irq(int irq, void *data)
2395
2399
return IRQ_HANDLED ;
2396
2400
}
2397
2401
2402
+ static irqreturn_t rt5640_jd_gpio_irq (int irq , void * data )
2403
+ {
2404
+ struct rt5640_priv * rt5640 = data ;
2405
+
2406
+ queue_delayed_work (system_long_wq , & rt5640 -> jack_work ,
2407
+ msecs_to_jiffies (JACK_SETTLE_TIME ));
2408
+
2409
+ return IRQ_HANDLED ;
2410
+ }
2411
+
2398
2412
static void rt5640_cancel_work (void * data )
2399
2413
{
2400
2414
struct rt5640_priv * rt5640 = data ;
@@ -2439,7 +2453,12 @@ static void rt5640_disable_jack_detect(struct snd_soc_component *component)
2439
2453
if (!rt5640 -> jack )
2440
2454
return ;
2441
2455
2442
- free_irq (rt5640 -> irq , rt5640 );
2456
+ if (rt5640 -> jd_gpio_irq_requested )
2457
+ free_irq (rt5640 -> jd_gpio_irq , rt5640 );
2458
+
2459
+ if (rt5640 -> irq_requested )
2460
+ free_irq (rt5640 -> irq , rt5640 );
2461
+
2443
2462
rt5640_cancel_work (rt5640 );
2444
2463
2445
2464
if (rt5640 -> jack -> status & SND_JACK_MICROPHONE ) {
@@ -2448,6 +2467,9 @@ static void rt5640_disable_jack_detect(struct snd_soc_component *component)
2448
2467
snd_soc_jack_report (rt5640 -> jack , 0 , SND_JACK_BTN_0 );
2449
2468
}
2450
2469
2470
+ rt5640 -> jd_gpio_irq_requested = false;
2471
+ rt5640 -> irq_requested = false;
2472
+ rt5640 -> jd_gpio = NULL ;
2451
2473
rt5640 -> jack = NULL ;
2452
2474
}
2453
2475
@@ -2500,16 +2522,31 @@ static void rt5640_enable_jack_detect(struct snd_soc_component *component,
2500
2522
if (jack_data && jack_data -> codec_irq_override )
2501
2523
rt5640 -> irq = jack_data -> codec_irq_override ;
2502
2524
2525
+ if (jack_data && jack_data -> jd_gpio ) {
2526
+ rt5640 -> jd_gpio = jack_data -> jd_gpio ;
2527
+ rt5640 -> jd_gpio_irq = gpiod_to_irq (rt5640 -> jd_gpio );
2528
+
2529
+ ret = request_irq (rt5640 -> jd_gpio_irq , rt5640_jd_gpio_irq ,
2530
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING ,
2531
+ "rt5640-jd-gpio" , rt5640 );
2532
+ if (ret ) {
2533
+ dev_warn (component -> dev , "Failed to request jd GPIO IRQ %d: %d\n" ,
2534
+ rt5640 -> jd_gpio_irq , ret );
2535
+ rt5640_disable_jack_detect (component );
2536
+ return ;
2537
+ }
2538
+ rt5640 -> jd_gpio_irq_requested = true;
2539
+ }
2540
+
2503
2541
ret = request_irq (rt5640 -> irq , rt5640_irq ,
2504
2542
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT ,
2505
2543
"rt5640" , rt5640 );
2506
2544
if (ret ) {
2507
2545
dev_warn (component -> dev , "Failed to reguest IRQ %d: %d\n" , rt5640 -> irq , ret );
2508
- rt5640 -> irq = - ENXIO ;
2509
- /* Undo above settings */
2510
2546
rt5640_disable_jack_detect (component );
2511
2547
return ;
2512
2548
}
2549
+ rt5640 -> irq_requested = true;
2513
2550
2514
2551
/* sync initial jack state */
2515
2552
queue_delayed_work (system_long_wq , & rt5640 -> jack_work , 0 );
0 commit comments