1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ISP1760_HCD_H_
3 #define _ISP1760_HCD_H_
4 
5 #include <linux/spinlock.h>
6 #include <linux/regmap.h>
7 
8 #include "isp1760-regs.h"
9 
10 struct isp1760_qh;
11 struct isp1760_qtd;
12 struct resource;
13 struct usb_hcd;
14 
15 struct isp1760_slotinfo {
16 	struct isp1760_qh *qh;
17 	struct isp1760_qtd *qtd;
18 	unsigned long timestamp;
19 };
20 
21 /* chip memory management */
22 #define ISP176x_BLOCK_MAX (32 + 20 + 4)
23 #define ISP176x_BLOCK_NUM 3
24 
25 struct isp1760_memory_layout {
26 	unsigned int blocks[ISP176x_BLOCK_NUM];
27 	unsigned int blocks_size[ISP176x_BLOCK_NUM];
28 
29 	unsigned int slot_num;
30 	unsigned int payload_blocks;
31 	unsigned int payload_area_size;
32 };
33 
34 struct isp1760_memory_chunk {
35 	unsigned int start;
36 	unsigned int size;
37 	unsigned int free;
38 };
39 
40 enum isp1760_queue_head_types {
41 	QH_CONTROL,
42 	QH_BULK,
43 	QH_INTERRUPT,
44 	QH_END
45 };
46 
47 struct isp1760_hcd {
48 	struct usb_hcd		*hcd;
49 
50 	void __iomem		*base;
51 
52 	struct regmap		*regs;
53 	struct regmap_field	*fields[HC_FIELD_MAX];
54 
55 	bool			is_isp1763;
56 	const struct isp1760_memory_layout	*memory_layout;
57 
58 	spinlock_t		lock;
59 	struct isp1760_slotinfo	*atl_slots;
60 	int			atl_done_map;
61 	struct isp1760_slotinfo	*int_slots;
62 	int			int_done_map;
63 	struct isp1760_memory_chunk memory_pool[ISP176x_BLOCK_MAX];
64 	struct list_head	qh_list[QH_END];
65 
66 	/* periodic schedule support */
67 #define	DEFAULT_I_TDPS		1024
68 	unsigned		periodic_size;
69 	unsigned		i_thresh;
70 	unsigned long		reset_done;
71 	unsigned long		next_statechange;
72 };
73 
74 #ifdef CONFIG_USB_ISP1760_HCD
75 int isp1760_hcd_register(struct isp1760_hcd *priv, struct resource *mem,
76 			 int irq, unsigned long irqflags, struct device *dev);
77 void isp1760_hcd_unregister(struct isp1760_hcd *priv);
78 
79 int isp1760_init_kmem_once(void);
80 void isp1760_deinit_kmem_cache(void);
81 #else
isp1760_hcd_register(struct isp1760_hcd * priv,struct resource * mem,int irq,unsigned long irqflags,struct device * dev)82 static inline int isp1760_hcd_register(struct isp1760_hcd *priv,
83 				       struct resource *mem,
84 				       int irq, unsigned long irqflags,
85 				       struct device *dev)
86 {
87 	return 0;
88 }
89 
isp1760_hcd_unregister(struct isp1760_hcd * priv)90 static inline void isp1760_hcd_unregister(struct isp1760_hcd *priv)
91 {
92 }
93 
isp1760_init_kmem_once(void)94 static inline int isp1760_init_kmem_once(void)
95 {
96 	return 0;
97 }
98 
isp1760_deinit_kmem_cache(void)99 static inline void isp1760_deinit_kmem_cache(void)
100 {
101 }
102 #endif
103 
104 #endif /* _ISP1760_HCD_H_ */
105