aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/i915/intel_i2c.c')
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index a64f26c670af..1369fc41d039 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -114,8 +114,8 @@ intel_i2c_reset(struct drm_device *dev)
114{ 114{
115 struct drm_i915_private *dev_priv = dev->dev_private; 115 struct drm_i915_private *dev_priv = dev->dev_private;
116 116
117 I915_WRITE(dev_priv->gpio_mmio_base + GMBUS0, 0); 117 I915_WRITE(GMBUS0, 0);
118 I915_WRITE(dev_priv->gpio_mmio_base + GMBUS4, 0); 118 I915_WRITE(GMBUS4, 0);
119} 119}
120 120
121static void intel_i2c_quirk_set(struct drm_i915_private *dev_priv, bool enable) 121static void intel_i2c_quirk_set(struct drm_i915_private *dev_priv, bool enable)
@@ -261,7 +261,6 @@ gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
261 u32 gmbus4_irq_en) 261 u32 gmbus4_irq_en)
262{ 262{
263 int i; 263 int i;
264 int reg_offset = dev_priv->gpio_mmio_base;
265 u32 gmbus2 = 0; 264 u32 gmbus2 = 0;
266 DEFINE_WAIT(wait); 265 DEFINE_WAIT(wait);
267 266
@@ -271,13 +270,13 @@ gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
271 /* Important: The hw handles only the first bit, so set only one! Since 270 /* Important: The hw handles only the first bit, so set only one! Since
272 * we also need to check for NAKs besides the hw ready/idle signal, we 271 * we also need to check for NAKs besides the hw ready/idle signal, we
273 * need to wake up periodically and check that ourselves. */ 272 * need to wake up periodically and check that ourselves. */
274 I915_WRITE(GMBUS4 + reg_offset, gmbus4_irq_en); 273 I915_WRITE(GMBUS4, gmbus4_irq_en);
275 274
276 for (i = 0; i < msecs_to_jiffies_timeout(50); i++) { 275 for (i = 0; i < msecs_to_jiffies_timeout(50); i++) {
277 prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait, 276 prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait,
278 TASK_UNINTERRUPTIBLE); 277 TASK_UNINTERRUPTIBLE);
279 278
280 gmbus2 = I915_READ_NOTRACE(GMBUS2 + reg_offset); 279 gmbus2 = I915_READ_NOTRACE(GMBUS2);
281 if (gmbus2 & (GMBUS_SATOER | gmbus2_status)) 280 if (gmbus2 & (GMBUS_SATOER | gmbus2_status))
282 break; 281 break;
283 282
@@ -285,7 +284,7 @@ gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
285 } 284 }
286 finish_wait(&dev_priv->gmbus_wait_queue, &wait); 285 finish_wait(&dev_priv->gmbus_wait_queue, &wait);
287 286
288 I915_WRITE(GMBUS4 + reg_offset, 0); 287 I915_WRITE(GMBUS4, 0);
289 288
290 if (gmbus2 & GMBUS_SATOER) 289 if (gmbus2 & GMBUS_SATOER)
291 return -ENXIO; 290 return -ENXIO;
@@ -298,20 +297,19 @@ static int
298gmbus_wait_idle(struct drm_i915_private *dev_priv) 297gmbus_wait_idle(struct drm_i915_private *dev_priv)
299{ 298{
300 int ret; 299 int ret;
301 int reg_offset = dev_priv->gpio_mmio_base;
302 300
303#define C ((I915_READ_NOTRACE(GMBUS2 + reg_offset) & GMBUS_ACTIVE) == 0) 301#define C ((I915_READ_NOTRACE(GMBUS2) & GMBUS_ACTIVE) == 0)
304 302
305 if (!HAS_GMBUS_IRQ(dev_priv->dev)) 303 if (!HAS_GMBUS_IRQ(dev_priv->dev))
306 return wait_for(C, 10); 304 return wait_for(C, 10);
307 305
308 /* Important: The hw handles only the first bit, so set only one! */ 306 /* Important: The hw handles only the first bit, so set only one! */
309 I915_WRITE(GMBUS4 + reg_offset, GMBUS_IDLE_EN); 307 I915_WRITE(GMBUS4, GMBUS_IDLE_EN);
310 308
311 ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C, 309 ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
312 msecs_to_jiffies_timeout(10)); 310 msecs_to_jiffies_timeout(10));
313 311
314 I915_WRITE(GMBUS4 + reg_offset, 0); 312 I915_WRITE(GMBUS4, 0);
315 313
316 if (ret) 314 if (ret)
317 return 0; 315 return 0;
@@ -325,9 +323,7 @@ gmbus_xfer_read_chunk(struct drm_i915_private *dev_priv,
325 unsigned short addr, u8 *buf, unsigned int len, 323 unsigned short addr, u8 *buf, unsigned int len,
326 u32 gmbus1_index) 324 u32 gmbus1_index)
327{ 325{
328 int reg_offset = dev_priv->gpio_mmio_base; 326 I915_WRITE(GMBUS1,
329
330 I915_WRITE(GMBUS1 + reg_offset,
331 gmbus1_index | 327 gmbus1_index |
332 GMBUS_CYCLE_WAIT | 328 GMBUS_CYCLE_WAIT |
333 (len << GMBUS_BYTE_COUNT_SHIFT) | 329 (len << GMBUS_BYTE_COUNT_SHIFT) |
@@ -342,7 +338,7 @@ gmbus_xfer_read_chunk(struct drm_i915_private *dev_priv,
342 if (ret) 338 if (ret)
343 return ret; 339 return ret;
344 340
345 val = I915_READ(GMBUS3 + reg_offset); 341 val = I915_READ(GMBUS3);
346 do { 342 do {
347 *buf++ = val & 0xff; 343 *buf++ = val & 0xff;
348 val >>= 8; 344 val >>= 8;
@@ -380,7 +376,6 @@ static int
380gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv, 376gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv,
381 unsigned short addr, u8 *buf, unsigned int len) 377 unsigned short addr, u8 *buf, unsigned int len)
382{ 378{
383 int reg_offset = dev_priv->gpio_mmio_base;
384 unsigned int chunk_size = len; 379 unsigned int chunk_size = len;
385 u32 val, loop; 380 u32 val, loop;
386 381
@@ -390,8 +385,8 @@ gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv,
390 len -= 1; 385 len -= 1;
391 } 386 }
392 387
393 I915_WRITE(GMBUS3 + reg_offset, val); 388 I915_WRITE(GMBUS3, val);
394 I915_WRITE(GMBUS1 + reg_offset, 389 I915_WRITE(GMBUS1,
395 GMBUS_CYCLE_WAIT | 390 GMBUS_CYCLE_WAIT |
396 (chunk_size << GMBUS_BYTE_COUNT_SHIFT) | 391 (chunk_size << GMBUS_BYTE_COUNT_SHIFT) |
397 (addr << GMBUS_SLAVE_ADDR_SHIFT) | 392 (addr << GMBUS_SLAVE_ADDR_SHIFT) |
@@ -404,7 +399,7 @@ gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv,
404 val |= *buf++ << (8 * loop); 399 val |= *buf++ << (8 * loop);
405 } while (--len && ++loop < 4); 400 } while (--len && ++loop < 4);
406 401
407 I915_WRITE(GMBUS3 + reg_offset, val); 402 I915_WRITE(GMBUS3, val);
408 403
409 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY, 404 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
410 GMBUS_HW_RDY_EN); 405 GMBUS_HW_RDY_EN);
@@ -452,7 +447,6 @@ gmbus_is_index_read(struct i2c_msg *msgs, int i, int num)
452static int 447static int
453gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs) 448gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
454{ 449{
455 int reg_offset = dev_priv->gpio_mmio_base;
456 u32 gmbus1_index = 0; 450 u32 gmbus1_index = 0;
457 u32 gmbus5 = 0; 451 u32 gmbus5 = 0;
458 int ret; 452 int ret;
@@ -466,13 +460,13 @@ gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
466 460
467 /* GMBUS5 holds 16-bit index */ 461 /* GMBUS5 holds 16-bit index */
468 if (gmbus5) 462 if (gmbus5)
469 I915_WRITE(GMBUS5 + reg_offset, gmbus5); 463 I915_WRITE(GMBUS5, gmbus5);
470 464
471 ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index); 465 ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index);
472 466
473 /* Clear GMBUS5 after each index transfer */ 467 /* Clear GMBUS5 after each index transfer */
474 if (gmbus5) 468 if (gmbus5)
475 I915_WRITE(GMBUS5 + reg_offset, 0); 469 I915_WRITE(GMBUS5, 0);
476 470
477 return ret; 471 return ret;
478} 472}
@@ -486,7 +480,7 @@ gmbus_xfer(struct i2c_adapter *adapter,
486 struct intel_gmbus, 480 struct intel_gmbus,
487 adapter); 481 adapter);
488 struct drm_i915_private *dev_priv = bus->dev_priv; 482 struct drm_i915_private *dev_priv = bus->dev_priv;
489 int i = 0, inc, try = 0, reg_offset; 483 int i = 0, inc, try = 0;
490 int ret = 0; 484 int ret = 0;
491 485
492 intel_aux_display_runtime_get(dev_priv); 486 intel_aux_display_runtime_get(dev_priv);
@@ -497,10 +491,8 @@ gmbus_xfer(struct i2c_adapter *adapter,
497 goto out; 491 goto out;
498 } 492 }
499 493
500 reg_offset = dev_priv->gpio_mmio_base;
501
502retry: 494retry:
503 I915_WRITE(GMBUS0 + reg_offset, bus->reg0); 495 I915_WRITE(GMBUS0, bus->reg0);
504 496
505 for (; i < num; i += inc) { 497 for (; i < num; i += inc) {
506 inc = 1; 498 inc = 1;
@@ -530,7 +522,7 @@ retry:
530 * a STOP on the very first cycle. To simplify the code we 522 * a STOP on the very first cycle. To simplify the code we
531 * unconditionally generate the STOP condition with an additional gmbus 523 * unconditionally generate the STOP condition with an additional gmbus
532 * cycle. */ 524 * cycle. */
533 I915_WRITE(GMBUS1 + reg_offset, GMBUS_CYCLE_STOP | GMBUS_SW_RDY); 525 I915_WRITE(GMBUS1, GMBUS_CYCLE_STOP | GMBUS_SW_RDY);
534 526
535 /* Mark the GMBUS interface as disabled after waiting for idle. 527 /* Mark the GMBUS interface as disabled after waiting for idle.
536 * We will re-enable it at the start of the next xfer, 528 * We will re-enable it at the start of the next xfer,
@@ -541,7 +533,7 @@ retry:
541 adapter->name); 533 adapter->name);
542 ret = -ETIMEDOUT; 534 ret = -ETIMEDOUT;
543 } 535 }
544 I915_WRITE(GMBUS0 + reg_offset, 0); 536 I915_WRITE(GMBUS0, 0);
545 ret = ret ?: i; 537 ret = ret ?: i;
546 goto out; 538 goto out;
547 539
@@ -570,9 +562,9 @@ clear_err:
570 * of resetting the GMBUS controller and so clearing the 562 * of resetting the GMBUS controller and so clearing the
571 * BUS_ERROR raised by the slave's NAK. 563 * BUS_ERROR raised by the slave's NAK.
572 */ 564 */
573 I915_WRITE(GMBUS1 + reg_offset, GMBUS_SW_CLR_INT); 565 I915_WRITE(GMBUS1, GMBUS_SW_CLR_INT);
574 I915_WRITE(GMBUS1 + reg_offset, 0); 566 I915_WRITE(GMBUS1, 0);
575 I915_WRITE(GMBUS0 + reg_offset, 0); 567 I915_WRITE(GMBUS0, 0);
576 568
577 DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n", 569 DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n",
578 adapter->name, msgs[i].addr, 570 adapter->name, msgs[i].addr,
@@ -595,7 +587,7 @@ clear_err:
595timeout: 587timeout:
596 DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n", 588 DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n",
597 bus->adapter.name, bus->reg0 & 0xff); 589 bus->adapter.name, bus->reg0 & 0xff);
598 I915_WRITE(GMBUS0 + reg_offset, 0); 590 I915_WRITE(GMBUS0, 0);
599 591
600 /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */ 592 /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
601 bus->force_bit = 1; 593 bus->force_bit = 1;