summaryrefslogtreecommitdiff
path: root/drivers/staging/cg2900/devices-cg2900-ux500.c
blob: 7e7c12ce4a085863384f1ee7d521b06e887cfad5 (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
/*
 * Copyright (C) ST-Ericsson SA 2011
 * Authors:
 * Par-Gunnar Hjalmdahl (par-gunnar.p.hjalmdahl@stericsson.com) for ST-Ericsson.
 * Henrik Possung (henrik.possung@stericsson.com) for ST-Ericsson.
 * Josef Kindberg (josef.kindberg@stericsson.com) for ST-Ericsson.
 * Dariusz Szymszak (dariusz.xd.szymczak@stericsson.com) for ST-Ericsson.
 * Kjell Andersson (kjell.k.andersson@stericsson.com) for ST-Ericsson.
 * Hemant Gupta (hemant.gupta@stericsson.com) for ST-Ericsson.
 * License terms:  GNU General Public License (GPL), version 2
 *
 * Board specific device support for the Linux Bluetooth HCI H:4 Driver
 * for ST-Ericsson connectivity controller.
 */

#include <asm/byteorder.h>
#include <asm-generic/errno-base.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/mfd/abx500/ab5500.h>
#include <linux/mfd/dbx500-prcmu.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/types.h>
#include <plat/pincfg.h>

#include "devices-cg2900.h"

void dcg2900_u8500_enable_chip(struct cg2900_chip_dev *dev)
{
	struct dcg2900_info *info = dev->b_data;

	if (info->gbf_gpio == -1)
		return;

	/*
	 * Due to a bug in CG2900 we cannot just set GPIO high to enable
	 * the chip. We must wait more than 100 msecs before enabling the
	 * chip.
	 * - Set PDB to low.
	 * - Wait for 100 msecs
	 * - Set PDB to high.
	 */
	gpio_set_value(info->gbf_gpio, 0);
	schedule_timeout_uninterruptible(msecs_to_jiffies(
					CHIP_ENABLE_PDB_LOW_TIMEOUT));

	if (info->pmuen_gpio != -1) {
		/*
		 * We must first set PMU_EN pin high and then wait 300 us before
		 * setting the GBF_EN high.
		 */
		gpio_set_value(info->pmuen_gpio, 1);
		udelay(CHIP_ENABLE_PMU_EN_TIMEOUT);
	}

	gpio_set_value(info->gbf_gpio, 1);
}

void dcg2900_u8500_disable_chip(struct cg2900_chip_dev *dev)
{
	struct dcg2900_info *info = dev->b_data;

	if (info->gbf_gpio != -1)
		gpio_set_value(info->gbf_gpio, 0);
	if (info->pmuen_gpio != -1)
		gpio_set_value(info->pmuen_gpio, 0);
}

int dcg2900_u8500_setup(struct cg2900_chip_dev *dev,
					struct dcg2900_info *info)
{
	int err = 0;
	struct resource *resource;
	const char *gbf_name;
	const char *bt_name = NULL;
	const char *pmuen_name = NULL;

	resource = platform_get_resource_byname(dev->pdev, IORESOURCE_IO,
						"gbf_ena_reset");
	if (!resource) {
		dev_err(dev->dev, "GBF GPIO does not exist\n");
		err = -EINVAL;
		goto err_handling;
	}

	info->gbf_gpio = resource->start;
	gbf_name = resource->name;

	resource = platform_get_resource_byname(dev->pdev, IORESOURCE_IO,
						"bt_enable");
	/* BT Enable GPIO may not exist */
	if (resource) {
		info->bt_gpio = resource->start;
		bt_name = resource->name;
	}

	resource = platform_get_resource_byname(dev->pdev, IORESOURCE_IO,
						"pmu_en");
	/* PMU_EN GPIO may not exist */
	if (resource) {
		info->pmuen_gpio = resource->start;
		pmuen_name = resource->name;
	}

	/* Now setup the GPIOs */
	err = gpio_request(info->gbf_gpio, gbf_name);
	if (err < 0) {
		dev_err(dev->dev, "gpio_request %s failed with err: %d\n",
			gbf_name, err);
		goto err_handling;
	}

	err = gpio_direction_output(info->gbf_gpio, 0);
	if (err < 0) {
		dev_err(dev->dev,
			"gpio_direction_output %s failed with err: %d\n",
			gbf_name, err);
		goto err_handling_free_gpio_gbf;
	}

	if (!pmuen_name)
		goto set_bt_gpio;

	err = gpio_request(info->pmuen_gpio, pmuen_name);
	if (err < 0) {
		dev_err(dev->dev, "gpio_request %s failed with err: %d\n",
			pmuen_name, err);
		goto err_handling_free_gpio_gbf;
	}

	err = gpio_direction_output(info->pmuen_gpio, 0);
	if (err < 0) {
		dev_err(dev->dev,
			"gpio_direction_output %s failed with err: %d\n",
			pmuen_name, err);
		goto err_handling_free_gpio_pmuen;
	}

set_bt_gpio:
	if (!bt_name)
		goto finished;

	err = gpio_request(info->bt_gpio, bt_name);
	if (err < 0) {
		dev_err(dev->dev, "gpio_request %s failed with err: %d\n",
			bt_name, err);
		goto err_handling_free_gpio_pmuen;
	}

	err = gpio_direction_output(info->bt_gpio, 1);
	if (err < 0) {
		dev_err(dev->dev,
			"gpio_direction_output %s failed with err: %d\n",
			bt_name, err);
		goto err_handling_free_gpio_bt;
	}

finished:

	return 0;

err_handling_free_gpio_bt:
	gpio_free(info->bt_gpio);
	info->bt_gpio = -1;
err_handling_free_gpio_pmuen:
	if (info->pmuen_gpio != -1) {
		gpio_free(info->pmuen_gpio);
		info->pmuen_gpio = -1;
	}
err_handling_free_gpio_gbf:
	gpio_free(info->gbf_gpio);
	info->gbf_gpio = -1;
err_handling:

	return err;
}

/* prcmu resout1 pin is used for CG2900 reset*/
void dcg2900_u5500_enable_chip(struct cg2900_chip_dev *dev)
{
	struct dcg2900_info *info = dev->b_data;

	clk_enable(info->lpoclk);
	/*
	 * Due to a bug in CG2900 we cannot just set GPIO high to enable
	 * the chip. We must wait more than 100 msecs before enbling the
	 * chip.
	 * - Set PDB to low.
	 * - Wait for 100 msecs
	 * - Set PDB to high.
	 */
	prcmu_resetout(1, 0);
	schedule_timeout_uninterruptible(msecs_to_jiffies(
					CHIP_ENABLE_PDB_LOW_TIMEOUT));
	prcmu_resetout(1, 1);
}

void dcg2900_u5500_disable_chip(struct cg2900_chip_dev *dev)
{
	struct dcg2900_info *info = dev->b_data;

	prcmu_resetout(1, 0);
	clk_disable(info->lpoclk);
}

int dcg2900_u5500_setup(struct cg2900_chip_dev *dev,
				struct dcg2900_info *info)
{
	info->lpoclk = clk_get(dev->dev, "lpoclk");
	if (IS_ERR(info->lpoclk))
		return PTR_ERR(info->lpoclk);

	return 0;
}