linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Mack <daniel@caiaq.de>
To: linux-kernel@vger.kernel.org
Cc: Daniel Mack <daniel@caiaq.de>, Pavel Machek <pavel@ucw.cz>,
	Eric Piel <eric.piel@tremplin-utc.net>
Subject: [PATCH 5/5] lis3: SPI transport layer
Date: Mon,  2 Mar 2009 15:31:50 +0100	[thread overview]
Message-ID: <1236004310-29196-5-git-send-email-daniel@caiaq.de> (raw)
In-Reply-To: <1236004310-29196-4-git-send-email-daniel@caiaq.de>

Make use of the new abstraction layer and add a new transport layer for
spi. Works fine on a PXA based board.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Eric Piel <eric.piel@tremplin-utc.net>
---
 drivers/hwmon/Kconfig         |   16 ++++++
 drivers/hwmon/Makefile        |    1 +
 drivers/hwmon/lis3lv02d_spi.c |  113 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/lis3lv02d_spi.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index b84bf06..9d78ab4 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -895,6 +895,22 @@ config SENSORS_LIS3LV02D
 	  Say Y here if you have an applicable laptop and want to experience
 	  the awesome power of lis3lv02d.
 
+config SENSORS_LIS3_SPI
+	tristate "STMicroeletronics LIS3LV02Dx three-axis digital accelerometer (SPI)"
+	depends on !ACPI && SPI_MASTER && INPUT
+	default n
+	help
+	  This driver provides support for the LIS3LV02Dx accelerometer connected
+	  via SPI. The accelerometer data is readable via
+	  /sys/devices/platform/lis3lv02d.
+
+	  This driver also provides an absolute input class device, allowing
+	  the laptop to act as a pinball machine-esque joystick.
+
+	  This driver can also be built as modules.  If so, the core module
+	  will be called lis3lv02d and a specific module for the SPI transport
+	  is called lis3lv02d_spi.
+
 config SENSORS_APPLESMC
 	tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
 	depends on INPUT && X86
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2e80f37..6f0f4b3 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_SENSORS_IBMPEX)	+= ibmpex.o
 obj-$(CONFIG_SENSORS_IT87)	+= it87.o
 obj-$(CONFIG_SENSORS_K8TEMP)	+= k8temp.o
 obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
+obj-$(CONFIG_SENSORS_LIS3_SPI)	+= lis3lv02d.o lis3lv02d_spi.o
 obj-$(CONFIG_SENSORS_LM63)	+= lm63.o
 obj-$(CONFIG_SENSORS_LM70)	+= lm70.o
 obj-$(CONFIG_SENSORS_LM75)	+= lm75.o
