bpf: Prevent memory disambiguation attack
[linux/fpc-iii.git] / drivers / gpu / drm / bridge / analogix-anx78xx.c
blobed12a7ddd64aee41b607c36166454eedda235637
1 /*
2 * Copyright(c) 2016, Analogix Semiconductor.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * Based on anx7808 driver obtained from chromeos with copyright:
14 * Copyright(c) 2013, Google Inc.
17 #include <linux/delay.h>
18 #include <linux/err.h>
19 #include <linux/interrupt.h>
20 #include <linux/i2c.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/of_gpio.h>
24 #include <linux/of_irq.h>
25 #include <linux/of_platform.h>
26 #include <linux/regmap.h>
27 #include <linux/types.h>
28 #include <linux/gpio/consumer.h>
29 #include <linux/regulator/consumer.h>
31 #include <drm/drmP.h>
32 #include <drm/drm_atomic_helper.h>
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_crtc_helper.h>
35 #include <drm/drm_dp_helper.h>
36 #include <drm/drm_edid.h>
38 #include "analogix-anx78xx.h"
40 #define I2C_NUM_ADDRESSES 5
41 #define I2C_IDX_TX_P0 0
42 #define I2C_IDX_TX_P1 1
43 #define I2C_IDX_TX_P2 2
44 #define I2C_IDX_RX_P0 3
45 #define I2C_IDX_RX_P1 4
47 #define XTAL_CLK 270 /* 27M */
48 #define AUX_CH_BUFFER_SIZE 16
49 #define AUX_WAIT_TIMEOUT_MS 15
51 static const u8 anx78xx_i2c_addresses[] = {
52 [I2C_IDX_TX_P0] = TX_P0,
53 [I2C_IDX_TX_P1] = TX_P1,
54 [I2C_IDX_TX_P2] = TX_P2,
55 [I2C_IDX_RX_P0] = RX_P0,
56 [I2C_IDX_RX_P1] = RX_P1,
59 struct anx78xx_platform_data {
60 struct regulator *dvdd10;
61 struct gpio_desc *gpiod_hpd;
62 struct gpio_desc *gpiod_pd;
63 struct gpio_desc *gpiod_reset;
65 int hpd_irq;
66 int intp_irq;
69 struct anx78xx {
70 struct drm_dp_aux aux;
71 struct drm_bridge bridge;
72 struct i2c_client *client;
73 struct edid *edid;
74 struct drm_connector connector;
75 struct drm_dp_link link;
76 struct anx78xx_platform_data pdata;
77 struct mutex lock;
80 * I2C Slave addresses of ANX7814 are mapped as TX_P0, TX_P1, TX_P2,
81 * RX_P0 and RX_P1.
83 struct i2c_client *i2c_dummy[I2C_NUM_ADDRESSES];
84 struct regmap *map[I2C_NUM_ADDRESSES];
86 u16 chipid;
87 u8 dpcd[DP_RECEIVER_CAP_SIZE];
89 bool powered;
92 static inline struct anx78xx *connector_to_anx78xx(struct drm_connector *c)
94 return container_of(c, struct anx78xx, connector);
97 static inline struct anx78xx *bridge_to_anx78xx(struct drm_bridge *bridge)
99 return container_of(bridge, struct anx78xx, bridge);
102 static int anx78xx_set_bits(struct regmap *map, u8 reg, u8 mask)
104 return regmap_update_bits(map, reg, mask, mask);
107 static int anx78xx_clear_bits(struct regmap *map, u8 reg, u8 mask)
109 return regmap_update_bits(map, reg, mask, 0);
112 static bool anx78xx_aux_op_finished(struct anx78xx *anx78xx)
114 unsigned int value;
115 int err;
117 err = regmap_read(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL2_REG,
118 &value);
119 if (err < 0)
120 return false;
122 return (value & SP_AUX_EN) == 0;
125 static int anx78xx_aux_wait(struct anx78xx *anx78xx)
127 unsigned long timeout;
128 unsigned int status;
129 int err;
131 timeout = jiffies + msecs_to_jiffies(AUX_WAIT_TIMEOUT_MS) + 1;
133 while (!anx78xx_aux_op_finished(anx78xx)) {
134 if (time_after(jiffies, timeout)) {
135 if (!anx78xx_aux_op_finished(anx78xx)) {
136 DRM_ERROR("Timed out waiting AUX to finish\n");
137 return -ETIMEDOUT;
140 break;
143 usleep_range(1000, 2000);
146 /* Read the AUX channel access status */
147 err = regmap_read(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_CH_STATUS_REG,
148 &status);
149 if (err < 0) {
150 DRM_ERROR("Failed to read from AUX channel: %d\n", err);
151 return err;
154 if (status & SP_AUX_STATUS) {
155 DRM_ERROR("Failed to wait for AUX channel (status: %02x)\n",
156 status);
157 return -ETIMEDOUT;
160 return 0;
163 static int anx78xx_aux_address(struct anx78xx *anx78xx, unsigned int addr)
165 int err;
167 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_ADDR_7_0_REG,
168 addr & 0xff);
169 if (err)
170 return err;
172 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_ADDR_15_8_REG,
173 (addr & 0xff00) >> 8);
174 if (err)
175 return err;
178 * DP AUX CH Address Register #2, only update bits[3:0]
179 * [7:4] RESERVED
180 * [3:0] AUX_ADDR[19:16], Register control AUX CH address.
182 err = regmap_update_bits(anx78xx->map[I2C_IDX_TX_P0],
183 SP_AUX_ADDR_19_16_REG,
184 SP_AUX_ADDR_19_16_MASK,
185 (addr & 0xf0000) >> 16);
187 if (err)
188 return err;
190 return 0;
193 static ssize_t anx78xx_aux_transfer(struct drm_dp_aux *aux,
194 struct drm_dp_aux_msg *msg)
196 struct anx78xx *anx78xx = container_of(aux, struct anx78xx, aux);
197 u8 ctrl1 = msg->request;
198 u8 ctrl2 = SP_AUX_EN;
199 u8 *buffer = msg->buffer;
200 int err;
202 /* The DP AUX transmit and receive buffer has 16 bytes. */
203 if (WARN_ON(msg->size > AUX_CH_BUFFER_SIZE))
204 return -E2BIG;
206 /* Zero-sized messages specify address-only transactions. */
207 if (msg->size < 1)
208 ctrl2 |= SP_ADDR_ONLY;
209 else /* For non-zero-sized set the length field. */
210 ctrl1 |= (msg->size - 1) << SP_AUX_LENGTH_SHIFT;
212 if ((msg->request & DP_AUX_I2C_READ) == 0) {
213 /* When WRITE | MOT write values to data buffer */
214 err = regmap_bulk_write(anx78xx->map[I2C_IDX_TX_P0],
215 SP_DP_BUF_DATA0_REG, buffer,
216 msg->size);
217 if (err)
218 return err;
221 /* Write address and request */
222 err = anx78xx_aux_address(anx78xx, msg->address);
223 if (err)
224 return err;
226 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL1_REG,
227 ctrl1);
228 if (err)
229 return err;
231 /* Start transaction */
232 err = regmap_update_bits(anx78xx->map[I2C_IDX_TX_P0],
233 SP_DP_AUX_CH_CTRL2_REG, SP_ADDR_ONLY |
234 SP_AUX_EN, ctrl2);
235 if (err)
236 return err;
238 err = anx78xx_aux_wait(anx78xx);
239 if (err)
240 return err;
242 msg->reply = DP_AUX_I2C_REPLY_ACK;
244 if ((msg->size > 0) && (msg->request & DP_AUX_I2C_READ)) {
245 /* Read values from data buffer */
246 err = regmap_bulk_read(anx78xx->map[I2C_IDX_TX_P0],
247 SP_DP_BUF_DATA0_REG, buffer,
248 msg->size);
249 if (err)
250 return err;
253 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0],
254 SP_DP_AUX_CH_CTRL2_REG, SP_ADDR_ONLY);
255 if (err)
256 return err;
258 return msg->size;
261 static int anx78xx_set_hpd(struct anx78xx *anx78xx)
263 int err;
265 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_RX_P0],
266 SP_TMDS_CTRL_BASE + 7, SP_PD_RT);
267 if (err)
268 return err;
270 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL3_REG,
271 SP_HPD_OUT);
272 if (err)
273 return err;
275 return 0;
278 static int anx78xx_clear_hpd(struct anx78xx *anx78xx)
280 int err;
282 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL3_REG,
283 SP_HPD_OUT);
284 if (err)
285 return err;
287 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0],
288 SP_TMDS_CTRL_BASE + 7, SP_PD_RT);
289 if (err)
290 return err;
292 return 0;
295 static const struct reg_sequence tmds_phy_initialization[] = {
296 { SP_TMDS_CTRL_BASE + 1, 0x90 },
297 { SP_TMDS_CTRL_BASE + 2, 0xa9 },
298 { SP_TMDS_CTRL_BASE + 6, 0x92 },
299 { SP_TMDS_CTRL_BASE + 7, 0x80 },
300 { SP_TMDS_CTRL_BASE + 20, 0xf2 },
301 { SP_TMDS_CTRL_BASE + 22, 0xc4 },
302 { SP_TMDS_CTRL_BASE + 23, 0x18 },
305 static int anx78xx_rx_initialization(struct anx78xx *anx78xx)
307 int err;
309 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG,
310 SP_AUD_MUTE | SP_VID_MUTE);
311 if (err)
312 return err;
314 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], SP_CHIP_CTRL_REG,
315 SP_MAN_HDMI5V_DET | SP_PLLLOCK_CKDT_EN |
316 SP_DIGITAL_CKDT_EN);
317 if (err)
318 return err;
320 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0],
321 SP_SOFTWARE_RESET1_REG, SP_HDCP_MAN_RST |
322 SP_SW_MAN_RST | SP_TMDS_RST | SP_VIDEO_RST);
323 if (err)
324 return err;
326 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_RX_P0],
327 SP_SOFTWARE_RESET1_REG, SP_HDCP_MAN_RST |
328 SP_SW_MAN_RST | SP_TMDS_RST | SP_VIDEO_RST);
329 if (err)
330 return err;
332 /* Sync detect change, GP set mute */
333 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0],
334 SP_AUD_EXCEPTION_ENABLE_BASE + 1, BIT(5) |
335 BIT(6));
336 if (err)
337 return err;
339 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0],
340 SP_AUD_EXCEPTION_ENABLE_BASE + 3,
341 SP_AEC_EN21);
342 if (err)
343 return err;
345 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], SP_AUDVID_CTRL_REG,
346 SP_AVC_EN | SP_AAC_OE | SP_AAC_EN);
347 if (err)
348 return err;
350 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_RX_P0],
351 SP_SYSTEM_POWER_DOWN1_REG, SP_PWDN_CTRL);
352 if (err)
353 return err;
355 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0],
356 SP_VID_DATA_RANGE_CTRL_REG, SP_R2Y_INPUT_LIMIT);
357 if (err)
358 return err;
360 /* Enable DDC stretch */
361 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
362 SP_DP_EXTRA_I2C_DEV_ADDR_REG, SP_I2C_EXTRA_ADDR);
363 if (err)
364 return err;
366 /* TMDS phy initialization */
367 err = regmap_multi_reg_write(anx78xx->map[I2C_IDX_RX_P0],
368 tmds_phy_initialization,
369 ARRAY_SIZE(tmds_phy_initialization));
370 if (err)
371 return err;
373 err = anx78xx_clear_hpd(anx78xx);
374 if (err)
375 return err;
377 return 0;
380 static const u8 dp_tx_output_precise_tune_bits[20] = {
381 0x01, 0x03, 0x07, 0x7f, 0x71, 0x6b, 0x7f,
382 0x73, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
383 0x0c, 0x42, 0x1e, 0x3e, 0x72, 0x7e,
386 static int anx78xx_link_phy_initialization(struct anx78xx *anx78xx)
388 int err;
391 * REVISIT : It is writing to a RESERVED bits in Analog Control 0
392 * register.
394 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_ANALOG_CTRL0_REG,
395 0x02);
396 if (err)
397 return err;
400 * Write DP TX output emphasis precise tune bits.
402 err = regmap_bulk_write(anx78xx->map[I2C_IDX_TX_P1],
403 SP_DP_TX_LT_CTRL0_REG,
404 dp_tx_output_precise_tune_bits,
405 ARRAY_SIZE(dp_tx_output_precise_tune_bits));
407 if (err)
408 return err;
410 return 0;
413 static int anx78xx_xtal_clk_sel(struct anx78xx *anx78xx)
415 unsigned int value;
416 int err;
418 err = regmap_update_bits(anx78xx->map[I2C_IDX_TX_P2],
419 SP_ANALOG_DEBUG2_REG,
420 SP_XTAL_FRQ | SP_FORCE_SW_OFF_BYPASS,
421 SP_XTAL_FRQ_27M);
422 if (err)
423 return err;
425 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL3_REG,
426 XTAL_CLK & SP_WAIT_COUNTER_7_0_MASK);
427 if (err)
428 return err;
430 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL4_REG,
431 ((XTAL_CLK & 0xff00) >> 2) | (XTAL_CLK / 10));
432 if (err)
433 return err;
435 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
436 SP_I2C_GEN_10US_TIMER0_REG, XTAL_CLK & 0xff);
437 if (err)
438 return err;
440 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
441 SP_I2C_GEN_10US_TIMER1_REG,
442 (XTAL_CLK & 0xff00) >> 8);
443 if (err)
444 return err;
446 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_MISC_CTRL_REG,
447 XTAL_CLK / 10 - 1);
448 if (err)
449 return err;
451 err = regmap_read(anx78xx->map[I2C_IDX_RX_P0],
452 SP_HDMI_US_TIMER_CTRL_REG,
453 &value);
454 if (err)
455 return err;
457 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0],
458 SP_HDMI_US_TIMER_CTRL_REG,
459 (value & SP_MS_TIMER_MARGIN_10_8_MASK) |
460 ((((XTAL_CLK / 10) >> 1) - 2) << 3));
461 if (err)
462 return err;
464 return 0;
467 static const struct reg_sequence otp_key_protect[] = {
468 { SP_OTP_KEY_PROTECT1_REG, SP_OTP_PSW1 },
469 { SP_OTP_KEY_PROTECT2_REG, SP_OTP_PSW2 },
470 { SP_OTP_KEY_PROTECT3_REG, SP_OTP_PSW3 },
473 static int anx78xx_tx_initialization(struct anx78xx *anx78xx)
475 int err;
477 /* Set terminal resistor to 50 ohm */
478 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL2_REG,
479 0x30);
480 if (err)
481 return err;
483 /* Enable aux double diff output */
484 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
485 SP_DP_AUX_CH_CTRL2_REG, 0x08);
486 if (err)
487 return err;
489 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0],
490 SP_DP_HDCP_CTRL_REG, SP_AUTO_EN |
491 SP_AUTO_START);
492 if (err)
493 return err;
495 err = regmap_multi_reg_write(anx78xx->map[I2C_IDX_TX_P0],
496 otp_key_protect,
497 ARRAY_SIZE(otp_key_protect));
498 if (err)
499 return err;
501 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
502 SP_HDCP_KEY_COMMAND_REG, SP_DISABLE_SYNC_HDCP);
503 if (err)
504 return err;
506 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL8_REG,
507 SP_VID_VRES_TH);
508 if (err)
509 return err;
512 * DP HDCP auto authentication wait timer (when downstream starts to
513 * auth, DP side will wait for this period then do auth automatically)
515 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_HDCP_AUTO_TIMER_REG,
516 0x00);
517 if (err)
518 return err;
520 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
521 SP_DP_HDCP_CTRL_REG, SP_LINK_POLLING);
522 if (err)
523 return err;
525 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
526 SP_DP_LINK_DEBUG_CTRL_REG, SP_M_VID_DEBUG);
527 if (err)
528 return err;
530 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2],
531 SP_ANALOG_DEBUG2_REG, SP_POWERON_TIME_1P5MS);
532 if (err)
533 return err;
535 err = anx78xx_xtal_clk_sel(anx78xx);
536 if (err)
537 return err;
539 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_DEFER_CTRL_REG,
540 SP_DEFER_CTRL_EN | 0x0c);
541 if (err)
542 return err;
544 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
545 SP_DP_POLLING_CTRL_REG,
546 SP_AUTO_POLLING_DISABLE);
547 if (err)
548 return err;
551 * Short the link integrity check timer to speed up bstatus
552 * polling for HDCP CTS item 1A-07
554 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
555 SP_HDCP_LINK_CHECK_TIMER_REG, 0x1d);
556 if (err)
557 return err;
559 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
560 SP_DP_MISC_CTRL_REG, SP_EQ_TRAINING_LOOP);
561 if (err)
562 return err;
564 /* Power down the main link by default */
565 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
566 SP_DP_ANALOG_POWER_DOWN_REG, SP_CH0_PD);
567 if (err)
568 return err;
570 err = anx78xx_link_phy_initialization(anx78xx);
571 if (err)
572 return err;
574 /* Gen m_clk with downspreading */
575 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
576 SP_DP_M_CALCULATION_CTRL_REG, SP_M_GEN_CLK_SEL);
577 if (err)
578 return err;
580 return 0;
583 static int anx78xx_enable_interrupts(struct anx78xx *anx78xx)
585 int err;
588 * BIT0: INT pin assertion polarity: 1 = assert high
589 * BIT1: INT pin output type: 0 = push/pull
591 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_INT_CTRL_REG, 0x01);
592 if (err)
593 return err;
595 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2],
596 SP_COMMON_INT_MASK4_REG, SP_HPD_LOST | SP_HPD_PLUG);
597 if (err)
598 return err;
600 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_DP_INT_MASK1_REG,
601 SP_TRAINING_FINISH);
602 if (err)
603 return err;
605 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_INT_MASK1_REG,
606 SP_CKDT_CHG | SP_SCDT_CHG);
607 if (err)
608 return err;
610 return 0;
613 static void anx78xx_poweron(struct anx78xx *anx78xx)
615 struct anx78xx_platform_data *pdata = &anx78xx->pdata;
616 int err;
618 if (WARN_ON(anx78xx->powered))
619 return;
621 if (pdata->dvdd10) {
622 err = regulator_enable(pdata->dvdd10);
623 if (err) {
624 DRM_ERROR("Failed to enable DVDD10 regulator: %d\n",
625 err);
626 return;
629 usleep_range(1000, 2000);
632 gpiod_set_value_cansleep(pdata->gpiod_reset, 1);
633 usleep_range(1000, 2000);
635 gpiod_set_value_cansleep(pdata->gpiod_pd, 0);
636 usleep_range(1000, 2000);
638 gpiod_set_value_cansleep(pdata->gpiod_reset, 0);
640 /* Power on registers module */
641 anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_POWERDOWN_CTRL_REG,
642 SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD | SP_LINK_PD);
643 anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], SP_POWERDOWN_CTRL_REG,
644 SP_REGISTER_PD | SP_TOTAL_PD);
646 anx78xx->powered = true;
649 static void anx78xx_poweroff(struct anx78xx *anx78xx)
651 struct anx78xx_platform_data *pdata = &anx78xx->pdata;
652 int err;
654 if (WARN_ON(!anx78xx->powered))
655 return;
657 gpiod_set_value_cansleep(pdata->gpiod_reset, 1);
658 usleep_range(1000, 2000);
660 gpiod_set_value_cansleep(pdata->gpiod_pd, 1);
661 usleep_range(1000, 2000);
663 if (pdata->dvdd10) {
664 err = regulator_disable(pdata->dvdd10);
665 if (err) {
666 DRM_ERROR("Failed to disable DVDD10 regulator: %d\n",
667 err);
668 return;
671 usleep_range(1000, 2000);
674 anx78xx->powered = false;
677 static int anx78xx_start(struct anx78xx *anx78xx)
679 int err;
681 /* Power on all modules */
682 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2],
683 SP_POWERDOWN_CTRL_REG,
684 SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD |
685 SP_LINK_PD);
687 err = anx78xx_enable_interrupts(anx78xx);
688 if (err) {
689 DRM_ERROR("Failed to enable interrupts: %d\n", err);
690 goto err_poweroff;
693 err = anx78xx_rx_initialization(anx78xx);
694 if (err) {
695 DRM_ERROR("Failed receiver initialization: %d\n", err);
696 goto err_poweroff;
699 err = anx78xx_tx_initialization(anx78xx);
700 if (err) {
701 DRM_ERROR("Failed transmitter initialization: %d\n", err);
702 goto err_poweroff;
706 * This delay seems to help keep the hardware in a good state. Without
707 * it, there are times where it fails silently.
709 usleep_range(10000, 15000);
711 return 0;
713 err_poweroff:
714 DRM_ERROR("Failed SlimPort transmitter initialization: %d\n", err);
715 anx78xx_poweroff(anx78xx);
717 return err;
720 static int anx78xx_init_pdata(struct anx78xx *anx78xx)
722 struct anx78xx_platform_data *pdata = &anx78xx->pdata;
723 struct device *dev = &anx78xx->client->dev;
725 /* 1.0V digital core power regulator */
726 pdata->dvdd10 = devm_regulator_get(dev, "dvdd10");
727 if (IS_ERR(pdata->dvdd10)) {
728 DRM_ERROR("DVDD10 regulator not found\n");
729 return PTR_ERR(pdata->dvdd10);
732 /* GPIO for HPD */
733 pdata->gpiod_hpd = devm_gpiod_get(dev, "hpd", GPIOD_IN);
734 if (IS_ERR(pdata->gpiod_hpd))
735 return PTR_ERR(pdata->gpiod_hpd);
737 /* GPIO for chip power down */
738 pdata->gpiod_pd = devm_gpiod_get(dev, "pd", GPIOD_OUT_HIGH);
739 if (IS_ERR(pdata->gpiod_pd))
740 return PTR_ERR(pdata->gpiod_pd);
742 /* GPIO for chip reset */
743 pdata->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
745 return PTR_ERR_OR_ZERO(pdata->gpiod_reset);
748 static int anx78xx_dp_link_training(struct anx78xx *anx78xx)
750 u8 dp_bw, value;
751 int err;
753 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG,
754 0x0);
755 if (err)
756 return err;
758 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2],
759 SP_POWERDOWN_CTRL_REG,
760 SP_TOTAL_PD);
761 if (err)
762 return err;
764 err = drm_dp_dpcd_readb(&anx78xx->aux, DP_MAX_LINK_RATE, &dp_bw);
765 if (err < 0)
766 return err;
768 switch (dp_bw) {
769 case DP_LINK_BW_1_62:
770 case DP_LINK_BW_2_7:
771 case DP_LINK_BW_5_4:
772 break;
774 default:
775 DRM_DEBUG_KMS("DP bandwidth (%#02x) not supported\n", dp_bw);
776 return -EINVAL;
779 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL1_REG,
780 SP_VIDEO_MUTE);
781 if (err)
782 return err;
784 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2],
785 SP_VID_CTRL1_REG, SP_VIDEO_EN);
786 if (err)
787 return err;
789 /* Get DPCD info */
790 err = drm_dp_dpcd_read(&anx78xx->aux, DP_DPCD_REV,
791 &anx78xx->dpcd, DP_RECEIVER_CAP_SIZE);
792 if (err < 0) {
793 DRM_ERROR("Failed to read DPCD: %d\n", err);
794 return err;
797 /* Clear channel x SERDES power down */
798 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0],
799 SP_DP_ANALOG_POWER_DOWN_REG, SP_CH0_PD);
800 if (err)
801 return err;
803 /* Check link capabilities */
804 err = drm_dp_link_probe(&anx78xx->aux, &anx78xx->link);
805 if (err < 0) {
806 DRM_ERROR("Failed to probe link capabilities: %d\n", err);
807 return err;
810 /* Power up the sink */
811 err = drm_dp_link_power_up(&anx78xx->aux, &anx78xx->link);
812 if (err < 0) {
813 DRM_ERROR("Failed to power up DisplayPort link: %d\n", err);
814 return err;
817 /* Possibly enable downspread on the sink */
818 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
819 SP_DP_DOWNSPREAD_CTRL1_REG, 0);
820 if (err)
821 return err;
823 if (anx78xx->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5) {
824 DRM_DEBUG("Enable downspread on the sink\n");
825 /* 4000PPM */
826 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
827 SP_DP_DOWNSPREAD_CTRL1_REG, 8);
828 if (err)
829 return err;
831 err = drm_dp_dpcd_writeb(&anx78xx->aux, DP_DOWNSPREAD_CTRL,
832 DP_SPREAD_AMP_0_5);
833 if (err < 0)
834 return err;
835 } else {
836 err = drm_dp_dpcd_writeb(&anx78xx->aux, DP_DOWNSPREAD_CTRL, 0);
837 if (err < 0)
838 return err;
841 /* Set the lane count and the link rate on the sink */
842 if (drm_dp_enhanced_frame_cap(anx78xx->dpcd))
843 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
844 SP_DP_SYSTEM_CTRL_BASE + 4,
845 SP_ENHANCED_MODE);
846 else
847 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0],
848 SP_DP_SYSTEM_CTRL_BASE + 4,
849 SP_ENHANCED_MODE);
850 if (err)
851 return err;
853 value = drm_dp_link_rate_to_bw_code(anx78xx->link.rate);
854 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
855 SP_DP_MAIN_LINK_BW_SET_REG, value);
856 if (err)
857 return err;
859 err = drm_dp_link_configure(&anx78xx->aux, &anx78xx->link);
860 if (err < 0) {
861 DRM_ERROR("Failed to configure DisplayPort link: %d\n", err);
862 return err;
865 /* Start training on the source */
866 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_LT_CTRL_REG,
867 SP_LT_EN);
868 if (err)
869 return err;
871 return 0;
874 static int anx78xx_config_dp_output(struct anx78xx *anx78xx)
876 int err;
878 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL1_REG,
879 SP_VIDEO_MUTE);
880 if (err)
881 return err;
883 /* Enable DP output */
884 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL1_REG,
885 SP_VIDEO_EN);
886 if (err)
887 return err;
889 return 0;
892 static int anx78xx_send_video_infoframe(struct anx78xx *anx78xx,
893 struct hdmi_avi_infoframe *frame)
895 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
896 int err;
898 err = hdmi_avi_infoframe_pack(frame, buffer, sizeof(buffer));
899 if (err < 0) {
900 DRM_ERROR("Failed to pack AVI infoframe: %d\n", err);
901 return err;
904 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0],
905 SP_PACKET_SEND_CTRL_REG, SP_AVI_IF_EN);
906 if (err)
907 return err;
909 err = regmap_bulk_write(anx78xx->map[I2C_IDX_TX_P2],
910 SP_INFOFRAME_AVI_DB1_REG, buffer,
911 frame->length);
912 if (err)
913 return err;
915 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
916 SP_PACKET_SEND_CTRL_REG, SP_AVI_IF_UD);
917 if (err)
918 return err;
920 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0],
921 SP_PACKET_SEND_CTRL_REG, SP_AVI_IF_EN);
922 if (err)
923 return err;
925 return 0;
928 static int anx78xx_get_downstream_info(struct anx78xx *anx78xx)
930 u8 value;
931 int err;
933 err = drm_dp_dpcd_readb(&anx78xx->aux, DP_SINK_COUNT, &value);
934 if (err < 0) {
935 DRM_ERROR("Get sink count failed %d\n", err);
936 return err;
939 if (!DP_GET_SINK_COUNT(value)) {
940 DRM_ERROR("Downstream disconnected\n");
941 return -EIO;
944 return 0;
947 static int anx78xx_get_modes(struct drm_connector *connector)
949 struct anx78xx *anx78xx = connector_to_anx78xx(connector);
950 int err, num_modes = 0;
952 if (WARN_ON(!anx78xx->powered))
953 return 0;
955 if (anx78xx->edid)
956 return drm_add_edid_modes(connector, anx78xx->edid);
958 mutex_lock(&anx78xx->lock);
960 err = anx78xx_get_downstream_info(anx78xx);
961 if (err) {
962 DRM_ERROR("Failed to get downstream info: %d\n", err);
963 goto unlock;
966 anx78xx->edid = drm_get_edid(connector, &anx78xx->aux.ddc);
967 if (!anx78xx->edid) {
968 DRM_ERROR("Failed to read EDID\n");
969 goto unlock;
972 err = drm_mode_connector_update_edid_property(connector,
973 anx78xx->edid);
974 if (err) {
975 DRM_ERROR("Failed to update EDID property: %d\n", err);
976 goto unlock;
979 num_modes = drm_add_edid_modes(connector, anx78xx->edid);
981 unlock:
982 mutex_unlock(&anx78xx->lock);
984 return num_modes;
987 static const struct drm_connector_helper_funcs anx78xx_connector_helper_funcs = {
988 .get_modes = anx78xx_get_modes,
991 static enum drm_connector_status anx78xx_detect(struct drm_connector *connector,
992 bool force)
994 struct anx78xx *anx78xx = connector_to_anx78xx(connector);
996 if (!gpiod_get_value(anx78xx->pdata.gpiod_hpd))
997 return connector_status_disconnected;
999 return connector_status_connected;
1002 static const struct drm_connector_funcs anx78xx_connector_funcs = {
1003 .fill_modes = drm_helper_probe_single_connector_modes,
1004 .detect = anx78xx_detect,
1005 .destroy = drm_connector_cleanup,
1006 .reset = drm_atomic_helper_connector_reset,
1007 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1008 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1011 static int anx78xx_bridge_attach(struct drm_bridge *bridge)
1013 struct anx78xx *anx78xx = bridge_to_anx78xx(bridge);
1014 int err;
1016 if (!bridge->encoder) {
1017 DRM_ERROR("Parent encoder object not found");
1018 return -ENODEV;
1021 /* Register aux channel */
1022 anx78xx->aux.name = "DP-AUX";
1023 anx78xx->aux.dev = &anx78xx->client->dev;
1024 anx78xx->aux.transfer = anx78xx_aux_transfer;
1026 err = drm_dp_aux_register(&anx78xx->aux);
1027 if (err < 0) {
1028 DRM_ERROR("Failed to register aux channel: %d\n", err);
1029 return err;
1032 err = drm_connector_init(bridge->dev, &anx78xx->connector,
1033 &anx78xx_connector_funcs,
1034 DRM_MODE_CONNECTOR_DisplayPort);
1035 if (err) {
1036 DRM_ERROR("Failed to initialize connector: %d\n", err);
1037 return err;
1040 drm_connector_helper_add(&anx78xx->connector,
1041 &anx78xx_connector_helper_funcs);
1043 err = drm_connector_register(&anx78xx->connector);
1044 if (err) {
1045 DRM_ERROR("Failed to register connector: %d\n", err);
1046 return err;
1049 anx78xx->connector.polled = DRM_CONNECTOR_POLL_HPD;
1051 err = drm_mode_connector_attach_encoder(&anx78xx->connector,
1052 bridge->encoder);
1053 if (err) {
1054 DRM_ERROR("Failed to link up connector to encoder: %d\n", err);
1055 return err;
1058 return 0;
1061 static enum drm_mode_status
1062 anx78xx_bridge_mode_valid(struct drm_bridge *bridge,
1063 const struct drm_display_mode *mode)
1065 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1066 return MODE_NO_INTERLACE;
1068 /* Max 1200p at 5.4 Ghz, one lane */
1069 if (mode->clock > 154000)
1070 return MODE_CLOCK_HIGH;
1072 return MODE_OK;
1075 static void anx78xx_bridge_disable(struct drm_bridge *bridge)
1077 struct anx78xx *anx78xx = bridge_to_anx78xx(bridge);
1079 /* Power off all modules except configuration registers access */
1080 anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_POWERDOWN_CTRL_REG,
1081 SP_HDCP_PD | SP_AUDIO_PD | SP_VIDEO_PD | SP_LINK_PD);
1084 static void anx78xx_bridge_mode_set(struct drm_bridge *bridge,
1085 struct drm_display_mode *mode,
1086 struct drm_display_mode *adjusted_mode)
1088 struct anx78xx *anx78xx = bridge_to_anx78xx(bridge);
1089 struct hdmi_avi_infoframe frame;
1090 int err;
1092 if (WARN_ON(!anx78xx->powered))
1093 return;
1095 mutex_lock(&anx78xx->lock);
1097 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, adjusted_mode,
1098 false);
1099 if (err) {
1100 DRM_ERROR("Failed to setup AVI infoframe: %d\n", err);
1101 goto unlock;
1104 err = anx78xx_send_video_infoframe(anx78xx, &frame);
1105 if (err)
1106 DRM_ERROR("Failed to send AVI infoframe: %d\n", err);
1108 unlock:
1109 mutex_unlock(&anx78xx->lock);
1112 static void anx78xx_bridge_enable(struct drm_bridge *bridge)
1114 struct anx78xx *anx78xx = bridge_to_anx78xx(bridge);
1115 int err;
1117 err = anx78xx_start(anx78xx);
1118 if (err) {
1119 DRM_ERROR("Failed to initialize: %d\n", err);
1120 return;
1123 err = anx78xx_set_hpd(anx78xx);
1124 if (err)
1125 DRM_ERROR("Failed to set HPD: %d\n", err);
1128 static const struct drm_bridge_funcs anx78xx_bridge_funcs = {
1129 .attach = anx78xx_bridge_attach,
1130 .mode_valid = anx78xx_bridge_mode_valid,
1131 .disable = anx78xx_bridge_disable,
1132 .mode_set = anx78xx_bridge_mode_set,
1133 .enable = anx78xx_bridge_enable,
1136 static irqreturn_t anx78xx_hpd_threaded_handler(int irq, void *data)
1138 struct anx78xx *anx78xx = data;
1139 int err;
1141 if (anx78xx->powered)
1142 return IRQ_HANDLED;
1144 mutex_lock(&anx78xx->lock);
1146 /* Cable is pulled, power on the chip */
1147 anx78xx_poweron(anx78xx);
1149 err = anx78xx_enable_interrupts(anx78xx);
1150 if (err)
1151 DRM_ERROR("Failed to enable interrupts: %d\n", err);
1153 mutex_unlock(&anx78xx->lock);
1155 return IRQ_HANDLED;
1158 static int anx78xx_handle_dp_int_1(struct anx78xx *anx78xx, u8 irq)
1160 int err;
1162 DRM_DEBUG_KMS("Handle DP interrupt 1: %02x\n", irq);
1164 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_DP_INT_STATUS1_REG,
1165 irq);
1166 if (err)
1167 return err;
1169 if (irq & SP_TRAINING_FINISH) {
1170 DRM_DEBUG_KMS("IRQ: hardware link training finished\n");
1171 err = anx78xx_config_dp_output(anx78xx);
1174 return err;
1177 static bool anx78xx_handle_common_int_4(struct anx78xx *anx78xx, u8 irq)
1179 bool event = false;
1180 int err;
1182 DRM_DEBUG_KMS("Handle common interrupt 4: %02x\n", irq);
1184 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2],
1185 SP_COMMON_INT_STATUS4_REG, irq);
1186 if (err) {
1187 DRM_ERROR("Failed to write SP_COMMON_INT_STATUS4 %d\n", err);
1188 return event;
1191 if (irq & SP_HPD_LOST) {
1192 DRM_DEBUG_KMS("IRQ: Hot plug detect - cable is pulled out\n");
1193 event = true;
1194 anx78xx_poweroff(anx78xx);
1195 /* Free cached EDID */
1196 kfree(anx78xx->edid);
1197 anx78xx->edid = NULL;
1198 } else if (irq & SP_HPD_PLUG) {
1199 DRM_DEBUG_KMS("IRQ: Hot plug detect - cable plug\n");
1200 event = true;
1203 return event;
1206 static void anx78xx_handle_hdmi_int_1(struct anx78xx *anx78xx, u8 irq)
1208 unsigned int value;
1209 int err;
1211 DRM_DEBUG_KMS("Handle HDMI interrupt 1: %02x\n", irq);
1213 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_INT_STATUS1_REG,
1214 irq);
1215 if (err) {
1216 DRM_ERROR("Write HDMI int 1 failed: %d\n", err);
1217 return;
1220 if ((irq & SP_CKDT_CHG) || (irq & SP_SCDT_CHG)) {
1221 DRM_DEBUG_KMS("IRQ: HDMI input detected\n");
1223 err = regmap_read(anx78xx->map[I2C_IDX_RX_P0],
1224 SP_SYSTEM_STATUS_REG, &value);
1225 if (err) {
1226 DRM_ERROR("Read system status reg failed: %d\n", err);
1227 return;
1230 if (!(value & SP_TMDS_CLOCK_DET)) {
1231 DRM_DEBUG_KMS("IRQ: *** Waiting for HDMI clock ***\n");
1232 return;
1235 if (!(value & SP_TMDS_DE_DET)) {
1236 DRM_DEBUG_KMS("IRQ: *** Waiting for HDMI signal ***\n");
1237 return;
1240 err = anx78xx_dp_link_training(anx78xx);
1241 if (err)
1242 DRM_ERROR("Failed to start link training: %d\n", err);
1246 static irqreturn_t anx78xx_intp_threaded_handler(int unused, void *data)
1248 struct anx78xx *anx78xx = data;
1249 bool event = false;
1250 unsigned int irq;
1251 int err;
1253 mutex_lock(&anx78xx->lock);
1255 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DP_INT_STATUS1_REG,
1256 &irq);
1257 if (err) {
1258 DRM_ERROR("Failed to read DP interrupt 1 status: %d\n", err);
1259 goto unlock;
1262 if (irq)
1263 anx78xx_handle_dp_int_1(anx78xx, irq);
1265 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2],
1266 SP_COMMON_INT_STATUS4_REG, &irq);
1267 if (err) {
1268 DRM_ERROR("Failed to read common interrupt 4 status: %d\n",
1269 err);
1270 goto unlock;
1273 if (irq)
1274 event = anx78xx_handle_common_int_4(anx78xx, irq);
1276 /* Make sure we are still powered after handle HPD events */
1277 if (!anx78xx->powered)
1278 goto unlock;
1280 err = regmap_read(anx78xx->map[I2C_IDX_RX_P0], SP_INT_STATUS1_REG,
1281 &irq);
1282 if (err) {
1283 DRM_ERROR("Failed to read HDMI int 1 status: %d\n", err);
1284 goto unlock;
1287 if (irq)
1288 anx78xx_handle_hdmi_int_1(anx78xx, irq);
1290 unlock:
1291 mutex_unlock(&anx78xx->lock);
1293 if (event)
1294 drm_helper_hpd_irq_event(anx78xx->connector.dev);
1296 return IRQ_HANDLED;
1299 static void unregister_i2c_dummy_clients(struct anx78xx *anx78xx)
1301 unsigned int i;
1303 for (i = 0; i < ARRAY_SIZE(anx78xx->i2c_dummy); i++)
1304 if (anx78xx->i2c_dummy[i])
1305 i2c_unregister_device(anx78xx->i2c_dummy[i]);
1308 static const struct regmap_config anx78xx_regmap_config = {
1309 .reg_bits = 8,
1310 .val_bits = 8,
1313 static const u16 anx78xx_chipid_list[] = {
1314 0x7812,
1315 0x7814,
1316 0x7818,
1319 static int anx78xx_i2c_probe(struct i2c_client *client,
1320 const struct i2c_device_id *id)
1322 struct anx78xx *anx78xx;
1323 struct anx78xx_platform_data *pdata;
1324 unsigned int i, idl, idh, version;
1325 bool found = false;
1326 int err;
1328 anx78xx = devm_kzalloc(&client->dev, sizeof(*anx78xx), GFP_KERNEL);
1329 if (!anx78xx)
1330 return -ENOMEM;
1332 pdata = &anx78xx->pdata;
1334 mutex_init(&anx78xx->lock);
1336 #if IS_ENABLED(CONFIG_OF)
1337 anx78xx->bridge.of_node = client->dev.of_node;
1338 #endif
1340 anx78xx->client = client;
1341 i2c_set_clientdata(client, anx78xx);
1343 err = anx78xx_init_pdata(anx78xx);
1344 if (err) {
1345 DRM_ERROR("Failed to initialize pdata: %d\n", err);
1346 return err;
1349 pdata->hpd_irq = gpiod_to_irq(pdata->gpiod_hpd);
1350 if (pdata->hpd_irq < 0) {
1351 DRM_ERROR("Failed to get HPD IRQ: %d\n", pdata->hpd_irq);
1352 return -ENODEV;
1355 pdata->intp_irq = client->irq;
1356 if (!pdata->intp_irq) {
1357 DRM_ERROR("Failed to get CABLE_DET and INTP IRQ\n");
1358 return -ENODEV;
1361 /* Map slave addresses of ANX7814 */
1362 for (i = 0; i < I2C_NUM_ADDRESSES; i++) {
1363 anx78xx->i2c_dummy[i] = i2c_new_dummy(client->adapter,
1364 anx78xx_i2c_addresses[i] >> 1);
1365 if (!anx78xx->i2c_dummy[i]) {
1366 err = -ENOMEM;
1367 DRM_ERROR("Failed to reserve I2C bus %02x\n",
1368 anx78xx_i2c_addresses[i]);
1369 goto err_unregister_i2c;
1372 anx78xx->map[i] = devm_regmap_init_i2c(anx78xx->i2c_dummy[i],
1373 &anx78xx_regmap_config);
1374 if (IS_ERR(anx78xx->map[i])) {
1375 err = PTR_ERR(anx78xx->map[i]);
1376 DRM_ERROR("Failed regmap initialization %02x\n",
1377 anx78xx_i2c_addresses[i]);
1378 goto err_unregister_i2c;
1382 /* Look for supported chip ID */
1383 anx78xx_poweron(anx78xx);
1385 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DEVICE_IDL_REG,
1386 &idl);
1387 if (err)
1388 goto err_poweroff;
1390 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DEVICE_IDH_REG,
1391 &idh);
1392 if (err)
1393 goto err_poweroff;
1395 anx78xx->chipid = (u8)idl | ((u8)idh << 8);
1397 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DEVICE_VERSION_REG,
1398 &version);
1399 if (err)
1400 goto err_poweroff;
1402 for (i = 0; i < ARRAY_SIZE(anx78xx_chipid_list); i++) {
1403 if (anx78xx->chipid == anx78xx_chipid_list[i]) {
1404 DRM_INFO("Found ANX%x (ver. %d) SlimPort Transmitter\n",
1405 anx78xx->chipid, version);
1406 found = true;
1407 break;
1411 if (!found) {
1412 DRM_ERROR("ANX%x (ver. %d) not supported by this driver\n",
1413 anx78xx->chipid, version);
1414 err = -ENODEV;
1415 goto err_poweroff;
1418 err = devm_request_threaded_irq(&client->dev, pdata->hpd_irq, NULL,
1419 anx78xx_hpd_threaded_handler,
1420 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
1421 "anx78xx-hpd", anx78xx);
1422 if (err) {
1423 DRM_ERROR("Failed to request CABLE_DET threaded IRQ: %d\n",
1424 err);
1425 goto err_poweroff;
1428 err = devm_request_threaded_irq(&client->dev, pdata->intp_irq, NULL,
1429 anx78xx_intp_threaded_handler,
1430 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
1431 "anx78xx-intp", anx78xx);
1432 if (err) {
1433 DRM_ERROR("Failed to request INTP threaded IRQ: %d\n", err);
1434 goto err_poweroff;
1437 anx78xx->bridge.funcs = &anx78xx_bridge_funcs;
1439 drm_bridge_add(&anx78xx->bridge);
1441 /* If cable is pulled out, just poweroff and wait for HPD event */
1442 if (!gpiod_get_value(anx78xx->pdata.gpiod_hpd))
1443 anx78xx_poweroff(anx78xx);
1445 return 0;
1447 err_poweroff:
1448 anx78xx_poweroff(anx78xx);
1450 err_unregister_i2c:
1451 unregister_i2c_dummy_clients(anx78xx);
1452 return err;
1455 static int anx78xx_i2c_remove(struct i2c_client *client)
1457 struct anx78xx *anx78xx = i2c_get_clientdata(client);
1459 drm_bridge_remove(&anx78xx->bridge);
1461 unregister_i2c_dummy_clients(anx78xx);
1463 kfree(anx78xx->edid);
1465 return 0;
1468 static const struct i2c_device_id anx78xx_id[] = {
1469 { "anx7814", 0 },
1470 { /* sentinel */ }
1472 MODULE_DEVICE_TABLE(i2c, anx78xx_id);
1474 #if IS_ENABLED(CONFIG_OF)
1475 static const struct of_device_id anx78xx_match_table[] = {
1476 { .compatible = "analogix,anx7814", },
1477 { /* sentinel */ },
1479 MODULE_DEVICE_TABLE(of, anx78xx_match_table);
1480 #endif
1482 static struct i2c_driver anx78xx_driver = {
1483 .driver = {
1484 .name = "anx7814",
1485 .of_match_table = of_match_ptr(anx78xx_match_table),
1487 .probe = anx78xx_i2c_probe,
1488 .remove = anx78xx_i2c_remove,
1489 .id_table = anx78xx_id,
1491 module_i2c_driver(anx78xx_driver);
1493 MODULE_DESCRIPTION("ANX78xx SlimPort Transmitter driver");
1494 MODULE_AUTHOR("Enric Balletbo i Serra <enric.balletbo@collabora.com>");
1495 MODULE_LICENSE("GPL v2");