2 * tps6507x.c -- TPS6507x chip family multi-function driver
4 * Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com)
7 * todd.fischer@ridgerun.com
11 * Using code from wm831x-*.c, wm8400-core, Wolfson Microelectronics PLC.
13 * For licencing details see kernel-base/COPYING
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/init.h>
20 #include <linux/slab.h>
21 #include <linux/i2c.h>
22 #include <linux/mfd/core.h>
23 #include <linux/mfd/tps6507x.h>
25 static struct mfd_cell tps6507x_devs[] = {
27 .name = "tps6507x-pmic",
32 static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
33 int bytes, void *dest)
35 struct i2c_client *i2c = tps6507x->i2c_client;
36 struct i2c_msg xfer[2];
40 xfer[0].addr = i2c->addr;
46 xfer[1].addr = i2c->addr;
47 xfer[1].flags = I2C_M_RD;
51 ret = i2c_transfer(i2c->adapter, xfer, 2);
60 static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
63 struct i2c_client *i2c = tps6507x->i2c_client;
64 /* we add 1 byte for device register */
65 u8 msg[TPS6507X_MAX_REGISTER + 1];
68 if (bytes > (TPS6507X_MAX_REGISTER + 1))
72 memcpy(&msg[1], src, bytes);
74 ret = i2c_master_send(i2c, msg, bytes + 1);
82 static int tps6507x_i2c_probe(struct i2c_client *i2c,
83 const struct i2c_device_id *id)
85 struct tps6507x_dev *tps6507x;
88 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
89 if (tps6507x == NULL) {
94 i2c_set_clientdata(i2c, tps6507x);
95 tps6507x->dev = &i2c->dev;
96 tps6507x->i2c_client = i2c;
97 tps6507x->read_dev = tps6507x_i2c_read_device;
98 tps6507x->write_dev = tps6507x_i2c_write_device;
100 ret = mfd_add_devices(tps6507x->dev, -1,
101 tps6507x_devs, ARRAY_SIZE(tps6507x_devs),
110 mfd_remove_devices(tps6507x->dev);
115 static int tps6507x_i2c_remove(struct i2c_client *i2c)
117 struct tps6507x_dev *tps6507x = i2c_get_clientdata(i2c);
119 mfd_remove_devices(tps6507x->dev);
125 static const struct i2c_device_id tps6507x_i2c_id[] = {
129 MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
132 static struct i2c_driver tps6507x_i2c_driver = {
135 .owner = THIS_MODULE,
137 .probe = tps6507x_i2c_probe,
138 .remove = tps6507x_i2c_remove,
139 .id_table = tps6507x_i2c_id,
142 static int __init tps6507x_i2c_init(void)
144 return i2c_add_driver(&tps6507x_i2c_driver);
146 /* init early so consumer devices can complete system boot */
147 subsys_initcall(tps6507x_i2c_init);
149 static void __exit tps6507x_i2c_exit(void)
151 i2c_del_driver(&tps6507x_i2c_driver);
153 module_exit(tps6507x_i2c_exit);
155 MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
156 MODULE_LICENSE("GPL");