Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
93 lines
2.1 KiB
C
93 lines
2.1 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2013-2021 Intel Corporation
|
|
*
|
|
* LPT/WPT IOSF sideband.
|
|
*/
|
|
|
|
#include <drm/drm_print.h>
|
|
|
|
#include "intel_de.h"
|
|
#include "intel_display_core.h"
|
|
#include "intel_sbi.h"
|
|
#include "intel_sbi_regs.h"
|
|
|
|
/* SBI access */
|
|
static int intel_sbi_rw(struct intel_display *display, u16 reg,
|
|
enum intel_sbi_destination destination,
|
|
u32 *val, bool is_read)
|
|
{
|
|
u32 cmd;
|
|
|
|
lockdep_assert_held(&display->sbi.lock);
|
|
|
|
if (intel_de_wait_fw_ms(display, SBI_CTL_STAT,
|
|
SBI_STATUS_MASK, SBI_STATUS_READY, 100, NULL)) {
|
|
drm_err(display->drm, "timeout waiting for SBI to become ready\n");
|
|
return -EBUSY;
|
|
}
|
|
|
|
intel_de_write_fw(display, SBI_ADDR, SBI_ADDR_VALUE(reg));
|
|
intel_de_write_fw(display, SBI_DATA, is_read ? 0 : *val);
|
|
|
|
if (destination == SBI_ICLK)
|
|
cmd = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
|
|
else
|
|
cmd = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
|
|
if (!is_read)
|
|
cmd |= SBI_CTL_OP_WR;
|
|
intel_de_write_fw(display, SBI_CTL_STAT, cmd | SBI_STATUS_BUSY);
|
|
|
|
if (intel_de_wait_fw_ms(display, SBI_CTL_STAT,
|
|
SBI_STATUS_MASK, SBI_STATUS_READY, 100, &cmd)) {
|
|
drm_err(display->drm, "timeout waiting for SBI to complete read\n");
|
|
return -ETIMEDOUT;
|
|
}
|
|
|
|
if (cmd & SBI_RESPONSE_FAIL) {
|
|
drm_err(display->drm, "error during SBI read of reg %x\n", reg);
|
|
return -ENXIO;
|
|
}
|
|
|
|
if (is_read)
|
|
*val = intel_de_read_fw(display, SBI_DATA);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void intel_sbi_lock(struct intel_display *display)
|
|
{
|
|
mutex_lock(&display->sbi.lock);
|
|
}
|
|
|
|
void intel_sbi_unlock(struct intel_display *display)
|
|
{
|
|
mutex_unlock(&display->sbi.lock);
|
|
}
|
|
|
|
u32 intel_sbi_read(struct intel_display *display, u16 reg,
|
|
enum intel_sbi_destination destination)
|
|
{
|
|
u32 result = 0;
|
|
|
|
intel_sbi_rw(display, reg, destination, &result, true);
|
|
|
|
return result;
|
|
}
|
|
|
|
void intel_sbi_write(struct intel_display *display, u16 reg, u32 value,
|
|
enum intel_sbi_destination destination)
|
|
{
|
|
intel_sbi_rw(display, reg, destination, &value, false);
|
|
}
|
|
|
|
void intel_sbi_init(struct intel_display *display)
|
|
{
|
|
mutex_init(&display->sbi.lock);
|
|
}
|
|
|
|
void intel_sbi_fini(struct intel_display *display)
|
|
{
|
|
mutex_destroy(&display->sbi.lock);
|
|
}
|