pch_uart.c 44 KB

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