2 * drivers/mfd/rt5025-core.c
3 * Driver for Richtek RT5025 Core PMIC
5 * Copyright (C) 2014 Richtek Technology Corp.
6 * cy_huang <cy_huang@richtek.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/version.h>
17 #include <linux/i2c.h>
18 #include <linux/mfd/core.h>
19 #include <linux/mfd/rt5025.h>
21 #ifdef CONFIG_REGULATOR_RT5025
23 #define RT5025_BUCKVR_DEVS(_id, _idx) \
25 .name = RT5025_DEV_NAME "-regulator", \
27 .of_compatible = "rt," RT5025_DEV_NAME "-dcdc" #_idx , \
28 .id = RT5025_ID_##_id, \
31 #define RT5025_LDOVR_DEVS(_id, _idx) \
33 .name = RT5025_DEV_NAME "-regulator", \
35 .of_compatible = "rt," RT5025_DEV_NAME "-ldo" #_idx , \
36 .id = RT5025_ID_##_id, \
39 #define RT5025_BUCKVR_DEVS(_id, _idx) \
41 .name = RT5025_DEV_NAME "-regulator", \
43 .id = RT5025_ID_##_id, \
46 #define RT5025_LDOVR_DEVS(_id, _idx) \
48 .name = RT5025_DEV_NAME "-regulator", \
50 .id = RT5025_ID_##_id, \
52 #endif /* #ifdef CONFIG_OF */
53 static struct mfd_cell regulator_devs[] = {
54 RT5025_BUCKVR_DEVS(DCDC1, 1),
55 RT5025_BUCKVR_DEVS(DCDC2, 2),
56 RT5025_BUCKVR_DEVS(DCDC3, 3),
57 RT5025_BUCKVR_DEVS(DCDC4, 4),
58 RT5025_LDOVR_DEVS(LDO1, 1),
59 RT5025_LDOVR_DEVS(LDO2, 2),
60 RT5025_LDOVR_DEVS(LDO3, 3),
61 RT5025_LDOVR_DEVS(LDO4, 4),
62 RT5025_LDOVR_DEVS(LDO5, 5),
63 RT5025_LDOVR_DEVS(LDO6, 6),
65 #endif /* #ifdef CONFIG_REGULATOR_RT5025 */
67 #ifdef CONFIG_CHARGER_RT5025
68 static struct mfd_cell chg_devs[] = {
70 .name = RT5025_DEV_NAME "-charger",
74 .of_compatible = "rt," RT5025_DEV_NAME "-charger" ,
75 #endif /*#ifdef CONFIG_OF */
78 #endif /* #ifdef CONFIG_CHARGER_RT5025 */
80 #ifdef CONFIG_BATTERY_RT5025
81 static struct mfd_cell fg_devs[] = {
83 .name = RT5025_DEV_NAME "-battery",
87 .of_compatible = "rt," RT5025_DEV_NAME "-battery" ,
88 #endif /*#ifdef CONFIG_OF */
91 #endif /* #ifdef CONFIG_BATTERY_RT5025 */
93 #ifdef CONFIG_GPIO_RT5025
94 static struct mfd_cell gpio_devs[] = {
96 .name = RT5025_DEV_NAME "-gpio",
100 .of_compatible = "rt," RT5025_DEV_NAME "-gpio" ,
101 #endif /*#ifdef CONFIG_OF */
104 #endif /* #ifdef CONFIG_GPIO_RT5025 */
106 #ifdef CONFIG_MISC_RT5025
107 static struct mfd_cell misc_devs[] = {
109 .name = RT5025_DEV_NAME "-misc",
113 .of_compatible = "rt," RT5025_DEV_NAME "-misc" ,
114 #endif /*#ifdef CONFIG_OF */
117 #endif /* #ifdef CONFIG_MISC_RT5025 */
119 #ifdef CONFIG_IRQ_RT5025
120 static struct mfd_cell irq_devs[] = {
122 .name = RT5025_DEV_NAME "-irq",
126 .of_compatible = "rt," RT5025_DEV_NAME "-irq" ,
127 #endif /*#ifdef CONFIG_OF */
130 #endif /* #ifdef CONFIG_IRQ_RT5025 */
132 #ifdef CONFIG_DEBUG_RT5025
133 static struct mfd_cell debug_devs[] = {
135 .name = RT5025_DEV_NAME "-debug",
139 .of_compatible = "rt," RT5025_DEV_NAME "-debug" ,
140 #endif /*#ifdef CONFIG_OF */
143 #endif /* #ifdef CONFIG_DEBUG_RT5025 */
145 int rt5025_core_init(struct rt5025_chip *chip,
146 struct rt5025_platform_data *pdata)
149 bool use_dt = chip->dev->of_node;
151 RTINFO("Start to initialize all device\n");
153 #ifdef CONFIG_REGULATOR_RT5025
154 if (use_dt || (pdata && pdata->regulator[0])) {
155 RTINFO("mfd add regulators dev\n");
156 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
157 ret = mfd_add_devices(chip->dev, 0, ®ulator_devs[0],
158 ARRAY_SIZE(regulator_devs),
161 ret = mfd_add_devices(chip->dev, 0, ®ulator_devs[0],
162 ARRAY_SIZE(regulator_devs),
164 #endif /* LINUX_VERSION_CODE >= KERNL_VERSION(3,6,0) */
166 dev_err(chip->dev, "Failed to add regulator subdev\n");
170 #endif /* #ifdef CONFIG_REGULATOR_RT5025 */
172 #ifdef CONFIG_CHARGER_RT5025
173 if (use_dt || (pdata && pdata->chg_pdata)) {
174 RTINFO("mfd add charger dev\n");
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
176 ret = mfd_add_devices(chip->dev, 0, &chg_devs[0],
177 ARRAY_SIZE(chg_devs),
180 ret = mfd_add_devices(chip->dev, 0, &chg_devs[0],
181 ARRAY_SIZE(chg_devs),
185 dev_err(chip->dev, "Failed to add power supply subdev\n");
189 #endif /* #ifdef CONFIG_CHARGER_RT5025 */
191 #ifdef CONFIG_BATTERY_RT5025
192 if (use_dt || (pdata)) {
193 RTINFO("mfd add fuelgauge dev\n");
194 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
195 ret = mfd_add_devices(chip->dev, 0, &fg_devs[0],
199 ret = mfd_add_devices(chip->dev, 0, &fg_devs[0],
204 dev_err(chip->dev, "Failed to add power supply "
209 #endif /* #ifdef CONFIG_BATTERY_RT5025 */
211 /*Initialize the RT5025_GPIO*/
212 #ifdef CONFIG_GPIO_RT5025
213 if (use_dt || (pdata && pdata->gpio_pdata)) {
214 RTINFO("mfd add gpios dev\n");
215 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
216 ret = mfd_add_devices(chip->dev, 0, &gpio_devs[0],
217 ARRAY_SIZE(gpio_devs),
220 ret = mfd_add_devices(chip->dev, 0, &gpio_devs[0],
221 ARRAY_SIZE(gpio_devs),
223 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
225 dev_err(chip->dev, "Failed to add gpio subdev\n");
229 #endif /* #ifdef CONFIG_GPIO_RT5025 */
231 #ifdef CONFIG_MISC_RT5025
232 if (use_dt || (pdata && pdata->misc_pdata)) {
233 RTINFO("mfd add misc dev\n");
234 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
235 ret = mfd_add_devices(chip->dev, 0, &misc_devs[0],
236 ARRAY_SIZE(misc_devs),
239 ret = mfd_add_devices(chip->dev, 0, &misc_devs[0],
240 ARRAY_SIZE(misc_devs),
242 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
244 dev_err(chip->dev, "Failed to add misc subdev\n");
248 #endif /* #ifdef CONFIG_MISC_RT5025 */
250 #ifdef CONFIG_IRQ_RT5025
251 if (use_dt || (pdata && pdata->irq_pdata)) {
252 RTINFO("mfd add irq dev\n");
253 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
254 ret = mfd_add_devices(chip->dev, 0, &irq_devs[0],
255 ARRAY_SIZE(irq_devs),
258 ret = mfd_add_devices(chip->dev, 0, &irq_devs[0],
259 ARRAY_SIZE(irq_devs),
261 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
263 dev_err(chip->dev, "Failed to add irq subdev\n");
267 #endif /* #ifdef CONFIG_IRQ_RT5025 */
269 #ifdef CONFIG_DEBUG_RT5025
270 RTINFO("mfd add debug dev\n");
271 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
272 ret = mfd_add_devices(chip->dev, 0, &debug_devs[0],
273 ARRAY_SIZE(debug_devs),
276 ret = mfd_add_devices(chip->dev, 0, &debug_devs[0],
277 ARRAY_SIZE(debug_devs),
279 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
281 dev_err(chip->dev, "Failed to add debug subdev\n");
284 #endif /* CONFIG_DEBUG_RT5025 */
286 RTINFO("Initialize all device successfully\n");
289 mfd_remove_devices(chip->dev);
292 EXPORT_SYMBOL(rt5025_core_init);
294 int rt5025_core_deinit(struct rt5025_chip *chip)
296 mfd_remove_devices(chip->dev);
299 EXPORT_SYMBOL(rt5025_core_deinit);