summaryrefslogtreecommitdiff
path: root/arch/arm/plat-stmp3xxx/mmc.c
blob: 75dc3a9f282a50f025e0cb1cdca2865bb7dede86 (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
/*
 * Freescale STMP37XX/STMP378X MMC pin multiplexing
 *
 * Embedded Alley Solutions, Inc <source@embeddedalley.com>
 *
 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
 * Copyright 2008 Embedded Alley Solutions, 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/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/clk.h>
#include <linux/gpio.h>
#include <mach/pinmux.h>
#include <mach/stmp3xxx.h>
#include <mach/platform.h>
#include <mach/mmc.h>
#include <mach/regs-ssp.h>

#if defined(CONFIG_MACH_STMP378X)
#define MMC_POWER	PINID_PWM3
#define MMC_WP		PINID_PWM4
#elif defined(CONFIG_MACH_STMP37XX)
#define MMC_POWER	PINID_PWM3
#define MMC_WP		PINID_PWM4
#else
#define MMC_POWER	PINID_NO_PIN
#define MMC_WP		PINID_NO_PIN
#endif

static int mmc_drive_power;
static int mmc_wp_supported;

static struct pin_desc mmc_pins_desc[] = {
	{ PINID_SSP1_DATA0, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
	{ PINID_SSP1_DATA1, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
	{ PINID_SSP1_DATA2, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
	{ PINID_SSP1_DATA3, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
	{ PINID_SSP1_CMD, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
	{ PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
	{ PINID_SSP1_DETECT, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
};

static struct pin_group mmc_pins = {
	.pins		= mmc_pins_desc,
	.nr_pins	= ARRAY_SIZE(mmc_pins_desc),
};

int stmp3xxxmmc_get_wp(void)
{
	if (mmc_wp_supported)
		return gpio_get_value(MMC_WP);

	return 0;
}

int stmp3xxxmmc_hw_init_ssp1(void)
{
	int ret;

	mmc_drive_power = stmp3xxx_valid_pin(MMC_POWER);
	mmc_wp_supported = stmp3xxx_valid_pin(MMC_WP);

	ret = stmp3xxx_request_pin_group(&mmc_pins, "mmc");
	if (ret)
		goto out;

	if (mmc_wp_supported) {
		/* Configure write protect GPIO pin */
		ret = gpio_request(MMC_WP, "mmc wp");
		if (ret)
			goto out_wp;

		gpio_set_value(MMC_WP, 0);
		gpio_direction_input(MMC_WP);
	}

	if (mmc_drive_power) {
		/* Configure POWER pin as gpio to drive power to MMC slot */
		ret = gpio_request(MMC_POWER, "mmc power");
		if (ret)
			goto out_power;

		gpio_direction_output(MMC_POWER, 0);
		mdelay(100);
	}

	return 0;

out_power:
	if (mmc_wp_supported)
		gpio_free(MMC_WP);
out_wp:
	stmp3xxx_release_pin_group(&mmc_pins, "mmc");
out:
	return ret;
}

void stmp3xxxmmc_hw_release_ssp1(void)
{
	if (mmc_drive_power)
		gpio_free(MMC_POWER);

	if (mmc_wp_supported)
		gpio_free(MMC_WP);

	stmp3xxx_release_pin_group(&mmc_pins, "mmc");
}

void stmp3xxxmmc_cmd_pullup_ssp1(int enable)
{
	stmp3xxx_pin_pullup(PINID_SSP1_CMD, enable, "mmc");
}

unsigned long stmp3xxxmmc_setclock_ssp1(unsigned long hz)
{
	struct clk *ssp = clk_get(NULL, "ssp"), *parent;
	char *p;
	long r;

	/* using SSP1, no timeout, clock rate 1 */
	__raw_writel(BF(2, SSP_TIMING_CLOCK_DIVIDE) |
			BF(0xFFFF, SSP_TIMING_TIMEOUT),
			REGS_SSP1_BASE + HW_SSP_TIMING);

	if (hz > 1000000)
		p = "io";
	else
		p = "osc_24M";

	parent = clk_get(NULL, p);
	clk_set_parent(ssp, parent);
	r = clk_set_rate(ssp, 2 * hz / 1000);
	clk_put(parent);
	clk_put(ssp);

	return hz;
}