1
0
Fork 0

Input: synaptics-rmi4 - add support for Synaptics RMI4 devices

Synaptics uses the Register Mapped Interface (RMI) protocol as a
communications interface for their devices. This driver adds the core
functionality needed to interface with RMI4 devices.

RMI devices can be connected to the host via several transport protocols
and can supports a wide variety of functionality defined by RMI functions.
Support for transport protocols and RMI functions are implemented in
individual drivers. The RMI4 core driver uses a bus architecture to
facilitate the various combinations of transport and function drivers
needed by a particular device.

Signed-off-by: Andrew Duggan <aduggan@synaptics.com>
Signed-off-by: Christopher Heiny <cheiny@synaptics.com>
Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
hifive-unleashed-5.1
Andrew Duggan 2016-03-10 15:35:49 -08:00 committed by Dmitry Torokhov
parent afd2ff9b7e
commit 2b6a321da9
11 changed files with 2491 additions and 0 deletions

View File

@ -201,6 +201,8 @@ source "drivers/input/touchscreen/Kconfig"
source "drivers/input/misc/Kconfig"
source "drivers/input/rmi4/Kconfig"
endif
menu "Hardware I/O ports"

View File

@ -26,3 +26,5 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
obj-$(CONFIG_INPUT_MISC) += misc/
obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
obj-$(CONFIG_RMI4_CORE) += rmi4/

View File

@ -0,0 +1,10 @@
#
# RMI4 configuration
#
config RMI4_CORE
tristate "Synaptics RMI4 bus support"
help
Say Y here if you want to support the Synaptics RMI4 bus. This is
required for all RMI4 device support.
If unsure, say Y.

View File

@ -0,0 +1,2 @@
obj-$(CONFIG_RMI4_CORE) += rmi_core.o
rmi_core-y := rmi_bus.o rmi_driver.o rmi_f01.o

View File

