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