dcp/dpav: Add DPAV endpoint

Signed-off-by: Janne Grunau <j@jannau.net>
This commit is contained in:
Janne Grunau 2023-08-24 23:04:55 +02:00 committed by Hector Martin
parent b44a862756
commit f46da8bbbb
3 changed files with 95 additions and 0 deletions

View file

@ -74,6 +74,7 @@ LIBFDT_OBJECTS := $(patsubst %,libfdt/%, \
fdt_wip.o fdt.o) fdt_wip.o fdt.o)
DCP_OBJECTS := $(patsubst %,dcp/%, \ DCP_OBJECTS := $(patsubst %,dcp/%, \
dpav_ep.o \
dptx_phy.o \ dptx_phy.o \
dptx_port_ep.o \ dptx_port_ep.o \
parser.o) parser.o)

78
src/dcp/dpav_ep.c Normal file
View file

@ -0,0 +1,78 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/* Copyright 2022 Sven Peter <sven@svenpeter.dev> */
#include <stdbool.h>
#include <string.h>
#include "dpav_ep.h"
#include "malloc.h"
#include "parser.h"
#include "../afk.h"
#include "../dcp.h"
#include "../types.h"
#include "../utils.h"
#define DCP_DPAV_ENDPOINT 0x24
#define TXBUF_LEN 0x4000
#define RXBUF_LEN 0x4000
typedef struct dcp_dpav_if {
afk_epic_ep_t *epic;
dcp_dev_t *dcp;
} dcp_dpav_if_t;
static void dpav_init(afk_epic_service_t *service, const char *name, const char *eclass, s64 unit)
{
UNUSED(service);
UNUSED(name);
UNUSED(eclass);
UNUSED(unit);
// printf("DPAV: init(name='%s', class='%s' unit=%ld:\n", name, eclass, unit);
}
static const afk_epic_service_ops_t dcp_dpav_ops[] = {
{
.name = "AppleDCPDPTXController",
.init = dpav_init,
},
{},
};
dcp_dpav_if_t *dcp_dpav_init(dcp_dev_t *dcp)
{
dcp_dpav_if_t *dpav = malloc(sizeof(dcp_dpav_if_t));
if (!dpav)
return NULL;
dpav->dcp = dcp;
dpav->epic = afk_epic_start_ep(dcp->afk, DCP_DPAV_ENDPOINT, dcp_dpav_ops, true);
if (!dpav->epic) {
printf("dpav: failed to initialize EPIC\n");
goto err_free;
}
int err = afk_epic_start_interface(dpav->epic, dpav, TXBUF_LEN, RXBUF_LEN);
if (err < 0) {
printf("dpav: failed to initialize DPAV interface\n");
goto err_shutdown;
}
return dpav;
err_shutdown:
afk_epic_shutdown_ep(dpav->epic);
err_free:
free(dpav);
return NULL;
}
int dcp_dpav_shutdown(dcp_dpav_if_t *dpav)
{
if (dpav) {
afk_epic_shutdown_ep(dpav->epic);
free(dpav);
}
return 0;
}

16
src/dcp/dpav_ep.h Normal file
View file

@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/* Copyright 2023 Janne Grunau <j@jannau.net> */
#ifndef __APPLE_DCP_DPAV_EP_H__
#define __APPLE_DCP_DPAV_EP_H__
#include "../types.h"
typedef struct dcp_dev dcp_dev_t;
typedef struct dcp_dpav_if dcp_dpav_if_t;
dcp_dpav_if_t *dcp_dpav_init(dcp_dev_t *dcp);
int dcp_dpav_shutdown(dcp_dpav_if_t *dpav);
#endif