@ -0,0 +1,375 @@
/*
* Copyright (c) 2011-2016 Synaptics Incorporated
* Copyright (c) 2011 Unixphere
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/kconfig.h>
#include <linux/list.h>
#include <linux/pm.h>
#include <linux/rmi.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/of.h>
#include "rmi_bus.h"
#include "rmi_driver.h"
static int debug_flags;
module_param(debug_flags, int, 0644);
MODULE_PARM_DESC(debug_flags, "control debugging information");
void rmi_dbg(int flags, struct device *dev, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
if (flags & debug_flags) {
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
dev_printk(KERN_DEBUG, dev, "%pV", &vaf);
va_end(args);
}
}
EXPORT_SYMBOL_GPL(rmi_dbg);
/*
* RMI Physical devices
*
* Physical RMI device consists of several functions serving particular
* purpose. For example F11 is a 2D touch sensor while F01 is a generic
* function present in every RMI device.
*/
static void rmi_release_device(struct device *dev)
{
struct rmi_device *rmi_dev = to_rmi_device(dev);
kfree(rmi_dev);
}
static struct device_type rmi_device_type = {
.name = "rmi4_sensor",
.release = rmi_release_device,
};
bool rmi_is_physical_device(struct device *dev)
{
return dev->type == &rmi_device_type;
}
/**
* rmi_register_transport_device - register a transport device connection
* on the RMI bus. Transport drivers provide communication from the devices
* on a bus (such as SPI, I2C, and so on) to the RMI4 sensor.
*
* @xport: the transport device to register
*/
int rmi_register_transport_device(struct rmi_transport_dev *xport)
{
static atomic_t transport_device_count = ATOMIC_INIT(0);
struct rmi_device *rmi_dev;
int error;
rmi_dev = kzalloc(sizeof(struct rmi_device), GFP_KERNEL);
if (!rmi_dev)
return -ENOMEM;
device_initialize(&rmi_dev->dev);
rmi_dev->xport = xport;
rmi_dev->number = atomic_inc_return(&transport_device_count) - 1;
dev_set_name(&rmi_dev->dev, "rmi4-%02d", rmi_dev->number);
rmi_dev->dev.bus = &rmi_bus_type;
rmi_dev->dev.type = &rmi_device_type;
xport->rmi_dev = rmi_dev;
error = device_add(&rmi_dev->dev);
if (error)
goto err_put_device;
rmi_dbg(RMI_DEBUG_CORE, xport->dev,
"%s: Registered %s as %s.\n", __func__,
dev_name(rmi_dev->xport->dev), dev_name(&rmi_dev->dev));
return 0;
err_put_device:
put_device(&rmi_dev->dev);
return error;
}
EXPORT_SYMBOL_GPL(rmi_register_transport_device);
/**
* rmi_unregister_transport_device - unregister a transport device connection
* @xport: the transport driver to unregister
*
*/
void rmi_unregister_transport_device(struct rmi_transport_dev *xport)
{
struct rmi_device *rmi_dev = xport->rmi_dev;
device_del(&rmi_dev->dev);
put_device(&rmi_dev->dev);
}
EXPORT_SYMBOL(rmi_unregister_transport_device);
/* Function specific stuff */
static void rmi_release_function(struct device *dev)
{
struct rmi_function *fn = to_rmi_function(dev);
kfree(fn);
}
static struct device_type rmi_function_type = {
.name = "rmi4_function",
.release = rmi_release_function,
};
bool rmi_is_function_device(struct device *dev)
{
return dev->type == &rmi_function_type;
}
static int rmi_function_match(struct device *dev, struct device_driver *drv)
{
struct rmi_function_handler *handler = to_rmi_function_handler(drv);
struct rmi_function *fn = to_rmi_function(dev);
return fn->fd.function_number == handler->func;
}
static int rmi_function_probe(struct device *dev)
{
struct rmi_function *fn = to_rmi_function(dev);
struct rmi_function_handler *handler =
to_rmi_function_handler(dev->driver);
int error;
if (handler->probe) {
error = handler->probe(fn);
return error;
}
return 0;
}
static int rmi_function_remove(struct device *dev)
{
struct rmi_function *fn = to_rmi_function(dev);
struct rmi_function_handler *handler =
to_rmi_function_handler(dev->driver);
if (handler->remove)
handler->remove(fn);
return 0;
}
int rmi_register_function(struct rmi_function *fn)
{
struct rmi_device *rmi_dev = fn->rmi_dev;
int error;
device_initialize(&fn->dev);
dev_set_name(&fn->dev, "%s.fn%02x",
dev_name(&rmi_dev->dev), fn->fd.function_number);
fn->dev.parent = &rmi_dev->dev;
fn->dev.type = &rmi_function_type;
fn->dev.bus = &rmi_bus_type;
error = device_add(&fn->dev);
if (error) {
dev_err(&rmi_dev->dev,
"Failed device_register function device %s\n",
dev_name(&fn->dev));
goto err_put_device;
}
rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev, "Registered F%02X.\n",
fn->fd.function_number);
return 0;
err_put_device:
put_device(&fn->dev);
return error;
}
void rmi_unregister_function(struct rmi_function *fn)
{
device_del(&fn->dev);
if (fn->dev.of_node)
of_node_put(fn->dev.of_node);
put_device(&fn->dev);
}
/**
* rmi_register_function_handler - register a handler for an RMI function
* @handler: RMI handler that should be registered.
* @module: pointer to module that implements the handler
* @mod_name: name of the module implementing the handler
*
* This function performs additional setup of RMI function handler and
* registers it with the RMI core so that it can be bound to
* RMI function devices.
*/
int __rmi_register_function_handler(struct rmi_function_handler *handler,
struct module *owner,
const char *mod_name)
{
struct device_driver *driver = &handler->driver;
int error;
driver->bus = &rmi_bus_type;
driver->owner = owner;
driver->mod_name = mod_name;
driver->probe = rmi_function_probe;
driver->remove = rmi_function_remove;
error = driver_register(&handler->driver);
if (error) {
pr_err("driver_register() failed for %s, error: %d\n",
handler->driver.name, error);
return error;
}
return 0;
}
EXPORT_SYMBOL_GPL(__rmi_register_function_handler);
/**
* rmi_unregister_function_handler - unregister given RMI function handler
* @handler: RMI handler that should be unregistered.
*
* This function unregisters given function handler from RMI core which
* causes it to be unbound from the function devices.
*/
void rmi_unregister_function_handler(struct rmi_function_handler *handler)
{
driver_unregister(&handler->driver);
}
EXPORT_SYMBOL_GPL(rmi_unregister_function_handler);
/* Bus specific stuff */
static int rmi_bus_match(struct device *dev, struct device_driver *drv)
{
bool physical = rmi_is_physical_device(dev);
/* First see if types are not compatible */
if (physical != rmi_is_physical_driver(drv))
return 0;
return physical || rmi_function_match(dev, drv);
}
struct bus_type rmi_bus_type = {
.match = rmi_bus_match,
.name = "rmi4",
};
static struct rmi_function_handler *fn_handlers[] = {
&rmi_f01_handler,
};
static void __rmi_unregister_function_handlers(int start_idx)
{
int i;
for (i = start_idx; i >= 0; i--)
rmi_unregister_function_handler(fn_handlers[i]);
}
static void rmi_unregister_function_handlers(void)
{
__rmi_unregister_function_handlers(ARRAY_SIZE(fn_handlers) - 1);
}
static int rmi_register_function_handlers(void)
{
int ret;
int i;
for (i = 0; i < ARRAY_SIZE(fn_handlers); i++) {
ret = rmi_register_function_handler(fn_handlers[i]);
if (ret) {
pr_err("%s: error registering the RMI F%02x handler: %d\n",
__func__, fn_handlers[i]->func, ret);
goto err_unregister_function_handlers;
}
}
return 0;
err_unregister_function_handlers:
__rmi_unregister_function_handlers(i - 1);
return ret;
}
static int __init rmi_bus_init(void)
{
int error;
error = bus_register(&rmi_bus_type);
if (error) {
pr_err("%s: error registering the RMI bus: %d\n",
__func__, error);
return error;
}
error = rmi_register_function_handlers();
if (error)
goto err_unregister_bus;
error = rmi_register_physical_driver();
if (error) {
pr_err("%s: error registering the RMI physical driver: %d\n",
__func__, error);
goto err_unregister_bus;
}
return 0;
err_unregister_bus:
bus_unregister(&rmi_bus_type);
return error;
}
module_init(rmi_bus_init);
static void __exit rmi_bus_exit(void)
{
/*
* We should only ever get here if all drivers are unloaded, so
* all we have to do at this point is unregister ourselves.
*/
rmi_unregister_physical_driver();
rmi_unregister_function_handlers();
bus_unregister(&rmi_bus_type);
}
module_exit(rmi_bus_exit);
MODULE_AUTHOR("Christopher Heiny <cheiny@synaptics.com");
MODULE_AUTHOR("Andrew Duggan <aduggan@synaptics.com");
MODULE_DESCRIPTION("RMI bus");
MODULE_LICENSE("GPL");
MODULE_VERSION(RMI_DRIVER_VERSION);

