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