pch_uart.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  1. /*
  2. *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
  3. *
  4. *This program is free software; you can redistribute it and/or modify
  5. *it under the terms of the GNU General Public License as published by
  6. *the Free Software Foundation; version 2 of the License.
  7. *
  8. *This program is distributed in the hope that it will be useful,
  9. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. *GNU General Public License for more details.
  12. *
  13. *You should have received a copy of the GNU General Public License
  14. *along with this program; if not, write to the Free Software
  15. *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/slab.h>
  20. #include <linux/module.h>
  21. #include <linux/pci.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/tty.h>
  24. #include <linux/tty_flip.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/dmi.h>
  28. #include <linux/console.h>
  29. #include <linux/nmi.h>
  30. #include <linux/delay.h>
  31. #include <linux/debugfs.h>
  32. #include <linux/dmaengine.h>
  33. #include <linux/pch_dma.h>
  34. enum {
  35. PCH_UART_HANDLED_RX_INT_SHIFT,
  36. PCH_UART_HANDLED_TX_INT_SHIFT,
  37. PCH_UART_HANDLED_RX_ERR_INT_SHIFT,
  38. PCH_UART_HANDLED_RX_TRG_INT_SHIFT,
  39. PCH_UART_HANDLED_MS_INT_SHIFT,
  40. };
  41. enum {
  42. PCH_UART_8LINE,
  43. PCH_UART_2LINE,
  44. };
  45. #define PCH_UART_DRIVER_DEVICE "ttyPCH"
  46. /* Set the max number of UART port
  47. * Intel EG20T PCH: 4 port
  48. * LAPIS Semiconductor ML7213 IOH: 3 port
  49. * LAPIS Semiconductor ML7223 IOH: 2 port
  50. */
  51. #define PCH_UART_NR 4
  52. #define PCH_UART_HANDLED_RX_INT (1<<((PCH_UART_HANDLED_RX_INT_SHIFT)<<1))
  53. #define PCH_UART_HANDLED_TX_INT (1<<((PCH_UART_HANDLED_TX_INT_SHIFT)<<1))
  54. #define PCH_UART_HANDLED_RX_ERR_INT (1<<((\
  55. PCH_UART_HANDLED_RX_ERR_INT_SHIFT)<<1))
  56. #define PCH_UART_HANDLED_RX_TRG_INT (1<<((\
  57. PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))
  58. #define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))
  59. #define PCH_UART_RBR 0x00
  60. #define PCH_UART_THR 0x00
  61. #define PCH_UART_IER_MASK (PCH_UART_IER_ERBFI|PCH_UART_IER_ETBEI|\
  62. PCH_UART_IER_ELSI|PCH_UART_IER_EDSSI)
  63. #define PCH_UART_IER_ERBFI 0x00000001
  64. #define PCH_UART_IER_ETBEI 0x00000002
  65. #define PCH_UART_IER_ELSI 0x00000004
  66. #define PCH_UART_IER_EDSSI 0x00000008
  67. #define PCH_UART_IIR_IP 0x00000001
  68. #define PCH_UART_IIR_IID 0x00000006
  69. #define PCH_UART_IIR_MSI 0x00000000
  70. #define PCH_UART_IIR_TRI 0x00000002
  71. #define PCH_UART_IIR_RRI 0x00000004
  72. #define PCH_UART_IIR_REI 0x00000006
  73. #define PCH_UART_IIR_TOI 0x00000008
  74. #define PCH_UART_IIR_FIFO256 0x00000020
  75. #define PCH_UART_IIR_FIFO64 PCH_UART_IIR_FIFO256
  76. #define PCH_UART_IIR_FE 0x000000C0
  77. #define PCH_UART_FCR_FIFOE 0x00000001
  78. #define PCH_UART_FCR_RFR 0x00000002
  79. #define PCH_UART_FCR_TFR 0x00000004
  80. #define PCH_UART_FCR_DMS 0x00000008
  81. #define PCH_UART_FCR_FIFO256 0x00000020
  82. #define PCH_UART_FCR_RFTL 0x000000C0
  83. #define PCH_UART_FCR_RFTL1 0x00000000
  84. #define PCH_UART_FCR_RFTL64 0x00000040
  85. #define PCH_UART_FCR_RFTL128 0x00000080
  86. #define PCH_UART_FCR_RFTL224 0x000000C0
  87. #define PCH_UART_FCR_RFTL16 PCH_UART_FCR_RFTL64
  88. #define PCH_UART_FCR_RFTL32 PCH_UART_FCR_RFTL128
  89. #define PCH_UART_FCR_RFTL56 PCH_UART_FCR_RFTL224
  90. #define PCH_UART_FCR_RFTL4 PCH_UART_FCR_RFTL64
  91. #define PCH_UART_FCR_RFTL8 PCH_UART_FCR_RFTL128
  92. #define PCH_UART_FCR_RFTL14 PCH_UART_FCR_RFTL224
  93. #define PCH_UART_FCR_RFTL_SHIFT 6
  94. #define PCH_UART_LCR_WLS 0x00000003
  95. #define PCH_UART_LCR_STB 0x00000004
  96. #define PCH_UART_LCR_PEN 0x00000008
  97. #define PCH_UART_LCR_EPS 0x00000010
  98. #define PCH_UART_LCR_SP 0x00000020
  99. #define PCH_UART_LCR_SB 0x00000040
  100. #define PCH_UART_LCR_DLAB 0x00000080
  101. #define PCH_UART_LCR_NP 0x00000000
  102. #define PCH_UART_LCR_OP PCH_UART_LCR_PEN
  103. #define PCH_UART_LCR_EP (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS)
  104. #define PCH_UART_LCR_1P (PCH_UART_LCR_PEN | PCH_UART_LCR_SP)
  105. #define PCH_UART_LCR_0P (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS |\
  106. PCH_UART_LCR_SP)
  107. #define PCH_UART_LCR_5BIT 0x00000000
  108. #define PCH_UART_LCR_6BIT 0x00000001
  109. #define PCH_UART_LCR_7BIT 0x00000002
  110. #define PCH_UART_LCR_8BIT 0x00000003
  111. #define PCH_UART_MCR_DTR 0x00000001
  112. #define PCH_UART_MCR_RTS 0x00000002
  113. #define PCH_UART_MCR_OUT 0x0000000C
  114. #define PCH_UART_MCR_LOOP 0x00000010
  115. #define PCH_UART_MCR_AFE 0x00000020
  116. #define PCH_UART_LSR_DR 0x00000001
  117. #define PCH_UART_LSR_ERR (1<<7)
  118. #define PCH_UART_MSR_DCTS 0x00000001
  119. #define PCH_UART_MSR_DDSR 0x00000002
  120. #define PCH_UART_MSR_TERI 0x00000004
  121. #define PCH_UART_MSR_DDCD 0x00000008
  122. #define PCH_UART_MSR_CTS 0x00000010
  123. #define PCH_UART_MSR_DSR 0x00000020
  124. #define PCH_UART_MSR_RI 0x00000040
  125. #define PCH_UART_MSR_DCD 0x00000080
  126. #define PCH_UART_MSR_DELTA (PCH_UART_MSR_DCTS | PCH_UART_MSR_DDSR |\
  127. PCH_UART_MSR_TERI | PCH_UART_MSR_DDCD)
  128. #define PCH_UART_DLL 0x00
  129. #define PCH_UART_DLM 0x01
  130. #define PCH_UART_BRCSR 0x0E
  131. #define PCH_UART_IID_RLS (PCH_UART_IIR_REI)
  132. #define PCH_UART_IID_RDR (PCH_UART_IIR_RRI)
  133. #define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
  134. #define PCH_UART_IID_THRE (PCH_UART_IIR_TRI)
  135. #define PCH_UART_IID_MS (PCH_UART_IIR_MSI)
  136. #define PCH_UART_HAL_PARITY_NONE (PCH_UART_LCR_NP)
  137. #define PCH_UART_HAL_PARITY_ODD (PCH_UART_LCR_OP)
  138. #define PCH_UART_HAL_PARITY_EVEN (PCH_UART_LCR_EP)
  139. #define PCH_UART_HAL_PARITY_FIX1 (PCH_UART_LCR_1P)
  140. #define PCH_UART_HAL_PARITY_FIX0 (PCH_UART_LCR_0P)
  141. #define PCH_UART_HAL_5BIT (PCH_UART_LCR_5BIT)
  142. #define PCH_UART_HAL_6BIT (PCH_UART_LCR_6BIT)
  143. #define PCH_UART_HAL_7BIT (PCH_UART_LCR_7BIT)
  144. #define PCH_UART_HAL_8BIT (PCH_UART_LCR_8BIT)
  145. #define PCH_UART_HAL_STB1 0
  146. #define PCH_UART_HAL_STB2 (PCH_UART_LCR_STB)
  147. #define PCH_UART_HAL_CLR_TX_FIFO (PCH_UART_FCR_TFR)
  148. #define PCH_UART_HAL_CLR_RX_FIFO (PCH_UART_FCR_RFR)
  149. #define PCH_UART_HAL_CLR_ALL_FIFO (PCH_UART_HAL_CLR_TX_FIFO | \
  150. PCH_UART_HAL_CLR_RX_FIFO)
  151. #define PCH_UART_HAL_DMA_MODE0 0
  152. #define PCH_UART_HAL_FIFO_DIS 0
  153. #define PCH_UART_HAL_FIFO16 (PCH_UART_FCR_FIFOE)
  154. #define PCH_UART_HAL_FIFO256 (PCH_UART_FCR_FIFOE | \
  155. PCH_UART_FCR_FIFO256)
  156. #define PCH_UART_HAL_FIFO64 (PCH_UART_HAL_FIFO256)
  157. #define PCH_UART_HAL_TRIGGER1 (PCH_UART_FCR_RFTL1)
  158. #define PCH_UART_HAL_TRIGGER64 (PCH_UART_FCR_RFTL64)
  159. #define PCH_UART_HAL_TRIGGER128 (PCH_UART_FCR_RFTL128)
  160. #define PCH_UART_HAL_TRIGGER224 (PCH_UART_FCR_RFTL224)
  161. #define PCH_UART_HAL_TRIGGER16 (PCH_UART_FCR_RFTL16)
  162. #define PCH_UART_HAL_TRIGGER32 (PCH_UART_FCR_RFTL32)
  163. #define PCH_UART_HAL_TRIGGER56 (PCH_UART_FCR_RFTL56)
  164. #define PCH_UART_HAL_TRIGGER4 (PCH_UART_FCR_RFTL4)
  165. #define PCH_UART_HAL_TRIGGER8 (PCH_UART_FCR_RFTL8)
  166. #define PCH_UART_HAL_TRIGGER14 (PCH_UART_FCR_RFTL14)
  167. #define PCH_UART_HAL_TRIGGER_L (PCH_UART_FCR_RFTL64)
  168. #define PCH_UART_HAL_TRIGGER_M (PCH_UART_FCR_RFTL128)
  169. #define PCH_UART_HAL_TRIGGER_H (PCH_UART_FCR_RFTL224)
  170. #define PCH_UART_HAL_RX_INT (PCH_UART_IER_ERBFI)
  171. #define PCH_UART_HAL_TX_INT (PCH_UART_IER_ETBEI)
  172. #define PCH_UART_HAL_RX_ERR_INT (PCH_UART_IER_ELSI)
  173. #define PCH_UART_HAL_MS_INT (PCH_UART_IER_EDSSI)
  174. #define PCH_UART_HAL_ALL_INT (PCH_UART_IER_MASK)
  175. #define PCH_UART_HAL_DTR (PCH_UART_MCR_DTR)
  176. #define PCH_UART_HAL_RTS (PCH_UART_MCR_RTS)
  177. #define PCH_UART_HAL_OUT (PCH_UART_MCR_OUT)
  178. #define PCH_UART_HAL_LOOP (PCH_UART_MCR_LOOP)
  179. #define PCH_UART_HAL_AFE (PCH_UART_MCR_AFE)
  180. #define PCI_VENDOR_ID_ROHM 0x10DB
  181. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  182. #define DEFAULT_UARTCLK 1843200 /* 1.8432 MHz */
  183. #define CMITC_UARTCLK 192000000 /* 192.0000 MHz */
  184. #define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */
  185. #define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */
  186. struct pch_uart_buffer {
  187. unsigned char *buf;
  188. int size;
  189. };
  190. struct eg20t_port {
  191. struct uart_port port;
  192. int port_type;
  193. void __iomem *membase;
  194. resource_size_t mapbase;
  195. unsigned int iobase;
  196. struct pci_dev *pdev;
  197. int fifo_size;
  198. int uartclk;
  199. int start_tx;
  200. int start_rx;
  201. int tx_empty;
  202. int int_dis_flag;
  203. int trigger;
  204. int trigger_level;
  205. struct pch_uart_buffer rxbuf;
  206. unsigned int dmsr;
  207. unsigned int fcr;
  208. unsigned int mcr;
  209. unsigned int use_dma;
  210. struct dma_async_tx_descriptor *desc_tx;
  211. struct dma_async_tx_descriptor *desc_rx;
  212. struct pch_dma_slave param_tx;
  213. struct pch_dma_slave param_rx;
  214. struct dma_chan *chan_tx;
  215. struct dma_chan *chan_rx;
  216. struct scatterlist *sg_tx_p;
  217. int nent;
  218. struct scatterlist sg_rx;
  219. int tx_dma_use;
  220. void *rx_buf_virt;
  221. dma_addr_t rx_buf_dma;
  222. struct dentry *debugfs;
  223. };
  224. /**
  225. * struct pch_uart_driver_data - private data structure for UART-DMA
  226. * @port_type: The number of DMA channel
  227. * @line_no: UART port line number (0, 1, 2...)
  228. */
  229. struct pch_uart_driver_data {
  230. int port_type;
  231. int line_no;
  232. };
  233. enum pch_uart_num_t {
  234. pch_et20t_uart0 = 0,
  235. pch_et20t_uart1,
  236. pch_et20t_uart2,
  237. pch_et20t_uart3,
  238. pch_ml7213_uart0,
  239. pch_ml7213_uart1,
  240. pch_ml7213_uart2,
  241. pch_ml7223_uart0,
  242. pch_ml7223_uart1,
  243. pch_ml7831_uart0,
  244. pch_ml7831_uart1,
  245. };
  246. static struct pch_uart_driver_data drv_dat[] = {
  247. [pch_et20t_uart0] = {PCH_UART_8LINE, 0},
  248. [pch_et20t_uart1] = {PCH_UART_2LINE, 1},
  249. [pch_et20t_uart2] = {PCH_UART_2LINE, 2},
  250. [pch_et20t_uart3] = {PCH_UART_2LINE, 3},
  251. [pch_ml7213_uart0] = {PCH_UART_8LINE, 0},
  252. [pch_ml7213_uart1] = {PCH_UART_2LINE, 1},
  253. [pch_ml7213_uart2] = {PCH_UART_2LINE, 2},
  254. [pch_ml7223_uart0] = {PCH_UART_8LINE, 0},
  255. [pch_ml7223_uart1] = {PCH_UART_2LINE, 1},
  256. [pch_ml7831_uart0] = {PCH_UART_8LINE, 0},
  257. [pch_ml7831_uart1] = {PCH_UART_2LINE, 1},
  258. };
  259. #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
  260. static struct eg20t_port *pch_uart_ports[PCH_UART_NR];
  261. #endif
  262. static unsigned int default_baud = 9600;
  263. static unsigned int user_uartclk = 0;
  264. static const int trigger_level_256[4] = { 1, 64, 128, 224 };
  265. static const int trigger_level_64[4] = { 1, 16, 32, 56 };
  266. static const int trigger_level_16[4] = { 1, 4, 8, 14 };
  267. static const int trigger_level_1[4] = { 1, 1, 1, 1 };
  268. #ifdef CONFIG_DEBUG_FS
  269. #define PCH_REGS_BUFSIZE 1024
  270. static ssize_t port_show_regs(struct file *file, char __user *user_buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct eg20t_port *priv = file->private_data;
  274. char *buf;
  275. u32 len = 0;
  276. ssize_t ret;
  277. unsigned char lcr;
  278. buf = kzalloc(PCH_REGS_BUFSIZE, GFP_KERNEL);
  279. if (!buf)
  280. return 0;
  281. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  282. "PCH EG20T port[%d] regs:\n", priv->port.line);
  283. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  284. "=================================\n");
  285. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  286. "IER: \t0x%02x\n", ioread8(priv->membase + UART_IER));
  287. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  288. "IIR: \t0x%02x\n", ioread8(priv->membase + UART_IIR));
  289. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  290. "LCR: \t0x%02x\n", ioread8(priv->membase + UART_LCR));
  291. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  292. "MCR: \t0x%02x\n", ioread8(priv->membase + UART_MCR));
  293. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  294. "LSR: \t0x%02x\n", ioread8(priv->membase + UART_LSR));
  295. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  296. "MSR: \t0x%02x\n", ioread8(priv->membase + UART_MSR));
  297. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  298. "BRCSR: \t0x%02x\n",
  299. ioread8(priv->membase + PCH_UART_BRCSR));
  300. lcr = ioread8(priv->membase + UART_LCR);
  301. iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
  302. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  303. "DLL: \t0x%02x\n", ioread8(priv->membase + UART_DLL));
  304. len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
  305. "DLM: \t0x%02x\n", ioread8(priv->membase + UART_DLM));
  306. iowrite8(lcr, priv->membase + UART_LCR);
  307. if (len > PCH_REGS_BUFSIZE)
  308. len = PCH_REGS_BUFSIZE;
  309. ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  310. kfree(buf);
  311. return ret;
  312. }
  313. static const struct file_operations port_regs_ops = {
  314. .owner = THIS_MODULE,
  315. .open = simple_open,
  316. .read = port_show_regs,
  317. .llseek = default_llseek,
  318. };
  319. #endif /* CONFIG_DEBUG_FS */
  320. /* Return UART clock, checking for board specific clocks. */
  321. static int pch_uart_get_uartclk(void)
  322. {
  323. const char *cmp;
  324. if (user_uartclk)
  325. return user_uartclk;
  326. cmp = dmi_get_system_info(DMI_BOARD_NAME);
  327. if (cmp && strstr(cmp, "CM-iTC"))
  328. return CMITC_UARTCLK;
  329. cmp = dmi_get_system_info(DMI_BIOS_VERSION);
  330. if (cmp && strnstr(cmp, "FRI2", 4))
  331. return FRI2_64_UARTCLK;
  332. cmp = dmi_get_system_info(DMI_PRODUCT_NAME);
  333. if (cmp && strstr(cmp, "Fish River Island II"))
  334. return FRI2_48_UARTCLK;
  335. return DEFAULT_UARTCLK;
  336. }
  337. static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv,
  338. unsigned int flag)
  339. {
  340. u8 ier = ioread8(priv->membase + UART_IER);
  341. ier |= flag & PCH_UART_IER_MASK;
  342. iowrite8(ier, priv->membase + UART_IER);
  343. }
  344. static void pch_uart_hal_disable_interrupt(struct eg20t_port *priv,
  345. unsigned int flag)
  346. {
  347. u8 ier = ioread8(priv->membase + UART_IER);
  348. ier &= ~(flag & PCH_UART_IER_MASK);
  349. iowrite8(ier, priv->membase + UART_IER);
  350. }
  351. static int pch_uart_hal_set_line(struct eg20t_port *priv, int baud,
  352. unsigned int parity, unsigned int bits,
  353. unsigned int stb)
  354. {
  355. unsigned int dll, dlm, lcr;
  356. int div;
  357. div = DIV_ROUND_CLOSEST(priv->uartclk / 16, baud);
  358. if (div < 0 || USHRT_MAX <= div) {
  359. dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div);
  360. return -EINVAL;
  361. }
  362. dll = (unsigned int)div & 0x00FFU;
  363. dlm = ((unsigned int)div >> 8) & 0x00FFU;
  364. if (parity & ~(PCH_UART_LCR_PEN | PCH_UART_LCR_EPS | PCH_UART_LCR_SP)) {
  365. dev_err(priv->port.dev, "Invalid parity(0x%x)\n", parity);
  366. return -EINVAL;
  367. }
  368. if (bits & ~PCH_UART_LCR_WLS) {
  369. dev_err(priv->port.dev, "Invalid bits(0x%x)\n", bits);
  370. return -EINVAL;
  371. }
  372. if (stb & ~PCH_UART_LCR_STB) {
  373. dev_err(priv->port.dev, "Invalid STB(0x%x)\n", stb);
  374. return -EINVAL;
  375. }
  376. lcr = parity;
  377. lcr |= bits;
  378. lcr |= stb;
  379. dev_dbg(priv->port.dev, "%s:baud = %d, div = %04x, lcr = %02x (%lu)\n",
  380. __func__, baud, div, lcr, jiffies);
  381. iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
  382. iowrite8(dll, priv->membase + PCH_UART_DLL);
  383. iowrite8(dlm, priv->membase + PCH_UART_DLM);
  384. iowrite8(lcr, priv->membase + UART_LCR);
  385. return 0;
  386. }
  387. static int pch_uart_hal_fifo_reset(struct eg20t_port *priv,
  388. unsigned int flag)
  389. {
  390. if (flag & ~(PCH_UART_FCR_TFR | PCH_UART_FCR_RFR)) {
  391. dev_err(priv->port.dev, "%s:Invalid flag(0x%x)\n",
  392. __func__, flag);
  393. return -EINVAL;
  394. }
  395. iowrite8(PCH_UART_FCR_FIFOE | priv->fcr, priv->membase + UART_FCR);
  396. iowrite8(PCH_UART_FCR_FIFOE | priv->fcr | flag,
  397. priv->membase + UART_FCR);
  398. iowrite8(priv->fcr, priv->membase + UART_FCR);
  399. return 0;
  400. }
  401. static int pch_uart_hal_set_fifo(struct eg20t_port *priv,
  402. unsigned int dmamode,
  403. unsigned int fifo_size, unsigned int trigger)
  404. {
  405. u8 fcr;
  406. if (dmamode & ~PCH_UART_FCR_DMS) {
  407. dev_err(priv->port.dev, "%s:Invalid DMA Mode(0x%x)\n",
  408. __func__, dmamode);
  409. return -EINVAL;
  410. }
  411. if (fifo_size & ~(PCH_UART_FCR_FIFOE | PCH_UART_FCR_FIFO256)) {
  412. dev_err(priv->port.dev, "%s:Invalid FIFO SIZE(0x%x)\n",
  413. __func__, fifo_size);
  414. return -EINVAL;
  415. }
  416. if (trigger & ~PCH_UART_FCR_RFTL) {
  417. dev_err(priv->port.dev, "%s:Invalid TRIGGER(0x%x)\n",
  418. __func__, trigger);
  419. return -EINVAL;
  420. }
  421. switch (priv->fifo_size) {
  422. case 256:
  423. priv->trigger_level =
  424. trigger_level_256[trigger >> PCH_UART_FCR_RFTL_SHIFT];
  425. break;
  426. case 64:
  427. priv->trigger_level =
  428. trigger_level_64[trigger >> PCH_UART_FCR_RFTL_SHIFT];
  429. break;
  430. case 16:
  431. priv->trigger_level =
  432. trigger_level_16[trigger >> PCH_UART_FCR_RFTL_SHIFT];
  433. break;
  434. default:
  435. priv->trigger_level =
  436. trigger_level_1[trigger >> PCH_UART_FCR_RFTL_SHIFT];
  437. break;
  438. }
  439. fcr =
  440. dmamode | fifo_size | trigger | PCH_UART_FCR_RFR | PCH_UART_FCR_TFR;
  441. iowrite8(PCH_UART_FCR_FIFOE, priv->membase + UART_FCR);
  442. iowrite8(PCH_UART_FCR_FIFOE | PCH_UART_FCR_RFR | PCH_UART_FCR_TFR,
  443. priv->membase + UART_FCR);
  444. iowrite8(fcr, priv->membase + UART_FCR);
  445. priv->fcr = fcr;
  446. return 0;
  447. }
  448. static u8 pch_uart_hal_get_modem(struct eg20t_port *priv)
  449. {
  450. unsigned int msr = ioread8(priv->membase + UART_MSR);
  451. priv->dmsr = msr & PCH_UART_MSR_DELTA;
  452. return (u8)msr;
  453. }
  454. static void pch_uart_hal_write(struct eg20t_port *priv,
  455. const unsigned char *buf, int tx_size)
  456. {
  457. int i;
  458. unsigned int thr;
  459. for (i = 0; i < tx_size;) {
  460. thr = buf[i++];
  461. iowrite8(thr, priv->membase + PCH_UART_THR);
  462. }
  463. }
  464. static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf,
  465. int rx_size)
  466. {
  467. int i;
  468. u8 rbr, lsr;
  469. lsr = ioread8(priv->membase + UART_LSR);
  470. for (i = 0, lsr = ioread8(priv->membase + UART_LSR);
  471. i < rx_size && lsr & UART_LSR_DR;
  472. lsr = ioread8(priv->membase + UART_LSR)) {
  473. rbr = ioread8(priv->membase + PCH_UART_RBR);
  474. buf[i++] = rbr;
  475. }
  476. return i;
  477. }
  478. static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv)
  479. {
  480. return ioread8(priv->membase + UART_IIR) &\
  481. (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP);
  482. }
  483. static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv)
  484. {
  485. return ioread8(priv->membase + UART_LSR);
  486. }
  487. static void pch_uart_hal_set_break(struct eg20t_port *priv, int on)
  488. {
  489. unsigned int lcr;
  490. lcr = ioread8(priv->membase + UART_LCR);
  491. if (on)
  492. lcr |= PCH_UART_LCR_SB;
  493. else
  494. lcr &= ~PCH_UART_LCR_SB;
  495. iowrite8(lcr, priv->membase + UART_LCR);
  496. }
  497. static int push_rx(struct eg20t_port *priv, const unsigned char *buf,
  498. int size)
  499. {
  500. struct uart_port *port;
  501. struct tty_struct *tty;
  502. port = &priv->port;
  503. tty = tty_port_tty_get(&port->state->port);
  504. if (!tty) {
  505. dev_dbg(priv->port.dev, "%s:tty is busy now", __func__);
  506. return -EBUSY;
  507. }
  508. tty_insert_flip_string(tty, buf, size);
  509. tty_flip_buffer_push(tty);
  510. tty_kref_put(tty);
  511. return 0;
  512. }
  513. static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf)
  514. {
  515. int ret = 0;
  516. struct uart_port *port = &priv->port;
  517. if (port->x_char) {
  518. dev_dbg(priv->port.dev, "%s:X character send %02x (%lu)\n",
  519. __func__, port->x_char, jiffies);
  520. buf[0] = port->x_char;
  521. port->x_char = 0;
  522. ret = 1;
  523. }
  524. return ret;
  525. }
  526. static int dma_push_rx(struct eg20t_port *priv, int size)
  527. {
  528. struct tty_struct *tty;
  529. int room;
  530. struct uart_port *port = &priv->port;
  531. port = &priv->port;
  532. tty = tty_port_tty_get(&port->state->port);
  533. if (!tty) {
  534. dev_dbg(priv->port.dev, "%s:tty is busy now", __func__);
  535. return 0;
  536. }
  537. room = tty_buffer_request_room(tty, size);
  538. if (room < size)
  539. dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
  540. size - room);
  541. if (!room)
  542. return room;
  543. tty_insert_flip_string(tty, sg_virt(&priv->sg_rx), size);
  544. port->icount.rx += room;
  545. tty_kref_put(tty);
  546. return room;
  547. }
  548. static void pch_free_dma(struct uart_port *port)
  549. {
  550. struct eg20t_port *priv;
  551. priv = container_of(port, struct eg20t_port, port);
  552. if (priv->chan_tx) {
  553. dma_release_channel(priv->chan_tx);
  554. priv->chan_tx = NULL;
  555. }
  556. if (priv->chan_rx) {
  557. dma_release_channel(priv->chan_rx);
  558. priv->chan_rx = NULL;
  559. }
  560. if (sg_dma_address(&priv->sg_rx))
  561. dma_free_coherent(port->dev, port->fifosize,
  562. sg_virt(&priv->sg_rx),
  563. sg_dma_address(&priv->sg_rx));
  564. return;
  565. }
  566. static bool filter(struct dma_chan *chan, void *slave)
  567. {
  568. struct pch_dma_slave *param = slave;
  569. if ((chan->chan_id == param->chan_id) && (param->dma_dev ==
  570. chan->device->dev)) {
  571. chan->private = param;
  572. return true;
  573. } else {
  574. return false;
  575. }
  576. }
  577. static void pch_request_dma(struct uart_port *port)
  578. {
  579. dma_cap_mask_t mask;
  580. struct dma_chan *chan;
  581. struct pci_dev *dma_dev;
  582. struct pch_dma_slave *param;
  583. struct eg20t_port *priv =
  584. container_of(port, struct eg20t_port, port);
  585. dma_cap_zero(mask);
  586. dma_cap_set(DMA_SLAVE, mask);
  587. dma_dev = pci_get_bus_and_slot(priv->pdev->bus->number,
  588. PCI_DEVFN(0xa, 0)); /* Get DMA's dev
  589. information */
  590. /* Set Tx DMA */
  591. param = &priv->param_tx;
  592. param->dma_dev = &dma_dev->dev;
  593. param->chan_id = priv->port.line * 2; /* Tx = 0, 2, 4, ... */
  594. param->tx_reg = port->mapbase + UART_TX;
  595. chan = dma_request_channel(mask, filter, param);
  596. if (!chan) {
  597. dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Tx)\n",
  598. __func__);
  599. return;
  600. }
  601. priv->chan_tx = chan;
  602. /* Set Rx DMA */
  603. param = &priv->param_rx;
  604. param->dma_dev = &dma_dev->dev;
  605. param->chan_id = priv->port.line * 2 + 1; /* Rx = Tx + 1 */
  606. param->rx_reg = port->mapbase + UART_RX;
  607. chan = dma_request_channel(mask, filter, param);
  608. if (!chan) {
  609. dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n",
  610. __func__);
  611. dma_release_channel(priv->chan_tx);
  612. priv->chan_tx = NULL;
  613. return;
  614. }
  615. /* Get Consistent memory for DMA */
  616. priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
  617. &priv->rx_buf_dma, GFP_KERNEL);
  618. priv->chan_rx = chan;
  619. }
  620. static void pch_dma_rx_complete(void *arg)
  621. {
  622. struct eg20t_port *priv = arg;
  623. struct uart_port *port = &priv->port;
  624. struct tty_struct *tty = tty_port_tty_get(&port->state->port);
  625. int count;
  626. if (!tty) {
  627. dev_dbg(priv->port.dev, "%s:tty is busy now", __func__);
  628. return;
  629. }
  630. dma_sync_sg_for_cpu(port->dev, &priv->sg_rx, 1, DMA_FROM_DEVICE);
  631. count = dma_push_rx(priv, priv->trigger_level);
  632. if (count)
  633. tty_flip_buffer_push(tty);
  634. tty_kref_put(tty);
  635. async_tx_ack(priv->desc_rx);
  636. pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT);
  637. }
  638. static void pch_dma_tx_complete(void *arg)
  639. {
  640. struct eg20t_port *priv = arg;
  641. struct uart_port *port = &priv->port;
  642. struct circ_buf *xmit = &port->state->xmit;
  643. struct scatterlist *sg = priv->sg_tx_p;
  644. int i;
  645. for (i = 0; i < priv->nent; i++, sg++) {
  646. xmit->tail += sg_dma_len(sg);
  647. port->icount.tx += sg_dma_len(sg);
  648. }
  649. xmit->tail &= UART_XMIT_SIZE - 1;
  650. async_tx_ack(priv->desc_tx);
  651. dma_unmap_sg(port->dev, sg, priv->nent, DMA_TO_DEVICE);
  652. priv->tx_dma_use = 0;
  653. priv->nent = 0;
  654. kfree(priv->sg_tx_p);
  655. pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
  656. }
  657. static int pop_tx(struct eg20t_port *priv, int size)
  658. {
  659. int count = 0;
  660. struct uart_port *port = &priv->port;
  661. struct circ_buf *xmit = &port->state->xmit;
  662. if (uart_tx_stopped(port) || uart_circ_empty(xmit) || count >= size)
  663. goto pop_tx_end;
  664. do {
  665. int cnt_to_end =
  666. CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
  667. int sz = min(size - count, cnt_to_end);
  668. pch_uart_hal_write(priv, &xmit->buf[xmit->tail], sz);
  669. xmit->tail = (xmit->tail + sz) & (UART_XMIT_SIZE - 1);
  670. count += sz;
  671. } while (!uart_circ_empty(xmit) && count < size);
  672. pop_tx_end:
  673. dev_dbg(priv->port.dev, "%d characters. Remained %d characters.(%lu)\n",
  674. count, size - count, jiffies);
  675. return count;
  676. }
  677. static int handle_rx_to(struct eg20t_port *priv)
  678. {
  679. struct pch_uart_buffer *buf;
  680. int rx_size;
  681. int ret;
  682. if (!priv->start_rx) {
  683. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
  684. return 0;
  685. }
  686. buf = &priv->rxbuf;
  687. do {
  688. rx_size = pch_uart_hal_read(priv, buf->buf, buf->size);
  689. ret = push_rx(priv, buf->buf, rx_size);
  690. if (ret)
  691. return 0;
  692. } while (rx_size == buf->size);
  693. return PCH_UART_HANDLED_RX_INT;
  694. }
  695. static int handle_rx(struct eg20t_port *priv)
  696. {
  697. return handle_rx_to(priv);
  698. }
  699. static int dma_handle_rx(struct eg20t_port *priv)
  700. {
  701. struct uart_port *port = &priv->port;
  702. struct dma_async_tx_descriptor *desc;
  703. struct scatterlist *sg;
  704. priv = container_of(port, struct eg20t_port, port);
  705. sg = &priv->sg_rx;
  706. sg_init_table(&priv->sg_rx, 1); /* Initialize SG table */
  707. sg_dma_len(sg) = priv->trigger_level;
  708. sg_set_page(&priv->sg_rx, virt_to_page(priv->rx_buf_virt),
  709. sg_dma_len(sg), (unsigned long)priv->rx_buf_virt &
  710. ~PAGE_MASK);
  711. sg_dma_address(sg) = priv->rx_buf_dma;
  712. desc = dmaengine_prep_slave_sg(priv->chan_rx,
  713. sg, 1, DMA_DEV_TO_MEM,
  714. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  715. if (!desc)
  716. return 0;
  717. priv->desc_rx = desc;
  718. desc->callback = pch_dma_rx_complete;
  719. desc->callback_param = priv;
  720. desc->tx_submit(desc);
  721. dma_async_issue_pending(priv->chan_rx);
  722. return PCH_UART_HANDLED_RX_INT;
  723. }
  724. static unsigned int handle_tx(struct eg20t_port *priv)
  725. {
  726. struct uart_port *port = &priv->port;
  727. struct circ_buf *xmit = &port->state->xmit;
  728. int fifo_size;
  729. int tx_size;
  730. int size;
  731. int tx_empty;
  732. if (!priv->start_tx) {
  733. dev_info(priv->port.dev, "%s:Tx isn't started. (%lu)\n",
  734. __func__, jiffies);
  735. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
  736. priv->tx_empty = 1;
  737. return 0;
  738. }
  739. fifo_size = max(priv->fifo_size, 1);
  740. tx_empty = 1;
  741. if (pop_tx_x(priv, xmit->buf)) {
  742. pch_uart_hal_write(priv, xmit->buf, 1);
  743. port->icount.tx++;
  744. tx_empty = 0;
  745. fifo_size--;
  746. }
  747. size = min(xmit->head - xmit->tail, fifo_size);
  748. if (size < 0)
  749. size = fifo_size;
  750. tx_size = pop_tx(priv, size);
  751. if (tx_size > 0) {
  752. port->icount.tx += tx_size;
  753. tx_empty = 0;
  754. }
  755. priv->tx_empty = tx_empty;
  756. if (tx_empty) {
  757. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
  758. uart_write_wakeup(port);
  759. }
  760. return PCH_UART_HANDLED_TX_INT;
  761. }
  762. static unsigned int dma_handle_tx(struct eg20t_port *priv)
  763. {
  764. struct uart_port *port = &priv->port;
  765. struct circ_buf *xmit = &port->state->xmit;
  766. struct scatterlist *sg;
  767. int nent;
  768. int fifo_size;
  769. int tx_empty;
  770. struct dma_async_tx_descriptor *desc;
  771. int num;
  772. int i;
  773. int bytes;
  774. int size;
  775. int rem;
  776. if (!priv->start_tx) {
  777. dev_info(priv->port.dev, "%s:Tx isn't started. (%lu)\n",
  778. __func__, jiffies);
  779. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
  780. priv->tx_empty = 1;
  781. return 0;
  782. }
  783. if (priv->tx_dma_use) {
  784. dev_dbg(priv->port.dev, "%s:Tx is not completed. (%lu)\n",
  785. __func__, jiffies);
  786. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
  787. priv->tx_empty = 1;
  788. return 0;
  789. }
  790. fifo_size = max(priv->fifo_size, 1);
  791. tx_empty = 1;
  792. if (pop_tx_x(priv, xmit->buf)) {
  793. pch_uart_hal_write(priv, xmit->buf, 1);
  794. port->icount.tx++;
  795. tx_empty = 0;
  796. fifo_size--;
  797. }
  798. bytes = min((int)CIRC_CNT(xmit->head, xmit->tail,
  799. UART_XMIT_SIZE), CIRC_CNT_TO_END(xmit->head,
  800. xmit->tail, UART_XMIT_SIZE));
  801. if (!bytes) {
  802. dev_dbg(priv->port.dev, "%s 0 bytes return\n", __func__);
  803. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
  804. uart_write_wakeup(port);
  805. return 0;
  806. }
  807. if (bytes > fifo_size) {
  808. num = bytes / fifo_size + 1;
  809. size = fifo_size;
  810. rem = bytes % fifo_size;
  811. } else {
  812. num = 1;
  813. size = bytes;
  814. rem = bytes;
  815. }
  816. dev_dbg(priv->port.dev, "%s num=%d size=%d rem=%d\n",
  817. __func__, num, size, rem);
  818. priv->tx_dma_use = 1;
  819. priv->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
  820. sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
  821. sg = priv->sg_tx_p;
  822. for (i = 0; i < num; i++, sg++) {
  823. if (i == (num - 1))
  824. sg_set_page(sg, virt_to_page(xmit->buf),
  825. rem, fifo_size * i);
  826. else
  827. sg_set_page(sg, virt_to_page(xmit->buf),
  828. size, fifo_size * i);
  829. }
  830. sg = priv->sg_tx_p;
  831. nent = dma_map_sg(port->dev, sg, num, DMA_TO_DEVICE);
  832. if (!nent) {
  833. dev_err(priv->port.dev, "%s:dma_map_sg Failed\n", __func__);
  834. return 0;
  835. }
  836. priv->nent = nent;
  837. for (i = 0; i < nent; i++, sg++) {
  838. sg->offset = (xmit->tail & (UART_XMIT_SIZE - 1)) +
  839. fifo_size * i;
  840. sg_dma_address(sg) = (sg_dma_address(sg) &
  841. ~(UART_XMIT_SIZE - 1)) + sg->offset;
  842. if (i == (nent - 1))
  843. sg_dma_len(sg) = rem;
  844. else
  845. sg_dma_len(sg) = size;
  846. }
  847. desc = dmaengine_prep_slave_sg(priv->chan_tx,
  848. priv->sg_tx_p, nent, DMA_MEM_TO_DEV,
  849. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  850. if (!desc) {
  851. dev_err(priv->port.dev, "%s:device_prep_slave_sg Failed\n",
  852. __func__);
  853. return 0;
  854. }
  855. dma_sync_sg_for_device(port->dev, priv->sg_tx_p, nent, DMA_TO_DEVICE);
  856. priv->desc_tx = desc;
  857. desc->callback = pch_dma_tx_complete;
  858. desc->callback_param = priv;
  859. desc->tx_submit(desc);
  860. dma_async_issue_pending(priv->chan_tx);
  861. return PCH_UART_HANDLED_TX_INT;
  862. }
  863. static void pch_uart_err_ir(struct eg20t_port *priv, unsigned int lsr)
  864. {
  865. u8 fcr = ioread8(priv->membase + UART_FCR);
  866. /* Reset FIFO */
  867. fcr |= UART_FCR_CLEAR_RCVR;
  868. iowrite8(fcr, priv->membase + UART_FCR);
  869. if (lsr & PCH_UART_LSR_ERR)
  870. dev_err(&priv->pdev->dev, "Error data in FIFO\n");
  871. if (lsr & UART_LSR_FE)
  872. dev_err(&priv->pdev->dev, "Framing Error\n");
  873. if (lsr & UART_LSR_PE)
  874. dev_err(&priv->pdev->dev, "Parity Error\n");
  875. if (lsr & UART_LSR_OE)
  876. dev_err(&priv->pdev->dev, "Overrun Error\n");
  877. }
  878. static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
  879. {
  880. struct eg20t_port *priv = dev_id;
  881. unsigned int handled;
  882. u8 lsr;
  883. int ret = 0;
  884. unsigned char iid;
  885. unsigned long flags;
  886. int next = 1;
  887. u8 msr;
  888. spin_lock_irqsave(&priv->port.lock, flags);
  889. handled = 0;
  890. while (next) {
  891. iid = pch_uart_hal_get_iid(priv);
  892. if (iid & PCH_UART_IIR_IP) /* No Interrupt */
  893. break;
  894. switch (iid) {
  895. case PCH_UART_IID_RLS: /* Receiver Line Status */
  896. lsr = pch_uart_hal_get_line_status(priv);
  897. if (lsr & (PCH_UART_LSR_ERR | UART_LSR_FE |
  898. UART_LSR_PE | UART_LSR_OE)) {
  899. pch_uart_err_ir(priv, lsr);
  900. ret = PCH_UART_HANDLED_RX_ERR_INT;
  901. }
  902. break;
  903. case PCH_UART_IID_RDR: /* Received Data Ready */
  904. if (priv->use_dma) {
  905. pch_uart_hal_disable_interrupt(priv,
  906. PCH_UART_HAL_RX_INT);
  907. ret = dma_handle_rx(priv);
  908. if (!ret)
  909. pch_uart_hal_enable_interrupt(priv,
  910. PCH_UART_HAL_RX_INT);
  911. } else {
  912. ret = handle_rx(priv);
  913. }
  914. break;
  915. case PCH_UART_IID_RDR_TO: /* Received Data Ready
  916. (FIFO Timeout) */
  917. ret = handle_rx_to(priv);
  918. break;
  919. case PCH_UART_IID_THRE: /* Transmitter Holding Register
  920. Empty */
  921. if (priv->use_dma)
  922. ret = dma_handle_tx(priv);
  923. else
  924. ret = handle_tx(priv);
  925. break;
  926. case PCH_UART_IID_MS: /* Modem Status */
  927. msr = pch_uart_hal_get_modem(priv);
  928. next = 0; /* MS ir prioirty is the lowest. So, MS ir
  929. means final interrupt */
  930. if ((msr & UART_MSR_ANY_DELTA) == 0)
  931. break;
  932. ret |= PCH_UART_HANDLED_MS_INT;
  933. break;
  934. default: /* Never junp to this label */
  935. dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__,
  936. iid, jiffies);
  937. ret = -1;
  938. next = 0;
  939. break;
  940. }
  941. handled |= (unsigned int)ret;
  942. }
  943. if (handled == 0 && iid <= 1) {
  944. if (priv->int_dis_flag)
  945. priv->int_dis_flag = 0;
  946. }
  947. spin_unlock_irqrestore(&priv->port.lock, flags);
  948. return IRQ_RETVAL(handled);
  949. }
  950. /* This function tests whether the transmitter fifo and shifter for the port
  951. described by 'port' is empty. */
  952. static unsigned int pch_uart_tx_empty(struct uart_port *port)
  953. {
  954. struct eg20t_port *priv;
  955. priv = container_of(port, struct eg20t_port, port);
  956. if (priv->tx_empty)
  957. return TIOCSER_TEMT;
  958. else
  959. return 0;
  960. }
  961. /* Returns the current state of modem control inputs. */
  962. static unsigned int pch_uart_get_mctrl(struct uart_port *port)
  963. {
  964. struct eg20t_port *priv;
  965. u8 modem;
  966. unsigned int ret = 0;
  967. priv = container_of(port, struct eg20t_port, port);
  968. modem = pch_uart_hal_get_modem(priv);
  969. if (modem & UART_MSR_DCD)
  970. ret |= TIOCM_CAR;
  971. if (modem & UART_MSR_RI)
  972. ret |= TIOCM_RNG;
  973. if (modem & UART_MSR_DSR)
  974. ret |= TIOCM_DSR;
  975. if (modem & UART_MSR_CTS)
  976. ret |= TIOCM_CTS;
  977. return ret;
  978. }
  979. static void pch_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
  980. {
  981. u32 mcr = 0;
  982. struct eg20t_port *priv = container_of(port, struct eg20t_port, port);
  983. if (mctrl & TIOCM_DTR)
  984. mcr |= UART_MCR_DTR;
  985. if (mctrl & TIOCM_RTS)
  986. mcr |= UART_MCR_RTS;
  987. if (mctrl & TIOCM_LOOP)
  988. mcr |= UART_MCR_LOOP;
  989. if (priv->mcr & UART_MCR_AFE)
  990. mcr |= UART_MCR_AFE;
  991. if (mctrl)
  992. iowrite8(mcr, priv->membase + UART_MCR);
  993. }
  994. static void pch_uart_stop_tx(struct uart_port *port)
  995. {
  996. struct eg20t_port *priv;
  997. priv = container_of(port, struct eg20t_port, port);
  998. priv->start_tx = 0;
  999. priv->tx_dma_use = 0;
  1000. }
  1001. static void pch_uart_start_tx(struct uart_port *port)
  1002. {
  1003. struct eg20t_port *priv;
  1004. priv = container_of(port, struct eg20t_port, port);
  1005. if (priv->use_dma) {
  1006. if (priv->tx_dma_use) {
  1007. dev_dbg(priv->port.dev, "%s : Tx DMA is NOT empty.\n",
  1008. __func__);
  1009. return;
  1010. }
  1011. }
  1012. priv->start_tx = 1;
  1013. pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
  1014. }
  1015. static void pch_uart_stop_rx(struct uart_port *port)
  1016. {
  1017. struct eg20t_port *priv;
  1018. priv = container_of(port, struct eg20t_port, port);
  1019. priv->start_rx = 0;
  1020. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
  1021. priv->int_dis_flag = 1;
  1022. }
  1023. /* Enable the modem status interrupts. */
  1024. static void pch_uart_enable_ms(struct uart_port *port)
  1025. {
  1026. struct eg20t_port *priv;
  1027. priv = container_of(port, struct eg20t_port, port);
  1028. pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_MS_INT);
  1029. }
  1030. /* Control the transmission of a break signal. */
  1031. static void pch_uart_break_ctl(struct uart_port *port, int ctl)
  1032. {
  1033. struct eg20t_port *priv;
  1034. unsigned long flags;
  1035. priv = container_of(port, struct eg20t_port, port);
  1036. spin_lock_irqsave(&port->lock, flags);
  1037. pch_uart_hal_set_break(priv, ctl);
  1038. spin_unlock_irqrestore(&port->lock, flags);
  1039. }
  1040. /* Grab any interrupt resources and initialise any low level driver state. */
  1041. static int pch_uart_startup(struct uart_port *port)
  1042. {
  1043. struct eg20t_port *priv;
  1044. int ret;
  1045. int fifo_size;
  1046. int trigger_level;
  1047. priv = container_of(port, struct eg20t_port, port);
  1048. priv->tx_empty = 1;
  1049. if (port->uartclk)
  1050. priv->uartclk = port->uartclk;
  1051. else
  1052. port->uartclk = priv->uartclk;
  1053. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
  1054. ret = pch_uart_hal_set_line(priv, default_baud,
  1055. PCH_UART_HAL_PARITY_NONE, PCH_UART_HAL_8BIT,
  1056. PCH_UART_HAL_STB1);
  1057. if (ret)
  1058. return ret;
  1059. switch (priv->fifo_size) {
  1060. case 256:
  1061. fifo_size = PCH_UART_HAL_FIFO256;
  1062. break;
  1063. case 64:
  1064. fifo_size = PCH_UART_HAL_FIFO64;
  1065. break;
  1066. case 16:
  1067. fifo_size = PCH_UART_HAL_FIFO16;
  1068. case 1:
  1069. default:
  1070. fifo_size = PCH_UART_HAL_FIFO_DIS;
  1071. break;
  1072. }
  1073. switch (priv->trigger) {
  1074. case PCH_UART_HAL_TRIGGER1:
  1075. trigger_level = 1;
  1076. break;
  1077. case PCH_UART_HAL_TRIGGER_L:
  1078. trigger_level = priv->fifo_size / 4;
  1079. break;
  1080. case PCH_UART_HAL_TRIGGER_M:
  1081. trigger_level = priv->fifo_size / 2;
  1082. break;
  1083. case PCH_UART_HAL_TRIGGER_H:
  1084. default:
  1085. trigger_level = priv->fifo_size - (priv->fifo_size / 8);
  1086. break;
  1087. }
  1088. priv->trigger_level = trigger_level;
  1089. ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
  1090. fifo_size, priv->trigger);
  1091. if (ret < 0)
  1092. return ret;
  1093. ret = request_irq(priv->port.irq, pch_uart_interrupt, IRQF_SHARED,
  1094. KBUILD_MODNAME, priv);
  1095. if (ret < 0)
  1096. return ret;
  1097. if (priv->use_dma)
  1098. pch_request_dma(port);
  1099. priv->start_rx = 1;
  1100. pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT);
  1101. uart_update_timeout(port, CS8, default_baud);
  1102. return 0;
  1103. }
  1104. static void pch_uart_shutdown(struct uart_port *port)
  1105. {
  1106. struct eg20t_port *priv;
  1107. int ret;
  1108. priv = container_of(port, struct eg20t_port, port);
  1109. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
  1110. pch_uart_hal_fifo_reset(priv, PCH_UART_HAL_CLR_ALL_FIFO);
  1111. ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
  1112. PCH_UART_HAL_FIFO_DIS, PCH_UART_HAL_TRIGGER1);
  1113. if (ret)
  1114. dev_err(priv->port.dev,
  1115. "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret);
  1116. pch_free_dma(port);
  1117. free_irq(priv->port.irq, priv);
  1118. }
  1119. /* Change the port parameters, including word length, parity, stop
  1120. *bits. Update read_status_mask and ignore_status_mask to indicate
  1121. *the types of events we are interested in receiving. */
  1122. static void pch_uart_set_termios(struct uart_port *port,
  1123. struct ktermios *termios, struct ktermios *old)
  1124. {
  1125. int baud;
  1126. int rtn;
  1127. unsigned int parity, bits, stb;
  1128. struct eg20t_port *priv;
  1129. unsigned long flags;
  1130. priv = container_of(port, struct eg20t_port, port);
  1131. switch (termios->c_cflag & CSIZE) {
  1132. case CS5:
  1133. bits = PCH_UART_HAL_5BIT;
  1134. break;
  1135. case CS6:
  1136. bits = PCH_UART_HAL_6BIT;
  1137. break;
  1138. case CS7:
  1139. bits = PCH_UART_HAL_7BIT;
  1140. break;
  1141. default: /* CS8 */
  1142. bits = PCH_UART_HAL_8BIT;
  1143. break;
  1144. }
  1145. if (termios->c_cflag & CSTOPB)
  1146. stb = PCH_UART_HAL_STB2;
  1147. else
  1148. stb = PCH_UART_HAL_STB1;
  1149. if (termios->c_cflag & PARENB) {
  1150. if (!(termios->c_cflag & PARODD))
  1151. parity = PCH_UART_HAL_PARITY_ODD;
  1152. else
  1153. parity = PCH_UART_HAL_PARITY_EVEN;
  1154. } else
  1155. parity = PCH_UART_HAL_PARITY_NONE;
  1156. /* Only UART0 has auto hardware flow function */
  1157. if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256))
  1158. priv->mcr |= UART_MCR_AFE;
  1159. else
  1160. priv->mcr &= ~UART_MCR_AFE;
  1161. termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */
  1162. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
  1163. spin_lock_irqsave(&port->lock, flags);
  1164. uart_update_timeout(port, termios->c_cflag, baud);
  1165. rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
  1166. if (rtn)
  1167. goto out;
  1168. pch_uart_set_mctrl(&priv->port, priv->port.mctrl);
  1169. /* Don't rewrite B0 */
  1170. if (tty_termios_baud_rate(termios))
  1171. tty_termios_encode_baud_rate(termios, baud, baud);
  1172. out:
  1173. spin_unlock_irqrestore(&port->lock, flags);
  1174. }
  1175. static const char *pch_uart_type(struct uart_port *port)
  1176. {
  1177. return KBUILD_MODNAME;
  1178. }
  1179. static void pch_uart_release_port(struct uart_port *port)
  1180. {
  1181. struct eg20t_port *priv;
  1182. priv = container_of(port, struct eg20t_port, port);
  1183. pci_iounmap(priv->pdev, priv->membase);
  1184. pci_release_regions(priv->pdev);
  1185. }
  1186. static int pch_uart_request_port(struct uart_port *port)
  1187. {
  1188. struct eg20t_port *priv;
  1189. int ret;
  1190. void __iomem *membase;
  1191. priv = container_of(port, struct eg20t_port, port);
  1192. ret = pci_request_regions(priv->pdev, KBUILD_MODNAME);
  1193. if (ret < 0)
  1194. return -EBUSY;
  1195. membase = pci_iomap(priv->pdev, 1, 0);
  1196. if (!membase) {
  1197. pci_release_regions(priv->pdev);
  1198. return -EBUSY;
  1199. }
  1200. priv->membase = port->membase = membase;
  1201. return 0;
  1202. }
  1203. static void pch_uart_config_port(struct uart_port *port, int type)
  1204. {
  1205. struct eg20t_port *priv;
  1206. priv = container_of(port, struct eg20t_port, port);
  1207. if (type & UART_CONFIG_TYPE) {
  1208. port->type = priv->port_type;
  1209. pch_uart_request_port(port);
  1210. }
  1211. }
  1212. static int pch_uart_verify_port(struct uart_port *port,
  1213. struct serial_struct *serinfo)
  1214. {
  1215. struct eg20t_port *priv;
  1216. priv = container_of(port, struct eg20t_port, port);
  1217. if (serinfo->flags & UPF_LOW_LATENCY) {
  1218. dev_info(priv->port.dev,
  1219. "PCH UART : Use PIO Mode (without DMA)\n");
  1220. priv->use_dma = 0;
  1221. serinfo->flags &= ~UPF_LOW_LATENCY;
  1222. } else {
  1223. #ifndef CONFIG_PCH_DMA
  1224. dev_err(priv->port.dev, "%s : PCH DMA is not Loaded.\n",
  1225. __func__);
  1226. return -EOPNOTSUPP;
  1227. #endif
  1228. priv->use_dma = 1;
  1229. dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
  1230. }
  1231. return 0;
  1232. }
  1233. static struct uart_ops pch_uart_ops = {
  1234. .tx_empty = pch_uart_tx_empty,
  1235. .set_mctrl = pch_uart_set_mctrl,
  1236. .get_mctrl = pch_uart_get_mctrl,
  1237. .stop_tx = pch_uart_stop_tx,
  1238. .start_tx = pch_uart_start_tx,
  1239. .stop_rx = pch_uart_stop_rx,
  1240. .enable_ms = pch_uart_enable_ms,
  1241. .break_ctl = pch_uart_break_ctl,
  1242. .startup = pch_uart_startup,
  1243. .shutdown = pch_uart_shutdown,
  1244. .set_termios = pch_uart_set_termios,
  1245. /* .pm = pch_uart_pm, Not supported yet */
  1246. /* .set_wake = pch_uart_set_wake, Not supported yet */
  1247. .type = pch_uart_type,
  1248. .release_port = pch_uart_release_port,
  1249. .request_port = pch_uart_request_port,
  1250. .config_port = pch_uart_config_port,
  1251. .verify_port = pch_uart_verify_port
  1252. };
  1253. #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
  1254. /*
  1255. * Wait for transmitter & holding register to empty
  1256. */
  1257. static void wait_for_xmitr(struct eg20t_port *up, int bits)
  1258. {
  1259. unsigned int status, tmout = 10000;
  1260. /* Wait up to 10ms for the character(s) to be sent. */
  1261. for (;;) {
  1262. status = ioread8(up->membase + UART_LSR);
  1263. if ((status & bits) == bits)
  1264. break;
  1265. if (--tmout == 0)
  1266. break;
  1267. udelay(1);
  1268. }
  1269. /* Wait up to 1s for flow control if necessary */
  1270. if (up->port.flags & UPF_CONS_FLOW) {
  1271. unsigned int tmout;
  1272. for (tmout = 1000000; tmout; tmout--) {
  1273. unsigned int msr = ioread8(up->membase + UART_MSR);
  1274. if (msr & UART_MSR_CTS)
  1275. break;
  1276. udelay(1);
  1277. touch_nmi_watchdog();
  1278. }
  1279. }
  1280. }
  1281. static void pch_console_putchar(struct uart_port *port, int ch)
  1282. {
  1283. struct eg20t_port *priv =
  1284. container_of(port, struct eg20t_port, port);
  1285. wait_for_xmitr(priv, UART_LSR_THRE);
  1286. iowrite8(ch, priv->membase + PCH_UART_THR);
  1287. }
  1288. /*
  1289. * Print a string to the serial port trying not to disturb
  1290. * any possible real use of the port...
  1291. *
  1292. * The console_lock must be held when we get here.
  1293. */
  1294. static void
  1295. pch_console_write(struct console *co, const char *s, unsigned int count)
  1296. {
  1297. struct eg20t_port *priv;
  1298. unsigned long flags;
  1299. u8 ier;
  1300. int locked = 1;
  1301. priv = pch_uart_ports[co->index];
  1302. touch_nmi_watchdog();
  1303. local_irq_save(flags);
  1304. if (priv->port.sysrq) {
  1305. /* serial8250_handle_port() already took the lock */
  1306. locked = 0;
  1307. } else if (oops_in_progress) {
  1308. locked = spin_trylock(&priv->port.lock);
  1309. } else
  1310. spin_lock(&priv->port.lock);
  1311. /*
  1312. * First save the IER then disable the interrupts
  1313. */
  1314. ier = ioread8(priv->membase + UART_IER);
  1315. pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
  1316. uart_console_write(&priv->port, s, count, pch_console_putchar);
  1317. /*
  1318. * Finally, wait for transmitter to become empty
  1319. * and restore the IER
  1320. */
  1321. wait_for_xmitr(priv, BOTH_EMPTY);
  1322. iowrite8(ier, priv->membase + UART_IER);
  1323. if (locked)
  1324. spin_unlock(&priv->port.lock);
  1325. local_irq_restore(flags);
  1326. }
  1327. static int __init pch_console_setup(struct console *co, char *options)
  1328. {
  1329. struct uart_port *port;
  1330. int baud = default_baud;
  1331. int bits = 8;
  1332. int parity = 'n';
  1333. int flow = 'n';
  1334. /*
  1335. * Check whether an invalid uart number has been specified, and
  1336. * if so, search for the first available port that does have
  1337. * console support.
  1338. */
  1339. if (co->index >= PCH_UART_NR)
  1340. co->index = 0;
  1341. port = &pch_uart_ports[co->index]->port;
  1342. if (!port || (!port->iobase && !port->membase))
  1343. return -ENODEV;
  1344. port->uartclk = pch_uart_get_uartclk();
  1345. if (options)
  1346. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1347. return uart_set_options(port, co, baud, parity, bits, flow);
  1348. }
  1349. static struct uart_driver pch_uart_driver;
  1350. static struct console pch_console = {
  1351. .name = PCH_UART_DRIVER_DEVICE,
  1352. .write = pch_console_write,
  1353. .device = uart_console_device,
  1354. .setup = pch_console_setup,
  1355. .flags = CON_PRINTBUFFER | CON_ANYTIME,
  1356. .index = -1,
  1357. .data = &pch_uart_driver,
  1358. };
  1359. #define PCH_CONSOLE (&pch_console)
  1360. #else
  1361. #define PCH_CONSOLE NULL
  1362. #endif
  1363. static struct uart_driver pch_uart_driver = {
  1364. .owner = THIS_MODULE,
  1365. .driver_name = KBUILD_MODNAME,
  1366. .dev_name = PCH_UART_DRIVER_DEVICE,
  1367. .major = 0,
  1368. .minor = 0,
  1369. .nr = PCH_UART_NR,
  1370. .cons = PCH_CONSOLE,
  1371. };
  1372. static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
  1373. const struct pci_device_id *id)
  1374. {
  1375. struct eg20t_port *priv;
  1376. int ret;
  1377. unsigned int iobase;
  1378. unsigned int mapbase;
  1379. unsigned char *rxbuf;
  1380. int fifosize;
  1381. int port_type;
  1382. struct pch_uart_driver_data *board;
  1383. char name[32]; /* for debugfs file name */
  1384. board = &drv_dat[id->driver_data];
  1385. port_type = board->port_type;
  1386. priv = kzalloc(sizeof(struct eg20t_port), GFP_KERNEL);
  1387. if (priv == NULL)
  1388. goto init_port_alloc_err;
  1389. rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
  1390. if (!rxbuf)
  1391. goto init_port_free_txbuf;
  1392. switch (port_type) {
  1393. case PORT_UNKNOWN:
  1394. fifosize = 256; /* EG20T/ML7213: UART0 */
  1395. break;
  1396. case PORT_8250:
  1397. fifosize = 64; /* EG20T:UART1~3 ML7213: UART1~2*/
  1398. break;
  1399. default:
  1400. dev_err(&pdev->dev, "Invalid Port Type(=%d)\n", port_type);
  1401. goto init_port_hal_free;
  1402. }
  1403. pci_enable_msi(pdev);
  1404. iobase = pci_resource_start(pdev, 0);
  1405. mapbase = pci_resource_start(pdev, 1);
  1406. priv->mapbase = mapbase;
  1407. priv->iobase = iobase;
  1408. priv->pdev = pdev;
  1409. priv->tx_empty = 1;
  1410. priv->rxbuf.buf = rxbuf;
  1411. priv->rxbuf.size = PAGE_SIZE;
  1412. priv->fifo_size = fifosize;
  1413. priv->uartclk = pch_uart_get_uartclk();
  1414. priv->port_type = PORT_MAX_8250 + port_type + 1;
  1415. priv->port.dev = &pdev->dev;
  1416. priv->port.iobase = iobase;
  1417. priv->port.membase = NULL;
  1418. priv->port.mapbase = mapbase;
  1419. priv->port.irq = pdev->irq;
  1420. priv->port.iotype = UPIO_PORT;
  1421. priv->port.ops = &pch_uart_ops;
  1422. priv->port.flags = UPF_BOOT_AUTOCONF;
  1423. priv->port.fifosize = fifosize;
  1424. priv->port.line = board->line_no;
  1425. priv->trigger = PCH_UART_HAL_TRIGGER_M;
  1426. spin_lock_init(&priv->port.lock);
  1427. pci_set_drvdata(pdev, priv);
  1428. priv->trigger_level = 1;
  1429. priv->fcr = 0;
  1430. #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
  1431. pch_uart_ports[board->line_no] = priv;
  1432. #endif
  1433. ret = uart_add_one_port(&pch_uart_driver, &priv->port);
  1434. if (ret < 0)
  1435. goto init_port_hal_free;
  1436. #ifdef CONFIG_DEBUG_FS
  1437. snprintf(name, sizeof(name), "uart%d_regs", board->line_no);
  1438. priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO,
  1439. NULL, priv, &port_regs_ops);
  1440. #endif
  1441. return priv;
  1442. init_port_hal_free:
  1443. #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
  1444. pch_uart_ports[board->line_no] = NULL;
  1445. #endif
  1446. free_page((unsigned long)rxbuf);
  1447. init_port_free_txbuf:
  1448. kfree(priv);
  1449. init_port_alloc_err:
  1450. return NULL;
  1451. }
  1452. static void pch_uart_exit_port(struct eg20t_port *priv)
  1453. {
  1454. #ifdef CONFIG_DEBUG_FS
  1455. if (priv->debugfs)
  1456. debugfs_remove(priv->debugfs);
  1457. #endif
  1458. uart_remove_one_port(&pch_uart_driver, &priv->port);
  1459. pci_set_drvdata(priv->pdev, NULL);
  1460. free_page((unsigned long)priv->rxbuf.buf);
  1461. }
  1462. static void pch_uart_pci_remove(struct pci_dev *pdev)
  1463. {
  1464. struct eg20t_port *priv = pci_get_drvdata(pdev);
  1465. pci_disable_msi(pdev);
  1466. #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
  1467. pch_uart_ports[priv->port.line] = NULL;
  1468. #endif
  1469. pch_uart_exit_port(priv);
  1470. pci_disable_device(pdev);
  1471. kfree(priv);
  1472. return;
  1473. }
  1474. #ifdef CONFIG_PM
  1475. static int pch_uart_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1476. {
  1477. struct eg20t_port *priv = pci_get_drvdata(pdev);
  1478. uart_suspend_port(&pch_uart_driver, &priv->port);
  1479. pci_save_state(pdev);
  1480. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  1481. return 0;
  1482. }
  1483. static int pch_uart_pci_resume(struct pci_dev *pdev)
  1484. {
  1485. struct eg20t_port *priv = pci_get_drvdata(pdev);
  1486. int ret;
  1487. pci_set_power_state(pdev, PCI_D0);
  1488. pci_restore_state(pdev);
  1489. ret = pci_enable_device(pdev);
  1490. if (ret) {
  1491. dev_err(&pdev->dev,
  1492. "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
  1493. return ret;
  1494. }
  1495. uart_resume_port(&pch_uart_driver, &priv->port);
  1496. return 0;
  1497. }
  1498. #else
  1499. #define pch_uart_pci_suspend NULL
  1500. #define pch_uart_pci_resume NULL
  1501. #endif
  1502. static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id) = {
  1503. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8811),
  1504. .driver_data = pch_et20t_uart0},
  1505. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8812),
  1506. .driver_data = pch_et20t_uart1},
  1507. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8813),
  1508. .driver_data = pch_et20t_uart2},
  1509. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8814),
  1510. .driver_data = pch_et20t_uart3},
  1511. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8027),
  1512. .driver_data = pch_ml7213_uart0},
  1513. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8028),
  1514. .driver_data = pch_ml7213_uart1},
  1515. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8029),
  1516. .driver_data = pch_ml7213_uart2},
  1517. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800C),
  1518. .driver_data = pch_ml7223_uart0},
  1519. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D),
  1520. .driver_data = pch_ml7223_uart1},
  1521. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8811),
  1522. .driver_data = pch_ml7831_uart0},
  1523. {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8812),
  1524. .driver_data = pch_ml7831_uart1},
  1525. {0,},
  1526. };
  1527. static int __devinit pch_uart_pci_probe(struct pci_dev *pdev,
  1528. const struct pci_device_id *id)
  1529. {
  1530. int ret;
  1531. struct eg20t_port *priv;
  1532. ret = pci_enable_device(pdev);
  1533. if (ret < 0)
  1534. goto probe_error;
  1535. priv = pch_uart_init_port(pdev, id);
  1536. if (!priv) {
  1537. ret = -EBUSY;
  1538. goto probe_disable_device;
  1539. }
  1540. pci_set_drvdata(pdev, priv);
  1541. return ret;
  1542. probe_disable_device:
  1543. pci_disable_msi(pdev);
  1544. pci_disable_device(pdev);
  1545. probe_error:
  1546. return ret;
  1547. }
  1548. static struct pci_driver pch_uart_pci_driver = {
  1549. .name = "pch_uart",
  1550. .id_table = pch_uart_pci_id,
  1551. .probe = pch_uart_pci_probe,
  1552. .remove = __devexit_p(pch_uart_pci_remove),
  1553. .suspend = pch_uart_pci_suspend,
  1554. .resume = pch_uart_pci_resume,
  1555. };
  1556. static int __init pch_uart_module_init(void)
  1557. {
  1558. int ret;
  1559. /* register as UART driver */
  1560. ret = uart_register_driver(&pch_uart_driver);
  1561. if (ret < 0)
  1562. return ret;
  1563. /* register as PCI driver */
  1564. ret = pci_register_driver(&pch_uart_pci_driver);
  1565. if (ret < 0)
  1566. uart_unregister_driver(&pch_uart_driver);
  1567. return ret;
  1568. }
  1569. module_init(pch_uart_module_init);
  1570. static void __exit pch_uart_module_exit(void)
  1571. {
  1572. pci_unregister_driver(&pch_uart_pci_driver);
  1573. uart_unregister_driver(&pch_uart_driver);
  1574. }
  1575. module_exit(pch_uart_module_exit);
  1576. MODULE_LICENSE("GPL v2");
  1577. MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
  1578. module_param(default_baud, uint, S_IRUGO);
  1579. MODULE_PARM_DESC(default_baud,
  1580. "Default BAUD for initial driver state and console (default 9600)");
  1581. module_param(user_uartclk, uint, S_IRUGO);
  1582. MODULE_PARM_DESC(user_uartclk,
  1583. "Override UART default or board specific UART clock");