344
344
#define COLOR_BAR_MODE_BARS 2
345
345
#define PLL_DBG 0x0a04
346
346
347
+ enum tc_mode {
348
+ mode_dpi_to_edp = BIT (1 ) | BIT (2 ),
349
+ mode_dpi_to_dp = BIT (1 ),
350
+ mode_dsi_to_edp = BIT (0 ) | BIT (2 ),
351
+ mode_dsi_to_dp = BIT (0 ),
352
+ mode_dsi_to_dpi = BIT (0 ) | BIT (1 ),
353
+ };
354
+
347
355
static bool tc_test_pattern ;
348
356
module_param_named (test , tc_test_pattern , bool , 0644 );
349
357
@@ -2327,7 +2335,6 @@ static int tc_probe_dpi_bridge_endpoint(struct tc_data *tc)
2327
2335
if (bridge ) {
2328
2336
tc -> panel_bridge = bridge ;
2329
2337
tc -> bridge .type = DRM_MODE_CONNECTOR_DPI ;
2330
- tc -> bridge .funcs = & tc_dpi_bridge_funcs ;
2331
2338
2332
2339
return 0 ;
2333
2340
}
@@ -2360,25 +2367,18 @@ static int tc_probe_edp_bridge_endpoint(struct tc_data *tc)
2360
2367
tc -> bridge .type = DRM_MODE_CONNECTOR_DisplayPort ;
2361
2368
}
2362
2369
2363
- tc -> bridge .funcs = & tc_edp_bridge_funcs ;
2364
2370
if (tc -> hpd_pin >= 0 )
2365
2371
tc -> bridge .ops |= DRM_BRIDGE_OP_DETECT ;
2366
2372
tc -> bridge .ops |= DRM_BRIDGE_OP_EDID ;
2367
2373
2368
2374
return 0 ;
2369
2375
}
2370
2376
2371
- static int tc_probe_bridge_endpoint (struct tc_data * tc )
2377
+ static enum tc_mode tc_probe_get_mode (struct device * dev )
2372
2378
{
2373
- struct device * dev = tc -> dev ;
2374
2379
struct of_endpoint endpoint ;
2375
2380
struct device_node * node = NULL ;
2376
- const u8 mode_dpi_to_edp = BIT (1 ) | BIT (2 );
2377
- const u8 mode_dpi_to_dp = BIT (1 );
2378
- const u8 mode_dsi_to_edp = BIT (0 ) | BIT (2 );
2379
- const u8 mode_dsi_to_dp = BIT (0 );
2380
- const u8 mode_dsi_to_dpi = BIT (0 ) | BIT (1 );
2381
- u8 mode = 0 ;
2381
+ enum tc_mode mode = 0 ;
2382
2382
2383
2383
/*
2384
2384
* Determine bridge configuration.
@@ -2401,7 +2401,27 @@ static int tc_probe_bridge_endpoint(struct tc_data *tc)
2401
2401
return - EINVAL ;
2402
2402
}
2403
2403
mode |= BIT (endpoint .port );
2404
+ }
2405
+
2406
+ if (mode != mode_dpi_to_edp &&
2407
+ mode != mode_dpi_to_dp &&
2408
+ mode != mode_dsi_to_dpi &&
2409
+ mode != mode_dsi_to_edp &&
2410
+ mode != mode_dsi_to_dp ) {
2411
+ dev_warn (dev , "Invalid mode (0x%x) is not supported!\n" , mode );
2412
+ return - EINVAL ;
2413
+ }
2414
+
2415
+ return mode ;
2416
+ }
2404
2417
2418
+ static int tc_probe_bridge_endpoint (struct tc_data * tc , enum tc_mode mode )
2419
+ {
2420
+ struct device * dev = tc -> dev ;
2421
+ struct of_endpoint endpoint ;
2422
+ struct device_node * node = NULL ;
2423
+
2424
+ for_each_endpoint_of_node (dev -> of_node , node ) {
2405
2425
if (endpoint .port == 2 ) {
2406
2426
of_property_read_u8_array (node , "toshiba,pre-emphasis" ,
2407
2427
tc -> pre_emphasis ,
@@ -2427,24 +2447,28 @@ static int tc_probe_bridge_endpoint(struct tc_data *tc)
2427
2447
return tc_probe_edp_bridge_endpoint (tc );
2428
2448
}
2429
2449
2430
- dev_warn (dev , "Invalid mode (0x%x) is not supported!\n" , mode );
2431
-
2450
+ /* Should never happen, mode was validated by tc_probe_get_mode() */
2432
2451
return - EINVAL ;
2433
2452
}
2434
2453
2435
2454
static int tc_probe (struct i2c_client * client )
2436
2455
{
2437
2456
struct device * dev = & client -> dev ;
2457
+ const struct drm_bridge_funcs * funcs ;
2438
2458
struct tc_data * tc ;
2459
+ int mode ;
2439
2460
int ret ;
2440
2461
2441
- tc = devm_kzalloc (dev , sizeof (* tc ), GFP_KERNEL );
2442
- if (!tc )
2443
- return - ENOMEM ;
2462
+ mode = tc_probe_get_mode (dev );
2463
+ funcs = (mode == mode_dsi_to_dpi ) ? & tc_dpi_bridge_funcs : & tc_edp_bridge_funcs ;
2464
+
2465
+ tc = devm_drm_bridge_alloc (dev , struct tc_data , bridge , funcs );
2466
+ if (IS_ERR (tc ))
2467
+ return PTR_ERR (tc );
2444
2468
2445
2469
tc -> dev = dev ;
2446
2470
2447
- ret = tc_probe_bridge_endpoint (tc );
2471
+ ret = tc_probe_bridge_endpoint (tc , mode );
2448
2472
if (ret )
2449
2473
return ret ;
2450
2474
0 commit comments