18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2011-2016 Synaptics Incorporated 48c2ecf20Sopenharmony_ci * Copyright (c) 2011 Unixphere 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef _RMI_BUS_H 88c2ecf20Sopenharmony_ci#define _RMI_BUS_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/rmi.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct rmi_device; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* 158c2ecf20Sopenharmony_ci * The interrupt source count in the function descriptor can represent up to 168c2ecf20Sopenharmony_ci * 6 interrupt sources in the normal manner. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#define RMI_FN_MAX_IRQS 6 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/** 218c2ecf20Sopenharmony_ci * struct rmi_function - represents the implementation of an RMI4 228c2ecf20Sopenharmony_ci * function for a particular device (basically, a driver for that RMI4 function) 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * @fd: The function descriptor of the RMI function 258c2ecf20Sopenharmony_ci * @rmi_dev: Pointer to the RMI device associated with this function container 268c2ecf20Sopenharmony_ci * @dev: The device associated with this particular function. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * @num_of_irqs: The number of irqs needed by this function 298c2ecf20Sopenharmony_ci * @irq_pos: The position in the irq bitfield this function holds 308c2ecf20Sopenharmony_ci * @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN 318c2ecf20Sopenharmony_ci * interrupt handling. 328c2ecf20Sopenharmony_ci * @irqs: assigned virq numbers (up to num_of_irqs) 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * @node: entry in device's list of functions 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_cistruct rmi_function { 378c2ecf20Sopenharmony_ci struct rmi_function_descriptor fd; 388c2ecf20Sopenharmony_ci struct rmi_device *rmi_dev; 398c2ecf20Sopenharmony_ci struct device dev; 408c2ecf20Sopenharmony_ci struct list_head node; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci unsigned int num_of_irqs; 438c2ecf20Sopenharmony_ci int irq[RMI_FN_MAX_IRQS]; 448c2ecf20Sopenharmony_ci unsigned int irq_pos; 458c2ecf20Sopenharmony_ci unsigned long irq_mask[]; 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define to_rmi_function(d) container_of(d, struct rmi_function, dev) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cibool rmi_is_function_device(struct device *dev); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciint __must_check rmi_register_function(struct rmi_function *); 538c2ecf20Sopenharmony_civoid rmi_unregister_function(struct rmi_function *); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/** 568c2ecf20Sopenharmony_ci * struct rmi_function_handler - driver routines for a particular RMI function. 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * @func: The RMI function number 598c2ecf20Sopenharmony_ci * @reset: Called when a reset of the touch sensor is detected. The routine 608c2ecf20Sopenharmony_ci * should perform any out-of-the-ordinary reset handling that might be 618c2ecf20Sopenharmony_ci * necessary. Restoring of touch sensor configuration registers should be 628c2ecf20Sopenharmony_ci * handled in the config() callback, below. 638c2ecf20Sopenharmony_ci * @config: Called when the function container is first initialized, and 648c2ecf20Sopenharmony_ci * after a reset is detected. This routine should write any necessary 658c2ecf20Sopenharmony_ci * configuration settings to the device. 668c2ecf20Sopenharmony_ci * @attention: Called when the IRQ(s) for the function are set by the touch 678c2ecf20Sopenharmony_ci * sensor. 688c2ecf20Sopenharmony_ci * @suspend: Should perform any required operations to suspend the particular 698c2ecf20Sopenharmony_ci * function. 708c2ecf20Sopenharmony_ci * @resume: Should perform any required operations to resume the particular 718c2ecf20Sopenharmony_ci * function. 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * All callbacks are expected to return 0 on success, error code on failure. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct rmi_function_handler { 768c2ecf20Sopenharmony_ci struct device_driver driver; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci u8 func; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci int (*probe)(struct rmi_function *fn); 818c2ecf20Sopenharmony_ci void (*remove)(struct rmi_function *fn); 828c2ecf20Sopenharmony_ci int (*config)(struct rmi_function *fn); 838c2ecf20Sopenharmony_ci int (*reset)(struct rmi_function *fn); 848c2ecf20Sopenharmony_ci irqreturn_t (*attention)(int irq, void *ctx); 858c2ecf20Sopenharmony_ci int (*suspend)(struct rmi_function *fn); 868c2ecf20Sopenharmony_ci int (*resume)(struct rmi_function *fn); 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define to_rmi_function_handler(d) \ 908c2ecf20Sopenharmony_ci container_of(d, struct rmi_function_handler, driver) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciint __must_check __rmi_register_function_handler(struct rmi_function_handler *, 938c2ecf20Sopenharmony_ci struct module *, const char *); 948c2ecf20Sopenharmony_ci#define rmi_register_function_handler(handler) \ 958c2ecf20Sopenharmony_ci __rmi_register_function_handler(handler, THIS_MODULE, KBUILD_MODNAME) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_civoid rmi_unregister_function_handler(struct rmi_function_handler *); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define to_rmi_driver(d) \ 1008c2ecf20Sopenharmony_ci container_of(d, struct rmi_driver, driver) 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define to_rmi_device(d) container_of(d, struct rmi_device, dev) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic inline struct rmi_device_platform_data * 1058c2ecf20Sopenharmony_cirmi_get_platform_data(struct rmi_device *d) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci return &d->xport->pdata; 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cibool rmi_is_physical_device(struct device *dev); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/** 1138c2ecf20Sopenharmony_ci * rmi_reset - reset a RMI4 device 1148c2ecf20Sopenharmony_ci * @d: Pointer to an RMI device 1158c2ecf20Sopenharmony_ci * 1168c2ecf20Sopenharmony_ci * Calls for a reset of each function implemented by a specific device. 1178c2ecf20Sopenharmony_ci * Returns 0 on success or a negative error code. 1188c2ecf20Sopenharmony_ci */ 1198c2ecf20Sopenharmony_cistatic inline int rmi_reset(struct rmi_device *d) 1208c2ecf20Sopenharmony_ci{ 1218c2ecf20Sopenharmony_ci return d->driver->reset_handler(d); 1228c2ecf20Sopenharmony_ci} 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/** 1258c2ecf20Sopenharmony_ci * rmi_read - read a single byte 1268c2ecf20Sopenharmony_ci * @d: Pointer to an RMI device 1278c2ecf20Sopenharmony_ci * @addr: The address to read from 1288c2ecf20Sopenharmony_ci * @buf: The read buffer 1298c2ecf20Sopenharmony_ci * 1308c2ecf20Sopenharmony_ci * Reads a single byte of data using the underlying transport protocol 1318c2ecf20Sopenharmony_ci * into memory pointed by @buf. It returns 0 on success or a negative 1328c2ecf20Sopenharmony_ci * error code. 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistatic inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci return d->xport->ops->read_block(d->xport, addr, buf, 1); 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/** 1408c2ecf20Sopenharmony_ci * rmi_read_block - read a block of bytes 1418c2ecf20Sopenharmony_ci * @d: Pointer to an RMI device 1428c2ecf20Sopenharmony_ci * @addr: The start address to read from 1438c2ecf20Sopenharmony_ci * @buf: The read buffer 1448c2ecf20Sopenharmony_ci * @len: Length of the read buffer 1458c2ecf20Sopenharmony_ci * 1468c2ecf20Sopenharmony_ci * Reads a block of byte data using the underlying transport protocol 1478c2ecf20Sopenharmony_ci * into memory pointed by @buf. It returns 0 on success or a negative 1488c2ecf20Sopenharmony_ci * error code. 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_cistatic inline int rmi_read_block(struct rmi_device *d, u16 addr, 1518c2ecf20Sopenharmony_ci void *buf, size_t len) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci return d->xport->ops->read_block(d->xport, addr, buf, len); 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci/** 1578c2ecf20Sopenharmony_ci * rmi_write - write a single byte 1588c2ecf20Sopenharmony_ci * @d: Pointer to an RMI device 1598c2ecf20Sopenharmony_ci * @addr: The address to write to 1608c2ecf20Sopenharmony_ci * @data: The data to write 1618c2ecf20Sopenharmony_ci * 1628c2ecf20Sopenharmony_ci * Writes a single byte using the underlying transport protocol. It 1638c2ecf20Sopenharmony_ci * returns zero on success or a negative error code. 1648c2ecf20Sopenharmony_ci */ 1658c2ecf20Sopenharmony_cistatic inline int rmi_write(struct rmi_device *d, u16 addr, u8 data) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci return d->xport->ops->write_block(d->xport, addr, &data, 1); 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/** 1718c2ecf20Sopenharmony_ci * rmi_write_block - write a block of bytes 1728c2ecf20Sopenharmony_ci * @d: Pointer to an RMI device 1738c2ecf20Sopenharmony_ci * @addr: The start address to write to 1748c2ecf20Sopenharmony_ci * @buf: The write buffer 1758c2ecf20Sopenharmony_ci * @len: Length of the write buffer 1768c2ecf20Sopenharmony_ci * 1778c2ecf20Sopenharmony_ci * Writes a block of byte data from buf using the underlaying transport 1788c2ecf20Sopenharmony_ci * protocol. It returns the amount of bytes written or a negative error code. 1798c2ecf20Sopenharmony_ci */ 1808c2ecf20Sopenharmony_cistatic inline int rmi_write_block(struct rmi_device *d, u16 addr, 1818c2ecf20Sopenharmony_ci const void *buf, size_t len) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci return d->xport->ops->write_block(d->xport, addr, buf, len); 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ciint rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data)); 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ciextern struct bus_type rmi_bus_type; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciint rmi_of_property_read_u32(struct device *dev, u32 *result, 1918c2ecf20Sopenharmony_ci const char *prop, bool optional); 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define RMI_DEBUG_CORE BIT(0) 1948c2ecf20Sopenharmony_ci#define RMI_DEBUG_XPORT BIT(1) 1958c2ecf20Sopenharmony_ci#define RMI_DEBUG_FN BIT(2) 1968c2ecf20Sopenharmony_ci#define RMI_DEBUG_2D_SENSOR BIT(3) 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_civoid rmi_dbg(int flags, struct device *dev, const char *fmt, ...); 1998c2ecf20Sopenharmony_ci#endif 200