hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/bridge/analogix/analogix-anx6345.c
....@@ -1,52 +1,48 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+/* SPDX-License-Identifier: GPL-2.0-only */
22 /*
3
- * Copyright(c) Icenowy Zheng <icenowy@aosc.io>
4
- * Based on analogix-anx6345.c, which is:
5
- * Copyright(c) 2016, Analogix Semiconductor.
3
+ * Copyright(c) 2016, Analogix Semiconductor.
4
+ * Copyright(c) 2017, Icenowy Zheng <icenowy@aosc.io>
5
+ *
6
+ * Based on anx7808 driver obtained from chromeos with copyright:
7
+ * Copyright(c) 2013, Google Inc.
68 */
79 #include <linux/delay.h>
810 #include <linux/err.h>
9
-#include <linux/interrupt.h>
11
+#include <linux/gpio/consumer.h>
1012 #include <linux/i2c.h>
13
+#include <linux/interrupt.h>
1114 #include <linux/kernel.h>
1215 #include <linux/module.h>
13
-#include <linux/of_gpio.h>
1416 #include <linux/of_platform.h>
1517 #include <linux/regmap.h>
16
-#include <linux/types.h>
17
-#include <linux/gpio/consumer.h>
1818 #include <linux/regulator/consumer.h>
19
+#include <linux/types.h>
1920
20
-#include <drm/drmP.h>
2121 #include <drm/drm_atomic_helper.h>
22
+#include <drm/drm_bridge.h>
2223 #include <drm/drm_crtc.h>
2324 #include <drm/drm_crtc_helper.h>
2425 #include <drm/drm_dp_helper.h>
2526 #include <drm/drm_edid.h>
27
+#include <drm/drm_of.h>
28
+#include <drm/drm_panel.h>
29
+#include <drm/drm_print.h>
30
+#include <drm/drm_probe_helper.h>
2631
2732 #include "analogix-i2c-dptx.h"
2833 #include "analogix-i2c-txcommon.h"
2934
30
-#define I2C_NUM_ADDRESSES 2
31
-#define I2C_IDX_DPTX 0
32
-#define I2C_IDX_TXCOM 1
33
-
34
-#define XTAL_CLK 270 /* 27M */
35
-
3635 #define POLL_DELAY 50000 /* us */
3736 #define POLL_TIMEOUT 5000000 /* us */
3837
39
-static const u8 anx6345_i2c_addresses[] = {
40
- [I2C_IDX_DPTX] = ANALOGIX_I2C_DPTX,
41
- [I2C_IDX_TXCOM] = ANALOGIX_I2C_TXCOMMON,
42
-};
38
+#define I2C_IDX_DPTX 0
39
+#define I2C_IDX_TXCOM 1
4340
44
-struct anx6345_platform_data {
45
- struct regulator *dvdd12;
46
- struct regulator *dvdd25;
47
- struct regulator *vcc_panel;
48
- struct gpio_desc *gpiod_reset;
41
+static const u8 anx6345_i2c_addresses[] = {
42
+ [I2C_IDX_DPTX] = 0x70,
43
+ [I2C_IDX_TXCOM] = 0x72,
4944 };
45
+#define I2C_NUM_ADDRESSES ARRAY_SIZE(anx6345_i2c_addresses)
5046
5147 struct anx6345 {
5248 struct drm_dp_aux aux;
....@@ -54,13 +50,13 @@
5450 struct i2c_client *client;
5551 struct edid *edid;
5652 struct drm_connector connector;
57
- struct drm_dp_link link;
58
- struct anx6345_platform_data pdata;
59
- struct mutex lock;
53
+ struct drm_panel *panel;
54
+ struct regulator *dvdd12;
55
+ struct regulator *dvdd25;
56
+ struct gpio_desc *gpiod_reset;
57
+ struct mutex lock; /* protect EDID access */
6058
61
- /*
62
- * I2C Slave addresses of ANX6345 are mapped as DPTX and SYS
63
- */
59
+ /* I2C Slave addresses of ANX6345 are mapped as DPTX and SYS */
6460 struct i2c_client *i2c_clients[I2C_NUM_ADDRESSES];
6561 struct regmap *map[I2C_NUM_ADDRESSES];
6662
....@@ -95,13 +91,13 @@
9591 {
9692 struct anx6345 *anx6345 = container_of(aux, struct anx6345, aux);
9793
98
- return anx_aux_transfer(anx6345->map[I2C_IDX_DPTX], msg);
94
+ return anx_dp_aux_transfer(anx6345->map[I2C_IDX_DPTX], msg);
9995 }
10096
10197 static int anx6345_dp_link_training(struct anx6345 *anx6345)
10298 {
10399 unsigned int value;
104
- u8 dp_bw;
100
+ u8 dp_bw, dpcd[2];
105101 int err;
106102
107103 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
....@@ -148,18 +144,34 @@
148144 if (err)
149145 return err;
150146
151
- /* Check link capabilities */
152
- err = drm_dp_link_probe(&anx6345->aux, &anx6345->link);
153
- if (err < 0) {
154
- DRM_ERROR("Failed to probe link capabilities: %d\n", err);
155
- return err;
156
- }
147
+ /*
148
+ * Power up the sink (DP_SET_POWER register is only available on DPCD
149
+ * v1.1 and later).
150
+ */
151
+ if (anx6345->dpcd[DP_DPCD_REV] >= 0x11) {
152
+ err = drm_dp_dpcd_readb(&anx6345->aux, DP_SET_POWER, &dpcd[0]);
153
+ if (err < 0) {
154
+ DRM_ERROR("Failed to read DP_SET_POWER register: %d\n",
155
+ err);
156
+ return err;
157
+ }
157158
158
- /* Power up the sink */
159
- err = drm_dp_link_power_up(&anx6345->aux, &anx6345->link);
160
- if (err < 0) {
161
- DRM_ERROR("Failed to power up DisplayPort link: %d\n", err);
162
- return err;
159
+ dpcd[0] &= ~DP_SET_POWER_MASK;
160
+ dpcd[0] |= DP_SET_POWER_D0;
161
+
162
+ err = drm_dp_dpcd_writeb(&anx6345->aux, DP_SET_POWER, dpcd[0]);
163
+ if (err < 0) {
164
+ DRM_ERROR("Failed to power up DisplayPort link: %d\n",
165
+ err);
166
+ return err;
167
+ }
168
+
169
+ /*
170
+ * According to the DP 1.1 specification, a "Sink Device must
171
+ * exit the power saving state within 1 ms" (Section 2.5.3.1,
172
+ * Table 5-52, "Sink Control Field" (register 0x600).
173
+ */
174
+ usleep_range(1000, 2000);
163175 }
164176
165177 /* Possibly enable downspread on the sink */
....@@ -198,20 +210,27 @@
198210 if (err)
199211 return err;
200212
201
- value = drm_dp_link_rate_to_bw_code(anx6345->link.rate);
213
+ dpcd[0] = dp_bw;
202214 err = regmap_write(anx6345->map[I2C_IDX_DPTX],
203
- SP_DP_MAIN_LINK_BW_SET_REG, value);
215
+ SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]);
204216 if (err)
205217 return err;
206218
219
+ dpcd[1] = drm_dp_max_lane_count(anx6345->dpcd);
220
+
207221 err = regmap_write(anx6345->map[I2C_IDX_DPTX],
208
- SP_DP_LANE_COUNT_SET_REG, anx6345->link.num_lanes);
222
+ SP_DP_LANE_COUNT_SET_REG, dpcd[1]);
209223 if (err)
210224 return err;
211225
212
- err = drm_dp_link_configure(&anx6345->aux, &anx6345->link);
226
+ if (drm_dp_enhanced_frame_cap(anx6345->dpcd))
227
+ dpcd[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
228
+
229
+ err = drm_dp_dpcd_write(&anx6345->aux, DP_LINK_BW_SET, dpcd,
230
+ sizeof(dpcd));
231
+
213232 if (err < 0) {
214
- DRM_ERROR("Failed to configure DisplayPort link: %d\n", err);
233
+ DRM_ERROR("Failed to configure link: %d\n", err);
215234 return err;
216235 }
217236
....@@ -221,40 +240,19 @@
221240 if (err)
222241 return err;
223242
224
- err = regmap_read_poll_timeout(anx6345->map[I2C_IDX_DPTX],
243
+ return regmap_read_poll_timeout(anx6345->map[I2C_IDX_DPTX],
225244 SP_DP_LT_CTRL_REG,
226245 value, !(value & SP_DP_LT_INPROGRESS),
227246 POLL_DELAY, POLL_TIMEOUT);
228
- if (err)
229
- return err;
230
-
231
- return 0;
232247 }
233248
234249 static int anx6345_tx_initialization(struct anx6345 *anx6345)
235250 {
236
- struct drm_display_info *di = &anx6345->connector.display_info;
237251 int err, i;
238
- u32 color_depth;
239252
240
- switch (di->bpc) {
241
- case 12:
242
- color_depth = SP_IN_BPC_12BIT;
243
- break;
244
- case 10:
245
- color_depth = SP_IN_BPC_10BIT;
246
- break;
247
- case 6:
248
- color_depth = SP_IN_BPC_6BIT;
249
- break;
250
- case 8:
251
- default:
252
- color_depth = SP_IN_BPC_8BIT;
253
- break;
254
- }
255
-
253
+ /* FIXME: colordepth is hardcoded for now */
256254 err = regmap_write(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL2_REG,
257
- color_depth << SP_IN_BPC_SHIFT);
255
+ SP_IN_BPC_6BIT << SP_IN_BPC_SHIFT);
258256 if (err)
259257 return err;
260258
....@@ -299,116 +297,81 @@
299297 if (err)
300298 return err;
301299
302
- err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
300
+ return anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
303301 SP_RESET_CTRL2_REG, SP_AUX_RST);
304
- if (err)
305
- return err;
306
-
307
- err = anx6345_dp_link_training(anx6345);
308
- if (err)
309
- return err;
310
-
311
- return 0;
312302 }
313303
314304 static void anx6345_poweron(struct anx6345 *anx6345)
315305 {
316
- struct anx6345_platform_data *pdata = &anx6345->pdata;
317306 int err;
318
- u32 idl;
319307
320
- if (WARN_ON(anx6345->powered))
321
- return;
308
+ /* Ensure reset is asserted before starting power on sequence */
309
+ gpiod_set_value_cansleep(anx6345->gpiod_reset, 1);
310
+ usleep_range(1000, 2000);
322311
323
- if (pdata->dvdd12) {
324
- err = regulator_enable(pdata->dvdd12);
325
- if (err) {
326
- DRM_ERROR("Failed to enable DVDD12 regulator: %d\n",
327
- err);
328
- return;
329
- }
330
-
331
- usleep_range(1000, 2000);
332
- }
333
-
334
- if (pdata->dvdd25) {
335
- err = regulator_enable(pdata->dvdd25);
336
- if (err) {
337
- DRM_ERROR("Failed to enable DVDD25 regulator: %d\n",
338
- err);
339
- return;
340
- }
341
-
342
- usleep_range(5000, 10000);
343
- }
344
-
345
- if (pdata->vcc_panel) {
346
- err = regulator_enable(pdata->vcc_panel);
347
- if (err) {
348
- DRM_ERROR("Failed to enable panel regulator: %d\n",
349
- err);
350
- return;
351
- }
352
- }
353
-
354
- err = regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDL_REG, &idl);
312
+ err = regulator_enable(anx6345->dvdd12);
355313 if (err) {
356
- gpiod_direction_output(pdata->gpiod_reset, 1);
357
- usleep_range(1000, 2000);
358
-
359
- gpiod_direction_output(pdata->gpiod_reset, 0);
314
+ DRM_ERROR("Failed to enable dvdd12 regulator: %d\n",
315
+ err);
316
+ return;
360317 }
318
+
319
+ /* T1 - delay between VDD12 and VDD25 should be 0-2ms */
320
+ usleep_range(1000, 2000);
321
+
322
+ err = regulator_enable(anx6345->dvdd25);
323
+ if (err) {
324
+ DRM_ERROR("Failed to enable dvdd25 regulator: %d\n",
325
+ err);
326
+ return;
327
+ }
328
+
329
+ /* T2 - delay between RESETN and all power rail stable,
330
+ * should be 2-5ms
331
+ */
332
+ usleep_range(2000, 5000);
333
+
334
+ gpiod_set_value_cansleep(anx6345->gpiod_reset, 0);
361335
362336 /* Power on registers module */
363337 anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG,
364
- SP_HDCP_PD | SP_AUDIO_PD);
338
+ SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD | SP_LINK_PD);
365339 anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG,
366340 SP_REGISTER_PD | SP_TOTAL_PD);
341
+
342
+ if (anx6345->panel)
343
+ drm_panel_prepare(anx6345->panel);
367344
368345 anx6345->powered = true;
369346 }
370347
371348 static void anx6345_poweroff(struct anx6345 *anx6345)
372349 {
373
- struct anx6345_platform_data *pdata = &anx6345->pdata;
374350 int err;
375351
376
- if (WARN_ON(!anx6345->powered))
377
- return;
378
-
379
- gpiod_set_value_cansleep(pdata->gpiod_reset, 1);
352
+ gpiod_set_value_cansleep(anx6345->gpiod_reset, 1);
380353 usleep_range(1000, 2000);
381354
382
- if (pdata->vcc_panel) {
383
- err = regulator_disable(pdata->vcc_panel);
384
- if (err) {
385
- DRM_ERROR("Failed to disable panel regulator: %d\n",
386
- err);
387
- return;
388
- }
355
+ if (anx6345->panel)
356
+ drm_panel_unprepare(anx6345->panel);
357
+
358
+ err = regulator_disable(anx6345->dvdd25);
359
+ if (err) {
360
+ DRM_ERROR("Failed to disable dvdd25 regulator: %d\n",
361
+ err);
362
+ return;
389363 }
390364
391
- if (pdata->dvdd25) {
392
- err = regulator_disable(pdata->dvdd25);
393
- if (err) {
394
- DRM_ERROR("Failed to disable DVDD25 regulator: %d\n",
395
- err);
396
- return;
397
- }
365
+ usleep_range(5000, 10000);
398366
399
- usleep_range(5000, 10000);
367
+ err = regulator_disable(anx6345->dvdd12);
368
+ if (err) {
369
+ DRM_ERROR("Failed to disable dvdd12 regulator: %d\n",
370
+ err);
371
+ return;
400372 }
401373
402
- if (pdata->dvdd12) {
403
- err = regulator_disable(pdata->dvdd12);
404
- if (err) {
405
- DRM_ERROR("Failed to disable DVDD12 regulator: %d\n",
406
- err);
407
- return;
408
- }
409
-
410
- usleep_range(1000, 2000);
411
- }
374
+ usleep_range(1000, 2000);
412375
413376 anx6345->powered = false;
414377 }
....@@ -422,13 +385,21 @@
422385
423386 /* Power on needed modules */
424387 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
425
- SP_POWERDOWN_CTRL_REG,
426
- SP_VIDEO_PD | SP_LINK_PD);
388
+ SP_POWERDOWN_CTRL_REG,
389
+ SP_VIDEO_PD | SP_LINK_PD);
427390
428391 err = anx6345_tx_initialization(anx6345);
429392 if (err) {
430
- DRM_ERROR("Failed transmitter initialization: %d\n", err);
431
- goto err_poweroff;
393
+ DRM_ERROR("Failed eDP transmitter initialization: %d\n", err);
394
+ anx6345_poweroff(anx6345);
395
+ return err;
396
+ }
397
+
398
+ err = anx6345_dp_link_training(anx6345);
399
+ if (err) {
400
+ DRM_ERROR("Failed link training: %d\n", err);
401
+ anx6345_poweroff(anx6345);
402
+ return err;
432403 }
433404
434405 /*
....@@ -438,44 +409,6 @@
438409 usleep_range(10000, 15000);
439410
440411 return 0;
441
-
442
-err_poweroff:
443
- DRM_ERROR("Failed DisplayPort transmitter initialization: %d\n", err);
444
- anx6345_poweroff(anx6345);
445
-
446
- return err;
447
-}
448
-
449
-static int anx6345_init_pdata(struct anx6345 *anx6345)
450
-{
451
- struct anx6345_platform_data *pdata = &anx6345->pdata;
452
- struct device *dev = &anx6345->client->dev;
453
-
454
- /* 1.2V digital core power regulator */
455
- pdata->dvdd12 = devm_regulator_get(dev, "dvdd12");
456
- if (IS_ERR(pdata->dvdd12)) {
457
- DRM_ERROR("DVDD12 regulator not found\n");
458
- return PTR_ERR(pdata->dvdd12);
459
- }
460
-
461
- /* 2.5V digital core power regulator */
462
- pdata->dvdd25 = devm_regulator_get(dev, "dvdd25");
463
- if (IS_ERR(pdata->dvdd25)) {
464
- DRM_ERROR("DVDD25 regulator not found\n");
465
- return PTR_ERR(pdata->dvdd25);
466
- }
467
-
468
- /* panel power regulator */
469
- pdata->vcc_panel = devm_regulator_get(dev, "panel");
470
- if (IS_ERR(pdata->vcc_panel)) {
471
- DRM_ERROR("panel regulator not found\n");
472
- return PTR_ERR(pdata->vcc_panel);
473
- }
474
-
475
- /* GPIO for chip reset */
476
- pdata->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
477
-
478
- return PTR_ERR_OR_ZERO(pdata->gpiod_reset);
479412 }
480413
481414 static int anx6345_config_dp_output(struct anx6345 *anx6345)
....@@ -494,13 +427,9 @@
494427 return err;
495428
496429 /* Force stream valid */
497
- err = anx6345_set_bits(anx6345->map[I2C_IDX_DPTX],
430
+ return anx6345_set_bits(anx6345->map[I2C_IDX_DPTX],
498431 SP_DP_SYSTEM_CTRL_BASE + 3,
499432 SP_STRM_FORCE | SP_STRM_CTRL);
500
- if (err)
501
- return err;
502
-
503
- return 0;
504433 }
505434
506435 static int anx6345_get_downstream_info(struct anx6345 *anx6345)
....@@ -522,96 +451,83 @@
522451 return 0;
523452 }
524453
525
-static int anx6345_probe_edid_from_of(struct anx6345 *anx6345)
526
-{
527
- const u8 *edidp;
528
- int len;
529
-
530
- if (!anx6345->bridge.of_node)
531
- return -ENODEV;
532
-
533
- edidp = of_get_property(anx6345->bridge.of_node, "edid", &len);
534
- if (!edidp || len != EDID_LENGTH)
535
- return -EINVAL;
536
-
537
- anx6345->edid = devm_kmemdup(&anx6345->client->dev, edidp,
538
- len, GFP_KERNEL);
539
-
540
- if (!anx6345->edid)
541
- return -ENOMEM;
542
-
543
- return 0;
544
-}
545
-
546454 static int anx6345_get_modes(struct drm_connector *connector)
547455 {
548456 struct anx6345 *anx6345 = connector_to_anx6345(connector);
549457 int err, num_modes = 0;
550
-
551
- if (WARN_ON(!anx6345->powered))
552
- return 0;
553
-
554
- if (anx6345->edid)
555
- return drm_add_edid_modes(connector, anx6345->edid);
458
+ bool power_off = false;
556459
557460 mutex_lock(&anx6345->lock);
558461
559
- err = anx6345_get_downstream_info(anx6345);
560
- if (err) {
561
- DRM_ERROR("Failed to get downstream info: %d\n", err);
562
- goto unlock;
563
- }
564
-
565
- anx6345->edid = drm_get_edid(connector, &anx6345->aux.ddc);
566
- if (!anx6345->edid)
567
- DRM_ERROR("Failed to read EDID from panel\n");
568
-
569462 if (!anx6345->edid) {
570
- err = anx6345_probe_edid_from_of(anx6345);
463
+ if (!anx6345->powered) {
464
+ anx6345_poweron(anx6345);
465
+ power_off = true;
466
+ }
467
+
468
+ err = anx6345_get_downstream_info(anx6345);
571469 if (err) {
572
- DRM_ERROR("Failed to probe EDID from device tree\n");
470
+ DRM_ERROR("Failed to get downstream info: %d\n", err);
471
+ goto unlock;
472
+ }
473
+
474
+ anx6345->edid = drm_get_edid(connector, &anx6345->aux.ddc);
475
+ if (!anx6345->edid)
476
+ DRM_ERROR("Failed to read EDID from panel\n");
477
+
478
+ err = drm_connector_update_edid_property(connector,
479
+ anx6345->edid);
480
+ if (err) {
481
+ DRM_ERROR("Failed to update EDID property: %d\n", err);
573482 goto unlock;
574483 }
575484 }
576485
577
- err = drm_mode_connector_update_edid_property(connector, anx6345->edid);
578
- if (err) {
579
- DRM_ERROR("Failed to update EDID property: %d\n", err);
580
- goto unlock;
581
- }
486
+ num_modes += drm_add_edid_modes(connector, anx6345->edid);
582487
583
- num_modes = drm_add_edid_modes(connector, anx6345->edid);
488
+ /* Driver currently supports only 6bpc */
489
+ connector->display_info.bpc = 6;
584490
585491 unlock:
492
+ if (power_off)
493
+ anx6345_poweroff(anx6345);
494
+
586495 mutex_unlock(&anx6345->lock);
496
+
497
+ if (!num_modes && anx6345->panel)
498
+ num_modes += drm_panel_get_modes(anx6345->panel, connector);
587499
588500 return num_modes;
589501 }
590502
591503 static const struct drm_connector_helper_funcs anx6345_connector_helper_funcs = {
592504 .get_modes = anx6345_get_modes,
593
- .best_encoder = drm_atomic_helper_best_encoder,
594505 };
595506
596
-static enum drm_connector_status anx6345_detect(struct drm_connector *connector,
597
- bool force)
507
+static void
508
+anx6345_connector_destroy(struct drm_connector *connector)
598509 {
599
- return connector_status_connected;
510
+ drm_connector_cleanup(connector);
600511 }
601512
602513 static const struct drm_connector_funcs anx6345_connector_funcs = {
603514 .fill_modes = drm_helper_probe_single_connector_modes,
604
- .detect = anx6345_detect,
605
- .destroy = drm_connector_cleanup,
515
+ .destroy = anx6345_connector_destroy,
606516 .reset = drm_atomic_helper_connector_reset,
607517 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
608518 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
609519 };
610520
611
-static int anx6345_bridge_attach(struct drm_bridge *bridge)
521
+static int anx6345_bridge_attach(struct drm_bridge *bridge,
522
+ enum drm_bridge_attach_flags flags)
612523 {
613524 struct anx6345 *anx6345 = bridge_to_anx6345(bridge);
614525 int err;
526
+
527
+ if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
528
+ DRM_ERROR("Fix bridge driver to make connector optional!");
529
+ return -EINVAL;
530
+ }
615531
616532 if (!bridge->encoder) {
617533 DRM_ERROR("Parent encoder object not found");
....@@ -640,11 +556,16 @@
640556 drm_connector_helper_add(&anx6345->connector,
641557 &anx6345_connector_helper_funcs);
642558
643
- anx6345->connector.port = anx6345->client->dev.of_node;
559
+ err = drm_connector_register(&anx6345->connector);
560
+ if (err) {
561
+ DRM_ERROR("Failed to register connector: %d\n", err);
562
+ return err;
563
+ }
564
+
644565 anx6345->connector.polled = DRM_CONNECTOR_POLL_HPD;
645566
646
- err = drm_mode_connector_attach_encoder(&anx6345->connector,
647
- bridge->encoder);
567
+ err = drm_connector_attach_encoder(&anx6345->connector,
568
+ bridge->encoder);
648569 if (err) {
649570 DRM_ERROR("Failed to link up connector to encoder: %d\n", err);
650571 return err;
....@@ -653,18 +574,19 @@
653574 return 0;
654575 }
655576
656
-static bool anx6345_bridge_mode_fixup(struct drm_bridge *bridge,
657
- const struct drm_display_mode *mode,
658
- struct drm_display_mode *adjusted_mode)
577
+static enum drm_mode_status
578
+anx6345_bridge_mode_valid(struct drm_bridge *bridge,
579
+ const struct drm_display_info *info,
580
+ const struct drm_display_mode *mode)
659581 {
660582 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
661
- return false;
583
+ return MODE_NO_INTERLACE;
662584
663585 /* Max 1200p at 5.4 Ghz, one lane */
664586 if (mode->clock > 154000)
665
- return false;
587
+ return MODE_CLOCK_HIGH;
666588
667
- return true;
589
+ return MODE_OK;
668590 }
669591
670592 static void anx6345_bridge_disable(struct drm_bridge *bridge)
....@@ -674,22 +596,20 @@
674596 /* Power off all modules except configuration registers access */
675597 anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG,
676598 SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD | SP_LINK_PD);
677
-}
599
+ if (anx6345->panel)
600
+ drm_panel_disable(anx6345->panel);
678601
679
-static void anx6345_bridge_mode_set(struct drm_bridge *bridge,
680
- struct drm_display_mode *mode,
681
- struct drm_display_mode *adjusted_mode)
682
-{
683
- struct anx6345 *anx6345 = bridge_to_anx6345(bridge);
684
-
685
- if (WARN_ON(!anx6345->powered))
686
- return;
602
+ if (anx6345->powered)
603
+ anx6345_poweroff(anx6345);
687604 }
688605
689606 static void anx6345_bridge_enable(struct drm_bridge *bridge)
690607 {
691608 struct anx6345 *anx6345 = bridge_to_anx6345(bridge);
692609 int err;
610
+
611
+ if (anx6345->panel)
612
+ drm_panel_enable(anx6345->panel);
693613
694614 err = anx6345_start(anx6345);
695615 if (err) {
....@@ -704,9 +624,8 @@
704624
705625 static const struct drm_bridge_funcs anx6345_bridge_funcs = {
706626 .attach = anx6345_bridge_attach,
707
- .mode_fixup = anx6345_bridge_mode_fixup,
627
+ .mode_valid = anx6345_bridge_mode_valid,
708628 .disable = anx6345_bridge_disable,
709
- .mode_set = anx6345_bridge_mode_set,
710629 .enable = anx6345_bridge_enable,
711630 };
712631
....@@ -724,52 +643,106 @@
724643 .reg_bits = 8,
725644 .val_bits = 8,
726645 .max_register = 0xff,
646
+ .cache_type = REGCACHE_NONE,
727647 };
728648
729649 static const u16 anx6345_chipid_list[] = {
730650 0x6345,
731651 };
732652
653
+static bool anx6345_get_chip_id(struct anx6345 *anx6345)
654
+{
655
+ unsigned int i, idl, idh, version;
656
+
657
+ if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDL_REG, &idl))
658
+ return false;
659
+
660
+ if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDH_REG, &idh))
661
+ return false;
662
+
663
+ anx6345->chipid = (u8)idl | ((u8)idh << 8);
664
+
665
+ if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_VERSION_REG,
666
+ &version))
667
+ return false;
668
+
669
+ for (i = 0; i < ARRAY_SIZE(anx6345_chipid_list); i++) {
670
+ if (anx6345->chipid == anx6345_chipid_list[i]) {
671
+ DRM_INFO("Found ANX%x (ver. %d) eDP Transmitter\n",
672
+ anx6345->chipid, version);
673
+ return true;
674
+ }
675
+ }
676
+
677
+ DRM_ERROR("ANX%x (ver. %d) not supported by this driver\n",
678
+ anx6345->chipid, version);
679
+
680
+ return false;
681
+}
682
+
733683 static int anx6345_i2c_probe(struct i2c_client *client,
734684 const struct i2c_device_id *id)
735685 {
736686 struct anx6345 *anx6345;
737
- struct anx6345_platform_data *pdata;
738
- unsigned int i, idl, idh, version;
739
- bool found = false;
740
- int err;
687
+ struct device *dev;
688
+ int i, err;
741689
742690 anx6345 = devm_kzalloc(&client->dev, sizeof(*anx6345), GFP_KERNEL);
743691 if (!anx6345)
744692 return -ENOMEM;
745693
746
- pdata = &anx6345->pdata;
747
-
748694 mutex_init(&anx6345->lock);
749695
750
-#if IS_ENABLED(CONFIG_OF)
751696 anx6345->bridge.of_node = client->dev.of_node;
752
-#endif
753697
754698 anx6345->client = client;
755699 i2c_set_clientdata(client, anx6345);
756700
757
- err = anx6345_init_pdata(anx6345);
758
- if (err) {
759
- DRM_ERROR("Failed to initialize pdata: %d\n", err);
701
+ dev = &anx6345->client->dev;
702
+
703
+ err = drm_of_find_panel_or_bridge(client->dev.of_node, 1, 0,
704
+ &anx6345->panel, NULL);
705
+ if (err == -EPROBE_DEFER)
760706 return err;
707
+
708
+ if (err)
709
+ DRM_DEBUG("No panel found\n");
710
+
711
+ /* 1.2V digital core power regulator */
712
+ anx6345->dvdd12 = devm_regulator_get(dev, "dvdd12");
713
+ if (IS_ERR(anx6345->dvdd12)) {
714
+ if (PTR_ERR(anx6345->dvdd12) != -EPROBE_DEFER)
715
+ DRM_ERROR("Failed to get dvdd12 supply (%ld)\n",
716
+ PTR_ERR(anx6345->dvdd12));
717
+ return PTR_ERR(anx6345->dvdd12);
718
+ }
719
+
720
+ /* 2.5V digital core power regulator */
721
+ anx6345->dvdd25 = devm_regulator_get(dev, "dvdd25");
722
+ if (IS_ERR(anx6345->dvdd25)) {
723
+ if (PTR_ERR(anx6345->dvdd25) != -EPROBE_DEFER)
724
+ DRM_ERROR("Failed to get dvdd25 supply (%ld)\n",
725
+ PTR_ERR(anx6345->dvdd25));
726
+ return PTR_ERR(anx6345->dvdd25);
727
+ }
728
+
729
+ /* GPIO for chip reset */
730
+ anx6345->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
731
+ if (IS_ERR(anx6345->gpiod_reset)) {
732
+ DRM_ERROR("Reset gpio not found\n");
733
+ return PTR_ERR(anx6345->gpiod_reset);
761734 }
762735
763736 /* Map slave addresses of ANX6345 */
764737 for (i = 0; i < I2C_NUM_ADDRESSES; i++) {
765738 if (anx6345_i2c_addresses[i] >> 1 != client->addr)
766
- anx6345->i2c_clients[i] = i2c_new_dummy(client->adapter,
739
+ anx6345->i2c_clients[i] = i2c_new_dummy_device(client->adapter,
767740 anx6345_i2c_addresses[i] >> 1);
768741 else
769742 anx6345->i2c_clients[i] = client;
770743
771
- if (!anx6345->i2c_clients[i]) {
772
- err = -ENOMEM;
744
+ if (IS_ERR(anx6345->i2c_clients[i])) {
745
+ err = PTR_ERR(anx6345->i2c_clients[i]);
773746 DRM_ERROR("Failed to reserve I2C bus %02x\n",
774747 anx6345_i2c_addresses[i]);
775748 goto err_unregister_i2c;
....@@ -787,48 +760,15 @@
787760
788761 /* Look for supported chip ID */
789762 anx6345_poweron(anx6345);
763
+ if (anx6345_get_chip_id(anx6345)) {
764
+ anx6345->bridge.funcs = &anx6345_bridge_funcs;
765
+ drm_bridge_add(&anx6345->bridge);
790766
791
- err = regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDL_REG,
792
- &idl);
793
- if (err)
794
- goto err_poweroff;
795
-
796
- err = regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDH_REG,
797
- &idh);
798
- if (err)
799
- goto err_poweroff;
800
-
801
- anx6345->chipid = (u8)idl | ((u8)idh << 8);
802
-
803
- err = regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_VERSION_REG,
804
- &version);
805
- if (err)
806
- goto err_poweroff;
807
-
808
- for (i = 0; i < ARRAY_SIZE(anx6345_chipid_list); i++) {
809
- if (anx6345->chipid == anx6345_chipid_list[i]) {
810
- DRM_INFO("Found ANX%x (ver. %d) eDP Transmitter\n",
811
- anx6345->chipid, version);
812
- found = true;
813
- break;
814
- }
815
- }
816
-
817
- if (!found) {
818
- DRM_ERROR("ANX%x (ver. %d) not supported by this driver\n",
819
- anx6345->chipid, version);
767
+ return 0;
768
+ } else {
769
+ anx6345_poweroff(anx6345);
820770 err = -ENODEV;
821
- goto err_poweroff;
822771 }
823
-
824
- anx6345->bridge.funcs = &anx6345_bridge_funcs;
825
-
826
- drm_bridge_add(&anx6345->bridge);
827
-
828
- return 0;
829
-
830
-err_poweroff:
831
- anx6345_poweroff(anx6345);
832772
833773 err_unregister_i2c:
834774 unregister_i2c_dummy_clients(anx6345);
....@@ -843,6 +783,10 @@
843783
844784 unregister_i2c_dummy_clients(anx6345);
845785
786
+ kfree(anx6345->edid);
787
+
788
+ mutex_destroy(&anx6345->lock);
789
+
846790 return 0;
847791 }
848792
....@@ -852,13 +796,11 @@
852796 };
853797 MODULE_DEVICE_TABLE(i2c, anx6345_id);
854798
855
-#if IS_ENABLED(CONFIG_OF)
856799 static const struct of_device_id anx6345_match_table[] = {
857800 { .compatible = "analogix,anx6345", },
858801 { /* sentinel */ },
859802 };
860803 MODULE_DEVICE_TABLE(of, anx6345_match_table);
861
-#endif
862804
863805 static struct i2c_driver anx6345_driver = {
864806 .driver = {