pch_uart.c 47 KB

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