Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (c) 2021 pureLiFi
0004  */
0005 
0006 #include <linux/kernel.h>
0007 #include <linux/errno.h>
0008 
0009 #include "chip.h"
0010 #include "mac.h"
0011 #include "usb.h"
0012 
0013 void plfxlc_chip_init(struct plfxlc_chip *chip,
0014               struct ieee80211_hw *hw,
0015               struct usb_interface *intf)
0016 {
0017     memset(chip, 0, sizeof(*chip));
0018     mutex_init(&chip->mutex);
0019     plfxlc_usb_init(&chip->usb, hw, intf);
0020 }
0021 
0022 void plfxlc_chip_release(struct plfxlc_chip *chip)
0023 {
0024     plfxlc_usb_release(&chip->usb);
0025     mutex_destroy(&chip->mutex);
0026 }
0027 
0028 int plfxlc_set_beacon_interval(struct plfxlc_chip *chip, u16 interval,
0029                    u8 dtim_period, int type)
0030 {
0031     if (!interval ||
0032         (chip->beacon_set && chip->beacon_interval == interval))
0033         return 0;
0034 
0035     chip->beacon_interval = interval;
0036     chip->beacon_set = true;
0037     return plfxlc_usb_wreq(chip->usb.ez_usb,
0038                    &chip->beacon_interval,
0039                    sizeof(chip->beacon_interval),
0040                    USB_REQ_BEACON_INTERVAL_WR);
0041 }
0042 
0043 int plfxlc_chip_init_hw(struct plfxlc_chip *chip)
0044 {
0045     unsigned char *addr = plfxlc_mac_get_perm_addr(plfxlc_chip_to_mac(chip));
0046     struct usb_device *udev = interface_to_usbdev(chip->usb.intf);
0047 
0048     pr_info("plfxlc chip %04x:%04x v%02x %pM %s\n",
0049         le16_to_cpu(udev->descriptor.idVendor),
0050         le16_to_cpu(udev->descriptor.idProduct),
0051         le16_to_cpu(udev->descriptor.bcdDevice),
0052         addr,
0053         plfxlc_speed(udev->speed));
0054 
0055     return plfxlc_set_beacon_interval(chip, 100, 0, 0);
0056 }
0057 
0058 int plfxlc_chip_switch_radio(struct plfxlc_chip *chip, u16 value)
0059 {
0060     int r;
0061     __le16 radio_on = cpu_to_le16(value);
0062 
0063     r = plfxlc_usb_wreq(chip->usb.ez_usb, &radio_on,
0064                 sizeof(value), USB_REQ_POWER_WR);
0065     if (r)
0066         dev_err(plfxlc_chip_dev(chip), "POWER_WR failed (%d)\n", r);
0067     return r;
0068 }
0069 
0070 int plfxlc_chip_enable_rxtx(struct plfxlc_chip *chip)
0071 {
0072     plfxlc_usb_enable_tx(&chip->usb);
0073     return plfxlc_usb_enable_rx(&chip->usb);
0074 }
0075 
0076 void plfxlc_chip_disable_rxtx(struct plfxlc_chip *chip)
0077 {
0078     u8 value = 0;
0079 
0080     plfxlc_usb_wreq(chip->usb.ez_usb,
0081             &value, sizeof(value), USB_REQ_RXTX_WR);
0082     plfxlc_usb_disable_rx(&chip->usb);
0083     plfxlc_usb_disable_tx(&chip->usb);
0084 }
0085 
0086 int plfxlc_chip_set_rate(struct plfxlc_chip *chip, u8 rate)
0087 {
0088     int r;
0089 
0090     if (!chip)
0091         return -EINVAL;
0092 
0093     r = plfxlc_usb_wreq(chip->usb.ez_usb,
0094                 &rate, sizeof(rate), USB_REQ_RATE_WR);
0095     if (r)
0096         dev_err(plfxlc_chip_dev(chip), "RATE_WR failed (%d)\n", r);
0097     return r;
0098 }