intel_sbi.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: MIT
  2. /*
  3. * Copyright © 2013-2021 Intel Corporation
  4. *
  5. * LPT/WPT IOSF sideband.
  6. */
  7. #include "i915_drv.h"
  8. #include "intel_sbi.h"
  9. #include "i915_reg.h"
  10. /* SBI access */
  11. static int intel_sbi_rw(struct drm_i915_private *i915, u16 reg,
  12. enum intel_sbi_destination destination,
  13. u32 *val, bool is_read)
  14. {
  15. struct intel_uncore *uncore = &i915->uncore;
  16. u32 cmd;
  17. lockdep_assert_held(&i915->sb_lock);
  18. if (intel_wait_for_register_fw(uncore,
  19. SBI_CTL_STAT, SBI_BUSY, 0,
  20. 100)) {
  21. drm_err(&i915->drm,
  22. "timeout waiting for SBI to become ready\n");
  23. return -EBUSY;
  24. }
  25. intel_uncore_write_fw(uncore, SBI_ADDR, (u32)reg << 16);
  26. intel_uncore_write_fw(uncore, SBI_DATA, is_read ? 0 : *val);
  27. if (destination == SBI_ICLK)
  28. cmd = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
  29. else
  30. cmd = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
  31. if (!is_read)
  32. cmd |= BIT(8);
  33. intel_uncore_write_fw(uncore, SBI_CTL_STAT, cmd | SBI_BUSY);
  34. if (__intel_wait_for_register_fw(uncore,
  35. SBI_CTL_STAT, SBI_BUSY, 0,
  36. 100, 100, &cmd)) {
  37. drm_err(&i915->drm,
  38. "timeout waiting for SBI to complete read\n");
  39. return -ETIMEDOUT;
  40. }
  41. if (cmd & SBI_RESPONSE_FAIL) {
  42. drm_err(&i915->drm, "error during SBI read of reg %x\n", reg);
  43. return -ENXIO;
  44. }
  45. if (is_read)
  46. *val = intel_uncore_read_fw(uncore, SBI_DATA);
  47. return 0;
  48. }
  49. u32 intel_sbi_read(struct drm_i915_private *i915, u16 reg,
  50. enum intel_sbi_destination destination)
  51. {
  52. u32 result = 0;
  53. intel_sbi_rw(i915, reg, destination, &result, true);
  54. return result;
  55. }
  56. void intel_sbi_write(struct drm_i915_private *i915, u16 reg, u32 value,
  57. enum intel_sbi_destination destination)
  58. {
  59. intel_sbi_rw(i915, reg, destination, &value, false);
  60. }