summaryrefslogtreecommitdiff
path: root/sta_dk_4_0_4_32/pform/linux/src/tnetw_sdio.c
blob: a6bb7bada4a61d918b1f35daccb8737b202189d2 (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
/* tnetw_sdio.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Copyright © Texas Instruments Incorporated (Oct 2005)
 * THIS CODE/PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDED BUT NOT LIMITED TO , THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * This program has been modified from its original operation by Texas
 * Instruments Incorporated. These changes are covered under version 2
 * of the GNU General Public License, dated June 1991.
 *
 * Copyright © Google Inc (Feb 2008)
 */
/*-------------------------------------------------------------------*/
#ifdef TIWLAN_MSM7000
#include <linux/delay.h>
#include <linux/mmc/core.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/sdio_ids.h>
#include "esta_drv.h"
#include "mmc_omap_api.h"
#include "osApi.h"

/*-------------------------------------------------------------------*/
extern int tiwlan_sdio_init(struct sdio_func *func);
extern int sdio_reset_comm(struct mmc_card *card);

/*-------------------------------------------------------------------*/
static struct sdio_func *tiwlan_func = NULL;
static int sdio_reset_flag = 0;

#define DMA_THRESHOLD_SIZE  64
static void *sdio_dma_ptr = NULL;

/*-------------------------------------------------------------------*/
void SDIO_SetFunc( struct sdio_func *func )
{
	tiwlan_func = func;
}

struct sdio_func *SDIO_GetFunc( void )
{
	return tiwlan_func;
}

SDIO_Status SDIO_Init(SDIO_ConfigParams *ConfigParams, SDIO_Handle *Handle)
{
	if (Handle == NULL) {
		printk(KERN_ERR "Error: SDIO_Init() called with NULL!\n");
		return SDIO_FAILURE;
	}

	*Handle = (SDIO_Handle)SDIO_GetFunc();
	if ((*Handle) == NULL) {
		printk(KERN_ERR "SDIO_Init() called before init!\n");
		return SDIO_FAILURE;
	}

	if (!sdio_dma_ptr) {
		if (!(sdio_dma_ptr = kmalloc(PAGE_SIZE, GFP_KERNEL))) {
			printk(KERN_ERR "Failed to alloc DMA bounce buffer\n");
			return SDIO_FAILURE;
		}
	}
	return SDIO_SUCCESS;
}

SDIO_Status SDIO_Shutdown(SDIO_Handle Handle)
{
	if (sdio_dma_ptr) {
		kfree(sdio_dma_ptr);
		sdio_dma_ptr = NULL;
	}
	return SDIO_SUCCESS;
}

SDIO_Status SDIO_Start(SDIO_Handle Handle)
{
	struct sdio_func *func = (struct sdio_func *)Handle;

	if (func) {
		if (sdio_reset_flag) {
			sdio_reset_flag = 0;
			if (tiwlan_sdio_init(func)) {
				printk("TI: tiwlan_sdio_init Error!\n");
				return SDIO_FAILURE;
			}

		}
	}
	return SDIO_SUCCESS;
}

SDIO_Status SDIO_Reset(SDIO_Handle Handle)
{
	struct sdio_func *func = (struct sdio_func *)Handle;

	if(func && func->card)
		sdio_reset_comm(func->card);
	return SDIO_SUCCESS;
}

SDIO_Status SDIO_Stop(SDIO_Handle Handle, unsigned long Wait_Window)
{
	sdio_reset_flag = 1;
	return SDIO_Reset(Handle);
}

SDIO_Status SDIO_SyncRead(SDIO_Handle Handle, SDIO_Request_t *Req)
{
	struct sdio_func *func = (struct sdio_func *)Handle;
	int rc;

	if (Req->buffer_len < DMA_THRESHOLD_SIZE) {
		rc = sdio_memcpy_fromio(func, Req->buffer,
					Req->peripheral_addr, Req->buffer_len);
        } else {
		rc = sdio_memcpy_fromio(func, sdio_dma_ptr,
					Req->peripheral_addr, Req->buffer_len);
		memcpy(Req->buffer, sdio_dma_ptr, Req->buffer_len);
	}

	if (!rc)
		return SDIO_SUCCESS;

	printk("SDIO Write failure (%d)\n", rc);
	return SDIO_FAILURE;
}

SDIO_Status SDIO_SyncWrite(SDIO_Handle Handle, SDIO_Request_t *Req)
{
	struct sdio_func *func = (struct sdio_func *)Handle;
	int rc;
	void *dma_ptr;

	if (Req->buffer_len < DMA_THRESHOLD_SIZE)
		dma_ptr = Req->buffer;
	else {
		dma_ptr = sdio_dma_ptr;
		memcpy(dma_ptr, Req->buffer, Req->buffer_len);
	}

	rc = sdio_memcpy_toio(func, Req->peripheral_addr, dma_ptr,
			      Req->buffer_len);
	if (!rc)
		return SDIO_SUCCESS;

	printk("SDIO Write failure (%d)\n", rc);
	return SDIO_FAILURE;
}
#endif