#ifndef __APPLE_DCP_INTERNAL_H__
#define __APPLE_DCP_INTERNAL_H__
#include <linux/backlight.h>
#include <linux/device.h>
#include <linux/ioport.h>
#include <linux/mutex.h>
#include <linux/mux/consumer.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include "dptxep.h"
#include "iomfb.h"
#include "iomfb_v12_3.h"
#include "iomfb_v13_3.h"
#define DCP_MAX_PLANES 2
struct apple_dcp;
struct apple_dcp_afkep;
enum dcp_firmware_version {
DCP_FIRMWARE_UNKNOWN,
DCP_FIRMWARE_V_12_3,
DCP_FIRMWARE_V_13_5,
};
enum {
SYSTEM_ENDPOINT = 0x20,
TEST_ENDPOINT = 0x21,
DCP_EXPERT_ENDPOINT = 0x22,
DISP0_ENDPOINT = 0x23,
DPTX_ENDPOINT = 0x2a,
HDCP_ENDPOINT = 0x2b,
REMOTE_ALLOC_ENDPOINT = 0x2d,
IOMFB_ENDPOINT = 0x37,
};
struct dcp_chunks {
size_t length;
void *data;
};
#define DCP_MAX_MAPPINGS (128)
#define MAX_DISP_REGISTERS (7)
struct dcp_mem_descriptor {
size_t size;
void *buf;
dma_addr_t dva;
struct sg_table map;
u64 reg;
};
#define DCP_MAX_CALL_DEPTH 8
typedef void (*dcp_callback_t)(struct apple_dcp *, void *, void *);
struct dcp_channel {
dcp_callback_t callbacks[DCP_MAX_CALL_DEPTH];
void *cookies[DCP_MAX_CALL_DEPTH];
void *output[DCP_MAX_CALL_DEPTH];
u16 end[DCP_MAX_CALL_DEPTH];
u8 depth;
};
struct dcp_fb_reference {
struct list_head head;
struct drm_framebuffer *fb;
u32 swap_id;
};
#define MAX_NOTCH_HEIGHT 160
struct dcp_brightness {
struct backlight_device *bl_dev;
u32 maximum;
u32 dac;
int nits;
int scale;
bool update;
};
struct dcp_panel {
int width_mm;
int height_mm;
bool has_mini_led;
};
struct apple_dcp_hw_data {
u32 num_dptx_ports;
};
struct apple_dcp {
struct device *dev;
struct platform_device *piodma;
struct iommu_domain *iommu_dom;
struct apple_rtkit *rtk;
struct apple_crtc *crtc;
struct apple_connector *connector;
struct apple_dcp_hw_data hw;
enum dcp_firmware_version fw_compat;
void __iomem *coproc_reg;
bool crashed;
struct clk *clk;
void *shmem;
struct resource *disp_registers[MAX_DISP_REGISTERS];
unsigned int nr_disp_registers;
struct resource disp_bw_scratch_res;
struct resource disp_bw_doorbell_res;
u32 disp_bw_scratch_index;
u32 disp_bw_scratch_offset;
u32 disp_bw_doorbell_index;
u32 disp_bw_doorbell_offset;
u32 index;
DECLARE_BITMAP(memdesc_map, DCP_MAX_MAPPINGS);
struct dcp_mem_descriptor memdesc[DCP_MAX_MAPPINGS];
struct dcp_channel ch_cmd, ch_oobcmd;
struct dcp_channel ch_cb, ch_oobcb, ch_async, ch_oobasync;
const iomfb_cb_handler *cb_handlers;
struct dcp_chunks chunks;
union {
struct dcp_swap_submit_req_v12_3 v12_3;
struct dcp_swap_submit_req_v13_3 v13_3;
} swap;
u32 last_swap_id;
bool during_modeset;
bool valid_mode;
struct dcp_set_digital_out_mode_req mode;
struct completion start_done;
bool active;
bool main_display;
bool surfaces_cleared;
struct dcp_display_mode *modes;
unsigned int nr_modes;
int connector_type;
int width_mm, height_mm;
unsigned notch_height;
struct work_struct vblank_wq;
struct list_head swapped_out_fbs;
struct dcp_brightness brightness;
struct work_struct bl_register_wq;
struct rwlock bl_register_mutex;
struct work_struct bl_update_wq;
struct dcp_panel panel;
struct apple_dcp_afkep *systemep;
struct completion systemep_done;
struct apple_dcp_afkep *ibootep;
struct apple_dcp_afkep *dptxep;
struct dptx_port dptxport[2];
struct phy *phy;
struct mux_control *xbar;
struct gpio_desc *hdmi_hpd;
struct gpio_desc *hdmi_pwren;
struct gpio_desc *dp2hdmi_pwren;
struct rwlock hpd_mutex;
u32 dptx_phy;
u32 dptx_die;
int hdmi_hpd_irq;
};
int dcp_backlight_register(struct apple_dcp *dcp);
int dcp_backlight_update(struct apple_dcp *dcp);
bool dcp_has_panel(struct apple_dcp *dcp);
#define DCP_AUDIO_MAX_CHANS 15
#endif