1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Freescale MPL115A2 pressure/temperature sensor
4  *
5  * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
6  *
7  * (7-bit I2C slave address 0x60)
8  *
9  * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A2.pdf
10  */
11 
12 #include <linux/module.h>
13 #include <linux/i2c.h>
14 
15 #include "mpl115.h"
16 
mpl115_i2c_init(struct device * dev)17 static int mpl115_i2c_init(struct device *dev)
18 {
19 	return 0;
20 }
21 
mpl115_i2c_read(struct device * dev,u8 address)22 static int mpl115_i2c_read(struct device *dev, u8 address)
23 {
24 	return i2c_smbus_read_word_swapped(to_i2c_client(dev), address);
25 }
26 
mpl115_i2c_write(struct device * dev,u8 address,u8 value)27 static int mpl115_i2c_write(struct device *dev, u8 address, u8 value)
28 {
29 	return i2c_smbus_write_byte_data(to_i2c_client(dev), address, value);
30 }
31 
32 static const struct mpl115_ops mpl115_i2c_ops = {
33 	.init = mpl115_i2c_init,
34 	.read = mpl115_i2c_read,
35 	.write = mpl115_i2c_write,
36 };
37 
mpl115_i2c_probe(struct i2c_client * client,const struct i2c_device_id * id)38 static int mpl115_i2c_probe(struct i2c_client *client,
39 			 const struct i2c_device_id *id)
40 {
41 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
42 		return -EOPNOTSUPP;
43 
44 	return mpl115_probe(&client->dev, id->name, &mpl115_i2c_ops);
45 }
46 
47 static const struct i2c_device_id mpl115_i2c_id[] = {
48 	{ "mpl115", 0 },
49 	{ }
50 };
51 MODULE_DEVICE_TABLE(i2c, mpl115_i2c_id);
52 
53 static struct i2c_driver mpl115_i2c_driver = {
54 	.driver = {
55 		.name	= "mpl115",
56 	},
57 	.probe = mpl115_i2c_probe,
58 	.id_table = mpl115_i2c_id,
59 };
60 module_i2c_driver(mpl115_i2c_driver);
61 
62 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
63 MODULE_DESCRIPTION("Freescale MPL115A2 pressure/temperature driver");
64 MODULE_LICENSE("GPL");
65