Skip to content

Commit 14295a1

Browse files
Chunfeng Yungregkh
authored andcommitted
usb: xhci-mtk: support to build xhci-mtk-hcd.ko
Currently xhci-hcd.ko building depends on USB_XHCI_MTK, this is not flexible for some cases. For example: USB_XHCI_HCD is y, and USB_XHCI_MTK is m, then we can't implement extended functions if only update xhci-mtk.ko This patch is used to remove the dependence. Acked-by: Mathias Nyman <[email protected]> Signed-off-by: Chunfeng Yun <[email protected]> Link: https://lore.kernel.org/r/0b62e21ddfacc1c2874726dd27ccab80c993f303.1615170625.git.chunfeng.yun@mediatek.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent dc9d3b2 commit 14295a1

File tree

8 files changed

+64
-66
lines changed

8 files changed

+64
-66
lines changed

drivers/usb/host/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ ifneq ($(CONFIG_USB_XHCI_DBGCAP), )
1919
xhci-hcd-y += xhci-dbgcap.o xhci-dbgtty.o
2020
endif
2121

22-
ifneq ($(CONFIG_USB_XHCI_MTK), )
23-
xhci-hcd-y += xhci-mtk-sch.o
24-
endif
22+
xhci-mtk-hcd-y := xhci-mtk.o xhci-mtk-sch.o
2523

2624
xhci-plat-hcd-y := xhci-plat.o
2725
ifneq ($(CONFIG_USB_XHCI_MVEBU), )
@@ -73,7 +71,7 @@ obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
7371
obj-$(CONFIG_USB_XHCI_PCI_RENESAS) += xhci-pci-renesas.o
7472
obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
7573
obj-$(CONFIG_USB_XHCI_HISTB) += xhci-histb.o
76-
obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
74+
obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk-hcd.o
7775
obj-$(CONFIG_USB_XHCI_TEGRA) += xhci-tegra.o
7876
obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
7977
obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o

drivers/usb/host/xhci-mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
532532
return (struct xhci_ep_ctx *)
533533
(ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
534534
}
535-
535+
EXPORT_SYMBOL_GPL(xhci_get_ep_ctx);
536536

537537
/***************** Streams structures manipulation *************************/
538538

drivers/usb/host/xhci-mtk-sch.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -691,25 +691,22 @@ int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
691691

692692
return 0;
693693
}
694-
EXPORT_SYMBOL_GPL(xhci_mtk_sch_init);
695694

696695
void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk)
697696
{
698697
kfree(mtk->sch_array);
699698
}
700-
EXPORT_SYMBOL_GPL(xhci_mtk_sch_exit);
701699

702-
int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
703-
struct usb_host_endpoint *ep)
700+
static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
701+
struct usb_host_endpoint *ep)
704702
{
705703
struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
706-
struct xhci_hcd *xhci;
704+
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
707705
struct xhci_ep_ctx *ep_ctx;
708706
struct xhci_virt_device *virt_dev;
709707
struct mu3h_sch_ep_info *sch_ep;
710708
unsigned int ep_index;
711709

712-
xhci = hcd_to_xhci(hcd);
713710
virt_dev = xhci->devs[udev->slot_id];
714711
ep_index = xhci_get_endpoint_index(&ep->desc);
715712
ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
@@ -741,18 +738,16 @@ int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
741738

742739
return 0;
743740
}
744-
EXPORT_SYMBOL_GPL(xhci_mtk_add_ep_quirk);
745741

746-
void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
747-
struct usb_host_endpoint *ep)
742+
static void drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
743+
struct usb_host_endpoint *ep)
748744
{
749745
struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
750-
struct xhci_hcd *xhci;
746+
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
751747
struct xhci_virt_device *virt_dev;
752748
struct mu3h_sch_bw_info *sch_bw;
753749
struct mu3h_sch_ep_info *sch_ep, *tmp;
754750

755-
xhci = hcd_to_xhci(hcd);
756751
virt_dev = xhci->devs[udev->slot_id];
757752

758753
xhci_dbg(xhci, "%s() type:%d, speed:%d, mpks:%d, dir:%d, ep:%p\n",
@@ -772,7 +767,6 @@ void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
772767
}
773768
}
774769
}
775-
EXPORT_SYMBOL_GPL(xhci_mtk_drop_ep_quirk);
776770

