Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/drivers/gpu/drm/bridge/analogix/analogix-anx6345.c
26516 views
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
/*
3
* Copyright(c) 2016, Analogix Semiconductor.
4
* Copyright(c) 2017, Icenowy Zheng <[email protected]>
5
*
6
* Based on anx7808 driver obtained from chromeos with copyright:
7
* Copyright(c) 2013, Google Inc.
8
*/
9
#include <linux/delay.h>
10
#include <linux/err.h>
11
#include <linux/gpio/consumer.h>
12
#include <linux/i2c.h>
13
#include <linux/interrupt.h>
14
#include <linux/kernel.h>
15
#include <linux/module.h>
16
#include <linux/of_platform.h>
17
#include <linux/regmap.h>
18
#include <linux/regulator/consumer.h>
19
#include <linux/types.h>
20
21
#include <drm/display/drm_dp_helper.h>
22
#include <drm/drm_atomic_helper.h>
23
#include <drm/drm_bridge.h>
24
#include <drm/drm_crtc.h>
25
#include <drm/drm_edid.h>
26
#include <drm/drm_of.h>
27
#include <drm/drm_panel.h>
28
#include <drm/drm_print.h>
29
#include <drm/drm_probe_helper.h>
30
31
#include "analogix-i2c-dptx.h"
32
#include "analogix-i2c-txcommon.h"
33
34
#define POLL_DELAY 50000 /* us */
35
#define POLL_TIMEOUT 5000000 /* us */
36
37
#define I2C_IDX_DPTX 0
38
#define I2C_IDX_TXCOM 1
39
40
static const u8 anx6345_i2c_addresses[] = {
41
[I2C_IDX_DPTX] = 0x70,
42
[I2C_IDX_TXCOM] = 0x72,
43
};
44
#define I2C_NUM_ADDRESSES ARRAY_SIZE(anx6345_i2c_addresses)
45
46
struct anx6345 {
47
struct drm_dp_aux aux;
48
struct drm_bridge bridge;
49
struct i2c_client *client;
50
const struct drm_edid *drm_edid;
51
struct drm_connector connector;
52
struct drm_panel *panel;
53
struct regulator *dvdd12;
54
struct regulator *dvdd25;
55
struct gpio_desc *gpiod_reset;
56
struct mutex lock; /* protect EDID access */
57
58
/* I2C Slave addresses of ANX6345 are mapped as DPTX and SYS */
59
struct i2c_client *i2c_clients[I2C_NUM_ADDRESSES];
60
struct regmap *map[I2C_NUM_ADDRESSES];
61
62
u16 chipid;
63
u8 dpcd[DP_RECEIVER_CAP_SIZE];
64
65
bool powered;
66
};
67
68
static inline struct anx6345 *connector_to_anx6345(struct drm_connector *c)
69
{
70
return container_of(c, struct anx6345, connector);
71
}
72
73
static inline struct anx6345 *bridge_to_anx6345(struct drm_bridge *bridge)
74
{
75
return container_of(bridge, struct anx6345, bridge);
76
}
77
78
static int anx6345_set_bits(struct regmap *map, u8 reg, u8 mask)
79
{
80
return regmap_update_bits(map, reg, mask, mask);
81
}
82
83
static int anx6345_clear_bits(struct regmap *map, u8 reg, u8 mask)
84
{
85
return regmap_update_bits(map, reg, mask, 0);
86
}
87
88
static ssize_t anx6345_aux_transfer(struct drm_dp_aux *aux,
89
struct drm_dp_aux_msg *msg)
90
{
91
struct anx6345 *anx6345 = container_of(aux, struct anx6345, aux);
92
93
return anx_dp_aux_transfer(anx6345->map[I2C_IDX_DPTX], msg);
94
}
95
96
static int anx6345_dp_link_training(struct anx6345 *anx6345)
97
{
98
unsigned int value;
99
u8 dp_bw, dpcd[2];
100
int err;
101
102
err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
103
SP_POWERDOWN_CTRL_REG,
104
SP_TOTAL_PD);
105
if (err)
106
return err;
107
108
err = drm_dp_dpcd_readb(&anx6345->aux, DP_MAX_LINK_RATE, &dp_bw);
109
if (err < 0)
110
return err;
111
112
switch (dp_bw) {
113
case DP_LINK_BW_1_62:
114
case DP_LINK_BW_2_7:
115
break;
116
117
default:
118
DRM_DEBUG_KMS("DP bandwidth (%#02x) not supported\n", dp_bw);
119
return -EINVAL;
120
}
121
122
err = anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL1_REG,
123
SP_VIDEO_MUTE);
124
if (err)
125
return err;
126
127
err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
128
SP_VID_CTRL1_REG, SP_VIDEO_EN);
129
if (err)
130
return err;
131
132
/* Get DPCD info */
133
err = drm_dp_dpcd_read(&anx6345->aux, DP_DPCD_REV,
134
&anx6345->dpcd, DP_RECEIVER_CAP_SIZE);
135
if (err < 0) {
136
DRM_ERROR("Failed to read DPCD: %d\n", err);
137
return err;
138
}
139
140
/* Clear channel x SERDES power down */
141
err = anx6345_clear_bits(anx6345->map[I2C_IDX_DPTX],
142
SP_DP_ANALOG_POWER_DOWN_REG, SP_CH0_PD);
143
if (err)
144
return err;
145
146
drm_dp_link_power_up(&anx6345->aux, anx6345->dpcd[DP_DPCD_REV]);
147
148
/* Possibly enable downspread on the sink */
149
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
150
SP_DP_DOWNSPREAD_CTRL1_REG, 0);
151
if (err)
152
return err;
153
154
if (anx6345->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5) {
155
DRM_DEBUG("Enable downspread on the sink\n");
156
/* 4000PPM */
157
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
158
SP_DP_DOWNSPREAD_CTRL1_REG, 8);
159
if (err)
160
return err;
161
162
err = drm_dp_dpcd_writeb(&anx6345->aux, DP_DOWNSPREAD_CTRL,
163
DP_SPREAD_AMP_0_5);
164
if (err < 0)
165
return err;
166
} else {
167
err = drm_dp_dpcd_writeb(&anx6345->aux, DP_DOWNSPREAD_CTRL, 0);
168
if (err < 0)
169
return err;
170
}
171
172
/* Set the lane count and the link rate on the sink */
173
if (drm_dp_enhanced_frame_cap(anx6345->dpcd))
174
err = anx6345_set_bits(anx6345->map[I2C_IDX_DPTX],
175
SP_DP_SYSTEM_CTRL_BASE + 4,
176
SP_ENHANCED_MODE);
177
else
178
err = anx6345_clear_bits(anx6345->map[I2C_IDX_DPTX],
179
SP_DP_SYSTEM_CTRL_BASE + 4,
180
SP_ENHANCED_MODE);
181
if (err)
182
return err;
183
184
dpcd[0] = dp_bw;
185
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
186
SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]);
187
if (err)
188
return err;
189
190
dpcd[1] = drm_dp_max_lane_count(anx6345->dpcd);
191
192
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
193
SP_DP_LANE_COUNT_SET_REG, dpcd[1]);
194
if (err)
195
return err;
196
197
if (drm_dp_enhanced_frame_cap(anx6345->dpcd))
198
dpcd[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
199
200
err = drm_dp_dpcd_write(&anx6345->aux, DP_LINK_BW_SET, dpcd,
201
sizeof(dpcd));
202
203
if (err < 0) {
204
DRM_ERROR("Failed to configure link: %d\n", err);
205
return err;
206
}
207
208
/* Start training on the source */
209
err = regmap_write(anx6345->map[I2C_IDX_DPTX], SP_DP_LT_CTRL_REG,
210
SP_LT_EN);
211
if (err)
212
return err;
213
214
return regmap_read_poll_timeout(anx6345->map[I2C_IDX_DPTX],
215
SP_DP_LT_CTRL_REG,
216
value, !(value & SP_DP_LT_INPROGRESS),
217
POLL_DELAY, POLL_TIMEOUT);
218
}
219
220
static int anx6345_tx_initialization(struct anx6345 *anx6345)
221
{
222
int err, i;
223
224
/* FIXME: colordepth is hardcoded for now */
225
err = regmap_write(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL2_REG,
226
SP_IN_BPC_6BIT << SP_IN_BPC_SHIFT);
227
if (err)
228
return err;
229
230
err = regmap_write(anx6345->map[I2C_IDX_DPTX], SP_DP_PLL_CTRL_REG, 0);
231
if (err)
232
return err;
233
234
err = regmap_write(anx6345->map[I2C_IDX_TXCOM],
235
SP_ANALOG_DEBUG1_REG, 0);
236
if (err)
237
return err;
238
239
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
240
SP_DP_LINK_DEBUG_CTRL_REG,
241
SP_NEW_PRBS7 | SP_M_VID_DEBUG);
242
if (err)
243
return err;
244
245
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
246
SP_DP_ANALOG_POWER_DOWN_REG, 0);
247
if (err)
248
return err;
249
250
/* Force HPD */
251
err = anx6345_set_bits(anx6345->map[I2C_IDX_DPTX],
252
SP_DP_SYSTEM_CTRL_BASE + 3,
253
SP_HPD_FORCE | SP_HPD_CTRL);
254
if (err)
255
return err;
256
257
for (i = 0; i < 4; i++) {
258
/* 4 lanes */
259
err = regmap_write(anx6345->map[I2C_IDX_DPTX],
260
SP_DP_LANE0_LT_CTRL_REG + i, 0);
261
if (err)
262
return err;
263
}
264
265
/* Reset AUX */
266
err = anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM],
267
SP_RESET_CTRL2_REG, SP_AUX_RST);
268
if (err)
269
return err;
270
271
return anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
272
SP_RESET_CTRL2_REG, SP_AUX_RST);
273
}
274
275
static void anx6345_poweron(struct anx6345 *anx6345)
276
{
277
int err;
278
279
/* Ensure reset is asserted before starting power on sequence */
280
gpiod_set_value_cansleep(anx6345->gpiod_reset, 1);
281
usleep_range(1000, 2000);
282
283
err = regulator_enable(anx6345->dvdd12);
284
if (err) {
285
DRM_ERROR("Failed to enable dvdd12 regulator: %d\n",
286
err);
287
return;
288
}
289
290
/* T1 - delay between VDD12 and VDD25 should be 0-2ms */
291
usleep_range(1000, 2000);
292
293
err = regulator_enable(anx6345->dvdd25);
294
if (err) {
295
DRM_ERROR("Failed to enable dvdd25 regulator: %d\n",
296
err);
297
return;
298
}
299
300
/* T2 - delay between RESETN and all power rail stable,
301
* should be 2-5ms
302
*/
303
usleep_range(2000, 5000);
304
305
gpiod_set_value_cansleep(anx6345->gpiod_reset, 0);
306
307
/* Power on registers module */
308
anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG,
309
SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD | SP_LINK_PD);
310
anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG,
311
SP_REGISTER_PD | SP_TOTAL_PD);
312
313
if (anx6345->panel)
314
drm_panel_prepare(anx6345->panel);
315
316
anx6345->powered = true;
317
}
318
319
static void anx6345_poweroff(struct anx6345 *anx6345)
320
{
321
int err;
322
323
gpiod_set_value_cansleep(anx6345->gpiod_reset, 1);
324
usleep_range(1000, 2000);
325
326
if (anx6345->panel)
327
drm_panel_unprepare(anx6345->panel);
328
329
err = regulator_disable(anx6345->dvdd25);
330
if (err) {
331
DRM_ERROR("Failed to disable dvdd25 regulator: %d\n",
332
err);
333
return;
334
}
335
336
usleep_range(5000, 10000);
337
338
err = regulator_disable(anx6345->dvdd12);
339
if (err) {
340
DRM_ERROR("Failed to disable dvdd12 regulator: %d\n",
341
err);
342
return;
343
}
344
345
usleep_range(1000, 2000);
346
347
anx6345->powered = false;
348
}
349
350
static int anx6345_start(struct anx6345 *anx6345)
351
{
352
int err;
353
354
if (!anx6345->powered)
355
anx6345_poweron(anx6345);
356
357
/* Power on needed modules */
358
err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM],
359
SP_POWERDOWN_CTRL_REG,
360
SP_VIDEO_PD | SP_LINK_PD);
361
362
err = anx6345_tx_initialization(anx6345);
363
if (err) {
364
DRM_ERROR("Failed eDP transmitter initialization: %d\n", err);
365
anx6345_poweroff(anx6345);
366
return err;
367
}
368
369
err = anx6345_dp_link_training(anx6345);
370
if (err) {
371
DRM_ERROR("Failed link training: %d\n", err);
372
anx6345_poweroff(anx6345);
373
return err;
374
}
375
376
/*
377
* This delay seems to help keep the hardware in a good state. Without
378
* it, there are times where it fails silently.
379
*/
380
usleep_range(10000, 15000);
381
382
return 0;
383
}
384
385
static int anx6345_config_dp_output(struct anx6345 *anx6345)
386
{
387
int err;
388
389
err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL1_REG,
390
SP_VIDEO_MUTE);
391
if (err)
392
return err;
393
394
/* Enable DP output */
395
err = anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL1_REG,
396
SP_VIDEO_EN);
397
if (err)
398
return err;
399
400
/* Force stream valid */
401
return anx6345_set_bits(anx6345->map[I2C_IDX_DPTX],
402
SP_DP_SYSTEM_CTRL_BASE + 3,
403
SP_STRM_FORCE | SP_STRM_CTRL);
404
}
405
406
static int anx6345_get_downstream_info(struct anx6345 *anx6345)
407
{
408
u8 value;
409
int err;
410
411
err = drm_dp_dpcd_readb(&anx6345->aux, DP_SINK_COUNT, &value);
412
if (err < 0) {
413
DRM_ERROR("Get sink count failed %d\n", err);
414
return err;
415
}
416
417
if (!DP_GET_SINK_COUNT(value)) {
418
DRM_ERROR("Downstream disconnected\n");
419
return -EIO;
420
}
421
422
return 0;
423
}
424
425
static int anx6345_get_modes(struct drm_connector *connector)
426
{
427
struct anx6345 *anx6345 = connector_to_anx6345(connector);
428
int err, num_modes = 0;
429
bool power_off = false;
430
431
mutex_lock(&anx6345->lock);
432
433
if (!anx6345->drm_edid) {
434
if (!anx6345->powered) {
435
anx6345_poweron(anx6345);
436
power_off = true;
437
}
438
439
err = anx6345_get_downstream_info(anx6345);
440
if (err) {
441
DRM_ERROR("Failed to get downstream info: %d\n", err);
442
goto unlock;
443
}
444
445
anx6345->drm_edid = drm_edid_read_ddc(connector, &anx6345->aux.ddc);
446
if (!anx6345->drm_edid)
447
DRM_ERROR("Failed to read EDID from panel\n");
448
449
err = drm_edid_connector_update(connector, anx6345->drm_edid);
450
if (err) {
451
DRM_ERROR("Failed to update EDID property: %d\n", err);
452
goto unlock;
453
}
454
}
455
456
num_modes += drm_edid_connector_add_modes(connector);
457
458
/* Driver currently supports only 6bpc */
459
connector->display_info.bpc = 6;
460
461
unlock:
462
if (power_off)
463
anx6345_poweroff(anx6345);
464
465
mutex_unlock(&anx6345->lock);
466
467
if (!num_modes && anx6345->panel)
468
num_modes += drm_panel_get_modes(anx6345->panel, connector);
469
470
return num_modes;
471
}
472
473
static const struct drm_connector_helper_funcs anx6345_connector_helper_funcs = {
474
.get_modes = anx6345_get_modes,
475
};
476
477
static void
478
anx6345_connector_destroy(struct drm_connector *connector)
479
{
480
drm_connector_cleanup(connector);
481
}
482
483
static const struct drm_connector_funcs anx6345_connector_funcs = {
484
.fill_modes = drm_helper_probe_single_connector_modes,
485
.destroy = anx6345_connector_destroy,
486
.reset = drm_atomic_helper_connector_reset,
487
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
488
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
489
};
490
491
static int anx6345_bridge_attach(struct drm_bridge *bridge,
492
struct drm_encoder *encoder,
493
enum drm_bridge_attach_flags flags)
494
{
495
struct anx6345 *anx6345 = bridge_to_anx6345(bridge);
496
int err;
497
498
if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
499
DRM_ERROR("Fix bridge driver to make connector optional!");
500
return -EINVAL;
501
}
502
503
/* Register aux channel */
504
anx6345->aux.name = "DP-AUX";
505
anx6345->aux.dev = &anx6345->client->dev;
506
anx6345->aux.drm_dev = bridge->dev;
507
anx6345->aux.transfer = anx6345_aux_transfer;
508
509
err = drm_dp_aux_register(&anx6345->aux);
510
if (err < 0) {
511
DRM_ERROR("Failed to register aux channel: %d\n", err);
512
return err;
513
}
514
515
err = drm_connector_init(bridge->dev, &anx6345->connector,
516
&anx6345_connector_funcs,
517
DRM_MODE_CONNECTOR_eDP);
518
if (err) {
519
DRM_ERROR("Failed to initialize connector: %d\n", err);
520
goto aux_unregister;
521
}
522
523
drm_connector_helper_add(&anx6345->connector,
524
&anx6345_connector_helper_funcs);
525
526
anx6345->connector.polled = DRM_CONNECTOR_POLL_HPD;
527
528
err = drm_connector_attach_encoder(&anx6345->connector,
529
encoder);
530
if (err) {
531
DRM_ERROR("Failed to link up connector to encoder: %d\n", err);
532
goto connector_cleanup;
533
}
534
535
err = drm_connector_register(&anx6345->connector);
536
if (err) {
537
DRM_ERROR("Failed to register connector: %d\n", err);
538
goto connector_cleanup;
539
}
540
541
return 0;
542
connector_cleanup:
543
drm_connector_cleanup(&anx6345->connector);
544
aux_unregister:
545
drm_dp_aux_unregister(&anx6345->aux);
546
return err;
547
}
548
549
static void anx6345_bridge_detach(struct drm_bridge *bridge)
550
{
551
drm_dp_aux_unregister(&bridge_to_anx6345(bridge)->aux);
552
}
553
554
static enum drm_mode_status
555
anx6345_bridge_mode_valid(struct drm_bridge *bridge,
556
const struct drm_display_info *info,
557
const struct drm_display_mode *mode)
558
{
559
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
560
return MODE_NO_INTERLACE;
561
562
/* Max 1200p at 5.4 Ghz, one lane */
563
if (mode->clock > 154000)
564
return MODE_CLOCK_HIGH;
565
566
return MODE_OK;
567
}
568
569
static void anx6345_bridge_disable(struct drm_bridge *bridge)
570
{
571
struct anx6345 *anx6345 = bridge_to_anx6345(bridge);
572
573
/* Power off all modules except configuration registers access */
574
anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG,
575
SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD | SP_LINK_PD);
576
if (anx6345->panel)
577
drm_panel_disable(anx6345->panel);
578
579
if (anx6345->powered)
580
anx6345_poweroff(anx6345);
581
}
582
583
static void anx6345_bridge_enable(struct drm_bridge *bridge)
584
{
585
struct anx6345 *anx6345 = bridge_to_anx6345(bridge);
586
int err;
587
588
if (anx6345->panel)
589
drm_panel_enable(anx6345->panel);
590
591
err = anx6345_start(anx6345);
592
if (err) {
593
DRM_ERROR("Failed to initialize: %d\n", err);
594
return;
595
}
596
597
err = anx6345_config_dp_output(anx6345);
598
if (err)
599
DRM_ERROR("Failed to enable DP output: %d\n", err);
600
}
601
602
static const struct drm_bridge_funcs anx6345_bridge_funcs = {
603
.attach = anx6345_bridge_attach,
604
.detach = anx6345_bridge_detach,
605
.mode_valid = anx6345_bridge_mode_valid,
606
.disable = anx6345_bridge_disable,
607
.enable = anx6345_bridge_enable,
608
};
609
610
static void unregister_i2c_dummy_clients(struct anx6345 *anx6345)
611
{
612
unsigned int i;
613
614
for (i = 1; i < ARRAY_SIZE(anx6345->i2c_clients); i++)
615
if (anx6345->i2c_clients[i] &&
616
anx6345->i2c_clients[i]->addr != anx6345->client->addr)
617
i2c_unregister_device(anx6345->i2c_clients[i]);
618
}
619
620
static const struct regmap_config anx6345_regmap_config = {
621
.reg_bits = 8,
622
.val_bits = 8,
623
.max_register = 0xff,
624
.cache_type = REGCACHE_NONE,
625
};
626
627
static const u16 anx6345_chipid_list[] = {
628
0x6345,
629
};
630
631
static bool anx6345_get_chip_id(struct anx6345 *anx6345)
632
{
633
unsigned int i, idl, idh, version;
634
635
if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDL_REG, &idl))
636
return false;
637
638
if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDH_REG, &idh))
639
return false;
640
641
anx6345->chipid = (u8)idl | ((u8)idh << 8);
642
643
if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_VERSION_REG,
644
&version))
645
return false;
646
647
for (i = 0; i < ARRAY_SIZE(anx6345_chipid_list); i++) {
648
if (anx6345->chipid == anx6345_chipid_list[i]) {
649
DRM_INFO("Found ANX%x (ver. %d) eDP Transmitter\n",
650
anx6345->chipid, version);
651
return true;
652
}
653
}
654
655
DRM_ERROR("ANX%x (ver. %d) not supported by this driver\n",
656
anx6345->chipid, version);
657
658
return false;
659
}
660
661
static int anx6345_i2c_probe(struct i2c_client *client)
662
{
663
struct anx6345 *anx6345;
664
struct device *dev;
665
int i, err;
666
667
anx6345 = devm_drm_bridge_alloc(&client->dev, struct anx6345, bridge,
668
&anx6345_bridge_funcs);
669
if (IS_ERR(anx6345))
670
return PTR_ERR(anx6345);
671
672
mutex_init(&anx6345->lock);
673
674
anx6345->bridge.of_node = client->dev.of_node;
675
676
anx6345->client = client;
677
i2c_set_clientdata(client, anx6345);
678
679
dev = &anx6345->client->dev;
680
681
err = drm_of_find_panel_or_bridge(client->dev.of_node, 1, 0,
682
&anx6345->panel, NULL);
683
if (err == -EPROBE_DEFER)
684
return err;
685
686
if (err)
687
DRM_DEBUG("No panel found\n");
688
689
/* 1.2V digital core power regulator */
690
anx6345->dvdd12 = devm_regulator_get(dev, "dvdd12");
691
if (IS_ERR(anx6345->dvdd12)) {
692
if (PTR_ERR(anx6345->dvdd12) != -EPROBE_DEFER)
693
DRM_ERROR("Failed to get dvdd12 supply (%ld)\n",
694
PTR_ERR(anx6345->dvdd12));
695
return PTR_ERR(anx6345->dvdd12);
696
}
697
698
/* 2.5V digital core power regulator */
699
anx6345->dvdd25 = devm_regulator_get(dev, "dvdd25");
700
if (IS_ERR(anx6345->dvdd25)) {
701
if (PTR_ERR(anx6345->dvdd25) != -EPROBE_DEFER)
702
DRM_ERROR("Failed to get dvdd25 supply (%ld)\n",
703
PTR_ERR(anx6345->dvdd25));
704
return PTR_ERR(anx6345->dvdd25);
705
}
706
707
/* GPIO for chip reset */
708
anx6345->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
709
if (IS_ERR(anx6345->gpiod_reset)) {
710
DRM_ERROR("Reset gpio not found\n");
711
return PTR_ERR(anx6345->gpiod_reset);
712
}
713
714
/* Map slave addresses of ANX6345 */
715
for (i = 0; i < I2C_NUM_ADDRESSES; i++) {
716
if (anx6345_i2c_addresses[i] >> 1 != client->addr)
717
anx6345->i2c_clients[i] = i2c_new_dummy_device(client->adapter,
718
anx6345_i2c_addresses[i] >> 1);
719
else
720
anx6345->i2c_clients[i] = client;
721
722
if (IS_ERR(anx6345->i2c_clients[i])) {
723
err = PTR_ERR(anx6345->i2c_clients[i]);
724
DRM_ERROR("Failed to reserve I2C bus %02x\n",
725
anx6345_i2c_addresses[i]);
726
goto err_unregister_i2c;
727
}
728
729
anx6345->map[i] = devm_regmap_init_i2c(anx6345->i2c_clients[i],
730
&anx6345_regmap_config);
731
if (IS_ERR(anx6345->map[i])) {
732
err = PTR_ERR(anx6345->map[i]);
733
DRM_ERROR("Failed regmap initialization %02x\n",
734
anx6345_i2c_addresses[i]);
735
goto err_unregister_i2c;
736
}
737
}
738
739
/* Look for supported chip ID */
740
anx6345_poweron(anx6345);
741
if (anx6345_get_chip_id(anx6345)) {
742
drm_bridge_add(&anx6345->bridge);
743
744
return 0;
745
} else {
746
anx6345_poweroff(anx6345);
747
err = -ENODEV;
748
}
749
750
err_unregister_i2c:
751
unregister_i2c_dummy_clients(anx6345);
752
return err;
753
}
754
755
static void anx6345_i2c_remove(struct i2c_client *client)
756
{
757
struct anx6345 *anx6345 = i2c_get_clientdata(client);
758
759
drm_bridge_remove(&anx6345->bridge);
760
761
unregister_i2c_dummy_clients(anx6345);
762
763
drm_edid_free(anx6345->drm_edid);
764
765
mutex_destroy(&anx6345->lock);
766
}
767
768
static const struct i2c_device_id anx6345_id[] = {
769
{ "anx6345" },
770
{ /* sentinel */ }
771
};
772
MODULE_DEVICE_TABLE(i2c, anx6345_id);
773
774
static const struct of_device_id anx6345_match_table[] = {
775
{ .compatible = "analogix,anx6345", },
776
{ /* sentinel */ },
777
};
778
MODULE_DEVICE_TABLE(of, anx6345_match_table);
779
780
static struct i2c_driver anx6345_driver = {
781
.driver = {
782
.name = "anx6345",
783
.of_match_table = anx6345_match_table,
784
},
785
.probe = anx6345_i2c_probe,
786
.remove = anx6345_i2c_remove,
787
.id_table = anx6345_id,
788
};
789
module_i2c_driver(anx6345_driver);
790
791
MODULE_DESCRIPTION("ANX6345 eDP Transmitter driver");
792
MODULE_AUTHOR("Icenowy Zheng <[email protected]>");
793
MODULE_LICENSE("GPL v2");
794
795