linux/drivers/input/touchscreen/atmel_mxt_ts.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Atmel maXTouch Touchscreen driver
 *
 * Copyright (C) 2010 Samsung Electronics Co.Ltd
 * Copyright (C) 2011-2014 Atmel Corporation
 * Copyright (C) 2012 Google, Inc.
 * Copyright (C) 2016 Zodiac Inflight Innovations
 *
 * Author: Joonyoung Shim <[email protected]>
 */

#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/input/mt.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/of.h>
#include <linux/property.h>
#include <linux/slab.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/unaligned.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-vmalloc.h>
#include <dt-bindings/input/atmel-maxtouch.h>

/* Firmware files */
#define MXT_FW_NAME
#define MXT_CFG_NAME
#define MXT_CFG_MAGIC

/* Registers */
#define MXT_OBJECT_START
#define MXT_OBJECT_SIZE
#define MXT_INFO_CHECKSUM_SIZE
#define MXT_MAX_BLOCK_WRITE

/* Object types */
#define MXT_DEBUG_DIAGNOSTIC_T37
#define MXT_GEN_MESSAGE_T5
#define MXT_GEN_COMMAND_T6
#define MXT_GEN_POWER_T7
#define MXT_GEN_ACQUIRE_T8
#define MXT_GEN_DATASOURCE_T53
#define MXT_TOUCH_MULTI_T9
#define MXT_TOUCH_KEYARRAY_T15
#define MXT_TOUCH_PROXIMITY_T23
#define MXT_TOUCH_PROXKEY_T52
#define MXT_TOUCH_PTC_KEYS_T97
#define MXT_PROCI_GRIPFACE_T20
#define MXT_PROCG_NOISE_T22
#define MXT_PROCI_ONETOUCH_T24
#define MXT_PROCI_TWOTOUCH_T27
#define MXT_PROCI_GRIP_T40
#define MXT_PROCI_PALM_T41
#define MXT_PROCI_TOUCHSUPPRESSION_T42
#define MXT_PROCI_STYLUS_T47
#define MXT_PROCG_NOISESUPPRESSION_T48
#define MXT_SPT_COMMSCONFIG_T18
#define MXT_SPT_GPIOPWM_T19
#define MXT_SPT_SELFTEST_T25
#define MXT_SPT_CTECONFIG_T28
#define MXT_SPT_USERDATA_T38
#define MXT_SPT_DIGITIZER_T43
#define MXT_SPT_MESSAGECOUNT_T44
#define MXT_SPT_CTECONFIG_T46
#define MXT_SPT_DYNAMICCONFIGURATIONCONTAINER_T71
#define MXT_TOUCH_MULTITOUCHSCREEN_T100

/* MXT_GEN_MESSAGE_T5 object */
#define MXT_RPTID_NOMSG

/* MXT_GEN_COMMAND_T6 field */
#define MXT_COMMAND_RESET
#define MXT_COMMAND_BACKUPNV
#define MXT_COMMAND_CALIBRATE
#define MXT_COMMAND_REPORTALL
#define MXT_COMMAND_DIAGNOSTIC

/* Define for T6 status byte */
#define MXT_T6_STATUS_RESET
#define MXT_T6_STATUS_OFL
#define MXT_T6_STATUS_SIGERR
#define MXT_T6_STATUS_CAL
#define MXT_T6_STATUS_CFGERR
#define MXT_T6_STATUS_COMSERR

/* MXT_GEN_POWER_T7 field */
struct t7_config {} __packed;

#define MXT_POWER_CFG_RUN
#define MXT_POWER_CFG_DEEPSLEEP

/* MXT_TOUCH_MULTI_T9 field */
#define MXT_T9_CTRL
#define MXT_T9_XSIZE
#define MXT_T9_YSIZE
#define MXT_T9_ORIENT
#define MXT_T9_RANGE

/* MXT_TOUCH_MULTI_T9 status */
#define MXT_T9_UNGRIP
#define MXT_T9_SUPPRESS
#define MXT_T9_AMP
#define MXT_T9_VECTOR
#define MXT_T9_MOVE
#define MXT_T9_RELEASE
#define MXT_T9_PRESS
#define MXT_T9_DETECT

