mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Christopher Heiny <cheiny@synaptics.com>
Cc: Andrew Duggan <aduggan@synaptics.com>,
	Vincent Huang <vincent.huang@tw.synaptics.com>,
	Vivian Ly <vly@synaptics.com>,
	Daniel Rosenberg <daniel.rosenberg@synaptics.com>,
	Linus Walleij <linus.walleij@stericsson.com>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Courtney Cavin <courtney.cavin@sonymobile.com>,
	Linux Input <linux-input@vger.kernel.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 09/11] Input: synaptics-rmi4 - consolidate memory allocations in F01
Date: Wed, 12 Feb 2014 21:27:55 -0800	[thread overview]
Message-ID: <1392269277-16391-9-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1392269277-16391-1-git-send-email-dmitry.torokhov@gmail.com>

Let's allocate interrupt mask together with the main structure and combine
rmi_f01_alloc_memory, rmi_f01_initialize and rmi_f01_probe into single
function.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/rmi4/rmi_f01.c | 86 ++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 56 deletions(-)

diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index a2f05bc..0e21004 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -130,37 +130,15 @@ struct f01_data {
 	u16 doze_interval_addr;
 	u16 wakeup_threshold_addr;
 	u16 doze_holdoff_addr;
-	int irq_count;
-	int num_of_irq_regs;
 
 #ifdef CONFIG_PM_SLEEP
 	bool suspended;
 	bool old_nosleep;
 #endif
-};
-
-static int rmi_f01_alloc_memory(struct rmi_function *fn,
-				int num_of_irq_regs)
-{
-	struct f01_data *f01;
 
-	f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL);
-	if (!f01) {
-		dev_err(&fn->dev, "Failed to allocate fn_01_data.\n");
-		return -ENOMEM;
-	}
-
-	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(&fn->dev, "Failed to allocate interrupt enable.\n");
-		return -ENOMEM;
-	}
-	fn->data = f01;
-
-	return 0;
-}
+	unsigned int num_of_irq_regs;
+	u8 interrupt_enable[];
+};
 
 static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
 				   u16 query_base_addr,
@@ -202,16 +180,28 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
 	return 0;
 }
 
-static int rmi_f01_initialize(struct rmi_function *fn)
+static int rmi_f01_probe(struct rmi_function *fn)
 {
-	u8 temp;
-	int error;
 	struct rmi_device *rmi_dev = fn->rmi_dev;
 	struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
-	struct f01_data *f01 = fn->data;
 	const struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);
+	struct f01_data *f01;
+	size_t f01_size;
+	int error;
 	u16 ctrl_base_addr = fn->fd.control_base_addr;
 	u8 device_status;
+	u8 temp;
+
+	f01_size = sizeof(struct f01_data) +
+				sizeof(u8) * driver_data->num_of_irq_regs;
+	f01 = devm_kzalloc(&fn->dev, f01_size, GFP_KERNEL);
+	if (!f01) {
+		dev_err(&fn->dev, "Failed to allocate fn01_data.\n");
+		return -ENOMEM;
+	}
+
+	f01->num_of_irq_regs = driver_data->num_of_irq_regs;
+	f01->device_control.interrupt_enable = f01->interrupt_enable;
 
 	/*
 	 * Set the configured bit and (optionally) other important stuff
@@ -257,12 +247,11 @@ static int rmi_f01_initialize(struct rmi_function *fn)
 		return error;
 	}
 
-	f01->irq_count = driver_data->irq_count;
-	f01->num_of_irq_regs = driver_data->num_of_irq_regs;
-	ctrl_base_addr += sizeof(u8);
-
+	/* Advance to interrupt control registers */
+	ctrl_base_addr++;
 	f01->interrupt_enable_addr = ctrl_base_addr;
