linux/drivers/gpu/drm/i915/display/intel_dp_aux.c
<<
>>
Prefs
   1// SPDX-License-Identifier: MIT
   2/*
   3 * Copyright © 2020-2021 Intel Corporation
   4 */
   5
   6#include "i915_drv.h"
   7#include "i915_trace.h"
   8#include "intel_display_types.h"
   9#include "intel_dp_aux.h"
  10#include "intel_pps.h"
  11#include "intel_tc.h"
  12
  13u32 intel_dp_pack_aux(const u8 *src, int src_bytes)
  14{
  15        int i;
  16        u32 v = 0;
  17
  18        if (src_bytes > 4)
  19                src_bytes = 4;
  20        for (i = 0; i < src_bytes; i++)
  21                v |= ((u32)src[i]) << ((3 - i) * 8);
  22        return v;
  23}
  24
  25static void intel_dp_unpack_aux(u32 src, u8 *dst, int dst_bytes)
  26{
  27        int i;
  28
  29        if (dst_bytes > 4)
  30                dst_bytes = 4;
  31        for (i = 0; i < dst_bytes; i++)
  32                dst[i] = src >> ((3 - i) * 8);
  33}
  34
  35static u32
  36intel_dp_aux_wait_done(struct intel_dp *intel_dp)
  37{
  38        struct drm_i915_private *i915 = dp_to_i915(intel_dp);
  39        i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
  40        const unsigned int timeout_ms = 10;
  41        u32 status;
  42        bool done;
  43
  44#define C (((status = intel_uncore_read_notrace(&i915->uncore, ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  45        done = wait_event_timeout(i915->gmbus_wait_queue, C,
  46                                  msecs_to_jiffies_timeout(timeout_ms));
  47
  48        /* just trace the final value */
  49        trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
  50
  51        if (!done)
  52                drm_err(&i915->drm,
  53                        "%s: did not complete or timeout within %ums (status 0x%08x)\n",
  54                        intel_dp->aux.name, timeout_ms, status);
  55#undef C
  56
  57        return status;
  58}
  59
  60static u32 g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  61{
  62        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
  63
  64        if (index)
  65                return 0;
  66
  67        /*
  68         * The clock divider is based off the hrawclk, and would like to run at
  69         * 2MHz.  So, take the hrawclk value and divide by 2000 and use that
  70         */
  71        return DIV_ROUND_CLOSEST(RUNTIME_INFO(dev_priv)->rawclk_freq, 2000);
  72}
  73
  74static u32 ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  75{
  76        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
  77        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  78        u32 freq;
  79
  80        if (index)
  81                return 0;
  82
  83        /*
  84         * The clock divider is based off the cdclk or PCH rawclk, and would
  85         * like to run at 2MHz.  So, take the cdclk or PCH rawclk value and
  86         * divide by 2000 and use that
  87         */
  88        if (dig_port->aux_ch == AUX_CH_A)
  89                freq = dev_priv->cdclk.hw.cdclk;
  90        else
  91                freq = RUNTIME_INFO(dev_priv)->rawclk_freq;
  92        return DIV_ROUND_CLOSEST(freq, 2000);
  93}
  94
  95static u32 hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  96{
  97        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
  98        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  99
 100        if (dig_port->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) {
 101                /* Workaround for non-ULT HSW */
 102                switch (index) {
 103                case 0: return 63;
 104                case 1: return 72;
 105                default: return 0;
 106                }
 107        }
 108
 109        return ilk_get_aux_clock_divider(intel_dp, index);
 110}
 111
 112static u32 skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
 113{
 114        /*
 115         * SKL doesn't need us to program the AUX clock divider (Hardware will
 116         * derive the clock from CDCLK automatically). We still implement the
 117         * get_aux_clock_divider vfunc to plug-in into the existing code.
 118         */
 119        return index ? 0 : 1;
 120}
 121
 122static u32 g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
 123                                int send_bytes,
 124                                u32 aux_clock_divider)
 125{
 126        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 127        struct drm_i915_private *dev_priv =
 128                        to_i915(dig_port->base.base.dev);
 129        u32 timeout;
 130
 131        /* Max timeout value on G4x-BDW: 1.6ms */
 132        if (IS_BROADWELL(dev_priv))
 133                timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
 134        else
 135                timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
 136
 137        return DP_AUX_CH_CTL_SEND_BUSY |
 138               DP_AUX_CH_CTL_DONE |
 139               DP_AUX_CH_CTL_INTERRUPT |
 140               DP_AUX_CH_CTL_TIME_OUT_ERROR |
 141               timeout |
 142               DP_AUX_CH_CTL_RECEIVE_ERROR |
 143               (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
 144               (3 << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
 145               (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
 146}
 147
 148static u32 skl_get_aux_send_ctl(struct intel_dp *intel_dp,
 149                                int send_bytes,
 150                                u32 unused)
 151{
 152        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 153        u32 ret;
 154
 155        /*
 156         * Max timeout values:
 157         * SKL-GLK: 1.6ms
 158         * CNL: 3.2ms
 159         * ICL+: 4ms
 160         */
 161        ret = DP_AUX_CH_CTL_SEND_BUSY |
 162              DP_AUX_CH_CTL_DONE |
 163              DP_AUX_CH_CTL_INTERRUPT |
 164              DP_AUX_CH_CTL_TIME_OUT_ERROR |
 165              DP_AUX_CH_CTL_TIME_OUT_MAX |
 166              DP_AUX_CH_CTL_RECEIVE_ERROR |
 167              (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
 168              DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
 169              DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
 170
 171        if (intel_tc_port_in_tbt_alt_mode(dig_port))
 172                ret |= DP_AUX_CH_CTL_TBT_IO;
 173
 174        return ret;
 175}
 176
 177static int
 178intel_dp_aux_xfer(struct intel_dp *intel_dp,
 179                  const u8 *send, int send_bytes,
 180                  u8 *recv, int recv_size,
 181                  u32 aux_send_ctl_flags)
 182{
 183        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 184        struct drm_i915_private *i915 =
 185                        to_i915(dig_port->base.base.dev);
 186        struct intel_uncore *uncore = &i915->uncore;
 187        enum phy phy = intel_port_to_phy(i915, dig_port->base.port);
 188        bool is_tc_port = intel_phy_is_tc(i915, phy);
 189        i915_reg_t ch_ctl, ch_data[5];
 190        u32 aux_clock_divider;
 191        enum intel_display_power_domain aux_domain;
 192        intel_wakeref_t aux_wakeref;
 193        intel_wakeref_t pps_wakeref;
 194        int i, ret, recv_bytes;
 195        int try, clock = 0;
 196        u32 status;
 197        bool vdd;
 198
 199        ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
 200        for (i = 0; i < ARRAY_SIZE(ch_data); i++)
 201                ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
 202
 203        if (is_tc_port)
 204                intel_tc_port_lock(dig_port);
 205
 206        aux_domain = intel_aux_power_domain(dig_port);
 207
 208        aux_wakeref = intel_display_power_get(i915, aux_domain);
 209        pps_wakeref = intel_pps_lock(intel_dp);
 210
 211        /*
 212         * We will be called with VDD already enabled for dpcd/edid/oui reads.
 213         * In such cases we want to leave VDD enabled and it's up to upper layers
 214         * to turn it off. But for eg. i2c-dev access we need to turn it on/off
 215         * ourselves.
 216         */
 217        vdd = intel_pps_vdd_on_unlocked(intel_dp);
 218
 219        /*
 220         * dp aux is extremely sensitive to irq latency, hence request the
 221         * lowest possible wakeup latency and so prevent the cpu from going into
 222         * deep sleep states.
 223         */
 224        cpu_latency_qos_update_request(&intel_dp->pm_qos, 0);
 225
 226        intel_pps_check_power_unlocked(intel_dp);
 227
 228        /* Try to wait for any previous AUX channel activity */
 229        for (try = 0; try < 3; try++) {
 230                status = intel_uncore_read_notrace(uncore, ch_ctl);
 231                if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
 232                        break;
 233                msleep(1);
 234        }
 235        /* just trace the final value */
 236        trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
 237
 238        if (try == 3) {
 239                const u32 status = intel_uncore_read(uncore, ch_ctl);
 240
 241                if (status != intel_dp->aux_busy_last_status) {
 242                        drm_WARN(&i915->drm, 1,
 243                                 "%s: not started (status 0x%08x)\n",
 244                                 intel_dp->aux.name, status);
 245                        intel_dp->aux_busy_last_status = status;
 246                }
 247
 248                ret = -EBUSY;
 249                goto out;
 250        }
 251
 252        /* Only 5 data registers! */
 253        if (drm_WARN_ON(&i915->drm, send_bytes > 20 || recv_size > 20)) {
 254                ret = -E2BIG;
 255                goto out;
 256        }
 257
 258        while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
 259                u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
 260                                                          send_bytes,
 261                                                          aux_clock_divider);
 262
 263                send_ctl |= aux_send_ctl_flags;
 264
 265                /* Must try at least 3 times according to DP spec */
 266                for (try = 0; try < 5; try++) {
 267                        /* Load the send data into the aux channel data registers */
 268                        for (i = 0; i < send_bytes; i += 4)
 269                                intel_uncore_write(uncore,
 270                                                   ch_data[i >> 2],
 271                                                   intel_dp_pack_aux(send + i,
 272                                                                     send_bytes - i));
 273
 274                        /* Send the command and wait for it to complete */
 275                        intel_uncore_write(uncore, ch_ctl, send_ctl);
 276
 277                        status = intel_dp_aux_wait_done(intel_dp);
 278
 279                        /* Clear done status and any errors */
 280                        intel_uncore_write(uncore,
 281                                           ch_ctl,
 282                                           status |
 283                                           DP_AUX_CH_CTL_DONE |
 284                                           DP_AUX_CH_CTL_TIME_OUT_ERROR |
 285                                           DP_AUX_CH_CTL_RECEIVE_ERROR);
 286
 287                        /*
 288                         * DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
 289                         *   400us delay required for errors and timeouts
 290                         *   Timeout errors from the HW already meet this
 291                         *   requirement so skip to next iteration
 292                         */
 293                        if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
 294                                continue;
 295
 296                        if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
 297                                usleep_range(400, 500);
 298                                continue;
 299                        }
 300                        if (status & DP_AUX_CH_CTL_DONE)
 301                                goto done;
 302                }
 303        }
 304
 305        if ((status & DP_AUX_CH_CTL_DONE) == 0) {
 306                drm_err(&i915->drm, "%s: not done (status 0x%08x)\n",
 307                        intel_dp->aux.name, status);
 308                ret = -EBUSY;
 309                goto out;
 310        }
 311
 312done:
 313        /*
 314         * Check for timeout or receive error. Timeouts occur when the sink is
 315         * not connected.
 316         */
 317        if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
 318                drm_err(&i915->drm, "%s: receive error (status 0x%08x)\n",
 319                        intel_dp->aux.name, status);
 320                ret = -EIO;
 321                goto out;
 322        }
 323
 324        /*
 325         * Timeouts occur when the device isn't connected, so they're "normal"
 326         * -- don't fill the kernel log with these
 327         */
 328        if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
 329                drm_dbg_kms(&i915->drm, "%s: timeout (status 0x%08x)\n",
 330                            intel_dp->aux.name, status);
 331                ret = -ETIMEDOUT;
 332                goto out;
 333        }
 334
 335        /* Unload any bytes sent back from the other side */
 336        recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
 337                      DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
 338
 339        /*
 340         * By BSpec: "Message sizes of 0 or >20 are not allowed."
 341         * We have no idea of what happened so we return -EBUSY so
 342         * drm layer takes care for the necessary retries.
 343         */
 344        if (recv_bytes == 0 || recv_bytes > 20) {
 345                drm_dbg_kms(&i915->drm,
 346                            "%s: Forbidden recv_bytes = %d on aux transaction\n",
 347                            intel_dp->aux.name, recv_bytes);
 348                ret = -EBUSY;
 349                goto out;
 350        }
 351
 352        if (recv_bytes > recv_size)
 353                recv_bytes = recv_size;
 354
 355        for (i = 0; i < recv_bytes; i += 4)
 356                intel_dp_unpack_aux(intel_uncore_read(uncore, ch_data[i >> 2]),
 357                                    recv + i, recv_bytes - i);
 358
 359        ret = recv_bytes;
 360out:
 361        cpu_latency_qos_update_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE);
 362
 363        if (vdd)
 364                intel_pps_vdd_off_unlocked(intel_dp, false);
 365
 366        intel_pps_unlock(intel_dp, pps_wakeref);
 367        intel_display_power_put_async(i915, aux_domain, aux_wakeref);
 368
 369        if (is_tc_port)
 370                intel_tc_port_unlock(dig_port);
 371
 372        return ret;
 373}
 374
 375#define BARE_ADDRESS_SIZE       3
 376#define HEADER_SIZE             (BARE_ADDRESS_SIZE + 1)
 377
 378static void
 379intel_dp_aux_header(u8 txbuf[HEADER_SIZE],
 380                    const struct drm_dp_aux_msg *msg)
 381{
 382        txbuf[0] = (msg->request << 4) | ((msg->address >> 16) & 0xf);
 383        txbuf[1] = (msg->address >> 8) & 0xff;
 384        txbuf[2] = msg->address & 0xff;
 385        txbuf[3] = msg->size - 1;
 386}
 387
 388static u32 intel_dp_aux_xfer_flags(const struct drm_dp_aux_msg *msg)
 389{
 390        /*
 391         * If we're trying to send the HDCP Aksv, we need to set a the Aksv
 392         * select bit to inform the hardware to send the Aksv after our header
 393         * since we can't access that data from software.
 394         */
 395        if ((msg->request & ~DP_AUX_I2C_MOT) == DP_AUX_NATIVE_WRITE &&
 396            msg->address == DP_AUX_HDCP_AKSV)
 397                return DP_AUX_CH_CTL_AUX_AKSV_SELECT;
 398
 399        return 0;
 400}
 401
 402static ssize_t
 403intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
 404{
 405        struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
 406        struct drm_i915_private *i915 = dp_to_i915(intel_dp);
 407        u8 txbuf[20], rxbuf[20];
 408        size_t txsize, rxsize;
 409        u32 flags = intel_dp_aux_xfer_flags(msg);
 410        int ret;
 411
 412        intel_dp_aux_header(txbuf, msg);
 413
 414        switch (msg->request & ~DP_AUX_I2C_MOT) {
 415        case DP_AUX_NATIVE_WRITE:
 416        case DP_AUX_I2C_WRITE:
 417        case DP_AUX_I2C_WRITE_STATUS_UPDATE:
 418                txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
 419                rxsize = 2; /* 0 or 1 data bytes */
 420
 421                if (drm_WARN_ON(&i915->drm, txsize > 20))
 422                        return -E2BIG;
 423
 424                drm_WARN_ON(&i915->drm, !msg->buffer != !msg->size);
 425
 426                if (msg->buffer)
 427                        memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
 428
 429                ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
 430                                        rxbuf, rxsize, flags);
 431                if (ret > 0) {
 432                        msg->reply = rxbuf[0] >> 4;
 433
 434                        if (ret > 1) {
 435                                /* Number of bytes written in a short write. */
 436                                ret = clamp_t(int, rxbuf[1], 0, msg->size);
 437                        } else {
 438                                /* Return payload size. */
 439                                ret = msg->size;
 440                        }
 441                }
 442                break;
 443
 444        case DP_AUX_NATIVE_READ:
 445        case DP_AUX_I2C_READ:
 446                txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
 447                rxsize = msg->size + 1;
 448
 449                if (drm_WARN_ON(&i915->drm, rxsize > 20))
 450                        return -E2BIG;
 451
 452                ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
 453                                        rxbuf, rxsize, flags);
 454                if (ret > 0) {
 455                        msg->reply = rxbuf[0] >> 4;
 456                        /*
 457                         * Assume happy day, and copy the data. The caller is
 458                         * expected to check msg->reply before touching it.
 459                         *
 460                         * Return payload size.
 461                         */
 462                        ret--;
 463                        memcpy(msg->buffer, rxbuf + 1, ret);
 464                }
 465                break;
 466
 467        default:
 468                ret = -EINVAL;
 469                break;
 470        }
 471
 472        return ret;
 473}
 474
 475static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
 476{
 477        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 478        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 479        enum aux_ch aux_ch = dig_port->aux_ch;
 480
 481        switch (aux_ch) {
 482        case AUX_CH_B:
 483        case AUX_CH_C:
 484        case AUX_CH_D:
 485                return DP_AUX_CH_CTL(aux_ch);
 486        default:
 487                MISSING_CASE(aux_ch);
 488                return DP_AUX_CH_CTL(AUX_CH_B);
 489        }
 490}
 491
 492static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
 493{
 494        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 495        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 496        enum aux_ch aux_ch = dig_port->aux_ch;
 497
 498        switch (aux_ch) {
 499        case AUX_CH_B:
 500        case AUX_CH_C:
 501        case AUX_CH_D:
 502                return DP_AUX_CH_DATA(aux_ch, index);
 503        default:
 504                MISSING_CASE(aux_ch);
 505                return DP_AUX_CH_DATA(AUX_CH_B, index);
 506        }
 507}
 508
 509static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
 510{
 511        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 512        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 513        enum aux_ch aux_ch = dig_port->aux_ch;
 514
 515        switch (aux_ch) {
 516        case AUX_CH_A:
 517                return DP_AUX_CH_CTL(aux_ch);
 518        case AUX_CH_B:
 519        case AUX_CH_C:
 520        case AUX_CH_D:
 521                return PCH_DP_AUX_CH_CTL(aux_ch);
 522        default:
 523                MISSING_CASE(aux_ch);
 524                return DP_AUX_CH_CTL(AUX_CH_A);
 525        }
 526}
 527
 528static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
 529{
 530        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 531        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 532        enum aux_ch aux_ch = dig_port->aux_ch;
 533
 534        switch (aux_ch) {
 535        case AUX_CH_A:
 536                return DP_AUX_CH_DATA(aux_ch, index);
 537        case AUX_CH_B:
 538        case AUX_CH_C:
 539        case AUX_CH_D:
 540                return PCH_DP_AUX_CH_DATA(aux_ch, index);
 541        default:
 542                MISSING_CASE(aux_ch);
 543                return DP_AUX_CH_DATA(AUX_CH_A, index);
 544        }
 545}
 546
 547static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
 548{
 549        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 550        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 551        enum aux_ch aux_ch = dig_port->aux_ch;
 552
 553        switch (aux_ch) {
 554        case AUX_CH_A:
 555        case AUX_CH_B:
 556        case AUX_CH_C:
 557        case AUX_CH_D:
 558        case AUX_CH_E:
 559        case AUX_CH_F:
 560                return DP_AUX_CH_CTL(aux_ch);
 561        default:
 562                MISSING_CASE(aux_ch);
 563                return DP_AUX_CH_CTL(AUX_CH_A);
 564        }
 565}
 566
 567static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
 568{
 569        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 570        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 571        enum aux_ch aux_ch = dig_port->aux_ch;
 572
 573        switch (aux_ch) {
 574        case AUX_CH_A:
 575        case AUX_CH_B:
 576        case AUX_CH_C:
 577        case AUX_CH_D:
 578        case AUX_CH_E:
 579        case AUX_CH_F:
 580                return DP_AUX_CH_DATA(aux_ch, index);
 581        default:
 582                MISSING_CASE(aux_ch);
 583                return DP_AUX_CH_DATA(AUX_CH_A, index);
 584        }
 585}
 586
 587static i915_reg_t tgl_aux_ctl_reg(struct intel_dp *intel_dp)
 588{
 589        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 590        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 591        enum aux_ch aux_ch = dig_port->aux_ch;
 592
 593        switch (aux_ch) {
 594        case AUX_CH_A:
 595        case AUX_CH_B:
 596        case AUX_CH_C:
 597        case AUX_CH_USBC1:
 598        case AUX_CH_USBC2:
 599        case AUX_CH_USBC3:
 600        case AUX_CH_USBC4:
 601        case AUX_CH_USBC5:  /* aka AUX_CH_D_XELPD */
 602        case AUX_CH_USBC6:  /* aka AUX_CH_E_XELPD */
 603                return DP_AUX_CH_CTL(aux_ch);
 604        default:
 605                MISSING_CASE(aux_ch);
 606                return DP_AUX_CH_CTL(AUX_CH_A);
 607        }
 608}
 609
 610static i915_reg_t tgl_aux_data_reg(struct intel_dp *intel_dp, int index)
 611{
 612        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 613        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 614        enum aux_ch aux_ch = dig_port->aux_ch;
 615
 616        switch (aux_ch) {
 617        case AUX_CH_A:
 618        case AUX_CH_B:
 619        case AUX_CH_C:
 620        case AUX_CH_USBC1:
 621        case AUX_CH_USBC2:
 622        case AUX_CH_USBC3:
 623        case AUX_CH_USBC4:
 624        case AUX_CH_USBC5:  /* aka AUX_CH_D_XELPD */
 625        case AUX_CH_USBC6:  /* aka AUX_CH_E_XELPD */
 626                return DP_AUX_CH_DATA(aux_ch, index);
 627        default:
 628                MISSING_CASE(aux_ch);
 629                return DP_AUX_CH_DATA(AUX_CH_A, index);
 630        }
 631}
 632
 633void intel_dp_aux_fini(struct intel_dp *intel_dp)
 634{
 635        if (cpu_latency_qos_request_active(&intel_dp->pm_qos))
 636                cpu_latency_qos_remove_request(&intel_dp->pm_qos);
 637
 638        kfree(intel_dp->aux.name);
 639}
 640
 641void intel_dp_aux_init(struct intel_dp *intel_dp)
 642{
 643        struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
 644        struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
 645        struct intel_encoder *encoder = &dig_port->base;
 646        enum aux_ch aux_ch = dig_port->aux_ch;
 647
 648        if (DISPLAY_VER(dev_priv) >= 12) {
 649                intel_dp->aux_ch_ctl_reg = tgl_aux_ctl_reg;
 650                intel_dp->aux_ch_data_reg = tgl_aux_data_reg;
 651        } else if (DISPLAY_VER(dev_priv) >= 9) {
 652                intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
 653                intel_dp->aux_ch_data_reg = skl_aux_data_reg;
 654        } else if (HAS_PCH_SPLIT(dev_priv)) {
 655                intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
 656                intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
 657        } else {
 658                intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
 659                intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
 660        }
 661
 662        if (DISPLAY_VER(dev_priv) >= 9)
 663                intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
 664        else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
 665                intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
 666        else if (HAS_PCH_SPLIT(dev_priv))
 667                intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
 668        else
 669                intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
 670
 671        if (DISPLAY_VER(dev_priv) >= 9)
 672                intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
 673        else
 674                intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
 675
 676        intel_dp->aux.drm_dev = &dev_priv->drm;
 677        drm_dp_aux_init(&intel_dp->aux);
 678
 679        /* Failure to allocate our preferred name is not critical */
 680        if (DISPLAY_VER(dev_priv) >= 13 && aux_ch >= AUX_CH_D_XELPD)
 681                intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/%s",
 682                                               aux_ch_name(aux_ch - AUX_CH_D_XELPD + AUX_CH_D),
 683                                               encoder->base.name);
 684        else if (DISPLAY_VER(dev_priv) >= 12 && aux_ch >= AUX_CH_USBC1)
 685                intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX USBC%c/%s",
 686                                               aux_ch - AUX_CH_USBC1 + '1',
 687                                               encoder->base.name);
 688        else
 689                intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/%s",
 690                                               aux_ch_name(aux_ch),
 691                                               encoder->base.name);
 692
 693        intel_dp->aux.transfer = intel_dp_aux_transfer;
 694        cpu_latency_qos_add_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE);
 695}
 696