Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2011-2016 Synaptics Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2011 Unixphere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/rmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "rmi_driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define RMI_PRODUCT_ID_LENGTH    10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define RMI_PRODUCT_INFO_LENGTH   2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define RMI_DATE_CODE_LENGTH      3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define PRODUCT_ID_OFFSET 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PRODUCT_INFO_OFFSET 0x1E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /* Force a firmware reset of the sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define RMI_F01_CMD_DEVICE_RESET	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* Various F01_RMI_QueryX bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define RMI_F01_QRY1_CUSTOM_MAP		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define RMI_F01_QRY1_NON_COMPLIANT	BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define RMI_F01_QRY1_HAS_LTS		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define RMI_F01_QRY1_HAS_SENSOR_ID	BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define RMI_F01_QRY1_HAS_CHARGER_INP	BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define RMI_F01_QRY1_HAS_ADJ_DOZE	BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define RMI_F01_QRY1_HAS_ADJ_DOZE_HOFF	BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define RMI_F01_QRY1_HAS_QUERY42	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define RMI_F01_QRY5_YEAR_MASK		0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define RMI_F01_QRY6_MONTH_MASK		0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define RMI_F01_QRY7_DAY_MASK		0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define RMI_F01_QRY2_PRODINFO_MASK	0x7f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define RMI_F01_BASIC_QUERY_LEN		21 /* From Query 00 through 20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) struct f01_basic_properties {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 manufacturer_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	bool has_lts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	bool has_adjustable_doze;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	bool has_adjustable_doze_holdoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	char dom[11]; /* YYYY/MM/DD + '\0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	u8 product_id[RMI_PRODUCT_ID_LENGTH + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u16 productinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u32 firmware_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u32 package_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /* F01 device status bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) /* Most recent device status event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define RMI_F01_STATUS_CODE(status)		((status) & 0x0f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /* The device has lost its configuration for some reason. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define RMI_F01_STATUS_UNCONFIGURED(status)	(!!((status) & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /* The device is in bootloader mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define RMI_F01_STATUS_BOOTLOADER(status)	((status) & 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /* Control register bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * Sleep mode controls power management on the device and affects all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * functions of the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define RMI_F01_CTRL0_SLEEP_MODE_MASK	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define RMI_SLEEP_MODE_NORMAL		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define RMI_SLEEP_MODE_SENSOR_SLEEP	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define RMI_SLEEP_MODE_RESERVED0	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define RMI_SLEEP_MODE_RESERVED1	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * This bit disables whatever sleep mode may be selected by the sleep_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * field and forces the device to run at full power without sleeping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define RMI_F01_CTRL0_NOSLEEP_BIT	BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * When this bit is set, the touch controller employs a noise-filtering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * algorithm designed for use with a connected battery charger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define RMI_F01_CTRL0_CHARGER_BIT	BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * Sets the report rate for the device. The effect of this setting is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * highly product dependent. Check the spec sheet for your particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * touch sensor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define RMI_F01_CTRL0_REPORTRATE_BIT	BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * Written by the host as an indicator that the device has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * successfully configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define RMI_F01_CTRL0_CONFIGURED_BIT	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * @ctrl0 - see the bit definitions above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * @doze_interval - controls the interval between checks for finger presence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * when the touch sensor is in doze mode, in units of 10ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * @wakeup_threshold - controls the capacitance threshold at which the touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * sensor will decide to wake up from that low power state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * @doze_holdoff - controls how long the touch sensor waits after the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * finger lifts before entering the doze state, in units of 100ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct f01_device_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u8 ctrl0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	u8 doze_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	u8 wakeup_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	u8 doze_holdoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct f01_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct f01_basic_properties properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct f01_device_control device_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	u16 doze_interval_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	u16 wakeup_threshold_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	u16 doze_holdoff_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	bool suspended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	bool old_nosleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	unsigned int num_of_irq_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				   u16 query_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				   struct f01_basic_properties *props)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	u8 queries[RMI_F01_BASIC_QUERY_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	int query_offset = query_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	bool has_ds4_queries = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	bool has_query42 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	bool has_sensor_id = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	bool has_package_id_query = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	bool has_build_id_query = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	u16 prod_info_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	u8 ds4_query_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	ret = rmi_read_block(rmi_dev, query_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			       queries, RMI_F01_BASIC_QUERY_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		dev_err(&rmi_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			"Failed to read device query registers: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	prod_info_addr = query_offset + 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	query_offset += RMI_F01_BASIC_QUERY_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* Now parse what we got */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	props->manufacturer_id = queries[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	props->has_lts = queries[1] & RMI_F01_QRY1_HAS_LTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	props->has_adjustable_doze =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			queries[1] & RMI_F01_QRY1_HAS_ADJ_DOZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	props->has_adjustable_doze_holdoff =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			queries[1] & RMI_F01_QRY1_HAS_ADJ_DOZE_HOFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	has_query42 = queries[1] & RMI_F01_QRY1_HAS_QUERY42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	has_sensor_id = queries[1] & RMI_F01_QRY1_HAS_SENSOR_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	snprintf(props->dom, sizeof(props->dom), "20%02d/%02d/%02d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		 queries[5] & RMI_F01_QRY5_YEAR_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		 queries[6] & RMI_F01_QRY6_MONTH_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		 queries[7] & RMI_F01_QRY7_DAY_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	memcpy(props->product_id, &queries[11],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		RMI_PRODUCT_ID_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	props->product_id[RMI_PRODUCT_ID_LENGTH] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	props->productinfo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			((queries[2] & RMI_F01_QRY2_PRODINFO_MASK) << 7) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			(queries[3] & RMI_F01_QRY2_PRODINFO_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (has_sensor_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		query_offset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (has_query42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		ret = rmi_read(rmi_dev, query_offset, queries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			dev_err(&rmi_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				"Failed to read query 42 register: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		has_ds4_queries = !!(queries[0] & BIT(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		query_offset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (has_ds4_queries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		ret = rmi_read(rmi_dev, query_offset, &ds4_query_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			dev_err(&rmi_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				"Failed to read DS4 queries length: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		query_offset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (ds4_query_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			ret = rmi_read(rmi_dev, query_offset, queries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				dev_err(&rmi_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					"Failed to read DS4 queries: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			has_package_id_query = !!(queries[0] & BIT(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			has_build_id_query = !!(queries[0] & BIT(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (has_package_id_query) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			ret = rmi_read_block(rmi_dev, prod_info_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 					     queries, sizeof(__le64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				dev_err(&rmi_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 					"Failed to read package info: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 					ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			props->package_id = get_unaligned_le64(queries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			prod_info_addr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (has_build_id_query) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			ret = rmi_read_block(rmi_dev, prod_info_addr, queries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					    3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				dev_err(&rmi_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 					"Failed to read product info: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 					ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			props->firmware_id = queries[1] << 8 | queries[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			props->firmware_id += queries[2] * 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) const char *rmi_f01_get_product_ID(struct rmi_function *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct f01_data *f01 = dev_get_drvdata(&fn->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return f01->properties.product_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static ssize_t rmi_driver_manufacturer_id_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 					       struct device_attribute *dattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 					       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct rmi_driver_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return scnprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			 f01->properties.manufacturer_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static DEVICE_ATTR(manufacturer_id, 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		   rmi_driver_manufacturer_id_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static ssize_t rmi_driver_dom_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				   struct device_attribute *dattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct rmi_driver_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static DEVICE_ATTR(date_of_manufacture, 0444, rmi_driver_dom_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static ssize_t rmi_driver_product_id_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 					  struct device_attribute *dattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct rmi_driver_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.product_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static DEVICE_ATTR(product_id, 0444, rmi_driver_product_id_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static ssize_t rmi_driver_firmware_id_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 					   struct device_attribute *dattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 					   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct rmi_driver_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return scnprintf(buf, PAGE_SIZE, "%d\n", f01->properties.firmware_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static DEVICE_ATTR(firmware_id, 0444, rmi_driver_firmware_id_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static ssize_t rmi_driver_package_id_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 					  struct device_attribute *dattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 					  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct rmi_driver_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	u32 package_id = f01->properties.package_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return scnprintf(buf, PAGE_SIZE, "%04x.%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			 package_id & 0xffff, (package_id >> 16) & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static DEVICE_ATTR(package_id, 0444, rmi_driver_package_id_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct attribute *rmi_f01_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	&dev_attr_manufacturer_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	&dev_attr_date_of_manufacture.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	&dev_attr_product_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	&dev_attr_firmware_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	&dev_attr_package_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static const struct attribute_group rmi_f01_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.attrs = rmi_f01_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int rmi_f01_of_probe(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				struct rmi_device_platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	retval = rmi_of_property_read_u32(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			(u32 *)&pdata->power_management.nosleep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			"syna,nosleep-mode", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	retval = rmi_of_property_read_u32(dev, &val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			"syna,wakeup-threshold", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	pdata->power_management.wakeup_threshold = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	retval = rmi_of_property_read_u32(dev, &val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			"syna,doze-holdoff-ms", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	pdata->power_management.doze_holdoff = val * 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	retval = rmi_of_property_read_u32(dev, &val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			"syna,doze-interval-ms", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	pdata->power_management.doze_interval = val / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static inline int rmi_f01_of_probe(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 					struct rmi_device_platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static int rmi_f01_probe(struct rmi_function *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct rmi_device *rmi_dev = fn->rmi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct f01_data *f01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	u16 ctrl_base_addr = fn->fd.control_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	u8 device_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	u8 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (fn->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		error = rmi_f01_of_probe(&fn->dev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (!f01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	f01->num_of_irq_regs = driver_data->num_of_irq_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	 * Set the configured bit and (optionally) other important stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	 * in the device control register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	error = rmi_read(rmi_dev, fn->fd.control_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			 &f01->device_control.ctrl0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		dev_err(&fn->dev, "Failed to read F01 control: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	switch (pdata->power_management.nosleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	case RMI_REG_STATE_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	case RMI_REG_STATE_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_NOSLEEP_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	case RMI_REG_STATE_ON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		f01->device_control.ctrl0 |= RMI_F01_CTRL0_NOSLEEP_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	 * Sleep mode might be set as a hangover from a system crash or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	 * reboot without power cycle.  If so, clear it so the sensor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	 * is certain to function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if ((f01->device_control.ctrl0 & RMI_F01_CTRL0_SLEEP_MODE_MASK) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			RMI_SLEEP_MODE_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		dev_warn(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			 "WARNING: Non-zero sleep mode found. Clearing...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	f01->device_control.ctrl0 |= RMI_F01_CTRL0_CONFIGURED_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	error = rmi_write(rmi_dev, fn->fd.control_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			  f01->device_control.ctrl0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		dev_err(&fn->dev, "Failed to write F01 control: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	/* Dummy read in order to clear irqs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	error = rmi_read(rmi_dev, fn->fd.data_base_addr + 1, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		dev_err(&fn->dev, "Failed to read Interrupt Status.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	error = rmi_f01_read_properties(rmi_dev, fn->fd.query_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 					&f01->properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		dev_err(&fn->dev, "Failed to read F01 properties.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	dev_info(&fn->dev, "found RMI device, manufacturer: %s, product: %s, fw id: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		 f01->properties.manufacturer_id == 1 ? "Synaptics" : "unknown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		 f01->properties.product_id, f01->properties.firmware_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	/* Advance to interrupt control registers, then skip over them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	ctrl_base_addr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	ctrl_base_addr += f01->num_of_irq_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* read control register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (f01->properties.has_adjustable_doze) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		f01->doze_interval_addr = ctrl_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		ctrl_base_addr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		if (pdata->power_management.doze_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			f01->device_control.doze_interval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 				pdata->power_management.doze_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			error = rmi_write(rmi_dev, f01->doze_interval_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 					  f01->device_control.doze_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 					"Failed to configure F01 doze interval register: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			error = rmi_read(rmi_dev, f01->doze_interval_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 					 &f01->device_control.doze_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 				dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 					"Failed to read F01 doze interval register: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		f01->wakeup_threshold_addr = ctrl_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		ctrl_base_addr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		if (pdata->power_management.wakeup_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			f01->device_control.wakeup_threshold =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 				pdata->power_management.wakeup_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 			error = rmi_write(rmi_dev, f01->wakeup_threshold_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 					  f01->device_control.wakeup_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 				dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 					"Failed to configure F01 wakeup threshold register: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			error = rmi_read(rmi_dev, f01->wakeup_threshold_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 					 &f01->device_control.wakeup_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 				dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 					"Failed to read F01 wakeup threshold register: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	if (f01->properties.has_lts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		ctrl_base_addr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	if (f01->properties.has_adjustable_doze_holdoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		f01->doze_holdoff_addr = ctrl_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		ctrl_base_addr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if (pdata->power_management.doze_holdoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			f01->device_control.doze_holdoff =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 				pdata->power_management.doze_holdoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			error = rmi_write(rmi_dev, f01->doze_holdoff_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 					  f01->device_control.doze_holdoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 				dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 					"Failed to configure F01 doze holdoff register: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			error = rmi_read(rmi_dev, f01->doze_holdoff_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 					 &f01->device_control.doze_holdoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 				dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 					"Failed to read F01 doze holdoff register: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	error = rmi_read(rmi_dev, fn->fd.data_base_addr, &device_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			"Failed to read device status: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	if (RMI_F01_STATUS_UNCONFIGURED(device_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			"Device was reset during configuration process, status: %#02x!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 			RMI_F01_STATUS_CODE(device_status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	dev_set_drvdata(&fn->dev, f01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	error = sysfs_create_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		dev_warn(&fn->dev, "Failed to create sysfs group: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static void rmi_f01_remove(struct rmi_function *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	/* Note that the bus device is used, not the F01 device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	sysfs_remove_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static int rmi_f01_config(struct rmi_function *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	struct f01_data *f01 = dev_get_drvdata(&fn->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	error = rmi_write(fn->rmi_dev, fn->fd.control_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			  f01->device_control.ctrl0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 			"Failed to write device_control register: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (f01->properties.has_adjustable_doze) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		error = rmi_write(fn->rmi_dev, f01->doze_interval_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 				  f01->device_control.doze_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 			dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 				"Failed to write doze interval: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		error = rmi_write_block(fn->rmi_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 					 f01->wakeup_threshold_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 					 &f01->device_control.wakeup_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 					 sizeof(u8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 			dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 				"Failed to write wakeup threshold: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 				error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	if (f01->properties.has_adjustable_doze_holdoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		error = rmi_write(fn->rmi_dev, f01->doze_holdoff_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 				  f01->device_control.doze_holdoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 			dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 				"Failed to write doze holdoff: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static int rmi_f01_suspend(struct rmi_function *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	struct f01_data *f01 = dev_get_drvdata(&fn->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	f01->old_nosleep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		f01->device_control.ctrl0 & RMI_F01_CTRL0_NOSLEEP_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_NOSLEEP_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	if (device_may_wakeup(fn->rmi_dev->xport->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		f01->device_control.ctrl0 |= RMI_SLEEP_MODE_RESERVED1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		f01->device_control.ctrl0 |= RMI_SLEEP_MODE_SENSOR_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	error = rmi_write(fn->rmi_dev, fn->fd.control_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 			  f01->device_control.ctrl0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		dev_err(&fn->dev, "Failed to write sleep mode: %d.\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		if (f01->old_nosleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 			f01->device_control.ctrl0 |= RMI_F01_CTRL0_NOSLEEP_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		f01->device_control.ctrl0 |= RMI_SLEEP_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static int rmi_f01_resume(struct rmi_function *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	struct f01_data *f01 = dev_get_drvdata(&fn->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	if (f01->old_nosleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		f01->device_control.ctrl0 |= RMI_F01_CTRL0_NOSLEEP_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	f01->device_control.ctrl0 |= RMI_SLEEP_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	error = rmi_write(fn->rmi_dev, fn->fd.control_base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			  f01->device_control.ctrl0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			"Failed to restore normal operation: %d.\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static irqreturn_t rmi_f01_attention(int irq, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	struct rmi_function *fn = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	struct rmi_device *rmi_dev = fn->rmi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	u8 device_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	error = rmi_read(rmi_dev, fn->fd.data_base_addr, &device_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		dev_err(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 			"Failed to read device status: %d.\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		return IRQ_RETVAL(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	if (RMI_F01_STATUS_BOOTLOADER(device_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		dev_warn(&fn->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 			 "Device in bootloader mode, please update firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	if (RMI_F01_STATUS_UNCONFIGURED(device_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 		dev_warn(&fn->dev, "Device reset detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		error = rmi_dev->driver->reset_handler(rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 			dev_err(&fn->dev, "Device reset failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 			return IRQ_RETVAL(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct rmi_function_handler rmi_f01_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		.name	= "rmi4_f01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		 * Do not allow user unbinding F01 as it is critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		 * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		.suppress_bind_attrs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	.func		= 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	.probe		= rmi_f01_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	.remove		= rmi_f01_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	.config		= rmi_f01_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	.attention	= rmi_f01_attention,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	.suspend	= rmi_f01_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	.resume		= rmi_f01_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) };