777771
int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
778772
{
@@ -818,7 +812,6 @@ int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
818812

819813
return xhci_check_bandwidth(hcd, udev);
820814
}
821-
EXPORT_SYMBOL_GPL(xhci_mtk_check_bandwidth);
822815

823816
void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
824817
{
@@ -836,4 +829,31 @@ void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
836829

837830
xhci_reset_bandwidth(hcd, udev);
838831
}
839-
EXPORT_SYMBOL_GPL(xhci_mtk_reset_bandwidth);
832+
833+
int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
834+
struct usb_host_endpoint *ep)
835+
{
836+
int ret;
837+
838+
ret = xhci_add_endpoint(hcd, udev, ep);
839+
if (ret)
840+
return ret;
841+
842+
if (ep->hcpriv)
843+
ret = add_ep_quirk(hcd, udev, ep);
844+
845+
return ret;
846+
}
847+
848+
int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
849+
struct usb_host_endpoint *ep)
850+
{
851+
int ret;
852+
853+
ret = xhci_drop_endpoint(hcd, udev, ep);
854+
if (ret)
855+
return ret;
856+
857+
drop_ep_quirk(hcd, udev, ep);
858+
return 0;
859+
}

drivers/usb/host/xhci-mtk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ static int xhci_mtk_setup(struct usb_hcd *hcd)
417417

418418
static const struct xhci_driver_overrides xhci_mtk_overrides __initconst = {
419419
.reset = xhci_mtk_setup,
420+
.add_endpoint = xhci_mtk_add_ep,
421+
.drop_endpoint = xhci_mtk_drop_ep,
420422
.check_bandwidth = xhci_mtk_check_bandwidth,
421423
.reset_bandwidth = xhci_mtk_reset_bandwidth,
422424
};

drivers/usb/host/xhci-mtk.h

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -161,38 +161,13 @@ static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
161161
return dev_get_drvdata(hcd->self.controller);
162162
}
163163

164-
#if IS_ENABLED(CONFIG_USB_XHCI_MTK)
165164
int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
166165
void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
167-
int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
168-
struct usb_host_endpoint *ep);
169-
void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
170-
struct usb_host_endpoint *ep);
166+
int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
167+
struct usb_host_endpoint *ep);
168+
int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
169+
struct usb_host_endpoint *ep);
171170
int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
172171
void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
173172

174-
#else
175-
static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd,
176-
struct usb_device *udev, struct usb_host_endpoint *ep)
177-
{
178-
return 0;
179-
}
180-
181-
static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd,
182-
struct usb_device *udev, struct usb_host_endpoint *ep)
183-
{
184-
}
185-
186-
static inline int xhci_mtk_check_bandwidth(struct usb_hcd *hcd,
187-
struct usb_device *udev)
188-
{
189-
return 0;
190-
}
191-
192-
static inline void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd,
193-
struct usb_device *udev)
194-
{
195-
}
196-
#endif
197-
198173
#endif /* _XHCI_MTK_H_ */

drivers/usb/host/xhci-ring.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include <linux/dma-mapping.h>
5858
#include "xhci.h"
5959
#include "xhci-trace.h"
60-
#include "xhci-mtk.h"
6160

6261
static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
6362
u32 field1, u32 field2,

drivers/usb/host/xhci.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "xhci.h"
2222
#include "xhci-trace.h"
23-
#include "xhci-mtk.h"
2423
#include "xhci-debugfs.h"
2524
#include "xhci-dbgcap.h"
2625

@@ -1420,6 +1419,7 @@ unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc)
14201419
(usb_endpoint_dir_in(desc) ? 1 : 0) - 1;
14211420
return index;
14221421
}
1422+
EXPORT_SYMBOL_GPL(xhci_get_endpoint_index);
14231423

