1 /****************************************************************************
2 * (C) Copyright 2008 Samsung Electronics Co., Ltd., All rights reserved
4 * @file s3c-otg-hcdi-kal.h
5 * @brief header of s3c-otg-hcdi-kal \n
7 * -# Jun 9,2008 v1.0 by SeungSoo Yang (ss1.yang@samsung.com) \n
8 * : Creating the initial version of this code \n
9 * -# Jul 15,2008 v1.2 by SeungSoo Yang (ss1.yang@samsung.com) \n
10 * : Optimizing for performance \n
11 * -# Aug 18,2008 v1.3 by SeungSoo Yang (ss1.yang@samsung.com) \n
12 * : Modifying for successful rmmod & disconnecting \n
14 ****************************************************************************/
15 /****************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 ****************************************************************************/
31 #ifndef _S3C_OTG_HCDI_KAL_H_
32 #define _S3C_OTG_HCDI_KAL_H_
39 #include "s3c-otg-hcdi-debug.h"
40 #include "s3c-otg-common-common.h"
41 #include "s3c-otg-common-datastruct.h"
42 #include "s3c-otg-common-const.h"
44 #include <asm/io.h> //for readl, writel
45 #include <linux/usb/ch9.h> //for usb_device_driver, enum usb_device_speed
46 #include <linux/usb.h>
47 #include <linux/usb/hcd.h>
49 #include <plat/regs-otg.h>
51 extern volatile u8 * g_pUDCBase;
52 extern struct usb_hcd* g_pUsbHcd;
54 #include <linux/spinlock.h>
55 #define SPINLOCK_t spinlock_t
56 #define SPIN_LOCK_INIT SPIN_LOCK_UNLOCKED
58 #define spin_lock_otg(lock) spin_lock(lock)
59 #define spin_lock_irg_otg(lock) spin_lock_irq(lock)
60 #define spin_lock_irq_save_otg(lock, flags) spin_lock_irqsave(lock, flags)
62 #define spin_unlock_otg(lock) spin_unlock(lock)
63 #define spin_unlock_irq_otg(lock) spin_unlock_irq(lock)
64 #define spin_unlock_irq_save_otg(lock, flags) spin_unlock_irqrestore(lock, flags)
66 #define ctrlr_base_reg_addr(offset) \
67 ((volatile unsigned int *)((g_pUDCBase) + (offset)))
69 * otg_kal_make_ep_null
71 * @brief make ep->hcpriv NULL
73 * @param [in] pdelete_ed : pointer of ed
83 ((struct usb_host_endpoint *)(pdelete_ed->ed_private))->hcpriv = NULL;
85 //---------------------------------------------------------------------------------------
90 * @brief check ep->hcpriv is NULL or not
92 * @param [in] pdelete_ed : pointer of ed
102 if (((struct usb_host_endpoint *)(pdelete_ed->ed_private))->hcpriv == NULL)
107 //---------------------------------------------------------------------------------------
111 * int otg_usbcore_get_calc_bustime()
113 * @brief get bus time of usbcore
115 * @param [in] speed : usb speed
116 * [in] is_input : input or not
117 * [in] is_isoch : isochronous or not
118 * [in] byte_count : bytes
120 * @return bus time of usbcore \n
123 otg_usbcore_get_calc_bustime
128 unsigned int byte_count
131 unsigned int convert_speed = 0;
133 otg_dbg(OTG_DBG_OTGHCDI_KAL, "otg_usbcore_get_calc_bustime \n");
134 /* enum usb_device_speed {
135 USB_SPEED_UNKNOWN = 0,
136 USB_SPEED_LOW, USB_SPEED_FULL,
138 USB_SPEED_VARIABLE, };*/
140 case HIGH_SPEED_OTG :
141 convert_speed = USB_SPEED_HIGH;
144 case FULL_SPEED_OTG :
145 convert_speed = USB_SPEED_FULL;
149 convert_speed = USB_SPEED_LOW;
153 convert_speed = USB_SPEED_UNKNOWN;
156 return usb_calc_bus_time(convert_speed, is_input, (unsigned int)is_isoch, byte_count);
159 //-------------------------------------------------------------------------------
162 * void otg_usbcore_giveback(td_t td_p)
164 * @brief give-back a td as urb
166 * @param [in] td_p : pointer of td_t to give back
171 otg_usbcore_giveback(td_t * td_p)
173 struct urb *urb_p = NULL;
175 otg_dbg(OTG_DBG_OTGHCDI_KAL, "otg_usbcore_giveback \n");
177 if (td_p->td_private == NULL)
179 otg_err(OTG_DBG_OTGHCDI_KAL,
180 "td_p->td_private == NULL \n");
184 urb_p = (struct urb *)td_p->td_private;
186 urb_p->actual_length = (int)(td_p->transferred_szie);
187 urb_p->status = (int)(td_p->error_code);
188 urb_p->error_count = (int)(td_p->err_cnt);
189 urb_p->hcpriv = NULL;
191 usb_hcd_giveback_urb(g_pUsbHcd, urb_p, urb_p->status);
193 //-------------------------------------------------------------------------------
196 * void otg_usbcore_hc_died(void)
198 * @brief inform usbcore of hc die
203 otg_usbcore_hc_died(void)
205 otg_dbg(OTG_DBG_OTGHCDI_KAL, "otg_usbcore_hc_died \n");
206 usb_hc_died(g_pUsbHcd);
208 //-------------------------------------------------------------------------------
211 * void otg_usbcore_poll_rh_status(void)
213 * @brief invoke usbcore's usb_hcd_poll_rh_status
220 otg_usbcore_poll_rh_status(void)
222 usb_hcd_poll_rh_status(g_pUsbHcd);
224 //-------------------------------------------------------------------------------
227 * void otg_usbcore_resume_roothub(void)
229 * @brief invoke usbcore's usb_hcd_resume_root_hub
236 otg_usbcore_resume_roothub(void)
238 otg_dbg(OTG_DBG_OTGHCDI_KAL,
239 "otg_usbcore_resume_roothub \n");
240 usb_hcd_resume_root_hub(g_pUsbHcd);
242 //-------------------------------------------------------------------------------
245 * int otg_usbcore_inc_usb_bandwidth(u32 band_width)
247 * @brief increase bandwidth of usb bus
249 * @param [in] band_width : bandwidth to be increased
251 * @return USB_ERR_SUCCESS \n
254 otg_usbcore_inc_usb_bandwidth(u32 band_width)
256 otg_dbg(OTG_DBG_OTGHCDI_KAL,
257 "otg_usbcore_inc_usb_bandwidth \n");
258 hcd_to_bus(g_pUsbHcd)->bandwidth_allocated += band_width;
259 return USB_ERR_SUCCESS;
261 //-------------------------------------------------------------------------------
264 * int otg_usbcore_des_usb_bandwidth(u32 uiBandwidth)
266 * @brief decrease bandwidth of usb bus
268 * @param [in] band_width : bandwidth to be decreased
270 * @return USB_ERR_SUCCESS \n
273 otg_usbcore_des_usb_bandwidth(u32 band_width)
275 otg_dbg(OTG_DBG_OTGHCDI_KAL,
276 "otg_usbcore_des_usb_bandwidth \n");
277 hcd_to_bus(g_pUsbHcd)->bandwidth_allocated -= band_width;
278 return USB_ERR_SUCCESS;
280 //-------------------------------------------------------------------------------
283 * int otg_usbcore_inc_periodic_transfer_cnt(u8 transfer_type)
285 * @brief increase count of periodic transfer
287 * @param [in] transfer_type : type of transfer
289 * @return USB_ERR_SUCCESS : If success \n
290 * USB_ERR_FAIL : If call fail \n
293 otg_usbcore_inc_periodic_transfer_cnt(u8 transfer_type)
295 otg_dbg(OTG_DBG_OTGHCDI_KAL,
296 "otg_usbcore_inc_periodic_transfer_cnt \n");
298 switch(transfer_type) {
300 hcd_to_bus(g_pUsbHcd)->bandwidth_int_reqs++;
302 case ISOCH_TRANSFER :
303 hcd_to_bus(g_pUsbHcd)->bandwidth_isoc_reqs++;
306 otg_err(OTG_DBG_OTGHCDI_KAL,
307 "not proper TransferType for otg_usbcore_inc_periodic_transfer_cnt()\n");
310 return USB_ERR_SUCCESS;
312 //-------------------------------------------------------------------------------
315 * int otg_usbcore_des_periodic_transfer_cnt(u8 transfer_type)
317 * @brief decrease count of periodic transfer
319 * @param [in] transfer_type : type of transfer
321 * @return USB_ERR_SUCCESS : If success \n
322 * USB_ERR_FAIL : If call fail \n
325 otg_usbcore_des_periodic_transfer_cnt(u8 transfer_type)
327 otg_dbg(OTG_DBG_OTGHCDI_KAL,
328 "otg_usbcore_des_periodic_transfer_cnt \n");
330 switch(transfer_type) {
332 hcd_to_bus(g_pUsbHcd)->bandwidth_int_reqs--;
334 case ISOCH_TRANSFER :
335 hcd_to_bus(g_pUsbHcd)->bandwidth_isoc_reqs--;
338 otg_err(OTG_DBG_OTGHCDI_KAL,
339 "not proper TransferType for otg_usbcore_des_periodic_transfer_cnt()\n");
342 return USB_ERR_SUCCESS;
344 //-------------------------------------------------------------------------------
347 * u32 read_reg_32(u32 offset)
349 * @brief Reads the content of a register.
351 * @param [in] offset : offset of address of register to read.
353 * @return contents of the register. \n
354 * @remark call readl()
356 static inline u32 read_reg_32(u32 offset)
358 volatile unsigned int * reg_addr_p = ctrlr_base_reg_addr(offset);
361 //return readl(reg_addr_p);
363 //-------------------------------------------------------------------------------
366 * void write_reg_32( u32 offset, const u32 value)
368 * @brief Writes a register with a 32 bit value.
370 * @param [in] offset : offset of address of register to write.
371 * @param [in] value : value to write
373 * @remark call writel()
375 static inline void write_reg_32( u32 offset, const u32 value)
377 volatile unsigned int * reg_addr_p = ctrlr_base_reg_addr(offset);
380 //writel( value, reg_addr_p );
382 //-------------------------------------------------------------------------------
385 * void update_reg_32(u32 offset, u32 value)
387 * @brief logic or operation
389 * @param [in] offset : offset of address of register to write.
390 * @param [in] value : value to or
393 static inline void update_reg_32(u32 offset, u32 value)
395 write_reg_32(offset, (read_reg_32(offset) | value));
397 //---------------------------------------------------------------------------------------
400 * void clear_reg_32(u32 offset, u32 value)
402 * @brief logic not operation
404 * @param [in] offset : offset of address of register to write.
405 * @param [in] value : value to not
408 static inline void clear_reg_32(u32 offset, u32 value)
410 write_reg_32(offset, (read_reg_32(offset) & ~value));
412 //---------------------------------------------------------------------------------------
419 #endif /* _S3C_OTG_HCDI_KAL_H_ */