forked from openwrt/mt76
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mt76: usb: introduce __mt76u_init utility routine
Introduce __mt76u_init unitility routine and move mt7615 usb bus ops into mt7615 module in order to allow specifying driver specific parameter. This is a preliminary patch to add usb support to mt7921 driver. Tested-by: Sean Wang <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
- Loading branch information
1 parent
74a519a
commit 2651d2c
Showing
5 changed files
with
110 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,8 @@ static bool disable_usb_sg; | |
module_param_named(disable_usb_sg, disable_usb_sg, bool, 0644); | ||
MODULE_PARM_DESC(disable_usb_sg, "Disable usb scatter-gather support"); | ||
|
||
static int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, | ||
u8 req_type, u16 val, u16 offset, | ||
void *buf, size_t len) | ||
int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type, | ||
u16 val, u16 offset, void *buf, size_t len) | ||
{ | ||
struct usb_interface *uintf = to_usb_interface(dev->dev); | ||
struct usb_device *udev = interface_to_usbdev(uintf); | ||
|
@@ -45,6 +44,7 @@ static int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, | |
req, offset, ret); | ||
return ret; | ||
} | ||
EXPORT_SYMBOL_GPL(__mt76u_vendor_request); | ||
|
||
int mt76u_vendor_request(struct mt76_dev *dev, u8 req, | ||
u8 req_type, u16 val, u16 offset, | ||
|
@@ -62,8 +62,7 @@ int mt76u_vendor_request(struct mt76_dev *dev, u8 req, | |
} | ||
EXPORT_SYMBOL_GPL(mt76u_vendor_request); | ||
|
||
static u32 ___mt76u_rr(struct mt76_dev *dev, u8 req, u8 req_type, | ||
u32 addr) | ||
u32 ___mt76u_rr(struct mt76_dev *dev, u8 req, u8 req_type, u32 addr) | ||
{ | ||
struct mt76_usb *usb = &dev->usb; | ||
u32 data = ~0; | ||
|
@@ -77,6 +76,7 @@ static u32 ___mt76u_rr(struct mt76_dev *dev, u8 req, u8 req_type, | |
|
||
return data; | ||
} | ||
EXPORT_SYMBOL_GPL(___mt76u_rr); | ||
|
||
static u32 __mt76u_rr(struct mt76_dev *dev, u32 addr) | ||
{ | ||
|
@@ -109,20 +109,8 @@ static u32 mt76u_rr(struct mt76_dev *dev, u32 addr) | |
return ret; | ||
} | ||
|
||
static u32 mt76u_rr_ext(struct mt76_dev *dev, u32 addr) | ||
{ | ||
u32 ret; | ||
|
||
mutex_lock(&dev->usb.usb_ctrl_mtx); | ||
ret = ___mt76u_rr(dev, MT_VEND_READ_EXT, | ||
USB_DIR_IN | USB_TYPE_VENDOR, addr); | ||
mutex_unlock(&dev->usb.usb_ctrl_mtx); | ||
|
||
return ret; | ||
} | ||
|
||
static void ___mt76u_wr(struct mt76_dev *dev, u8 req, u8 req_type, | ||
u32 addr, u32 val) | ||
void ___mt76u_wr(struct mt76_dev *dev, u8 req, u8 req_type, | ||
u32 addr, u32 val) | ||
{ | ||
struct mt76_usb *usb = &dev->usb; | ||
|
||
|
@@ -131,6 +119,7 @@ static void ___mt76u_wr(struct mt76_dev *dev, u8 req, u8 req_type, | |
addr, usb->data, sizeof(__le32)); | ||
trace_usb_reg_wr(dev, addr, val); | ||
} | ||
EXPORT_SYMBOL_GPL(___mt76u_wr); | ||
|
||
static void __mt76u_wr(struct mt76_dev *dev, u32 addr, u32 val) | ||
{ | ||
|
@@ -155,14 +144,6 @@ static void mt76u_wr(struct mt76_dev *dev, u32 addr, u32 val) | |
mutex_unlock(&dev->usb.usb_ctrl_mtx); | ||
} | ||
|
||
static void mt76u_wr_ext(struct mt76_dev *dev, u32 addr, u32 val) | ||
{ | ||
mutex_lock(&dev->usb.usb_ctrl_mtx); | ||
___mt76u_wr(dev, MT_VEND_WRITE_EXT, | ||
USB_DIR_OUT | USB_TYPE_VENDOR, addr, val); | ||
mutex_unlock(&dev->usb.usb_ctrl_mtx); | ||
} | ||
|
||
static u32 mt76u_rmw(struct mt76_dev *dev, u32 addr, | ||
u32 mask, u32 val) | ||
{ | ||
|
@@ -174,19 +155,6 @@ static u32 mt76u_rmw(struct mt76_dev *dev, u32 addr, | |
return val; | ||
} | ||
|
||
static u32 mt76u_rmw_ext(struct mt76_dev *dev, u32 addr, | ||
u32 mask, u32 val) | ||
{ | ||
mutex_lock(&dev->usb.usb_ctrl_mtx); | ||
val |= ___mt76u_rr(dev, MT_VEND_READ_EXT, | ||
USB_DIR_IN | USB_TYPE_VENDOR, addr) & ~mask; | ||
___mt76u_wr(dev, MT_VEND_WRITE_EXT, | ||
USB_DIR_OUT | USB_TYPE_VENDOR, addr, val); | ||
mutex_unlock(&dev->usb.usb_ctrl_mtx); | ||
|
||
return val; | ||
} | ||
|
||
static void mt76u_copy(struct mt76_dev *dev, u32 offset, | ||
const void *data, int len) | ||
{ | ||
|
@@ -219,33 +187,8 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset, | |
mutex_unlock(&usb->usb_ctrl_mtx); | ||
} | ||
|
||
static void mt76u_copy_ext(struct mt76_dev *dev, u32 offset, | ||
const void *data, int len) | ||
{ | ||
struct mt76_usb *usb = &dev->usb; | ||
int ret, i = 0, batch_len; | ||
const u8 *val = data; | ||
|
||
len = round_up(len, 4); | ||
mutex_lock(&usb->usb_ctrl_mtx); | ||
while (i < len) { | ||
batch_len = min_t(int, usb->data_len, len - i); | ||
memcpy(usb->data, val + i, batch_len); | ||
ret = __mt76u_vendor_request(dev, MT_VEND_WRITE_EXT, | ||
USB_DIR_OUT | USB_TYPE_VENDOR, | ||
(offset + i) >> 16, offset + i, | ||
usb->data, batch_len); | ||
if (ret < 0) | ||
break; | ||
|
||
i += batch_len; | ||
} | ||
mutex_unlock(&usb->usb_ctrl_mtx); | ||
} | ||
|
||
static void | ||
mt76u_read_copy_ext(struct mt76_dev *dev, u32 offset, | ||
void *data, int len) | ||
void mt76u_read_copy(struct mt76_dev *dev, u32 offset, | ||
void *data, int len) | ||
{ | ||
struct mt76_usb *usb = &dev->usb; | ||
int i = 0, batch_len, ret; | ||
|
@@ -267,6 +210,7 @@ mt76u_read_copy_ext(struct mt76_dev *dev, u32 offset, | |
} | ||
mutex_unlock(&usb->usb_ctrl_mtx); | ||
} | ||
EXPORT_SYMBOL_GPL(mt76u_read_copy); | ||
|
||
void mt76u_single_wr(struct mt76_dev *dev, const u8 req, | ||
const u16 offset, const u32 val) | ||
|
@@ -1115,24 +1059,13 @@ static const struct mt76_queue_ops usb_queue_ops = { | |
.kick = mt76u_tx_kick, | ||
}; | ||
|
||
int mt76u_init(struct mt76_dev *dev, | ||
struct usb_interface *intf, bool ext) | ||
int __mt76u_init(struct mt76_dev *dev, struct usb_interface *intf, | ||
struct mt76_bus_ops *ops) | ||
{ | ||
static struct mt76_bus_ops mt76u_ops = { | ||
.read_copy = mt76u_read_copy_ext, | ||
.wr_rp = mt76u_wr_rp, | ||
.rd_rp = mt76u_rd_rp, | ||
.type = MT76_BUS_USB, | ||
}; | ||
struct usb_device *udev = interface_to_usbdev(intf); | ||
struct mt76_usb *usb = &dev->usb; | ||
int err; | ||
|
||
mt76u_ops.rr = ext ? mt76u_rr_ext : mt76u_rr; | ||
mt76u_ops.wr = ext ? mt76u_wr_ext : mt76u_wr; | ||
mt76u_ops.rmw = ext ? mt76u_rmw_ext : mt76u_rmw; | ||
mt76u_ops.write_copy = ext ? mt76u_copy_ext : mt76u_copy; | ||
|
||
INIT_WORK(&usb->stat_work, mt76u_tx_status_data); | ||
|
||
usb->data_len = usb_maxpacket(udev, usb_sndctrlpipe(udev, 0), 1); | ||
|
@@ -1144,7 +1077,7 @@ int mt76u_init(struct mt76_dev *dev, | |
return -ENOMEM; | ||
|
||
mutex_init(&usb->usb_ctrl_mtx); | ||
dev->bus = &mt76u_ops; | ||
dev->bus = ops; | ||
dev->queue_ops = &usb_queue_ops; | ||
|
||
dev_set_drvdata(&udev->dev, dev); | ||
|
@@ -1170,6 +1103,23 @@ int mt76u_init(struct mt76_dev *dev, | |
|
||
return 0; | ||
} | ||
EXPORT_SYMBOL_GPL(__mt76u_init); | ||
|
||
int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf) | ||
{ | ||
static struct mt76_bus_ops bus_ops = { | ||
.rr = mt76u_rr, | ||
.wr = mt76u_wr, | ||
.rmw = mt76u_rmw, | ||
.read_copy = mt76u_read_copy, | ||
.write_copy = mt76u_copy, | ||
.wr_rp = mt76u_wr_rp, | ||
.rd_rp = mt76u_rd_rp, | ||
.type = MT76_BUS_USB, | ||
}; | ||
|
||
return __mt76u_init(dev, intf, &bus_ops); | ||
} | ||
EXPORT_SYMBOL_GPL(mt76u_init); | ||
|
||
MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>"); | ||
|