162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2011-2016 Synaptics Incorporated 462306a36Sopenharmony_ci * Copyright (c) 2011 Unixphere 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef _RMI_BUS_H 862306a36Sopenharmony_ci#define _RMI_BUS_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/rmi.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_cistruct rmi_device; 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* 1562306a36Sopenharmony_ci * The interrupt source count in the function descriptor can represent up to 1662306a36Sopenharmony_ci * 6 interrupt sources in the normal manner. 1762306a36Sopenharmony_ci */ 1862306a36Sopenharmony_ci#define RMI_FN_MAX_IRQS 6 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/** 2162306a36Sopenharmony_ci * struct rmi_function - represents the implementation of an RMI4 2262306a36Sopenharmony_ci * function for a particular device (basically, a driver for that RMI4 function) 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * @fd: The function descriptor of the RMI function 2562306a36Sopenharmony_ci * @rmi_dev: Pointer to the RMI device associated with this function container 2662306a36Sopenharmony_ci * @dev: The device associated with this particular function. 2762306a36Sopenharmony_ci * 2862306a36Sopenharmony_ci * @num_of_irqs: The number of irqs needed by this function 2962306a36Sopenharmony_ci * @irq_pos: The position in the irq bitfield this function holds 3062306a36Sopenharmony_ci * @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN 3162306a36Sopenharmony_ci * interrupt handling. 3262306a36Sopenharmony_ci * @irqs: assigned virq numbers (up to num_of_irqs) 3362306a36Sopenharmony_ci * 3462306a36Sopenharmony_ci * @node: entry in device's list of functions 3562306a36Sopenharmony_ci */ 3662306a36Sopenharmony_cistruct rmi_function { 3762306a36Sopenharmony_ci struct rmi_function_descriptor fd; 3862306a36Sopenharmony_ci struct rmi_device *rmi_dev; 3962306a36Sopenharmony_ci struct device dev; 4062306a36Sopenharmony_ci struct list_head node; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci unsigned int num_of_irqs; 4362306a36Sopenharmony_ci int irq[RMI_FN_MAX_IRQS]; 4462306a36Sopenharmony_ci unsigned int irq_pos; 4562306a36Sopenharmony_ci unsigned long irq_mask[]; 4662306a36Sopenharmony_ci}; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#define to_rmi_function(d) container_of(d, struct rmi_function, dev) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_cibool rmi_is_function_device(struct device *dev); 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciint __must_check rmi_register_function(struct rmi_function *); 5362306a36Sopenharmony_civoid rmi_unregister_function(struct rmi_function *); 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/** 5662306a36Sopenharmony_ci * struct rmi_function_handler - driver routines for a particular RMI function. 5762306a36Sopenharmony_ci * 5862306a36Sopenharmony_ci * @func: The RMI function number 5962306a36Sopenharmony_ci * @reset: Called when a reset of the touch sensor is detected. The routine 6062306a36Sopenharmony_ci * should perform any out-of-the-ordinary reset handling that might be 6162306a36Sopenharmony_ci * necessary. Restoring of touch sensor configuration registers should be 6262306a36Sopenharmony_ci * handled in the config() callback, below. 6362306a36Sopenharmony_ci * @config: Called when the function container is first initialized, and 6462306a36Sopenharmony_ci * after a reset is detected. This routine should write any necessary 6562306a36Sopenharmony_ci * configuration settings to the device. 6662306a36Sopenharmony_ci * @attention: Called when the IRQ(s) for the function are set by the touch 6762306a36Sopenharmony_ci * sensor. 6862306a36Sopenharmony_ci * @suspend: Should perform any required operations to suspend the particular 6962306a36Sopenharmony_ci * function. 7062306a36Sopenharmony_ci * @resume: Should perform any required operations to resume the particular 7162306a36Sopenharmony_ci * function. 7262306a36Sopenharmony_ci * 7362306a36Sopenharmony_ci * All callbacks are expected to return 0 on success, error code on failure. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_cistruct rmi_function_handler { 7662306a36Sopenharmony_ci struct device_driver driver; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci u8 func; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci int (*probe)(struct rmi_function *fn); 8162306a36Sopenharmony_ci void (*remove)(struct rmi_function *fn); 8262306a36Sopenharmony_ci int (*config)(struct rmi_function *fn); 8362306a36Sopenharmony_ci int (*reset)(struct rmi_function *fn); 8462306a36Sopenharmony_ci irqreturn_t (*attention)(int irq, void *ctx); 8562306a36Sopenharmony_ci int (*suspend)(struct rmi_function *fn); 8662306a36Sopenharmony_ci int (*resume)(struct rmi_function *fn); 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci#define to_rmi_function_handler(d) \ 9062306a36Sopenharmony_ci container_of(d, struct rmi_function_handler, driver) 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciint __must_check __rmi_register_function_handler(struct rmi_function_handler *, 9362306a36Sopenharmony_ci struct module *, const char *); 9462306a36Sopenharmony_ci#define rmi_register_function_handler(handler) \ 9562306a36Sopenharmony_ci __rmi_register_function_handler(handler, THIS_MODULE, KBUILD_MODNAME) 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_civoid rmi_unregister_function_handler(struct rmi_function_handler *); 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#define to_rmi_driver(d) \ 10062306a36Sopenharmony_ci container_of(d, struct rmi_driver, driver) 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci#define to_rmi_device(d) container_of(d, struct rmi_device, dev) 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_cistatic inline struct rmi_device_platform_data * 10562306a36Sopenharmony_cirmi_get_platform_data(struct rmi_device *d) 10662306a36Sopenharmony_ci{ 10762306a36Sopenharmony_ci return &d->xport->pdata; 10862306a36Sopenharmony_ci} 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cibool rmi_is_physical_device(struct device *dev); 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci/** 11362306a36Sopenharmony_ci * rmi_reset - reset a RMI4 device 11462306a36Sopenharmony_ci * @d: Pointer to an RMI device 11562306a36Sopenharmony_ci * 11662306a36Sopenharmony_ci * Calls for a reset of each function implemented by a specific device. 11762306a36Sopenharmony_ci * Returns 0 on success or a negative error code. 11862306a36Sopenharmony_ci */ 11962306a36Sopenharmony_cistatic inline int rmi_reset(struct rmi_device *d) 12062306a36Sopenharmony_ci{ 12162306a36Sopenharmony_ci return d->driver->reset_handler(d); 12262306a36Sopenharmony_ci} 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci/** 12562306a36Sopenharmony_ci * rmi_read - read a single byte 12662306a36Sopenharmony_ci * @d: Pointer to an RMI device 12762306a36Sopenharmony_ci * @addr: The address to read from 12862306a36Sopenharmony_ci * @buf: The read buffer 12962306a36Sopenharmony_ci * 13062306a36Sopenharmony_ci * Reads a single byte of data using the underlying transport protocol 13162306a36Sopenharmony_ci * into memory pointed by @buf. It returns 0 on success or a negative 13262306a36Sopenharmony_ci * error code. 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_cistatic inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf) 13562306a36Sopenharmony_ci{ 13662306a36Sopenharmony_ci return d->xport->ops->read_block(d->xport, addr, buf, 1); 13762306a36Sopenharmony_ci} 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci/** 14062306a36Sopenharmony_ci * rmi_read_block - read a block of bytes 14162306a36Sopenharmony_ci * @d: Pointer to an RMI device 14262306a36Sopenharmony_ci * @addr: The start address to read from 14362306a36Sopenharmony_ci * @buf: The read buffer 14462306a36Sopenharmony_ci * @len: Length of the read buffer 14562306a36Sopenharmony_ci * 14662306a36Sopenharmony_ci * Reads a block of byte data using the underlying transport protocol 14762306a36Sopenharmony_ci * into memory pointed by @buf. It returns 0 on success or a negative 14862306a36Sopenharmony_ci * error code. 14962306a36Sopenharmony_ci */ 15062306a36Sopenharmony_cistatic inline int rmi_read_block(struct rmi_device *d, u16 addr, 15162306a36Sopenharmony_ci void *buf, size_t len) 15262306a36Sopenharmony_ci{ 15362306a36Sopenharmony_ci return d->xport->ops->read_block(d->xport, addr, buf, len); 15462306a36Sopenharmony_ci} 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/** 15762306a36Sopenharmony_ci * rmi_write - write a single byte 15862306a36Sopenharmony_ci * @d: Pointer to an RMI device 15962306a36Sopenharmony_ci * @addr: The address to write to 16062306a36Sopenharmony_ci * @data: The data to write 16162306a36Sopenharmony_ci * 16262306a36Sopenharmony_ci * Writes a single byte using the underlying transport protocol. It 16362306a36Sopenharmony_ci * returns zero on success or a negative error code. 16462306a36Sopenharmony_ci */ 16562306a36Sopenharmony_cistatic inline int rmi_write(struct rmi_device *d, u16 addr, u8 data) 16662306a36Sopenharmony_ci{ 16762306a36Sopenharmony_ci return d->xport->ops->write_block(d->xport, addr, &data, 1); 16862306a36Sopenharmony_ci} 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci/** 17162306a36Sopenharmony_ci * rmi_write_block - write a block of bytes 17262306a36Sopenharmony_ci * @d: Pointer to an RMI device 17362306a36Sopenharmony_ci * @addr: The start address to write to 17462306a36Sopenharmony_ci * @buf: The write buffer 17562306a36Sopenharmony_ci * @len: Length of the write buffer 17662306a36Sopenharmony_ci * 17762306a36Sopenharmony_ci * Writes a block of byte data from buf using the underlaying transport 17862306a36Sopenharmony_ci * protocol. It returns the amount of bytes written or a negative error code. 17962306a36Sopenharmony_ci */ 18062306a36Sopenharmony_cistatic inline int rmi_write_block(struct rmi_device *d, u16 addr, 18162306a36Sopenharmony_ci const void *buf, size_t len) 18262306a36Sopenharmony_ci{ 18362306a36Sopenharmony_ci return d->xport->ops->write_block(d->xport, addr, buf, len); 18462306a36Sopenharmony_ci} 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ciint rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data)); 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ciextern struct bus_type rmi_bus_type; 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ciint rmi_of_property_read_u32(struct device *dev, u32 *result, 19162306a36Sopenharmony_ci const char *prop, bool optional); 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define RMI_DEBUG_CORE BIT(0) 19462306a36Sopenharmony_ci#define RMI_DEBUG_XPORT BIT(1) 19562306a36Sopenharmony_ci#define RMI_DEBUG_FN BIT(2) 19662306a36Sopenharmony_ci#define RMI_DEBUG_2D_SENSOR BIT(3) 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_civoid rmi_dbg(int flags, struct device *dev, const char *fmt, ...); 19962306a36Sopenharmony_ci#endif 200