2012-11-27 09:22:49

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 1/4] Input RMI4 - rename rmi_function_container to rmi_function

To save my old fingers...

Signed-off-by: Dmitry Torokhov <[email protected]>
---

It looks like this driver(s) need some love and I might have some time so I
will refresh my "synaptics" branch with the patches you have sent and start
working off it. If you have updates I would appreciate if you also make them
available relative to that branch. When we are ready we'll squash them all
together and apply to the official branch.

Thanks.

drivers/input/rmi4/rmi_driver.c | 158 +++++++++++----------
drivers/input/rmi4/rmi_driver.h | 4 +-
drivers/input/rmi4/rmi_f01.c | 298 ++++++++++++++++++++--------------------
drivers/input/rmi4/rmi_f11.c | 258 +++++++++++++++++-----------------
include/linux/rmi.h | 22 ++-
5 files changed, 368 insertions(+), 372 deletions(-)

diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 05a73ae..e8a4b52 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -594,7 +594,7 @@ static struct device_attribute bsr_attribute = __ATTR(bsr, RMI_RW_ATTR,

static void rmi_free_function_list(struct rmi_device *rmi_dev)
{
- struct rmi_function_container *entry, *n;
+ struct rmi_function *entry, *n;
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);

if (!data) {
@@ -613,44 +613,44 @@ static void rmi_free_function_list(struct rmi_device *rmi_dev)
}
}

-static void release_fc_device(struct device *dev)
+static void release_function_device(struct device *dev)
{
dev_dbg(dev, "REMOVING KOBJ!");
kobject_put(&dev->kobj);
}