struct t9_range {} __packed;

/* MXT_TOUCH_MULTI_T9 orient */
#define MXT_T9_ORIENT_SWITCH
#define MXT_T9_ORIENT_INVERTX
#define MXT_T9_ORIENT_INVERTY

/* MXT_SPT_COMMSCONFIG_T18 */
#define MXT_COMMS_CTRL
#define MXT_COMMS_CMD
#define MXT_COMMS_RETRIGEN

/* MXT_DEBUG_DIAGNOSTIC_T37 */
#define MXT_DIAGNOSTIC_PAGEUP
#define MXT_DIAGNOSTIC_DELTAS
#define MXT_DIAGNOSTIC_REFS
#define MXT_DIAGNOSTIC_SIZE

#define MXT_FAMILY_1386
#define MXT1386_COLUMNS
#define MXT1386_PAGES_PER_COLUMN

struct t37_debug {};

/* Define for MXT_GEN_COMMAND_T6 */
#define MXT_BOOT_VALUE
#define MXT_RESET_VALUE
#define MXT_BACKUP_VALUE

/* T100 Multiple Touch Touchscreen */
#define MXT_T100_CTRL
#define MXT_T100_CFG1
#define MXT_T100_TCHAUX
#define MXT_T100_XSIZE
#define MXT_T100_XRANGE
#define MXT_T100_YSIZE
#define MXT_T100_YRANGE

#define MXT_T100_CFG_SWITCHXY
#define MXT_T100_CFG_INVERTY
#define MXT_T100_CFG_INVERTX

#define MXT_T100_TCHAUX_VECT
#define MXT_T100_TCHAUX_AMPL
#define MXT_T100_TCHAUX_AREA

#define MXT_T100_DETECT
#define MXT_T100_TYPE_MASK

enum t100_type {};

#define MXT_DISTANCE_ACTIVE_TOUCH
#define MXT_DISTANCE_HOVERING

#define MXT_TOUCH_MAJOR_DEFAULT
#define MXT_PRESSURE_DEFAULT

/* Delay times */
#define MXT_BACKUP_TIME
#define MXT_RESET_GPIO_TIME
#define MXT_RESET_INVALID_CHG
#define MXT_RESET_TIME
#define MXT_RESET_TIMEOUT
#define MXT_CRC_TIMEOUT
#define MXT_FW_RESET_TIME
#define MXT_FW_CHG_TIMEOUT
#define MXT_WAKEUP_TIME

/* Command to unlock bootloader */
#define MXT_UNLOCK_CMD_MSB
#define MXT_UNLOCK_CMD_LSB

/* Bootloader mode status */
#define MXT_WAITING_BOOTLOAD_CMD
#define MXT_WAITING_FRAME_DATA
#define MXT_FRAME_CRC_CHECK
#define MXT_FRAME_CRC_FAIL
#define MXT_FRAME_CRC_PASS
#define MXT_APP_CRC_FAIL
#define MXT_BOOT_STATUS_MASK
#define MXT_BOOT_EXTENDED_ID
#define MXT_BOOT_ID_MASK

/* Touchscreen absolute values */
#define MXT_MAX_AREA

#define MXT_PIXELS_PER_MM

struct mxt_info {};

struct mxt_object {} __packed;

struct mxt_dbg {};

enum v4l_dbg_inputs {};

enum mxt_suspend_mode {};

/* Config update context */
struct mxt_cfg {};

/* Each client has this additional data */
struct mxt_data {};

struct mxt_vb2_buffer {};

static size_t mxt_obj_size(const struct mxt_object *obj)
{}

static size_t mxt_obj_instances(const struct mxt_object *obj)
{}

static bool mxt_object_readable(unsigned int type)
{}

static void mxt_dump_message(struct mxt_data *data, u8 *message)
{}

static int mxt_wait_for_completion(struct mxt_data *data,
				   struct completion *comp,
				   unsigned int timeout_ms)
{}

static int mxt_bootloader_read(struct mxt_data *data,
			       u8 *val, unsigned int count)
{}

static int mxt_bootloader_write(struct mxt_data *data,
				const u8 * const val, unsigned int count)
{}