View File

@ -0,0 +1,186 @@
/*
* Copyright (c) 2011-2016 Synaptics Incorporated
* Copyright (c) 2011 Unixphere
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _RMI_BUS_H
#define _RMI_BUS_H
#include <linux/rmi.h>
struct rmi_device;
/**
* struct rmi_function - represents the implementation of an RMI4
* function for a particular device (basically, a driver for that RMI4 function)
*
* @fd: The function descriptor of the RMI function
* @rmi_dev: Pointer to the RMI device associated with this function container
* @dev: The device associated with this particular function.
*
* @num_of_irqs: The number of irqs needed by this function
* @irq_pos: The position in the irq bitfield this function holds
* @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN
* interrupt handling.
*
* @node: entry in device's list of functions
*/
struct rmi_function {
struct rmi_function_descriptor fd;
struct rmi_device *rmi_dev;
struct device dev;
struct list_head node;
unsigned int num_of_irqs;
unsigned int irq_pos;
unsigned long irq_mask[];
};
#define to_rmi_function(d) container_of(d, struct rmi_function, dev)
bool rmi_is_function_device(struct device *dev);
int __must_check rmi_register_function(struct rmi_function *);
void rmi_unregister_function(struct rmi_function *);
/**
* struct rmi_function_handler - driver routines for a particular RMI function.
*
* @func: The RMI function number
* @reset: Called when a reset of the touch sensor is detected. The routine
* should perform any out-of-the-ordinary reset handling that might be
* necessary. Restoring of touch sensor configuration registers should be
* handled in the config() callback, below.
* @config: Called when the function container is first initialized, and
* after a reset is detected. This routine should write any necessary
* configuration settings to the device.
* @attention: Called when the IRQ(s) for the function are set by the touch
* sensor.
* @suspend: Should perform any required operations to suspend the particular
* function.
* @resume: Should perform any required operations to resume the particular
* function.
*
* All callbacks are expected to return 0 on success, error code on failure.
*/
struct rmi_function_handler {
struct device_driver driver;
u8 func;
int (*probe)(struct rmi_function *fn);
void (*remove)(struct rmi_function *fn);
int (*config)(struct rmi_function *fn);
int (*reset)(struct rmi_function *fn);
int (*attention)(struct rmi_function *fn, unsigned long *irq_bits);
int (*suspend)(struct rmi_function *fn);
int (*resume)(struct rmi_function *fn);
};
#define to_rmi_function_handler(d) \
container_of(d, struct rmi_function_handler, driver)
int __must_check __rmi_register_function_handler(struct rmi_function_handler *,
struct module *, const char *);
#define rmi_register_function_handler(handler) \
__rmi_register_function_handler(handler, THIS_MODULE, KBUILD_MODNAME)
void rmi_unregister_function_handler(struct rmi_function_handler *);
#define to_rmi_driver(d) \
container_of(d, struct rmi_driver, driver)
#define to_rmi_device(d) container_of(d, struct rmi_device, dev)
static inline struct rmi_device_platform_data *
rmi_get_platform_data(struct rmi_device *d)
{
return &d->xport->pdata;
}
bool rmi_is_physical_device(struct device *dev);
/**
* rmi_read - read a single byte
* @d: Pointer to an RMI device
* @addr: The address to read from
* @buf: The read buffer
*
* Reads a single byte of data using the underlying transport protocol
* into memory pointed by @buf. It returns 0 on success or a negative
* error code.
*/
static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf)
{
return d->xport->ops->read_block(d->xport, addr, buf, 1);
}
/**
* rmi_read_block - read a block of bytes
* @d: Pointer to an RMI device
* @addr: The start address to read from
* @buf: The read buffer
* @len: Length of the read buffer
*
* Reads a block of byte data using the underlying transport protocol
* into memory pointed by @buf. It returns 0 on success or a negative
* error code.
*/
static inline int rmi_read_block(struct rmi_device *d, u16 addr,
void *buf, size_t len)
{
return d->xport->ops->read_block(d->xport, addr, buf, len);
}
/**
* rmi_write - write a single byte
* @d: Pointer to an RMI device
* @addr: The address to write to
* @data: The data to write
*
* Writes a single byte using the underlying transport protocol. It
* returns zero on success or a negative error code.
*/
static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data)
{
return d->xport->ops->write_block(d->xport, addr, &data, 1);
}
/**
* rmi_write_block - write a block of bytes
* @d: Pointer to an RMI device
* @addr: The start address to write to
* @buf: The write buffer
* @len: Length of the write buffer
*
* Writes a block of byte data from buf using the underlaying transport
* protocol. It returns the amount of bytes written or a negative error code.
*/
static inline int rmi_write_block(struct rmi_device *d, u16 addr,
const void *buf, size_t len)
{
return d->xport->ops->write_block(d->xport, addr, buf, len);
}
int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
extern struct bus_type rmi_bus_type;
int rmi_of_property_read_u32(struct device *dev, u32 *result,
const char *prop, bool optional);
int rmi_of_property_read_u16(struct device *dev, u16 *result,
const char *prop, bool optional);
int rmi_of_property_read_u8(struct device *dev, u8 *result,
const char *prop, bool optional);
#define RMI_DEBUG_CORE BIT(0)
#define RMI_DEBUG_XPORT BIT(1)
#define RMI_DEBUG_FN BIT(2)
#define RMI_DEBUG_2D_SENSOR BIT(3)
void rmi_dbg(int flags, struct device *dev, const char *fmt, ...);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2011-2016 Synaptics Incorporated
* Copyright (c) 2011 Unixphere
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _RMI_DRIVER_H
#define _RMI_DRIVER_H
#include <linux/ctype.h>
#include <linux/hrtimer.h>
#include <linux/ktime.h>
#include <linux/input.h>
#include "rmi_bus.h"
#define RMI_DRIVER_VERSION "2.0"
#define SYNAPTICS_INPUT_DEVICE_NAME "Synaptics RMI4 Touch Sensor"
#define SYNAPTICS_VENDOR_ID 0x06cb
#define GROUP(_attrs) { \
.attrs = _attrs, \
}
#define PDT_PROPERTIES_LOCATION 0x00EF
#define BSR_LOCATION 0x00FE
#define RMI_PDT_PROPS_HAS_BSR 0x02
#define NAME_BUFFER_SIZE 256
#define RMI_PDT_ENTRY_SIZE 6
#define RMI_PDT_FUNCTION_VERSION_MASK 0x60
#define RMI_PDT_INT_SOURCE_COUNT_MASK 0x07
#define PDT_START_SCAN_LOCATION 0x00e9
#define PDT_END_SCAN_LOCATION 0x0005
#define RMI4_END_OF_PDT(id) ((id) == 0x00 || (id) == 0xff)
struct pdt_entry {
u16 page_start;
u8 query_base_addr;
u8 command_base_addr;
u8 control_base_addr;
u8 data_base_addr;
u8 interrupt_source_count;
u8 function_version;
u8 function_number;
};
int rmi_read_pdt_entry(struct rmi_device *rmi_dev, struct pdt_entry *entry,
u16 pdt_address);
#define RMI_REG_DESC_PRESENSE_BITS (32 * BITS_PER_BYTE)
#define RMI_REG_DESC_SUBPACKET_BITS (37 * BITS_PER_BYTE)
/* describes a single packet register */
struct rmi_register_desc_item {
u16 reg;
unsigned long reg_size;
u8 num_subpackets;
unsigned long subpacket_map[BITS_TO_LONGS(
RMI_REG_DESC_SUBPACKET_BITS)];
};
/*
* describes the packet registers for a particular type
* (ie query, control, data)
*/
struct rmi_register_descriptor {
unsigned long struct_size;
unsigned long presense_map[BITS_TO_LONGS(RMI_REG_DESC_PRESENSE_BITS)];
u8 num_registers;
struct rmi_register_desc_item *registers;
};
int rmi_read_register_desc(struct rmi_device *d, u16 addr,
struct rmi_register_descriptor *rdesc);
const struct rmi_register_desc_item *rmi_get_register_desc_item(
struct rmi_register_descriptor *rdesc, u16 reg);
/*
* Calculate the total size of all of the registers described in the
* descriptor.
*/
size_t rmi_register_desc_calc_size(struct rmi_register_descriptor *rdesc);
int rmi_register_desc_calc_reg_offset(
struct rmi_register_descriptor *rdesc, u16 reg);
bool rmi_register_desc_has_subpacket(const struct rmi_register_desc_item *item,
u8 subpacket);
bool rmi_is_physical_driver(struct device_driver *);
int rmi_register_physical_driver(void);
void rmi_unregister_physical_driver(void);
char *rmi_f01_get_product_ID(struct rmi_function *fn);
extern struct rmi_function_handler rmi_f01_handler;
#endif

