1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2015 Synaptics Incorporated
4 * Copyright (C) 2016 Zodiac Inflight Innovations
7 #include <linux/bitops.h>
8 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include "rmi_driver.h"
13 #define F55_NAME "rmi4_f55"
15 /* F55 data offsets */
16 #define F55_NUM_RX_OFFSET 0
17 #define F55_NUM_TX_OFFSET 1
18 #define F55_PHYS_CHAR_OFFSET 2
20 /* Only read required query registers */
21 #define F55_QUERY_LEN 3
23 /* F55 capabilities */
24 #define F55_CAP_SENSOR_ASSIGN BIT(0)
27 struct rmi_function
*fn
;
29 u8 qry
[F55_QUERY_LEN
];
31 u8 cfg_num_rx_electrodes
;
33 u8 cfg_num_tx_electrodes
;
36 static int rmi_f55_detect(struct rmi_function
*fn
)
38 struct rmi_device
*rmi_dev
= fn
->rmi_dev
;
39 struct rmi_driver_data
*drv_data
= dev_get_drvdata(&rmi_dev
->dev
);
43 f55
= dev_get_drvdata(&fn
->dev
);
45 error
= rmi_read_block(fn
->rmi_dev
, fn
->fd
.query_base_addr
,
46 &f55
->qry
, sizeof(f55
->qry
));
48 dev_err(&fn
->dev
, "%s: Failed to query F55 properties\n",
53 f55
->num_rx_electrodes
= f55
->qry
[F55_NUM_RX_OFFSET
];
54 f55
->num_tx_electrodes
= f55
->qry
[F55_NUM_TX_OFFSET
];
56 f55
->cfg_num_rx_electrodes
= f55
->num_rx_electrodes
;
57 f55
->cfg_num_tx_electrodes
= f55
->num_rx_electrodes
;
59 drv_data
->num_rx_electrodes
= f55
->cfg_num_rx_electrodes
;
60 drv_data
->num_tx_electrodes
= f55
->cfg_num_rx_electrodes
;
62 if (f55
->qry
[F55_PHYS_CHAR_OFFSET
] & F55_CAP_SENSOR_ASSIGN
) {
67 * Calculate the number of enabled receive and transmit
68 * electrodes by reading F55:Ctrl1 (sensor receiver assignment)
69 * and F55:Ctrl2 (sensor transmitter assignment). The number of
70 * enabled electrodes is the sum of all field entries with a
71 * value other than 0xff.
73 error
= rmi_read_block(fn
->rmi_dev
,
74 fn
->fd
.control_base_addr
+ 1,
75 buf
, f55
->num_rx_electrodes
);
78 for (i
= 0; i
< f55
->num_rx_electrodes
; i
++) {
82 f55
->cfg_num_rx_electrodes
= total
;
83 drv_data
->num_rx_electrodes
= total
;
86 error
= rmi_read_block(fn
->rmi_dev
,
87 fn
->fd
.control_base_addr
+ 2,
88 buf
, f55
->num_tx_electrodes
);
91 for (i
= 0; i
< f55
->num_tx_electrodes
; i
++) {
95 f55
->cfg_num_tx_electrodes
= total
;
96 drv_data
->num_tx_electrodes
= total
;
100 rmi_dbg(RMI_DEBUG_FN
, &fn
->dev
, "F55 num_rx_electrodes: %d (raw %d)\n",
101 f55
->cfg_num_rx_electrodes
, f55
->num_rx_electrodes
);
102 rmi_dbg(RMI_DEBUG_FN
, &fn
->dev
, "F55 num_tx_electrodes: %d (raw %d)\n",
103 f55
->cfg_num_tx_electrodes
, f55
->num_tx_electrodes
);
108 static int rmi_f55_probe(struct rmi_function
*fn
)
110 struct f55_data
*f55
;
112 f55
= devm_kzalloc(&fn
->dev
, sizeof(struct f55_data
), GFP_KERNEL
);
117 dev_set_drvdata(&fn
->dev
, f55
);
119 return rmi_f55_detect(fn
);
122 struct rmi_function_handler rmi_f55_handler
= {
127 .probe
= rmi_f55_probe
,