static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry)
{}

static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address)
{}

static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val)
{}

static int mxt_check_bootloader(struct mxt_data *data, unsigned int state,
				bool wait)
{}

static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock)
{}

static bool mxt_wakeup_toggle(struct i2c_client *client,
			      bool wake_up, bool in_i2c)
{}

static int __mxt_read_reg(struct i2c_client *client,
			       u16 reg, u16 len, void *val)
{}

static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
			   const void *val)
{}

static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
{}

static struct mxt_object *
mxt_get_object(struct mxt_data *data, u8 type)
{}

static void mxt_proc_t6_messages(struct mxt_data *data, u8 *msg)
{}

static int mxt_write_object(struct mxt_data *data,
				 u8 type, u8 offset, u8 val)
{}

static void mxt_input_button(struct mxt_data *data, u8 *message)
{}

static void mxt_input_sync(struct mxt_data *data)
{}

static void mxt_proc_t9_message(struct mxt_data *data, u8 *message)
{}

static void mxt_proc_t15_messages(struct mxt_data *data, u8 *message)
{}

static void mxt_proc_t97_messages(struct mxt_data *data, u8 *message)
{}

static void mxt_proc_t100_message(struct mxt_data *data, u8 *message)
{}

static int mxt_proc_message(struct mxt_data *data, u8 *message)
{}

static int mxt_read_and_process_messages(struct mxt_data *data, u8 count)
{}

static irqreturn_t mxt_process_messages_t44(struct mxt_data *data)
{}

static int mxt_process_messages_until_invalid(struct mxt_data *data)
{}

static irqreturn_t mxt_process_messages(struct mxt_data *data)
{}

static irqreturn_t mxt_interrupt(int irq, void *dev_id)
{}

static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset,
			  u8 value, bool wait)
{}

static int mxt_acquire_irq(struct mxt_data *data)
{}

static int mxt_soft_reset(struct mxt_data *data)
{}

static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value)
{}

static void mxt_calc_crc24(u32 *crc, u8 firstbyte, u8 secondbyte)
{}

static u32 mxt_calculate_crc(u8 *base, off_t start_off, off_t end_off)
{}

static int mxt_check_retrigen(struct mxt_data *data)
{}

static int mxt_prepare_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg)
{}

static int mxt_upload_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg)
{}

static int mxt_init_t7_power_cfg(struct mxt_data *data);

/*
 * mxt_update_cfg - download configuration to chip
 *
 * Atmel Raw Config File Format
 *
 * The first four lines of the raw config file contain:
 *  1) Version
 *  2) Chip ID Information (first 7 bytes of device memory)
 *  3) Chip Information Block 24-bit CRC Checksum
 *  4) Chip Configuration 24-bit CRC Checksum
 *
 * The rest of the file consists of one line per object instance:
 *   <TYPE> <INSTANCE> <SIZE> <CONTENTS>
 *
 *   <TYPE> - 2-byte object type as hex
 *   <INSTANCE> - 2-byte object instance number as hex
 *   <SIZE> - 2-byte object size as hex
 *   <CONTENTS> - array of <SIZE> 1-byte hex values
 */
static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw)
{}

static void mxt_free_input_device(struct mxt_data *data)
{}

static void mxt_free_object_table(struct mxt_data *data)
{}

static int mxt_parse_object_table(struct mxt_data *data,
				  struct mxt_object *object_table)
{}

static int mxt_read_info_block(struct mxt_data *data)
{}

static int mxt_read_t9_resolution(struct mxt_data *data)
{}

static int mxt_read_t100_config(struct mxt_data *data)
{}

static int mxt_input_open(struct input_dev *dev);
static void mxt_input_close(struct input_dev *dev);

static void mxt_set_up_as_touchpad(struct input_dev *input_dev,
				   struct mxt_data *data)
{}

static int mxt_initialize_input_device(struct mxt_data *data)
{}

static int mxt_configure_objects(struct mxt_data *data,
				 const struct firmware *cfg);

static void mxt_config_cb(const struct firmware *cfg, void *ctx)
{}

static int mxt_initialize(struct mxt_data *data)
{}

static int mxt_set_t7_power_cfg(struct mxt_data *data, u8 sleep)
{}

