1 /******************************************************************************
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
25 ******************************************************************************/
29 #include "osdep_service.h"
30 #include "osdep_intf.h"
34 #define MAX_PROT_SZ (64-16)
37 #define _IO_WAIT_COMPLETE 1
38 #define _IO_WAIT_RSP 2
41 #define _IOSZ_MASK_ (0x7F)
42 #define _IO_WRITE_ BIT(7)
43 #define _IO_FIXED_ BIT(8)
44 #define _IO_BURST_ BIT(9)
45 #define _IO_BYTE_ BIT(10)
46 #define _IO_HW_ BIT(11)
47 #define _IO_WORD_ BIT(12)
48 #define _IO_SYNC_ BIT(13)
49 #define _IO_CMDMASK_ (0x1F80)
52 For prompt mode accessing, caller shall free io_req
53 Otherwise, io_handler will free io_req
56 #define _IO_ERR_ BIT(2)
57 #define _IO_SUCCESS_ BIT(1)
58 #define _IO_DONE_ BIT(0)
59 #define IO_RD32 (_IO_SYNC_ | _IO_WORD_)
60 #define IO_RD16 (_IO_SYNC_ | _IO_HW_)
61 #define IO_RD8 (_IO_SYNC_ | _IO_BYTE_)
62 #define IO_RD32_ASYNC (_IO_WORD_)
63 #define IO_RD16_ASYNC (_IO_HW_)
64 #define IO_RD8_ASYNC (_IO_BYTE_)
65 #define IO_WR32 (_IO_WRITE_ | _IO_SYNC_ | _IO_WORD_)
66 #define IO_WR16 (_IO_WRITE_ | _IO_SYNC_ | _IO_HW_)
67 #define IO_WR8 (_IO_WRITE_ | _IO_SYNC_ | _IO_BYTE_)
68 #define IO_WR32_ASYNC (_IO_WRITE_ | _IO_WORD_)
69 #define IO_WR16_ASYNC (_IO_WRITE_ | _IO_HW_)
70 #define IO_WR8_ASYNC (_IO_WRITE_ | _IO_BYTE_)
72 Only Sync. burst accessing is provided.
74 #define IO_WR_BURST(x) (IO_WRITE_ | _IO_SYNC_ | _IO_BURST_ | \
76 #define IO_RD_BURST(x) (_IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
77 /*below is for the intf_option bit defition...*/
78 #define _INTF_ASYNC_ BIT(0) /*support async io*/
83 uint (*_sdbus_read_bytes_to_membuf
)(struct intf_priv
*pintfpriv
,
84 u32 addr
, u32 cnt
, u8
*pbuf
);
85 uint (*_sdbus_read_blocks_to_membuf
)(struct intf_priv
*pintfpriv
,
86 u32 addr
, u32 cnt
, u8
*pbuf
);
87 u8 (*_read8
)(struct intf_hdl
*pintfhdl
, u32 addr
);
88 u16 (*_read16
)(struct intf_hdl
*pintfhdl
, u32 addr
);
89 u32 (*_read32
)(struct intf_hdl
*pintfhdl
, u32 addr
);
90 uint (*_sdbus_write_blocks_from_membuf
)(struct intf_priv
*pintfpriv
,
91 u32 addr
, u32 cnt
, u8
*pbuf
,
93 uint (*_sdbus_write_bytes_from_membuf
)(struct intf_priv
*pintfpriv
,
94 u32 addr
, u32 cnt
, u8
*pbuf
);
95 u8 (*_cmd52r
)(struct intf_priv
*pintfpriv
, u32 addr
);
96 void (*_cmd52w
)(struct intf_priv
*pintfpriv
, u32 addr
, u8 val8
);
97 u8 (*_cmdfunc152r
)(struct intf_priv
*pintfpriv
, u32 addr
);
98 void (*_cmdfunc152w
)(struct intf_priv
*pintfpriv
, u32 addr
, u8 val8
);
99 void (*_write8
)(struct intf_hdl
*pintfhdl
, u32 addr
, u8 val
);
100 void (*_write16
)(struct intf_hdl
*pintfhdl
, u32 addr
, u16 val
);
101 void (*_write32
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 val
);
102 void (*_read_mem
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 cnt
,
104 void (*_write_mem
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 cnt
,
106 void (*_sync_irp_protocol_rw
)(struct io_queue
*pio_q
);
107 u32 (*_read_port
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 cnt
,
109 u32 (*_write_port
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 cnt
,
114 struct list_head list
;
116 /*volatile*/ u32 val
;
120 struct semaphore sema
;
121 void (*_async_io_callback
)(struct _adapter
*padater
,
122 struct io_req
*pio_req
, u8
*cnxt
);
130 struct intf_priv
*pintfpriv
;
131 void (*intf_hdl_init
)(u8
*priv
);
132 void (*intf_hdl_unload
)(u8
*priv
);
133 void (*intf_hdl_open
)(u8
*priv
);
134 void (*intf_hdl_close
)(u8
*priv
);
135 struct _io_ops io_ops
;
138 struct reg_protocol_rd
{
140 #ifdef __LITTLE_ENDIAN
147 u32 WriteEnable
:1; /*0:read, 1:write*/
148 u32 FixOrContinuous
:1; /*0:continuous, 1: Fix*/
171 u32 FixOrContinuous
:1;
179 struct reg_protocol_wt
{
180 #ifdef __LITTLE_ENDIAN
187 u32 WriteEnable
:1; /*0:read, 1:write*/
188 u32 FixOrContinuous
:1; /*0:continuous, 1: Fix*/
212 u32 FixOrContinuous
:1;
222 Below is the data structure used by _io_handler
227 struct list_head free_ioreqs
;
228 /*The io_req list that will be served in the single protocol r/w.*/
229 struct list_head pending
;
230 struct list_head processing
;
231 u8
*free_ioreqs_buf
; /* 4-byte aligned */
232 u8
*pallocated_free_ioreqs_buf
;
233 struct intf_hdl intf
;
236 static inline u32
_RND4(u32 sz
)
239 val
= ((sz
>> 2) + ((sz
& 3) ? 1 : 0)) << 2;
243 u8
r8712_read8(struct _adapter
*adapter
, u32 addr
);
244 u16
r8712_read16(struct _adapter
*adapter
, u32 addr
);
245 u32
r8712_read32(struct _adapter
*adapter
, u32 addr
);
246 void r8712_read_mem(struct _adapter
*adapter
, u32 addr
, u32 cnt
, u8
*pmem
);
247 void r8712_read_port(struct _adapter
*adapter
, u32 addr
, u32 cnt
, u8
*pmem
);
248 void r8712_write8(struct _adapter
*adapter
, u32 addr
, u8 val
);
249 void r8712_write16(struct _adapter
*adapter
, u32 addr
, u16 val
);
250 void r8712_write32(struct _adapter
*adapter
, u32 addr
, u32 val
);
251 void r8712_write_mem(struct _adapter
*adapter
, u32 addr
, u32 cnt
, u8
*pmem
);
252 void r8712_write_port(struct _adapter
*adapter
, u32 addr
, u32 cnt
, u8
*pmem
);
254 uint
r8712_alloc_io_queue(struct _adapter
*adapter
);
255 void r8712_free_io_queue(struct _adapter
*adapter
);
257 #endif /*_RTL8711_IO_H_*/