sched: task_tick_rt: Remove the obsolete ->signal != NULL check
[linux-2.6/next.git] / drivers / hwmon / lis3lv02d_i2c.c
blobdc1f5402c1d7ddcdaf4396fe177a689550b9ac2b
1 /*
2 * drivers/hwmon/lis3lv02d_i2c.c
4 * Implements I2C interface for lis3lv02d (STMicroelectronics) accelerometer.
5 * Driver is based on corresponding SPI driver written by Daniel Mack
6 * (lis3lv02d_spi.c (C) 2009 Daniel Mack <daniel@caiaq.de> ).
8 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
10 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/err.h>
31 #include <linux/i2c.h>
32 #include "lis3lv02d.h"
34 #define DRV_NAME "lis3lv02d_i2c"
36 static inline s32 lis3_i2c_write(struct lis3lv02d *lis3, int reg, u8 value)
38 struct i2c_client *c = lis3->bus_priv;
39 return i2c_smbus_write_byte_data(c, reg, value);
42 static inline s32 lis3_i2c_read(struct lis3lv02d *lis3, int reg, u8 *v)
44 struct i2c_client *c = lis3->bus_priv;
45 *v = i2c_smbus_read_byte_data(c, reg);
46 return 0;
49 static int lis3_i2c_init(struct lis3lv02d *lis3)
51 u8 reg;
52 int ret;
54 /* power up the device */
55 ret = lis3->read(lis3, CTRL_REG1, &reg);
56 if (ret < 0)
57 return ret;
59 reg |= CTRL1_PD0;
60 return lis3->write(lis3, CTRL_REG1, reg);
63 /* Default axis mapping but it can be overwritten by platform data */
64 static struct axis_conversion lis3lv02d_axis_map = { LIS3_DEV_X,
65 LIS3_DEV_Y,
66 LIS3_DEV_Z };
68 static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
69 const struct i2c_device_id *id)
71 int ret = 0;
72 struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
74 if (pdata) {
75 if (pdata->axis_x)
76 lis3lv02d_axis_map.x = pdata->axis_x;
78 if (pdata->axis_y)
79 lis3lv02d_axis_map.y = pdata->axis_y;
81 if (pdata->axis_z)
82 lis3lv02d_axis_map.z = pdata->axis_z;
84 if (pdata->setup_resources)
85 ret = pdata->setup_resources();
87 if (ret)
88 goto fail;
91 lis3_dev.pdata = pdata;
92 lis3_dev.bus_priv = client;
93 lis3_dev.init = lis3_i2c_init;
94 lis3_dev.read = lis3_i2c_read;
95 lis3_dev.write = lis3_i2c_write;
96 lis3_dev.irq = client->irq;
97 lis3_dev.ac = lis3lv02d_axis_map;
99 i2c_set_clientdata(client, &lis3_dev);
100 ret = lis3lv02d_init_device(&lis3_dev);
101 fail:
102 return ret;
105 static int __devexit lis3lv02d_i2c_remove(struct i2c_client *client)
107 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
108 struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
110 if (pdata && pdata->release_resources)
111 pdata->release_resources();
113 lis3lv02d_joystick_disable();
114 lis3lv02d_poweroff(lis3);
116 return lis3lv02d_remove_fs(&lis3_dev);
119 #ifdef CONFIG_PM
120 static int lis3lv02d_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
122 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
124 if (!lis3->pdata->wakeup_flags)
125 lis3lv02d_poweroff(lis3);
126 return 0;
129 static int lis3lv02d_i2c_resume(struct i2c_client *client)
131 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
133 if (!lis3->pdata->wakeup_flags)
134 lis3lv02d_poweron(lis3);
135 return 0;
138 static void lis3lv02d_i2c_shutdown(struct i2c_client *client)
140 lis3lv02d_i2c_suspend(client, PMSG_SUSPEND);
142 #else
143 #define lis3lv02d_i2c_suspend NULL
144 #define lis3lv02d_i2c_resume NULL
145 #define lis3lv02d_i2c_shutdown NULL
146 #endif
148 static const struct i2c_device_id lis3lv02d_id[] = {
149 {"lis3lv02d", 0 },
153 MODULE_DEVICE_TABLE(i2c, lis3lv02d_id);
155 static struct i2c_driver lis3lv02d_i2c_driver = {
156 .driver = {
157 .name = DRV_NAME,
158 .owner = THIS_MODULE,
160 .suspend = lis3lv02d_i2c_suspend,
161 .shutdown = lis3lv02d_i2c_shutdown,
162 .resume = lis3lv02d_i2c_resume,
163 .probe = lis3lv02d_i2c_probe,
164 .remove = __devexit_p(lis3lv02d_i2c_remove),
165 .id_table = lis3lv02d_id,
168 static int __init lis3lv02d_init(void)
170 return i2c_add_driver(&lis3lv02d_i2c_driver);
173 static void __exit lis3lv02d_exit(void)
175 i2c_del_driver(&lis3lv02d_i2c_driver);
178 MODULE_AUTHOR("Nokia Corporation");
179 MODULE_DESCRIPTION("lis3lv02d I2C interface");
180 MODULE_LICENSE("GPL");
182 module_init(lis3lv02d_init);
183 module_exit(lis3lv02d_exit);