xref: /linux/drivers/iio/pressure/mpl115_i2c.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
136edc939SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c984b9cbSAkinobu Mita /*
3c984b9cbSAkinobu Mita  * Freescale MPL115A2 pressure/temperature sensor
4c984b9cbSAkinobu Mita  *
5c984b9cbSAkinobu Mita  * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
6c984b9cbSAkinobu Mita  *
7c984b9cbSAkinobu Mita  * (7-bit I2C slave address 0x60)
8c984b9cbSAkinobu Mita  *
9c984b9cbSAkinobu Mita  * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A2.pdf
10c984b9cbSAkinobu Mita  */
11c984b9cbSAkinobu Mita 
12c984b9cbSAkinobu Mita #include <linux/module.h>
13c984b9cbSAkinobu Mita #include <linux/i2c.h>
14c984b9cbSAkinobu Mita 
15c984b9cbSAkinobu Mita #include "mpl115.h"
16c984b9cbSAkinobu Mita 
mpl115_i2c_init(struct device * dev)17c984b9cbSAkinobu Mita static int mpl115_i2c_init(struct device *dev)
18c984b9cbSAkinobu Mita {
19c984b9cbSAkinobu Mita 	return 0;
20c984b9cbSAkinobu Mita }
21c984b9cbSAkinobu Mita 
mpl115_i2c_read(struct device * dev,u8 address)22c984b9cbSAkinobu Mita static int mpl115_i2c_read(struct device *dev, u8 address)
23c984b9cbSAkinobu Mita {
24c984b9cbSAkinobu Mita 	return i2c_smbus_read_word_swapped(to_i2c_client(dev), address);
25c984b9cbSAkinobu Mita }
26c984b9cbSAkinobu Mita 
mpl115_i2c_write(struct device * dev,u8 address,u8 value)27c984b9cbSAkinobu Mita static int mpl115_i2c_write(struct device *dev, u8 address, u8 value)
28c984b9cbSAkinobu Mita {
29c984b9cbSAkinobu Mita 	return i2c_smbus_write_byte_data(to_i2c_client(dev), address, value);
30c984b9cbSAkinobu Mita }
31c984b9cbSAkinobu Mita 
32c984b9cbSAkinobu Mita static const struct mpl115_ops mpl115_i2c_ops = {
33c984b9cbSAkinobu Mita 	.init = mpl115_i2c_init,
34c984b9cbSAkinobu Mita 	.read = mpl115_i2c_read,
35c984b9cbSAkinobu Mita 	.write = mpl115_i2c_write,
36c984b9cbSAkinobu Mita };
37c984b9cbSAkinobu Mita 
mpl115_i2c_probe(struct i2c_client * client)388afce858SUwe Kleine-König static int mpl115_i2c_probe(struct i2c_client *client)
39c984b9cbSAkinobu Mita {
408afce858SUwe Kleine-König 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
41c984b9cbSAkinobu Mita 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
42f8d9d3b4SMatt Ranostay 		return -EOPNOTSUPP;
43c984b9cbSAkinobu Mita 
44c984b9cbSAkinobu Mita 	return mpl115_probe(&client->dev, id->name, &mpl115_i2c_ops);
45c984b9cbSAkinobu Mita }
46c984b9cbSAkinobu Mita 
47c984b9cbSAkinobu Mita static const struct i2c_device_id mpl115_i2c_id[] = {
48*4391affaSUwe Kleine-König 	{ "mpl115" },
49c984b9cbSAkinobu Mita 	{ }
50c984b9cbSAkinobu Mita };
51c984b9cbSAkinobu Mita MODULE_DEVICE_TABLE(i2c, mpl115_i2c_id);
52c984b9cbSAkinobu Mita 
53c984b9cbSAkinobu Mita static struct i2c_driver mpl115_i2c_driver = {
54c984b9cbSAkinobu Mita 	.driver = {
55c984b9cbSAkinobu Mita 		.name	= "mpl115",
560c3a3335SRajat Khandelwal 		.pm = pm_ptr(&mpl115_dev_pm_ops),
57c984b9cbSAkinobu Mita 	},
587cf15f42SUwe Kleine-König 	.probe = mpl115_i2c_probe,
59c984b9cbSAkinobu Mita 	.id_table = mpl115_i2c_id,
60c984b9cbSAkinobu Mita };
61c984b9cbSAkinobu Mita module_i2c_driver(mpl115_i2c_driver);
62c984b9cbSAkinobu Mita 
63c984b9cbSAkinobu Mita MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
64c984b9cbSAkinobu Mita MODULE_DESCRIPTION("Freescale MPL115A2 pressure/temperature driver");
65c984b9cbSAkinobu Mita MODULE_LICENSE("GPL");
66c7c848b0SJonathan Cameron MODULE_IMPORT_NS(IIO_MPL115);
67