pch_uart.c 46 KB

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