Skip to content

Commit 36e5287

Browse files
Margarita OlayaSamuel Ortiz
authored andcommitted
mfd: tps65912: Add new mfd device
The tps65912 chip is a power management IC. It contains the following components: - Regulators - GPIO controller The core driver is registered as a platform driver, it provides communication through I2C and SPI interfaces. Signed-off-by: Margarita Olaya Cabrera <magi@slimlogic.co.uk> Acked-by: Samuel Ortiz <sameo@linux.intel.com> Acked-by: Liam Girdwood <lrg@ti.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 8504d63 commit 36e5287

6 files changed

Lines changed: 792 additions & 0 deletions

File tree

‎drivers/mfd/Kconfig‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,28 @@ config MFD_TPS6586X
171171
This driver can also be built as a module. If so, the module
172172
will be called tps6586x.
173173

174+
config MFD_TPS65912
175+
bool "TPS65912 PMIC"
176+
depends on GPIOLIB
177+
178+
config MFD_TPS65912_I2C
179+
bool "TPS95612 Power Management chip with I2C"
180+
select MFD_CORE
181+
select MFD_TPS65912
182+
depends on I2C=y && GPIOLIB
183+
help
184+
If you say yes here you get support for the TPS65912 series of
185+
PM chips with I2C interface.
186+
187+
config MFD_TPS65912_SPI
188+
bool "TPS65912 Power Management chip with SPI"
189+
select MFD_CORE
190+
select MFD_TPS65912
191+
depends on SPI_MASTER && GPIOLIB
192+
help
193+
If you say yes here you get support for the TPS65912 series of
194+
PM chips with SPI interface.
195+
174196
config MENELAUS
175197
bool "Texas Instruments TWL92330/Menelaus PM chip"
176198
depends on I2C=y && ARCH_OMAP2

‎drivers/mfd/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ obj-$(CONFIG_MFD_WM8994) += wm8994-core.o wm8994-irq.o
3636
obj-$(CONFIG_TPS6105X) += tps6105x.o
3737
obj-$(CONFIG_TPS65010) += tps65010.o
3838
obj-$(CONFIG_TPS6507X) += tps6507x.o
39+
tps65912-objs := tps65912-core.o
40+
obj-$(CONFIG_MFD_TPS65912) += tps65912.o
41+
obj-$(CONFIG_MFD_TPS65912_I2C) += tps65912-i2c.o
42+
obj-$(CONFIG_MFD_TPS65912_SPI) += tps65912-spi.o
3943
obj-$(CONFIG_MENELAUS) += menelaus.o
4044

4145
obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o

