2 * tps65912-core.c -- TI TPS65912x
4 * Copyright 2011 Texas Instruments Inc.
6 * Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk>
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.
13 * This driver is based on wm8350 implementation.
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/slab.h>
19 #include <linux/gpio.h>
20 #include <linux/mfd/core.h>
21 #include <linux/mfd/tps65912.h>
23 static const struct mfd_cell tps65912s
[] = {
25 .name
= "tps65912-pmic",
29 int tps65912_set_bits(struct tps65912
*tps65912
, u8 reg
, u8 mask
)
34 mutex_lock(&tps65912
->io_mutex
);
36 err
= tps65912
->read(tps65912
, reg
, 1, &data
);
38 dev_err(tps65912
->dev
, "Read from reg 0x%x failed\n", reg
);
43 err
= tps65912
->write(tps65912
, reg
, 1, &data
);
45 dev_err(tps65912
->dev
, "Write to reg 0x%x failed\n", reg
);
48 mutex_unlock(&tps65912
->io_mutex
);
51 EXPORT_SYMBOL_GPL(tps65912_set_bits
);
53 int tps65912_clear_bits(struct tps65912
*tps65912
, u8 reg
, u8 mask
)
58 mutex_lock(&tps65912
->io_mutex
);
59 err
= tps65912
->read(tps65912
, reg
, 1, &data
);
61 dev_err(tps65912
->dev
, "Read from reg 0x%x failed\n", reg
);
66 err
= tps65912
->write(tps65912
, reg
, 1, &data
);
68 dev_err(tps65912
->dev
, "Write to reg 0x%x failed\n", reg
);
71 mutex_unlock(&tps65912
->io_mutex
);
74 EXPORT_SYMBOL_GPL(tps65912_clear_bits
);
76 static inline int tps65912_read(struct tps65912
*tps65912
, u8 reg
)
81 err
= tps65912
->read(tps65912
, reg
, 1, &val
);
88 static inline int tps65912_write(struct tps65912
*tps65912
, u8 reg
, u8 val
)
90 return tps65912
->write(tps65912
, reg
, 1, &val
);
93 int tps65912_reg_read(struct tps65912
*tps65912
, u8 reg
)
97 mutex_lock(&tps65912
->io_mutex
);
99 data
= tps65912_read(tps65912
, reg
);
101 dev_err(tps65912
->dev
, "Read from reg 0x%x failed\n", reg
);
103 mutex_unlock(&tps65912
->io_mutex
);
106 EXPORT_SYMBOL_GPL(tps65912_reg_read
);
108 int tps65912_reg_write(struct tps65912
*tps65912
, u8 reg
, u8 val
)
112 mutex_lock(&tps65912
->io_mutex
);
114 err
= tps65912_write(tps65912
, reg
, val
);
116 dev_err(tps65912
->dev
, "Write for reg 0x%x failed\n", reg
);
118 mutex_unlock(&tps65912
->io_mutex
);
121 EXPORT_SYMBOL_GPL(tps65912_reg_write
);
123 int tps65912_device_init(struct tps65912
*tps65912
)
125 struct tps65912_board
*pmic_plat_data
= dev_get_platdata(tps65912
->dev
);
126 struct tps65912_platform_data
*init_data
;
127 int ret
, dcdc_avs
, value
;
129 init_data
= kzalloc(sizeof(struct tps65912_platform_data
), GFP_KERNEL
);
130 if (init_data
== NULL
)
133 mutex_init(&tps65912
->io_mutex
);
134 dev_set_drvdata(tps65912
->dev
, tps65912
);
136 dcdc_avs
= (pmic_plat_data
->is_dcdc1_avs
<< 0 |
137 pmic_plat_data
->is_dcdc2_avs
<< 1 |
138 pmic_plat_data
->is_dcdc3_avs
<< 2 |
139 pmic_plat_data
->is_dcdc4_avs
<< 3);
141 tps65912
->read(tps65912
, TPS65912_I2C_SPI_CFG
, 1, &value
);
143 tps65912
->write(tps65912
, TPS65912_I2C_SPI_CFG
, 1, &dcdc_avs
);
146 ret
= mfd_add_devices(tps65912
->dev
, -1,
147 tps65912s
, ARRAY_SIZE(tps65912s
),
152 init_data
->irq
= pmic_plat_data
->irq
;
153 init_data
->irq_base
= pmic_plat_data
->irq_base
;
154 ret
= tps65912_irq_init(tps65912
, init_data
->irq
, init_data
);
163 mfd_remove_devices(tps65912
->dev
);
167 void tps65912_device_exit(struct tps65912
*tps65912
)
169 mfd_remove_devices(tps65912
->dev
);
170 tps65912_irq_exit(tps65912
);
173 MODULE_AUTHOR("Margarita Olaya <magi@slimlogic.co.uk>");
174 MODULE_DESCRIPTION("TPS65912x chip family multi-function driver");
175 MODULE_LICENSE("GPL");