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 ****************************************************************************/
34 #include <linux/io.h> /* for readl, writel */
35 #include <linux/usb/ch9.h>
36 #include <linux/usb.h>
37 #include <linux/usb/hcd.h>
39 #include <plat/regs-otg.h>
41 extern volatile u8 *g_pUDCBase;
42 extern struct usb_hcd *g_pUsbHcd;
44 #define ctrlr_base_reg_addr(offset) \
45 ((volatile unsigned int *)((g_pUDCBase) + (offset)))
47 * otg_kal_make_ep_null
49 * @brief make ep->hcpriv NULL
51 * @param [in] pdelete_ed : pointer of ed
56 otg_kal_make_ep_null(struct ed *pdelete_ed)
58 ((struct usb_host_endpoint *)(pdelete_ed->ed_private))->hcpriv = NULL;
64 * @brief check ep->hcpriv is NULL or not
66 * @param [in] pdelete_ed : pointer of ed
71 otg_kal_is_ep_null(struct ed *pdelete_ed)
73 if (((struct usb_host_endpoint *)
74 (pdelete_ed->ed_private))->hcpriv == NULL)
82 * int otg_usbcore_get_calc_bustime()
84 * @brief get bus time of usbcore
86 * @param [in] speed : usb speed
87 * [in] is_input : input or not
88 * [in] is_isoch : isochronous or not
89 * [in] byte_count : bytes
91 * @return bus time of usbcore \n
94 otg_usbcore_get_calc_bustime(u8 speed, bool is_input,
95 bool is_isoch, unsigned int byte_count)
97 unsigned int convert_speed = 0;
99 otg_dbg(OTG_DBG_OTGHCDI_KAL, "otg_usbcore_get_calc_bustime\n");
100 /* enum usb_device_speed {
101 USB_SPEED_UNKNOWN = 0,
102 USB_SPEED_LOW, USB_SPEED_FULL,
104 USB_SPEED_VARIABLE, };*/
107 convert_speed = USB_SPEED_HIGH; break;
109 convert_speed = USB_SPEED_FULL; break;
111 convert_speed = USB_SPEED_LOW; break;
113 convert_speed = USB_SPEED_UNKNOWN; break;
115 return usb_calc_bus_time(convert_speed, is_input,
116 (unsigned int)is_isoch, byte_count);
121 * void otg_usbcore_giveback(struct td td_p)
123 * @brief give-back a td as urb
125 * @param [in] td_p : pointer of struct td to give back
130 otg_usbcore_giveback(struct td *td_p)
132 struct urb *urb_p = NULL;
134 otg_dbg(OTG_DBG_OTGHCDI_KAL, "otg_usbcore_giveback\n");
136 if (td_p->td_private == NULL) {
137 otg_err(OTG_DBG_OTGHCDI_KAL,
138 "td_p->td_private == NULL\n");
142 urb_p = (struct urb *)td_p->td_private;
144 urb_p->actual_length = (int)(td_p->transferred_szie);
145 urb_p->status = (int)(td_p->error_code);
146 urb_p->error_count = (int)(td_p->err_cnt);
147 urb_p->hcpriv = NULL;
149 usb_hcd_giveback_urb(g_pUsbHcd, urb_p, urb_p->status);
153 * void otg_usbcore_hc_died(void)
155 * @brief inform usbcore of hc die
160 otg_usbcore_hc_died(void)
162 otg_dbg(OTG_DBG_OTGHCDI_KAL, "otg_usbcore_hc_died\n");
163 usb_hc_died(g_pUsbHcd);
167 * void otg_usbcore_poll_rh_status(void)
169 * @brief invoke usbcore's usb_hcd_poll_rh_status
176 otg_usbcore_poll_rh_status(void)
178 usb_hcd_poll_rh_status(g_pUsbHcd);
182 * void otg_usbcore_resume_roothub(void)
184 * @brief invoke usbcore's usb_hcd_resume_root_hub
191 otg_usbcore_resume_roothub(void)
193 otg_dbg(OTG_DBG_OTGHCDI_KAL,
194 "otg_usbcore_resume_roothub\n");
195 usb_hcd_resume_root_hub(g_pUsbHcd);
199 * int otg_usbcore_inc_usb_bandwidth(u32 band_width)
201 * @brief increase bandwidth of usb bus
203 * @param [in] band_width : bandwidth to be increased
205 * @return USB_ERR_SUCCESS \n
208 otg_usbcore_inc_usb_bandwidth(u32 band_width)
210 otg_dbg(OTG_DBG_OTGHCDI_KAL,
211 "otg_usbcore_inc_usb_bandwidth\n");
212 hcd_to_bus(g_pUsbHcd)->bandwidth_allocated += band_width;
213 return USB_ERR_SUCCESS;
217 * int otg_usbcore_des_usb_bandwidth(u32 uiBandwidth)
219 * @brief decrease bandwidth of usb bus
221 * @param [in] band_width : bandwidth to be decreased
223 * @return USB_ERR_SUCCESS \n
226 otg_usbcore_des_usb_bandwidth(u32 band_width)
228 otg_dbg(OTG_DBG_OTGHCDI_KAL,
229 "otg_usbcore_des_usb_bandwidth\n");
230 hcd_to_bus(g_pUsbHcd)->bandwidth_allocated -= band_width;
231 return USB_ERR_SUCCESS;
235 * int otg_usbcore_inc_periodic_transfer_cnt(u8 transfer_type)
237 * @brief increase count of periodic transfer
239 * @param [in] transfer_type : type of transfer
241 * @return USB_ERR_SUCCESS : If success \n
242 * USB_ERR_FAIL : If call fail \n
245 otg_usbcore_inc_periodic_transfer_cnt(u8 transfer_type)
247 otg_dbg(OTG_DBG_OTGHCDI_KAL,
248 "otg_usbcore_inc_periodic_transfer_cnt\n");
250 switch (transfer_type) {
252 hcd_to_bus(g_pUsbHcd)->bandwidth_int_reqs++;
255 hcd_to_bus(g_pUsbHcd)->bandwidth_isoc_reqs++;
258 otg_err(OTG_DBG_OTGHCDI_KAL,
259 "not proper TransferType\n");
262 return USB_ERR_SUCCESS;
266 * int otg_usbcore_des_periodic_transfer_cnt(u8 transfer_type)
268 * @brief decrease count of periodic transfer
270 * @param [in] transfer_type : type of transfer
272 * @return USB_ERR_SUCCESS : If success \n
273 * USB_ERR_FAIL : If call fail \n
276 otg_usbcore_des_periodic_transfer_cnt(u8 transfer_type)
278 otg_dbg(OTG_DBG_OTGHCDI_KAL,
279 "otg_usbcore_des_periodic_transfer_cnt\n");
281 switch (transfer_type) {
283 hcd_to_bus(g_pUsbHcd)->bandwidth_int_reqs--;
286 hcd_to_bus(g_pUsbHcd)->bandwidth_isoc_reqs--;
289 otg_err(OTG_DBG_OTGHCDI_KAL,
290 "not proper TransferType\n");
293 return USB_ERR_SUCCESS;
297 * u32 read_reg_32(u32 offset)
299 * @brief Reads the content of a register.
301 * @param [in] offset : offset of address of register to read.
303 * @return contents of the register. \n
304 * @remark call readl()
306 static inline u32 read_reg_32(u32 offset)
308 volatile unsigned int *reg_addr_p = ctrlr_base_reg_addr(offset);
311 /* return readl(reg_addr_p); */
315 * void write_reg_32( u32 offset, const u32 value)
317 * @brief Writes a register with a 32 bit value.
319 * @param [in] offset : offset of address of register to write.
320 * @param [in] value : value to write
322 * @remark call writel()
324 static inline void write_reg_32(u32 offset, const u32 value)
326 volatile unsigned int *reg_addr_p = ctrlr_base_reg_addr(offset);
329 /* writel( value, reg_addr_p ); */
333 * void update_reg_32(u32 offset, u32 value)
335 * @brief logic or operation
337 * @param [in] offset : offset of address of register to write.
338 * @param [in] value : value to or
341 static inline void update_reg_32(u32 offset, u32 value)
343 write_reg_32(offset, (read_reg_32(offset) | value));
347 * void clear_reg_32(u32 offset, u32 value)
349 * @brief logic not operation
351 * @param [in] offset : offset of address of register to write.
352 * @param [in] value : value to not
355 static inline void clear_reg_32(u32 offset, u32 value)
357 write_reg_32(offset, (read_reg_32(offset) & ~value));
360 #endif /* _S3C_OTG_HCDI_KAL_H_ */