aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-ux500/board-mop500-wlan.c
blob: 65863efc78c4c5653e8fa3bf5b655ca1fc252e9b (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
/*
 * Copyright (C) ST-Ericsson SA 2011
 *
 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@stericsson.com>
 * License terms: GNU General Public License (GPL) version 2
 */

#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <asm/mach-types.h>
#include <mach/irqs.h>
#include <plat/pincfg.h>
#include "pins.h"
#include "../drivers/staging/cw1200/cw1200_plat.h"

static void cw1200_release(struct device *dev);
static int cw1200_power_ctrl(const struct cw1200_platform_data *pdata,
			     bool enable);

static struct resource cw1200_href_resources[] = {
	{
		.start = 215,
		.end = 215,
		.flags = IORESOURCE_IO,
		.name = "cw1200_reset",
	},
#ifdef CONFIG_CW1200_USE_GPIO_IRQ
	{
		.start = NOMADIK_GPIO_TO_IRQ(216),
		.end = NOMADIK_GPIO_TO_IRQ(216),
		.flags = IORESOURCE_IRQ,
		.name = "cw1200_irq",
	},
#endif /* CONFIG_CW1200_USE_GPIO_IRQ */
};

static struct resource cw1200_href60_resources[] = {
	{
		.start = 85,
		.end = 85,
		.flags = IORESOURCE_IO,
		.name = "cw1200_reset",
	},
#ifdef CONFIG_CW1200_USE_GPIO_IRQ
	{
		.start = NOMADIK_GPIO_TO_IRQ(4),
		.end = NOMADIK_GPIO_TO_IRQ(4),
		.flags = IORESOURCE_IRQ,
		.name = "cw1200_irq",
	},
#endif /* CONFIG_CW1200_USE_GPIO_IRQ */
};

static struct cw1200_platform_data cw1200_platform_data = { 0 };

static struct platform_device cw1200_device = {
	.name = "cw1200_wlan",
	.dev = {
		.platform_data = &cw1200_platform_data,
		.release = cw1200_release,
		.init_name = "cw1200_wlan",
	},
};

const struct cw1200_platform_data *cw1200_get_platform_data(void)
{
	return &cw1200_platform_data;
}
EXPORT_SYMBOL_GPL(cw1200_get_platform_data);

static int cw1200_pins_enable(bool enable)
{
	struct ux500_pins *pins;
	int ret = 0;

	pins = ux500_pins_get("sdi1");
	if (!pins) {
		printk(KERN_ERR "cw1200: Pins are not found. "
				"Check platform data.\n");
		return -ENOENT;
	}

	if (enable)
		ret = ux500_pins_enable(pins);
	else
		ret = ux500_pins_disable(pins);

	if (ret)
		printk(KERN_ERR "cw1200: Pins can not be %s: %d.\n",
				enable ? "enabled" : "disabled",
				ret);

	ux500_pins_put(pins);

	return ret;
}

static int cw1200_power_ctrl(const struct cw1200_platform_data *pdata,
			     bool enable)
{
	static const char *vdd_name = "vdd";
	struct regulator *vdd;
	int ret = 0;

	vdd = regulator_get(&cw1200_device.dev, vdd_name);
	if (IS_ERR(vdd)) {
		ret = PTR_ERR(vdd);
		dev_warn(&cw1200_device.dev,
				"%s: Failed to get regulator '%s': %d\n",
				__func__, vdd_name, ret);
	} else {
		if (enable)
			ret = regulator_enable(vdd);
		else
			ret = regulator_disable(vdd);

		if (ret) {
			dev_warn(&cw1200_device.dev,
				"%s: Failed to %s regulator '%s': %d\n",
				__func__, enable ? "enable" : "disable",
				vdd_name, ret);
		}
		regulator_put(vdd);
	}
	return  ret;
}

int __init mop500_wlan_init(void)
{
	int ret;
	if (machine_is_snowball() ||
			machine_is_u8500() ||
			machine_is_u5500() ||
			machine_is_nomadik()) {
		cw1200_device.num_resources =
				ARRAY_SIZE(cw1200_href_resources);
		cw1200_device.resource = cw1200_href_resources;
	} else if (machine_is_hrefv60()) {
		cw1200_device.num_resources =
				ARRAY_SIZE(cw1200_href60_resources);
		cw1200_device.resource = cw1200_href60_resources;
	} else {
		dev_err(&cw1200_device.dev,
				"Unsupported mach type %d "
				"(check mach-types.h)\n",
				__machine_arch_type);
		return -ENOTSUPP;
	}

	if (machine_is_snowball())
		cw1200_platform_data.mmc_id = "mmc2";
	else
		cw1200_platform_data.mmc_id = "mmc3";

	cw1200_platform_data.reset = &cw1200_device.resource[0];
#ifdef CONFIG_CW1200_USE_GPIO_IRQ
	cw1200_platform_data.irq = &cw1200_device.resource[1];
#endif /* #ifdef CONFIG_CW1200_USE_GPIO_IRQ */

	cw1200_device.dev.release = cw1200_release;
	if (machine_is_snowball())
		cw1200_platform_data.power_ctrl = cw1200_power_ctrl;

	ret = cw1200_pins_enable(true);
	if (WARN_ON(ret))
		return ret;

	ret = platform_device_register(&cw1200_device);
	if (ret)
		cw1200_pins_enable(false);

	return ret;
}

static void cw1200_release(struct device *dev)
{
	cw1200_pins_enable(false);
}