aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/s3c-otg/s3c-otg-isr.c
blob: b72b386198ed31719de993928c3a6ad906cf3d33 (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/****************************************************************************
 *  (C) Copyright 2008 Samsung Electronics Co., Ltd., All rights reserved
 *
 *  [File Name]   : Isr.c
 *  [Description] : The file implement the external and internal functions of ISR
 *  [Author]      : Jang Kyu Hyeok { kyuhyeok.jang@samsung.com }
 *  [Department]  : System LSI Division/Embedded S/W Platform
 *  [Created Date]: 2009/02/10
 *  [Revision History]
 *	  (1) 2008/06/13   by Jang Kyu Hyeok { kyuhyeok.jang@samsung.com }
 *          - Created this file and implements functions of ISR
 *
 ****************************************************************************/
/****************************************************************************
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ****************************************************************************/

#include "s3c-otg-isr.h"

/**
 * void otg_handle_interrupt(void)
 *
 * @brief Main interrupt processing routine
 *
 * @param None
 *
 * @return None
 *
 * @remark
 *
 */

__inline__ void otg_handle_interrupt(struct usb_hcd *hcd)
{
	gintsts_t clearIntr = {.d32 = 0};
	gintsts_t gintsts = {.d32 = 0};
	struct sec_otghost *otghost = hcd_to_sec_otghost(hcd);

	gintsts.d32 = read_reg_32(GINTSTS) & read_reg_32(GINTMSK);

	otg_dbg(OTG_DBG_ISR, "otg_handle_interrupt - GINTSTS=0x%8x\n",
		      				 	gintsts.d32);

	if (gintsts.b.wkupintr) {
		otg_dbg(true, "Wakeup Interrupt\n");
		clearIntr.b.wkupintr = 1;
	}

	if (gintsts.b.disconnect) {
		otg_dbg(true, "Disconnect  Interrupt\n");
		otghost->port_flag.b.port_connect_status_change = 1;
		otghost->port_flag.b.port_connect_status = 0;
		clearIntr.b.disconnect = 1;
		/*
		wake_unlock(&otghost->wake_lock);
		*/
	}

	if (gintsts.b.conidstschng) {
		otg_dbg(OTG_DBG_ISR, "Connect ID Status Change Interrupt\n");
		clearIntr.b.conidstschng = 1;
		oci_init_mode();
	}

	if (gintsts.b.hcintr) {
		/* Mask Channel Interrupt to prevent generating interrupt */
		otg_dbg(OTG_DBG_ISR, "Channel Interrupt\n");
		if(!otghost->ch_halt) {
			do_transfer_checker(otghost);
		}
	}

	if (gintsts.b.portintr) {
		/* Read Only */
		otg_dbg(true, "Port Interrupt\n");
		process_port_intr(hcd);
	}


	if (gintsts.b.otgintr) {
		/* Read Only */
		otg_dbg(OTG_DBG_ISR, "OTG Interrupt\n");
	}

	if (gintsts.b.sofintr) {
		/* otg_dbg(OTG_DBG_ISR, "SOF Interrupt\n"); */
		do_schedule(otghost);
		clearIntr.b.sofintr = 1;
	}

	if (gintsts.b.modemismatch) {
		otg_dbg(OTG_DBG_ISR, "Mode Mismatch Interrupt\n");
		clearIntr.b.modemismatch = 1;
	}
	update_reg_32(GINTSTS, clearIntr.d32);
}

/**
 * void mask_channel_interrupt(u32 ch_num, u32 mask_info)
 *
 * @brief Mask specific channel interrupt
 *
 * @param [IN] chnum : channel number for masking
 *	   [IN] mask_info : mask information to write register
 *
 * @return None
 *
 * @remark
 *
 */
void mask_channel_interrupt(u32 ch_num, u32 mask_info)
{
	clear_reg_32(HCINTMSK(ch_num),mask_info);
}

/**
 * void unmask_channel_interrupt(u32 ch_num, u32 mask_info)
 *
 * @brief Unmask specific channel interrupt
 *
 * @param [IN] chnum : channel number for unmasking
 *	   [IN] mask_info : mask information to write register
 *
 * @return None
 *
 * @remark
 *
 */
void unmask_channel_interrupt(u32	ch_num, u32 mask_info)
{
	update_reg_32(HCINTMSK(ch_num),mask_info);
}

/**
 * int get_ch_info(hc_info_t * hc_reg, u8 ch_num)
 *
 * @brief Get current channel information about specific channel
 *
 * @param [OUT] hc_reg : structure to write channel inforamtion value
 *	   [IN] ch_num : channel number for unmasking
 *
 * @return None
 *
 * @remark
 *
 */
int get_ch_info(hc_info_t *hc_reg, u8 ch_num)
{
	if(hc_reg !=NULL) {
		hc_reg->hc_int_msk.d32 	= read_reg_32(HCINTMSK(ch_num));
		hc_reg->hc_int.d32 	= read_reg_32(HCINT(ch_num));
		hc_reg->dma_addr 	= read_reg_32(HCDMA(ch_num));
		hc_reg->hc_char.d32 	= read_reg_32(HCCHAR(ch_num));
		hc_reg->hc_size.d32 	= read_reg_32(HCTSIZ(ch_num));

		return USB_ERR_SUCCESS;
	}
	return USB_ERR_FAIL;
}

/**
 * void get_intr_ch(u32* haint, u32* haintmsk)
 *
 * @brief Get Channel Interrupt Information in HAINT, HAINTMSK register
 *
 * @param [OUT] haint : HAINT register value
 *	   [OUT] haintmsk : HAINTMSK register value
 *
 * @return None
 *
 * @remark
 *
 */
void get_intr_ch(u32 *haint, u32 *haintmsk)
{
	*haint = read_reg_32(HAINT);
	*haintmsk = read_reg_32(HAINTMSK);
}

/**
 * void clear_ch_intr(u8 ch_num, u32 clear_bit)
 *
 * @brief Get Channel Interrupt Information in HAINT, HAINTMSK register
 *
 * @param [IN] haint : HAINT register value
 *	   [IN] haintmsk : HAINTMSK register value
 *
 * @return None
 *
 * @remark
 *
 */
void clear_ch_intr(u8 ch_num, u32 clear_bit)
{
	update_reg_32(HCINT(ch_num),clear_bit);
}

/**
 * void enable_sof(void)
 *
 * @brief Generate SOF Interrupt.
 *
 * @param None
 *
 * @return None
 *
 * @remark
 *
 */
void enable_sof(void)
{
	gintmsk_t gintmsk = {.d32 = 0};
	gintmsk.b.sofintr = 1;
	update_reg_32(GINTMSK, gintmsk.d32);
}

/**
 *  void disable_sof(void)
 *
 * @brief Stop to generage SOF interrupt
 *
 * @param None
 *
 * @return None
 *
 * @remark
 *
 */
void disable_sof(void)
{
	gintmsk_t gintmsk = {.d32 = 0};
	gintmsk.b.sofintr = 1;
	clear_reg_32(GINTMSK, gintmsk.d32);
}

/*Internal function of isr */
void process_port_intr(struct usb_hcd *hcd)
{
	hprt_t	hprt; /* by ss1, clear_hprt; */
	struct sec_otghost *otghost = hcd_to_sec_otghost(hcd);

	hprt.d32 = read_reg_32(HPRT);

	otg_dbg(OTG_DBG_ISR, "Port Interrupt() : HPRT = 0x%x\n",hprt.d32);

	if(hprt.b.prtconndet) {
		otg_dbg(true, "detect connection");

		otghost->port_flag.b.port_connect_status_change = 1;

		if(hprt.b.prtconnsts)
			otghost->port_flag.b.port_connect_status = 1;

		/* wake_lock(&otghost->wake_lock); */
	}


	if(hprt.b.prtenchng) {
		otg_dbg(true, "port enable/disable changed\n");
		otghost->port_flag.b.port_enable_change = 1;
	}

	if(hprt.b.prtovrcurrchng) {
		otg_dbg(true, "over current condition is changed\n");
		if(hprt.b.prtovrcurract) {
			otg_dbg(true, "port_over_current_change = 1\n");
			otghost->port_flag.b.port_over_current_change = 1;
		}
		else {
			otghost->port_flag.b.port_over_current_change = 0;
		}
		/* defer otg power control into a kernel thread */
		queue_work(otghost->wq, &otghost->work);
	}

	hprt.b.prtena = 0; /* prtena¸¦ writeclear½ÃÅ°¸é ¾ÈµÊ. */
	/* hprt.b.prtpwr = 0; */
	hprt.b.prtrst = 0;
	hprt.b.prtconnsts = 0;

	write_reg_32(HPRT, hprt.d32);
}