2021-10-14 13:28:58 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2013-05-22 15:36:16 +03:00
|
|
|
/*
|
2021-10-14 13:28:58 +03:00
|
|
|
* Copyright © 2013-2021 Intel Corporation
|
2013-05-22 15:36:16 +03:00
|
|
|
*
|
2021-10-14 13:28:58 +03:00
|
|
|
* LPT/WPT IOSF sideband.
|
2013-05-22 15:36:16 +03:00
|
|
|
*/
|
|
|
|
|
2025-05-27 13:59:12 +03:00
|
|
|
#include <drm/drm_print.h>
|
|
|
|
|
|
|
|
#include "intel_de.h"
|
2025-05-27 13:59:08 +03:00
|
|
|
#include "intel_display_core.h"
|
|
|
|
#include "intel_sbi.h"
|
2025-05-27 13:59:13 +03:00
|
|
|
#include "intel_sbi_regs.h"
|
2013-05-22 15:36:16 +03:00
|
|
|
|
|
|
|
/* SBI access */
|
2025-05-27 13:59:08 +03:00
|
|
|
static int intel_sbi_rw(struct intel_display *display, u16 reg,
|
2019-04-26 09:17:23 +01:00
|
|
|
enum intel_sbi_destination destination,
|
|
|
|
u32 *val, bool is_read)
|
2013-05-22 15:36:16 +03:00
|
|
|
{
|
2019-04-26 09:17:23 +01:00
|
|
|
u32 cmd;
|
2019-04-26 09:17:19 +01:00
|
|
|
|
2025-05-27 13:59:09 +03:00
|
|
|
lockdep_assert_held(&display->sbi.lock);
|
2013-05-22 15:36:16 +03:00
|
|
|
|
2025-05-27 13:59:14 +03:00
|
|
|
if (intel_de_wait_fw(display, SBI_CTL_STAT, SBI_STATUS_MASK, SBI_STATUS_READY, 100, NULL)) {
|
2025-05-27 13:59:08 +03:00
|
|
|
drm_err(display->drm, "timeout waiting for SBI to become ready\n");
|
2019-04-26 09:17:23 +01:00
|
|
|
return -EBUSY;
|
2013-05-22 15:36:16 +03:00
|
|
|
}
|
|
|
|
|
2025-05-27 13:59:14 +03:00
|
|
|
intel_de_write_fw(display, SBI_ADDR, SBI_ADDR_VALUE(reg));
|
2025-05-27 13:59:12 +03:00
|
|
|
intel_de_write_fw(display, SBI_DATA, is_read ? 0 : *val);
|
2013-05-22 15:36:16 +03:00
|
|
|
|
|
|
|
if (destination == SBI_ICLK)
|
2019-04-26 09:17:23 +01:00
|
|
|
cmd = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
|
2013-05-22 15:36:16 +03:00
|
|
|
else
|
2019-04-26 09:17:23 +01:00
|
|
|
cmd = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
|
|
|
|
if (!is_read)
|
2025-05-27 13:59:14 +03:00
|
|
|
cmd |= SBI_CTL_OP_WR;
|
|
|
|
intel_de_write_fw(display, SBI_CTL_STAT, cmd | SBI_STATUS_BUSY);
|
2019-04-26 09:17:23 +01:00
|
|
|
|
2025-05-27 13:59:14 +03:00
|
|
|
if (intel_de_wait_fw(display, SBI_CTL_STAT, SBI_STATUS_MASK, SBI_STATUS_READY, 100, &cmd)) {
|
2025-05-27 13:59:08 +03:00
|
|
|
drm_err(display->drm, "timeout waiting for SBI to complete read\n");
|
2019-04-26 09:17:23 +01:00
|
|
|
return -ETIMEDOUT;
|
2017-02-23 14:10:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 09:17:23 +01:00
|
|
|
if (cmd & SBI_RESPONSE_FAIL) {
|
2025-05-27 13:59:08 +03:00
|
|
|
drm_err(display->drm, "error during SBI read of reg %x\n", reg);
|
2019-04-26 09:17:23 +01:00
|
|
|
return -ENXIO;
|
2013-05-22 15:36:16 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 09:17:23 +01:00
|
|
|
if (is_read)
|
2025-05-27 13:59:12 +03:00
|
|
|
*val = intel_de_read_fw(display, SBI_DATA);
|
2019-04-26 09:17:23 +01:00
|
|
|
|
|
|
|
return 0;
|
2013-05-22 15:36:16 +03:00
|
|
|
}
|
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
void intel_sbi_lock(struct intel_display *display)
|
2024-10-29 11:25:23 +02:00
|
|
|
{
|
2025-05-27 13:59:09 +03:00
|
|
|
mutex_lock(&display->sbi.lock);
|
2024-10-29 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
void intel_sbi_unlock(struct intel_display *display)
|
2024-10-29 11:25:23 +02:00
|
|
|
{
|
2025-05-27 13:59:09 +03:00
|
|
|
mutex_unlock(&display->sbi.lock);
|
2024-10-29 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
u32 intel_sbi_read(struct intel_display *display, u16 reg,
|
2019-04-26 09:17:23 +01:00
|
|
|
enum intel_sbi_destination destination)
|
2013-05-22 15:36:16 +03:00
|
|
|
{
|
2019-04-26 09:17:23 +01:00
|
|
|
u32 result = 0;
|
2013-05-22 15:36:16 +03:00
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
intel_sbi_rw(display, reg, destination, &result, true);
|
2013-05-22 15:36:16 +03:00
|
|
|
|
2019-04-26 09:17:23 +01:00
|
|
|
return result;
|
|
|
|
}
|
2017-02-23 14:10:20 +00:00
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
void intel_sbi_write(struct intel_display *display, u16 reg, u32 value,
|
2019-04-26 09:17:23 +01:00
|
|
|
enum intel_sbi_destination destination)
|
|
|
|
{
|
2025-05-27 13:59:08 +03:00
|
|
|
intel_sbi_rw(display, reg, destination, &value, false);
|
2013-05-22 15:36:16 +03:00
|
|
|
}
|
2024-10-29 11:25:24 +02:00
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
void intel_sbi_init(struct intel_display *display)
|
2024-10-29 11:25:24 +02:00
|
|
|
{
|
2025-05-27 13:59:09 +03:00
|
|
|
mutex_init(&display->sbi.lock);
|
2024-10-29 11:25:24 +02:00
|
|
|
}
|
|
|
|
|
2025-05-27 13:59:08 +03:00
|
|
|
void intel_sbi_fini(struct intel_display *display)
|
2024-10-29 11:25:24 +02:00
|
|
|
{
|
2025-05-27 13:59:09 +03:00
|
|
|
mutex_destroy(&display->sbi.lock);
|
2024-10-29 11:25:24 +02:00
|
|
|
}
|