Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,224 changes: 1,224 additions & 0 deletions bridges/anxdp/anx_dp.c

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions bridges/anxdp/anx_dp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@


/* $NetBSD: anx_dp.h,v 1.5 2021/12/19 12:43:37 riastradh Exp $ */

/*-
* Copyright (c) 2019 Jonathan A. Kollasch <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#ifndef _DEV_IC_ANXDP_H
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#define ANXDP_AUDIO 0
#define _DEV_IC_ANXDP_H

#if ANXDP_AUDIO
#include <dev/audio/audio_dai.h>
#endif

#include <drm/drm_bridge.h>
#include <drm/drm_connector.h>
#include <drm/drm_dp_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_panel.h>
#include <drm/drm_probe_helper.h>

struct anxdp_softc;

struct anxdp_connector {
struct drm_connector base;
struct anxdp_softc *sc;
struct drm_encoder *encoder;
#if ANXDP_AUDIO

bool monitor_audio;
#endif
};

struct anxdp_softc {
device_t sc_dev;
struct resource *res[2];
u_int sc_flags;
#define ANXDP_FLAG_ROCKCHIP 1

#if ANXDP_AUDIO
struct audio_dai_device sc_dai;
uint8_t sc_swvol;

#endif
struct anxdp_connector sc_connector;
struct drm_bridge sc_bridge;
struct drm_dp_aux sc_dpaux;
struct drm_panel *sc_panel;
uint8_t sc_dpcd[DP_RECEIVER_CAP_SIZE];
device_t iicbus;
struct i2c_adapter *ddc;
struct drm_display_mode sc_curmode;


};


int anxdp_attach(struct anxdp_softc *);
int anxdp_bind(struct anxdp_softc *, struct drm_encoder *);

void anxdp_dpms(struct anxdp_softc *, int);
DECLARE_CLASS(anxdp_driver);
#endif /* !_DEV_IC_ANXDP_H */
48 changes: 32 additions & 16 deletions core/drm_dp_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,11 @@ ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset,
if (ret != 1)
goto out;
}

if (aux->is_remote)
#ifdef __linux__
If (aux->is_remote)
ret = drm_dp_mst_dpcd_read(aux, offset, buffer, size);
else
#endif
ret = drm_dp_dpcd_access(aux, DP_AUX_NATIVE_READ, offset,
buffer, size);

