tmp006.c (2bb3b8f69accde535daee238e0f707dec452e0e4) | tmp006.c (c359a80ca29099be951a1fa5c7529792cadf3e8f) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * tmp006.c - Support for TI TMP006 IR thermopile sensor 4 * 5 * Copyright (c) 2013 Peter Meerwald <pmeerw@pmeerw.net> 6 * 7 * Driver for the Texas Instruments I2C 16-bit IR thermopile sensor 8 * --- 179 unchanged lines hidden (view full) --- 188 189 did = i2c_smbus_read_word_swapped(client, TMP006_DEVICE_ID); 190 if (did < 0) 191 return false; 192 193 return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; 194} 195 | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * tmp006.c - Support for TI TMP006 IR thermopile sensor 4 * 5 * Copyright (c) 2013 Peter Meerwald <pmeerw@pmeerw.net> 6 * 7 * Driver for the Texas Instruments I2C 16-bit IR thermopile sensor 8 * --- 179 unchanged lines hidden (view full) --- 188 189 did = i2c_smbus_read_word_swapped(client, TMP006_DEVICE_ID); 190 if (did < 0) 191 return false; 192 193 return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; 194} 195 |
196static int tmp006_powerdown(struct tmp006_data *data) | 196static int tmp006_power(struct device *dev, bool up) |
197{ | 197{ |
198 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 199 struct tmp006_data *data = iio_priv(indio_dev); 200 201 if (up) 202 data->config |= TMP006_CONFIG_MOD_MASK; 203 else 204 data->config &= ~TMP006_CONFIG_MOD_MASK; 205 |
|
198 return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, | 206 return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, |
199 data->config & ~TMP006_CONFIG_MOD_MASK); | 207 data->config); |
200} 201 | 208} 209 |
202static void tmp006_powerdown_cleanup(void *data) | 210static void tmp006_powerdown_cleanup(void *dev) |
203{ | 211{ |
204 tmp006_powerdown(data); | 212 tmp006_power(dev, false); |
205} 206 207static int tmp006_probe(struct i2c_client *client, 208 const struct i2c_device_id *id) 209{ 210 struct iio_dev *indio_dev; 211 struct tmp006_data *data; 212 int ret; --- 21 unchanged lines hidden (view full) --- 234 indio_dev->channels = tmp006_channels; 235 indio_dev->num_channels = ARRAY_SIZE(tmp006_channels); 236 237 ret = i2c_smbus_read_word_swapped(data->client, TMP006_CONFIG); 238 if (ret < 0) 239 return ret; 240 data->config = ret; 241 | 213} 214 215static int tmp006_probe(struct i2c_client *client, 216 const struct i2c_device_id *id) 217{ 218 struct iio_dev *indio_dev; 219 struct tmp006_data *data; 220 int ret; --- 21 unchanged lines hidden (view full) --- 242 indio_dev->channels = tmp006_channels; 243 indio_dev->num_channels = ARRAY_SIZE(tmp006_channels); 244 245 ret = i2c_smbus_read_word_swapped(data->client, TMP006_CONFIG); 246 if (ret < 0) 247 return ret; 248 data->config = ret; 249 |
242 ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data); | 250 if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) { 251 ret = tmp006_power(&client->dev, true); 252 if (ret < 0) 253 return ret; 254 } 255 256 ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup, 257 &client->dev); |
243 if (ret < 0) 244 return ret; 245 246 return devm_iio_device_register(&client->dev, indio_dev); 247} 248 249#ifdef CONFIG_PM_SLEEP 250static int tmp006_suspend(struct device *dev) 251{ | 258 if (ret < 0) 259 return ret; 260 261 return devm_iio_device_register(&client->dev, indio_dev); 262} 263 264#ifdef CONFIG_PM_SLEEP 265static int tmp006_suspend(struct device *dev) 266{ |
252 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 253 return tmp006_powerdown(iio_priv(indio_dev)); | 267 return tmp006_power(dev, false); |
254} 255 256static int tmp006_resume(struct device *dev) 257{ | 268} 269 270static int tmp006_resume(struct device *dev) 271{ |
258 struct tmp006_data *data = iio_priv(i2c_get_clientdata( 259 to_i2c_client(dev))); 260 return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 261 data->config | TMP006_CONFIG_MOD_MASK); | 272 return tmp006_power(dev, true); |
262} 263#endif 264 265static SIMPLE_DEV_PM_OPS(tmp006_pm_ops, tmp006_suspend, tmp006_resume); 266 267static const struct i2c_device_id tmp006_id[] = { 268 { "tmp006", 0 }, 269 { } --- 16 unchanged lines hidden --- | 273} 274#endif 275 276static SIMPLE_DEV_PM_OPS(tmp006_pm_ops, tmp006_suspend, tmp006_resume); 277 278static const struct i2c_device_id tmp006_id[] = { 279 { "tmp006", 0 }, 280 { } --- 16 unchanged lines hidden --- |