‎drivers/mfd/tps65912-core.c‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* tps65912-core.c -- TI TPS65912x
3+
*
4+
* Copyright 2011 Texas Instruments Inc.
5+
*
6+
* Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk>
7+
*
8+
* This program is free software; you can redistribute it and/or modify it
9+
* under the terms of the GNU General Public License as published by the
10+
* Free Software Foundation; either version 2 of the License, or (at your
11+
* option) any later version.
12+
*
13+
* This driver is based on wm8350 implementation.
14+
*/
15+
16+
#include <linux/module.h>
17+
#include <linux/moduleparam.h>
18+
#include <linux/init.h>
19+
#include <linux/slab.h>
20+
#include <linux/gpio.h>
21+
#include <linux/mfd/core.h>
22+
#include <linux/mfd/tps65912.h>
23+
24+
static struct mfd_cell tps65912s[] = {
25+
{
26+
.name = "tps65912-pmic",
27+
},
28+
};
29+
30+
int tps65912_set_bits(struct tps65912 *tps65912, u8 reg, u8 mask)
31+
{
32+
u8 data;
33+
int err;
34+
35+
mutex_lock(&tps65912->io_mutex);
36+
37+
err = tps65912->read(tps65912, reg, 1, &data);
38+
if (err) {
39+
dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
40+
goto out;
41+
}
42+
43+
data |= mask;
44+
err = tps65912->write(tps65912, reg, 1, &data);
45+
if (err)
46+
dev_err(tps65912->dev, "Write to reg 0x%x failed\n", reg);
47+
48+
out:
49+
mutex_unlock(&tps65912->io_mutex);
50+
return err;
51+
}
52+
EXPORT_SYMBOL_GPL(tps65912_set_bits);
53+
54+
int tps65912_clear_bits(struct tps65912 *tps65912, u8 reg, u8 mask)
55+
{
56+
u8 data;
57+
int err;
58+
59+
mutex_lock(&tps65912->io_mutex);
60+
err = tps65912->read(tps65912, reg, 1, &data);
61+
if (err) {
62+
dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
63+
goto out;
64+
}
65+
66+
data &= ~mask;
67+
err = tps65912->write(tps65912, reg, 1, &data);
68+
if (err)
69+
dev_err(tps65912->dev, "Write to reg 0x%x failed\n", reg);
70+
71+
out:
72+
mutex_unlock(&tps65912->io_mutex);
73+
return err;
74+
}
75+
EXPORT_SYMBOL_GPL(tps65912_clear_bits);
76+
77+
static inline int tps65912_read(struct tps65912 *tps65912, u8 reg)
78+
{
79+
u8 val;
80+
int err;
81+
82+
err = tps65912->read(tps65912, reg, 1, &val);
83+
if (err < 0)
84+
return err;
85+
86+
return val;
87+
}
88+
89+
static inline int tps65912_write(struct tps65912 *tps65912, u8 reg, u8 val)
90+
{
91+
return tps65912->write(tps65912, reg, 1, &val);
92+
}
93+
94+
int tps65912_reg_read(struct tps65912 *tps65912, u8 reg)
95+
{
96+
int data;
97+
98+
mutex_lock(&tps65912->io_mutex);
99+
100+
data = tps65912_read(tps65912, reg);
101+
if (data < 0)
102+
dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
103+
104+
mutex_unlock(&tps65912->io_mutex);
105+
return data;
106+
}
107+
EXPORT_SYMBOL_GPL(tps65912_reg_read);
108+
109+
int tps65912_reg_write(struct tps65912 *tps65912, u8 reg, u8 val)
110+
{
111+
int err;
112+
113+
mutex_lock(&tps65912->io_mutex);
114+
115+
err = tps65912_write(tps65912, reg, val);
116+
if (err < 0)
117+
dev_err(tps65912->dev, "Write for reg 0x%x failed\n", reg);
118+
119+
mutex_unlock(&tps65912->io_mutex);
120+
return err;
121+
}
122+
EXPORT_SYMBOL_GPL(tps65912_reg_write);
123+
124+
int tps65912_device_init(struct tps65912 *tps65912)
125+
{
126+
struct tps65912_board *pmic_plat_data = tps65912->dev->platform_data;
127+
int ret, dcdc_avs, value;
128+
129+
mutex_init(&tps65912->io_mutex);
130+
dev_set_drvdata(tps65912->dev, tps65912);
131+
132+
dcdc_avs = (pmic_plat_data->is_dcdc1_avs << 0 |
133+
pmic_plat_data->is_dcdc2_avs << 1 |
134+
pmic_plat_data->is_dcdc3_avs << 2 |
135+
pmic_plat_data->is_dcdc4_avs << 3);
136+
if (dcdc_avs) {
137+
tps65912->read(tps65912, TPS65912_I2C_SPI_CFG, 1, &value);
138+
dcdc_avs |= value;
139+
tps65912->write(tps65912, TPS65912_I2C_SPI_CFG, 1, &dcdc_avs);
140+
}
141+
142+
ret = mfd_add_devices(tps65912->dev, -1,
143+
tps65912s, ARRAY_SIZE(tps65912s),
144+
NULL, 0);
145+
if (ret < 0)
146+
goto err;
147+
148+
return ret;
149+
150+
err:
151+
mfd_remove_devices(tps65912->dev);
152+
kfree(tps65912);
153+
return ret;
154+
}
155+
156+
void tps65912_device_exit(struct tps65912 *tps65912)
157+
{
158+
mfd_remove_devices(tps65912->dev);
159+
kfree(tps65912);
160+
}
161+
162+
MODULE_AUTHOR("Margarita Olaya <magi@slimlogic.co.uk>");
163+
MODULE_DESCRIPTION("TPS65912x chip family multi-function driver");
164+
MODULE_LICENSE("GPL");

