2 * Copyright (C) 2013 NVIDIA Corporation
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 as
6 * published by the Free Software Foundation.
10 #include <linux/delay.h>
11 #include <linux/gpio.h>
12 #include <linux/interrupt.h>
14 #include <linux/of_gpio.h>
15 #include <linux/pinctrl/pinconf-generic.h>
16 #include <linux/pinctrl/pinctrl.h>
17 #include <linux/pinctrl/pinmux.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/platform_device.h>
20 #include <linux/reset.h>
21 #include <linux/regulator/consumer.h>
22 #include <linux/workqueue.h>
24 #include <drm/drm_dp_helper.h>
25 #include <drm/drm_panel.h>
31 static DEFINE_MUTEX(dpaux_lock
);
32 static LIST_HEAD(dpaux_list
);
35 struct drm_dp_aux aux
;
41 struct tegra_output
*output
;
43 struct reset_control
*rst
;
44 struct clk
*clk_parent
;
47 struct regulator
*vdd
;
49 struct completion complete
;
50 struct work_struct work
;
51 struct list_head list
;
53 #ifdef CONFIG_GENERIC_PINCONF
54 struct pinctrl_dev
*pinctrl
;
55 struct pinctrl_desc desc
;
59 static inline struct tegra_dpaux
*to_dpaux(struct drm_dp_aux
*aux
)
61 return container_of(aux
, struct tegra_dpaux
, aux
);
64 static inline struct tegra_dpaux
*work_to_dpaux(struct work_struct
*work
)
66 return container_of(work
, struct tegra_dpaux
, work
);
69 static inline u32
tegra_dpaux_readl(struct tegra_dpaux
*dpaux
,
72 u32 value
= readl(dpaux
->regs
+ (offset
<< 2));
74 trace_dpaux_readl(dpaux
->dev
, offset
, value
);
79 static inline void tegra_dpaux_writel(struct tegra_dpaux
*dpaux
,
80 u32 value
, unsigned int offset
)
82 trace_dpaux_writel(dpaux
->dev
, offset
, value
);
83 writel(value
, dpaux
->regs
+ (offset
<< 2));
86 static void tegra_dpaux_write_fifo(struct tegra_dpaux
*dpaux
, const u8
*buffer
,
91 for (i
= 0; i
< DIV_ROUND_UP(size
, 4); i
++) {
92 size_t num
= min_t(size_t, size
- i
* 4, 4);
95 for (j
= 0; j
< num
; j
++)
96 value
|= buffer
[i
* 4 + j
] << (j
* 8);
98 tegra_dpaux_writel(dpaux
, value
, DPAUX_DP_AUXDATA_WRITE(i
));
102 static void tegra_dpaux_read_fifo(struct tegra_dpaux
*dpaux
, u8
*buffer
,
107 for (i
= 0; i
< DIV_ROUND_UP(size
, 4); i
++) {
108 size_t num
= min_t(size_t, size
- i
* 4, 4);
111 value
= tegra_dpaux_readl(dpaux
, DPAUX_DP_AUXDATA_READ(i
));
113 for (j
= 0; j
< num
; j
++)
114 buffer
[i
* 4 + j
] = value
>> (j
* 8);
118 static ssize_t
tegra_dpaux_transfer(struct drm_dp_aux
*aux
,
119 struct drm_dp_aux_msg
*msg
)
121 unsigned long timeout
= msecs_to_jiffies(250);
122 struct tegra_dpaux
*dpaux
= to_dpaux(aux
);
123 unsigned long status
;
127 /* Tegra has 4x4 byte DP AUX transmit and receive FIFOs. */
132 * Allow zero-sized messages only for I2C, in which case they specify
133 * address-only transactions.
136 switch (msg
->request
& ~DP_AUX_I2C_MOT
) {
137 case DP_AUX_I2C_WRITE_STATUS_UPDATE
:
138 case DP_AUX_I2C_WRITE
:
139 case DP_AUX_I2C_READ
:
140 value
= DPAUX_DP_AUXCTL_CMD_ADDRESS_ONLY
;
147 /* For non-zero-sized messages, set the CMDLEN field. */
148 value
= DPAUX_DP_AUXCTL_CMDLEN(msg
->size
- 1);
151 switch (msg
->request
& ~DP_AUX_I2C_MOT
) {
152 case DP_AUX_I2C_WRITE
:
153 if (msg
->request
& DP_AUX_I2C_MOT
)
154 value
|= DPAUX_DP_AUXCTL_CMD_MOT_WR
;
156 value
|= DPAUX_DP_AUXCTL_CMD_I2C_WR
;
160 case DP_AUX_I2C_READ
:
161 if (msg
->request
& DP_AUX_I2C_MOT
)
162 value
|= DPAUX_DP_AUXCTL_CMD_MOT_RD
;
164 value
|= DPAUX_DP_AUXCTL_CMD_I2C_RD
;
168 case DP_AUX_I2C_WRITE_STATUS_UPDATE
:
169 if (msg
->request
& DP_AUX_I2C_MOT
)
170 value
|= DPAUX_DP_AUXCTL_CMD_MOT_RQ
;
172 value
|= DPAUX_DP_AUXCTL_CMD_I2C_RQ
;
176 case DP_AUX_NATIVE_WRITE
:
177 value
|= DPAUX_DP_AUXCTL_CMD_AUX_WR
;
180 case DP_AUX_NATIVE_READ
:
181 value
|= DPAUX_DP_AUXCTL_CMD_AUX_RD
;
188 tegra_dpaux_writel(dpaux
, msg
->address
, DPAUX_DP_AUXADDR
);
189 tegra_dpaux_writel(dpaux
, value
, DPAUX_DP_AUXCTL
);
191 if ((msg
->request
& DP_AUX_I2C_READ
) == 0) {
192 tegra_dpaux_write_fifo(dpaux
, msg
->buffer
, msg
->size
);
196 /* start transaction */
197 value
= tegra_dpaux_readl(dpaux
, DPAUX_DP_AUXCTL
);
198 value
|= DPAUX_DP_AUXCTL_TRANSACTREQ
;
199 tegra_dpaux_writel(dpaux
, value
, DPAUX_DP_AUXCTL
);
201 status
= wait_for_completion_timeout(&dpaux
->complete
, timeout
);
205 /* read status and clear errors */
206 value
= tegra_dpaux_readl(dpaux
, DPAUX_DP_AUXSTAT
);
207 tegra_dpaux_writel(dpaux
, 0xf00, DPAUX_DP_AUXSTAT
);
209 if (value
& DPAUX_DP_AUXSTAT_TIMEOUT_ERROR
)
212 if ((value
& DPAUX_DP_AUXSTAT_RX_ERROR
) ||
213 (value
& DPAUX_DP_AUXSTAT_SINKSTAT_ERROR
) ||
214 (value
& DPAUX_DP_AUXSTAT_NO_STOP_ERROR
))
217 switch ((value
& DPAUX_DP_AUXSTAT_REPLY_TYPE_MASK
) >> 16) {
219 msg
->reply
= DP_AUX_NATIVE_REPLY_ACK
;
223 msg
->reply
= DP_AUX_NATIVE_REPLY_NACK
;
227 msg
->reply
= DP_AUX_NATIVE_REPLY_DEFER
;
231 msg
->reply
= DP_AUX_I2C_REPLY_NACK
;
235 msg
->reply
= DP_AUX_I2C_REPLY_DEFER
;
239 if ((msg
->size
> 0) && (msg
->reply
== DP_AUX_NATIVE_REPLY_ACK
)) {
240 if (msg
->request
& DP_AUX_I2C_READ
) {
241 size_t count
= value
& DPAUX_DP_AUXSTAT_REPLY_MASK
;
243 if (WARN_ON(count
!= msg
->size
))
244 count
= min_t(size_t, count
, msg
->size
);
246 tegra_dpaux_read_fifo(dpaux
, msg
->buffer
, count
);
254 static void tegra_dpaux_hotplug(struct work_struct
*work
)
256 struct tegra_dpaux
*dpaux
= work_to_dpaux(work
);
259 drm_helper_hpd_irq_event(dpaux
->output
->connector
.dev
);
262 static irqreturn_t
tegra_dpaux_irq(int irq
, void *data
)
264 struct tegra_dpaux
*dpaux
= data
;
265 irqreturn_t ret
= IRQ_HANDLED
;
268 /* clear interrupts */
269 value
= tegra_dpaux_readl(dpaux
, DPAUX_INTR_AUX
);
270 tegra_dpaux_writel(dpaux
, value
, DPAUX_INTR_AUX
);
272 if (value
& (DPAUX_INTR_PLUG_EVENT
| DPAUX_INTR_UNPLUG_EVENT
))
273 schedule_work(&dpaux
->work
);
275 if (value
& DPAUX_INTR_IRQ_EVENT
) {
276 /* TODO: handle this */
279 if (value
& DPAUX_INTR_AUX_DONE
)
280 complete(&dpaux
->complete
);
285 enum tegra_dpaux_functions
{
286 DPAUX_PADCTL_FUNC_AUX
,
287 DPAUX_PADCTL_FUNC_I2C
,
288 DPAUX_PADCTL_FUNC_OFF
,
291 static void tegra_dpaux_pad_power_down(struct tegra_dpaux
*dpaux
)
293 u32 value
= tegra_dpaux_readl(dpaux
, DPAUX_HYBRID_SPARE
);
295 value
|= DPAUX_HYBRID_SPARE_PAD_POWER_DOWN
;
297 tegra_dpaux_writel(dpaux
, value
, DPAUX_HYBRID_SPARE
);
300 static void tegra_dpaux_pad_power_up(struct tegra_dpaux
*dpaux
)
302 u32 value
= tegra_dpaux_readl(dpaux
, DPAUX_HYBRID_SPARE
);
304 value
&= ~DPAUX_HYBRID_SPARE_PAD_POWER_DOWN
;
306 tegra_dpaux_writel(dpaux
, value
, DPAUX_HYBRID_SPARE
);
309 static int tegra_dpaux_pad_config(struct tegra_dpaux
*dpaux
, unsigned function
)
314 case DPAUX_PADCTL_FUNC_AUX
:
315 value
= DPAUX_HYBRID_PADCTL_AUX_CMH(2) |
316 DPAUX_HYBRID_PADCTL_AUX_DRVZ(4) |
317 DPAUX_HYBRID_PADCTL_AUX_DRVI(0x18) |
318 DPAUX_HYBRID_PADCTL_AUX_INPUT_RCV
|
319 DPAUX_HYBRID_PADCTL_MODE_AUX
;
322 case DPAUX_PADCTL_FUNC_I2C
:
323 value
= DPAUX_HYBRID_PADCTL_I2C_SDA_INPUT_RCV
|
324 DPAUX_HYBRID_PADCTL_I2C_SCL_INPUT_RCV
|
325 DPAUX_HYBRID_PADCTL_AUX_CMH(2) |
326 DPAUX_HYBRID_PADCTL_AUX_DRVZ(4) |
327 DPAUX_HYBRID_PADCTL_AUX_DRVI(0x18) |
328 DPAUX_HYBRID_PADCTL_MODE_I2C
;
331 case DPAUX_PADCTL_FUNC_OFF
:
332 tegra_dpaux_pad_power_down(dpaux
);
339 tegra_dpaux_writel(dpaux
, value
, DPAUX_HYBRID_PADCTL
);
340 tegra_dpaux_pad_power_up(dpaux
);
345 #ifdef CONFIG_GENERIC_PINCONF
346 static const struct pinctrl_pin_desc tegra_dpaux_pins
[] = {
347 PINCTRL_PIN(0, "DP_AUX_CHx_P"),
348 PINCTRL_PIN(1, "DP_AUX_CHx_N"),
351 static const unsigned tegra_dpaux_pin_numbers
[] = { 0, 1 };
353 static const char * const tegra_dpaux_groups
[] = {
357 static const char * const tegra_dpaux_functions
[] = {
363 static int tegra_dpaux_get_groups_count(struct pinctrl_dev
*pinctrl
)
365 return ARRAY_SIZE(tegra_dpaux_groups
);
368 static const char *tegra_dpaux_get_group_name(struct pinctrl_dev
*pinctrl
,
371 return tegra_dpaux_groups
[group
];
374 static int tegra_dpaux_get_group_pins(struct pinctrl_dev
*pinctrl
,
375 unsigned group
, const unsigned **pins
,
378 *pins
= tegra_dpaux_pin_numbers
;
379 *num_pins
= ARRAY_SIZE(tegra_dpaux_pin_numbers
);
384 static const struct pinctrl_ops tegra_dpaux_pinctrl_ops
= {
385 .get_groups_count
= tegra_dpaux_get_groups_count
,
386 .get_group_name
= tegra_dpaux_get_group_name
,
387 .get_group_pins
= tegra_dpaux_get_group_pins
,
388 .dt_node_to_map
= pinconf_generic_dt_node_to_map_group
,
389 .dt_free_map
= pinconf_generic_dt_free_map
,
392 static int tegra_dpaux_get_functions_count(struct pinctrl_dev
*pinctrl
)
394 return ARRAY_SIZE(tegra_dpaux_functions
);
397 static const char *tegra_dpaux_get_function_name(struct pinctrl_dev
*pinctrl
,
398 unsigned int function
)
400 return tegra_dpaux_functions
[function
];
403 static int tegra_dpaux_get_function_groups(struct pinctrl_dev
*pinctrl
,
404 unsigned int function
,
405 const char * const **groups
,
406 unsigned * const num_groups
)
408 *num_groups
= ARRAY_SIZE(tegra_dpaux_groups
);
409 *groups
= tegra_dpaux_groups
;
414 static int tegra_dpaux_set_mux(struct pinctrl_dev
*pinctrl
,
415 unsigned int function
, unsigned int group
)
417 struct tegra_dpaux
*dpaux
= pinctrl_dev_get_drvdata(pinctrl
);
419 return tegra_dpaux_pad_config(dpaux
, function
);
422 static const struct pinmux_ops tegra_dpaux_pinmux_ops
= {
423 .get_functions_count
= tegra_dpaux_get_functions_count
,
424 .get_function_name
= tegra_dpaux_get_function_name
,
425 .get_function_groups
= tegra_dpaux_get_function_groups
,
426 .set_mux
= tegra_dpaux_set_mux
,
430 static int tegra_dpaux_probe(struct platform_device
*pdev
)
432 struct tegra_dpaux
*dpaux
;
433 struct resource
*regs
;
437 dpaux
= devm_kzalloc(&pdev
->dev
, sizeof(*dpaux
), GFP_KERNEL
);
441 INIT_WORK(&dpaux
->work
, tegra_dpaux_hotplug
);
442 init_completion(&dpaux
->complete
);
443 INIT_LIST_HEAD(&dpaux
->list
);
444 dpaux
->dev
= &pdev
->dev
;
446 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
447 dpaux
->regs
= devm_ioremap_resource(&pdev
->dev
, regs
);
448 if (IS_ERR(dpaux
->regs
))
449 return PTR_ERR(dpaux
->regs
);
451 dpaux
->irq
= platform_get_irq(pdev
, 0);
452 if (dpaux
->irq
< 0) {
453 dev_err(&pdev
->dev
, "failed to get IRQ\n");
457 if (!pdev
->dev
.pm_domain
) {
458 dpaux
->rst
= devm_reset_control_get(&pdev
->dev
, "dpaux");
459 if (IS_ERR(dpaux
->rst
)) {
461 "failed to get reset control: %ld\n",
462 PTR_ERR(dpaux
->rst
));
463 return PTR_ERR(dpaux
->rst
);
467 dpaux
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
468 if (IS_ERR(dpaux
->clk
)) {
469 dev_err(&pdev
->dev
, "failed to get module clock: %ld\n",
470 PTR_ERR(dpaux
->clk
));
471 return PTR_ERR(dpaux
->clk
);
474 dpaux
->clk_parent
= devm_clk_get(&pdev
->dev
, "parent");
475 if (IS_ERR(dpaux
->clk_parent
)) {
476 dev_err(&pdev
->dev
, "failed to get parent clock: %ld\n",
477 PTR_ERR(dpaux
->clk_parent
));
478 return PTR_ERR(dpaux
->clk_parent
);
481 err
= clk_set_rate(dpaux
->clk_parent
, 270000000);
483 dev_err(&pdev
->dev
, "failed to set clock to 270 MHz: %d\n",
488 dpaux
->vdd
= devm_regulator_get(&pdev
->dev
, "vdd");
489 if (IS_ERR(dpaux
->vdd
)) {
490 dev_err(&pdev
->dev
, "failed to get VDD supply: %ld\n",
491 PTR_ERR(dpaux
->vdd
));
492 return PTR_ERR(dpaux
->vdd
);
495 platform_set_drvdata(pdev
, dpaux
);
496 pm_runtime_enable(&pdev
->dev
);
497 pm_runtime_get_sync(&pdev
->dev
);
499 err
= devm_request_irq(dpaux
->dev
, dpaux
->irq
, tegra_dpaux_irq
, 0,
500 dev_name(dpaux
->dev
), dpaux
);
502 dev_err(dpaux
->dev
, "failed to request IRQ#%u: %d\n",
507 disable_irq(dpaux
->irq
);
509 dpaux
->aux
.transfer
= tegra_dpaux_transfer
;
510 dpaux
->aux
.dev
= &pdev
->dev
;
512 err
= drm_dp_aux_register(&dpaux
->aux
);
517 * Assume that by default the DPAUX/I2C pads will be used for HDMI,
518 * so power them up and configure them in I2C mode.
520 * The DPAUX code paths reconfigure the pads in AUX mode, but there
521 * is no possibility to perform the I2C mode configuration in the
524 err
= tegra_dpaux_pad_config(dpaux
, DPAUX_HYBRID_PADCTL_MODE_I2C
);
528 #ifdef CONFIG_GENERIC_PINCONF
529 dpaux
->desc
.name
= dev_name(&pdev
->dev
);
530 dpaux
->desc
.pins
= tegra_dpaux_pins
;
531 dpaux
->desc
.npins
= ARRAY_SIZE(tegra_dpaux_pins
);
532 dpaux
->desc
.pctlops
= &tegra_dpaux_pinctrl_ops
;
533 dpaux
->desc
.pmxops
= &tegra_dpaux_pinmux_ops
;
534 dpaux
->desc
.owner
= THIS_MODULE
;
536 dpaux
->pinctrl
= devm_pinctrl_register(&pdev
->dev
, &dpaux
->desc
, dpaux
);
537 if (IS_ERR(dpaux
->pinctrl
)) {
538 dev_err(&pdev
->dev
, "failed to register pincontrol\n");
539 return PTR_ERR(dpaux
->pinctrl
);
542 /* enable and clear all interrupts */
543 value
= DPAUX_INTR_AUX_DONE
| DPAUX_INTR_IRQ_EVENT
|
544 DPAUX_INTR_UNPLUG_EVENT
| DPAUX_INTR_PLUG_EVENT
;
545 tegra_dpaux_writel(dpaux
, value
, DPAUX_INTR_EN_AUX
);
546 tegra_dpaux_writel(dpaux
, value
, DPAUX_INTR_AUX
);
548 mutex_lock(&dpaux_lock
);
549 list_add_tail(&dpaux
->list
, &dpaux_list
);
550 mutex_unlock(&dpaux_lock
);
555 static int tegra_dpaux_remove(struct platform_device
*pdev
)
557 struct tegra_dpaux
*dpaux
= platform_get_drvdata(pdev
);
559 cancel_work_sync(&dpaux
->work
);
561 /* make sure pads are powered down when not in use */
562 tegra_dpaux_pad_power_down(dpaux
);
564 pm_runtime_put(&pdev
->dev
);
565 pm_runtime_disable(&pdev
->dev
);
567 drm_dp_aux_unregister(&dpaux
->aux
);
569 mutex_lock(&dpaux_lock
);
570 list_del(&dpaux
->list
);
571 mutex_unlock(&dpaux_lock
);
577 static int tegra_dpaux_suspend(struct device
*dev
)
579 struct tegra_dpaux
*dpaux
= dev_get_drvdata(dev
);
583 err
= reset_control_assert(dpaux
->rst
);
585 dev_err(dev
, "failed to assert reset: %d\n", err
);
590 usleep_range(1000, 2000);
592 clk_disable_unprepare(dpaux
->clk_parent
);
593 clk_disable_unprepare(dpaux
->clk
);
598 static int tegra_dpaux_resume(struct device
*dev
)
600 struct tegra_dpaux
*dpaux
= dev_get_drvdata(dev
);
603 err
= clk_prepare_enable(dpaux
->clk
);
605 dev_err(dev
, "failed to enable clock: %d\n", err
);
609 err
= clk_prepare_enable(dpaux
->clk_parent
);
611 dev_err(dev
, "failed to enable parent clock: %d\n", err
);
615 usleep_range(1000, 2000);
618 err
= reset_control_deassert(dpaux
->rst
);
620 dev_err(dev
, "failed to deassert reset: %d\n", err
);
624 usleep_range(1000, 2000);
630 clk_disable_unprepare(dpaux
->clk_parent
);
632 clk_disable_unprepare(dpaux
->clk
);
637 static const struct dev_pm_ops tegra_dpaux_pm_ops
= {
638 SET_RUNTIME_PM_OPS(tegra_dpaux_suspend
, tegra_dpaux_resume
, NULL
)
641 static const struct of_device_id tegra_dpaux_of_match
[] = {
642 { .compatible
= "nvidia,tegra186-dpaux", },
643 { .compatible
= "nvidia,tegra210-dpaux", },
644 { .compatible
= "nvidia,tegra124-dpaux", },
647 MODULE_DEVICE_TABLE(of
, tegra_dpaux_of_match
);
649 struct platform_driver tegra_dpaux_driver
= {
651 .name
= "tegra-dpaux",
652 .of_match_table
= tegra_dpaux_of_match
,
653 .pm
= &tegra_dpaux_pm_ops
,
655 .probe
= tegra_dpaux_probe
,
656 .remove
= tegra_dpaux_remove
,
659 struct drm_dp_aux
*drm_dp_aux_find_by_of_node(struct device_node
*np
)
661 struct tegra_dpaux
*dpaux
;
663 mutex_lock(&dpaux_lock
);
665 list_for_each_entry(dpaux
, &dpaux_list
, list
)
666 if (np
== dpaux
->dev
->of_node
) {
667 mutex_unlock(&dpaux_lock
);
671 mutex_unlock(&dpaux_lock
);
676 int drm_dp_aux_attach(struct drm_dp_aux
*aux
, struct tegra_output
*output
)
678 struct tegra_dpaux
*dpaux
= to_dpaux(aux
);
679 unsigned long timeout
;
682 output
->connector
.polled
= DRM_CONNECTOR_POLL_HPD
;
683 dpaux
->output
= output
;
685 err
= regulator_enable(dpaux
->vdd
);
689 timeout
= jiffies
+ msecs_to_jiffies(250);
691 while (time_before(jiffies
, timeout
)) {
692 enum drm_connector_status status
;
694 status
= drm_dp_aux_detect(aux
);
695 if (status
== connector_status_connected
) {
696 enable_irq(dpaux
->irq
);
700 usleep_range(1000, 2000);
706 int drm_dp_aux_detach(struct drm_dp_aux
*aux
)
708 struct tegra_dpaux
*dpaux
= to_dpaux(aux
);
709 unsigned long timeout
;
712 disable_irq(dpaux
->irq
);
714 err
= regulator_disable(dpaux
->vdd
);
718 timeout
= jiffies
+ msecs_to_jiffies(250);
720 while (time_before(jiffies
, timeout
)) {
721 enum drm_connector_status status
;
723 status
= drm_dp_aux_detect(aux
);
724 if (status
== connector_status_disconnected
) {
725 dpaux
->output
= NULL
;
729 usleep_range(1000, 2000);
735 enum drm_connector_status
drm_dp_aux_detect(struct drm_dp_aux
*aux
)
737 struct tegra_dpaux
*dpaux
= to_dpaux(aux
);
740 value
= tegra_dpaux_readl(dpaux
, DPAUX_DP_AUXSTAT
);
742 if (value
& DPAUX_DP_AUXSTAT_HPD_STATUS
)
743 return connector_status_connected
;
745 return connector_status_disconnected
;
748 int drm_dp_aux_enable(struct drm_dp_aux
*aux
)
750 struct tegra_dpaux
*dpaux
= to_dpaux(aux
);
752 return tegra_dpaux_pad_config(dpaux
, DPAUX_PADCTL_FUNC_AUX
);
755 int drm_dp_aux_disable(struct drm_dp_aux
*aux
)
757 struct tegra_dpaux
*dpaux
= to_dpaux(aux
);
759 tegra_dpaux_pad_power_down(dpaux
);
764 int drm_dp_aux_prepare(struct drm_dp_aux
*aux
, u8 encoding
)
768 err
= drm_dp_dpcd_writeb(aux
, DP_MAIN_LINK_CHANNEL_CODING_SET
,
776 int drm_dp_aux_train(struct drm_dp_aux
*aux
, struct drm_dp_link
*link
,
779 u8 tp
= pattern
& DP_TRAINING_PATTERN_MASK
;
780 u8 status
[DP_LINK_STATUS_SIZE
], values
[4];
784 err
= drm_dp_dpcd_writeb(aux
, DP_TRAINING_PATTERN_SET
, pattern
);
788 if (tp
== DP_TRAINING_PATTERN_DISABLE
)
791 for (i
= 0; i
< link
->num_lanes
; i
++)
792 values
[i
] = DP_TRAIN_MAX_PRE_EMPHASIS_REACHED
|
793 DP_TRAIN_PRE_EMPH_LEVEL_0
|
794 DP_TRAIN_MAX_SWING_REACHED
|
795 DP_TRAIN_VOLTAGE_SWING_LEVEL_0
;
797 err
= drm_dp_dpcd_write(aux
, DP_TRAINING_LANE0_SET
, values
,
802 usleep_range(500, 1000);
804 err
= drm_dp_dpcd_read_link_status(aux
, status
);
809 case DP_TRAINING_PATTERN_1
:
810 if (!drm_dp_clock_recovery_ok(status
, link
->num_lanes
))
815 case DP_TRAINING_PATTERN_2
:
816 if (!drm_dp_channel_eq_ok(status
, link
->num_lanes
))
822 dev_err(aux
->dev
, "unsupported training pattern %u\n", tp
);
826 err
= drm_dp_dpcd_writeb(aux
, DP_EDP_CONFIGURATION_SET
, 0);