-	error = rmi_read_block(rmi_dev, ctrl_base_addr,
+
+	error = rmi_read_block(rmi_dev, f01->interrupt_enable_addr,
 				f01->device_control.interrupt_enable,
 				sizeof(u8) * (f01->num_of_irq_regs));
 	if (error) {
@@ -272,9 +261,7 @@ static int rmi_f01_initialize(struct rmi_function *fn)
 		return error;
 	}
 
-	ctrl_base_addr += f01->num_of_irq_regs;
-
-	/* dummy read in order to clear irqs */
+	/* Dummy read in order to clear irqs */
 	error = rmi_read(rmi_dev, fn->fd.data_base_addr + 1, &temp);
 	if (error < 0) {
 		dev_err(&fn->dev, "Failed to read Interrupt Status.\n");
@@ -287,11 +274,13 @@ static int rmi_f01_initialize(struct rmi_function *fn)
 		dev_err(&fn->dev, "Failed to read F01 properties.\n");
 		return error;
 	}
+
 	dev_info(&fn->dev, "found RMI device, manufacturer: %s, product: %s\n",
-		 f01->properties.manufacturer_id == 1 ?
-							"Synaptics" : "unknown",
+		 f01->properties.manufacturer_id == 1 ? "Synaptics" : "unknown",
 		 f01->properties.product_id);
 
+	ctrl_base_addr += f01->num_of_irq_regs;
+
 	/* read control register */
 	if (f01->properties.has_adjustable_doze) {
 		f01->doze_interval_addr = ctrl_base_addr;
@@ -365,6 +354,8 @@ static int rmi_f01_initialize(struct rmi_function *fn)
 		return -EINVAL;
 	}
 
+	fn->data = f01;
+
 	return 0;
 }
 
@@ -424,23 +415,6 @@ static int rmi_f01_config(struct rmi_function *fn)
 	return 0;
 }
 
-static int rmi_f01_probe(struct rmi_function *fn)
-{
-	struct rmi_driver_data *driver_data =
-			dev_get_drvdata(&fn->rmi_dev->dev);
-	int error;
-
-	error = rmi_f01_alloc_memory(fn, driver_data->num_of_irq_regs);
-	if (error)
-		return error;
-
-	error = rmi_f01_initialize(fn);
-	if (error)
-		return error;
-
-	return 0;
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int rmi_f01_suspend(struct device *dev)
 {
-- 
1.8.5.3


  parent reply	other threads:[~2014-02-13  5:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13  5:27 [PATCH 01/11] Input: synaptics-rmi4 - do not kfree() managed memory " Dmitry Torokhov
2014-02-13  5:27 ` [PATCH 02/11] Input: synaptics-rmi4 - remove unused rmi_f01_remove() Dmitry Torokhov
2014-02-13 19:11   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 03/11] Input: synaptics-rmi4 - do not update configuration in rmi_f01_probe() Dmitry Torokhov
2014-02-13 19:23   ` Christopher Heiny
2014-02-13 21:54     ` Dmitry Torokhov
2014-02-14 23:00       ` Christopher Heiny
2014-02-17 19:23         ` Dmitry Torokhov
2014-02-18 21:32           ` Christopher Heiny
2014-03-19  0:21   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 04/11] Input: synaptics-rmi4 - fix LTS handling in F01 Dmitry Torokhov
2014-02-13 19:32   ` Christopher Heiny
2014-02-14  8:05     ` Dmitry Torokhov
2014-02-13  5:27 ` [PATCH 05/11] Input: synaptics-rmi4 - remove control_mutex from f01_data Dmitry Torokhov
2014-02-13 23:01   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 06/11] Input: synaptics-rmi4 - remove device_status form f01_data Dmitry Torokhov
2014-02-13 21:15   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 07/11] Input: synaptics-rmi4 - rename instances of f01_data from data to f01 Dmitry Torokhov
2014-02-13 21:32   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 08/11] Input: synaptics-rmi4 - use rmi_read/rmi_write in F01 Dmitry Torokhov
2014-02-13 21:33   ` Christopher Heiny
2014-02-13  5:27 ` Dmitry Torokhov [this message]
2014-02-13 19:52   ` [PATCH 09/11] Input: synaptics-rmi4 - consolidate memory allocations " Christopher Heiny
2014-02-13  5:27 ` [PATCH 10/11] Input: synaptics-rmi4 - make accessor for platform data return const pointer Dmitry Torokhov
2014-02-13 20:00   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 11/11] Input: synaptics-rmi4 - remove data pointer from RMI fucntion structure Dmitry Torokhov
2014-02-13 21:33   ` Christopher Heiny
2014-02-13 19:11 ` [PATCH 01/11] Input: synaptics-rmi4 - do not kfree() managed memory in F01 Christopher Heiny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392269277-16391-9-git-send-email-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=aduggan@synaptics.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=cheiny@synaptics.com \
    --cc=courtney.cavin@sonymobile.com \
    --cc=daniel.rosenberg@synaptics.com \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vincent.huang@tw.synaptics.com \
    --cc=vly@synaptics.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome