* [PATCHv6_input/next 0/5] Add spi support for CMA3000 driver
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi
The following set of patches add spi and device tree support for the cma3000 driver.
v6 of the set.
Changelog:
v6: -Rebase to input/next
v5: -Changes propossed by Grant Likely
-Remove crm300 driver from the set
v4: -Changes propossed by Dmitry Torokhov
v3: -Support for device tree
-Separate read/write spi
v2: -Changes propossed by Jonathan Cameron
-More fixes for the cma3000 driver
Ricardo Ribalda Delgado (5):
input/cma3000_d0x: Support devices without pdata
input/cma3000_d0x: Check silicon version
input/cma3000_d0x: Keep configuration on poweroff
input/cma3000_d0x: Add CMA3000 spi support
input/cma3000_d0x: Match comment to name of struct
Ricardo Ribalda Delgado (5):
input/cma3000_d0x: Support devices without pdata
input/cma3000_d0x: Check silicon version
input/cma3000_d0x: Keep configuration on poweroff
input/cma3000_d0x: Add CMA3000 spi support
input/cma3000_d0x: Match comment to name of struct
.../devicetree/bindings/input/cma3000_d0x.txt | 71 +++++++++
drivers/input/misc/Kconfig | 14 ++-
drivers/input/misc/Makefile | 1 +
drivers/input/misc/cma3000_d0x.c | 100 +++++++++++--
drivers/input/misc/cma3000_d0x_i2c.c | 7 +
drivers/input/misc/cma3000_d0x_spi.c | 153 ++++++++++++++++++++
include/linux/input/cma3000.h | 2 +-
7 files changed, 332 insertions(+), 16 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/cma3000_d0x.txt
create mode 100644 drivers/input/misc/cma3000_d0x_spi.c
--
1.7.7.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 0/5] Add spi support for CMA3000 driver
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi, alan, david, Shubhrajyoti,
saaguirre, hemanthv, linux-doc, linux-kernel, linux-input,
devicetree-discuss
The following set of patches add spi and device tree support for the cma3000 driver.
v6 of the set.
Changelog:
v6: -Rebase to input/next
v5: -Changes propossed by Grant Likely
-Remove crm300 driver from the set
v4: -Changes propossed by Dmitry Torokhov
v3: -Support for device tree
-Separate read/write spi
v2: -Changes propossed by Jonathan Cameron
-More fixes for the cma3000 driver
Ricardo Ribalda Delgado (5):
input/cma3000_d0x: Support devices without pdata
input/cma3000_d0x: Check silicon version
input/cma3000_d0x: Keep configuration on poweroff
input/cma3000_d0x: Add CMA3000 spi support
input/cma3000_d0x: Match comment to name of struct
Ricardo Ribalda Delgado (5):
input/cma3000_d0x: Support devices without pdata
input/cma3000_d0x: Check silicon version
input/cma3000_d0x: Keep configuration on poweroff
input/cma3000_d0x: Add CMA3000 spi support
input/cma3000_d0x: Match comment to name of struct
.../devicetree/bindings/input/cma3000_d0x.txt | 71 +++++++++
drivers/input/misc/Kconfig | 14 ++-
drivers/input/misc/Makefile | 1 +
drivers/input/misc/cma3000_d0x.c | 100 +++++++++++--
drivers/input/misc/cma3000_d0x_i2c.c | 7 +
drivers/input/misc/cma3000_d0x_spi.c | 153 ++++++++++++++++++++
include/linux/input/cma3000.h | 2 +-
7 files changed, 332 insertions(+), 16 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/cma3000_d0x.txt
create mode 100644 drivers/input/misc/cma3000_d0x_spi.c
--
1.7.7.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 1/5] input/cma3000_d0x: Support devices without pdata
2011-11-09 21:37 ` Ricardo Ribalda Delgado
(?)
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
-1 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi
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.
v5: Fixes suggested by Grant Likely
-Device tree binding doc
-Use of_device_id table
v3: Fixes suggested by Jonathan Cameron
-Code style
-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>
---
.../devicetree/bindings/input/cma3000_d0x.txt | 71 ++++++++++++++++
drivers/input/misc/cma3000_d0x.c | 86 +++++++++++++++++---
drivers/input/misc/cma3000_d0x_i2c.c | 7 ++
3 files changed, 153 insertions(+), 11 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/cma3000_d0x.txt
diff --git a/Documentation/devicetree/bindings/input/cma3000_d0x.txt b/Documentation/devicetree/bindings/input/cma3000_d0x.txt
new file mode 100644
index 0000000..41becc1
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/cma3000_d0x.txt
@@ -0,0 +1,71 @@
+* VTI CMA3000-D0x Accelerometer
+
+Required properties:
+
+- compatible : "vti,cma3000_d01"
+
+- reg : Offset and length of the register set for this device
+
+- interrupts : <a> where a is the interrupt number for the port.
+
+- interrupt-parent : the phandle for the interrupt controller
+that services interrupts for this device.
+
+
+Optional properties:
+
+- vti,fuzz_x: <a> where a is the noise on X Axis in mili g.
+ * Value per default is 18;
+
+- vti,fuzz_y: <a> where a is the noise on Y Axis in mili g
+ * Value per default is 18;
+
+- vti,fuzz_z: <a> where a is the noise on Z Axis in mili g
+ * Value per default is 18;
+
+- g_range: <a> where a is G range in milli g. Value can be:
+ - 2000: for 2G
+ - 8000: for 8G
+ * Value per default is 2000;
+
+- mode: <a> where a is the default Operating mode. Value can be:
+ - 0: power down mode
+ - 1: 100 Hz Measurement mode
+ - 2: 400 Hz Measurement mode
+ - 3: 40 Hz Measurement mode
+ - 4: Motion Detect mode (default)
+ - 5: 100 Hz Free fall mode
+ - 6: 40 Hz Free fall mode
+ - 7: Power off mode
+ * Value per default is 2;
+
+- mdthr: <a> where a is the Motion detect g range threshold value.
+Value X means:
+ - X: X * 71mg (8G Range)
+ - X: X * 18mg (2G Range)
+ * Value per default is 8;
+
+- mdfftmr: <a> where a is the Motion detect and free fall time threshold value.
+Value X memans:
+ - X: (X & 0x70) * 100 ms (MDTMR)
+ - (X & 0x0F) * 2.5 ms (FFTMR 400 Hz)
+ - (X & 0x0F) * 10 ms (FFTMR 100 Hz)
+ * Value per default is 51;
+
+- ffthr: <a> where a is the Free fall g range threshold value. Value X means:
+ - X: (X >> 2) * 18mg (2G Range)
+ - X: (X & 0x0F) * 71 mg (8G Range)
+ * Value per default is 8;
+
+
+Example:
+
+cma3000 {
+ compatible = "vti,cma3000_d01";
+ reg = < 1 1 >;
+ interrupt-parent = <&xps_intc_0>;
+ interrupts = < 7 2 >;
+ spi-max-frequency = <500000>;
+ vti,mode = <2>;
+} ;
+
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);
+
+ return;
+}
+#endif
+
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);
diff --git a/drivers/input/misc/cma3000_d0x_i2c.c b/drivers/input/misc/cma3000_d0x_i2c.c
index d100cc5..922f8c2 100644
--- a/drivers/input/misc/cma3000_d0x_i2c.c
+++ b/drivers/input/misc/cma3000_d0x_i2c.c
@@ -112,6 +112,12 @@ static const struct i2c_device_id cma3000_i2c_id[] = {
MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);
+static const struct of_device_id cma3000_i2c_dt_ids[] = {
+ { .compatible = "vti,cma3000_d01", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, cma3000_i2c_dt_ids);
+
static struct i2c_driver cma3000_i2c_driver = {
.probe = cma3000_i2c_probe,
.remove = __devexit_p(cma3000_i2c_remove),
@@ -119,6 +125,7 @@ static struct i2c_driver cma3000_i2c_driver = {
.driver = {
.name = "cma3000_i2c_accl",
.owner = THIS_MODULE,
+ .of_match_table = cma3000_i2c_dt_ids,
#ifdef CONFIG_PM
.pm = &cma3000_i2c_pm_ops,
#endif
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 1/5] input/cma3000_d0x: Support devices without pdata
[not found] ` <1320874652-18371-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi, alan, david, Shubhrajyoti,
saaguirre, hemanthv, linux-doc, linux-kernel, linux-input,
devicetree-discuss
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.
v5: Fixes suggested by Grant Likely
-Device tree binding doc
-Use of_device_id table
v3: Fixes suggested by Jonathan Cameron
-Code style
-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>
---
.../devicetree/bindings/input/cma3000_d0x.txt | 71 ++++++++++++++++
drivers/input/misc/cma3000_d0x.c | 86 +++++++++++++++++---
drivers/input/misc/cma3000_d0x_i2c.c | 7 ++
3 files changed, 153 insertions(+), 11 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/cma3000_d0x.txt
diff --git a/Documentation/devicetree/bindings/input/cma3000_d0x.txt b/Documentation/devicetree/bindings/input/cma3000_d0x.txt
new file mode 100644
index 0000000..41becc1
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/cma3000_d0x.txt
@@ -0,0 +1,71 @@
+* VTI CMA3000-D0x Accelerometer
+
+Required properties:
+
+- compatible : "vti,cma3000_d01"
+
+- reg : Offset and length of the register set for this device
+
+- interrupts : <a> where a is the interrupt number for the port.
+
+- interrupt-parent : the phandle for the interrupt controller
+that services interrupts for this device.
+
+
+Optional properties:
+
+- vti,fuzz_x: <a> where a is the noise on X Axis in mili g.
+ * Value per default is 18;
+
+- vti,fuzz_y: <a> where a is the noise on Y Axis in mili g
+ * Value per default is 18;
+
+- vti,fuzz_z: <a> where a is the noise on Z Axis in mili g
+ * Value per default is 18;
+
+- g_range: <a> where a is G range in milli g. Value can be:
+ - 2000: for 2G
+ - 8000: for 8G
+ * Value per default is 2000;
+
+- mode: <a> where a is the default Operating mode. Value can be:
+ - 0: power down mode
+ - 1: 100 Hz Measurement mode
+ - 2: 400 Hz Measurement mode
+ - 3: 40 Hz Measurement mode
+ - 4: Motion Detect mode (default)
+ - 5: 100 Hz Free fall mode
+ - 6: 40 Hz Free fall mode
+ - 7: Power off mode
+ * Value per default is 2;
+
+- mdthr: <a> where a is the Motion detect g range threshold value.
+Value X means:
+ - X: X * 71mg (8G Range)
+ - X: X * 18mg (2G Range)
+ * Value per default is 8;
+
+- mdfftmr: <a> where a is the Motion detect and free fall time threshold value.
+Value X memans:
+ - X: (X & 0x70) * 100 ms (MDTMR)
+ - (X & 0x0F) * 2.5 ms (FFTMR 400 Hz)
+ - (X & 0x0F) * 10 ms (FFTMR 100 Hz)
+ * Value per default is 51;
+
+- ffthr: <a> where a is the Free fall g range threshold value. Value X means:
+ - X: (X >> 2) * 18mg (2G Range)
+ - X: (X & 0x0F) * 71 mg (8G Range)
+ * Value per default is 8;
+
+
+Example:
+
+cma3000 {
+ compatible = "vti,cma3000_d01";
+ reg = < 1 1 >;
+ interrupt-parent = <&xps_intc_0>;
+ interrupts = < 7 2 >;
+ spi-max-frequency = <500000>;
+ vti,mode = <2>;
+} ;
+
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);
+
+ return;
+}
+#endif
+
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);
diff --git a/drivers/input/misc/cma3000_d0x_i2c.c b/drivers/input/misc/cma3000_d0x_i2c.c
index d100cc5..922f8c2 100644
--- a/drivers/input/misc/cma3000_d0x_i2c.c
+++ b/drivers/input/misc/cma3000_d0x_i2c.c
@@ -112,6 +112,12 @@ static const struct i2c_device_id cma3000_i2c_id[] = {
MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);
+static const struct of_device_id cma3000_i2c_dt_ids[] = {
+ { .compatible = "vti,cma3000_d01", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, cma3000_i2c_dt_ids);
+
static struct i2c_driver cma3000_i2c_driver = {
.probe = cma3000_i2c_probe,
.remove = __devexit_p(cma3000_i2c_remove),
@@ -119,6 +125,7 @@ static struct i2c_driver cma3000_i2c_driver = {
.driver = {
.name = "cma3000_i2c_accl",
.owner = THIS_MODULE,
+ .of_match_table = cma3000_i2c_dt_ids,
#ifdef CONFIG_PM
.pm = &cma3000_i2c_pm_ops,
#endif
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 1/5] input/cma3000_d0x: Support devices without pdata
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap-/UHa2rfvQTnk1uMJSBkQmQ,
dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w,
jic23-KWPb1pKIrIJaa/9Udqfwiw, aghayal-sgV2jX0FEOL9JmXXK+q4OQ,
sameo-VuQAYsv1563Yd54FQh9/CA, peter.ujfalusi
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.
v5: Fixes suggested by Grant Likely
-Device tree binding doc
-Use of_device_id table
v3: Fixes suggested by Jonathan Cameron
-Code style
-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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
.../devicetree/bindings/input/cma3000_d0x.txt | 71 ++++++++++++++++
drivers/input/misc/cma3000_d0x.c | 86 +++++++++++++++++---
drivers/input/misc/cma3000_d0x_i2c.c | 7 ++
3 files changed, 153 insertions(+), 11 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/cma3000_d0x.txt
diff --git a/Documentation/devicetree/bindings/input/cma3000_d0x.txt b/Documentation/devicetree/bindings/input/cma3000_d0x.txt
new file mode 100644
index 0000000..41becc1
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/cma3000_d0x.txt
@@ -0,0 +1,71 @@
+* VTI CMA3000-D0x Accelerometer
+
+Required properties:
+
+- compatible : "vti,cma3000_d01"
+
+- reg : Offset and length of the register set for this device
+
+- interrupts : <a> where a is the interrupt number for the port.
+
+- interrupt-parent : the phandle for the interrupt controller
+that services interrupts for this device.
+
+
+Optional properties:
+
+- vti,fuzz_x: <a> where a is the noise on X Axis in mili g.
+ * Value per default is 18;
+
+- vti,fuzz_y: <a> where a is the noise on Y Axis in mili g
+ * Value per default is 18;
+
+- vti,fuzz_z: <a> where a is the noise on Z Axis in mili g
+ * Value per default is 18;
+
+- g_range: <a> where a is G range in milli g. Value can be:
+ - 2000: for 2G
+ - 8000: for 8G
+ * Value per default is 2000;
+
+- mode: <a> where a is the default Operating mode. Value can be:
+ - 0: power down mode
+ - 1: 100 Hz Measurement mode
+ - 2: 400 Hz Measurement mode
+ - 3: 40 Hz Measurement mode
+ - 4: Motion Detect mode (default)
+ - 5: 100 Hz Free fall mode
+ - 6: 40 Hz Free fall mode
+ - 7: Power off mode
+ * Value per default is 2;
+
+- mdthr: <a> where a is the Motion detect g range threshold value.
+Value X means:
+ - X: X * 71mg (8G Range)
+ - X: X * 18mg (2G Range)
+ * Value per default is 8;
+
+- mdfftmr: <a> where a is the Motion detect and free fall time threshold value.
+Value X memans:
+ - X: (X & 0x70) * 100 ms (MDTMR)
+ - (X & 0x0F) * 2.5 ms (FFTMR 400 Hz)
+ - (X & 0x0F) * 10 ms (FFTMR 100 Hz)
+ * Value per default is 51;
+
+- ffthr: <a> where a is the Free fall g range threshold value. Value X means:
+ - X: (X >> 2) * 18mg (2G Range)
+ - X: (X & 0x0F) * 71 mg (8G Range)
+ * Value per default is 8;
+
+
+Example:
+
+cma3000 {
+ compatible = "vti,cma3000_d01";
+ reg = < 1 1 >;
+ interrupt-parent = <&xps_intc_0>;
+ interrupts = < 7 2 >;
+ spi-max-frequency = <500000>;
+ vti,mode = <2>;
+} ;
+
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);
+
+ return;
+}
+#endif
+
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);
diff --git a/drivers/input/misc/cma3000_d0x_i2c.c b/drivers/input/misc/cma3000_d0x_i2c.c
index d100cc5..922f8c2 100644
--- a/drivers/input/misc/cma3000_d0x_i2c.c
+++ b/drivers/input/misc/cma3000_d0x_i2c.c
@@ -112,6 +112,12 @@ static const struct i2c_device_id cma3000_i2c_id[] = {
MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);
+static const struct of_device_id cma3000_i2c_dt_ids[] = {
+ { .compatible = "vti,cma3000_d01", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, cma3000_i2c_dt_ids);
+
static struct i2c_driver cma3000_i2c_driver = {
.probe = cma3000_i2c_probe,
.remove = __devexit_p(cma3000_i2c_remove),
@@ -119,6 +125,7 @@ static struct i2c_driver cma3000_i2c_driver = {
.driver = {
.name = "cma3000_i2c_accl",
.owner = THIS_MODULE,
+ .of_match_table = cma3000_i2c_dt_ids,
#ifdef CONFIG_PM
.pm = &cma3000_i2c_pm_ops,
#endif
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 2/5] input/cma3000_d0x: Check silicon version
2011-11-09 21:37 ` Ricardo Ribalda Delgado
` (3 preceding siblings ...)
(?)
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
-1 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi
Improve probing of the cma3000 chip, by checking the revision of the
device.
v4: Add ACKs to patch
v2: Fixes suggested by Jonathan Cameron
-Remove WhoamI pr_info
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/input/misc/cma3000_d0x.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index e66036d..97e36fa 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -27,6 +27,8 @@
#include "cma3000_d0x.h"
+#define CMA3000_REV 0x10
+
#define CMA3000_WHOAMI 0x00
#define CMA3000_REVID 0x01
#define CMA3000_CTRL 0x02
@@ -420,7 +422,11 @@ struct cma3000_accl_data *cma3000_init(struct device *dev, int irq,
error = rev;
goto err_free_mem;
}
-
+ if (rev != CMA3000_REV) {
+ error = -EINVAL;
+ pr_err("CMA3000 Accelerometer: Unknown Revision %x\n", rev);
+ goto err_free_mem;
+ }
pr_info("CMA3000 Accelerometer: Revision %x\n", rev);
error = request_threaded_irq(irq, NULL, cma3000_thread_irq,
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 2/5] input/cma3000_d0x: Check silicon version
[not found] ` <1320874652-18371-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi, alan, david, Shubhrajyoti,
saaguirre, hemanthv, linux-doc, linux-kernel, linux-input,
devicetree-discuss
Improve probing of the cma3000 chip, by checking the revision of the
device.
v4: Add ACKs to patch
v2: Fixes suggested by Jonathan Cameron
-Remove WhoamI pr_info
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/input/misc/cma3000_d0x.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index e66036d..97e36fa 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -27,6 +27,8 @@
#include "cma3000_d0x.h"
+#define CMA3000_REV 0x10
+
#define CMA3000_WHOAMI 0x00
#define CMA3000_REVID 0x01
#define CMA3000_CTRL 0x02
@@ -420,7 +422,11 @@ struct cma3000_accl_data *cma3000_init(struct device *dev, int irq,
error = rev;
goto err_free_mem;
}
-
+ if (rev != CMA3000_REV) {
+ error = -EINVAL;
+ pr_err("CMA3000 Accelerometer: Unknown Revision %x\n", rev);
+ goto err_free_mem;
+ }
pr_info("CMA3000 Accelerometer: Revision %x\n", rev);
error = request_threaded_irq(irq, NULL, cma3000_thread_irq,
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 2/5] input/cma3000_d0x: Check silicon version
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap-/UHa2rfvQTnk1uMJSBkQmQ,
dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w,
jic23-KWPb1pKIrIJaa/9Udqfwiw, aghayal-sgV2jX0FEOL9JmXXK+q4OQ,
sameo-VuQAYsv1563Yd54FQh9/CA, peter.ujfalusi
Improve probing of the cma3000 chip, by checking the revision of the
device.
v4: Add ACKs to patch
v2: Fixes suggested by Jonathan Cameron
-Remove WhoamI pr_info
Acked-by: Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/input/misc/cma3000_d0x.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index e66036d..97e36fa 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -27,6 +27,8 @@
#include "cma3000_d0x.h"
+#define CMA3000_REV 0x10
+
#define CMA3000_WHOAMI 0x00
#define CMA3000_REVID 0x01
#define CMA3000_CTRL 0x02
@@ -420,7 +422,11 @@ struct cma3000_accl_data *cma3000_init(struct device *dev, int irq,
error = rev;
goto err_free_mem;
}
-
+ if (rev != CMA3000_REV) {
+ error = -EINVAL;
+ pr_err("CMA3000 Accelerometer: Unknown Revision %x\n", rev);
+ goto err_free_mem;
+ }
pr_info("CMA3000 Accelerometer: Revision %x\n", rev);
error = request_threaded_irq(irq, NULL, cma3000_thread_irq,
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 3/5] input/cma3000_d0x: Keep configuration on poweroff
2011-11-09 21:37 ` Ricardo Ribalda Delgado
` (4 preceding siblings ...)
(?)
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
-1 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi
When the device goes to poweroff keep the spi/i2c configuration.
Otherwhise the device could not wake up if it was in spi mode.
v2: Fixes suggested by Jonathan Cameron
-Code Style
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/input/misc/cma3000_d0x.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index 97e36fa..35d2577 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -45,6 +45,7 @@
#define CMA3000_RANGE2G (1 << 7)
#define CMA3000_RANGE8G (0 << 7)
#define CMA3000_BUSI2C (0 << 4)
+#define CMA3000_BUSSPI (1 << 4)
#define CMA3000_MODEMASK (7 << 1)
#define CMA3000_GRANGEMASK (1 << 7)
@@ -231,8 +232,11 @@ static int cma3000_poweron(struct cma3000_accl_data *data)
static int cma3000_poweroff(struct cma3000_accl_data *data)
{
int ret;
+ u8 ctrl = CMAMODE_POFF;
- ret = CMA3000_SET(data, CMA3000_CTRL, CMAMODE_POFF, "Mode setting");
+ ctrl |= data->bus_ops->ctrl_mod;
+
+ ret = CMA3000_SET(data, CMA3000_CTRL, ctrl, "Mode setting");
msleep(CMA3000_SETDELAY);
return ret;
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 3/5] input/cma3000_d0x: Keep configuration on poweroff
[not found] ` <1320874652-18371-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi, alan, david, Shubhrajyoti,
saaguirre, hemanthv, linux-doc, linux-kernel, linux-input,
devicetree-discuss
When the device goes to poweroff keep the spi/i2c configuration.
Otherwhise the device could not wake up if it was in spi mode.
v2: Fixes suggested by Jonathan Cameron
-Code Style
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/input/misc/cma3000_d0x.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index 97e36fa..35d2577 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -45,6 +45,7 @@
#define CMA3000_RANGE2G (1 << 7)
#define CMA3000_RANGE8G (0 << 7)
#define CMA3000_BUSI2C (0 << 4)
+#define CMA3000_BUSSPI (1 << 4)
#define CMA3000_MODEMASK (7 << 1)
#define CMA3000_GRANGEMASK (1 << 7)
@@ -231,8 +232,11 @@ static int cma3000_poweron(struct cma3000_accl_data *data)
static int cma3000_poweroff(struct cma3000_accl_data *data)
{
int ret;
+ u8 ctrl = CMAMODE_POFF;
- ret = CMA3000_SET(data, CMA3000_CTRL, CMAMODE_POFF, "Mode setting");
+ ctrl |= data->bus_ops->ctrl_mod;
+
+ ret = CMA3000_SET(data, CMA3000_CTRL, ctrl, "Mode setting");
msleep(CMA3000_SETDELAY);
return ret;
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 3/5] input/cma3000_d0x: Keep configuration on poweroff
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap-/UHa2rfvQTnk1uMJSBkQmQ,
dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w,
jic23-KWPb1pKIrIJaa/9Udqfwiw, aghayal-sgV2jX0FEOL9JmXXK+q4OQ,
sameo-VuQAYsv1563Yd54FQh9/CA, peter.ujfalusi
When the device goes to poweroff keep the spi/i2c configuration.
Otherwhise the device could not wake up if it was in spi mode.
v2: Fixes suggested by Jonathan Cameron
-Code Style
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/input/misc/cma3000_d0x.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index 97e36fa..35d2577 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -45,6 +45,7 @@
#define CMA3000_RANGE2G (1 << 7)
#define CMA3000_RANGE8G (0 << 7)
#define CMA3000_BUSI2C (0 << 4)
+#define CMA3000_BUSSPI (1 << 4)
#define CMA3000_MODEMASK (7 << 1)
#define CMA3000_GRANGEMASK (1 << 7)
@@ -231,8 +232,11 @@ static int cma3000_poweron(struct cma3000_accl_data *data)
static int cma3000_poweroff(struct cma3000_accl_data *data)
{
int ret;
+ u8 ctrl = CMAMODE_POFF;
- ret = CMA3000_SET(data, CMA3000_CTRL, CMAMODE_POFF, "Mode setting");
+ ctrl |= data->bus_ops->ctrl_mod;
+
+ ret = CMA3000_SET(data, CMA3000_CTRL, ctrl, "Mode setting");
msleep(CMA3000_SETDELAY);
return ret;
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 4/5] input/cma3000_d0x: Add CMA3000 spi support
2011-11-09 21:37 ` Ricardo Ribalda Delgado
` (7 preceding siblings ...)
(?)
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
-1 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi
Add support for SPI communication.
v5: Fixes suggested by Grant Likely
-Drop .bus line
-Code Style
-Use of_device_id table
v4: Add ACKs to patch
v3: Fixes suggested by Jonathan Cameron
-Separate write/read commands
-Do not check 1/0 mask
-Use spi_w8r8 and spi_write_then_read functions
v2: Fixes suggested by Jonathan Cameron
-Add filename to based on header
-Rename set with write
-Set spi buffers as cache aligned
-Code Style
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/input/misc/Kconfig | 14 +++-
drivers/input/misc/Makefile | 1 +
drivers/input/misc/cma3000_d0x_spi.c | 153 ++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+), 2 deletions(-)
create mode 100644 drivers/input/misc/cma3000_d0x_spi.c
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index a1aa35a..39f4374 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -519,8 +519,8 @@ config INPUT_CMA3000
Say Y here if you want to use VTI CMA3000_D0x Accelerometer
driver
- This driver currently only supports I2C interface to the
- controller. Also select the I2C method.
+ This driver supports I2C and SPI interface to the
+ controller. Also select the I2C method and/or the SPI method.
If unsure, say N
@@ -537,6 +537,16 @@ config INPUT_CMA3000_I2C
To compile this driver as a module, choose M here: the
module will be called cma3000_d0x_i2c.
+config INPUT_CMA3000_SPI
+ tristate "Support SPI bus connection"
+ depends on INPUT_CMA3000 && SPI
+ help
+ Say Y here if you want to use VTI CMA3000_D0x Accelerometer
+ through SPI interface.
+
+ To compile this driver as a module, choose M here: the
+ module will be called cma3000_d0x_spi.
+
config INPUT_XEN_KBDDEV_FRONTEND
tristate "Xen virtual keyboard and mouse support"
depends on XEN_FBDEV_FRONTEND
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 53a8d0f..fb05beb 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_INPUT_BMA150) += bma150.o
obj-$(CONFIG_INPUT_CM109) += cm109.o
obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o
obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o
+obj-$(CONFIG_INPUT_CMA3000_SPI) += cma3000_d0x_spi.o
obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o
obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
diff --git a/drivers/input/misc/cma3000_d0x_spi.c b/drivers/input/misc/cma3000_d0x_spi.c
new file mode 100644
index 0000000..ab61861
--- /dev/null
+++ b/drivers/input/misc/cma3000_d0x_spi.c
@@ -0,0 +1,153 @@
+/*
+ * Implements SPI interface for VTI CMA300_D0x Accelerometer driver
+ *
+ * Copyright (C) 2011 Qtechnology
+ * Author: Ricardo Ribalda <ricardo.ribalda@gmail.com.com>
+ * Based on:
+ * drivers/input/misc/cma3000_d0x_i2c.c by Hemanth V
+ * drivers/input/mis/adxl34x-spi.c by Michael Hennerich
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/input/cma3000.h>
+#include "cma3000_d0x.h"
+
+static int cma3000_spi_write(struct device *dev, u8 reg, u8 val, char *msg)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ int ret;
+ u8 tmp[2];
+
+ tmp[0] = (reg << 2) | 2;
+ tmp[1] = val;
+
+ ret = spi_write_then_read(spi, tmp, sizeof(tmp), NULL, 0);
+ if (ret < 0) {
+ dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int cma3000_spi_read(struct device *dev, u8 reg, char *msg)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ int ret;
+
+ ret = spi_w8r8(spi, reg << 2);
+ if (ret < 0)
+ dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
+
+ return ret;
+}
+
+static const struct cma3000_bus_ops cma3000_spi_bops = {
+ .bustype = BUS_SPI,
+#define CMA3000_BUSSPI (1 << 4)
+ .ctrl_mod = CMA3000_BUSSPI,
+ .read = cma3000_spi_read,
+ .write = cma3000_spi_write,
+};
+
+static int __devinit cma3000_spi_probe(struct spi_device *spi)
+{
+ struct cma3000_accl_data *data;
+
+ data = cma3000_init(&spi->dev, spi->irq, &cma3000_spi_bops);
+ if (IS_ERR(data))
+ return PTR_ERR(data);
+
+ spi_set_drvdata(spi, data);
+
+ return 0;
+}
+
+static int __devexit cma3000_spi_remove(struct spi_device *spi)
+{
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_exit(data);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int cma3000_spi_suspend(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_suspend(data);
+
+ return 0;
+}
+
+static int cma3000_spi_resume(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_resume(data);
+
+ return 0;
+}
+
+static const struct dev_pm_ops cma3000_spi_pm_ops = {
+ .suspend = cma3000_spi_suspend,
+ .resume = cma3000_spi_resume,
+};
+
+static SIMPLE_DEV_PM_OPS(cma3000_spi_pm, cma3000_spi_suspend,
+ cma3000_spi_resume);
+#endif
+
+static const struct of_device_id cma3000_spi_dt_ids[] = {
+ { .compatible = "vti,cma3000_d01", },
+ { },
+};
+
+MODULE_DEVICE_TABLE(of, cma3000_spi_dt_ids);
+
+static struct spi_driver cma3000_driver = {
+ .driver = {
+ .name = "cma3000_d01",
+ .owner = THIS_MODULE,
+ .of_match_table = cma3000_spi_dt_ids,
+#ifdef CONFIG_PM
+ .pm = &cma3000_spi_pm,
+#endif
+ },
+ .probe = cma3000_spi_probe,
+ .remove = __devexit_p(cma3000_spi_remove),
+};
+
+static int __init cma3000_spi_init(void)
+{
+ return spi_register_driver(&cma3000_driver);
+}
+module_init(cma3000_spi_init);
+
+static void __exit cma3000_spi_exit(void)
+{
+ spi_unregister_driver(&cma3000_driver);
+}
+module_exit(cma3000_spi_exit);
+
+MODULE_DESCRIPTION("CMA3000-D0x Accelerometer SPI Driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>");
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 4/5] input/cma3000_d0x: Add CMA3000 spi support
[not found] ` <1320874652-18371-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi, alan, david, Shubhrajyoti,
saaguirre, hemanthv, linux-doc, linux-kernel, linux-input,
devicetree-discuss
Add support for SPI communication.
v5: Fixes suggested by Grant Likely
-Drop .bus line
-Code Style
-Use of_device_id table
v4: Add ACKs to patch
v3: Fixes suggested by Jonathan Cameron
-Separate write/read commands
-Do not check 1/0 mask
-Use spi_w8r8 and spi_write_then_read functions
v2: Fixes suggested by Jonathan Cameron
-Add filename to based on header
-Rename set with write
-Set spi buffers as cache aligned
-Code Style
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/input/misc/Kconfig | 14 +++-
drivers/input/misc/Makefile | 1 +
drivers/input/misc/cma3000_d0x_spi.c | 153 ++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+), 2 deletions(-)
create mode 100644 drivers/input/misc/cma3000_d0x_spi.c
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index a1aa35a..39f4374 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -519,8 +519,8 @@ config INPUT_CMA3000
Say Y here if you want to use VTI CMA3000_D0x Accelerometer
driver
- This driver currently only supports I2C interface to the
- controller. Also select the I2C method.
+ This driver supports I2C and SPI interface to the
+ controller. Also select the I2C method and/or the SPI method.
If unsure, say N
@@ -537,6 +537,16 @@ config INPUT_CMA3000_I2C
To compile this driver as a module, choose M here: the
module will be called cma3000_d0x_i2c.
+config INPUT_CMA3000_SPI
+ tristate "Support SPI bus connection"
+ depends on INPUT_CMA3000 && SPI
+ help
+ Say Y here if you want to use VTI CMA3000_D0x Accelerometer
+ through SPI interface.
+
+ To compile this driver as a module, choose M here: the
+ module will be called cma3000_d0x_spi.
+
config INPUT_XEN_KBDDEV_FRONTEND
tristate "Xen virtual keyboard and mouse support"
depends on XEN_FBDEV_FRONTEND
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 53a8d0f..fb05beb 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_INPUT_BMA150) += bma150.o
obj-$(CONFIG_INPUT_CM109) += cm109.o
obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o
obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o
+obj-$(CONFIG_INPUT_CMA3000_SPI) += cma3000_d0x_spi.o
obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o
obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
diff --git a/drivers/input/misc/cma3000_d0x_spi.c b/drivers/input/misc/cma3000_d0x_spi.c
new file mode 100644
index 0000000..ab61861
--- /dev/null
+++ b/drivers/input/misc/cma3000_d0x_spi.c
@@ -0,0 +1,153 @@
+/*
+ * Implements SPI interface for VTI CMA300_D0x Accelerometer driver
+ *
+ * Copyright (C) 2011 Qtechnology
+ * Author: Ricardo Ribalda <ricardo.ribalda@gmail.com.com>
+ * Based on:
+ * drivers/input/misc/cma3000_d0x_i2c.c by Hemanth V
+ * drivers/input/mis/adxl34x-spi.c by Michael Hennerich
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/input/cma3000.h>
+#include "cma3000_d0x.h"
+
+static int cma3000_spi_write(struct device *dev, u8 reg, u8 val, char *msg)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ int ret;
+ u8 tmp[2];
+
+ tmp[0] = (reg << 2) | 2;
+ tmp[1] = val;
+
+ ret = spi_write_then_read(spi, tmp, sizeof(tmp), NULL, 0);
+ if (ret < 0) {
+ dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int cma3000_spi_read(struct device *dev, u8 reg, char *msg)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ int ret;
+
+ ret = spi_w8r8(spi, reg << 2);
+ if (ret < 0)
+ dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
+
+ return ret;
+}
+
+static const struct cma3000_bus_ops cma3000_spi_bops = {
+ .bustype = BUS_SPI,
+#define CMA3000_BUSSPI (1 << 4)
+ .ctrl_mod = CMA3000_BUSSPI,
+ .read = cma3000_spi_read,
+ .write = cma3000_spi_write,
+};
+
+static int __devinit cma3000_spi_probe(struct spi_device *spi)
+{
+ struct cma3000_accl_data *data;
+
+ data = cma3000_init(&spi->dev, spi->irq, &cma3000_spi_bops);
+ if (IS_ERR(data))
+ return PTR_ERR(data);
+
+ spi_set_drvdata(spi, data);
+
+ return 0;
+}
+
+static int __devexit cma3000_spi_remove(struct spi_device *spi)
+{
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_exit(data);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int cma3000_spi_suspend(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_suspend(data);
+
+ return 0;
+}
+
+static int cma3000_spi_resume(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_resume(data);
+
+ return 0;
+}
+
+static const struct dev_pm_ops cma3000_spi_pm_ops = {
+ .suspend = cma3000_spi_suspend,
+ .resume = cma3000_spi_resume,
+};
+
+static SIMPLE_DEV_PM_OPS(cma3000_spi_pm, cma3000_spi_suspend,
+ cma3000_spi_resume);
+#endif
+
+static const struct of_device_id cma3000_spi_dt_ids[] = {
+ { .compatible = "vti,cma3000_d01", },
+ { },
+};
+
+MODULE_DEVICE_TABLE(of, cma3000_spi_dt_ids);
+
+static struct spi_driver cma3000_driver = {
+ .driver = {
+ .name = "cma3000_d01",
+ .owner = THIS_MODULE,
+ .of_match_table = cma3000_spi_dt_ids,
+#ifdef CONFIG_PM
+ .pm = &cma3000_spi_pm,
+#endif
+ },
+ .probe = cma3000_spi_probe,
+ .remove = __devexit_p(cma3000_spi_remove),
+};
+
+static int __init cma3000_spi_init(void)
+{
+ return spi_register_driver(&cma3000_driver);
+}
+module_init(cma3000_spi_init);
+
+static void __exit cma3000_spi_exit(void)
+{
+ spi_unregister_driver(&cma3000_driver);
+}
+module_exit(cma3000_spi_exit);
+
+MODULE_DESCRIPTION("CMA3000-D0x Accelerometer SPI Driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>");
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 4/5] input/cma3000_d0x: Add CMA3000 spi support
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap-/UHa2rfvQTnk1uMJSBkQmQ,
dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w,
jic23-KWPb1pKIrIJaa/9Udqfwiw, aghayal-sgV2jX0FEOL9JmXXK+q4OQ,
sameo-VuQAYsv1563Yd54FQh9/CA, peter.ujfalusi
Add support for SPI communication.
v5: Fixes suggested by Grant Likely
-Drop .bus line
-Code Style
-Use of_device_id table
v4: Add ACKs to patch
v3: Fixes suggested by Jonathan Cameron
-Separate write/read commands
-Do not check 1/0 mask
-Use spi_w8r8 and spi_write_then_read functions
v2: Fixes suggested by Jonathan Cameron
-Add filename to based on header
-Rename set with write
-Set spi buffers as cache aligned
-Code Style
Acked-by: Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/input/misc/Kconfig | 14 +++-
drivers/input/misc/Makefile | 1 +
drivers/input/misc/cma3000_d0x_spi.c | 153 ++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+), 2 deletions(-)
create mode 100644 drivers/input/misc/cma3000_d0x_spi.c
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index a1aa35a..39f4374 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -519,8 +519,8 @@ config INPUT_CMA3000
Say Y here if you want to use VTI CMA3000_D0x Accelerometer
driver
- This driver currently only supports I2C interface to the
- controller. Also select the I2C method.
+ This driver supports I2C and SPI interface to the
+ controller. Also select the I2C method and/or the SPI method.
If unsure, say N
@@ -537,6 +537,16 @@ config INPUT_CMA3000_I2C
To compile this driver as a module, choose M here: the
module will be called cma3000_d0x_i2c.
+config INPUT_CMA3000_SPI
+ tristate "Support SPI bus connection"
+ depends on INPUT_CMA3000 && SPI
+ help
+ Say Y here if you want to use VTI CMA3000_D0x Accelerometer
+ through SPI interface.
+
+ To compile this driver as a module, choose M here: the
+ module will be called cma3000_d0x_spi.
+
config INPUT_XEN_KBDDEV_FRONTEND
tristate "Xen virtual keyboard and mouse support"
depends on XEN_FBDEV_FRONTEND
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 53a8d0f..fb05beb 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_INPUT_BMA150) += bma150.o
obj-$(CONFIG_INPUT_CM109) += cm109.o
obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o
obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o
+obj-$(CONFIG_INPUT_CMA3000_SPI) += cma3000_d0x_spi.o
obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o
obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
diff --git a/drivers/input/misc/cma3000_d0x_spi.c b/drivers/input/misc/cma3000_d0x_spi.c
new file mode 100644
index 0000000..ab61861
--- /dev/null
+++ b/drivers/input/misc/cma3000_d0x_spi.c
@@ -0,0 +1,153 @@
+/*
+ * Implements SPI interface for VTI CMA300_D0x Accelerometer driver
+ *
+ * Copyright (C) 2011 Qtechnology
+ * Author: Ricardo Ribalda <ricardo.ribalda-Re5JQEeQqe8ybS5Ee8rs3A@public.gmane.org>
+ * Based on:
+ * drivers/input/misc/cma3000_d0x_i2c.c by Hemanth V
+ * drivers/input/mis/adxl34x-spi.c by Michael Hennerich
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/input/cma3000.h>
+#include "cma3000_d0x.h"
+
+static int cma3000_spi_write(struct device *dev, u8 reg, u8 val, char *msg)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ int ret;
+ u8 tmp[2];
+
+ tmp[0] = (reg << 2) | 2;
+ tmp[1] = val;
+
+ ret = spi_write_then_read(spi, tmp, sizeof(tmp), NULL, 0);
+ if (ret < 0) {
+ dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int cma3000_spi_read(struct device *dev, u8 reg, char *msg)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ int ret;
+
+ ret = spi_w8r8(spi, reg << 2);
+ if (ret < 0)
+ dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
+
+ return ret;
+}
+
+static const struct cma3000_bus_ops cma3000_spi_bops = {
+ .bustype = BUS_SPI,
+#define CMA3000_BUSSPI (1 << 4)
+ .ctrl_mod = CMA3000_BUSSPI,
+ .read = cma3000_spi_read,
+ .write = cma3000_spi_write,
+};
+
+static int __devinit cma3000_spi_probe(struct spi_device *spi)
+{
+ struct cma3000_accl_data *data;
+
+ data = cma3000_init(&spi->dev, spi->irq, &cma3000_spi_bops);
+ if (IS_ERR(data))
+ return PTR_ERR(data);
+
+ spi_set_drvdata(spi, data);
+
+ return 0;
+}
+
+static int __devexit cma3000_spi_remove(struct spi_device *spi)
+{
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_exit(data);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int cma3000_spi_suspend(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_suspend(data);
+
+ return 0;
+}
+
+static int cma3000_spi_resume(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
+
+ cma3000_resume(data);
+
+ return 0;
+}
+
+static const struct dev_pm_ops cma3000_spi_pm_ops = {
+ .suspend = cma3000_spi_suspend,
+ .resume = cma3000_spi_resume,
+};
+
+static SIMPLE_DEV_PM_OPS(cma3000_spi_pm, cma3000_spi_suspend,
+ cma3000_spi_resume);
+#endif
+
+static const struct of_device_id cma3000_spi_dt_ids[] = {
+ { .compatible = "vti,cma3000_d01", },
+ { },
+};
+
+MODULE_DEVICE_TABLE(of, cma3000_spi_dt_ids);
+
+static struct spi_driver cma3000_driver = {
+ .driver = {
+ .name = "cma3000_d01",
+ .owner = THIS_MODULE,
+ .of_match_table = cma3000_spi_dt_ids,
+#ifdef CONFIG_PM
+ .pm = &cma3000_spi_pm,
+#endif
+ },
+ .probe = cma3000_spi_probe,
+ .remove = __devexit_p(cma3000_spi_remove),
+};
+
+static int __init cma3000_spi_init(void)
+{
+ return spi_register_driver(&cma3000_driver);
+}
+module_init(cma3000_spi_init);
+
+static void __exit cma3000_spi_exit(void)
+{
+ spi_unregister_driver(&cma3000_driver);
+}
+module_exit(cma3000_spi_exit);
+
+MODULE_DESCRIPTION("CMA3000-D0x Accelerometer SPI Driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>");
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 5/5] input/cma3000_d0x: Match comment to name of struct
2011-11-09 21:37 ` Ricardo Ribalda Delgado
` (9 preceding siblings ...)
(?)
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
-1 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
include/linux/input/cma3000.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/linux/input/cma3000.h b/include/linux/input/cma3000.h
index cbbaac2..e8c28e8 100644
--- a/include/linux/input/cma3000.h
+++ b/include/linux/input/cma3000.h
@@ -33,7 +33,7 @@
#define CMARANGE_8G 8000
/**
- * struct cma3000_i2c_platform_data - CMA3000 Platform data
+ * struct cma3000_platform_data - CMA3000 Platform data
* @fuzz_x: Noise on X Axis
* @fuzz_y: Noise on Y Axis
* @fuzz_z: Noise on Z Axis
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 5/5] input/cma3000_d0x: Match comment to name of struct
2011-11-09 21:37 ` Ricardo Ribalda Delgado
` (10 preceding siblings ...)
(?)
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
-1 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap, dmitry.torokhov, grant.likely, ricardo.ribalda, jic23,
aghayal, sameo, peter.ujfalusi, alan, david, Shubhrajyoti,
saaguirre, hemanthv, linux-doc, linux-kernel, linux-input,
devicetree-discuss
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
include/linux/input/cma3000.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/linux/input/cma3000.h b/include/linux/input/cma3000.h
index cbbaac2..e8c28e8 100644
--- a/include/linux/input/cma3000.h
+++ b/include/linux/input/cma3000.h
@@ -33,7 +33,7 @@
#define CMARANGE_8G 8000
/**
- * struct cma3000_i2c_platform_data - CMA3000 Platform data
+ * struct cma3000_platform_data - CMA3000 Platform data
* @fuzz_x: Noise on X Axis
* @fuzz_y: Noise on Y Axis
* @fuzz_z: Noise on Z Axis
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCHv6_input/next 5/5] input/cma3000_d0x: Match comment to name of struct
[not found] ` <1320874652-18371-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-11-09 21:37 ` Ricardo Ribalda Delgado
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda Delgado @ 2011-11-09 21:37 UTC (permalink / raw)
To: rdunlap-/UHa2rfvQTnk1uMJSBkQmQ,
dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w,
jic23-KWPb1pKIrIJaa/9Udqfwiw, aghayal-sgV2jX0FEOL9JmXXK+q4OQ,
sameo-VuQAYsv1563Yd54FQh9/CA, peter.ujfalusi
Acked-by: Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
include/linux/input/cma3000.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/linux/input/cma3000.h b/include/linux/input/cma3000.h
index cbbaac2..e8c28e8 100644
--- a/include/linux/input/cma3000.h
+++ b/include/linux/input/cma3000.h
@@ -33,7 +33,7 @@
#define CMARANGE_8G 8000
/**
- * struct cma3000_i2c_platform_data - CMA3000 Platform data
+ * struct cma3000_platform_data - CMA3000 Platform data
* @fuzz_x: Noise on X Axis
* @fuzz_y: Noise on Y Axis
* @fuzz_z: Noise on Z Axis
--
1.7.7.2
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCHv6_input/next 4/5] input/cma3000_d0x: Add CMA3000 spi support
2011-11-09 21:37 ` Ricardo Ribalda Delgado
(?)
@ 2011-11-10 9:50 ` Shubhrajyoti
-1 siblings, 0 replies; 18+ messages in thread
From: Shubhrajyoti @ 2011-11-10 9:50 UTC (permalink / raw)
To: Ricardo Ribalda Delgado
Cc: rdunlap, dmitry.torokhov, grant.likely, jic23, aghayal, sameo,
peter.ujfalusi, alan, david, saaguirre, hemanthv, linux-doc,
linux-kernel, linux-input, devicetree-discuss
Hi Ricardo,
On Thursday 10 November 2011 03:07 AM, Ricardo Ribalda Delgado wrote:
> Add support for SPI communication.
>
> v5: Fixes suggested by Grant Likely
> -Drop .bus line
> -Code Style
> -Use of_device_id table
>
> v4: Add ACKs to patch
>
> v3: Fixes suggested by Jonathan Cameron
> -Separate write/read commands
> -Do not check 1/0 mask
> -Use spi_w8r8 and spi_write_then_read functions
>
> v2: Fixes suggested by Jonathan Cameron
> -Add filename to based on header
> -Rename set with write
> -Set spi buffers as cache aligned
> -Code Style
>
> Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
> drivers/input/misc/Kconfig | 14 +++-
> drivers/input/misc/Makefile | 1 +
> drivers/input/misc/cma3000_d0x_spi.c | 153 ++++++++++++++++++++++++++++++++++
> 3 files changed, 166 insertions(+), 2 deletions(-)
> create mode 100644 drivers/input/misc/cma3000_d0x_spi.c
>
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index a1aa35a..39f4374 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -519,8 +519,8 @@ config INPUT_CMA3000
> Say Y here if you want to use VTI CMA3000_D0x Accelerometer
> driver
>
> - This driver currently only supports I2C interface to the
> - controller. Also select the I2C method.
> + This driver supports I2C and SPI interface to the
> + controller. Also select the I2C method and/or the SPI method.
>
> If unsure, say N
>
> @@ -537,6 +537,16 @@ config INPUT_CMA3000_I2C
> To compile this driver as a module, choose M here: the
> module will be called cma3000_d0x_i2c.
>
> +config INPUT_CMA3000_SPI
> + tristate "Support SPI bus connection"
> + depends on INPUT_CMA3000 && SPI
> + help
> + Say Y here if you want to use VTI CMA3000_D0x Accelerometer
> + through SPI interface.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called cma3000_d0x_spi.
> +
> config INPUT_XEN_KBDDEV_FRONTEND
> tristate "Xen virtual keyboard and mouse support"
> depends on XEN_FBDEV_FRONTEND
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 53a8d0f..fb05beb 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -21,6 +21,7 @@ obj-$(CONFIG_INPUT_BMA150) += bma150.o
> obj-$(CONFIG_INPUT_CM109) += cm109.o
> obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o
> obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o
> +obj-$(CONFIG_INPUT_CMA3000_SPI) += cma3000_d0x_spi.o
> obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
> obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o
> obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
> diff --git a/drivers/input/misc/cma3000_d0x_spi.c b/drivers/input/misc/cma3000_d0x_spi.c
> new file mode 100644
> index 0000000..ab61861
> --- /dev/null
> +++ b/drivers/input/misc/cma3000_d0x_spi.c
> @@ -0,0 +1,153 @@
> +/*
> + * Implements SPI interface for VTI CMA300_D0x Accelerometer driver
> + *
> + * Copyright (C) 2011 Qtechnology
> + * Author: Ricardo Ribalda <ricardo.ribalda@gmail.com.com>
> + * Based on:
> + * drivers/input/misc/cma3000_d0x_i2c.c by Hemanth V
> + * drivers/input/mis/adxl34x-spi.c by Michael Hennerich
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 as published by
> + * the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/module.h>
> +#include <linux/spi/spi.h>
> +#include <linux/input/cma3000.h>
> +#include "cma3000_d0x.h"
> +
> +static int cma3000_spi_write(struct device *dev, u8 reg, u8 val, char *msg)
> +{
> + struct spi_device *spi = to_spi_device(dev);
> + int ret;
> + u8 tmp[2];
> +
> + tmp[0] = (reg << 2) | 2;
> + tmp[1] = val;
> +
> + ret = spi_write_then_read(spi, tmp, sizeof(tmp), NULL, 0);
> + if (ret < 0) {
> + dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static int cma3000_spi_read(struct device *dev, u8 reg, char *msg)
> +{
> + struct spi_device *spi = to_spi_device(dev);
> + int ret;
> +
> + ret = spi_w8r8(spi, reg << 2);
> + if (ret < 0)
> + dev_err(dev, "%s failed (%s, %d)\n", __func__, msg, ret);
> +
> + return ret;
> +}
> +
> +static const struct cma3000_bus_ops cma3000_spi_bops = {
> + .bustype = BUS_SPI,
> +#define CMA3000_BUSSPI (1 << 4)
> + .ctrl_mod = CMA3000_BUSSPI,
> + .read = cma3000_spi_read,
> + .write = cma3000_spi_write,
> +};
> +
> +static int __devinit cma3000_spi_probe(struct spi_device *spi)
> +{
> + struct cma3000_accl_data *data;
> +
> + data = cma3000_init(&spi->dev, spi->irq, &cma3000_spi_bops);
> + if (IS_ERR(data))
> + return PTR_ERR(data);
Maybe PTR_RET ?
Just a suggestion.
> +
> + spi_set_drvdata(spi, data);
> +
> + return 0;
> +}
> +
> +static int __devexit cma3000_spi_remove(struct spi_device *spi)
> +{
> + struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
> +
> + cma3000_exit(data);
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM
> +static int cma3000_spi_suspend(struct device *dev)
> +{
> + struct spi_device *spi = to_spi_device(dev);
> + struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
> +
> + cma3000_suspend(data);
> +
> + return 0;
> +}
> +
> +static int cma3000_spi_resume(struct device *dev)
> +{
> + struct spi_device *spi = to_spi_device(dev);
> + struct cma3000_accl_data *data = dev_get_drvdata(&spi->dev);
> +
> + cma3000_resume(data);
> +
> + return 0;
> +}
> +
> +static const struct dev_pm_ops cma3000_spi_pm_ops = {
> + .suspend = cma3000_spi_suspend,
> + .resume = cma3000_spi_resume,
> +};
> +
> +static SIMPLE_DEV_PM_OPS(cma3000_spi_pm, cma3000_spi_suspend,
> + cma3000_spi_resume);
> +#endif
> +
> +static const struct of_device_id cma3000_spi_dt_ids[] = {
> + { .compatible = "vti,cma3000_d01", },
> + { },
> +};
> +
> +MODULE_DEVICE_TABLE(of, cma3000_spi_dt_ids);
> +
> +static struct spi_driver cma3000_driver = {
> + .driver = {
> + .name = "cma3000_d01",
> + .owner = THIS_MODULE,
> + .of_match_table = cma3000_spi_dt_ids,
> +#ifdef CONFIG_PM
> + .pm = &cma3000_spi_pm,
> +#endif
> + },
> + .probe = cma3000_spi_probe,
> + .remove = __devexit_p(cma3000_spi_remove),
> +};
> +
> +static int __init cma3000_spi_init(void)
> +{
> + return spi_register_driver(&cma3000_driver);
> +}
> +module_init(cma3000_spi_init);
> +
> +static void __exit cma3000_spi_exit(void)
> +{
> + spi_unregister_driver(&cma3000_driver);
> +}
> +module_exit(cma3000_spi_exit);
> +
> +MODULE_DESCRIPTION("CMA3000-D0x Accelerometer SPI Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>");
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2011-11-10 9:50 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-09 21:37 [PATCHv6_input/next 0/5] Add spi support for CMA3000 driver Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` [PATCHv6_input/next 1/5] input/cma3000_d0x: Support devices without pdata Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` [PATCHv6_input/next 2/5] input/cma3000_d0x: Check silicon version Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` [PATCHv6_input/next 3/5] input/cma3000_d0x: Keep configuration on poweroff Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` [PATCHv6_input/next 4/5] input/cma3000_d0x: Add CMA3000 spi support Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-10 9:50 ` Shubhrajyoti
2011-11-09 21:37 ` Ricardo Ribalda Delgado
[not found] ` <1320874652-18371-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-11-09 21:37 ` [PATCHv6_input/next 5/5] input/cma3000_d0x: Match comment to name of struct Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
2011-11-09 21:37 ` Ricardo Ribalda Delgado
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.