|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | #include <linux/slab.h> |
| 25 | +#include <linux/delay.h> |
25 | 26 |
|
26 | 27 | #include <drm/drm_scdc_helper.h> |
| 28 | +#include <drm/drmP.h> |
27 | 29 |
|
28 | 30 | /** |
29 | 31 | * DOC: scdc helpers |
@@ -109,3 +111,122 @@ ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset, |
109 | 111 | return err; |
110 | 112 | } |
111 | 113 | EXPORT_SYMBOL(drm_scdc_write); |
| 114 | + |
| 115 | +/** |
| 116 | + * drm_scdc_check_scrambling_status - what is status of scrambling? |
| 117 | + * @adapter: I2C adapter for DDC channel |
| 118 | + * |
| 119 | + * Reads the scrambler status over SCDC, and checks the |
| 120 | + * scrambling status. |
| 121 | + * |
| 122 | + * Returns: |
| 123 | + * True if the scrambling is enabled, false otherwise. |
| 124 | + */ |
| 125 | + |
| 126 | +bool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter) |
| 127 | +{ |
| 128 | + u8 status; |
| 129 | + int ret; |
| 130 | + |
| 131 | + ret = drm_scdc_readb(adapter, SCDC_SCRAMBLER_STATUS, &status); |
| 132 | + if (ret < 0) { |
| 133 | + DRM_ERROR("Failed to read scrambling status, error %d\n", ret); |
| 134 | + return false; |
| 135 | + } |
| 136 | + |
| 137 | + return status & SCDC_SCRAMBLING_STATUS; |
| 138 | +} |
| 139 | +EXPORT_SYMBOL(drm_scdc_get_scrambling_status); |
| 140 | + |
| 141 | +/** |
| 142 | + * drm_scdc_set_scrambling - enable scrambling |
| 143 | + * @adapter: I2C adapter for DDC channel |
| 144 | + * @enable: bool to indicate if scrambling is to be enabled/disabled |
| 145 | + * |
| 146 | + * Writes the TMDS config register over SCDC channel, and: |
| 147 | + * enables scrambling when enable = 1 |
| 148 | + * disables scrambling when enable = 0 |
| 149 | + * |
| 150 | + * Returns: |
| 151 | + * True if scrambling is set/reset successfully, false otherwise. |
| 152 | + */ |
| 153 | + |
| 154 | +bool drm_scdc_set_scrambling(struct i2c_adapter *adapter, bool enable) |
| 155 | +{ |
| 156 | + u8 config; |
| 157 | + int ret; |
| 158 | + |
| 159 | + ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config); |
| 160 | + if (ret < 0) { |
| 161 | + DRM_ERROR("Failed to read tmds config, err=%d\n", ret); |
| 162 | + return false; |
| 163 | + } |
| 164 | + |
| 165 | + if (enable) |
| 166 | + config |= SCDC_SCRAMBLING_ENABLE; |
| 167 | + else |
| 168 | + config &= ~SCDC_SCRAMBLING_ENABLE; |
| 169 | + |
| 170 | + ret = drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config); |
| 171 | + if (ret < 0) { |
| 172 | + DRM_ERROR("Failed to enable scrambling, error %d\n", ret); |
| 173 | + return false; |
| 174 | + } |
| 175 | + |
| 176 | + return true; |
| 177 | +} |
| 178 | +EXPORT_SYMBOL(drm_scdc_set_scrambling); |
| 179 | + |
| 180 | +/** |
| 181 | + * drm_scdc_set_high_tmds_clock_ratio - set TMDS clock ratio |
| 182 | + * @adapter: I2C adapter for DDC channel |
| 183 | + * @set: ret or reset the high clock ratio |
| 184 | + * |
| 185 | + * TMDS clock ratio calculations go like this: |
| 186 | + * TMDS character = 10 bit TMDS encoded value |
| 187 | + * TMDS character rate = The rate at which TMDS characters are transmitted(Mcsc) |
| 188 | + * TMDS bit rate = 10x TMDS character rate |
| 189 | + * As per the spec: |
| 190 | + * TMDS clock rate for pixel clock < 340 MHz = 1x the character rate |
| 191 | + * = 1/10 pixel clock rate |
| 192 | + * TMDS clock rate for pixel clock > 340 MHz = 0.25x the character rate |
| 193 | + * = 1/40 pixel clock rate |
| 194 | + * |
| 195 | + * Writes to the TMDS config register over SCDC channel, and: |
| 196 | + * sets TMDS clock ratio to 1/40 when set = 1 |
| 197 | + * sets TMDS clock ratio to 1/10 when set = 0 |
| 198 | + * |
| 199 | + * Returns: |
| 200 | + * True if write is successful, false otherwise. |
| 201 | + */ |
| 202 | +bool drm_scdc_set_high_tmds_clock_ratio(struct i2c_adapter *adapter, bool set) |
| 203 | +{ |
| 204 | + u8 config; |
| 205 | + int ret; |
| 206 | + |
| 207 | + ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config); |
| 208 | + if (ret < 0) { |
| 209 | + DRM_ERROR("Failed to read tmds config, err=%d\n", ret); |
| 210 | + return false; |
| 211 | + } |
| 212 | + |
| 213 | + if (set) |
| 214 | + config |= SCDC_TMDS_BIT_CLOCK_RATIO_BY_40; |
| 215 | + else |
| 216 | + config &= ~SCDC_TMDS_BIT_CLOCK_RATIO_BY_40; |
| 217 | + |
| 218 | + ret = drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config); |
| 219 | + if (ret < 0) { |
| 220 | + DRM_ERROR("Failed to set TMDS clock ratio, error %d\n", ret); |
| 221 | + return false; |
| 222 | + } |
| 223 | + |
| 224 | + /* |
| 225 | + * The spec says that a source should wait minimum 1ms and maximum |
| 226 | + * 100ms after writing the TMDS config for clock ratio. Lets allow a |
| 227 | + * wait of upto 2ms here. |
| 228 | + */ |
| 229 | + usleep_range(1000, 2000); |
| 230 | + return true; |
| 231 | +} |
| 232 | +EXPORT_SYMBOL(drm_scdc_set_high_tmds_clock_ratio); |
0 commit comments