Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2011-2016 Synaptics Incorporated
0004  * Copyright (c) 2011 Unixphere
0005  */
0006 
0007 #ifndef _RMI_BUS_H
0008 #define _RMI_BUS_H
0009 
0010 #include <linux/rmi.h>
0011 
0012 struct rmi_device;
0013 
0014 /*
0015  * The interrupt source count in the function descriptor can represent up to
0016  * 6 interrupt sources in the normal manner.
0017  */
0018 #define RMI_FN_MAX_IRQS 6
0019 
0020 /**
0021  * struct rmi_function - represents the implementation of an RMI4
0022  * function for a particular device (basically, a driver for that RMI4 function)
0023  *
0024  * @fd: The function descriptor of the RMI function
0025  * @rmi_dev: Pointer to the RMI device associated with this function container
0026  * @dev: The device associated with this particular function.
0027  *
0028  * @num_of_irqs: The number of irqs needed by this function
0029  * @irq_pos: The position in the irq bitfield this function holds
0030  * @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN
0031  * interrupt handling.
0032  * @irqs: assigned virq numbers (up to num_of_irqs)
0033  *
0034  * @node: entry in device's list of functions
0035  */
0036 struct rmi_function {
0037     struct rmi_function_descriptor fd;
0038     struct rmi_device *rmi_dev;
0039     struct device dev;
0040     struct list_head node;
0041 
0042     unsigned int num_of_irqs;
0043     int irq[RMI_FN_MAX_IRQS];
0044     unsigned int irq_pos;
0045     unsigned long irq_mask[];
0046 };
0047 
0048 #define to_rmi_function(d)  container_of(d, struct rmi_function, dev)
0049 
0050 bool rmi_is_function_device(struct device *dev);
0051 
0052 int __must_check rmi_register_function(struct rmi_function *);
0053 void rmi_unregister_function(struct rmi_function *);
0054 
0055 /**
0056  * struct rmi_function_handler - driver routines for a particular RMI function.
0057  *
0058  * @func: The RMI function number
0059  * @reset: Called when a reset of the touch sensor is detected.  The routine
0060  * should perform any out-of-the-ordinary reset handling that might be
0061  * necessary.  Restoring of touch sensor configuration registers should be
0062  * handled in the config() callback, below.
0063  * @config: Called when the function container is first initialized, and
0064  * after a reset is detected.  This routine should write any necessary
0065  * configuration settings to the device.
0066  * @attention: Called when the IRQ(s) for the function are set by the touch
0067  * sensor.
0068  * @suspend: Should perform any required operations to suspend the particular
0069  * function.
0070  * @resume: Should perform any required operations to resume the particular
0071  * function.
0072  *
0073  * All callbacks are expected to return 0 on success, error code on failure.
0074  */
0075 struct rmi_function_handler {
0076     struct device_driver driver;
0077 
0078     u8 func;
0079 
0080     int (*probe)(struct rmi_function *fn);
0081     void (*remove)(struct rmi_function *fn);
0082     int (*config)(struct rmi_function *fn);
0083     int (*reset)(struct rmi_function *fn);
0084     irqreturn_t (*attention)(int irq, void *ctx);
0085     int (*suspend)(struct rmi_function *fn);
0086     int (*resume)(struct rmi_function *fn);
0087 };
0088 
0089 #define to_rmi_function_handler(d) \
0090         container_of(d, struct rmi_function_handler, driver)
0091 
0092 int __must_check __rmi_register_function_handler(struct rmi_function_handler *,
0093                          struct module *, const char *);
0094 #define rmi_register_function_handler(handler) \
0095     __rmi_register_function_handler(handler, THIS_MODULE, KBUILD_MODNAME)
0096 
0097 void rmi_unregister_function_handler(struct rmi_function_handler *);
0098 
0099 #define to_rmi_driver(d) \
0100     container_of(d, struct rmi_driver, driver)
0101 
0102 #define to_rmi_device(d) container_of(d, struct rmi_device, dev)
0103 
0104 static inline struct rmi_device_platform_data *
0105 rmi_get_platform_data(struct rmi_device *d)
0106 {
0107     return &d->xport->pdata;
0108 }
0109 
0110 bool rmi_is_physical_device(struct device *dev);
0111 
0112 /**
0113  * rmi_reset - reset a RMI4 device
0114  * @d: Pointer to an RMI device
0115  *
0116  * Calls for a reset of each function implemented by a specific device.
0117  * Returns 0 on success or a negative error code.
0118  */
0119 static inline int rmi_reset(struct rmi_device *d)
0120 {
0121     return d->driver->reset_handler(d);
0122 }
0123 
0124 /**
0125  * rmi_read - read a single byte
0126  * @d: Pointer to an RMI device
0127  * @addr: The address to read from
0128  * @buf: The read buffer
0129  *
0130  * Reads a single byte of data using the underlying transport protocol
0131  * into memory pointed by @buf. It returns 0 on success or a negative
0132  * error code.
0133  */
0134 static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf)
0135 {
0136     return d->xport->ops->read_block(d->xport, addr, buf, 1);
0137 }
0138 
0139 /**
0140  * rmi_read_block - read a block of bytes
0141  * @d: Pointer to an RMI device
0142  * @addr: The start address to read from
0143  * @buf: The read buffer
0144  * @len: Length of the read buffer
0145  *
0146  * Reads a block of byte data using the underlying transport protocol
0147  * into memory pointed by @buf. It returns 0 on success or a negative
0148  * error code.
0149  */
0150 static inline int rmi_read_block(struct rmi_device *d, u16 addr,
0151                  void *buf, size_t len)
0152 {
0153     return d->xport->ops->read_block(d->xport, addr, buf, len);
0154 }
0155 
0156 /**
0157  * rmi_write - write a single byte
0158  * @d: Pointer to an RMI device
0159  * @addr: The address to write to
0160  * @data: The data to write
0161  *
0162  * Writes a single byte using the underlying transport protocol. It
0163  * returns zero on success or a negative error code.
0164  */
0165 static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data)
0166 {
0167     return d->xport->ops->write_block(d->xport, addr, &data, 1);
0168 }
0169 
0170 /**
0171  * rmi_write_block - write a block of bytes
0172  * @d: Pointer to an RMI device
0173  * @addr: The start address to write to
0174  * @buf: The write buffer
0175  * @len: Length of the write buffer
0176  *
0177  * Writes a block of byte data from buf using the underlaying transport
0178  * protocol.  It returns the amount of bytes written or a negative error code.
0179  */
0180 static inline int rmi_write_block(struct rmi_device *d, u16 addr,
0181                   const void *buf, size_t len)
0182 {
0183     return d->xport->ops->write_block(d->xport, addr, buf, len);
0184 }
0185 
0186 int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
0187 
0188 extern struct bus_type rmi_bus_type;
0189 
0190 int rmi_of_property_read_u32(struct device *dev, u32 *result,
0191                 const char *prop, bool optional);
0192 
0193 #define RMI_DEBUG_CORE          BIT(0)
0194 #define RMI_DEBUG_XPORT         BIT(1)
0195 #define RMI_DEBUG_FN            BIT(2)
0196 #define RMI_DEBUG_2D_SENSOR     BIT(3)
0197 
0198 void rmi_dbg(int flags, struct device *dev, const char *fmt, ...);
0199 #endif