summaryrefslogtreecommitdiff
path: root/drivers/regulator/reg-mc9s08dz60.c
blob: f2748e99fd80acff867ed3fa69d48967e954cbce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/bitops.h>
#include <linux/err.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/driver.h>
#include <linux/mfd/mc9s08dz60/core.h>
#include <linux/mfd/mc9s08dz60/pmic.h>
#include <linux/platform_device.h>
#include <linux/pmic_status.h>

/* lcd */
static int mc9s08dz60_lcd_enable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 6, 1);
}

static int mc9s08dz60_lcd_disable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 6, 0);
}

static struct regulator_ops mc9s08dz60_lcd_ops = {
	.enable = mc9s08dz60_lcd_enable,
	.disable = mc9s08dz60_lcd_disable,
};

/* wifi */
static int mc9s08dz60_wifi_enable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 5, 1);
}

static int mc9s08dz60_wifi_disable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 5, 0);
}

static struct regulator_ops mc9s08dz60_wifi_ops = {
	.enable = mc9s08dz60_wifi_enable,
	.disable = mc9s08dz60_wifi_disable,
};

/* hdd */
static int mc9s08dz60_hdd_enable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 4, 1);
}

static int mc9s08dz60_hdd_disable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 4, 0);
}

static struct regulator_ops mc9s08dz60_hdd_ops = {
	.enable = mc9s08dz60_hdd_enable,
	.disable = mc9s08dz60_hdd_disable,
};

/* gps */
static int mc9s08dz60_gps_enable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_2, 0, 1);
}

static int mc9s08dz60_gps_disable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_2, 0, 0);
}

static struct regulator_ops mc9s08dz60_gps_ops = {
	.enable = mc9s08dz60_gps_enable,
	.disable = mc9s08dz60_gps_disable,
};

/* speaker */
static int mc9s08dz60_speaker_enable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 0, 1);
}

static int mc9s08dz60_speaker_disable(struct regulator_dev *reg)
{
	return pmic_gpio_set_bit_val(MCU_GPIO_REG_GPIO_CONTROL_1, 0, 0);
}

static struct regulator_ops mc9s08dz60_speaker_ops = {
	.enable = mc9s08dz60_speaker_enable,
	.disable = mc9s08dz60_speaker_disable,
};

static struct regulator_desc mc9s08dz60_reg[] = {
	{
		.name = "LCD",
		.id = MC9S08DZ60_LCD,
		.ops = &mc9s08dz60_lcd_ops,
		.irq = 0,
		.type = REGULATOR_VOLTAGE,
		.owner = THIS_MODULE
	 },
	{
		.name = "WIFI",
		.id = MC9S08DZ60_WIFI,
		.ops = &mc9s08dz60_wifi_ops,
		.irq = 0,
		.type = REGULATOR_VOLTAGE,
		.owner = THIS_MODULE
	 },
	{
		.name = "HDD",
		.id = MC9S08DZ60_HDD,
		.ops = &mc9s08dz60_hdd_ops,
		.irq = 0,
		.type = REGULATOR_VOLTAGE,
		.owner = THIS_MODULE
	 },
	{
		.name = "GPS",
		.id = MC9S08DZ60_GPS,
		.ops = &mc9s08dz60_gps_ops,
		.irq = 0,
		.type = REGULATOR_VOLTAGE,
		.owner = THIS_MODULE
	 },
	{
		.name = "SPKR",
		.id = MC9S08DZ60_SPKR,
		.ops = &mc9s08dz60_speaker_ops,
		.irq = 0,
		.type = REGULATOR_VOLTAGE,
		.owner = THIS_MODULE
	 },

};

static int mc9s08dz60_regulator_probe(struct platform_device *pdev)
{
	struct regulator_dev *rdev;

	/* register regulator */
	rdev = regulator_register(&mc9s08dz60_reg[pdev->id], &pdev->dev,
				  pdev->dev.platform_data,
				  dev_get_drvdata(&pdev->dev));
	if (IS_ERR(rdev)) {
		dev_err(&pdev->dev, "failed to register %s\n",
			mc9s08dz60_reg[pdev->id].name);
		return PTR_ERR(rdev);
	}

	return 0;
}


static int mc9s08dz60_regulator_remove(struct platform_device *pdev)
{
	struct regulator_dev *rdev = platform_get_drvdata(pdev);

	regulator_unregister(rdev);

	return 0;
}

int mc9s08dz60_register_regulator(struct mc9s08dz60 *mc9s08dz60, int reg,
			      struct regulator_init_data *initdata)
{
	struct platform_device *pdev;
	int ret;

	if (mc9s08dz60->pmic.pdev[reg])
		return -EBUSY;

	pdev = platform_device_alloc("mc9s08dz60-regu", reg);
	if (!pdev)
		return -ENOMEM;

	mc9s08dz60->pmic.pdev[reg] = pdev;

	initdata->driver_data = mc9s08dz60;

	pdev->dev.platform_data = initdata;
	pdev->dev.parent = mc9s08dz60->dev;
	platform_set_drvdata(pdev, mc9s08dz60);
	ret = platform_device_add(pdev);

	if (ret != 0) {
		dev_err(mc9s08dz60->dev,
			"Failed to register regulator %d: %d\n",
			reg, ret);
		platform_device_del(pdev);
		mc9s08dz60->pmic.pdev[reg] = NULL;
	}

	return ret;
}
EXPORT_SYMBOL_GPL(mc9s08dz60_register_regulator);

static struct platform_driver mc9s08dz60_regulator_driver = {
	.probe = mc9s08dz60_regulator_probe,
	.remove = mc9s08dz60_regulator_remove,
	.driver		= {
		.name	= "mc9s08dz60-regu",
	},
};

static int __init mc9s08dz60_regulator_init(void)
{
	return platform_driver_register(&mc9s08dz60_regulator_driver);
}
subsys_initcall(mc9s08dz60_regulator_init);

static void __exit mc9s08dz60_regulator_exit(void)
{
	platform_driver_unregister(&mc9s08dz60_regulator_driver);
}
module_exit(mc9s08dz60_regulator_exit);


MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("MC9S08DZ60 Regulator driver");
MODULE_LICENSE("GPL");