| .. | .. |
|---|
| 20 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 21 | 21 | */ |
|---|
| 22 | 22 | |
|---|
| 23 | +#include <linux/delay.h> |
|---|
| 23 | 24 | #include <linux/errno.h> |
|---|
| 24 | 25 | #include <linux/export.h> |
|---|
| 25 | 26 | #include <linux/i2c.h> |
|---|
| 26 | 27 | #include <linux/slab.h> |
|---|
| 27 | 28 | #include <linux/string.h> |
|---|
| 29 | + |
|---|
| 28 | 30 | #include <drm/drm_dp_dual_mode_helper.h> |
|---|
| 29 | | -#include <drm/drmP.h> |
|---|
| 31 | +#include <drm/drm_print.h> |
|---|
| 30 | 32 | |
|---|
| 31 | 33 | /** |
|---|
| 32 | 34 | * DOC: dp dual mode helpers |
|---|
| .. | .. |
|---|
| 60 | 62 | ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter, |
|---|
| 61 | 63 | u8 offset, void *buffer, size_t size) |
|---|
| 62 | 64 | { |
|---|
| 65 | + u8 zero = 0; |
|---|
| 66 | + char *tmpbuf = NULL; |
|---|
| 67 | + /* |
|---|
| 68 | + * As sub-addressing is not supported by all adaptors, |
|---|
| 69 | + * always explicitly read from the start and discard |
|---|
| 70 | + * any bytes that come before the requested offset. |
|---|
| 71 | + * This way, no matter whether the adaptor supports it |
|---|
| 72 | + * or not, we'll end up reading the proper data. |
|---|
| 73 | + */ |
|---|
| 63 | 74 | struct i2c_msg msgs[] = { |
|---|
| 64 | 75 | { |
|---|
| 65 | 76 | .addr = DP_DUAL_MODE_SLAVE_ADDRESS, |
|---|
| 66 | 77 | .flags = 0, |
|---|
| 67 | 78 | .len = 1, |
|---|
| 68 | | - .buf = &offset, |
|---|
| 79 | + .buf = &zero, |
|---|
| 69 | 80 | }, |
|---|
| 70 | 81 | { |
|---|
| 71 | 82 | .addr = DP_DUAL_MODE_SLAVE_ADDRESS, |
|---|
| 72 | 83 | .flags = I2C_M_RD, |
|---|
| 73 | | - .len = size, |
|---|
| 84 | + .len = size + offset, |
|---|
| 74 | 85 | .buf = buffer, |
|---|
| 75 | 86 | }, |
|---|
| 76 | 87 | }; |
|---|
| 77 | 88 | int ret; |
|---|
| 78 | 89 | |
|---|
| 90 | + if (offset) { |
|---|
| 91 | + tmpbuf = kmalloc(size + offset, GFP_KERNEL); |
|---|
| 92 | + if (!tmpbuf) |
|---|
| 93 | + return -ENOMEM; |
|---|
| 94 | + |
|---|
| 95 | + msgs[1].buf = tmpbuf; |
|---|
| 96 | + } |
|---|
| 97 | + |
|---|
| 79 | 98 | ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs)); |
|---|
| 99 | + if (tmpbuf) |
|---|
| 100 | + memcpy(buffer, tmpbuf + offset, size); |
|---|
| 101 | + |
|---|
| 102 | + kfree(tmpbuf); |
|---|
| 103 | + |
|---|
| 80 | 104 | if (ret < 0) |
|---|
| 81 | 105 | return ret; |
|---|
| 82 | 106 | if (ret != ARRAY_SIZE(msgs)) |
|---|
| .. | .. |
|---|
| 203 | 227 | if (ret) |
|---|
| 204 | 228 | return DRM_DP_DUAL_MODE_UNKNOWN; |
|---|
| 205 | 229 | |
|---|
| 206 | | - /* |
|---|
| 207 | | - * Sigh. Some (maybe all?) type 1 adaptors are broken and ack |
|---|
| 208 | | - * the offset but ignore it, and instead they just always return |
|---|
| 209 | | - * data from the start of the HDMI ID buffer. So for a broken |
|---|
| 210 | | - * type 1 HDMI adaptor a single byte read will always give us |
|---|
| 211 | | - * 0x44, and for a type 1 DVI adaptor it should give 0x00 |
|---|
| 212 | | - * (assuming it implements any registers). Fortunately neither |
|---|
| 213 | | - * of those values will match the type 2 signature of the |
|---|
| 214 | | - * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with |
|---|
| 215 | | - * the type 2 adaptor detection safely even in the presence |
|---|
| 216 | | - * of broken type 1 adaptors. |
|---|
| 217 | | - */ |
|---|
| 218 | 230 | ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID, |
|---|
| 219 | 231 | &adaptor_id, sizeof(adaptor_id)); |
|---|
| 220 | 232 | DRM_DEBUG_KMS("DP dual mode adaptor ID: %02x (err %zd)\n", |
|---|
| .. | .. |
|---|
| 229 | 241 | return DRM_DP_DUAL_MODE_TYPE2_DVI; |
|---|
| 230 | 242 | } |
|---|
| 231 | 243 | /* |
|---|
| 232 | | - * If neither a proper type 1 ID nor a broken type 1 adaptor |
|---|
| 233 | | - * as described above, assume type 1, but let the user know |
|---|
| 234 | | - * that we may have misdetected the type. |
|---|
| 244 | + * If not a proper type 1 ID, still assume type 1, but let |
|---|
| 245 | + * the user know that we may have misdetected the type. |
|---|
| 235 | 246 | */ |
|---|
| 236 | | - if (!is_type1_adaptor(adaptor_id) && adaptor_id != hdmi_id[0]) |
|---|
| 247 | + if (!is_type1_adaptor(adaptor_id)) |
|---|
| 237 | 248 | DRM_ERROR("Unexpected DP dual mode adaptor ID %02x\n", |
|---|
| 238 | 249 | adaptor_id); |
|---|
| 239 | 250 | |
|---|
| .. | .. |
|---|
| 337 | 348 | * @enable: enable (as opposed to disable) the TMDS output buffers |
|---|
| 338 | 349 | * |
|---|
| 339 | 350 | * Set the state of the TMDS output buffers in the adaptor. For |
|---|
| 340 | | - * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As |
|---|
| 341 | | - * some type 1 adaptors have problems with registers (see comments |
|---|
| 342 | | - * in drm_dp_dual_mode_detect()) we avoid touching the register, |
|---|
| 343 | | - * making this function a no-op on type 1 adaptors. |
|---|
| 351 | + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. |
|---|
| 352 | + * Type1 adaptors do not support any register writes. |
|---|
| 344 | 353 | * |
|---|
| 345 | 354 | * Returns: |
|---|
| 346 | 355 | * 0 on success, negative error code on failure |
|---|