pch_uart.c 47 KB

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