‎drivers/mfd/tps65912-i2c.c‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* tps65912-i2c.c -- I2C access for TI TPS65912x PMIC
3+
*
4+
* Copyright 2011 Texas Instruments Inc.
5+
*
6+
* Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk>
7+
*
8+
* This program is free software; you can redistribute it and/or modify it
9+
* under the terms of the GNU General Public License as published by the
10+
* Free Software Foundation; either version 2 of the License, or (at your
11+
* option) any later version.
12+
*
13+
* This driver is based on wm8350 implementation.
14+
*/
15+
16+
#include <linux/module.h>
17+
#include <linux/moduleparam.h>
18+
#include <linux/init.h>
19+
#include <linux/slab.h>
20+
#include <linux/gpio.h>
21+
#include <linux/i2c.h>
22+
#include <linux/mfd/core.h>
23+
#include <linux/mfd/tps65912.h>
24+
25+
static int tps65912_i2c_read(struct tps65912 *tps65912, u8 reg,
26+
int bytes, void *dest)
27+
{
28+
struct i2c_client *i2c = tps65912->control_data;
29+
struct i2c_msg xfer[2];
30+
int ret;
31+
32+
/* Write register */
33+
xfer[0].addr = i2c->addr;
34+
xfer[0].flags = 0;
35+
xfer[0].len = 1;
36+
xfer[0].buf = &reg;
37+
38+
/* Read data */
39+
xfer[1].addr = i2c->addr;
40+
xfer[1].flags = I2C_M_RD;
41+
xfer[1].len = bytes;
42+
xfer[1].buf = dest;
43+
44+
ret = i2c_transfer(i2c->adapter, xfer, 2);
45+
if (ret == 2)
46+
ret = 0;
47+
else if (ret >= 0)
48+
ret = -EIO;
49+
return ret;
50+
}
51+
52+
static int tps65912_i2c_write(struct tps65912 *tps65912, u8 reg,
53+
int bytes, void *src)
54+
{
55+
struct i2c_client *i2c = tps65912->control_data;
56+
/* we add 1 byte for device register */
57+
u8 msg[TPS6591X_MAX_REGISTER + 1];
58+
int ret;
59+
60+
if (bytes > (TPS6591X_MAX_REGISTER + 1))
61+
return -EINVAL;
62+
63+
msg[0] = reg;
64+
memcpy(&msg[1], src, bytes);
65+
66+
ret = i2c_master_send(i2c, msg, bytes + 1);
67+
if (ret < 0)
68+
return ret;
69+
if (ret != bytes + 1)
70+
return -EIO;
71+
72+
return 0;
73+
}
74+
75+
static int tps65912_i2c_probe(struct i2c_client *i2c,
76+
const struct i2c_device_id *id)
77+
{
78+
struct tps65912 *tps65912;
79+
80+
tps65912 = kzalloc(sizeof(struct tps65912), GFP_KERNEL);
81+
if (tps65912 == NULL)
82+
return -ENOMEM;
83+
84+
i2c_set_clientdata(i2c, tps65912);
85+
tps65912->dev = &i2c->dev;
86+
tps65912->control_data = i2c;
87+
tps65912->read = tps65912_i2c_read;
88+
tps65912->write = tps65912_i2c_write;
89+
90+
return tps65912_device_init(tps65912);
91+
}
92+
93+
static int tps65912_i2c_remove(struct i2c_client *i2c)
94+
{
95+
struct tps65912 *tps65912 = i2c_get_clientdata(i2c);
96+
97+
tps65912_device_exit(tps65912);
98+
99+
return 0;
100+
}
101+
102+
static const struct i2c_device_id tps65912_i2c_id[] = {
103+
{"tps65912", 0 },
104+
{ }
105+
};
106+
MODULE_DEVICE_TABLE(i2c, tps65912_i2c_id);
107+
108+
static struct i2c_driver tps65912_i2c_driver = {
109+
.driver = {
110+
.name = "tps65912",
111+
.owner = THIS_MODULE,
112+
},
113+
.probe = tps65912_i2c_probe,
114+
.remove = tps65912_i2c_remove,
115+
.id_table = tps65912_i2c_id,
116+
};
117+
118+
static int __init tps65912_i2c_init(void)
119+
{
120+
int ret;
121+
122+
ret = i2c_add_driver(&tps65912_i2c_driver);
123+
if (ret != 0)
124+
pr_err("Failed to register TPS65912 I2C driver: %d\n", ret);
125+
126+
return ret;
127+
}
128+
/* init early so consumer devices can complete system boot */
129+
subsys_initcall(tps65912_i2c_init);
130+
131+
static void __exit tps65912_i2c_exit(void)
132+
{
133+
i2c_del_driver(&tps65912_i2c_driver);
134+
}
135+
module_exit(tps65912_i2c_exit);
136+
137+
MODULE_AUTHOR("Margarita Olaya <magi@slimlogic.co.uk>");
138+
MODULE_DESCRIPTION("TPS6591x chip family multi-function driver");
139+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)