1 // SPDX-License-Identifier: GPL-2.0-only
3 * Implements I2C interface for VTI CMA300_D0x Accelerometer driver
5 * Copyright (C) 2010 Texas Instruments
6 * Author: Hemanth V <hemanthv@ti.com>
9 #include <linux/module.h>
10 #include <linux/i2c.h>
11 #include <linux/input/cma3000.h>
12 #include "cma3000_d0x.h"
14 static int cma3000_i2c_set(struct device
*dev
,
15 u8 reg
, u8 val
, char *msg
)
17 struct i2c_client
*client
= to_i2c_client(dev
);
20 ret
= i2c_smbus_write_byte_data(client
, reg
, val
);
23 "%s failed (%s, %d)\n", __func__
, msg
, ret
);
27 static int cma3000_i2c_read(struct device
*dev
, u8 reg
, char *msg
)
29 struct i2c_client
*client
= to_i2c_client(dev
);
32 ret
= i2c_smbus_read_byte_data(client
, reg
);
35 "%s failed (%s, %d)\n", __func__
, msg
, ret
);
39 static const struct cma3000_bus_ops cma3000_i2c_bops
= {
41 #define CMA3000_BUSI2C (0 << 4)
42 .ctrl_mod
= CMA3000_BUSI2C
,
43 .read
= cma3000_i2c_read
,
44 .write
= cma3000_i2c_set
,
47 static int cma3000_i2c_probe(struct i2c_client
*client
)
49 struct cma3000_accl_data
*data
;
51 data
= cma3000_init(&client
->dev
, client
->irq
, &cma3000_i2c_bops
);
55 i2c_set_clientdata(client
, data
);
60 static void cma3000_i2c_remove(struct i2c_client
*client
)
62 struct cma3000_accl_data
*data
= i2c_get_clientdata(client
);
67 static int cma3000_i2c_suspend(struct device
*dev
)
69 struct i2c_client
*client
= to_i2c_client(dev
);
70 struct cma3000_accl_data
*data
= i2c_get_clientdata(client
);
72 cma3000_suspend(data
);
77 static int cma3000_i2c_resume(struct device
*dev
)
79 struct i2c_client
*client
= to_i2c_client(dev
);
80 struct cma3000_accl_data
*data
= i2c_get_clientdata(client
);
87 static const struct dev_pm_ops cma3000_i2c_pm_ops
= {
88 .suspend
= cma3000_i2c_suspend
,
89 .resume
= cma3000_i2c_resume
,
92 static const struct i2c_device_id cma3000_i2c_id
[] = {
97 MODULE_DEVICE_TABLE(i2c
, cma3000_i2c_id
);
99 static struct i2c_driver cma3000_i2c_driver
= {
100 .probe
= cma3000_i2c_probe
,
101 .remove
= cma3000_i2c_remove
,
102 .id_table
= cma3000_i2c_id
,
104 .name
= "cma3000_i2c_accl",
105 .pm
= pm_sleep_ptr(&cma3000_i2c_pm_ops
),
109 module_i2c_driver(cma3000_i2c_driver
);
111 MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver");
112 MODULE_LICENSE("GPL");
113 MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>");