View File

@ -0,0 +1,574 @@
/*
* Copyright (c) 2011-2016 Synaptics Incorporated
* Copyright (c) 2011 Unixphere
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#include <linux/kernel.h>
#include <linux/kconfig.h>
#include <linux/rmi.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/of.h>
#include "rmi_driver.h"
#define RMI_PRODUCT_ID_LENGTH 10
#define RMI_PRODUCT_INFO_LENGTH 2
#define RMI_DATE_CODE_LENGTH 3
#define PRODUCT_ID_OFFSET 0x10
#define PRODUCT_INFO_OFFSET 0x1E
/* Force a firmware reset of the sensor */
#define RMI_F01_CMD_DEVICE_RESET 1
/* Various F01_RMI_QueryX bits */
#define RMI_F01_QRY1_CUSTOM_MAP BIT(0)
#define RMI_F01_QRY1_NON_COMPLIANT BIT(1)
#define RMI_F01_QRY1_HAS_LTS BIT(2)
#define RMI_F01_QRY1_HAS_SENSOR_ID BIT(3)
#define RMI_F01_QRY1_HAS_CHARGER_INP BIT(4)
#define RMI_F01_QRY1_HAS_ADJ_DOZE BIT(5)
#define RMI_F01_QRY1_HAS_ADJ_DOZE_HOFF BIT(6)
#define RMI_F01_QRY1_HAS_QUERY42 BIT(7)
#define RMI_F01_QRY5_YEAR_MASK 0x1f
#define RMI_F01_QRY6_MONTH_MASK 0x0f
#define RMI_F01_QRY7_DAY_MASK 0x1f
#define RMI_F01_QRY2_PRODINFO_MASK 0x7f
#define RMI_F01_BASIC_QUERY_LEN 21 /* From Query 00 through 20 */
struct f01_basic_properties {
u8 manufacturer_id;
bool has_lts;
bool has_adjustable_doze;
bool has_adjustable_doze_holdoff;
char dom[11]; /* YYYY/MM/DD + '\0' */
u8 product_id[RMI_PRODUCT_ID_LENGTH + 1];
u16 productinfo;
u32 firmware_id;
};
/* F01 device status bits */
/* Most recent device status event */
#define RMI_F01_STATUS_CODE(status) ((status) & 0x0f)
/* The device has lost its configuration for some reason. */
#define RMI_F01_STATUS_UNCONFIGURED(status) (!!((status) & 0x80))
/* Control register bits */
/*
* Sleep mode controls power management on the device and affects all
* functions of the device.
*/
#define RMI_F01_CTRL0_SLEEP_MODE_MASK 0x03
#define RMI_SLEEP_MODE_NORMAL 0x00
#define RMI_SLEEP_MODE_SENSOR_SLEEP 0x01
#define RMI_SLEEP_MODE_RESERVED0 0x02
#define RMI_SLEEP_MODE_RESERVED1 0x03
/*
* This bit disables whatever sleep mode may be selected by the sleep_mode
* field and forces the device to run at full power without sleeping.
*/
#define RMI_F01_CRTL0_NOSLEEP_BIT BIT(2)
/*
* When this bit is set, the touch controller employs a noise-filtering
* algorithm designed for use with a connected battery charger.
*/
#define RMI_F01_CRTL0_CHARGER_BIT BIT(5)
/*
* Sets the report rate for the device. The effect of this setting is
* highly product dependent. Check the spec sheet for your particular
* touch sensor.
*/
#define RMI_F01_CRTL0_REPORTRATE_BIT BIT(6)
/*
* Written by the host as an indicator that the device has been
* successfully configured.
*/
#define RMI_F01_CRTL0_CONFIGURED_BIT BIT(7)
/**
* @ctrl0 - see the bit definitions above.
* @doze_interval - controls the interval between checks for finger presence
* when the touch sensor is in doze mode, in units of 10ms.
* @wakeup_threshold - controls the capacitance threshold at which the touch
* sensor will decide to wake up from that low power state.
* @doze_holdoff - controls how long the touch sensor waits after the last
* finger lifts before entering the doze state, in units of 100ms.
*/
struct f01_device_control {
u8 ctrl0;
u8 doze_interval;
u8 wakeup_threshold;
u8 doze_holdoff;
};
struct f01_data {
struct f01_basic_properties properties;
struct f01_device_control device_control;
u16 doze_interval_addr;
u16 wakeup_threshold_addr;
u16 doze_holdoff_addr;
bool suspended;
bool old_nosleep;
unsigned int num_of_irq_regs;
};
static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
u16 query_base_addr,
struct f01_basic_properties *props)
{
u8 queries[RMI_F01_BASIC_QUERY_LEN];
int ret;
int query_offset = query_base_addr;
bool has_ds4_queries = false;
bool has_query42 = false;
bool has_sensor_id = false;
bool has_package_id_query = false;
bool has_build_id_query = false;
u16 prod_info_addr;
u8 ds4_query_len;
ret = rmi_read_block(rmi_dev, query_offset,
queries, RMI_F01_BASIC_QUERY_LEN);
if (ret) {
dev_err(&rmi_dev->dev,
"Failed to read device query registers: %d\n", ret);
return ret;
}
prod_info_addr = query_offset + 17;
query_offset += RMI_F01_BASIC_QUERY_LEN;
/* Now parse what we got */
props->manufacturer_id = queries[0];
props->has_lts = queries[1] & RMI_F01_QRY1_HAS_LTS;
props->has_adjustable_doze =
queries[1] & RMI_F01_QRY1_HAS_ADJ_DOZE;
props->has_adjustable_doze_holdoff =
queries[1] & RMI_F01_QRY1_HAS_ADJ_DOZE_HOFF;
has_query42 = queries[1] & RMI_F01_QRY1_HAS_QUERY42;
has_sensor_id = queries[1] & RMI_F01_QRY1_HAS_SENSOR_ID;
snprintf(props->dom, sizeof(props->dom), "20%02d/%02d/%02d",
queries[5] & RMI_F01_QRY5_YEAR_MASK,
queries[6] & RMI_F01_QRY6_MONTH_MASK,
queries[7] & RMI_F01_QRY7_DAY_MASK);
memcpy(props->product_id, &queries[11],
RMI_PRODUCT_ID_LENGTH);
props->product_id[RMI_PRODUCT_ID_LENGTH] = '\0';
props->productinfo =
((queries[2] & RMI_F01_QRY2_PRODINFO_MASK) << 7) |
(queries[3] & RMI_F01_QRY2_PRODINFO_MASK);
if (has_sensor_id)
query_offset++;
if (has_query42) {
ret = rmi_read(rmi_dev, query_offset, queries);
if (ret) {
dev_err(&rmi_dev->dev,
"Failed to read query 42 register: %d\n", ret);
return ret;
}
has_ds4_queries = !!(queries[0] & BIT(0));
query_offset++;
}
if (has_ds4_queries) {
ret = rmi_read(rmi_dev, query_offset, &ds4_query_len);
if (ret) {
dev_err(&rmi_dev->dev,
"Failed to read DS4 queries length: %d\n", ret);
return ret;
}
query_offset++;
if (ds4_query_len > 0) {
ret = rmi_read(rmi_dev, query_offset, queries);
if (ret) {
dev_err(&rmi_dev->dev,
"Failed to read DS4 queries: %d\n",
ret);
return ret;
}
has_package_id_query = !!(queries[0] & BIT(0));
has_build_id_query = !!(queries[0] & BIT(1));
}
if (has_package_id_query)
prod_info_addr++;
if (has_build_id_query) {
ret = rmi_read_block(rmi_dev, prod_info_addr, queries,
3);
if (ret) {
dev_err(&rmi_dev->dev,
"Failed to read product info: %d\n",
ret);
return ret;
}
props->firmware_id = queries[1] << 8 | queries[0];
props->firmware_id += queries[2] * 65536;
}
}
return 0;
}
char *rmi_f01_get_product_ID(struct rmi_function *fn)
{
struct f01_data *f01 = dev_get_drvdata(&fn->dev);
return f01->properties.product_id;
}
static int rmi_f01_probe(struct rmi_function *fn)
{
struct rmi_device *rmi_dev = fn->rmi_dev;
struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
struct f01_data *f01;
int error;
u16 ctrl_base_addr = fn->fd.control_base_addr;
u8 device_status;
u8 temp;
f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL);
if (!f01)
return -ENOMEM;
f01->num_of_irq_regs = driver_data->num_of_irq_regs;
/*
* Set the configured bit and (optionally) other important stuff
* in the device control register.
*/
error = rmi_read(rmi_dev, fn->fd.control_base_addr,
&f01->device_control.ctrl0);
if (error) {
dev_err(&fn->dev, "Failed to read F01 control: %d\n", error);
return error;
}
switch (pdata->power_management.nosleep) {
case RMI_F01_NOSLEEP_DEFAULT:
break;
case RMI_F01_NOSLEEP_OFF:
f01->device_control.ctrl0 &= ~RMI_F01_CRTL0_NOSLEEP_BIT;
break;
case RMI_F01_NOSLEEP_ON:
f01->device_control.ctrl0 |= RMI_F01_CRTL0_NOSLEEP_BIT;
break;
}
/*
* Sleep mode might be set as a hangover from a system crash or
* reboot without power cycle. If so, clear it so the sensor
* is certain to function.
*/
if ((f01->device_control.ctrl0 & RMI_F01_CTRL0_SLEEP_MODE_MASK) !=
RMI_SLEEP_MODE_NORMAL) {
dev_warn(&fn->dev,
"WARNING: Non-zero sleep mode found. Clearing...\n");
f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
}
f01->device_control.ctrl0 |= RMI_F01_CRTL0_CONFIGURED_BIT;
error = rmi_write(rmi_dev, fn->fd.control_base_addr,
f01->device_control.ctrl0);
if (error) {
dev_err(&fn->dev, "Failed to write F01 control: %d\n", error);
return error;
}
/* Dummy read in order to clear irqs */
error = rmi_read(rmi_dev, fn->fd.data_base_addr + 1, &temp);
if (error < 0) {
dev_err(&fn->dev, "Failed to read Interrupt Status.\n");
return error;
}
error = rmi_f01_read_properties(rmi_dev, fn->fd.query_base_addr,
&f01->properties);
if (error < 0) {
dev_err(&fn->dev, "Failed to read F01 properties.\n");
return error;
}
dev_info(&fn->dev, "found RMI device, manufacturer: %s, product: %s, fw id: %d\n",
f01->properties.manufacturer_id == 1 ? "Synaptics" : "unknown",
f01->properties.product_id, f01->properties.firmware_id);
/* Advance to interrupt control registers, then skip over them. */
ctrl_base_addr++;
ctrl_base_addr += f01->num_of_irq_regs;
/* read control register */
if (f01->properties.has_adjustable_doze) {
f01->doze_interval_addr = ctrl_base_addr;
ctrl_base_addr++;
if (pdata->power_management.doze_interval) {
f01->device_control.doze_interval =
pdata->power_management.doze_interval;
error = rmi_write(rmi_dev, f01->doze_interval_addr,
f01->device_control.doze_interval);
if (error) {
dev_err(&fn->dev,
"Failed to configure F01 doze interval register: %d\n",
error);
return error;
}
} else {
error = rmi_read(rmi_dev, f01->doze_interval_addr,
&f01->device_control.doze_interval);
if (error) {
dev_err(&fn->dev,
"Failed to read F01 doze interval register: %d\n",
error);
return error;
}
}
f01->wakeup_threshold_addr = ctrl_base_addr;
ctrl_base_addr++;
if (pdata->power_management.wakeup_threshold) {
f01->device_control.wakeup_threshold =
pdata->power_management.wakeup_threshold;
error = rmi_write(rmi_dev, f01->wakeup_threshold_addr,
f01->device_control.wakeup_threshold);
if (error) {
dev_err(&fn->dev,
"Failed to configure F01 wakeup threshold register: %d\n",
error);
return error;
}
} else {
error = rmi_read(rmi_dev, f01->wakeup_threshold_addr,
&f01->device_control.wakeup_threshold);
if (error < 0) {
dev_err(&fn->dev,
"Failed to read F01 wakeup threshold register: %d\n",
error);
return error;
}
}
}
if (f01->properties.has_lts)
ctrl_base_addr++;
if (f01->properties.has_adjustable_doze_holdoff) {
f01->doze_holdoff_addr = ctrl_base_addr;
ctrl_base_addr++;
if (pdata->power_management.doze_holdoff) {
f01->device_control.doze_holdoff =
pdata->power_management.doze_holdoff;
error = rmi_write(rmi_dev, f01->doze_holdoff_addr,
f01->device_control.doze_holdoff);
if (error) {
dev_err(&fn->dev,
"Failed to configure F01 doze holdoff register: %d\n",
error);
return error;
}
} else {
error = rmi_read(rmi_dev, f01->doze_holdoff_addr,
&f01->device_control.doze_holdoff);
if (error) {
dev_err(&fn->dev,
"Failed to read F01 doze holdoff register: %d\n",
error);
return error;
}
}
}
error = rmi_read(rmi_dev, fn->fd.data_base_addr, &device_status);
if (error < 0) {
dev_err(&fn->dev,
"Failed to read device status: %d\n", error);
return error;
}
if (RMI_F01_STATUS_UNCONFIGURED(device_status)) {
dev_err(&fn->dev,
"Device was reset during configuration process, status: %#02x!\n",
RMI_F01_STATUS_CODE(device_status));
return -EINVAL;
}
dev_set_drvdata(&fn->dev, f01);
return 0;
}
static int rmi_f01_config(struct rmi_function *fn)
{
struct f01_data *f01 = dev_get_drvdata(&fn->dev);
int error;
error = rmi_write(fn->rmi_dev, fn->fd.control_base_addr,
f01->device_control.ctrl0);
if (error) {
dev_err(&fn->dev,
"Failed to write device_control register: %d\n", error);
return error;
}
if (f01->properties.has_adjustable_doze) {
error = rmi_write(fn->rmi_dev, f01->doze_interval_addr,
f01->device_control.doze_interval);
if (error) {
dev_err(&fn->dev,
"Failed to write doze interval: %d\n", error);
return error;
}
error = rmi_write_block(fn->rmi_dev,
f01->wakeup_threshold_addr,
&f01->device_control.wakeup_threshold,
sizeof(u8));
if (error) {
dev_err(&fn->dev,
"Failed to write wakeup threshold: %d\n",
error);
return error;
}
}
if (f01->properties.has_adjustable_doze_holdoff) {
error = rmi_write(fn->rmi_dev, f01->doze_holdoff_addr,
f01->device_control.doze_holdoff);
if (error) {
dev_err(&fn->dev,
"Failed to write doze holdoff: %d\n", error);
return error;
}
}
return 0;
}
static int rmi_f01_suspend(struct rmi_function *fn)
{
struct f01_data *f01 = dev_get_drvdata(&fn->dev);
int error;
f01->old_nosleep =
f01->device_control.ctrl0 & RMI_F01_CRTL0_NOSLEEP_BIT;
f01->device_control.ctrl0 &= ~RMI_F01_CRTL0_NOSLEEP_BIT;
f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
if (device_may_wakeup(fn->rmi_dev->xport->dev))
f01->device_control.ctrl0 |= RMI_SLEEP_MODE_RESERVED1;
else
f01->device_control.ctrl0 |= RMI_SLEEP_MODE_SENSOR_SLEEP;
error = rmi_write(fn->rmi_dev, fn->fd.control_base_addr,
f01->device_control.ctrl0);
if (error) {
dev_err(&fn->dev, "Failed to write sleep mode: %d.\n", error);
if (f01->old_nosleep)
f01->device_control.ctrl0 |= RMI_F01_CRTL0_NOSLEEP_BIT;
f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
f01->device_control.ctrl0 |= RMI_SLEEP_MODE_NORMAL;
return error;
}
return 0;
}
static int rmi_f01_resume(struct rmi_function *fn)
{
struct f01_data *f01 = dev_get_drvdata(&fn->dev);
int error;
if (f01->old_nosleep)
f01->device_control.ctrl0 |= RMI_F01_CRTL0_NOSLEEP_BIT;
f01->device_control.ctrl0 &= ~RMI_F01_CTRL0_SLEEP_MODE_MASK;
f01->device_control.ctrl0 |= RMI_SLEEP_MODE_NORMAL;
error = rmi_write(fn->rmi_dev, fn->fd.control_base_addr,
f01->device_control.ctrl0);
if (error) {
dev_err(&fn->dev,
"Failed to restore normal operation: %d.\n", error);
return error;
}
return 0;
}
static int rmi_f01_attention(struct rmi_function *fn,
unsigned long *irq_bits)
{
struct rmi_device *rmi_dev = fn->rmi_dev;
int error;
u8 device_status;
error = rmi_read(rmi_dev, fn->fd.data_base_addr, &device_status);
if (error) {
dev_err(&fn->dev,
"Failed to read device status: %d.\n", error);
return error;
}
if (RMI_F01_STATUS_UNCONFIGURED(device_status)) {
dev_warn(&fn->dev, "Device reset detected.\n");
error = rmi_dev->driver->reset_handler(rmi_dev);
if (error) {
dev_err(&fn->dev, "Device reset failed: %d\n", error);
return error;
}
}
return 0;
}
struct rmi_function_handler rmi_f01_handler = {
.driver = {
.name = "rmi4_f01",
/*
* Do not allow user unbinding F01 as it is critical
* function.
*/
.suppress_bind_attrs = true,
},
.func = 0x01,
.probe = rmi_f01_probe,
.config = rmi_f01_config,
.attention = rmi_f01_attention,
.suspend = rmi_f01_suspend,
.resume = rmi_f01_resume,
};

