amba-pl08x.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321
  1. /*
  2. * Copyright (c) 2006 ARM Ltd.
  3. * Copyright (c) 2010 ST-Ericsson SA
  4. *
  5. * Author: Peter Pearse <peter.pearse@arm.com>
  6. * Author: Linus Walleij <linus.walleij@stericsson.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59
  20. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. * The full GNU General Public License is in this distribution in the file
  23. * called COPYING.
  24. *
  25. * Documentation: ARM DDI 0196G == PL080
  26. * Documentation: ARM DDI 0218E == PL081
  27. * Documentation: S3C6410 User's Manual == PL080S
  28. *
  29. * PL080 & PL081 both have 16 sets of DMA signals that can be routed to any
  30. * channel.
  31. *
  32. * The PL080 has 8 channels available for simultaneous use, and the PL081
  33. * has only two channels. So on these DMA controllers the number of channels
  34. * and the number of incoming DMA signals are two totally different things.
  35. * It is usually not possible to theoretically handle all physical signals,
  36. * so a multiplexing scheme with possible denial of use is necessary.
  37. *
  38. * The PL080 has a dual bus master, PL081 has a single master.
  39. *
  40. * PL080S is a version modified by Samsung and used in S3C64xx SoCs.
  41. * It differs in following aspects:
  42. * - CH_CONFIG register at different offset,
  43. * - separate CH_CONTROL2 register for transfer size,
  44. * - bigger maximum transfer size,
  45. * - 8-word aligned LLI, instead of 4-word, due to extra CCTL2 word,
  46. * - no support for peripheral flow control.
  47. *
  48. * Memory to peripheral transfer may be visualized as
  49. * Get data from memory to DMAC
  50. * Until no data left
  51. * On burst request from peripheral
  52. * Destination burst from DMAC to peripheral
  53. * Clear burst request
  54. * Raise terminal count interrupt
  55. *
  56. * For peripherals with a FIFO:
  57. * Source burst size == half the depth of the peripheral FIFO
  58. * Destination burst size == the depth of the peripheral FIFO
  59. *
  60. * (Bursts are irrelevant for mem to mem transfers - there are no burst
  61. * signals, the DMA controller will simply facilitate its AHB master.)
  62. *
  63. * ASSUMES default (little) endianness for DMA transfers
  64. *
  65. * The PL08x has two flow control settings:
  66. * - DMAC flow control: the transfer size defines the number of transfers
  67. * which occur for the current LLI entry, and the DMAC raises TC at the
  68. * end of every LLI entry. Observed behaviour shows the DMAC listening
  69. * to both the BREQ and SREQ signals (contrary to documented),
  70. * transferring data if either is active. The LBREQ and LSREQ signals
  71. * are ignored.
  72. *
  73. * - Peripheral flow control: the transfer size is ignored (and should be
  74. * zero). The data is transferred from the current LLI entry, until
  75. * after the final transfer signalled by LBREQ or LSREQ. The DMAC
  76. * will then move to the next LLI entry. Unsupported by PL080S.
  77. */
  78. #include <linux/amba/bus.h>
  79. #include <linux/amba/pl08x.h>
  80. #include <linux/debugfs.h>
  81. #include <linux/delay.h>
  82. #include <linux/device.h>
  83. #include <linux/dmaengine.h>
  84. #include <linux/dmapool.h>
  85. #include <linux/dma-mapping.h>
  86. #include <linux/init.h>
  87. #include <linux/interrupt.h>
  88. #include <linux/module.h>
  89. #include <linux/pm_runtime.h>
  90. #include <linux/seq_file.h>
  91. #include <linux/slab.h>
  92. #include <linux/amba/pl080.h>
  93. #include "dmaengine.h"
  94. #include "virt-dma.h"
  95. #define DRIVER_NAME "pl08xdmac"
  96. static struct amba_driver pl08x_amba_driver;
  97. struct pl08x_driver_data;
  98. /**
  99. * struct vendor_data - vendor-specific config parameters for PL08x derivatives
  100. * @channels: the number of channels available in this variant
  101. * @dualmaster: whether this version supports dual AHB masters or not.
  102. * @nomadik: whether the channels have Nomadik security extension bits
  103. * that need to be checked for permission before use and some registers are
  104. * missing
  105. * @pl080s: whether this version is a PL080S, which has separate register and
  106. * LLI word for transfer size.
  107. */
  108. struct vendor_data {
  109. u8 config_offset;
  110. u8 channels;
  111. bool dualmaster;
  112. bool nomadik;
  113. bool pl080s;
  114. u32 max_transfer_size;
  115. };
  116. /**
  117. * struct pl08x_bus_data - information of source or destination
  118. * busses for a transfer
  119. * @addr: current address
  120. * @maxwidth: the maximum width of a transfer on this bus
  121. * @buswidth: the width of this bus in bytes: 1, 2 or 4
  122. */
  123. struct pl08x_bus_data {
  124. dma_addr_t addr;
  125. u8 maxwidth;
  126. u8 buswidth;
  127. };
  128. /**
  129. * struct pl08x_phy_chan - holder for the physical channels
  130. * @id: physical index to this channel
  131. * @lock: a lock to use when altering an instance of this struct
  132. * @serving: the virtual channel currently being served by this physical
  133. * channel
  134. * @locked: channel unavailable for the system, e.g. dedicated to secure
  135. * world
  136. */
  137. struct pl08x_phy_chan {
  138. unsigned int id;
  139. void __iomem *base;
  140. void __iomem *reg_config;
  141. spinlock_t lock;
  142. struct pl08x_dma_chan *serving;
  143. bool locked;
  144. };
  145. /**
  146. * struct pl08x_sg - structure containing data per sg
  147. * @src_addr: src address of sg
  148. * @dst_addr: dst address of sg
  149. * @len: transfer len in bytes
  150. * @node: node for txd's dsg_list
  151. */
  152. struct pl08x_sg {
  153. dma_addr_t src_addr;
  154. dma_addr_t dst_addr;
  155. size_t len;
  156. struct list_head node;
  157. };
  158. /**
  159. * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor
  160. * @vd: virtual DMA descriptor
  161. * @dsg_list: list of children sg's
  162. * @llis_bus: DMA memory address (physical) start for the LLIs
  163. * @llis_va: virtual memory address start for the LLIs
  164. * @cctl: control reg values for current txd
  165. * @ccfg: config reg values for current txd
  166. * @done: this marks completed descriptors, which should not have their
  167. * mux released.
  168. * @cyclic: indicate cyclic transfers
  169. */
  170. struct pl08x_txd {
  171. struct virt_dma_desc vd;
  172. struct list_head dsg_list;
  173. dma_addr_t llis_bus;
  174. u32 *llis_va;
  175. /* Default cctl value for LLIs */
  176. u32 cctl;
  177. /*
  178. * Settings to be put into the physical channel when we
  179. * trigger this txd. Other registers are in llis_va[0].
  180. */
  181. u32 ccfg;
  182. bool done;
  183. bool cyclic;
  184. };
  185. /**
  186. * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel
  187. * states
  188. * @PL08X_CHAN_IDLE: the channel is idle
  189. * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport
  190. * channel and is running a transfer on it
  191. * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport
  192. * channel, but the transfer is currently paused
  193. * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport
  194. * channel to become available (only pertains to memcpy channels)
  195. */
  196. enum pl08x_dma_chan_state {
  197. PL08X_CHAN_IDLE,
  198. PL08X_CHAN_RUNNING,
  199. PL08X_CHAN_PAUSED,
  200. PL08X_CHAN_WAITING,
  201. };
  202. /**
  203. * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel
  204. * @vc: wrappped virtual channel
  205. * @phychan: the physical channel utilized by this channel, if there is one
  206. * @name: name of channel
  207. * @cd: channel platform data
  208. * @runtime_addr: address for RX/TX according to the runtime config
  209. * @at: active transaction on this channel
  210. * @lock: a lock for this channel data
  211. * @host: a pointer to the host (internal use)
  212. * @state: whether the channel is idle, paused, running etc
  213. * @slave: whether this channel is a device (slave) or for memcpy
  214. * @signal: the physical DMA request signal which this channel is using
  215. * @mux_use: count of descriptors using this DMA request signal setting
  216. */
  217. struct pl08x_dma_chan {
  218. struct virt_dma_chan vc;
  219. struct pl08x_phy_chan *phychan;
  220. const char *name;
  221. const struct pl08x_channel_data *cd;
  222. struct dma_slave_config cfg;
  223. struct pl08x_txd *at;
  224. struct pl08x_driver_data *host;
  225. enum pl08x_dma_chan_state state;
  226. bool slave;
  227. int signal;
  228. unsigned mux_use;
  229. };
  230. /**
  231. * struct pl08x_driver_data - the local state holder for the PL08x
  232. * @slave: slave engine for this instance
  233. * @memcpy: memcpy engine for this instance
  234. * @base: virtual memory base (remapped) for the PL08x
  235. * @adev: the corresponding AMBA (PrimeCell) bus entry
  236. * @vd: vendor data for this PL08x variant
  237. * @pd: platform data passed in from the platform/machine
  238. * @phy_chans: array of data for the physical channels
  239. * @pool: a pool for the LLI descriptors
  240. * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI
  241. * fetches
  242. * @mem_buses: set to indicate memory transfers on AHB2.
  243. * @lock: a spinlock for this struct
  244. */
  245. struct pl08x_driver_data {
  246. struct dma_device slave;
  247. struct dma_device memcpy;
  248. void __iomem *base;
  249. struct amba_device *adev;
  250. const struct vendor_data *vd;
  251. struct pl08x_platform_data *pd;
  252. struct pl08x_phy_chan *phy_chans;
  253. struct dma_pool *pool;
  254. u8 lli_buses;
  255. u8 mem_buses;
  256. u8 lli_words;
  257. };
  258. /*
  259. * PL08X specific defines
  260. */
  261. /* The order of words in an LLI. */
  262. #define PL080_LLI_SRC 0
  263. #define PL080_LLI_DST 1
  264. #define PL080_LLI_LLI 2
  265. #define PL080_LLI_CCTL 3
  266. #define PL080S_LLI_CCTL2 4
  267. /* Total words in an LLI. */
  268. #define PL080_LLI_WORDS 4
  269. #define PL080S_LLI_WORDS 8
  270. /*
  271. * Number of LLIs in each LLI buffer allocated for one transfer
  272. * (maximum times we call dma_pool_alloc on this pool without freeing)
  273. */
  274. #define MAX_NUM_TSFR_LLIS 512
  275. #define PL08X_ALIGN 8
  276. static inline struct pl08x_dma_chan *to_pl08x_chan(struct dma_chan *chan)
  277. {
  278. return container_of(chan, struct pl08x_dma_chan, vc.chan);
  279. }
  280. static inline struct pl08x_txd *to_pl08x_txd(struct dma_async_tx_descriptor *tx)
  281. {
  282. return container_of(tx, struct pl08x_txd, vd.tx);
  283. }
  284. /*
  285. * Mux handling.
  286. *
  287. * This gives us the DMA request input to the PL08x primecell which the
  288. * peripheral described by the channel data will be routed to, possibly
  289. * via a board/SoC specific external MUX. One important point to note
  290. * here is that this does not depend on the physical channel.
  291. */
  292. static int pl08x_request_mux(struct pl08x_dma_chan *plchan)
  293. {
  294. const struct pl08x_platform_data *pd = plchan->host->pd;
  295. int ret;
  296. if (plchan->mux_use++ == 0 && pd->get_xfer_signal) {
  297. ret = pd->get_xfer_signal(plchan->cd);
  298. if (ret < 0) {
  299. plchan->mux_use = 0;
  300. return ret;
  301. }
  302. plchan->signal = ret;
  303. }
  304. return 0;
  305. }
  306. static void pl08x_release_mux(struct pl08x_dma_chan *plchan)
  307. {
  308. const struct pl08x_platform_data *pd = plchan->host->pd;
  309. if (plchan->signal >= 0) {
  310. WARN_ON(plchan->mux_use == 0);
  311. if (--plchan->mux_use == 0 && pd->put_xfer_signal) {
  312. pd->put_xfer_signal(plchan->cd, plchan->signal);
  313. plchan->signal = -1;
  314. }
  315. }
  316. }
  317. /*
  318. * Physical channel handling
  319. */
  320. /* Whether a certain channel is busy or not */
  321. static int pl08x_phy_channel_busy(struct pl08x_phy_chan *ch)
  322. {
  323. unsigned int val;
  324. val = readl(ch->reg_config);
  325. return val & PL080_CONFIG_ACTIVE;
  326. }
  327. static void pl08x_write_lli(struct pl08x_driver_data *pl08x,
  328. struct pl08x_phy_chan *phychan, const u32 *lli, u32 ccfg)
  329. {
  330. if (pl08x->vd->pl080s)
  331. dev_vdbg(&pl08x->adev->dev,
  332. "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, "
  333. "clli=0x%08x, cctl=0x%08x, cctl2=0x%08x, ccfg=0x%08x\n",
  334. phychan->id, lli[PL080_LLI_SRC], lli[PL080_LLI_DST],
  335. lli[PL080_LLI_LLI], lli[PL080_LLI_CCTL],
  336. lli[PL080S_LLI_CCTL2], ccfg);
  337. else
  338. dev_vdbg(&pl08x->adev->dev,
  339. "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, "
  340. "clli=0x%08x, cctl=0x%08x, ccfg=0x%08x\n",
  341. phychan->id, lli[PL080_LLI_SRC], lli[PL080_LLI_DST],
  342. lli[PL080_LLI_LLI], lli[PL080_LLI_CCTL], ccfg);
  343. writel_relaxed(lli[PL080_LLI_SRC], phychan->base + PL080_CH_SRC_ADDR);
  344. writel_relaxed(lli[PL080_LLI_DST], phychan->base + PL080_CH_DST_ADDR);
  345. writel_relaxed(lli[PL080_LLI_LLI], phychan->base + PL080_CH_LLI);
  346. writel_relaxed(lli[PL080_LLI_CCTL], phychan->base + PL080_CH_CONTROL);
  347. if (pl08x->vd->pl080s)
  348. writel_relaxed(lli[PL080S_LLI_CCTL2],
  349. phychan->base + PL080S_CH_CONTROL2);
  350. writel(ccfg, phychan->reg_config);
  351. }
  352. /*
  353. * Set the initial DMA register values i.e. those for the first LLI
  354. * The next LLI pointer and the configuration interrupt bit have
  355. * been set when the LLIs were constructed. Poke them into the hardware
  356. * and start the transfer.
  357. */
  358. static void pl08x_start_next_txd(struct pl08x_dma_chan *plchan)
  359. {
  360. struct pl08x_driver_data *pl08x = plchan->host;
  361. struct pl08x_phy_chan *phychan = plchan->phychan;
  362. struct virt_dma_desc *vd = vchan_next_desc(&plchan->vc);
  363. struct pl08x_txd *txd = to_pl08x_txd(&vd->tx);
  364. u32 val;
  365. list_del(&txd->vd.node);
  366. plchan->at = txd;
  367. /* Wait for channel inactive */
  368. while (pl08x_phy_channel_busy(phychan))
  369. cpu_relax();
  370. pl08x_write_lli(pl08x, phychan, &txd->llis_va[0], txd->ccfg);
  371. /* Enable the DMA channel */
  372. /* Do not access config register until channel shows as disabled */
  373. while (readl(pl08x->base + PL080_EN_CHAN) & (1 << phychan->id))
  374. cpu_relax();
  375. /* Do not access config register until channel shows as inactive */
  376. val = readl(phychan->reg_config);
  377. while ((val & PL080_CONFIG_ACTIVE) || (val & PL080_CONFIG_ENABLE))
  378. val = readl(phychan->reg_config);
  379. writel(val | PL080_CONFIG_ENABLE, phychan->reg_config);
  380. }
  381. /*
  382. * Pause the channel by setting the HALT bit.
  383. *
  384. * For M->P transfers, pause the DMAC first and then stop the peripheral -
  385. * the FIFO can only drain if the peripheral is still requesting data.
  386. * (note: this can still timeout if the DMAC FIFO never drains of data.)
  387. *
  388. * For P->M transfers, disable the peripheral first to stop it filling
  389. * the DMAC FIFO, and then pause the DMAC.
  390. */
  391. static void pl08x_pause_phy_chan(struct pl08x_phy_chan *ch)
  392. {
  393. u32 val;
  394. int timeout;
  395. /* Set the HALT bit and wait for the FIFO to drain */
  396. val = readl(ch->reg_config);
  397. val |= PL080_CONFIG_HALT;
  398. writel(val, ch->reg_config);
  399. /* Wait for channel inactive */
  400. for (timeout = 1000; timeout; timeout--) {
  401. if (!pl08x_phy_channel_busy(ch))
  402. break;
  403. udelay(1);
  404. }
  405. if (pl08x_phy_channel_busy(ch))
  406. pr_err("pl08x: channel%u timeout waiting for pause\n", ch->id);
  407. }
  408. static void pl08x_resume_phy_chan(struct pl08x_phy_chan *ch)
  409. {
  410. u32 val;
  411. /* Clear the HALT bit */
  412. val = readl(ch->reg_config);
  413. val &= ~PL080_CONFIG_HALT;
  414. writel(val, ch->reg_config);
  415. }
  416. /*
  417. * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and
  418. * clears any pending interrupt status. This should not be used for
  419. * an on-going transfer, but as a method of shutting down a channel
  420. * (eg, when it's no longer used) or terminating a transfer.
  421. */
  422. static void pl08x_terminate_phy_chan(struct pl08x_driver_data *pl08x,
  423. struct pl08x_phy_chan *ch)
  424. {
  425. u32 val = readl(ch->reg_config);
  426. val &= ~(PL080_CONFIG_ENABLE | PL080_CONFIG_ERR_IRQ_MASK |
  427. PL080_CONFIG_TC_IRQ_MASK);
  428. writel(val, ch->reg_config);
  429. writel(1 << ch->id, pl08x->base + PL080_ERR_CLEAR);
  430. writel(1 << ch->id, pl08x->base + PL080_TC_CLEAR);
  431. }
  432. static inline u32 get_bytes_in_cctl(u32 cctl)
  433. {
  434. /* The source width defines the number of bytes */
  435. u32 bytes = cctl & PL080_CONTROL_TRANSFER_SIZE_MASK;
  436. cctl &= PL080_CONTROL_SWIDTH_MASK;
  437. switch (cctl >> PL080_CONTROL_SWIDTH_SHIFT) {
  438. case PL080_WIDTH_8BIT:
  439. break;
  440. case PL080_WIDTH_16BIT:
  441. bytes *= 2;
  442. break;
  443. case PL080_WIDTH_32BIT:
  444. bytes *= 4;
  445. break;
  446. }
  447. return bytes;
  448. }
  449. static inline u32 get_bytes_in_cctl_pl080s(u32 cctl, u32 cctl1)
  450. {
  451. /* The source width defines the number of bytes */
  452. u32 bytes = cctl1 & PL080S_CONTROL_TRANSFER_SIZE_MASK;
  453. cctl &= PL080_CONTROL_SWIDTH_MASK;
  454. switch (cctl >> PL080_CONTROL_SWIDTH_SHIFT) {
  455. case PL080_WIDTH_8BIT:
  456. break;
  457. case PL080_WIDTH_16BIT:
  458. bytes *= 2;
  459. break;
  460. case PL080_WIDTH_32BIT:
  461. bytes *= 4;
  462. break;
  463. }
  464. return bytes;
  465. }
  466. /* The channel should be paused when calling this */
  467. static u32 pl08x_getbytes_chan(struct pl08x_dma_chan *plchan)
  468. {
  469. struct pl08x_driver_data *pl08x = plchan->host;
  470. const u32 *llis_va, *llis_va_limit;
  471. struct pl08x_phy_chan *ch;
  472. dma_addr_t llis_bus;
  473. struct pl08x_txd *txd;
  474. u32 llis_max_words;
  475. size_t bytes;
  476. u32 clli;
  477. ch = plchan->phychan;
  478. txd = plchan->at;
  479. if (!ch || !txd)
  480. return 0;
  481. /*
  482. * Follow the LLIs to get the number of remaining
  483. * bytes in the currently active transaction.
  484. */
  485. clli = readl(ch->base + PL080_CH_LLI) & ~PL080_LLI_LM_AHB2;
  486. /* First get the remaining bytes in the active transfer */
  487. if (pl08x->vd->pl080s)
  488. bytes = get_bytes_in_cctl_pl080s(
  489. readl(ch->base + PL080_CH_CONTROL),
  490. readl(ch->base + PL080S_CH_CONTROL2));
  491. else
  492. bytes = get_bytes_in_cctl(readl(ch->base + PL080_CH_CONTROL));
  493. if (!clli)
  494. return bytes;
  495. llis_va = txd->llis_va;
  496. llis_bus = txd->llis_bus;
  497. llis_max_words = pl08x->lli_words * MAX_NUM_TSFR_LLIS;
  498. BUG_ON(clli < llis_bus || clli >= llis_bus +
  499. sizeof(u32) * llis_max_words);
  500. /*
  501. * Locate the next LLI - as this is an array,
  502. * it's simple maths to find.
  503. */
  504. llis_va += (clli - llis_bus) / sizeof(u32);
  505. llis_va_limit = llis_va + llis_max_words;
  506. for (; llis_va < llis_va_limit; llis_va += pl08x->lli_words) {
  507. if (pl08x->vd->pl080s)
  508. bytes += get_bytes_in_cctl_pl080s(
  509. llis_va[PL080_LLI_CCTL],
  510. llis_va[PL080S_LLI_CCTL2]);
  511. else
  512. bytes += get_bytes_in_cctl(llis_va[PL080_LLI_CCTL]);
  513. /*
  514. * A LLI pointer going backward terminates the LLI list
  515. */
  516. if (llis_va[PL080_LLI_LLI] <= clli)
  517. break;
  518. }
  519. return bytes;
  520. }
  521. /*
  522. * Allocate a physical channel for a virtual channel
  523. *
  524. * Try to locate a physical channel to be used for this transfer. If all
  525. * are taken return NULL and the requester will have to cope by using
  526. * some fallback PIO mode or retrying later.
  527. */
  528. static struct pl08x_phy_chan *
  529. pl08x_get_phy_channel(struct pl08x_driver_data *pl08x,
  530. struct pl08x_dma_chan *virt_chan)
  531. {
  532. struct pl08x_phy_chan *ch = NULL;
  533. unsigned long flags;
  534. int i;
  535. for (i = 0; i < pl08x->vd->channels; i++) {
  536. ch = &pl08x->phy_chans[i];
  537. spin_lock_irqsave(&ch->lock, flags);
  538. if (!ch->locked && !ch->serving) {
  539. ch->serving = virt_chan;
  540. spin_unlock_irqrestore(&ch->lock, flags);
  541. break;
  542. }
  543. spin_unlock_irqrestore(&ch->lock, flags);
  544. }
  545. if (i == pl08x->vd->channels) {
  546. /* No physical channel available, cope with it */
  547. return NULL;
  548. }
  549. return ch;
  550. }
  551. /* Mark the physical channel as free. Note, this write is atomic. */
  552. static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x,
  553. struct pl08x_phy_chan *ch)
  554. {
  555. ch->serving = NULL;
  556. }
  557. /*
  558. * Try to allocate a physical channel. When successful, assign it to
  559. * this virtual channel, and initiate the next descriptor. The
  560. * virtual channel lock must be held at this point.
  561. */
  562. static void pl08x_phy_alloc_and_start(struct pl08x_dma_chan *plchan)
  563. {
  564. struct pl08x_driver_data *pl08x = plchan->host;
  565. struct pl08x_phy_chan *ch;
  566. ch = pl08x_get_phy_channel(pl08x, plchan);
  567. if (!ch) {
  568. dev_dbg(&pl08x->adev->dev, "no physical channel available for xfer on %s\n", plchan->name);
  569. plchan->state = PL08X_CHAN_WAITING;
  570. return;
  571. }
  572. dev_dbg(&pl08x->adev->dev, "allocated physical channel %d for xfer on %s\n",
  573. ch->id, plchan->name);
  574. plchan->phychan = ch;
  575. plchan->state = PL08X_CHAN_RUNNING;
  576. pl08x_start_next_txd(plchan);
  577. }
  578. static void pl08x_phy_reassign_start(struct pl08x_phy_chan *ch,
  579. struct pl08x_dma_chan *plchan)
  580. {
  581. struct pl08x_driver_data *pl08x = plchan->host;
  582. dev_dbg(&pl08x->adev->dev, "reassigned physical channel %d for xfer on %s\n",
  583. ch->id, plchan->name);
  584. /*
  585. * We do this without taking the lock; we're really only concerned
  586. * about whether this pointer is NULL or not, and we're guaranteed
  587. * that this will only be called when it _already_ is non-NULL.
  588. */
  589. ch->serving = plchan;
  590. plchan->phychan = ch;
  591. plchan->state = PL08X_CHAN_RUNNING;
  592. pl08x_start_next_txd(plchan);
  593. }
  594. /*
  595. * Free a physical DMA channel, potentially reallocating it to another
  596. * virtual channel if we have any pending.
  597. */
  598. static void pl08x_phy_free(struct pl08x_dma_chan *plchan)
  599. {
  600. struct pl08x_driver_data *pl08x = plchan->host;
  601. struct pl08x_dma_chan *p, *next;
  602. retry:
  603. next = NULL;
  604. /* Find a waiting virtual channel for the next transfer. */
  605. list_for_each_entry(p, &pl08x->memcpy.channels, vc.chan.device_node)
  606. if (p->state == PL08X_CHAN_WAITING) {
  607. next = p;
  608. break;
  609. }
  610. if (!next) {
  611. list_for_each_entry(p, &pl08x->slave.channels, vc.chan.device_node)
  612. if (p->state == PL08X_CHAN_WAITING) {
  613. next = p;
  614. break;
  615. }
  616. }
  617. /* Ensure that the physical channel is stopped */
  618. pl08x_terminate_phy_chan(pl08x, plchan->phychan);
  619. if (next) {
  620. bool success;
  621. /*
  622. * Eww. We know this isn't going to deadlock
  623. * but lockdep probably doesn't.
  624. */
  625. spin_lock(&next->vc.lock);
  626. /* Re-check the state now that we have the lock */
  627. success = next->state == PL08X_CHAN_WAITING;
  628. if (success)
  629. pl08x_phy_reassign_start(plchan->phychan, next);
  630. spin_unlock(&next->vc.lock);
  631. /* If the state changed, try to find another channel */
  632. if (!success)
  633. goto retry;
  634. } else {
  635. /* No more jobs, so free up the physical channel */
  636. pl08x_put_phy_channel(pl08x, plchan->phychan);
  637. }
  638. plchan->phychan = NULL;
  639. plchan->state = PL08X_CHAN_IDLE;
  640. }
  641. /*
  642. * LLI handling
  643. */
  644. static inline unsigned int pl08x_get_bytes_for_cctl(unsigned int coded)
  645. {
  646. switch (coded) {
  647. case PL080_WIDTH_8BIT:
  648. return 1;
  649. case PL080_WIDTH_16BIT:
  650. return 2;
  651. case PL080_WIDTH_32BIT:
  652. return 4;
  653. default:
  654. break;
  655. }
  656. BUG();
  657. return 0;
  658. }
  659. static inline u32 pl08x_cctl_bits(u32 cctl, u8 srcwidth, u8 dstwidth,
  660. size_t tsize)
  661. {
  662. u32 retbits = cctl;
  663. /* Remove all src, dst and transfer size bits */
  664. retbits &= ~PL080_CONTROL_DWIDTH_MASK;
  665. retbits &= ~PL080_CONTROL_SWIDTH_MASK;
  666. retbits &= ~PL080_CONTROL_TRANSFER_SIZE_MASK;
  667. /* Then set the bits according to the parameters */
  668. switch (srcwidth) {
  669. case 1:
  670. retbits |= PL080_WIDTH_8BIT << PL080_CONTROL_SWIDTH_SHIFT;
  671. break;
  672. case 2:
  673. retbits |= PL080_WIDTH_16BIT << PL080_CONTROL_SWIDTH_SHIFT;
  674. break;
  675. case 4:
  676. retbits |= PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT;
  677. break;
  678. default:
  679. BUG();
  680. break;
  681. }
  682. switch (dstwidth) {
  683. case 1:
  684. retbits |= PL080_WIDTH_8BIT << PL080_CONTROL_DWIDTH_SHIFT;
  685. break;
  686. case 2:
  687. retbits |= PL080_WIDTH_16BIT << PL080_CONTROL_DWIDTH_SHIFT;
  688. break;
  689. case 4:
  690. retbits |= PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT;
  691. break;
  692. default:
  693. BUG();
  694. break;
  695. }
  696. tsize &= PL080_CONTROL_TRANSFER_SIZE_MASK;
  697. retbits |= tsize << PL080_CONTROL_TRANSFER_SIZE_SHIFT;
  698. return retbits;
  699. }
  700. struct pl08x_lli_build_data {
  701. struct pl08x_txd *txd;
  702. struct pl08x_bus_data srcbus;
  703. struct pl08x_bus_data dstbus;
  704. size_t remainder;
  705. u32 lli_bus;
  706. };
  707. /*
  708. * Autoselect a master bus to use for the transfer. Slave will be the chosen as
  709. * victim in case src & dest are not similarly aligned. i.e. If after aligning
  710. * masters address with width requirements of transfer (by sending few byte by
  711. * byte data), slave is still not aligned, then its width will be reduced to
  712. * BYTE.
  713. * - prefers the destination bus if both available
  714. * - prefers bus with fixed address (i.e. peripheral)
  715. */
  716. static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd,
  717. struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl)
  718. {
  719. if (!(cctl & PL080_CONTROL_DST_INCR)) {
  720. *mbus = &bd->dstbus;
  721. *sbus = &bd->srcbus;
  722. } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {
  723. *mbus = &bd->srcbus;
  724. *sbus = &bd->dstbus;
  725. } else {
  726. if (bd->dstbus.buswidth >= bd->srcbus.buswidth) {
  727. *mbus = &bd->dstbus;
  728. *sbus = &bd->srcbus;
  729. } else {
  730. *mbus = &bd->srcbus;
  731. *sbus = &bd->dstbus;
  732. }
  733. }
  734. }
  735. /*
  736. * Fills in one LLI for a certain transfer descriptor and advance the counter
  737. */
  738. static void pl08x_fill_lli_for_desc(struct pl08x_driver_data *pl08x,
  739. struct pl08x_lli_build_data *bd,
  740. int num_llis, int len, u32 cctl, u32 cctl2)
  741. {
  742. u32 offset = num_llis * pl08x->lli_words;
  743. u32 *llis_va = bd->txd->llis_va + offset;
  744. dma_addr_t llis_bus = bd->txd->llis_bus;
  745. BUG_ON(num_llis >= MAX_NUM_TSFR_LLIS);
  746. /* Advance the offset to next LLI. */
  747. offset += pl08x->lli_words;
  748. llis_va[PL080_LLI_SRC] = bd->srcbus.addr;
  749. llis_va[PL080_LLI_DST] = bd->dstbus.addr;
  750. llis_va[PL080_LLI_LLI] = (llis_bus + sizeof(u32) * offset);
  751. llis_va[PL080_LLI_LLI] |= bd->lli_bus;
  752. llis_va[PL080_LLI_CCTL] = cctl;
  753. if (pl08x->vd->pl080s)
  754. llis_va[PL080S_LLI_CCTL2] = cctl2;
  755. if (cctl & PL080_CONTROL_SRC_INCR)
  756. bd->srcbus.addr += len;
  757. if (cctl & PL080_CONTROL_DST_INCR)
  758. bd->dstbus.addr += len;
  759. BUG_ON(bd->remainder < len);
  760. bd->remainder -= len;
  761. }
  762. static inline void prep_byte_width_lli(struct pl08x_driver_data *pl08x,
  763. struct pl08x_lli_build_data *bd, u32 *cctl, u32 len,
  764. int num_llis, size_t *total_bytes)
  765. {
  766. *cctl = pl08x_cctl_bits(*cctl, 1, 1, len);
  767. pl08x_fill_lli_for_desc(pl08x, bd, num_llis, len, *cctl, len);
  768. (*total_bytes) += len;
  769. }
  770. #ifdef VERBOSE_DEBUG
  771. static void pl08x_dump_lli(struct pl08x_driver_data *pl08x,
  772. const u32 *llis_va, int num_llis)
  773. {
  774. int i;
  775. if (pl08x->vd->pl080s) {
  776. dev_vdbg(&pl08x->adev->dev,
  777. "%-3s %-9s %-10s %-10s %-10s %-10s %s\n",
  778. "lli", "", "csrc", "cdst", "clli", "cctl", "cctl2");
  779. for (i = 0; i < num_llis; i++) {
  780. dev_vdbg(&pl08x->adev->dev,
  781. "%3d @%p: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  782. i, llis_va, llis_va[PL080_LLI_SRC],
  783. llis_va[PL080_LLI_DST], llis_va[PL080_LLI_LLI],
  784. llis_va[PL080_LLI_CCTL],
  785. llis_va[PL080S_LLI_CCTL2]);
  786. llis_va += pl08x->lli_words;
  787. }
  788. } else {
  789. dev_vdbg(&pl08x->adev->dev,
  790. "%-3s %-9s %-10s %-10s %-10s %s\n",
  791. "lli", "", "csrc", "cdst", "clli", "cctl");
  792. for (i = 0; i < num_llis; i++) {
  793. dev_vdbg(&pl08x->adev->dev,
  794. "%3d @%p: 0x%08x 0x%08x 0x%08x 0x%08x\n",
  795. i, llis_va, llis_va[PL080_LLI_SRC],
  796. llis_va[PL080_LLI_DST], llis_va[PL080_LLI_LLI],
  797. llis_va[PL080_LLI_CCTL]);
  798. llis_va += pl08x->lli_words;
  799. }
  800. }
  801. }
  802. #else
  803. static inline void pl08x_dump_lli(struct pl08x_driver_data *pl08x,
  804. const u32 *llis_va, int num_llis) {}
  805. #endif
  806. /*
  807. * This fills in the table of LLIs for the transfer descriptor
  808. * Note that we assume we never have to change the burst sizes
  809. * Return 0 for error
  810. */
  811. static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
  812. struct pl08x_txd *txd)
  813. {
  814. struct pl08x_bus_data *mbus, *sbus;
  815. struct pl08x_lli_build_data bd;
  816. int num_llis = 0;
  817. u32 cctl, early_bytes = 0;
  818. size_t max_bytes_per_lli, total_bytes;
  819. u32 *llis_va, *last_lli;
  820. struct pl08x_sg *dsg;
  821. txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, &txd->llis_bus);
  822. if (!txd->llis_va) {
  823. dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__);
  824. return 0;
  825. }
  826. bd.txd = txd;
  827. bd.lli_bus = (pl08x->lli_buses & PL08X_AHB2) ? PL080_LLI_LM_AHB2 : 0;
  828. cctl = txd->cctl;
  829. /* Find maximum width of the source bus */
  830. bd.srcbus.maxwidth =
  831. pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_SWIDTH_MASK) >>
  832. PL080_CONTROL_SWIDTH_SHIFT);
  833. /* Find maximum width of the destination bus */
  834. bd.dstbus.maxwidth =
  835. pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_DWIDTH_MASK) >>
  836. PL080_CONTROL_DWIDTH_SHIFT);
  837. list_for_each_entry(dsg, &txd->dsg_list, node) {
  838. total_bytes = 0;
  839. cctl = txd->cctl;
  840. bd.srcbus.addr = dsg->src_addr;
  841. bd.dstbus.addr = dsg->dst_addr;
  842. bd.remainder = dsg->len;
  843. bd.srcbus.buswidth = bd.srcbus.maxwidth;
  844. bd.dstbus.buswidth = bd.dstbus.maxwidth;
  845. pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl);
  846. dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu\n",
  847. bd.srcbus.addr, cctl & PL080_CONTROL_SRC_INCR ? "+" : "",
  848. bd.srcbus.buswidth,
  849. bd.dstbus.addr, cctl & PL080_CONTROL_DST_INCR ? "+" : "",
  850. bd.dstbus.buswidth,
  851. bd.remainder);
  852. dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n",
  853. mbus == &bd.srcbus ? "src" : "dst",
  854. sbus == &bd.srcbus ? "src" : "dst");
  855. /*
  856. * Zero length is only allowed if all these requirements are
  857. * met:
  858. * - flow controller is peripheral.
  859. * - src.addr is aligned to src.width
  860. * - dst.addr is aligned to dst.width
  861. *
  862. * sg_len == 1 should be true, as there can be two cases here:
  863. *
  864. * - Memory addresses are contiguous and are not scattered.
  865. * Here, Only one sg will be passed by user driver, with
  866. * memory address and zero length. We pass this to controller
  867. * and after the transfer it will receive the last burst
  868. * request from peripheral and so transfer finishes.
  869. *
  870. * - Memory addresses are scattered and are not contiguous.
  871. * Here, Obviously as DMA controller doesn't know when a lli's
  872. * transfer gets over, it can't load next lli. So in this
  873. * case, there has to be an assumption that only one lli is
  874. * supported. Thus, we can't have scattered addresses.
  875. */
  876. if (!bd.remainder) {
  877. u32 fc = (txd->ccfg & PL080_CONFIG_FLOW_CONTROL_MASK) >>
  878. PL080_CONFIG_FLOW_CONTROL_SHIFT;
  879. if (!((fc >= PL080_FLOW_SRC2DST_DST) &&
  880. (fc <= PL080_FLOW_SRC2DST_SRC))) {
  881. dev_err(&pl08x->adev->dev, "%s sg len can't be zero",
  882. __func__);
  883. return 0;
  884. }
  885. if ((bd.srcbus.addr % bd.srcbus.buswidth) ||
  886. (bd.dstbus.addr % bd.dstbus.buswidth)) {
  887. dev_err(&pl08x->adev->dev,
  888. "%s src & dst address must be aligned to src"
  889. " & dst width if peripheral is flow controller",
  890. __func__);
  891. return 0;
  892. }
  893. cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,
  894. bd.dstbus.buswidth, 0);
  895. pl08x_fill_lli_for_desc(pl08x, &bd, num_llis++,
  896. 0, cctl, 0);
  897. break;
  898. }
  899. /*
  900. * Send byte by byte for following cases
  901. * - Less than a bus width available
  902. * - until master bus is aligned
  903. */
  904. if (bd.remainder < mbus->buswidth)
  905. early_bytes = bd.remainder;
  906. else if ((mbus->addr) % (mbus->buswidth)) {
  907. early_bytes = mbus->buswidth - (mbus->addr) %
  908. (mbus->buswidth);
  909. if ((bd.remainder - early_bytes) < mbus->buswidth)
  910. early_bytes = bd.remainder;
  911. }
  912. if (early_bytes) {
  913. dev_vdbg(&pl08x->adev->dev,
  914. "%s byte width LLIs (remain 0x%08x)\n",
  915. __func__, bd.remainder);
  916. prep_byte_width_lli(pl08x, &bd, &cctl, early_bytes,
  917. num_llis++, &total_bytes);
  918. }
  919. if (bd.remainder) {
  920. /*
  921. * Master now aligned
  922. * - if slave is not then we must set its width down
  923. */
  924. if (sbus->addr % sbus->buswidth) {
  925. dev_dbg(&pl08x->adev->dev,
  926. "%s set down bus width to one byte\n",
  927. __func__);
  928. sbus->buswidth = 1;
  929. }
  930. /*
  931. * Bytes transferred = tsize * src width, not
  932. * MIN(buswidths)
  933. */
  934. max_bytes_per_lli = bd.srcbus.buswidth *
  935. pl08x->vd->max_transfer_size;
  936. dev_vdbg(&pl08x->adev->dev,
  937. "%s max bytes per lli = %zu\n",
  938. __func__, max_bytes_per_lli);
  939. /*
  940. * Make largest possible LLIs until less than one bus
  941. * width left
  942. */
  943. while (bd.remainder > (mbus->buswidth - 1)) {
  944. size_t lli_len, tsize, width;
  945. /*
  946. * If enough left try to send max possible,
  947. * otherwise try to send the remainder
  948. */
  949. lli_len = min(bd.remainder, max_bytes_per_lli);
  950. /*
  951. * Check against maximum bus alignment:
  952. * Calculate actual transfer size in relation to
  953. * bus width an get a maximum remainder of the
  954. * highest bus width - 1
  955. */
  956. width = max(mbus->buswidth, sbus->buswidth);
  957. lli_len = (lli_len / width) * width;
  958. tsize = lli_len / bd.srcbus.buswidth;
  959. dev_vdbg(&pl08x->adev->dev,
  960. "%s fill lli with single lli chunk of "
  961. "size 0x%08zx (remainder 0x%08zx)\n",
  962. __func__, lli_len, bd.remainder);
  963. cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,
  964. bd.dstbus.buswidth, tsize);
  965. pl08x_fill_lli_for_desc(pl08x, &bd, num_llis++,
  966. lli_len, cctl, tsize);
  967. total_bytes += lli_len;
  968. }
  969. /*
  970. * Send any odd bytes
  971. */
  972. if (bd.remainder) {
  973. dev_vdbg(&pl08x->adev->dev,
  974. "%s align with boundary, send odd bytes (remain %zu)\n",
  975. __func__, bd.remainder);
  976. prep_byte_width_lli(pl08x, &bd, &cctl,
  977. bd.remainder, num_llis++, &total_bytes);
  978. }
  979. }
  980. if (total_bytes != dsg->len) {
  981. dev_err(&pl08x->adev->dev,
  982. "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n",
  983. __func__, total_bytes, dsg->len);
  984. return 0;
  985. }
  986. if (num_llis >= MAX_NUM_TSFR_LLIS) {
  987. dev_err(&pl08x->adev->dev,
  988. "%s need to increase MAX_NUM_TSFR_LLIS from 0x%08x\n",
  989. __func__, MAX_NUM_TSFR_LLIS);
  990. return 0;
  991. }
  992. }
  993. llis_va = txd->llis_va;
  994. last_lli = llis_va + (num_llis - 1) * pl08x->lli_words;
  995. if (txd->cyclic) {
  996. /* Link back to the first LLI. */
  997. last_lli[PL080_LLI_LLI] = txd->llis_bus | bd.lli_bus;
  998. } else {
  999. /* The final LLI terminates the LLI. */
  1000. last_lli[PL080_LLI_LLI] = 0;
  1001. /* The final LLI element shall also fire an interrupt. */
  1002. last_lli[PL080_LLI_CCTL] |= PL080_CONTROL_TC_IRQ_EN;
  1003. }
  1004. pl08x_dump_lli(pl08x, llis_va, num_llis);
  1005. return num_llis;
  1006. }
  1007. static void pl08x_free_txd(struct pl08x_driver_data *pl08x,
  1008. struct pl08x_txd *txd)
  1009. {
  1010. struct pl08x_sg *dsg, *_dsg;
  1011. if (txd->llis_va)
  1012. dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus);
  1013. list_for_each_entry_safe(dsg, _dsg, &txd->dsg_list, node) {
  1014. list_del(&dsg->node);
  1015. kfree(dsg);
  1016. }
  1017. kfree(txd);
  1018. }
  1019. static void pl08x_unmap_buffers(struct pl08x_txd *txd)
  1020. {
  1021. struct device *dev = txd->vd.tx.chan->device->dev;
  1022. struct pl08x_sg *dsg;
  1023. if (!(txd->vd.tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
  1024. if (txd->vd.tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE)
  1025. list_for_each_entry(dsg, &txd->dsg_list, node)
  1026. dma_unmap_single(dev, dsg->src_addr, dsg->len,
  1027. DMA_TO_DEVICE);
  1028. else {
  1029. list_for_each_entry(dsg, &txd->dsg_list, node)
  1030. dma_unmap_page(dev, dsg->src_addr, dsg->len,
  1031. DMA_TO_DEVICE);
  1032. }
  1033. }
  1034. if (!(txd->vd.tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
  1035. if (txd->vd.tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE)
  1036. list_for_each_entry(dsg, &txd->dsg_list, node)
  1037. dma_unmap_single(dev, dsg->dst_addr, dsg->len,
  1038. DMA_FROM_DEVICE);
  1039. else
  1040. list_for_each_entry(dsg, &txd->dsg_list, node)
  1041. dma_unmap_page(dev, dsg->dst_addr, dsg->len,
  1042. DMA_FROM_DEVICE);
  1043. }
  1044. }
  1045. static void pl08x_desc_free(struct virt_dma_desc *vd)
  1046. {
  1047. struct pl08x_txd *txd = to_pl08x_txd(&vd->tx);
  1048. struct pl08x_dma_chan *plchan = to_pl08x_chan(vd->tx.chan);
  1049. if (!plchan->slave)
  1050. pl08x_unmap_buffers(txd);
  1051. if (!txd->done)
  1052. pl08x_release_mux(plchan);
  1053. pl08x_free_txd(plchan->host, txd);
  1054. }
  1055. static void pl08x_free_txd_list(struct pl08x_driver_data *pl08x,
  1056. struct pl08x_dma_chan *plchan)
  1057. {
  1058. LIST_HEAD(head);
  1059. vchan_get_all_descriptors(&plchan->vc, &head);
  1060. vchan_dma_desc_free_list(&plchan->vc, &head);
  1061. }
  1062. /*
  1063. * The DMA ENGINE API
  1064. */
  1065. static int pl08x_alloc_chan_resources(struct dma_chan *chan)
  1066. {
  1067. return 0;
  1068. }
  1069. static void pl08x_free_chan_resources(struct dma_chan *chan)
  1070. {
  1071. /* Ensure all queued descriptors are freed */
  1072. vchan_free_chan_resources(to_virt_chan(chan));
  1073. }
  1074. static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt(
  1075. struct dma_chan *chan, unsigned long flags)
  1076. {
  1077. struct dma_async_tx_descriptor *retval = NULL;
  1078. return retval;
  1079. }
  1080. /*
  1081. * Code accessing dma_async_is_complete() in a tight loop may give problems.
  1082. * If slaves are relying on interrupts to signal completion this function
  1083. * must not be called with interrupts disabled.
  1084. */
  1085. static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan,
  1086. dma_cookie_t cookie, struct dma_tx_state *txstate)
  1087. {
  1088. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1089. struct virt_dma_desc *vd;
  1090. unsigned long flags;
  1091. enum dma_status ret;
  1092. size_t bytes = 0;
  1093. ret = dma_cookie_status(chan, cookie, txstate);
  1094. if (ret == DMA_SUCCESS)
  1095. return ret;
  1096. /*
  1097. * There's no point calculating the residue if there's
  1098. * no txstate to store the value.
  1099. */
  1100. if (!txstate) {
  1101. if (plchan->state == PL08X_CHAN_PAUSED)
  1102. ret = DMA_PAUSED;
  1103. return ret;
  1104. }
  1105. spin_lock_irqsave(&plchan->vc.lock, flags);
  1106. ret = dma_cookie_status(chan, cookie, txstate);
  1107. if (ret != DMA_SUCCESS) {
  1108. vd = vchan_find_desc(&plchan->vc, cookie);
  1109. if (vd) {
  1110. /* On the issued list, so hasn't been processed yet */
  1111. struct pl08x_txd *txd = to_pl08x_txd(&vd->tx);
  1112. struct pl08x_sg *dsg;
  1113. list_for_each_entry(dsg, &txd->dsg_list, node)
  1114. bytes += dsg->len;
  1115. } else {
  1116. bytes = pl08x_getbytes_chan(plchan);
  1117. }
  1118. }
  1119. spin_unlock_irqrestore(&plchan->vc.lock, flags);
  1120. /*
  1121. * This cookie not complete yet
  1122. * Get number of bytes left in the active transactions and queue
  1123. */
  1124. dma_set_residue(txstate, bytes);
  1125. if (plchan->state == PL08X_CHAN_PAUSED && ret == DMA_IN_PROGRESS)
  1126. ret = DMA_PAUSED;
  1127. /* Whether waiting or running, we're in progress */
  1128. return ret;
  1129. }
  1130. /* PrimeCell DMA extension */
  1131. struct burst_table {
  1132. u32 burstwords;
  1133. u32 reg;
  1134. };
  1135. static const struct burst_table burst_sizes[] = {
  1136. {
  1137. .burstwords = 256,
  1138. .reg = PL080_BSIZE_256,
  1139. },
  1140. {
  1141. .burstwords = 128,
  1142. .reg = PL080_BSIZE_128,
  1143. },
  1144. {
  1145. .burstwords = 64,
  1146. .reg = PL080_BSIZE_64,
  1147. },
  1148. {
  1149. .burstwords = 32,
  1150. .reg = PL080_BSIZE_32,
  1151. },
  1152. {
  1153. .burstwords = 16,
  1154. .reg = PL080_BSIZE_16,
  1155. },
  1156. {
  1157. .burstwords = 8,
  1158. .reg = PL080_BSIZE_8,
  1159. },
  1160. {
  1161. .burstwords = 4,
  1162. .reg = PL080_BSIZE_4,
  1163. },
  1164. {
  1165. .burstwords = 0,
  1166. .reg = PL080_BSIZE_1,
  1167. },
  1168. };
  1169. /*
  1170. * Given the source and destination available bus masks, select which
  1171. * will be routed to each port. We try to have source and destination
  1172. * on separate ports, but always respect the allowable settings.
  1173. */
  1174. static u32 pl08x_select_bus(u8 src, u8 dst)
  1175. {
  1176. u32 cctl = 0;
  1177. if (!(dst & PL08X_AHB1) || ((dst & PL08X_AHB2) && (src & PL08X_AHB1)))
  1178. cctl |= PL080_CONTROL_DST_AHB2;
  1179. if (!(src & PL08X_AHB1) || ((src & PL08X_AHB2) && !(dst & PL08X_AHB2)))
  1180. cctl |= PL080_CONTROL_SRC_AHB2;
  1181. return cctl;
  1182. }
  1183. static u32 pl08x_cctl(u32 cctl)
  1184. {
  1185. cctl &= ~(PL080_CONTROL_SRC_AHB2 | PL080_CONTROL_DST_AHB2 |
  1186. PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR |
  1187. PL080_CONTROL_PROT_MASK);
  1188. /* Access the cell in privileged mode, non-bufferable, non-cacheable */
  1189. return cctl | PL080_CONTROL_PROT_SYS;
  1190. }
  1191. static u32 pl08x_width(enum dma_slave_buswidth width)
  1192. {
  1193. switch (width) {
  1194. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  1195. return PL080_WIDTH_8BIT;
  1196. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  1197. return PL080_WIDTH_16BIT;
  1198. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  1199. return PL080_WIDTH_32BIT;
  1200. default:
  1201. return ~0;
  1202. }
  1203. }
  1204. static u32 pl08x_burst(u32 maxburst)
  1205. {
  1206. int i;
  1207. for (i = 0; i < ARRAY_SIZE(burst_sizes); i++)
  1208. if (burst_sizes[i].burstwords <= maxburst)
  1209. break;
  1210. return burst_sizes[i].reg;
  1211. }
  1212. static u32 pl08x_get_cctl(struct pl08x_dma_chan *plchan,
  1213. enum dma_slave_buswidth addr_width, u32 maxburst)
  1214. {
  1215. u32 width, burst, cctl = 0;
  1216. width = pl08x_width(addr_width);
  1217. if (width == ~0)
  1218. return ~0;
  1219. cctl |= width << PL080_CONTROL_SWIDTH_SHIFT;
  1220. cctl |= width << PL080_CONTROL_DWIDTH_SHIFT;
  1221. /*
  1222. * If this channel will only request single transfers, set this
  1223. * down to ONE element. Also select one element if no maxburst
  1224. * is specified.
  1225. */
  1226. if (plchan->cd->single)
  1227. maxburst = 1;
  1228. burst = pl08x_burst(maxburst);
  1229. cctl |= burst << PL080_CONTROL_SB_SIZE_SHIFT;
  1230. cctl |= burst << PL080_CONTROL_DB_SIZE_SHIFT;
  1231. return pl08x_cctl(cctl);
  1232. }
  1233. static int dma_set_runtime_config(struct dma_chan *chan,
  1234. struct dma_slave_config *config)
  1235. {
  1236. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1237. struct pl08x_driver_data *pl08x = plchan->host;
  1238. if (!plchan->slave)
  1239. return -EINVAL;
  1240. /* Reject definitely invalid configurations */
  1241. if (config->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
  1242. config->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
  1243. return -EINVAL;
  1244. if (config->device_fc && pl08x->vd->pl080s) {
  1245. dev_err(&pl08x->adev->dev,
  1246. "%s: PL080S does not support peripheral flow control\n",
  1247. __func__);
  1248. return -EINVAL;
  1249. }
  1250. plchan->cfg = *config;
  1251. return 0;
  1252. }
  1253. /*
  1254. * Slave transactions callback to the slave device to allow
  1255. * synchronization of slave DMA signals with the DMAC enable
  1256. */
  1257. static void pl08x_issue_pending(struct dma_chan *chan)
  1258. {
  1259. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1260. unsigned long flags;
  1261. spin_lock_irqsave(&plchan->vc.lock, flags);
  1262. if (vchan_issue_pending(&plchan->vc)) {
  1263. if (!plchan->phychan && plchan->state != PL08X_CHAN_WAITING)
  1264. pl08x_phy_alloc_and_start(plchan);
  1265. }
  1266. spin_unlock_irqrestore(&plchan->vc.lock, flags);
  1267. }
  1268. static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan)
  1269. {
  1270. struct pl08x_txd *txd = kzalloc(sizeof(*txd), GFP_NOWAIT);
  1271. if (txd) {
  1272. INIT_LIST_HEAD(&txd->dsg_list);
  1273. /* Always enable error and terminal interrupts */
  1274. txd->ccfg = PL080_CONFIG_ERR_IRQ_MASK |
  1275. PL080_CONFIG_TC_IRQ_MASK;
  1276. }
  1277. return txd;
  1278. }
  1279. /*
  1280. * Initialize a descriptor to be used by memcpy submit
  1281. */
  1282. static struct dma_async_tx_descriptor *pl08x_prep_dma_memcpy(
  1283. struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  1284. size_t len, unsigned long flags)
  1285. {
  1286. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1287. struct pl08x_driver_data *pl08x = plchan->host;
  1288. struct pl08x_txd *txd;
  1289. struct pl08x_sg *dsg;
  1290. int ret;
  1291. txd = pl08x_get_txd(plchan);
  1292. if (!txd) {
  1293. dev_err(&pl08x->adev->dev,
  1294. "%s no memory for descriptor\n", __func__);
  1295. return NULL;
  1296. }
  1297. dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT);
  1298. if (!dsg) {
  1299. pl08x_free_txd(pl08x, txd);
  1300. dev_err(&pl08x->adev->dev, "%s no memory for pl080 sg\n",
  1301. __func__);
  1302. return NULL;
  1303. }
  1304. list_add_tail(&dsg->node, &txd->dsg_list);
  1305. dsg->src_addr = src;
  1306. dsg->dst_addr = dest;
  1307. dsg->len = len;
  1308. /* Set platform data for m2m */
  1309. txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT;
  1310. txd->cctl = pl08x->pd->memcpy_channel.cctl_memcpy &
  1311. ~(PL080_CONTROL_DST_AHB2 | PL080_CONTROL_SRC_AHB2);
  1312. /* Both to be incremented or the code will break */
  1313. txd->cctl |= PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR;
  1314. if (pl08x->vd->dualmaster)
  1315. txd->cctl |= pl08x_select_bus(pl08x->mem_buses,
  1316. pl08x->mem_buses);
  1317. ret = pl08x_fill_llis_for_desc(plchan->host, txd);
  1318. if (!ret) {
  1319. pl08x_free_txd(pl08x, txd);
  1320. return NULL;
  1321. }
  1322. return vchan_tx_prep(&plchan->vc, &txd->vd, flags);
  1323. }
  1324. static struct pl08x_txd *pl08x_init_txd(
  1325. struct dma_chan *chan,
  1326. enum dma_transfer_direction direction,
  1327. dma_addr_t *slave_addr)
  1328. {
  1329. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1330. struct pl08x_driver_data *pl08x = plchan->host;
  1331. struct pl08x_txd *txd;
  1332. enum dma_slave_buswidth addr_width;
  1333. int ret, tmp;
  1334. u8 src_buses, dst_buses;
  1335. u32 maxburst, cctl;
  1336. txd = pl08x_get_txd(plchan);
  1337. if (!txd) {
  1338. dev_err(&pl08x->adev->dev, "%s no txd\n", __func__);
  1339. return NULL;
  1340. }
  1341. /*
  1342. * Set up addresses, the PrimeCell configured address
  1343. * will take precedence since this may configure the
  1344. * channel target address dynamically at runtime.
  1345. */
  1346. if (direction == DMA_MEM_TO_DEV) {
  1347. cctl = PL080_CONTROL_SRC_INCR;
  1348. *slave_addr = plchan->cfg.dst_addr;
  1349. addr_width = plchan->cfg.dst_addr_width;
  1350. maxburst = plchan->cfg.dst_maxburst;
  1351. src_buses = pl08x->mem_buses;
  1352. dst_buses = plchan->cd->periph_buses;
  1353. } else if (direction == DMA_DEV_TO_MEM) {
  1354. cctl = PL080_CONTROL_DST_INCR;
  1355. *slave_addr = plchan->cfg.src_addr;
  1356. addr_width = plchan->cfg.src_addr_width;
  1357. maxburst = plchan->cfg.src_maxburst;
  1358. src_buses = plchan->cd->periph_buses;
  1359. dst_buses = pl08x->mem_buses;
  1360. } else {
  1361. pl08x_free_txd(pl08x, txd);
  1362. dev_err(&pl08x->adev->dev,
  1363. "%s direction unsupported\n", __func__);
  1364. return NULL;
  1365. }
  1366. cctl |= pl08x_get_cctl(plchan, addr_width, maxburst);
  1367. if (cctl == ~0) {
  1368. pl08x_free_txd(pl08x, txd);
  1369. dev_err(&pl08x->adev->dev,
  1370. "DMA slave configuration botched?\n");
  1371. return NULL;
  1372. }
  1373. txd->cctl = cctl | pl08x_select_bus(src_buses, dst_buses);
  1374. if (plchan->cfg.device_fc)
  1375. tmp = (direction == DMA_MEM_TO_DEV) ? PL080_FLOW_MEM2PER_PER :
  1376. PL080_FLOW_PER2MEM_PER;
  1377. else
  1378. tmp = (direction == DMA_MEM_TO_DEV) ? PL080_FLOW_MEM2PER :
  1379. PL080_FLOW_PER2MEM;
  1380. txd->ccfg |= tmp << PL080_CONFIG_FLOW_CONTROL_SHIFT;
  1381. ret = pl08x_request_mux(plchan);
  1382. if (ret < 0) {
  1383. pl08x_free_txd(pl08x, txd);
  1384. dev_dbg(&pl08x->adev->dev,
  1385. "unable to mux for transfer on %s due to platform restrictions\n",
  1386. plchan->name);
  1387. return NULL;
  1388. }
  1389. dev_dbg(&pl08x->adev->dev, "allocated DMA request signal %d for xfer on %s\n",
  1390. plchan->signal, plchan->name);
  1391. /* Assign the flow control signal to this channel */
  1392. if (direction == DMA_MEM_TO_DEV)
  1393. txd->ccfg |= plchan->signal << PL080_CONFIG_DST_SEL_SHIFT;
  1394. else
  1395. txd->ccfg |= plchan->signal << PL080_CONFIG_SRC_SEL_SHIFT;
  1396. return txd;
  1397. }
  1398. static int pl08x_tx_add_sg(struct pl08x_txd *txd,
  1399. enum dma_transfer_direction direction,
  1400. dma_addr_t slave_addr,
  1401. dma_addr_t buf_addr,
  1402. unsigned int len)
  1403. {
  1404. struct pl08x_sg *dsg;
  1405. dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT);
  1406. if (!dsg)
  1407. return -ENOMEM;
  1408. list_add_tail(&dsg->node, &txd->dsg_list);
  1409. dsg->len = len;
  1410. if (direction == DMA_MEM_TO_DEV) {
  1411. dsg->src_addr = buf_addr;
  1412. dsg->dst_addr = slave_addr;
  1413. } else {
  1414. dsg->src_addr = slave_addr;
  1415. dsg->dst_addr = buf_addr;
  1416. }
  1417. return 0;
  1418. }
  1419. static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
  1420. struct dma_chan *chan, struct scatterlist *sgl,
  1421. unsigned int sg_len, enum dma_transfer_direction direction,
  1422. unsigned long flags, void *context)
  1423. {
  1424. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1425. struct pl08x_driver_data *pl08x = plchan->host;
  1426. struct pl08x_txd *txd;
  1427. struct scatterlist *sg;
  1428. int ret, tmp;
  1429. dma_addr_t slave_addr;
  1430. dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n",
  1431. __func__, sg_dma_len(sgl), plchan->name);
  1432. txd = pl08x_init_txd(chan, direction, &slave_addr);
  1433. if (!txd)
  1434. return NULL;
  1435. for_each_sg(sgl, sg, sg_len, tmp) {
  1436. ret = pl08x_tx_add_sg(txd, direction, slave_addr,
  1437. sg_dma_address(sg),
  1438. sg_dma_len(sg));
  1439. if (ret) {
  1440. pl08x_release_mux(plchan);
  1441. pl08x_free_txd(pl08x, txd);
  1442. dev_err(&pl08x->adev->dev, "%s no mem for pl080 sg\n",
  1443. __func__);
  1444. return NULL;
  1445. }
  1446. }
  1447. ret = pl08x_fill_llis_for_desc(plchan->host, txd);
  1448. if (!ret) {
  1449. pl08x_release_mux(plchan);
  1450. pl08x_free_txd(pl08x, txd);
  1451. return NULL;
  1452. }
  1453. return vchan_tx_prep(&plchan->vc, &txd->vd, flags);
  1454. }
  1455. static struct dma_async_tx_descriptor *pl08x_prep_dma_cyclic(
  1456. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  1457. size_t period_len, enum dma_transfer_direction direction,
  1458. unsigned long flags, void *context)
  1459. {
  1460. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1461. struct pl08x_driver_data *pl08x = plchan->host;
  1462. struct pl08x_txd *txd;
  1463. int ret, tmp;
  1464. dma_addr_t slave_addr;
  1465. dev_dbg(&pl08x->adev->dev,
  1466. "%s prepare cyclic transaction of %d/%d bytes %s %s\n",
  1467. __func__, period_len, buf_len,
  1468. direction == DMA_MEM_TO_DEV ? "to" : "from",
  1469. plchan->name);
  1470. txd = pl08x_init_txd(chan, direction, &slave_addr);
  1471. if (!txd)
  1472. return NULL;
  1473. txd->cyclic = true;
  1474. txd->cctl |= PL080_CONTROL_TC_IRQ_EN;
  1475. for (tmp = 0; tmp < buf_len; tmp += period_len) {
  1476. ret = pl08x_tx_add_sg(txd, direction, slave_addr,
  1477. buf_addr + tmp, period_len);
  1478. if (ret) {
  1479. pl08x_release_mux(plchan);
  1480. pl08x_free_txd(pl08x, txd);
  1481. return NULL;
  1482. }
  1483. }
  1484. ret = pl08x_fill_llis_for_desc(plchan->host, txd);
  1485. if (!ret) {
  1486. pl08x_release_mux(plchan);
  1487. pl08x_free_txd(pl08x, txd);
  1488. return NULL;
  1489. }
  1490. return vchan_tx_prep(&plchan->vc, &txd->vd, flags);
  1491. }
  1492. static int pl08x_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  1493. unsigned long arg)
  1494. {
  1495. struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
  1496. struct pl08x_driver_data *pl08x = plchan->host;
  1497. unsigned long flags;
  1498. int ret = 0;
  1499. /* Controls applicable to inactive channels */
  1500. if (cmd == DMA_SLAVE_CONFIG) {
  1501. return dma_set_runtime_config(chan,
  1502. (struct dma_slave_config *)arg);
  1503. }
  1504. /*
  1505. * Anything succeeds on channels with no physical allocation and
  1506. * no queued transfers.
  1507. */
  1508. spin_lock_irqsave(&plchan->vc.lock, flags);
  1509. if (!plchan->phychan && !plchan->at) {
  1510. spin_unlock_irqrestore(&plchan->vc.lock, flags);
  1511. return 0;
  1512. }
  1513. switch (cmd) {
  1514. case DMA_TERMINATE_ALL:
  1515. plchan->state = PL08X_CHAN_IDLE;
  1516. if (plchan->phychan) {
  1517. /*
  1518. * Mark physical channel as free and free any slave
  1519. * signal
  1520. */
  1521. pl08x_phy_free(plchan);
  1522. }
  1523. /* Dequeue jobs and free LLIs */
  1524. if (plchan->at) {
  1525. pl08x_desc_free(&plchan->at->vd);
  1526. plchan->at = NULL;
  1527. }
  1528. /* Dequeue jobs not yet fired as well */
  1529. pl08x_free_txd_list(pl08x, plchan);
  1530. break;
  1531. case DMA_PAUSE:
  1532. pl08x_pause_phy_chan(plchan->phychan);
  1533. plchan->state = PL08X_CHAN_PAUSED;
  1534. break;
  1535. case DMA_RESUME:
  1536. pl08x_resume_phy_chan(plchan->phychan);
  1537. plchan->state = PL08X_CHAN_RUNNING;
  1538. break;
  1539. default:
  1540. /* Unknown command */
  1541. ret = -ENXIO;
  1542. break;
  1543. }
  1544. spin_unlock_irqrestore(&plchan->vc.lock, flags);
  1545. return ret;
  1546. }
  1547. bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
  1548. {
  1549. struct pl08x_dma_chan *plchan;
  1550. char *name = chan_id;
  1551. /* Reject channels for devices not bound to this driver */
  1552. if (chan->device->dev->driver != &pl08x_amba_driver.drv)
  1553. return false;
  1554. plchan = to_pl08x_chan(chan);
  1555. /* Check that the channel is not taken! */
  1556. if (!strcmp(plchan->name, name))
  1557. return true;
  1558. return false;
  1559. }
  1560. /*
  1561. * Just check that the device is there and active
  1562. * TODO: turn this bit on/off depending on the number of physical channels
  1563. * actually used, if it is zero... well shut it off. That will save some
  1564. * power. Cut the clock at the same time.
  1565. */
  1566. static void pl08x_ensure_on(struct pl08x_driver_data *pl08x)
  1567. {
  1568. /* The Nomadik variant does not have the config register */
  1569. if (pl08x->vd->nomadik)
  1570. return;
  1571. writel(PL080_CONFIG_ENABLE, pl08x->base + PL080_CONFIG);
  1572. }
  1573. static irqreturn_t pl08x_irq(int irq, void *dev)
  1574. {
  1575. struct pl08x_driver_data *pl08x = dev;
  1576. u32 mask = 0, err, tc, i;
  1577. /* check & clear - ERR & TC interrupts */
  1578. err = readl(pl08x->base + PL080_ERR_STATUS);
  1579. if (err) {
  1580. dev_err(&pl08x->adev->dev, "%s error interrupt, register value 0x%08x\n",
  1581. __func__, err);
  1582. writel(err, pl08x->base + PL080_ERR_CLEAR);
  1583. }
  1584. tc = readl(pl08x->base + PL080_TC_STATUS);
  1585. if (tc)
  1586. writel(tc, pl08x->base + PL080_TC_CLEAR);
  1587. if (!err && !tc)
  1588. return IRQ_NONE;
  1589. for (i = 0; i < pl08x->vd->channels; i++) {
  1590. if (((1 << i) & err) || ((1 << i) & tc)) {
  1591. /* Locate physical channel */
  1592. struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i];
  1593. struct pl08x_dma_chan *plchan = phychan->serving;
  1594. struct pl08x_txd *tx;
  1595. if (!plchan) {
  1596. dev_err(&pl08x->adev->dev,
  1597. "%s Error TC interrupt on unused channel: 0x%08x\n",
  1598. __func__, i);
  1599. continue;
  1600. }
  1601. spin_lock(&plchan->vc.lock);
  1602. tx = plchan->at;
  1603. if (tx && tx->cyclic) {
  1604. vchan_cyclic_callback(&tx->vd);
  1605. } else if (tx) {
  1606. plchan->at = NULL;
  1607. /*
  1608. * This descriptor is done, release its mux
  1609. * reservation.
  1610. */
  1611. pl08x_release_mux(plchan);
  1612. tx->done = true;
  1613. vchan_cookie_complete(&tx->vd);
  1614. /*
  1615. * And start the next descriptor (if any),
  1616. * otherwise free this channel.
  1617. */
  1618. if (vchan_next_desc(&plchan->vc))
  1619. pl08x_start_next_txd(plchan);
  1620. else
  1621. pl08x_phy_free(plchan);
  1622. }
  1623. spin_unlock(&plchan->vc.lock);
  1624. mask |= (1 << i);
  1625. }
  1626. }
  1627. return mask ? IRQ_HANDLED : IRQ_NONE;
  1628. }
  1629. static void pl08x_dma_slave_init(struct pl08x_dma_chan *chan)
  1630. {
  1631. chan->slave = true;
  1632. chan->name = chan->cd->bus_id;
  1633. chan->cfg.src_addr = chan->cd->addr;
  1634. chan->cfg.dst_addr = chan->cd->addr;
  1635. }
  1636. /*
  1637. * Initialise the DMAC memcpy/slave channels.
  1638. * Make a local wrapper to hold required data
  1639. */
  1640. static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
  1641. struct dma_device *dmadev, unsigned int channels, bool slave)
  1642. {
  1643. struct pl08x_dma_chan *chan;
  1644. int i;
  1645. INIT_LIST_HEAD(&dmadev->channels);
  1646. /*
  1647. * Register as many many memcpy as we have physical channels,
  1648. * we won't always be able to use all but the code will have
  1649. * to cope with that situation.
  1650. */
  1651. for (i = 0; i < channels; i++) {
  1652. chan = kzalloc(sizeof(*chan), GFP_KERNEL);
  1653. if (!chan) {
  1654. dev_err(&pl08x->adev->dev,
  1655. "%s no memory for channel\n", __func__);
  1656. return -ENOMEM;
  1657. }
  1658. chan->host = pl08x;
  1659. chan->state = PL08X_CHAN_IDLE;
  1660. chan->signal = -1;
  1661. if (slave) {
  1662. chan->cd = &pl08x->pd->slave_channels[i];
  1663. pl08x_dma_slave_init(chan);
  1664. } else {
  1665. chan->cd = &pl08x->pd->memcpy_channel;
  1666. chan->name = kasprintf(GFP_KERNEL, "memcpy%d", i);
  1667. if (!chan->name) {
  1668. kfree(chan);
  1669. return -ENOMEM;
  1670. }
  1671. }
  1672. dev_dbg(&pl08x->adev->dev,
  1673. "initialize virtual channel \"%s\"\n",
  1674. chan->name);
  1675. chan->vc.desc_free = pl08x_desc_free;
  1676. vchan_init(&chan->vc, dmadev);
  1677. }
  1678. dev_info(&pl08x->adev->dev, "initialized %d virtual %s channels\n",
  1679. i, slave ? "slave" : "memcpy");
  1680. return i;
  1681. }
  1682. static void pl08x_free_virtual_channels(struct dma_device *dmadev)
  1683. {
  1684. struct pl08x_dma_chan *chan = NULL;
  1685. struct pl08x_dma_chan *next;
  1686. list_for_each_entry_safe(chan,
  1687. next, &dmadev->channels, vc.chan.device_node) {
  1688. list_del(&chan->vc.chan.device_node);
  1689. kfree(chan);
  1690. }
  1691. }
  1692. #ifdef CONFIG_DEBUG_FS
  1693. static const char *pl08x_state_str(enum pl08x_dma_chan_state state)
  1694. {
  1695. switch (state) {
  1696. case PL08X_CHAN_IDLE:
  1697. return "idle";
  1698. case PL08X_CHAN_RUNNING:
  1699. return "running";
  1700. case PL08X_CHAN_PAUSED:
  1701. return "paused";
  1702. case PL08X_CHAN_WAITING:
  1703. return "waiting";
  1704. default:
  1705. break;
  1706. }
  1707. return "UNKNOWN STATE";
  1708. }
  1709. static int pl08x_debugfs_show(struct seq_file *s, void *data)
  1710. {
  1711. struct pl08x_driver_data *pl08x = s->private;
  1712. struct pl08x_dma_chan *chan;
  1713. struct pl08x_phy_chan *ch;
  1714. unsigned long flags;
  1715. int i;
  1716. seq_printf(s, "PL08x physical channels:\n");
  1717. seq_printf(s, "CHANNEL:\tUSER:\n");
  1718. seq_printf(s, "--------\t-----\n");
  1719. for (i = 0; i < pl08x->vd->channels; i++) {
  1720. struct pl08x_dma_chan *virt_chan;
  1721. ch = &pl08x->phy_chans[i];
  1722. spin_lock_irqsave(&ch->lock, flags);
  1723. virt_chan = ch->serving;
  1724. seq_printf(s, "%d\t\t%s%s\n",
  1725. ch->id,
  1726. virt_chan ? virt_chan->name : "(none)",
  1727. ch->locked ? " LOCKED" : "");
  1728. spin_unlock_irqrestore(&ch->lock, flags);
  1729. }
  1730. seq_printf(s, "\nPL08x virtual memcpy channels:\n");
  1731. seq_printf(s, "CHANNEL:\tSTATE:\n");
  1732. seq_printf(s, "--------\t------\n");
  1733. list_for_each_entry(chan, &pl08x->memcpy.channels, vc.chan.device_node) {
  1734. seq_printf(s, "%s\t\t%s\n", chan->name,
  1735. pl08x_state_str(chan->state));
  1736. }
  1737. seq_printf(s, "\nPL08x virtual slave channels:\n");
  1738. seq_printf(s, "CHANNEL:\tSTATE:\n");
  1739. seq_printf(s, "--------\t------\n");
  1740. list_for_each_entry(chan, &pl08x->slave.channels, vc.chan.device_node) {
  1741. seq_printf(s, "%s\t\t%s\n", chan->name,
  1742. pl08x_state_str(chan->state));
  1743. }
  1744. return 0;
  1745. }
  1746. static int pl08x_debugfs_open(struct inode *inode, struct file *file)
  1747. {
  1748. return single_open(file, pl08x_debugfs_show, inode->i_private);
  1749. }
  1750. static const struct file_operations pl08x_debugfs_operations = {
  1751. .open = pl08x_debugfs_open,
  1752. .read = seq_read,
  1753. .llseek = seq_lseek,
  1754. .release = single_release,
  1755. };
  1756. static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x)
  1757. {
  1758. /* Expose a simple debugfs interface to view all clocks */
  1759. (void) debugfs_create_file(dev_name(&pl08x->adev->dev),
  1760. S_IFREG | S_IRUGO, NULL, pl08x,
  1761. &pl08x_debugfs_operations);
  1762. }
  1763. #else
  1764. static inline void init_pl08x_debugfs(struct pl08x_driver_data *pl08x)
  1765. {
  1766. }
  1767. #endif
  1768. static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
  1769. {
  1770. struct pl08x_driver_data *pl08x;
  1771. const struct vendor_data *vd = id->data;
  1772. u32 tsfr_size;
  1773. int ret = 0;
  1774. int i;
  1775. ret = amba_request_regions(adev, NULL);
  1776. if (ret)
  1777. return ret;
  1778. /* Create the driver state holder */
  1779. pl08x = kzalloc(sizeof(*pl08x), GFP_KERNEL);
  1780. if (!pl08x) {
  1781. ret = -ENOMEM;
  1782. goto out_no_pl08x;
  1783. }
  1784. /* Initialize memcpy engine */
  1785. dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask);
  1786. pl08x->memcpy.dev = &adev->dev;
  1787. pl08x->memcpy.device_alloc_chan_resources = pl08x_alloc_chan_resources;
  1788. pl08x->memcpy.device_free_chan_resources = pl08x_free_chan_resources;
  1789. pl08x->memcpy.device_prep_dma_memcpy = pl08x_prep_dma_memcpy;
  1790. pl08x->memcpy.device_prep_dma_interrupt = pl08x_prep_dma_interrupt;
  1791. pl08x->memcpy.device_tx_status = pl08x_dma_tx_status;
  1792. pl08x->memcpy.device_issue_pending = pl08x_issue_pending;
  1793. pl08x->memcpy.device_control = pl08x_control;
  1794. /* Initialize slave engine */
  1795. dma_cap_set(DMA_SLAVE, pl08x->slave.cap_mask);
  1796. dma_cap_set(DMA_CYCLIC, pl08x->slave.cap_mask);
  1797. pl08x->slave.dev = &adev->dev;
  1798. pl08x->slave.device_alloc_chan_resources = pl08x_alloc_chan_resources;
  1799. pl08x->slave.device_free_chan_resources = pl08x_free_chan_resources;
  1800. pl08x->slave.device_prep_dma_interrupt = pl08x_prep_dma_interrupt;
  1801. pl08x->slave.device_tx_status = pl08x_dma_tx_status;
  1802. pl08x->slave.device_issue_pending = pl08x_issue_pending;
  1803. pl08x->slave.device_prep_slave_sg = pl08x_prep_slave_sg;
  1804. pl08x->slave.device_prep_dma_cyclic = pl08x_prep_dma_cyclic;
  1805. pl08x->slave.device_control = pl08x_control;
  1806. /* Get the platform data */
  1807. pl08x->pd = dev_get_platdata(&adev->dev);
  1808. if (!pl08x->pd) {
  1809. dev_err(&adev->dev, "no platform data supplied\n");
  1810. ret = -EINVAL;
  1811. goto out_no_platdata;
  1812. }
  1813. /* Assign useful pointers to the driver state */
  1814. pl08x->adev = adev;
  1815. pl08x->vd = vd;
  1816. /* By default, AHB1 only. If dualmaster, from platform */
  1817. pl08x->lli_buses = PL08X_AHB1;
  1818. pl08x->mem_buses = PL08X_AHB1;
  1819. if (pl08x->vd->dualmaster) {
  1820. pl08x->lli_buses = pl08x->pd->lli_buses;
  1821. pl08x->mem_buses = pl08x->pd->mem_buses;
  1822. }
  1823. if (vd->pl080s)
  1824. pl08x->lli_words = PL080S_LLI_WORDS;
  1825. else
  1826. pl08x->lli_words = PL080_LLI_WORDS;
  1827. tsfr_size = MAX_NUM_TSFR_LLIS * pl08x->lli_words * sizeof(u32);
  1828. /* A DMA memory pool for LLIs, align on 1-byte boundary */
  1829. pl08x->pool = dma_pool_create(DRIVER_NAME, &pl08x->adev->dev,
  1830. tsfr_size, PL08X_ALIGN, 0);
  1831. if (!pl08x->pool) {
  1832. ret = -ENOMEM;
  1833. goto out_no_lli_pool;
  1834. }
  1835. pl08x->base = ioremap(adev->res.start, resource_size(&adev->res));
  1836. if (!pl08x->base) {
  1837. ret = -ENOMEM;
  1838. goto out_no_ioremap;
  1839. }
  1840. /* Turn on the PL08x */
  1841. pl08x_ensure_on(pl08x);
  1842. /* Attach the interrupt handler */
  1843. writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR);
  1844. writel(0x000000FF, pl08x->base + PL080_TC_CLEAR);
  1845. ret = request_irq(adev->irq[0], pl08x_irq, IRQF_DISABLED,
  1846. DRIVER_NAME, pl08x);
  1847. if (ret) {
  1848. dev_err(&adev->dev, "%s failed to request interrupt %d\n",
  1849. __func__, adev->irq[0]);
  1850. goto out_no_irq;
  1851. }
  1852. /* Initialize physical channels */
  1853. pl08x->phy_chans = kzalloc((vd->channels * sizeof(*pl08x->phy_chans)),
  1854. GFP_KERNEL);
  1855. if (!pl08x->phy_chans) {
  1856. dev_err(&adev->dev, "%s failed to allocate "
  1857. "physical channel holders\n",
  1858. __func__);
  1859. ret = -ENOMEM;
  1860. goto out_no_phychans;
  1861. }
  1862. for (i = 0; i < vd->channels; i++) {
  1863. struct pl08x_phy_chan *ch = &pl08x->phy_chans[i];
  1864. ch->id = i;
  1865. ch->base = pl08x->base + PL080_Cx_BASE(i);
  1866. ch->reg_config = ch->base + vd->config_offset;
  1867. spin_lock_init(&ch->lock);
  1868. /*
  1869. * Nomadik variants can have channels that are locked
  1870. * down for the secure world only. Lock up these channels
  1871. * by perpetually serving a dummy virtual channel.
  1872. */
  1873. if (vd->nomadik) {
  1874. u32 val;
  1875. val = readl(ch->reg_config);
  1876. if (val & (PL080N_CONFIG_ITPROT | PL080N_CONFIG_SECPROT)) {
  1877. dev_info(&adev->dev, "physical channel %d reserved for secure access only\n", i);
  1878. ch->locked = true;
  1879. }
  1880. }
  1881. dev_dbg(&adev->dev, "physical channel %d is %s\n",
  1882. i, pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");
  1883. }
  1884. /* Register as many memcpy channels as there are physical channels */
  1885. ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->memcpy,
  1886. pl08x->vd->channels, false);
  1887. if (ret <= 0) {
  1888. dev_warn(&pl08x->adev->dev,
  1889. "%s failed to enumerate memcpy channels - %d\n",
  1890. __func__, ret);
  1891. goto out_no_memcpy;
  1892. }
  1893. pl08x->memcpy.chancnt = ret;
  1894. /* Register slave channels */
  1895. ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave,
  1896. pl08x->pd->num_slave_channels, true);
  1897. if (ret <= 0) {
  1898. dev_warn(&pl08x->adev->dev,
  1899. "%s failed to enumerate slave channels - %d\n",
  1900. __func__, ret);
  1901. goto out_no_slave;
  1902. }
  1903. pl08x->slave.chancnt = ret;
  1904. ret = dma_async_device_register(&pl08x->memcpy);
  1905. if (ret) {
  1906. dev_warn(&pl08x->adev->dev,
  1907. "%s failed to register memcpy as an async device - %d\n",
  1908. __func__, ret);
  1909. goto out_no_memcpy_reg;
  1910. }
  1911. ret = dma_async_device_register(&pl08x->slave);
  1912. if (ret) {
  1913. dev_warn(&pl08x->adev->dev,
  1914. "%s failed to register slave as an async device - %d\n",
  1915. __func__, ret);
  1916. goto out_no_slave_reg;
  1917. }
  1918. amba_set_drvdata(adev, pl08x);
  1919. init_pl08x_debugfs(pl08x);
  1920. dev_info(&pl08x->adev->dev, "DMA: PL%03x%s rev%u at 0x%08llx irq %d\n",
  1921. amba_part(adev), pl08x->vd->pl080s ? "s" : "", amba_rev(adev),
  1922. (unsigned long long)adev->res.start, adev->irq[0]);
  1923. return 0;
  1924. out_no_slave_reg:
  1925. dma_async_device_unregister(&pl08x->memcpy);
  1926. out_no_memcpy_reg:
  1927. pl08x_free_virtual_channels(&pl08x->slave);
  1928. out_no_slave:
  1929. pl08x_free_virtual_channels(&pl08x->memcpy);
  1930. out_no_memcpy:
  1931. kfree(pl08x->phy_chans);
  1932. out_no_phychans:
  1933. free_irq(adev->irq[0], pl08x);
  1934. out_no_irq:
  1935. iounmap(pl08x->base);
  1936. out_no_ioremap:
  1937. dma_pool_destroy(pl08x->pool);
  1938. out_no_lli_pool:
  1939. out_no_platdata:
  1940. kfree(pl08x);
  1941. out_no_pl08x:
  1942. amba_release_regions(adev);
  1943. return ret;
  1944. }
  1945. /* PL080 has 8 channels and the PL080 have just 2 */
  1946. static struct vendor_data vendor_pl080 = {
  1947. .config_offset = PL080_CH_CONFIG,
  1948. .channels = 8,
  1949. .dualmaster = true,
  1950. .max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK,
  1951. };
  1952. static struct vendor_data vendor_nomadik = {
  1953. .config_offset = PL080_CH_CONFIG,
  1954. .channels = 8,
  1955. .dualmaster = true,
  1956. .nomadik = true,
  1957. .max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK,
  1958. };
  1959. static struct vendor_data vendor_pl080s = {
  1960. .config_offset = PL080S_CH_CONFIG,
  1961. .channels = 8,
  1962. .pl080s = true,
  1963. .max_transfer_size = PL080S_CONTROL_TRANSFER_SIZE_MASK,
  1964. };
  1965. static struct vendor_data vendor_pl081 = {
  1966. .config_offset = PL080_CH_CONFIG,
  1967. .channels = 2,
  1968. .dualmaster = false,
  1969. .max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK,
  1970. };
  1971. static struct amba_id pl08x_ids[] = {
  1972. /* Samsung PL080S variant */
  1973. {
  1974. .id = 0x0a141080,
  1975. .mask = 0xffffffff,
  1976. .data = &vendor_pl080s,
  1977. },
  1978. /* PL080 */
  1979. {
  1980. .id = 0x00041080,
  1981. .mask = 0x000fffff,
  1982. .data = &vendor_pl080,
  1983. },
  1984. /* PL081 */
  1985. {
  1986. .id = 0x00041081,
  1987. .mask = 0x000fffff,
  1988. .data = &vendor_pl081,
  1989. },
  1990. /* Nomadik 8815 PL080 variant */
  1991. {
  1992. .id = 0x00280080,
  1993. .mask = 0x00ffffff,
  1994. .data = &vendor_nomadik,
  1995. },
  1996. { 0, 0 },
  1997. };
  1998. MODULE_DEVICE_TABLE(amba, pl08x_ids);
  1999. static struct amba_driver pl08x_amba_driver = {
  2000. .drv.name = DRIVER_NAME,
  2001. .id_table = pl08x_ids,
  2002. .probe = pl08x_probe,
  2003. };
  2004. static int __init pl08x_init(void)
  2005. {
  2006. int retval;
  2007. retval = amba_driver_register(&pl08x_amba_driver);
  2008. if (retval)
  2009. printk(KERN_WARNING DRIVER_NAME
  2010. "failed to register as an AMBA device (%d)\n",
  2011. retval);
  2012. return retval;
  2013. }
  2014. subsys_initcall(pl08x_init);