-static int reset_one_function(struct rmi_function_container *fc)
+static int reset_one_function(struct rmi_function *fn)
{
struct rmi_function_handler *fh;
int retval = 0;

- if (!fc || !fc->dev.driver)
+ if (!fn || !fn->dev.driver)
return 0;

- fh = to_rmi_function_handler(fc->dev.driver);
+ fh = to_rmi_function_handler(fn->dev.driver);
if (fh->reset) {
- retval = fh->reset(fc);
+ retval = fh->reset(fn);
if (retval < 0)
- dev_err(&fc->dev, "Reset failed with code %d.\n",
+ dev_err(&fn->dev, "Reset failed with code %d.\n",
retval);
}

return retval;
}

-static int configure_one_function(struct rmi_function_container *fc)
+static int configure_one_function(struct rmi_function *fn)
{
struct rmi_function_handler *fh;
int retval = 0;

- if (!fc || !fc->dev.driver)
+ if (!fn || !fn->dev.driver)
return 0;

- fh = to_rmi_function_handler(fc->dev.driver);
+ fh = to_rmi_function_handler(fn->dev.driver);
if (fh->config) {
- retval = fh->config(fc);
+ retval = fh->config(fn);
if (retval < 0)
- dev_err(&fc->dev, "Config failed with code %d.\n",
+ dev_err(&fn->dev, "Config failed with code %d.\n",
retval);
}

@@ -660,7 +660,7 @@ static int configure_one_function(struct rmi_function_container *fc)
static int rmi_driver_process_reset_requests(struct rmi_device *rmi_dev)
{
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
- struct rmi_function_container *entry;
+ struct rmi_function *entry;
int retval;

if (list_empty(&data->rmi_functions.list))
@@ -678,7 +678,7 @@ static int rmi_driver_process_reset_requests(struct rmi_device *rmi_dev)
static int rmi_driver_process_config_requests(struct rmi_device *rmi_dev)
{
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
- struct rmi_function_container *entry;
+ struct rmi_function *entry;
int retval;

if (list_empty(&data->rmi_functions.list))
@@ -693,30 +693,29 @@ static int rmi_driver_process_config_requests(struct rmi_device *rmi_dev)
return 0;
}

-static void process_one_interrupt(struct rmi_function_container *fc,
+static void process_one_interrupt(struct rmi_function *fn,
unsigned long *irq_status, struct rmi_driver_data *data)
{
struct rmi_function_handler *fh;
DECLARE_BITMAP(irq_bits, data->num_of_irq_regs);

- if (!fc || !fc->dev.driver)
+ if (!fn || !fn->dev.driver)
return;

- fh = to_rmi_function_handler(fc->dev.driver);
- if (fc->irq_mask && fh->attention) {
- bitmap_and(irq_bits, irq_status, fc->irq_mask,
+ fh = to_rmi_function_handler(fn->dev.driver);
+ if (fn->irq_mask && fh->attention) {
+ bitmap_and(irq_bits, irq_status, fn->irq_mask,
data->irq_count);
if (!bitmap_empty(irq_bits, data->irq_count))
- fh->attention(fc, irq_bits);
+ fh->attention(fn, irq_bits);
}
-
}

static int process_interrupt_requests(struct rmi_device *rmi_dev)
{
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
struct device *dev = &rmi_dev->dev;
- struct rmi_function_container *entry;
+ struct rmi_function *entry;
int error;

error = rmi_read_block(rmi_dev,
@@ -904,65 +903,65 @@ static int rmi_driver_reset_handler(struct rmi_device *rmi_dev)
* Construct a function's IRQ mask. This should be called once and stored.
*/
int rmi_driver_irq_get_mask(struct rmi_device *rmi_dev,
- struct rmi_function_container *fc) {
+ struct rmi_function *fn) {
int i;
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);

/* call devm_kcalloc when it will be defined in kernel in future */
- fc->irq_mask = devm_kzalloc(&rmi_dev->dev,
+ fn->irq_mask = devm_kzalloc(&rmi_dev->dev,
BITS_TO_LONGS(data->irq_count)*sizeof(unsigned long),
GFP_KERNEL);

- if (fc->irq_mask) {
- for (i = 0; i < fc->num_of_irqs; i++)
- set_bit(fc->irq_pos+i, fc->irq_mask);
+ if (fn->irq_mask) {
+ for (i = 0; i < fn->num_of_irqs; i++)
+ set_bit(fn->irq_pos+i, fn->irq_mask);
return 0;
} else
return -ENOMEM;
}

static int init_function_device(struct rmi_device *rmi_dev,
- struct rmi_function_container *fc)
+ struct rmi_function *fn)
{
int retval;

/* This memset might not be what we want to do... */
- memset(&(fc->dev), 0, sizeof(struct device));
- dev_set_name(&(fc->dev), "%s.fn%02x", dev_name(&rmi_dev->dev),
- fc->fd.function_number);
- fc->dev.release = release_fc_device;
-
- fc->dev.parent = &rmi_dev->dev;
- fc->dev.type = &rmi_function_type;
- fc->dev.bus = &rmi_bus_type;
- dev_dbg(&rmi_dev->dev, "Register F%02X.\n", fc->fd.function_number);
- retval = device_register(&fc->dev);
+ memset(&fn->dev, 0, sizeof(struct device));
+ dev_set_name(&fn->dev, "%s.fn%02x", dev_name(&rmi_dev->dev),
+ fn->fd.function_number);
+ fn->dev.release = release_function_device;
+
+ fn->dev.parent = &rmi_dev->dev;
+ fn->dev.type = &rmi_function_type;
+ fn->dev.bus = &rmi_bus_type;
+ dev_dbg(&rmi_dev->dev, "Register F%02X.\n", fn->fd.function_number);
+ retval = device_register(&fn->dev);
if (retval) {
dev_err(&rmi_dev->dev, "Failed device_register for F%02X.\n",
- fc->fd.function_number);
+ fn->fd.function_number);
return retval;
}

if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
char dirname[12];

- snprintf(dirname, 12, "F%02X", fc->fd.function_number);
- fc->debugfs_root = debugfs_create_dir(dirname,
+ snprintf(dirname, 12, "F%02X", fn->fd.function_number);
+ fn->debugfs_root = debugfs_create_dir(dirname,
rmi_dev->debugfs_root);
- if (!fc->debugfs_root)
- dev_warn(&fc->dev, "Failed to create debugfs dir.\n");
+ if (!fn->debugfs_root)
+ dev_warn(&fn->dev, "Failed to create debugfs dir.\n");
}

return 0;
}

-static int create_function_container(struct rmi_device *rmi_dev,
+static int create_function(struct rmi_device *rmi_dev,
struct pdt_entry *pdt_ptr,
int *current_irq_count,
u16 page_start)
{
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
- struct rmi_function_container *fc = NULL;
+ struct rmi_function *fn = NULL;
int retval = 0;
struct device *dev = &rmi_dev->dev;
struct rmi_device_platform_data *pdata;
@@ -972,37 +971,37 @@ static int create_function_container(struct rmi_device *rmi_dev,
dev_dbg(dev, "Initializing F%02X for %s.\n", pdt_ptr->function_number,
pdata->sensor_name);

- fc = devm_kzalloc(dev, sizeof(struct rmi_function_container),
+ fn = devm_kzalloc(dev, sizeof(struct rmi_function),
GFP_KERNEL);
- if (!fc) {
+ if (!fn) {
dev_err(dev, "Failed to allocate F%02X container.\n",
pdt_ptr->function_number);
return -ENOMEM;
}

- copy_pdt_entry_to_fd(pdt_ptr, &fc->fd, page_start);
+ copy_pdt_entry_to_fd(pdt_ptr, &fn->fd, page_start);

- fc->rmi_dev = rmi_dev;
- fc->num_of_irqs = pdt_ptr->interrupt_source_count;
+ fn->rmi_dev = rmi_dev;
+ fn->num_of_irqs = pdt_ptr->interrupt_source_count;

- fc->irq_pos = *current_irq_count;
- *current_irq_count += fc->num_of_irqs;
+ fn->irq_pos = *current_irq_count;
+ *current_irq_count += fn->num_of_irqs;

- retval = init_function_device(rmi_dev, fc);
+ retval = init_function_device(rmi_dev, fn);
if (retval < 0) {
dev_err(dev, "Failed to initialize F%02X device.\n",
pdt_ptr->function_number);
goto error_free_data;
}

- INIT_LIST_HEAD(&fc->list);
+ INIT_LIST_HEAD(&fn->list);
/* we need to ensure that F01 is at the head of the list.
*/
if (pdt_ptr->function_number == 0x01) {
- list_add(&fc->list, &data->rmi_functions.list);
- data->f01_container = fc;
+ list_add(&fn->list, &data->rmi_functions.list);
+ data->f01_container = fn;
} else
- list_add_tail(&fc->list, &data->rmi_functions.list);
+ list_add_tail(&fn->list, &data->rmi_functions.list);
return 0;

error_free_data:
@@ -1032,7 +1031,6 @@ static void check_bootloader_mode(struct rmi_device *rmi_dev,
if (device_status.flash_prog)
dev_warn(&rmi_dev->dev,
"WARNING: RMI4 device is in bootloader mode!\n");
-
}

/*
@@ -1203,7 +1201,7 @@ static int rmi_scan_pdt(struct rmi_device *rmi_dev)
page_start);


- retval = create_function_container(rmi_dev,
+ retval = create_function(rmi_dev,
&pdt_entry, &irq_count, page_start);

if (retval)
@@ -1228,23 +1226,23 @@ static int f01_notifier_call(struct notifier_block *nb,
unsigned long action, void *data)
{
struct device *dev = data;
- struct rmi_function_container *fc;
+ struct rmi_function *fn;

if (dev->type != &rmi_function_type)
return 0;

- fc = to_rmi_function_container(dev);
- if (fc->fd.function_number != 0x01)
+ fn = to_rmi_function(dev);
+ if (fn->fd.function_number != 0x01)
return 0;

switch (action) {
case BUS_NOTIFY_BOUND_DRIVER:
dev_dbg(dev, "%s: F01 driver bound.\n", __func__);
- enable_sensor(fc->rmi_dev);
+ enable_sensor(fn->rmi_dev);
break;
case BUS_NOTIFY_UNBIND_DRIVER:
dev_dbg(dev, "%s: F01 driver going away.\n", __func__);
- disable_sensor(fc->rmi_dev);
+ disable_sensor(fn->rmi_dev);
break;
}
return 0;
@@ -1255,20 +1253,20 @@ static struct notifier_block rmi_bus_notifier = {
};

#ifdef CONFIG_PM
-static int suspend_one_device(struct rmi_function_container *fc)
+static int suspend_one_device(struct rmi_function *fn)
{
struct rmi_function_handler *fh;
int retval = 0;

- if (!fc->dev.driver)
+ if (!fn->dev.driver)
return 0;

- fh = to_rmi_function_handler(fc->dev.driver);
+ fh = to_rmi_function_handler(fn->dev.driver);

if (fh->suspend) {
- retval = fh->suspend(fc);
+ retval = fh->suspend(fn);
if (retval < 0)
- dev_err(&fc->dev, "Suspend failed, code: %d",
+ dev_err(&fn->dev, "Suspend failed, code: %d",
retval);
}

@@ -1278,7 +1276,7 @@ static int suspend_one_device(struct rmi_function_container *fc)
static int rmi_driver_suspend(struct device *dev)
{
struct rmi_driver_data *data;
- struct rmi_function_container *entry;
+ struct rmi_function *entry;
int retval = 0;
struct rmi_device *rmi_dev = to_rmi_device(dev);

@@ -1311,20 +1309,20 @@ exit:
return retval;
}

-static int resume_one_device(struct rmi_function_container *fc)
+static int resume_one_device(struct rmi_function *fn)
{
struct rmi_function_handler *fh;
int retval = 0;

- if (!fc->dev.driver)
+ if (!fn->dev.driver)
return 0;

- fh = to_rmi_function_handler(fc->dev.driver);
+ fh = to_rmi_function_handler(fn->dev.driver);

if (fh->resume) {
- retval = fh->resume(fc);
+ retval = fh->resume(fn);
if (retval < 0)
- dev_err(&fc->dev, "Resume failed, code: %d",
+ dev_err(&fn->dev, "Resume failed, code: %d",
retval);
}

@@ -1334,7 +1332,7 @@ static int resume_one_device(struct rmi_function_container *fc)
static int rmi_driver_resume(struct device *dev)
{
struct rmi_driver_data *data;
- struct rmi_function_container *entry;
+ struct rmi_function *entry;
int retval = 0;
struct rmi_device *rmi_dev = to_rmi_device(dev);

@@ -1399,7 +1397,7 @@ static int __devinit rmi_driver_probe(struct device *dev)
{
struct rmi_driver *rmi_driver;
struct rmi_driver_data *data = NULL;
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
struct rmi_device_platform_data *pdata;
int retval = 0;
int attr_count = 0;
@@ -1467,8 +1465,8 @@ static int __devinit rmi_driver_probe(struct device *dev)
goto err_free_data;
}

- list_for_each_entry(fc, &data->rmi_functions.list, list) {
- retval = rmi_driver_irq_get_mask(rmi_dev, fc);
+ list_for_each_entry(fn, &data->rmi_functions.list, list) {
+ retval = rmi_driver_irq_get_mask(rmi_dev, fn);
if (retval < 0) {
dev_err(dev, "%s: Failed to create irq_mask.\n",
__func__);
@@ -1573,7 +1571,7 @@ static int __devinit rmi_driver_probe(struct device *dev)
if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
retval = setup_debugfs(rmi_dev);
if (retval < 0)
- dev_warn(&fc->dev, "Failed to setup debugfs. Code: %d.\n",
+ dev_warn(&fn->dev, "Failed to setup debugfs. Code: %d.\n",
retval);
}

diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index f5b221a..1fc4676 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -44,10 +44,10 @@ struct pdt_properties {
} __attribute__((__packed__));

struct rmi_driver_data {
- struct rmi_function_container rmi_functions;
+ struct rmi_function rmi_functions;
struct rmi_device *rmi_dev;

- struct rmi_function_container *f01_container;
+ struct rmi_function *f01_container;
bool f01_bootloader_mode;

atomic_t attn_count;
diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index b6352ba..5e6bef6 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -138,19 +138,19 @@ struct f01_data {
#ifdef CONFIG_RMI4_DEBUG
struct f01_debugfs_data {
bool done;
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
};

static int f01_debug_open(struct inode *inodep, struct file *filp)
{
struct f01_debugfs_data *data;
- struct rmi_function_container *fc = inodep->i_private;
+ struct rmi_function *fn = inodep->i_private;

data = kzalloc(sizeof(struct f01_debugfs_data), GFP_KERNEL);
if (!data)
return -ENOMEM;

- data->fc = fc;
+ data->fn = fn;
filp->private_data = data;
return 0;
}
@@ -169,7 +169,7 @@ static ssize_t interrupt_enable_read(struct file *filp, char __user *buffer,
char local_buf[size];
char *current_buf = local_buf;
struct f01_debugfs_data *data = filp->private_data;
- struct f01_data *f01 = data->fc->data;
+ struct f01_data *f01 = data->fn->data;

if (data->done)
return 0;
@@ -199,7 +199,7 @@ static ssize_t interrupt_enable_read(struct file *filp, char __user *buffer,
current_buf += len;
total_len += len;
} else {
- dev_err(&data->fc->dev, "Failed to build interrupt_enable buffer, code = %d.\n",
+ dev_err(&data->fn->dev, "Failed to build interrupt_enable buffer, code = %d.\n",
len);
return snprintf(local_buf, size, "unknown\n");
}
@@ -208,7 +208,7 @@ static ssize_t interrupt_enable_read(struct file *filp, char __user *buffer,
if (len > 0)
total_len += len;
else
- dev_warn(&data->fc->dev, "%s: Failed to append carriage return.\n",
+ dev_warn(&data->fn->dev, "%s: Failed to append carriage return.\n",
__func__);

if (copy_to_user(buffer, local_buf, total_len))
@@ -226,7 +226,7 @@ static ssize_t interrupt_enable_write(struct file *filp,
int irq_count = 0;
int irq_reg = 0;
struct f01_debugfs_data *data = filp->private_data;
- struct f01_data *f01 = data->fc->data;
+ struct f01_data *f01 = data->fn->data;

retval = copy_from_user(buf, buffer, size);
if (retval)
@@ -246,7 +246,7 @@ static ssize_t interrupt_enable_write(struct file *filp,
result = sscanf(local_buf, "%u", &interrupt_enable);
if ((result != 1) ||
(interrupt_enable != 0 && interrupt_enable != 1)) {
- dev_err(&data->fc->dev, "Interrupt enable[%d] is not a valid value 0x%x.\n",
+ dev_err(&data->fn->dev, "Interrupt enable[%d] is not a valid value 0x%x.\n",
i, interrupt_enable);
return -EINVAL;
}
@@ -261,17 +261,17 @@ static ssize_t interrupt_enable_write(struct file *filp,

/* Make sure the irq count matches */
if (irq_count != f01->irq_count) {
- dev_err(&data->fc->dev, "Interrupt enable count of %d doesn't match device count of %d.\n",
+ dev_err(&data->fn->dev, "Interrupt enable count of %d doesn't match device count of %d.\n",
irq_count, f01->irq_count);
return -EINVAL;
}

/* write back to the control register */
- retval = rmi_write_block(data->fc->rmi_dev, f01->interrupt_enable_addr,
+ retval = rmi_write_block(data->fn->rmi_dev, f01->interrupt_enable_addr,
f01->device_control.interrupt_enable,
f01->num_of_irq_regs);
if (retval < 0) {
- dev_err(&data->fc->dev, "Could not write interrupt_enable mask to %#06x\n",
+ dev_err(&data->fn->dev, "Could not write interrupt_enable mask to %#06x\n",
f01->interrupt_enable_addr);
return retval;
}
@@ -287,17 +287,17 @@ static const struct file_operations interrupt_enable_fops = {
.write = interrupt_enable_write,
};

-static int setup_debugfs(struct rmi_function_container *fc)
+static int setup_debugfs(struct rmi_function *fn)
{
- struct f01_data *data = fc->data;
+ struct f01_data *data = fn->data;

- if (!fc->debugfs_root)
+ if (!fn->debugfs_root)
return -ENODEV;

data->debugfs_interrupt_enable = debugfs_create_file("interrupt_enable",
- RMI_RW_ATTR, fc->debugfs_root, fc, &interrupt_enable_fops);
+ RMI_RW_ATTR, fn->debugfs_root, fn, &interrupt_enable_fops);
if (!data->debugfs_interrupt_enable)
- dev_warn(&fc->dev,
+ dev_warn(&fn->dev,
"Failed to create debugfs interrupt_enable.\n");

return 0;
@@ -311,7 +311,7 @@ static void teardown_debugfs(struct f01_data *f01)

#else

-static inline int setup_debugfs(struct rmi_function_container *fc)
+static inline int setup_debugfs(struct rmi_function *fn)
{
return 0;
}
@@ -326,8 +326,8 @@ static ssize_t rmi_fn_01_productinfo_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
data->basic_queries.productinfo_1,
@@ -338,8 +338,8 @@ static ssize_t rmi_fn_01_productid_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%s\n", data->product_id);
}
@@ -348,8 +348,8 @@ static ssize_t rmi_fn_01_manufacturer_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "0x%02x\n",
data->basic_queries.manufacturer_id);
@@ -359,8 +359,8 @@ static ssize_t rmi_fn_01_datecode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "20%02u-%02u-%02u\n",
data->basic_queries.year,
@@ -372,7 +372,7 @@ static ssize_t rmi_fn_01_reset_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
+ struct rmi_function *fn = to_rmi_function(dev);
unsigned int reset;
int retval = 0;

@@ -388,7 +388,7 @@ static ssize_t rmi_fn_01_reset_store(struct device *dev,
struct f01_device_commands commands = {
.reset = 1
};
- retval = rmi_write_block(fc->rmi_dev, fc->fd.command_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.command_base_addr,
&commands, sizeof(commands));
if (retval < 0) {
dev_err(dev, "Failed to issue reset command, code = %d.",
@@ -404,8 +404,8 @@ static ssize_t rmi_fn_01_sleepmode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE,
"%d\n", data->device_control.ctrl0.sleep_mode);
@@ -415,8 +415,8 @@ static ssize_t rmi_fn_01_sleepmode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;

@@ -428,7 +428,7 @@ static ssize_t rmi_fn_01_sleepmode_store(struct device *dev,

dev_dbg(dev, "Setting sleep mode to %ld.", new_value);
data->device_control.ctrl0.sleep_mode = new_value;
- retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval >= 0)
@@ -441,8 +441,8 @@ static ssize_t rmi_fn_01_sleepmode_store(struct device *dev,
static ssize_t rmi_fn_01_nosleep_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.ctrl0.nosleep);
@@ -452,8 +452,8 @@ static ssize_t rmi_fn_01_nosleep_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;

@@ -464,7 +464,7 @@ static ssize_t rmi_fn_01_nosleep_store(struct device *dev,
}

data->device_control.ctrl0.nosleep = new_value;
- retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval >= 0)
@@ -478,8 +478,8 @@ static ssize_t rmi_fn_01_nosleep_store(struct device *dev,
static ssize_t rmi_fn_01_chargerinput_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.ctrl0.charger_input);
@@ -489,8 +489,8 @@ static ssize_t rmi_fn_01_chargerinput_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;

@@ -501,7 +501,7 @@ static ssize_t rmi_fn_01_chargerinput_store(struct device *dev,
}

data->device_control.ctrl0.charger_input = new_value;
- retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval >= 0)
@@ -515,8 +515,8 @@ static ssize_t rmi_fn_01_chargerinput_store(struct device *dev,
static ssize_t rmi_fn_01_reportrate_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.ctrl0.report_rate);
@@ -526,8 +526,8 @@ static ssize_t rmi_fn_01_reportrate_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;

@@ -538,7 +538,7 @@ static ssize_t rmi_fn_01_reportrate_store(struct device *dev,
}

data->device_control.ctrl0.report_rate = new_value;
- retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval >= 0)
@@ -552,8 +552,8 @@ static ssize_t rmi_fn_01_reportrate_store(struct device *dev,
static ssize_t rmi_fn_01_interrupt_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
int i, len, total_len = 0;
char *current_buf = buf;

@@ -598,8 +598,8 @@ static ssize_t rmi_fn_01_interrupt_enable_show(struct device *dev,
static ssize_t rmi_fn_01_doze_interval_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.doze_interval);
@@ -610,8 +610,8 @@ static ssize_t rmi_fn_01_doze_interval_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;
u16 ctrl_base_addr;
@@ -623,12 +623,12 @@ static ssize_t rmi_fn_01_doze_interval_store(struct device *dev,
}

data->device_control.doze_interval = new_value;
- ctrl_base_addr = fc->fd.control_base_addr + sizeof(u8) +
+ ctrl_base_addr = fn->fd.control_base_addr + sizeof(u8) +
(sizeof(u8)*(data->num_of_irq_regs));
dev_dbg(dev, "doze_interval store address %x, value %d",
ctrl_base_addr, data->device_control.doze_interval);

- retval = rmi_write_block(fc->rmi_dev, data->doze_interval_addr,
+ retval = rmi_write_block(fn->rmi_dev, data->doze_interval_addr,
&data->device_control.doze_interval,
sizeof(u8));
if (retval >= 0)
@@ -644,8 +644,8 @@ static ssize_t rmi_fn_01_wakeup_threshold_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.wakeup_threshold);
@@ -655,8 +655,8 @@ static ssize_t rmi_fn_01_wakeup_threshold_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;

@@ -667,7 +667,7 @@ static ssize_t rmi_fn_01_wakeup_threshold_store(struct device *dev,
}

data->device_control.doze_interval = new_value;
- retval = rmi_write_block(fc->rmi_dev, data->wakeup_threshold_addr,
+ retval = rmi_write_block(fn->rmi_dev, data->wakeup_threshold_addr,
&data->device_control.wakeup_threshold,
sizeof(u8));
if (retval >= 0)
@@ -682,8 +682,8 @@ static ssize_t rmi_fn_01_doze_holdoff_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.doze_holdoff);
@@ -695,8 +695,8 @@ static ssize_t rmi_fn_01_doze_holdoff_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
unsigned long new_value;
int retval;

@@ -707,7 +707,7 @@ static ssize_t rmi_fn_01_doze_holdoff_store(struct device *dev,
}

data->device_control.doze_interval = new_value;
- retval = rmi_write_block(fc->rmi_dev, data->doze_holdoff_addr,
+ retval = rmi_write_block(fn->rmi_dev, data->doze_holdoff_addr,
&data->device_control.doze_holdoff,
sizeof(u8));
if (retval >= 0)
@@ -722,8 +722,8 @@ static ssize_t rmi_fn_01_doze_holdoff_store(struct device *dev,
static ssize_t rmi_fn_01_configured_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_control.ctrl0.configured);
@@ -732,8 +732,8 @@ static ssize_t rmi_fn_01_configured_show(struct device *dev,
static ssize_t rmi_fn_01_unconfigured_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_status.unconfigured);
@@ -742,8 +742,8 @@ static ssize_t rmi_fn_01_unconfigured_show(struct device *dev,
static ssize_t rmi_fn_01_flashprog_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "%d\n",
data->device_status.flash_prog);
@@ -752,8 +752,8 @@ static ssize_t rmi_fn_01_flashprog_show(struct device *dev,
static ssize_t rmi_fn_01_statuscode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;

return snprintf(buf, PAGE_SIZE, "0x%02x\n",
data->device_status.status_code);
@@ -835,8 +835,8 @@ static umode_t rmi_fn_01_attr_visible(struct kobject *kobj,
struct attribute *attr, int n)
{
struct device *dev = kobj_to_dev(kobj);
- struct rmi_function_container *fc = to_rmi_function_container(dev);
- struct f01_data *data = fc->data;
+ struct rmi_function *fn = to_rmi_function(dev);
+ struct f01_data *data = fn->data;
umode_t mode = attr->mode;

if (attr == &dev_attr_doze_interval.attr) {
@@ -858,47 +858,47 @@ static struct attribute_group rmi_fn_01_attr_group = {
.attrs = rmi_fn_01_attrs,
};

-static int rmi_f01_alloc_memory(struct rmi_function_container *fc,
+static int rmi_f01_alloc_memory(struct rmi_function *fn,
int num_of_irq_regs)
{
struct f01_data *f01;

- f01 = devm_kzalloc(&fc->dev, sizeof(struct f01_data), GFP_KERNEL);
+ f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL);
if (!f01) {
- dev_err(&fc->dev, "Failed to allocate fn_01_data.\n");
+ dev_err(&fn->dev, "Failed to allocate fn_01_data.\n");
return -ENOMEM;
}

- f01->device_control.interrupt_enable = devm_kzalloc(&fc->dev,
+ f01->device_control.interrupt_enable = devm_kzalloc(&fn->dev,
sizeof(u8)*(num_of_irq_regs),
GFP_KERNEL);
if (!f01->device_control.interrupt_enable) {
- dev_err(&fc->dev, "Failed to allocate interrupt enable.\n");
+ dev_err(&fn->dev, "Failed to allocate interrupt enable.\n");
return -ENOMEM;
}
- fc->data = f01;
+ fn->data = f01;

return 0;
}

-static int rmi_f01_initialize(struct rmi_function_container *fc)
+static int rmi_f01_initialize(struct rmi_function *fn)
{
u8 temp;
int error;
u16 ctrl_base_addr;
- struct rmi_device *rmi_dev = fc->rmi_dev;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
- struct f01_data *data = fc->data;
+ struct f01_data *data = fn->data;
struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);

/* Set the configured bit and (optionally) other important stuff
* in the device control register. */
- ctrl_base_addr = fc->fd.control_base_addr;
- error = rmi_read_block(rmi_dev, fc->fd.control_base_addr,
+ ctrl_base_addr = fn->fd.control_base_addr;
+ error = rmi_read_block(rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (error < 0) {
- dev_err(&fc->dev, "Failed to read F01 control.\n");
+ dev_err(&fn->dev, "Failed to read F01 control.\n");
return error;
}
switch (pdata->power_management.nosleep) {
@@ -916,17 +916,17 @@ static int rmi_f01_initialize(struct rmi_function_container *fc)
* is certain to function.
*/
if (data->device_control.ctrl0.sleep_mode != RMI_SLEEP_MODE_NORMAL) {
- dev_warn(&fc->dev,
+ dev_warn(&fn->dev,
"WARNING: Non-zero sleep mode found. Clearing...\n");
data->device_control.ctrl0.sleep_mode = RMI_SLEEP_MODE_NORMAL;
}

data->device_control.ctrl0.configured = 1;
- error = rmi_write_block(rmi_dev, fc->fd.control_base_addr,
+ error = rmi_write_block(rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (error < 0) {
- dev_err(&fc->dev, "Failed to write F01 control.\n");
+ dev_err(&fn->dev, "Failed to write F01 control.\n");
return error;
}

@@ -939,35 +939,35 @@ static int rmi_f01_initialize(struct rmi_function_container *fc)
data->device_control.interrupt_enable,
sizeof(u8)*(data->num_of_irq_regs));
if (error < 0) {
- dev_err(&fc->dev, "Failed to read F01 control interrupt enable register.\n");
+ dev_err(&fn->dev, "Failed to read F01 control interrupt enable register.\n");
goto error_exit;
}
ctrl_base_addr += data->num_of_irq_regs;

/* dummy read in order to clear irqs */
- error = rmi_read(rmi_dev, fc->fd.data_base_addr + 1, &temp);
+ error = rmi_read(rmi_dev, fn->fd.data_base_addr + 1, &temp);
if (error < 0) {
- dev_err(&fc->dev, "Failed to read Interrupt Status.\n");
+ dev_err(&fn->dev, "Failed to read Interrupt Status.\n");
return error;
}

- error = rmi_read_block(rmi_dev, fc->fd.query_base_addr,
+ error = rmi_read_block(rmi_dev, fn->fd.query_base_addr,
&data->basic_queries,
sizeof(data->basic_queries));
if (error < 0) {
- dev_err(&fc->dev, "Failed to read device query registers.\n");
+ dev_err(&fn->dev, "Failed to read device query registers.\n");
return error;
}

error = rmi_read_block(rmi_dev,
- fc->fd.query_base_addr + sizeof(data->basic_queries),
+ fn->fd.query_base_addr + sizeof(data->basic_queries),
data->product_id, RMI_PRODUCT_ID_LENGTH);
if (error < 0) {
- dev_err(&fc->dev, "Failed to read product ID.\n");
+ dev_err(&fn->dev, "Failed to read product ID.\n");
return error;
}
data->product_id[RMI_PRODUCT_ID_LENGTH] = '\0';
- dev_info(&fc->dev, "found RMI device, manufacturer: %s, product: %s\n",
+ dev_info(&fn->dev, "found RMI device, manufacturer: %s, product: %s\n",
data->basic_queries.manufacturer_id == 1 ?
"synaptics" : "unknown",
data->product_id);
@@ -983,14 +983,14 @@ static int rmi_f01_initialize(struct rmi_function_container *fc)
error = rmi_write(rmi_dev, data->doze_interval_addr,
data->device_control.doze_interval);
if (error < 0) {
- dev_err(&fc->dev, "Failed to configure F01 doze interval register.\n");
+ dev_err(&fn->dev, "Failed to configure F01 doze interval register.\n");
goto error_exit;
}
} else {
error = rmi_read(rmi_dev, data->doze_interval_addr,
&data->device_control.doze_interval);
if (error < 0) {
- dev_err(&fc->dev, "Failed to read F01 doze interval register.\n");
+ dev_err(&fn->dev, "Failed to read F01 doze interval register.\n");
goto error_exit;
}
}
@@ -1004,14 +1004,14 @@ static int rmi_f01_initialize(struct rmi_function_container *fc)
error = rmi_write(rmi_dev, data->wakeup_threshold_addr,
data->device_control.wakeup_threshold);
if (error < 0) {
- dev_err(&fc->dev, "Failed to configure F01 wakeup threshold register.\n");
+ dev_err(&fn->dev, "Failed to configure F01 wakeup threshold register.\n");
goto error_exit;
}
} else {
error = rmi_read(rmi_dev, data->wakeup_threshold_addr,
&data->device_control.wakeup_threshold);
if (error < 0) {
- dev_err(&fc->dev, "Failed to read F01 wakeup threshold register.\n");
+ dev_err(&fn->dev, "Failed to read F01 wakeup threshold register.\n");
goto error_exit;
}
}
@@ -1027,36 +1027,36 @@ static int rmi_f01_initialize(struct rmi_function_container *fc)
error = rmi_write(rmi_dev, data->doze_holdoff_addr,
data->device_control.doze_holdoff);
if (error < 0) {
- dev_err(&fc->dev, "Failed to configure F01 doze holdoff register.\n");
+ dev_err(&fn->dev, "Failed to configure F01 doze holdoff register.\n");
goto error_exit;
}
} else {
error = rmi_read(rmi_dev, data->doze_holdoff_addr,
&data->device_control.doze_holdoff);
if (error < 0) {
- dev_err(&fc->dev, "Failed to read F01 doze holdoff register.\n");
+ dev_err(&fn->dev, "Failed to read F01 doze holdoff register.\n");
goto error_exit;
}
}
}

- error = rmi_read_block(rmi_dev, fc->fd.data_base_addr,
+ error = rmi_read_block(rmi_dev, fn->fd.data_base_addr,
&data->device_status, sizeof(data->device_status));
if (error < 0) {
- dev_err(&fc->dev, "Failed to read device status.\n");
+ dev_err(&fn->dev, "Failed to read device status.\n");
goto error_exit;
}

if (data->device_status.unconfigured) {
- dev_err(&fc->dev, "Device reset during configuration process, status: %#02x!\n",
+ dev_err(&fn->dev, "Device reset during configuration process, status: %#02x!\n",
data->device_status.status_code);
error = -EINVAL;
goto error_exit;
}

- error = setup_debugfs(fc);
+ error = setup_debugfs(fn);
if (error)
- dev_warn(&fc->dev, "Failed to setup debugfs, error: %d.\n",
+ dev_warn(&fn->dev, "Failed to setup debugfs, error: %d.\n",
error);

return 0;
@@ -1066,75 +1066,75 @@ static int rmi_f01_initialize(struct rmi_function_container *fc)
return error;
}

-static int rmi_f01_config(struct rmi_function_container *fc)
+static int rmi_f01_config(struct rmi_function *fn)
{
- struct f01_data *data = fc->data;
+ struct f01_data *data = fn->data;
int retval;

- retval = rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval < 0) {
- dev_err(&fc->dev, "Failed to write device_control.reg.\n");
+ dev_err(&fn->dev, "Failed to write device_control.reg.\n");
return retval;
}

- retval = rmi_write_block(fc->rmi_dev, data->interrupt_enable_addr,
+ retval = rmi_write_block(fn->rmi_dev, data->interrupt_enable_addr,
data->device_control.interrupt_enable,
sizeof(u8)*(data->num_of_irq_regs));

if (retval < 0) {
- dev_err(&fc->dev, "Failed to write interrupt enable.\n");
+ dev_err(&fn->dev, "Failed to write interrupt enable.\n");
return retval;
}
if (data->basic_queries.has_lts) {
- retval = rmi_write_block(fc->rmi_dev, data->doze_interval_addr,
+ retval = rmi_write_block(fn->rmi_dev, data->doze_interval_addr,
&data->device_control.doze_interval,
sizeof(u8));
if (retval < 0) {
- dev_err(&fc->dev, "Failed to write doze interval.\n");
+ dev_err(&fn->dev, "Failed to write doze interval.\n");
return retval;
}
}

if (data->basic_queries.has_adjustable_doze) {
retval = rmi_write_block(
- fc->rmi_dev, data->wakeup_threshold_addr,
+ fn->rmi_dev, data->wakeup_threshold_addr,
&data->device_control.wakeup_threshold,
sizeof(u8));
if (retval < 0) {
- dev_err(&fc->dev, "Failed to write wakeup threshold.\n");
+ dev_err(&fn->dev, "Failed to write wakeup threshold.\n");
return retval;
}
}

if (data->basic_queries.has_adjustable_doze_holdoff) {
- retval = rmi_write_block(fc->rmi_dev, data->doze_holdoff_addr,
+ retval = rmi_write_block(fn->rmi_dev, data->doze_holdoff_addr,
&data->device_control.doze_holdoff,
sizeof(u8));
if (retval < 0) {
- dev_err(&fc->dev, "Failed to write doze holdoff.\n");
+ dev_err(&fn->dev, "Failed to write doze holdoff.\n");
return retval;
}
}
return 0;
}

-static int f01_device_init(struct rmi_function_container *fc)
+static int f01_device_init(struct rmi_function *fn)
{
struct rmi_driver_data *driver_data =
- dev_get_drvdata(&fc->rmi_dev->dev);
+ dev_get_drvdata(&fn->rmi_dev->dev);
int error;

- error = rmi_f01_alloc_memory(fc, driver_data->num_of_irq_regs);
+ error = rmi_f01_alloc_memory(fn, driver_data->num_of_irq_regs);
if (error)
return error;

- error = rmi_f01_initialize(fc);
+ error = rmi_f01_initialize(fn);
if (error)
return error;

- error = sysfs_create_group(&fc->dev.kobj, &rmi_fn_01_attr_group);
+ error = sysfs_create_group(&fn->dev.kobj, &rmi_fn_01_attr_group);
if (error)
return error;

@@ -1142,10 +1142,10 @@ static int f01_device_init(struct rmi_function_container *fc)
}

#ifdef CONFIG_PM
-static int rmi_f01_suspend(struct rmi_function_container *fc)
+static int rmi_f01_suspend(struct rmi_function *fn)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
- struct f01_data *data = fc->data;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
+ struct f01_data *data = fn->data;
int retval = 0;

if (data->suspended)
@@ -1156,11 +1156,11 @@ static int rmi_f01_suspend(struct rmi_function_container *fc)
data->device_control.ctrl0.sleep_mode = RMI_SLEEP_MODE_SENSOR_SLEEP;

retval = rmi_write_block(rmi_dev,
- fc->fd.control_base_addr,
+ fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval < 0) {
- dev_err(&fc->dev, "Failed to write sleep mode. Code: %d.\n",
+ dev_err(&fn->dev, "Failed to write sleep mode. Code: %d.\n",
retval);
data->device_control.ctrl0.nosleep = data->old_nosleep;
data->device_control.ctrl0.sleep_mode = RMI_SLEEP_MODE_NORMAL;
@@ -1172,10 +1172,10 @@ static int rmi_f01_suspend(struct rmi_function_container *fc)
return retval;
}

-static int rmi_f01_resume(struct rmi_function_container *fc)
+static int rmi_f01_resume(struct rmi_function *fn)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
- struct f01_data *data = fc->data;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
+ struct f01_data *data = fn->data;
int retval = 0;

if (!data->suspended)
@@ -1184,11 +1184,11 @@ static int rmi_f01_resume(struct rmi_function_container *fc)
data->device_control.ctrl0.nosleep = data->old_nosleep;
data->device_control.ctrl0.sleep_mode = RMI_SLEEP_MODE_NORMAL;

- retval = rmi_write_block(rmi_dev, fc->fd.control_base_addr,
+ retval = rmi_write_block(rmi_dev, fn->fd.control_base_addr,
&data->device_control.ctrl0,
sizeof(data->device_control.ctrl0));
if (retval < 0)
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to restore normal operation. Code: %d.\n",
retval);
else {
@@ -1202,30 +1202,30 @@ static int rmi_f01_resume(struct rmi_function_container *fc)

static int f01_remove(struct device *dev)
{
- struct rmi_function_container *fc = to_rmi_function_container(dev);
+ struct rmi_function *fn = to_rmi_function(dev);

- teardown_debugfs(fc->data);
- sysfs_remove_group(&fc->dev.kobj, &rmi_fn_01_attr_group);
+ teardown_debugfs(fn->data);
+ sysfs_remove_group(&fn->dev.kobj, &rmi_fn_01_attr_group);

return 0;
}

-static int rmi_f01_attention(struct rmi_function_container *fc,
+static int rmi_f01_attention(struct rmi_function *fn,
unsigned long *irq_bits)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
- struct f01_data *data = fc->data;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
+ struct f01_data *data = fn->data;
int retval;

- retval = rmi_read_block(rmi_dev, fc->fd.data_base_addr,
+ retval = rmi_read_block(rmi_dev, fn->fd.data_base_addr,
&data->device_status, sizeof(data->device_status));
if (retval < 0) {
- dev_err(&fc->dev, "Failed to read device status, code: %d.\n",
+ dev_err(&fn->dev, "Failed to read device status, code: %d.\n",
retval);
return retval;
}
if (data->device_status.unconfigured) {
- dev_warn(&fc->dev, "Device reset detected.\n");
+ dev_warn(&fn->dev, "Device reset detected.\n");
retval = rmi_dev->driver->reset_handler(rmi_dev);
if (retval < 0)
return retval;
@@ -1235,16 +1235,16 @@ static int rmi_f01_attention(struct rmi_function_container *fc,

static int f01_probe(struct device *dev)
{
- struct rmi_function_container *fc;
+ struct rmi_function *fn;

if (dev->type != &rmi_function_type)
return 1;

- fc = to_rmi_function_container(dev);
- if (fc->fd.function_number != FUNCTION_NUMBER)
+ fn = to_rmi_function(dev);
+ if (fn->fd.function_number != FUNCTION_NUMBER)
return 1;

- return f01_device_init(fc);
+ return f01_device_init(fn);
}

static struct rmi_function_handler function_handler = {
diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
index b9a84bc..dd270b4 100644
--- a/drivers/input/rmi4/rmi_f11.c
+++ b/drivers/input/rmi4/rmi_f11.c
@@ -825,7 +825,7 @@ struct f11_2d_sensor {
enum rmi_f11_sensor_type sensor_type;
struct input_dev *input;
struct input_dev *mouse_input;
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
char input_phys[NAME_BUFFER_SIZE];
char input_phys_mouse[NAME_BUFFER_SIZE];

@@ -876,11 +876,11 @@ static ssize_t f11_maxPos_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
struct f11_data *data;

- fc = to_rmi_function_container(dev);
- data = fc->data;
+ fn = to_rmi_function(dev);
+ data = fn->data;

return snprintf(buf, PAGE_SIZE, "%u %u\n",
data->sensors[0].max_x, data->sensors[0].max_y);
@@ -890,11 +890,11 @@ static ssize_t f11_relreport_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
struct f11_data *instance_data;

- fc = to_rmi_function_container(dev);
- instance_data = fc->data;
+ fn = to_rmi_function(dev);
+ instance_data = fn->data;

return snprintf(buf, PAGE_SIZE, "%u\n",
instance_data->
@@ -906,12 +906,12 @@ static ssize_t f11_relreport_store(struct device *dev,
const char *buf,
size_t count)
{
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
struct f11_data *instance_data;
unsigned int new_value;

- fc = to_rmi_function_container(dev);
- instance_data = fc->data;
+ fn = to_rmi_function(dev);
+ instance_data = fn->data;


if (sscanf(buf, "%u", &new_value) != 1)
@@ -927,11 +927,11 @@ static ssize_t f11_rezero_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct rmi_function_container *fc = NULL;
+ struct rmi_function *fn = NULL;
unsigned int rezero;
int retval = 0;

- fc = to_rmi_function_container(dev);
+ fn = to_rmi_function(dev);

if (sscanf(buf, "%u", &rezero) != 1)
return -EINVAL;
@@ -945,7 +945,7 @@ static ssize_t f11_rezero_store(struct device *dev,
.rezero = true,
};

- retval = rmi_write_block(fc->rmi_dev, fc->fd.command_base_addr,
+ retval = rmi_write_block(fn->rmi_dev, fn->fd.command_base_addr,
&commands, sizeof(commands));
if (retval < 0) {
dev_err(dev, "%s: failed to issue rezero command, error = %d.",
@@ -1058,7 +1058,7 @@ static ssize_t delta_threshold_read(struct file *filp, char __user *buffer,
int retval;
char *local_buf;
struct sensor_debugfs_data *data = filp->private_data;
- struct f11_data *f11 = data->sensor->fc->data;
+ struct f11_data *f11 = data->sensor->fn->data;
struct f11_2d_ctrl *ctrl = &f11->dev_controls;

if (data->done)
@@ -1090,9 +1090,9 @@ static ssize_t delta_threshold_write(struct file *filp,
u8 save_X, save_Y;
int rc;
struct sensor_debugfs_data *data = filp->private_data;
- struct f11_data *f11 = data->sensor->fc->data;
+ struct f11_data *f11 = data->sensor->fn->data;
struct f11_2d_ctrl *ctrl = &f11->dev_controls;
- struct rmi_device *rmi_dev = data->sensor->fc->rmi_dev;
+ struct rmi_device *rmi_dev = data->sensor->fn->rmi_dev;

local_buf = kcalloc(size, sizeof(u8), GFP_KERNEL);
if (!local_buf)
@@ -1117,7 +1117,7 @@ static ssize_t delta_threshold_write(struct file *filp,
rc = rmi_write_block(rmi_dev, ctrl->ctrl0_9_address,
ctrl->ctrl0_9, sizeof(*ctrl->ctrl0_9));
if (rc < 0) {
- dev_warn(&data->sensor->fc->dev,
+ dev_warn(&data->sensor->fn->dev,
"Failed to write to delta_threshold. Code: %d.\n",
rc);
ctrl->ctrl0_9->delta_x_threshold = save_X;
@@ -1392,58 +1392,58 @@ static int setup_sensor_debugfs(struct f11_2d_sensor *sensor)
{
int retval = 0;
char fname[NAME_BUFFER_SIZE];
- struct rmi_function_container *fc = sensor->fc;
+ struct rmi_function *fn = sensor->fn;

- if (!fc->debugfs_root)
+ if (!fn->debugfs_root)
return -ENODEV;

retval = snprintf(fname, NAME_BUFFER_SIZE, "flip.%d",
sensor->sensor_index);
sensor->debugfs_flip = debugfs_create_file(fname, RMI_RW_ATTR,
- fc->debugfs_root, sensor, &flip_fops);
+ fn->debugfs_root, sensor, &flip_fops);
if (!sensor->debugfs_flip)
- dev_warn(&fc->dev, "Failed to create debugfs %s.\n",
+ dev_warn(&fn->dev, "Failed to create debugfs %s.\n",
fname);

retval = snprintf(fname, NAME_BUFFER_SIZE, "clip.%d",
sensor->sensor_index);
sensor->debugfs_clip = debugfs_create_file(fname, RMI_RW_ATTR,
- fc->debugfs_root, sensor, &clip_fops);
+ fn->debugfs_root, sensor, &clip_fops);
if (!sensor->debugfs_clip)
- dev_warn(&fc->dev, "Failed to create debugfs %s.\n",
+ dev_warn(&fn->dev, "Failed to create debugfs %s.\n",
fname);

retval = snprintf(fname, NAME_BUFFER_SIZE, "delta_threshold.%d",
sensor->sensor_index);
sensor->debugfs_clip = debugfs_create_file(fname, RMI_RW_ATTR,
- fc->debugfs_root, sensor,
+ fn->debugfs_root, sensor,
&delta_threshold_fops);
if (!sensor->debugfs_delta_threshold)
- dev_warn(&fc->dev, "Failed to create debugfs %s.\n",
+ dev_warn(&fn->dev, "Failed to create debugfs %s.\n",
fname);

retval = snprintf(fname, NAME_BUFFER_SIZE, "offset.%d",
sensor->sensor_index);
sensor->debugfs_offset = debugfs_create_file(fname, RMI_RW_ATTR,
- fc->debugfs_root, sensor, &offset_fops);
+ fn->debugfs_root, sensor, &offset_fops);
if (!sensor->debugfs_offset)
- dev_warn(&fc->dev, "Failed to create debugfs %s.\n",
+ dev_warn(&fn->dev, "Failed to create debugfs %s.\n",
fname);

retval = snprintf(fname, NAME_BUFFER_SIZE, "swap.%d",
sensor->sensor_index);
sensor->debugfs_swap = debugfs_create_file(fname, RMI_RW_ATTR,
- fc->debugfs_root, sensor, &swap_fops);
+ fn->debugfs_root, sensor, &swap_fops);
if (!sensor->debugfs_swap)
- dev_warn(&fc->dev, "Failed to create debugfs %s.\n",
+ dev_warn(&fn->dev, "Failed to create debugfs %s.\n",
fname);

retval = snprintf(fname, NAME_BUFFER_SIZE, "type_a.%d",
sensor->sensor_index);
sensor->debugfs_type_a = debugfs_create_file(fname, RMI_RW_ATTR,
- fc->debugfs_root, sensor, &type_a_fops);
+ fn->debugfs_root, sensor, &type_a_fops);
if (!sensor->debugfs_type_a)
- dev_warn(&fc->dev, "Failed to create debugfs %s.\n",
+ dev_warn(&fn->dev, "Failed to create debugfs %s.\n",
fname);

return retval;
@@ -1469,20 +1469,20 @@ static void teardown_sensor_debugfs(struct f11_2d_sensor *sensor)

struct f11_debugfs_data {
bool done;
- struct rmi_function_container *fc;
+ struct rmi_function *fn;
};

static int f11_debug_open(struct inode *inodep, struct file *filp)
{
struct f11_debugfs_data *data;
- struct rmi_function_container *fc = inodep->i_private;
+ struct rmi_function *fn = inodep->i_private;

- data = devm_kzalloc(&fc->dev, sizeof(struct f11_debugfs_data),
+ data = devm_kzalloc(&fn->dev, sizeof(struct f11_debugfs_data),
GFP_KERNEL);
if (!data)
return -ENOMEM;

- data->fc = fc;
+ data->fn = fn;
filp->private_data = data;
return 0;
}
@@ -1492,7 +1492,7 @@ static ssize_t rezero_wait_read(struct file *filp, char __user *buffer,
int retval;
char *local_buf;
struct f11_debugfs_data *data = filp->private_data;
- struct f11_data *f11 = data->fc->data;
+ struct f11_data *f11 = data->fn->data;

if (data->done)
return 0;
@@ -1519,7 +1519,7 @@ static ssize_t rezero_wait_write(struct file *filp, const char __user *buffer,
char *local_buf;
int new_value;
struct f11_debugfs_data *data = filp->private_data;
- struct f11_data *f11 = data->fc->data;
+ struct f11_data *f11 = data->fn->data;

local_buf = kcalloc(size, sizeof(u8), GFP_KERNEL);
if (!local_buf)
@@ -1547,17 +1547,17 @@ static const struct file_operations rezero_wait_fops = {
.write = rezero_wait_write,
};

-static int setup_f11_debugfs(struct rmi_function_container *fc)
+static int setup_f11_debugfs(struct rmi_function *fn)
{
- struct f11_data *f11 = fc->data;
+ struct f11_data *f11 = fn->data;

- if (!fc->debugfs_root)
+ if (!fn->debugfs_root)
return -ENODEV;

f11->debugfs_rezero_wait = debugfs_create_file("rezero_wait",
- RMI_RW_ATTR, fc->debugfs_root, fc, &rezero_wait_fops);
+ RMI_RW_ATTR, fn->debugfs_root, fn, &rezero_wait_fops);
if (!f11->debugfs_rezero_wait)
- dev_warn(&fc->dev,
+ dev_warn(&fn->dev,
"Failed to create debugfs rezero_wait.\n");

return 0;
@@ -1698,7 +1698,7 @@ static void rmi_f11_abs_pos_report(struct f11_data *f11,
input_report_abs(sensor->input, ABS_MT_ORIENTATION, orient);
input_report_abs(sensor->input, ABS_MT_POSITION_X, x);
input_report_abs(sensor->input, ABS_MT_POSITION_Y, y);
- dev_dbg(&sensor->fc->dev,
+ dev_dbg(&sensor->fn->dev,
"finger[%d]:%d - x:%d y:%d z:%d w_max:%d w_min:%d\n",
n_finger, finger_state, x, y, z, w_max, w_min);
}
@@ -1840,9 +1840,9 @@ static int f11_2d_construct_data(struct f11_2d_sensor *sensor)
return 0;
}

-static int f11_read_control_regs(struct rmi_function_container *fc,
+static int f11_read_control_regs(struct rmi_function *fn,
struct f11_2d_ctrl *ctrl, u16 ctrl_base_addr) {
- struct rmi_device *rmi_dev = fc->rmi_dev;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
u16 read_address = ctrl_base_addr;
int error = 0;

@@ -1850,7 +1850,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address, ctrl->ctrl0_9,
sizeof(*ctrl->ctrl0_9));
if (error < 0) {
- dev_err(&fc->dev, "Failed to read ctrl0, code: %d.\n", error);
+ dev_err(&fn->dev, "Failed to read ctrl0, code: %d.\n", error);
return error;
}
read_address += sizeof(*ctrl->ctrl0_9);
@@ -1859,7 +1859,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl10, sizeof(*ctrl->ctrl10));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl10, code: %d.\n", error);
return error;
}
@@ -1870,7 +1870,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl11, sizeof(*ctrl->ctrl11));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl11, code: %d.\n", error);
return error;
}
@@ -1881,7 +1881,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl14, sizeof(*ctrl->ctrl14));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl14, code: %d.\n", error);
return error;
}
@@ -1892,7 +1892,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl15, sizeof(*ctrl->ctrl15));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl15, code: %d.\n", error);
return error;
}
@@ -1903,7 +1903,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl16, sizeof(*ctrl->ctrl16));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl16, code: %d.\n", error);
return error;
}
@@ -1914,7 +1914,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl17, sizeof(*ctrl->ctrl17));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl17, code: %d.\n", error);
return error;
}
@@ -1925,7 +1925,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl18_19, sizeof(*ctrl->ctrl18_19));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl18_19, code: %d.\n", error);
return error;
}
@@ -1936,7 +1936,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl20_21, sizeof(*ctrl->ctrl20_21));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl20_21, code: %d.\n", error);
return error;
}
@@ -1947,7 +1947,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl22_26, sizeof(*ctrl->ctrl22_26));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl22_26, code: %d.\n", error);
return error;
}
@@ -1958,7 +1958,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl27, sizeof(*ctrl->ctrl27));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl27, code: %d.\n", error);
return error;
}
@@ -1969,7 +1969,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl28, sizeof(*ctrl->ctrl28));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl28, code: %d.\n", error);
return error;
}
@@ -1980,7 +1980,7 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
error = rmi_read_block(rmi_dev, read_address,
ctrl->ctrl29_30, sizeof(*ctrl->ctrl29_30));
if (error < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read ctrl29_30, code: %d.\n", error);
return error;
}
@@ -1989,39 +1989,39 @@ static int f11_read_control_regs(struct rmi_function_container *fc,
return 0;
}

-static int f11_allocate_control_regs(struct rmi_function_container *fc,
+static int f11_allocate_control_regs(struct rmi_function *fn,
struct f11_2d_device_query *device_query,
struct f11_2d_sensor_queries *sensor_query,
struct f11_2d_ctrl *ctrl,
u16 ctrl_base_addr) {

- ctrl->ctrl0_9 = devm_kzalloc(&fc->dev, sizeof(struct f11_2d_ctrl0_9),
+ ctrl->ctrl0_9 = devm_kzalloc(&fn->dev, sizeof(struct f11_2d_ctrl0_9),
GFP_KERNEL);
if (!ctrl->ctrl0_9)
return -ENOMEM;
if (has_gesture_bits(&sensor_query->gesture_info, 0)) {
- ctrl->ctrl10 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl10 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl10), GFP_KERNEL);
if (!ctrl->ctrl10)
return -ENOMEM;
}

if (has_gesture_bits(&sensor_query->gesture_info, 1)) {
- ctrl->ctrl11 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl11 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl11), GFP_KERNEL);
if (!ctrl->ctrl11)
return -ENOMEM;
}

if (device_query->has_query9 && sensor_query->query9.has_pen) {
- ctrl->ctrl20_21 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl20_21 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl20_21), GFP_KERNEL);
if (!ctrl->ctrl20_21)
return -ENOMEM;
}

if (device_query->has_query9 && sensor_query->query9.has_proximity) {
- ctrl->ctrl22_26 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl22_26 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl22_26), GFP_KERNEL);
if (!ctrl->ctrl22_26)
return -ENOMEM;
@@ -2030,14 +2030,14 @@ static int f11_allocate_control_regs(struct rmi_function_container *fc,
if (device_query->has_query9 &&
(sensor_query->query9.has_palm_det_sensitivity ||
sensor_query->query9.has_suppress_on_palm_detect)) {
- ctrl->ctrl27 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl27 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl27), GFP_KERNEL);
if (!ctrl->ctrl27)
return -ENOMEM;
}

if (sensor_query->gesture_info.has_multi_finger_scroll) {
- ctrl->ctrl28 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl28 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl28), GFP_KERNEL);
if (!ctrl->ctrl28)
return -ENOMEM;
@@ -2045,7 +2045,7 @@ static int f11_allocate_control_regs(struct rmi_function_container *fc,

if (device_query->has_query11 &&
sensor_query->features_1.has_z_tuning) {
- ctrl->ctrl29_30 = devm_kzalloc(&fc->dev,
+ ctrl->ctrl29_30 = devm_kzalloc(&fn->dev,
sizeof(struct f11_2d_ctrl29_30), GFP_KERNEL);
if (!ctrl->ctrl29_30)
return -ENOMEM;
@@ -2054,12 +2054,12 @@ static int f11_allocate_control_regs(struct rmi_function_container *fc,
return 0;
}

-static int f11_write_control_regs(struct rmi_function_container *fc,
+static int f11_write_control_regs(struct rmi_function *fn,
struct f11_2d_sensor_queries *query,
struct f11_2d_ctrl *ctrl,
u16 ctrl_base_addr)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
u16 write_address = ctrl_base_addr;
int error;

@@ -2269,9 +2269,9 @@ static int rmi_f11_get_query_parameters(struct rmi_device *rmi_dev,
/* This operation is done in a number of places, so we have a handy routine
* for it.
*/
-static void f11_set_abs_params(struct rmi_function_container *fc, int index)
+static void f11_set_abs_params(struct rmi_function *fn, int index)
{
- struct f11_data *f11 = fc->data;
+ struct f11_data *f11 = fn->data;
struct f11_2d_sensor *sensor = &f11->sensors[index];
struct input_dev *input = sensor->input;
int device_x_max =
@@ -2314,7 +2314,7 @@ static void f11_set_abs_params(struct rmi_function_container *fc, int index)
else
y_max = device_y_max;

- dev_dbg(&fc->dev, "Set ranges X=[%d..%d] Y=[%d..%d].",
+ dev_dbg(&fn->dev, "Set ranges X=[%d..%d] Y=[%d..%d].",
x_min, x_max, y_min, y_max);

input_set_abs_params(input, ABS_MT_PRESSURE, 0,
@@ -2344,9 +2344,9 @@ static void f11_set_abs_params(struct rmi_function_container *fc, int index)
0, MT_TOOL_FINGER, 0, 0);
}

-static int rmi_f11_initialize(struct rmi_function_container *fc)
+static int rmi_f11_initialize(struct rmi_function *fn)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
struct f11_data *f11;
struct f11_2d_ctrl *ctrl;
u8 query_offset;
@@ -2357,21 +2357,21 @@ static int rmi_f11_initialize(struct rmi_function_container *fc)
int i;
struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);

- dev_dbg(&fc->dev, "Initializing F11 values for %s.\n",
+ dev_dbg(&fn->dev, "Initializing F11 values for %s.\n",
pdata->sensor_name);

/*
** init instance data, fill in values and create any sysfs files
*/
- f11 = devm_kzalloc(&fc->dev, sizeof(struct f11_data), GFP_KERNEL);
+ f11 = devm_kzalloc(&fn->dev, sizeof(struct f11_data), GFP_KERNEL);
if (!f11)
return -ENOMEM;

- fc->data = f11;
+ fn->data = f11;
f11->rezero_wait_ms = pdata->f11_rezero_wait;

- query_base_addr = fc->fd.query_base_addr;
- control_base_addr = fc->fd.control_base_addr;
+ query_base_addr = fn->fd.query_base_addr;
+ control_base_addr = fn->fd.control_base_addr;

rc = rmi_read(rmi_dev, query_base_addr, &f11->dev_query);
if (rc < 0)
@@ -2382,7 +2382,7 @@ static int rmi_f11_initialize(struct rmi_function_container *fc)
for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
struct f11_2d_sensor *sensor = &f11->sensors[i];
sensor->sensor_index = i;
- sensor->fc = fc;
+ sensor->fn = fn;

rc = rmi_f11_get_query_parameters(rmi_dev, &f11->dev_query,
&sensor->sens_query, query_offset);
@@ -2390,19 +2390,19 @@ static int rmi_f11_initialize(struct rmi_function_container *fc)
return rc;
query_offset += rc;

- rc = f11_allocate_control_regs(fc,
+ rc = f11_allocate_control_regs(fn,
&f11->dev_query, &sensor->sens_query,
&f11->dev_controls, control_base_addr);
if (rc < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to allocate F11 control params.\n");
return rc;
}

- rc = f11_read_control_regs(fc, &f11->dev_controls,
+ rc = f11_read_control_regs(fn, &f11->dev_controls,
control_base_addr);
if (rc < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"Failed to read F11 control params.\n");
return rc;
}
@@ -2448,7 +2448,7 @@ static int rmi_f11_initialize(struct rmi_function_container *fc)
ctrl->ctrl0_9,
sizeof(*ctrl->ctrl0_9));
if (rc < 0)
- dev_warn(&fc->dev, "Failed to write to delta_x_threshold %d. Code: %d.\n",
+ dev_warn(&fn->dev, "Failed to write to delta_x_threshold %d. Code: %d.\n",
i, rc);

}
@@ -2461,22 +2461,22 @@ static int rmi_f11_initialize(struct rmi_function_container *fc)
ctrl->ctrl0_9,
sizeof(*ctrl->ctrl0_9));
if (rc < 0)
- dev_warn(&fc->dev, "Failed to write to delta_y_threshold %d. Code: %d.\n",
+ dev_warn(&fn->dev, "Failed to write to delta_y_threshold %d. Code: %d.\n",
i, rc);
}

if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
rc = setup_sensor_debugfs(sensor);
if (rc < 0)
- dev_warn(&fc->dev, "Failed to setup debugfs for F11 sensor %d. Code: %d.\n",
+ dev_warn(&fn->dev, "Failed to setup debugfs for F11 sensor %d. Code: %d.\n",
i, rc);
}
}

if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
- rc = setup_f11_debugfs(fc);
+ rc = setup_f11_debugfs(fn);
if (rc < 0)
- dev_warn(&fc->dev, "Failed to setup debugfs for F11. Code: %d.\n",
+ dev_warn(&fn->dev, "Failed to setup debugfs for F11. Code: %d.\n",
rc);
}

@@ -2484,10 +2484,10 @@ static int rmi_f11_initialize(struct rmi_function_container *fc)
return 0;
}

-static int rmi_f11_register_devices(struct rmi_function_container *fc)
+static int rmi_f11_register_devices(struct rmi_function *fn)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
- struct f11_data *f11 = fc->data;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
+ struct f11_data *f11 = fn->data;
struct input_dev *input_dev;
struct input_dev *input_dev_mouse;
struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
@@ -2513,14 +2513,14 @@ static int rmi_f11_register_devices(struct rmi_function_container *fc)
if (driver->set_input_params) {
rc = driver->set_input_params(rmi_dev, input_dev);
if (rc < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"%s: Error in setting input device.\n",
__func__);
goto error_unregister;
}
}
sprintf(sensor->input_phys, "%s.abs%d/input0",
- dev_name(&fc->dev), i);
+ dev_name(&fn->dev), i);
input_dev->phys = sensor->input_phys;
input_dev->dev.parent = &rmi_dev->dev;
input_set_drvdata(input_dev, f11);
@@ -2529,7 +2529,7 @@ static int rmi_f11_register_devices(struct rmi_function_container *fc)
set_bit(EV_ABS, input_dev->evbit);
input_set_capability(input_dev, EV_KEY, BTN_TOUCH);

- f11_set_abs_params(fc, i);
+ f11_set_abs_params(fn, i);

if (sensor->sens_query.info.has_rel) {
set_bit(EV_REL, input_dev->evbit);
@@ -2556,14 +2556,14 @@ static int rmi_f11_register_devices(struct rmi_function_container *fc)
rc = driver->set_input_params(rmi_dev,
input_dev_mouse);
if (rc < 0) {
- dev_err(&fc->dev,
+ dev_err(&fn->dev,
"%s: Error in setting input device.\n",
__func__);
goto error_unregister;
}
}
sprintf(sensor->input_phys_mouse, "%s.rel%d/input0",
- dev_name(&fc->dev), i);
+ dev_name(&fn->dev), i);
set_bit(EV_REL, input_dev_mouse->evbit);
set_bit(REL_X, input_dev_mouse->relbit);
set_bit(REL_Y, input_dev_mouse->relbit);
@@ -2605,9 +2605,9 @@ error_unregister:
return rc;
}

-static void rmi_f11_free_devices(struct rmi_function_container *fc)
+static void rmi_f11_free_devices(struct rmi_function *fn)
{
- struct f11_data *f11 = fc->data;
+ struct f11_data *f11 = fn->data;
int i;

for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
@@ -2618,15 +2618,15 @@ static void rmi_f11_free_devices(struct rmi_function_container *fc)
}
}

-static int rmi_f11_create_sysfs(struct rmi_function_container *fc)
+static int rmi_f11_create_sysfs(struct rmi_function *fn)
{
int attr_count = 0;
int rc;

for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
if (sysfs_create_file
- (&fc->dev.kobj, &attrs[attr_count].attr) < 0) {
- dev_err(&fc->dev, "Failed to create sysfs file for %s.",
+ (&fn->dev.kobj, &attrs[attr_count].attr) < 0) {
+ dev_err(&fn->dev, "Failed to create sysfs file for %s.",
attrs[attr_count].attr.name);
rc = -ENODEV;
goto err_remove_sysfs;
@@ -2637,19 +2637,19 @@ static int rmi_f11_create_sysfs(struct rmi_function_container *fc)

err_remove_sysfs:
for (attr_count--; attr_count >= 0; attr_count--)
- sysfs_remove_file(&fc->dev.kobj, &attrs[attr_count].attr);
+ sysfs_remove_file(&fn->dev.kobj, &attrs[attr_count].attr);
return rc;
}

-static int rmi_f11_config(struct rmi_function_container *fc)
+static int rmi_f11_config(struct rmi_function *fn)
{
- struct f11_data *f11 = fc->data;
+ struct f11_data *f11 = fn->data;
int i;
int rc;

for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
- rc = f11_write_control_regs(fc, &f11->sensors[i].sens_query,
- &f11->dev_controls, fc->fd.query_base_addr);
+ rc = f11_write_control_regs(fn, &f11->sensors[i].sens_query,
+ &f11->dev_controls, fn->fd.query_base_addr);
if (rc < 0)
return rc;
}
@@ -2657,12 +2657,12 @@ static int rmi_f11_config(struct rmi_function_container *fc)
return 0;
}

-int rmi_f11_attention(struct rmi_function_container *fc,
+int rmi_f11_attention(struct rmi_function *fn,
unsigned long *irq_bits)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
- struct f11_data *f11 = fc->data;
- u16 data_base_addr = fc->fd.data_base_addr;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
+ struct f11_data *f11 = fn->data;
+ u16 data_base_addr = fn->fd.data_base_addr;
u16 data_base_addr_offset = 0;
int error;
int i;
@@ -2683,26 +2683,26 @@ int rmi_f11_attention(struct rmi_function_container *fc,
}

#ifdef CONFIG_PM
-static int rmi_f11_resume(struct rmi_function_container *fc)
+static int rmi_f11_resume(struct rmi_function *fn)
{
- struct rmi_device *rmi_dev = fc->rmi_dev;
- struct f11_data *data = fc->data;
+ struct rmi_device *rmi_dev = fn->rmi_dev;
+ struct f11_data *data = fn->data;
/* Command register always reads as 0, so we can just use a local. */
struct f11_2d_commands commands = {
.rezero = true,
};
int retval = 0;

- dev_dbg(&fc->dev, "Resuming...\n");
+ dev_dbg(&fn->dev, "Resuming...\n");
if (!data->rezero_wait_ms)
return 0;

mdelay(data->rezero_wait_ms);

- retval = rmi_write_block(rmi_dev, fc->fd.command_base_addr,
+ retval = rmi_write_block(rmi_dev, fn->fd.command_base_addr,
&commands, sizeof(commands));
if (retval < 0) {
- dev_err(&fc->dev, "%s: failed to issue rezero command, error = %d.",
+ dev_err(&fn->dev, "%s: failed to issue rezero command, error = %d.",
__func__, retval);
return retval;
}
@@ -2715,9 +2715,9 @@ static int f11_remove_device(struct device *dev)
{
int attr_count = 0;
struct f11_data *f11;
- struct rmi_function_container *fc = to_rmi_function_container(dev);
+ struct rmi_function *fn = to_rmi_function(dev);

- f11 = fc->data;
+ f11 = fn->data;

if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
int i;
@@ -2728,25 +2728,25 @@ static int f11_remove_device(struct device *dev)
}

for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++)
- sysfs_remove_file(&fc->dev.kobj, &attrs[attr_count].attr);
+ sysfs_remove_file(&fn->dev.kobj, &attrs[attr_count].attr);

- rmi_f11_free_devices(fc);
+ rmi_f11_free_devices(fn);
return 0;
}

-static int f11_device_init(struct rmi_function_container *fc)
+static int f11_device_init(struct rmi_function *fn)
{
int rc;

- rc = rmi_f11_initialize(fc);
+ rc = rmi_f11_initialize(fn);
if (rc < 0)
return rc;

- rc = rmi_f11_register_devices(fc);
+ rc = rmi_f11_register_devices(fn);
if (rc < 0)
return rc;

- rc = rmi_f11_create_sysfs(fc);
+ rc = rmi_f11_create_sysfs(fn);
if (rc < 0)
return rc;

@@ -2755,16 +2755,16 @@ static int f11_device_init(struct rmi_function_container *fc)

static __devinit int f11_probe(struct device *dev)
{
- struct rmi_function_container *fc;
+ struct rmi_function *fn;

if (dev->type != &rmi_function_type)
return 1;

- fc = to_rmi_function_container(dev);
- if (fc->fd.function_number != FUNCTION_NUMBER)
+ fn = to_rmi_function(dev);
+ if (fn->fd.function_number != FUNCTION_NUMBER)
return 1;

- return f11_device_init(fc);
+ return f11_device_init(fn);
}


diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index a41c874..fa8a352e 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -338,7 +338,7 @@ struct rmi_function_descriptor {
u8 function_version;
};

-struct rmi_function_container;
+struct rmi_function;
struct rmi_device;

/**
@@ -365,13 +365,12 @@ struct rmi_function_handler {
struct device_driver driver;

u8 func;
- int (*config)(struct rmi_function_container *fc);
- int (*reset)(struct rmi_function_container *fc);
- int (*attention)(struct rmi_function_container *fc,
- unsigned long *irq_bits);
+ int (*config)(struct rmi_function *fn);
+ int (*reset)(struct rmi_function *fn);
+ int (*attention)(struct rmi_function *fn, unsigned long *irq_bits);
#ifdef CONFIG_PM
- int (*suspend)(struct rmi_function_container *fc);
- int (*resume)(struct rmi_function_container *fc);
+ int (*suspend)(struct rmi_function *fn);
+ int (*resume)(struct rmi_function *fn);
#endif
};

@@ -379,7 +378,7 @@ struct rmi_function_handler {
container_of(d, struct rmi_function_handler, driver)

/**
- * struct rmi_function_container - represents the implementation of an RMI4
+ * 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
@@ -396,8 +395,7 @@ struct rmi_function_handler {
* @debugfs_root: used during debugging
*
*/
-struct rmi_function_container {
-
+struct rmi_function {
struct rmi_function_descriptor fd;
struct rmi_device *rmi_dev;
struct device dev;
@@ -412,8 +410,8 @@ struct rmi_function_container {
#endif
};

-#define to_rmi_function_container(d) \
- container_of(d, struct rmi_function_container, dev)
+#define to_rmi_function(d) \
+ container_of(d, struct rmi_function, dev)

/**
* struct rmi_driver - driver for an RMI4 sensor on the RMI bus.
--
1.7.11.7


2012-11-27 09:21:47

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 2/4] Input: RMI4 - move sensor driver and F01 handler into the core

There is no point in having the sensor driver and F01 handler separate
from the RMI core since it is not useful without them and having them
all together simplifies initialization among other things.

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/input/rmi4/Kconfig | 23 ++++++-----------------
drivers/input/rmi4/Makefile | 10 +++++++---
drivers/input/rmi4/rmi_bus.c | 41 ++++++++++++++++++++++++++++++++---------
drivers/input/rmi4/rmi_driver.c | 36 ++++++++++++++----------------------
drivers/input/rmi4/rmi_driver.h | 6 ++++++
drivers/input/rmi4/rmi_f01.c | 22 +++-------------------
6 files changed, 68 insertions(+), 70 deletions(-)

diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index 41cbbee..d0c7b6e 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -1,8 +1,8 @@
#
# RMI4 configuration
#
-config RMI4_BUS
- bool "Synaptics RMI4 bus support"
+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.
@@ -13,7 +13,7 @@ config RMI4_BUS

config RMI4_DEBUG
bool "RMI4 Debugging"
- depends on RMI4_BUS
+ depends on RMI4_CORE
select DEBUG_FS
help
Say Y here to enable debug feature in the RMI4 driver.
@@ -26,8 +26,8 @@ config RMI4_DEBUG
If unsure, say N.

config RMI4_I2C
- bool "RMI4 I2C Support"
- depends on RMI4_BUS && I2C
+ tristate "RMI4 I2C Support"
+ depends on RMI4_CORE && I2C
help
Say Y here if you want to support RMI4 devices connected to an I2C
bus.
@@ -36,20 +36,9 @@ config RMI4_I2C

This feature is not currently available as a loadable module.

-config RMI4_GENERIC
- bool "RMI4 Generic driver"
- depends on RMI4_BUS
- help
- Say Y here if you want to support generic RMI4 devices.
-
- This is pretty much required if you want to do anything useful with
- your RMI device.
-
- This feature is not currently available as a loadable module.
-
config RMI4_F11
tristate "RMI4 Function 11 (2D pointing)"
- depends on RMI4_BUS && RMI4_GENERIC
+ depends on RMI4_CORE
help
Say Y here if you want to add support for RMI4 function 11.

diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index 8882c3d..5c6bad5 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -1,8 +1,12 @@
-obj-$(CONFIG_RMI4_BUS) += rmi_bus.o
-obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o
-obj-$(CONFIG_RMI4_GENERIC) += rmi_driver.o rmi_f01.o
+obj-$(CONFIG_RMI4_CORE) += rmi_core.o
+rmi_core-y := rmi_bus.o rmi_driver.o rmi_f01.o
+
+# Function drivers
obj-$(CONFIG_RMI4_F11) += rmi_f11.o

+# Transports
+obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o
+
ccflags-$(CONFIG_RMI4_DEBUG) += -DDEBUG

ifeq ($(KERNELRELEASE),)
diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index a912349..47cf0d5 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -206,6 +206,27 @@ static int __init rmi_bus_init(void)

mutex_init(&rmi_bus_mutex);

+ 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_f01_handler();
+ if (error) {
+ pr_err("%s: error registering the RMI F01 handler: %d\n",
+ __func__, error);
+ goto err_unregister_bus;
+ }
+
+ error = rmi_register_sensor_driver();
+ if (error) {
+ pr_err("%s: error registering the RMI sensor driver: %d\n",
+ __func__, error);
+ goto err_unregister_f01;
+ }
+
if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
rmi_debugfs_root = debugfs_create_dir(rmi_bus_type.name, NULL);
if (!rmi_debugfs_root)
@@ -218,24 +239,26 @@ static int __init rmi_bus_init(void)
}
}

- error = bus_register(&rmi_bus_type);
- if (error < 0) {
- pr_err("%s: error registering the RMI bus: %d\n", __func__,
- error);
- return error;
- }
- pr_debug("%s: successfully registered RMI bus.\n", __func__);
-
return 0;
+
+err_unregister_f01:
+ rmi_unregister_f01_handler();
+err_unregister_bus:
+ bus_unregister(&rmi_bus_type);
+ return error;
}

static void __exit rmi_bus_exit(void)
{
- /* We should only ever get here if all drivers are unloaded, so
+ /*
+ * We should only ever get here if all drivers are unloaded, so
* all we have to do at this point is unregister ourselves.
*/
if (IS_ENABLED(CONFIG_RMI4_DEBUG) && rmi_debugfs_root)
debugfs_remove(rmi_debugfs_root);
+
+ rmi_unregister_sensor_driver();
+ rmi_unregister_f01_handler();
bus_unregister(&rmi_bus_type);
}

diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index e8a4b52..6b6ac0c 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -1608,7 +1608,7 @@ static int __devinit rmi_driver_probe(struct device *dev)
static UNIVERSAL_DEV_PM_OPS(rmi_driver_pm, rmi_driver_suspend,
rmi_driver_resume, NULL);

-static struct rmi_driver sensor_driver = {
+static struct rmi_driver rmi_sensor_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "rmi_generic",
@@ -1624,38 +1624,30 @@ static struct rmi_driver sensor_driver = {
.set_input_params = rmi_driver_set_input_params,
};

-static int __init rmi_driver_init(void)
+int __init rmi_register_sensor_driver(void)
{
- int retval;
+ int error;

- retval = driver_register(&sensor_driver.driver);
- if (retval) {
+ error = driver_register(&rmi_sensor_driver.driver);
+ if (error) {
pr_err("%s: driver register failed, code=%d.\n", __func__,
- retval);
- return retval;
+ error);
+ return error;
}

/* Ask the bus to let us know when drivers are bound to devices. */
- retval = bus_register_notifier(&rmi_bus_type, &rmi_bus_notifier);
- if (retval) {
+ error = bus_register_notifier(&rmi_bus_type, &rmi_bus_notifier);
+ if (error) {
pr_err("%s: failed to register bus notifier, code=%d.\n",
- __func__, retval);
- return retval;
+ __func__, error);
+ return error;
}

- return retval;
+ return 0;
}

-static void __exit rmi_driver_exit(void)
+void __exit rmi_unregister_sensor_driver(void)
{
bus_unregister_notifier(&rmi_bus_type, &rmi_bus_notifier);
- driver_unregister(&sensor_driver.driver);
+ driver_unregister(&rmi_sensor_driver.driver);
}
-
-module_init(rmi_driver_init);
-module_exit(rmi_driver_exit);
-
-MODULE_AUTHOR("Christopher Heiny <[email protected]");
-MODULE_DESCRIPTION("RMI generic driver");
-MODULE_LICENSE("GPL");
-MODULE_VERSION(RMI_DRIVER_VERSION);
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 1fc4676..e71ffdc 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -136,4 +136,10 @@ extern void rmi4_fw_update(struct rmi_device *rmi_dev,
#define rmi4_fw_update(rmi_dev, f01_pdt, f34_pdt)
#endif

+int rmi_register_sensor_driver(void);
+void rmi_unregister_sensor_driver(void);
+
+int rmi_register_f01_handler(void);
+void rmi_unregister_f01_handler(void);
+
#endif
diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index 5e6bef6..41ac5f0 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -1265,28 +1265,12 @@ static struct rmi_function_handler function_handler = {
#endif /* CONFIG_PM */
};

-static int __init rmi_f01_module_init(void)
+int __init rmi_register_f01_handler(void)
{
- int error;
-
- error = driver_register(&function_handler.driver);
- if (error < 0) {
- pr_err("%s: register failed!\n", __func__);
- return error;
- }
-
- return 0;
+ return driver_register(&function_handler.driver);
}

-static void __exit rmi_f01_module_exit(void)
+void __exit rmi_unregister_f01_handler(void)
{
driver_unregister(&function_handler.driver);
}
-
-module_init(rmi_f01_module_init);
-module_exit(rmi_f01_module_exit);
-
-MODULE_AUTHOR("Christopher Heiny <[email protected]>");
-MODULE_DESCRIPTION("RMI F01 module");
-MODULE_LICENSE("GPL");
-MODULE_VERSION(RMI_DRIVER_VERSION);
--
1.7.11.7

2012-11-27 09:21:51

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 3/4] Input: RMI4 - move function registration into the core

This saves on boilerplate code that is needed in individual modules
implementing function handlers.

Also converted bool bitfields back to u8.

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/input/rmi4/rmi_bus.c | 189 ++++++++++++++++++++++--------
drivers/input/rmi4/rmi_driver.c | 2 +-
drivers/input/rmi4/rmi_driver.h | 6 +-
drivers/input/rmi4/rmi_f01.c | 57 ++-------
drivers/input/rmi4/rmi_f11.c | 250 +++++++++++++++++-----------------------
include/linux/rmi.h | 9 ++
6 files changed, 271 insertions(+), 242 deletions(-)

diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index 47cf0d5..acbfd3d 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -73,51 +73,6 @@ static atomic_t physical_device_count = ATOMIC_INIT(0);
static struct dentry *rmi_debugfs_root;
#endif

-#ifdef CONFIG_PM
-static int rmi_bus_suspend(struct device *dev)
-{
- struct device_driver *driver = dev->driver;
- const struct dev_pm_ops *pm;
-
- if (!driver)
- return 0;
-
- pm = driver->pm;
- if (pm && pm->suspend)
- return pm->suspend(dev);
- if (driver->suspend)
- return driver->suspend(dev, PMSG_SUSPEND);
-
- return 0;
-}
-
-static int rmi_bus_resume(struct device *dev)
-{
- struct device_driver *driver = dev->driver;
- const struct dev_pm_ops *pm;
-
- if (!driver)
- return 0;
-
- pm = driver->pm;
- if (pm && pm->resume)
- return pm->resume(dev);
- if (driver->resume)
- return driver->resume(dev);
-
- return 0;
-}
-#endif
-
-static SIMPLE_DEV_PM_OPS(rmi_bus_pm_ops,
- rmi_bus_suspend, rmi_bus_resume);
-
-struct bus_type rmi_bus_type = {
- .name = "rmi",
- .pm = &rmi_bus_pm_ops
-};
-EXPORT_SYMBOL_GPL(rmi_bus_type);
-
static void release_rmidev_device(struct device *dev)
{
device_unregister(dev);
@@ -184,6 +139,142 @@ void rmi_unregister_phys_device(struct rmi_phys_device *phys)
EXPORT_SYMBOL(rmi_unregister_phys_device);

/**
+ * 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)
+{
+ int error;
+
+ handler->driver.bus = &rmi_bus_type;
+ handler->driver.owner = owner;
+ handler->driver.mod_name = mod_name;
+
+ 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(__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(rmi_unregister_function_handler);
+
+
+static int rmi_function_match(struct device *dev, struct device_driver *drv)
+{
+ struct rmi_function_handler *handler;
+ struct rmi_function *fn;
+
+ if (dev->type != &rmi_function_type)
+ return 0;
+
+ if (drv == &rmi_sensor_driver.driver)
+ return 0;
+
+ fn = to_rmi_function(dev);
+ handler = to_rmi_function_handler(drv);
+
+ 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;
+}
+
+#ifdef CONFIG_PM
+static int rmi_bus_suspend(struct device *dev)
+{
+ struct device_driver *driver = dev->driver;
+ const struct dev_pm_ops *pm;
+
+ if (!driver)
+ return 0;
+
+ pm = driver->pm;
+ if (pm && pm->suspend)
+ return pm->suspend(dev);
+ if (driver->suspend)
+ return driver->suspend(dev, PMSG_SUSPEND);
+
+ return 0;
+}
+
+static int rmi_bus_resume(struct device *dev)
+{
+ struct device_driver *driver = dev->driver;
+ const struct dev_pm_ops *pm;
+
+ if (!driver)
+ return 0;
+
+ pm = driver->pm;
+ if (pm && pm->resume)
+ return pm->resume(dev);
+ if (driver->resume)
+ return driver->resume(dev);
+
+ return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(rmi_bus_pm_ops,
+ rmi_bus_suspend, rmi_bus_resume);
+
+struct bus_type rmi_bus_type = {
+ .match = rmi_function_match,
+ .probe = rmi_function_probe,
+ .remove = rmi_function_remove,
+ .name = "rmi",
+ .pm = &rmi_bus_pm_ops,
+};
+
+/**
* rmi_for_each_dev - provides a way for other parts of the system to enumerate
* the devices on the RMI bus.
*
@@ -198,7 +289,7 @@ int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data))
mutex_unlock(&rmi_bus_mutex);
return retval;
}
-EXPORT_SYMBOL_GPL(rmi_for_each_dev);
+EXPORT_SYMBOL(rmi_for_each_dev);

static int __init rmi_bus_init(void)
{
@@ -213,7 +304,7 @@ static int __init rmi_bus_init(void)
return error;
}

- error = rmi_register_f01_handler();
+ error = rmi_register_function_handler(&rmi_f01_handler);
if (error) {
pr_err("%s: error registering the RMI F01 handler: %d\n",
__func__, error);
@@ -242,7 +333,7 @@ static int __init rmi_bus_init(void)
return 0;

err_unregister_f01:
- rmi_unregister_f01_handler();
+ rmi_unregister_function_handler(&rmi_f01_handler);
err_unregister_bus:
bus_unregister(&rmi_bus_type);
return error;
@@ -258,7 +349,7 @@ static void __exit rmi_bus_exit(void)
debugfs_remove(rmi_debugfs_root);

rmi_unregister_sensor_driver();
- rmi_unregister_f01_handler();
+ rmi_unregister_function_handler(&rmi_f01_handler);
bus_unregister(&rmi_bus_type);
}

diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 6b6ac0c..bbd23f9 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -1608,7 +1608,7 @@ static int __devinit rmi_driver_probe(struct device *dev)
static UNIVERSAL_DEV_PM_OPS(rmi_driver_pm, rmi_driver_suspend,
rmi_driver_resume, NULL);

-static struct rmi_driver rmi_sensor_driver = {
+struct rmi_driver rmi_sensor_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "rmi_generic",
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index e71ffdc..2866f7d 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -136,10 +136,10 @@ extern void rmi4_fw_update(struct rmi_device *rmi_dev,
#define rmi4_fw_update(rmi_dev, f01_pdt, f34_pdt)
#endif

+extern struct rmi_driver rmi_sensor_driver;
+extern struct rmi_function_handler rmi_f01_handler;
+
int rmi_register_sensor_driver(void);
void rmi_unregister_sensor_driver(void);

-int rmi_register_f01_handler(void);
-void rmi_unregister_f01_handler(void);
-
#endif
diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index 41ac5f0..d7461d7 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -26,8 +26,6 @@
#include "rmi_driver.h"
#include "rmi_f01.h"

-#define FUNCTION_NUMBER 0x01
-
/**
* @reset - set this bit to force a firmware reset of the sensor.
*/
@@ -1120,7 +1118,7 @@ static int rmi_f01_config(struct rmi_function *fn)
return 0;
}

-static int f01_device_init(struct rmi_function *fn)
+static int rmi_f01_probe(struct rmi_function *fn)
{
struct rmi_driver_data *driver_data =
dev_get_drvdata(&fn->rmi_dev->dev);
@@ -1141,6 +1139,12 @@ static int f01_device_init(struct rmi_function *fn)
return 0;
}

+static void rmi_f01_remove(struct rmi_function *fn)
+{
+ teardown_debugfs(fn->data);
+ sysfs_remove_group(&fn->dev.kobj, &rmi_fn_01_attr_group);
+}
+
#ifdef CONFIG_PM
static int rmi_f01_suspend(struct rmi_function *fn)
{
@@ -1200,18 +1204,8 @@ static int rmi_f01_resume(struct rmi_function *fn)
}
#endif /* CONFIG_PM */

-static int f01_remove(struct device *dev)
-{
- struct rmi_function *fn = to_rmi_function(dev);
-
- teardown_debugfs(fn->data);
- sysfs_remove_group(&fn->dev.kobj, &rmi_fn_01_attr_group);
-
- return 0;
-}
-
static int rmi_f01_attention(struct rmi_function *fn,
- unsigned long *irq_bits)
+ unsigned long *irq_bits)
{
struct rmi_device *rmi_dev = fn->rmi_dev;
struct f01_data *data = fn->data;
@@ -1233,44 +1227,17 @@ static int rmi_f01_attention(struct rmi_function *fn,
return 0;
}

-static int f01_probe(struct device *dev)
-{
- struct rmi_function *fn;
-
- if (dev->type != &rmi_function_type)
- return 1;
-
- fn = to_rmi_function(dev);
- if (fn->fd.function_number != FUNCTION_NUMBER)
- return 1;
-
- return f01_device_init(fn);
-}
-
-static struct rmi_function_handler function_handler = {
+struct rmi_function_handler rmi_f01_handler = {
.driver = {
- .owner = THIS_MODULE,
.name = "rmi_f01",
- .bus = &rmi_bus_type,
- .probe = f01_probe,
- .remove = f01_remove,
},
- .func = FUNCTION_NUMBER,
+ .func = 0x01,
+ .probe = rmi_f01_probe,
+ .remove = rmi_f01_remove,
.config = rmi_f01_config,
.attention = rmi_f01_attention,
-
#ifdef CONFIG_PM
.suspend = rmi_f01_suspend,
.resume = rmi_f01_resume,
#endif /* CONFIG_PM */
};
-
-int __init rmi_register_f01_handler(void)
-{
- return driver_register(&function_handler.driver);
-}
-
-void __exit rmi_unregister_f01_handler(void)
-{
- driver_unregister(&function_handler.driver);
-}
diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
index dd270b4..dbb6060 100644
--- a/drivers/input/rmi4/rmi_f11.c
+++ b/drivers/input/rmi4/rmi_f11.c
@@ -18,7 +18,6 @@
*/

#define FUNCTION_DATA f11_data
-#define FNUM 11

#include <linux/kernel.h>
#include <linux/delay.h>
@@ -108,7 +107,7 @@
* current capacitive state.
*/
struct f11_2d_commands {
- bool rezero:1;
+ u8 rezero:1;
u8 reserved:7;
} __attribute__((__packed__));

@@ -122,11 +121,11 @@ struct f11_2d_commands {
*/
struct f11_2d_device_query {
u8 nbr_of_sensors:3;
- bool has_query9:1;
- bool has_query11:1;
- bool has_query12:1;
- bool has_query27:1;
- bool has_query28:1;
+ u8 has_query9:1;
+ u8 has_query11:1;
+ u8 has_query12:1;
+ u8 has_query27:1;
+ u8 has_query28:1;
} __attribute__((__packed__));

/** Query registers 1 through 4 are always present.
@@ -148,11 +147,11 @@ struct f11_2d_device_query {
struct f11_2d_sensor_info {
/* query1 */
u8 number_of_fingers:3;
- bool has_rel:1;
- bool has_abs:1;
- bool has_gestures:1;
- bool has_sensitivity_adjust:1;
- bool configurable:1;
+ u8 has_rel:1;
+ u8 has_abs:1;
+ u8 has_gestures:1;
+ u8 has_sensitivity_adjust:1;
+ u8 configurable:1;
/* query2 */
u8 num_of_x_electrodes:7;
u8 reserved_1:1;
@@ -184,12 +183,12 @@ struct f11_2d_sensor_info {
*/
struct f11_2d_abs_info {
u8 abs_data_size:2;
- bool has_anchored_finger:1;
- bool has_adj_hyst:1;
- bool has_dribble:1;
- bool has_bending_correction:1;
- bool has_large_object_suppression:1;
- bool has_jitter_filter:1;
+ u8 has_anchored_finger:1;
+ u8 has_adj_hyst:1;
+ u8 has_dribble:1;
+ u8 has_bending_correction:1;
+ u8 has_large_object_suppression:1;
+ u8 has_jitter_filter:1;
} __attribute__((__packed__));

/** Gesture information queries 7 and 8 are present if has_gestures bit is set.
@@ -215,23 +214,23 @@ struct f11_2d_abs_info {
* more than one finger is involved in a scrolling action.
*/
struct f11_2d_gesture_info {
- bool has_single_tap:1;
- bool has_tap_n_hold:1;
- bool has_double_tap:1;
- bool has_early_tap:1;
- bool has_flick:1;
- bool has_press:1;
- bool has_pinch:1;
- bool has_chiral:1;
-
- bool has_palm_det:1;
- bool has_rotate:1;
- bool has_touch_shapes:1;
- bool has_scroll_zones:1;
- bool has_individual_scroll_zones:1;
- bool has_multi_finger_scroll:1;
- bool has_mf_edge_motion:1;
- bool has_mf_scroll_inertia:1;
+ u8 has_single_tap:1;
+ u8 has_tap_n_hold:1;
+ u8 has_double_tap:1;
+ u8 has_early_tap:1;
+ u8 has_flick:1;
+ u8 has_press:1;
+ u8 has_pinch:1;
+ u8 has_chiral:1;
+
+ u8 has_palm_det:1;
+ u8 has_rotate:1;
+ u8 has_touch_shapes:1;
+ u8 has_scroll_zones:1;
+ u8 has_individual_scroll_zones:1;
+ u8 has_multi_finger_scroll:1;
+ u8 has_mf_edge_motion:1;
+ u8 has_mf_scroll_inertia:1;
} __attribute__((__packed__));

/** Utility for checking bytes in the gesture info registers. This is done
@@ -255,14 +254,14 @@ static bool has_gesture_bits(const struct f11_2d_gesture_info *info,
* F11_2D_Data27 exist.
*/
struct f11_2d_query9 {
- bool has_pen:1;
- bool has_proximity:1;
- bool has_palm_det_sensitivity:1;
- bool has_suppress_on_palm_detect:1;
- bool has_two_pen_thresholds:1;
- bool has_contact_geometry:1;
- bool has_pen_hover_discrimination:1;
- bool has_pen_filters:1;
+ u8 has_pen:1;
+ u8 has_proximity:1;
+ u8 has_palm_det_sensitivity:1;
+ u8 has_suppress_on_palm_detect:1;
+ u8 has_two_pen_thresholds:1;
+ u8 has_contact_geometry:1;
+ u8 has_pen_hover_discrimination:1;
+ u8 has_pen_filters:1;
} __attribute__((__packed__));

/** Touch shape info (query 10) is present if has_touch_shapes is set.
@@ -296,14 +295,14 @@ struct f11_2d_ts_info {
* F11_2D_Ctrl50 and F11_2D_Ctrl51 exist.
*/
struct f11_2d_query11 {
- bool has_z_tuning:1;
- bool has_algorithm_selection:1;
- bool has_w_tuning:1;
- bool has_pitch_info:1;
- bool has_finger_size:1;
- bool has_segmentation_aggressiveness:1;
- bool has_XY_clip:1;
- bool has_drumming_filter:1;
+ u8 has_z_tuning:1;
+ u8 has_algorithm_selection:1;
+ u8 has_w_tuning:1;
+ u8 has_pitch_info:1;
+ u8 has_finger_size:1;
+ u8 has_segmentation_aggressiveness:1;
+ u8 has_XY_clip:1;
+ u8 has_drumming_filter:1;
} __attribute__((__packed__));

/**
@@ -320,14 +319,14 @@ struct f11_2d_query11 {
* @has_linear_coeff - indicates that F11 Ctrl 81 exists.
*/
struct f11_2d_query12 {
- bool has_gapless_finger:1;
- bool has_gapless_finger_tuning:1;
- bool has_8bit_w:1;
- bool has_adjustable_mapping:1;
- bool has_info2:1;
- bool has_physical_props:1;
- bool has_finger_limit:1;
- bool has_linear_coeff_2:1;
+ u8 has_gapless_finger:1;
+ u8 has_gapless_finger_tuning:1;
+ u8 has_8bit_w:1;
+ u8 has_adjustable_mapping:1;
+ u8 has_info2:1;
+ u8 has_physical_props:1;
+ u8 has_finger_limit:1;
+ u8 has_linear_coeff_2:1;
} __attribute__((__packed__));

/** This register is present if Query 5's has_jitter_filter bit is set.
@@ -353,10 +352,10 @@ struct f11_2d_query13 {
*/
struct f11_2d_query14 {
u8 light_control:2;
- bool is_clear:1;
+ u8 is_clear:1;
u8 clickpad_props:2;
u8 mouse_buttons:2;
- bool has_advanced_gestures:1;
+ u8 has_advanced_gestures:1;
} __attribute__((__packed__));

#define F11_LIGHT_CTL_NONE 0x00
@@ -371,23 +370,14 @@ struct f11_2d_query14 {
*/
struct f11_2d_sensor_queries {
struct f11_2d_sensor_info info;
-
struct f11_2d_abs_info abs_info;
-
u8 f11_2d_query6;
-
struct f11_2d_gesture_info gesture_info;
-
struct f11_2d_query9 query9;
-
struct f11_2d_ts_info ts_info;
-
struct f11_2d_query11 features_1;
-
struct f11_2d_query12 features_2;
-
struct f11_2d_query13 jitter_filter;
-
struct f11_2d_query14 info_2;
};

@@ -426,16 +416,16 @@ struct f11_2d_sensor_queries {
struct f11_2d_ctrl0_9 {
/* F11_2D_Ctrl0 */
u8 reporting_mode:3;
- bool abs_pos_filt:1;
- bool rel_pos_filt:1;
- bool rel_ballistics:1;
- bool dribble:1;
- bool report_beyond_clip:1;
+ u8 abs_pos_filt:1;
+ u8 rel_pos_filt:1;
+ u8 rel_ballistics:1;
+ u8 dribble:1;
+ u8 report_beyond_clip:1;
/* F11_2D_Ctrl1 */
u8 palm_detect_thres:4;
u8 motion_sensitivity:2;
- bool man_track_en:1;
- bool man_tracked_finger:1;
+ u8 man_track_en:1;
+ u8 man_tracked_finger:1;
/* F11_2D_Ctrl2 and 3 */
u8 delta_x_threshold:8;
u8 delta_y_threshold:8;
@@ -459,13 +449,13 @@ struct f11_2d_ctrl0_9 {
* @pinch_int_enable - enable pinch detection.
*/
struct f11_2d_ctrl10 {
- bool single_tap_int_enable:1;
- bool tap_n_hold_int_enable:1;
- bool double_tap_int_enable:1;
- bool early_tap_int_enable:1;
- bool flick_int_enable:1;
- bool press_int_enable:1;
- bool pinch_int_enable:1;
+ u8 single_tap_int_enable:1;
+ u8 tap_n_hold_int_enable:1;
+ u8 double_tap_int_enable:1;
+ u8 early_tap_int_enable:1;
+ u8 flick_int_enable:1;
+ u8 press_int_enable:1;
+ u8 pinch_int_enable:1;
u8 reserved:1;
} __attribute__((__packed__));

@@ -477,11 +467,11 @@ struct f11_2d_ctrl10 {
* @multi_finger_scroll_int_enable - enable the multfinger scroll feature.
*/
struct f11_2d_ctrl11 {
- bool palm_detect_int_enable:1;
- bool rotate_int_enable:1;
- bool touch_shape_int_enable:1;
- bool scroll_zone_int_enable:1;
- bool multi_finger_scroll_int_enable:1;
+ u8 palm_detect_int_enable:1;
+ u8 rotate_int_enable:1;
+ u8 touch_shape_int_enable:1;
+ u8 scroll_zone_int_enable:1;
+ u8 multi_finger_scroll_int_enable:1;
u8 reserved:3;
} __attribute__((__packed__));

@@ -540,8 +530,8 @@ struct f11_2d_ctrl18_19 {
* values result in higher sensitivity.
*/
struct f11_2d_ctrl20_21 {
- bool pen_detect_enable:1;
- bool pen_jitter_filter_enable:1;
+ u8 pen_detect_enable:1;
+ u8 pen_jitter_filter_enable:1;
u8 ctrl20_reserved:6;
u8 pen_z_threshold:8;
} __attribute__((__packed__));
@@ -566,8 +556,8 @@ struct f11_2d_ctrl20_21 {
*/
struct f11_2d_ctrl22_26 {
/* control 22 */
- bool proximity_detect_int_en:1;
- bool proximity_jitter_filter_en:1;
+ u8 proximity_detect_int_en:1;
+ u8 proximity_jitter_filter_en:1;
u8 f11_2d_ctrl6_b3__7:6;

/* control 23 */
@@ -592,7 +582,7 @@ struct f11_2d_ctrl22_26 {
*/
struct f11_2d_ctrl27 {
s8 palm_detect_sensitivity:4;
- bool suppress_on_palm_detect:1;
+ u8 suppress_on_palm_detect:1;
u8 f11_2d_ctrl27_b5__7:3;
} __attribute__((__packed__));

@@ -605,8 +595,8 @@ struct f11_2d_ctrl27 {
*/
struct f11_2d_ctrl28 {
u8 multi_finger_scroll_mode:2;
- bool edge_motion_en:1;
- bool f11_2d_ctrl28b_3:1;
+ u8 edge_motion_en:1;
+ u8 f11_2d_ctrl28b_3:1;
u8 multi_finger_scroll_momentum:4;
} __attribute__((__packed__));

@@ -2711,30 +2701,7 @@ static int rmi_f11_resume(struct rmi_function *fn)
}
#endif /* CONFIG_PM */

-static int f11_remove_device(struct device *dev)
-{
- int attr_count = 0;
- struct f11_data *f11;
- struct rmi_function *fn = to_rmi_function(dev);
-
- f11 = fn->data;
-
- if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
- int i;
-
- for (i = 0; i < f11->dev_query.nbr_of_sensors + 1; i++)
- teardown_sensor_debugfs(&f11->sensors[i]);
- teardown_f11_debugfs(f11);
- }
-
- for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++)
- sysfs_remove_file(&fn->dev.kobj, &attrs[attr_count].attr);
-
- rmi_f11_free_devices(fn);
- return 0;
-}
-
-static int f11_device_init(struct rmi_function *fn)
+static int rmi_f11_probe(struct rmi_function *fn)
{
int rc;

@@ -2753,30 +2720,33 @@ static int f11_device_init(struct rmi_function *fn)
return 0;
}

-static __devinit int f11_probe(struct device *dev)
+static void rmi_f11_remove(struct rmi_function *fn)
{
- struct rmi_function *fn;
+ struct f11_data *f11 = fn->data;
+ int attr_count = 0;

- if (dev->type != &rmi_function_type)
- return 1;
+ if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
+ int i;

- fn = to_rmi_function(dev);
- if (fn->fd.function_number != FUNCTION_NUMBER)
- return 1;
+ for (i = 0; i < f11->dev_query.nbr_of_sensors + 1; i++)
+ teardown_sensor_debugfs(&f11->sensors[i]);
+ teardown_f11_debugfs(f11);
+ }
+
+ for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++)
+ sysfs_remove_file(&fn->dev.kobj, &attrs[attr_count].attr);

- return f11_device_init(fn);
+ rmi_f11_free_devices(fn);
}


-static struct rmi_function_handler function_handler = {
+static struct rmi_function_handler rmi_f11_handler = {
.driver = {
- .owner = THIS_MODULE,
.name = "rmi_f11",
- .bus = &rmi_bus_type,
- .probe = f11_probe,
- .remove = f11_remove_device,
},
- .func = FUNCTION_NUMBER,
+ .func = 0x11,
+ .probe = rmi_f11_probe,
+ .remove = rmi_f11_remove,
.config = rmi_f11_config,
.attention = rmi_f11_attention,
#ifdef CONFIG_HAS_EARLYSUSPEND
@@ -2788,20 +2758,12 @@ static struct rmi_function_handler function_handler = {

static int __init rmi_f11_module_init(void)
{
- int error;
-
- error = driver_register(&function_handler.driver);
- if (error < 0) {
- pr_err("%s: register driver failed!\n", __func__);
- return error;
- }
-
- return 0;
+ return rmi_register_function_handler(&rmi_f11_handler);
}

static void __exit rmi_f11_module_exit(void)
{
- driver_unregister(&function_handler.driver);
+ rmi_unregister_function_handler(&rmi_f11_handler);
}

module_init(rmi_f11_module_init);
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index fa8a352e..8a74066 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -365,6 +365,8 @@ 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);
@@ -377,6 +379,13 @@ struct rmi_function_handler {
#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 *);
+
/**
* struct rmi_function - represents the implementation of an RMI4
* function for a particular device (basically, a driver for that RMI4 function)
--
1.7.11.7

2012-11-27 09:22:18

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 4/4] Input: RMI4 - introduce rmi_module_driver() macro

This also allows us to cut down on the boilerplate code in the function
handler modules.

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/input/rmi4/rmi_f11.c | 13 +------------
include/linux/rmi.h | 14 ++++++++++++++
2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
index dbb6060..8457ab4 100644
--- a/drivers/input/rmi4/rmi_f11.c
+++ b/drivers/input/rmi4/rmi_f11.c
@@ -2756,18 +2756,7 @@ static struct rmi_function_handler rmi_f11_handler = {
#endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
};

-static int __init rmi_f11_module_init(void)
-{
- return rmi_register_function_handler(&rmi_f11_handler);
-}
-
-static void __exit rmi_f11_module_exit(void)
-{
- rmi_unregister_function_handler(&rmi_f11_handler);
-}
-
-module_init(rmi_f11_module_init);
-module_exit(rmi_f11_module_exit);
+module_rmi_driver(rmi_f11_handler);

MODULE_AUTHOR("Christopher Heiny <[email protected]");
MODULE_DESCRIPTION("RMI F11 module");
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index 8a74066..daca41b 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -600,4 +600,18 @@ int rmi_register_phys_device(struct rmi_phys_device *phys);
void rmi_unregister_phys_device(struct rmi_phys_device *phys);
int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));

+/**
+ * module_serio_driver() - Helper macro for registering a serio driver
+ * @__serio_driver: serio_driver struct
+ *
+ * Helper macro for serio drivers which do not do anything special in
+ * module init/exit. This eliminates a lot of boilerplate. Each module
+ * may only use this macro once, and calling it replaces module_init()
+ * and module_exit().
+ */
+#define module_rmi_driver(__rmi_driver) \
+ module_driver(__rmi_driver, \
+ rmi_register_function_handler, \
+ rmi_unregister_function_handler)
+
#endif
--
1.7.11.7

2012-11-27 23:43:11

by Christopher Heiny

[permalink] [raw]
Subject: Re: [PATCH 1/4] Input RMI4 - rename rmi_function_container to rmi_function

On 11/27/2012 01:21 AM, Dmitry Torokhov wrote:
> To save my old fingers...
>
> Signed-off-by: Dmitry Torokhov<[email protected]>
> ---
>
> It looks like this driver(s) need some love and I might have some time so I
> will refresh my "synaptics" branch with the patches you have sent and start
> working off it. If you have updates I would appreciate if you also make them
> available relative to that branch. When we are ready we'll squash them all
> together and apply to the official branch.

No problem - let me know which branch/tag to work with, and we'll be
happy to patch against that for the next round.

>
> Thanks.
>
> drivers/input/rmi4/rmi_driver.c | 158 +++++++++++----------
> drivers/input/rmi4/rmi_driver.h | 4 +-
> drivers/input/rmi4/rmi_f01.c | 298 ++++++++++++++++++++--------------------
> drivers/input/rmi4/rmi_f11.c | 258 +++++++++++++++++-----------------
> include/linux/rmi.h | 22 ++-
> 5 files changed, 368 insertions(+), 372 deletions(-)
>
> diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
> index 05a73ae..e8a4b52 100644
> --- a/drivers/input/rmi4/rmi_driver.c
> +++ b/drivers/input/rmi4/rmi_driver.c
> @@ -594,7 +594,7 @@ static struct device_attribute bsr_attribute = __ATTR(bsr, RMI_RW_ATTR,
>
> static void rmi_free_function_list(struct rmi_device *rmi_dev)
> {
> - struct rmi_function_container *entry, *n;
> + struct rmi_function *entry, *n;
> struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
>
> if (!data) {
> @@ -613,44 +613,44 @@ static void rmi_free_function_list(struct rmi_device *rmi_dev)
> }
> }
>
> -static void release_fc_device(struct device *dev)
> +static void release_function_device(struct device *dev)
> {
> dev_dbg(dev, "REMOVING KOBJ!");
> kobject_put(&dev->kobj);
> }

Hmmm. Since rmi_function_container has evolved into a child device of
the RMI4 module, maybe it would be better renamed rmi_function_device or
rmi_function_dev? I find this clearer, but can live with just
rmi_function if you prefer that.


Similarly, rmi_function_handler has evolved into a driver for such
devices, so perhaps it should be renamed rmi_function_driver?

[snip]

2012-11-27 23:46:15

by Christopher Heiny

[permalink] [raw]
Subject: Re: [PATCH 4/4] Input: RMI4 - introduce rmi_module_driver() macro

On 11/27/2012 01:21 AM, Dmitry Torokhov wrote:
> This also allows us to cut down on the boilerplate code in the function
> handler modules.

I like this idea a lot. We'll adopt it.

Thanks!
Chris

>
> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
> drivers/input/rmi4/rmi_f11.c | 13 +------------
> include/linux/rmi.h | 14 ++++++++++++++
> 2 files changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
> index dbb6060..8457ab4 100644
> --- a/drivers/input/rmi4/rmi_f11.c
> +++ b/drivers/input/rmi4/rmi_f11.c
> @@ -2756,18 +2756,7 @@ static struct rmi_function_handler rmi_f11_handler = {
> #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
> };
>
> -static int __init rmi_f11_module_init(void)
> -{
> - return rmi_register_function_handler(&rmi_f11_handler);
> -}
> -
> -static void __exit rmi_f11_module_exit(void)
> -{
> - rmi_unregister_function_handler(&rmi_f11_handler);
> -}
> -
> -module_init(rmi_f11_module_init);
> -module_exit(rmi_f11_module_exit);
> +module_rmi_driver(rmi_f11_handler);
>
> MODULE_AUTHOR("Christopher Heiny <[email protected]");
> MODULE_DESCRIPTION("RMI F11 module");
> diff --git a/include/linux/rmi.h b/include/linux/rmi.h
> index 8a74066..daca41b 100644
> --- a/include/linux/rmi.h
> +++ b/include/linux/rmi.h
> @@ -600,4 +600,18 @@ int rmi_register_phys_device(struct rmi_phys_device *phys);
> void rmi_unregister_phys_device(struct rmi_phys_device *phys);
> int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
>
> +/**
> + * module_serio_driver() - Helper macro for registering a serio driver
> + * @__serio_driver: serio_driver struct
> + *
> + * Helper macro for serio drivers which do not do anything special in
> + * module init/exit. This eliminates a lot of boilerplate. Each module
> + * may only use this macro once, and calling it replaces module_init()
> + * and module_exit().
> + */
> +#define module_rmi_driver(__rmi_driver) \
> + module_driver(__rmi_driver, \
> + rmi_register_function_handler, \
> + rmi_unregister_function_handler)
> +
> #endif
>


--

Christopher Heiny
Senior Staff Firmware Engineer
Synaptics Incorporated

2012-11-28 07:09:16

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 1/4] Input RMI4 - rename rmi_function_container to rmi_function

On Tue, Nov 27, 2012 at 03:43:05PM -0800, Christopher Heiny wrote:
> On 11/27/2012 01:21 AM, Dmitry Torokhov wrote:
> >To save my old fingers...
> >
> >Signed-off-by: Dmitry Torokhov<[email protected]>
> >---
> >
> >It looks like this driver(s) need some love and I might have some time so I
> >will refresh my "synaptics" branch with the patches you have sent and start
> >working off it. If you have updates I would appreciate if you also make them
> >available relative to that branch. When we are ready we'll squash them all
> >together and apply to the official branch.
>
> No problem - let me know which branch/tag to work with, and we'll be
> happy to patch against that for the next round.

synaptics-rmi4. It is based off 3.7-rc6.


>
> >
> >Thanks.
> >
> > drivers/input/rmi4/rmi_driver.c | 158 +++++++++++----------
> > drivers/input/rmi4/rmi_driver.h | 4 +-
> > drivers/input/rmi4/rmi_f01.c | 298 ++++++++++++++++++++--------------------
> > drivers/input/rmi4/rmi_f11.c | 258 +++++++++++++++++-----------------
> > include/linux/rmi.h | 22 ++-
> > 5 files changed, 368 insertions(+), 372 deletions(-)
> >
> >diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
> >index 05a73ae..e8a4b52 100644
> >--- a/drivers/input/rmi4/rmi_driver.c
> >+++ b/drivers/input/rmi4/rmi_driver.c
> >@@ -594,7 +594,7 @@ static struct device_attribute bsr_attribute = __ATTR(bsr, RMI_RW_ATTR,
> >
> > static void rmi_free_function_list(struct rmi_device *rmi_dev)
> > {
> >- struct rmi_function_container *entry, *n;
> >+ struct rmi_function *entry, *n;
> > struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
> >
> > if (!data) {
> >@@ -613,44 +613,44 @@ static void rmi_free_function_list(struct rmi_device *rmi_dev)
> > }
> > }
> >
> >-static void release_fc_device(struct device *dev)
> >+static void release_function_device(struct device *dev)
> > {
> > dev_dbg(dev, "REMOVING KOBJ!");
> > kobject_put(&dev->kobj);
> > }
>
> Hmmm. Since rmi_function_container has evolved into a child device
> of the RMI4 module, maybe it would be better renamed
> rmi_function_device or rmi_function_dev? I find this clearer, but
> can live with just rmi_function if you prefer that.

I just prefer something reasonably short so I still like rmi_function or
something of similar length.

>
>
> Similarly, rmi_function_handler has evolved into a driver for such
> devices, so perhaps it should be renamed rmi_function_driver?

No preference here.

Thanks.

--
Dmitry

2012-11-29 04:54:37

by Christopher Heiny

[permalink] [raw]
Subject: Re: [PATCH 2/4] Input: RMI4 - move sensor driver and F01 handler into the core

On 11/27/2012 01:21 AM, Dmitry Torokhov wrote:
> There is no point in having the sensor driver and F01 handler separate
> from the RMI core since it is not useful without them and having them
> all together simplifies initialization among other things.

Hi Dmitry,

I've been looking at this patch as well as your patch 3/4 changes, and
I'm not sure it's for the better.

One thing that confuses me is that these appear to go against the advice
we've been getting over the past months to rely more on standard kernel
bus and driver implementations, instead of the "roll-your-own"
implementation we had been using before.

More importantly, the patches inextricably link the sensor driver
implementation and the F01 driver implementation to the bus
implementation, and means that any given system can have only one way of
managing F01. As you observed, a sensor is pretty much useless without
an F01 handler, but I am reasonably sure that there will be future
systems that have more than one RMI4 sensor in them, and there is a
strong possibility that these sensors may have different requirements
for handling F01. In the near future, then, these changes will have to
be refactored back to something more like the structure of our
2012/11/16 patch set.

Additionally, having F01 as a special case means that when we start
implementing things such as support for request_firmware(), there will
have to be a bunch of special case code to deal with F01, since it's no
longer "just another function driver". That seems to go in exactly the
opposite direction of the simplification that you're trying to achieve.

I fully agree that there's a lot of boilerplate that could be (and must
be) consolidated and/or eliminated, and that some of the F01 handling
during initialization can be simplified. I'm just not sure that this is
the right way to go about doing that.

If you'd like me to address this inline in the patches, let me know. I
just thought it would be better to address design issues up top.
Alternatively, I could submit a patch that tries to address your
concerns from another approach.

Of course, it's entirely possible that I'm full of fertilizer here - I
trust that you will let me know in detail if that is the case. :-)

Thanks very much,
Chris

>
> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
> drivers/input/rmi4/Kconfig | 23 ++++++-----------------
> drivers/input/rmi4/Makefile | 10 +++++++---
> drivers/input/rmi4/rmi_bus.c | 41 ++++++++++++++++++++++++++++++++---------
> drivers/input/rmi4/rmi_driver.c | 36 ++++++++++++++----------------------
> drivers/input/rmi4/rmi_driver.h | 6 ++++++
> drivers/input/rmi4/rmi_f01.c | 22 +++-------------------
> 6 files changed, 68 insertions(+), 70 deletions(-)
>
> diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
> index 41cbbee..d0c7b6e 100644
> --- a/drivers/input/rmi4/Kconfig
> +++ b/drivers/input/rmi4/Kconfig
> @@ -1,8 +1,8 @@
> #
> # RMI4 configuration
> #
> -config RMI4_BUS
> - bool "Synaptics RMI4 bus support"
> +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.
> @@ -13,7 +13,7 @@ config RMI4_BUS
>
> config RMI4_DEBUG
> bool "RMI4 Debugging"
> - depends on RMI4_BUS
> + depends on RMI4_CORE
> select DEBUG_FS
> help
> Say Y here to enable debug feature in the RMI4 driver.
> @@ -26,8 +26,8 @@ config RMI4_DEBUG
> If unsure, say N.
>
> config RMI4_I2C
> - bool "RMI4 I2C Support"
> - depends on RMI4_BUS && I2C
> + tristate "RMI4 I2C Support"
> + depends on RMI4_CORE && I2C
> help
> Say Y here if you want to support RMI4 devices connected to an I2C
> bus.
> @@ -36,20 +36,9 @@ config RMI4_I2C
>
> This feature is not currently available as a loadable module.
>
> -config RMI4_GENERIC
> - bool "RMI4 Generic driver"
> - depends on RMI4_BUS
> - help
> - Say Y here if you want to support generic RMI4 devices.
> -
> - This is pretty much required if you want to do anything useful with
> - your RMI device.
> -
> - This feature is not currently available as a loadable module.
> -
> config RMI4_F11
> tristate "RMI4 Function 11 (2D pointing)"
> - depends on RMI4_BUS && RMI4_GENERIC
> + depends on RMI4_CORE
> help
> Say Y here if you want to add support for RMI4 function 11.
>
> diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
> index 8882c3d..5c6bad5 100644
> --- a/drivers/input/rmi4/Makefile
> +++ b/drivers/input/rmi4/Makefile
> @@ -1,8 +1,12 @@
> -obj-$(CONFIG_RMI4_BUS) += rmi_bus.o
> -obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o
> -obj-$(CONFIG_RMI4_GENERIC) += rmi_driver.o rmi_f01.o
> +obj-$(CONFIG_RMI4_CORE) += rmi_core.o
> +rmi_core-y := rmi_bus.o rmi_driver.o rmi_f01.o
> +
> +# Function drivers
> obj-$(CONFIG_RMI4_F11) += rmi_f11.o
>
> +# Transports
> +obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o
> +
> ccflags-$(CONFIG_RMI4_DEBUG) += -DDEBUG
>
> ifeq ($(KERNELRELEASE),)
> diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
> index a912349..47cf0d5 100644
> --- a/drivers/input/rmi4/rmi_bus.c
> +++ b/drivers/input/rmi4/rmi_bus.c
> @@ -206,6 +206,27 @@ static int __init rmi_bus_init(void)
>
> mutex_init(&rmi_bus_mutex);
>
> + 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_f01_handler();
> + if (error) {
> + pr_err("%s: error registering the RMI F01 handler: %d\n",
> + __func__, error);
> + goto err_unregister_bus;
> + }
> +
> + error = rmi_register_sensor_driver();
> + if (error) {
> + pr_err("%s: error registering the RMI sensor driver: %d\n",
> + __func__, error);
> + goto err_unregister_f01;
> + }
> +
> if (IS_ENABLED(CONFIG_RMI4_DEBUG)) {
> rmi_debugfs_root = debugfs_create_dir(rmi_bus_type.name, NULL);
> if (!rmi_debugfs_root)
> @@ -218,24 +239,26 @@ static int __init rmi_bus_init(void)
> }
> }
>
> - error = bus_register(&rmi_bus_type);
> - if (error < 0) {
> - pr_err("%s: error registering the RMI bus: %d\n", __func__,
> - error);
> - return error;
> - }
> - pr_debug("%s: successfully registered RMI bus.\n", __func__);
> -
> return 0;
> +
> +err_unregister_f01:
> + rmi_unregister_f01_handler();
> +err_unregister_bus:
> + bus_unregister(&rmi_bus_type);
> + return error;
> }
>
> static void __exit rmi_bus_exit(void)
> {
> - /* We should only ever get here if all drivers are unloaded, so
> + /*
> + * We should only ever get here if all drivers are unloaded, so
> * all we have to do at this point is unregister ourselves.
> */
> if (IS_ENABLED(CONFIG_RMI4_DEBUG) && rmi_debugfs_root)
> debugfs_remove(rmi_debugfs_root);
> +
> + rmi_unregister_sensor_driver();
> + rmi_unregister_f01_handler();
> bus_unregister(&rmi_bus_type);
> }
>
> diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
> index e8a4b52..6b6ac0c 100644
> --- a/drivers/input/rmi4/rmi_driver.c
> +++ b/drivers/input/rmi4/rmi_driver.c
> @@ -1608,7 +1608,7 @@ static int __devinit rmi_driver_probe(struct device *dev)
> static UNIVERSAL_DEV_PM_OPS(rmi_driver_pm, rmi_driver_suspend,
> rmi_driver_resume, NULL);
>
> -static struct rmi_driver sensor_driver = {
> +static struct rmi_driver rmi_sensor_driver = {
> .driver = {
> .owner = THIS_MODULE,
> .name = "rmi_generic",
> @@ -1624,38 +1624,30 @@ static struct rmi_driver sensor_driver = {
> .set_input_params = rmi_driver_set_input_params,
> };
>
> -static int __init rmi_driver_init(void)
> +int __init rmi_register_sensor_driver(void)
> {
> - int retval;
> + int error;
>
> - retval = driver_register(&sensor_driver.driver);
> - if (retval) {
> + error = driver_register(&rmi_sensor_driver.driver);
> + if (error) {
> pr_err("%s: driver register failed, code=%d.\n", __func__,
> - retval);
> - return retval;
> + error);
> + return error;
> }
>
> /* Ask the bus to let us know when drivers are bound to devices. */
> - retval = bus_register_notifier(&rmi_bus_type, &rmi_bus_notifier);
> - if (retval) {
> + error = bus_register_notifier(&rmi_bus_type, &rmi_bus_notifier);
> + if (error) {
> pr_err("%s: failed to register bus notifier, code=%d.\n",
> - __func__, retval);
> - return retval;
> + __func__, error);
> + return error;
> }
>
> - return retval;
> + return 0;
> }
>
> -static void __exit rmi_driver_exit(void)
> +void __exit rmi_unregister_sensor_driver(void)
> {
> bus_unregister_notifier(&rmi_bus_type, &rmi_bus_notifier);
> - driver_unregister(&sensor_driver.driver);
> + driver_unregister(&rmi_sensor_driver.driver);
> }
> -
> -module_init(rmi_driver_init);
> -module_exit(rmi_driver_exit);
> -
> -MODULE_AUTHOR("Christopher Heiny <[email protected]");
> -MODULE_DESCRIPTION("RMI generic driver");
> -MODULE_LICENSE("GPL");
> -MODULE_VERSION(RMI_DRIVER_VERSION);
> diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
> index 1fc4676..e71ffdc 100644
> --- a/drivers/input/rmi4/rmi_driver.h
> +++ b/drivers/input/rmi4/rmi_driver.h
> @@ -136,4 +136,10 @@ extern void rmi4_fw_update(struct rmi_device *rmi_dev,
> #define rmi4_fw_update(rmi_dev, f01_pdt, f34_pdt)
> #endif
>
> +int rmi_register_sensor_driver(void);
> +void rmi_unregister_sensor_driver(void);
> +
> +int rmi_register_f01_handler(void);
> +void rmi_unregister_f01_handler(void);
> +
> #endif
> diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
> index 5e6bef6..41ac5f0 100644
> --- a/drivers/input/rmi4/rmi_f01.c
> +++ b/drivers/input/rmi4/rmi_f01.c
> @@ -1265,28 +1265,12 @@ static struct rmi_function_handler function_handler = {
> #endif /* CONFIG_PM */
> };
>
> -static int __init rmi_f01_module_init(void)
> +int __init rmi_register_f01_handler(void)
> {
> - int error;
> -
> - error = driver_register(&function_handler.driver);
> - if (error < 0) {
> - pr_err("%s: register failed!\n", __func__);
> - return error;
> - }
> -
> - return 0;
> + return driver_register(&function_handler.driver);
> }
>
> -static void __exit rmi_f01_module_exit(void)
> +void __exit rmi_unregister_f01_handler(void)
> {
> driver_unregister(&function_handler.driver);
> }
> -
> -module_init(rmi_f01_module_init);
> -module_exit(rmi_f01_module_exit);
> -
> -MODULE_AUTHOR("Christopher Heiny <[email protected]>");
> -MODULE_DESCRIPTION("RMI F01 module");
> -MODULE_LICENSE("GPL");
> -MODULE_VERSION(RMI_DRIVER_VERSION);
>


--

Christopher Heiny
Senior Staff Firmware Engineer
Synaptics Incorporated

2012-11-29 17:21:27

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 2/4] Input: RMI4 - move sensor driver and F01 handler into the core

Hi Chris,
On Wed, Nov 28, 2012 at 08:54:32PM -0800, Christopher Heiny wrote:
> On 11/27/2012 01:21 AM, Dmitry Torokhov wrote:
> >There is no point in having the sensor driver and F01 handler separate
> >from the RMI core since it is not useful without them and having them
> >all together simplifies initialization among other things.
>
> Hi Dmitry,
>
> I've been looking at this patch as well as your patch 3/4 changes,
> and I'm not sure it's for the better.
>
> One thing that confuses me is that these appear to go against the
> advice we've been getting over the past months to rely more on
> standard kernel bus and driver implementations, instead of the
> "roll-your-own" implementation we had been using before.
>
> More importantly, the patches inextricably link the sensor driver
> implementation and the F01 driver implementation to the bus
> implementation, and means that any given system can have only one
> way of managing F01. As you observed, a sensor is pretty much
> useless without an F01 handler, but I am reasonably sure that there
> will be future systems that have more than one RMI4 sensor in them,
> and there is a strong possibility that these sensors may have
> different requirements for handling F01. In the near future, then,
> these changes will have to be refactored back to something more like
> the structure of our 2012/11/16 patch set.
>
> Additionally, having F01 as a special case means that when we start
> implementing things such as support for request_firmware(), there
> will have to be a bunch of special case code to deal with F01, since
> it's no longer "just another function driver". That seems to go in
> exactly the opposite direction of the simplification that you're
> trying to achieve.

But F01 continues to being "just another function driver" even with my
changes. It is still registered as rmi_fucntion_handler and uses
standard matching mechanisms to bind to rmi_functions registered by the
sensor driver. What I changed is the fact that rmi_f01 is no longer a
separate module which could be loaded after loading rmi_bus and it can't
be unloaded without unloading rmi_bus. This simplifies things and makes
it easier to have rmi core compiled as a module.

Also I do not quite follow your idea that devices might have different
requirements for handling F01. If that is true then be _can't_ implement
"F01" as "another function driver"... But that is orthogonal for the 3/4
change we are discussing here.

Thanks.

--
Dmitry