xilinx_uartps.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Cadence UART driver (found in Xilinx Zynq)
  4. *
  5. * 2011 - 2014 (C) Xilinx Inc.
  6. *
  7. * This driver has originally been pushed by Xilinx using a Zynq-branding. This
  8. * still shows in the naming of this file, the kconfig symbols and some symbols
  9. * in the code.
  10. */
  11. #if defined(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  12. #define SUPPORT_SYSRQ
  13. #endif
  14. #include <linux/platform_device.h>
  15. #include <linux/serial.h>
  16. #include <linux/console.h>
  17. #include <linux/serial_core.h>
  18. #include <linux/slab.h>
  19. #include <linux/tty.h>
  20. #include <linux/tty_flip.h>
  21. #include <linux/clk.h>
  22. #include <linux/irq.h>
  23. #include <linux/io.h>
  24. #include <linux/of.h>
  25. #include <linux/module.h>
  26. #include <linux/pm_runtime.h>
  27. #include <linux/iopoll.h>
  28. #define CDNS_UART_TTY_NAME "ttyPS"
  29. #define CDNS_UART_NAME "xuartps"
  30. #define CDNS_UART_MAJOR 0 /* use dynamic node allocation */
  31. #define CDNS_UART_MINOR 0 /* works best with devtmpfs */
  32. #define CDNS_UART_NR_PORTS 2
  33. #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */
  34. #define CDNS_UART_REGISTER_SPACE 0x1000
  35. #define TX_TIMEOUT 500000
  36. /* Rx Trigger level */
  37. static int rx_trigger_level = 56;
  38. module_param(rx_trigger_level, uint, S_IRUGO);
  39. MODULE_PARM_DESC(rx_trigger_level, "Rx trigger level, 1-63 bytes");
  40. /* Rx Timeout */
  41. static int rx_timeout = 10;
  42. module_param(rx_timeout, uint, S_IRUGO);
  43. MODULE_PARM_DESC(rx_timeout, "Rx timeout, 1-255");
  44. /* Register offsets for the UART. */
  45. #define CDNS_UART_CR 0x00 /* Control Register */
  46. #define CDNS_UART_MR 0x04 /* Mode Register */
  47. #define CDNS_UART_IER 0x08 /* Interrupt Enable */
  48. #define CDNS_UART_IDR 0x0C /* Interrupt Disable */
  49. #define CDNS_UART_IMR 0x10 /* Interrupt Mask */
  50. #define CDNS_UART_ISR 0x14 /* Interrupt Status */
  51. #define CDNS_UART_BAUDGEN 0x18 /* Baud Rate Generator */
  52. #define CDNS_UART_RXTOUT 0x1C /* RX Timeout */
  53. #define CDNS_UART_RXWM 0x20 /* RX FIFO Trigger Level */
  54. #define CDNS_UART_MODEMCR 0x24 /* Modem Control */
  55. #define CDNS_UART_MODEMSR 0x28 /* Modem Status */
  56. #define CDNS_UART_SR 0x2C /* Channel Status */
  57. #define CDNS_UART_FIFO 0x30 /* FIFO */
  58. #define CDNS_UART_BAUDDIV 0x34 /* Baud Rate Divider */
  59. #define CDNS_UART_FLOWDEL 0x38 /* Flow Delay */
  60. #define CDNS_UART_IRRX_PWIDTH 0x3C /* IR Min Received Pulse Width */
  61. #define CDNS_UART_IRTX_PWIDTH 0x40 /* IR Transmitted pulse Width */
  62. #define CDNS_UART_TXWM 0x44 /* TX FIFO Trigger Level */
  63. #define CDNS_UART_RXBS 0x48 /* RX FIFO byte status register */
  64. /* Control Register Bit Definitions */
  65. #define CDNS_UART_CR_STOPBRK 0x00000100 /* Stop TX break */
  66. #define CDNS_UART_CR_STARTBRK 0x00000080 /* Set TX break */
  67. #define CDNS_UART_CR_TX_DIS 0x00000020 /* TX disabled. */
  68. #define CDNS_UART_CR_TX_EN 0x00000010 /* TX enabled */
  69. #define CDNS_UART_CR_RX_DIS 0x00000008 /* RX disabled. */
  70. #define CDNS_UART_CR_RX_EN 0x00000004 /* RX enabled */
  71. #define CDNS_UART_CR_TXRST 0x00000002 /* TX logic reset */
  72. #define CDNS_UART_CR_RXRST 0x00000001 /* RX logic reset */
  73. #define CDNS_UART_CR_RST_TO 0x00000040 /* Restart Timeout Counter */
  74. #define CDNS_UART_RXBS_PARITY 0x00000001 /* Parity error status */
  75. #define CDNS_UART_RXBS_FRAMING 0x00000002 /* Framing error status */
  76. #define CDNS_UART_RXBS_BRK 0x00000004 /* Overrun error status */
  77. /*
  78. * Mode Register:
  79. * The mode register (MR) defines the mode of transfer as well as the data
  80. * format. If this register is modified during transmission or reception,
  81. * data validity cannot be guaranteed.
  82. */
  83. #define CDNS_UART_MR_CLKSEL 0x00000001 /* Pre-scalar selection */
  84. #define CDNS_UART_MR_CHMODE_L_LOOP 0x00000200 /* Local loop back mode */
  85. #define CDNS_UART_MR_CHMODE_NORM 0x00000000 /* Normal mode */
  86. #define CDNS_UART_MR_CHMODE_MASK 0x00000300 /* Mask for mode bits */
  87. #define CDNS_UART_MR_STOPMODE_2_BIT 0x00000080 /* 2 stop bits */
  88. #define CDNS_UART_MR_STOPMODE_1_BIT 0x00000000 /* 1 stop bit */
  89. #define CDNS_UART_MR_PARITY_NONE 0x00000020 /* No parity mode */
  90. #define CDNS_UART_MR_PARITY_MARK 0x00000018 /* Mark parity mode */
  91. #define CDNS_UART_MR_PARITY_SPACE 0x00000010 /* Space parity mode */
  92. #define CDNS_UART_MR_PARITY_ODD 0x00000008 /* Odd parity mode */
  93. #define CDNS_UART_MR_PARITY_EVEN 0x00000000 /* Even parity mode */
  94. #define CDNS_UART_MR_CHARLEN_6_BIT 0x00000006 /* 6 bits data */
  95. #define CDNS_UART_MR_CHARLEN_7_BIT 0x00000004 /* 7 bits data */
  96. #define CDNS_UART_MR_CHARLEN_8_BIT 0x00000000 /* 8 bits data */
  97. /*
  98. * Interrupt Registers:
  99. * Interrupt control logic uses the interrupt enable register (IER) and the
  100. * interrupt disable register (IDR) to set the value of the bits in the
  101. * interrupt mask register (IMR). The IMR determines whether to pass an
  102. * interrupt to the interrupt status register (ISR).
  103. * Writing a 1 to IER Enables an interrupt, writing a 1 to IDR disables an
  104. * interrupt. IMR and ISR are read only, and IER and IDR are write only.
  105. * Reading either IER or IDR returns 0x00.
  106. * All four registers have the same bit definitions.
  107. */
  108. #define CDNS_UART_IXR_TOUT 0x00000100 /* RX Timeout error interrupt */
  109. #define CDNS_UART_IXR_PARITY 0x00000080 /* Parity error interrupt */
  110. #define CDNS_UART_IXR_FRAMING 0x00000040 /* Framing error interrupt */
  111. #define CDNS_UART_IXR_OVERRUN 0x00000020 /* Overrun error interrupt */
  112. #define CDNS_UART_IXR_TXFULL 0x00000010 /* TX FIFO Full interrupt */
  113. #define CDNS_UART_IXR_TXEMPTY 0x00000008 /* TX FIFO empty interrupt */
  114. #define CDNS_UART_ISR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt */
  115. #define CDNS_UART_IXR_RXTRIG 0x00000001 /* RX FIFO trigger interrupt */
  116. #define CDNS_UART_IXR_RXFULL 0x00000004 /* RX FIFO full interrupt. */
  117. #define CDNS_UART_IXR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt. */
  118. #define CDNS_UART_IXR_RXMASK 0x000021e7 /* Valid RX bit mask */
  119. /*
  120. * Do not enable parity error interrupt for the following
  121. * reason: When parity error interrupt is enabled, each Rx
  122. * parity error always results in 2 events. The first one
  123. * being parity error interrupt and the second one with a
  124. * proper Rx interrupt with the incoming data. Disabling
  125. * parity error interrupt ensures better handling of parity
  126. * error events. With this change, for a parity error case, we
  127. * get a Rx interrupt with parity error set in ISR register
  128. * and we still handle parity errors in the desired way.
  129. */
  130. #define CDNS_UART_RX_IRQS (CDNS_UART_IXR_FRAMING | \
  131. CDNS_UART_IXR_OVERRUN | \
  132. CDNS_UART_IXR_RXTRIG | \
  133. CDNS_UART_IXR_TOUT)
  134. /* Goes in read_status_mask for break detection as the HW doesn't do it*/
  135. #define CDNS_UART_IXR_BRK 0x00002000
  136. #define CDNS_UART_RXBS_SUPPORT BIT(1)
  137. /*
  138. * Modem Control register:
  139. * The read/write Modem Control register controls the interface with the modem
  140. * or data set, or a peripheral device emulating a modem.
  141. */
  142. #define CDNS_UART_MODEMCR_FCM 0x00000020 /* Automatic flow control mode */
  143. #define CDNS_UART_MODEMCR_RTS 0x00000002 /* Request to send output control */
  144. #define CDNS_UART_MODEMCR_DTR 0x00000001 /* Data Terminal Ready */
  145. /*
  146. * Channel Status Register:
  147. * The channel status register (CSR) is provided to enable the control logic
  148. * to monitor the status of bits in the channel interrupt status register,
  149. * even if these are masked out by the interrupt mask register.
  150. */
  151. #define CDNS_UART_SR_RXEMPTY 0x00000002 /* RX FIFO empty */
  152. #define CDNS_UART_SR_TXEMPTY 0x00000008 /* TX FIFO empty */
  153. #define CDNS_UART_SR_TXFULL 0x00000010 /* TX FIFO full */
  154. #define CDNS_UART_SR_RXTRIG 0x00000001 /* Rx Trigger */
  155. #define CDNS_UART_SR_TACTIVE 0x00000800 /* TX state machine active */
  156. /* baud dividers min/max values */
  157. #define CDNS_UART_BDIV_MIN 4
  158. #define CDNS_UART_BDIV_MAX 255
  159. #define CDNS_UART_CD_MAX 65535
  160. #define UART_AUTOSUSPEND_TIMEOUT 3000
  161. /**
  162. * struct cdns_uart - device data
  163. * @port: Pointer to the UART port
  164. * @uartclk: Reference clock
  165. * @pclk: APB clock
  166. * @baud: Current baud rate
  167. * @clk_rate_change_nb: Notifier block for clock changes
  168. * @quirks: Flags for RXBS support.
  169. */
  170. struct cdns_uart {
  171. struct uart_port *port;
  172. struct clk *uartclk;
  173. struct clk *pclk;
  174. unsigned int baud;
  175. struct notifier_block clk_rate_change_nb;
  176. u32 quirks;
  177. };
  178. struct cdns_platform_data {
  179. u32 quirks;
  180. };
  181. #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
  182. clk_rate_change_nb);
  183. /**
  184. * cdns_uart_handle_rx - Handle the received bytes along with Rx errors.
  185. * @dev_id: Id of the UART port
  186. * @isrstatus: The interrupt status register value as read
  187. * Return: None
  188. */
  189. static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus)
  190. {
  191. struct uart_port *port = (struct uart_port *)dev_id;
  192. struct cdns_uart *cdns_uart = port->private_data;
  193. unsigned int data;
  194. unsigned int rxbs_status = 0;
  195. unsigned int status_mask;
  196. unsigned int framerrprocessed = 0;
  197. char status = TTY_NORMAL;
  198. bool is_rxbs_support;
  199. is_rxbs_support = cdns_uart->quirks & CDNS_UART_RXBS_SUPPORT;
  200. while ((readl(port->membase + CDNS_UART_SR) &
  201. CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) {
  202. if (is_rxbs_support)
  203. rxbs_status = readl(port->membase + CDNS_UART_RXBS);
  204. data = readl(port->membase + CDNS_UART_FIFO);
  205. port->icount.rx++;
  206. /*
  207. * There is no hardware break detection in Zynq, so we interpret
  208. * framing error with all-zeros data as a break sequence.
  209. * Most of the time, there's another non-zero byte at the
  210. * end of the sequence.
  211. */
  212. if (!is_rxbs_support && (isrstatus & CDNS_UART_IXR_FRAMING)) {
  213. if (!data) {
  214. port->read_status_mask |= CDNS_UART_IXR_BRK;
  215. framerrprocessed = 1;
  216. continue;
  217. }
  218. }
  219. if (is_rxbs_support && (rxbs_status & CDNS_UART_RXBS_BRK)) {
  220. port->icount.brk++;
  221. status = TTY_BREAK;
  222. if (uart_handle_break(port))
  223. continue;
  224. }
  225. isrstatus &= port->read_status_mask;
  226. isrstatus &= ~port->ignore_status_mask;
  227. status_mask = port->read_status_mask;
  228. status_mask &= ~port->ignore_status_mask;
  229. if (data &&
  230. (port->read_status_mask & CDNS_UART_IXR_BRK)) {
  231. port->read_status_mask &= ~CDNS_UART_IXR_BRK;
  232. port->icount.brk++;
  233. if (uart_handle_break(port))
  234. continue;
  235. }
  236. if (uart_handle_sysrq_char(port, data))
  237. continue;
  238. if (is_rxbs_support) {
  239. if ((rxbs_status & CDNS_UART_RXBS_PARITY)
  240. && (status_mask & CDNS_UART_IXR_PARITY)) {
  241. port->icount.parity++;
  242. status = TTY_PARITY;
  243. }
  244. if ((rxbs_status & CDNS_UART_RXBS_FRAMING)
  245. && (status_mask & CDNS_UART_IXR_PARITY)) {
  246. port->icount.frame++;
  247. status = TTY_FRAME;
  248. }
  249. } else {
  250. if (isrstatus & CDNS_UART_IXR_PARITY) {
  251. port->icount.parity++;
  252. status = TTY_PARITY;
  253. }
  254. if ((isrstatus & CDNS_UART_IXR_FRAMING) &&
  255. !framerrprocessed) {
  256. port->icount.frame++;
  257. status = TTY_FRAME;
  258. }
  259. }
  260. if (isrstatus & CDNS_UART_IXR_OVERRUN) {
  261. port->icount.overrun++;
  262. tty_insert_flip_char(&port->state->port, 0,
  263. TTY_OVERRUN);
  264. }
  265. tty_insert_flip_char(&port->state->port, data, status);
  266. isrstatus = 0;
  267. }
  268. spin_unlock(&port->lock);
  269. tty_flip_buffer_push(&port->state->port);
  270. spin_lock(&port->lock);
  271. }
  272. /**
  273. * cdns_uart_handle_tx - Handle the bytes to be Txed.
  274. * @dev_id: Id of the UART port
  275. * Return: None
  276. */
  277. static void cdns_uart_handle_tx(void *dev_id)
  278. {
  279. struct uart_port *port = (struct uart_port *)dev_id;
  280. unsigned int numbytes;
  281. if (uart_circ_empty(&port->state->xmit)) {
  282. writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IDR);
  283. } else {
  284. numbytes = port->fifosize;
  285. while (numbytes && !uart_circ_empty(&port->state->xmit) &&
  286. !(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)) {
  287. /*
  288. * Get the data from the UART circular buffer
  289. * and write it to the cdns_uart's TX_FIFO
  290. * register.
  291. */
  292. writel(
  293. port->state->xmit.buf[port->state->xmit.
  294. tail], port->membase + CDNS_UART_FIFO);
  295. port->icount.tx++;
  296. /*
  297. * Adjust the tail of the UART buffer and wrap
  298. * the buffer if it reaches limit.
  299. */
  300. port->state->xmit.tail =
  301. (port->state->xmit.tail + 1) &
  302. (UART_XMIT_SIZE - 1);
  303. numbytes--;
  304. }
  305. if (uart_circ_chars_pending(
  306. &port->state->xmit) < WAKEUP_CHARS)
  307. uart_write_wakeup(port);
  308. }
  309. }
  310. /**
  311. * cdns_uart_isr - Interrupt handler
  312. * @irq: Irq number
  313. * @dev_id: Id of the port
  314. *
  315. * Return: IRQHANDLED
  316. */
  317. static irqreturn_t cdns_uart_isr(int irq, void *dev_id)
  318. {
  319. struct uart_port *port = (struct uart_port *)dev_id;
  320. unsigned int isrstatus;
  321. spin_lock(&port->lock);
  322. /* Read the interrupt status register to determine which
  323. * interrupt(s) is/are active and clear them.
  324. */
  325. isrstatus = readl(port->membase + CDNS_UART_ISR);
  326. writel(isrstatus, port->membase + CDNS_UART_ISR);
  327. if (isrstatus & CDNS_UART_IXR_TXEMPTY) {
  328. cdns_uart_handle_tx(dev_id);
  329. isrstatus &= ~CDNS_UART_IXR_TXEMPTY;
  330. }
  331. /*
  332. * Skip RX processing if RX is disabled as RXEMPTY will never be set
  333. * as read bytes will not be removed from the FIFO.
  334. */
  335. if (isrstatus & CDNS_UART_IXR_RXMASK &&
  336. !(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS))
  337. cdns_uart_handle_rx(dev_id, isrstatus);
  338. spin_unlock(&port->lock);
  339. return IRQ_HANDLED;
  340. }
  341. /**
  342. * cdns_uart_calc_baud_divs - Calculate baud rate divisors
  343. * @clk: UART module input clock
  344. * @baud: Desired baud rate
  345. * @rbdiv: BDIV value (return value)
  346. * @rcd: CD value (return value)
  347. * @div8: Value for clk_sel bit in mod (return value)
  348. * Return: baud rate, requested baud when possible, or actual baud when there
  349. * was too much error, zero if no valid divisors are found.
  350. *
  351. * Formula to obtain baud rate is
  352. * baud_tx/rx rate = clk/CD * (BDIV + 1)
  353. * input_clk = (Uart User Defined Clock or Apb Clock)
  354. * depends on UCLKEN in MR Reg
  355. * clk = input_clk or input_clk/8;
  356. * depends on CLKS in MR reg
  357. * CD and BDIV depends on values in
  358. * baud rate generate register
  359. * baud rate clock divisor register
  360. */
  361. static unsigned int cdns_uart_calc_baud_divs(unsigned int clk,
  362. unsigned int baud, u32 *rbdiv, u32 *rcd, int *div8)
  363. {
  364. u32 cd, bdiv;
  365. unsigned int calc_baud;
  366. unsigned int bestbaud = 0;
  367. unsigned int bauderror;
  368. unsigned int besterror = ~0;
  369. if (baud < clk / ((CDNS_UART_BDIV_MAX + 1) * CDNS_UART_CD_MAX)) {
  370. *div8 = 1;
  371. clk /= 8;
  372. } else {
  373. *div8 = 0;
  374. }
  375. for (bdiv = CDNS_UART_BDIV_MIN; bdiv <= CDNS_UART_BDIV_MAX; bdiv++) {
  376. cd = DIV_ROUND_CLOSEST(clk, baud * (bdiv + 1));
  377. if (cd < 1 || cd > CDNS_UART_CD_MAX)
  378. continue;
  379. calc_baud = clk / (cd * (bdiv + 1));
  380. if (baud > calc_baud)
  381. bauderror = baud - calc_baud;
  382. else
  383. bauderror = calc_baud - baud;
  384. if (besterror > bauderror) {
  385. *rbdiv = bdiv;
  386. *rcd = cd;
  387. bestbaud = calc_baud;
  388. besterror = bauderror;
  389. }
  390. }
  391. /* use the values when percent error is acceptable */
  392. if (((besterror * 100) / baud) < 3)
  393. bestbaud = baud;
  394. return bestbaud;
  395. }
  396. /**
  397. * cdns_uart_set_baud_rate - Calculate and set the baud rate
  398. * @port: Handle to the uart port structure
  399. * @baud: Baud rate to set
  400. * Return: baud rate, requested baud when possible, or actual baud when there
  401. * was too much error, zero if no valid divisors are found.
  402. */
  403. static unsigned int cdns_uart_set_baud_rate(struct uart_port *port,
  404. unsigned int baud)
  405. {
  406. unsigned int calc_baud;
  407. u32 cd = 0, bdiv = 0;
  408. u32 mreg;
  409. int div8;
  410. struct cdns_uart *cdns_uart = port->private_data;
  411. calc_baud = cdns_uart_calc_baud_divs(port->uartclk, baud, &bdiv, &cd,
  412. &div8);
  413. /* Write new divisors to hardware */
  414. mreg = readl(port->membase + CDNS_UART_MR);
  415. if (div8)
  416. mreg |= CDNS_UART_MR_CLKSEL;
  417. else
  418. mreg &= ~CDNS_UART_MR_CLKSEL;
  419. writel(mreg, port->membase + CDNS_UART_MR);
  420. writel(cd, port->membase + CDNS_UART_BAUDGEN);
  421. writel(bdiv, port->membase + CDNS_UART_BAUDDIV);
  422. cdns_uart->baud = baud;
  423. return calc_baud;
  424. }
  425. #ifdef CONFIG_COMMON_CLK
  426. /**
  427. * cdns_uart_clk_notitifer_cb - Clock notifier callback
  428. * @nb: Notifier block
  429. * @event: Notify event
  430. * @data: Notifier data
  431. * Return: NOTIFY_OK or NOTIFY_DONE on success, NOTIFY_BAD on error.
  432. */
  433. static int cdns_uart_clk_notifier_cb(struct notifier_block *nb,
  434. unsigned long event, void *data)
  435. {
  436. u32 ctrl_reg;
  437. struct uart_port *port;
  438. int locked = 0;
  439. struct clk_notifier_data *ndata = data;
  440. unsigned long flags = 0;
  441. struct cdns_uart *cdns_uart = to_cdns_uart(nb);
  442. port = cdns_uart->port;
  443. if (port->suspended)
  444. return NOTIFY_OK;
  445. switch (event) {
  446. case PRE_RATE_CHANGE:
  447. {
  448. u32 bdiv, cd;
  449. int div8;
  450. /*
  451. * Find out if current baud-rate can be achieved with new clock
  452. * frequency.
  453. */
  454. if (!cdns_uart_calc_baud_divs(ndata->new_rate, cdns_uart->baud,
  455. &bdiv, &cd, &div8)) {
  456. dev_warn(port->dev, "clock rate change rejected\n");
  457. return NOTIFY_BAD;
  458. }
  459. spin_lock_irqsave(&cdns_uart->port->lock, flags);
  460. /* Disable the TX and RX to set baud rate */
  461. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  462. ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS;
  463. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  464. spin_unlock_irqrestore(&cdns_uart->port->lock, flags);
  465. return NOTIFY_OK;
  466. }
  467. case POST_RATE_CHANGE:
  468. /*
  469. * Set clk dividers to generate correct baud with new clock
  470. * frequency.
  471. */
  472. spin_lock_irqsave(&cdns_uart->port->lock, flags);
  473. locked = 1;
  474. port->uartclk = ndata->new_rate;
  475. cdns_uart->baud = cdns_uart_set_baud_rate(cdns_uart->port,
  476. cdns_uart->baud);
  477. /* fall through */
  478. case ABORT_RATE_CHANGE:
  479. if (!locked)
  480. spin_lock_irqsave(&cdns_uart->port->lock, flags);
  481. /* Set TX/RX Reset */
  482. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  483. ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST;
  484. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  485. while (readl(port->membase + CDNS_UART_CR) &
  486. (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
  487. cpu_relax();
  488. /*
  489. * Clear the RX disable and TX disable bits and then set the TX
  490. * enable bit and RX enable bit to enable the transmitter and
  491. * receiver.
  492. */
  493. writel(rx_timeout, port->membase + CDNS_UART_RXTOUT);
  494. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  495. ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS);
  496. ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN;
  497. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  498. spin_unlock_irqrestore(&cdns_uart->port->lock, flags);
  499. return NOTIFY_OK;
  500. default:
  501. return NOTIFY_DONE;
  502. }
  503. }
  504. #endif
  505. /**
  506. * cdns_uart_start_tx - Start transmitting bytes
  507. * @port: Handle to the uart port structure
  508. */
  509. static void cdns_uart_start_tx(struct uart_port *port)
  510. {
  511. unsigned int status;
  512. if (uart_tx_stopped(port))
  513. return;
  514. /*
  515. * Set the TX enable bit and clear the TX disable bit to enable the
  516. * transmitter.
  517. */
  518. status = readl(port->membase + CDNS_UART_CR);
  519. status &= ~CDNS_UART_CR_TX_DIS;
  520. status |= CDNS_UART_CR_TX_EN;
  521. writel(status, port->membase + CDNS_UART_CR);
  522. if (uart_circ_empty(&port->state->xmit))
  523. return;
  524. cdns_uart_handle_tx(port);
  525. writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_ISR);
  526. /* Enable the TX Empty interrupt */
  527. writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IER);
  528. }
  529. /**
  530. * cdns_uart_stop_tx - Stop TX
  531. * @port: Handle to the uart port structure
  532. */
  533. static void cdns_uart_stop_tx(struct uart_port *port)
  534. {
  535. unsigned int regval;
  536. regval = readl(port->membase + CDNS_UART_CR);
  537. regval |= CDNS_UART_CR_TX_DIS;
  538. /* Disable the transmitter */
  539. writel(regval, port->membase + CDNS_UART_CR);
  540. }
  541. /**
  542. * cdns_uart_stop_rx - Stop RX
  543. * @port: Handle to the uart port structure
  544. */
  545. static void cdns_uart_stop_rx(struct uart_port *port)
  546. {
  547. unsigned int regval;
  548. /* Disable RX IRQs */
  549. writel(CDNS_UART_RX_IRQS, port->membase + CDNS_UART_IDR);
  550. /* Disable the receiver */
  551. regval = readl(port->membase + CDNS_UART_CR);
  552. regval |= CDNS_UART_CR_RX_DIS;
  553. writel(regval, port->membase + CDNS_UART_CR);
  554. }
  555. /**
  556. * cdns_uart_tx_empty - Check whether TX is empty
  557. * @port: Handle to the uart port structure
  558. *
  559. * Return: TIOCSER_TEMT on success, 0 otherwise
  560. */
  561. static unsigned int cdns_uart_tx_empty(struct uart_port *port)
  562. {
  563. unsigned int status;
  564. status = readl(port->membase + CDNS_UART_SR) &
  565. CDNS_UART_SR_TXEMPTY;
  566. return status ? TIOCSER_TEMT : 0;
  567. }
  568. /**
  569. * cdns_uart_break_ctl - Based on the input ctl we have to start or stop
  570. * transmitting char breaks
  571. * @port: Handle to the uart port structure
  572. * @ctl: Value based on which start or stop decision is taken
  573. */
  574. static void cdns_uart_break_ctl(struct uart_port *port, int ctl)
  575. {
  576. unsigned int status;
  577. unsigned long flags;
  578. spin_lock_irqsave(&port->lock, flags);
  579. status = readl(port->membase + CDNS_UART_CR);
  580. if (ctl == -1)
  581. writel(CDNS_UART_CR_STARTBRK | status,
  582. port->membase + CDNS_UART_CR);
  583. else {
  584. if ((status & CDNS_UART_CR_STOPBRK) == 0)
  585. writel(CDNS_UART_CR_STOPBRK | status,
  586. port->membase + CDNS_UART_CR);
  587. }
  588. spin_unlock_irqrestore(&port->lock, flags);
  589. }
  590. /**
  591. * cdns_uart_set_termios - termios operations, handling data length, parity,
  592. * stop bits, flow control, baud rate
  593. * @port: Handle to the uart port structure
  594. * @termios: Handle to the input termios structure
  595. * @old: Values of the previously saved termios structure
  596. */
  597. static void cdns_uart_set_termios(struct uart_port *port,
  598. struct ktermios *termios, struct ktermios *old)
  599. {
  600. unsigned int cval = 0;
  601. unsigned int baud, minbaud, maxbaud;
  602. unsigned long flags;
  603. unsigned int ctrl_reg, mode_reg, val;
  604. int err;
  605. /* Wait for the transmit FIFO to empty before making changes */
  606. if (!(readl(port->membase + CDNS_UART_CR) &
  607. CDNS_UART_CR_TX_DIS)) {
  608. err = readl_poll_timeout(port->membase + CDNS_UART_SR,
  609. val, (val & CDNS_UART_SR_TXEMPTY),
  610. 1000, TX_TIMEOUT);
  611. if (err) {
  612. dev_err(port->dev, "timed out waiting for tx empty");
  613. return;
  614. }
  615. }
  616. spin_lock_irqsave(&port->lock, flags);
  617. /* Disable the TX and RX to set baud rate */
  618. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  619. ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS;
  620. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  621. /*
  622. * Min baud rate = 6bps and Max Baud Rate is 10Mbps for 100Mhz clk
  623. * min and max baud should be calculated here based on port->uartclk.
  624. * this way we get a valid baud and can safely call set_baud()
  625. */
  626. minbaud = port->uartclk /
  627. ((CDNS_UART_BDIV_MAX + 1) * CDNS_UART_CD_MAX * 8);
  628. maxbaud = port->uartclk / (CDNS_UART_BDIV_MIN + 1);
  629. baud = uart_get_baud_rate(port, termios, old, minbaud, maxbaud);
  630. baud = cdns_uart_set_baud_rate(port, baud);
  631. if (tty_termios_baud_rate(termios))
  632. tty_termios_encode_baud_rate(termios, baud, baud);
  633. /* Update the per-port timeout. */
  634. uart_update_timeout(port, termios->c_cflag, baud);
  635. /* Set TX/RX Reset */
  636. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  637. ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST;
  638. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  639. while (readl(port->membase + CDNS_UART_CR) &
  640. (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
  641. cpu_relax();
  642. /*
  643. * Clear the RX disable and TX disable bits and then set the TX enable
  644. * bit and RX enable bit to enable the transmitter and receiver.
  645. */
  646. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  647. ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS);
  648. ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN;
  649. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  650. writel(rx_timeout, port->membase + CDNS_UART_RXTOUT);
  651. port->read_status_mask = CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_RXTRIG |
  652. CDNS_UART_IXR_OVERRUN | CDNS_UART_IXR_TOUT;
  653. port->ignore_status_mask = 0;
  654. if (termios->c_iflag & INPCK)
  655. port->read_status_mask |= CDNS_UART_IXR_PARITY |
  656. CDNS_UART_IXR_FRAMING;
  657. if (termios->c_iflag & IGNPAR)
  658. port->ignore_status_mask |= CDNS_UART_IXR_PARITY |
  659. CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN;
  660. /* ignore all characters if CREAD is not set */
  661. if ((termios->c_cflag & CREAD) == 0)
  662. port->ignore_status_mask |= CDNS_UART_IXR_RXTRIG |
  663. CDNS_UART_IXR_TOUT | CDNS_UART_IXR_PARITY |
  664. CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN;
  665. mode_reg = readl(port->membase + CDNS_UART_MR);
  666. /* Handling Data Size */
  667. switch (termios->c_cflag & CSIZE) {
  668. case CS6:
  669. cval |= CDNS_UART_MR_CHARLEN_6_BIT;
  670. break;
  671. case CS7:
  672. cval |= CDNS_UART_MR_CHARLEN_7_BIT;
  673. break;
  674. default:
  675. case CS8:
  676. cval |= CDNS_UART_MR_CHARLEN_8_BIT;
  677. termios->c_cflag &= ~CSIZE;
  678. termios->c_cflag |= CS8;
  679. break;
  680. }
  681. /* Handling Parity and Stop Bits length */
  682. if (termios->c_cflag & CSTOPB)
  683. cval |= CDNS_UART_MR_STOPMODE_2_BIT; /* 2 STOP bits */
  684. else
  685. cval |= CDNS_UART_MR_STOPMODE_1_BIT; /* 1 STOP bit */
  686. if (termios->c_cflag & PARENB) {
  687. /* Mark or Space parity */
  688. if (termios->c_cflag & CMSPAR) {
  689. if (termios->c_cflag & PARODD)
  690. cval |= CDNS_UART_MR_PARITY_MARK;
  691. else
  692. cval |= CDNS_UART_MR_PARITY_SPACE;
  693. } else {
  694. if (termios->c_cflag & PARODD)
  695. cval |= CDNS_UART_MR_PARITY_ODD;
  696. else
  697. cval |= CDNS_UART_MR_PARITY_EVEN;
  698. }
  699. } else {
  700. cval |= CDNS_UART_MR_PARITY_NONE;
  701. }
  702. cval |= mode_reg & 1;
  703. writel(cval, port->membase + CDNS_UART_MR);
  704. spin_unlock_irqrestore(&port->lock, flags);
  705. }
  706. /**
  707. * cdns_uart_startup - Called when an application opens a cdns_uart port
  708. * @port: Handle to the uart port structure
  709. *
  710. * Return: 0 on success, negative errno otherwise
  711. */
  712. static int cdns_uart_startup(struct uart_port *port)
  713. {
  714. struct cdns_uart *cdns_uart = port->private_data;
  715. bool is_brk_support;
  716. int ret;
  717. unsigned long flags;
  718. unsigned int status = 0;
  719. is_brk_support = cdns_uart->quirks & CDNS_UART_RXBS_SUPPORT;
  720. spin_lock_irqsave(&port->lock, flags);
  721. /* Disable the TX and RX */
  722. writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS,
  723. port->membase + CDNS_UART_CR);
  724. /* Set the Control Register with TX/RX Enable, TX/RX Reset,
  725. * no break chars.
  726. */
  727. writel(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST,
  728. port->membase + CDNS_UART_CR);
  729. while (readl(port->membase + CDNS_UART_CR) &
  730. (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
  731. cpu_relax();
  732. /*
  733. * Clear the RX disable bit and then set the RX enable bit to enable
  734. * the receiver.
  735. */
  736. status = readl(port->membase + CDNS_UART_CR);
  737. status &= ~CDNS_UART_CR_RX_DIS;
  738. status |= CDNS_UART_CR_RX_EN;
  739. writel(status, port->membase + CDNS_UART_CR);
  740. /* Set the Mode Register with normal mode,8 data bits,1 stop bit,
  741. * no parity.
  742. */
  743. writel(CDNS_UART_MR_CHMODE_NORM | CDNS_UART_MR_STOPMODE_1_BIT
  744. | CDNS_UART_MR_PARITY_NONE | CDNS_UART_MR_CHARLEN_8_BIT,
  745. port->membase + CDNS_UART_MR);
  746. /*
  747. * Set the RX FIFO Trigger level to use most of the FIFO, but it
  748. * can be tuned with a module parameter
  749. */
  750. writel(rx_trigger_level, port->membase + CDNS_UART_RXWM);
  751. /*
  752. * Receive Timeout register is enabled but it
  753. * can be tuned with a module parameter
  754. */
  755. writel(rx_timeout, port->membase + CDNS_UART_RXTOUT);
  756. /* Clear out any pending interrupts before enabling them */
  757. writel(readl(port->membase + CDNS_UART_ISR),
  758. port->membase + CDNS_UART_ISR);
  759. spin_unlock_irqrestore(&port->lock, flags);
  760. ret = request_irq(port->irq, cdns_uart_isr, 0, CDNS_UART_NAME, port);
  761. if (ret) {
  762. dev_err(port->dev, "request_irq '%d' failed with %d\n",
  763. port->irq, ret);
  764. return ret;
  765. }
  766. /* Set the Interrupt Registers with desired interrupts */
  767. if (is_brk_support)
  768. writel(CDNS_UART_RX_IRQS | CDNS_UART_IXR_BRK,
  769. port->membase + CDNS_UART_IER);
  770. else
  771. writel(CDNS_UART_RX_IRQS, port->membase + CDNS_UART_IER);
  772. return 0;
  773. }
  774. /**
  775. * cdns_uart_shutdown - Called when an application closes a cdns_uart port
  776. * @port: Handle to the uart port structure
  777. */
  778. static void cdns_uart_shutdown(struct uart_port *port)
  779. {
  780. int status;
  781. unsigned long flags;
  782. spin_lock_irqsave(&port->lock, flags);
  783. /* Disable interrupts */
  784. status = readl(port->membase + CDNS_UART_IMR);
  785. writel(status, port->membase + CDNS_UART_IDR);
  786. writel(0xffffffff, port->membase + CDNS_UART_ISR);
  787. /* Disable the TX and RX */
  788. writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS,
  789. port->membase + CDNS_UART_CR);
  790. spin_unlock_irqrestore(&port->lock, flags);
  791. free_irq(port->irq, port);
  792. }
  793. /**
  794. * cdns_uart_type - Set UART type to cdns_uart port
  795. * @port: Handle to the uart port structure
  796. *
  797. * Return: string on success, NULL otherwise
  798. */
  799. static const char *cdns_uart_type(struct uart_port *port)
  800. {
  801. return port->type == PORT_XUARTPS ? CDNS_UART_NAME : NULL;
  802. }
  803. /**
  804. * cdns_uart_verify_port - Verify the port params
  805. * @port: Handle to the uart port structure
  806. * @ser: Handle to the structure whose members are compared
  807. *
  808. * Return: 0 on success, negative errno otherwise.
  809. */
  810. static int cdns_uart_verify_port(struct uart_port *port,
  811. struct serial_struct *ser)
  812. {
  813. if (ser->type != PORT_UNKNOWN && ser->type != PORT_XUARTPS)
  814. return -EINVAL;
  815. if (port->irq != ser->irq)
  816. return -EINVAL;
  817. if (ser->io_type != UPIO_MEM)
  818. return -EINVAL;
  819. if (port->iobase != ser->port)
  820. return -EINVAL;
  821. if (ser->hub6 != 0)
  822. return -EINVAL;
  823. return 0;
  824. }
  825. /**
  826. * cdns_uart_request_port - Claim the memory region attached to cdns_uart port,
  827. * called when the driver adds a cdns_uart port via
  828. * uart_add_one_port()
  829. * @port: Handle to the uart port structure
  830. *
  831. * Return: 0 on success, negative errno otherwise.
  832. */
  833. static int cdns_uart_request_port(struct uart_port *port)
  834. {
  835. if (!request_mem_region(port->mapbase, CDNS_UART_REGISTER_SPACE,
  836. CDNS_UART_NAME)) {
  837. return -ENOMEM;
  838. }
  839. port->membase = ioremap(port->mapbase, CDNS_UART_REGISTER_SPACE);
  840. if (!port->membase) {
  841. dev_err(port->dev, "Unable to map registers\n");
  842. release_mem_region(port->mapbase, CDNS_UART_REGISTER_SPACE);
  843. return -ENOMEM;
  844. }
  845. return 0;
  846. }
  847. /**
  848. * cdns_uart_release_port - Release UART port
  849. * @port: Handle to the uart port structure
  850. *
  851. * Release the memory region attached to a cdns_uart port. Called when the
  852. * driver removes a cdns_uart port via uart_remove_one_port().
  853. */
  854. static void cdns_uart_release_port(struct uart_port *port)
  855. {
  856. release_mem_region(port->mapbase, CDNS_UART_REGISTER_SPACE);
  857. iounmap(port->membase);
  858. port->membase = NULL;
  859. }
  860. /**
  861. * cdns_uart_config_port - Configure UART port
  862. * @port: Handle to the uart port structure
  863. * @flags: If any
  864. */
  865. static void cdns_uart_config_port(struct uart_port *port, int flags)
  866. {
  867. if (flags & UART_CONFIG_TYPE && cdns_uart_request_port(port) == 0)
  868. port->type = PORT_XUARTPS;
  869. }
  870. /**
  871. * cdns_uart_get_mctrl - Get the modem control state
  872. * @port: Handle to the uart port structure
  873. *
  874. * Return: the modem control state
  875. */
  876. static unsigned int cdns_uart_get_mctrl(struct uart_port *port)
  877. {
  878. return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
  879. }
  880. static void cdns_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
  881. {
  882. u32 val;
  883. u32 mode_reg;
  884. val = readl(port->membase + CDNS_UART_MODEMCR);
  885. mode_reg = readl(port->membase + CDNS_UART_MR);
  886. val &= ~(CDNS_UART_MODEMCR_RTS | CDNS_UART_MODEMCR_DTR);
  887. mode_reg &= ~CDNS_UART_MR_CHMODE_MASK;
  888. if (mctrl & TIOCM_RTS)
  889. val |= CDNS_UART_MODEMCR_RTS;
  890. if (mctrl & TIOCM_DTR)
  891. val |= CDNS_UART_MODEMCR_DTR;
  892. if (mctrl & TIOCM_LOOP)
  893. mode_reg |= CDNS_UART_MR_CHMODE_L_LOOP;
  894. else
  895. mode_reg |= CDNS_UART_MR_CHMODE_NORM;
  896. writel(val, port->membase + CDNS_UART_MODEMCR);
  897. writel(mode_reg, port->membase + CDNS_UART_MR);
  898. }
  899. #ifdef CONFIG_CONSOLE_POLL
  900. static int cdns_uart_poll_get_char(struct uart_port *port)
  901. {
  902. int c;
  903. unsigned long flags;
  904. spin_lock_irqsave(&port->lock, flags);
  905. /* Check if FIFO is empty */
  906. if (readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_RXEMPTY)
  907. c = NO_POLL_CHAR;
  908. else /* Read a character */
  909. c = (unsigned char) readl(port->membase + CDNS_UART_FIFO);
  910. spin_unlock_irqrestore(&port->lock, flags);
  911. return c;
  912. }
  913. static void cdns_uart_poll_put_char(struct uart_port *port, unsigned char c)
  914. {
  915. unsigned long flags;
  916. spin_lock_irqsave(&port->lock, flags);
  917. /* Wait until FIFO is empty */
  918. while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY))
  919. cpu_relax();
  920. /* Write a character */
  921. writel(c, port->membase + CDNS_UART_FIFO);
  922. /* Wait until FIFO is empty */
  923. while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY))
  924. cpu_relax();
  925. spin_unlock_irqrestore(&port->lock, flags);
  926. return;
  927. }
  928. #endif
  929. static void cdns_uart_pm(struct uart_port *port, unsigned int state,
  930. unsigned int oldstate)
  931. {
  932. switch (state) {
  933. case UART_PM_STATE_OFF:
  934. pm_runtime_mark_last_busy(port->dev);
  935. pm_runtime_put_autosuspend(port->dev);
  936. break;
  937. default:
  938. pm_runtime_get_sync(port->dev);
  939. break;
  940. }
  941. }
  942. static const struct uart_ops cdns_uart_ops = {
  943. .set_mctrl = cdns_uart_set_mctrl,
  944. .get_mctrl = cdns_uart_get_mctrl,
  945. .start_tx = cdns_uart_start_tx,
  946. .stop_tx = cdns_uart_stop_tx,
  947. .stop_rx = cdns_uart_stop_rx,
  948. .tx_empty = cdns_uart_tx_empty,
  949. .break_ctl = cdns_uart_break_ctl,
  950. .set_termios = cdns_uart_set_termios,
  951. .startup = cdns_uart_startup,
  952. .shutdown = cdns_uart_shutdown,
  953. .pm = cdns_uart_pm,
  954. .type = cdns_uart_type,
  955. .verify_port = cdns_uart_verify_port,
  956. .request_port = cdns_uart_request_port,
  957. .release_port = cdns_uart_release_port,
  958. .config_port = cdns_uart_config_port,
  959. #ifdef CONFIG_CONSOLE_POLL
  960. .poll_get_char = cdns_uart_poll_get_char,
  961. .poll_put_char = cdns_uart_poll_put_char,
  962. #endif
  963. };
  964. #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
  965. /**
  966. * cdns_uart_console_putchar - write the character to the FIFO buffer
  967. * @port: Handle to the uart port structure
  968. * @ch: Character to be written
  969. */
  970. static void cdns_uart_console_putchar(struct uart_port *port, int ch)
  971. {
  972. while (readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)
  973. cpu_relax();
  974. writel(ch, port->membase + CDNS_UART_FIFO);
  975. }
  976. static void cdns_early_write(struct console *con, const char *s,
  977. unsigned n)
  978. {
  979. struct earlycon_device *dev = con->data;
  980. uart_console_write(&dev->port, s, n, cdns_uart_console_putchar);
  981. }
  982. static int __init cdns_early_console_setup(struct earlycon_device *device,
  983. const char *opt)
  984. {
  985. struct uart_port *port = &device->port;
  986. if (!port->membase)
  987. return -ENODEV;
  988. /* initialise control register */
  989. writel(CDNS_UART_CR_TX_EN|CDNS_UART_CR_TXRST|CDNS_UART_CR_RXRST,
  990. port->membase + CDNS_UART_CR);
  991. /* only set baud if specified on command line - otherwise
  992. * assume it has been initialized by a boot loader.
  993. */
  994. if (port->uartclk && device->baud) {
  995. u32 cd = 0, bdiv = 0;
  996. u32 mr;
  997. int div8;
  998. cdns_uart_calc_baud_divs(port->uartclk, device->baud,
  999. &bdiv, &cd, &div8);
  1000. mr = CDNS_UART_MR_PARITY_NONE;
  1001. if (div8)
  1002. mr |= CDNS_UART_MR_CLKSEL;
  1003. writel(mr, port->membase + CDNS_UART_MR);
  1004. writel(cd, port->membase + CDNS_UART_BAUDGEN);
  1005. writel(bdiv, port->membase + CDNS_UART_BAUDDIV);
  1006. }
  1007. device->con->write = cdns_early_write;
  1008. return 0;
  1009. }
  1010. OF_EARLYCON_DECLARE(cdns, "xlnx,xuartps", cdns_early_console_setup);
  1011. OF_EARLYCON_DECLARE(cdns, "cdns,uart-r1p8", cdns_early_console_setup);
  1012. OF_EARLYCON_DECLARE(cdns, "cdns,uart-r1p12", cdns_early_console_setup);
  1013. OF_EARLYCON_DECLARE(cdns, "xlnx,zynqmp-uart", cdns_early_console_setup);
  1014. /* Static pointer to console port */
  1015. static struct uart_port *console_port;
  1016. /**
  1017. * cdns_uart_console_write - perform write operation
  1018. * @co: Console handle
  1019. * @s: Pointer to character array
  1020. * @count: No of characters
  1021. */
  1022. static void cdns_uart_console_write(struct console *co, const char *s,
  1023. unsigned int count)
  1024. {
  1025. struct uart_port *port = console_port;
  1026. unsigned long flags;
  1027. unsigned int imr, ctrl;
  1028. int locked = 1;
  1029. if (port->sysrq)
  1030. locked = 0;
  1031. else if (oops_in_progress)
  1032. locked = spin_trylock_irqsave(&port->lock, flags);
  1033. else
  1034. spin_lock_irqsave(&port->lock, flags);
  1035. /* save and disable interrupt */
  1036. imr = readl(port->membase + CDNS_UART_IMR);
  1037. writel(imr, port->membase + CDNS_UART_IDR);
  1038. /*
  1039. * Make sure that the tx part is enabled. Set the TX enable bit and
  1040. * clear the TX disable bit to enable the transmitter.
  1041. */
  1042. ctrl = readl(port->membase + CDNS_UART_CR);
  1043. ctrl &= ~CDNS_UART_CR_TX_DIS;
  1044. ctrl |= CDNS_UART_CR_TX_EN;
  1045. writel(ctrl, port->membase + CDNS_UART_CR);
  1046. uart_console_write(port, s, count, cdns_uart_console_putchar);
  1047. while ((readl(port->membase + CDNS_UART_SR) &
  1048. (CDNS_UART_SR_TXEMPTY | CDNS_UART_SR_TACTIVE)) !=
  1049. CDNS_UART_SR_TXEMPTY)
  1050. cpu_relax();
  1051. /* restore interrupt state */
  1052. writel(imr, port->membase + CDNS_UART_IER);
  1053. if (locked)
  1054. spin_unlock_irqrestore(&port->lock, flags);
  1055. }
  1056. /**
  1057. * cdns_uart_console_setup - Initialize the uart to default config
  1058. * @co: Console handle
  1059. * @options: Initial settings of uart
  1060. *
  1061. * Return: 0 on success, negative errno otherwise.
  1062. */
  1063. static int cdns_uart_console_setup(struct console *co, char *options)
  1064. {
  1065. struct uart_port *port = console_port;
  1066. int baud = 9600;
  1067. int bits = 8;
  1068. int parity = 'n';
  1069. int flow = 'n';
  1070. unsigned long time_out;
  1071. if (!port->membase) {
  1072. pr_debug("console on " CDNS_UART_TTY_NAME "%i not present\n",
  1073. co->index);
  1074. return -ENODEV;
  1075. }
  1076. if (options)
  1077. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1078. /* Wait for tx_empty before setting up the console */
  1079. time_out = jiffies + usecs_to_jiffies(TX_TIMEOUT);
  1080. while (time_before(jiffies, time_out) &&
  1081. cdns_uart_tx_empty(port) != TIOCSER_TEMT)
  1082. cpu_relax();
  1083. return uart_set_options(port, co, baud, parity, bits, flow);
  1084. }
  1085. static struct uart_driver cdns_uart_uart_driver;
  1086. static struct console cdns_uart_console = {
  1087. .name = CDNS_UART_TTY_NAME,
  1088. .write = cdns_uart_console_write,
  1089. .device = uart_console_device,
  1090. .setup = cdns_uart_console_setup,
  1091. .flags = CON_PRINTBUFFER,
  1092. .index = -1, /* Specified on the cmdline (e.g. console=ttyPS ) */
  1093. .data = &cdns_uart_uart_driver,
  1094. };
  1095. #endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */
  1096. static struct uart_driver cdns_uart_uart_driver = {
  1097. .owner = THIS_MODULE,
  1098. .driver_name = CDNS_UART_NAME,
  1099. .dev_name = CDNS_UART_TTY_NAME,
  1100. .major = CDNS_UART_MAJOR,
  1101. .minor = CDNS_UART_MINOR,
  1102. .nr = CDNS_UART_NR_PORTS,
  1103. #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
  1104. .cons = &cdns_uart_console,
  1105. #endif
  1106. };
  1107. #ifdef CONFIG_PM_SLEEP
  1108. /**
  1109. * cdns_uart_suspend - suspend event
  1110. * @device: Pointer to the device structure
  1111. *
  1112. * Return: 0
  1113. */
  1114. static int cdns_uart_suspend(struct device *device)
  1115. {
  1116. struct uart_port *port = dev_get_drvdata(device);
  1117. int may_wake;
  1118. may_wake = device_may_wakeup(device);
  1119. if (console_suspend_enabled && may_wake) {
  1120. unsigned long flags = 0;
  1121. spin_lock_irqsave(&port->lock, flags);
  1122. /* Empty the receive FIFO 1st before making changes */
  1123. while (!(readl(port->membase + CDNS_UART_SR) &
  1124. CDNS_UART_SR_RXEMPTY))
  1125. readl(port->membase + CDNS_UART_FIFO);
  1126. /* set RX trigger level to 1 */
  1127. writel(1, port->membase + CDNS_UART_RXWM);
  1128. /* disable RX timeout interrups */
  1129. writel(CDNS_UART_IXR_TOUT, port->membase + CDNS_UART_IDR);
  1130. spin_unlock_irqrestore(&port->lock, flags);
  1131. }
  1132. /*
  1133. * Call the API provided in serial_core.c file which handles
  1134. * the suspend.
  1135. */
  1136. return uart_suspend_port(&cdns_uart_uart_driver, port);
  1137. }
  1138. /**
  1139. * cdns_uart_resume - Resume after a previous suspend
  1140. * @device: Pointer to the device structure
  1141. *
  1142. * Return: 0
  1143. */
  1144. static int cdns_uart_resume(struct device *device)
  1145. {
  1146. struct uart_port *port = dev_get_drvdata(device);
  1147. unsigned long flags = 0;
  1148. u32 ctrl_reg;
  1149. int may_wake;
  1150. may_wake = device_may_wakeup(device);
  1151. if (console_suspend_enabled && !may_wake) {
  1152. struct cdns_uart *cdns_uart = port->private_data;
  1153. clk_enable(cdns_uart->pclk);
  1154. clk_enable(cdns_uart->uartclk);
  1155. spin_lock_irqsave(&port->lock, flags);
  1156. /* Set TX/RX Reset */
  1157. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  1158. ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST;
  1159. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  1160. while (readl(port->membase + CDNS_UART_CR) &
  1161. (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
  1162. cpu_relax();
  1163. /* restore rx timeout value */
  1164. writel(rx_timeout, port->membase + CDNS_UART_RXTOUT);
  1165. /* Enable Tx/Rx */
  1166. ctrl_reg = readl(port->membase + CDNS_UART_CR);
  1167. ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS);
  1168. ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN;
  1169. writel(ctrl_reg, port->membase + CDNS_UART_CR);
  1170. clk_disable(cdns_uart->uartclk);
  1171. clk_disable(cdns_uart->pclk);
  1172. spin_unlock_irqrestore(&port->lock, flags);
  1173. } else {
  1174. spin_lock_irqsave(&port->lock, flags);
  1175. /* restore original rx trigger level */
  1176. writel(rx_trigger_level, port->membase + CDNS_UART_RXWM);
  1177. /* enable RX timeout interrupt */
  1178. writel(CDNS_UART_IXR_TOUT, port->membase + CDNS_UART_IER);
  1179. spin_unlock_irqrestore(&port->lock, flags);
  1180. }
  1181. return uart_resume_port(&cdns_uart_uart_driver, port);
  1182. }
  1183. #endif /* ! CONFIG_PM_SLEEP */
  1184. static int __maybe_unused cdns_runtime_suspend(struct device *dev)
  1185. {
  1186. struct uart_port *port = dev_get_drvdata(dev);
  1187. struct cdns_uart *cdns_uart = port->private_data;
  1188. clk_disable(cdns_uart->uartclk);
  1189. clk_disable(cdns_uart->pclk);
  1190. return 0;
  1191. };
  1192. static int __maybe_unused cdns_runtime_resume(struct device *dev)
  1193. {
  1194. struct uart_port *port = dev_get_drvdata(dev);
  1195. struct cdns_uart *cdns_uart = port->private_data;
  1196. clk_enable(cdns_uart->pclk);
  1197. clk_enable(cdns_uart->uartclk);
  1198. return 0;
  1199. };
  1200. static const struct dev_pm_ops cdns_uart_dev_pm_ops = {
  1201. SET_SYSTEM_SLEEP_PM_OPS(cdns_uart_suspend, cdns_uart_resume)
  1202. SET_RUNTIME_PM_OPS(cdns_runtime_suspend,
  1203. cdns_runtime_resume, NULL)
  1204. };
  1205. static const struct cdns_platform_data zynqmp_uart_def = {
  1206. .quirks = CDNS_UART_RXBS_SUPPORT, };
  1207. /* Match table for of_platform binding */
  1208. static const struct of_device_id cdns_uart_of_match[] = {
  1209. { .compatible = "xlnx,xuartps", },
  1210. { .compatible = "cdns,uart-r1p8", },
  1211. { .compatible = "cdns,uart-r1p12", .data = &zynqmp_uart_def },
  1212. { .compatible = "xlnx,zynqmp-uart", .data = &zynqmp_uart_def },
  1213. {}
  1214. };
  1215. MODULE_DEVICE_TABLE(of, cdns_uart_of_match);
  1216. /**
  1217. * cdns_uart_probe - Platform driver probe
  1218. * @pdev: Pointer to the platform device structure
  1219. *
  1220. * Return: 0 on success, negative errno otherwise
  1221. */
  1222. static int cdns_uart_probe(struct platform_device *pdev)
  1223. {
  1224. int rc, id, irq;
  1225. struct uart_port *port;
  1226. struct resource *res;
  1227. struct cdns_uart *cdns_uart_data;
  1228. const struct of_device_id *match;
  1229. cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data),
  1230. GFP_KERNEL);
  1231. if (!cdns_uart_data)
  1232. return -ENOMEM;
  1233. port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
  1234. if (!port)
  1235. return -ENOMEM;
  1236. match = of_match_node(cdns_uart_of_match, pdev->dev.of_node);
  1237. if (match && match->data) {
  1238. const struct cdns_platform_data *data = match->data;
  1239. cdns_uart_data->quirks = data->quirks;
  1240. }
  1241. cdns_uart_data->pclk = devm_clk_get(&pdev->dev, "pclk");
  1242. if (IS_ERR(cdns_uart_data->pclk)) {
  1243. cdns_uart_data->pclk = devm_clk_get(&pdev->dev, "aper_clk");
  1244. if (!IS_ERR(cdns_uart_data->pclk))
  1245. dev_err(&pdev->dev, "clock name 'aper_clk' is deprecated.\n");
  1246. }
  1247. if (IS_ERR(cdns_uart_data->pclk)) {
  1248. dev_err(&pdev->dev, "pclk clock not found.\n");
  1249. return PTR_ERR(cdns_uart_data->pclk);
  1250. }
  1251. cdns_uart_data->uartclk = devm_clk_get(&pdev->dev, "uart_clk");
  1252. if (IS_ERR(cdns_uart_data->uartclk)) {
  1253. cdns_uart_data->uartclk = devm_clk_get(&pdev->dev, "ref_clk");
  1254. if (!IS_ERR(cdns_uart_data->uartclk))
  1255. dev_err(&pdev->dev, "clock name 'ref_clk' is deprecated.\n");
  1256. }
  1257. if (IS_ERR(cdns_uart_data->uartclk)) {
  1258. dev_err(&pdev->dev, "uart_clk clock not found.\n");
  1259. return PTR_ERR(cdns_uart_data->uartclk);
  1260. }
  1261. rc = clk_prepare_enable(cdns_uart_data->pclk);
  1262. if (rc) {
  1263. dev_err(&pdev->dev, "Unable to enable pclk clock.\n");
  1264. return rc;
  1265. }
  1266. rc = clk_prepare_enable(cdns_uart_data->uartclk);
  1267. if (rc) {
  1268. dev_err(&pdev->dev, "Unable to enable device clock.\n");
  1269. goto err_out_clk_dis_pclk;
  1270. }
  1271. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1272. if (!res) {
  1273. rc = -ENODEV;
  1274. goto err_out_clk_disable;
  1275. }
  1276. irq = platform_get_irq(pdev, 0);
  1277. if (irq <= 0) {
  1278. rc = -ENXIO;
  1279. goto err_out_clk_disable;
  1280. }
  1281. #ifdef CONFIG_COMMON_CLK
  1282. cdns_uart_data->clk_rate_change_nb.notifier_call =
  1283. cdns_uart_clk_notifier_cb;
  1284. if (clk_notifier_register(cdns_uart_data->uartclk,
  1285. &cdns_uart_data->clk_rate_change_nb))
  1286. dev_warn(&pdev->dev, "Unable to register clock notifier.\n");
  1287. #endif
  1288. /* Look for a serialN alias */
  1289. id = of_alias_get_id(pdev->dev.of_node, "serial");
  1290. if (id < 0)
  1291. id = 0;
  1292. if (id >= CDNS_UART_NR_PORTS) {
  1293. dev_err(&pdev->dev, "Cannot get uart_port structure\n");
  1294. rc = -ENODEV;
  1295. goto err_out_notif_unreg;
  1296. }
  1297. /* At this point, we've got an empty uart_port struct, initialize it */
  1298. spin_lock_init(&port->lock);
  1299. port->membase = NULL;
  1300. port->irq = 0;
  1301. port->type = PORT_UNKNOWN;
  1302. port->iotype = UPIO_MEM32;
  1303. port->flags = UPF_BOOT_AUTOCONF;
  1304. port->ops = &cdns_uart_ops;
  1305. port->fifosize = CDNS_UART_FIFO_SIZE;
  1306. port->line = id;
  1307. port->dev = NULL;
  1308. /*
  1309. * Register the port.
  1310. * This function also registers this device with the tty layer
  1311. * and triggers invocation of the config_port() entry point.
  1312. */
  1313. port->mapbase = res->start;
  1314. port->irq = irq;
  1315. port->dev = &pdev->dev;
  1316. port->uartclk = clk_get_rate(cdns_uart_data->uartclk);
  1317. port->private_data = cdns_uart_data;
  1318. cdns_uart_data->port = port;
  1319. platform_set_drvdata(pdev, port);
  1320. pm_runtime_use_autosuspend(&pdev->dev);
  1321. pm_runtime_set_autosuspend_delay(&pdev->dev, UART_AUTOSUSPEND_TIMEOUT);
  1322. pm_runtime_set_active(&pdev->dev);
  1323. pm_runtime_enable(&pdev->dev);
  1324. #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
  1325. /*
  1326. * If console hasn't been found yet try to assign this port
  1327. * because it is required to be assigned for console setup function.
  1328. * If register_console() don't assign value, then console_port pointer
  1329. * is cleanup.
  1330. */
  1331. if (cdns_uart_uart_driver.cons->index == -1)
  1332. console_port = port;
  1333. #endif
  1334. rc = uart_add_one_port(&cdns_uart_uart_driver, port);
  1335. if (rc) {
  1336. dev_err(&pdev->dev,
  1337. "uart_add_one_port() failed; err=%i\n", rc);
  1338. goto err_out_pm_disable;
  1339. }
  1340. #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
  1341. /* This is not port which is used for console that's why clean it up */
  1342. if (cdns_uart_uart_driver.cons->index == -1)
  1343. console_port = NULL;
  1344. #endif
  1345. return 0;
  1346. err_out_pm_disable:
  1347. pm_runtime_disable(&pdev->dev);
  1348. pm_runtime_set_suspended(&pdev->dev);
  1349. pm_runtime_dont_use_autosuspend(&pdev->dev);
  1350. err_out_notif_unreg:
  1351. #ifdef CONFIG_COMMON_CLK
  1352. clk_notifier_unregister(cdns_uart_data->uartclk,
  1353. &cdns_uart_data->clk_rate_change_nb);
  1354. #endif
  1355. err_out_clk_disable:
  1356. clk_disable_unprepare(cdns_uart_data->uartclk);
  1357. err_out_clk_dis_pclk:
  1358. clk_disable_unprepare(cdns_uart_data->pclk);
  1359. return rc;
  1360. }
  1361. /**
  1362. * cdns_uart_remove - called when the platform driver is unregistered
  1363. * @pdev: Pointer to the platform device structure
  1364. *
  1365. * Return: 0 on success, negative errno otherwise
  1366. */
  1367. static int cdns_uart_remove(struct platform_device *pdev)
  1368. {
  1369. struct uart_port *port = platform_get_drvdata(pdev);
  1370. struct cdns_uart *cdns_uart_data = port->private_data;
  1371. int rc;
  1372. /* Remove the cdns_uart port from the serial core */
  1373. #ifdef CONFIG_COMMON_CLK
  1374. clk_notifier_unregister(cdns_uart_data->uartclk,
  1375. &cdns_uart_data->clk_rate_change_nb);
  1376. #endif
  1377. rc = uart_remove_one_port(&cdns_uart_uart_driver, port);
  1378. port->mapbase = 0;
  1379. clk_disable_unprepare(cdns_uart_data->uartclk);
  1380. clk_disable_unprepare(cdns_uart_data->pclk);
  1381. pm_runtime_disable(&pdev->dev);
  1382. pm_runtime_set_suspended(&pdev->dev);
  1383. pm_runtime_dont_use_autosuspend(&pdev->dev);
  1384. return rc;
  1385. }
  1386. static struct platform_driver cdns_uart_platform_driver = {
  1387. .probe = cdns_uart_probe,
  1388. .remove = cdns_uart_remove,
  1389. .driver = {
  1390. .name = CDNS_UART_NAME,
  1391. .of_match_table = cdns_uart_of_match,
  1392. .pm = &cdns_uart_dev_pm_ops,
  1393. .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_XILINX_PS_UART),
  1394. },
  1395. };
  1396. static int __init cdns_uart_init(void)
  1397. {
  1398. int retval = 0;
  1399. /* Register the cdns_uart driver with the serial core */
  1400. retval = uart_register_driver(&cdns_uart_uart_driver);
  1401. if (retval)
  1402. return retval;
  1403. /* Register the platform driver */
  1404. retval = platform_driver_register(&cdns_uart_platform_driver);
  1405. if (retval)
  1406. uart_unregister_driver(&cdns_uart_uart_driver);
  1407. return retval;
  1408. }
  1409. static void __exit cdns_uart_exit(void)
  1410. {
  1411. /* Unregister the platform driver */
  1412. platform_driver_unregister(&cdns_uart_platform_driver);
  1413. /* Unregister the cdns_uart driver */
  1414. uart_unregister_driver(&cdns_uart_uart_driver);
  1415. }
  1416. arch_initcall(cdns_uart_init);
  1417. module_exit(cdns_uart_exit);
  1418. MODULE_DESCRIPTION("Driver for Cadence UART");
  1419. MODULE_AUTHOR("Xilinx Inc.");
  1420. MODULE_LICENSE("GPL");