amba-pl08x.c 61 KB

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