2 * tps65910.c -- TI TPS6591x
4 * Copyright 2010 Texas Instruments Inc.
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
7 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/i2c.h>
21 #include <linux/gpio.h>
22 #include <linux/mfd/core.h>
23 #include <linux/mfd/tps65910.h>
25 static struct mfd_cell tps65910s
[] = {
27 .name
= "tps65910-pmic",
30 .name
= "tps65910-rtc",
33 .name
= "tps65910-power",
38 static int tps65910_i2c_read(struct tps65910
*tps65910
, u8 reg
,
39 int bytes
, void *dest
)
41 struct i2c_client
*i2c
= tps65910
->i2c_client
;
42 struct i2c_msg xfer
[2];
46 xfer
[0].addr
= i2c
->addr
;
52 xfer
[1].addr
= i2c
->addr
;
53 xfer
[1].flags
= I2C_M_RD
;
57 ret
= i2c_transfer(i2c
->adapter
, xfer
, 2);
66 static int tps65910_i2c_write(struct tps65910
*tps65910
, u8 reg
,
69 struct i2c_client
*i2c
= tps65910
->i2c_client
;
70 /* we add 1 byte for device register */
71 u8 msg
[TPS65910_MAX_REGISTER
+ 1];
74 if (bytes
> TPS65910_MAX_REGISTER
)
78 memcpy(&msg
[1], src
, bytes
);
80 ret
= i2c_master_send(i2c
, msg
, bytes
+ 1);
88 int tps65910_set_bits(struct tps65910
*tps65910
, u8 reg
, u8 mask
)
93 mutex_lock(&tps65910
->io_mutex
);
94 err
= tps65910_i2c_read(tps65910
, reg
, 1, &data
);
96 dev_err(tps65910
->dev
, "read from reg %x failed\n", reg
);
101 err
= tps65910_i2c_write(tps65910
, reg
, 1, &data
);
103 dev_err(tps65910
->dev
, "write to reg %x failed\n", reg
);
106 mutex_unlock(&tps65910
->io_mutex
);
109 EXPORT_SYMBOL_GPL(tps65910_set_bits
);
111 int tps65910_clear_bits(struct tps65910
*tps65910
, u8 reg
, u8 mask
)
116 mutex_lock(&tps65910
->io_mutex
);
117 err
= tps65910_i2c_read(tps65910
, reg
, 1, &data
);
119 dev_err(tps65910
->dev
, "read from reg %x failed\n", reg
);
124 err
= tps65910_i2c_write(tps65910
, reg
, 1, &data
);
126 dev_err(tps65910
->dev
, "write to reg %x failed\n", reg
);
129 mutex_unlock(&tps65910
->io_mutex
);
132 EXPORT_SYMBOL_GPL(tps65910_clear_bits
);
134 static int tps65910_i2c_probe(struct i2c_client
*i2c
,
135 const struct i2c_device_id
*id
)
137 struct tps65910
*tps65910
;
138 struct tps65910_board
*pmic_plat_data
;
139 struct tps65910_platform_data
*init_data
;
142 pmic_plat_data
= dev_get_platdata(&i2c
->dev
);
146 init_data
= kzalloc(sizeof(struct tps65910_platform_data
), GFP_KERNEL
);
147 if (init_data
== NULL
)
150 init_data
->irq
= pmic_plat_data
->irq
;
151 init_data
->irq_base
= pmic_plat_data
->irq
;
153 tps65910
= kzalloc(sizeof(struct tps65910
), GFP_KERNEL
);
154 if (tps65910
== NULL
)
157 i2c_set_clientdata(i2c
, tps65910
);
158 tps65910
->dev
= &i2c
->dev
;
159 tps65910
->i2c_client
= i2c
;
160 tps65910
->id
= id
->driver_data
;
161 tps65910
->read
= tps65910_i2c_read
;
162 tps65910
->write
= tps65910_i2c_write
;
163 mutex_init(&tps65910
->io_mutex
);
165 ret
= mfd_add_devices(tps65910
->dev
, -1,
166 tps65910s
, ARRAY_SIZE(tps65910s
),
171 tps65910_gpio_init(tps65910
, pmic_plat_data
->gpio_base
);
173 ret
= tps65910_irq_init(tps65910
, init_data
->irq
, init_data
);
180 mfd_remove_devices(tps65910
->dev
);
185 static int tps65910_i2c_remove(struct i2c_client
*i2c
)
187 struct tps65910
*tps65910
= i2c_get_clientdata(i2c
);
189 mfd_remove_devices(tps65910
->dev
);
195 static const struct i2c_device_id tps65910_i2c_id
[] = {
196 { "tps65910", TPS65910
},
197 { "tps65911", TPS65911
},
200 MODULE_DEVICE_TABLE(i2c
, tps65910_i2c_id
);
203 static struct i2c_driver tps65910_i2c_driver
= {
206 .owner
= THIS_MODULE
,
208 .probe
= tps65910_i2c_probe
,
209 .remove
= tps65910_i2c_remove
,
210 .id_table
= tps65910_i2c_id
,
213 static int __init
tps65910_i2c_init(void)
215 return i2c_add_driver(&tps65910_i2c_driver
);
217 /* init early so consumer devices can complete system boot */
218 subsys_initcall(tps65910_i2c_init
);
220 static void __exit
tps65910_i2c_exit(void)
222 i2c_del_driver(&tps65910_i2c_driver
);
224 module_exit(tps65910_i2c_exit
);
226 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
227 MODULE_AUTHOR("Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>");
228 MODULE_DESCRIPTION("TPS6591x chip family multi-function driver");
229 MODULE_LICENSE("GPL");