shdma-base.c (eeca9fad52fc4bfdf42c38bfcf383e932eb3e9d6) shdma-base.c (ec5b103ecfde929004b691f29183255aeeadecd5)
1/*
2 * Dmaengine driver base library for DMA controllers, found on SH-based SoCs
3 *
4 * extracted from shdma.c
5 *
6 * Copyright (C) 2011-2012 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
7 * Copyright (C) 2009 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
8 * Copyright (C) 2009 Renesas Solutions, Inc. All rights reserved.

--- 157 unchanged lines hidden (view full) ---

166 BUG_ON(sdesc->mark != DESC_IDLE);
167 list_del(&sdesc->node);
168 return sdesc;
169 }
170
171 return NULL;
172}
173
1/*
2 * Dmaengine driver base library for DMA controllers, found on SH-based SoCs
3 *
4 * extracted from shdma.c
5 *
6 * Copyright (C) 2011-2012 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
7 * Copyright (C) 2009 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
8 * Copyright (C) 2009 Renesas Solutions, Inc. All rights reserved.

--- 157 unchanged lines hidden (view full) ---

166 BUG_ON(sdesc->mark != DESC_IDLE);
167 list_del(&sdesc->node);
168 return sdesc;
169 }
170
171 return NULL;
172}
173
174static int shdma_setup_slave(struct shdma_chan *schan, int slave_id)
174static int shdma_setup_slave(struct shdma_chan *schan, int slave_id,
175 dma_addr_t slave_addr)
175{
176 struct shdma_dev *sdev = to_shdma_dev(schan->dma_chan.device);
177 const struct shdma_ops *ops = sdev->ops;
178 int ret, match;
179
180 if (schan->dev->of_node) {
181 match = schan->hw_req;
176{
177 struct shdma_dev *sdev = to_shdma_dev(schan->dma_chan.device);
178 const struct shdma_ops *ops = sdev->ops;
179 int ret, match;
180
181 if (schan->dev->of_node) {
182 match = schan->hw_req;
182 ret = ops->set_slave(schan, match, true);
183 ret = ops->set_slave(schan, match, slave_addr, true);
183 if (ret < 0)
184 return ret;
185
186 slave_id = schan->slave_id;
187 } else {
188 match = slave_id;
189 }
190
191 if (slave_id < 0 || slave_id >= slave_num)
192 return -EINVAL;
193
194 if (test_and_set_bit(slave_id, shdma_slave_used))
195 return -EBUSY;
196
184 if (ret < 0)
185 return ret;
186
187 slave_id = schan->slave_id;
188 } else {
189 match = slave_id;
190 }
191
192 if (slave_id < 0 || slave_id >= slave_num)
193 return -EINVAL;
194
195 if (test_and_set_bit(slave_id, shdma_slave_used))
196 return -EBUSY;
197
197 ret = ops->set_slave(schan, match, false);
198 ret = ops->set_slave(schan, match, slave_addr, false);
198 if (ret < 0) {
199 clear_bit(slave_id, shdma_slave_used);
200 return ret;
201 }
202
203 schan->slave_id = slave_id;
204
205 return 0;

--- 25 unchanged lines hidden (view full) ---

231
232 if (match < 0)
233 /* No slave requested - arbitrary channel */
234 return true;
235
236 if (!schan->dev->of_node && match >= slave_num)
237 return false;
238
199 if (ret < 0) {
200 clear_bit(slave_id, shdma_slave_used);
201 return ret;
202 }
203
204 schan->slave_id = slave_id;
205
206 return 0;

--- 25 unchanged lines hidden (view full) ---

232
233 if (match < 0)
234 /* No slave requested - arbitrary channel */
235 return true;
236
237 if (!schan->dev->of_node && match >= slave_num)
238 return false;
239
239 ret = ops->set_slave(schan, match, true);
240 ret = ops->set_slave(schan, match, 0, true);
240 if (ret < 0)
241 return false;
242
243 return true;
244}
245EXPORT_SYMBOL(shdma_chan_filter);
246
247static int shdma_alloc_chan_resources(struct dma_chan *chan)

--- 6 unchanged lines hidden (view full) ---

