qcom_geni_serial.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2017-2018, The Linux foundation. All rights reserved.
  3. #include <linux/clk.h>
  4. #include <linux/console.h>
  5. #include <linux/io.h>
  6. #include <linux/iopoll.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/of_device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/qcom-geni-se.h>
  12. #include <linux/serial.h>
  13. #include <linux/serial_core.h>
  14. #include <linux/slab.h>
  15. #include <linux/tty.h>
  16. #include <linux/tty_flip.h>
  17. /* UART specific GENI registers */
  18. #define SE_UART_TX_TRANS_CFG 0x25c
  19. #define SE_UART_TX_WORD_LEN 0x268
  20. #define SE_UART_TX_STOP_BIT_LEN 0x26c
  21. #define SE_UART_TX_TRANS_LEN 0x270
  22. #define SE_UART_RX_TRANS_CFG 0x280
  23. #define SE_UART_RX_WORD_LEN 0x28c
  24. #define SE_UART_RX_STALE_CNT 0x294
  25. #define SE_UART_TX_PARITY_CFG 0x2a4
  26. #define SE_UART_RX_PARITY_CFG 0x2a8
  27. /* SE_UART_TRANS_CFG */
  28. #define UART_TX_PAR_EN BIT(0)
  29. #define UART_CTS_MASK BIT(1)
  30. /* SE_UART_TX_WORD_LEN */
  31. #define TX_WORD_LEN_MSK GENMASK(9, 0)
  32. /* SE_UART_TX_STOP_BIT_LEN */
  33. #define TX_STOP_BIT_LEN_MSK GENMASK(23, 0)
  34. #define TX_STOP_BIT_LEN_1 0
  35. #define TX_STOP_BIT_LEN_1_5 1
  36. #define TX_STOP_BIT_LEN_2 2
  37. /* SE_UART_TX_TRANS_LEN */
  38. #define TX_TRANS_LEN_MSK GENMASK(23, 0)
  39. /* SE_UART_RX_TRANS_CFG */
  40. #define UART_RX_INS_STATUS_BIT BIT(2)
  41. #define UART_RX_PAR_EN BIT(3)
  42. /* SE_UART_RX_WORD_LEN */
  43. #define RX_WORD_LEN_MASK GENMASK(9, 0)
  44. /* SE_UART_RX_STALE_CNT */
  45. #define RX_STALE_CNT GENMASK(23, 0)
  46. /* SE_UART_TX_PARITY_CFG/RX_PARITY_CFG */
  47. #define PAR_CALC_EN BIT(0)
  48. #define PAR_MODE_MSK GENMASK(2, 1)
  49. #define PAR_MODE_SHFT 1
  50. #define PAR_EVEN 0x00
  51. #define PAR_ODD 0x01
  52. #define PAR_SPACE 0x10
  53. #define PAR_MARK 0x11
  54. /* UART M_CMD OP codes */
  55. #define UART_START_TX 0x1
  56. #define UART_START_BREAK 0x4
  57. #define UART_STOP_BREAK 0x5
  58. /* UART S_CMD OP codes */
  59. #define UART_START_READ 0x1
  60. #define UART_PARAM 0x1
  61. #define UART_OVERSAMPLING 32
  62. #define STALE_TIMEOUT 16
  63. #define DEFAULT_BITS_PER_CHAR 10
  64. #define GENI_UART_CONS_PORTS 1
  65. #define DEF_FIFO_DEPTH_WORDS 16
  66. #define DEF_TX_WM 2
  67. #define DEF_FIFO_WIDTH_BITS 32
  68. #define UART_CONSOLE_RX_WM 2
  69. #ifdef CONFIG_CONSOLE_POLL
  70. #define RX_BYTES_PW 1
  71. #else
  72. #define RX_BYTES_PW 4
  73. #endif
  74. struct qcom_geni_serial_port {
  75. struct uart_port uport;
  76. struct geni_se se;
  77. char name[20];
  78. u32 tx_fifo_depth;
  79. u32 tx_fifo_width;
  80. u32 rx_fifo_depth;
  81. u32 tx_wm;
  82. u32 rx_wm;
  83. u32 rx_rfr;
  84. enum geni_se_xfer_mode xfer_mode;
  85. bool setup;
  86. int (*handle_rx)(struct uart_port *uport, u32 bytes, bool drop);
  87. unsigned int xmit_size;
  88. unsigned int baud;
  89. unsigned int tx_bytes_pw;
  90. unsigned int rx_bytes_pw;
  91. bool brk;
  92. };
  93. static const struct uart_ops qcom_geni_serial_pops;
  94. static struct uart_driver qcom_geni_console_driver;
  95. static int handle_rx_console(struct uart_port *uport, u32 bytes, bool drop);
  96. static unsigned int qcom_geni_serial_tx_empty(struct uart_port *port);
  97. static void qcom_geni_serial_stop_rx(struct uart_port *uport);
  98. static const unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
  99. 32000000, 48000000, 64000000, 80000000,
  100. 96000000, 100000000};
  101. #define to_dev_port(ptr, member) \
  102. container_of(ptr, struct qcom_geni_serial_port, member)
  103. static struct qcom_geni_serial_port qcom_geni_console_port;
  104. static int qcom_geni_serial_request_port(struct uart_port *uport)
  105. {
  106. struct platform_device *pdev = to_platform_device(uport->dev);
  107. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  108. struct resource *res;
  109. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  110. uport->membase = devm_ioremap_resource(&pdev->dev, res);
  111. if (IS_ERR(uport->membase))
  112. return PTR_ERR(uport->membase);
  113. port->se.base = uport->membase;
  114. return 0;
  115. }
  116. static void qcom_geni_serial_config_port(struct uart_port *uport, int cfg_flags)
  117. {
  118. if (cfg_flags & UART_CONFIG_TYPE) {
  119. uport->type = PORT_MSM;
  120. qcom_geni_serial_request_port(uport);
  121. }
  122. }
  123. static unsigned int qcom_geni_cons_get_mctrl(struct uart_port *uport)
  124. {
  125. return TIOCM_DSR | TIOCM_CAR | TIOCM_CTS;
  126. }
  127. static void qcom_geni_cons_set_mctrl(struct uart_port *uport,
  128. unsigned int mctrl)
  129. {
  130. }
  131. static const char *qcom_geni_serial_get_type(struct uart_port *uport)
  132. {
  133. return "MSM";
  134. }
  135. static struct qcom_geni_serial_port *get_port_from_line(int line)
  136. {
  137. if (line < 0 || line >= GENI_UART_CONS_PORTS)
  138. return ERR_PTR(-ENXIO);
  139. return &qcom_geni_console_port;
  140. }
  141. static bool qcom_geni_serial_poll_bit(struct uart_port *uport,
  142. int offset, int field, bool set)
  143. {
  144. u32 reg;
  145. struct qcom_geni_serial_port *port;
  146. unsigned int baud;
  147. unsigned int fifo_bits;
  148. unsigned long timeout_us = 20000;
  149. /* Ensure polling is not re-ordered before the prior writes/reads */
  150. mb();
  151. if (uport->private_data) {
  152. port = to_dev_port(uport, uport);
  153. baud = port->baud;
  154. if (!baud)
  155. baud = 115200;
  156. fifo_bits = port->tx_fifo_depth * port->tx_fifo_width;
  157. /*
  158. * Total polling iterations based on FIFO worth of bytes to be
  159. * sent at current baud. Add a little fluff to the wait.
  160. */
  161. timeout_us = ((fifo_bits * USEC_PER_SEC) / baud) + 500;
  162. }
  163. return !readl_poll_timeout_atomic(uport->membase + offset, reg,
  164. (bool)(reg & field) == set, 10, timeout_us);
  165. }
  166. static void qcom_geni_serial_setup_tx(struct uart_port *uport, u32 xmit_size)
  167. {
  168. u32 m_cmd;
  169. writel_relaxed(xmit_size, uport->membase + SE_UART_TX_TRANS_LEN);
  170. m_cmd = UART_START_TX << M_OPCODE_SHFT;
  171. writel(m_cmd, uport->membase + SE_GENI_M_CMD0);
  172. }
  173. static void qcom_geni_serial_poll_tx_done(struct uart_port *uport)
  174. {
  175. int done;
  176. u32 irq_clear = M_CMD_DONE_EN;
  177. done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  178. M_CMD_DONE_EN, true);
  179. if (!done) {
  180. writel_relaxed(M_GENI_CMD_ABORT, uport->membase +
  181. SE_GENI_M_CMD_CTRL_REG);
  182. irq_clear |= M_CMD_ABORT_EN;
  183. qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  184. M_CMD_ABORT_EN, true);
  185. }
  186. writel_relaxed(irq_clear, uport->membase + SE_GENI_M_IRQ_CLEAR);
  187. }
  188. static void qcom_geni_serial_abort_rx(struct uart_port *uport)
  189. {
  190. u32 irq_clear = S_CMD_DONE_EN | S_CMD_ABORT_EN;
  191. writel(S_GENI_CMD_ABORT, uport->membase + SE_GENI_S_CMD_CTRL_REG);
  192. qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
  193. S_GENI_CMD_ABORT, false);
  194. writel_relaxed(irq_clear, uport->membase + SE_GENI_S_IRQ_CLEAR);
  195. writel_relaxed(FORCE_DEFAULT, uport->membase + GENI_FORCE_DEFAULT_REG);
  196. }
  197. #ifdef CONFIG_CONSOLE_POLL
  198. static int qcom_geni_serial_get_char(struct uart_port *uport)
  199. {
  200. u32 rx_fifo;
  201. u32 status;
  202. status = readl_relaxed(uport->membase + SE_GENI_M_IRQ_STATUS);
  203. writel_relaxed(status, uport->membase + SE_GENI_M_IRQ_CLEAR);
  204. status = readl_relaxed(uport->membase + SE_GENI_S_IRQ_STATUS);
  205. writel_relaxed(status, uport->membase + SE_GENI_S_IRQ_CLEAR);
  206. /*
  207. * Ensure the writes to clear interrupts is not re-ordered after
  208. * reading the data.
  209. */
  210. mb();
  211. status = readl_relaxed(uport->membase + SE_GENI_RX_FIFO_STATUS);
  212. if (!(status & RX_FIFO_WC_MSK))
  213. return NO_POLL_CHAR;
  214. rx_fifo = readl(uport->membase + SE_GENI_RX_FIFOn);
  215. return rx_fifo & 0xff;
  216. }
  217. static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
  218. unsigned char c)
  219. {
  220. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  221. writel_relaxed(port->tx_wm, uport->membase + SE_GENI_TX_WATERMARK_REG);
  222. qcom_geni_serial_setup_tx(uport, 1);
  223. WARN_ON(!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  224. M_TX_FIFO_WATERMARK_EN, true));
  225. writel_relaxed(c, uport->membase + SE_GENI_TX_FIFOn);
  226. writel_relaxed(M_TX_FIFO_WATERMARK_EN, uport->membase +
  227. SE_GENI_M_IRQ_CLEAR);
  228. qcom_geni_serial_poll_tx_done(uport);
  229. }
  230. #endif
  231. #ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
  232. static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch)
  233. {
  234. writel_relaxed(ch, uport->membase + SE_GENI_TX_FIFOn);
  235. }
  236. static void
  237. __qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
  238. unsigned int count)
  239. {
  240. int i;
  241. u32 bytes_to_send = count;
  242. for (i = 0; i < count; i++) {
  243. if (s[i] == '\n')
  244. bytes_to_send++;
  245. }
  246. writel_relaxed(DEF_TX_WM, uport->membase + SE_GENI_TX_WATERMARK_REG);
  247. qcom_geni_serial_setup_tx(uport, bytes_to_send);
  248. for (i = 0; i < count; ) {
  249. size_t chars_to_write = 0;
  250. size_t avail = DEF_FIFO_DEPTH_WORDS - DEF_TX_WM;
  251. /*
  252. * If the WM bit never set, then the Tx state machine is not
  253. * in a valid state, so break, cancel/abort any existing
  254. * command. Unfortunately the current data being written is
  255. * lost.
  256. */
  257. if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  258. M_TX_FIFO_WATERMARK_EN, true))
  259. break;
  260. chars_to_write = min_t(size_t, (size_t)(count - i), avail / 2);
  261. uart_console_write(uport, s + i, chars_to_write,
  262. qcom_geni_serial_wr_char);
  263. writel_relaxed(M_TX_FIFO_WATERMARK_EN, uport->membase +
  264. SE_GENI_M_IRQ_CLEAR);
  265. i += chars_to_write;
  266. }
  267. qcom_geni_serial_poll_tx_done(uport);
  268. }
  269. static void qcom_geni_serial_console_write(struct console *co, const char *s,
  270. unsigned int count)
  271. {
  272. struct uart_port *uport;
  273. struct qcom_geni_serial_port *port;
  274. bool locked = true;
  275. unsigned long flags;
  276. WARN_ON(co->index < 0 || co->index >= GENI_UART_CONS_PORTS);
  277. port = get_port_from_line(co->index);
  278. if (IS_ERR(port))
  279. return;
  280. uport = &port->uport;
  281. if (oops_in_progress)
  282. locked = spin_trylock_irqsave(&uport->lock, flags);
  283. else
  284. spin_lock_irqsave(&uport->lock, flags);
  285. /* Cancel the current write to log the fault */
  286. if (!locked) {
  287. geni_se_cancel_m_cmd(&port->se);
  288. if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  289. M_CMD_CANCEL_EN, true)) {
  290. geni_se_abort_m_cmd(&port->se);
  291. qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  292. M_CMD_ABORT_EN, true);
  293. writel_relaxed(M_CMD_ABORT_EN, uport->membase +
  294. SE_GENI_M_IRQ_CLEAR);
  295. }
  296. writel_relaxed(M_CMD_CANCEL_EN, uport->membase +
  297. SE_GENI_M_IRQ_CLEAR);
  298. }
  299. __qcom_geni_serial_console_write(uport, s, count);
  300. if (locked)
  301. spin_unlock_irqrestore(&uport->lock, flags);
  302. }
  303. static int handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
  304. {
  305. u32 i;
  306. unsigned char buf[sizeof(u32)];
  307. struct tty_port *tport;
  308. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  309. tport = &uport->state->port;
  310. for (i = 0; i < bytes; ) {
  311. int c;
  312. int chunk = min_t(int, bytes - i, port->rx_bytes_pw);
  313. ioread32_rep(uport->membase + SE_GENI_RX_FIFOn, buf, 1);
  314. i += chunk;
  315. if (drop)
  316. continue;
  317. for (c = 0; c < chunk; c++) {
  318. int sysrq;
  319. uport->icount.rx++;
  320. if (port->brk && buf[c] == 0) {
  321. port->brk = false;
  322. if (uart_handle_break(uport))
  323. continue;
  324. }
  325. sysrq = uart_handle_sysrq_char(uport, buf[c]);
  326. if (!sysrq)
  327. tty_insert_flip_char(tport, buf[c], TTY_NORMAL);
  328. }
  329. }
  330. if (!drop)
  331. tty_flip_buffer_push(tport);
  332. return 0;
  333. }
  334. #else
  335. static int handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
  336. {
  337. return -EPERM;
  338. }
  339. #endif /* CONFIG_SERIAL_QCOM_GENI_CONSOLE */
  340. static void qcom_geni_serial_start_tx(struct uart_port *uport)
  341. {
  342. u32 irq_en;
  343. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  344. u32 status;
  345. if (port->xfer_mode == GENI_SE_FIFO) {
  346. status = readl_relaxed(uport->membase + SE_GENI_STATUS);
  347. if (status & M_GENI_CMD_ACTIVE)
  348. return;
  349. if (!qcom_geni_serial_tx_empty(uport))
  350. return;
  351. /*
  352. * Ensure writing to IRQ_EN & watermark registers are not
  353. * re-ordered before checking the status of the Serial
  354. * Engine and TX FIFO
  355. */
  356. mb();
  357. irq_en = readl_relaxed(uport->membase + SE_GENI_M_IRQ_EN);
  358. irq_en |= M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN;
  359. writel_relaxed(port->tx_wm, uport->membase +
  360. SE_GENI_TX_WATERMARK_REG);
  361. writel_relaxed(irq_en, uport->membase + SE_GENI_M_IRQ_EN);
  362. }
  363. }
  364. static void qcom_geni_serial_stop_tx(struct uart_port *uport)
  365. {
  366. u32 irq_en;
  367. u32 status;
  368. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  369. irq_en = readl_relaxed(uport->membase + SE_GENI_M_IRQ_EN);
  370. irq_en &= ~M_CMD_DONE_EN;
  371. if (port->xfer_mode == GENI_SE_FIFO) {
  372. irq_en &= ~M_TX_FIFO_WATERMARK_EN;
  373. writel_relaxed(0, uport->membase +
  374. SE_GENI_TX_WATERMARK_REG);
  375. }
  376. port->xmit_size = 0;
  377. writel_relaxed(irq_en, uport->membase + SE_GENI_M_IRQ_EN);
  378. status = readl_relaxed(uport->membase + SE_GENI_STATUS);
  379. /* Possible stop tx is called multiple times. */
  380. if (!(status & M_GENI_CMD_ACTIVE))
  381. return;
  382. /*
  383. * Ensure cancel command write is not re-ordered before checking
  384. * the status of the Primary Sequencer.
  385. */
  386. mb();
  387. geni_se_cancel_m_cmd(&port->se);
  388. if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  389. M_CMD_CANCEL_EN, true)) {
  390. geni_se_abort_m_cmd(&port->se);
  391. qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
  392. M_CMD_ABORT_EN, true);
  393. writel_relaxed(M_CMD_ABORT_EN, uport->membase +
  394. SE_GENI_M_IRQ_CLEAR);
  395. }
  396. writel_relaxed(M_CMD_CANCEL_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
  397. }
  398. static void qcom_geni_serial_start_rx(struct uart_port *uport)
  399. {
  400. u32 irq_en;
  401. u32 status;
  402. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  403. status = readl_relaxed(uport->membase + SE_GENI_STATUS);
  404. if (status & S_GENI_CMD_ACTIVE)
  405. qcom_geni_serial_stop_rx(uport);
  406. /*
  407. * Ensure setup command write is not re-ordered before checking
  408. * the status of the Secondary Sequencer.
  409. */
  410. mb();
  411. geni_se_setup_s_cmd(&port->se, UART_START_READ, 0);
  412. if (port->xfer_mode == GENI_SE_FIFO) {
  413. irq_en = readl_relaxed(uport->membase + SE_GENI_S_IRQ_EN);
  414. irq_en |= S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN;
  415. writel_relaxed(irq_en, uport->membase + SE_GENI_S_IRQ_EN);
  416. irq_en = readl_relaxed(uport->membase + SE_GENI_M_IRQ_EN);
  417. irq_en |= M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN;
  418. writel_relaxed(irq_en, uport->membase + SE_GENI_M_IRQ_EN);
  419. }
  420. }
  421. static void qcom_geni_serial_stop_rx(struct uart_port *uport)
  422. {
  423. u32 irq_en;
  424. u32 status;
  425. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  426. u32 irq_clear = S_CMD_DONE_EN;
  427. if (port->xfer_mode == GENI_SE_FIFO) {
  428. irq_en = readl_relaxed(uport->membase + SE_GENI_S_IRQ_EN);
  429. irq_en &= ~(S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN);
  430. writel_relaxed(irq_en, uport->membase + SE_GENI_S_IRQ_EN);
  431. irq_en = readl_relaxed(uport->membase + SE_GENI_M_IRQ_EN);
  432. irq_en &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);
  433. writel_relaxed(irq_en, uport->membase + SE_GENI_M_IRQ_EN);
  434. }
  435. status = readl_relaxed(uport->membase + SE_GENI_STATUS);
  436. /* Possible stop rx is called multiple times. */
  437. if (!(status & S_GENI_CMD_ACTIVE))
  438. return;
  439. /*
  440. * Ensure cancel command write is not re-ordered before checking
  441. * the status of the Secondary Sequencer.
  442. */
  443. mb();
  444. geni_se_cancel_s_cmd(&port->se);
  445. qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
  446. S_GENI_CMD_CANCEL, false);
  447. status = readl_relaxed(uport->membase + SE_GENI_STATUS);
  448. writel_relaxed(irq_clear, uport->membase + SE_GENI_S_IRQ_CLEAR);
  449. if (status & S_GENI_CMD_ACTIVE)
  450. qcom_geni_serial_abort_rx(uport);
  451. }
  452. static void qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop)
  453. {
  454. u32 status;
  455. u32 word_cnt;
  456. u32 last_word_byte_cnt;
  457. u32 last_word_partial;
  458. u32 total_bytes;
  459. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  460. status = readl_relaxed(uport->membase + SE_GENI_RX_FIFO_STATUS);
  461. word_cnt = status & RX_FIFO_WC_MSK;
  462. last_word_partial = status & RX_LAST;
  463. last_word_byte_cnt = (status & RX_LAST_BYTE_VALID_MSK) >>
  464. RX_LAST_BYTE_VALID_SHFT;
  465. if (!word_cnt)
  466. return;
  467. total_bytes = port->rx_bytes_pw * (word_cnt - 1);
  468. if (last_word_partial && last_word_byte_cnt)
  469. total_bytes += last_word_byte_cnt;
  470. else
  471. total_bytes += port->rx_bytes_pw;
  472. port->handle_rx(uport, total_bytes, drop);
  473. }
  474. static void qcom_geni_serial_handle_tx(struct uart_port *uport)
  475. {
  476. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  477. struct circ_buf *xmit = &uport->state->xmit;
  478. size_t avail;
  479. size_t remaining;
  480. int i;
  481. u32 status;
  482. unsigned int chunk;
  483. int tail;
  484. chunk = uart_circ_chars_pending(xmit);
  485. status = readl_relaxed(uport->membase + SE_GENI_TX_FIFO_STATUS);
  486. /* Both FIFO and framework buffer are drained */
  487. if (chunk == port->xmit_size && !status) {
  488. port->xmit_size = 0;
  489. uart_circ_clear(xmit);
  490. qcom_geni_serial_stop_tx(uport);
  491. goto out_write_wakeup;
  492. }
  493. chunk -= port->xmit_size;
  494. avail = (port->tx_fifo_depth - port->tx_wm) * port->tx_bytes_pw;
  495. tail = (xmit->tail + port->xmit_size) & (UART_XMIT_SIZE - 1);
  496. if (chunk > (UART_XMIT_SIZE - tail))
  497. chunk = UART_XMIT_SIZE - tail;
  498. if (chunk > avail)
  499. chunk = avail;
  500. if (!chunk)
  501. goto out_write_wakeup;
  502. qcom_geni_serial_setup_tx(uport, chunk);
  503. remaining = chunk;
  504. for (i = 0; i < chunk; ) {
  505. unsigned int tx_bytes;
  506. unsigned int buf = 0;
  507. int c;
  508. tx_bytes = min_t(size_t, remaining, (size_t)port->tx_bytes_pw);
  509. for (c = 0; c < tx_bytes ; c++)
  510. buf |= (xmit->buf[tail + c] << (c * BITS_PER_BYTE));
  511. writel_relaxed(buf, uport->membase + SE_GENI_TX_FIFOn);
  512. i += tx_bytes;
  513. tail = (tail + tx_bytes) & (UART_XMIT_SIZE - 1);
  514. uport->icount.tx += tx_bytes;
  515. remaining -= tx_bytes;
  516. }
  517. qcom_geni_serial_poll_tx_done(uport);
  518. port->xmit_size += chunk;
  519. out_write_wakeup:
  520. uart_write_wakeup(uport);
  521. }
  522. static irqreturn_t qcom_geni_serial_isr(int isr, void *dev)
  523. {
  524. unsigned int m_irq_status;
  525. unsigned int s_irq_status;
  526. struct uart_port *uport = dev;
  527. unsigned long flags;
  528. unsigned int m_irq_en;
  529. bool drop_rx = false;
  530. struct tty_port *tport = &uport->state->port;
  531. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  532. if (uport->suspended)
  533. return IRQ_HANDLED;
  534. spin_lock_irqsave(&uport->lock, flags);
  535. m_irq_status = readl_relaxed(uport->membase + SE_GENI_M_IRQ_STATUS);
  536. s_irq_status = readl_relaxed(uport->membase + SE_GENI_S_IRQ_STATUS);
  537. m_irq_en = readl_relaxed(uport->membase + SE_GENI_M_IRQ_EN);
  538. writel_relaxed(m_irq_status, uport->membase + SE_GENI_M_IRQ_CLEAR);
  539. writel_relaxed(s_irq_status, uport->membase + SE_GENI_S_IRQ_CLEAR);
  540. if (WARN_ON(m_irq_status & M_ILLEGAL_CMD_EN))
  541. goto out_unlock;
  542. if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
  543. uport->icount.overrun++;
  544. tty_insert_flip_char(tport, 0, TTY_OVERRUN);
  545. }
  546. if (m_irq_status & (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN) &&
  547. m_irq_en & (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN))
  548. qcom_geni_serial_handle_tx(uport);
  549. if (s_irq_status & S_GP_IRQ_0_EN || s_irq_status & S_GP_IRQ_1_EN) {
  550. if (s_irq_status & S_GP_IRQ_0_EN)
  551. uport->icount.parity++;
  552. drop_rx = true;
  553. } else if (s_irq_status & S_GP_IRQ_2_EN ||
  554. s_irq_status & S_GP_IRQ_3_EN) {
  555. uport->icount.brk++;
  556. port->brk = true;
  557. }
  558. if (s_irq_status & S_RX_FIFO_WATERMARK_EN ||
  559. s_irq_status & S_RX_FIFO_LAST_EN)
  560. qcom_geni_serial_handle_rx(uport, drop_rx);
  561. out_unlock:
  562. spin_unlock_irqrestore(&uport->lock, flags);
  563. return IRQ_HANDLED;
  564. }
  565. static int get_tx_fifo_size(struct qcom_geni_serial_port *port)
  566. {
  567. struct uart_port *uport;
  568. if (!port)
  569. return -ENODEV;
  570. uport = &port->uport;
  571. port->tx_fifo_depth = geni_se_get_tx_fifo_depth(&port->se);
  572. port->tx_fifo_width = geni_se_get_tx_fifo_width(&port->se);
  573. port->rx_fifo_depth = geni_se_get_rx_fifo_depth(&port->se);
  574. uport->fifosize =
  575. (port->tx_fifo_depth * port->tx_fifo_width) / BITS_PER_BYTE;
  576. return 0;
  577. }
  578. static void set_rfr_wm(struct qcom_geni_serial_port *port)
  579. {
  580. /*
  581. * Set RFR (Flow off) to FIFO_DEPTH - 2.
  582. * RX WM level at 10% RX_FIFO_DEPTH.
  583. * TX WM level at 10% TX_FIFO_DEPTH.
  584. */
  585. port->rx_rfr = port->rx_fifo_depth - 2;
  586. port->rx_wm = UART_CONSOLE_RX_WM;
  587. port->tx_wm = DEF_TX_WM;
  588. }
  589. static void qcom_geni_serial_shutdown(struct uart_port *uport)
  590. {
  591. unsigned long flags;
  592. /* Stop the console before stopping the current tx */
  593. console_stop(uport->cons);
  594. disable_irq(uport->irq);
  595. free_irq(uport->irq, uport);
  596. spin_lock_irqsave(&uport->lock, flags);
  597. qcom_geni_serial_stop_tx(uport);
  598. qcom_geni_serial_stop_rx(uport);
  599. spin_unlock_irqrestore(&uport->lock, flags);
  600. }
  601. static int qcom_geni_serial_port_setup(struct uart_port *uport)
  602. {
  603. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  604. unsigned int rxstale = DEFAULT_BITS_PER_CHAR * STALE_TIMEOUT;
  605. set_rfr_wm(port);
  606. writel_relaxed(rxstale, uport->membase + SE_UART_RX_STALE_CNT);
  607. /*
  608. * Make an unconditional cancel on the main sequencer to reset
  609. * it else we could end up in data loss scenarios.
  610. */
  611. port->xfer_mode = GENI_SE_FIFO;
  612. qcom_geni_serial_poll_tx_done(uport);
  613. geni_se_config_packing(&port->se, BITS_PER_BYTE, port->tx_bytes_pw,
  614. false, true, false);
  615. geni_se_config_packing(&port->se, BITS_PER_BYTE, port->rx_bytes_pw,
  616. false, false, true);
  617. geni_se_init(&port->se, port->rx_wm, port->rx_rfr);
  618. geni_se_select_mode(&port->se, port->xfer_mode);
  619. port->setup = true;
  620. return 0;
  621. }
  622. static int qcom_geni_serial_startup(struct uart_port *uport)
  623. {
  624. int ret;
  625. u32 proto;
  626. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  627. scnprintf(port->name, sizeof(port->name),
  628. "qcom_serial_geni%d", uport->line);
  629. proto = geni_se_read_proto(&port->se);
  630. if (proto != GENI_SE_UART) {
  631. dev_err(uport->dev, "Invalid FW loaded, proto: %d\n", proto);
  632. return -ENXIO;
  633. }
  634. get_tx_fifo_size(port);
  635. if (!port->setup) {
  636. ret = qcom_geni_serial_port_setup(uport);
  637. if (ret)
  638. return ret;
  639. }
  640. ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
  641. port->name, uport);
  642. if (ret)
  643. dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
  644. return ret;
  645. }
  646. static unsigned long get_clk_cfg(unsigned long clk_freq)
  647. {
  648. int i;
  649. for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
  650. if (!(root_freq[i] % clk_freq))
  651. return root_freq[i];
  652. }
  653. return 0;
  654. }
  655. static unsigned long get_clk_div_rate(unsigned int baud, unsigned int *clk_div)
  656. {
  657. unsigned long ser_clk;
  658. unsigned long desired_clk;
  659. desired_clk = baud * UART_OVERSAMPLING;
  660. ser_clk = get_clk_cfg(desired_clk);
  661. if (!ser_clk) {
  662. pr_err("%s: Can't find matching DFS entry for baud %d\n",
  663. __func__, baud);
  664. return ser_clk;
  665. }
  666. *clk_div = ser_clk / desired_clk;
  667. return ser_clk;
  668. }
  669. static void qcom_geni_serial_set_termios(struct uart_port *uport,
  670. struct ktermios *termios, struct ktermios *old)
  671. {
  672. unsigned int baud;
  673. unsigned int bits_per_char;
  674. unsigned int tx_trans_cfg;
  675. unsigned int tx_parity_cfg;
  676. unsigned int rx_trans_cfg;
  677. unsigned int rx_parity_cfg;
  678. unsigned int stop_bit_len;
  679. unsigned int clk_div;
  680. unsigned long ser_clk_cfg;
  681. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  682. unsigned long clk_rate;
  683. qcom_geni_serial_stop_rx(uport);
  684. /* baud rate */
  685. baud = uart_get_baud_rate(uport, termios, old, 300, 4000000);
  686. port->baud = baud;
  687. clk_rate = get_clk_div_rate(baud, &clk_div);
  688. if (!clk_rate)
  689. goto out_restart_rx;
  690. uport->uartclk = clk_rate;
  691. clk_set_rate(port->se.clk, clk_rate);
  692. ser_clk_cfg = SER_CLK_EN;
  693. ser_clk_cfg |= clk_div << CLK_DIV_SHFT;
  694. /* parity */
  695. tx_trans_cfg = readl_relaxed(uport->membase + SE_UART_TX_TRANS_CFG);
  696. tx_parity_cfg = readl_relaxed(uport->membase + SE_UART_TX_PARITY_CFG);
  697. rx_trans_cfg = readl_relaxed(uport->membase + SE_UART_RX_TRANS_CFG);
  698. rx_parity_cfg = readl_relaxed(uport->membase + SE_UART_RX_PARITY_CFG);
  699. if (termios->c_cflag & PARENB) {
  700. tx_trans_cfg |= UART_TX_PAR_EN;
  701. rx_trans_cfg |= UART_RX_PAR_EN;
  702. tx_parity_cfg |= PAR_CALC_EN;
  703. rx_parity_cfg |= PAR_CALC_EN;
  704. if (termios->c_cflag & PARODD) {
  705. tx_parity_cfg |= PAR_ODD;
  706. rx_parity_cfg |= PAR_ODD;
  707. } else if (termios->c_cflag & CMSPAR) {
  708. tx_parity_cfg |= PAR_SPACE;
  709. rx_parity_cfg |= PAR_SPACE;
  710. } else {
  711. tx_parity_cfg |= PAR_EVEN;
  712. rx_parity_cfg |= PAR_EVEN;
  713. }
  714. } else {
  715. tx_trans_cfg &= ~UART_TX_PAR_EN;
  716. rx_trans_cfg &= ~UART_RX_PAR_EN;
  717. tx_parity_cfg &= ~PAR_CALC_EN;
  718. rx_parity_cfg &= ~PAR_CALC_EN;
  719. }
  720. /* bits per char */
  721. switch (termios->c_cflag & CSIZE) {
  722. case CS5:
  723. bits_per_char = 5;
  724. break;
  725. case CS6:
  726. bits_per_char = 6;
  727. break;
  728. case CS7:
  729. bits_per_char = 7;
  730. break;
  731. case CS8:
  732. default:
  733. bits_per_char = 8;
  734. break;
  735. }
  736. /* stop bits */
  737. if (termios->c_cflag & CSTOPB)
  738. stop_bit_len = TX_STOP_BIT_LEN_2;
  739. else
  740. stop_bit_len = TX_STOP_BIT_LEN_1;
  741. /* flow control, clear the CTS_MASK bit if using flow control. */
  742. if (termios->c_cflag & CRTSCTS)
  743. tx_trans_cfg &= ~UART_CTS_MASK;
  744. else
  745. tx_trans_cfg |= UART_CTS_MASK;
  746. if (baud)
  747. uart_update_timeout(uport, termios->c_cflag, baud);
  748. writel_relaxed(tx_trans_cfg, uport->membase + SE_UART_TX_TRANS_CFG);
  749. writel_relaxed(tx_parity_cfg, uport->membase + SE_UART_TX_PARITY_CFG);
  750. writel_relaxed(rx_trans_cfg, uport->membase + SE_UART_RX_TRANS_CFG);
  751. writel_relaxed(rx_parity_cfg, uport->membase + SE_UART_RX_PARITY_CFG);
  752. writel_relaxed(bits_per_char, uport->membase + SE_UART_TX_WORD_LEN);
  753. writel_relaxed(bits_per_char, uport->membase + SE_UART_RX_WORD_LEN);
  754. writel_relaxed(stop_bit_len, uport->membase + SE_UART_TX_STOP_BIT_LEN);
  755. writel_relaxed(ser_clk_cfg, uport->membase + GENI_SER_M_CLK_CFG);
  756. writel_relaxed(ser_clk_cfg, uport->membase + GENI_SER_S_CLK_CFG);
  757. out_restart_rx:
  758. qcom_geni_serial_start_rx(uport);
  759. }
  760. static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
  761. {
  762. return !readl_relaxed(uport->membase + SE_GENI_TX_FIFO_STATUS);
  763. }
  764. #ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
  765. static int __init qcom_geni_console_setup(struct console *co, char *options)
  766. {
  767. struct uart_port *uport;
  768. struct qcom_geni_serial_port *port;
  769. int baud;
  770. int bits = 8;
  771. int parity = 'n';
  772. int flow = 'n';
  773. if (co->index >= GENI_UART_CONS_PORTS || co->index < 0)
  774. return -ENXIO;
  775. port = get_port_from_line(co->index);
  776. if (IS_ERR(port)) {
  777. pr_err("Invalid line %d(%d)\n", co->index, (int)PTR_ERR(port));
  778. return PTR_ERR(port);
  779. }
  780. uport = &port->uport;
  781. if (unlikely(!uport->membase))
  782. return -ENXIO;
  783. if (geni_se_resources_on(&port->se)) {
  784. dev_err(port->se.dev, "Error turning on resources\n");
  785. return -ENXIO;
  786. }
  787. if (unlikely(geni_se_read_proto(&port->se) != GENI_SE_UART)) {
  788. geni_se_resources_off(&port->se);
  789. return -ENXIO;
  790. }
  791. if (!port->setup) {
  792. port->tx_bytes_pw = 1;
  793. port->rx_bytes_pw = RX_BYTES_PW;
  794. qcom_geni_serial_stop_rx(uport);
  795. qcom_geni_serial_port_setup(uport);
  796. }
  797. if (options)
  798. uart_parse_options(options, &baud, &parity, &bits, &flow);
  799. return uart_set_options(uport, co, baud, parity, bits, flow);
  800. }
  801. static int __init console_register(struct uart_driver *drv)
  802. {
  803. return uart_register_driver(drv);
  804. }
  805. static void console_unregister(struct uart_driver *drv)
  806. {
  807. uart_unregister_driver(drv);
  808. }
  809. static struct console cons_ops = {
  810. .name = "ttyMSM",
  811. .write = qcom_geni_serial_console_write,
  812. .device = uart_console_device,
  813. .setup = qcom_geni_console_setup,
  814. .flags = CON_PRINTBUFFER,
  815. .index = -1,
  816. .data = &qcom_geni_console_driver,
  817. };
  818. static struct uart_driver qcom_geni_console_driver = {
  819. .owner = THIS_MODULE,
  820. .driver_name = "qcom_geni_console",
  821. .dev_name = "ttyMSM",
  822. .nr = GENI_UART_CONS_PORTS,
  823. .cons = &cons_ops,
  824. };
  825. #else
  826. static int console_register(struct uart_driver *drv)
  827. {
  828. return 0;
  829. }
  830. static void console_unregister(struct uart_driver *drv)
  831. {
  832. }
  833. #endif /* CONFIG_SERIAL_QCOM_GENI_CONSOLE */
  834. static void qcom_geni_serial_cons_pm(struct uart_port *uport,
  835. unsigned int new_state, unsigned int old_state)
  836. {
  837. struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
  838. if (unlikely(!uart_console(uport)))
  839. return;
  840. if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
  841. geni_se_resources_on(&port->se);
  842. else if (new_state == UART_PM_STATE_OFF &&
  843. old_state == UART_PM_STATE_ON)
  844. geni_se_resources_off(&port->se);
  845. }
  846. static const struct uart_ops qcom_geni_console_pops = {
  847. .tx_empty = qcom_geni_serial_tx_empty,
  848. .stop_tx = qcom_geni_serial_stop_tx,
  849. .start_tx = qcom_geni_serial_start_tx,
  850. .stop_rx = qcom_geni_serial_stop_rx,
  851. .set_termios = qcom_geni_serial_set_termios,
  852. .startup = qcom_geni_serial_startup,
  853. .request_port = qcom_geni_serial_request_port,
  854. .config_port = qcom_geni_serial_config_port,
  855. .shutdown = qcom_geni_serial_shutdown,
  856. .type = qcom_geni_serial_get_type,
  857. .set_mctrl = qcom_geni_cons_set_mctrl,
  858. .get_mctrl = qcom_geni_cons_get_mctrl,
  859. #ifdef CONFIG_CONSOLE_POLL
  860. .poll_get_char = qcom_geni_serial_get_char,
  861. .poll_put_char = qcom_geni_serial_poll_put_char,
  862. #endif
  863. .pm = qcom_geni_serial_cons_pm,
  864. };
  865. static int qcom_geni_serial_probe(struct platform_device *pdev)
  866. {
  867. int ret = 0;
  868. int line = -1;
  869. struct qcom_geni_serial_port *port;
  870. struct uart_port *uport;
  871. struct resource *res;
  872. int irq;
  873. if (pdev->dev.of_node)
  874. line = of_alias_get_id(pdev->dev.of_node, "serial");
  875. else
  876. line = pdev->id;
  877. if (line < 0 || line >= GENI_UART_CONS_PORTS)
  878. return -ENXIO;
  879. port = get_port_from_line(line);
  880. if (IS_ERR(port)) {
  881. ret = PTR_ERR(port);
  882. dev_err(&pdev->dev, "Invalid line %d(%d)\n", line, ret);
  883. return ret;
  884. }
  885. uport = &port->uport;
  886. /* Don't allow 2 drivers to access the same port */
  887. if (uport->private_data)
  888. return -ENODEV;
  889. uport->dev = &pdev->dev;
  890. port->se.dev = &pdev->dev;
  891. port->se.wrapper = dev_get_drvdata(pdev->dev.parent);
  892. port->se.clk = devm_clk_get(&pdev->dev, "se");
  893. if (IS_ERR(port->se.clk)) {
  894. ret = PTR_ERR(port->se.clk);
  895. dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
  896. return ret;
  897. }
  898. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  899. if (!res)
  900. return -EINVAL;
  901. uport->mapbase = res->start;
  902. port->tx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
  903. port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
  904. port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
  905. irq = platform_get_irq(pdev, 0);
  906. if (irq < 0) {
  907. dev_err(&pdev->dev, "Failed to get IRQ %d\n", irq);
  908. return irq;
  909. }
  910. uport->irq = irq;
  911. uport->private_data = &qcom_geni_console_driver;
  912. platform_set_drvdata(pdev, port);
  913. port->handle_rx = handle_rx_console;
  914. port->setup = false;
  915. return uart_add_one_port(&qcom_geni_console_driver, uport);
  916. }
  917. static int qcom_geni_serial_remove(struct platform_device *pdev)
  918. {
  919. struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
  920. struct uart_driver *drv = port->uport.private_data;
  921. uart_remove_one_port(drv, &port->uport);
  922. return 0;
  923. }
  924. static int __maybe_unused qcom_geni_serial_sys_suspend_noirq(struct device *dev)
  925. {
  926. struct platform_device *pdev = to_platform_device(dev);
  927. struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
  928. struct uart_port *uport = &port->uport;
  929. uart_suspend_port(uport->private_data, uport);
  930. return 0;
  931. }
  932. static int __maybe_unused qcom_geni_serial_sys_resume_noirq(struct device *dev)
  933. {
  934. struct platform_device *pdev = to_platform_device(dev);
  935. struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
  936. struct uart_port *uport = &port->uport;
  937. if (console_suspend_enabled && uport->suspended) {
  938. uart_resume_port(uport->private_data, uport);
  939. disable_irq(uport->irq);
  940. }
  941. return 0;
  942. }
  943. static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
  944. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_geni_serial_sys_suspend_noirq,
  945. qcom_geni_serial_sys_resume_noirq)
  946. };
  947. static const struct of_device_id qcom_geni_serial_match_table[] = {
  948. { .compatible = "qcom,geni-debug-uart", },
  949. {}
  950. };
  951. MODULE_DEVICE_TABLE(of, qcom_geni_serial_match_table);
  952. static struct platform_driver qcom_geni_serial_platform_driver = {
  953. .remove = qcom_geni_serial_remove,
  954. .probe = qcom_geni_serial_probe,
  955. .driver = {
  956. .name = "qcom_geni_serial",
  957. .of_match_table = qcom_geni_serial_match_table,
  958. .pm = &qcom_geni_serial_pm_ops,
  959. },
  960. };
  961. static int __init qcom_geni_serial_init(void)
  962. {
  963. int ret;
  964. qcom_geni_console_port.uport.iotype = UPIO_MEM;
  965. qcom_geni_console_port.uport.ops = &qcom_geni_console_pops;
  966. qcom_geni_console_port.uport.flags = UPF_BOOT_AUTOCONF;
  967. qcom_geni_console_port.uport.line = 0;
  968. ret = console_register(&qcom_geni_console_driver);
  969. if (ret)
  970. return ret;
  971. ret = platform_driver_register(&qcom_geni_serial_platform_driver);
  972. if (ret)
  973. console_unregister(&qcom_geni_console_driver);
  974. return ret;
  975. }
  976. module_init(qcom_geni_serial_init);
  977. static void __exit qcom_geni_serial_exit(void)
  978. {
  979. platform_driver_unregister(&qcom_geni_serial_platform_driver);
  980. console_unregister(&qcom_geni_console_driver);
  981. }
  982. module_exit(qcom_geni_serial_exit);
  983. MODULE_DESCRIPTION("Serial driver for GENI based QUP cores");
  984. MODULE_LICENSE("GPL v2");