2 * drivers/mfd/rt5036-core.c
3 * Driver for Richtek RT5036 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/mfd/core.h>
19 #include <linux/mfd/rt5036/rt5036.h>
21 #ifdef CONFIG_REGULATOR_RT5036
23 #define RT5036_BUCKVR_DEVS(_id, _idx) \
25 .name = RT5036_DEV_NAME "-regulator", \
27 .of_compatible = "rt," RT5036_DEV_NAME "-dcdc" #_idx, \
28 .id = RT5036_ID_##_id, \
31 #define RT5036_LDOVR_DEVS(_id, _idx) \
33 .name = RT5036_DEV_NAME "-regulator", \
35 .of_compatible = "rt," RT5036_DEV_NAME "-ldo" #_idx, \
36 .id = RT5036_ID_##_id, \
39 #define RT5036_LSWVR_DEVS(_id, _idx) \
41 .name = RT5036_DEV_NAME "-regulator", \
43 .of_compatible = "rt," RT5036_DEV_NAME "-lsw" #_idx, \
44 .id = RT5036_ID_##_id, \
47 #define RT5036_BUCKVR_DEVS(_id, _idx) \
49 .name = RT5036_DEV_NAME "-regulator", \
51 .id = RT5036_ID_##_id, \
54 #define RT5036_LDOVR_DEVS(_id, _idx) \
56 .name = RT5036_DEV_NAME "-regulator", \
58 .id = RT5036_ID_##_id, \
61 #define RT5036_LSWVR_DEVS(_id, _idx) \
63 .name = RT5036_DEV_NAME "-regulator", \
65 .id = RT5036_ID_##_id, \
67 #endif /* #ifdef CONFIG_OF */
69 static struct mfd_cell regulator_devs[] = {
70 RT5036_BUCKVR_DEVS(DCDC1, 1),
71 RT5036_BUCKVR_DEVS(DCDC2, 2),
72 RT5036_BUCKVR_DEVS(DCDC3, 3),
73 RT5036_BUCKVR_DEVS(DCDC4, 4),
74 RT5036_LDOVR_DEVS(LDO1, 1),
75 RT5036_LDOVR_DEVS(LDO2, 2),
76 RT5036_LDOVR_DEVS(LDO3, 3),
77 RT5036_LDOVR_DEVS(LDO4, 4),
78 RT5036_LSWVR_DEVS(LSW1, 1),
79 RT5036_LSWVR_DEVS(LSW2, 2),
81 #endif /* CONFIG_REGULATOR_RT5036 */
83 #ifdef CONFIG_CHARGER_RT5036
84 static struct mfd_cell chg_devs[] = {
86 .name = RT5036_DEV_NAME "-charger",
90 .of_compatible = "rt," RT5036_DEV_NAME "-charger",
91 #endif /*#ifdef CONFIG_OF */
94 #endif /* CONFIG_CHARGER_RT5036 */
96 #ifdef CONFIG_RTC_RT5036
97 static struct mfd_cell rtc_devs[] = {
99 .name = RT5036_DEV_NAME "-rtc",
103 .of_compatible = "rt," RT5036_DEV_NAME "-rtc",
104 #endif /*#ifdef CONFIG_OF */
107 #endif /* CONFIG_RTC_RT5036 */
109 #ifdef CONFIG_MISC_RT5036
110 static struct mfd_cell misc_devs[] = {
112 .name = RT5036_DEV_NAME "-misc",
116 .of_compatible = "rt," RT5036_DEV_NAME "-misc",
117 #endif /*#ifdef CONFIG_OF */
120 #endif /* CONFIG_MISC_RT5036 */
122 #ifdef CONFIG_IRQ_RT5036
123 static struct mfd_cell irq_devs[] = {
125 .name = RT5036_DEV_NAME "-irq",
129 .of_compatible = "rt," RT5036_DEV_NAME "-irq",
130 #endif /*#ifdef CONFIG_OF */
133 #endif /* CONFIG_IRQ_RT5036 */
135 #ifdef CONFIG_DEBUG_RT5036
136 static struct mfd_cell debug_devs[] = {
138 .name = RT5036_DEV_NAME "-debug",
142 .of_compatible = "rt," RT5036_DEV_NAME "-debug",
143 #endif /*#ifdef CONFIG_OF */
146 #endif /* CONFIG_DEBUG_RT5036 */
148 int rt5036_core_init(struct device *dev,
149 struct rt5036_platform_data *pdata)
153 RTINFO("Start to initialize all device\n");
154 #ifdef CONFIG_REGULATOR_RT5036
155 if (dev->of_node || (pdata && pdata->regulator[0])) {
156 RTINFO("mfd add regulators dev\n");
157 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
158 ret = mfd_add_devices(dev, 0, ®ulator_devs[0],
159 ARRAY_SIZE(regulator_devs),
162 ret = mfd_add_devices(dev, 0, ®ulator_devs[0],
163 ARRAY_SIZE(regulator_devs), NULL, 0);
164 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
166 dev_err(dev, "Failed to add regulator subdev\n");
170 #endif /* CONFIG_REGULATOR_RT5036 */
172 #ifdef CONFIG_CHARGER_RT5036
173 if (dev->of_node || (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(dev, 0, &chg_devs[0],
177 ARRAY_SIZE(chg_devs), NULL, 0, NULL);
179 ret = mfd_add_devices(dev, 0, &chg_devs[0],
180 ARRAY_SIZE(chg_devs), NULL, 0);
181 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
183 dev_err(dev, "Failed to add charger subdev\n");
187 #endif /* CONFIG_CHARGER_RT5036 */
189 #ifdef CONFIG_RTC_RT5036
190 if (dev->of_node || pdata) {
191 RTINFO("mfd add rtc dev\n");
192 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
193 ret = mfd_add_devices(dev, 0, &rtc_devs[0],
194 ARRAY_SIZE(rtc_devs), NULL, 0, NULL);
196 ret = mfd_add_devices(dev, 0, &rtc_devs[0],
197 ARRAY_SIZE(rtc_devs), NULL, 0);
198 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
200 dev_err(dev, "Failed to add rtc subdev\n");
204 #endif /* CONFIG_RTC_RT5036 */
206 #ifdef CONFIG_MISC_RT5036
207 if (dev->of_node || (pdata && pdata->misc_pdata)) {
208 RTINFO("mfd add misc dev\n");
209 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
210 ret = mfd_add_devices(dev, 0, &misc_devs[0],
211 ARRAY_SIZE(misc_devs), NULL, 0, NULL);
213 ret = mfd_add_devices(dev, 0, &misc_devs[0],
214 ARRAY_SIZE(misc_devs), NULL, 0);
215 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
217 dev_err(dev, "Failed to add misc subdev\n");
221 #endif /* CONFIG_MISC_RT5036 */
223 #ifdef CONFIG_IRQ_RT5036
224 if (dev->of_node || (pdata && pdata->irq_pdata)) {
225 RTINFO("mfd add irq dev\n");
226 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
227 ret = mfd_add_devices(dev, 0, &irq_devs[0],
228 ARRAY_SIZE(irq_devs), NULL, 0, NULL);
230 ret = mfd_add_devices(dev, 0, &irq_devs[0],
231 ARRAY_SIZE(irq_devs), NULL, 0);
232 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
234 dev_err(dev, "Failed to add irq subdev\n");
238 #endif /* CONFIG_IRQ_RT5036 */
240 #ifdef CONFIG_DEBUG_RT5036
241 RTINFO("mfd add debug dev\n");
242 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
243 ret = mfd_add_devices(dev, 0, &debug_devs[0],
244 ARRAY_SIZE(debug_devs), NULL, 0, NULL);
246 ret = mfd_add_devices(dev, 0, &debug_devs[0],
247 ARRAY_SIZE(debug_devs), NULL, 0);
248 #endif /* LINUX_VERSION_CODE>=KERNL_VERSION(3,6,0) */
250 dev_err(dev, "Failed to add debug subdev\n");
253 #endif /* CONFIG_DEBUG_RT5036 */
255 RTINFO("Initialize all device successfully\n");
258 mfd_remove_devices(dev);
261 EXPORT_SYMBOL(rt5036_core_init);
263 int rt5036_core_deinit(struct device *dev)
265 mfd_remove_devices(dev);
268 EXPORT_SYMBOL(rt5036_core_deinit);