linux/drivers/staging/rtl8712/usb_ops.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/******************************************************************************
   3 * usb_ops.c
   4 *
   5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
   6 * Linux device driver for RTL8192SU
   7 *
   8 * Modifications for inclusion into the Linux staging tree are
   9 * Copyright(c) 2010 Larry Finger. All rights reserved.
  10 *
  11 * Contact information:
  12 * WLAN FAE <wlanfae@realtek.com>
  13 * Larry Finger <Larry.Finger@lwfinger.net>
  14 *
  15 ******************************************************************************/
  16
  17#define _HCI_OPS_C_
  18
  19#include "osdep_service.h"
  20#include "drv_types.h"
  21#include "osdep_intf.h"
  22#include "usb_ops.h"
  23#include "recv_osdep.h"
  24
  25static u8 usb_read8(struct intf_hdl *intfhdl, u32 addr)
  26{
  27        u8 request;
  28        u8 requesttype;
  29        u16 wvalue;
  30        u16 index;
  31        u16 len;
  32        __le32 data;
  33        struct intf_priv *intfpriv = intfhdl->pintfpriv;
  34
  35        request = 0x05;
  36        requesttype = 0x01; /* read_in */
  37        index = 0;
  38        wvalue = (u16)(addr & 0x0000ffff);
  39        len = 1;
  40        r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
  41                                requesttype);
  42        return (u8)(le32_to_cpu(data) & 0x0ff);
  43}
  44
  45static u16 usb_read16(struct intf_hdl *intfhdl, u32 addr)
  46{
  47        u8 request;
  48        u8 requesttype;
  49        u16 wvalue;
  50        u16 index;
  51        u16 len;
  52        __le32 data;
  53        struct intf_priv *intfpriv = intfhdl->pintfpriv;
  54
  55        request = 0x05;
  56        requesttype = 0x01; /* read_in */
  57        index = 0;
  58        wvalue = (u16)(addr & 0x0000ffff);
  59        len = 2;
  60        r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
  61                                requesttype);
  62        return (u16)(le32_to_cpu(data) & 0xffff);
  63}
  64
  65static u32 usb_read32(struct intf_hdl *intfhdl, u32 addr)
  66{
  67        u8 request;
  68        u8 requesttype;
  69        u16 wvalue;
  70        u16 index;
  71        u16 len;
  72        __le32 data;
  73        struct intf_priv *intfpriv = intfhdl->pintfpriv;
  74
  75        request = 0x05;
  76        requesttype = 0x01; /* read_in */
  77        index = 0;
  78        wvalue = (u16)(addr & 0x0000ffff);
  79        len = 4;
  80        r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
  81                                requesttype);
  82        return le32_to_cpu(data);
  83}
  84
  85static void usb_write8(struct intf_hdl *intfhdl, u32 addr, u8 val)
  86{
  87        u8 request;
  88        u8 requesttype;
  89        u16 wvalue;
  90        u16 index;
  91        u16 len;
  92        __le32 data;
  93        struct intf_priv *intfpriv = intfhdl->pintfpriv;
  94
  95        request = 0x05;
  96        requesttype = 0x00; /* write_out */
  97        index = 0;
  98        wvalue = (u16)(addr & 0x0000ffff);
  99        len = 1;
 100        data = cpu_to_le32((u32)val & 0x000000ff);
 101        r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
 102                                requesttype);
 103}
 104
 105static void usb_write16(struct intf_hdl *intfhdl, u32 addr, u16 val)
 106{
 107        u8 request;
 108        u8 requesttype;
 109        u16 wvalue;
 110        u16 index;
 111        u16 len;
 112        __le32 data;
 113        struct intf_priv *intfpriv = intfhdl->pintfpriv;
 114
 115        request = 0x05;
 116        requesttype = 0x00; /* write_out */
 117        index = 0;
 118        wvalue = (u16)(addr & 0x0000ffff);
 119        len = 2;
 120        data = cpu_to_le32((u32)val & 0x0000ffff);
 121        r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
 122                                requesttype);
 123}
 124
 125static void usb_write32(struct intf_hdl *intfhdl, u32 addr, u32 val)
 126{
 127        u8 request;
 128        u8 requesttype;
 129        u16 wvalue;
 130        u16 index;
 131        u16 len;
 132        __le32 data;
 133        struct intf_priv *intfpriv = intfhdl->pintfpriv;
 134
 135        request = 0x05;
 136        requesttype = 0x00; /* write_out */
 137        index = 0;
 138        wvalue = (u16)(addr & 0x0000ffff);
 139        len = 4;
 140        data = cpu_to_le32(val);
 141        r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
 142                                requesttype);
 143}
 144
 145void r8712_usb_set_intf_option(u32 *option)
 146{
 147        *option = ((*option) | _INTF_ASYNC_);
 148}
 149
 150static void usb_intf_hdl_init(u8 *priv)
 151{
 152}
 153
 154static void usb_intf_hdl_unload(u8 *priv)
 155{
 156}
 157
 158static void usb_intf_hdl_open(u8 *priv)
 159{
 160}
 161
 162static void usb_intf_hdl_close(u8 *priv)
 163{
 164}
 165
 166void r8712_usb_set_intf_funs(struct intf_hdl *intfhdl)
 167{
 168        intfhdl->intf_hdl_init = usb_intf_hdl_init;
 169        intfhdl->intf_hdl_unload = usb_intf_hdl_unload;
 170        intfhdl->intf_hdl_open = usb_intf_hdl_open;
 171        intfhdl->intf_hdl_close = usb_intf_hdl_close;
 172}
 173
 174void r8712_usb_set_intf_ops(struct _io_ops *ops)
 175{
 176        memset((u8 *)ops, 0, sizeof(struct _io_ops));
 177        ops->_read8 = usb_read8;
 178        ops->_read16 = usb_read16;
 179        ops->_read32 = usb_read32;
 180        ops->_read_port = r8712_usb_read_port;
 181        ops->_write8 = usb_write8;
 182        ops->_write16 = usb_write16;
 183        ops->_write32 = usb_write32;
 184        ops->_write_mem = r8712_usb_write_mem;
 185        ops->_write_port = r8712_usb_write_port;
 186}
 187