aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorDaniel Mack <daniel@caiaq.de>2009-03-31 18:24:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-01 11:59:22 -0400
commitbb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5 (patch)
treeb95c8f5b1a26f807755ca18d99b09627e184b33e /drivers/hwmon
parenta38da2ed74f628c1f3e907c772be21a66eccab9c (diff)
lis3: SPI transport layer
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> Acked-by: Pavel Machek <pavel@ucw.cz> Acked-by: Eric Piel <eric.piel@tremplin-utc.net> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig16
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/lis3lv02d_spi.c114
3 files changed, 131 insertions, 0 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bc6810c22dd7..ce52bf2f235e 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -932,6 +932,22 @@ config SENSORS_LIS3LV02D
932 Say Y here if you have an applicable laptop and want to experience 932 Say Y here if you have an applicable laptop and want to experience
933 the awesome power of lis3lv02d. 933 the awesome power of lis3lv02d.
934 934
935config SENSORS_LIS3_SPI
936 tristate "STMicroeletronics LIS3LV02Dx three-axis digital accelerometer (SPI)"
937 depends on !ACPI && SPI_MASTER && INPUT
938 default n
939 help
940 This driver provides support for the LIS3LV02Dx accelerometer connected
941 via SPI. The accelerometer data is readable via
942 /sys/devices/platform/lis3lv02d.
943
944 This driver also provides an absolute input class device, allowing
945 the laptop to act as a pinball machine-esque joystick.
946
947 This driver can also be built as modules. If so, the core module
948 will be called lis3lv02d and a specific module for the SPI transport
949 is called lis3lv02d_spi.
950
935config SENSORS_APPLESMC 951config SENSORS_APPLESMC
936 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" 952 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
937 depends on INPUT && X86 953 depends on INPUT && X86
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 4da261d16abf..3a6b1f06f8f4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
52obj-$(CONFIG_SENSORS_IT87) += it87.o 52obj-$(CONFIG_SENSORS_IT87) += it87.o
53obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o 53obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
54obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o 54obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
55obj-$(CONFIG_SENSORS_LIS3_SPI) += lis3lv02d.o lis3lv02d_spi.o
55obj-$(CONFIG_SENSORS_LM63) += lm63.o 56obj-$(CONFIG_SENSORS_LM63) += lm63.o
56obj-$(CONFIG_SENSORS_LM70) += lm70.o 57obj-$(CONFIG_SENSORS_LM70) += lm70.o
57obj-$(CONFIG_SENSORS_LM75) += lm75.o 58obj-$(CONFIG_SENSORS_LM75) += lm75.o
diff --git a/drivers/hwmon/lis3lv02d_spi.c b/drivers/hwmon/lis3lv02d_spi.c
new file mode 100644
index 000000000000..07ae74b0e191
--- /dev/null
+++ b/drivers/hwmon/lis3lv02d_spi.c
@@ -0,0 +1,114 @@
1/*
2 * lis3lv02d_spi - SPI glue layer for lis3lv02d
3 *
4 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * publishhed by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/input.h>
16#include <linux/interrupt.h>
17#include <linux/workqueue.h>
18#include <linux/spi/spi.h>
19
20#include "lis3lv02d.h"
21
22#define DRV_NAME "lis3lv02d_spi"
23#define LIS3_SPI_READ 0x80
24
25static int lis3_spi_read(struct lis3lv02d *lis3, int reg, u8 *v)
26{
27 struct spi_device *spi = lis3->bus_priv;
28 int ret = spi_w8r8(spi, reg | LIS3_SPI_READ);
29 if (ret < 0)
30 return -EINVAL;
31
32 *v = (u8) ret;
33 return 0;
34}
35
36static int lis3_spi_write(struct lis3lv02d *lis3, int reg, u8 val)
37{
38 u8 tmp[2] = { reg, val };
39 struct spi_device *spi = lis3->bus_priv;
40 return spi_write(spi, tmp, sizeof(tmp));
41}
42
43static int lis3_spi_init(struct lis3lv02d *lis3)
44{
45 u8 reg;
46 int ret;
47
48 /* power up the device */
49 ret = lis3->read(lis3, CTRL_REG1, &reg);
50 if (ret < 0)
51 return ret;
52
53 reg |= CTRL1_PD0;
54 return lis3->write(lis3, CTRL_REG1, reg);
55}
56
57static struct axis_conversion lis3lv02d_axis_normal = { 1, 2, 3 };
58
59static int __devinit lis302dl_spi_probe(struct spi_device *spi)
60{
61 int ret;
62
63 spi->bits_per_word = 8;
64 spi->mode = SPI_MODE_0;
65 ret = spi_setup(spi);
66 if (ret < 0)
67 return ret;
68
69 lis3_dev.bus_priv = spi;
70 lis3_dev.init = lis3_spi_init;
71 lis3_dev.read = lis3_spi_read;
72 lis3_dev.write = lis3_spi_write;
73 lis3_dev.irq = spi->irq;
74 lis3_dev.ac = lis3lv02d_axis_normal;
75 spi_set_drvdata(spi, &lis3_dev);
76
77 ret = lis3lv02d_init_device(&lis3_dev);
78 return ret;
79}
80
81static int __devexit lis302dl_spi_remove(struct spi_device *spi)
82{
83 struct lis3lv02d *lis3 = spi_get_drvdata(spi);
84 lis3lv02d_joystick_disable();
85 lis3lv02d_poweroff(lis3);
86 return 0;
87}
88
89static struct spi_driver lis302dl_spi_driver = {
90 .driver = {
91 .name = DRV_NAME,
92 .owner = THIS_MODULE,
93 },
94 .probe = lis302dl_spi_probe,
95 .remove = __devexit_p(lis302dl_spi_remove),
96};
97
98static int __init lis302dl_init(void)
99{
100 return spi_register_driver(&lis302dl_spi_driver);
101}
102
103static void __exit lis302dl_exit(void)
104{
105 spi_unregister_driver(&lis302dl_spi_driver);
106}
107
108module_init(lis302dl_init);
109module_exit(lis302dl_exit);
110
111MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
112MODULE_DESCRIPTION("lis3lv02d SPI glue layer");
113MODULE_LICENSE("GPL");
114