diff options
author | Todd Fischer <todd.fischer@ridgerun.com> | 2010-04-08 03:04:55 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-05-27 19:37:38 -0400 |
commit | 31dd6a2672e337f5de188df3e5169ee732798236 (patch) | |
tree | d0a12a6622d9a32a107267a4479f6e12a495dbd3 /drivers/mfd/tps6507x.c | |
parent | 4ce5ba5ba2dfc8186bf31fe7f2d23ff6b5384124 (diff) |
mfd: Add TPS6507x support
TPS6507x are multi function (PM, touchscreen) chipsets from TI.
This commit also changes the corresponding regulator driver from being
standalone to an MFD subdevice.
Signed-off-by: Todd Fischer <todd.fischer@ridgerun.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/tps6507x.c')
-rw-r--r-- | drivers/mfd/tps6507x.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/drivers/mfd/tps6507x.c b/drivers/mfd/tps6507x.c new file mode 100644 index 000000000000..c59f74570b3b --- /dev/null +++ b/drivers/mfd/tps6507x.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * tps6507x.c -- TPS6507x chip family multi-function driver | ||
3 | * | ||
4 | * Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com) | ||
5 | * | ||
6 | * Author: Todd Fischer | ||
7 | * todd.fischer@ridgerun.com | ||
8 | * | ||
9 | * Credits: | ||
10 | * | ||
11 | * Using code from wm831x-*.c, wm8400-core, Wolfson Microelectronics PLC. | ||
12 | * | ||
13 | * For licencing details see kernel-base/COPYING | ||
14 | * | ||
15 | */ | ||
16 | |||
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> | ||
24 | |||
25 | static struct mfd_cell tps6507x_devs[] = { | ||
26 | { | ||
27 | .name = "tps6507x-pmic", | ||
28 | }, | ||
29 | }; | ||
30 | |||
31 | |||
32 | static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg, | ||
33 | int bytes, void *dest) | ||
34 | { | ||
35 | struct i2c_client *i2c = tps6507x->i2c_client; | ||
36 | struct i2c_msg xfer[2]; | ||
37 | int ret; | ||
38 | |||
39 | /* Write register */ | ||
40 | xfer[0].addr = i2c->addr; | ||
41 | xfer[0].flags = 0; | ||
42 | xfer[0].len = 1; | ||
43 | xfer[0].buf = ® | ||
44 | |||
45 | /* Read data */ | ||
46 | xfer[1].addr = i2c->addr; | ||
47 | xfer[1].flags = I2C_M_RD; | ||
48 | xfer[1].len = bytes; | ||
49 | xfer[1].buf = dest; | ||
50 | |||
51 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
52 | if (ret == 2) | ||
53 | ret = 0; | ||
54 | else if (ret >= 0) | ||
55 | ret = -EIO; | ||
56 | |||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg, | ||
61 | int bytes, void *src) | ||
62 | { | ||
63 | struct i2c_client *i2c = tps6507x->i2c_client; | ||
64 | /* we add 1 byte for device register */ | ||
65 | u8 msg[TPS6507X_MAX_REGISTER + 1]; | ||
66 | int ret; | ||
67 | |||
68 | if (bytes > (TPS6507X_MAX_REGISTER + 1)) | ||
69 | return -EINVAL; | ||
70 | |||
71 | msg[0] = reg; | ||
72 | memcpy(&msg[1], src, bytes); | ||
73 | |||
74 | ret = i2c_master_send(i2c, msg, bytes + 1); | ||
75 | if (ret < 0) | ||
76 | return ret; | ||
77 | if (ret != bytes + 1) | ||
78 | return -EIO; | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static int tps6507x_i2c_probe(struct i2c_client *i2c, | ||
83 | const struct i2c_device_id *id) | ||
84 | { | ||
85 | struct tps6507x_dev *tps6507x; | ||
86 | int ret = 0; | ||
87 | |||
88 | tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL); | ||
89 | if (tps6507x == NULL) { | ||
90 | kfree(i2c); | ||
91 | return -ENOMEM; | ||
92 | } | ||
93 | |||
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; | ||
99 | |||
100 | ret = mfd_add_devices(tps6507x->dev, -1, | ||
101 | tps6507x_devs, ARRAY_SIZE(tps6507x_devs), | ||
102 | NULL, 0); | ||
103 | |||
104 | if (ret < 0) | ||
105 | goto err; | ||
106 | |||
107 | return ret; | ||
108 | |||
109 | err: | ||
110 | mfd_remove_devices(tps6507x->dev); | ||
111 | kfree(tps6507x); | ||
112 | return ret; | ||
113 | } | ||
114 | |||
115 | static int tps6507x_i2c_remove(struct i2c_client *i2c) | ||
116 | { | ||
117 | struct tps6507x_dev *tps6507x = i2c_get_clientdata(i2c); | ||
118 | |||
119 | mfd_remove_devices(tps6507x->dev); | ||
120 | kfree(tps6507x); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static const struct i2c_device_id tps6507x_i2c_id[] = { | ||
126 | { "tps6507x", 0 }, | ||
127 | { } | ||
128 | }; | ||
129 | MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id); | ||
130 | |||
131 | |||
132 | static struct i2c_driver tps6507x_i2c_driver = { | ||
133 | .driver = { | ||
134 | .name = "tps6507x", | ||
135 | .owner = THIS_MODULE, | ||
136 | }, | ||
137 | .probe = tps6507x_i2c_probe, | ||
138 | .remove = tps6507x_i2c_remove, | ||
139 | .id_table = tps6507x_i2c_id, | ||
140 | }; | ||
141 | |||
142 | static int __init tps6507x_i2c_init(void) | ||
143 | { | ||
144 | return i2c_add_driver(&tps6507x_i2c_driver); | ||
145 | } | ||
146 | /* init early so consumer devices can complete system boot */ | ||
147 | subsys_initcall(tps6507x_i2c_init); | ||
148 | |||
149 | static void __exit tps6507x_i2c_exit(void) | ||
150 | { | ||
151 | i2c_del_driver(&tps6507x_i2c_driver); | ||
152 | } | ||
153 | module_exit(tps6507x_i2c_exit); | ||
154 | |||
155 | MODULE_DESCRIPTION("TPS6507x chip family multi-function driver"); | ||
156 | MODULE_LICENSE("GPL"); | ||