Expand Down Expand Up @@ -333,10 +334,11 @@ ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset,
void *buffer, size_t size)
{
int ret;

#ifdef __linux
if (aux->is_remote)
ret = drm_dp_mst_dpcd_write(aux, offset, buffer, size);
else
#endif
ret = drm_dp_dpcd_access(aux, DP_AUX_NATIVE_WRITE, offset,
buffer, size);

Expand Down Expand Up @@ -597,15 +599,15 @@ EXPORT_SYMBOL(drm_dp_downstream_debug);
/*
* I2C-over-AUX implementation
*/

#ifdef __linux__
static u32 drm_dp_i2c_functionality(struct i2c_adapter *adapter)
{
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
I2C_FUNC_SMBUS_READ_BLOCK_DATA |
I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
I2C_FUNC_10BIT_ADDR;
}

#endif
static void drm_dp_i2c_msg_write_status_update(struct drm_dp_aux_msg *msg)
{
/*
Expand Down Expand Up @@ -821,7 +823,9 @@ static void drm_dp_i2c_msg_set_request(struct drm_dp_aux_msg *msg,
{
msg->request = (i2c_msg->flags & I2C_M_RD) ?
DP_AUX_I2C_READ : DP_AUX_I2C_WRITE;
if (!(i2c_msg->flags & I2C_M_STOP))
#ifdef __linux__
if (!(i2c_msg->flags & IIC_M_STOP))
#endif
msg->request |= DP_AUX_I2C_MOT;
}

Expand Down Expand Up @@ -862,11 +866,13 @@ static int dp_aux_i2c_transfer_size __read_mostly = DP_AUX_MAX_PAYLOAD_BYTES;
module_param_unsafe(dp_aux_i2c_transfer_size, int, 0644);
MODULE_PARM_DESC(dp_aux_i2c_transfer_size,
"Number of bytes to transfer in a single I2C over DP AUX CH message, (1-16, default 16)");

#ifdef __linux__
static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
int num)
{

struct drm_dp_aux *aux = adapter->algo_data;

unsigned int i, j;
unsigned transfer_size;
struct drm_dp_aux_msg msg;
Expand Down Expand Up @@ -937,7 +943,7 @@ static const struct i2c_algorithm drm_dp_i2c_algo = {
.functionality = drm_dp_i2c_functionality,
.master_xfer = drm_dp_i2c_xfer,
};

#endif
static struct drm_dp_aux *i2c_to_aux(struct i2c_adapter *i2c)
{
return container_of(i2c, struct drm_dp_aux, ddc);
Expand All @@ -957,13 +963,13 @@ static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags)
{
mutex_unlock(&i2c_to_aux(i2c)->hw_mutex);
}

#ifdef __linux__
static const struct i2c_lock_operations drm_dp_i2c_lock_ops = {
.lock_bus = lock_bus,
.trylock_bus = trylock_bus,
.unlock_bus = unlock_bus,
};

#endif
static int drm_dp_aux_get_crc(struct drm_dp_aux *aux, u8 *crc)
{
u8 buf, count;
Expand Down Expand Up @@ -1063,12 +1069,12 @@ void drm_dp_aux_init(struct drm_dp_aux *aux)
mutex_init(&aux->hw_mutex);
mutex_init(&aux->cec.lock);
INIT_WORK(&aux->crc_work, drm_dp_aux_crc_work);

#ifdef __linux__
aux->ddc.algo = &drm_dp_i2c_algo;
aux->ddc.algo_data = aux;
aux->ddc.retries = 3;

aux->ddc.lock_ops = &drm_dp_i2c_lock_ops;
#endif
}
EXPORT_SYMBOL(drm_dp_aux_init);

Expand All @@ -1091,27 +1097,35 @@ EXPORT_SYMBOL(drm_dp_aux_init);
int drm_dp_aux_register(struct drm_dp_aux *aux)
{
int ret;

#ifdef __linux__
if (!aux->ddc.algo)
#else
if (!aux->ddc.bsddev)
#endif
drm_dp_aux_init(aux);

#ifdef __linux__
aux->ddc.class = I2C_CLASS_DDC;
aux->ddc.owner = THIS_MODULE;
aux->ddc.dev.parent = aux->dev;

strlcpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev),
sizeof(aux->ddc.name));

#else
aux->ddc.bsddev = aux->dev;
strlcpy(aux->ddc.name, aux->name ? aux->name : device_get_name(aux->dev),
sizeof(aux->ddc.name));
#endif
ret = drm_dp_aux_register_devnode(aux);
if (ret)
return ret;

#ifdef __linux__
ret = i2c_add_adapter(&aux->ddc);
if (ret) {
drm_dp_aux_unregister_devnode(aux);
return ret;
}

#endif
return 0;
}
EXPORT_SYMBOL(drm_dp_aux_register);
Expand All @@ -1123,7 +1137,9 @@ EXPORT_SYMBOL(drm_dp_aux_register);
void drm_dp_aux_unregister(struct drm_dp_aux *aux)
{
drm_dp_aux_unregister_devnode(aux);
#ifdef __linux__
i2c_del_adapter(&aux->ddc);
#endif
}
EXPORT_SYMBOL(drm_dp_aux_unregister);

Expand Down
4 changes: 3 additions & 1 deletion core/include/drm/drm_dp_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

#ifndef _DRM_DP_HELPER_H_
#define _DRM_DP_HELPER_H_

#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/i2c.h>
#include <linux/types.h>

Expand Down
18 changes: 3 additions & 15 deletions core/include/drm/drm_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,7 @@ void drm_dev_dbg(const struct device *dev, enum drm_debug_category category,
* @fmt: printf() like format string.
*/
#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
({ \
static DEFINE_RATELIMIT_STATE(_rs, \
DEFAULT_RATELIMIT_INTERVAL, \
DEFAULT_RATELIMIT_BURST); \
\
if (__ratelimit(&_rs)) \
DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
})
DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__);

#define DRM_DEV_INFO(dev, fmt, ...) \
drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
Expand Down Expand Up @@ -508,13 +501,8 @@ void __drm_err(const char *format, ...);


#define DRM_DEBUG_KMS_RATELIMITED(fmt, ...) \
({ \
static DEFINE_RATELIMIT_STATE(_rs, \
DEFAULT_RATELIMIT_INTERVAL, \
DEFAULT_RATELIMIT_BURST); \
if (__ratelimit(&_rs)) \
drm_dev_dbg(NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__); \
})
drm_dev_dbg(NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__)


/*
* struct drm_device based WARNs
Expand Down
2 changes: 2 additions & 0 deletions extra_patches/files
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dev/drm/core/drm_color_mgmt.c optional compat_drmcompat drm compile-with "${DR
dev/drm/core/drm_connector.c optional compat_drmcompat drm compile-with "${DRM_C}"
dev/drm/core/drm_crtc.c optional compat_drmcompat drm compile-with "${DRM_C}"
dev/drm/core/drm_crtc_helper.c optional compat_drmcompat drm compile-with "${DRM_C}"
dev/drm/core/drm_dp_helper.c optional compat_drmcompat drm compile-with "${DRM_C}"
#dev/drm/core/drm_dp_mst_topology.c optional compat_drmcompat drm compile-with "${DRM_C}"
dev/drm/core/drm_damage_helper.c optional compat_drmcompat drm compile-with "${DRM_C}"
dev/drm/core/drm_drv.c optional compat_drmcompat drm compile-with "${DRM_C}"
dev/drm/core/drm_dumb_buffers.c optional compat_drmcompat drm compile-with "${DRM_C}"
Expand Down
4 changes: 3 additions & 1 deletion extra_patches/files.bridges
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
dev/drm/bridges/dw_hdmi/aw_de2_dw_hdmi.c optional drm fdt dw_hdmi aw_de2_drm compile-with "${DRM_C}"
dev/drm/bridges/dw_hdmi/rk_dw_hdmi.c optional drm fdt dw_hdmi rk_drm compile-with "${DRM_C}"
dev/drm/bridges/dw_hdmi/dw_hdmi.c optional drm fdt dw_hdmi compile-with "${DRM_C}"
dev/drm/bridges/dw_hdmi/dw_hdmi_if.m optional drm fdt dw_hdmi
dev/drm/bridges/dw_hdmi/dw_hdmi_if.m optional drm fdt dw_hdmi | rk_anxdp
dev/drm/bridges/dw_hdmi/dw_hdmi_phy_if.m optional drm fdt dw_hdmi

# ANX6345 RGB to eDP bridge
dev/drm/bridges/anx6345/anx6345.c optional fdt anx6345 compile-with "${DRM_C}"
# ANXDP for pinebookpro
dev/drm/bridges/anxdp/anx_dp.c optional fdt rk_anxdp compile-with "${DRM_C}"
1 change: 1 addition & 0 deletions extra_patches/files.rk
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dev/drm/rockchip/rk_gem.c optional drm fdt rk_drm compile-with "${DRM_C}"
dev/drm/rockchip/rk_plane.c optional drm fdt rk_drm compile-with "${DRM_C}"
dev/drm/rockchip/rk_vop.c optional drm fdt rk_drm compile-with "${DRM_C}"
dev/drm/rockchip/rk_vop_if.m optional drm fdt rk_drm
dev/drm/rockchip/rk_anxdp.c optional drm fdt rk_anxdp compile-with "${DRM_C}"
Loading