static int mxt_init_t7_power_cfg(struct mxt_data *data)
{}

#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
static const struct v4l2_file_operations mxt_video_fops =;

static u16 mxt_get_debug_value(struct mxt_data *data, unsigned int x,
			       unsigned int y)
{}

static int mxt_convert_debug_pages(struct mxt_data *data, u16 *outbuf)
{}

static int mxt_read_diagnostic_debug(struct mxt_data *data, u8 mode,
				     u16 *outbuf)
{}

static int mxt_queue_setup(struct vb2_queue *q,
		       unsigned int *nbuffers, unsigned int *nplanes,
		       unsigned int sizes[], struct device *alloc_devs[])
{}

static void mxt_buffer_queue(struct vb2_buffer *vb)
{}

/* V4L2 structures */
static const struct vb2_ops mxt_queue_ops =;

static const struct vb2_queue mxt_queue =;

static int mxt_vidioc_querycap(struct file *file, void *priv,
				 struct v4l2_capability *cap)
{}

static int mxt_vidioc_enum_input(struct file *file, void *priv,
				   struct v4l2_input *i)
{}

static int mxt_set_input(struct mxt_data *data, unsigned int i)
{}

static int mxt_vidioc_s_input(struct file *file, void *priv, unsigned int i)
{}

static int mxt_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
{}

static int mxt_vidioc_fmt(struct file *file, void *priv, struct v4l2_format *f)
{}

static int mxt_vidioc_enum_fmt(struct file *file, void *priv,
				 struct v4l2_fmtdesc *fmt)
{}

static int mxt_vidioc_g_parm(struct file *file, void *fh,
			     struct v4l2_streamparm *a)
{}

static const struct v4l2_ioctl_ops mxt_video_ioctl_ops =;

static const struct video_device mxt_video_device =;

static void mxt_debug_init(struct mxt_data *data)
{}
#else
static void mxt_debug_init(struct mxt_data *data)
{
}
#endif

static int mxt_configure_objects(struct mxt_data *data,
				 const struct firmware *cfg)
{}

/* Firmware Version is returned as Major.Minor.Build */
static ssize_t mxt_fw_version_show(struct device *dev,
				   struct device_attribute *attr, char *buf)
{}

/* Hardware Version is returned as FamilyID.VariantID */
static ssize_t mxt_hw_version_show(struct device *dev,
				   struct device_attribute *attr, char *buf)
{}

static ssize_t mxt_show_instance(char *buf, int count,
				 struct mxt_object *object, int instance,
				 const u8 *val)
{}

static ssize_t mxt_object_show(struct device *dev,
			       struct device_attribute *attr, char *buf)
{}

static int mxt_check_firmware_format(struct device *dev,
				     const struct firmware *fw)
{}

static int mxt_load_fw(struct device *dev, const char *fn)
{}

static ssize_t mxt_update_fw_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t count)
{}

static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);

static struct attribute *mxt_attrs[] =;

ATTRIBUTE_GROUPS();

static void mxt_start(struct mxt_data *data)
{}

static void mxt_stop(struct mxt_data *data)
{}

static int mxt_input_open(struct input_dev *dev)
{}

static void mxt_input_close(struct input_dev *dev)
{}

static int mxt_parse_device_properties(struct mxt_data *data)
{}

static const struct dmi_system_id chromebook_T9_suspend_dmi[] =;

static int mxt_probe(struct i2c_client *client)
{}

static void mxt_remove(struct i2c_client *client)
{}

static int mxt_suspend(struct device *dev)
{}

static int mxt_resume(struct device *dev)
{}

static DEFINE_SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);

static const struct of_device_id mxt_of_match[] =;
MODULE_DEVICE_TABLE(of, mxt_of_match);

#ifdef CONFIG_ACPI
static const struct acpi_device_id mxt_acpi_id[] =;
MODULE_DEVICE_TABLE(acpi, mxt_acpi_id);
#endif

static const struct i2c_device_id mxt_id[] =;
MODULE_DEVICE_TABLE(i2c, mxt_id);

static struct i2c_driver mxt_driver =;

module_i2c_driver();

/* Module information */
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();