Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4808528imm; Mon, 14 May 2018 13:31:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZojjFwnVNWl1bOvnU8m9lUeOjyPUmc06nZBRRLzmjzN8BfA4dGycyra3Ndl3tmhzZS0nRB0 X-Received: by 2002:a17:902:7b83:: with SMTP id w3-v6mr11498052pll.12.1526329883169; Mon, 14 May 2018 13:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526329883; cv=none; d=google.com; s=arc-20160816; b=ZVj6PWetLGcj0Ch+Ar96bQdMoPMThyPHIep2aSa/ji/wMDnaoiwtgR/LL5XZK0KD8h QFk80W87hmovw3HN5hJ201hGLT9K4qiwnmqvavIowi5xB63SO3/IMAEhrfmfW30c5Blt pvGgEnCnf6qGib/Ip2+O5KpneEzmT4p6RTbs8q8jPbwJ3P9L8N1VTUN2ann18jlsMprq PSkn9qmiYpmoiJad2bCG9tBLgy6CeyjEJZ9P10DNv4IBOdxhQ58dFOlE9uN6RZ+hzDSS zqxafZO5UTVzsx+0bnSDEq3Vn0LIYSIKX3GBrC9FYeAFMi8VDMjt4ZuHzRsxckrAIpjK kJkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=rQ9dHI0zZMbfM+ysHP0783GdR5gH0RgI0MYRDoIWAm0=; b=Xy+zOVhNtLeFhwaEs3u1JCfO20WJ74m6PAJuOC38RfzO9Wu5CtBuW+Wccc0ZcTzUFi C++yae4nIvVkkgmP/Xye6ljXYE0JjNkLtdjMRRKYa//TdWmSDw5Etclxql/c6X0GE6us y3/Sh1wP1X5U5P99nz/TXLLxgpo2OP42hYkU5boLHwyD9tHZZjwBK0WG7L1/ZThzD0vq irAiLDvKonj8uMyAsMVfQRfuibtf6xnIu9YACUD1GggDTxcAcsQq8GWNlDQDQS7E4hP5 X5bXHdA3Ksrms7kbIIEswr5wcXldW8CwDTA+3rmervRPl0mb96dQWBm2lbGSuDvyWnKG YGfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NseVcCdr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o7-v6si8492716pgr.88.2018.05.14.13.31.08; Mon, 14 May 2018 13:31:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NseVcCdr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752173AbeENUaS (ORCPT + 99 others); Mon, 14 May 2018 16:30:18 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:45281 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752017AbeENUaP (ORCPT ); Mon, 14 May 2018 16:30:15 -0400 Received: by mail-qt0-f196.google.com with SMTP id j42-v6so17922781qtj.12; Mon, 14 May 2018 13:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rQ9dHI0zZMbfM+ysHP0783GdR5gH0RgI0MYRDoIWAm0=; b=NseVcCdrRVZYJcQHX0VxIYrnVxGGRRnKzOev5iZhYl8nG+LnYWF6X6aOrdMLjsaXGj VDZEkpOD5vcDqbqcM1nHUzGsrk8dBmMo25Wz2sC+WeYjiUag09S0fZtmuBgJBizU+d75 AWXwaDVhdDRXRkgOHZkCUzzC6ZzPjehit+pa52q0vKeSot9QE5fzULkUYNAt8pduFPoh nPZpQHUaWXXAMPpB3zLh3QXno1jZVVAqIQDThHNrS10F1veqmlmLSUeLlZfqZ1IKOJNL u7NDBsPsisYHlzAXEVBZYxpTmWIzmDul8JJamGq5jpc5k4m3Z/wGgA6JMOxU4cT+YW7K 4+dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rQ9dHI0zZMbfM+ysHP0783GdR5gH0RgI0MYRDoIWAm0=; b=K09iUkq5KNYSUjULF+pPhIu/djU3fLWcpWM2P6DFMcDmIStxLvo3P4gpZ7FL8xQDq9 5DDN1QyOmEX6zFGjZc9WjCzb0Z5zC5lDYhkFeH8yX3sF85h40WzWWSWwLZ6yheczxAGs 94o4tDjg2gxAL/ObJ73aejI1aBXph7NqtA2ArF03qKxPRdTHw9Wkz9PTcy89jO+USg/3 r0TYCz9Gos/OlsB3I+j7UZBXkDIZ8oTNvsQG+mmk8rYna/49kezJwDBtcR4burvCfDS7 SGy31zZ4B3xvxzqwIEY/aGOLhgNipQTYUi8LhntyhfL4FNg3VFzAFSZDhsCBptMZ+7PY 6M4w== X-Gm-Message-State: ALKqPwfshuksvdg294X7PY3Qw7dxb5LtW53+kxNYNamVMtnQIwEXgu+f coE1f/fUEQkowpDKkwEBzoz/+2ibip/v/pHSSNs= X-Received: by 2002:ac8:1b18:: with SMTP id y24-v6mr10176636qtj.161.1526329813896; Mon, 14 May 2018 13:30:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.68.201 with HTTP; Mon, 14 May 2018 13:30:13 -0700 (PDT) In-Reply-To: <1526291635-31122-1-git-send-email-hl@rock-chips.com> References: <1526291635-31122-1-git-send-email-hl@rock-chips.com> From: Enric Balletbo Serra Date: Mon, 14 May 2018 22:30:13 +0200 Message-ID: Subject: Re: [PATCH v3 1/4] drm/rockchip: add transfer function for cdn-dp To: Lin Huang Cc: Sean Paul , David Airlie , Chris Zhong , Doug Anderson , Brian Norris , "open list:ARM/Rockchip SoC..." , =?UTF-8?Q?Heiko_St=C3=BCbner?= , daniel.vetter@intel.com, jani.nikula@linux.intel.com, dri-devel , Linux ARM , linux-kernel , Rob Herring , "devicetree@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lin, 2018-05-14 11:53 GMT+02:00 Lin Huang : > From: Chris Zhong > > We may support training outside firmware, so we need support > dpcd read/write to get the message or do some setting with > display. > > Signed-off-by: Chris Zhong > Signed-off-by: Lin Huang > Reviewed-by: Sean Paul > Reviewed-by: Enric Balletbo If you need to send another version, could you use the following name and email address instead? Reviewed-by: Enric Balletbo i Serra Thanks :) Enric > --- > Changes in v2: > - update patch following Enric suggest > - None > drivers/gpu/drm/rockchip/cdn-dp-core.c | 55 +++++++++++++++++++++++---- > drivers/gpu/drm/rockchip/cdn-dp-core.h | 1 + > drivers/gpu/drm/rockchip/cdn-dp-reg.c | 69 ++++++++++++++++++++++++++++++---- > drivers/gpu/drm/rockchip/cdn-dp-reg.h | 14 ++++++- > 4 files changed, 122 insertions(+), 17 deletions(-) > > diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c > index c6fbdcd..cce64c1 100644 > --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c > +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c > @@ -176,8 +176,8 @@ static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) > u8 value; > > *sink_count = 0; > - ret = cdn_dp_dpcd_read(dp, DP_SINK_COUNT, &value, 1); > - if (ret) > + ret = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, &value, 1); > + if (ret < 0) > return ret; > > *sink_count = DP_GET_SINK_COUNT(value); > @@ -374,9 +374,9 @@ static int cdn_dp_get_sink_capability(struct cdn_dp_device *dp) > if (!cdn_dp_check_sink_connection(dp)) > return -ENODEV; > > - ret = cdn_dp_dpcd_read(dp, DP_DPCD_REV, dp->dpcd, > - DP_RECEIVER_CAP_SIZE); > - if (ret) { > + ret = drm_dp_dpcd_read(&dp->aux, DP_DPCD_REV, dp->dpcd, > + sizeof(dp->dpcd)); > + if (ret < 0) { > DRM_DEV_ERROR(dp->dev, "Failed to get caps %d\n", ret); > return ret; > } > @@ -582,8 +582,8 @@ static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) > if (!port || !dp->link.rate || !dp->link.num_lanes) > return false; > > - if (cdn_dp_dpcd_read(dp, DP_LANE0_1_STATUS, link_status, > - DP_LINK_STATUS_SIZE)) { > + if (drm_dp_dpcd_read_link_status(&dp->aux, link_status) != > + DP_LINK_STATUS_SIZE) { > DRM_ERROR("Failed to get link status\n"); > return false; > } > @@ -1012,6 +1012,40 @@ static int cdn_dp_pd_event(struct notifier_block *nb, > return NOTIFY_DONE; > } > > +static ssize_t cdn_dp_aux_transfer(struct drm_dp_aux *aux, > + struct drm_dp_aux_msg *msg) > +{ > + struct cdn_dp_device *dp = container_of(aux, struct cdn_dp_device, aux); > + int ret; > + u8 status; > + > + switch (msg->request & ~DP_AUX_I2C_MOT) { > + case DP_AUX_NATIVE_WRITE: > + case DP_AUX_I2C_WRITE: > + case DP_AUX_I2C_WRITE_STATUS_UPDATE: > + ret = cdn_dp_dpcd_write(dp, msg->address, msg->buffer, > + msg->size); > + break; > + case DP_AUX_NATIVE_READ: > + case DP_AUX_I2C_READ: > + ret = cdn_dp_dpcd_read(dp, msg->address, msg->buffer, > + msg->size); > + break; > + default: > + return -EINVAL; > + } > + > + status = cdn_dp_get_aux_status(dp); > + if (status == AUX_STATUS_ACK) > + msg->reply = DP_AUX_NATIVE_REPLY_ACK; > + else if (status == AUX_STATUS_NACK) > + msg->reply = DP_AUX_NATIVE_REPLY_NACK; > + else if (status == AUX_STATUS_DEFER) > + msg->reply = DP_AUX_NATIVE_REPLY_DEFER; > + > + return ret; > +} > + > static int cdn_dp_bind(struct device *dev, struct device *master, void *data) > { > struct cdn_dp_device *dp = dev_get_drvdata(dev); > @@ -1030,6 +1064,13 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data) > dp->active = false; > dp->active_port = -1; > dp->fw_loaded = false; > + dp->aux.name = "DP-AUX"; > + dp->aux.transfer = cdn_dp_aux_transfer; > + dp->aux.dev = dev; > + > + ret = drm_dp_aux_register(&dp->aux); > + if (ret) > + return ret; > > INIT_WORK(&dp->event_work, cdn_dp_pd_event_work); > > diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.h b/drivers/gpu/drm/rockchip/cdn-dp-core.h > index f57e296..46159b2 100644 > --- a/drivers/gpu/drm/rockchip/cdn-dp-core.h > +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.h > @@ -78,6 +78,7 @@ struct cdn_dp_device { > struct platform_device *audio_pdev; > struct work_struct event_work; > struct edid *edid; > + struct drm_dp_aux aux; > > struct mutex lock; > bool connected; > diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.c b/drivers/gpu/drm/rockchip/cdn-dp-reg.c > index eb3042c..979355d 100644 > --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.c > +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.c > @@ -221,7 +221,12 @@ static int cdn_dp_reg_write_bit(struct cdn_dp_device *dp, u16 addr, > sizeof(field), field); > } > > -int cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len) > +/* > + * Returns the number of bytes transferred on success, or a negative > + * error code on failure. -ETIMEDOUT is returned if mailbox message was > + * not send successfully; > + */ > +ssize_t cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len) > { > u8 msg[5], reg[5]; > int ret; > @@ -247,24 +252,41 @@ int cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len) > goto err_dpcd_read; > > ret = cdn_dp_mailbox_read_receive(dp, data, len); > + if (!ret) > + return len; > > err_dpcd_read: > + DRM_DEV_ERROR(dp->dev, "dpcd read failed: %d\n", ret); > return ret; > } > > -int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value) > +#define CDN_AUX_HEADER_SIZE 5 > +#define CDN_AUX_MSG_SIZE 20 > +/* > + * Returns the number of bytes transferred on success, or a negative error > + * code on failure. -ETIMEDOUT is returned if mailbox message was not send > + * success; -EINVAL is returned if get the wrong data size after message > + * is sent > + */ > +ssize_t cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len) > { > - u8 msg[6], reg[5]; > + u8 msg[CDN_AUX_MSG_SIZE + CDN_AUX_HEADER_SIZE]; > + u8 reg[CDN_AUX_HEADER_SIZE]; > int ret; > > - msg[0] = 0; > - msg[1] = 1; > + if (WARN_ON(len > CDN_AUX_MSG_SIZE) || WARN_ON(len <= 0)) > + return -EINVAL; > + > + msg[0] = (len >> 8) & 0xff; > + msg[1] = len & 0xff; > msg[2] = (addr >> 16) & 0xff; > msg[3] = (addr >> 8) & 0xff; > msg[4] = addr & 0xff; > - msg[5] = value; > + > + memcpy(msg + CDN_AUX_HEADER_SIZE, data, len); > + > ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_WRITE_DPCD, > - sizeof(msg), msg); > + CDN_AUX_HEADER_SIZE + len, msg); > if (ret) > goto err_dpcd_write; > > @@ -277,8 +299,12 @@ int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value) > if (ret) > goto err_dpcd_write; > > - if (addr != (reg[2] << 16 | reg[3] << 8 | reg[4])) > + if ((len != (reg[0] << 8 | reg[1])) || > + (addr != (reg[2] << 16 | reg[3] << 8 | reg[4]))) { > ret = -EINVAL; > + } else { > + return len; > + } > > err_dpcd_write: > if (ret) > @@ -286,6 +312,33 @@ int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value) > return ret; > } > > +int cdn_dp_get_aux_status(struct cdn_dp_device *dp) > +{ > + u8 status; > + int ret; > + > + ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, > + DPTX_GET_LAST_AUX_STAUS, 0, NULL); > + if (ret) > + goto err_get_hpd; > + > + ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX, > + DPTX_GET_LAST_AUX_STAUS, > + sizeof(status)); > + if (ret) > + goto err_get_hpd; > + > + ret = cdn_dp_mailbox_read_receive(dp, &status, sizeof(status)); > + if (ret) > + goto err_get_hpd; > + > + return status; > + > +err_get_hpd: > + DRM_DEV_ERROR(dp->dev, "get aux status failed: %d\n", ret); > + return ret; > +} > + > int cdn_dp_load_firmware(struct cdn_dp_device *dp, const u32 *i_mem, > u32 i_size, const u32 *d_mem, u32 d_size) > { > diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.h b/drivers/gpu/drm/rockchip/cdn-dp-reg.h > index c4bbb4a83..6580b11 100644 > --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.h > +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.h > @@ -328,6 +328,13 @@ > #define GENERAL_BUS_SETTINGS 0x03 > #define GENERAL_TEST_ACCESS 0x04 > > +/* AUX status*/ > +#define AUX_STATUS_ACK 0 > +#define AUX_STATUS_NACK 1 > +#define AUX_STATUS_DEFER 2 > +#define AUX_STATUS_SINK_ERROR 3 > +#define AUX_STATUS_BUS_ERROR 4 > + > #define DPTX_SET_POWER_MNG 0x00 > #define DPTX_SET_HOST_CAPABILITIES 0x01 > #define DPTX_GET_EDID 0x02 > @@ -469,8 +476,11 @@ int cdn_dp_set_host_cap(struct cdn_dp_device *dp, u8 lanes, bool flip); > int cdn_dp_event_config(struct cdn_dp_device *dp); > u32 cdn_dp_get_event(struct cdn_dp_device *dp); > int cdn_dp_get_hpd_status(struct cdn_dp_device *dp); > -int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value); > -int cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len); > +ssize_t cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, > + u8 *data, u16 len); > +ssize_t cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, > + u8 *data, u16 len); > +int cdn_dp_get_aux_status(struct cdn_dp_device *dp); > int cdn_dp_get_edid_block(void *dp, u8 *edid, > unsigned int block, size_t length); > int cdn_dp_train_link(struct cdn_dp_device *dp); > -- > 2.7.4 >