209
include/linux/rmi.h 100644
View File

@ -0,0 +1,209 @@
/*
* Copyright (c) 2011-2016 Synaptics Incorporated
* Copyright (c) 2011 Unixphere
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _RMI_H
#define _RMI_H
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/input.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/types.h>
#define NAME_BUFFER_SIZE 256
/**
* struct rmi_f01_power - override default power management settings.
*
*/
enum rmi_f01_nosleep {
RMI_F01_NOSLEEP_DEFAULT = 0,
RMI_F01_NOSLEEP_OFF = 1,
RMI_F01_NOSLEEP_ON = 2
};
/**
* struct rmi_f01_power_management -When non-zero, these values will be written
* to the touch sensor to override the default firmware settigns. For a
* detailed explanation of what each field does, see the corresponding
* documention in the RMI4 specification.
*
* @nosleep - specifies whether the device is permitted to sleep or doze (that
* is, enter a temporary low power state) when no fingers are touching the
* sensor.
* @wakeup_threshold - controls the capacitance threshold at which the touch
* sensor will decide to wake up from that low power state.
* @doze_holdoff - controls how long the touch sensor waits after the last
* finger lifts before entering the doze state, in units of 100ms.
* @doze_interval - controls the interval between checks for finger presence
* when the touch sensor is in doze mode, in units of 10ms.
*/
struct rmi_f01_power_management {
enum rmi_f01_nosleep nosleep;
u8 wakeup_threshold;
u8 doze_holdoff;
u8 doze_interval;
};
/**
* struct rmi_device_platform_data - system specific configuration info.
*
* @reset_delay_ms - after issuing a reset command to the touch sensor, the
* driver waits a few milliseconds to give the firmware a chance to
* to re-initialize. You can override the default wait period here.
*/
struct rmi_device_platform_data {
int reset_delay_ms;
/* function handler pdata */
struct rmi_f01_power_management power_management;
};
/**
* struct rmi_function_descriptor - RMI function base addresses
*
* @query_base_addr: The RMI Query base address
* @command_base_addr: The RMI Command base address
* @control_base_addr: The RMI Control base address
* @data_base_addr: The RMI Data base address
* @interrupt_source_count: The number of irqs this RMI function needs
* @function_number: The RMI function number
*
* This struct is used when iterating the Page Description Table. The addresses
* are 16-bit values to include the current page address.
*
*/
struct rmi_function_descriptor {
u16 query_base_addr;
u16 command_base_addr;
u16 control_base_addr;
u16 data_base_addr;
u8 interrupt_source_count;
u8 function_number;
u8 function_version;
};
struct rmi_device;
/**
* struct rmi_transport_dev - represent an RMI transport device
*
* @dev: Pointer to the communication device, e.g. i2c or spi
* @rmi_dev: Pointer to the RMI device
* @proto_name: name of the transport protocol (SPI, i2c, etc)
* @ops: pointer to transport operations implementation
*
* The RMI transport device implements the glue between different communication
* buses such as I2C and SPI.
*
*/
struct rmi_transport_dev {
struct device *dev;
struct rmi_device *rmi_dev;
const char *proto_name;
const struct rmi_transport_ops *ops;
struct rmi_device_platform_data pdata;
struct input_dev *input;
void *attn_data;
int attn_size;
};
/**
* struct rmi_transport_ops - defines transport protocol operations.
*
* @write_block: Writing a block of data to the specified address
* @read_block: Read a block of data from the specified address.
*/
struct rmi_transport_ops {
int (*write_block)(struct rmi_transport_dev *xport, u16 addr,
const void *buf, size_t len);
int (*read_block)(struct rmi_transport_dev *xport, u16 addr,
void *buf, size_t len);
int (*reset)(struct rmi_transport_dev *xport, u16 reset_addr);
};
/**
* struct rmi_driver - driver for an RMI4 sensor on the RMI bus.
*
* @driver: Device driver model driver
* @reset_handler: Called when a reset is detected.
* @clear_irq_bits: Clear the specified bits in the current interrupt mask.
* @set_irq_bist: Set the specified bits in the current interrupt mask.
* @store_productid: Callback for cache product id from function 01
* @data: Private data pointer
*
*/
struct rmi_driver {
struct device_driver driver;
int (*reset_handler)(struct rmi_device *rmi_dev);
int (*clear_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
int (*set_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
int (*store_productid)(struct rmi_device *rmi_dev);
int (*set_input_params)(struct rmi_device *rmi_dev,
struct input_dev *input);
void *data;
};
/**
* struct rmi_device - represents an RMI4 sensor device on the RMI bus.
*
* @dev: The device created for the RMI bus
* @number: Unique number for the device on the bus.
* @driver: Pointer to associated driver
* @xport: Pointer to the transport interface
*
*/
struct rmi_device {
struct device dev;
int number;
struct rmi_driver *driver;
struct rmi_transport_dev *xport;
};
struct rmi_driver_data {
struct list_head function_list;
struct rmi_device *rmi_dev;
struct rmi_function *f01_container;
bool f01_bootloader_mode;
u32 attn_count;
int num_of_irq_regs;
int irq_count;
unsigned long *irq_status;
unsigned long *fn_irq_bits;
unsigned long *current_irq_mask;
unsigned long *new_irq_mask;
struct mutex irq_mutex;
struct input_dev *input;
u8 pdt_props;
u8 bsr;
bool enabled;
void *data;
};
int rmi_register_transport_device(struct rmi_transport_dev *xport);
void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
int rmi_process_interrupt_requests(struct rmi_device *rmi_dev);
int rmi_driver_suspend(struct rmi_device *rmi_dev);
int rmi_driver_resume(struct rmi_device *rmi_dev);
#endif

View File

@ -246,6 +246,7 @@ struct input_mask {
#define BUS_GSC 0x1A
#define BUS_ATARI 0x1B
#define BUS_SPI 0x1C
#define BUS_RMI 0x1D
/*
* MT_TOOL types