aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3/gadget.c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2012-01-18 11:04:09 -0500
committerFelipe Balbi <balbi@ti.com>2012-02-06 04:48:34 -0500
commit457e84b6624b4d97e6ffae437887ea51a22d54a0 (patch)
treee1ca1503cdda97570fa692589e44a1ca43e72d8b /drivers/usb/dwc3/gadget.c
parentbb5cfd6811c63c47403e98028bde7e98bd7a1751 (diff)
usb: dwc3: gadget: dynamically re-size TxFifos
We need to dynamically re-size TxFifos for the cases where default values will not do. While at that, we create a simple function which, for now, will just allocate one full packet fifo space for each of the enabled endpoints. This can be improved later in order to allow for better throughput by allocating more space for endpoints which could make good use of that like isochronous and bulk. Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3/gadget.c')
-rw-r--r--drivers/usb/dwc3/gadget.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index d406a75456a0..7913d1b50e38 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -125,6 +125,80 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
125 return -ETIMEDOUT; 125 return -ETIMEDOUT;
126} 126}
127 127
128/**
129 * dwc3_gadget_resize_tx_fifos - reallocate fifo spaces for current use-case
130 * @dwc: pointer to our context structure
131 *
132 * This function will a best effort FIFO allocation in order
133 * to improve FIFO usage and throughput, while still allowing
134 * us to enable as many endpoints as possible.
135 *
136 * Keep in mind that this operation will be highly dependent
137 * on the configured size for RAM1 - which contains TxFifo -,
138 * the amount of endpoints enabled on coreConsultant tool, and
139 * the width of the Master Bus.
140 *
141 * In the ideal world, we would always be able to satisfy the
142 * following equation:
143 *
144 * ((512 + 2 * MDWIDTH-Bytes) + (Number of IN Endpoints - 1) * \
145 * (3 * (1024 + MDWIDTH-Bytes) + MDWIDTH-Bytes)) / MDWIDTH-Bytes
146 *
147 * Unfortunately, due to many variables that's not always the case.
148 */
149int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
150{
151 int last_fifo_depth = 0;
152 int ram1_depth;
153 int fifo_size;
154 int mdwidth;
155 int num;
156
157 if (!dwc->needs_fifo_resize)
158 return 0;
159
160 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7);
161 mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
162
163 /* MDWIDTH is represented in bits, we need it in bytes */
164 mdwidth >>= 3;
165
166 /*
167 * FIXME For now we will only allocate 1 wMaxPacketSize space
168 * for each enabled endpoint, later patches will come to
169 * improve this algorithm so that we better use the internal
170 * FIFO space
171 */
172 for (num = 0; num < DWC3_ENDPOINTS_NUM; num++) {
173 struct dwc3_ep *dep = dwc->eps[num];
174 int fifo_number = dep->number >> 1;
175 int tmp;
176
177 if (!(dep->number & 1))
178 continue;
179
180 if (!(dep->flags & DWC3_EP_ENABLED))
181 continue;
182
183 tmp = dep->endpoint.maxpacket;
184 tmp += mdwidth;
185 tmp += mdwidth;
186
187 fifo_size = DIV_ROUND_UP(tmp, mdwidth);
188 fifo_size |= (last_fifo_depth << 16);
189
190 dev_vdbg(dwc->dev, "%s: Fifo Addr %04x Size %d\n",
191 dep->name, last_fifo_depth, fifo_size & 0xffff);
192
193 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(fifo_number),
194 fifo_size);
195
196 last_fifo_depth += (fifo_size & 0xffff);
197 }
198
199 return 0;
200}
201
128void dwc3_map_buffer_to_dma(struct dwc3_request *req) 202void dwc3_map_buffer_to_dma(struct dwc3_request *req)
129{ 203{
130 struct dwc3 *dwc = req->dep->dwc; 204 struct dwc3 *dwc = req->dep->dwc;