pch_uart.c 47 KB

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