summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/board-enterprise-baseband.c
blob: 285f01dcdb24bdb83d2334769377f4b68d78c7d1 (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
/*
 * arch/arm/mach-tegra/board-enterprise-baseband.c
 *
 * Copyright (c) 2011, NVIDIA Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <linux/resource.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/err.h>
#include <linux/platform_data/tegra_usb.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <mach/pinmux.h>
#include <mach/usb_phy.h>
#include "devices.h"
#include "gpio-names.h"

/* T30 BB GPIO */
#define MODEM_PWR_ON	TEGRA_GPIO_PE0
#define MODEM_RESET	TEGRA_GPIO_PE1

/* PH450 */
#define AP2MDM_ACK	TEGRA_GPIO_PE3
#define MDM2AP_ACK	TEGRA_GPIO_PU5
#define AP2MDM_ACK2	TEGRA_GPIO_PE2
#define MDM2AP_ACK2	TEGRA_GPIO_PV0

static int ph450_reset(void);
static int ph450_handshake(void);

static struct tegra_ulpi_trimmer e1219_trimmer = { 10, 1, 1, 1 };

static struct tegra_ulpi_config ehci2_null_ulpi_phy_config = {
	.trimmer = &e1219_trimmer,
	.preinit = ph450_reset,
	.postinit = ph450_handshake,
};

static struct tegra_ehci_platform_data ehci2_null_ulpi_platform_data = {
	.operating_mode = TEGRA_USB_HOST,
	.power_down_on_bus_suspend = 0,
	.phy_config = &ehci2_null_ulpi_phy_config,
	.phy_type = TEGRA_USB_PHY_TYPE_NULL_ULPI,
};

static int __init tegra_null_ulpi_init(void)
{
	tegra_ehci2_device.dev.platform_data = &ehci2_null_ulpi_platform_data;
	platform_device_register(&tegra_ehci2_device);
	return 0;
}

static int __init ph450_init(void)
{
	int ret;

	ret = gpio_request(MODEM_PWR_ON, "mdm_power");
	if (ret)
		return ret;

	ret = gpio_request(MODEM_RESET, "mdm_reset");
	if (ret) {
		gpio_free(MODEM_PWR_ON);
		return ret;
	}
	ret = gpio_request(AP2MDM_ACK2, "ap2mdm_ack2");
	if (ret) {
		gpio_free(MODEM_PWR_ON);
		gpio_free(MODEM_RESET);
		return ret;
	}
	ret = gpio_request(MDM2AP_ACK2, "mdm2ap_ack2");
	if (ret) {
		gpio_free(MODEM_PWR_ON);
		gpio_free(MODEM_RESET);
		gpio_free(AP2MDM_ACK2);
		return ret;
	}

	/* enable pull-up for MDM2AP_ACK2 */
	tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_GPIO_PV0,
				    TEGRA_PUPD_PULL_UP);

	tegra_gpio_enable(MODEM_PWR_ON);
	tegra_gpio_enable(MODEM_RESET);
	tegra_gpio_enable(AP2MDM_ACK2);
	tegra_gpio_enable(MDM2AP_ACK2);

	gpio_direction_output(MODEM_PWR_ON, 0);
	gpio_direction_output(MODEM_RESET, 0);
	gpio_direction_output(AP2MDM_ACK2, 1);
	gpio_direction_input(MDM2AP_ACK2);

	return 0;
}

static int ph450_reset(void)
{
	int retry = 100; /* retry for 10 sec */

	gpio_set_value(AP2MDM_ACK2, 1);
	gpio_set_value(MODEM_PWR_ON, 0);
	gpio_set_value(MODEM_RESET, 0);
	mdelay(200);
	gpio_set_value(MODEM_RESET, 1);
	mdelay(30);
	gpio_set_value(MODEM_PWR_ON, 1);

	while (retry) {
		/* wait for MDM2AP_ACK2 low */
		int val = gpio_get_value(MDM2AP_ACK2);
		if (!val) {
			pr_info("MDM2AP_ACK2 detected\n");
			return 0;
		} else {
			pr_info(".");
			retry--;
			mdelay(100);
		}
	}
	return 1;
}

static int ph450_handshake(void)
{
	/* set AP2MDM_ACK2 low */
	gpio_set_value(AP2MDM_ACK2, 0);

	return 0;
}

int __init enterprise_modem_init(void)
{
	int ret;

	ret = ph450_init();
	if (ret) {
		pr_err("modem init failed\n");
		return ret;
	}

	tegra_null_ulpi_init();
	return 0;
}