Commit fbb899356d4a6b6080ab3d9656914938db49449e
Committed by
Dmitry Torokhov
1 parent
76e2c68f32
Exists in
master
and in
7 other branches
Input: adxl34x-i2c - convert to dev_pm_ops
There is a general move to convert drivers to use dev_pm_ops rather than bus specific ones in order to facilitate core development. Do this conversion for adxl34x-i2c. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Showing 1 changed file with 9 additions and 7 deletions Inline Diff
drivers/input/misc/adxl34x-i2c.c
1 | /* | 1 | /* |
2 | * ADLX345/346 Three-Axis Digital Accelerometers (I2C Interface) | 2 | * ADLX345/346 Three-Axis Digital Accelerometers (I2C Interface) |
3 | * | 3 | * |
4 | * Enter bugs at http://blackfin.uclinux.org/ | 4 | * Enter bugs at http://blackfin.uclinux.org/ |
5 | * | 5 | * |
6 | * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc. | 6 | * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc. |
7 | * Licensed under the GPL-2 or later. | 7 | * Licensed under the GPL-2 or later. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/input.h> /* BUS_I2C */ | 10 | #include <linux/input.h> /* BUS_I2C */ |
11 | #include <linux/i2c.h> | 11 | #include <linux/i2c.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/pm.h> | ||
14 | #include "adxl34x.h" | 15 | #include "adxl34x.h" |
15 | 16 | ||
16 | static int adxl34x_smbus_read(struct device *dev, unsigned char reg) | 17 | static int adxl34x_smbus_read(struct device *dev, unsigned char reg) |
17 | { | 18 | { |
18 | struct i2c_client *client = to_i2c_client(dev); | 19 | struct i2c_client *client = to_i2c_client(dev); |
19 | 20 | ||
20 | return i2c_smbus_read_byte_data(client, reg); | 21 | return i2c_smbus_read_byte_data(client, reg); |
21 | } | 22 | } |
22 | 23 | ||
23 | static int adxl34x_smbus_write(struct device *dev, | 24 | static int adxl34x_smbus_write(struct device *dev, |
24 | unsigned char reg, unsigned char val) | 25 | unsigned char reg, unsigned char val) |
25 | { | 26 | { |
26 | struct i2c_client *client = to_i2c_client(dev); | 27 | struct i2c_client *client = to_i2c_client(dev); |
27 | 28 | ||
28 | return i2c_smbus_write_byte_data(client, reg, val); | 29 | return i2c_smbus_write_byte_data(client, reg, val); |
29 | } | 30 | } |
30 | 31 | ||
31 | static int adxl34x_smbus_read_block(struct device *dev, | 32 | static int adxl34x_smbus_read_block(struct device *dev, |
32 | unsigned char reg, int count, | 33 | unsigned char reg, int count, |
33 | void *buf) | 34 | void *buf) |
34 | { | 35 | { |
35 | struct i2c_client *client = to_i2c_client(dev); | 36 | struct i2c_client *client = to_i2c_client(dev); |
36 | 37 | ||
37 | return i2c_smbus_read_i2c_block_data(client, reg, count, buf); | 38 | return i2c_smbus_read_i2c_block_data(client, reg, count, buf); |
38 | } | 39 | } |
39 | 40 | ||
40 | static int adxl34x_i2c_read_block(struct device *dev, | 41 | static int adxl34x_i2c_read_block(struct device *dev, |
41 | unsigned char reg, int count, | 42 | unsigned char reg, int count, |
42 | void *buf) | 43 | void *buf) |
43 | { | 44 | { |
44 | struct i2c_client *client = to_i2c_client(dev); | 45 | struct i2c_client *client = to_i2c_client(dev); |
45 | int ret; | 46 | int ret; |
46 | 47 | ||
47 | ret = i2c_master_send(client, ®, 1); | 48 | ret = i2c_master_send(client, ®, 1); |
48 | if (ret < 0) | 49 | if (ret < 0) |
49 | return ret; | 50 | return ret; |
50 | 51 | ||
51 | ret = i2c_master_recv(client, buf, count); | 52 | ret = i2c_master_recv(client, buf, count); |
52 | if (ret < 0) | 53 | if (ret < 0) |
53 | return ret; | 54 | return ret; |
54 | 55 | ||
55 | if (ret != count) | 56 | if (ret != count) |
56 | return -EIO; | 57 | return -EIO; |
57 | 58 | ||
58 | return 0; | 59 | return 0; |
59 | } | 60 | } |
60 | 61 | ||
61 | static const struct adxl34x_bus_ops adxl34x_smbus_bops = { | 62 | static const struct adxl34x_bus_ops adxl34x_smbus_bops = { |
62 | .bustype = BUS_I2C, | 63 | .bustype = BUS_I2C, |
63 | .write = adxl34x_smbus_write, | 64 | .write = adxl34x_smbus_write, |
64 | .read = adxl34x_smbus_read, | 65 | .read = adxl34x_smbus_read, |
65 | .read_block = adxl34x_smbus_read_block, | 66 | .read_block = adxl34x_smbus_read_block, |
66 | }; | 67 | }; |
67 | 68 | ||
68 | static const struct adxl34x_bus_ops adxl34x_i2c_bops = { | 69 | static const struct adxl34x_bus_ops adxl34x_i2c_bops = { |
69 | .bustype = BUS_I2C, | 70 | .bustype = BUS_I2C, |
70 | .write = adxl34x_smbus_write, | 71 | .write = adxl34x_smbus_write, |
71 | .read = adxl34x_smbus_read, | 72 | .read = adxl34x_smbus_read, |
72 | .read_block = adxl34x_i2c_read_block, | 73 | .read_block = adxl34x_i2c_read_block, |
73 | }; | 74 | }; |
74 | 75 | ||
75 | static int __devinit adxl34x_i2c_probe(struct i2c_client *client, | 76 | static int __devinit adxl34x_i2c_probe(struct i2c_client *client, |
76 | const struct i2c_device_id *id) | 77 | const struct i2c_device_id *id) |
77 | { | 78 | { |
78 | struct adxl34x *ac; | 79 | struct adxl34x *ac; |
79 | int error; | 80 | int error; |
80 | 81 | ||
81 | error = i2c_check_functionality(client->adapter, | 82 | error = i2c_check_functionality(client->adapter, |
82 | I2C_FUNC_SMBUS_BYTE_DATA); | 83 | I2C_FUNC_SMBUS_BYTE_DATA); |
83 | if (!error) { | 84 | if (!error) { |
84 | dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); | 85 | dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); |
85 | return -EIO; | 86 | return -EIO; |
86 | } | 87 | } |
87 | 88 | ||
88 | ac = adxl34x_probe(&client->dev, client->irq, false, | 89 | ac = adxl34x_probe(&client->dev, client->irq, false, |
89 | i2c_check_functionality(client->adapter, | 90 | i2c_check_functionality(client->adapter, |
90 | I2C_FUNC_SMBUS_READ_I2C_BLOCK) ? | 91 | I2C_FUNC_SMBUS_READ_I2C_BLOCK) ? |
91 | &adxl34x_smbus_bops : &adxl34x_i2c_bops); | 92 | &adxl34x_smbus_bops : &adxl34x_i2c_bops); |
92 | if (IS_ERR(ac)) | 93 | if (IS_ERR(ac)) |
93 | return PTR_ERR(ac); | 94 | return PTR_ERR(ac); |
94 | 95 | ||
95 | i2c_set_clientdata(client, ac); | 96 | i2c_set_clientdata(client, ac); |
96 | 97 | ||
97 | return 0; | 98 | return 0; |
98 | } | 99 | } |
99 | 100 | ||
100 | static int __devexit adxl34x_i2c_remove(struct i2c_client *client) | 101 | static int __devexit adxl34x_i2c_remove(struct i2c_client *client) |
101 | { | 102 | { |
102 | struct adxl34x *ac = i2c_get_clientdata(client); | 103 | struct adxl34x *ac = i2c_get_clientdata(client); |
103 | 104 | ||
104 | return adxl34x_remove(ac); | 105 | return adxl34x_remove(ac); |
105 | } | 106 | } |
106 | 107 | ||
107 | #ifdef CONFIG_PM | 108 | #ifdef CONFIG_PM |
108 | static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) | 109 | static int adxl34x_i2c_suspend(struct device *dev) |
109 | { | 110 | { |
111 | struct i2c_client *client = to_i2c_client(dev); | ||
110 | struct adxl34x *ac = i2c_get_clientdata(client); | 112 | struct adxl34x *ac = i2c_get_clientdata(client); |
111 | 113 | ||
112 | adxl34x_suspend(ac); | 114 | adxl34x_suspend(ac); |
113 | 115 | ||
114 | return 0; | 116 | return 0; |
115 | } | 117 | } |
116 | 118 | ||
117 | static int adxl34x_i2c_resume(struct i2c_client *client) | 119 | static int adxl34x_i2c_resume(struct device *dev) |
118 | { | 120 | { |
121 | struct i2c_client *client = to_i2c_client(dev); | ||
119 | struct adxl34x *ac = i2c_get_clientdata(client); | 122 | struct adxl34x *ac = i2c_get_clientdata(client); |
120 | 123 | ||
121 | adxl34x_resume(ac); | 124 | adxl34x_resume(ac); |
122 | 125 | ||
123 | return 0; | 126 | return 0; |
124 | } | 127 | } |
125 | #else | ||
126 | # define adxl34x_i2c_suspend NULL | ||
127 | # define adxl34x_i2c_resume NULL | ||
128 | #endif | 128 | #endif |
129 | 129 | ||
130 | static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend, | ||
131 | adxl34x_i2c_resume); | ||
132 | |||
130 | static const struct i2c_device_id adxl34x_id[] = { | 133 | static const struct i2c_device_id adxl34x_id[] = { |
131 | { "adxl34x", 0 }, | 134 | { "adxl34x", 0 }, |
132 | { } | 135 | { } |
133 | }; | 136 | }; |
134 | 137 | ||
135 | MODULE_DEVICE_TABLE(i2c, adxl34x_id); | 138 | MODULE_DEVICE_TABLE(i2c, adxl34x_id); |
136 | 139 | ||
137 | static struct i2c_driver adxl34x_driver = { | 140 | static struct i2c_driver adxl34x_driver = { |
138 | .driver = { | 141 | .driver = { |
139 | .name = "adxl34x", | 142 | .name = "adxl34x", |
140 | .owner = THIS_MODULE, | 143 | .owner = THIS_MODULE, |
144 | .pm = &adxl34x_i2c_pm, | ||
141 | }, | 145 | }, |
142 | .probe = adxl34x_i2c_probe, | 146 | .probe = adxl34x_i2c_probe, |
143 | .remove = __devexit_p(adxl34x_i2c_remove), | 147 | .remove = __devexit_p(adxl34x_i2c_remove), |
144 | .suspend = adxl34x_i2c_suspend, | ||
145 | .resume = adxl34x_i2c_resume, | ||
146 | .id_table = adxl34x_id, | 148 | .id_table = adxl34x_id, |
147 | }; | 149 | }; |
148 | 150 | ||
149 | static int __init adxl34x_i2c_init(void) | 151 | static int __init adxl34x_i2c_init(void) |
150 | { | 152 | { |
151 | return i2c_add_driver(&adxl34x_driver); | 153 | return i2c_add_driver(&adxl34x_driver); |
152 | } | 154 | } |
153 | module_init(adxl34x_i2c_init); | 155 | module_init(adxl34x_i2c_init); |
154 | 156 | ||
155 | static void __exit adxl34x_i2c_exit(void) | 157 | static void __exit adxl34x_i2c_exit(void) |
156 | { | 158 | { |
157 | i2c_del_driver(&adxl34x_driver); | 159 | i2c_del_driver(&adxl34x_driver); |
158 | } | 160 | } |
159 | module_exit(adxl34x_i2c_exit); | 161 | module_exit(adxl34x_i2c_exit); |