···6666 * after the final transfer signalled by LBREQ or LSREQ. The DMAC6767 * will then move to the next LLI entry.6868 *6969- * Only the former works sanely with scatter lists, so we only implement7070- * the DMAC flow control method. However, peripherals which use the LBREQ7171- * and LSREQ signals (eg, MMCI) are unable to use this mode, which through7272- * these hardware restrictions prevents them from using scatter DMA.7373- *7469 * Global TODO:7570 * - Break out common code from arch/arm/mach-s3c64xx and share7671 */7777-#include <linux/device.h>7878-#include <linux/init.h>7979-#include <linux/module.h>8080-#include <linux/interrupt.h>8181-#include <linux/slab.h>8282-#include <linux/delay.h>8383-#include <linux/dma-mapping.h>8484-#include <linux/dmapool.h>8585-#include <linux/dmaengine.h>8672#include <linux/amba/bus.h>8773#include <linux/amba/pl08x.h>8874#include <linux/debugfs.h>7575+#include <linux/delay.h>7676+#include <linux/device.h>7777+#include <linux/dmaengine.h>7878+#include <linux/dmapool.h>7979+#include <linux/dma-mapping.h>8080+#include <linux/init.h>8181+#include <linux/interrupt.h>8282+#include <linux/module.h>8383+#include <linux/pm_runtime.h>8984#include <linux/seq_file.h>9090-8585+#include <linux/slab.h>9186#include <asm/hardware/pl080.h>92879388#define DRIVER_NAME "pl08xdmac"···121126 * @phy_chans: array of data for the physical channels122127 * @pool: a pool for the LLI descriptors123128 * @pool_ctr: counter of LLIs in the pool124124- * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI fetches129129+ * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI130130+ * fetches125131 * @mem_buses: set to indicate memory transfers on AHB2.126132 * @lock: a spinlock for this struct127133 */···144148/*145149 * PL08X specific defines146150 */147147-148148-/*149149- * Memory boundaries: the manual for PL08x says that the controller150150- * cannot read past a 1KiB boundary, so these defines are used to151151- * create transfer LLIs that do not cross such boundaries.152152- */153153-#define PL08X_BOUNDARY_SHIFT (10) /* 1KB 0x400 */154154-#define PL08X_BOUNDARY_SIZE (1 << PL08X_BOUNDARY_SHIFT)155151156152/* Size (bytes) of each LLI buffer allocated for one transfer */157153# define PL08X_LLI_TSFR_SIZE 0x2000···259271 val &= ~PL080_CONFIG_HALT;260272 writel(val, ch->base + PL080_CH_CONFIG);261273}262262-263274264275/*265276 * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and···394407 return NULL;395408 }396409410410+ pm_runtime_get_sync(&pl08x->adev->dev);397411 return ch;398412}399413···407419408420 /* Stop the channel and clear its interrupts */409421 pl08x_terminate_phy_chan(pl08x, ch);422422+423423+ pm_runtime_put(&pl08x->adev->dev);410424411425 /* Mark it as free */412426 ch->serving = NULL;···489499};490500491501/*492492- * Autoselect a master bus to use for the transfer this prefers the493493- * destination bus if both available if fixed address on one bus the494494- * other will be chosen502502+ * Autoselect a master bus to use for the transfer. Slave will be the chosen as503503+ * victim in case src & dest are not similarly aligned. i.e. If after aligning504504+ * masters address with width requirements of transfer (by sending few byte by505505+ * byte data), slave is still not aligned, then its width will be reduced to506506+ * BYTE.507507+ * - prefers the destination bus if both available508508+ * - prefers bus with fixed address (i.e. peripheral)495509 */496510static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd,497511 struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl)498512{499513 if (!(cctl & PL080_CONTROL_DST_INCR)) {500500- *mbus = &bd->srcbus;501501- *sbus = &bd->dstbus;502502- } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {503514 *mbus = &bd->dstbus;504515 *sbus = &bd->srcbus;516516+ } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {517517+ *mbus = &bd->srcbus;518518+ *sbus = &bd->dstbus;505519 } else {506506- if (bd->dstbus.buswidth == 4) {520520+ if (bd->dstbus.buswidth >= bd->srcbus.buswidth) {507521 *mbus = &bd->dstbus;508522 *sbus = &bd->srcbus;509509- } else if (bd->srcbus.buswidth == 4) {510510- *mbus = &bd->srcbus;511511- *sbus = &bd->dstbus;512512- } else if (bd->dstbus.buswidth == 2) {513513- *mbus = &bd->dstbus;514514- *sbus = &bd->srcbus;515515- } else if (bd->srcbus.buswidth == 2) {516516- *mbus = &bd->srcbus;517517- *sbus = &bd->dstbus;518523 } else {519519- /* bd->srcbus.buswidth == 1 */520520- *mbus = &bd->dstbus;521521- *sbus = &bd->srcbus;524524+ *mbus = &bd->srcbus;525525+ *sbus = &bd->dstbus;522526 }523527 }524528}···531547 llis_va[num_llis].cctl = cctl;532548 llis_va[num_llis].src = bd->srcbus.addr;533549 llis_va[num_llis].dst = bd->dstbus.addr;534534- llis_va[num_llis].lli = llis_bus + (num_llis + 1) * sizeof(struct pl08x_lli);550550+ llis_va[num_llis].lli = llis_bus + (num_llis + 1) *551551+ sizeof(struct pl08x_lli);535552 llis_va[num_llis].lli |= bd->lli_bus;536553537554 if (cctl & PL080_CONTROL_SRC_INCR)···545560 bd->remainder -= len;546561}547562548548-/*549549- * Return number of bytes to fill to boundary, or len.550550- * This calculation works for any value of addr.551551- */552552-static inline size_t pl08x_pre_boundary(u32 addr, size_t len)563563+static inline void prep_byte_width_lli(struct pl08x_lli_build_data *bd,564564+ u32 *cctl, u32 len, int num_llis, size_t *total_bytes)553565{554554- size_t boundary_len = PL08X_BOUNDARY_SIZE -555555- (addr & (PL08X_BOUNDARY_SIZE - 1));556556-557557- return min(boundary_len, len);566566+ *cctl = pl08x_cctl_bits(*cctl, 1, 1, len);567567+ pl08x_fill_lli_for_desc(bd, num_llis, len, *cctl);568568+ (*total_bytes) += len;558569}559570560571/*···564583 struct pl08x_bus_data *mbus, *sbus;565584 struct pl08x_lli_build_data bd;566585 int num_llis = 0;567567- u32 cctl;568568- size_t max_bytes_per_lli;569569- size_t total_bytes = 0;586586+ u32 cctl, early_bytes = 0;587587+ size_t max_bytes_per_lli, total_bytes = 0;570588 struct pl08x_lli *llis_va;571589572572- txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT,573573- &txd->llis_bus);590590+ txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, &txd->llis_bus);574591 if (!txd->llis_va) {575592 dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__);576593 return 0;···598619 bd.srcbus.buswidth = bd.srcbus.maxwidth;599620 bd.dstbus.buswidth = bd.dstbus.maxwidth;600621601601- /*602602- * Bytes transferred == tsize * MIN(buswidths), not max(buswidths)603603- */604604- max_bytes_per_lli = min(bd.srcbus.buswidth, bd.dstbus.buswidth) *605605- PL080_CONTROL_TRANSFER_SIZE_MASK;606606-607622 /* We need to count this down to zero */608623 bd.remainder = txd->len;609624610610- /*611611- * Choose bus to align to612612- * - prefers destination bus if both available613613- * - if fixed address on one bus chooses other614614- */615625 pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl);616626617617- dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu llimax=%zu\n",627627+ dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu\n",618628 bd.srcbus.addr, cctl & PL080_CONTROL_SRC_INCR ? "+" : "",619629 bd.srcbus.buswidth,620630 bd.dstbus.addr, cctl & PL080_CONTROL_DST_INCR ? "+" : "",621631 bd.dstbus.buswidth,622622- bd.remainder, max_bytes_per_lli);632632+ bd.remainder);623633 dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n",624634 mbus == &bd.srcbus ? "src" : "dst",625635 sbus == &bd.srcbus ? "src" : "dst");626636627627- if (txd->len < mbus->buswidth) {628628- /* Less than a bus width available - send as single bytes */629629- while (bd.remainder) {630630- dev_vdbg(&pl08x->adev->dev,631631- "%s single byte LLIs for a transfer of "632632- "less than a bus width (remain 0x%08x)\n",633633- __func__, bd.remainder);634634- cctl = pl08x_cctl_bits(cctl, 1, 1, 1);635635- pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);636636- total_bytes++;637637- }638638- } else {639639- /* Make one byte LLIs until master bus is aligned */640640- while ((mbus->addr) % (mbus->buswidth)) {641641- dev_vdbg(&pl08x->adev->dev,642642- "%s adjustment lli for less than bus width "643643- "(remain 0x%08x)\n",644644- __func__, bd.remainder);645645- cctl = pl08x_cctl_bits(cctl, 1, 1, 1);646646- pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);647647- total_bytes++;637637+ /*638638+ * Zero length is only allowed if all these requirements are met:639639+ * - flow controller is peripheral.640640+ * - src.addr is aligned to src.width641641+ * - dst.addr is aligned to dst.width642642+ *643643+ * sg_len == 1 should be true, as there can be two cases here:644644+ * - Memory addresses are contiguous and are not scattered. Here, Only645645+ * one sg will be passed by user driver, with memory address and zero646646+ * length. We pass this to controller and after the transfer it will647647+ * receive the last burst request from peripheral and so transfer648648+ * finishes.649649+ *650650+ * - Memory addresses are scattered and are not contiguous. Here,651651+ * Obviously as DMA controller doesn't know when a lli's transfer gets652652+ * over, it can't load next lli. So in this case, there has to be an653653+ * assumption that only one lli is supported. Thus, we can't have654654+ * scattered addresses.655655+ */656656+ if (!bd.remainder) {657657+ u32 fc = (txd->ccfg & PL080_CONFIG_FLOW_CONTROL_MASK) >>658658+ PL080_CONFIG_FLOW_CONTROL_SHIFT;659659+ if (!((fc >= PL080_FLOW_SRC2DST_DST) &&660660+ (fc <= PL080_FLOW_SRC2DST_SRC))) {661661+ dev_err(&pl08x->adev->dev, "%s sg len can't be zero",662662+ __func__);663663+ return 0;648664 }649665666666+ if ((bd.srcbus.addr % bd.srcbus.buswidth) ||667667+ (bd.srcbus.addr % bd.srcbus.buswidth)) {668668+ dev_err(&pl08x->adev->dev,669669+ "%s src & dst address must be aligned to src"670670+ " & dst width if peripheral is flow controller",671671+ __func__);672672+ return 0;673673+ }674674+675675+ cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,676676+ bd.dstbus.buswidth, 0);677677+ pl08x_fill_lli_for_desc(&bd, num_llis++, 0, cctl);678678+ }679679+680680+ /*681681+ * Send byte by byte for following cases682682+ * - Less than a bus width available683683+ * - until master bus is aligned684684+ */685685+ if (bd.remainder < mbus->buswidth)686686+ early_bytes = bd.remainder;687687+ else if ((mbus->addr) % (mbus->buswidth)) {688688+ early_bytes = mbus->buswidth - (mbus->addr) % (mbus->buswidth);689689+ if ((bd.remainder - early_bytes) < mbus->buswidth)690690+ early_bytes = bd.remainder;691691+ }692692+693693+ if (early_bytes) {694694+ dev_vdbg(&pl08x->adev->dev, "%s byte width LLIs "695695+ "(remain 0x%08x)\n", __func__, bd.remainder);696696+ prep_byte_width_lli(&bd, &cctl, early_bytes, num_llis++,697697+ &total_bytes);698698+ }699699+700700+ if (bd.remainder) {650701 /*651702 * Master now aligned652703 * - if slave is not then we must set its width down···689680 sbus->buswidth = 1;690681 }691682683683+ /* Bytes transferred = tsize * src width, not MIN(buswidths) */684684+ max_bytes_per_lli = bd.srcbus.buswidth *685685+ PL080_CONTROL_TRANSFER_SIZE_MASK;686686+692687 /*693688 * Make largest possible LLIs until less than one bus694689 * width left695690 */696691 while (bd.remainder > (mbus->buswidth - 1)) {697697- size_t lli_len, target_len, tsize, odd_bytes;692692+ size_t lli_len, tsize, width;698693699694 /*700695 * If enough left try to send max possible,701696 * otherwise try to send the remainder702697 */703703- target_len = min(bd.remainder, max_bytes_per_lli);698698+ lli_len = min(bd.remainder, max_bytes_per_lli);704699705700 /*706706- * Set bus lengths for incrementing buses to the707707- * number of bytes which fill to next memory boundary,708708- * limiting on the target length calculated above.701701+ * Check against maximum bus alignment: Calculate actual702702+ * transfer size in relation to bus width and get a703703+ * maximum remainder of the highest bus width - 1709704 */710710- if (cctl & PL080_CONTROL_SRC_INCR)711711- bd.srcbus.fill_bytes =712712- pl08x_pre_boundary(bd.srcbus.addr,713713- target_len);714714- else715715- bd.srcbus.fill_bytes = target_len;705705+ width = max(mbus->buswidth, sbus->buswidth);706706+ lli_len = (lli_len / width) * width;707707+ tsize = lli_len / bd.srcbus.buswidth;716708717717- if (cctl & PL080_CONTROL_DST_INCR)718718- bd.dstbus.fill_bytes =719719- pl08x_pre_boundary(bd.dstbus.addr,720720- target_len);721721- else722722- bd.dstbus.fill_bytes = target_len;709709+ dev_vdbg(&pl08x->adev->dev,710710+ "%s fill lli with single lli chunk of "711711+ "size 0x%08zx (remainder 0x%08zx)\n",712712+ __func__, lli_len, bd.remainder);723713724724- /* Find the nearest */725725- lli_len = min(bd.srcbus.fill_bytes,726726- bd.dstbus.fill_bytes);727727-728728- BUG_ON(lli_len > bd.remainder);729729-730730- if (lli_len <= 0) {731731- dev_err(&pl08x->adev->dev,732732- "%s lli_len is %zu, <= 0\n",733733- __func__, lli_len);734734- return 0;735735- }736736-737737- if (lli_len == target_len) {738738- /*739739- * Can send what we wanted.740740- * Maintain alignment741741- */742742- lli_len = (lli_len/mbus->buswidth) *743743- mbus->buswidth;744744- odd_bytes = 0;745745- } else {746746- /*747747- * So now we know how many bytes to transfer748748- * to get to the nearest boundary. The next749749- * LLI will past the boundary. However, we750750- * may be working to a boundary on the slave751751- * bus. We need to ensure the master stays752752- * aligned, and that we are working in753753- * multiples of the bus widths.754754- */755755- odd_bytes = lli_len % mbus->buswidth;756756- lli_len -= odd_bytes;757757-758758- }759759-760760- if (lli_len) {761761- /*762762- * Check against minimum bus alignment:763763- * Calculate actual transfer size in relation764764- * to bus width an get a maximum remainder of765765- * the smallest bus width - 1766766- */767767- /* FIXME: use round_down()? */768768- tsize = lli_len / min(mbus->buswidth,769769- sbus->buswidth);770770- lli_len = tsize * min(mbus->buswidth,771771- sbus->buswidth);772772-773773- if (target_len != lli_len) {774774- dev_vdbg(&pl08x->adev->dev,775775- "%s can't send what we want. Desired 0x%08zx, lli of 0x%08zx bytes in txd of 0x%08zx\n",776776- __func__, target_len, lli_len, txd->len);777777- }778778-779779- cctl = pl08x_cctl_bits(cctl,780780- bd.srcbus.buswidth,781781- bd.dstbus.buswidth,782782- tsize);783783-784784- dev_vdbg(&pl08x->adev->dev,785785- "%s fill lli with single lli chunk of size 0x%08zx (remainder 0x%08zx)\n",786786- __func__, lli_len, bd.remainder);787787- pl08x_fill_lli_for_desc(&bd, num_llis++,788788- lli_len, cctl);789789- total_bytes += lli_len;790790- }791791-792792-793793- if (odd_bytes) {794794- /*795795- * Creep past the boundary, maintaining796796- * master alignment797797- */798798- int j;799799- for (j = 0; (j < mbus->buswidth)800800- && (bd.remainder); j++) {801801- cctl = pl08x_cctl_bits(cctl, 1, 1, 1);802802- dev_vdbg(&pl08x->adev->dev,803803- "%s align with boundary, single byte (remain 0x%08zx)\n",804804- __func__, bd.remainder);805805- pl08x_fill_lli_for_desc(&bd,806806- num_llis++, 1, cctl);807807- total_bytes++;808808- }809809- }714714+ cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,715715+ bd.dstbus.buswidth, tsize);716716+ pl08x_fill_lli_for_desc(&bd, num_llis++, lli_len, cctl);717717+ total_bytes += lli_len;810718 }811719812720 /*813721 * Send any odd bytes814722 */815815- while (bd.remainder) {816816- cctl = pl08x_cctl_bits(cctl, 1, 1, 1);723723+ if (bd.remainder) {817724 dev_vdbg(&pl08x->adev->dev,818818- "%s align with boundary, single odd byte (remain %zu)\n",725725+ "%s align with boundary, send odd bytes (remain %zu)\n",819726 __func__, bd.remainder);820820- pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);821821- total_bytes++;727727+ prep_byte_width_lli(&bd, &cctl, bd.remainder,728728+ num_llis++, &total_bytes);822729 }823730 }731731+824732 if (total_bytes != txd->len) {825733 dev_err(&pl08x->adev->dev,826734 "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n",···843917 * need, but for slaves the physical signals may be muxed!844918 * Can the platform allow us to use this channel?845919 */846846- if (plchan->slave &&847847- ch->signal < 0 &&848848- pl08x->pd->get_signal) {920920+ if (plchan->slave && pl08x->pd->get_signal) {849921 ret = pl08x->pd->get_signal(plchan);850922 if (ret < 0) {851923 dev_dbg(&pl08x->adev->dev,···9321008 * If slaves are relying on interrupts to signal completion this function9331009 * must not be called with interrupts disabled.9341010 */935935-static enum dma_status936936-pl08x_dma_tx_status(struct dma_chan *chan,937937- dma_cookie_t cookie,938938- struct dma_tx_state *txstate)10111011+static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan,10121012+ dma_cookie_t cookie, struct dma_tx_state *txstate)9391013{9401014 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);9411015 dma_cookie_t last_used;···1175125311761254 num_llis = pl08x_fill_llis_for_desc(pl08x, txd);11771255 if (!num_llis) {11781178- kfree(txd);12561256+ spin_lock_irqsave(&plchan->lock, flags);12571257+ pl08x_free_txd(pl08x, txd);12581258+ spin_unlock_irqrestore(&plchan->lock, flags);11791259 return -EINVAL;11801260 }11811261···12251301static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan,12261302 unsigned long flags)12271303{12281228- struct pl08x_txd *txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT);13041304+ struct pl08x_txd *txd = kzalloc(sizeof(*txd), GFP_NOWAIT);1229130512301306 if (txd) {12311307 dma_async_tx_descriptor_init(&txd->tx, &plchan->chan);···12911367 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);12921368 struct pl08x_driver_data *pl08x = plchan->host;12931369 struct pl08x_txd *txd;12941294- int ret;13701370+ int ret, tmp;1295137112961372 /*12971373 * Current implementation ASSUMES only one sg···13251401 txd->len = sgl->length;1326140213271403 if (direction == DMA_TO_DEVICE) {13281328- txd->ccfg |= PL080_FLOW_MEM2PER << PL080_CONFIG_FLOW_CONTROL_SHIFT;13291404 txd->cctl = plchan->dst_cctl;13301405 txd->src_addr = sgl->dma_address;13311406 txd->dst_addr = plchan->dst_addr;13321407 } else if (direction == DMA_FROM_DEVICE) {13331333- txd->ccfg |= PL080_FLOW_PER2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT;13341408 txd->cctl = plchan->src_cctl;13351409 txd->src_addr = plchan->src_addr;13361410 txd->dst_addr = sgl->dma_address;···13371415 "%s direction unsupported\n", __func__);13381416 return NULL;13391417 }14181418+14191419+ if (plchan->cd->device_fc)14201420+ tmp = (direction == DMA_TO_DEVICE) ? PL080_FLOW_MEM2PER_PER :14211421+ PL080_FLOW_PER2MEM_PER;14221422+ else14231423+ tmp = (direction == DMA_TO_DEVICE) ? PL080_FLOW_MEM2PER :14241424+ PL080_FLOW_PER2MEM;14251425+14261426+ txd->ccfg |= tmp << PL080_CONFIG_FLOW_CONTROL_SHIFT;1340142713411428 ret = pl08x_prep_channel_resources(plchan, txd);13421429 if (ret)···14381507 */14391508static void pl08x_ensure_on(struct pl08x_driver_data *pl08x)14401509{14411441- u32 val;14421442-14431443- val = readl(pl08x->base + PL080_CONFIG);14441444- val &= ~(PL080_CONFIG_M2_BE | PL080_CONFIG_M1_BE | PL080_CONFIG_ENABLE);14451445- /* We implicitly clear bit 1 and that means little-endian mode */14461446- val |= PL080_CONFIG_ENABLE;14471447- writel(val, pl08x->base + PL080_CONFIG);15101510+ writel(PL080_CONFIG_ENABLE, pl08x->base + PL080_CONFIG);14481511}1449151214501513static void pl08x_unmap_buffers(struct pl08x_txd *txd)···15141589 */15151590 list_for_each_entry(waiting, &pl08x->memcpy.channels,15161591 chan.device_node) {15171517- if (waiting->state == PL08X_CHAN_WAITING &&15181518- waiting->waiting != NULL) {15921592+ if (waiting->state == PL08X_CHAN_WAITING &&15931593+ waiting->waiting != NULL) {15191594 int ret;1520159515211596 /* This should REALLY not fail now */···15551630static irqreturn_t pl08x_irq(int irq, void *dev)15561631{15571632 struct pl08x_driver_data *pl08x = dev;15581558- u32 mask = 0;15591559- u32 val;15601560- int i;16331633+ u32 mask = 0, err, tc, i;1561163415621562- val = readl(pl08x->base + PL080_ERR_STATUS);15631563- if (val) {15641564- /* An error interrupt (on one or more channels) */15651565- dev_err(&pl08x->adev->dev,15661566- "%s error interrupt, register value 0x%08x\n",15671567- __func__, val);15681568- /*15691569- * Simply clear ALL PL08X error interrupts,15701570- * regardless of channel and cause15711571- * FIXME: should be 0x00000003 on PL081 really.15721572- */15731573- writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR);16351635+ /* check & clear - ERR & TC interrupts */16361636+ err = readl(pl08x->base + PL080_ERR_STATUS);16371637+ if (err) {16381638+ dev_err(&pl08x->adev->dev, "%s error interrupt, register value 0x%08x\n",16391639+ __func__, err);16401640+ writel(err, pl08x->base + PL080_ERR_CLEAR);15741641 }15751575- val = readl(pl08x->base + PL080_INT_STATUS);16421642+ tc = readl(pl08x->base + PL080_INT_STATUS);16431643+ if (tc)16441644+ writel(tc, pl08x->base + PL080_TC_CLEAR);16451645+16461646+ if (!err && !tc)16471647+ return IRQ_NONE;16481648+15761649 for (i = 0; i < pl08x->vd->channels; i++) {15771577- if ((1 << i) & val) {16501650+ if (((1 << i) & err) || ((1 << i) & tc)) {15781651 /* Locate physical channel */15791652 struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i];15801653 struct pl08x_dma_chan *plchan = phychan->serving;1581165416551655+ if (!plchan) {16561656+ dev_err(&pl08x->adev->dev,16571657+ "%s Error TC interrupt on unused channel: 0x%08x\n",16581658+ __func__, i);16591659+ continue;16601660+ }16611661+15821662 /* Schedule tasklet on this channel */15831663 tasklet_schedule(&plchan->tasklet);15841584-15851664 mask |= (1 << i);15861665 }15871666 }15881588- /* Clear only the terminal interrupts on channels we processed */15891589- writel(mask, pl08x->base + PL080_TC_CLEAR);1590166715911668 return mask ? IRQ_HANDLED : IRQ_NONE;15921669}···16121685 * Make a local wrapper to hold required data16131686 */16141687static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,16151615- struct dma_device *dmadev,16161616- unsigned int channels,16171617- bool slave)16881688+ struct dma_device *dmadev, unsigned int channels, bool slave)16181689{16191690 struct pl08x_dma_chan *chan;16201691 int i;···16251700 * to cope with that situation.16261701 */16271702 for (i = 0; i < channels; i++) {16281628- chan = kzalloc(sizeof(struct pl08x_dma_chan), GFP_KERNEL);17031703+ chan = kzalloc(sizeof(*chan), GFP_KERNEL);16291704 if (!chan) {16301705 dev_err(&pl08x->adev->dev,16311706 "%s no memory for channel\n", __func__);···16531728 kfree(chan);16541729 continue;16551730 }16561656- dev_info(&pl08x->adev->dev,17311731+ dev_dbg(&pl08x->adev->dev,16571732 "initialize virtual channel \"%s\"\n",16581733 chan->name);16591734···17621837static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x)17631838{17641839 /* Expose a simple debugfs interface to view all clocks */17651765- (void) debugfs_create_file(dev_name(&pl08x->adev->dev), S_IFREG | S_IRUGO,17661766- NULL, pl08x,17671767- &pl08x_debugfs_operations);18401840+ (void) debugfs_create_file(dev_name(&pl08x->adev->dev),18411841+ S_IFREG | S_IRUGO, NULL, pl08x,18421842+ &pl08x_debugfs_operations);17681843}1769184417701845#else···17851860 return ret;1786186117871862 /* Create the driver state holder */17881788- pl08x = kzalloc(sizeof(struct pl08x_driver_data), GFP_KERNEL);18631863+ pl08x = kzalloc(sizeof(*pl08x), GFP_KERNEL);17891864 if (!pl08x) {17901865 ret = -ENOMEM;17911866 goto out_no_pl08x;17921867 }18681868+18691869+ pm_runtime_set_active(&adev->dev);18701870+ pm_runtime_enable(&adev->dev);1793187117941872 /* Initialize memcpy engine */17951873 dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask);···18671939 }1868194018691941 /* Initialize physical channels */18701870- pl08x->phy_chans = kmalloc((vd->channels * sizeof(struct pl08x_phy_chan)),19421942+ pl08x->phy_chans = kmalloc((vd->channels * sizeof(*pl08x->phy_chans)),18711943 GFP_KERNEL);18721944 if (!pl08x->phy_chans) {18731945 dev_err(&adev->dev, "%s failed to allocate "···18841956 spin_lock_init(&ch->lock);18851957 ch->serving = NULL;18861958 ch->signal = -1;18871887- dev_info(&adev->dev,18881888- "physical channel %d is %s\n", i,18891889- pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");19591959+ dev_dbg(&adev->dev, "physical channel %d is %s\n",19601960+ i, pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");18901961 }1891196218921963 /* Register as many memcpy channels as there are physical channels */···1901197419021975 /* Register slave channels */19031976 ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave,19041904- pl08x->pd->num_slave_channels,19051905- true);19771977+ pl08x->pd->num_slave_channels, true);19061978 if (ret <= 0) {19071979 dev_warn(&pl08x->adev->dev,19081980 "%s failed to enumerate slave channels - %d\n",···19312005 dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n",19322006 amba_part(adev), amba_rev(adev),19332007 (unsigned long long)adev->res.start, adev->irq[0]);20082008+20092009+ pm_runtime_put(&adev->dev);19342010 return 0;1935201119362012out_no_slave_reg:···19512023 dma_pool_destroy(pl08x->pool);19522024out_no_lli_pool:19532025out_no_platdata:20262026+ pm_runtime_put(&adev->dev);20272027+ pm_runtime_disable(&adev->dev);20282028+19542029 kfree(pl08x);19552030out_no_pl08x:19562031 amba_release_regions(adev);
+125-34
drivers/dma/at_hdmac.c
···107107{108108 struct at_desc *desc, *_desc;109109 struct at_desc *ret = NULL;110110+ unsigned long flags;110111 unsigned int i = 0;111112 LIST_HEAD(tmp_list);112113113113- spin_lock_bh(&atchan->lock);114114+ spin_lock_irqsave(&atchan->lock, flags);114115 list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) {115116 i++;116117 if (async_tx_test_ack(&desc->txd)) {···122121 dev_dbg(chan2dev(&atchan->chan_common),123122 "desc %p not ACKed\n", desc);124123 }125125- spin_unlock_bh(&atchan->lock);124124+ spin_unlock_irqrestore(&atchan->lock, flags);126125 dev_vdbg(chan2dev(&atchan->chan_common),127126 "scanned %u descriptors on freelist\n", i);128127···130129 if (!ret) {131130 ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC);132131 if (ret) {133133- spin_lock_bh(&atchan->lock);132132+ spin_lock_irqsave(&atchan->lock, flags);134133 atchan->descs_allocated++;135135- spin_unlock_bh(&atchan->lock);134134+ spin_unlock_irqrestore(&atchan->lock, flags);136135 } else {137136 dev_err(chan2dev(&atchan->chan_common),138137 "not enough descriptors available\n");···151150{152151 if (desc) {153152 struct at_desc *child;153153+ unsigned long flags;154154155155- spin_lock_bh(&atchan->lock);155155+ spin_lock_irqsave(&atchan->lock, flags);156156 list_for_each_entry(child, &desc->tx_list, desc_node)157157 dev_vdbg(chan2dev(&atchan->chan_common),158158 "moving child desc %p to freelist\n",···162160 dev_vdbg(chan2dev(&atchan->chan_common),163161 "moving desc %p to freelist\n", desc);164162 list_add(&desc->desc_node, &atchan->free_list);165165- spin_unlock_bh(&atchan->lock);163163+ spin_unlock_irqrestore(&atchan->lock, flags);166164 }167165}168166···301299302300 /* for cyclic transfers,303301 * no need to replay callback function while stopping */304304- if (!test_bit(ATC_IS_CYCLIC, &atchan->status)) {302302+ if (!atc_chan_is_cyclic(atchan)) {305303 dma_async_tx_callback callback = txd->callback;306304 void *param = txd->callback_param;307305···473471static void atc_tasklet(unsigned long data)474472{475473 struct at_dma_chan *atchan = (struct at_dma_chan *)data;474474+ unsigned long flags;476475477477- spin_lock(&atchan->lock);476476+ spin_lock_irqsave(&atchan->lock, flags);478477 if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status))479478 atc_handle_error(atchan);480480- else if (test_bit(ATC_IS_CYCLIC, &atchan->status))479479+ else if (atc_chan_is_cyclic(atchan))481480 atc_handle_cyclic(atchan);482481 else483482 atc_advance_work(atchan);484483485485- spin_unlock(&atchan->lock);484484+ spin_unlock_irqrestore(&atchan->lock, flags);486485}487486488487static irqreturn_t at_dma_interrupt(int irq, void *dev_id)···542539 struct at_desc *desc = txd_to_at_desc(tx);543540 struct at_dma_chan *atchan = to_at_dma_chan(tx->chan);544541 dma_cookie_t cookie;542542+ unsigned long flags;545543546546- spin_lock_bh(&atchan->lock);544544+ spin_lock_irqsave(&atchan->lock, flags);547545 cookie = atc_assign_cookie(atchan, desc);548546549547 if (list_empty(&atchan->active_list)) {···558554 list_add_tail(&desc->desc_node, &atchan->queue);559555 }560556561561- spin_unlock_bh(&atchan->lock);557557+ spin_unlock_irqrestore(&atchan->lock, flags);562558563559 return cookie;564560}···931927 struct at_dma_chan *atchan = to_at_dma_chan(chan);932928 struct at_dma *atdma = to_at_dma(chan->device);933929 int chan_id = atchan->chan_common.chan_id;930930+ unsigned long flags;934931935932 LIST_HEAD(list);936933937934 dev_vdbg(chan2dev(chan), "atc_control (%d)\n", cmd);938935939936 if (cmd == DMA_PAUSE) {940940- spin_lock_bh(&atchan->lock);937937+ spin_lock_irqsave(&atchan->lock, flags);941938942939 dma_writel(atdma, CHER, AT_DMA_SUSP(chan_id));943940 set_bit(ATC_IS_PAUSED, &atchan->status);944941945945- spin_unlock_bh(&atchan->lock);942942+ spin_unlock_irqrestore(&atchan->lock, flags);946943 } else if (cmd == DMA_RESUME) {947947- if (!test_bit(ATC_IS_PAUSED, &atchan->status))944944+ if (!atc_chan_is_paused(atchan))948945 return 0;949946950950- spin_lock_bh(&atchan->lock);947947+ spin_lock_irqsave(&atchan->lock, flags);951948952949 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id));953950 clear_bit(ATC_IS_PAUSED, &atchan->status);954951955955- spin_unlock_bh(&atchan->lock);952952+ spin_unlock_irqrestore(&atchan->lock, flags);956953 } else if (cmd == DMA_TERMINATE_ALL) {957954 struct at_desc *desc, *_desc;958955 /*···962957 * channel. We still have to poll the channel enable bit due963958 * to AHB/HSB limitations.964959 */965965- spin_lock_bh(&atchan->lock);960960+ spin_lock_irqsave(&atchan->lock, flags);966961967962 /* disabling channel: must also remove suspend state */968963 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id) | atchan->mask);···983978 /* if channel dedicated to cyclic operations, free it */984979 clear_bit(ATC_IS_CYCLIC, &atchan->status);985980986986- spin_unlock_bh(&atchan->lock);981981+ spin_unlock_irqrestore(&atchan->lock, flags);987982 } else {988983 return -ENXIO;989984 }···10091004 struct at_dma_chan *atchan = to_at_dma_chan(chan);10101005 dma_cookie_t last_used;10111006 dma_cookie_t last_complete;10071007+ unsigned long flags;10121008 enum dma_status ret;1013100910141014- spin_lock_bh(&atchan->lock);10101010+ spin_lock_irqsave(&atchan->lock, flags);1015101110161012 last_complete = atchan->completed_cookie;10171013 last_used = chan->cookie;···10271021 ret = dma_async_is_complete(cookie, last_complete, last_used);10281022 }1029102310301030- spin_unlock_bh(&atchan->lock);10241024+ spin_unlock_irqrestore(&atchan->lock, flags);1031102510321026 if (ret != DMA_SUCCESS)10331027 dma_set_tx_state(txstate, last_complete, last_used,···10351029 else10361030 dma_set_tx_state(txstate, last_complete, last_used, 0);1037103110381038- if (test_bit(ATC_IS_PAUSED, &atchan->status))10321032+ if (atc_chan_is_paused(atchan))10391033 ret = DMA_PAUSED;1040103410411035 dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d (d%d, u%d)\n",···10521046static void atc_issue_pending(struct dma_chan *chan)10531047{10541048 struct at_dma_chan *atchan = to_at_dma_chan(chan);10491049+ unsigned long flags;1055105010561051 dev_vdbg(chan2dev(chan), "issue_pending\n");1057105210581053 /* Not needed for cyclic transfers */10591059- if (test_bit(ATC_IS_CYCLIC, &atchan->status))10541054+ if (atc_chan_is_cyclic(atchan))10601055 return;1061105610621062- spin_lock_bh(&atchan->lock);10571057+ spin_lock_irqsave(&atchan->lock, flags);10631058 if (!atc_chan_is_enabled(atchan)) {10641059 atc_advance_work(atchan);10651060 }10661066- spin_unlock_bh(&atchan->lock);10611061+ spin_unlock_irqrestore(&atchan->lock, flags);10671062}1068106310691064/**···10801073 struct at_dma *atdma = to_at_dma(chan->device);10811074 struct at_desc *desc;10821075 struct at_dma_slave *atslave;10761076+ unsigned long flags;10831077 int i;10841078 u32 cfg;10851079 LIST_HEAD(tmp_list);···11241116 list_add_tail(&desc->desc_node, &tmp_list);11251117 }1126111811271127- spin_lock_bh(&atchan->lock);11191119+ spin_lock_irqsave(&atchan->lock, flags);11281120 atchan->descs_allocated = i;11291121 list_splice(&tmp_list, &atchan->free_list);11301122 atchan->completed_cookie = chan->cookie = 1;11311131- spin_unlock_bh(&atchan->lock);11231123+ spin_unlock_irqrestore(&atchan->lock, flags);1132112411331125 /* channel parameters */11341126 channel_writel(atchan, CFG, cfg);···13011293 if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask))13021294 atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy;1303129513041304- if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask))12961296+ if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask)) {13051297 atdma->dma_common.device_prep_slave_sg = atc_prep_slave_sg;13061306-13071307- if (dma_has_cap(DMA_CYCLIC, atdma->dma_common.cap_mask))12981298+ /* controller can do slave DMA: can trigger cyclic transfers */12991299+ dma_cap_set(DMA_CYCLIC, atdma->dma_common.cap_mask);13081300 atdma->dma_common.device_prep_dma_cyclic = atc_prep_dma_cyclic;13091309-13101310- if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ||13111311- dma_has_cap(DMA_CYCLIC, atdma->dma_common.cap_mask))13121301 atdma->dma_common.device_control = atc_control;13021302+ }1313130313141304 dma_writel(atdma, EN, AT_DMA_ENABLE);13151305···13831377 clk_disable(atdma->clk);13841378}1385137913801380+static int at_dma_prepare(struct device *dev)13811381+{13821382+ struct platform_device *pdev = to_platform_device(dev);13831383+ struct at_dma *atdma = platform_get_drvdata(pdev);13841384+ struct dma_chan *chan, *_chan;13851385+13861386+ list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,13871387+ device_node) {13881388+ struct at_dma_chan *atchan = to_at_dma_chan(chan);13891389+ /* wait for transaction completion (except in cyclic case) */13901390+ if (atc_chan_is_enabled(atchan) && !atc_chan_is_cyclic(atchan))13911391+ return -EAGAIN;13921392+ }13931393+ return 0;13941394+}13951395+13961396+static void atc_suspend_cyclic(struct at_dma_chan *atchan)13971397+{13981398+ struct dma_chan *chan = &atchan->chan_common;13991399+14001400+ /* Channel should be paused by user14011401+ * do it anyway even if it is not done already */14021402+ if (!atc_chan_is_paused(atchan)) {14031403+ dev_warn(chan2dev(chan),14041404+ "cyclic channel not paused, should be done by channel user\n");14051405+ atc_control(chan, DMA_PAUSE, 0);14061406+ }14071407+14081408+ /* now preserve additional data for cyclic operations */14091409+ /* next descriptor address in the cyclic list */14101410+ atchan->save_dscr = channel_readl(atchan, DSCR);14111411+14121412+ vdbg_dump_regs(atchan);14131413+}14141414+13861415static int at_dma_suspend_noirq(struct device *dev)13871416{13881417 struct platform_device *pdev = to_platform_device(dev);13891418 struct at_dma *atdma = platform_get_drvdata(pdev);14191419+ struct dma_chan *chan, *_chan;1390142013911391- at_dma_off(platform_get_drvdata(pdev));14211421+ /* preserve data */14221422+ list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,14231423+ device_node) {14241424+ struct at_dma_chan *atchan = to_at_dma_chan(chan);14251425+14261426+ if (atc_chan_is_cyclic(atchan))14271427+ atc_suspend_cyclic(atchan);14281428+ atchan->save_cfg = channel_readl(atchan, CFG);14291429+ }14301430+ atdma->save_imr = dma_readl(atdma, EBCIMR);14311431+14321432+ /* disable DMA controller */14331433+ at_dma_off(atdma);13921434 clk_disable(atdma->clk);13931435 return 0;14361436+}14371437+14381438+static void atc_resume_cyclic(struct at_dma_chan *atchan)14391439+{14401440+ struct at_dma *atdma = to_at_dma(atchan->chan_common.device);14411441+14421442+ /* restore channel status for cyclic descriptors list:14431443+ * next descriptor in the cyclic list at the time of suspend */14441444+ channel_writel(atchan, SADDR, 0);14451445+ channel_writel(atchan, DADDR, 0);14461446+ channel_writel(atchan, CTRLA, 0);14471447+ channel_writel(atchan, CTRLB, 0);14481448+ channel_writel(atchan, DSCR, atchan->save_dscr);14491449+ dma_writel(atdma, CHER, atchan->mask);14501450+14511451+ /* channel pause status should be removed by channel user14521452+ * We cannot take the initiative to do it here */14531453+14541454+ vdbg_dump_regs(atchan);13941455}1395145613961457static int at_dma_resume_noirq(struct device *dev)13971458{13981459 struct platform_device *pdev = to_platform_device(dev);13991460 struct at_dma *atdma = platform_get_drvdata(pdev);14611461+ struct dma_chan *chan, *_chan;1400146214631463+ /* bring back DMA controller */14011464 clk_enable(atdma->clk);14021465 dma_writel(atdma, EN, AT_DMA_ENABLE);14661466+14671467+ /* clear any pending interrupt */14681468+ while (dma_readl(atdma, EBCISR))14691469+ cpu_relax();14701470+14711471+ /* restore saved data */14721472+ dma_writel(atdma, EBCIER, atdma->save_imr);14731473+ list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,14741474+ device_node) {14751475+ struct at_dma_chan *atchan = to_at_dma_chan(chan);14761476+14771477+ channel_writel(atchan, CFG, atchan->save_cfg);14781478+ if (atc_chan_is_cyclic(atchan))14791479+ atc_resume_cyclic(atchan);14801480+ }14031481 return 0;14041482}1405148314061484static const struct dev_pm_ops at_dma_dev_pm_ops = {14851485+ .prepare = at_dma_prepare,14071486 .suspend_noirq = at_dma_suspend_noirq,14081487 .resume_noirq = at_dma_resume_noirq,14091488};
+24
drivers/dma/at_hdmac_regs.h
···204204 * @status: transmit status information from irq/prep* functions205205 * to tasklet (use atomic operations)206206 * @tasklet: bottom half to finish transaction work207207+ * @save_cfg: configuration register that is saved on suspend/resume cycle208208+ * @save_dscr: for cyclic operations, preserve next descriptor address in209209+ * the cyclic list on suspend/resume cycle207210 * @lock: serializes enqueue/dequeue operations to descriptors lists208211 * @completed_cookie: identifier for the most recently completed operation209212 * @active_list: list of descriptors dmaengine is being running on···221218 u8 mask;222219 unsigned long status;223220 struct tasklet_struct tasklet;221221+ u32 save_cfg;222222+ u32 save_dscr;224223225224 spinlock_t lock;226225···253248 * @chan_common: common dmaengine dma_device object members254249 * @ch_regs: memory mapped register base255250 * @clk: dma controller clock251251+ * @save_imr: interrupt mask register that is saved on suspend/resume cycle256252 * @all_chan_mask: all channels availlable in a mask257253 * @dma_desc_pool: base of DMA descriptor region (DMA address)258254 * @chan: channels table to store at_dma_chan structures···262256 struct dma_device dma_common;263257 void __iomem *regs;264258 struct clk *clk;259259+ u32 save_imr;265260266261 u8 all_chan_mask;267262···362355 return !!(dma_readl(atdma, CHSR) & atchan->mask);363356}364357358358+/**359359+ * atc_chan_is_paused - test channel pause/resume status360360+ * @atchan: channel we want to test status361361+ */362362+static inline int atc_chan_is_paused(struct at_dma_chan *atchan)363363+{364364+ return test_bit(ATC_IS_PAUSED, &atchan->status);365365+}366366+367367+/**368368+ * atc_chan_is_cyclic - test if given channel has cyclic property set369369+ * @atchan: channel we want to test status370370+ */371371+static inline int atc_chan_is_cyclic(struct at_dma_chan *atchan)372372+{373373+ return test_bit(ATC_IS_CYCLIC, &atchan->status);374374+}365375366376/**367377 * set_desc_eol - set end-of-link to descriptor so it will end transfer
+21-2
drivers/dma/dmatest.c
···1010#include <linux/delay.h>1111#include <linux/dma-mapping.h>1212#include <linux/dmaengine.h>1313+#include <linux/freezer.h>1314#include <linux/init.h>1415#include <linux/kthread.h>1516#include <linux/module.h>···252251 int i;253252254253 thread_name = current->comm;254254+ set_freezable_with_signal();255255256256 ret = -ENOMEM;257257···307305 dma_addr_t dma_srcs[src_cnt];308306 dma_addr_t dma_dsts[dst_cnt];309307 struct completion cmp;310310- unsigned long tmo = msecs_to_jiffies(timeout);308308+ unsigned long start, tmo, end = 0 /* compiler... */;309309+ bool reload = true;311310 u8 align = 0;312311313312 total_tests++;···407404 }408405 dma_async_issue_pending(chan);409406410410- tmo = wait_for_completion_timeout(&cmp, tmo);407407+ do {408408+ start = jiffies;409409+ if (reload)410410+ end = start + msecs_to_jiffies(timeout);411411+ else if (end <= start)412412+ end = start + 1;413413+ tmo = wait_for_completion_interruptible_timeout(&cmp,414414+ end - start);415415+ reload = try_to_freeze();416416+ } while (tmo == -ERESTARTSYS);417417+411418 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);412419413420 if (tmo == 0) {···490477 pr_notice("%s: terminating after %u tests, %u failures (status %d)\n",491478 thread_name, total_tests, failed_tests, ret);492479480480+ /* terminate all transfers on specified channels */481481+ chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);493482 if (iterations > 0)494483 while (!kthread_should_stop()) {495484 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);···514499 list_del(&thread->node);515500 kfree(thread);516501 }502502+503503+ /* terminate all transfers on specified channels */504504+ dtc->chan->device->device_control(dtc->chan, DMA_TERMINATE_ALL, 0);505505+517506 kfree(dtc);518507}519508
+38-9
drivers/dma/imx-sdma.c
···318318 dma_addr_t context_phys;319319 struct dma_device dma_device;320320 struct clk *clk;321321+ struct mutex channel_0_lock;321322 struct sdma_script_start_addrs *script_addrs;322323};323324···416415 dma_addr_t buf_phys;417416 int ret;418417418418+ mutex_lock(&sdma->channel_0_lock);419419+419420 buf_virt = dma_alloc_coherent(NULL,420421 size,421422 &buf_phys, GFP_KERNEL);422422- if (!buf_virt)423423- return -ENOMEM;423423+ if (!buf_virt) {424424+ ret = -ENOMEM;425425+ goto err_out;426426+ }424427425428 bd0->mode.command = C0_SETPM;426429 bd0->mode.status = BD_DONE | BD_INTR | BD_WRAP | BD_EXTD;···437432 ret = sdma_run_channel(&sdma->channel[0]);438433439434 dma_free_coherent(NULL, size, buf_virt, buf_phys);435435+436436+err_out:437437+ mutex_unlock(&sdma->channel_0_lock);440438441439 return ret;442440}···664656 dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0);665657 dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1);666658659659+ mutex_lock(&sdma->channel_0_lock);660660+667661 memset(context, 0, sizeof(*context));668662 context->channel_state.pc = load_address;669663···685675 bd0->ext_buffer_addr = 2048 + (sizeof(*context) / 4) * channel;686676687677 ret = sdma_run_channel(&sdma->channel[0]);678678+679679+ mutex_unlock(&sdma->channel_0_lock);688680689681 return ret;690682}···11431131 saddr_arr[i] = addr_arr[i];11441132}1145113311461146-static int __init sdma_get_firmware(struct sdma_engine *sdma,11471147- const char *fw_name)11341134+static void sdma_load_firmware(const struct firmware *fw, void *context)11481135{11491149- const struct firmware *fw;11361136+ struct sdma_engine *sdma = context;11501137 const struct sdma_firmware_header *header;11511151- int ret;11521138 const struct sdma_script_start_addrs *addr;11531139 unsigned short *ram_code;1154114011551155- ret = request_firmware(&fw, fw_name, sdma->dev);11561156- if (ret)11571157- return ret;11411141+ if (!fw) {11421142+ dev_err(sdma->dev, "firmware not found\n");11431143+ return;11441144+ }1158114511591146 if (fw->size < sizeof(*header))11601147 goto err_firmware;···1183117211841173err_firmware:11851174 release_firmware(fw);11751175+}11761176+11771177+static int __init sdma_get_firmware(struct sdma_engine *sdma,11781178+ const char *fw_name)11791179+{11801180+ int ret;11811181+11821182+ ret = request_firmware_nowait(THIS_MODULE,11831183+ FW_ACTION_HOTPLUG, fw_name, sdma->dev,11841184+ GFP_KERNEL, sdma, sdma_load_firmware);1186118511871186 return ret;11881187}···12901269 struct sdma_platform_data *pdata = pdev->dev.platform_data;12911270 int i;12921271 struct sdma_engine *sdma;12721272+ s32 *saddr_arr;1293127312941274 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL);12951275 if (!sdma)12961276 return -ENOMEM;12771277+12781278+ mutex_init(&sdma->channel_0_lock);1297127912981280 sdma->dev = &pdev->dev;12991281···13331309 ret = -ENOMEM;13341310 goto err_alloc;13351311 }13121312+13131313+ /* initially no scripts available */13141314+ saddr_arr = (s32 *)sdma->script_addrs;13151315+ for (i = 0; i < SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; i++)13161316+ saddr_arr[i] = -EINVAL;1336131713371318 if (of_id)13381319 pdev->id_entry = of_id->data;
+24-21
drivers/dma/mxs-dma.c
···130130 struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS];131131};132132133133+static inline void mxs_dma_clkgate(struct mxs_dma_chan *mxs_chan, int enable)134134+{135135+ struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;136136+ int chan_id = mxs_chan->chan.chan_id;137137+ int set_clr = enable ? MXS_CLR_ADDR : MXS_SET_ADDR;138138+139139+ /* enable apbh channel clock */140140+ if (dma_is_apbh()) {141141+ if (apbh_is_old())142142+ writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),143143+ mxs_dma->base + HW_APBHX_CTRL0 + set_clr);144144+ else145145+ writel(1 << chan_id,146146+ mxs_dma->base + HW_APBHX_CTRL0 + set_clr);147147+ }148148+}149149+133150static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)134151{135152 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;···165148 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;166149 int chan_id = mxs_chan->chan.chan_id;167150151151+ /* clkgate needs to be enabled before writing other registers */152152+ mxs_dma_clkgate(mxs_chan, 1);153153+168154 /* set cmd_addr up */169155 writel(mxs_chan->ccw_phys,170156 mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(chan_id));171171-172172- /* enable apbh channel clock */173173- if (dma_is_apbh()) {174174- if (apbh_is_old())175175- writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),176176- mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);177177- else178178- writel(1 << chan_id,179179- mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);180180- }181157182158 /* write 1 to SEMA to kick off the channel */183159 writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(chan_id));···178168179169static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan)180170{181181- struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;182182- int chan_id = mxs_chan->chan.chan_id;183183-184171 /* disable apbh channel clock */185185- if (dma_is_apbh()) {186186- if (apbh_is_old())187187- writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),188188- mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);189189- else190190- writel(1 << chan_id,191191- mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);192192- }172172+ mxs_dma_clkgate(mxs_chan, 0);193173194174 mxs_chan->status = DMA_SUCCESS;195175}···338338 if (ret)339339 goto err_clk;340340341341+ /* clkgate needs to be enabled for reset to finish */342342+ mxs_dma_clkgate(mxs_chan, 1);341343 mxs_dma_reset_chan(mxs_chan);344344+ mxs_dma_clkgate(mxs_chan, 0);342345343346 dma_async_tx_descriptor_init(&mxs_chan->desc, chan);344347 mxs_chan->desc.tx_submit = mxs_dma_tx_submit;
+12-2
include/linux/amba/pl08x.h
···4747 * @muxval: a number usually used to poke into some mux regiser to4848 * mux in the signal to this channel4949 * @cctl_opt: default options for the channel control register5050+ * @device_fc: Flow Controller Settings for ccfg register. Only valid for slave5151+ * channels. Fill with 'true' if peripheral should be flow controller. Direction5252+ * will be selected at Runtime.5053 * @addr: source/target address in physical memory for this DMA channel,5154 * can be the address of a FIFO register for burst requests for example.5255 * This can be left undefined if the PrimeCell API is used for configuring···6865 int max_signal;6966 u32 muxval;7067 u32 cctl;6868+ bool device_fc;7169 dma_addr_t addr;7270 bool circular_buffer;7371 bool single;···8177 * @addr: current address8278 * @maxwidth: the maximum width of a transfer on this bus8379 * @buswidth: the width of this bus in bytes: 1, 2 or 48484- * @fill_bytes: bytes required to fill to the next bus memory boundary8580 */8681struct pl08x_bus_data {8782 dma_addr_t addr;8883 u8 maxwidth;8984 u8 buswidth;9090- size_t fill_bytes;9185};92869387/**···107105108106/**109107 * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor108108+ * @tx: async tx descriptor109109+ * @node: node for txd list for channels110110+ * @src_addr: src address of txd111111+ * @dst_addr: dst address of txd112112+ * @len: transfer len in bytes113113+ * @direction: direction of transfer110114 * @llis_bus: DMA memory address (physical) start for the LLIs111115 * @llis_va: virtual memory address start for the LLIs116116+ * @cctl: control reg values for current txd117117+ * @ccfg: config reg values for current txd112118 */113119struct pl08x_txd {114120 struct dma_async_tx_descriptor tx;