All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely@secretlab.ca>
To: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Cc: dmitry.torokhov@gmail.com, sameo@linux.intel.com,
	peter.ujfalusi@ti.com, jic23@cam.ac.uk, aghayal@codeaurora.org,
	david@hardeman.nu, Shubhrajyoti@ti.com, saaguirre@ti.com,
	hemanthv@ti.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCHv4 1/6] input/cma3000_d0x: Support devices without pdata
Date: Mon, 24 Oct 2011 23:31:04 +0200	[thread overview]
Message-ID: <20111024213104.GA4394@ponder.secretlab.ca> (raw)
In-Reply-To: <1319487676-27181-2-git-send-email-ricardo.ribalda@gmail.com>

On Mon, Oct 24, 2011 at 10:21:11PM +0200, Ricardo Ribalda Delgado wrote:
> Architectures based on device-tree does not have platform data
> associated to the spi/i2c devices. Instead they can have some of
> the options embedded in the device tree.
> 
> This patch allows the cma3000  driver to get the configuration
> from the platform_data, the device tree, or in the wort case,
> just use a default configuration.
> 
> ---

Drop this line, git cuts everything below a '---' line from the commit text.

> 
> v3: Fixes suggested by Jonathan Cameron
>     -Code style
> 
> v3: Fixes suggested by Jonathan Cameron
>     -Add support for the device tree
> 
> v2: Fixes suggested by Jonathan Cameron
>     -Spelling
>     -Simplify pdata!=NULL check
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  drivers/input/misc/cma3000_d0x.c |   86 +++++++++++++++++++++++++++++++++-----
>  1 files changed, 75 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
> index 1633b63..e66036d 100644
> --- a/drivers/input/misc/cma3000_d0x.c
> +++ b/drivers/input/misc/cma3000_d0x.c
> @@ -23,6 +23,7 @@
>  #include <linux/slab.h>
>  #include <linux/input.h>
>  #include <linux/input/cma3000.h>
> +#include <linux/of.h>
>  
>  #include "cma3000_d0x.h"
>  
> @@ -62,9 +63,21 @@
>  #define BIT_TO_2G  18
>  #define BIT_TO_8G  71
>  
> +static struct cma3000_platform_data cma3000_default_pdata = {
> +	.mdthr = 0x8,
> +	.mdfftmr = 0x33,
> +	.ffthr = 0x8,
> +	.mode = CMAMODE_MEAS400,
> +	.g_range = CMARANGE_2G,
> +	.fuzz_x = BIT_TO_2G,
> +	.fuzz_y = BIT_TO_2G,
> +	.fuzz_z = BIT_TO_2G,
> +	.irqflags = 0,
> +};
> +
>  struct cma3000_accl_data {
>  	const struct cma3000_bus_ops *bus_ops;
> -	const struct cma3000_platform_data *pdata;
> +	struct cma3000_platform_data pdata;
>  
>  	struct device *dev;
>  	struct input_dev *input_dev;
> @@ -182,7 +195,7 @@ static int cma3000_reset(struct cma3000_accl_data *data)
>  
>  static int cma3000_poweron(struct cma3000_accl_data *data)
>  {
> -	const struct cma3000_platform_data *pdata = data->pdata;
> +	struct cma3000_platform_data *pdata = &data->pdata;
>  	u8 ctrl = 0;
>  	int ret;
>  
> @@ -280,22 +293,57 @@ void cma3000_resume(struct cma3000_accl_data *data)
>  }
>  EXPORT_SYMBOL(cma3000_resume);
>  
> +#ifdef CONFIG_OF
> +void cma3000_get_pdata_of(struct device *dev, struct cma3000_accl_data *data)
> +{
> +	const __be32 *property;
> +	int len;
> +
> +	property = of_get_property(dev->of_node, "vti,mdthr", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.mdthr = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,mdfftmr", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.mdfftmr = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,mode", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.mode = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,g_range", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.g_range = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,fuzz_x", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.fuzz_x = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,fuzz_y", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.fuzz_y = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,fuzz_z", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.fuzz_z = be32_to_cpup(property);
> +
> +	property = of_get_property(dev->of_node, "vti,irqflags", &len);
> +	if (property && len == sizeof(int))
> +		data->pdata.irqflags = be32_to_cpup(property);

This binding needs documentation before it can be merged.

> +
> +	return;
> +}
> +#endif

No of_device_id match table to match against compatible values?

> +
>  struct cma3000_accl_data *cma3000_init(struct device *dev, int irq,
>  				       const struct cma3000_bus_ops *bops)
>  {
> -	const struct cma3000_platform_data *pdata = dev->platform_data;
> +	struct cma3000_platform_data *pdata;
>  	struct cma3000_accl_data *data;
>  	struct input_dev *input_dev;
>  	int rev;
>  	int error;
>  
> -	if (!pdata) {
> -		dev_err(dev, "platform data not found\n");
> -		error = -EINVAL;
> -		goto err_out;
> -	}
> -
> -
>  	/* if no IRQ return error */
>  	if (irq == 0) {
>  		error = -EINVAL;
> @@ -309,10 +357,26 @@ struct cma3000_accl_data *cma3000_init(struct device *dev, int irq,
>  		goto err_free_mem;
>  	}
>  
> +	/*Init platform data*/
> +	if (dev->platform_data != NULL) {
> +		memcpy(&data->pdata, dev->platform_data, sizeof(data->pdata));
> +	} else {
> +		memcpy(&data->pdata, &cma3000_default_pdata,
> +				sizeof(data->pdata));
> +		#ifdef CONFIG_OF
> +		if (dev->of_node != NULL)
> +			cma3000_get_pdata_of(dev, data);
> +		 else
> +			dev_info(dev, "platform data not found, using default\n");
> +		#else
> +		dev_info(dev, "platform data not found, using default\n");
> +		#endif
> +	}
> +	pdata = &data->pdata;
> +
>  	data->dev = dev;
>  	data->input_dev = input_dev;
>  	data->bus_ops = bops;
> -	data->pdata = pdata;
>  	data->irq = irq;
>  	mutex_init(&data->mutex);
>  
> -- 
> 1.7.7
> 

  reply	other threads:[~2011-10-24 21:31 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-24 20:21 [PATCHv4 0/6] Add spi support for CMA3000 driver and new driver CMR3000 Ricardo Ribalda Delgado
2011-10-24 20:21 ` Ricardo Ribalda Delgado
2011-10-24 20:21 ` [PATCHv4 1/6] input/cma3000_d0x: Support devices without pdata Ricardo Ribalda Delgado
2011-10-24 20:21 ` Ricardo Ribalda Delgado
2011-10-24 21:31   ` Grant Likely [this message]
2011-10-25  7:38     ` Ricardo Ribalda Delgado
2011-10-25  7:38       ` Ricardo Ribalda Delgado
2011-10-25  7:46       ` Grant Likely
2011-10-25  7:46         ` Grant Likely
2011-11-02 12:41         ` Ricardo Ribalda Delgado
2011-11-02 12:41           ` Ricardo Ribalda Delgado
2011-11-02 14:51           ` Ricardo Ribalda Delgado
2011-11-02 14:51             ` Ricardo Ribalda Delgado
2011-10-24 20:21 ` [PATCHv4 2/6] input/cma3000_d0x: Check silicon version Ricardo Ribalda Delgado
2011-10-24 20:21 ` Ricardo Ribalda Delgado
2011-10-24 20:21 ` [PATCHv4 3/6] input/cma3000_d0x: Keep configuration on poweroff Ricardo Ribalda Delgado
2011-10-24 20:21 ` Ricardo Ribalda Delgado
2011-10-24 20:21 ` [PATCHv4 4/6] input/cma3000_d0x: Add CMA3000 spi support Ricardo Ribalda Delgado
2011-10-24 20:21 ` Ricardo Ribalda Delgado
2011-10-24 21:36   ` Grant Likely
2011-10-25  7:24     ` Ricardo Ribalda Delgado
2011-10-25  7:24       ` Ricardo Ribalda Delgado
2011-10-25  8:29       ` Grant Likely
2011-10-25  8:29         ` Grant Likely
2011-10-25  8:32       ` Jonathan Cameron
2011-10-25  8:36         ` Mark Brown
2011-11-02 12:38           ` Ricardo Ribalda Delgado
2011-11-02 12:49             ` Mark Brown
2011-10-24 20:21 ` [PATCHv4 5/6] Input: add CMR3000 gyrsocope driver Ricardo Ribalda Delgado
2011-10-24 20:21   ` Ricardo Ribalda Delgado
2011-10-24 21:40   ` Grant Likely
2011-10-25  7:26     ` Ricardo Ribalda Delgado
2011-10-25  7:26       ` Ricardo Ribalda Delgado
2011-10-25  8:28       ` Grant Likely
2011-10-25  8:28         ` Grant Likely
2011-11-02 14:28         ` Ricardo Ribalda Delgado
2011-11-02 14:28           ` Ricardo Ribalda Delgado
2011-10-24 20:21 ` [PATCHv4 6/6] input/cma3000_d0x: Match comment to name of struct Ricardo Ribalda Delgado
2011-10-24 20:21   ` Ricardo Ribalda Delgado

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=20111024213104.GA4394@ponder.secretlab.ca \
    --to=grant.likely@secretlab.ca \
    --cc=Shubhrajyoti@ti.com \
    --cc=aghayal@codeaurora.org \
    --cc=david@hardeman.nu \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hemanthv@ti.com \
    --cc=jic23@cam.ac.uk \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=ricardo.ribalda@gmail.com \
    --cc=saaguirre@ti.com \
    --cc=sameo@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.