msm_serial.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for msm7k serial device and console
  4. *
  5. * Copyright (C) 2007 Google, Inc.
  6. * Author: Robert Love <rlove@google.com>
  7. * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
  8. */
  9. #if defined(CONFIG_SERIAL_MSM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  10. # define SUPPORT_SYSRQ
  11. #endif
  12. #include <linux/kernel.h>
  13. #include <linux/atomic.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/dmaengine.h>
  16. #include <linux/module.h>
  17. #include <linux/io.h>
  18. #include <linux/ioport.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/init.h>
  21. #include <linux/console.h>
  22. #include <linux/tty.h>
  23. #include <linux/tty_flip.h>
  24. #include <linux/serial_core.h>
  25. #include <linux/slab.h>
  26. #include <linux/clk.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/delay.h>
  29. #include <linux/of.h>
  30. #include <linux/of_device.h>
  31. #include <linux/wait.h>
  32. #define UART_MR1 0x0000
  33. #define UART_MR1_AUTO_RFR_LEVEL0 0x3F
  34. #define UART_MR1_AUTO_RFR_LEVEL1 0x3FF00
  35. #define UART_DM_MR1_AUTO_RFR_LEVEL1 0xFFFFFF00
  36. #define UART_MR1_RX_RDY_CTL BIT(7)
  37. #define UART_MR1_CTS_CTL BIT(6)
  38. #define UART_MR2 0x0004
  39. #define UART_MR2_ERROR_MODE BIT(6)
  40. #define UART_MR2_BITS_PER_CHAR 0x30
  41. #define UART_MR2_BITS_PER_CHAR_5 (0x0 << 4)
  42. #define UART_MR2_BITS_PER_CHAR_6 (0x1 << 4)
  43. #define UART_MR2_BITS_PER_CHAR_7 (0x2 << 4)
  44. #define UART_MR2_BITS_PER_CHAR_8 (0x3 << 4)
  45. #define UART_MR2_STOP_BIT_LEN_ONE (0x1 << 2)
  46. #define UART_MR2_STOP_BIT_LEN_TWO (0x3 << 2)
  47. #define UART_MR2_PARITY_MODE_NONE 0x0
  48. #define UART_MR2_PARITY_MODE_ODD 0x1
  49. #define UART_MR2_PARITY_MODE_EVEN 0x2
  50. #define UART_MR2_PARITY_MODE_SPACE 0x3
  51. #define UART_MR2_PARITY_MODE 0x3
  52. #define UART_CSR 0x0008
  53. #define UART_TF 0x000C
  54. #define UARTDM_TF 0x0070
  55. #define UART_CR 0x0010
  56. #define UART_CR_CMD_NULL (0 << 4)
  57. #define UART_CR_CMD_RESET_RX (1 << 4)
  58. #define UART_CR_CMD_RESET_TX (2 << 4)
  59. #define UART_CR_CMD_RESET_ERR (3 << 4)
  60. #define UART_CR_CMD_RESET_BREAK_INT (4 << 4)
  61. #define UART_CR_CMD_START_BREAK (5 << 4)
  62. #define UART_CR_CMD_STOP_BREAK (6 << 4)
  63. #define UART_CR_CMD_RESET_CTS (7 << 4)
  64. #define UART_CR_CMD_RESET_STALE_INT (8 << 4)
  65. #define UART_CR_CMD_PACKET_MODE (9 << 4)
  66. #define UART_CR_CMD_MODE_RESET (12 << 4)
  67. #define UART_CR_CMD_SET_RFR (13 << 4)
  68. #define UART_CR_CMD_RESET_RFR (14 << 4)
  69. #define UART_CR_CMD_PROTECTION_EN (16 << 4)
  70. #define UART_CR_CMD_STALE_EVENT_DISABLE (6 << 8)
  71. #define UART_CR_CMD_STALE_EVENT_ENABLE (80 << 4)
  72. #define UART_CR_CMD_FORCE_STALE (4 << 8)
  73. #define UART_CR_CMD_RESET_TX_READY (3 << 8)
  74. #define UART_CR_TX_DISABLE BIT(3)
  75. #define UART_CR_TX_ENABLE BIT(2)
  76. #define UART_CR_RX_DISABLE BIT(1)
  77. #define UART_CR_RX_ENABLE BIT(0)
  78. #define UART_CR_CMD_RESET_RXBREAK_START ((1 << 11) | (2 << 4))
  79. #define UART_IMR 0x0014
  80. #define UART_IMR_TXLEV BIT(0)
  81. #define UART_IMR_RXSTALE BIT(3)
  82. #define UART_IMR_RXLEV BIT(4)
  83. #define UART_IMR_DELTA_CTS BIT(5)
  84. #define UART_IMR_CURRENT_CTS BIT(6)
  85. #define UART_IMR_RXBREAK_START BIT(10)
  86. #define UART_IPR_RXSTALE_LAST 0x20
  87. #define UART_IPR_STALE_LSB 0x1F
  88. #define UART_IPR_STALE_TIMEOUT_MSB 0x3FF80
  89. #define UART_DM_IPR_STALE_TIMEOUT_MSB 0xFFFFFF80
  90. #define UART_IPR 0x0018
  91. #define UART_TFWR 0x001C
  92. #define UART_RFWR 0x0020
  93. #define UART_HCR 0x0024
  94. #define UART_MREG 0x0028
  95. #define UART_NREG 0x002C
  96. #define UART_DREG 0x0030
  97. #define UART_MNDREG 0x0034
  98. #define UART_IRDA 0x0038
  99. #define UART_MISR_MODE 0x0040
  100. #define UART_MISR_RESET 0x0044
  101. #define UART_MISR_EXPORT 0x0048
  102. #define UART_MISR_VAL 0x004C
  103. #define UART_TEST_CTRL 0x0050
  104. #define UART_SR 0x0008
  105. #define UART_SR_HUNT_CHAR BIT(7)
  106. #define UART_SR_RX_BREAK BIT(6)
  107. #define UART_SR_PAR_FRAME_ERR BIT(5)
  108. #define UART_SR_OVERRUN BIT(4)
  109. #define UART_SR_TX_EMPTY BIT(3)
  110. #define UART_SR_TX_READY BIT(2)
  111. #define UART_SR_RX_FULL BIT(1)
  112. #define UART_SR_RX_READY BIT(0)
  113. #define UART_RF 0x000C
  114. #define UARTDM_RF 0x0070
  115. #define UART_MISR 0x0010
  116. #define UART_ISR 0x0014
  117. #define UART_ISR_TX_READY BIT(7)
  118. #define UARTDM_RXFS 0x50
  119. #define UARTDM_RXFS_BUF_SHIFT 0x7
  120. #define UARTDM_RXFS_BUF_MASK 0x7
  121. #define UARTDM_DMEN 0x3C
  122. #define UARTDM_DMEN_RX_SC_ENABLE BIT(5)
  123. #define UARTDM_DMEN_TX_SC_ENABLE BIT(4)
  124. #define UARTDM_DMEN_TX_BAM_ENABLE BIT(2) /* UARTDM_1P4 */
  125. #define UARTDM_DMEN_TX_DM_ENABLE BIT(0) /* < UARTDM_1P4 */
  126. #define UARTDM_DMEN_RX_BAM_ENABLE BIT(3) /* UARTDM_1P4 */
  127. #define UARTDM_DMEN_RX_DM_ENABLE BIT(1) /* < UARTDM_1P4 */
  128. #define UARTDM_DMRX 0x34
  129. #define UARTDM_NCF_TX 0x40
  130. #define UARTDM_RX_TOTAL_SNAP 0x38
  131. #define UARTDM_BURST_SIZE 16 /* in bytes */
  132. #define UARTDM_TX_AIGN(x) ((x) & ~0x3) /* valid for > 1p3 */
  133. #define UARTDM_TX_MAX 256 /* in bytes, valid for <= 1p3 */
  134. #define UARTDM_RX_SIZE (UART_XMIT_SIZE / 4)
  135. enum {
  136. UARTDM_1P1 = 1,
  137. UARTDM_1P2,
  138. UARTDM_1P3,
  139. UARTDM_1P4,
  140. };
  141. struct msm_dma {
  142. struct dma_chan *chan;
  143. enum dma_data_direction dir;
  144. dma_addr_t phys;
  145. unsigned char *virt;
  146. dma_cookie_t cookie;
  147. u32 enable_bit;
  148. unsigned int count;
  149. struct dma_async_tx_descriptor *desc;
  150. };
  151. struct msm_port {
  152. struct uart_port uart;
  153. char name[16];
  154. struct clk *clk;
  155. struct clk *pclk;
  156. unsigned int imr;
  157. int is_uartdm;
  158. unsigned int old_snap_state;
  159. bool break_detected;
  160. struct msm_dma tx_dma;
  161. struct msm_dma rx_dma;
  162. };
  163. #define UART_TO_MSM(uart_port) container_of(uart_port, struct msm_port, uart)
  164. static
  165. void msm_write(struct uart_port *port, unsigned int val, unsigned int off)
  166. {
  167. writel_relaxed(val, port->membase + off);
  168. }
  169. static
  170. unsigned int msm_read(struct uart_port *port, unsigned int off)
  171. {
  172. return readl_relaxed(port->membase + off);
  173. }
  174. /*
  175. * Setup the MND registers to use the TCXO clock.
  176. */
  177. static void msm_serial_set_mnd_regs_tcxo(struct uart_port *port)
  178. {
  179. msm_write(port, 0x06, UART_MREG);
  180. msm_write(port, 0xF1, UART_NREG);
  181. msm_write(port, 0x0F, UART_DREG);
  182. msm_write(port, 0x1A, UART_MNDREG);
  183. port->uartclk = 1843200;
  184. }
  185. /*
  186. * Setup the MND registers to use the TCXO clock divided by 4.
  187. */
  188. static void msm_serial_set_mnd_regs_tcxoby4(struct uart_port *port)
  189. {
  190. msm_write(port, 0x18, UART_MREG);
  191. msm_write(port, 0xF6, UART_NREG);
  192. msm_write(port, 0x0F, UART_DREG);
  193. msm_write(port, 0x0A, UART_MNDREG);
  194. port->uartclk = 1843200;
  195. }
  196. static void msm_serial_set_mnd_regs(struct uart_port *port)
  197. {
  198. struct msm_port *msm_port = UART_TO_MSM(port);
  199. /*
  200. * These registers don't exist so we change the clk input rate
  201. * on uartdm hardware instead
  202. */
  203. if (msm_port->is_uartdm)
  204. return;
  205. if (port->uartclk == 19200000)
  206. msm_serial_set_mnd_regs_tcxo(port);
  207. else if (port->uartclk == 4800000)
  208. msm_serial_set_mnd_regs_tcxoby4(port);
  209. }
  210. static void msm_handle_tx(struct uart_port *port);
  211. static void msm_start_rx_dma(struct msm_port *msm_port);
  212. static void msm_stop_dma(struct uart_port *port, struct msm_dma *dma)
  213. {
  214. struct device *dev = port->dev;
  215. unsigned int mapped;
  216. u32 val;
  217. mapped = dma->count;
  218. dma->count = 0;
  219. dmaengine_terminate_all(dma->chan);
  220. /*
  221. * DMA Stall happens if enqueue and flush command happens concurrently.
  222. * For example before changing the baud rate/protocol configuration and
  223. * sending flush command to ADM, disable the channel of UARTDM.
  224. * Note: should not reset the receiver here immediately as it is not
  225. * suggested to do disable/reset or reset/disable at the same time.
  226. */
  227. val = msm_read(port, UARTDM_DMEN);
  228. val &= ~dma->enable_bit;
  229. msm_write(port, val, UARTDM_DMEN);
  230. if (mapped)
  231. dma_unmap_single(dev, dma->phys, mapped, dma->dir);
  232. }
  233. static void msm_release_dma(struct msm_port *msm_port)
  234. {
  235. struct msm_dma *dma;
  236. dma = &msm_port->tx_dma;
  237. if (dma->chan) {
  238. msm_stop_dma(&msm_port->uart, dma);
  239. dma_release_channel(dma->chan);
  240. }
  241. memset(dma, 0, sizeof(*dma));
  242. dma = &msm_port->rx_dma;
  243. if (dma->chan) {
  244. msm_stop_dma(&msm_port->uart, dma);
  245. dma_release_channel(dma->chan);
  246. kfree(dma->virt);
  247. }
  248. memset(dma, 0, sizeof(*dma));
  249. }
  250. static void msm_request_tx_dma(struct msm_port *msm_port, resource_size_t base)
  251. {
  252. struct device *dev = msm_port->uart.dev;
  253. struct dma_slave_config conf;
  254. struct msm_dma *dma;
  255. u32 crci = 0;
  256. int ret;
  257. dma = &msm_port->tx_dma;
  258. /* allocate DMA resources, if available */
  259. dma->chan = dma_request_slave_channel_reason(dev, "tx");
  260. if (IS_ERR(dma->chan))
  261. goto no_tx;
  262. of_property_read_u32(dev->of_node, "qcom,tx-crci", &crci);
  263. memset(&conf, 0, sizeof(conf));
  264. conf.direction = DMA_MEM_TO_DEV;
  265. conf.device_fc = true;
  266. conf.dst_addr = base + UARTDM_TF;
  267. conf.dst_maxburst = UARTDM_BURST_SIZE;
  268. conf.slave_id = crci;
  269. ret = dmaengine_slave_config(dma->chan, &conf);
  270. if (ret)
  271. goto rel_tx;
  272. dma->dir = DMA_TO_DEVICE;
  273. if (msm_port->is_uartdm < UARTDM_1P4)
  274. dma->enable_bit = UARTDM_DMEN_TX_DM_ENABLE;
  275. else
  276. dma->enable_bit = UARTDM_DMEN_TX_BAM_ENABLE;
  277. return;
  278. rel_tx:
  279. dma_release_channel(dma->chan);
  280. no_tx:
  281. memset(dma, 0, sizeof(*dma));
  282. }
  283. static void msm_request_rx_dma(struct msm_port *msm_port, resource_size_t base)
  284. {
  285. struct device *dev = msm_port->uart.dev;
  286. struct dma_slave_config conf;
  287. struct msm_dma *dma;
  288. u32 crci = 0;
  289. int ret;
  290. dma = &msm_port->rx_dma;
  291. /* allocate DMA resources, if available */
  292. dma->chan = dma_request_slave_channel_reason(dev, "rx");
  293. if (IS_ERR(dma->chan))
  294. goto no_rx;
  295. of_property_read_u32(dev->of_node, "qcom,rx-crci", &crci);
  296. dma->virt = kzalloc(UARTDM_RX_SIZE, GFP_KERNEL);
  297. if (!dma->virt)
  298. goto rel_rx;
  299. memset(&conf, 0, sizeof(conf));
  300. conf.direction = DMA_DEV_TO_MEM;
  301. conf.device_fc = true;
  302. conf.src_addr = base + UARTDM_RF;
  303. conf.src_maxburst = UARTDM_BURST_SIZE;
  304. conf.slave_id = crci;
  305. ret = dmaengine_slave_config(dma->chan, &conf);
  306. if (ret)
  307. goto err;
  308. dma->dir = DMA_FROM_DEVICE;
  309. if (msm_port->is_uartdm < UARTDM_1P4)
  310. dma->enable_bit = UARTDM_DMEN_RX_DM_ENABLE;
  311. else
  312. dma->enable_bit = UARTDM_DMEN_RX_BAM_ENABLE;
  313. return;
  314. err:
  315. kfree(dma->virt);
  316. rel_rx:
  317. dma_release_channel(dma->chan);
  318. no_rx:
  319. memset(dma, 0, sizeof(*dma));
  320. }
  321. static inline void msm_wait_for_xmitr(struct uart_port *port)
  322. {
  323. unsigned int timeout = 500000;
  324. while (!(msm_read(port, UART_SR) & UART_SR_TX_EMPTY)) {
  325. if (msm_read(port, UART_ISR) & UART_ISR_TX_READY)
  326. break;
  327. udelay(1);
  328. if (!timeout--)
  329. break;
  330. }
  331. msm_write(port, UART_CR_CMD_RESET_TX_READY, UART_CR);
  332. }
  333. static void msm_stop_tx(struct uart_port *port)
  334. {
  335. struct msm_port *msm_port = UART_TO_MSM(port);
  336. msm_port->imr &= ~UART_IMR_TXLEV;
  337. msm_write(port, msm_port->imr, UART_IMR);
  338. }
  339. static void msm_start_tx(struct uart_port *port)
  340. {
  341. struct msm_port *msm_port = UART_TO_MSM(port);
  342. struct msm_dma *dma = &msm_port->tx_dma;
  343. /* Already started in DMA mode */
  344. if (dma->count)
  345. return;
  346. msm_port->imr |= UART_IMR_TXLEV;
  347. msm_write(port, msm_port->imr, UART_IMR);
  348. }
  349. static void msm_reset_dm_count(struct uart_port *port, int count)
  350. {
  351. msm_wait_for_xmitr(port);
  352. msm_write(port, count, UARTDM_NCF_TX);
  353. msm_read(port, UARTDM_NCF_TX);
  354. }
  355. static void msm_complete_tx_dma(void *args)
  356. {
  357. struct msm_port *msm_port = args;
  358. struct uart_port *port = &msm_port->uart;
  359. struct circ_buf *xmit = &port->state->xmit;
  360. struct msm_dma *dma = &msm_port->tx_dma;
  361. struct dma_tx_state state;
  362. enum dma_status status;
  363. unsigned long flags;
  364. unsigned int count;
  365. u32 val;
  366. spin_lock_irqsave(&port->lock, flags);
  367. /* Already stopped */
  368. if (!dma->count)
  369. goto done;
  370. status = dmaengine_tx_status(dma->chan, dma->cookie, &state);
  371. dma_unmap_single(port->dev, dma->phys, dma->count, dma->dir);
  372. val = msm_read(port, UARTDM_DMEN);
  373. val &= ~dma->enable_bit;
  374. msm_write(port, val, UARTDM_DMEN);
  375. if (msm_port->is_uartdm > UARTDM_1P3) {
  376. msm_write(port, UART_CR_CMD_RESET_TX, UART_CR);
  377. msm_write(port, UART_CR_TX_ENABLE, UART_CR);
  378. }
  379. count = dma->count - state.residue;
  380. port->icount.tx += count;
  381. dma->count = 0;
  382. xmit->tail += count;
  383. xmit->tail &= UART_XMIT_SIZE - 1;
  384. /* Restore "Tx FIFO below watermark" interrupt */
  385. msm_port->imr |= UART_IMR_TXLEV;
  386. msm_write(port, msm_port->imr, UART_IMR);
  387. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  388. uart_write_wakeup(port);
  389. msm_handle_tx(port);
  390. done:
  391. spin_unlock_irqrestore(&port->lock, flags);
  392. }
  393. static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count)
  394. {
  395. struct circ_buf *xmit = &msm_port->uart.state->xmit;
  396. struct uart_port *port = &msm_port->uart;
  397. struct msm_dma *dma = &msm_port->tx_dma;
  398. void *cpu_addr;
  399. int ret;
  400. u32 val;
  401. cpu_addr = &xmit->buf[xmit->tail];
  402. dma->phys = dma_map_single(port->dev, cpu_addr, count, dma->dir);
  403. ret = dma_mapping_error(port->dev, dma->phys);
  404. if (ret)
  405. return ret;
  406. dma->desc = dmaengine_prep_slave_single(dma->chan, dma->phys,
  407. count, DMA_MEM_TO_DEV,
  408. DMA_PREP_INTERRUPT |
  409. DMA_PREP_FENCE);
  410. if (!dma->desc) {
  411. ret = -EIO;
  412. goto unmap;
  413. }
  414. dma->desc->callback = msm_complete_tx_dma;
  415. dma->desc->callback_param = msm_port;
  416. dma->cookie = dmaengine_submit(dma->desc);
  417. ret = dma_submit_error(dma->cookie);
  418. if (ret)
  419. goto unmap;
  420. /*
  421. * Using DMA complete for Tx FIFO reload, no need for
  422. * "Tx FIFO below watermark" one, disable it
  423. */
  424. msm_port->imr &= ~UART_IMR_TXLEV;
  425. msm_write(port, msm_port->imr, UART_IMR);
  426. dma->count = count;
  427. val = msm_read(port, UARTDM_DMEN);
  428. val |= dma->enable_bit;
  429. if (msm_port->is_uartdm < UARTDM_1P4)
  430. msm_write(port, val, UARTDM_DMEN);
  431. msm_reset_dm_count(port, count);
  432. if (msm_port->is_uartdm > UARTDM_1P3)
  433. msm_write(port, val, UARTDM_DMEN);
  434. dma_async_issue_pending(dma->chan);
  435. return 0;
  436. unmap:
  437. dma_unmap_single(port->dev, dma->phys, count, dma->dir);
  438. return ret;
  439. }
  440. static void msm_complete_rx_dma(void *args)
  441. {
  442. struct msm_port *msm_port = args;
  443. struct uart_port *port = &msm_port->uart;
  444. struct tty_port *tport = &port->state->port;
  445. struct msm_dma *dma = &msm_port->rx_dma;
  446. int count = 0, i, sysrq;
  447. unsigned long flags;
  448. u32 val;
  449. spin_lock_irqsave(&port->lock, flags);
  450. /* Already stopped */
  451. if (!dma->count)
  452. goto done;
  453. val = msm_read(port, UARTDM_DMEN);
  454. val &= ~dma->enable_bit;
  455. msm_write(port, val, UARTDM_DMEN);
  456. if (msm_read(port, UART_SR) & UART_SR_OVERRUN) {
  457. port->icount.overrun++;
  458. tty_insert_flip_char(tport, 0, TTY_OVERRUN);
  459. msm_write(port, UART_CR_CMD_RESET_ERR, UART_CR);
  460. }
  461. count = msm_read(port, UARTDM_RX_TOTAL_SNAP);
  462. port->icount.rx += count;
  463. dma->count = 0;
  464. dma_unmap_single(port->dev, dma->phys, UARTDM_RX_SIZE, dma->dir);
  465. for (i = 0; i < count; i++) {
  466. char flag = TTY_NORMAL;
  467. if (msm_port->break_detected && dma->virt[i] == 0) {
  468. port->icount.brk++;
  469. flag = TTY_BREAK;
  470. msm_port->break_detected = false;
  471. if (uart_handle_break(port))
  472. continue;
  473. }
  474. if (!(port->read_status_mask & UART_SR_RX_BREAK))
  475. flag = TTY_NORMAL;
  476. spin_unlock_irqrestore(&port->lock, flags);
  477. sysrq = uart_handle_sysrq_char(port, dma->virt[i]);
  478. spin_lock_irqsave(&port->lock, flags);
  479. if (!sysrq)
  480. tty_insert_flip_char(tport, dma->virt[i], flag);
  481. }
  482. msm_start_rx_dma(msm_port);
  483. done:
  484. spin_unlock_irqrestore(&port->lock, flags);
  485. if (count)
  486. tty_flip_buffer_push(tport);
  487. }
  488. static void msm_start_rx_dma(struct msm_port *msm_port)
  489. {
  490. struct msm_dma *dma = &msm_port->rx_dma;
  491. struct uart_port *uart = &msm_port->uart;
  492. u32 val;
  493. int ret;
  494. if (!dma->chan)
  495. return;
  496. dma->phys = dma_map_single(uart->dev, dma->virt,
  497. UARTDM_RX_SIZE, dma->dir);
  498. ret = dma_mapping_error(uart->dev, dma->phys);
  499. if (ret)
  500. return;
  501. dma->desc = dmaengine_prep_slave_single(dma->chan, dma->phys,
  502. UARTDM_RX_SIZE, DMA_DEV_TO_MEM,
  503. DMA_PREP_INTERRUPT);
  504. if (!dma->desc)
  505. goto unmap;
  506. dma->desc->callback = msm_complete_rx_dma;
  507. dma->desc->callback_param = msm_port;
  508. dma->cookie = dmaengine_submit(dma->desc);
  509. ret = dma_submit_error(dma->cookie);
  510. if (ret)
  511. goto unmap;
  512. /*
  513. * Using DMA for FIFO off-load, no need for "Rx FIFO over
  514. * watermark" or "stale" interrupts, disable them
  515. */
  516. msm_port->imr &= ~(UART_IMR_RXLEV | UART_IMR_RXSTALE);
  517. /*
  518. * Well, when DMA is ADM3 engine(implied by <= UARTDM v1.3),
  519. * we need RXSTALE to flush input DMA fifo to memory
  520. */
  521. if (msm_port->is_uartdm < UARTDM_1P4)
  522. msm_port->imr |= UART_IMR_RXSTALE;
  523. msm_write(uart, msm_port->imr, UART_IMR);
  524. dma->count = UARTDM_RX_SIZE;
  525. dma_async_issue_pending(dma->chan);
  526. msm_write(uart, UART_CR_CMD_RESET_STALE_INT, UART_CR);
  527. msm_write(uart, UART_CR_CMD_STALE_EVENT_ENABLE, UART_CR);
  528. val = msm_read(uart, UARTDM_DMEN);
  529. val |= dma->enable_bit;
  530. if (msm_port->is_uartdm < UARTDM_1P4)
  531. msm_write(uart, val, UARTDM_DMEN);
  532. msm_write(uart, UARTDM_RX_SIZE, UARTDM_DMRX);
  533. if (msm_port->is_uartdm > UARTDM_1P3)
  534. msm_write(uart, val, UARTDM_DMEN);
  535. return;
  536. unmap:
  537. dma_unmap_single(uart->dev, dma->phys, UARTDM_RX_SIZE, dma->dir);
  538. }
  539. static void msm_stop_rx(struct uart_port *port)
  540. {
  541. struct msm_port *msm_port = UART_TO_MSM(port);
  542. struct msm_dma *dma = &msm_port->rx_dma;
  543. msm_port->imr &= ~(UART_IMR_RXLEV | UART_IMR_RXSTALE);
  544. msm_write(port, msm_port->imr, UART_IMR);
  545. if (dma->chan)
  546. msm_stop_dma(port, dma);
  547. }
  548. static void msm_enable_ms(struct uart_port *port)
  549. {
  550. struct msm_port *msm_port = UART_TO_MSM(port);
  551. msm_port->imr |= UART_IMR_DELTA_CTS;
  552. msm_write(port, msm_port->imr, UART_IMR);
  553. }
  554. static void msm_handle_rx_dm(struct uart_port *port, unsigned int misr)
  555. {
  556. struct tty_port *tport = &port->state->port;
  557. unsigned int sr;
  558. int count = 0;
  559. struct msm_port *msm_port = UART_TO_MSM(port);
  560. if ((msm_read(port, UART_SR) & UART_SR_OVERRUN)) {
  561. port->icount.overrun++;
  562. tty_insert_flip_char(tport, 0, TTY_OVERRUN);
  563. msm_write(port, UART_CR_CMD_RESET_ERR, UART_CR);
  564. }
  565. if (misr & UART_IMR_RXSTALE) {
  566. count = msm_read(port, UARTDM_RX_TOTAL_SNAP) -
  567. msm_port->old_snap_state;
  568. msm_port->old_snap_state = 0;
  569. } else {
  570. count = 4 * (msm_read(port, UART_RFWR));
  571. msm_port->old_snap_state += count;
  572. }
  573. /* TODO: Precise error reporting */
  574. port->icount.rx += count;
  575. while (count > 0) {
  576. unsigned char buf[4];
  577. int sysrq, r_count, i;
  578. sr = msm_read(port, UART_SR);
  579. if ((sr & UART_SR_RX_READY) == 0) {
  580. msm_port->old_snap_state -= count;
  581. break;
  582. }
  583. ioread32_rep(port->membase + UARTDM_RF, buf, 1);
  584. r_count = min_t(int, count, sizeof(buf));
  585. for (i = 0; i < r_count; i++) {
  586. char flag = TTY_NORMAL;
  587. if (msm_port->break_detected && buf[i] == 0) {
  588. port->icount.brk++;
  589. flag = TTY_BREAK;
  590. msm_port->break_detected = false;
  591. if (uart_handle_break(port))
  592. continue;
  593. }
  594. if (!(port->read_status_mask & UART_SR_RX_BREAK))
  595. flag = TTY_NORMAL;
  596. spin_unlock(&port->lock);
  597. sysrq = uart_handle_sysrq_char(port, buf[i]);
  598. spin_lock(&port->lock);
  599. if (!sysrq)
  600. tty_insert_flip_char(tport, buf[i], flag);
  601. }
  602. count -= r_count;
  603. }
  604. spin_unlock(&port->lock);
  605. tty_flip_buffer_push(tport);
  606. spin_lock(&port->lock);
  607. if (misr & (UART_IMR_RXSTALE))
  608. msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR);
  609. msm_write(port, 0xFFFFFF, UARTDM_DMRX);
  610. msm_write(port, UART_CR_CMD_STALE_EVENT_ENABLE, UART_CR);
  611. /* Try to use DMA */
  612. msm_start_rx_dma(msm_port);
  613. }
  614. static void msm_handle_rx(struct uart_port *port)
  615. {
  616. struct tty_port *tport = &port->state->port;
  617. unsigned int sr;
  618. /*
  619. * Handle overrun. My understanding of the hardware is that overrun
  620. * is not tied to the RX buffer, so we handle the case out of band.
  621. */
  622. if ((msm_read(port, UART_SR) & UART_SR_OVERRUN)) {
  623. port->icount.overrun++;
  624. tty_insert_flip_char(tport, 0, TTY_OVERRUN);
  625. msm_write(port, UART_CR_CMD_RESET_ERR, UART_CR);
  626. }
  627. /* and now the main RX loop */
  628. while ((sr = msm_read(port, UART_SR)) & UART_SR_RX_READY) {
  629. unsigned int c;
  630. char flag = TTY_NORMAL;
  631. int sysrq;
  632. c = msm_read(port, UART_RF);
  633. if (sr & UART_SR_RX_BREAK) {
  634. port->icount.brk++;
  635. if (uart_handle_break(port))
  636. continue;
  637. } else if (sr & UART_SR_PAR_FRAME_ERR) {
  638. port->icount.frame++;
  639. } else {
  640. port->icount.rx++;
  641. }
  642. /* Mask conditions we're ignorning. */
  643. sr &= port->read_status_mask;
  644. if (sr & UART_SR_RX_BREAK)
  645. flag = TTY_BREAK;
  646. else if (sr & UART_SR_PAR_FRAME_ERR)
  647. flag = TTY_FRAME;
  648. spin_unlock(&port->lock);
  649. sysrq = uart_handle_sysrq_char(port, c);
  650. spin_lock(&port->lock);
  651. if (!sysrq)
  652. tty_insert_flip_char(tport, c, flag);
  653. }
  654. spin_unlock(&port->lock);
  655. tty_flip_buffer_push(tport);
  656. spin_lock(&port->lock);
  657. }
  658. static void msm_handle_tx_pio(struct uart_port *port, unsigned int tx_count)
  659. {
  660. struct circ_buf *xmit = &port->state->xmit;
  661. struct msm_port *msm_port = UART_TO_MSM(port);
  662. unsigned int num_chars;
  663. unsigned int tf_pointer = 0;
  664. void __iomem *tf;
  665. if (msm_port->is_uartdm)
  666. tf = port->membase + UARTDM_TF;
  667. else
  668. tf = port->membase + UART_TF;
  669. if (tx_count && msm_port->is_uartdm)
  670. msm_reset_dm_count(port, tx_count);
  671. while (tf_pointer < tx_count) {
  672. int i;
  673. char buf[4] = { 0 };
  674. if (!(msm_read(port, UART_SR) & UART_SR_TX_READY))
  675. break;
  676. if (msm_port->is_uartdm)
  677. num_chars = min(tx_count - tf_pointer,
  678. (unsigned int)sizeof(buf));
  679. else
  680. num_chars = 1;
  681. for (i = 0; i < num_chars; i++) {
  682. buf[i] = xmit->buf[xmit->tail + i];
  683. port->icount.tx++;
  684. }
  685. iowrite32_rep(tf, buf, 1);
  686. xmit->tail = (xmit->tail + num_chars) & (UART_XMIT_SIZE - 1);
  687. tf_pointer += num_chars;
  688. }
  689. /* disable tx interrupts if nothing more to send */
  690. if (uart_circ_empty(xmit))
  691. msm_stop_tx(port);
  692. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  693. uart_write_wakeup(port);
  694. }
  695. static void msm_handle_tx(struct uart_port *port)
  696. {
  697. struct msm_port *msm_port = UART_TO_MSM(port);
  698. struct circ_buf *xmit = &msm_port->uart.state->xmit;
  699. struct msm_dma *dma = &msm_port->tx_dma;
  700. unsigned int pio_count, dma_count, dma_min;
  701. char buf[4] = { 0 };
  702. void __iomem *tf;
  703. int err = 0;
  704. if (port->x_char) {
  705. if (msm_port->is_uartdm)
  706. tf = port->membase + UARTDM_TF;
  707. else
  708. tf = port->membase + UART_TF;
  709. buf[0] = port->x_char;
  710. if (msm_port->is_uartdm)
  711. msm_reset_dm_count(port, 1);
  712. iowrite32_rep(tf, buf, 1);
  713. port->icount.tx++;
  714. port->x_char = 0;
  715. return;
  716. }
  717. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  718. msm_stop_tx(port);
  719. return;
  720. }
  721. pio_count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
  722. dma_count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
  723. dma_min = 1; /* Always DMA */
  724. if (msm_port->is_uartdm > UARTDM_1P3) {
  725. dma_count = UARTDM_TX_AIGN(dma_count);
  726. dma_min = UARTDM_BURST_SIZE;
  727. } else {
  728. if (dma_count > UARTDM_TX_MAX)
  729. dma_count = UARTDM_TX_MAX;
  730. }
  731. if (pio_count > port->fifosize)
  732. pio_count = port->fifosize;
  733. if (!dma->chan || dma_count < dma_min)
  734. msm_handle_tx_pio(port, pio_count);
  735. else
  736. err = msm_handle_tx_dma(msm_port, dma_count);
  737. if (err) /* fall back to PIO mode */
  738. msm_handle_tx_pio(port, pio_count);
  739. }
  740. static void msm_handle_delta_cts(struct uart_port *port)
  741. {
  742. msm_write(port, UART_CR_CMD_RESET_CTS, UART_CR);
  743. port->icount.cts++;
  744. wake_up_interruptible(&port->state->port.delta_msr_wait);
  745. }
  746. static irqreturn_t msm_uart_irq(int irq, void *dev_id)
  747. {
  748. struct uart_port *port = dev_id;
  749. struct msm_port *msm_port = UART_TO_MSM(port);
  750. struct msm_dma *dma = &msm_port->rx_dma;
  751. unsigned long flags;
  752. unsigned int misr;
  753. u32 val;
  754. spin_lock_irqsave(&port->lock, flags);
  755. misr = msm_read(port, UART_MISR);
  756. msm_write(port, 0, UART_IMR); /* disable interrupt */
  757. if (misr & UART_IMR_RXBREAK_START) {
  758. msm_port->break_detected = true;
  759. msm_write(port, UART_CR_CMD_RESET_RXBREAK_START, UART_CR);
  760. }
  761. if (misr & (UART_IMR_RXLEV | UART_IMR_RXSTALE)) {
  762. if (dma->count) {
  763. val = UART_CR_CMD_STALE_EVENT_DISABLE;
  764. msm_write(port, val, UART_CR);
  765. val = UART_CR_CMD_RESET_STALE_INT;
  766. msm_write(port, val, UART_CR);
  767. /*
  768. * Flush DMA input fifo to memory, this will also
  769. * trigger DMA RX completion
  770. */
  771. dmaengine_terminate_all(dma->chan);
  772. } else if (msm_port->is_uartdm) {
  773. msm_handle_rx_dm(port, misr);
  774. } else {
  775. msm_handle_rx(port);
  776. }
  777. }
  778. if (misr & UART_IMR_TXLEV)
  779. msm_handle_tx(port);
  780. if (misr & UART_IMR_DELTA_CTS)
  781. msm_handle_delta_cts(port);
  782. msm_write(port, msm_port->imr, UART_IMR); /* restore interrupt */
  783. spin_unlock_irqrestore(&port->lock, flags);
  784. return IRQ_HANDLED;
  785. }
  786. static unsigned int msm_tx_empty(struct uart_port *port)
  787. {
  788. return (msm_read(port, UART_SR) & UART_SR_TX_EMPTY) ? TIOCSER_TEMT : 0;
  789. }
  790. static unsigned int msm_get_mctrl(struct uart_port *port)
  791. {
  792. return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR | TIOCM_RTS;
  793. }
  794. static void msm_reset(struct uart_port *port)
  795. {
  796. struct msm_port *msm_port = UART_TO_MSM(port);
  797. unsigned int mr;
  798. /* reset everything */
  799. msm_write(port, UART_CR_CMD_RESET_RX, UART_CR);
  800. msm_write(port, UART_CR_CMD_RESET_TX, UART_CR);
  801. msm_write(port, UART_CR_CMD_RESET_ERR, UART_CR);
  802. msm_write(port, UART_CR_CMD_RESET_BREAK_INT, UART_CR);
  803. msm_write(port, UART_CR_CMD_RESET_CTS, UART_CR);
  804. msm_write(port, UART_CR_CMD_RESET_RFR, UART_CR);
  805. mr = msm_read(port, UART_MR1);
  806. mr &= ~UART_MR1_RX_RDY_CTL;
  807. msm_write(port, mr, UART_MR1);
  808. /* Disable DM modes */
  809. if (msm_port->is_uartdm)
  810. msm_write(port, 0, UARTDM_DMEN);
  811. }
  812. static void msm_set_mctrl(struct uart_port *port, unsigned int mctrl)
  813. {
  814. unsigned int mr;
  815. mr = msm_read(port, UART_MR1);
  816. if (!(mctrl & TIOCM_RTS)) {
  817. mr &= ~UART_MR1_RX_RDY_CTL;
  818. msm_write(port, mr, UART_MR1);
  819. msm_write(port, UART_CR_CMD_RESET_RFR, UART_CR);
  820. } else {
  821. mr |= UART_MR1_RX_RDY_CTL;
  822. msm_write(port, mr, UART_MR1);
  823. }
  824. }
  825. static void msm_break_ctl(struct uart_port *port, int break_ctl)
  826. {
  827. if (break_ctl)
  828. msm_write(port, UART_CR_CMD_START_BREAK, UART_CR);
  829. else
  830. msm_write(port, UART_CR_CMD_STOP_BREAK, UART_CR);
  831. }
  832. struct msm_baud_map {
  833. u16 divisor;
  834. u8 code;
  835. u8 rxstale;
  836. };
  837. static const struct msm_baud_map *
  838. msm_find_best_baud(struct uart_port *port, unsigned int baud,
  839. unsigned long *rate)
  840. {
  841. struct msm_port *msm_port = UART_TO_MSM(port);
  842. unsigned int divisor, result;
  843. unsigned long target, old, best_rate = 0, diff, best_diff = ULONG_MAX;
  844. const struct msm_baud_map *entry, *end, *best;
  845. static const struct msm_baud_map table[] = {
  846. { 1, 0xff, 31 },
  847. { 2, 0xee, 16 },
  848. { 3, 0xdd, 8 },
  849. { 4, 0xcc, 6 },
  850. { 6, 0xbb, 6 },
  851. { 8, 0xaa, 6 },
  852. { 12, 0x99, 6 },
  853. { 16, 0x88, 1 },
  854. { 24, 0x77, 1 },
  855. { 32, 0x66, 1 },
  856. { 48, 0x55, 1 },
  857. { 96, 0x44, 1 },
  858. { 192, 0x33, 1 },
  859. { 384, 0x22, 1 },
  860. { 768, 0x11, 1 },
  861. { 1536, 0x00, 1 },
  862. };
  863. best = table; /* Default to smallest divider */
  864. target = clk_round_rate(msm_port->clk, 16 * baud);
  865. divisor = DIV_ROUND_CLOSEST(target, 16 * baud);
  866. end = table + ARRAY_SIZE(table);
  867. entry = table;
  868. while (entry < end) {
  869. if (entry->divisor <= divisor) {
  870. result = target / entry->divisor / 16;
  871. diff = abs(result - baud);
  872. /* Keep track of best entry */
  873. if (diff < best_diff) {
  874. best_diff = diff;
  875. best = entry;
  876. best_rate = target;
  877. }
  878. if (result == baud)
  879. break;
  880. } else if (entry->divisor > divisor) {
  881. old = target;
  882. target = clk_round_rate(msm_port->clk, old + 1);
  883. /*
  884. * The rate didn't get any faster so we can't do
  885. * better at dividing it down
  886. */
  887. if (target == old)
  888. break;
  889. /* Start the divisor search over at this new rate */
  890. entry = table;
  891. divisor = DIV_ROUND_CLOSEST(target, 16 * baud);
  892. continue;
  893. }
  894. entry++;
  895. }
  896. *rate = best_rate;
  897. return best;
  898. }
  899. static int msm_set_baud_rate(struct uart_port *port, unsigned int baud,
  900. unsigned long *saved_flags)
  901. {
  902. unsigned int rxstale, watermark, mask;
  903. struct msm_port *msm_port = UART_TO_MSM(port);
  904. const struct msm_baud_map *entry;
  905. unsigned long flags, rate;
  906. flags = *saved_flags;
  907. spin_unlock_irqrestore(&port->lock, flags);
  908. entry = msm_find_best_baud(port, baud, &rate);
  909. clk_set_rate(msm_port->clk, rate);
  910. baud = rate / 16 / entry->divisor;
  911. spin_lock_irqsave(&port->lock, flags);
  912. *saved_flags = flags;
  913. port->uartclk = rate;
  914. msm_write(port, entry->code, UART_CSR);
  915. /* RX stale watermark */
  916. rxstale = entry->rxstale;
  917. watermark = UART_IPR_STALE_LSB & rxstale;
  918. if (msm_port->is_uartdm) {
  919. mask = UART_DM_IPR_STALE_TIMEOUT_MSB;
  920. } else {
  921. watermark |= UART_IPR_RXSTALE_LAST;
  922. mask = UART_IPR_STALE_TIMEOUT_MSB;
  923. }
  924. watermark |= mask & (rxstale << 2);
  925. msm_write(port, watermark, UART_IPR);
  926. /* set RX watermark */
  927. watermark = (port->fifosize * 3) / 4;
  928. msm_write(port, watermark, UART_RFWR);
  929. /* set TX watermark */
  930. msm_write(port, 10, UART_TFWR);
  931. msm_write(port, UART_CR_CMD_PROTECTION_EN, UART_CR);
  932. msm_reset(port);
  933. /* Enable RX and TX */
  934. msm_write(port, UART_CR_TX_ENABLE | UART_CR_RX_ENABLE, UART_CR);
  935. /* turn on RX and CTS interrupts */
  936. msm_port->imr = UART_IMR_RXLEV | UART_IMR_RXSTALE |
  937. UART_IMR_CURRENT_CTS | UART_IMR_RXBREAK_START;
  938. msm_write(port, msm_port->imr, UART_IMR);
  939. if (msm_port->is_uartdm) {
  940. msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR);
  941. msm_write(port, 0xFFFFFF, UARTDM_DMRX);
  942. msm_write(port, UART_CR_CMD_STALE_EVENT_ENABLE, UART_CR);
  943. }
  944. return baud;
  945. }
  946. static void msm_init_clock(struct uart_port *port)
  947. {
  948. struct msm_port *msm_port = UART_TO_MSM(port);
  949. clk_prepare_enable(msm_port->clk);
  950. clk_prepare_enable(msm_port->pclk);
  951. msm_serial_set_mnd_regs(port);
  952. }
  953. static int msm_startup(struct uart_port *port)
  954. {
  955. struct msm_port *msm_port = UART_TO_MSM(port);
  956. unsigned int data, rfr_level, mask;
  957. int ret;
  958. snprintf(msm_port->name, sizeof(msm_port->name),
  959. "msm_serial%d", port->line);
  960. msm_init_clock(port);
  961. if (likely(port->fifosize > 12))
  962. rfr_level = port->fifosize - 12;
  963. else
  964. rfr_level = port->fifosize;
  965. /* set automatic RFR level */
  966. data = msm_read(port, UART_MR1);
  967. if (msm_port->is_uartdm)
  968. mask = UART_DM_MR1_AUTO_RFR_LEVEL1;
  969. else
  970. mask = UART_MR1_AUTO_RFR_LEVEL1;
  971. data &= ~mask;
  972. data &= ~UART_MR1_AUTO_RFR_LEVEL0;
  973. data |= mask & (rfr_level << 2);
  974. data |= UART_MR1_AUTO_RFR_LEVEL0 & rfr_level;
  975. msm_write(port, data, UART_MR1);
  976. if (msm_port->is_uartdm) {
  977. msm_request_tx_dma(msm_port, msm_port->uart.mapbase);
  978. msm_request_rx_dma(msm_port, msm_port->uart.mapbase);
  979. }
  980. ret = request_irq(port->irq, msm_uart_irq, IRQF_TRIGGER_HIGH,
  981. msm_port->name, port);
  982. if (unlikely(ret))
  983. goto err_irq;
  984. return 0;
  985. err_irq:
  986. if (msm_port->is_uartdm)
  987. msm_release_dma(msm_port);
  988. clk_disable_unprepare(msm_port->pclk);
  989. clk_disable_unprepare(msm_port->clk);
  990. return ret;
  991. }
  992. static void msm_shutdown(struct uart_port *port)
  993. {
  994. struct msm_port *msm_port = UART_TO_MSM(port);
  995. msm_port->imr = 0;
  996. msm_write(port, 0, UART_IMR); /* disable interrupts */
  997. if (msm_port->is_uartdm)
  998. msm_release_dma(msm_port);
  999. clk_disable_unprepare(msm_port->clk);
  1000. free_irq(port->irq, port);
  1001. }
  1002. static void msm_set_termios(struct uart_port *port, struct ktermios *termios,
  1003. struct ktermios *old)
  1004. {
  1005. struct msm_port *msm_port = UART_TO_MSM(port);
  1006. struct msm_dma *dma = &msm_port->rx_dma;
  1007. unsigned long flags;
  1008. unsigned int baud, mr;
  1009. spin_lock_irqsave(&port->lock, flags);
  1010. if (dma->chan) /* Terminate if any */
  1011. msm_stop_dma(port, dma);
  1012. /* calculate and set baud rate */
  1013. baud = uart_get_baud_rate(port, termios, old, 300, 4000000);
  1014. baud = msm_set_baud_rate(port, baud, &flags);
  1015. if (tty_termios_baud_rate(termios))
  1016. tty_termios_encode_baud_rate(termios, baud, baud);
  1017. /* calculate parity */
  1018. mr = msm_read(port, UART_MR2);
  1019. mr &= ~UART_MR2_PARITY_MODE;
  1020. if (termios->c_cflag & PARENB) {
  1021. if (termios->c_cflag & PARODD)
  1022. mr |= UART_MR2_PARITY_MODE_ODD;
  1023. else if (termios->c_cflag & CMSPAR)
  1024. mr |= UART_MR2_PARITY_MODE_SPACE;
  1025. else
  1026. mr |= UART_MR2_PARITY_MODE_EVEN;
  1027. }
  1028. /* calculate bits per char */
  1029. mr &= ~UART_MR2_BITS_PER_CHAR;
  1030. switch (termios->c_cflag & CSIZE) {
  1031. case CS5:
  1032. mr |= UART_MR2_BITS_PER_CHAR_5;
  1033. break;
  1034. case CS6:
  1035. mr |= UART_MR2_BITS_PER_CHAR_6;
  1036. break;
  1037. case CS7:
  1038. mr |= UART_MR2_BITS_PER_CHAR_7;
  1039. break;
  1040. case CS8:
  1041. default:
  1042. mr |= UART_MR2_BITS_PER_CHAR_8;
  1043. break;
  1044. }
  1045. /* calculate stop bits */
  1046. mr &= ~(UART_MR2_STOP_BIT_LEN_ONE | UART_MR2_STOP_BIT_LEN_TWO);
  1047. if (termios->c_cflag & CSTOPB)
  1048. mr |= UART_MR2_STOP_BIT_LEN_TWO;
  1049. else
  1050. mr |= UART_MR2_STOP_BIT_LEN_ONE;
  1051. /* set parity, bits per char, and stop bit */
  1052. msm_write(port, mr, UART_MR2);
  1053. /* calculate and set hardware flow control */
  1054. mr = msm_read(port, UART_MR1);
  1055. mr &= ~(UART_MR1_CTS_CTL | UART_MR1_RX_RDY_CTL);
  1056. if (termios->c_cflag & CRTSCTS) {
  1057. mr |= UART_MR1_CTS_CTL;
  1058. mr |= UART_MR1_RX_RDY_CTL;
  1059. }
  1060. msm_write(port, mr, UART_MR1);
  1061. /* Configure status bits to ignore based on termio flags. */
  1062. port->read_status_mask = 0;
  1063. if (termios->c_iflag & INPCK)
  1064. port->read_status_mask |= UART_SR_PAR_FRAME_ERR;
  1065. if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
  1066. port->read_status_mask |= UART_SR_RX_BREAK;
  1067. uart_update_timeout(port, termios->c_cflag, baud);
  1068. /* Try to use DMA */
  1069. msm_start_rx_dma(msm_port);
  1070. spin_unlock_irqrestore(&port->lock, flags);
  1071. }
  1072. static const char *msm_type(struct uart_port *port)
  1073. {
  1074. return "MSM";
  1075. }
  1076. static void msm_release_port(struct uart_port *port)
  1077. {
  1078. struct platform_device *pdev = to_platform_device(port->dev);
  1079. struct resource *uart_resource;
  1080. resource_size_t size;
  1081. uart_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1082. if (unlikely(!uart_resource))
  1083. return;
  1084. size = resource_size(uart_resource);
  1085. release_mem_region(port->mapbase, size);
  1086. iounmap(port->membase);
  1087. port->membase = NULL;
  1088. }
  1089. static int msm_request_port(struct uart_port *port)
  1090. {
  1091. struct platform_device *pdev = to_platform_device(port->dev);
  1092. struct resource *uart_resource;
  1093. resource_size_t size;
  1094. int ret;
  1095. uart_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1096. if (unlikely(!uart_resource))
  1097. return -ENXIO;
  1098. size = resource_size(uart_resource);
  1099. if (!request_mem_region(port->mapbase, size, "msm_serial"))
  1100. return -EBUSY;
  1101. port->membase = ioremap(port->mapbase, size);
  1102. if (!port->membase) {
  1103. ret = -EBUSY;
  1104. goto fail_release_port;
  1105. }
  1106. return 0;
  1107. fail_release_port:
  1108. release_mem_region(port->mapbase, size);
  1109. return ret;
  1110. }
  1111. static void msm_config_port(struct uart_port *port, int flags)
  1112. {
  1113. int ret;
  1114. if (flags & UART_CONFIG_TYPE) {
  1115. port->type = PORT_MSM;
  1116. ret = msm_request_port(port);
  1117. if (ret)
  1118. return;
  1119. }
  1120. }
  1121. static int msm_verify_port(struct uart_port *port, struct serial_struct *ser)
  1122. {
  1123. if (unlikely(ser->type != PORT_UNKNOWN && ser->type != PORT_MSM))
  1124. return -EINVAL;
  1125. if (unlikely(port->irq != ser->irq))
  1126. return -EINVAL;
  1127. return 0;
  1128. }
  1129. static void msm_power(struct uart_port *port, unsigned int state,
  1130. unsigned int oldstate)
  1131. {
  1132. struct msm_port *msm_port = UART_TO_MSM(port);
  1133. switch (state) {
  1134. case 0:
  1135. clk_prepare_enable(msm_port->clk);
  1136. clk_prepare_enable(msm_port->pclk);
  1137. break;
  1138. case 3:
  1139. clk_disable_unprepare(msm_port->clk);
  1140. clk_disable_unprepare(msm_port->pclk);
  1141. break;
  1142. default:
  1143. pr_err("msm_serial: Unknown PM state %d\n", state);
  1144. }
  1145. }
  1146. #ifdef CONFIG_CONSOLE_POLL
  1147. static int msm_poll_get_char_single(struct uart_port *port)
  1148. {
  1149. struct msm_port *msm_port = UART_TO_MSM(port);
  1150. unsigned int rf_reg = msm_port->is_uartdm ? UARTDM_RF : UART_RF;
  1151. if (!(msm_read(port, UART_SR) & UART_SR_RX_READY))
  1152. return NO_POLL_CHAR;
  1153. return msm_read(port, rf_reg) & 0xff;
  1154. }
  1155. static int msm_poll_get_char_dm(struct uart_port *port)
  1156. {
  1157. int c;
  1158. static u32 slop;
  1159. static int count;
  1160. unsigned char *sp = (unsigned char *)&slop;
  1161. /* Check if a previous read had more than one char */
  1162. if (count) {
  1163. c = sp[sizeof(slop) - count];
  1164. count--;
  1165. /* Or if FIFO is empty */
  1166. } else if (!(msm_read(port, UART_SR) & UART_SR_RX_READY)) {
  1167. /*
  1168. * If RX packing buffer has less than a word, force stale to
  1169. * push contents into RX FIFO
  1170. */
  1171. count = msm_read(port, UARTDM_RXFS);
  1172. count = (count >> UARTDM_RXFS_BUF_SHIFT) & UARTDM_RXFS_BUF_MASK;
  1173. if (count) {
  1174. msm_write(port, UART_CR_CMD_FORCE_STALE, UART_CR);
  1175. slop = msm_read(port, UARTDM_RF);
  1176. c = sp[0];
  1177. count--;
  1178. msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR);
  1179. msm_write(port, 0xFFFFFF, UARTDM_DMRX);
  1180. msm_write(port, UART_CR_CMD_STALE_EVENT_ENABLE,
  1181. UART_CR);
  1182. } else {
  1183. c = NO_POLL_CHAR;
  1184. }
  1185. /* FIFO has a word */
  1186. } else {
  1187. slop = msm_read(port, UARTDM_RF);
  1188. c = sp[0];
  1189. count = sizeof(slop) - 1;
  1190. }
  1191. return c;
  1192. }
  1193. static int msm_poll_get_char(struct uart_port *port)
  1194. {
  1195. u32 imr;
  1196. int c;
  1197. struct msm_port *msm_port = UART_TO_MSM(port);
  1198. /* Disable all interrupts */
  1199. imr = msm_read(port, UART_IMR);
  1200. msm_write(port, 0, UART_IMR);
  1201. if (msm_port->is_uartdm)
  1202. c = msm_poll_get_char_dm(port);
  1203. else
  1204. c = msm_poll_get_char_single(port);
  1205. /* Enable interrupts */
  1206. msm_write(port, imr, UART_IMR);
  1207. return c;
  1208. }
  1209. static void msm_poll_put_char(struct uart_port *port, unsigned char c)
  1210. {
  1211. u32 imr;
  1212. struct msm_port *msm_port = UART_TO_MSM(port);
  1213. /* Disable all interrupts */
  1214. imr = msm_read(port, UART_IMR);
  1215. msm_write(port, 0, UART_IMR);
  1216. if (msm_port->is_uartdm)
  1217. msm_reset_dm_count(port, 1);
  1218. /* Wait until FIFO is empty */
  1219. while (!(msm_read(port, UART_SR) & UART_SR_TX_READY))
  1220. cpu_relax();
  1221. /* Write a character */
  1222. msm_write(port, c, msm_port->is_uartdm ? UARTDM_TF : UART_TF);
  1223. /* Wait until FIFO is empty */
  1224. while (!(msm_read(port, UART_SR) & UART_SR_TX_READY))
  1225. cpu_relax();
  1226. /* Enable interrupts */
  1227. msm_write(port, imr, UART_IMR);
  1228. }
  1229. #endif
  1230. static struct uart_ops msm_uart_pops = {
  1231. .tx_empty = msm_tx_empty,
  1232. .set_mctrl = msm_set_mctrl,
  1233. .get_mctrl = msm_get_mctrl,
  1234. .stop_tx = msm_stop_tx,
  1235. .start_tx = msm_start_tx,
  1236. .stop_rx = msm_stop_rx,
  1237. .enable_ms = msm_enable_ms,
  1238. .break_ctl = msm_break_ctl,
  1239. .startup = msm_startup,
  1240. .shutdown = msm_shutdown,
  1241. .set_termios = msm_set_termios,
  1242. .type = msm_type,
  1243. .release_port = msm_release_port,
  1244. .request_port = msm_request_port,
  1245. .config_port = msm_config_port,
  1246. .verify_port = msm_verify_port,
  1247. .pm = msm_power,
  1248. #ifdef CONFIG_CONSOLE_POLL
  1249. .poll_get_char = msm_poll_get_char,
  1250. .poll_put_char = msm_poll_put_char,
  1251. #endif
  1252. };
  1253. static struct msm_port msm_uart_ports[] = {
  1254. {
  1255. .uart = {
  1256. .iotype = UPIO_MEM,
  1257. .ops = &msm_uart_pops,
  1258. .flags = UPF_BOOT_AUTOCONF,
  1259. .fifosize = 64,
  1260. .line = 0,
  1261. },
  1262. },
  1263. {
  1264. .uart = {
  1265. .iotype = UPIO_MEM,
  1266. .ops = &msm_uart_pops,
  1267. .flags = UPF_BOOT_AUTOCONF,
  1268. .fifosize = 64,
  1269. .line = 1,
  1270. },
  1271. },
  1272. {
  1273. .uart = {
  1274. .iotype = UPIO_MEM,
  1275. .ops = &msm_uart_pops,
  1276. .flags = UPF_BOOT_AUTOCONF,
  1277. .fifosize = 64,
  1278. .line = 2,
  1279. },
  1280. },
  1281. };
  1282. #define UART_NR ARRAY_SIZE(msm_uart_ports)
  1283. static inline struct uart_port *msm_get_port_from_line(unsigned int line)
  1284. {
  1285. return &msm_uart_ports[line].uart;
  1286. }
  1287. #ifdef CONFIG_SERIAL_MSM_CONSOLE
  1288. static void __msm_console_write(struct uart_port *port, const char *s,
  1289. unsigned int count, bool is_uartdm)
  1290. {
  1291. int i;
  1292. int num_newlines = 0;
  1293. bool replaced = false;
  1294. void __iomem *tf;
  1295. int locked = 1;
  1296. if (is_uartdm)
  1297. tf = port->membase + UARTDM_TF;
  1298. else
  1299. tf = port->membase + UART_TF;
  1300. /* Account for newlines that will get a carriage return added */
  1301. for (i = 0; i < count; i++)
  1302. if (s[i] == '\n')
  1303. num_newlines++;
  1304. count += num_newlines;
  1305. if (port->sysrq)
  1306. locked = 0;
  1307. else if (oops_in_progress)
  1308. locked = spin_trylock(&port->lock);
  1309. else
  1310. spin_lock(&port->lock);
  1311. if (is_uartdm)
  1312. msm_reset_dm_count(port, count);
  1313. i = 0;
  1314. while (i < count) {
  1315. int j;
  1316. unsigned int num_chars;
  1317. char buf[4] = { 0 };
  1318. if (is_uartdm)
  1319. num_chars = min(count - i, (unsigned int)sizeof(buf));
  1320. else
  1321. num_chars = 1;
  1322. for (j = 0; j < num_chars; j++) {
  1323. char c = *s;
  1324. if (c == '\n' && !replaced) {
  1325. buf[j] = '\r';
  1326. j++;
  1327. replaced = true;
  1328. }
  1329. if (j < num_chars) {
  1330. buf[j] = c;
  1331. s++;
  1332. replaced = false;
  1333. }
  1334. }
  1335. while (!(msm_read(port, UART_SR) & UART_SR_TX_READY))
  1336. cpu_relax();
  1337. iowrite32_rep(tf, buf, 1);
  1338. i += num_chars;
  1339. }
  1340. if (locked)
  1341. spin_unlock(&port->lock);
  1342. }
  1343. static void msm_console_write(struct console *co, const char *s,
  1344. unsigned int count)
  1345. {
  1346. struct uart_port *port;
  1347. struct msm_port *msm_port;
  1348. BUG_ON(co->index < 0 || co->index >= UART_NR);
  1349. port = msm_get_port_from_line(co->index);
  1350. msm_port = UART_TO_MSM(port);
  1351. __msm_console_write(port, s, count, msm_port->is_uartdm);
  1352. }
  1353. static int msm_console_setup(struct console *co, char *options)
  1354. {
  1355. struct uart_port *port;
  1356. int baud = 115200;
  1357. int bits = 8;
  1358. int parity = 'n';
  1359. int flow = 'n';
  1360. if (unlikely(co->index >= UART_NR || co->index < 0))
  1361. return -ENXIO;
  1362. port = msm_get_port_from_line(co->index);
  1363. if (unlikely(!port->membase))
  1364. return -ENXIO;
  1365. msm_init_clock(port);
  1366. if (options)
  1367. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1368. pr_info("msm_serial: console setup on port #%d\n", port->line);
  1369. return uart_set_options(port, co, baud, parity, bits, flow);
  1370. }
  1371. static void
  1372. msm_serial_early_write(struct console *con, const char *s, unsigned n)
  1373. {
  1374. struct earlycon_device *dev = con->data;
  1375. __msm_console_write(&dev->port, s, n, false);
  1376. }
  1377. static int __init
  1378. msm_serial_early_console_setup(struct earlycon_device *device, const char *opt)
  1379. {
  1380. if (!device->port.membase)
  1381. return -ENODEV;
  1382. device->con->write = msm_serial_early_write;
  1383. return 0;
  1384. }
  1385. OF_EARLYCON_DECLARE(msm_serial, "qcom,msm-uart",
  1386. msm_serial_early_console_setup);
  1387. static void
  1388. msm_serial_early_write_dm(struct console *con, const char *s, unsigned n)
  1389. {
  1390. struct earlycon_device *dev = con->data;
  1391. __msm_console_write(&dev->port, s, n, true);
  1392. }
  1393. static int __init
  1394. msm_serial_early_console_setup_dm(struct earlycon_device *device,
  1395. const char *opt)
  1396. {
  1397. if (!device->port.membase)
  1398. return -ENODEV;
  1399. device->con->write = msm_serial_early_write_dm;
  1400. return 0;
  1401. }
  1402. OF_EARLYCON_DECLARE(msm_serial_dm, "qcom,msm-uartdm",
  1403. msm_serial_early_console_setup_dm);
  1404. static struct uart_driver msm_uart_driver;
  1405. static struct console msm_console = {
  1406. .name = "ttyMSM",
  1407. .write = msm_console_write,
  1408. .device = uart_console_device,
  1409. .setup = msm_console_setup,
  1410. .flags = CON_PRINTBUFFER,
  1411. .index = -1,
  1412. .data = &msm_uart_driver,
  1413. };
  1414. #define MSM_CONSOLE (&msm_console)
  1415. #else
  1416. #define MSM_CONSOLE NULL
  1417. #endif
  1418. static struct uart_driver msm_uart_driver = {
  1419. .owner = THIS_MODULE,
  1420. .driver_name = "msm_serial",
  1421. .dev_name = "ttyMSM",
  1422. .nr = UART_NR,
  1423. .cons = MSM_CONSOLE,
  1424. };
  1425. static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
  1426. static const struct of_device_id msm_uartdm_table[] = {
  1427. { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
  1428. { .compatible = "qcom,msm-uartdm-v1.2", .data = (void *)UARTDM_1P2 },
  1429. { .compatible = "qcom,msm-uartdm-v1.3", .data = (void *)UARTDM_1P3 },
  1430. { .compatible = "qcom,msm-uartdm-v1.4", .data = (void *)UARTDM_1P4 },
  1431. { }
  1432. };
  1433. static int msm_serial_probe(struct platform_device *pdev)
  1434. {
  1435. struct msm_port *msm_port;
  1436. struct resource *resource;
  1437. struct uart_port *port;
  1438. const struct of_device_id *id;
  1439. int irq, line;
  1440. if (pdev->dev.of_node)
  1441. line = of_alias_get_id(pdev->dev.of_node, "serial");
  1442. else
  1443. line = pdev->id;
  1444. if (line < 0)
  1445. line = atomic_inc_return(&msm_uart_next_id) - 1;
  1446. if (unlikely(line < 0 || line >= UART_NR))
  1447. return -ENXIO;
  1448. dev_info(&pdev->dev, "msm_serial: detected port #%d\n", line);
  1449. port = msm_get_port_from_line(line);
  1450. port->dev = &pdev->dev;
  1451. msm_port = UART_TO_MSM(port);
  1452. id = of_match_device(msm_uartdm_table, &pdev->dev);
  1453. if (id)
  1454. msm_port->is_uartdm = (unsigned long)id->data;
  1455. else
  1456. msm_port->is_uartdm = 0;
  1457. msm_port->clk = devm_clk_get(&pdev->dev, "core");
  1458. if (IS_ERR(msm_port->clk))
  1459. return PTR_ERR(msm_port->clk);
  1460. if (msm_port->is_uartdm) {
  1461. msm_port->pclk = devm_clk_get(&pdev->dev, "iface");
  1462. if (IS_ERR(msm_port->pclk))
  1463. return PTR_ERR(msm_port->pclk);
  1464. }
  1465. port->uartclk = clk_get_rate(msm_port->clk);
  1466. dev_info(&pdev->dev, "uartclk = %d\n", port->uartclk);
  1467. resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1468. if (unlikely(!resource))
  1469. return -ENXIO;
  1470. port->mapbase = resource->start;
  1471. irq = platform_get_irq(pdev, 0);
  1472. if (unlikely(irq < 0))
  1473. return -ENXIO;
  1474. port->irq = irq;
  1475. platform_set_drvdata(pdev, port);
  1476. return uart_add_one_port(&msm_uart_driver, port);
  1477. }
  1478. static int msm_serial_remove(struct platform_device *pdev)
  1479. {
  1480. struct uart_port *port = platform_get_drvdata(pdev);
  1481. uart_remove_one_port(&msm_uart_driver, port);
  1482. return 0;
  1483. }
  1484. static const struct of_device_id msm_match_table[] = {
  1485. { .compatible = "qcom,msm-uart" },
  1486. { .compatible = "qcom,msm-uartdm" },
  1487. {}
  1488. };
  1489. MODULE_DEVICE_TABLE(of, msm_match_table);
  1490. static int __maybe_unused msm_serial_suspend(struct device *dev)
  1491. {
  1492. struct msm_port *port = dev_get_drvdata(dev);
  1493. uart_suspend_port(&msm_uart_driver, &port->uart);
  1494. return 0;
  1495. }
  1496. static int __maybe_unused msm_serial_resume(struct device *dev)
  1497. {
  1498. struct msm_port *port = dev_get_drvdata(dev);
  1499. uart_resume_port(&msm_uart_driver, &port->uart);
  1500. return 0;
  1501. }
  1502. static const struct dev_pm_ops msm_serial_dev_pm_ops = {
  1503. SET_SYSTEM_SLEEP_PM_OPS(msm_serial_suspend, msm_serial_resume)
  1504. };
  1505. static struct platform_driver msm_platform_driver = {
  1506. .remove = msm_serial_remove,
  1507. .probe = msm_serial_probe,
  1508. .driver = {
  1509. .name = "msm_serial",
  1510. .pm = &msm_serial_dev_pm_ops,
  1511. .of_match_table = msm_match_table,
  1512. },
  1513. };
  1514. static int __init msm_serial_init(void)
  1515. {
  1516. int ret;
  1517. ret = uart_register_driver(&msm_uart_driver);
  1518. if (unlikely(ret))
  1519. return ret;
  1520. ret = platform_driver_register(&msm_platform_driver);
  1521. if (unlikely(ret))
  1522. uart_unregister_driver(&msm_uart_driver);
  1523. pr_info("msm_serial: driver initialized\n");
  1524. return ret;
  1525. }
  1526. static void __exit msm_serial_exit(void)
  1527. {
  1528. platform_driver_unregister(&msm_platform_driver);
  1529. uart_unregister_driver(&msm_uart_driver);
  1530. }
  1531. module_init(msm_serial_init);
  1532. module_exit(msm_serial_exit);
  1533. MODULE_AUTHOR("Robert Love <rlove@google.com>");
  1534. MODULE_DESCRIPTION("Driver for msm7x serial device");
  1535. MODULE_LICENSE("GPL");