xhci: Add missing CAS workaround for Intel Sunrise Point xHCI
[linux/fpc-iii.git] / drivers / mfd / tps6507x.c
blob1f308c4e36941cf29897469006d8daeae035a4be
1 /*
2 * tps6507x.c -- TPS6507x chip family multi-function driver
4 * Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com)
6 * Author: Todd Fischer
7 * todd.fischer@ridgerun.com
9 * Credits:
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/of.h>
23 #include <linux/of_device.h>
24 #include <linux/mfd/core.h>
25 #include <linux/mfd/tps6507x.h>
27 static const struct mfd_cell tps6507x_devs[] = {
29 .name = "tps6507x-pmic",
32 .name = "tps6507x-ts",
37 static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
38 int bytes, void *dest)
40 struct i2c_client *i2c = tps6507x->i2c_client;
41 struct i2c_msg xfer[2];
42 int ret;
44 /* Write register */
45 xfer[0].addr = i2c->addr;
46 xfer[0].flags = 0;
47 xfer[0].len = 1;
48 xfer[0].buf = &reg;
50 /* Read data */
51 xfer[1].addr = i2c->addr;
52 xfer[1].flags = I2C_M_RD;
53 xfer[1].len = bytes;
54 xfer[1].buf = dest;
56 ret = i2c_transfer(i2c->adapter, xfer, 2);
57 if (ret == 2)
58 ret = 0;
59 else if (ret >= 0)
60 ret = -EIO;
62 return ret;
65 static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
66 int bytes, void *src)
68 struct i2c_client *i2c = tps6507x->i2c_client;
69 /* we add 1 byte for device register */
70 u8 msg[TPS6507X_MAX_REGISTER + 1];
71 int ret;
73 if (bytes > TPS6507X_MAX_REGISTER)
74 return -EINVAL;
76 msg[0] = reg;
77 memcpy(&msg[1], src, bytes);
79 ret = i2c_master_send(i2c, msg, bytes + 1);
80 if (ret < 0)
81 return ret;
82 if (ret != bytes + 1)
83 return -EIO;
84 return 0;
87 static int tps6507x_i2c_probe(struct i2c_client *i2c,
88 const struct i2c_device_id *id)
90 struct tps6507x_dev *tps6507x;
92 tps6507x = devm_kzalloc(&i2c->dev, sizeof(struct tps6507x_dev),
93 GFP_KERNEL);
94 if (tps6507x == NULL)
95 return -ENOMEM;
97 i2c_set_clientdata(i2c, tps6507x);
98 tps6507x->dev = &i2c->dev;
99 tps6507x->i2c_client = i2c;
100 tps6507x->read_dev = tps6507x_i2c_read_device;
101 tps6507x->write_dev = tps6507x_i2c_write_device;
103 return devm_mfd_add_devices(tps6507x->dev, -1, tps6507x_devs,
104 ARRAY_SIZE(tps6507x_devs), NULL, 0, NULL);
107 static const struct i2c_device_id tps6507x_i2c_id[] = {
108 { "tps6507x", 0 },
111 MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
113 #ifdef CONFIG_OF
114 static const struct of_device_id tps6507x_of_match[] = {
115 {.compatible = "ti,tps6507x", },
118 MODULE_DEVICE_TABLE(of, tps6507x_of_match);
119 #endif
121 static struct i2c_driver tps6507x_i2c_driver = {
122 .driver = {
123 .name = "tps6507x",
124 .of_match_table = of_match_ptr(tps6507x_of_match),
126 .probe = tps6507x_i2c_probe,
127 .id_table = tps6507x_i2c_id,
130 static int __init tps6507x_i2c_init(void)
132 return i2c_add_driver(&tps6507x_i2c_driver);
134 /* init early so consumer devices can complete system boot */
135 subsys_initcall(tps6507x_i2c_init);
137 static void __exit tps6507x_i2c_exit(void)
139 i2c_del_driver(&tps6507x_i2c_driver);
141 module_exit(tps6507x_i2c_exit);
143 MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
144 MODULE_LICENSE("GPL");