diff --git a/drivers/hwmon/lis3lv02d_spi.c b/drivers/hwmon/lis3lv02d_spi.c
new file mode 100644
index 0000000..14436e7
--- /dev/null
+++ b/drivers/hwmon/lis3lv02d_spi.c
@@ -0,0 +1,113 @@
+/*
+ * lis3lv02d_spi - SPI glue layer for lis3lv02d
+ *
+ * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
+ *
+ *  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
+ *  publishhed by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/spi/spi.h>
+
+#include "lis3lv02d.h"
+
+#define DRV_NAME 	"lis3lv02d_spi"
+#define LIS3_SPI_READ	0x80
+
+static int lis3_spi_read(struct lis3lv02d *lis3, int reg, u8 *v)
+{
+	struct spi_device *spi = lis3->bus_priv;
+	int ret = spi_w8r8(spi, reg | LIS3_SPI_READ);
+	if (ret < 0)
+		return -EINVAL;
+
+	*v = (u8) ret;
+	return 0;
+}
+
+static int lis3_spi_write(struct lis3lv02d *lis3, int reg, u8 val)
+{
+	u8 tmp[2] = { reg, val };
+	struct spi_device *spi = lis3->bus_priv;
+	return spi_write(spi, tmp, sizeof(tmp));
+}
+
+static int lis3_spi_init(struct lis3lv02d *lis3)
+{
+	u8 reg;
+	int ret;
+
+	ret = lis3->read(lis3, CTRL_REG1, &reg);
+	if (ret < 0)
+		return ret;
+
+	reg |= 0x40;
+	return lis3->write(lis3, CTRL_REG1, reg);
+}
+
+static struct axis_conversion lis3lv02d_axis_normal = { 1, 2, 3 };
+
+static int __devinit lis302dl_spi_probe(struct spi_device *spi)
+{
+	int ret;
+
+	spi->bits_per_word = 8;
+	spi->mode = SPI_MODE_0;
+	ret = spi_setup(spi);
+	if (ret < 0)
+		return ret;
+
+	lis3_dev.bus_priv = spi;
+	lis3_dev.init = lis3_spi_init;
+	lis3_dev.read = lis3_spi_read;
+	lis3_dev.write = lis3_spi_write;
+	lis3_dev.irq = spi->irq;
+	lis3_dev.ac = lis3lv02d_axis_normal;
+	spi_set_drvdata(spi, &lis3_dev);
+
+	ret = lis3lv02d_init_device(&lis3_dev);
+	return ret;
+}
+
+static int __devexit lis302dl_spi_remove(struct spi_device *spi)
+{
+	struct lis3lv02d *lis3 = spi_get_drvdata(spi);
+	lis3lv02d_joystick_disable();
+	lis3lv02d_poweroff(lis3);
+	return 0;
+}
+
+static struct spi_driver lis302dl_spi_driver = {
+	.driver	 = {
+		.name   = DRV_NAME,
+		.owner  = THIS_MODULE,
+	},
+	.probe	= lis302dl_spi_probe,
+	.remove	= __devexit_p(lis302dl_spi_remove),
+};
+
+static int __init lis302dl_init(void)
+{
+	return spi_register_driver(&lis302dl_spi_driver);
+}
+
+static void __exit lis302dl_exit(void)
+{
+	spi_unregister_driver(&lis302dl_spi_driver);
+}
+
+module_init(lis302dl_init);
+module_exit(lis302dl_exit);
+
+MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
+MODULE_DESCRIPTION("lis3lv02d SPI glue layer");
+MODULE_LICENSE("GPL");
+
-- 
1.6.1.3


  reply	other threads:[~2009-03-02 14:33 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-01 13:29 lis3's ACPI dependency Daniel Mack
2009-03-01 18:28 ` Éric Piel
2009-03-02  0:55   ` Daniel Mack
2009-03-02 10:17     ` Éric Piel
2009-03-02 14:31       ` Daniel Mack
2009-03-02 14:31         ` Daniel Mack
2009-03-02 14:31           ` [PATCH 3/5] lis3: reorder functions to make forward decl obsolete Daniel Mack
2009-03-02 14:31             ` [PATCH 4/5] lis3: solve dependency between core and ACPI Daniel Mack
2009-03-02 14:31               ` Daniel Mack [this message]
2009-03-02 15:11                 ` [PATCH 5/5] lis3: SPI transport layer Pavel Machek
2009-03-03 19:59                 ` Éric Piel
2009-03-02 15:10               ` [PATCH 4/5] lis3: solve dependency between core and ACPI Pavel Machek
2009-03-03 19:54               ` Éric Piel
2009-03-04  1:43                 ` Daniel Mack
2009-03-16 19:09                   ` Daniel Mack
2009-03-16 21:30                     ` Pavel Machek
2009-03-04  1:44                 ` [PATCH 3/5] lis3: reorder functions to make forward decl obsolete Daniel Mack
2009-03-04  1:44                   ` [PATCH 4/5] lis3: solve dependency between core and ACPI Daniel Mack
2009-03-04  1:44                     ` [PATCH 5/5] lis3: SPI transport layer Daniel Mack
2009-03-22 23:31                       ` Éric Piel
2009-03-23 15:41                         ` Daniel Mack
2009-03-22 23:25                     ` [PATCH 4/5] lis3: solve dependency between core and ACPI Éric Piel
2009-03-22 23:42                       ` Daniel Mack
2009-03-22 23:51                         ` [PATCH 1/3] lis3: reorder functions to make forward decl obsolete Daniel Mack
2009-03-22 23:51                           ` [PATCH 2/3] lis3: solve dependency between core and ACPI Daniel Mack
2009-03-22 23:51                             ` [PATCH 3/3] lis3: SPI transport layer Daniel Mack
2009-03-23 15:48                               ` Éric Piel
2016-08-10 10:31                               ` Geert Uytterhoeven
2009-03-23 15:48                             ` [PATCH 2/3] lis3: solve dependency between core and ACPI Éric Piel
2009-03-23 15:48                           ` [PATCH 1/3] lis3: reorder functions to make forward decl obsolete Éric Piel
2009-03-02 14:57             ` [PATCH 3/5] " Pavel Machek
2009-03-02 14:36       ` lis3's ACPI dependency Daniel Mack
2009-03-02 14:40         ` Éric Piel
2009-03-01 19:51 ` Robert Hancock
2009-03-02  0:50   ` Daniel Mack

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=1236004310-29196-5-git-send-email-daniel@caiaq.de \
    --to=daniel@caiaq.de \
    --cc=eric.piel@tremplin-utc.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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;
as well as URLs for NNTP newsgroup(s).