net/core: Remove unnecessary casts of private_data
[linux-2.6/x86.git] / drivers / mfd / tps6507x.c
blobd859dffed39f009d8b68c6a069d8f589341a36c2
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/mfd/core.h>
23 #include <linux/mfd/tps6507x.h>
25 static struct mfd_cell tps6507x_devs[] = {
27 .name = "tps6507x-pmic",
30 .name = "tps6507x-ts",
35 static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
36 int bytes, void *dest)
38 struct i2c_client *i2c = tps6507x->i2c_client;
39 struct i2c_msg xfer[2];
40 int ret;
42 /* Write register */
43 xfer[0].addr = i2c->addr;
44 xfer[0].flags = 0;
45 xfer[0].len = 1;
46 xfer[0].buf = &reg;
48 /* Read data */
49 xfer[1].addr = i2c->addr;
50 xfer[1].flags = I2C_M_RD;
51 xfer[1].len = bytes;
52 xfer[1].buf = dest;
54 ret = i2c_transfer(i2c->adapter, xfer, 2);
55 if (ret == 2)
56 ret = 0;
57 else if (ret >= 0)
58 ret = -EIO;
60 return ret;
63 static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
64 int bytes, void *src)
66 struct i2c_client *i2c = tps6507x->i2c_client;
67 /* we add 1 byte for device register */
68 u8 msg[TPS6507X_MAX_REGISTER + 1];
69 int ret;
71 if (bytes > (TPS6507X_MAX_REGISTER + 1))
72 return -EINVAL;
74 msg[0] = reg;
75 memcpy(&msg[1], src, bytes);
77 ret = i2c_master_send(i2c, msg, bytes + 1);
78 if (ret < 0)
79 return ret;
80 if (ret != bytes + 1)
81 return -EIO;
82 return 0;
85 static int tps6507x_i2c_probe(struct i2c_client *i2c,
86 const struct i2c_device_id *id)
88 struct tps6507x_dev *tps6507x;
89 int ret = 0;
91 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
92 if (tps6507x == NULL) {
93 kfree(i2c);
94 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 ret = mfd_add_devices(tps6507x->dev, -1,
104 tps6507x_devs, ARRAY_SIZE(tps6507x_devs),
105 NULL, 0);
107 if (ret < 0)
108 goto err;
110 return ret;
112 err:
113 mfd_remove_devices(tps6507x->dev);
114 kfree(tps6507x);
115 return ret;
118 static int tps6507x_i2c_remove(struct i2c_client *i2c)
120 struct tps6507x_dev *tps6507x = i2c_get_clientdata(i2c);
122 mfd_remove_devices(tps6507x->dev);
123 kfree(tps6507x);
125 return 0;
128 static const struct i2c_device_id tps6507x_i2c_id[] = {
129 { "tps6507x", 0 },
132 MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
135 static struct i2c_driver tps6507x_i2c_driver = {
136 .driver = {
137 .name = "tps6507x",
138 .owner = THIS_MODULE,
140 .probe = tps6507x_i2c_probe,
141 .remove = tps6507x_i2c_remove,
142 .id_table = tps6507x_i2c_id,
145 static int __init tps6507x_i2c_init(void)
147 return i2c_add_driver(&tps6507x_i2c_driver);
149 /* init early so consumer devices can complete system boot */
150 subsys_initcall(tps6507x_i2c_init);
152 static void __exit tps6507x_i2c_exit(void)
154 i2c_del_driver(&tps6507x_i2c_driver);
156 module_exit(tps6507x_i2c_exit);
158 MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
159 MODULE_LICENSE("GPL");