14241424
/* The reverse operation to xhci_get_endpoint_index. Calculate the USB endpoint
14251425
* address from the XHCI endpoint index.
@@ -1852,8 +1852,8 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
18521852
* disabled, so there's no need for mutual exclusion to protect
18531853
* the xhci->devs[slot_id] structure.
18541854
*/
1855-
static int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1856-
struct usb_host_endpoint *ep)
1855+
int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1856+
struct usb_host_endpoint *ep)
18571857
{
18581858
struct xhci_hcd *xhci;
18591859
struct xhci_container_ctx *in_ctx, *out_ctx;
@@ -1913,16 +1913,14 @@ static int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
19131913

19141914
xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
19151915

1916-
if (xhci->quirks & XHCI_MTK_HOST)
1917-
xhci_mtk_drop_ep_quirk(hcd, udev, ep);
1918-
19191916
xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n",
19201917
(unsigned int) ep->desc.bEndpointAddress,
19211918
udev->slot_id,
19221919
(unsigned int) new_drop_flags,
19231920
(unsigned int) new_add_flags);
19241921
return 0;
19251922
}
1923+
EXPORT_SYMBOL_GPL(xhci_drop_endpoint);
19261924

19271925
/* Add an endpoint to a new possible bandwidth configuration for this device.
19281926
* Only one call to this function is allowed per endpoint before
@@ -1937,8 +1935,8 @@ static int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
19371935
* configuration or alt setting is installed in the device, so there's no need
19381936
* for mutual exclusion to protect the xhci->devs[slot_id] structure.
19391937
*/
1940-
static int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1941-
struct usb_host_endpoint *ep)
1938+
int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1939+
struct usb_host_endpoint *ep)
19421940
{
19431941
struct xhci_hcd *xhci;
19441942
struct xhci_container_ctx *in_ctx;
@@ -2012,15 +2010,6 @@ static int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
20122010
return -ENOMEM;
20132011
}
20142012

2015-
if (xhci->quirks & XHCI_MTK_HOST) {
2016-
ret = xhci_mtk_add_ep_quirk(hcd, udev, ep);
2017-
if (ret < 0) {
2018-
xhci_ring_free(xhci, virt_dev->eps[ep_index].new_ring);
2019-
virt_dev->eps[ep_index].new_ring = NULL;
2020-
return ret;
2021-
}
2022-
}
2023-
20242013
ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs);
20252014
new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
20262015

@@ -2045,6 +2034,7 @@ static int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
20452034
(unsigned int) new_add_flags);
20462035
return 0;
20472036
}
2037+
EXPORT_SYMBOL_GPL(xhci_add_endpoint);
20482038

20492039
static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev)
20502040
{
@@ -3078,6 +3068,7 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
30783068

30793069
return ret;
30803070
}
3071+
EXPORT_SYMBOL_GPL(xhci_check_bandwidth);
30813072

30823073
void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
30833074
{
@@ -3102,6 +3093,7 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
31023093
}
31033094
xhci_zero_in_ctx(xhci, virt_dev);
31043095
}
3096+
EXPORT_SYMBOL_GPL(xhci_reset_bandwidth);
31053097

31063098
static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci,
31073099
struct xhci_container_ctx *in_ctx,
@@ -5428,6 +5420,10 @@ void xhci_init_driver(struct hc_driver *drv,
54285420
drv->reset = over->reset;
54295421
if (over->start)
54305422
drv->start = over->start;
5423+
if (over->add_endpoint)
5424+
drv->add_endpoint = over->add_endpoint;
5425+
if (over->drop_endpoint)
5426+
drv->drop_endpoint = over->drop_endpoint;
54315427
if (over->check_bandwidth)
54325428
drv->check_bandwidth = over->check_bandwidth;
54335429
if (over->reset_bandwidth)

drivers/usb/host/xhci.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,10 @@ struct xhci_driver_overrides {
19281928
size_t extra_priv_size;
19291929
int (*reset)(struct usb_hcd *hcd);
19301930
int (*start)(struct usb_hcd *hcd);
1931+
int (*add_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1932+
struct usb_host_endpoint *ep);
1933+
int (*drop_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1934+
struct usb_host_endpoint *ep);
19311935
int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);
19321936
void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
19331937
};
@@ -2080,6 +2084,10 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
20802084
void xhci_shutdown(struct usb_hcd *hcd);
20812085
void xhci_init_driver(struct hc_driver *drv,
20822086
const struct xhci_driver_overrides *over);
2087+
int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2088+
struct usb_host_endpoint *ep);
2089+
int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2090+
struct usb_host_endpoint *ep);
20832091
int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
20842092
void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
20852093
int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);

0 commit comments

Comments
 (0)