Files
threeeye bc1d038eac REVVL 6 Pro kernel bring-up: full working tree snapshot (2026-09-12)
Squashed backup commit (no shallow-clone history issues) of
xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2 branch, upstream
commit 9eece662e) plus all fixes applied to get everpal_defconfig building
clean against a modern (GCC 15.2.0) toolchain -- see the previous commit
message on the lineage-23.2 branch (also in this repo history is not
available here since this is a squashed snapshot; full incremental history
lives in the local DL380 checkout and the upstream GitHub remote).

Upstream: https://github.com/xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2)
2026-09-12 13:36:46 +00:00

253 lines
6.3 KiB
C

/*
* Copyright (C) 2013-2016, Shenzhen Huiding Technology Co., Ltd.
* Copyright (C) 2021 XiaoMi, Inc.
* All Rights Reserved.
*/
#ifndef __GF_SPI_TEE_H
#define __GF_SPI_TEE_H
#include <linux/types.h>
#include <linux/netlink.h>
#include <linux/cdev.h>
#include <linux/input.h>
#ifndef CONFIG_SPI_MT65XX
#include "mtk_spi.h"
#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#else
#include <linux/notifier.h>
#endif
/**************************debug******************************/
#define ERR_LOG (0)
#define INFO_LOG (1)
#define DEBUG_LOG (2)
/* debug log setting */
u8 g_debug_level = DEBUG_LOG;
#define gf_debug(level, fmt, args...) do { \
if (g_debug_level >= level) {\
pr_warn("[gf] " fmt, ##args); \
} \
} while (0)
#define FUNC_ENTRY() gf_debug(DEBUG_LOG, "%s, %d, enter\n", __func__, __LINE__)
#define FUNC_EXIT() gf_debug(DEBUG_LOG, "%s, %d, exit\n", __func__, __LINE__)
/**********************IO Magic**********************/
#define GF_IOC_MAGIC 'g'
#define GF_NAV_INPUT_UP KEY_UP
#define GF_NAV_INPUT_DOWN KEY_DOWN
#define GF_NAV_INPUT_LEFT KEY_LEFT
#define GF_NAV_INPUT_RIGHT KEY_RIGHT
#define GF_NAV_INPUT_CLICK KEY_VOLUMEDOWN
#define GF_NAV_INPUT_DOUBLE_CLICK KEY_VOLUMEUP
#define GF_NAV_INPUT_LONG_PRESS KEY_SEARCH
#define GF_NAV_INPUT_HEAVY KEY_CHAT
typedef enum gf_nav_event {
GF_NAV_NONE = 0,
GF_NAV_FINGER_UP,
GF_NAV_FINGER_DOWN,
GF_NAV_UP,
GF_NAV_DOWN,
GF_NAV_LEFT,
GF_NAV_RIGHT,
GF_NAV_CLICK,
GF_NAV_HEAVY,
GF_NAV_LONG_PRESS,
GF_NAV_DOUBLE_CLICK,
} gf_nav_event_t;
typedef enum gf_key_event {
GF_KEY_NONE = 0,
GF_KEY_POWER,
GF_KEY_MENU,
GF_KEY_BACK,
GF_KEY_CAMERA,
GF_KEY_HOME_DOUBLE_CLICK,
} gf_key_event_t;
enum gf_netlink_cmd {
GF_NETLINK_TEST = 0,
GF_NETLINK_IRQ = 1,
GF_NETLINK_SCREEN_OFF,
GF_NETLINK_SCREEN_ON
};
struct gf_ioc_transfer {
u8 cmd; /* spi read = 0, spi write = 1 */
u8 reserved;
u16 addr;
u32 len;
u8 *buf;
};
struct gf_ioc_transfer_raw {
u32 len;
u8 *read_buf;
u8 *write_buf;
uint32_t high_time;
uint32_t low_time;
};
struct gf_ioc_chip_info {
u8 vendor_id;
u8 mode;
u8 operation;
u8 reserved[5];
};
/* define for gf_spi_cfg_t->speed_hz */
#define GF_SPI_SPEED_LOW 1
#define GF_SPI_SPEED_MEDIUM 6
#define GF_SPI_SPEED_HIGH 9
enum gf_spi_cpol {
GF_SPI_CPOL_0,
GF_SPI_CPOL_1
};
enum gf_spi_cpha {
GF_SPI_CPHA_0,
GF_SPI_CPHA_1
};
typedef struct {
unsigned int cs_setuptime;
unsigned int cs_holdtime;
unsigned int cs_idletime;
unsigned int speed_hz; //spi clock rate
unsigned int duty_cycle; //The time ratio of active level in a period. Default value is 50. that means high time and low time is same.
enum gf_spi_cpol cpol;
enum gf_spi_cpol cpha;
} gf_spi_cfg_t;
/* define commands */
#define GF_IOC_INIT _IOR(GF_IOC_MAGIC, 0, u8)
#define GF_IOC_EXIT _IO(GF_IOC_MAGIC, 1)
#define GF_IOC_RESET _IO(GF_IOC_MAGIC, 2)
#define GF_IOC_ENABLE_IRQ _IO(GF_IOC_MAGIC, 3)
#define GF_IOC_DISABLE_IRQ _IO(GF_IOC_MAGIC, 4)
#define GF_IOC_ENABLE_SPI_CLK _IOW(GF_IOC_MAGIC, 5, uint32_t)
#define GF_IOC_DISABLE_SPI_CLK _IO(GF_IOC_MAGIC, 6)
#define GF_IOC_ENABLE_POWER _IO(GF_IOC_MAGIC, 7)
#define GF_IOC_DISABLE_POWER _IO(GF_IOC_MAGIC, 8)
/* fp sensor has change to sleep mode while screen off */
#define GF_IOC_ENTER_SLEEP_MODE _IO(GF_IOC_MAGIC, 10)
#define GF_IOC_GET_FW_INFO _IOR(GF_IOC_MAGIC, 11, u8)
#define GF_IOC_REMOVE _IO(GF_IOC_MAGIC, 12)
#define GF_IOC_CHIP_INFO _IOW(GF_IOC_MAGIC, 13, struct gf_ioc_chip_info)
#define GF_IOC_NAV_EVENT _IOW(GF_IOC_MAGIC, 14, gf_nav_event_t)
/* for SPI REE transfer */
#define GF_IOC_TRANSFER_CMD _IOWR(GF_IOC_MAGIC, 15, struct gf_ioc_transfer)
#define GF_IOC_TRANSFER_RAW_CMD _IOWR(GF_IOC_MAGIC, 16, struct gf_ioc_transfer_raw)
#define GF_IOC_SPI_INIT_CFG_CMD _IOW(GF_IOC_MAGIC, 17, gf_spi_cfg_t)
#define GF_IOC_MAXNR 18 /* THIS MACRO IS NOT USED NOW... */
struct gf_device {
dev_t devno;
struct cdev cdev;
struct device *device;
struct class *class;
struct spi_device *spi;
struct platform_device *pldev;
int device_count;
#ifndef CONFIG_SPI_MT65XX
struct mt_chip_conf spi_mcc;
#endif
spinlock_t spi_lock;
struct list_head device_entry;
struct input_dev *input;
u8 *spi_buffer; /* only used for SPI transfer internal */
struct mutex buf_lock;
struct mutex release_lock;
u8 buf_status;
/* for netlink use */
struct sock *nl_sk;
#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
#else
struct notifier_block notifier;
#endif
u8 probe_finish;
u8 irq_count;
/* bit24-bit32 of signal count */
/* bit16-bit23 of event type, 1: key down; 2: key up; 3: fp data ready; 4: home key */
/* bit0-bit15 of event type, buffer status register */
u32 event_type;
u8 sig_count;
u8 is_sleep_mode;
u8 system_status;
u32 cs_gpio;
u32 reset_gpio;
u32 irq_gpio;
u32 irq_num;
u8 need_update;
u32 irq;
u8 fb_black;
u8 wait_finger_down;
#ifdef CONFIG_OF
struct pinctrl *pinctrl_gpios;
struct pinctrl_state *pins_irq;
struct pinctrl_state *pins_miso_spi, *pins_miso_pullhigh, *pins_miso_pulllow;
struct pinctrl_state *pins_reset_high, *pins_reset_low;
#endif
};
/**************************REE SPI******************************/
#ifndef SUPPORT_REE_SPI
#define SUPPORT_REE_SPI
//#define SUPPORT_REE_OSWEGO
#endif
#ifdef SUPPORT_REE_SPI
#define HIGH_SPEED 6
#define LOW_SPEED 1
#define ERR_NO_SENSOR 111
#define ERR_FW_DESTROY 112
#define ERR_PREPARE_FAIL 113
/**********************function defination**********************/
#ifndef CONFIG_SPI_MT65XX
void gf_spi_setup_conf_ree(struct gf_device *gf_dev, u32 speed, enum spi_transfer_mode mode);
#endif
int gf_spi_read_bytes_ree(struct gf_device *gf_dev, u16 addr, u32 data_len, u8 *rx_buf);
int gf_spi_write_bytes_ree(struct gf_device *gf_dev, u16 addr, u32 data_len, u8 *tx_buf);
int gf_spi_read_byte_ree(struct gf_device *gf_dev, u16 addr, u8 *value);
int gf_spi_write_byte_ree(struct gf_device *gf_dev, u16 addr, u8 value);
int gf_ioctl_transfer_raw_cmd(struct gf_device *gf_dev, unsigned long arg,unsigned int bufsiz);
#ifndef CONFIG_SPI_MT65XX
int gf_ioctl_spi_init_cfg_cmd(struct mt_chip_conf *mcc, unsigned long arg);
#endif
#ifdef CONFIG_SPI_MT65XX
extern void mt_spi_enable_master_clk(struct spi_device *spidev);
extern void mt_spi_disable_master_clk(struct spi_device *spidev);
#endif
#endif
#endif /* __GF_SPI_TEE_H */