254 int ret, i;
255
256 /*
257 * This relies on the guarantee from dmaengine that alloc_chan_resources
258 * never runs concurrently with itself or free_chan_resources.
259 */
260 if (slave) {
261 /* Legacy mode: .private is set in filter */
241 if (ret < 0)
242 return false;
243
244 return true;
245}
246EXPORT_SYMBOL(shdma_chan_filter);
247
248static int shdma_alloc_chan_resources(struct dma_chan *chan)

--- 6 unchanged lines hidden (view full) ---

255 int ret, i;
256
257 /*
258 * This relies on the guarantee from dmaengine that alloc_chan_resources
259 * never runs concurrently with itself or free_chan_resources.
260 */
261 if (slave) {
262 /* Legacy mode: .private is set in filter */
262 ret = shdma_setup_slave(schan, slave->slave_id);
263 ret = shdma_setup_slave(schan, slave->slave_id, 0);
263 if (ret < 0)
264 goto esetslave;
265 } else {
266 schan->slave_id = -EINVAL;
267 }
268
269 schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
270 sdev->desc_size, GFP_KERNEL);

--- 404 unchanged lines hidden (view full) ---

675 */
676 if (!arg)
677 return -EINVAL;
678 /*
679 * We could lock this, but you shouldn't be configuring the
680 * channel, while using it...
681 */
682 config = (struct dma_slave_config *)arg;
264 if (ret < 0)
265 goto esetslave;
266 } else {
267 schan->slave_id = -EINVAL;
268 }
269
270 schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
271 sdev->desc_size, GFP_KERNEL);

--- 404 unchanged lines hidden (view full) ---

676 */
677 if (!arg)
678 return -EINVAL;
679 /*
680 * We could lock this, but you shouldn't be configuring the
681 * channel, while using it...
682 */
683 config = (struct dma_slave_config *)arg;
683 ret = shdma_setup_slave(schan, config->slave_id);
684 ret = shdma_setup_slave(schan, config->slave_id,
685 config->direction == DMA_DEV_TO_MEM ?
686 config->src_addr : config->dst_addr);
684 if (ret < 0)
685 return ret;
686 break;
687 default:
688 return -ENXIO;
689 }
690
691 return 0;

--- 134 unchanged lines hidden (view full) ---

826 shdma_chan_ld_cleanup(schan, false);
827
828 return IRQ_HANDLED;
829}
830
831int shdma_request_irq(struct shdma_chan *schan, int irq,
832 unsigned long flags, const char *name)
833{
687 if (ret < 0)
688 return ret;
689 break;
690 default:
691 return -ENXIO;
692 }
693
694 return 0;

--- 134 unchanged lines hidden (view full) ---

829 shdma_chan_ld_cleanup(schan, false);
830
831 return IRQ_HANDLED;
832}
833
834int shdma_request_irq(struct shdma_chan *schan, int irq,
835 unsigned long flags, const char *name)
836{
834 int ret = request_threaded_irq(irq, chan_irq, chan_irqt,
835 flags, name, schan);
837 int ret = devm_request_threaded_irq(schan->dev, irq, chan_irq,
838 chan_irqt, flags, name, schan);
836
837 schan->irq = ret < 0 ? ret : irq;
838
839 return ret;
840}
841EXPORT_SYMBOL(shdma_request_irq);
842
839
840 schan->irq = ret < 0 ? ret : irq;
841
842 return ret;
843}
844EXPORT_SYMBOL(shdma_request_irq);
845
843void shdma_free_irq(struct shdma_chan *schan)
844{
845 if (schan->irq >= 0)
846 free_irq(schan->irq, schan);
847}
848EXPORT_SYMBOL(shdma_free_irq);
849
850void shdma_chan_probe(struct shdma_dev *sdev,
851 struct shdma_chan *schan, int id)
852{
853 schan->pm_state = SHDMA_PM_ESTABLISHED;
854
855 /* reference struct dma_device */
856 schan->dma_chan.device = &sdev->dma_dev;
857 dma_cookie_init(&schan->dma_chan);

--- 97 unchanged lines hidden ---
846void shdma_chan_probe(struct shdma_dev *sdev,
847 struct shdma_chan *schan, int id)
848{
849 schan->pm_state = SHDMA_PM_ESTABLISHED;
850
851 /* reference struct dma_device */
852 schan->dma_chan.device = &sdev->dma_dev;
853 dma_cookie_init(&schan->dma_chan);

--- 97 unchanged lines hidden ---