Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Cadence MHDP8546 DP bridge driver.
0004  *
0005  * Copyright (C) 2020 Cadence Design Systems, Inc.
0006  *
0007  * Author: Quentin Schulz <quentin.schulz@free-electrons.com>
0008  *         Swapnil Jakhade <sjakhade@cadence.com>
0009  */
0010 
0011 #ifndef CDNS_MHDP8546_CORE_H
0012 #define CDNS_MHDP8546_CORE_H
0013 
0014 #include <linux/bits.h>
0015 #include <linux/mutex.h>
0016 #include <linux/spinlock.h>
0017 
0018 #include <drm/display/drm_dp_helper.h>
0019 #include <drm/drm_bridge.h>
0020 #include <drm/drm_connector.h>
0021 
0022 struct clk;
0023 struct device;
0024 struct phy;
0025 
0026 /* Register offsets */
0027 #define CDNS_APB_CTRL               0x00000
0028 #define CDNS_CPU_STALL              BIT(3)
0029 
0030 #define CDNS_MAILBOX_FULL           0x00008
0031 #define CDNS_MAILBOX_EMPTY          0x0000c
0032 #define CDNS_MAILBOX_TX_DATA            0x00010
0033 #define CDNS_MAILBOX_RX_DATA            0x00014
0034 #define CDNS_KEEP_ALIVE             0x00018
0035 #define CDNS_KEEP_ALIVE_MASK            GENMASK(7, 0)
0036 
0037 #define CDNS_VER_L              0x0001C
0038 #define CDNS_VER_H              0x00020
0039 #define CDNS_LIB_L_ADDR             0x00024
0040 #define CDNS_LIB_H_ADDR             0x00028
0041 
0042 #define CDNS_MB_INT_MASK            0x00034
0043 #define CDNS_MB_INT_STATUS          0x00038
0044 
0045 #define CDNS_SW_CLK_L               0x0003c
0046 #define CDNS_SW_CLK_H               0x00040
0047 
0048 #define CDNS_SW_EVENT0              0x00044
0049 #define CDNS_DPTX_HPD               BIT(0)
0050 #define CDNS_HDCP_TX_STATUS         BIT(4)
0051 #define CDNS_HDCP2_TX_IS_KM_STORED      BIT(5)
0052 #define CDNS_HDCP2_TX_STORE_KM          BIT(6)
0053 #define CDNS_HDCP_TX_IS_RCVR_ID_VALID       BIT(7)
0054 
0055 #define CDNS_SW_EVENT1              0x00048
0056 #define CDNS_SW_EVENT2              0x0004c
0057 #define CDNS_SW_EVENT3              0x00050
0058 
0059 #define CDNS_APB_INT_MASK           0x0006C
0060 #define CDNS_APB_INT_MASK_MAILBOX_INT       BIT(0)
0061 #define CDNS_APB_INT_MASK_SW_EVENT_INT      BIT(1)
0062 
0063 #define CDNS_APB_INT_STATUS         0x00070
0064 
0065 #define CDNS_DPTX_CAR               0x00904
0066 #define CDNS_VIF_CLK_EN             BIT(0)
0067 #define CDNS_VIF_CLK_RSTN           BIT(1)
0068 
0069 #define CDNS_SOURCE_VIDEO_IF(s)         (0x00b00 + ((s) * 0x20))
0070 #define CDNS_BND_HSYNC2VSYNC(s)         (CDNS_SOURCE_VIDEO_IF(s) + \
0071                          0x00)
0072 #define CDNS_IP_DTCT_WIN            GENMASK(11, 0)
0073 #define CDNS_IP_DET_INTERLACE_FORMAT        BIT(12)
0074 #define CDNS_IP_BYPASS_V_INTERFACE      BIT(13)
0075 
0076 #define CDNS_HSYNC2VSYNC_POL_CTRL(s)        (CDNS_SOURCE_VIDEO_IF(s) + \
0077                          0x10)
0078 #define CDNS_H2V_HSYNC_POL_ACTIVE_LOW       BIT(1)
0079 #define CDNS_H2V_VSYNC_POL_ACTIVE_LOW       BIT(2)
0080 
0081 #define CDNS_DPTX_PHY_CONFIG            0x02000
0082 #define CDNS_PHY_TRAINING_EN            BIT(0)
0083 #define CDNS_PHY_TRAINING_TYPE(x)       (((x) & GENMASK(3, 0)) << 1)
0084 #define CDNS_PHY_SCRAMBLER_BYPASS       BIT(5)
0085 #define CDNS_PHY_ENCODER_BYPASS         BIT(6)
0086 #define CDNS_PHY_SKEW_BYPASS            BIT(7)
0087 #define CDNS_PHY_TRAINING_AUTO          BIT(8)
0088 #define CDNS_PHY_LANE0_SKEW(x)          (((x) & GENMASK(2, 0)) << 9)
0089 #define CDNS_PHY_LANE1_SKEW(x)          (((x) & GENMASK(2, 0)) << 12)
0090 #define CDNS_PHY_LANE2_SKEW(x)          (((x) & GENMASK(2, 0)) << 15)
0091 #define CDNS_PHY_LANE3_SKEW(x)          (((x) & GENMASK(2, 0)) << 18)
0092 #define CDNS_PHY_COMMON_CONFIG          (CDNS_PHY_LANE1_SKEW(1) | \
0093                         CDNS_PHY_LANE2_SKEW(2) |  \
0094                         CDNS_PHY_LANE3_SKEW(3))
0095 #define CDNS_PHY_10BIT_EN           BIT(21)
0096 
0097 #define CDNS_DP_FRAMER_GLOBAL_CONFIG        0x02200
0098 #define CDNS_DP_NUM_LANES(x)            ((x) - 1)
0099 #define CDNS_DP_MST_EN              BIT(2)
0100 #define CDNS_DP_FRAMER_EN           BIT(3)
0101 #define CDNS_DP_RATE_GOVERNOR_EN        BIT(4)
0102 #define CDNS_DP_NO_VIDEO_MODE           BIT(5)
0103 #define CDNS_DP_DISABLE_PHY_RST         BIT(6)
0104 #define CDNS_DP_WR_FAILING_EDGE_VSYNC       BIT(7)
0105 
0106 #define CDNS_DP_FRAMER_TU           0x02208
0107 #define CDNS_DP_FRAMER_TU_SIZE(x)       (((x) & GENMASK(6, 0)) << 8)
0108 #define CDNS_DP_FRAMER_TU_VS(x)         ((x) & GENMASK(5, 0))
0109 #define CDNS_DP_FRAMER_TU_CNT_RST_EN        BIT(15)
0110 
0111 #define CDNS_DP_MTPH_CONTROL            0x02264
0112 #define CDNS_DP_MTPH_ECF_EN         BIT(0)
0113 #define CDNS_DP_MTPH_ACT_EN         BIT(1)
0114 #define CDNS_DP_MTPH_LVP_EN         BIT(2)
0115 
0116 #define CDNS_DP_MTPH_STATUS         0x0226C
0117 #define CDNS_DP_MTPH_ACT_STATUS         BIT(0)
0118 
0119 #define CDNS_DP_LANE_EN             0x02300
0120 #define CDNS_DP_LANE_EN_LANES(x)        GENMASK((x) - 1, 0)
0121 
0122 #define CDNS_DP_ENHNCD              0x02304
0123 
0124 #define CDNS_DPTX_STREAM(s)         (0x03000 + (s) * 0x80)
0125 #define CDNS_DP_MSA_HORIZONTAL_0(s)     (CDNS_DPTX_STREAM(s) + 0x00)
0126 #define CDNS_DP_MSAH0_H_TOTAL(x)        (x)
0127 #define CDNS_DP_MSAH0_HSYNC_START(x)        ((x) << 16)
0128 
0129 #define CDNS_DP_MSA_HORIZONTAL_1(s)     (CDNS_DPTX_STREAM(s) + 0x04)
0130 #define CDNS_DP_MSAH1_HSYNC_WIDTH(x)        (x)
0131 #define CDNS_DP_MSAH1_HSYNC_POL_LOW     BIT(15)
0132 #define CDNS_DP_MSAH1_HDISP_WIDTH(x)        ((x) << 16)
0133 
0134 #define CDNS_DP_MSA_VERTICAL_0(s)       (CDNS_DPTX_STREAM(s) + 0x08)
0135 #define CDNS_DP_MSAV0_V_TOTAL(x)        (x)
0136 #define CDNS_DP_MSAV0_VSYNC_START(x)        ((x) << 16)
0137 
0138 #define CDNS_DP_MSA_VERTICAL_1(s)       (CDNS_DPTX_STREAM(s) + 0x0c)
0139 #define CDNS_DP_MSAV1_VSYNC_WIDTH(x)        (x)
0140 #define CDNS_DP_MSAV1_VSYNC_POL_LOW     BIT(15)
0141 #define CDNS_DP_MSAV1_VDISP_WIDTH(x)        ((x) << 16)
0142 
0143 #define CDNS_DP_MSA_MISC(s)         (CDNS_DPTX_STREAM(s) + 0x10)
0144 #define CDNS_DP_STREAM_CONFIG(s)        (CDNS_DPTX_STREAM(s) + 0x14)
0145 #define CDNS_DP_STREAM_CONFIG_2(s)      (CDNS_DPTX_STREAM(s) + 0x2c)
0146 #define CDNS_DP_SC2_TU_VS_DIFF(x)       ((x) << 8)
0147 
0148 #define CDNS_DP_HORIZONTAL(s)           (CDNS_DPTX_STREAM(s) + 0x30)
0149 #define CDNS_DP_H_HSYNC_WIDTH(x)        (x)
0150 #define CDNS_DP_H_H_TOTAL(x)            ((x) << 16)
0151 
0152 #define CDNS_DP_VERTICAL_0(s)           (CDNS_DPTX_STREAM(s) + 0x34)
0153 #define CDNS_DP_V0_VHEIGHT(x)           (x)
0154 #define CDNS_DP_V0_VSTART(x)            ((x) << 16)
0155 
0156 #define CDNS_DP_VERTICAL_1(s)           (CDNS_DPTX_STREAM(s) + 0x38)
0157 #define CDNS_DP_V1_VTOTAL(x)            (x)
0158 #define CDNS_DP_V1_VTOTAL_EVEN          BIT(16)
0159 
0160 #define CDNS_DP_MST_SLOT_ALLOCATE(s)        (CDNS_DPTX_STREAM(s) + 0x44)
0161 #define CDNS_DP_S_ALLOC_START_SLOT(x)       (x)
0162 #define CDNS_DP_S_ALLOC_END_SLOT(x)     ((x) << 8)
0163 
0164 #define CDNS_DP_RATE_GOVERNING(s)       (CDNS_DPTX_STREAM(s) + 0x48)
0165 #define CDNS_DP_RG_TARG_AV_SLOTS_Y(x)       (x)
0166 #define CDNS_DP_RG_TARG_AV_SLOTS_X(x)       ((x) << 4)
0167 #define CDNS_DP_RG_ENABLE           BIT(10)
0168 
0169 #define CDNS_DP_FRAMER_PXL_REPR(s)      (CDNS_DPTX_STREAM(s) + 0x4c)
0170 #define CDNS_DP_FRAMER_6_BPC            BIT(0)
0171 #define CDNS_DP_FRAMER_8_BPC            BIT(1)
0172 #define CDNS_DP_FRAMER_10_BPC           BIT(2)
0173 #define CDNS_DP_FRAMER_12_BPC           BIT(3)
0174 #define CDNS_DP_FRAMER_16_BPC           BIT(4)
0175 #define CDNS_DP_FRAMER_PXL_FORMAT       0x8
0176 #define CDNS_DP_FRAMER_RGB          BIT(0)
0177 #define CDNS_DP_FRAMER_YCBCR444         BIT(1)
0178 #define CDNS_DP_FRAMER_YCBCR422         BIT(2)
0179 #define CDNS_DP_FRAMER_YCBCR420         BIT(3)
0180 #define CDNS_DP_FRAMER_Y_ONLY           BIT(4)
0181 
0182 #define CDNS_DP_FRAMER_SP(s)            (CDNS_DPTX_STREAM(s) + 0x50)
0183 #define CDNS_DP_FRAMER_VSYNC_POL_LOW        BIT(0)
0184 #define CDNS_DP_FRAMER_HSYNC_POL_LOW        BIT(1)
0185 #define CDNS_DP_FRAMER_INTERLACE        BIT(2)
0186 
0187 #define CDNS_DP_LINE_THRESH(s)          (CDNS_DPTX_STREAM(s) + 0x64)
0188 #define CDNS_DP_ACTIVE_LINE_THRESH(x)       (x)
0189 
0190 #define CDNS_DP_VB_ID(s)            (CDNS_DPTX_STREAM(s) + 0x68)
0191 #define CDNS_DP_VB_ID_INTERLACED        BIT(2)
0192 #define CDNS_DP_VB_ID_COMPRESSED        BIT(6)
0193 
0194 #define CDNS_DP_FRONT_BACK_PORCH(s)     (CDNS_DPTX_STREAM(s) + 0x78)
0195 #define CDNS_DP_BACK_PORCH(x)           (x)
0196 #define CDNS_DP_FRONT_PORCH(x)          ((x) << 16)
0197 
0198 #define CDNS_DP_BYTE_COUNT(s)           (CDNS_DPTX_STREAM(s) + 0x7c)
0199 #define CDNS_DP_BYTE_COUNT_BYTES_IN_CHUNK_SHIFT 16
0200 
0201 /* mailbox */
0202 #define MAILBOX_RETRY_US            1000
0203 #define MAILBOX_TIMEOUT_US          2000000
0204 
0205 #define MB_OPCODE_ID                0
0206 #define MB_MODULE_ID                1
0207 #define MB_SIZE_MSB_ID              2
0208 #define MB_SIZE_LSB_ID              3
0209 #define MB_DATA_ID              4
0210 
0211 #define MB_MODULE_ID_DP_TX          0x01
0212 #define MB_MODULE_ID_HDCP_TX            0x07
0213 #define MB_MODULE_ID_HDCP_RX            0x08
0214 #define MB_MODULE_ID_HDCP_GENERAL       0x09
0215 #define MB_MODULE_ID_GENERAL            0x0a
0216 
0217 /* firmware and opcodes */
0218 #define FW_NAME                 "cadence/mhdp8546.bin"
0219 #define CDNS_MHDP_IMEM              0x10000
0220 
0221 #define GENERAL_MAIN_CONTROL            0x01
0222 #define GENERAL_TEST_ECHO           0x02
0223 #define GENERAL_BUS_SETTINGS            0x03
0224 #define GENERAL_TEST_ACCESS         0x04
0225 #define GENERAL_REGISTER_READ           0x07
0226 
0227 #define DPTX_SET_POWER_MNG          0x00
0228 #define DPTX_GET_EDID               0x02
0229 #define DPTX_READ_DPCD              0x03
0230 #define DPTX_WRITE_DPCD             0x04
0231 #define DPTX_ENABLE_EVENT           0x05
0232 #define DPTX_WRITE_REGISTER         0x06
0233 #define DPTX_READ_REGISTER          0x07
0234 #define DPTX_WRITE_FIELD            0x08
0235 #define DPTX_READ_EVENT             0x0a
0236 #define DPTX_GET_LAST_AUX_STAUS         0x0e
0237 #define DPTX_HPD_STATE              0x11
0238 #define DPTX_ADJUST_LT              0x12
0239 
0240 #define FW_STANDBY              0
0241 #define FW_ACTIVE               1
0242 
0243 /* HPD */
0244 #define DPTX_READ_EVENT_HPD_TO_HIGH             BIT(0)
0245 #define DPTX_READ_EVENT_HPD_TO_LOW              BIT(1)
0246 #define DPTX_READ_EVENT_HPD_PULSE               BIT(2)
0247 #define DPTX_READ_EVENT_HPD_STATE               BIT(3)
0248 
0249 /* general */
0250 #define CDNS_DP_TRAINING_PATTERN_4      0x7
0251 
0252 #define CDNS_KEEP_ALIVE_TIMEOUT         2000
0253 
0254 #define CDNS_VOLT_SWING(x)          ((x) & GENMASK(1, 0))
0255 #define CDNS_FORCE_VOLT_SWING           BIT(2)
0256 
0257 #define CDNS_PRE_EMPHASIS(x)            ((x) & GENMASK(1, 0))
0258 #define CDNS_FORCE_PRE_EMPHASIS         BIT(2)
0259 
0260 #define CDNS_SUPPORT_TPS(x)         BIT((x) - 1)
0261 
0262 #define CDNS_FAST_LINK_TRAINING         BIT(0)
0263 
0264 #define CDNS_LANE_MAPPING_TYPE_C_LANE_0(x)  ((x) & GENMASK(1, 0))
0265 #define CDNS_LANE_MAPPING_TYPE_C_LANE_1(x)  ((x) & GENMASK(3, 2))
0266 #define CDNS_LANE_MAPPING_TYPE_C_LANE_2(x)  ((x) & GENMASK(5, 4))
0267 #define CDNS_LANE_MAPPING_TYPE_C_LANE_3(x)  ((x) & GENMASK(7, 6))
0268 #define CDNS_LANE_MAPPING_NORMAL        0xe4
0269 #define CDNS_LANE_MAPPING_FLIPPED       0x1b
0270 
0271 #define CDNS_DP_MAX_NUM_LANES           4
0272 #define CDNS_DP_TEST_VSC_SDP            BIT(6) /* 1.3+ */
0273 #define CDNS_DP_TEST_COLOR_FORMAT_RAW_Y_ONLY    BIT(7)
0274 
0275 #define CDNS_MHDP_MAX_STREAMS           4
0276 
0277 #define DP_LINK_CAP_ENHANCED_FRAMING        BIT(0)
0278 
0279 struct cdns_mhdp_link {
0280     unsigned char revision;
0281     unsigned int rate;
0282     unsigned int num_lanes;
0283     unsigned long capabilities;
0284 };
0285 
0286 struct cdns_mhdp_host {
0287     unsigned int link_rate;
0288     u8 lanes_cnt;
0289     u8 volt_swing;
0290     u8 pre_emphasis;
0291     u8 pattern_supp;
0292     u8 lane_mapping;
0293     bool fast_link;
0294     bool enhanced;
0295     bool scrambler;
0296     bool ssc;
0297 };
0298 
0299 struct cdns_mhdp_sink {
0300     unsigned int link_rate;
0301     u8 lanes_cnt;
0302     u8 pattern_supp;
0303     bool fast_link;
0304     bool enhanced;
0305     bool ssc;
0306 };
0307 
0308 struct cdns_mhdp_display_fmt {
0309     u32 color_format;
0310     u32 bpc;
0311     bool y_only;
0312 };
0313 
0314 /*
0315  * These enums present MHDP hw initialization state
0316  * Legal state transitions are:
0317  * MHDP_HW_READY <-> MHDP_HW_STOPPED
0318  */
0319 enum mhdp_hw_state {
0320     MHDP_HW_READY = 1,  /* HW ready, FW active */
0321     MHDP_HW_STOPPED     /* Driver removal FW to be stopped */
0322 };
0323 
0324 struct cdns_mhdp_device;
0325 
0326 struct mhdp_platform_ops {
0327     int (*init)(struct cdns_mhdp_device *mhdp);
0328     void (*exit)(struct cdns_mhdp_device *mhdp);
0329     void (*enable)(struct cdns_mhdp_device *mhdp);
0330     void (*disable)(struct cdns_mhdp_device *mhdp);
0331 };
0332 
0333 struct cdns_mhdp_bridge_state {
0334     struct drm_bridge_state base;
0335     struct drm_display_mode *current_mode;
0336 };
0337 
0338 struct cdns_mhdp_platform_info {
0339     const struct drm_bridge_timings *timings;
0340     const struct mhdp_platform_ops *ops;
0341 };
0342 
0343 #define to_cdns_mhdp_bridge_state(s) \
0344         container_of(s, struct cdns_mhdp_bridge_state, base)
0345 
0346 struct cdns_mhdp_hdcp {
0347     struct delayed_work check_work;
0348     struct work_struct prop_work;
0349     struct mutex mutex; /* mutex to protect hdcp.value */
0350     u32 value;
0351     u8 hdcp_content_type;
0352 };
0353 
0354 struct cdns_mhdp_device {
0355     void __iomem *regs;
0356     void __iomem *sapb_regs;
0357     void __iomem *j721e_regs;
0358 
0359     struct device *dev;
0360     struct clk *clk;
0361     struct phy *phy;
0362 
0363     const struct cdns_mhdp_platform_info *info;
0364 
0365     /* This is to protect mailbox communications with the firmware */
0366     struct mutex mbox_mutex;
0367 
0368     /*
0369      * "link_mutex" protects the access to all the link parameters
0370      * including the link training process. Link training will be
0371      * invoked both from threaded interrupt handler and from atomic
0372      * callbacks when link_up is not set. So this mutex protects
0373      * flags such as link_up, bridge_enabled, link.num_lanes,
0374      * link.rate etc.
0375      */
0376     struct mutex link_mutex;
0377 
0378     struct drm_connector connector;
0379     struct drm_bridge bridge;
0380 
0381     struct cdns_mhdp_link link;
0382     struct drm_dp_aux aux;
0383 
0384     struct cdns_mhdp_host host;
0385     struct cdns_mhdp_sink sink;
0386     struct cdns_mhdp_display_fmt display_fmt;
0387     u8 stream_id;
0388 
0389     bool link_up;
0390     bool plugged;
0391 
0392     /*
0393      * "start_lock" protects the access to bridge_attached and
0394      * hw_state data members that control the delayed firmware
0395      * loading and attaching the bridge. They are accessed from
0396      * both the DRM core and cdns_mhdp_fw_cb(). In most cases just
0397      * protecting the data members is enough, but the irq mask
0398      * setting needs to be protected when enabling the FW.
0399      */
0400     spinlock_t start_lock;
0401     bool bridge_attached;
0402     bool bridge_enabled;
0403     enum mhdp_hw_state hw_state;
0404     wait_queue_head_t fw_load_wq;
0405 
0406     /* Work struct to schedule a uevent on link train failure */
0407     struct work_struct modeset_retry_work;
0408     struct work_struct hpd_work;
0409 
0410     wait_queue_head_t sw_events_wq;
0411     u32 sw_events;
0412 
0413     struct cdns_mhdp_hdcp hdcp;
0414     bool hdcp_supported;
0415 };
0416 
0417 #define connector_to_mhdp(x) container_of(x, struct cdns_mhdp_device, connector)
0418 #define bridge_to_mhdp(x) container_of(x, struct cdns_mhdp_device, bridge)
0419 
0420 u32 cdns_mhdp_wait_for_sw_event(struct cdns_mhdp_device *mhdp, uint32_t event);
0421 
0422 #endif