cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

dp_hpd.c (1392B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/*
      3 * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
      4 */
      5
      6#define pr_fmt(fmt)	"[drm-dp] %s: " fmt, __func__
      7
      8#include <linux/slab.h>
      9#include <linux/device.h>
     10
     11#include "dp_hpd.h"
     12
     13/* DP specific VDM commands */
     14#define DP_USBPD_VDM_STATUS	0x10
     15#define DP_USBPD_VDM_CONFIGURE	0x11
     16
     17/* USBPD-TypeC specific Macros */
     18#define VDM_VERSION		0x0
     19#define USB_C_DP_SID		0xFF01
     20
     21struct dp_hpd_private {
     22	struct device *dev;
     23	struct dp_usbpd_cb *dp_cb;
     24	struct dp_usbpd dp_usbpd;
     25};
     26
     27int dp_hpd_connect(struct dp_usbpd *dp_usbpd, bool hpd)
     28{
     29	int rc = 0;
     30	struct dp_hpd_private *hpd_priv;
     31
     32	hpd_priv = container_of(dp_usbpd, struct dp_hpd_private,
     33					dp_usbpd);
     34
     35	if (!hpd_priv->dp_cb || !hpd_priv->dp_cb->configure
     36				|| !hpd_priv->dp_cb->disconnect) {
     37		pr_err("hpd dp_cb not initialized\n");
     38		return -EINVAL;
     39	}
     40	if (hpd)
     41		hpd_priv->dp_cb->configure(hpd_priv->dev);
     42	else
     43		hpd_priv->dp_cb->disconnect(hpd_priv->dev);
     44
     45	return rc;
     46}
     47
     48struct dp_usbpd *dp_hpd_get(struct device *dev, struct dp_usbpd_cb *cb)
     49{
     50	struct dp_hpd_private *dp_hpd;
     51
     52	if (!cb) {
     53		pr_err("invalid cb data\n");
     54		return ERR_PTR(-EINVAL);
     55	}
     56
     57	dp_hpd = devm_kzalloc(dev, sizeof(*dp_hpd), GFP_KERNEL);
     58	if (!dp_hpd)
     59		return ERR_PTR(-ENOMEM);
     60
     61	dp_hpd->dev = dev;
     62	dp_hpd->dp_cb = cb;
     63
     64	dp_hpd->dp_usbpd.connect = dp_hpd_connect;
     65
     66	return &dp_hpd->dp_usbpd;
     67}