8250.c 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098
  1. /*
  2. * linux/drivers/char/8250.c
  3. *
  4. * Driver for 8250/16550-type serial ports
  5. *
  6. * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  7. *
  8. * Copyright (C) 2001 Russell King.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * A note about mapbase / membase
  16. *
  17. * mapbase is the physical address of the IO port.
  18. * membase is an 'ioremapped' cookie.
  19. */
  20. #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  21. #define SUPPORT_SYSRQ
  22. #endif
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/ioport.h>
  26. #include <linux/init.h>
  27. #include <linux/console.h>
  28. #include <linux/sysrq.h>
  29. #include <linux/delay.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/tty.h>
  32. #include <linux/tty_flip.h>
  33. #include <linux/serial_reg.h>
  34. #include <linux/serial_core.h>
  35. #include <linux/serial.h>
  36. #include <linux/serial_8250.h>
  37. #include <linux/nmi.h>
  38. #include <linux/mutex.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. #include "8250.h"
  42. #ifdef CONFIG_SPARC
  43. #include "suncore.h"
  44. #endif
  45. /*
  46. * Configuration:
  47. * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
  48. * is unsafe when used on edge-triggered interrupts.
  49. */
  50. static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
  51. static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;
  52. static struct uart_driver serial8250_reg;
  53. static int serial_index(struct uart_port *port)
  54. {
  55. return (serial8250_reg.minor - 64) + port->line;
  56. }
  57. /*
  58. * Debugging.
  59. */
  60. #if 0
  61. #define DEBUG_AUTOCONF(fmt...) printk(fmt)
  62. #else
  63. #define DEBUG_AUTOCONF(fmt...) do { } while (0)
  64. #endif
  65. #if 0
  66. #define DEBUG_INTR(fmt...) printk(fmt)
  67. #else
  68. #define DEBUG_INTR(fmt...) do { } while (0)
  69. #endif
  70. #define PASS_LIMIT 256
  71. /*
  72. * We default to IRQ0 for the "no irq" hack. Some
  73. * machine types want others as well - they're free
  74. * to redefine this in their header file.
  75. */
  76. #define is_real_interrupt(irq) ((irq) != 0)
  77. #ifdef CONFIG_SERIAL_8250_DETECT_IRQ
  78. #define CONFIG_SERIAL_DETECT_IRQ 1
  79. #endif
  80. #ifdef CONFIG_SERIAL_8250_MANY_PORTS
  81. #define CONFIG_SERIAL_MANY_PORTS 1
  82. #endif
  83. /*
  84. * HUB6 is always on. This will be removed once the header
  85. * files have been cleaned.
  86. */
  87. #define CONFIG_HUB6 1
  88. #include <asm/serial.h>
  89. /*
  90. * SERIAL_PORT_DFNS tells us about built-in ports that have no
  91. * standard enumeration mechanism. Platforms that can find all
  92. * serial ports via mechanisms like ACPI or PCI need not supply it.
  93. */
  94. #ifndef SERIAL_PORT_DFNS
  95. #define SERIAL_PORT_DFNS
  96. #endif
  97. static const struct old_serial_port old_serial_port[] = {
  98. SERIAL_PORT_DFNS /* defined in asm/serial.h */
  99. };
  100. #define UART_NR CONFIG_SERIAL_8250_NR_UARTS
  101. #ifdef CONFIG_SERIAL_8250_RSA
  102. #define PORT_RSA_MAX 4
  103. static unsigned long probe_rsa[PORT_RSA_MAX];
  104. static unsigned int probe_rsa_count;
  105. #endif /* CONFIG_SERIAL_8250_RSA */
  106. struct uart_8250_port {
  107. struct uart_port port;
  108. struct timer_list timer; /* "no irq" timer */
  109. struct list_head list; /* ports on this IRQ */
  110. unsigned short capabilities; /* port capabilities */
  111. unsigned short bugs; /* port bugs */
  112. unsigned int tx_loadsz; /* transmit fifo load size */
  113. unsigned char acr;
  114. unsigned char ier;
  115. unsigned char lcr;
  116. unsigned char mcr;
  117. unsigned char mcr_mask; /* mask of user bits */
  118. unsigned char mcr_force; /* mask of forced bits */
  119. /*
  120. * Some bits in registers are cleared on a read, so they must
  121. * be saved whenever the register is read but the bits will not
  122. * be immediately processed.
  123. */
  124. #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
  125. unsigned char lsr_saved_flags;
  126. #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
  127. unsigned char msr_saved_flags;
  128. /*
  129. * We provide a per-port pm hook.
  130. */
  131. void (*pm)(struct uart_port *port,
  132. unsigned int state, unsigned int old);
  133. };
  134. struct irq_info {
  135. struct hlist_node node;
  136. int irq;
  137. spinlock_t lock; /* Protects list not the hash */
  138. struct list_head *head;
  139. };
  140. #define NR_IRQ_HASH 32 /* Can be adjusted later */
  141. static struct hlist_head irq_lists[NR_IRQ_HASH];
  142. static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
  143. /*
  144. * Here we define the default xmit fifo size used for each type of UART.
  145. */
  146. static const struct serial8250_config uart_config[] = {
  147. [PORT_UNKNOWN] = {
  148. .name = "unknown",
  149. .fifo_size = 1,
  150. .tx_loadsz = 1,
  151. },
  152. [PORT_8250] = {
  153. .name = "8250",
  154. .fifo_size = 1,
  155. .tx_loadsz = 1,
  156. },
  157. [PORT_16450] = {
  158. .name = "16450",
  159. .fifo_size = 1,
  160. .tx_loadsz = 1,
  161. },
  162. [PORT_16550] = {
  163. .name = "16550",
  164. .fifo_size = 1,
  165. .tx_loadsz = 1,
  166. },
  167. [PORT_16550A] = {
  168. .name = "16550A",
  169. .fifo_size = 16,
  170. .tx_loadsz = 16,
  171. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  172. .flags = UART_CAP_FIFO,
  173. },
  174. [PORT_CIRRUS] = {
  175. .name = "Cirrus",
  176. .fifo_size = 1,
  177. .tx_loadsz = 1,
  178. },
  179. [PORT_16650] = {
  180. .name = "ST16650",
  181. .fifo_size = 1,
  182. .tx_loadsz = 1,
  183. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  184. },
  185. [PORT_16650V2] = {
  186. .name = "ST16650V2",
  187. .fifo_size = 32,
  188. .tx_loadsz = 16,
  189. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
  190. UART_FCR_T_TRIG_00,
  191. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  192. },
  193. [PORT_16750] = {
  194. .name = "TI16750",
  195. .fifo_size = 64,
  196. .tx_loadsz = 64,
  197. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
  198. UART_FCR7_64BYTE,
  199. .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE,
  200. },
  201. [PORT_STARTECH] = {
  202. .name = "Startech",
  203. .fifo_size = 1,
  204. .tx_loadsz = 1,
  205. },
  206. [PORT_16C950] = {
  207. .name = "16C950/954",
  208. .fifo_size = 128,
  209. .tx_loadsz = 128,
  210. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  211. .flags = UART_CAP_FIFO,
  212. },
  213. [PORT_16654] = {
  214. .name = "ST16654",
  215. .fifo_size = 64,
  216. .tx_loadsz = 32,
  217. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
  218. UART_FCR_T_TRIG_10,
  219. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  220. },
  221. [PORT_16850] = {
  222. .name = "XR16850",
  223. .fifo_size = 128,
  224. .tx_loadsz = 128,
  225. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  226. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  227. },
  228. [PORT_RSA] = {
  229. .name = "RSA",
  230. .fifo_size = 2048,
  231. .tx_loadsz = 2048,
  232. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11,
  233. .flags = UART_CAP_FIFO,
  234. },
  235. [PORT_NS16550A] = {
  236. .name = "NS16550A",
  237. .fifo_size = 16,
  238. .tx_loadsz = 16,
  239. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  240. .flags = UART_CAP_FIFO | UART_NATSEMI,
  241. },
  242. [PORT_XSCALE] = {
  243. .name = "XScale",
  244. .fifo_size = 32,
  245. .tx_loadsz = 32,
  246. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  247. .flags = UART_CAP_FIFO | UART_CAP_UUE,
  248. },
  249. [PORT_RM9000] = {
  250. .name = "RM9000",
  251. .fifo_size = 16,
  252. .tx_loadsz = 16,
  253. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  254. .flags = UART_CAP_FIFO,
  255. },
  256. };
  257. #if defined (CONFIG_SERIAL_8250_AU1X00)
  258. /* Au1x00 UART hardware has a weird register layout */
  259. static const u8 au_io_in_map[] = {
  260. [UART_RX] = 0,
  261. [UART_IER] = 2,
  262. [UART_IIR] = 3,
  263. [UART_LCR] = 5,
  264. [UART_MCR] = 6,
  265. [UART_LSR] = 7,
  266. [UART_MSR] = 8,
  267. };
  268. static const u8 au_io_out_map[] = {
  269. [UART_TX] = 1,
  270. [UART_IER] = 2,
  271. [UART_FCR] = 4,
  272. [UART_LCR] = 5,
  273. [UART_MCR] = 6,
  274. };
  275. /* sane hardware needs no mapping */
  276. static inline int map_8250_in_reg(struct uart_8250_port *up, int offset)
  277. {
  278. if (up->port.iotype != UPIO_AU)
  279. return offset;
  280. return au_io_in_map[offset];
  281. }
  282. static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
  283. {
  284. if (up->port.iotype != UPIO_AU)
  285. return offset;
  286. return au_io_out_map[offset];
  287. }
  288. #elif defined(CONFIG_SERIAL_8250_RM9K)
  289. static const u8
  290. regmap_in[8] = {
  291. [UART_RX] = 0x00,
  292. [UART_IER] = 0x0c,
  293. [UART_IIR] = 0x14,
  294. [UART_LCR] = 0x1c,
  295. [UART_MCR] = 0x20,
  296. [UART_LSR] = 0x24,
  297. [UART_MSR] = 0x28,
  298. [UART_SCR] = 0x2c
  299. },
  300. regmap_out[8] = {
  301. [UART_TX] = 0x04,
  302. [UART_IER] = 0x0c,
  303. [UART_FCR] = 0x18,
  304. [UART_LCR] = 0x1c,
  305. [UART_MCR] = 0x20,
  306. [UART_LSR] = 0x24,
  307. [UART_MSR] = 0x28,
  308. [UART_SCR] = 0x2c
  309. };
  310. static inline int map_8250_in_reg(struct uart_8250_port *up, int offset)
  311. {
  312. if (up->port.iotype != UPIO_RM9000)
  313. return offset;
  314. return regmap_in[offset];
  315. }
  316. static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
  317. {
  318. if (up->port.iotype != UPIO_RM9000)
  319. return offset;
  320. return regmap_out[offset];
  321. }
  322. #else
  323. /* sane hardware needs no mapping */
  324. #define map_8250_in_reg(up, offset) (offset)
  325. #define map_8250_out_reg(up, offset) (offset)
  326. #endif
  327. static unsigned int serial_in(struct uart_8250_port *up, int offset)
  328. {
  329. unsigned int tmp;
  330. offset = map_8250_in_reg(up, offset) << up->port.regshift;
  331. switch (up->port.iotype) {
  332. case UPIO_HUB6:
  333. outb(up->port.hub6 - 1 + offset, up->port.iobase);
  334. return inb(up->port.iobase + 1);
  335. case UPIO_MEM:
  336. case UPIO_DWAPB:
  337. return readb(up->port.membase + offset);
  338. case UPIO_RM9000:
  339. case UPIO_MEM32:
  340. return readl(up->port.membase + offset);
  341. #ifdef CONFIG_SERIAL_8250_AU1X00
  342. case UPIO_AU:
  343. return __raw_readl(up->port.membase + offset);
  344. #endif
  345. case UPIO_TSI:
  346. if (offset == UART_IIR) {
  347. tmp = readl(up->port.membase + (UART_IIR & ~3));
  348. return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */
  349. } else
  350. return readb(up->port.membase + offset);
  351. default:
  352. return inb(up->port.iobase + offset);
  353. }
  354. }
  355. static void
  356. serial_out(struct uart_8250_port *up, int offset, int value)
  357. {
  358. /* Save the offset before it's remapped */
  359. int save_offset = offset;
  360. offset = map_8250_out_reg(up, offset) << up->port.regshift;
  361. switch (up->port.iotype) {
  362. case UPIO_HUB6:
  363. outb(up->port.hub6 - 1 + offset, up->port.iobase);
  364. outb(value, up->port.iobase + 1);
  365. break;
  366. case UPIO_MEM:
  367. writeb(value, up->port.membase + offset);
  368. break;
  369. case UPIO_RM9000:
  370. case UPIO_MEM32:
  371. writel(value, up->port.membase + offset);
  372. break;
  373. #ifdef CONFIG_SERIAL_8250_AU1X00
  374. case UPIO_AU:
  375. __raw_writel(value, up->port.membase + offset);
  376. break;
  377. #endif
  378. case UPIO_TSI:
  379. if (!((offset == UART_IER) && (value & UART_IER_UUE)))
  380. writeb(value, up->port.membase + offset);
  381. break;
  382. case UPIO_DWAPB:
  383. /* Save the LCR value so it can be re-written when a
  384. * Busy Detect interrupt occurs. */
  385. if (save_offset == UART_LCR)
  386. up->lcr = value;
  387. writeb(value, up->port.membase + offset);
  388. /* Read the IER to ensure any interrupt is cleared before
  389. * returning from ISR. */
  390. if (save_offset == UART_TX || save_offset == UART_IER)
  391. value = serial_in(up, UART_IER);
  392. break;
  393. default:
  394. outb(value, up->port.iobase + offset);
  395. }
  396. }
  397. static void
  398. serial_out_sync(struct uart_8250_port *up, int offset, int value)
  399. {
  400. switch (up->port.iotype) {
  401. case UPIO_MEM:
  402. case UPIO_MEM32:
  403. #ifdef CONFIG_SERIAL_8250_AU1X00
  404. case UPIO_AU:
  405. #endif
  406. case UPIO_DWAPB:
  407. serial_out(up, offset, value);
  408. serial_in(up, UART_LCR); /* safe, no side-effects */
  409. break;
  410. default:
  411. serial_out(up, offset, value);
  412. }
  413. }
  414. /*
  415. * We used to support using pause I/O for certain machines. We
  416. * haven't supported this for a while, but just in case it's badly
  417. * needed for certain old 386 machines, I've left these #define's
  418. * in....
  419. */
  420. #define serial_inp(up, offset) serial_in(up, offset)
  421. #define serial_outp(up, offset, value) serial_out(up, offset, value)
  422. /* Uart divisor latch read */
  423. static inline int _serial_dl_read(struct uart_8250_port *up)
  424. {
  425. return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8;
  426. }
  427. /* Uart divisor latch write */
  428. static inline void _serial_dl_write(struct uart_8250_port *up, int value)
  429. {
  430. serial_outp(up, UART_DLL, value & 0xff);
  431. serial_outp(up, UART_DLM, value >> 8 & 0xff);
  432. }
  433. #if defined(CONFIG_SERIAL_8250_AU1X00)
  434. /* Au1x00 haven't got a standard divisor latch */
  435. static int serial_dl_read(struct uart_8250_port *up)
  436. {
  437. if (up->port.iotype == UPIO_AU)
  438. return __raw_readl(up->port.membase + 0x28);
  439. else
  440. return _serial_dl_read(up);
  441. }
  442. static void serial_dl_write(struct uart_8250_port *up, int value)
  443. {
  444. if (up->port.iotype == UPIO_AU)
  445. __raw_writel(value, up->port.membase + 0x28);
  446. else
  447. _serial_dl_write(up, value);
  448. }
  449. #elif defined(CONFIG_SERIAL_8250_RM9K)
  450. static int serial_dl_read(struct uart_8250_port *up)
  451. {
  452. return (up->port.iotype == UPIO_RM9000) ?
  453. (((__raw_readl(up->port.membase + 0x10) << 8) |
  454. (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) :
  455. _serial_dl_read(up);
  456. }
  457. static void serial_dl_write(struct uart_8250_port *up, int value)
  458. {
  459. if (up->port.iotype == UPIO_RM9000) {
  460. __raw_writel(value, up->port.membase + 0x08);
  461. __raw_writel(value >> 8, up->port.membase + 0x10);
  462. } else {
  463. _serial_dl_write(up, value);
  464. }
  465. }
  466. #else
  467. #define serial_dl_read(up) _serial_dl_read(up)
  468. #define serial_dl_write(up, value) _serial_dl_write(up, value)
  469. #endif
  470. /*
  471. * For the 16C950
  472. */
  473. static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
  474. {
  475. serial_out(up, UART_SCR, offset);
  476. serial_out(up, UART_ICR, value);
  477. }
  478. static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
  479. {
  480. unsigned int value;
  481. serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
  482. serial_out(up, UART_SCR, offset);
  483. value = serial_in(up, UART_ICR);
  484. serial_icr_write(up, UART_ACR, up->acr);
  485. return value;
  486. }
  487. /*
  488. * FIFO support.
  489. */
  490. static void serial8250_clear_fifos(struct uart_8250_port *p)
  491. {
  492. if (p->capabilities & UART_CAP_FIFO) {
  493. serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO);
  494. serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO |
  495. UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
  496. serial_outp(p, UART_FCR, 0);
  497. }
  498. }
  499. /*
  500. * IER sleep support. UARTs which have EFRs need the "extended
  501. * capability" bit enabled. Note that on XR16C850s, we need to
  502. * reset LCR to write to IER.
  503. */
  504. static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
  505. {
  506. if (p->capabilities & UART_CAP_SLEEP) {
  507. if (p->capabilities & UART_CAP_EFR) {
  508. serial_outp(p, UART_LCR, 0xBF);
  509. serial_outp(p, UART_EFR, UART_EFR_ECB);
  510. serial_outp(p, UART_LCR, 0);
  511. }
  512. serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
  513. if (p->capabilities & UART_CAP_EFR) {
  514. serial_outp(p, UART_LCR, 0xBF);
  515. serial_outp(p, UART_EFR, 0);
  516. serial_outp(p, UART_LCR, 0);
  517. }
  518. }
  519. }
  520. #ifdef CONFIG_SERIAL_8250_RSA
  521. /*
  522. * Attempts to turn on the RSA FIFO. Returns zero on failure.
  523. * We set the port uart clock rate if we succeed.
  524. */
  525. static int __enable_rsa(struct uart_8250_port *up)
  526. {
  527. unsigned char mode;
  528. int result;
  529. mode = serial_inp(up, UART_RSA_MSR);
  530. result = mode & UART_RSA_MSR_FIFO;
  531. if (!result) {
  532. serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
  533. mode = serial_inp(up, UART_RSA_MSR);
  534. result = mode & UART_RSA_MSR_FIFO;
  535. }
  536. if (result)
  537. up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
  538. return result;
  539. }
  540. static void enable_rsa(struct uart_8250_port *up)
  541. {
  542. if (up->port.type == PORT_RSA) {
  543. if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
  544. spin_lock_irq(&up->port.lock);
  545. __enable_rsa(up);
  546. spin_unlock_irq(&up->port.lock);
  547. }
  548. if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
  549. serial_outp(up, UART_RSA_FRR, 0);
  550. }
  551. }
  552. /*
  553. * Attempts to turn off the RSA FIFO. Returns zero on failure.
  554. * It is unknown why interrupts were disabled in here. However,
  555. * the caller is expected to preserve this behaviour by grabbing
  556. * the spinlock before calling this function.
  557. */
  558. static void disable_rsa(struct uart_8250_port *up)
  559. {
  560. unsigned char mode;
  561. int result;
  562. if (up->port.type == PORT_RSA &&
  563. up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
  564. spin_lock_irq(&up->port.lock);
  565. mode = serial_inp(up, UART_RSA_MSR);
  566. result = !(mode & UART_RSA_MSR_FIFO);
  567. if (!result) {
  568. serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
  569. mode = serial_inp(up, UART_RSA_MSR);
  570. result = !(mode & UART_RSA_MSR_FIFO);
  571. }
  572. if (result)
  573. up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
  574. spin_unlock_irq(&up->port.lock);
  575. }
  576. }
  577. #endif /* CONFIG_SERIAL_8250_RSA */
  578. /*
  579. * This is a quickie test to see how big the FIFO is.
  580. * It doesn't work at all the time, more's the pity.
  581. */
  582. static int size_fifo(struct uart_8250_port *up)
  583. {
  584. unsigned char old_fcr, old_mcr, old_lcr;
  585. unsigned short old_dl;
  586. int count;
  587. old_lcr = serial_inp(up, UART_LCR);
  588. serial_outp(up, UART_LCR, 0);
  589. old_fcr = serial_inp(up, UART_FCR);
  590. old_mcr = serial_inp(up, UART_MCR);
  591. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
  592. UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
  593. serial_outp(up, UART_MCR, UART_MCR_LOOP);
  594. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  595. old_dl = serial_dl_read(up);
  596. serial_dl_write(up, 0x0001);
  597. serial_outp(up, UART_LCR, 0x03);
  598. for (count = 0; count < 256; count++)
  599. serial_outp(up, UART_TX, count);
  600. mdelay(20);/* FIXME - schedule_timeout */
  601. for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) &&
  602. (count < 256); count++)
  603. serial_inp(up, UART_RX);
  604. serial_outp(up, UART_FCR, old_fcr);
  605. serial_outp(up, UART_MCR, old_mcr);
  606. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  607. serial_dl_write(up, old_dl);
  608. serial_outp(up, UART_LCR, old_lcr);
  609. return count;
  610. }
  611. /*
  612. * Read UART ID using the divisor method - set DLL and DLM to zero
  613. * and the revision will be in DLL and device type in DLM. We
  614. * preserve the device state across this.
  615. */
  616. static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
  617. {
  618. unsigned char old_dll, old_dlm, old_lcr;
  619. unsigned int id;
  620. old_lcr = serial_inp(p, UART_LCR);
  621. serial_outp(p, UART_LCR, UART_LCR_DLAB);
  622. old_dll = serial_inp(p, UART_DLL);
  623. old_dlm = serial_inp(p, UART_DLM);
  624. serial_outp(p, UART_DLL, 0);
  625. serial_outp(p, UART_DLM, 0);
  626. id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8;
  627. serial_outp(p, UART_DLL, old_dll);
  628. serial_outp(p, UART_DLM, old_dlm);
  629. serial_outp(p, UART_LCR, old_lcr);
  630. return id;
  631. }
  632. /*
  633. * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
  634. * When this function is called we know it is at least a StarTech
  635. * 16650 V2, but it might be one of several StarTech UARTs, or one of
  636. * its clones. (We treat the broken original StarTech 16650 V1 as a
  637. * 16550, and why not? Startech doesn't seem to even acknowledge its
  638. * existence.)
  639. *
  640. * What evil have men's minds wrought...
  641. */
  642. static void autoconfig_has_efr(struct uart_8250_port *up)
  643. {
  644. unsigned int id1, id2, id3, rev;
  645. /*
  646. * Everything with an EFR has SLEEP
  647. */
  648. up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
  649. /*
  650. * First we check to see if it's an Oxford Semiconductor UART.
  651. *
  652. * If we have to do this here because some non-National
  653. * Semiconductor clone chips lock up if you try writing to the
  654. * LSR register (which serial_icr_read does)
  655. */
  656. /*
  657. * Check for Oxford Semiconductor 16C950.
  658. *
  659. * EFR [4] must be set else this test fails.
  660. *
  661. * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
  662. * claims that it's needed for 952 dual UART's (which are not
  663. * recommended for new designs).
  664. */
  665. up->acr = 0;
  666. serial_out(up, UART_LCR, 0xBF);
  667. serial_out(up, UART_EFR, UART_EFR_ECB);
  668. serial_out(up, UART_LCR, 0x00);
  669. id1 = serial_icr_read(up, UART_ID1);
  670. id2 = serial_icr_read(up, UART_ID2);
  671. id3 = serial_icr_read(up, UART_ID3);
  672. rev = serial_icr_read(up, UART_REV);
  673. DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
  674. if (id1 == 0x16 && id2 == 0xC9 &&
  675. (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
  676. up->port.type = PORT_16C950;
  677. /*
  678. * Enable work around for the Oxford Semiconductor 952 rev B
  679. * chip which causes it to seriously miscalculate baud rates
  680. * when DLL is 0.
  681. */
  682. if (id3 == 0x52 && rev == 0x01)
  683. up->bugs |= UART_BUG_QUOT;
  684. return;
  685. }
  686. /*
  687. * We check for a XR16C850 by setting DLL and DLM to 0, and then
  688. * reading back DLL and DLM. The chip type depends on the DLM
  689. * value read back:
  690. * 0x10 - XR16C850 and the DLL contains the chip revision.
  691. * 0x12 - XR16C2850.
  692. * 0x14 - XR16C854.
  693. */
  694. id1 = autoconfig_read_divisor_id(up);
  695. DEBUG_AUTOCONF("850id=%04x ", id1);
  696. id2 = id1 >> 8;
  697. if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
  698. up->port.type = PORT_16850;
  699. return;
  700. }
  701. /*
  702. * It wasn't an XR16C850.
  703. *
  704. * We distinguish between the '654 and the '650 by counting
  705. * how many bytes are in the FIFO. I'm using this for now,
  706. * since that's the technique that was sent to me in the
  707. * serial driver update, but I'm not convinced this works.
  708. * I've had problems doing this in the past. -TYT
  709. */
  710. if (size_fifo(up) == 64)
  711. up->port.type = PORT_16654;
  712. else
  713. up->port.type = PORT_16650V2;
  714. }
  715. /*
  716. * We detected a chip without a FIFO. Only two fall into
  717. * this category - the original 8250 and the 16450. The
  718. * 16450 has a scratch register (accessible with LCR=0)
  719. */
  720. static void autoconfig_8250(struct uart_8250_port *up)
  721. {
  722. unsigned char scratch, status1, status2;
  723. up->port.type = PORT_8250;
  724. scratch = serial_in(up, UART_SCR);
  725. serial_outp(up, UART_SCR, 0xa5);
  726. status1 = serial_in(up, UART_SCR);
  727. serial_outp(up, UART_SCR, 0x5a);
  728. status2 = serial_in(up, UART_SCR);
  729. serial_outp(up, UART_SCR, scratch);
  730. if (status1 == 0xa5 && status2 == 0x5a)
  731. up->port.type = PORT_16450;
  732. }
  733. static int broken_efr(struct uart_8250_port *up)
  734. {
  735. /*
  736. * Exar ST16C2550 "A2" devices incorrectly detect as
  737. * having an EFR, and report an ID of 0x0201. See
  738. * http://www.exar.com/info.php?pdf=dan180_oct2004.pdf
  739. */
  740. if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)
  741. return 1;
  742. return 0;
  743. }
  744. /*
  745. * We know that the chip has FIFOs. Does it have an EFR? The
  746. * EFR is located in the same register position as the IIR and
  747. * we know the top two bits of the IIR are currently set. The
  748. * EFR should contain zero. Try to read the EFR.
  749. */
  750. static void autoconfig_16550a(struct uart_8250_port *up)
  751. {
  752. unsigned char status1, status2;
  753. unsigned int iersave;
  754. up->port.type = PORT_16550A;
  755. up->capabilities |= UART_CAP_FIFO;
  756. /*
  757. * Check for presence of the EFR when DLAB is set.
  758. * Only ST16C650V1 UARTs pass this test.
  759. */
  760. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  761. if (serial_in(up, UART_EFR) == 0) {
  762. serial_outp(up, UART_EFR, 0xA8);
  763. if (serial_in(up, UART_EFR) != 0) {
  764. DEBUG_AUTOCONF("EFRv1 ");
  765. up->port.type = PORT_16650;
  766. up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
  767. } else {
  768. DEBUG_AUTOCONF("Motorola 8xxx DUART ");
  769. }
  770. serial_outp(up, UART_EFR, 0);
  771. return;
  772. }
  773. /*
  774. * Maybe it requires 0xbf to be written to the LCR.
  775. * (other ST16C650V2 UARTs, TI16C752A, etc)
  776. */
  777. serial_outp(up, UART_LCR, 0xBF);
  778. if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
  779. DEBUG_AUTOCONF("EFRv2 ");
  780. autoconfig_has_efr(up);
  781. return;
  782. }
  783. /*
  784. * Check for a National Semiconductor SuperIO chip.
  785. * Attempt to switch to bank 2, read the value of the LOOP bit
  786. * from EXCR1. Switch back to bank 0, change it in MCR. Then
  787. * switch back to bank 2, read it from EXCR1 again and check
  788. * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
  789. */
  790. serial_outp(up, UART_LCR, 0);
  791. status1 = serial_in(up, UART_MCR);
  792. serial_outp(up, UART_LCR, 0xE0);
  793. status2 = serial_in(up, 0x02); /* EXCR1 */
  794. if (!((status2 ^ status1) & UART_MCR_LOOP)) {
  795. serial_outp(up, UART_LCR, 0);
  796. serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP);
  797. serial_outp(up, UART_LCR, 0xE0);
  798. status2 = serial_in(up, 0x02); /* EXCR1 */
  799. serial_outp(up, UART_LCR, 0);
  800. serial_outp(up, UART_MCR, status1);
  801. if ((status2 ^ status1) & UART_MCR_LOOP) {
  802. unsigned short quot;
  803. serial_outp(up, UART_LCR, 0xE0);
  804. quot = serial_dl_read(up);
  805. quot <<= 3;
  806. status1 = serial_in(up, 0x04); /* EXCR2 */
  807. status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
  808. status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
  809. serial_outp(up, 0x04, status1);
  810. serial_dl_write(up, quot);
  811. serial_outp(up, UART_LCR, 0);
  812. up->port.uartclk = 921600*16;
  813. up->port.type = PORT_NS16550A;
  814. up->capabilities |= UART_NATSEMI;
  815. return;
  816. }
  817. }
  818. /*
  819. * No EFR. Try to detect a TI16750, which only sets bit 5 of
  820. * the IIR when 64 byte FIFO mode is enabled when DLAB is set.
  821. * Try setting it with and without DLAB set. Cheap clones
  822. * set bit 5 without DLAB set.
  823. */
  824. serial_outp(up, UART_LCR, 0);
  825. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
  826. status1 = serial_in(up, UART_IIR) >> 5;
  827. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  828. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  829. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
  830. status2 = serial_in(up, UART_IIR) >> 5;
  831. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  832. serial_outp(up, UART_LCR, 0);
  833. DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
  834. if (status1 == 6 && status2 == 7) {
  835. up->port.type = PORT_16750;
  836. up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP;
  837. return;
  838. }
  839. /*
  840. * Try writing and reading the UART_IER_UUE bit (b6).
  841. * If it works, this is probably one of the Xscale platform's
  842. * internal UARTs.
  843. * We're going to explicitly set the UUE bit to 0 before
  844. * trying to write and read a 1 just to make sure it's not
  845. * already a 1 and maybe locked there before we even start start.
  846. */
  847. iersave = serial_in(up, UART_IER);
  848. serial_outp(up, UART_IER, iersave & ~UART_IER_UUE);
  849. if (!(serial_in(up, UART_IER) & UART_IER_UUE)) {
  850. /*
  851. * OK it's in a known zero state, try writing and reading
  852. * without disturbing the current state of the other bits.
  853. */
  854. serial_outp(up, UART_IER, iersave | UART_IER_UUE);
  855. if (serial_in(up, UART_IER) & UART_IER_UUE) {
  856. /*
  857. * It's an Xscale.
  858. * We'll leave the UART_IER_UUE bit set to 1 (enabled).
  859. */
  860. DEBUG_AUTOCONF("Xscale ");
  861. up->port.type = PORT_XSCALE;
  862. up->capabilities |= UART_CAP_UUE;
  863. return;
  864. }
  865. } else {
  866. /*
  867. * If we got here we couldn't force the IER_UUE bit to 0.
  868. * Log it and continue.
  869. */
  870. DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
  871. }
  872. serial_outp(up, UART_IER, iersave);
  873. }
  874. /*
  875. * This routine is called by rs_init() to initialize a specific serial
  876. * port. It determines what type of UART chip this serial port is
  877. * using: 8250, 16450, 16550, 16550A. The important question is
  878. * whether or not this UART is a 16550A or not, since this will
  879. * determine whether or not we can use its FIFO features or not.
  880. */
  881. static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
  882. {
  883. unsigned char status1, scratch, scratch2, scratch3;
  884. unsigned char save_lcr, save_mcr;
  885. unsigned long flags;
  886. if (!up->port.iobase && !up->port.mapbase && !up->port.membase)
  887. return;
  888. DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",
  889. serial_index(&up->port), up->port.iobase, up->port.membase);
  890. /*
  891. * We really do need global IRQs disabled here - we're going to
  892. * be frobbing the chips IRQ enable register to see if it exists.
  893. */
  894. spin_lock_irqsave(&up->port.lock, flags);
  895. up->capabilities = 0;
  896. up->bugs = 0;
  897. if (!(up->port.flags & UPF_BUGGY_UART)) {
  898. /*
  899. * Do a simple existence test first; if we fail this,
  900. * there's no point trying anything else.
  901. *
  902. * 0x80 is used as a nonsense port to prevent against
  903. * false positives due to ISA bus float. The
  904. * assumption is that 0x80 is a non-existent port;
  905. * which should be safe since include/asm/io.h also
  906. * makes this assumption.
  907. *
  908. * Note: this is safe as long as MCR bit 4 is clear
  909. * and the device is in "PC" mode.
  910. */
  911. scratch = serial_inp(up, UART_IER);
  912. serial_outp(up, UART_IER, 0);
  913. #ifdef __i386__
  914. outb(0xff, 0x080);
  915. #endif
  916. /*
  917. * Mask out IER[7:4] bits for test as some UARTs (e.g. TL
  918. * 16C754B) allow only to modify them if an EFR bit is set.
  919. */
  920. scratch2 = serial_inp(up, UART_IER) & 0x0f;
  921. serial_outp(up, UART_IER, 0x0F);
  922. #ifdef __i386__
  923. outb(0, 0x080);
  924. #endif
  925. scratch3 = serial_inp(up, UART_IER) & 0x0f;
  926. serial_outp(up, UART_IER, scratch);
  927. if (scratch2 != 0 || scratch3 != 0x0F) {
  928. /*
  929. * We failed; there's nothing here
  930. */
  931. DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
  932. scratch2, scratch3);
  933. goto out;
  934. }
  935. }
  936. save_mcr = serial_in(up, UART_MCR);
  937. save_lcr = serial_in(up, UART_LCR);
  938. /*
  939. * Check to see if a UART is really there. Certain broken
  940. * internal modems based on the Rockwell chipset fail this
  941. * test, because they apparently don't implement the loopback
  942. * test mode. So this test is skipped on the COM 1 through
  943. * COM 4 ports. This *should* be safe, since no board
  944. * manufacturer would be stupid enough to design a board
  945. * that conflicts with COM 1-4 --- we hope!
  946. */
  947. if (!(up->port.flags & UPF_SKIP_TEST)) {
  948. serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
  949. status1 = serial_inp(up, UART_MSR) & 0xF0;
  950. serial_outp(up, UART_MCR, save_mcr);
  951. if (status1 != 0x90) {
  952. DEBUG_AUTOCONF("LOOP test failed (%02x) ",
  953. status1);
  954. goto out;
  955. }
  956. }
  957. /*
  958. * We're pretty sure there's a port here. Lets find out what
  959. * type of port it is. The IIR top two bits allows us to find
  960. * out if it's 8250 or 16450, 16550, 16550A or later. This
  961. * determines what we test for next.
  962. *
  963. * We also initialise the EFR (if any) to zero for later. The
  964. * EFR occupies the same register location as the FCR and IIR.
  965. */
  966. serial_outp(up, UART_LCR, 0xBF);
  967. serial_outp(up, UART_EFR, 0);
  968. serial_outp(up, UART_LCR, 0);
  969. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  970. scratch = serial_in(up, UART_IIR) >> 6;
  971. DEBUG_AUTOCONF("iir=%d ", scratch);
  972. switch (scratch) {
  973. case 0:
  974. autoconfig_8250(up);
  975. break;
  976. case 1:
  977. up->port.type = PORT_UNKNOWN;
  978. break;
  979. case 2:
  980. up->port.type = PORT_16550;
  981. break;
  982. case 3:
  983. autoconfig_16550a(up);
  984. break;
  985. }
  986. #ifdef CONFIG_SERIAL_8250_RSA
  987. /*
  988. * Only probe for RSA ports if we got the region.
  989. */
  990. if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) {
  991. int i;
  992. for (i = 0 ; i < probe_rsa_count; ++i) {
  993. if (probe_rsa[i] == up->port.iobase &&
  994. __enable_rsa(up)) {
  995. up->port.type = PORT_RSA;
  996. break;
  997. }
  998. }
  999. }
  1000. #endif
  1001. #ifdef CONFIG_SERIAL_8250_AU1X00
  1002. /* if access method is AU, it is a 16550 with a quirk */
  1003. if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU)
  1004. up->bugs |= UART_BUG_NOMSR;
  1005. #endif
  1006. serial_outp(up, UART_LCR, save_lcr);
  1007. if (up->capabilities != uart_config[up->port.type].flags) {
  1008. printk(KERN_WARNING
  1009. "ttyS%d: detected caps %08x should be %08x\n",
  1010. serial_index(&up->port), up->capabilities,
  1011. uart_config[up->port.type].flags);
  1012. }
  1013. up->port.fifosize = uart_config[up->port.type].fifo_size;
  1014. up->capabilities = uart_config[up->port.type].flags;
  1015. up->tx_loadsz = uart_config[up->port.type].tx_loadsz;
  1016. if (up->port.type == PORT_UNKNOWN)
  1017. goto out;
  1018. /*
  1019. * Reset the UART.
  1020. */
  1021. #ifdef CONFIG_SERIAL_8250_RSA
  1022. if (up->port.type == PORT_RSA)
  1023. serial_outp(up, UART_RSA_FRR, 0);
  1024. #endif
  1025. serial_outp(up, UART_MCR, save_mcr);
  1026. serial8250_clear_fifos(up);
  1027. serial_in(up, UART_RX);
  1028. if (up->capabilities & UART_CAP_UUE)
  1029. serial_outp(up, UART_IER, UART_IER_UUE);
  1030. else
  1031. serial_outp(up, UART_IER, 0);
  1032. out:
  1033. spin_unlock_irqrestore(&up->port.lock, flags);
  1034. DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);
  1035. }
  1036. static void autoconfig_irq(struct uart_8250_port *up)
  1037. {
  1038. unsigned char save_mcr, save_ier;
  1039. unsigned char save_ICP = 0;
  1040. unsigned int ICP = 0;
  1041. unsigned long irqs;
  1042. int irq;
  1043. if (up->port.flags & UPF_FOURPORT) {
  1044. ICP = (up->port.iobase & 0xfe0) | 0x1f;
  1045. save_ICP = inb_p(ICP);
  1046. outb_p(0x80, ICP);
  1047. (void) inb_p(ICP);
  1048. }
  1049. /* forget possible initially masked and pending IRQ */
  1050. probe_irq_off(probe_irq_on());
  1051. save_mcr = serial_inp(up, UART_MCR);
  1052. save_ier = serial_inp(up, UART_IER);
  1053. serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
  1054. irqs = probe_irq_on();
  1055. serial_outp(up, UART_MCR, 0);
  1056. udelay(10);
  1057. if (up->port.flags & UPF_FOURPORT) {
  1058. serial_outp(up, UART_MCR,
  1059. UART_MCR_DTR | UART_MCR_RTS);
  1060. } else {
  1061. serial_outp(up, UART_MCR,
  1062. UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
  1063. }
  1064. serial_outp(up, UART_IER, 0x0f); /* enable all intrs */
  1065. (void)serial_inp(up, UART_LSR);
  1066. (void)serial_inp(up, UART_RX);
  1067. (void)serial_inp(up, UART_IIR);
  1068. (void)serial_inp(up, UART_MSR);
  1069. serial_outp(up, UART_TX, 0xFF);
  1070. udelay(20);
  1071. irq = probe_irq_off(irqs);
  1072. serial_outp(up, UART_MCR, save_mcr);
  1073. serial_outp(up, UART_IER, save_ier);
  1074. if (up->port.flags & UPF_FOURPORT)
  1075. outb_p(save_ICP, ICP);
  1076. up->port.irq = (irq > 0) ? irq : 0;
  1077. }
  1078. static inline void __stop_tx(struct uart_8250_port *p)
  1079. {
  1080. if (p->ier & UART_IER_THRI) {
  1081. p->ier &= ~UART_IER_THRI;
  1082. serial_out(p, UART_IER, p->ier);
  1083. }
  1084. }
  1085. static void serial8250_stop_tx(struct uart_port *port)
  1086. {
  1087. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1088. __stop_tx(up);
  1089. /*
  1090. * We really want to stop the transmitter from sending.
  1091. */
  1092. if (up->port.type == PORT_16C950) {
  1093. up->acr |= UART_ACR_TXDIS;
  1094. serial_icr_write(up, UART_ACR, up->acr);
  1095. }
  1096. }
  1097. static void transmit_chars(struct uart_8250_port *up);
  1098. static void serial8250_start_tx(struct uart_port *port)
  1099. {
  1100. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1101. if (!(up->ier & UART_IER_THRI)) {
  1102. up->ier |= UART_IER_THRI;
  1103. serial_out(up, UART_IER, up->ier);
  1104. if (up->bugs & UART_BUG_TXEN) {
  1105. unsigned char lsr, iir;
  1106. lsr = serial_in(up, UART_LSR);
  1107. up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
  1108. iir = serial_in(up, UART_IIR) & 0x0f;
  1109. if ((up->port.type == PORT_RM9000) ?
  1110. (lsr & UART_LSR_THRE &&
  1111. (iir == UART_IIR_NO_INT || iir == UART_IIR_THRI)) :
  1112. (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT))
  1113. transmit_chars(up);
  1114. }
  1115. }
  1116. /*
  1117. * Re-enable the transmitter if we disabled it.
  1118. */
  1119. if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
  1120. up->acr &= ~UART_ACR_TXDIS;
  1121. serial_icr_write(up, UART_ACR, up->acr);
  1122. }
  1123. }
  1124. static void serial8250_stop_rx(struct uart_port *port)
  1125. {
  1126. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1127. up->ier &= ~UART_IER_RLSI;
  1128. up->port.read_status_mask &= ~UART_LSR_DR;
  1129. serial_out(up, UART_IER, up->ier);
  1130. }
  1131. static void serial8250_enable_ms(struct uart_port *port)
  1132. {
  1133. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1134. /* no MSR capabilities */
  1135. if (up->bugs & UART_BUG_NOMSR)
  1136. return;
  1137. up->ier |= UART_IER_MSI;
  1138. serial_out(up, UART_IER, up->ier);
  1139. }
  1140. static void
  1141. receive_chars(struct uart_8250_port *up, unsigned int *status)
  1142. {
  1143. struct tty_struct *tty = up->port.info->port.tty;
  1144. unsigned char ch, lsr = *status;
  1145. int max_count = 256;
  1146. char flag;
  1147. do {
  1148. if (likely(lsr & UART_LSR_DR))
  1149. ch = serial_inp(up, UART_RX);
  1150. else
  1151. /*
  1152. * Intel 82571 has a Serial Over Lan device that will
  1153. * set UART_LSR_BI without setting UART_LSR_DR when
  1154. * it receives a break. To avoid reading from the
  1155. * receive buffer without UART_LSR_DR bit set, we
  1156. * just force the read character to be 0
  1157. */
  1158. ch = 0;
  1159. flag = TTY_NORMAL;
  1160. up->port.icount.rx++;
  1161. lsr |= up->lsr_saved_flags;
  1162. up->lsr_saved_flags = 0;
  1163. if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
  1164. /*
  1165. * For statistics only
  1166. */
  1167. if (lsr & UART_LSR_BI) {
  1168. lsr &= ~(UART_LSR_FE | UART_LSR_PE);
  1169. up->port.icount.brk++;
  1170. /*
  1171. * We do the SysRQ and SAK checking
  1172. * here because otherwise the break
  1173. * may get masked by ignore_status_mask
  1174. * or read_status_mask.
  1175. */
  1176. if (uart_handle_break(&up->port))
  1177. goto ignore_char;
  1178. } else if (lsr & UART_LSR_PE)
  1179. up->port.icount.parity++;
  1180. else if (lsr & UART_LSR_FE)
  1181. up->port.icount.frame++;
  1182. if (lsr & UART_LSR_OE)
  1183. up->port.icount.overrun++;
  1184. /*
  1185. * Mask off conditions which should be ignored.
  1186. */
  1187. lsr &= up->port.read_status_mask;
  1188. if (lsr & UART_LSR_BI) {
  1189. DEBUG_INTR("handling break....");
  1190. flag = TTY_BREAK;
  1191. } else if (lsr & UART_LSR_PE)
  1192. flag = TTY_PARITY;
  1193. else if (lsr & UART_LSR_FE)
  1194. flag = TTY_FRAME;
  1195. }
  1196. if (uart_handle_sysrq_char(&up->port, ch))
  1197. goto ignore_char;
  1198. uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
  1199. ignore_char:
  1200. lsr = serial_inp(up, UART_LSR);
  1201. } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
  1202. spin_unlock(&up->port.lock);
  1203. tty_flip_buffer_push(tty);
  1204. spin_lock(&up->port.lock);
  1205. *status = lsr;
  1206. }
  1207. static void transmit_chars(struct uart_8250_port *up)
  1208. {
  1209. struct circ_buf *xmit = &up->port.info->xmit;
  1210. int count;
  1211. if (up->port.x_char) {
  1212. serial_outp(up, UART_TX, up->port.x_char);
  1213. up->port.icount.tx++;
  1214. up->port.x_char = 0;
  1215. return;
  1216. }
  1217. if (uart_tx_stopped(&up->port)) {
  1218. serial8250_stop_tx(&up->port);
  1219. return;
  1220. }
  1221. if (uart_circ_empty(xmit)) {
  1222. __stop_tx(up);
  1223. return;
  1224. }
  1225. count = up->tx_loadsz;
  1226. do {
  1227. serial_out(up, UART_TX, xmit->buf[xmit->tail]);
  1228. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  1229. up->port.icount.tx++;
  1230. if (uart_circ_empty(xmit))
  1231. break;
  1232. } while (--count > 0);
  1233. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  1234. uart_write_wakeup(&up->port);
  1235. DEBUG_INTR("THRE...");
  1236. if (uart_circ_empty(xmit))
  1237. __stop_tx(up);
  1238. }
  1239. static unsigned int check_modem_status(struct uart_8250_port *up)
  1240. {
  1241. unsigned int status = serial_in(up, UART_MSR);
  1242. status |= up->msr_saved_flags;
  1243. up->msr_saved_flags = 0;
  1244. if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
  1245. up->port.info != NULL) {
  1246. if (status & UART_MSR_TERI)
  1247. up->port.icount.rng++;
  1248. if (status & UART_MSR_DDSR)
  1249. up->port.icount.dsr++;
  1250. if (status & UART_MSR_DDCD)
  1251. uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
  1252. if (status & UART_MSR_DCTS)
  1253. uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
  1254. wake_up_interruptible(&up->port.info->delta_msr_wait);
  1255. }
  1256. return status;
  1257. }
  1258. /*
  1259. * This handles the interrupt from one port.
  1260. */
  1261. static void serial8250_handle_port(struct uart_8250_port *up)
  1262. {
  1263. unsigned int status;
  1264. unsigned long flags;
  1265. spin_lock_irqsave(&up->port.lock, flags);
  1266. status = serial_inp(up, UART_LSR);
  1267. DEBUG_INTR("status = %x...", status);
  1268. if (status & (UART_LSR_DR | UART_LSR_BI))
  1269. receive_chars(up, &status);
  1270. check_modem_status(up);
  1271. if (status & UART_LSR_THRE)
  1272. transmit_chars(up);
  1273. spin_unlock_irqrestore(&up->port.lock, flags);
  1274. }
  1275. /*
  1276. * This is the serial driver's interrupt routine.
  1277. *
  1278. * Arjan thinks the old way was overly complex, so it got simplified.
  1279. * Alan disagrees, saying that need the complexity to handle the weird
  1280. * nature of ISA shared interrupts. (This is a special exception.)
  1281. *
  1282. * In order to handle ISA shared interrupts properly, we need to check
  1283. * that all ports have been serviced, and therefore the ISA interrupt
  1284. * line has been de-asserted.
  1285. *
  1286. * This means we need to loop through all ports. checking that they
  1287. * don't have an interrupt pending.
  1288. */
  1289. static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
  1290. {
  1291. struct irq_info *i = dev_id;
  1292. struct list_head *l, *end = NULL;
  1293. int pass_counter = 0, handled = 0;
  1294. DEBUG_INTR("serial8250_interrupt(%d)...", irq);
  1295. spin_lock(&i->lock);
  1296. l = i->head;
  1297. do {
  1298. struct uart_8250_port *up;
  1299. unsigned int iir;
  1300. up = list_entry(l, struct uart_8250_port, list);
  1301. iir = serial_in(up, UART_IIR);
  1302. if (!(iir & UART_IIR_NO_INT)) {
  1303. serial8250_handle_port(up);
  1304. handled = 1;
  1305. end = NULL;
  1306. } else if (up->port.iotype == UPIO_DWAPB &&
  1307. (iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
  1308. /* The DesignWare APB UART has an Busy Detect (0x07)
  1309. * interrupt meaning an LCR write attempt occured while the
  1310. * UART was busy. The interrupt must be cleared by reading
  1311. * the UART status register (USR) and the LCR re-written. */
  1312. unsigned int status;
  1313. status = *(volatile u32 *)up->port.private_data;
  1314. serial_out(up, UART_LCR, up->lcr);
  1315. handled = 1;
  1316. end = NULL;
  1317. } else if (end == NULL)
  1318. end = l;
  1319. l = l->next;
  1320. if (l == i->head && pass_counter++ > PASS_LIMIT) {
  1321. /* If we hit this, we're dead. */
  1322. printk(KERN_ERR "serial8250: too much work for "
  1323. "irq%d\n", irq);
  1324. break;
  1325. }
  1326. } while (l != end);
  1327. spin_unlock(&i->lock);
  1328. DEBUG_INTR("end.\n");
  1329. return IRQ_RETVAL(handled);
  1330. }
  1331. /*
  1332. * To support ISA shared interrupts, we need to have one interrupt
  1333. * handler that ensures that the IRQ line has been deasserted
  1334. * before returning. Failing to do this will result in the IRQ
  1335. * line being stuck active, and, since ISA irqs are edge triggered,
  1336. * no more IRQs will be seen.
  1337. */
  1338. static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
  1339. {
  1340. spin_lock_irq(&i->lock);
  1341. if (!list_empty(i->head)) {
  1342. if (i->head == &up->list)
  1343. i->head = i->head->next;
  1344. list_del(&up->list);
  1345. } else {
  1346. BUG_ON(i->head != &up->list);
  1347. i->head = NULL;
  1348. }
  1349. spin_unlock_irq(&i->lock);
  1350. /* List empty so throw away the hash node */
  1351. if (i->head == NULL) {
  1352. hlist_del(&i->node);
  1353. kfree(i);
  1354. }
  1355. }
  1356. static int serial_link_irq_chain(struct uart_8250_port *up)
  1357. {
  1358. struct hlist_head *h;
  1359. struct hlist_node *n;
  1360. struct irq_info *i;
  1361. int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0;
  1362. mutex_lock(&hash_mutex);
  1363. h = &irq_lists[up->port.irq % NR_IRQ_HASH];
  1364. hlist_for_each(n, h) {
  1365. i = hlist_entry(n, struct irq_info, node);
  1366. if (i->irq == up->port.irq)
  1367. break;
  1368. }
  1369. if (n == NULL) {
  1370. i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
  1371. if (i == NULL) {
  1372. mutex_unlock(&hash_mutex);
  1373. return -ENOMEM;
  1374. }
  1375. spin_lock_init(&i->lock);
  1376. i->irq = up->port.irq;
  1377. hlist_add_head(&i->node, h);
  1378. }
  1379. mutex_unlock(&hash_mutex);
  1380. spin_lock_irq(&i->lock);
  1381. if (i->head) {
  1382. list_add(&up->list, i->head);
  1383. spin_unlock_irq(&i->lock);
  1384. ret = 0;
  1385. } else {
  1386. INIT_LIST_HEAD(&up->list);
  1387. i->head = &up->list;
  1388. spin_unlock_irq(&i->lock);
  1389. ret = request_irq(up->port.irq, serial8250_interrupt,
  1390. irq_flags, "serial", i);
  1391. if (ret < 0)
  1392. serial_do_unlink(i, up);
  1393. }
  1394. return ret;
  1395. }
  1396. static void serial_unlink_irq_chain(struct uart_8250_port *up)
  1397. {
  1398. struct irq_info *i;
  1399. struct hlist_node *n;
  1400. struct hlist_head *h;
  1401. mutex_lock(&hash_mutex);
  1402. h = &irq_lists[up->port.irq % NR_IRQ_HASH];
  1403. hlist_for_each(n, h) {
  1404. i = hlist_entry(n, struct irq_info, node);
  1405. if (i->irq == up->port.irq)
  1406. break;
  1407. }
  1408. BUG_ON(n == NULL);
  1409. BUG_ON(i->head == NULL);
  1410. if (list_empty(i->head))
  1411. free_irq(up->port.irq, i);
  1412. serial_do_unlink(i, up);
  1413. mutex_unlock(&hash_mutex);
  1414. }
  1415. /* Base timer interval for polling */
  1416. static inline int poll_timeout(int timeout)
  1417. {
  1418. return timeout > 6 ? (timeout / 2 - 2) : 1;
  1419. }
  1420. /*
  1421. * This function is used to handle ports that do not have an
  1422. * interrupt. This doesn't work very well for 16450's, but gives
  1423. * barely passable results for a 16550A. (Although at the expense
  1424. * of much CPU overhead).
  1425. */
  1426. static void serial8250_timeout(unsigned long data)
  1427. {
  1428. struct uart_8250_port *up = (struct uart_8250_port *)data;
  1429. unsigned int iir;
  1430. iir = serial_in(up, UART_IIR);
  1431. if (!(iir & UART_IIR_NO_INT))
  1432. serial8250_handle_port(up);
  1433. mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout));
  1434. }
  1435. static void serial8250_backup_timeout(unsigned long data)
  1436. {
  1437. struct uart_8250_port *up = (struct uart_8250_port *)data;
  1438. unsigned int iir, ier = 0, lsr;
  1439. unsigned long flags;
  1440. /*
  1441. * Must disable interrupts or else we risk racing with the interrupt
  1442. * based handler.
  1443. */
  1444. if (is_real_interrupt(up->port.irq)) {
  1445. ier = serial_in(up, UART_IER);
  1446. serial_out(up, UART_IER, 0);
  1447. }
  1448. iir = serial_in(up, UART_IIR);
  1449. /*
  1450. * This should be a safe test for anyone who doesn't trust the
  1451. * IIR bits on their UART, but it's specifically designed for
  1452. * the "Diva" UART used on the management processor on many HP
  1453. * ia64 and parisc boxes.
  1454. */
  1455. spin_lock_irqsave(&up->port.lock, flags);
  1456. lsr = serial_in(up, UART_LSR);
  1457. up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
  1458. spin_unlock_irqrestore(&up->port.lock, flags);
  1459. if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
  1460. (!uart_circ_empty(&up->port.info->xmit) || up->port.x_char) &&
  1461. (lsr & UART_LSR_THRE)) {
  1462. iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
  1463. iir |= UART_IIR_THRI;
  1464. }
  1465. if (!(iir & UART_IIR_NO_INT))
  1466. serial8250_handle_port(up);
  1467. if (is_real_interrupt(up->port.irq))
  1468. serial_out(up, UART_IER, ier);
  1469. /* Standard timer interval plus 0.2s to keep the port running */
  1470. mod_timer(&up->timer,
  1471. jiffies + poll_timeout(up->port.timeout) + HZ / 5);
  1472. }
  1473. static unsigned int serial8250_tx_empty(struct uart_port *port)
  1474. {
  1475. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1476. unsigned long flags;
  1477. unsigned int lsr;
  1478. spin_lock_irqsave(&up->port.lock, flags);
  1479. lsr = serial_in(up, UART_LSR);
  1480. up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
  1481. spin_unlock_irqrestore(&up->port.lock, flags);
  1482. return lsr & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
  1483. }
  1484. static unsigned int serial8250_get_mctrl(struct uart_port *port)
  1485. {
  1486. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1487. unsigned int status;
  1488. unsigned int ret;
  1489. status = check_modem_status(up);
  1490. ret = 0;
  1491. if (status & UART_MSR_DCD)
  1492. ret |= TIOCM_CAR;
  1493. if (status & UART_MSR_RI)
  1494. ret |= TIOCM_RNG;
  1495. if (status & UART_MSR_DSR)
  1496. ret |= TIOCM_DSR;
  1497. if (status & UART_MSR_CTS)
  1498. ret |= TIOCM_CTS;
  1499. return ret;
  1500. }
  1501. static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
  1502. {
  1503. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1504. unsigned char mcr = 0;
  1505. if (mctrl & TIOCM_RTS)
  1506. mcr |= UART_MCR_RTS;
  1507. if (mctrl & TIOCM_DTR)
  1508. mcr |= UART_MCR_DTR;
  1509. if (mctrl & TIOCM_OUT1)
  1510. mcr |= UART_MCR_OUT1;
  1511. if (mctrl & TIOCM_OUT2)
  1512. mcr |= UART_MCR_OUT2;
  1513. if (mctrl & TIOCM_LOOP)
  1514. mcr |= UART_MCR_LOOP;
  1515. mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
  1516. serial_out(up, UART_MCR, mcr);
  1517. }
  1518. static void serial8250_break_ctl(struct uart_port *port, int break_state)
  1519. {
  1520. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1521. unsigned long flags;
  1522. spin_lock_irqsave(&up->port.lock, flags);
  1523. if (break_state == -1)
  1524. up->lcr |= UART_LCR_SBC;
  1525. else
  1526. up->lcr &= ~UART_LCR_SBC;
  1527. serial_out(up, UART_LCR, up->lcr);
  1528. spin_unlock_irqrestore(&up->port.lock, flags);
  1529. }
  1530. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  1531. /*
  1532. * Wait for transmitter & holding register to empty
  1533. */
  1534. static void wait_for_xmitr(struct uart_8250_port *up, int bits)
  1535. {
  1536. unsigned int status, tmout = 10000;
  1537. /* Wait up to 10ms for the character(s) to be sent. */
  1538. do {
  1539. status = serial_in(up, UART_LSR);
  1540. up->lsr_saved_flags |= status & LSR_SAVE_FLAGS;
  1541. if (--tmout == 0)
  1542. break;
  1543. udelay(1);
  1544. } while ((status & bits) != bits);
  1545. /* Wait up to 1s for flow control if necessary */
  1546. if (up->port.flags & UPF_CONS_FLOW) {
  1547. unsigned int tmout;
  1548. for (tmout = 1000000; tmout; tmout--) {
  1549. unsigned int msr = serial_in(up, UART_MSR);
  1550. up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
  1551. if (msr & UART_MSR_CTS)
  1552. break;
  1553. udelay(1);
  1554. touch_nmi_watchdog();
  1555. }
  1556. }
  1557. }
  1558. #ifdef CONFIG_CONSOLE_POLL
  1559. /*
  1560. * Console polling routines for writing and reading from the uart while
  1561. * in an interrupt or debug context.
  1562. */
  1563. static int serial8250_get_poll_char(struct uart_port *port)
  1564. {
  1565. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1566. unsigned char lsr = serial_inp(up, UART_LSR);
  1567. while (!(lsr & UART_LSR_DR))
  1568. lsr = serial_inp(up, UART_LSR);
  1569. return serial_inp(up, UART_RX);
  1570. }
  1571. static void serial8250_put_poll_char(struct uart_port *port,
  1572. unsigned char c)
  1573. {
  1574. unsigned int ier;
  1575. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1576. /*
  1577. * First save the IER then disable the interrupts
  1578. */
  1579. ier = serial_in(up, UART_IER);
  1580. if (up->capabilities & UART_CAP_UUE)
  1581. serial_out(up, UART_IER, UART_IER_UUE);
  1582. else
  1583. serial_out(up, UART_IER, 0);
  1584. wait_for_xmitr(up, BOTH_EMPTY);
  1585. /*
  1586. * Send the character out.
  1587. * If a LF, also do CR...
  1588. */
  1589. serial_out(up, UART_TX, c);
  1590. if (c == 10) {
  1591. wait_for_xmitr(up, BOTH_EMPTY);
  1592. serial_out(up, UART_TX, 13);
  1593. }
  1594. /*
  1595. * Finally, wait for transmitter to become empty
  1596. * and restore the IER
  1597. */
  1598. wait_for_xmitr(up, BOTH_EMPTY);
  1599. serial_out(up, UART_IER, ier);
  1600. }
  1601. #endif /* CONFIG_CONSOLE_POLL */
  1602. static int serial8250_startup(struct uart_port *port)
  1603. {
  1604. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1605. unsigned long flags;
  1606. unsigned char lsr, iir;
  1607. int retval;
  1608. up->capabilities = uart_config[up->port.type].flags;
  1609. up->mcr = 0;
  1610. if (up->port.type == PORT_16C950) {
  1611. /* Wake up and initialize UART */
  1612. up->acr = 0;
  1613. serial_outp(up, UART_LCR, 0xBF);
  1614. serial_outp(up, UART_EFR, UART_EFR_ECB);
  1615. serial_outp(up, UART_IER, 0);
  1616. serial_outp(up, UART_LCR, 0);
  1617. serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
  1618. serial_outp(up, UART_LCR, 0xBF);
  1619. serial_outp(up, UART_EFR, UART_EFR_ECB);
  1620. serial_outp(up, UART_LCR, 0);
  1621. }
  1622. #ifdef CONFIG_SERIAL_8250_RSA
  1623. /*
  1624. * If this is an RSA port, see if we can kick it up to the
  1625. * higher speed clock.
  1626. */
  1627. enable_rsa(up);
  1628. #endif
  1629. /*
  1630. * Clear the FIFO buffers and disable them.
  1631. * (they will be reenabled in set_termios())
  1632. */
  1633. serial8250_clear_fifos(up);
  1634. /*
  1635. * Clear the interrupt registers.
  1636. */
  1637. (void) serial_inp(up, UART_LSR);
  1638. (void) serial_inp(up, UART_RX);
  1639. (void) serial_inp(up, UART_IIR);
  1640. (void) serial_inp(up, UART_MSR);
  1641. /*
  1642. * At this point, there's no way the LSR could still be 0xff;
  1643. * if it is, then bail out, because there's likely no UART
  1644. * here.
  1645. */
  1646. if (!(up->port.flags & UPF_BUGGY_UART) &&
  1647. (serial_inp(up, UART_LSR) == 0xff)) {
  1648. printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
  1649. serial_index(&up->port));
  1650. return -ENODEV;
  1651. }
  1652. /*
  1653. * For a XR16C850, we need to set the trigger levels
  1654. */
  1655. if (up->port.type == PORT_16850) {
  1656. unsigned char fctr;
  1657. serial_outp(up, UART_LCR, 0xbf);
  1658. fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
  1659. serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX);
  1660. serial_outp(up, UART_TRG, UART_TRG_96);
  1661. serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX);
  1662. serial_outp(up, UART_TRG, UART_TRG_96);
  1663. serial_outp(up, UART_LCR, 0);
  1664. }
  1665. if (is_real_interrupt(up->port.irq)) {
  1666. unsigned char iir1;
  1667. /*
  1668. * Test for UARTs that do not reassert THRE when the
  1669. * transmitter is idle and the interrupt has already
  1670. * been cleared. Real 16550s should always reassert
  1671. * this interrupt whenever the transmitter is idle and
  1672. * the interrupt is enabled. Delays are necessary to
  1673. * allow register changes to become visible.
  1674. */
  1675. spin_lock_irqsave(&up->port.lock, flags);
  1676. if (up->port.flags & UPF_SHARE_IRQ)
  1677. disable_irq_nosync(up->port.irq);
  1678. wait_for_xmitr(up, UART_LSR_THRE);
  1679. serial_out_sync(up, UART_IER, UART_IER_THRI);
  1680. udelay(1); /* allow THRE to set */
  1681. iir1 = serial_in(up, UART_IIR);
  1682. serial_out(up, UART_IER, 0);
  1683. serial_out_sync(up, UART_IER, UART_IER_THRI);
  1684. udelay(1); /* allow a working UART time to re-assert THRE */
  1685. iir = serial_in(up, UART_IIR);
  1686. serial_out(up, UART_IER, 0);
  1687. if (up->port.flags & UPF_SHARE_IRQ)
  1688. enable_irq(up->port.irq);
  1689. spin_unlock_irqrestore(&up->port.lock, flags);
  1690. /*
  1691. * If the interrupt is not reasserted, setup a timer to
  1692. * kick the UART on a regular basis.
  1693. */
  1694. if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) {
  1695. up->bugs |= UART_BUG_THRE;
  1696. pr_debug("ttyS%d - using backup timer\n",
  1697. serial_index(port));
  1698. }
  1699. }
  1700. /*
  1701. * The above check will only give an accurate result the first time
  1702. * the port is opened so this value needs to be preserved.
  1703. */
  1704. if (up->bugs & UART_BUG_THRE) {
  1705. up->timer.function = serial8250_backup_timeout;
  1706. up->timer.data = (unsigned long)up;
  1707. mod_timer(&up->timer, jiffies +
  1708. poll_timeout(up->port.timeout) + HZ / 5);
  1709. }
  1710. /*
  1711. * If the "interrupt" for this port doesn't correspond with any
  1712. * hardware interrupt, we use a timer-based system. The original
  1713. * driver used to do this with IRQ0.
  1714. */
  1715. if (!is_real_interrupt(up->port.irq)) {
  1716. up->timer.data = (unsigned long)up;
  1717. mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout));
  1718. } else {
  1719. retval = serial_link_irq_chain(up);
  1720. if (retval)
  1721. return retval;
  1722. }
  1723. /*
  1724. * Now, initialize the UART
  1725. */
  1726. serial_outp(up, UART_LCR, UART_LCR_WLEN8);
  1727. spin_lock_irqsave(&up->port.lock, flags);
  1728. if (up->port.flags & UPF_FOURPORT) {
  1729. if (!is_real_interrupt(up->port.irq))
  1730. up->port.mctrl |= TIOCM_OUT1;
  1731. } else
  1732. /*
  1733. * Most PC uarts need OUT2 raised to enable interrupts.
  1734. */
  1735. if (is_real_interrupt(up->port.irq))
  1736. up->port.mctrl |= TIOCM_OUT2;
  1737. serial8250_set_mctrl(&up->port, up->port.mctrl);
  1738. /*
  1739. * Do a quick test to see if we receive an
  1740. * interrupt when we enable the TX irq.
  1741. */
  1742. serial_outp(up, UART_IER, UART_IER_THRI);
  1743. lsr = serial_in(up, UART_LSR);
  1744. iir = serial_in(up, UART_IIR);
  1745. serial_outp(up, UART_IER, 0);
  1746. if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
  1747. if (!(up->bugs & UART_BUG_TXEN)) {
  1748. up->bugs |= UART_BUG_TXEN;
  1749. pr_debug("ttyS%d - enabling bad tx status workarounds\n",
  1750. serial_index(port));
  1751. }
  1752. } else {
  1753. up->bugs &= ~UART_BUG_TXEN;
  1754. }
  1755. spin_unlock_irqrestore(&up->port.lock, flags);
  1756. /*
  1757. * Clear the interrupt registers again for luck, and clear the
  1758. * saved flags to avoid getting false values from polling
  1759. * routines or the previous session.
  1760. */
  1761. serial_inp(up, UART_LSR);
  1762. serial_inp(up, UART_RX);
  1763. serial_inp(up, UART_IIR);
  1764. serial_inp(up, UART_MSR);
  1765. up->lsr_saved_flags = 0;
  1766. up->msr_saved_flags = 0;
  1767. /*
  1768. * Finally, enable interrupts. Note: Modem status interrupts
  1769. * are set via set_termios(), which will be occurring imminently
  1770. * anyway, so we don't enable them here.
  1771. */
  1772. up->ier = UART_IER_RLSI | UART_IER_RDI;
  1773. serial_outp(up, UART_IER, up->ier);
  1774. if (up->port.flags & UPF_FOURPORT) {
  1775. unsigned int icp;
  1776. /*
  1777. * Enable interrupts on the AST Fourport board
  1778. */
  1779. icp = (up->port.iobase & 0xfe0) | 0x01f;
  1780. outb_p(0x80, icp);
  1781. (void) inb_p(icp);
  1782. }
  1783. return 0;
  1784. }
  1785. static void serial8250_shutdown(struct uart_port *port)
  1786. {
  1787. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1788. unsigned long flags;
  1789. /*
  1790. * Disable interrupts from this port
  1791. */
  1792. up->ier = 0;
  1793. serial_outp(up, UART_IER, 0);
  1794. spin_lock_irqsave(&up->port.lock, flags);
  1795. if (up->port.flags & UPF_FOURPORT) {
  1796. /* reset interrupts on the AST Fourport board */
  1797. inb((up->port.iobase & 0xfe0) | 0x1f);
  1798. up->port.mctrl |= TIOCM_OUT1;
  1799. } else
  1800. up->port.mctrl &= ~TIOCM_OUT2;
  1801. serial8250_set_mctrl(&up->port, up->port.mctrl);
  1802. spin_unlock_irqrestore(&up->port.lock, flags);
  1803. /*
  1804. * Disable break condition and FIFOs
  1805. */
  1806. serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
  1807. serial8250_clear_fifos(up);
  1808. #ifdef CONFIG_SERIAL_8250_RSA
  1809. /*
  1810. * Reset the RSA board back to 115kbps compat mode.
  1811. */
  1812. disable_rsa(up);
  1813. #endif
  1814. /*
  1815. * Read data port to reset things, and then unlink from
  1816. * the IRQ chain.
  1817. */
  1818. (void) serial_in(up, UART_RX);
  1819. del_timer_sync(&up->timer);
  1820. up->timer.function = serial8250_timeout;
  1821. if (is_real_interrupt(up->port.irq))
  1822. serial_unlink_irq_chain(up);
  1823. }
  1824. static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
  1825. {
  1826. unsigned int quot;
  1827. /*
  1828. * Handle magic divisors for baud rates above baud_base on
  1829. * SMSC SuperIO chips.
  1830. */
  1831. if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
  1832. baud == (port->uartclk/4))
  1833. quot = 0x8001;
  1834. else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
  1835. baud == (port->uartclk/8))
  1836. quot = 0x8002;
  1837. else
  1838. quot = uart_get_divisor(port, baud);
  1839. return quot;
  1840. }
  1841. static void
  1842. serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
  1843. struct ktermios *old)
  1844. {
  1845. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1846. unsigned char cval, fcr = 0;
  1847. unsigned long flags;
  1848. unsigned int baud, quot;
  1849. switch (termios->c_cflag & CSIZE) {
  1850. case CS5:
  1851. cval = UART_LCR_WLEN5;
  1852. break;
  1853. case CS6:
  1854. cval = UART_LCR_WLEN6;
  1855. break;
  1856. case CS7:
  1857. cval = UART_LCR_WLEN7;
  1858. break;
  1859. default:
  1860. case CS8:
  1861. cval = UART_LCR_WLEN8;
  1862. break;
  1863. }
  1864. if (termios->c_cflag & CSTOPB)
  1865. cval |= UART_LCR_STOP;
  1866. if (termios->c_cflag & PARENB)
  1867. cval |= UART_LCR_PARITY;
  1868. if (!(termios->c_cflag & PARODD))
  1869. cval |= UART_LCR_EPAR;
  1870. #ifdef CMSPAR
  1871. if (termios->c_cflag & CMSPAR)
  1872. cval |= UART_LCR_SPAR;
  1873. #endif
  1874. /*
  1875. * Ask the core to calculate the divisor for us.
  1876. */
  1877. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  1878. quot = serial8250_get_divisor(port, baud);
  1879. /*
  1880. * Oxford Semi 952 rev B workaround
  1881. */
  1882. if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
  1883. quot++;
  1884. if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) {
  1885. if (baud < 2400)
  1886. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
  1887. else
  1888. fcr = uart_config[up->port.type].fcr;
  1889. }
  1890. /*
  1891. * MCR-based auto flow control. When AFE is enabled, RTS will be
  1892. * deasserted when the receive FIFO contains more characters than
  1893. * the trigger, or the MCR RTS bit is cleared. In the case where
  1894. * the remote UART is not using CTS auto flow control, we must
  1895. * have sufficient FIFO entries for the latency of the remote
  1896. * UART to respond. IOW, at least 32 bytes of FIFO.
  1897. */
  1898. if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) {
  1899. up->mcr &= ~UART_MCR_AFE;
  1900. if (termios->c_cflag & CRTSCTS)
  1901. up->mcr |= UART_MCR_AFE;
  1902. }
  1903. /*
  1904. * Ok, we're now changing the port state. Do it with
  1905. * interrupts disabled.
  1906. */
  1907. spin_lock_irqsave(&up->port.lock, flags);
  1908. /*
  1909. * Update the per-port timeout.
  1910. */
  1911. uart_update_timeout(port, termios->c_cflag, baud);
  1912. up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
  1913. if (termios->c_iflag & INPCK)
  1914. up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
  1915. if (termios->c_iflag & (BRKINT | PARMRK))
  1916. up->port.read_status_mask |= UART_LSR_BI;
  1917. /*
  1918. * Characteres to ignore
  1919. */
  1920. up->port.ignore_status_mask = 0;
  1921. if (termios->c_iflag & IGNPAR)
  1922. up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
  1923. if (termios->c_iflag & IGNBRK) {
  1924. up->port.ignore_status_mask |= UART_LSR_BI;
  1925. /*
  1926. * If we're ignoring parity and break indicators,
  1927. * ignore overruns too (for real raw support).
  1928. */
  1929. if (termios->c_iflag & IGNPAR)
  1930. up->port.ignore_status_mask |= UART_LSR_OE;
  1931. }
  1932. /*
  1933. * ignore all characters if CREAD is not set
  1934. */
  1935. if ((termios->c_cflag & CREAD) == 0)
  1936. up->port.ignore_status_mask |= UART_LSR_DR;
  1937. /*
  1938. * CTS flow control flag and modem status interrupts
  1939. */
  1940. up->ier &= ~UART_IER_MSI;
  1941. if (!(up->bugs & UART_BUG_NOMSR) &&
  1942. UART_ENABLE_MS(&up->port, termios->c_cflag))
  1943. up->ier |= UART_IER_MSI;
  1944. if (up->capabilities & UART_CAP_UUE)
  1945. up->ier |= UART_IER_UUE | UART_IER_RTOIE;
  1946. serial_out(up, UART_IER, up->ier);
  1947. if (up->capabilities & UART_CAP_EFR) {
  1948. unsigned char efr = 0;
  1949. /*
  1950. * TI16C752/Startech hardware flow control. FIXME:
  1951. * - TI16C752 requires control thresholds to be set.
  1952. * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
  1953. */
  1954. if (termios->c_cflag & CRTSCTS)
  1955. efr |= UART_EFR_CTS;
  1956. serial_outp(up, UART_LCR, 0xBF);
  1957. serial_outp(up, UART_EFR, efr);
  1958. }
  1959. #ifdef CONFIG_ARCH_OMAP15XX
  1960. /* Workaround to enable 115200 baud on OMAP1510 internal ports */
  1961. if (cpu_is_omap1510() && is_omap_port((unsigned int)up->port.membase)) {
  1962. if (baud == 115200) {
  1963. quot = 1;
  1964. serial_out(up, UART_OMAP_OSC_12M_SEL, 1);
  1965. } else
  1966. serial_out(up, UART_OMAP_OSC_12M_SEL, 0);
  1967. }
  1968. #endif
  1969. if (up->capabilities & UART_NATSEMI) {
  1970. /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */
  1971. serial_outp(up, UART_LCR, 0xe0);
  1972. } else {
  1973. serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
  1974. }
  1975. serial_dl_write(up, quot);
  1976. /*
  1977. * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
  1978. * is written without DLAB set, this mode will be disabled.
  1979. */
  1980. if (up->port.type == PORT_16750)
  1981. serial_outp(up, UART_FCR, fcr);
  1982. serial_outp(up, UART_LCR, cval); /* reset DLAB */
  1983. up->lcr = cval; /* Save LCR */
  1984. if (up->port.type != PORT_16750) {
  1985. if (fcr & UART_FCR_ENABLE_FIFO) {
  1986. /* emulated UARTs (Lucent Venus 167x) need two steps */
  1987. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  1988. }
  1989. serial_outp(up, UART_FCR, fcr); /* set fcr */
  1990. }
  1991. serial8250_set_mctrl(&up->port, up->port.mctrl);
  1992. spin_unlock_irqrestore(&up->port.lock, flags);
  1993. /* Don't rewrite B0 */
  1994. if (tty_termios_baud_rate(termios))
  1995. tty_termios_encode_baud_rate(termios, baud, baud);
  1996. }
  1997. static void
  1998. serial8250_pm(struct uart_port *port, unsigned int state,
  1999. unsigned int oldstate)
  2000. {
  2001. struct uart_8250_port *p = (struct uart_8250_port *)port;
  2002. serial8250_set_sleep(p, state != 0);
  2003. if (p->pm)
  2004. p->pm(port, state, oldstate);
  2005. }
  2006. /*
  2007. * Resource handling.
  2008. */
  2009. static int serial8250_request_std_resource(struct uart_8250_port *up)
  2010. {
  2011. unsigned int size = 8 << up->port.regshift;
  2012. int ret = 0;
  2013. switch (up->port.iotype) {
  2014. case UPIO_AU:
  2015. size = 0x100000;
  2016. /* fall thru */
  2017. case UPIO_TSI:
  2018. case UPIO_MEM32:
  2019. case UPIO_MEM:
  2020. case UPIO_DWAPB:
  2021. if (!up->port.mapbase)
  2022. break;
  2023. if (!request_mem_region(up->port.mapbase, size, "serial")) {
  2024. ret = -EBUSY;
  2025. break;
  2026. }
  2027. if (up->port.flags & UPF_IOREMAP) {
  2028. up->port.membase = ioremap_nocache(up->port.mapbase,
  2029. size);
  2030. if (!up->port.membase) {
  2031. release_mem_region(up->port.mapbase, size);
  2032. ret = -ENOMEM;
  2033. }
  2034. }
  2035. break;
  2036. case UPIO_HUB6:
  2037. case UPIO_PORT:
  2038. if (!request_region(up->port.iobase, size, "serial"))
  2039. ret = -EBUSY;
  2040. break;
  2041. }
  2042. return ret;
  2043. }
  2044. static void serial8250_release_std_resource(struct uart_8250_port *up)
  2045. {
  2046. unsigned int size = 8 << up->port.regshift;
  2047. switch (up->port.iotype) {
  2048. case UPIO_AU:
  2049. size = 0x100000;
  2050. /* fall thru */
  2051. case UPIO_TSI:
  2052. case UPIO_MEM32:
  2053. case UPIO_MEM:
  2054. case UPIO_DWAPB:
  2055. if (!up->port.mapbase)
  2056. break;
  2057. if (up->port.flags & UPF_IOREMAP) {
  2058. iounmap(up->port.membase);
  2059. up->port.membase = NULL;
  2060. }
  2061. release_mem_region(up->port.mapbase, size);
  2062. break;
  2063. case UPIO_HUB6:
  2064. case UPIO_PORT:
  2065. release_region(up->port.iobase, size);
  2066. break;
  2067. }
  2068. }
  2069. static int serial8250_request_rsa_resource(struct uart_8250_port *up)
  2070. {
  2071. unsigned long start = UART_RSA_BASE << up->port.regshift;
  2072. unsigned int size = 8 << up->port.regshift;
  2073. int ret = -EINVAL;
  2074. switch (up->port.iotype) {
  2075. case UPIO_HUB6:
  2076. case UPIO_PORT:
  2077. start += up->port.iobase;
  2078. if (request_region(start, size, "serial-rsa"))
  2079. ret = 0;
  2080. else
  2081. ret = -EBUSY;
  2082. break;
  2083. }
  2084. return ret;
  2085. }
  2086. static void serial8250_release_rsa_resource(struct uart_8250_port *up)
  2087. {
  2088. unsigned long offset = UART_RSA_BASE << up->port.regshift;
  2089. unsigned int size = 8 << up->port.regshift;
  2090. switch (up->port.iotype) {
  2091. case UPIO_HUB6:
  2092. case UPIO_PORT:
  2093. release_region(up->port.iobase + offset, size);
  2094. break;
  2095. }
  2096. }
  2097. static void serial8250_release_port(struct uart_port *port)
  2098. {
  2099. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2100. serial8250_release_std_resource(up);
  2101. if (up->port.type == PORT_RSA)
  2102. serial8250_release_rsa_resource(up);
  2103. }
  2104. static int serial8250_request_port(struct uart_port *port)
  2105. {
  2106. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2107. int ret = 0;
  2108. ret = serial8250_request_std_resource(up);
  2109. if (ret == 0 && up->port.type == PORT_RSA) {
  2110. ret = serial8250_request_rsa_resource(up);
  2111. if (ret < 0)
  2112. serial8250_release_std_resource(up);
  2113. }
  2114. return ret;
  2115. }
  2116. static void serial8250_config_port(struct uart_port *port, int flags)
  2117. {
  2118. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2119. int probeflags = PROBE_ANY;
  2120. int ret;
  2121. /*
  2122. * Find the region that we can probe for. This in turn
  2123. * tells us whether we can probe for the type of port.
  2124. */
  2125. ret = serial8250_request_std_resource(up);
  2126. if (ret < 0)
  2127. return;
  2128. ret = serial8250_request_rsa_resource(up);
  2129. if (ret < 0)
  2130. probeflags &= ~PROBE_RSA;
  2131. if (flags & UART_CONFIG_TYPE)
  2132. autoconfig(up, probeflags);
  2133. if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
  2134. autoconfig_irq(up);
  2135. if (up->port.type != PORT_RSA && probeflags & PROBE_RSA)
  2136. serial8250_release_rsa_resource(up);
  2137. if (up->port.type == PORT_UNKNOWN)
  2138. serial8250_release_std_resource(up);
  2139. }
  2140. static int
  2141. serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
  2142. {
  2143. if (ser->irq >= NR_IRQS || ser->irq < 0 ||
  2144. ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
  2145. ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
  2146. ser->type == PORT_STARTECH)
  2147. return -EINVAL;
  2148. return 0;
  2149. }
  2150. static const char *
  2151. serial8250_type(struct uart_port *port)
  2152. {
  2153. int type = port->type;
  2154. if (type >= ARRAY_SIZE(uart_config))
  2155. type = 0;
  2156. return uart_config[type].name;
  2157. }
  2158. static struct uart_ops serial8250_pops = {
  2159. .tx_empty = serial8250_tx_empty,
  2160. .set_mctrl = serial8250_set_mctrl,
  2161. .get_mctrl = serial8250_get_mctrl,
  2162. .stop_tx = serial8250_stop_tx,
  2163. .start_tx = serial8250_start_tx,
  2164. .stop_rx = serial8250_stop_rx,
  2165. .enable_ms = serial8250_enable_ms,
  2166. .break_ctl = serial8250_break_ctl,
  2167. .startup = serial8250_startup,
  2168. .shutdown = serial8250_shutdown,
  2169. .set_termios = serial8250_set_termios,
  2170. .pm = serial8250_pm,
  2171. .type = serial8250_type,
  2172. .release_port = serial8250_release_port,
  2173. .request_port = serial8250_request_port,
  2174. .config_port = serial8250_config_port,
  2175. .verify_port = serial8250_verify_port,
  2176. #ifdef CONFIG_CONSOLE_POLL
  2177. .poll_get_char = serial8250_get_poll_char,
  2178. .poll_put_char = serial8250_put_poll_char,
  2179. #endif
  2180. };
  2181. static struct uart_8250_port serial8250_ports[UART_NR];
  2182. static void __init serial8250_isa_init_ports(void)
  2183. {
  2184. struct uart_8250_port *up;
  2185. static int first = 1;
  2186. int i;
  2187. if (!first)
  2188. return;
  2189. first = 0;
  2190. for (i = 0; i < nr_uarts; i++) {
  2191. struct uart_8250_port *up = &serial8250_ports[i];
  2192. up->port.line = i;
  2193. spin_lock_init(&up->port.lock);
  2194. init_timer(&up->timer);
  2195. up->timer.function = serial8250_timeout;
  2196. /*
  2197. * ALPHA_KLUDGE_MCR needs to be killed.
  2198. */
  2199. up->mcr_mask = ~ALPHA_KLUDGE_MCR;
  2200. up->mcr_force = ALPHA_KLUDGE_MCR;
  2201. up->port.ops = &serial8250_pops;
  2202. }
  2203. for (i = 0, up = serial8250_ports;
  2204. i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
  2205. i++, up++) {
  2206. up->port.iobase = old_serial_port[i].port;
  2207. up->port.irq = irq_canonicalize(old_serial_port[i].irq);
  2208. up->port.uartclk = old_serial_port[i].baud_base * 16;
  2209. up->port.flags = old_serial_port[i].flags;
  2210. up->port.hub6 = old_serial_port[i].hub6;
  2211. up->port.membase = old_serial_port[i].iomem_base;
  2212. up->port.iotype = old_serial_port[i].io_type;
  2213. up->port.regshift = old_serial_port[i].iomem_reg_shift;
  2214. if (share_irqs)
  2215. up->port.flags |= UPF_SHARE_IRQ;
  2216. }
  2217. }
  2218. static void __init
  2219. serial8250_register_ports(struct uart_driver *drv, struct device *dev)
  2220. {
  2221. int i;
  2222. serial8250_isa_init_ports();
  2223. for (i = 0; i < nr_uarts; i++) {
  2224. struct uart_8250_port *up = &serial8250_ports[i];
  2225. up->port.dev = dev;
  2226. uart_add_one_port(drv, &up->port);
  2227. }
  2228. }
  2229. #ifdef CONFIG_SERIAL_8250_CONSOLE
  2230. static void serial8250_console_putchar(struct uart_port *port, int ch)
  2231. {
  2232. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2233. wait_for_xmitr(up, UART_LSR_THRE);
  2234. serial_out(up, UART_TX, ch);
  2235. }
  2236. /*
  2237. * Print a string to the serial port trying not to disturb
  2238. * any possible real use of the port...
  2239. *
  2240. * The console_lock must be held when we get here.
  2241. */
  2242. static void
  2243. serial8250_console_write(struct console *co, const char *s, unsigned int count)
  2244. {
  2245. struct uart_8250_port *up = &serial8250_ports[co->index];
  2246. unsigned long flags;
  2247. unsigned int ier;
  2248. int locked = 1;
  2249. touch_nmi_watchdog();
  2250. local_irq_save(flags);
  2251. if (up->port.sysrq) {
  2252. /* serial8250_handle_port() already took the lock */
  2253. locked = 0;
  2254. } else if (oops_in_progress) {
  2255. locked = spin_trylock(&up->port.lock);
  2256. } else
  2257. spin_lock(&up->port.lock);
  2258. /*
  2259. * First save the IER then disable the interrupts
  2260. */
  2261. ier = serial_in(up, UART_IER);
  2262. if (up->capabilities & UART_CAP_UUE)
  2263. serial_out(up, UART_IER, UART_IER_UUE);
  2264. else
  2265. serial_out(up, UART_IER, 0);
  2266. uart_console_write(&up->port, s, count, serial8250_console_putchar);
  2267. /*
  2268. * Finally, wait for transmitter to become empty
  2269. * and restore the IER
  2270. */
  2271. wait_for_xmitr(up, BOTH_EMPTY);
  2272. serial_out(up, UART_IER, ier);
  2273. /*
  2274. * The receive handling will happen properly because the
  2275. * receive ready bit will still be set; it is not cleared
  2276. * on read. However, modem control will not, we must
  2277. * call it if we have saved something in the saved flags
  2278. * while processing with interrupts off.
  2279. */
  2280. if (up->msr_saved_flags)
  2281. check_modem_status(up);
  2282. if (locked)
  2283. spin_unlock(&up->port.lock);
  2284. local_irq_restore(flags);
  2285. }
  2286. static int __init serial8250_console_setup(struct console *co, char *options)
  2287. {
  2288. struct uart_port *port;
  2289. int baud = 9600;
  2290. int bits = 8;
  2291. int parity = 'n';
  2292. int flow = 'n';
  2293. /*
  2294. * Check whether an invalid uart number has been specified, and
  2295. * if so, search for the first available port that does have
  2296. * console support.
  2297. */
  2298. if (co->index >= nr_uarts)
  2299. co->index = 0;
  2300. port = &serial8250_ports[co->index].port;
  2301. if (!port->iobase && !port->membase)
  2302. return -ENODEV;
  2303. if (options)
  2304. uart_parse_options(options, &baud, &parity, &bits, &flow);
  2305. return uart_set_options(port, co, baud, parity, bits, flow);
  2306. }
  2307. static int serial8250_console_early_setup(void)
  2308. {
  2309. return serial8250_find_port_for_earlycon();
  2310. }
  2311. static struct console serial8250_console = {
  2312. .name = "ttyS",
  2313. .write = serial8250_console_write,
  2314. .device = uart_console_device,
  2315. .setup = serial8250_console_setup,
  2316. .early_setup = serial8250_console_early_setup,
  2317. .flags = CON_PRINTBUFFER,
  2318. .index = -1,
  2319. .data = &serial8250_reg,
  2320. };
  2321. static int __init serial8250_console_init(void)
  2322. {
  2323. if (nr_uarts > UART_NR)
  2324. nr_uarts = UART_NR;
  2325. serial8250_isa_init_ports();
  2326. register_console(&serial8250_console);
  2327. return 0;
  2328. }
  2329. console_initcall(serial8250_console_init);
  2330. int serial8250_find_port(struct uart_port *p)
  2331. {
  2332. int line;
  2333. struct uart_port *port;
  2334. for (line = 0; line < nr_uarts; line++) {
  2335. port = &serial8250_ports[line].port;
  2336. if (uart_match_port(p, port))
  2337. return line;
  2338. }
  2339. return -ENODEV;
  2340. }
  2341. #define SERIAL8250_CONSOLE &serial8250_console
  2342. #else
  2343. #define SERIAL8250_CONSOLE NULL
  2344. #endif
  2345. static struct uart_driver serial8250_reg = {
  2346. .owner = THIS_MODULE,
  2347. .driver_name = "serial",
  2348. .dev_name = "ttyS",
  2349. .major = TTY_MAJOR,
  2350. .minor = 64,
  2351. .cons = SERIAL8250_CONSOLE,
  2352. };
  2353. /*
  2354. * early_serial_setup - early registration for 8250 ports
  2355. *
  2356. * Setup an 8250 port structure prior to console initialisation. Use
  2357. * after console initialisation will cause undefined behaviour.
  2358. */
  2359. int __init early_serial_setup(struct uart_port *port)
  2360. {
  2361. if (port->line >= ARRAY_SIZE(serial8250_ports))
  2362. return -ENODEV;
  2363. serial8250_isa_init_ports();
  2364. serial8250_ports[port->line].port = *port;
  2365. serial8250_ports[port->line].port.ops = &serial8250_pops;
  2366. return 0;
  2367. }
  2368. /**
  2369. * serial8250_suspend_port - suspend one serial port
  2370. * @line: serial line number
  2371. *
  2372. * Suspend one serial port.
  2373. */
  2374. void serial8250_suspend_port(int line)
  2375. {
  2376. uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
  2377. }
  2378. /**
  2379. * serial8250_resume_port - resume one serial port
  2380. * @line: serial line number
  2381. *
  2382. * Resume one serial port.
  2383. */
  2384. void serial8250_resume_port(int line)
  2385. {
  2386. struct uart_8250_port *up = &serial8250_ports[line];
  2387. if (up->capabilities & UART_NATSEMI) {
  2388. unsigned char tmp;
  2389. /* Ensure it's still in high speed mode */
  2390. serial_outp(up, UART_LCR, 0xE0);
  2391. tmp = serial_in(up, 0x04); /* EXCR2 */
  2392. tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
  2393. tmp |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
  2394. serial_outp(up, 0x04, tmp);
  2395. serial_outp(up, UART_LCR, 0);
  2396. }
  2397. uart_resume_port(&serial8250_reg, &up->port);
  2398. }
  2399. /*
  2400. * Register a set of serial devices attached to a platform device. The
  2401. * list is terminated with a zero flags entry, which means we expect
  2402. * all entries to have at least UPF_BOOT_AUTOCONF set.
  2403. */
  2404. static int __devinit serial8250_probe(struct platform_device *dev)
  2405. {
  2406. struct plat_serial8250_port *p = dev->dev.platform_data;
  2407. struct uart_port port;
  2408. int ret, i;
  2409. memset(&port, 0, sizeof(struct uart_port));
  2410. for (i = 0; p && p->flags != 0; p++, i++) {
  2411. port.iobase = p->iobase;
  2412. port.membase = p->membase;
  2413. port.irq = p->irq;
  2414. port.uartclk = p->uartclk;
  2415. port.regshift = p->regshift;
  2416. port.iotype = p->iotype;
  2417. port.flags = p->flags;
  2418. port.mapbase = p->mapbase;
  2419. port.hub6 = p->hub6;
  2420. port.private_data = p->private_data;
  2421. port.dev = &dev->dev;
  2422. if (share_irqs)
  2423. port.flags |= UPF_SHARE_IRQ;
  2424. ret = serial8250_register_port(&port);
  2425. if (ret < 0) {
  2426. dev_err(&dev->dev, "unable to register port at index %d "
  2427. "(IO%lx MEM%llx IRQ%d): %d\n", i,
  2428. p->iobase, (unsigned long long)p->mapbase,
  2429. p->irq, ret);
  2430. }
  2431. }
  2432. return 0;
  2433. }
  2434. /*
  2435. * Remove serial ports registered against a platform device.
  2436. */
  2437. static int __devexit serial8250_remove(struct platform_device *dev)
  2438. {
  2439. int i;
  2440. for (i = 0; i < nr_uarts; i++) {
  2441. struct uart_8250_port *up = &serial8250_ports[i];
  2442. if (up->port.dev == &dev->dev)
  2443. serial8250_unregister_port(i);
  2444. }
  2445. return 0;
  2446. }
  2447. static int serial8250_suspend(struct platform_device *dev, pm_message_t state)
  2448. {
  2449. int i;
  2450. for (i = 0; i < UART_NR; i++) {
  2451. struct uart_8250_port *up = &serial8250_ports[i];
  2452. if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  2453. uart_suspend_port(&serial8250_reg, &up->port);
  2454. }
  2455. return 0;
  2456. }
  2457. static int serial8250_resume(struct platform_device *dev)
  2458. {
  2459. int i;
  2460. for (i = 0; i < UART_NR; i++) {
  2461. struct uart_8250_port *up = &serial8250_ports[i];
  2462. if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  2463. serial8250_resume_port(i);
  2464. }
  2465. return 0;
  2466. }
  2467. static struct platform_driver serial8250_isa_driver = {
  2468. .probe = serial8250_probe,
  2469. .remove = __devexit_p(serial8250_remove),
  2470. .suspend = serial8250_suspend,
  2471. .resume = serial8250_resume,
  2472. .driver = {
  2473. .name = "serial8250",
  2474. .owner = THIS_MODULE,
  2475. },
  2476. };
  2477. /*
  2478. * This "device" covers _all_ ISA 8250-compatible serial devices listed
  2479. * in the table in include/asm/serial.h
  2480. */
  2481. static struct platform_device *serial8250_isa_devs;
  2482. /*
  2483. * serial8250_register_port and serial8250_unregister_port allows for
  2484. * 16x50 serial ports to be configured at run-time, to support PCMCIA
  2485. * modems and PCI multiport cards.
  2486. */
  2487. static DEFINE_MUTEX(serial_mutex);
  2488. static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
  2489. {
  2490. int i;
  2491. /*
  2492. * First, find a port entry which matches.
  2493. */
  2494. for (i = 0; i < nr_uarts; i++)
  2495. if (uart_match_port(&serial8250_ports[i].port, port))
  2496. return &serial8250_ports[i];
  2497. /*
  2498. * We didn't find a matching entry, so look for the first
  2499. * free entry. We look for one which hasn't been previously
  2500. * used (indicated by zero iobase).
  2501. */
  2502. for (i = 0; i < nr_uarts; i++)
  2503. if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
  2504. serial8250_ports[i].port.iobase == 0)
  2505. return &serial8250_ports[i];
  2506. /*
  2507. * That also failed. Last resort is to find any entry which
  2508. * doesn't have a real port associated with it.
  2509. */
  2510. for (i = 0; i < nr_uarts; i++)
  2511. if (serial8250_ports[i].port.type == PORT_UNKNOWN)
  2512. return &serial8250_ports[i];
  2513. return NULL;
  2514. }
  2515. /**
  2516. * serial8250_register_port - register a serial port
  2517. * @port: serial port template
  2518. *
  2519. * Configure the serial port specified by the request. If the
  2520. * port exists and is in use, it is hung up and unregistered
  2521. * first.
  2522. *
  2523. * The port is then probed and if necessary the IRQ is autodetected
  2524. * If this fails an error is returned.
  2525. *
  2526. * On success the port is ready to use and the line number is returned.
  2527. */
  2528. int serial8250_register_port(struct uart_port *port)
  2529. {
  2530. struct uart_8250_port *uart;
  2531. int ret = -ENOSPC;
  2532. if (port->uartclk == 0)
  2533. return -EINVAL;
  2534. mutex_lock(&serial_mutex);
  2535. uart = serial8250_find_match_or_unused(port);
  2536. if (uart) {
  2537. uart_remove_one_port(&serial8250_reg, &uart->port);
  2538. uart->port.iobase = port->iobase;
  2539. uart->port.membase = port->membase;
  2540. uart->port.irq = port->irq;
  2541. uart->port.uartclk = port->uartclk;
  2542. uart->port.fifosize = port->fifosize;
  2543. uart->port.regshift = port->regshift;
  2544. uart->port.iotype = port->iotype;
  2545. uart->port.flags = port->flags | UPF_BOOT_AUTOCONF;
  2546. uart->port.mapbase = port->mapbase;
  2547. uart->port.private_data = port->private_data;
  2548. if (port->dev)
  2549. uart->port.dev = port->dev;
  2550. ret = uart_add_one_port(&serial8250_reg, &uart->port);
  2551. if (ret == 0)
  2552. ret = uart->port.line;
  2553. }
  2554. mutex_unlock(&serial_mutex);
  2555. return ret;
  2556. }
  2557. EXPORT_SYMBOL(serial8250_register_port);
  2558. /**
  2559. * serial8250_unregister_port - remove a 16x50 serial port at runtime
  2560. * @line: serial line number
  2561. *
  2562. * Remove one serial port. This may not be called from interrupt
  2563. * context. We hand the port back to the our control.
  2564. */
  2565. void serial8250_unregister_port(int line)
  2566. {
  2567. struct uart_8250_port *uart = &serial8250_ports[line];
  2568. mutex_lock(&serial_mutex);
  2569. uart_remove_one_port(&serial8250_reg, &uart->port);
  2570. if (serial8250_isa_devs) {
  2571. uart->port.flags &= ~UPF_BOOT_AUTOCONF;
  2572. uart->port.type = PORT_UNKNOWN;
  2573. uart->port.dev = &serial8250_isa_devs->dev;
  2574. uart_add_one_port(&serial8250_reg, &uart->port);
  2575. } else {
  2576. uart->port.dev = NULL;
  2577. }
  2578. mutex_unlock(&serial_mutex);
  2579. }
  2580. EXPORT_SYMBOL(serial8250_unregister_port);
  2581. static int __init serial8250_init(void)
  2582. {
  2583. int ret;
  2584. if (nr_uarts > UART_NR)
  2585. nr_uarts = UART_NR;
  2586. printk(KERN_INFO "Serial: 8250/16550 driver"
  2587. "%d ports, IRQ sharing %sabled\n", nr_uarts,
  2588. share_irqs ? "en" : "dis");
  2589. #ifdef CONFIG_SPARC
  2590. ret = sunserial_register_minors(&serial8250_reg, UART_NR);
  2591. #else
  2592. serial8250_reg.nr = UART_NR;
  2593. ret = uart_register_driver(&serial8250_reg);
  2594. #endif
  2595. if (ret)
  2596. goto out;
  2597. serial8250_isa_devs = platform_device_alloc("serial8250",
  2598. PLAT8250_DEV_LEGACY);
  2599. if (!serial8250_isa_devs) {
  2600. ret = -ENOMEM;
  2601. goto unreg_uart_drv;
  2602. }
  2603. ret = platform_device_add(serial8250_isa_devs);
  2604. if (ret)
  2605. goto put_dev;
  2606. serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
  2607. ret = platform_driver_register(&serial8250_isa_driver);
  2608. if (ret == 0)
  2609. goto out;
  2610. platform_device_del(serial8250_isa_devs);
  2611. put_dev:
  2612. platform_device_put(serial8250_isa_devs);
  2613. unreg_uart_drv:
  2614. #ifdef CONFIG_SPARC
  2615. sunserial_unregister_minors(&serial8250_reg, UART_NR);
  2616. #else
  2617. uart_unregister_driver(&serial8250_reg);
  2618. #endif
  2619. out:
  2620. return ret;
  2621. }
  2622. static void __exit serial8250_exit(void)
  2623. {
  2624. struct platform_device *isa_dev = serial8250_isa_devs;
  2625. /*
  2626. * This tells serial8250_unregister_port() not to re-register
  2627. * the ports (thereby making serial8250_isa_driver permanently
  2628. * in use.)
  2629. */
  2630. serial8250_isa_devs = NULL;
  2631. platform_driver_unregister(&serial8250_isa_driver);
  2632. platform_device_unregister(isa_dev);
  2633. #ifdef CONFIG_SPARC
  2634. sunserial_unregister_minors(&serial8250_reg, UART_NR);
  2635. #else
  2636. uart_unregister_driver(&serial8250_reg);
  2637. #endif
  2638. }
  2639. module_init(serial8250_init);
  2640. module_exit(serial8250_exit);
  2641. EXPORT_SYMBOL(serial8250_suspend_port);
  2642. EXPORT_SYMBOL(serial8250_resume_port);
  2643. MODULE_LICENSE("GPL");
  2644. MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
  2645. module_param(share_irqs, uint, 0644);
  2646. MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
  2647. " (unsafe)");
  2648. module_param(nr_uarts, uint, 0644);
  2649. MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
  2650. #ifdef CONFIG_SERIAL_8250_RSA
  2651. module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
  2652. MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
  2653. #endif
  2654. MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);