mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
Merge commit '33c51f42c402b76fd06e46d1ae73f8b7080b6f43'
* commit '33c51f42c402b76fd06e46d1ae73f8b7080b6f43': drm/rockchip: dp-mst-sim: support mst device without aux client arm64: configs: rockchip_linux_defconfig: enable CONFIG_ROCKCHIP_DP_MST_AUX_CLIENT ASoC: rockchip: multi-dais: Workaround for interleaved for GKI dmaengine: pl330: Workaround for interleaved for GKI arm64: dts: rockchip: rk3576-vehiclke-evb: use vehicle sound video: rockchip: mpp: fix unused buffer move fail issue arm64: dts: rockchip: rk3576: set aclk_php to 250M by default Change-Id: I8dee24be866d8641fabfbebd449474898d1e764a
This commit is contained in:
@@ -8,61 +8,6 @@
|
||||
#include "rk3576-rk806.dtsi"
|
||||
|
||||
/ {
|
||||
es8388_sound: es8388-sound {
|
||||
status = "disabled";
|
||||
compatible = "rockchip,multicodecs-card";
|
||||
rockchip,card-name = "rockchip-es8388";
|
||||
hp-det-gpio = <&gpio0 RK_PD3 GPIO_ACTIVE_LOW>;
|
||||
io-channels = <&saradc 3>;
|
||||
io-channel-names = "adc-detect";
|
||||
keyup-threshold-microvolt = <1800000>;
|
||||
poll-interval = <100>;
|
||||
spk-con-gpio = <&gpio2 RK_PB1 GPIO_ACTIVE_HIGH>;
|
||||
hp-con-gpio = <&gpio3 RK_PD6 GPIO_ACTIVE_HIGH>;
|
||||
rockchip,format = "i2s";
|
||||
rockchip,mclk-fs = <256>;
|
||||
rockchip,cpu = <&sai1>;
|
||||
rockchip,codec = <&es8388>;
|
||||
rockchip,audio-routing =
|
||||
"Headphone", "LOUT1",
|
||||
"Headphone", "ROUT1",
|
||||
"Speaker", "LOUT2",
|
||||
"Speaker", "ROUT2",
|
||||
"Headphone", "Headphone Power",
|
||||
"Headphone", "Headphone Power",
|
||||
"Speaker", "Speaker Power",
|
||||
"Speaker", "Speaker Power",
|
||||
"LINPUT1", "Main Mic",
|
||||
"LINPUT2", "Main Mic",
|
||||
"RINPUT1", "Headset Mic",
|
||||
"RINPUT2", "Headset Mic";
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&hp_det>;
|
||||
play-pause-key {
|
||||
label = "playpause";
|
||||
linux,code = <KEY_PLAYPAUSE>;
|
||||
press-threshold-microvolt = <2000>;
|
||||
};
|
||||
};
|
||||
|
||||
pdmics: dummy-codec {
|
||||
status = "disabled";
|
||||
compatible = "rockchip,dummy-codec";
|
||||
#sound-dai-cells = <0>;
|
||||
};
|
||||
|
||||
pdm_mic_array: pdm-mic-array {
|
||||
status = "disabled";
|
||||
compatible = "simple-audio-card";
|
||||
simple-audio-card,name = "rockchip,pdm-mic-array";
|
||||
simple-audio-card,cpu {
|
||||
sound-dai = <&pdm1>;
|
||||
};
|
||||
simple-audio-card,codec {
|
||||
sound-dai = <&pdmics>;
|
||||
};
|
||||
};
|
||||
|
||||
vcc5v0_buck: vcc5v0-buck {
|
||||
compatible = "regulator-fixed";
|
||||
regulator-name = "vcc5v0_buck";
|
||||
@@ -142,8 +87,6 @@
|
||||
vin-supply = <&vcc_3v3_s0>;
|
||||
};
|
||||
|
||||
|
||||
|
||||
vcc5v0_host_usb30: vcc5v0-host-usb30 {
|
||||
compatible = "regulator-fixed";
|
||||
regulator-name = "vcc5v0_host_usb30";
|
||||
@@ -176,7 +119,13 @@
|
||||
vin-supply = <&vcc5v0_buck>;
|
||||
};
|
||||
|
||||
car_rk3308_sound: car-rk3308-sound {
|
||||
dummy_codec: dummy-codec {
|
||||
status = "okay";
|
||||
compatible = "rockchip,dummy-codec";
|
||||
#sound-dai-cells = <0>;
|
||||
};
|
||||
|
||||
vehicle_adsp_sound: vehicle-adsp-sound {
|
||||
status = "okay";
|
||||
compatible = "simple-audio-card";
|
||||
simple-audio-card,name = "rockchip,car-rk3308-sound";
|
||||
@@ -190,7 +139,7 @@
|
||||
dai-tdm-slot-width = <32>;
|
||||
};
|
||||
codec_master: simple-audio-card,codec {
|
||||
sound-dai = <&spi_codec>;
|
||||
sound-dai = <&dummy_codec>;
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -223,7 +172,6 @@
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
|
||||
&gmac0 {
|
||||
/* Use rgmii-rxid mode to disable rx delay inside Soc */
|
||||
phy-mode = "rgmii-rxid";
|
||||
@@ -325,7 +273,6 @@
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&i2c7m1_xfer>;
|
||||
|
||||
|
||||
icm42607_acc: icm_acc@68 {
|
||||
status = "okay";
|
||||
compatible = "icm42607_acc";
|
||||
@@ -393,12 +340,6 @@
|
||||
};
|
||||
};
|
||||
|
||||
headphone {
|
||||
hp_det: hp-det {
|
||||
rockchip,pins = <0 RK_PD3 RK_FUNC_GPIO &pcfg_pull_up>;
|
||||
};
|
||||
};
|
||||
|
||||
s35390a {
|
||||
s35390a_int: s35390a-int {
|
||||
rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
|
||||
@@ -435,12 +376,6 @@
|
||||
rockchip,pins = <1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_up>;
|
||||
};
|
||||
};
|
||||
|
||||
rk3308 {
|
||||
rk3308_reset: rk3308-reset {
|
||||
rockchip,pins = <2 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&route_hdmi {
|
||||
@@ -452,15 +387,15 @@
|
||||
status = "okay";
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&sai1m0_lrck
|
||||
&sai1m0_sclk
|
||||
&sai1m0_sdi0
|
||||
&sai1m0_sdi1
|
||||
&sai1m0_sdi2
|
||||
&sai1m0_sdi3
|
||||
&sai1m0_sdo0
|
||||
&sai1m0_sdo1
|
||||
&sai1m0_sdo2
|
||||
&sai1m0_sdo3>;
|
||||
&sai1m0_sclk
|
||||
&sai1m0_sdi0
|
||||
&sai1m0_sdi1
|
||||
&sai1m0_sdi2
|
||||
&sai1m0_sdi3
|
||||
&sai1m0_sdo0
|
||||
&sai1m0_sdo1
|
||||
&sai1m0_sdo2
|
||||
&sai1m0_sdo3>;
|
||||
};
|
||||
|
||||
&sdmmc {
|
||||
@@ -469,18 +404,14 @@
|
||||
|
||||
&spi1 {
|
||||
status = "okay";
|
||||
pinctrl-names = "default";
|
||||
max-freq = <50000000>; /* spi internal clk, don't modify */
|
||||
pinctrl-names = "default", "high_speed";
|
||||
pinctrl-0 = <&spi1m1_csn0 &spi1m1_pins>;
|
||||
|
||||
spi_codec: spi-codec@1 {
|
||||
compatible ="rockchip,spi-codec";
|
||||
reg = <1>;
|
||||
spi_dev@0 {
|
||||
compatible = "rockchip,spidev";
|
||||
reg = <0>;
|
||||
spi-max-frequency = <50000000>;
|
||||
spi-lsb-first;
|
||||
spi-max-frequency = <5000000>;
|
||||
#sound-dai-cells = <0>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&rk3308_reset>;
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1781,7 +1781,8 @@
|
||||
<&cru CLK_UART_FRAC_1>, <&cru CLK_UART_FRAC_2>,
|
||||
<&cru CLK_AUDIO_FRAC_0>, <&cru CLK_AUDIO_FRAC_1>,
|
||||
<&cru CLK_CPLL_DIV2>, <&cru CLK_CPLL_DIV4>,
|
||||
<&cru CLK_CPLL_DIV10>, <&cru FCLK_DDR_CM0_CORE>;
|
||||
<&cru CLK_CPLL_DIV10>, <&cru FCLK_DDR_CM0_CORE>,
|
||||
<&cru ACLK_PHP_ROOT>;
|
||||
assigned-clock-parents = <&cru PLL_AUPLL>;
|
||||
assigned-clock-rates =
|
||||
<0>,
|
||||
@@ -1790,7 +1791,8 @@
|
||||
<96000000>, <128000000>,
|
||||
<45158400>, <49152000>,
|
||||
<500000000>, <250000000>,
|
||||
<100000000>, <500000000>;
|
||||
<100000000>, <500000000>,
|
||||
<250000000>;
|
||||
};
|
||||
|
||||
i2c0: i2c@27300000 {
|
||||
|
||||
@@ -355,6 +355,7 @@ CONFIG_ROCKCHIP_INNO_HDMI=y
|
||||
CONFIG_ROCKCHIP_LVDS=y
|
||||
CONFIG_ROCKCHIP_RGB=y
|
||||
CONFIG_ROCKCHIP_DW_HDCP2=y
|
||||
CONFIG_ROCKCHIP_DP_MST_AUX_CLIENT=y
|
||||
CONFIG_DRM_PANEL_SIMPLE=y
|
||||
CONFIG_DRM_DISPLAY_CONNECTOR=y
|
||||
CONFIG_DRM_SII902X=y
|
||||
|
||||
@@ -2943,6 +2943,8 @@ static struct dma_async_tx_descriptor *pl330_prep_interleaved_dma(
|
||||
|
||||
#ifdef CONFIG_NO_GKI
|
||||
nump = xt->nump;
|
||||
#else
|
||||
nump = xt->sgl[1].size;
|
||||
#endif
|
||||
numf = xt->numf;
|
||||
size = xt->sgl[0].size;
|
||||
|
||||
@@ -173,6 +173,12 @@ config ROCKCHIP_DW_HDCP2
|
||||
Choose this option to enable support for the Synopsys
|
||||
Designware HDCP2 Controller.
|
||||
|
||||
config ROCKCHIP_DP_MST_AUX_CLIENT
|
||||
tristate "dp mst aux client"
|
||||
select DRM_DISPLAY_DP_HELPER
|
||||
help
|
||||
This selects support dp mst device that not support aux client.
|
||||
|
||||
source "drivers/gpu/drm/rockchip/rk618/Kconfig"
|
||||
source "drivers/gpu/drm/rockchip/ebc-dev/Kconfig"
|
||||
|
||||
|
||||
@@ -33,3 +33,6 @@ obj-$(CONFIG_ROCKCHIP_DW_HDCP2) += dw_hdcp2.o
|
||||
obj-$(CONFIG_DRM_ROCKCHIP) += rockchipdrm.o
|
||||
obj-$(CONFIG_DRM_ROCKCHIP_RK618) += rk618/
|
||||
obj-$(CONFIG_ROCKCHIP_EBC_DEV) += ebc-dev/
|
||||
|
||||
rockchip_aux_client-y := rockchip_dp_mst_aux_client.o rockchip_dp_mst_aux_client_helper.o
|
||||
obj-$(CONFIG_ROCKCHIP_DP_MST_AUX_CLIENT) += rockchip_aux_client.o
|
||||
|
||||
326
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client.c
Normal file
326
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client.c
Normal file
@@ -0,0 +1,326 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Rockchip DP MST simulation axu client
|
||||
*
|
||||
* Copyright (c) 2024 Rockchip Electronics Co. Ltd.
|
||||
*
|
||||
* Author: Zhang Yubing <yubing.zhang@rock-chips.com>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/of.h>
|
||||
#include <drm/drm_edid.h>
|
||||
#include <drm/drm_modes.h>
|
||||
#include <drm/display/drm_dp_helper.h>
|
||||
#include <video/display_timing.h>
|
||||
#include <video/of_display_timing.h>
|
||||
#include <video/videomode.h>
|
||||
|
||||
#include "rockchip_dp_mst_aux_client_helper.h"
|
||||
#include "rockchip_dp_mst_aux_client.h"
|
||||
|
||||
static DEFINE_MUTEX(aux_client_lock);
|
||||
static LIST_HEAD(aux_client_list);
|
||||
|
||||
#define to_rockchip_dp_aux_client(x) container_of((x), struct rockchip_dp_aux_client, bridge)
|
||||
|
||||
static const struct rockchip_dp_mst_sim_port output_port = {
|
||||
false, false, true, 3, false, 0x12,
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
0, 0, 2520, 2520, NULL, 0
|
||||
};
|
||||
|
||||
struct rockchip_dp_aux_client *rockchip_dp_get_aux_client(struct device_node *node,
|
||||
char *handle_name)
|
||||
{
|
||||
struct rockchip_dp_aux_client *aux_client;
|
||||
struct device_node *dev_node;
|
||||
|
||||
dev_node = of_parse_phandle(node, handle_name, 0);
|
||||
if (!dev_node)
|
||||
return NULL;
|
||||
|
||||
mutex_lock(&aux_client_lock);
|
||||
list_for_each_entry(aux_client, &aux_client_list, head)
|
||||
if (aux_client->dev->of_node == dev_node)
|
||||
goto out;
|
||||
aux_client = ERR_PTR(-EPROBE_DEFER);
|
||||
|
||||
out:
|
||||
mutex_unlock(&aux_client_lock);
|
||||
of_node_put(dev_node);
|
||||
|
||||
return aux_client;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_dp_get_aux_client);
|
||||
|
||||
static void rockchip_register_dp_aux_client(struct rockchip_dp_aux_client *aux_client)
|
||||
{
|
||||
|
||||
mutex_lock(&aux_client_lock);
|
||||
list_add(&aux_client->head, &aux_client_list);
|
||||
mutex_unlock(&aux_client_lock);
|
||||
}
|
||||
|
||||
static void rockchip_unregister_dp_aux_client(struct rockchip_dp_aux_client *aux_client)
|
||||
{
|
||||
|
||||
mutex_lock(&aux_client_lock);
|
||||
list_del(&aux_client->head);
|
||||
mutex_unlock(&aux_client_lock);
|
||||
}
|
||||
|
||||
static int rockchip_dp_aux_client_register_hpd_irq(struct rockchip_dp_aux_client *aux_client,
|
||||
void (*hpd_irq_cb)(void *), void *dev)
|
||||
{
|
||||
aux_client->host_dev = dev;
|
||||
aux_client->hpd_irq_cb = hpd_irq_cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_dp_aux_client_register_transfer(struct rockchip_dp_aux_client *aux_client,
|
||||
ssize_t (*transfer_cb)(struct drm_dp_aux *, struct drm_dp_aux_msg *))
|
||||
{
|
||||
aux_client->transfer_cb = transfer_cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t rockchip_dp_sim_transfer(struct rockchip_dp_aux_client *aux_client,
|
||||
struct drm_dp_aux *drm_aux,
|
||||
struct drm_dp_aux_msg *msg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rockchip_dp_mst_sim_transfer(aux_client->mst_ctx, msg);
|
||||
if (ret < 0) {
|
||||
if (aux_client->transfer_cb)
|
||||
ret = aux_client->transfer_cb(drm_aux, msg);
|
||||
else
|
||||
ret = -EIO;
|
||||
} else {
|
||||
ret = msg->size;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void rockchip_dp_sim_host_hpd_irq(void *host_dev)
|
||||
{
|
||||
struct rockchip_dp_aux_client *aux_client = host_dev;
|
||||
|
||||
if (aux_client->hpd_irq_cb)
|
||||
aux_client->hpd_irq_cb(aux_client->host_dev);
|
||||
}
|
||||
|
||||
static void rockchip_dp_sim_update_dtd(struct edid *edid,
|
||||
struct drm_display_mode *mode)
|
||||
{
|
||||
struct detailed_timing *dtd = &edid->detailed_timings[0];
|
||||
struct detailed_pixel_timing *pd = &dtd->data.pixel_data;
|
||||
u32 h_blank = mode->htotal - mode->hdisplay;
|
||||
u32 v_blank = mode->vtotal - mode->vdisplay;
|
||||
u32 h_img = 0, v_img = 0;
|
||||
|
||||
dtd->pixel_clock = cpu_to_le16(mode->clock / 10);
|
||||
|
||||
pd->hactive_lo = mode->hdisplay & 0xFF;
|
||||
pd->hblank_lo = h_blank & 0xFF;
|
||||
pd->hactive_hblank_hi = ((h_blank >> 8) & 0xF) |
|
||||
((mode->hdisplay >> 8) & 0xF) << 4;
|
||||
|
||||
pd->vactive_lo = mode->vdisplay & 0xFF;
|
||||
pd->vblank_lo = v_blank & 0xFF;
|
||||
pd->vactive_vblank_hi = ((v_blank >> 8) & 0xF) |
|
||||
((mode->vdisplay >> 8) & 0xF) << 4;
|
||||
|
||||
pd->hsync_offset_lo =
|
||||
(mode->hsync_start - mode->hdisplay) & 0xFF;
|
||||
pd->hsync_pulse_width_lo =
|
||||
(mode->hsync_end - mode->hsync_start) & 0xFF;
|
||||
pd->vsync_offset_pulse_width_lo =
|
||||
(((mode->vsync_start - mode->vdisplay) & 0xF) << 4) |
|
||||
((mode->vsync_end - mode->vsync_start) & 0xF);
|
||||
|
||||
pd->hsync_vsync_offset_pulse_width_hi =
|
||||
((((mode->hsync_start - mode->hdisplay) >> 8) & 0x3) << 6) |
|
||||
((((mode->hsync_end - mode->hsync_start) >> 8) & 0x3) << 4) |
|
||||
((((mode->vsync_start - mode->vdisplay) >> 4) & 0x3) << 2) |
|
||||
((((mode->vsync_end - mode->vsync_start) >> 4) & 0x3) << 0);
|
||||
|
||||
pd->width_mm_lo = h_img & 0xFF;
|
||||
pd->height_mm_lo = v_img & 0xFF;
|
||||
pd->width_height_mm_hi = (((h_img >> 8) & 0xF) << 4) |
|
||||
((v_img >> 8) & 0xF);
|
||||
|
||||
pd->hborder = 0;
|
||||
pd->vborder = 0;
|
||||
pd->misc = 0;
|
||||
}
|
||||
|
||||
static void rockchip_dp_sim_update_checksum(struct edid *edid)
|
||||
{
|
||||
u8 *data = (u8 *)edid;
|
||||
u32 i, sum = 0;
|
||||
|
||||
for (i = 0; i < EDID_LENGTH - 1; i++)
|
||||
sum += data[i];
|
||||
|
||||
edid->checksum = 0x100 - (sum & 0xFF);
|
||||
}
|
||||
|
||||
static int rockchip_dp_aux_client_parse(struct rockchip_dp_aux_client *aux_client)
|
||||
{
|
||||
struct device_node *of_node = aux_client->dev->of_node;
|
||||
struct device_node *node;
|
||||
struct rockchip_dp_mst_sim_port *ports;
|
||||
struct drm_display_mode mode_buf, *mode = &mode_buf;
|
||||
int rc, port_num, i;
|
||||
struct edid *edid;
|
||||
|
||||
const u8 edid_buf[EDID_LENGTH] = {
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x44, 0x6D,
|
||||
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1B, 0x10, 0x01, 0x03,
|
||||
0x80, 0x50, 0x2D, 0x78, 0x0A, 0x0D, 0xC9, 0xA0, 0x57, 0x47,
|
||||
0x98, 0x27, 0x12, 0x48, 0x4C, 0x00, 0x00, 0x00, 0x01, 0x01,
|
||||
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
||||
0x01, 0x01, 0x01, 0x01,
|
||||
};
|
||||
|
||||
port_num = of_get_child_count(of_node);
|
||||
|
||||
if (!port_num)
|
||||
return 0;
|
||||
|
||||
if (port_num >= 15)
|
||||
return -EINVAL;
|
||||
|
||||
ports = kcalloc(port_num, sizeof(*ports), GFP_KERNEL);
|
||||
if (!ports)
|
||||
return -ENOMEM;
|
||||
|
||||
i = 0;
|
||||
for_each_child_of_node(of_node, node) {
|
||||
struct display_timing dt;
|
||||
struct videomode vm;
|
||||
|
||||
edid = kzalloc(sizeof(*edid), GFP_KERNEL);
|
||||
if (!edid) {
|
||||
rc = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
memcpy(edid, edid_buf, sizeof(edid_buf));
|
||||
|
||||
if (!of_get_display_timing(node, "display-timings", &dt)) {
|
||||
videomode_from_timing(&dt, &vm);
|
||||
drm_display_mode_from_videomode(&vm, mode);
|
||||
rockchip_dp_sim_update_dtd(edid, mode);
|
||||
}
|
||||
|
||||
rockchip_dp_sim_update_checksum(edid);
|
||||
memcpy(&ports[i], &output_port, sizeof(*ports));
|
||||
ports[i].peer_guid[0] = i;
|
||||
ports[i].edid = (u8 *)edid;
|
||||
ports[i].edid_size = sizeof(*edid);
|
||||
i++;
|
||||
}
|
||||
|
||||
rc = rockchip_dp_mst_sim_update(aux_client->mst_ctx, port_num, ports);
|
||||
|
||||
fail:
|
||||
for (i = 0; i < port_num; i++)
|
||||
kfree(ports[i].edid);
|
||||
kfree(ports);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int rockchip_dp_aux_client_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct rockchip_dp_aux_client *aux_client;
|
||||
struct rockchip_dp_mst_sim_cfg cfg;
|
||||
int ret;
|
||||
|
||||
aux_client = devm_kzalloc(&pdev->dev, sizeof(*aux_client), GFP_KERNEL);
|
||||
if (!aux_client)
|
||||
return -ENOMEM;
|
||||
|
||||
aux_client->dev = &pdev->dev;
|
||||
aux_client->register_hpd_irq = rockchip_dp_aux_client_register_hpd_irq;
|
||||
aux_client->register_transfer = rockchip_dp_aux_client_register_transfer;
|
||||
aux_client->transfer = rockchip_dp_sim_transfer;
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.host_dev = aux_client;
|
||||
cfg.host_hpd_irq = rockchip_dp_sim_host_hpd_irq;
|
||||
cfg.guid[0] = 0xff;
|
||||
|
||||
ret = rockchip_dp_mst_sim_create(&cfg, &aux_client->mst_ctx);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = rockchip_dp_aux_client_parse(aux_client);
|
||||
if (ret)
|
||||
goto fail;
|
||||
|
||||
platform_set_drvdata(pdev, aux_client);
|
||||
|
||||
rockchip_register_dp_aux_client(aux_client);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
rockchip_dp_mst_sim_destroy(aux_client->mst_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rockchip_dp_aux_client_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct rockchip_dp_aux_client *aux_client;
|
||||
|
||||
aux_client = platform_get_drvdata(pdev);
|
||||
if (!aux_client)
|
||||
return 0;
|
||||
|
||||
rockchip_unregister_dp_aux_client(aux_client);
|
||||
rockchip_dp_mst_sim_destroy(aux_client->mst_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id dt_match[] = {
|
||||
{ .compatible = "rockchip,dp-mst-sim" },
|
||||
{},
|
||||
};
|
||||
|
||||
static struct platform_driver rockchip_dp_aux_client_driver = {
|
||||
.probe = rockchip_dp_aux_client_probe,
|
||||
.remove = rockchip_dp_aux_client_remove,
|
||||
.driver = {
|
||||
.name = "rockchip_dp_aux_client",
|
||||
.of_match_table = dt_match,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init rockchip_dp_aux_client_register(void)
|
||||
{
|
||||
return platform_driver_register(&rockchip_dp_aux_client_driver);
|
||||
}
|
||||
|
||||
static void __exit rockchip_dp_aux_client_unregister(void)
|
||||
{
|
||||
platform_driver_unregister(&rockchip_dp_aux_client_driver);
|
||||
}
|
||||
|
||||
module_init(rockchip_dp_aux_client_register);
|
||||
module_exit(rockchip_dp_aux_client_unregister);
|
||||
|
||||
MODULE_AUTHOR("Zhang Yubing <yubing.zhang@rock-chips.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Rockchip DP Simulate Aux Client Driver");
|
||||
41
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client.h
Normal file
41
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* Copyright (c) 2024 Rockchip Electronics Co. Ltd.
|
||||
* Author: Zhang Yubing <yubing.zhang@rock-chips.com>
|
||||
*/
|
||||
|
||||
#ifndef _ROCKCHIP_DP_MST_AUX_CLIENT_H_
|
||||
#define _ROCKCHIP_DP_MST_AUX_CLIENT_H_
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <drm/display/drm_dp_helper.h>
|
||||
|
||||
struct rockchip_dp_aux_client {
|
||||
struct device *dev;
|
||||
struct list_head head;
|
||||
void *mst_ctx;
|
||||
void *host_dev;
|
||||
void (*hpd_irq_cb)(void *host_dev);
|
||||
ssize_t (*transfer_cb)(struct drm_dp_aux *drm_aux,
|
||||
struct drm_dp_aux_msg *msg);
|
||||
int (*register_hpd_irq)(struct rockchip_dp_aux_client *aux_client,
|
||||
void (*hpd_irq_cb)(void *), void *dev);
|
||||
int (*register_transfer)(struct rockchip_dp_aux_client *aux_client,
|
||||
ssize_t (*transfer)(struct drm_dp_aux *, struct drm_dp_aux_msg *));
|
||||
ssize_t (*transfer)(struct rockchip_dp_aux_client *aux_client,
|
||||
struct drm_dp_aux *drm_aux,
|
||||
struct drm_dp_aux_msg *msg);
|
||||
};
|
||||
|
||||
#if IS_REACHABLE(CONFIG_ROCKCHIP_DP_MST_AUX_CLIENT)
|
||||
struct rockchip_dp_aux_client *rockchip_dp_get_aux_client(struct device_node *node,
|
||||
char *handle_name);
|
||||
#else
|
||||
static inline struct rockchip_dp_aux_client *rockchip_dp_get_aux_client(struct device_node *node,
|
||||
char *handle_name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
938
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client_helper.c
Normal file
938
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client_helper.c
Normal file
@@ -0,0 +1,938 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Rockchip DP MST simulation axu client
|
||||
*
|
||||
* Copyright (c) 2024 Rockchip Electronics Co. Ltd.
|
||||
*
|
||||
* Author: Zhang Yubing <yubing.zhang@rock-chips.com>
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/delay.h>
|
||||
#include <drm/drm_fixed.h>
|
||||
#include <drm/drm_edid.h>
|
||||
#include <drm/drm_print.h>
|
||||
#include <drm/display/drm_dp_mst_helper.h>
|
||||
|
||||
#include "rockchip_dp_mst_aux_client_helper.h"
|
||||
|
||||
#define DDC_SEGMENT_ADDR 0x30
|
||||
|
||||
struct rockchip_dp_mst_sim_context {
|
||||
void *host_dev;
|
||||
void (*host_hpd_irq)(void *host_dev);
|
||||
void (*host_req)(void *host_dev, const u8 *in, int in_size,
|
||||
u8 *out, int *out_size);
|
||||
|
||||
struct rockchip_dp_mst_sim_port *ports;
|
||||
u32 port_num;
|
||||
|
||||
struct drm_dp_sideband_msg_rx down_req;
|
||||
struct drm_dp_sideband_msg_rx down_rep;
|
||||
|
||||
struct mutex session_lock;
|
||||
struct completion session_comp;
|
||||
struct workqueue_struct *wq;
|
||||
|
||||
u8 esi[16];
|
||||
u8 guid[16];
|
||||
u8 dpcd[1024];
|
||||
};
|
||||
|
||||
struct rockchip_dp_mst_sim_work {
|
||||
struct work_struct base;
|
||||
struct rockchip_dp_mst_sim_context *ctx;
|
||||
unsigned int address;
|
||||
u8 buffer[256];
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static void rockchip_dp_sideband_hex_dump(const char *name,
|
||||
u32 address, u8 *buffer, size_t size)
|
||||
{
|
||||
char prefix[64];
|
||||
int i, linelen, remaining = size;
|
||||
const int rowsize = 16;
|
||||
u8 linebuf[64];
|
||||
|
||||
snprintf(prefix, sizeof(prefix), "%s(%d) %4xh(%2zu): ",
|
||||
name, current->pid, address, size);
|
||||
|
||||
for (i = 0; i < size; i += rowsize) {
|
||||
linelen = min(remaining, rowsize);
|
||||
remaining -= rowsize;
|
||||
|
||||
hex_dump_to_buffer(buffer + i, linelen, rowsize, 1,
|
||||
linebuf, sizeof(linebuf), false);
|
||||
|
||||
pr_debug("%s%s\n", prefix, linebuf);
|
||||
}
|
||||
}
|
||||
|
||||
static u8 drm_dp_msg_header_crc4(const uint8_t *data, size_t num_nibbles)
|
||||
{
|
||||
u8 bitmask = 0x80;
|
||||
u8 bitshift = 7;
|
||||
u8 array_index = 0;
|
||||
int number_of_bits = num_nibbles * 4;
|
||||
u8 remainder = 0;
|
||||
|
||||
while (number_of_bits != 0) {
|
||||
number_of_bits--;
|
||||
remainder <<= 1;
|
||||
remainder |= (data[array_index] & bitmask) >> bitshift;
|
||||
bitmask >>= 1;
|
||||
bitshift--;
|
||||
if (bitmask == 0) {
|
||||
bitmask = 0x80;
|
||||
bitshift = 7;
|
||||
array_index++;
|
||||
}
|
||||
if ((remainder & 0x10) == 0x10)
|
||||
remainder ^= 0x13;
|
||||
}
|
||||
|
||||
number_of_bits = 4;
|
||||
while (number_of_bits != 0) {
|
||||
number_of_bits--;
|
||||
remainder <<= 1;
|
||||
if ((remainder & 0x10) != 0)
|
||||
remainder ^= 0x13;
|
||||
}
|
||||
|
||||
return remainder;
|
||||
}
|
||||
|
||||
static u8 drm_dp_msg_data_crc4(const uint8_t *data, u8 number_of_bytes)
|
||||
{
|
||||
u8 bitmask = 0x80;
|
||||
u8 bitshift = 7;
|
||||
u8 array_index = 0;
|
||||
int number_of_bits = number_of_bytes * 8;
|
||||
u16 remainder = 0;
|
||||
|
||||
while (number_of_bits != 0) {
|
||||
number_of_bits--;
|
||||
remainder <<= 1;
|
||||
remainder |= (data[array_index] & bitmask) >> bitshift;
|
||||
bitmask >>= 1;
|
||||
bitshift--;
|
||||
if (bitmask == 0) {
|
||||
bitmask = 0x80;
|
||||
bitshift = 7;
|
||||
array_index++;
|
||||
}
|
||||
if ((remainder & 0x100) == 0x100)
|
||||
remainder ^= 0xd5;
|
||||
}
|
||||
|
||||
number_of_bits = 8;
|
||||
while (number_of_bits != 0) {
|
||||
number_of_bits--;
|
||||
remainder <<= 1;
|
||||
if ((remainder & 0x100) != 0)
|
||||
remainder ^= 0xd5;
|
||||
}
|
||||
|
||||
return remainder & 0xff;
|
||||
}
|
||||
|
||||
static bool drm_dp_decode_sideband_msg_hdr(struct drm_dp_sideband_msg_hdr *hdr,
|
||||
u8 *buf, int buflen, u8 *hdrlen)
|
||||
{
|
||||
u8 crc4;
|
||||
u8 len;
|
||||
int i;
|
||||
u8 idx;
|
||||
|
||||
if (buf[0] == 0)
|
||||
return false;
|
||||
len = 3;
|
||||
len += ((buf[0] & 0xf0) >> 4) / 2;
|
||||
if (len > buflen)
|
||||
return false;
|
||||
crc4 = drm_dp_msg_header_crc4(buf, (len * 2) - 1);
|
||||
|
||||
if ((crc4 & 0xf) != (buf[len - 1] & 0xf)) {
|
||||
DRM_DEBUG_KMS("crc4 mismatch 0x%x 0x%x\n", crc4, buf[len - 1]);
|
||||
return false;
|
||||
}
|
||||
|
||||
hdr->lct = (buf[0] & 0xf0) >> 4;
|
||||
hdr->lcr = (buf[0] & 0xf);
|
||||
idx = 1;
|
||||
for (i = 0; i < (hdr->lct / 2); i++)
|
||||
hdr->rad[i] = buf[idx++];
|
||||
hdr->broadcast = (buf[idx] >> 7) & 0x1;
|
||||
hdr->path_msg = (buf[idx] >> 6) & 0x1;
|
||||
hdr->msg_len = buf[idx] & 0x3f;
|
||||
idx++;
|
||||
hdr->somt = (buf[idx] >> 7) & 0x1;
|
||||
hdr->eomt = (buf[idx] >> 6) & 0x1;
|
||||
hdr->seqno = (buf[idx] >> 4) & 0x1;
|
||||
idx++;
|
||||
*hdrlen = idx;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool drm_dp_sideband_msg_build(struct drm_dp_sideband_msg_rx *msg,
|
||||
u8 *replybuf, u8 replybuflen, bool hdr)
|
||||
{
|
||||
int ret;
|
||||
u8 crc4;
|
||||
|
||||
if (hdr) {
|
||||
u8 hdrlen;
|
||||
struct drm_dp_sideband_msg_hdr recv_hdr;
|
||||
|
||||
ret = drm_dp_decode_sideband_msg_hdr(&recv_hdr,
|
||||
replybuf, replybuflen, &hdrlen);
|
||||
if (ret == false)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* ignore out-of-order messages or messages that are part of a
|
||||
* failed transaction
|
||||
*/
|
||||
if (!recv_hdr.somt && !msg->have_somt)
|
||||
return false;
|
||||
|
||||
/* get length contained in this portion */
|
||||
msg->curchunk_len = recv_hdr.msg_len;
|
||||
msg->curchunk_hdrlen = hdrlen;
|
||||
|
||||
/* we have already gotten an somt - don't bother parsing */
|
||||
if (recv_hdr.somt && msg->have_somt)
|
||||
return false;
|
||||
|
||||
if (recv_hdr.somt) {
|
||||
memcpy(&msg->initial_hdr, &recv_hdr,
|
||||
sizeof(struct drm_dp_sideband_msg_hdr));
|
||||
msg->have_somt = true;
|
||||
}
|
||||
if (recv_hdr.eomt)
|
||||
msg->have_eomt = true;
|
||||
|
||||
/* copy the bytes for the remainder of this header chunk */
|
||||
msg->curchunk_idx = min(msg->curchunk_len,
|
||||
(u8)(replybuflen - hdrlen));
|
||||
memcpy(&msg->chunk[0], replybuf + hdrlen, msg->curchunk_idx);
|
||||
} else {
|
||||
memcpy(&msg->chunk[msg->curchunk_idx], replybuf, replybuflen);
|
||||
msg->curchunk_idx += replybuflen;
|
||||
}
|
||||
|
||||
if (msg->curchunk_idx >= msg->curchunk_len) {
|
||||
/* do CRC */
|
||||
crc4 = drm_dp_msg_data_crc4(msg->chunk, msg->curchunk_len - 1);
|
||||
if (crc4 != msg->chunk[msg->curchunk_len - 1])
|
||||
pr_warn("msg crc4 check fail\n");
|
||||
/* copy chunk into bigger msg */
|
||||
memcpy(&msg->msg[msg->curlen], msg->chunk,
|
||||
msg->curchunk_len - 1);
|
||||
msg->curlen += msg->curchunk_len - 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void drm_dp_encode_sideband_msg_hdr(struct drm_dp_sideband_msg_hdr *hdr,
|
||||
u8 *buf, int *len)
|
||||
{
|
||||
int idx = 0;
|
||||
int i;
|
||||
u8 crc4;
|
||||
|
||||
buf[idx++] = ((hdr->lct & 0xf) << 4) | (hdr->lcr & 0xf);
|
||||
for (i = 0; i < (hdr->lct / 2); i++)
|
||||
buf[idx++] = hdr->rad[i];
|
||||
buf[idx++] = (hdr->broadcast << 7) | (hdr->path_msg << 6) |
|
||||
(hdr->msg_len & 0x3f);
|
||||
buf[idx++] = (hdr->somt << 7) | (hdr->eomt << 6) | (hdr->seqno << 4);
|
||||
|
||||
crc4 = drm_dp_msg_header_crc4(buf, (idx * 2) - 1);
|
||||
buf[idx - 1] |= (crc4 & 0xf);
|
||||
|
||||
*len = idx;
|
||||
}
|
||||
|
||||
static bool rockchip_dp_get_one_sb_msg(struct drm_dp_sideband_msg_rx *msg,
|
||||
struct drm_dp_aux_msg *aux_msg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!msg->have_somt) {
|
||||
ret = drm_dp_sideband_msg_build(msg,
|
||||
aux_msg->buffer, aux_msg->size, true);
|
||||
if (!ret) {
|
||||
pr_err("sideband hdr build failed\n");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ret = drm_dp_sideband_msg_build(msg,
|
||||
aux_msg->buffer, aux_msg->size, false);
|
||||
if (!ret) {
|
||||
pr_err("sideband msg build failed\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
rockchip_dp_sideband_build_nak_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
struct drm_dp_sideband_msg_rx *msg = &ctx->down_req;
|
||||
u8 *buf = ctx->down_rep.msg;
|
||||
int idx = 0;
|
||||
|
||||
buf[idx] = msg->msg[0] | 0x80;
|
||||
idx++;
|
||||
|
||||
memcpy(&buf[idx], ctx->guid, 16);
|
||||
idx += 16;
|
||||
|
||||
buf[idx] = 0x4;
|
||||
idx++;
|
||||
|
||||
buf[idx] = 0;
|
||||
idx++;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
rockchip_dp_sideband_build_link_address_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_port *port;
|
||||
u8 *buf = ctx->down_rep.msg;
|
||||
int idx = 0;
|
||||
u32 i, tmp;
|
||||
|
||||
buf[idx] = DP_LINK_ADDRESS;
|
||||
idx++;
|
||||
|
||||
memcpy(&buf[idx], ctx->guid, 16);
|
||||
idx += 16;
|
||||
|
||||
buf[idx] = ctx->port_num;
|
||||
idx++;
|
||||
|
||||
for (i = 0; i < ctx->port_num; i++) {
|
||||
port = &ctx->ports[i];
|
||||
|
||||
tmp = 0;
|
||||
if (port->input)
|
||||
tmp |= 0x80;
|
||||
tmp |= port->pdt << 4;
|
||||
tmp |= i & 0xF;
|
||||
buf[idx] = tmp;
|
||||
idx++;
|
||||
|
||||
tmp = 0;
|
||||
if (port->mcs)
|
||||
tmp |= 0x80;
|
||||
if (port->ddps)
|
||||
tmp |= 0x40;
|
||||
|
||||
if (port->input) {
|
||||
buf[idx] = tmp;
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port->ldps)
|
||||
tmp |= 0x20;
|
||||
buf[idx] = tmp;
|
||||
idx++;
|
||||
|
||||
buf[idx] = port->dpcd_rev;
|
||||
idx++;
|
||||
|
||||
memcpy(&buf[idx], port->peer_guid, 16);
|
||||
idx += 16;
|
||||
|
||||
buf[idx] = (port->num_sdp_streams << 4) |
|
||||
(port->num_sdp_stream_sinks);
|
||||
idx++;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
static int rockchip_dp_sideband_build_remote_i2c_read_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_port *port;
|
||||
struct drm_dp_remote_i2c_read i2c_read;
|
||||
u8 *buf;
|
||||
int idx;
|
||||
u32 i, start, len;
|
||||
|
||||
buf = ctx->down_req.msg;
|
||||
idx = 1;
|
||||
|
||||
i2c_read.num_transactions = buf[idx] & 0x3;
|
||||
i2c_read.port_number = buf[idx] >> 4;
|
||||
idx++;
|
||||
|
||||
if (i2c_read.port_number >= ctx->port_num)
|
||||
goto err;
|
||||
|
||||
for (i = 0; i < i2c_read.num_transactions; i++) {
|
||||
i2c_read.transactions[i].i2c_dev_id = buf[idx] & 0x7f;
|
||||
idx++;
|
||||
|
||||
i2c_read.transactions[i].num_bytes = buf[idx];
|
||||
idx++;
|
||||
|
||||
i2c_read.transactions[i].bytes = &buf[idx];
|
||||
idx += i2c_read.transactions[i].num_bytes;
|
||||
|
||||
i2c_read.transactions[i].no_stop_bit = (buf[idx] >> 4) & 0x1;
|
||||
i2c_read.transactions[i].i2c_transaction_delay = buf[idx] & 0xf;
|
||||
idx++;
|
||||
}
|
||||
|
||||
i2c_read.read_i2c_device_id = buf[idx];
|
||||
idx++;
|
||||
|
||||
i2c_read.num_bytes_read = buf[idx];
|
||||
idx++;
|
||||
|
||||
port = &ctx->ports[i2c_read.port_number];
|
||||
|
||||
if (i2c_read.num_transactions == 1) {
|
||||
if (i2c_read.transactions[0].i2c_dev_id != DDC_ADDR ||
|
||||
i2c_read.transactions[0].num_bytes != 1) {
|
||||
pr_err("unsupported i2c address\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
start = i2c_read.transactions[0].bytes[0];
|
||||
} else if (i2c_read.num_transactions == 2) {
|
||||
if (i2c_read.transactions[0].i2c_dev_id != DDC_SEGMENT_ADDR ||
|
||||
i2c_read.transactions[0].num_bytes != 1 ||
|
||||
i2c_read.transactions[1].i2c_dev_id != DDC_ADDR ||
|
||||
i2c_read.transactions[1].num_bytes != 1) {
|
||||
pr_err("unsupported i2c address\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
start = i2c_read.transactions[0].bytes[0] * EDID_LENGTH * 2 +
|
||||
i2c_read.transactions[1].bytes[0];
|
||||
} else {
|
||||
pr_err("unsupported i2c transaction\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
len = i2c_read.num_bytes_read;
|
||||
|
||||
if (start + len > port->edid_size) {
|
||||
pr_err("edid data exceeds maximum\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
buf = ctx->down_rep.msg;
|
||||
idx = 0;
|
||||
|
||||
buf[idx] = DP_REMOTE_I2C_READ;
|
||||
idx++;
|
||||
|
||||
buf[idx] = i2c_read.port_number;
|
||||
idx++;
|
||||
|
||||
buf[idx] = len;
|
||||
idx++;
|
||||
|
||||
memcpy(&buf[idx], &port->edid[start], len);
|
||||
idx += len;
|
||||
|
||||
return idx;
|
||||
err:
|
||||
return rockchip_dp_sideband_build_nak_rep(ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
rockchip_dp_sideband_build_enum_path_resources_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_port *port;
|
||||
u8 port_num;
|
||||
u8 *buf;
|
||||
int idx;
|
||||
|
||||
buf = ctx->down_req.msg;
|
||||
port_num = buf[1] >> 4;
|
||||
|
||||
if (port_num >= ctx->port_num) {
|
||||
pr_err("invalid port num\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
port = &ctx->ports[port_num];
|
||||
|
||||
buf = ctx->down_rep.msg;
|
||||
idx = 0;
|
||||
|
||||
buf[idx] = DP_ENUM_PATH_RESOURCES;
|
||||
idx++;
|
||||
|
||||
buf[idx] = port_num << 4;
|
||||
idx++;
|
||||
|
||||
buf[idx] = port->full_pbn >> 8;
|
||||
idx++;
|
||||
|
||||
buf[idx] = port->full_pbn & 0xFF;
|
||||
idx++;
|
||||
|
||||
buf[idx] = port->avail_pbn >> 8;
|
||||
idx++;
|
||||
|
||||
buf[idx] = port->avail_pbn & 0xFF;
|
||||
idx++;
|
||||
|
||||
return idx;
|
||||
err:
|
||||
return rockchip_dp_sideband_build_nak_rep(ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
rockchip_dp_sideband_build_allocate_payload_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
struct drm_dp_allocate_payload allocate_payload;
|
||||
u8 *buf;
|
||||
int idx;
|
||||
u32 i;
|
||||
|
||||
buf = ctx->down_req.msg;
|
||||
idx = 1;
|
||||
|
||||
allocate_payload.port_number = buf[idx] >> 4;
|
||||
allocate_payload.number_sdp_streams = buf[idx] & 0xF;
|
||||
idx++;
|
||||
|
||||
allocate_payload.vcpi = buf[idx];
|
||||
idx++;
|
||||
|
||||
allocate_payload.pbn = (buf[idx] << 8) | buf[idx+1];
|
||||
idx += 2;
|
||||
|
||||
for (i = 0; i < allocate_payload.number_sdp_streams / 2; i++) {
|
||||
allocate_payload.sdp_stream_sink[i * 2] = buf[idx] >> 4;
|
||||
allocate_payload.sdp_stream_sink[i * 2 + 1] = buf[idx] & 0xf;
|
||||
idx++;
|
||||
}
|
||||
if (allocate_payload.number_sdp_streams & 1) {
|
||||
i = allocate_payload.number_sdp_streams - 1;
|
||||
allocate_payload.sdp_stream_sink[i] = buf[idx] >> 4;
|
||||
idx++;
|
||||
}
|
||||
|
||||
if (allocate_payload.port_number >= ctx->port_num) {
|
||||
pr_err("invalid port num\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
buf = ctx->down_rep.msg;
|
||||
idx = 0;
|
||||
|
||||
buf[idx] = DP_ALLOCATE_PAYLOAD;
|
||||
idx++;
|
||||
|
||||
buf[idx] = allocate_payload.port_number;
|
||||
idx++;
|
||||
|
||||
buf[idx] = allocate_payload.vcpi;
|
||||
idx++;
|
||||
|
||||
buf[idx] = allocate_payload.pbn >> 8;
|
||||
idx++;
|
||||
|
||||
buf[idx] = allocate_payload.pbn & 0xFF;
|
||||
idx++;
|
||||
|
||||
return idx;
|
||||
err:
|
||||
return rockchip_dp_sideband_build_nak_rep(ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
rockchip_dp_sideband_build_power_updown_phy_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
u8 port_num;
|
||||
u8 *buf;
|
||||
int idx;
|
||||
|
||||
buf = ctx->down_req.msg;
|
||||
port_num = buf[1] >> 4;
|
||||
|
||||
if (port_num >= ctx->port_num) {
|
||||
pr_err("invalid port num\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
buf = ctx->down_rep.msg;
|
||||
idx = 0;
|
||||
|
||||
buf[idx] = ctx->down_req.msg[0];
|
||||
idx++;
|
||||
|
||||
buf[idx] = port_num;
|
||||
idx++;
|
||||
|
||||
return idx;
|
||||
err:
|
||||
return rockchip_dp_sideband_build_nak_rep(ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
rockchip_dp_sideband_build_clear_payload_id_table_rep(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
u8 *buf = ctx->down_rep.msg;
|
||||
int idx = 0;
|
||||
|
||||
buf[idx] = DP_CLEAR_PAYLOAD_ID_TABLE;
|
||||
idx++;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
static inline int
|
||||
rockchip_dp_sideband_update_esi(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
ctx->esi[0] = ctx->port_num;
|
||||
ctx->esi[1] = DP_DOWN_REP_MSG_RDY;
|
||||
ctx->esi[2] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
rockchip_dp_sideband_pending_esi(struct rockchip_dp_mst_sim_context *ctx)
|
||||
{
|
||||
return !!(ctx->esi[1] & DP_DOWN_REP_MSG_RDY);
|
||||
}
|
||||
|
||||
static int rockchip_dp_mst_sim_clear_esi(struct rockchip_dp_mst_sim_context *ctx,
|
||||
struct drm_dp_aux_msg *msg)
|
||||
{
|
||||
size_t i;
|
||||
u8 old_esi = ctx->esi[1];
|
||||
u32 addr = msg->address - DP_SINK_COUNT_ESI;
|
||||
|
||||
if (msg->size - addr >= 16) {
|
||||
msg->reply = DP_AUX_NATIVE_REPLY_NACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
mutex_lock(&ctx->session_lock);
|
||||
|
||||
for (i = 0; i < msg->size; i++)
|
||||
ctx->esi[addr + i] &= ~((u8 *)msg->buffer)[i];
|
||||
|
||||
if ((old_esi & DP_DOWN_REP_MSG_RDY) &&
|
||||
!(ctx->esi[1] & DP_DOWN_REP_MSG_RDY)) {
|
||||
complete(&ctx->session_comp);
|
||||
}
|
||||
|
||||
mutex_unlock(&ctx->session_lock);
|
||||
|
||||
msg->reply = DP_AUX_NATIVE_REPLY_ACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_dp_mst_sim_read_esi(struct rockchip_dp_mst_sim_context *ctx,
|
||||
struct drm_dp_aux_msg *msg)
|
||||
{
|
||||
u32 addr = msg->address - DP_SINK_COUNT_ESI;
|
||||
|
||||
if (msg->size - addr >= 16) {
|
||||
msg->reply = DP_AUX_NATIVE_REPLY_NACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(msg->buffer, &ctx->esi[addr], msg->size);
|
||||
msg->reply = DP_AUX_NATIVE_REPLY_ACK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_dp_mst_sim_down_req_internal(struct rockchip_dp_mst_sim_context *ctx,
|
||||
struct drm_dp_aux_msg *aux_msg)
|
||||
{
|
||||
struct drm_dp_sideband_msg_rx *msg = &ctx->down_req;
|
||||
struct drm_dp_sideband_msg_hdr hdr;
|
||||
bool seqno;
|
||||
int ret, size, len, hdr_len;
|
||||
|
||||
ret = rockchip_dp_get_one_sb_msg(msg, aux_msg);
|
||||
if (!ret)
|
||||
return -EINVAL;
|
||||
|
||||
if (!msg->have_eomt)
|
||||
return 0;
|
||||
|
||||
seqno = msg->initial_hdr.seqno;
|
||||
|
||||
switch (msg->msg[0]) {
|
||||
case DP_LINK_ADDRESS:
|
||||
size = rockchip_dp_sideband_build_link_address_rep(ctx);
|
||||
break;
|
||||
case DP_REMOTE_I2C_READ:
|
||||
size = rockchip_dp_sideband_build_remote_i2c_read_rep(ctx);
|
||||
break;
|
||||
case DP_ENUM_PATH_RESOURCES:
|
||||
size = rockchip_dp_sideband_build_enum_path_resources_rep(ctx);
|
||||
break;
|
||||
case DP_ALLOCATE_PAYLOAD:
|
||||
size = rockchip_dp_sideband_build_allocate_payload_rep(ctx);
|
||||
break;
|
||||
case DP_POWER_DOWN_PHY:
|
||||
case DP_POWER_UP_PHY:
|
||||
size = rockchip_dp_sideband_build_power_updown_phy_rep(ctx);
|
||||
break;
|
||||
case DP_CLEAR_PAYLOAD_ID_TABLE:
|
||||
size = rockchip_dp_sideband_build_clear_payload_id_table_rep(ctx);
|
||||
break;
|
||||
default:
|
||||
size = rockchip_dp_sideband_build_nak_rep(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ctx->host_req)
|
||||
ctx->host_req(ctx->host_dev,
|
||||
ctx->down_req.msg, ctx->down_req.curlen,
|
||||
ctx->down_rep.msg, &size);
|
||||
|
||||
memset(msg, 0, sizeof(*msg));
|
||||
msg = &ctx->down_rep;
|
||||
msg->curlen = 0;
|
||||
|
||||
while (msg->curlen < size) {
|
||||
/* copy data */
|
||||
len = min(size - msg->curlen, 44);
|
||||
memcpy(&ctx->dpcd[3], &msg->msg[msg->curlen], len);
|
||||
msg->curlen += len;
|
||||
|
||||
/* build header */
|
||||
memset(&hdr, 0, sizeof(struct drm_dp_sideband_msg_hdr));
|
||||
hdr.broadcast = 0;
|
||||
hdr.path_msg = 0;
|
||||
hdr.lct = 1;
|
||||
hdr.lcr = 0;
|
||||
hdr.seqno = seqno;
|
||||
hdr.msg_len = len + 1;
|
||||
hdr.eomt = (msg->curlen == size);
|
||||
hdr.somt = (msg->curlen == len);
|
||||
drm_dp_encode_sideband_msg_hdr(&hdr, ctx->dpcd, &hdr_len);
|
||||
|
||||
/* build crc */
|
||||
ctx->dpcd[len + 3] = drm_dp_msg_data_crc4(&ctx->dpcd[3], len);
|
||||
|
||||
/* update esi */
|
||||
mutex_lock(&ctx->session_lock);
|
||||
rockchip_dp_sideband_update_esi(ctx);
|
||||
mutex_unlock(&ctx->session_lock);
|
||||
|
||||
/* notify host */
|
||||
ctx->host_hpd_irq(ctx->host_dev);
|
||||
|
||||
/* wait until esi is cleared */
|
||||
mutex_lock(&ctx->session_lock);
|
||||
while (rockchip_dp_sideband_pending_esi(ctx)) {
|
||||
mutex_unlock(&ctx->session_lock);
|
||||
wait_for_completion(&ctx->session_comp);
|
||||
mutex_lock(&ctx->session_lock);
|
||||
}
|
||||
mutex_unlock(&ctx->session_lock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rockchip_dp_mst_sim_down_req_work(struct work_struct *work)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_work *sim_work =
|
||||
container_of(work, struct rockchip_dp_mst_sim_work, base);
|
||||
struct drm_dp_aux_msg msg;
|
||||
|
||||
msg.address = sim_work->address;
|
||||
msg.buffer = sim_work->buffer;
|
||||
msg.size = sim_work->size;
|
||||
|
||||
rockchip_dp_mst_sim_down_req_internal(sim_work->ctx, &msg);
|
||||
|
||||
kfree(sim_work);
|
||||
}
|
||||
|
||||
static int rockchip_dp_mst_sim_down_req(struct rockchip_dp_mst_sim_context *ctx,
|
||||
struct drm_dp_aux_msg *aux_msg)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_work *work;
|
||||
|
||||
if (aux_msg->size >= 256) {
|
||||
aux_msg->reply = DP_AUX_NATIVE_REPLY_NACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
rockchip_dp_sideband_hex_dump("request",
|
||||
aux_msg->address, aux_msg->buffer, aux_msg->size);
|
||||
|
||||
work = kzalloc(sizeof(*work), GFP_KERNEL);
|
||||
if (!work) {
|
||||
aux_msg->reply = DP_AUX_NATIVE_REPLY_NACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
work->ctx = ctx;
|
||||
work->address = aux_msg->address;
|
||||
work->size = aux_msg->size;
|
||||
memcpy(work->buffer, aux_msg->buffer, aux_msg->size);
|
||||
|
||||
INIT_WORK(&work->base, rockchip_dp_mst_sim_down_req_work);
|
||||
queue_work(ctx->wq, &work->base);
|
||||
|
||||
aux_msg->reply = DP_AUX_NATIVE_REPLY_ACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_dp_mst_sim_down_rep(struct rockchip_dp_mst_sim_context *ctx,
|
||||
struct drm_dp_aux_msg *msg)
|
||||
{
|
||||
u32 addr = msg->address - DP_SIDEBAND_MSG_DOWN_REP_BASE;
|
||||
|
||||
memcpy(msg->buffer, &ctx->dpcd[addr], msg->size);
|
||||
msg->reply = DP_AUX_NATIVE_REPLY_ACK;
|
||||
|
||||
rockchip_dp_sideband_hex_dump("reply",
|
||||
addr, msg->buffer, msg->size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rockchip_dp_mst_sim_transfer(void *mst_sim_context, struct drm_dp_aux_msg *msg)
|
||||
{
|
||||
if (msg->request == DP_AUX_NATIVE_WRITE) {
|
||||
if (msg->address >= DP_SIDEBAND_MSG_DOWN_REQ_BASE &&
|
||||
msg->address < DP_SIDEBAND_MSG_DOWN_REQ_BASE + 256)
|
||||
return rockchip_dp_mst_sim_down_req(mst_sim_context, msg);
|
||||
|
||||
if (msg->address >= DP_SINK_COUNT_ESI &&
|
||||
msg->address < DP_SINK_COUNT_ESI + 14)
|
||||
return rockchip_dp_mst_sim_clear_esi(mst_sim_context, msg);
|
||||
} else if (msg->request == DP_AUX_NATIVE_READ) {
|
||||
if (msg->address >= DP_SIDEBAND_MSG_DOWN_REP_BASE &&
|
||||
msg->address < DP_SIDEBAND_MSG_DOWN_REP_BASE + 256)
|
||||
return rockchip_dp_mst_sim_down_rep(mst_sim_context, msg);
|
||||
|
||||
if (msg->address >= DP_SINK_COUNT_ESI &&
|
||||
msg->address < DP_SINK_COUNT_ESI + 14)
|
||||
return rockchip_dp_mst_sim_read_esi(mst_sim_context, msg);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_dp_mst_sim_transfer);
|
||||
|
||||
int rockchip_dp_mst_sim_update(void *mst_sim_context, u32 port_num,
|
||||
struct rockchip_dp_mst_sim_port *ports)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_context *ctx = mst_sim_context;
|
||||
u8 *edid;
|
||||
int rc = 0;
|
||||
u32 i;
|
||||
|
||||
if (port_num >= 15)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&ctx->session_lock);
|
||||
|
||||
for (i = 0; i < ctx->port_num; i++)
|
||||
kfree(ctx->ports[i].edid);
|
||||
kfree(ctx->ports);
|
||||
ctx->port_num = 0;
|
||||
|
||||
ctx->ports = kcalloc(port_num, sizeof(*ports), GFP_KERNEL);
|
||||
if (!ctx->ports) {
|
||||
rc = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ctx->port_num = port_num;
|
||||
for (i = 0; i < port_num; i++) {
|
||||
ctx->ports[i] = ports[i];
|
||||
if (ports[i].edid_size) {
|
||||
if (!ports[i].edid) {
|
||||
rc = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
edid = kzalloc(ports[i].edid_size,
|
||||
GFP_KERNEL);
|
||||
if (!edid) {
|
||||
rc = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
memcpy(edid, ports[i].edid, ports[i].edid_size);
|
||||
ctx->ports[i].edid = edid;
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
if (rc) {
|
||||
for (i = 0; i < ctx->port_num; i++)
|
||||
kfree(ctx->ports[i].edid);
|
||||
kfree(ctx->ports);
|
||||
}
|
||||
|
||||
mutex_unlock(&ctx->session_lock);
|
||||
return rc;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_dp_mst_sim_update);
|
||||
|
||||
int rockchip_dp_mst_sim_create(const struct rockchip_dp_mst_sim_cfg *cfg,
|
||||
void **mst_sim_context)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_context *ctx;
|
||||
|
||||
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
||||
if (!ctx)
|
||||
return -ENOMEM;
|
||||
|
||||
ctx->host_dev = cfg->host_dev;
|
||||
ctx->host_hpd_irq = cfg->host_hpd_irq;
|
||||
ctx->host_req = cfg->host_req;
|
||||
memcpy(ctx->guid, cfg->guid, 16);
|
||||
|
||||
mutex_init(&ctx->session_lock);
|
||||
init_completion(&ctx->session_comp);
|
||||
|
||||
ctx->wq = create_singlethread_workqueue("dp_mst_sim");
|
||||
if (IS_ERR_OR_NULL(ctx->wq)) {
|
||||
pr_err("Error creating wq\n");
|
||||
kfree(ctx);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
*mst_sim_context = ctx;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_dp_mst_sim_create);
|
||||
|
||||
int rockchip_dp_mst_sim_destroy(void *mst_sim_context)
|
||||
{
|
||||
struct rockchip_dp_mst_sim_context *ctx = mst_sim_context;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < ctx->port_num; i++)
|
||||
kfree(ctx->ports[i].edid);
|
||||
kfree(ctx->ports);
|
||||
|
||||
destroy_workqueue(ctx->wq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_dp_mst_sim_destroy);
|
||||
117
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client_helper.h
Normal file
117
drivers/gpu/drm/rockchip/rockchip_dp_mst_aux_client_helper.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* Copyright (c) 2024 Rockchip Electronics Co. Ltd.
|
||||
*
|
||||
* Author: Zhang Yubing <yubing.zhang@rock-chips.com>
|
||||
*/
|
||||
|
||||
#ifndef _ROCKCHIP_DP_MST_AUX_CLIENT_HELPER_H_
|
||||
#define _ROCKCHIP_DP_MST_AUX_CLIENT_HELPER_H_
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <drm/display/drm_dp_helper.h>
|
||||
|
||||
/**
|
||||
* struct rockchip_dp_mst_sim_port - MST port configuration
|
||||
* @input: if this port is an input port.
|
||||
* @mcs: message capability status - DP 1.2 spec.
|
||||
* @ddps: DisplayPort Device Plug Status - DP 1.2
|
||||
* @pdt: Peer Device Type
|
||||
* @ldps: Legacy Device Plug Status
|
||||
* @dpcd_rev: DPCD revision of device on this port
|
||||
* @peer_guid: Peer GUID on this port
|
||||
* @num_sdp_streams: Number of simultaneous streams
|
||||
* @num_sdp_stream_sinks: Number of stream sinks
|
||||
* @full_pbn: Full bandwidth for this port.
|
||||
* @avail_pbn: Available bandwidth for this port.
|
||||
* @edid: EDID data on this port.
|
||||
* @edid_size: size of EDID data on this port.
|
||||
*/
|
||||
struct rockchip_dp_mst_sim_port {
|
||||
bool input;
|
||||
bool mcs;
|
||||
bool ddps;
|
||||
u8 pdt;
|
||||
bool ldps;
|
||||
u8 dpcd_rev;
|
||||
u8 peer_guid[16];
|
||||
u8 num_sdp_streams;
|
||||
u8 num_sdp_stream_sinks;
|
||||
u16 full_pbn;
|
||||
u16 avail_pbn;
|
||||
const u8 *edid;
|
||||
u32 edid_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rockchip_dp_mst_sim_cfg - MST simulator configuration
|
||||
* @host_dev: host device pointer used in callback functions
|
||||
* @guid: GUID of the top MST branch.
|
||||
*/
|
||||
struct rockchip_dp_mst_sim_cfg {
|
||||
void *host_dev;
|
||||
u8 guid[16];
|
||||
|
||||
/**
|
||||
* @host_hpd_irq:
|
||||
*
|
||||
* This callback is invoked whenever simulator need to
|
||||
* notify host that there is a HPD_IRQ.
|
||||
* @host_dev: host_dev pointer
|
||||
*/
|
||||
void (*host_hpd_irq)(void *host_dev);
|
||||
|
||||
/**
|
||||
* @host_req:
|
||||
*
|
||||
* This callback is invoked whenever simulator's reply is ready
|
||||
* to response downstream request. Host can use this function
|
||||
* to replace the reply generated by simulator.
|
||||
* @host_dev: host_dev pointer
|
||||
* @in: pointer of downstream request buffer to simulator
|
||||
* @in_size: size of downstream request buffer to simulator
|
||||
* @out: pointer of downstream reply from simulator
|
||||
* @out_size: pointer of size of downstream reply from simulator
|
||||
*
|
||||
* This callback is optional.
|
||||
*/
|
||||
void (*host_req)(void *host_dev, const u8 *in, int in_size,
|
||||
u8 *out, int *out_size);
|
||||
};
|
||||
|
||||
/**
|
||||
* rockchip_dp_mst_sim_create - Create simulator context
|
||||
* @cfg: see dp_mst_sim_cfg
|
||||
* @mst_sim_context: simulator context returned
|
||||
* return: 0 if successful
|
||||
*/
|
||||
int rockchip_dp_mst_sim_create(const struct rockchip_dp_mst_sim_cfg *cfg,
|
||||
void **mst_sim_context);
|
||||
|
||||
/**
|
||||
* rockchip_dp_mst_sim_destroy - Destroy simulator context
|
||||
* @mst_sim_context: simulator context
|
||||
* return: 0 if successful
|
||||
*/
|
||||
int rockchip_dp_mst_sim_destroy(void *mst_sim_context);
|
||||
|
||||
/**
|
||||
* dp_mst_sim_transfer - Send aux message to simulator context
|
||||
* @mst_sim_context: simulator context
|
||||
* @msg: aux message
|
||||
* return: 0 if successful
|
||||
*/
|
||||
int rockchip_dp_mst_sim_transfer(void *mst_sim_context, struct drm_dp_aux_msg *msg);
|
||||
|
||||
/**
|
||||
* dp_mst_sim_update - Update port configuration
|
||||
* @mst_sim_context: simulator context
|
||||
* @port_num: number of ports
|
||||
* @ports: ports configuration
|
||||
* return: 0 if successful
|
||||
*/
|
||||
int rockchip_dp_mst_sim_update(void *mst_sim_context, u32 port_num,
|
||||
struct rockchip_dp_mst_sim_port *ports);
|
||||
|
||||
#endif /* _ROCKCHIP_DP_MST_AUX_CLIENT_HELPER_H_ */
|
||||
|
||||
@@ -1363,7 +1363,7 @@ static int mpp_process_request(struct mpp_session *session,
|
||||
|
||||
mpp_iommu_down_read(mpp->iommu_info);
|
||||
buffer = mpp_dma_import_fd(mpp->iommu_info,
|
||||
session->dma, fd);
|
||||
session->dma, fd, 1);
|
||||
mpp_iommu_up_read(mpp->iommu_info);
|
||||
if (IS_ERR_OR_NULL(buffer)) {
|
||||
mpp_err("can not import fd %d\n", fd);
|
||||
@@ -1770,7 +1770,7 @@ mpp_task_attach_fd(struct mpp_task *task, int fd)
|
||||
mem_region->is_dup = true;
|
||||
} else {
|
||||
mpp_iommu_down_read(mpp->iommu_info);
|
||||
buffer = mpp_dma_import_fd(mpp->iommu_info, dma, fd);
|
||||
buffer = mpp_dma_import_fd(mpp->iommu_info, dma, fd, 0);
|
||||
mpp_iommu_up_read(mpp->iommu_info);
|
||||
if (IS_ERR(buffer)) {
|
||||
mpp_err("can't import dma-buf %d\n", fd);
|
||||
|
||||
@@ -33,6 +33,7 @@ mpp_dma_find_buffer_fd(struct mpp_dma_session *dma, int fd)
|
||||
struct dma_buf *dmabuf;
|
||||
struct mpp_dma_buffer *out = NULL;
|
||||
struct mpp_dma_buffer *buffer = NULL, *n;
|
||||
int find = 0;
|
||||
|
||||
dmabuf = dma_buf_get(fd);
|
||||
if (IS_ERR(dmabuf))
|
||||
@@ -47,9 +48,26 @@ mpp_dma_find_buffer_fd(struct mpp_dma_session *dma, int fd)
|
||||
*/
|
||||
if (buffer->dmabuf == dmabuf) {
|
||||
out = buffer;
|
||||
find = 1;
|
||||
list_move_tail(&buffer->link, &buffer->dma->used_list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!find) {
|
||||
list_for_each_entry_safe(buffer, n,
|
||||
&dma->static_list, link) {
|
||||
/*
|
||||
* fd may dup several and point the same dambuf.
|
||||
* thus, here should be distinguish with the dmabuf.
|
||||
*/
|
||||
if (buffer->dmabuf == dmabuf) {
|
||||
out = buffer;
|
||||
list_move_tail(&buffer->link, &buffer->dma->static_list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&dma->list_mutex);
|
||||
dma_buf_put(dmabuf);
|
||||
|
||||
@@ -84,22 +102,20 @@ static int
|
||||
mpp_dma_remove_extra_buffer(struct mpp_dma_session *dma)
|
||||
{
|
||||
struct mpp_dma_buffer *n;
|
||||
struct mpp_dma_buffer *oldest = NULL, *buffer = NULL;
|
||||
ktime_t oldest_time = ktime_set(0, 0);
|
||||
struct mpp_dma_buffer *removable = NULL, *buffer = NULL;
|
||||
|
||||
if (dma->buffer_count > dma->max_buffers) {
|
||||
mutex_lock(&dma->list_mutex);
|
||||
list_for_each_entry_safe(buffer, n,
|
||||
&dma->used_list,
|
||||
link) {
|
||||
if (ktime_to_ns(oldest_time) == 0 ||
|
||||
ktime_after(oldest_time, buffer->last_used)) {
|
||||
oldest_time = buffer->last_used;
|
||||
oldest = buffer;
|
||||
if (kref_read(&buffer->ref) == 1) {
|
||||
removable = buffer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (oldest && kref_read(&oldest->ref) == 1)
|
||||
kref_put(&oldest->ref, mpp_dma_release_buffer);
|
||||
if (removable)
|
||||
kref_put(&removable->ref, mpp_dma_release_buffer);
|
||||
mutex_unlock(&dma->list_mutex);
|
||||
}
|
||||
|
||||
@@ -176,7 +192,7 @@ int mpp_dma_free(struct mpp_dma_buffer *buffer)
|
||||
|
||||
struct mpp_dma_buffer *mpp_dma_import_fd(struct mpp_iommu_info *iommu_info,
|
||||
struct mpp_dma_session *dma,
|
||||
int fd)
|
||||
int fd, int static_use)
|
||||
{
|
||||
int ret = 0;
|
||||
struct sg_table *sgt;
|
||||
@@ -196,10 +212,8 @@ struct mpp_dma_buffer *mpp_dma_import_fd(struct mpp_iommu_info *iommu_info,
|
||||
/* Check whether in dma session */
|
||||
buffer = mpp_dma_find_buffer_fd(dma, fd);
|
||||
if (!IS_ERR_OR_NULL(buffer)) {
|
||||
if (kref_get_unless_zero(&buffer->ref)) {
|
||||
buffer->last_used = ktime_get();
|
||||
if (kref_get_unless_zero(&buffer->ref))
|
||||
return buffer;
|
||||
}
|
||||
dev_dbg(dma->dev, "missing the fd %d\n", fd);
|
||||
}
|
||||
|
||||
@@ -224,7 +238,6 @@ struct mpp_dma_buffer *mpp_dma_import_fd(struct mpp_iommu_info *iommu_info,
|
||||
|
||||
buffer->dmabuf = dmabuf;
|
||||
buffer->dir = DMA_BIDIRECTIONAL;
|
||||
buffer->last_used = ktime_get();
|
||||
|
||||
attach = dma_buf_attach(buffer->dmabuf, dma->dev);
|
||||
if (IS_ERR(attach)) {
|
||||
@@ -247,13 +260,16 @@ struct mpp_dma_buffer *mpp_dma_import_fd(struct mpp_iommu_info *iommu_info,
|
||||
|
||||
kref_init(&buffer->ref);
|
||||
|
||||
if (!IS_ENABLED(CONFIG_DMABUF_CACHE))
|
||||
if (!static_use && !IS_ENABLED(CONFIG_DMABUF_CACHE))
|
||||
/* Increase the reference for used outside the buffer pool */
|
||||
kref_get(&buffer->ref);
|
||||
|
||||
mutex_lock(&dma->list_mutex);
|
||||
dma->buffer_count++;
|
||||
list_add_tail(&buffer->link, &dma->used_list);
|
||||
if (static_use)
|
||||
list_add_tail(&buffer->link, &dma->static_list);
|
||||
else
|
||||
list_add_tail(&buffer->link, &dma->used_list);
|
||||
mutex_unlock(&dma->list_mutex);
|
||||
|
||||
return buffer;
|
||||
@@ -333,6 +349,11 @@ int mpp_dma_session_destroy(struct mpp_dma_session *dma)
|
||||
link) {
|
||||
kref_put(&buffer->ref, mpp_dma_release_buffer);
|
||||
}
|
||||
list_for_each_entry_safe(buffer, n,
|
||||
&dma->static_list,
|
||||
link) {
|
||||
kref_put(&buffer->ref, mpp_dma_release_buffer);
|
||||
}
|
||||
mutex_unlock(&dma->list_mutex);
|
||||
|
||||
kfree(dma);
|
||||
@@ -354,6 +375,7 @@ mpp_dma_session_create(struct device *dev, u32 max_buffers)
|
||||
mutex_init(&dma->list_mutex);
|
||||
INIT_LIST_HEAD(&dma->unused_list);
|
||||
INIT_LIST_HEAD(&dma->used_list);
|
||||
INIT_LIST_HEAD(&dma->static_list);
|
||||
|
||||
if (max_buffers > MPP_SESSION_MAX_BUFFERS) {
|
||||
mpp_debug(DEBUG_IOCTL, "session_max_buffer %d must less than %d\n",
|
||||
|
||||
@@ -57,6 +57,12 @@ struct mpp_dma_session {
|
||||
/* the buffer used in session */
|
||||
struct list_head unused_list;
|
||||
struct list_head used_list;
|
||||
/*
|
||||
* For those buffer import by ioctl MPP_CMD_TRANS_FD_TO_IOVA,
|
||||
* move to static_list instead of used_list and don't increase extra kref,
|
||||
* so that it will release when user space call ioctl MPP_CMD_RELEASE_FD.
|
||||
*/
|
||||
struct list_head static_list;
|
||||
struct mpp_dma_buffer dma_bufs[MPP_SESSION_MAX_BUFFERS];
|
||||
/* the mutex for the above buffer list */
|
||||
struct mutex list_mutex;
|
||||
@@ -108,7 +114,7 @@ int mpp_dma_free(struct mpp_dma_buffer *buffer);
|
||||
|
||||
struct mpp_dma_buffer *
|
||||
mpp_dma_import_fd(struct mpp_iommu_info *iommu_info,
|
||||
struct mpp_dma_session *dma, int fd);
|
||||
struct mpp_dma_session *dma, int fd, int static_use);
|
||||
int mpp_dma_release(struct mpp_dma_session *dma,
|
||||
struct mpp_dma_buffer *buffer);
|
||||
int mpp_dma_release_fd(struct mpp_dma_session *dma, int fd);
|
||||
|
||||
@@ -196,6 +196,8 @@ static int dmaengine_config_interleaved(struct snd_pcm_substream *substream,
|
||||
|
||||
#ifdef CONFIG_NO_GKI
|
||||
xt->nump = nump;
|
||||
#else
|
||||
xt->sgl[1].size = nump;
|
||||
#endif
|
||||
xt->numf = numf;
|
||||
|
||||
@@ -692,8 +694,14 @@ static int dmaengine_mpcm_open(struct snd_soc_component *component,
|
||||
if (!prtd)
|
||||
return -ENOMEM;
|
||||
|
||||
#ifdef CONFIG_NO_GKI
|
||||
prtd->xt = kzalloc(sizeof(struct dma_interleaved_template) +
|
||||
sizeof(struct data_chunk), GFP_KERNEL);
|
||||
#else
|
||||
prtd->xt = kzalloc(sizeof(struct dma_interleaved_template) +
|
||||
sizeof(struct data_chunk) * 2, GFP_KERNEL);
|
||||
|
||||
#endif
|
||||
if (!prtd->xt) {
|
||||
kfree(prtd);
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user