serial_core.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640
  1. /*
  2. * linux/drivers/char/core.c
  3. *
  4. * Driver core for serial ports
  5. *
  6. * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  7. *
  8. * Copyright 1999 ARM Limited
  9. * Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <linux/module.h>
  26. #include <linux/tty.h>
  27. #include <linux/slab.h>
  28. #include <linux/init.h>
  29. #include <linux/console.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/seq_file.h>
  32. #include <linux/smp_lock.h>
  33. #include <linux/device.h>
  34. #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
  35. #include <linux/serial_core.h>
  36. #include <linux/delay.h>
  37. #include <linux/mutex.h>
  38. #include <asm/irq.h>
  39. #include <asm/uaccess.h>
  40. /*
  41. * This is used to lock changes in serial line configuration.
  42. */
  43. static DEFINE_MUTEX(port_mutex);
  44. /*
  45. * lockdep: port->lock is initialized in two places, but we
  46. * want only one lock-class:
  47. */
  48. static struct lock_class_key port_lock_key;
  49. #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
  50. #ifdef CONFIG_SERIAL_CORE_CONSOLE
  51. #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line)
  52. #else
  53. #define uart_console(port) (0)
  54. #endif
  55. static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
  56. struct ktermios *old_termios);
  57. static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
  58. static void uart_change_pm(struct uart_state *state, int pm_state);
  59. /*
  60. * This routine is used by the interrupt handler to schedule processing in
  61. * the software interrupt portion of the driver.
  62. */
  63. void uart_write_wakeup(struct uart_port *port)
  64. {
  65. struct uart_state *state = port->state;
  66. /*
  67. * This means you called this function _after_ the port was
  68. * closed. No cookie for you.
  69. */
  70. BUG_ON(!state);
  71. tasklet_schedule(&state->tlet);
  72. }
  73. static void uart_stop(struct tty_struct *tty)
  74. {
  75. struct uart_state *state = tty->driver_data;
  76. struct uart_port *port = state->uart_port;
  77. unsigned long flags;
  78. spin_lock_irqsave(&port->lock, flags);
  79. port->ops->stop_tx(port);
  80. spin_unlock_irqrestore(&port->lock, flags);
  81. }
  82. static void __uart_start(struct tty_struct *tty)
  83. {
  84. struct uart_state *state = tty->driver_data;
  85. struct uart_port *port = state->uart_port;
  86. if (!uart_circ_empty(&state->xmit) && state->xmit.buf &&
  87. !tty->stopped && !tty->hw_stopped)
  88. port->ops->start_tx(port);
  89. }
  90. static void uart_start(struct tty_struct *tty)
  91. {
  92. struct uart_state *state = tty->driver_data;
  93. struct uart_port *port = state->uart_port;
  94. unsigned long flags;
  95. spin_lock_irqsave(&port->lock, flags);
  96. __uart_start(tty);
  97. spin_unlock_irqrestore(&port->lock, flags);
  98. }
  99. static void uart_tasklet_action(unsigned long data)
  100. {
  101. struct uart_state *state = (struct uart_state *)data;
  102. tty_wakeup(state->port.tty);
  103. }
  104. static inline void
  105. uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
  106. {
  107. unsigned long flags;
  108. unsigned int old;
  109. spin_lock_irqsave(&port->lock, flags);
  110. old = port->mctrl;
  111. port->mctrl = (old & ~clear) | set;
  112. if (old != port->mctrl)
  113. port->ops->set_mctrl(port, port->mctrl);
  114. spin_unlock_irqrestore(&port->lock, flags);
  115. }
  116. #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0)
  117. #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear)
  118. /*
  119. * Startup the port. This will be called once per open. All calls
  120. * will be serialised by the per-port mutex.
  121. */
  122. static int uart_startup(struct tty_struct *tty, struct uart_state *state, int init_hw)
  123. {
  124. struct uart_port *uport = state->uart_port;
  125. struct tty_port *port = &state->port;
  126. unsigned long page;
  127. int retval = 0;
  128. if (port->flags & ASYNC_INITIALIZED)
  129. return 0;
  130. /*
  131. * Set the TTY IO error marker - we will only clear this
  132. * once we have successfully opened the port. Also set
  133. * up the tty->alt_speed kludge
  134. */
  135. set_bit(TTY_IO_ERROR, &tty->flags);
  136. if (uport->type == PORT_UNKNOWN)
  137. return 0;
  138. /*
  139. * Initialise and allocate the transmit and temporary
  140. * buffer.
  141. */
  142. if (!state->xmit.buf) {
  143. /* This is protected by the per port mutex */
  144. page = get_zeroed_page(GFP_KERNEL);
  145. if (!page)
  146. return -ENOMEM;
  147. state->xmit.buf = (unsigned char *) page;
  148. uart_circ_clear(&state->xmit);
  149. }
  150. retval = uport->ops->startup(uport);
  151. if (retval == 0) {
  152. if (init_hw) {
  153. /*
  154. * Initialise the hardware port settings.
  155. */
  156. uart_change_speed(tty, state, NULL);
  157. /*
  158. * Setup the RTS and DTR signals once the
  159. * port is open and ready to respond.
  160. */
  161. if (tty->termios->c_cflag & CBAUD)
  162. uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
  163. }
  164. if (port->flags & ASYNC_CTS_FLOW) {
  165. spin_lock_irq(&uport->lock);
  166. if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
  167. tty->hw_stopped = 1;
  168. spin_unlock_irq(&uport->lock);
  169. }
  170. set_bit(ASYNCB_INITIALIZED, &port->flags);
  171. clear_bit(TTY_IO_ERROR, &tty->flags);
  172. }
  173. if (retval && capable(CAP_SYS_ADMIN))
  174. retval = 0;
  175. return retval;
  176. }
  177. /*
  178. * This routine will shutdown a serial port; interrupts are disabled, and
  179. * DTR is dropped if the hangup on close termio flag is on. Calls to
  180. * uart_shutdown are serialised by the per-port semaphore.
  181. */
  182. static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
  183. {
  184. struct uart_port *uport = state->uart_port;
  185. struct tty_port *port = &state->port;
  186. /*
  187. * Set the TTY IO error marker
  188. */
  189. if (tty)
  190. set_bit(TTY_IO_ERROR, &tty->flags);
  191. if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) {
  192. /*
  193. * Turn off DTR and RTS early.
  194. */
  195. if (!tty || (tty->termios->c_cflag & HUPCL))
  196. uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
  197. /*
  198. * clear delta_msr_wait queue to avoid mem leaks: we may free
  199. * the irq here so the queue might never be woken up. Note
  200. * that we won't end up waiting on delta_msr_wait again since
  201. * any outstanding file descriptors should be pointing at
  202. * hung_up_tty_fops now.
  203. */
  204. wake_up_interruptible(&port->delta_msr_wait);
  205. /*
  206. * Free the IRQ and disable the port.
  207. */
  208. uport->ops->shutdown(uport);
  209. /*
  210. * Ensure that the IRQ handler isn't running on another CPU.
  211. */
  212. synchronize_irq(uport->irq);
  213. }
  214. /*
  215. * kill off our tasklet
  216. */
  217. tasklet_kill(&state->tlet);
  218. /*
  219. * Free the transmit buffer page.
  220. */
  221. if (state->xmit.buf) {
  222. free_page((unsigned long)state->xmit.buf);
  223. state->xmit.buf = NULL;
  224. }
  225. }
  226. /**
  227. * uart_update_timeout - update per-port FIFO timeout.
  228. * @port: uart_port structure describing the port
  229. * @cflag: termios cflag value
  230. * @baud: speed of the port
  231. *
  232. * Set the port FIFO timeout value. The @cflag value should
  233. * reflect the actual hardware settings.
  234. */
  235. void
  236. uart_update_timeout(struct uart_port *port, unsigned int cflag,
  237. unsigned int baud)
  238. {
  239. unsigned int bits;
  240. /* byte size and parity */
  241. switch (cflag & CSIZE) {
  242. case CS5:
  243. bits = 7;
  244. break;
  245. case CS6:
  246. bits = 8;
  247. break;
  248. case CS7:
  249. bits = 9;
  250. break;
  251. default:
  252. bits = 10;
  253. break; /* CS8 */
  254. }
  255. if (cflag & CSTOPB)
  256. bits++;
  257. if (cflag & PARENB)
  258. bits++;
  259. /*
  260. * The total number of bits to be transmitted in the fifo.
  261. */
  262. bits = bits * port->fifosize;
  263. /*
  264. * Figure the timeout to send the above number of bits.
  265. * Add .02 seconds of slop
  266. */
  267. port->timeout = (HZ * bits) / baud + HZ/50;
  268. }
  269. EXPORT_SYMBOL(uart_update_timeout);
  270. /**
  271. * uart_get_baud_rate - return baud rate for a particular port
  272. * @port: uart_port structure describing the port in question.
  273. * @termios: desired termios settings.
  274. * @old: old termios (or NULL)
  275. * @min: minimum acceptable baud rate
  276. * @max: maximum acceptable baud rate
  277. *
  278. * Decode the termios structure into a numeric baud rate,
  279. * taking account of the magic 38400 baud rate (with spd_*
  280. * flags), and mapping the %B0 rate to 9600 baud.
  281. *
  282. * If the new baud rate is invalid, try the old termios setting.
  283. * If it's still invalid, we try 9600 baud.
  284. *
  285. * Update the @termios structure to reflect the baud rate
  286. * we're actually going to be using. Don't do this for the case
  287. * where B0 is requested ("hang up").
  288. */
  289. unsigned int
  290. uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
  291. struct ktermios *old, unsigned int min, unsigned int max)
  292. {
  293. unsigned int try, baud, altbaud = 38400;
  294. int hung_up = 0;
  295. upf_t flags = port->flags & UPF_SPD_MASK;
  296. if (flags == UPF_SPD_HI)
  297. altbaud = 57600;
  298. else if (flags == UPF_SPD_VHI)
  299. altbaud = 115200;
  300. else if (flags == UPF_SPD_SHI)
  301. altbaud = 230400;
  302. else if (flags == UPF_SPD_WARP)
  303. altbaud = 460800;
  304. for (try = 0; try < 2; try++) {
  305. baud = tty_termios_baud_rate(termios);
  306. /*
  307. * The spd_hi, spd_vhi, spd_shi, spd_warp kludge...
  308. * Die! Die! Die!
  309. */
  310. if (baud == 38400)
  311. baud = altbaud;
  312. /*
  313. * Special case: B0 rate.
  314. */
  315. if (baud == 0) {
  316. hung_up = 1;
  317. baud = 9600;
  318. }
  319. if (baud >= min && baud <= max)
  320. return baud;
  321. /*
  322. * Oops, the quotient was zero. Try again with
  323. * the old baud rate if possible.
  324. */
  325. termios->c_cflag &= ~CBAUD;
  326. if (old) {
  327. baud = tty_termios_baud_rate(old);
  328. if (!hung_up)
  329. tty_termios_encode_baud_rate(termios,
  330. baud, baud);
  331. old = NULL;
  332. continue;
  333. }
  334. /*
  335. * As a last resort, if the range cannot be met then clip to
  336. * the nearest chip supported rate.
  337. */
  338. if (!hung_up) {
  339. if (baud <= min)
  340. tty_termios_encode_baud_rate(termios,
  341. min + 1, min + 1);
  342. else
  343. tty_termios_encode_baud_rate(termios,
  344. max - 1, max - 1);
  345. }
  346. }
  347. /* Should never happen */
  348. WARN_ON(1);
  349. return 0;
  350. }
  351. EXPORT_SYMBOL(uart_get_baud_rate);
  352. /**
  353. * uart_get_divisor - return uart clock divisor
  354. * @port: uart_port structure describing the port.
  355. * @baud: desired baud rate
  356. *
  357. * Calculate the uart clock divisor for the port.
  358. */
  359. unsigned int
  360. uart_get_divisor(struct uart_port *port, unsigned int baud)
  361. {
  362. unsigned int quot;
  363. /*
  364. * Old custom speed handling.
  365. */
  366. if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
  367. quot = port->custom_divisor;
  368. else
  369. quot = (port->uartclk + (8 * baud)) / (16 * baud);
  370. return quot;
  371. }
  372. EXPORT_SYMBOL(uart_get_divisor);
  373. /* FIXME: Consistent locking policy */
  374. static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
  375. struct ktermios *old_termios)
  376. {
  377. struct tty_port *port = &state->port;
  378. struct uart_port *uport = state->uart_port;
  379. struct ktermios *termios;
  380. /*
  381. * If we have no tty, termios, or the port does not exist,
  382. * then we can't set the parameters for this port.
  383. */
  384. if (!tty || !tty->termios || uport->type == PORT_UNKNOWN)
  385. return;
  386. termios = tty->termios;
  387. /*
  388. * Set flags based on termios cflag
  389. */
  390. if (termios->c_cflag & CRTSCTS)
  391. set_bit(ASYNCB_CTS_FLOW, &port->flags);
  392. else
  393. clear_bit(ASYNCB_CTS_FLOW, &port->flags);
  394. if (termios->c_cflag & CLOCAL)
  395. clear_bit(ASYNCB_CHECK_CD, &port->flags);
  396. else
  397. set_bit(ASYNCB_CHECK_CD, &port->flags);
  398. uport->ops->set_termios(uport, termios, old_termios);
  399. }
  400. static inline int __uart_put_char(struct uart_port *port,
  401. struct circ_buf *circ, unsigned char c)
  402. {
  403. unsigned long flags;
  404. int ret = 0;
  405. if (!circ->buf)
  406. return 0;
  407. spin_lock_irqsave(&port->lock, flags);
  408. if (uart_circ_chars_free(circ) != 0) {
  409. circ->buf[circ->head] = c;
  410. circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1);
  411. ret = 1;
  412. }
  413. spin_unlock_irqrestore(&port->lock, flags);
  414. return ret;
  415. }
  416. static int uart_put_char(struct tty_struct *tty, unsigned char ch)
  417. {
  418. struct uart_state *state = tty->driver_data;
  419. return __uart_put_char(state->uart_port, &state->xmit, ch);
  420. }
  421. static void uart_flush_chars(struct tty_struct *tty)
  422. {
  423. uart_start(tty);
  424. }
  425. static int uart_write(struct tty_struct *tty,
  426. const unsigned char *buf, int count)
  427. {
  428. struct uart_state *state = tty->driver_data;
  429. struct uart_port *port;
  430. struct circ_buf *circ;
  431. unsigned long flags;
  432. int c, ret = 0;
  433. /*
  434. * This means you called this function _after_ the port was
  435. * closed. No cookie for you.
  436. */
  437. if (!state) {
  438. WARN_ON(1);
  439. return -EL3HLT;
  440. }
  441. port = state->uart_port;
  442. circ = &state->xmit;
  443. if (!circ->buf)
  444. return 0;
  445. spin_lock_irqsave(&port->lock, flags);
  446. while (1) {
  447. c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE);
  448. if (count < c)
  449. c = count;
  450. if (c <= 0)
  451. break;
  452. memcpy(circ->buf + circ->head, buf, c);
  453. circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1);
  454. buf += c;
  455. count -= c;
  456. ret += c;
  457. }
  458. spin_unlock_irqrestore(&port->lock, flags);
  459. uart_start(tty);
  460. return ret;
  461. }
  462. static int uart_write_room(struct tty_struct *tty)
  463. {
  464. struct uart_state *state = tty->driver_data;
  465. unsigned long flags;
  466. int ret;
  467. spin_lock_irqsave(&state->uart_port->lock, flags);
  468. ret = uart_circ_chars_free(&state->xmit);
  469. spin_unlock_irqrestore(&state->uart_port->lock, flags);
  470. return ret;
  471. }
  472. static int uart_chars_in_buffer(struct tty_struct *tty)
  473. {
  474. struct uart_state *state = tty->driver_data;
  475. unsigned long flags;
  476. int ret;
  477. spin_lock_irqsave(&state->uart_port->lock, flags);
  478. ret = uart_circ_chars_pending(&state->xmit);
  479. spin_unlock_irqrestore(&state->uart_port->lock, flags);
  480. return ret;
  481. }
  482. static void uart_flush_buffer(struct tty_struct *tty)
  483. {
  484. struct uart_state *state = tty->driver_data;
  485. struct uart_port *port;
  486. unsigned long flags;
  487. /*
  488. * This means you called this function _after_ the port was
  489. * closed. No cookie for you.
  490. */
  491. if (!state) {
  492. WARN_ON(1);
  493. return;
  494. }
  495. port = state->uart_port;
  496. pr_debug("uart_flush_buffer(%d) called\n", tty->index);
  497. spin_lock_irqsave(&port->lock, flags);
  498. uart_circ_clear(&state->xmit);
  499. if (port->ops->flush_buffer)
  500. port->ops->flush_buffer(port);
  501. spin_unlock_irqrestore(&port->lock, flags);
  502. tty_wakeup(tty);
  503. }
  504. /*
  505. * This function is used to send a high-priority XON/XOFF character to
  506. * the device
  507. */
  508. static void uart_send_xchar(struct tty_struct *tty, char ch)
  509. {
  510. struct uart_state *state = tty->driver_data;
  511. struct uart_port *port = state->uart_port;
  512. unsigned long flags;
  513. if (port->ops->send_xchar)
  514. port->ops->send_xchar(port, ch);
  515. else {
  516. port->x_char = ch;
  517. if (ch) {
  518. spin_lock_irqsave(&port->lock, flags);
  519. port->ops->start_tx(port);
  520. spin_unlock_irqrestore(&port->lock, flags);
  521. }
  522. }
  523. }
  524. static void uart_throttle(struct tty_struct *tty)
  525. {
  526. struct uart_state *state = tty->driver_data;
  527. if (I_IXOFF(tty))
  528. uart_send_xchar(tty, STOP_CHAR(tty));
  529. if (tty->termios->c_cflag & CRTSCTS)
  530. uart_clear_mctrl(state->uart_port, TIOCM_RTS);
  531. }
  532. static void uart_unthrottle(struct tty_struct *tty)
  533. {
  534. struct uart_state *state = tty->driver_data;
  535. struct uart_port *port = state->uart_port;
  536. if (I_IXOFF(tty)) {
  537. if (port->x_char)
  538. port->x_char = 0;
  539. else
  540. uart_send_xchar(tty, START_CHAR(tty));
  541. }
  542. if (tty->termios->c_cflag & CRTSCTS)
  543. uart_set_mctrl(port, TIOCM_RTS);
  544. }
  545. static int uart_get_info(struct uart_state *state,
  546. struct serial_struct __user *retinfo)
  547. {
  548. struct uart_port *uport = state->uart_port;
  549. struct tty_port *port = &state->port;
  550. struct serial_struct tmp;
  551. memset(&tmp, 0, sizeof(tmp));
  552. /* Ensure the state we copy is consistent and no hardware changes
  553. occur as we go */
  554. mutex_lock(&port->mutex);
  555. tmp.type = uport->type;
  556. tmp.line = uport->line;
  557. tmp.port = uport->iobase;
  558. if (HIGH_BITS_OFFSET)
  559. tmp.port_high = (long) uport->iobase >> HIGH_BITS_OFFSET;
  560. tmp.irq = uport->irq;
  561. tmp.flags = uport->flags;
  562. tmp.xmit_fifo_size = uport->fifosize;
  563. tmp.baud_base = uport->uartclk / 16;
  564. tmp.close_delay = port->close_delay / 10;
  565. tmp.closing_wait = port->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
  566. ASYNC_CLOSING_WAIT_NONE :
  567. port->closing_wait / 10;
  568. tmp.custom_divisor = uport->custom_divisor;
  569. tmp.hub6 = uport->hub6;
  570. tmp.io_type = uport->iotype;
  571. tmp.iomem_reg_shift = uport->regshift;
  572. tmp.iomem_base = (void *)(unsigned long)uport->mapbase;
  573. mutex_unlock(&port->mutex);
  574. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  575. return -EFAULT;
  576. return 0;
  577. }
  578. static int uart_set_info(struct tty_struct *tty, struct uart_state *state,
  579. struct serial_struct __user *newinfo)
  580. {
  581. struct serial_struct new_serial;
  582. struct uart_port *uport = state->uart_port;
  583. struct tty_port *port = &state->port;
  584. unsigned long new_port;
  585. unsigned int change_irq, change_port, closing_wait;
  586. unsigned int old_custom_divisor, close_delay;
  587. upf_t old_flags, new_flags;
  588. int retval = 0;
  589. if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
  590. return -EFAULT;
  591. new_port = new_serial.port;
  592. if (HIGH_BITS_OFFSET)
  593. new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
  594. new_serial.irq = irq_canonicalize(new_serial.irq);
  595. close_delay = new_serial.close_delay * 10;
  596. closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
  597. ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
  598. /*
  599. * This semaphore protects port->count. It is also
  600. * very useful to prevent opens. Also, take the
  601. * port configuration semaphore to make sure that a
  602. * module insertion/removal doesn't change anything
  603. * under us.
  604. */
  605. mutex_lock(&port->mutex);
  606. change_irq = !(uport->flags & UPF_FIXED_PORT)
  607. && new_serial.irq != uport->irq;
  608. /*
  609. * Since changing the 'type' of the port changes its resource
  610. * allocations, we should treat type changes the same as
  611. * IO port changes.
  612. */
  613. change_port = !(uport->flags & UPF_FIXED_PORT)
  614. && (new_port != uport->iobase ||
  615. (unsigned long)new_serial.iomem_base != uport->mapbase ||
  616. new_serial.hub6 != uport->hub6 ||
  617. new_serial.io_type != uport->iotype ||
  618. new_serial.iomem_reg_shift != uport->regshift ||
  619. new_serial.type != uport->type);
  620. old_flags = uport->flags;
  621. new_flags = new_serial.flags;
  622. old_custom_divisor = uport->custom_divisor;
  623. if (!capable(CAP_SYS_ADMIN)) {
  624. retval = -EPERM;
  625. if (change_irq || change_port ||
  626. (new_serial.baud_base != uport->uartclk / 16) ||
  627. (close_delay != port->close_delay) ||
  628. (closing_wait != port->closing_wait) ||
  629. (new_serial.xmit_fifo_size &&
  630. new_serial.xmit_fifo_size != uport->fifosize) ||
  631. (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0))
  632. goto exit;
  633. uport->flags = ((uport->flags & ~UPF_USR_MASK) |
  634. (new_flags & UPF_USR_MASK));
  635. uport->custom_divisor = new_serial.custom_divisor;
  636. goto check_and_exit;
  637. }
  638. /*
  639. * Ask the low level driver to verify the settings.
  640. */
  641. if (uport->ops->verify_port)
  642. retval = uport->ops->verify_port(uport, &new_serial);
  643. if ((new_serial.irq >= nr_irqs) || (new_serial.irq < 0) ||
  644. (new_serial.baud_base < 9600))
  645. retval = -EINVAL;
  646. if (retval)
  647. goto exit;
  648. if (change_port || change_irq) {
  649. retval = -EBUSY;
  650. /*
  651. * Make sure that we are the sole user of this port.
  652. */
  653. if (tty_port_users(port) > 1)
  654. goto exit;
  655. /*
  656. * We need to shutdown the serial port at the old
  657. * port/type/irq combination.
  658. */
  659. uart_shutdown(tty, state);
  660. }
  661. if (change_port) {
  662. unsigned long old_iobase, old_mapbase;
  663. unsigned int old_type, old_iotype, old_hub6, old_shift;
  664. old_iobase = uport->iobase;
  665. old_mapbase = uport->mapbase;
  666. old_type = uport->type;
  667. old_hub6 = uport->hub6;
  668. old_iotype = uport->iotype;
  669. old_shift = uport->regshift;
  670. /*
  671. * Free and release old regions
  672. */
  673. if (old_type != PORT_UNKNOWN)
  674. uport->ops->release_port(uport);
  675. uport->iobase = new_port;
  676. uport->type = new_serial.type;
  677. uport->hub6 = new_serial.hub6;
  678. uport->iotype = new_serial.io_type;
  679. uport->regshift = new_serial.iomem_reg_shift;
  680. uport->mapbase = (unsigned long)new_serial.iomem_base;
  681. /*
  682. * Claim and map the new regions
  683. */
  684. if (uport->type != PORT_UNKNOWN) {
  685. retval = uport->ops->request_port(uport);
  686. } else {
  687. /* Always success - Jean II */
  688. retval = 0;
  689. }
  690. /*
  691. * If we fail to request resources for the
  692. * new port, try to restore the old settings.
  693. */
  694. if (retval && old_type != PORT_UNKNOWN) {
  695. uport->iobase = old_iobase;
  696. uport->type = old_type;
  697. uport->hub6 = old_hub6;
  698. uport->iotype = old_iotype;
  699. uport->regshift = old_shift;
  700. uport->mapbase = old_mapbase;
  701. retval = uport->ops->request_port(uport);
  702. /*
  703. * If we failed to restore the old settings,
  704. * we fail like this.
  705. */
  706. if (retval)
  707. uport->type = PORT_UNKNOWN;
  708. /*
  709. * We failed anyway.
  710. */
  711. retval = -EBUSY;
  712. /* Added to return the correct error -Ram Gupta */
  713. goto exit;
  714. }
  715. }
  716. if (change_irq)
  717. uport->irq = new_serial.irq;
  718. if (!(uport->flags & UPF_FIXED_PORT))
  719. uport->uartclk = new_serial.baud_base * 16;
  720. uport->flags = (uport->flags & ~UPF_CHANGE_MASK) |
  721. (new_flags & UPF_CHANGE_MASK);
  722. uport->custom_divisor = new_serial.custom_divisor;
  723. port->close_delay = close_delay;
  724. port->closing_wait = closing_wait;
  725. if (new_serial.xmit_fifo_size)
  726. uport->fifosize = new_serial.xmit_fifo_size;
  727. if (port->tty)
  728. port->tty->low_latency =
  729. (uport->flags & UPF_LOW_LATENCY) ? 1 : 0;
  730. check_and_exit:
  731. retval = 0;
  732. if (uport->type == PORT_UNKNOWN)
  733. goto exit;
  734. if (port->flags & ASYNC_INITIALIZED) {
  735. if (((old_flags ^ uport->flags) & UPF_SPD_MASK) ||
  736. old_custom_divisor != uport->custom_divisor) {
  737. /*
  738. * If they're setting up a custom divisor or speed,
  739. * instead of clearing it, then bitch about it. No
  740. * need to rate-limit; it's CAP_SYS_ADMIN only.
  741. */
  742. if (uport->flags & UPF_SPD_MASK) {
  743. char buf[64];
  744. printk(KERN_NOTICE
  745. "%s sets custom speed on %s. This "
  746. "is deprecated.\n", current->comm,
  747. tty_name(port->tty, buf));
  748. }
  749. uart_change_speed(tty, state, NULL);
  750. }
  751. } else
  752. retval = uart_startup(tty, state, 1);
  753. exit:
  754. mutex_unlock(&port->mutex);
  755. return retval;
  756. }
  757. /**
  758. * uart_get_lsr_info - get line status register info
  759. * @tty: tty associated with the UART
  760. * @state: UART being queried
  761. * @value: returned modem value
  762. *
  763. * Note: uart_ioctl protects us against hangups.
  764. */
  765. static int uart_get_lsr_info(struct tty_struct *tty,
  766. struct uart_state *state, unsigned int __user *value)
  767. {
  768. struct uart_port *uport = state->uart_port;
  769. unsigned int result;
  770. result = uport->ops->tx_empty(uport);
  771. /*
  772. * If we're about to load something into the transmit
  773. * register, we'll pretend the transmitter isn't empty to
  774. * avoid a race condition (depending on when the transmit
  775. * interrupt happens).
  776. */
  777. if (uport->x_char ||
  778. ((uart_circ_chars_pending(&state->xmit) > 0) &&
  779. !tty->stopped && !tty->hw_stopped))
  780. result &= ~TIOCSER_TEMT;
  781. return put_user(result, value);
  782. }
  783. static int uart_tiocmget(struct tty_struct *tty, struct file *file)
  784. {
  785. struct uart_state *state = tty->driver_data;
  786. struct tty_port *port = &state->port;
  787. struct uart_port *uport = state->uart_port;
  788. int result = -EIO;
  789. mutex_lock(&port->mutex);
  790. if ((!file || !tty_hung_up_p(file)) &&
  791. !(tty->flags & (1 << TTY_IO_ERROR))) {
  792. result = uport->mctrl;
  793. spin_lock_irq(&uport->lock);
  794. result |= uport->ops->get_mctrl(uport);
  795. spin_unlock_irq(&uport->lock);
  796. }
  797. mutex_unlock(&port->mutex);
  798. return result;
  799. }
  800. static int
  801. uart_tiocmset(struct tty_struct *tty, struct file *file,
  802. unsigned int set, unsigned int clear)
  803. {
  804. struct uart_state *state = tty->driver_data;
  805. struct uart_port *uport = state->uart_port;
  806. struct tty_port *port = &state->port;
  807. int ret = -EIO;
  808. mutex_lock(&port->mutex);
  809. if ((!file || !tty_hung_up_p(file)) &&
  810. !(tty->flags & (1 << TTY_IO_ERROR))) {
  811. uart_update_mctrl(uport, set, clear);
  812. ret = 0;
  813. }
  814. mutex_unlock(&port->mutex);
  815. return ret;
  816. }
  817. static int uart_break_ctl(struct tty_struct *tty, int break_state)
  818. {
  819. struct uart_state *state = tty->driver_data;
  820. struct tty_port *port = &state->port;
  821. struct uart_port *uport = state->uart_port;
  822. mutex_lock(&port->mutex);
  823. if (uport->type != PORT_UNKNOWN)
  824. uport->ops->break_ctl(uport, break_state);
  825. mutex_unlock(&port->mutex);
  826. return 0;
  827. }
  828. static int uart_do_autoconfig(struct tty_struct *tty,struct uart_state *state)
  829. {
  830. struct uart_port *uport = state->uart_port;
  831. struct tty_port *port = &state->port;
  832. int flags, ret;
  833. if (!capable(CAP_SYS_ADMIN))
  834. return -EPERM;
  835. /*
  836. * Take the per-port semaphore. This prevents count from
  837. * changing, and hence any extra opens of the port while
  838. * we're auto-configuring.
  839. */
  840. if (mutex_lock_interruptible(&port->mutex))
  841. return -ERESTARTSYS;
  842. ret = -EBUSY;
  843. if (tty_port_users(port) == 1) {
  844. uart_shutdown(tty, state);
  845. /*
  846. * If we already have a port type configured,
  847. * we must release its resources.
  848. */
  849. if (uport->type != PORT_UNKNOWN)
  850. uport->ops->release_port(uport);
  851. flags = UART_CONFIG_TYPE;
  852. if (uport->flags & UPF_AUTO_IRQ)
  853. flags |= UART_CONFIG_IRQ;
  854. /*
  855. * This will claim the ports resources if
  856. * a port is found.
  857. */
  858. uport->ops->config_port(uport, flags);
  859. ret = uart_startup(tty, state, 1);
  860. }
  861. mutex_unlock(&port->mutex);
  862. return ret;
  863. }
  864. /*
  865. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  866. * - mask passed in arg for lines of interest
  867. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  868. * Caller should use TIOCGICOUNT to see which one it was
  869. *
  870. * FIXME: This wants extracting into a common all driver implementation
  871. * of TIOCMWAIT using tty_port.
  872. */
  873. static int
  874. uart_wait_modem_status(struct uart_state *state, unsigned long arg)
  875. {
  876. struct uart_port *uport = state->uart_port;
  877. struct tty_port *port = &state->port;
  878. DECLARE_WAITQUEUE(wait, current);
  879. struct uart_icount cprev, cnow;
  880. int ret;
  881. /*
  882. * note the counters on entry
  883. */
  884. spin_lock_irq(&uport->lock);
  885. memcpy(&cprev, &uport->icount, sizeof(struct uart_icount));
  886. /*
  887. * Force modem status interrupts on
  888. */
  889. uport->ops->enable_ms(uport);
  890. spin_unlock_irq(&uport->lock);
  891. add_wait_queue(&port->delta_msr_wait, &wait);
  892. for (;;) {
  893. spin_lock_irq(&uport->lock);
  894. memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
  895. spin_unlock_irq(&uport->lock);
  896. set_current_state(TASK_INTERRUPTIBLE);
  897. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  898. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  899. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  900. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
  901. ret = 0;
  902. break;
  903. }
  904. schedule();
  905. /* see if a signal did it */
  906. if (signal_pending(current)) {
  907. ret = -ERESTARTSYS;
  908. break;
  909. }
  910. cprev = cnow;
  911. }
  912. current->state = TASK_RUNNING;
  913. remove_wait_queue(&port->delta_msr_wait, &wait);
  914. return ret;
  915. }
  916. /*
  917. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  918. * Return: write counters to the user passed counter struct
  919. * NB: both 1->0 and 0->1 transitions are counted except for
  920. * RI where only 0->1 is counted.
  921. */
  922. static int uart_get_count(struct uart_state *state,
  923. struct serial_icounter_struct __user *icnt)
  924. {
  925. struct serial_icounter_struct icount;
  926. struct uart_icount cnow;
  927. struct uart_port *uport = state->uart_port;
  928. spin_lock_irq(&uport->lock);
  929. memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
  930. spin_unlock_irq(&uport->lock);
  931. icount.cts = cnow.cts;
  932. icount.dsr = cnow.dsr;
  933. icount.rng = cnow.rng;
  934. icount.dcd = cnow.dcd;
  935. icount.rx = cnow.rx;
  936. icount.tx = cnow.tx;
  937. icount.frame = cnow.frame;
  938. icount.overrun = cnow.overrun;
  939. icount.parity = cnow.parity;
  940. icount.brk = cnow.brk;
  941. icount.buf_overrun = cnow.buf_overrun;
  942. return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0;
  943. }
  944. /*
  945. * Called via sys_ioctl. We can use spin_lock_irq() here.
  946. */
  947. static int
  948. uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
  949. unsigned long arg)
  950. {
  951. struct uart_state *state = tty->driver_data;
  952. struct tty_port *port = &state->port;
  953. void __user *uarg = (void __user *)arg;
  954. int ret = -ENOIOCTLCMD;
  955. /*
  956. * These ioctls don't rely on the hardware to be present.
  957. */
  958. switch (cmd) {
  959. case TIOCGSERIAL:
  960. ret = uart_get_info(state, uarg);
  961. break;
  962. case TIOCSSERIAL:
  963. ret = uart_set_info(tty, state, uarg);
  964. break;
  965. case TIOCSERCONFIG:
  966. ret = uart_do_autoconfig(tty, state);
  967. break;
  968. case TIOCSERGWILD: /* obsolete */
  969. case TIOCSERSWILD: /* obsolete */
  970. ret = 0;
  971. break;
  972. }
  973. if (ret != -ENOIOCTLCMD)
  974. goto out;
  975. if (tty->flags & (1 << TTY_IO_ERROR)) {
  976. ret = -EIO;
  977. goto out;
  978. }
  979. /*
  980. * The following should only be used when hardware is present.
  981. */
  982. switch (cmd) {
  983. case TIOCMIWAIT:
  984. ret = uart_wait_modem_status(state, arg);
  985. break;
  986. case TIOCGICOUNT:
  987. ret = uart_get_count(state, uarg);
  988. break;
  989. }
  990. if (ret != -ENOIOCTLCMD)
  991. goto out;
  992. mutex_lock(&port->mutex);
  993. if (tty_hung_up_p(filp)) {
  994. ret = -EIO;
  995. goto out_up;
  996. }
  997. /*
  998. * All these rely on hardware being present and need to be
  999. * protected against the tty being hung up.
  1000. */
  1001. switch (cmd) {
  1002. case TIOCSERGETLSR: /* Get line status register */
  1003. ret = uart_get_lsr_info(tty, state, uarg);
  1004. break;
  1005. default: {
  1006. struct uart_port *uport = state->uart_port;
  1007. if (uport->ops->ioctl)
  1008. ret = uport->ops->ioctl(uport, cmd, arg);
  1009. break;
  1010. }
  1011. }
  1012. out_up:
  1013. mutex_unlock(&port->mutex);
  1014. out:
  1015. return ret;
  1016. }
  1017. static void uart_set_ldisc(struct tty_struct *tty)
  1018. {
  1019. struct uart_state *state = tty->driver_data;
  1020. struct uart_port *uport = state->uart_port;
  1021. if (uport->ops->set_ldisc)
  1022. uport->ops->set_ldisc(uport, tty->termios->c_line);
  1023. }
  1024. static void uart_set_termios(struct tty_struct *tty,
  1025. struct ktermios *old_termios)
  1026. {
  1027. struct uart_state *state = tty->driver_data;
  1028. unsigned long flags;
  1029. unsigned int cflag = tty->termios->c_cflag;
  1030. /*
  1031. * These are the bits that are used to setup various
  1032. * flags in the low level driver. We can ignore the Bfoo
  1033. * bits in c_cflag; c_[io]speed will always be set
  1034. * appropriately by set_termios() in tty_ioctl.c
  1035. */
  1036. #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  1037. if ((cflag ^ old_termios->c_cflag) == 0 &&
  1038. tty->termios->c_ospeed == old_termios->c_ospeed &&
  1039. tty->termios->c_ispeed == old_termios->c_ispeed &&
  1040. RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) {
  1041. return;
  1042. }
  1043. uart_change_speed(tty, state, old_termios);
  1044. /* Handle transition to B0 status */
  1045. if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
  1046. uart_clear_mctrl(state->uart_port, TIOCM_RTS | TIOCM_DTR);
  1047. /* Handle transition away from B0 status */
  1048. else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
  1049. unsigned int mask = TIOCM_DTR;
  1050. if (!(cflag & CRTSCTS) ||
  1051. !test_bit(TTY_THROTTLED, &tty->flags))
  1052. mask |= TIOCM_RTS;
  1053. uart_set_mctrl(state->uart_port, mask);
  1054. }
  1055. /* Handle turning off CRTSCTS */
  1056. if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
  1057. spin_lock_irqsave(&state->uart_port->lock, flags);
  1058. tty->hw_stopped = 0;
  1059. __uart_start(tty);
  1060. spin_unlock_irqrestore(&state->uart_port->lock, flags);
  1061. }
  1062. /* Handle turning on CRTSCTS */
  1063. else if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
  1064. spin_lock_irqsave(&state->uart_port->lock, flags);
  1065. if (!(state->uart_port->ops->get_mctrl(state->uart_port) & TIOCM_CTS)) {
  1066. tty->hw_stopped = 1;
  1067. state->uart_port->ops->stop_tx(state->uart_port);
  1068. }
  1069. spin_unlock_irqrestore(&state->uart_port->lock, flags);
  1070. }
  1071. #if 0
  1072. /*
  1073. * No need to wake up processes in open wait, since they
  1074. * sample the CLOCAL flag once, and don't recheck it.
  1075. * XXX It's not clear whether the current behavior is correct
  1076. * or not. Hence, this may change.....
  1077. */
  1078. if (!(old_termios->c_cflag & CLOCAL) &&
  1079. (tty->termios->c_cflag & CLOCAL))
  1080. wake_up_interruptible(&state->uart_port.open_wait);
  1081. #endif
  1082. }
  1083. /*
  1084. * In 2.4.5, calls to this will be serialized via the BKL in
  1085. * linux/drivers/char/tty_io.c:tty_release()
  1086. * linux/drivers/char/tty_io.c:do_tty_handup()
  1087. */
  1088. static void uart_close(struct tty_struct *tty, struct file *filp)
  1089. {
  1090. struct uart_state *state = tty->driver_data;
  1091. struct tty_port *port;
  1092. struct uart_port *uport;
  1093. unsigned long flags;
  1094. BUG_ON(!kernel_locked());
  1095. if (!state)
  1096. return;
  1097. uport = state->uart_port;
  1098. port = &state->port;
  1099. pr_debug("uart_close(%d) called\n", uport->line);
  1100. mutex_lock(&port->mutex);
  1101. spin_lock_irqsave(&port->lock, flags);
  1102. if (tty_hung_up_p(filp)) {
  1103. spin_unlock_irqrestore(&port->lock, flags);
  1104. goto done;
  1105. }
  1106. if ((tty->count == 1) && (port->count != 1)) {
  1107. /*
  1108. * Uh, oh. tty->count is 1, which means that the tty
  1109. * structure will be freed. port->count should always
  1110. * be one in these conditions. If it's greater than
  1111. * one, we've got real problems, since it means the
  1112. * serial port won't be shutdown.
  1113. */
  1114. printk(KERN_ERR "uart_close: bad serial port count; tty->count is 1, "
  1115. "port->count is %d\n", port->count);
  1116. port->count = 1;
  1117. }
  1118. if (--port->count < 0) {
  1119. printk(KERN_ERR "uart_close: bad serial port count for %s: %d\n",
  1120. tty->name, port->count);
  1121. port->count = 0;
  1122. }
  1123. if (port->count) {
  1124. spin_unlock_irqrestore(&port->lock, flags);
  1125. goto done;
  1126. }
  1127. /*
  1128. * Now we wait for the transmit buffer to clear; and we notify
  1129. * the line discipline to only process XON/XOFF characters by
  1130. * setting tty->closing.
  1131. */
  1132. tty->closing = 1;
  1133. spin_unlock_irqrestore(&port->lock, flags);
  1134. if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1135. tty_wait_until_sent(tty, msecs_to_jiffies(port->closing_wait));
  1136. /*
  1137. * At this point, we stop accepting input. To do this, we
  1138. * disable the receive line status interrupts.
  1139. */
  1140. if (port->flags & ASYNC_INITIALIZED) {
  1141. unsigned long flags;
  1142. spin_lock_irqsave(&uport->lock, flags);
  1143. uport->ops->stop_rx(uport);
  1144. spin_unlock_irqrestore(&uport->lock, flags);
  1145. /*
  1146. * Before we drop DTR, make sure the UART transmitter
  1147. * has completely drained; this is especially
  1148. * important if there is a transmit FIFO!
  1149. */
  1150. uart_wait_until_sent(tty, uport->timeout);
  1151. }
  1152. uart_shutdown(tty, state);
  1153. uart_flush_buffer(tty);
  1154. tty_ldisc_flush(tty);
  1155. tty_port_tty_set(port, NULL);
  1156. spin_lock_irqsave(&port->lock, flags);
  1157. tty->closing = 0;
  1158. if (port->blocked_open) {
  1159. spin_unlock_irqrestore(&port->lock, flags);
  1160. if (port->close_delay)
  1161. msleep_interruptible(port->close_delay);
  1162. spin_lock_irqsave(&port->lock, flags);
  1163. } else if (!uart_console(uport)) {
  1164. spin_unlock_irqrestore(&port->lock, flags);
  1165. uart_change_pm(state, 3);
  1166. spin_lock_irqsave(&port->lock, flags);
  1167. }
  1168. /*
  1169. * Wake up anyone trying to open this port.
  1170. */
  1171. clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
  1172. spin_unlock_irqrestore(&port->lock, flags);
  1173. wake_up_interruptible(&port->open_wait);
  1174. done:
  1175. mutex_unlock(&port->mutex);
  1176. }
  1177. static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
  1178. {
  1179. struct uart_state *state = tty->driver_data;
  1180. struct uart_port *port = state->uart_port;
  1181. unsigned long char_time, expire;
  1182. if (port->type == PORT_UNKNOWN || port->fifosize == 0)
  1183. return;
  1184. lock_kernel();
  1185. /*
  1186. * Set the check interval to be 1/5 of the estimated time to
  1187. * send a single character, and make it at least 1. The check
  1188. * interval should also be less than the timeout.
  1189. *
  1190. * Note: we have to use pretty tight timings here to satisfy
  1191. * the NIST-PCTS.
  1192. */
  1193. char_time = (port->timeout - HZ/50) / port->fifosize;
  1194. char_time = char_time / 5;
  1195. if (char_time == 0)
  1196. char_time = 1;
  1197. if (timeout && timeout < char_time)
  1198. char_time = timeout;
  1199. /*
  1200. * If the transmitter hasn't cleared in twice the approximate
  1201. * amount of time to send the entire FIFO, it probably won't
  1202. * ever clear. This assumes the UART isn't doing flow
  1203. * control, which is currently the case. Hence, if it ever
  1204. * takes longer than port->timeout, this is probably due to a
  1205. * UART bug of some kind. So, we clamp the timeout parameter at
  1206. * 2*port->timeout.
  1207. */
  1208. if (timeout == 0 || timeout > 2 * port->timeout)
  1209. timeout = 2 * port->timeout;
  1210. expire = jiffies + timeout;
  1211. pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n",
  1212. port->line, jiffies, expire);
  1213. /*
  1214. * Check whether the transmitter is empty every 'char_time'.
  1215. * 'timeout' / 'expire' give us the maximum amount of time
  1216. * we wait.
  1217. */
  1218. while (!port->ops->tx_empty(port)) {
  1219. msleep_interruptible(jiffies_to_msecs(char_time));
  1220. if (signal_pending(current))
  1221. break;
  1222. if (time_after(jiffies, expire))
  1223. break;
  1224. }
  1225. set_current_state(TASK_RUNNING); /* might not be needed */
  1226. unlock_kernel();
  1227. }
  1228. /*
  1229. * This is called with the BKL held in
  1230. * linux/drivers/char/tty_io.c:do_tty_hangup()
  1231. * We're called from the eventd thread, so we can sleep for
  1232. * a _short_ time only.
  1233. */
  1234. static void uart_hangup(struct tty_struct *tty)
  1235. {
  1236. struct uart_state *state = tty->driver_data;
  1237. struct tty_port *port = &state->port;
  1238. unsigned long flags;
  1239. BUG_ON(!kernel_locked());
  1240. pr_debug("uart_hangup(%d)\n", state->uart_port->line);
  1241. mutex_lock(&port->mutex);
  1242. if (port->flags & ASYNC_NORMAL_ACTIVE) {
  1243. uart_flush_buffer(tty);
  1244. uart_shutdown(tty, state);
  1245. spin_lock_irqsave(&port->lock, flags);
  1246. port->count = 0;
  1247. clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
  1248. spin_unlock_irqrestore(&port->lock, flags);
  1249. tty_port_tty_set(port, NULL);
  1250. wake_up_interruptible(&port->open_wait);
  1251. wake_up_interruptible(&port->delta_msr_wait);
  1252. }
  1253. mutex_unlock(&port->mutex);
  1254. }
  1255. /**
  1256. * uart_update_termios - update the terminal hw settings
  1257. * @tty: tty associated with UART
  1258. * @state: UART to update
  1259. *
  1260. * Copy across the serial console cflag setting into the termios settings
  1261. * for the initial open of the port. This allows continuity between the
  1262. * kernel settings, and the settings init adopts when it opens the port
  1263. * for the first time.
  1264. */
  1265. static void uart_update_termios(struct tty_struct *tty,
  1266. struct uart_state *state)
  1267. {
  1268. struct uart_port *port = state->uart_port;
  1269. if (uart_console(port) && port->cons->cflag) {
  1270. tty->termios->c_cflag = port->cons->cflag;
  1271. port->cons->cflag = 0;
  1272. }
  1273. /*
  1274. * If the device failed to grab its irq resources,
  1275. * or some other error occurred, don't try to talk
  1276. * to the port hardware.
  1277. */
  1278. if (!(tty->flags & (1 << TTY_IO_ERROR))) {
  1279. /*
  1280. * Make termios settings take effect.
  1281. */
  1282. uart_change_speed(tty, state, NULL);
  1283. /*
  1284. * And finally enable the RTS and DTR signals.
  1285. */
  1286. if (tty->termios->c_cflag & CBAUD)
  1287. uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
  1288. }
  1289. }
  1290. static int uart_carrier_raised(struct tty_port *port)
  1291. {
  1292. struct uart_state *state = container_of(port, struct uart_state, port);
  1293. struct uart_port *uport = state->uart_port;
  1294. int mctrl;
  1295. mutex_lock(&port->mutex);
  1296. spin_lock_irq(&uport->lock);
  1297. uport->ops->enable_ms(uport);
  1298. mctrl = uport->ops->get_mctrl(uport);
  1299. spin_unlock_irq(&uport->lock);
  1300. mutex_unlock(&port->mutex);
  1301. if (mctrl & TIOCM_CAR)
  1302. return 1;
  1303. return 0;
  1304. }
  1305. static void uart_dtr_rts(struct tty_port *port, int onoff)
  1306. {
  1307. struct uart_state *state = container_of(port, struct uart_state, port);
  1308. struct uart_port *uport = state->uart_port;
  1309. mutex_lock(&port->mutex);
  1310. if (onoff)
  1311. uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
  1312. else
  1313. uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
  1314. mutex_unlock(&port->mutex);
  1315. }
  1316. /*
  1317. * Block the open until the port is ready. We must be called with
  1318. * the per-port semaphore held.
  1319. */
  1320. static int
  1321. uart_block_til_ready(struct file *filp, struct uart_state *state)
  1322. {
  1323. DECLARE_WAITQUEUE(wait, current);
  1324. struct tty_port *port = &state->port;
  1325. unsigned long flags;
  1326. spin_lock_irqsave(&port->lock, flags);
  1327. if (!tty_hung_up_p(filp))
  1328. port->count--;
  1329. port->blocked_open++;
  1330. spin_unlock_irqrestore(&port->lock, flags);
  1331. add_wait_queue(&port->open_wait, &wait);
  1332. while (1) {
  1333. set_current_state(TASK_INTERRUPTIBLE);
  1334. /*
  1335. * If we have been hung up, tell userspace/restart open.
  1336. */
  1337. if (tty_hung_up_p(filp) || port->tty == NULL)
  1338. break;
  1339. /*
  1340. * If the port has been closed, tell userspace/restart open.
  1341. */
  1342. if (!(port->flags & ASYNC_INITIALIZED))
  1343. break;
  1344. /*
  1345. * If non-blocking mode is set, or CLOCAL mode is set,
  1346. * we don't want to wait for the modem status lines to
  1347. * indicate that the port is ready.
  1348. *
  1349. * Also, if the port is not enabled/configured, we want
  1350. * to allow the open to succeed here. Note that we will
  1351. * have set TTY_IO_ERROR for a non-existant port.
  1352. */
  1353. if ((filp->f_flags & O_NONBLOCK) ||
  1354. (port->tty->termios->c_cflag & CLOCAL) ||
  1355. (port->tty->flags & (1 << TTY_IO_ERROR)))
  1356. break;
  1357. /*
  1358. * Set DTR to allow modem to know we're waiting. Do
  1359. * not set RTS here - we want to make sure we catch
  1360. * the data from the modem.
  1361. */
  1362. if (port->tty->termios->c_cflag & CBAUD)
  1363. tty_port_raise_dtr_rts(port);
  1364. /*
  1365. * and wait for the carrier to indicate that the
  1366. * modem is ready for us.
  1367. */
  1368. if (tty_port_carrier_raised(port))
  1369. break;
  1370. schedule();
  1371. if (signal_pending(current))
  1372. break;
  1373. }
  1374. set_current_state(TASK_RUNNING);
  1375. remove_wait_queue(&port->open_wait, &wait);
  1376. spin_lock_irqsave(&port->lock, flags);
  1377. if (!tty_hung_up_p(filp))
  1378. port->count++;
  1379. port->blocked_open--;
  1380. spin_unlock_irqrestore(&port->lock, flags);
  1381. if (signal_pending(current))
  1382. return -ERESTARTSYS;
  1383. if (!port->tty || tty_hung_up_p(filp))
  1384. return -EAGAIN;
  1385. return 0;
  1386. }
  1387. static struct uart_state *uart_get(struct uart_driver *drv, int line)
  1388. {
  1389. struct uart_state *state;
  1390. struct tty_port *port;
  1391. int ret = 0;
  1392. state = drv->state + line;
  1393. port = &state->port;
  1394. if (mutex_lock_interruptible(&port->mutex)) {
  1395. ret = -ERESTARTSYS;
  1396. goto err;
  1397. }
  1398. port->count++;
  1399. if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
  1400. ret = -ENXIO;
  1401. goto err_unlock;
  1402. }
  1403. return state;
  1404. err_unlock:
  1405. port->count--;
  1406. mutex_unlock(&port->mutex);
  1407. err:
  1408. return ERR_PTR(ret);
  1409. }
  1410. /*
  1411. * calls to uart_open are serialised by the BKL in
  1412. * fs/char_dev.c:chrdev_open()
  1413. * Note that if this fails, then uart_close() _will_ be called.
  1414. *
  1415. * In time, we want to scrap the "opening nonpresent ports"
  1416. * behaviour and implement an alternative way for setserial
  1417. * to set base addresses/ports/types. This will allow us to
  1418. * get rid of a certain amount of extra tests.
  1419. */
  1420. static int uart_open(struct tty_struct *tty, struct file *filp)
  1421. {
  1422. struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state;
  1423. struct uart_state *state;
  1424. struct tty_port *port;
  1425. int retval, line = tty->index;
  1426. BUG_ON(!kernel_locked());
  1427. pr_debug("uart_open(%d) called\n", line);
  1428. /*
  1429. * tty->driver->num won't change, so we won't fail here with
  1430. * tty->driver_data set to something non-NULL (and therefore
  1431. * we won't get caught by uart_close()).
  1432. */
  1433. retval = -ENODEV;
  1434. if (line >= tty->driver->num)
  1435. goto fail;
  1436. /*
  1437. * We take the semaphore inside uart_get to guarantee that we won't
  1438. * be re-entered while allocating the state structure, or while we
  1439. * request any IRQs that the driver may need. This also has the nice
  1440. * side-effect that it delays the action of uart_hangup, so we can
  1441. * guarantee that state->port.tty will always contain something
  1442. * reasonable.
  1443. */
  1444. state = uart_get(drv, line);
  1445. if (IS_ERR(state)) {
  1446. retval = PTR_ERR(state);
  1447. goto fail;
  1448. }
  1449. port = &state->port;
  1450. /*
  1451. * Once we set tty->driver_data here, we are guaranteed that
  1452. * uart_close() will decrement the driver module use count.
  1453. * Any failures from here onwards should not touch the count.
  1454. */
  1455. tty->driver_data = state;
  1456. state->uart_port->state = state;
  1457. tty->low_latency = (state->uart_port->flags & UPF_LOW_LATENCY) ? 1 : 0;
  1458. tty->alt_speed = 0;
  1459. tty_port_tty_set(port, tty);
  1460. /*
  1461. * If the port is in the middle of closing, bail out now.
  1462. */
  1463. if (tty_hung_up_p(filp)) {
  1464. retval = -EAGAIN;
  1465. port->count--;
  1466. mutex_unlock(&port->mutex);
  1467. goto fail;
  1468. }
  1469. /*
  1470. * Make sure the device is in D0 state.
  1471. */
  1472. if (port->count == 1)
  1473. uart_change_pm(state, 0);
  1474. /*
  1475. * Start up the serial port.
  1476. */
  1477. retval = uart_startup(tty, state, 0);
  1478. /*
  1479. * If we succeeded, wait until the port is ready.
  1480. */
  1481. mutex_unlock(&port->mutex);
  1482. if (retval == 0)
  1483. retval = uart_block_til_ready(filp, state);
  1484. /*
  1485. * If this is the first open to succeed, adjust things to suit.
  1486. */
  1487. if (retval == 0 && !(port->flags & ASYNC_NORMAL_ACTIVE)) {
  1488. set_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
  1489. uart_update_termios(tty, state);
  1490. }
  1491. fail:
  1492. return retval;
  1493. }
  1494. static const char *uart_type(struct uart_port *port)
  1495. {
  1496. const char *str = NULL;
  1497. if (port->ops->type)
  1498. str = port->ops->type(port);
  1499. if (!str)
  1500. str = "unknown";
  1501. return str;
  1502. }
  1503. #ifdef CONFIG_PROC_FS
  1504. static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i)
  1505. {
  1506. struct uart_state *state = drv->state + i;
  1507. struct tty_port *port = &state->port;
  1508. int pm_state;
  1509. struct uart_port *uport = state->uart_port;
  1510. char stat_buf[32];
  1511. unsigned int status;
  1512. int mmio;
  1513. if (!uport)
  1514. return;
  1515. mmio = uport->iotype >= UPIO_MEM;
  1516. seq_printf(m, "%d: uart:%s %s%08llX irq:%d",
  1517. uport->line, uart_type(uport),
  1518. mmio ? "mmio:0x" : "port:",
  1519. mmio ? (unsigned long long)uport->mapbase
  1520. : (unsigned long long)uport->iobase,
  1521. uport->irq);
  1522. if (uport->type == PORT_UNKNOWN) {
  1523. seq_putc(m, '\n');
  1524. return;
  1525. }
  1526. if (capable(CAP_SYS_ADMIN)) {
  1527. mutex_lock(&port->mutex);
  1528. pm_state = state->pm_state;
  1529. if (pm_state)
  1530. uart_change_pm(state, 0);
  1531. spin_lock_irq(&uport->lock);
  1532. status = uport->ops->get_mctrl(uport);
  1533. spin_unlock_irq(&uport->lock);
  1534. if (pm_state)
  1535. uart_change_pm(state, pm_state);
  1536. mutex_unlock(&port->mutex);
  1537. seq_printf(m, " tx:%d rx:%d",
  1538. uport->icount.tx, uport->icount.rx);
  1539. if (uport->icount.frame)
  1540. seq_printf(m, " fe:%d",
  1541. uport->icount.frame);
  1542. if (uport->icount.parity)
  1543. seq_printf(m, " pe:%d",
  1544. uport->icount.parity);
  1545. if (uport->icount.brk)
  1546. seq_printf(m, " brk:%d",
  1547. uport->icount.brk);
  1548. if (uport->icount.overrun)
  1549. seq_printf(m, " oe:%d",
  1550. uport->icount.overrun);
  1551. #define INFOBIT(bit, str) \
  1552. if (uport->mctrl & (bit)) \
  1553. strncat(stat_buf, (str), sizeof(stat_buf) - \
  1554. strlen(stat_buf) - 2)
  1555. #define STATBIT(bit, str) \
  1556. if (status & (bit)) \
  1557. strncat(stat_buf, (str), sizeof(stat_buf) - \
  1558. strlen(stat_buf) - 2)
  1559. stat_buf[0] = '\0';
  1560. stat_buf[1] = '\0';
  1561. INFOBIT(TIOCM_RTS, "|RTS");
  1562. STATBIT(TIOCM_CTS, "|CTS");
  1563. INFOBIT(TIOCM_DTR, "|DTR");
  1564. STATBIT(TIOCM_DSR, "|DSR");
  1565. STATBIT(TIOCM_CAR, "|CD");
  1566. STATBIT(TIOCM_RNG, "|RI");
  1567. if (stat_buf[0])
  1568. stat_buf[0] = ' ';
  1569. seq_puts(m, stat_buf);
  1570. }
  1571. seq_putc(m, '\n');
  1572. #undef STATBIT
  1573. #undef INFOBIT
  1574. }
  1575. static int uart_proc_show(struct seq_file *m, void *v)
  1576. {
  1577. struct tty_driver *ttydrv = m->private;
  1578. struct uart_driver *drv = ttydrv->driver_state;
  1579. int i;
  1580. seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n",
  1581. "", "", "");
  1582. for (i = 0; i < drv->nr; i++)
  1583. uart_line_info(m, drv, i);
  1584. return 0;
  1585. }
  1586. static int uart_proc_open(struct inode *inode, struct file *file)
  1587. {
  1588. return single_open(file, uart_proc_show, PDE(inode)->data);
  1589. }
  1590. static const struct file_operations uart_proc_fops = {
  1591. .owner = THIS_MODULE,
  1592. .open = uart_proc_open,
  1593. .read = seq_read,
  1594. .llseek = seq_lseek,
  1595. .release = single_release,
  1596. };
  1597. #endif
  1598. #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
  1599. /*
  1600. * uart_console_write - write a console message to a serial port
  1601. * @port: the port to write the message
  1602. * @s: array of characters
  1603. * @count: number of characters in string to write
  1604. * @write: function to write character to port
  1605. */
  1606. void uart_console_write(struct uart_port *port, const char *s,
  1607. unsigned int count,
  1608. void (*putchar)(struct uart_port *, int))
  1609. {
  1610. unsigned int i;
  1611. for (i = 0; i < count; i++, s++) {
  1612. if (*s == '\n')
  1613. putchar(port, '\r');
  1614. putchar(port, *s);
  1615. }
  1616. }
  1617. EXPORT_SYMBOL_GPL(uart_console_write);
  1618. /*
  1619. * Check whether an invalid uart number has been specified, and
  1620. * if so, search for the first available port that does have
  1621. * console support.
  1622. */
  1623. struct uart_port * __init
  1624. uart_get_console(struct uart_port *ports, int nr, struct console *co)
  1625. {
  1626. int idx = co->index;
  1627. if (idx < 0 || idx >= nr || (ports[idx].iobase == 0 &&
  1628. ports[idx].membase == NULL))
  1629. for (idx = 0; idx < nr; idx++)
  1630. if (ports[idx].iobase != 0 ||
  1631. ports[idx].membase != NULL)
  1632. break;
  1633. co->index = idx;
  1634. return ports + idx;
  1635. }
  1636. /**
  1637. * uart_parse_options - Parse serial port baud/parity/bits/flow contro.
  1638. * @options: pointer to option string
  1639. * @baud: pointer to an 'int' variable for the baud rate.
  1640. * @parity: pointer to an 'int' variable for the parity.
  1641. * @bits: pointer to an 'int' variable for the number of data bits.
  1642. * @flow: pointer to an 'int' variable for the flow control character.
  1643. *
  1644. * uart_parse_options decodes a string containing the serial console
  1645. * options. The format of the string is <baud><parity><bits><flow>,
  1646. * eg: 115200n8r
  1647. */
  1648. void
  1649. uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow)
  1650. {
  1651. char *s = options;
  1652. *baud = simple_strtoul(s, NULL, 10);
  1653. while (*s >= '0' && *s <= '9')
  1654. s++;
  1655. if (*s)
  1656. *parity = *s++;
  1657. if (*s)
  1658. *bits = *s++ - '0';
  1659. if (*s)
  1660. *flow = *s;
  1661. }
  1662. EXPORT_SYMBOL_GPL(uart_parse_options);
  1663. struct baud_rates {
  1664. unsigned int rate;
  1665. unsigned int cflag;
  1666. };
  1667. static const struct baud_rates baud_rates[] = {
  1668. { 921600, B921600 },
  1669. { 460800, B460800 },
  1670. { 230400, B230400 },
  1671. { 115200, B115200 },
  1672. { 57600, B57600 },
  1673. { 38400, B38400 },
  1674. { 19200, B19200 },
  1675. { 9600, B9600 },
  1676. { 4800, B4800 },
  1677. { 2400, B2400 },
  1678. { 1200, B1200 },
  1679. { 0, B38400 }
  1680. };
  1681. /**
  1682. * uart_set_options - setup the serial console parameters
  1683. * @port: pointer to the serial ports uart_port structure
  1684. * @co: console pointer
  1685. * @baud: baud rate
  1686. * @parity: parity character - 'n' (none), 'o' (odd), 'e' (even)
  1687. * @bits: number of data bits
  1688. * @flow: flow control character - 'r' (rts)
  1689. */
  1690. int
  1691. uart_set_options(struct uart_port *port, struct console *co,
  1692. int baud, int parity, int bits, int flow)
  1693. {
  1694. struct ktermios termios;
  1695. static struct ktermios dummy;
  1696. int i;
  1697. /*
  1698. * Ensure that the serial console lock is initialised
  1699. * early.
  1700. */
  1701. spin_lock_init(&port->lock);
  1702. lockdep_set_class(&port->lock, &port_lock_key);
  1703. memset(&termios, 0, sizeof(struct ktermios));
  1704. termios.c_cflag = CREAD | HUPCL | CLOCAL;
  1705. /*
  1706. * Construct a cflag setting.
  1707. */
  1708. for (i = 0; baud_rates[i].rate; i++)
  1709. if (baud_rates[i].rate <= baud)
  1710. break;
  1711. termios.c_cflag |= baud_rates[i].cflag;
  1712. if (bits == 7)
  1713. termios.c_cflag |= CS7;
  1714. else
  1715. termios.c_cflag |= CS8;
  1716. switch (parity) {
  1717. case 'o': case 'O':
  1718. termios.c_cflag |= PARODD;
  1719. /*fall through*/
  1720. case 'e': case 'E':
  1721. termios.c_cflag |= PARENB;
  1722. break;
  1723. }
  1724. if (flow == 'r')
  1725. termios.c_cflag |= CRTSCTS;
  1726. /*
  1727. * some uarts on other side don't support no flow control.
  1728. * So we set * DTR in host uart to make them happy
  1729. */
  1730. port->mctrl |= TIOCM_DTR;
  1731. port->ops->set_termios(port, &termios, &dummy);
  1732. /*
  1733. * Allow the setting of the UART parameters with a NULL console
  1734. * too:
  1735. */
  1736. if (co)
  1737. co->cflag = termios.c_cflag;
  1738. return 0;
  1739. }
  1740. EXPORT_SYMBOL_GPL(uart_set_options);
  1741. #endif /* CONFIG_SERIAL_CORE_CONSOLE */
  1742. static void uart_change_pm(struct uart_state *state, int pm_state)
  1743. {
  1744. struct uart_port *port = state->uart_port;
  1745. if (state->pm_state != pm_state) {
  1746. if (port->ops->pm)
  1747. port->ops->pm(port, pm_state, state->pm_state);
  1748. state->pm_state = pm_state;
  1749. }
  1750. }
  1751. struct uart_match {
  1752. struct uart_port *port;
  1753. struct uart_driver *driver;
  1754. };
  1755. static int serial_match_port(struct device *dev, void *data)
  1756. {
  1757. struct uart_match *match = data;
  1758. struct tty_driver *tty_drv = match->driver->tty_driver;
  1759. dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
  1760. match->port->line;
  1761. return dev->devt == devt; /* Actually, only one tty per port */
  1762. }
  1763. int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
  1764. {
  1765. struct uart_state *state = drv->state + uport->line;
  1766. struct tty_port *port = &state->port;
  1767. struct device *tty_dev;
  1768. struct uart_match match = {uport, drv};
  1769. struct tty_struct *tty;
  1770. mutex_lock(&port->mutex);
  1771. /* Must be inside the mutex lock until we convert to tty_port */
  1772. tty = port->tty;
  1773. tty_dev = device_find_child(uport->dev, &match, serial_match_port);
  1774. if (device_may_wakeup(tty_dev)) {
  1775. enable_irq_wake(uport->irq);
  1776. put_device(tty_dev);
  1777. mutex_unlock(&port->mutex);
  1778. return 0;
  1779. }
  1780. if (console_suspend_enabled || !uart_console(uport))
  1781. uport->suspended = 1;
  1782. if (port->flags & ASYNC_INITIALIZED) {
  1783. const struct uart_ops *ops = uport->ops;
  1784. int tries;
  1785. if (console_suspend_enabled || !uart_console(uport)) {
  1786. set_bit(ASYNCB_SUSPENDED, &port->flags);
  1787. clear_bit(ASYNCB_INITIALIZED, &port->flags);
  1788. spin_lock_irq(&uport->lock);
  1789. ops->stop_tx(uport);
  1790. ops->set_mctrl(uport, 0);
  1791. ops->stop_rx(uport);
  1792. spin_unlock_irq(&uport->lock);
  1793. }
  1794. /*
  1795. * Wait for the transmitter to empty.
  1796. */
  1797. for (tries = 3; !ops->tx_empty(uport) && tries; tries--)
  1798. msleep(10);
  1799. if (!tries)
  1800. printk(KERN_ERR "%s%s%s%d: Unable to drain "
  1801. "transmitter\n",
  1802. uport->dev ? dev_name(uport->dev) : "",
  1803. uport->dev ? ": " : "",
  1804. drv->dev_name,
  1805. drv->tty_driver->name_base + uport->line);
  1806. if (console_suspend_enabled || !uart_console(uport))
  1807. ops->shutdown(uport);
  1808. }
  1809. /*
  1810. * Disable the console device before suspending.
  1811. */
  1812. if (console_suspend_enabled && uart_console(uport))
  1813. console_stop(uport->cons);
  1814. if (console_suspend_enabled || !uart_console(uport))
  1815. uart_change_pm(state, 3);
  1816. mutex_unlock(&port->mutex);
  1817. return 0;
  1818. }
  1819. int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
  1820. {
  1821. struct uart_state *state = drv->state + uport->line;
  1822. struct tty_port *port = &state->port;
  1823. struct device *tty_dev;
  1824. struct uart_match match = {uport, drv};
  1825. struct ktermios termios;
  1826. mutex_lock(&port->mutex);
  1827. tty_dev = device_find_child(uport->dev, &match, serial_match_port);
  1828. if (!uport->suspended && device_may_wakeup(tty_dev)) {
  1829. disable_irq_wake(uport->irq);
  1830. mutex_unlock(&port->mutex);
  1831. return 0;
  1832. }
  1833. uport->suspended = 0;
  1834. /*
  1835. * Re-enable the console device after suspending.
  1836. */
  1837. if (uart_console(uport)) {
  1838. uart_change_pm(state, 0);
  1839. uport->ops->set_termios(uport, &termios, NULL);
  1840. console_start(uport->cons);
  1841. }
  1842. if (port->flags & ASYNC_SUSPENDED) {
  1843. const struct uart_ops *ops = uport->ops;
  1844. int ret;
  1845. uart_change_pm(state, 0);
  1846. spin_lock_irq(&uport->lock);
  1847. ops->set_mctrl(uport, 0);
  1848. spin_unlock_irq(&uport->lock);
  1849. if (console_suspend_enabled || !uart_console(uport)) {
  1850. /* Protected by port mutex for now */
  1851. struct tty_struct *tty = port->tty;
  1852. ret = ops->startup(uport);
  1853. if (ret == 0) {
  1854. if (tty)
  1855. uart_change_speed(tty, state, NULL);
  1856. spin_lock_irq(&uport->lock);
  1857. ops->set_mctrl(uport, uport->mctrl);
  1858. ops->start_tx(uport);
  1859. spin_unlock_irq(&uport->lock);
  1860. set_bit(ASYNCB_INITIALIZED, &port->flags);
  1861. } else {
  1862. /*
  1863. * Failed to resume - maybe hardware went away?
  1864. * Clear the "initialized" flag so we won't try
  1865. * to call the low level drivers shutdown method.
  1866. */
  1867. uart_shutdown(tty, state);
  1868. }
  1869. }
  1870. clear_bit(ASYNCB_SUSPENDED, &port->flags);
  1871. }
  1872. mutex_unlock(&port->mutex);
  1873. return 0;
  1874. }
  1875. static inline void
  1876. uart_report_port(struct uart_driver *drv, struct uart_port *port)
  1877. {
  1878. char address[64];
  1879. switch (port->iotype) {
  1880. case UPIO_PORT:
  1881. snprintf(address, sizeof(address), "I/O 0x%lx", port->iobase);
  1882. break;
  1883. case UPIO_HUB6:
  1884. snprintf(address, sizeof(address),
  1885. "I/O 0x%lx offset 0x%x", port->iobase, port->hub6);
  1886. break;
  1887. case UPIO_MEM:
  1888. case UPIO_MEM32:
  1889. case UPIO_AU:
  1890. case UPIO_TSI:
  1891. case UPIO_DWAPB:
  1892. snprintf(address, sizeof(address),
  1893. "MMIO 0x%llx", (unsigned long long)port->mapbase);
  1894. break;
  1895. default:
  1896. strlcpy(address, "*unknown*", sizeof(address));
  1897. break;
  1898. }
  1899. printk(KERN_INFO "%s%s%s%d at %s (irq = %d) is a %s\n",
  1900. port->dev ? dev_name(port->dev) : "",
  1901. port->dev ? ": " : "",
  1902. drv->dev_name,
  1903. drv->tty_driver->name_base + port->line,
  1904. address, port->irq, uart_type(port));
  1905. }
  1906. static void
  1907. uart_configure_port(struct uart_driver *drv, struct uart_state *state,
  1908. struct uart_port *port)
  1909. {
  1910. unsigned int flags;
  1911. /*
  1912. * If there isn't a port here, don't do anything further.
  1913. */
  1914. if (!port->iobase && !port->mapbase && !port->membase)
  1915. return;
  1916. /*
  1917. * Now do the auto configuration stuff. Note that config_port
  1918. * is expected to claim the resources and map the port for us.
  1919. */
  1920. flags = 0;
  1921. if (port->flags & UPF_AUTO_IRQ)
  1922. flags |= UART_CONFIG_IRQ;
  1923. if (port->flags & UPF_BOOT_AUTOCONF) {
  1924. if (!(port->flags & UPF_FIXED_TYPE)) {
  1925. port->type = PORT_UNKNOWN;
  1926. flags |= UART_CONFIG_TYPE;
  1927. }
  1928. port->ops->config_port(port, flags);
  1929. }
  1930. if (port->type != PORT_UNKNOWN) {
  1931. unsigned long flags;
  1932. uart_report_port(drv, port);
  1933. /* Power up port for set_mctrl() */
  1934. uart_change_pm(state, 0);
  1935. /*
  1936. * Ensure that the modem control lines are de-activated.
  1937. * keep the DTR setting that is set in uart_set_options()
  1938. * We probably don't need a spinlock around this, but
  1939. */
  1940. spin_lock_irqsave(&port->lock, flags);
  1941. port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR);
  1942. spin_unlock_irqrestore(&port->lock, flags);
  1943. /*
  1944. * If this driver supports console, and it hasn't been
  1945. * successfully registered yet, try to re-register it.
  1946. * It may be that the port was not available.
  1947. */
  1948. if (port->cons && !(port->cons->flags & CON_ENABLED))
  1949. register_console(port->cons);
  1950. /*
  1951. * Power down all ports by default, except the
  1952. * console if we have one.
  1953. */
  1954. if (!uart_console(port))
  1955. uart_change_pm(state, 3);
  1956. }
  1957. }
  1958. #ifdef CONFIG_CONSOLE_POLL
  1959. static int uart_poll_init(struct tty_driver *driver, int line, char *options)
  1960. {
  1961. struct uart_driver *drv = driver->driver_state;
  1962. struct uart_state *state = drv->state + line;
  1963. struct uart_port *port;
  1964. int baud = 9600;
  1965. int bits = 8;
  1966. int parity = 'n';
  1967. int flow = 'n';
  1968. if (!state || !state->uart_port)
  1969. return -1;
  1970. port = state->uart_port;
  1971. if (!(port->ops->poll_get_char && port->ops->poll_put_char))
  1972. return -1;
  1973. if (options) {
  1974. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1975. return uart_set_options(port, NULL, baud, parity, bits, flow);
  1976. }
  1977. return 0;
  1978. }
  1979. static int uart_poll_get_char(struct tty_driver *driver, int line)
  1980. {
  1981. struct uart_driver *drv = driver->driver_state;
  1982. struct uart_state *state = drv->state + line;
  1983. struct uart_port *port;
  1984. if (!state || !state->uart_port)
  1985. return -1;
  1986. port = state->uart_port;
  1987. return port->ops->poll_get_char(port);
  1988. }
  1989. static void uart_poll_put_char(struct tty_driver *driver, int line, char ch)
  1990. {
  1991. struct uart_driver *drv = driver->driver_state;
  1992. struct uart_state *state = drv->state + line;
  1993. struct uart_port *port;
  1994. if (!state || !state->uart_port)
  1995. return;
  1996. port = state->uart_port;
  1997. port->ops->poll_put_char(port, ch);
  1998. }
  1999. #endif
  2000. static const struct tty_operations uart_ops = {
  2001. .open = uart_open,
  2002. .close = uart_close,
  2003. .write = uart_write,
  2004. .put_char = uart_put_char,
  2005. .flush_chars = uart_flush_chars,
  2006. .write_room = uart_write_room,
  2007. .chars_in_buffer= uart_chars_in_buffer,
  2008. .flush_buffer = uart_flush_buffer,
  2009. .ioctl = uart_ioctl,
  2010. .throttle = uart_throttle,
  2011. .unthrottle = uart_unthrottle,
  2012. .send_xchar = uart_send_xchar,
  2013. .set_termios = uart_set_termios,
  2014. .set_ldisc = uart_set_ldisc,
  2015. .stop = uart_stop,
  2016. .start = uart_start,
  2017. .hangup = uart_hangup,
  2018. .break_ctl = uart_break_ctl,
  2019. .wait_until_sent= uart_wait_until_sent,
  2020. #ifdef CONFIG_PROC_FS
  2021. .proc_fops = &uart_proc_fops,
  2022. #endif
  2023. .tiocmget = uart_tiocmget,
  2024. .tiocmset = uart_tiocmset,
  2025. #ifdef CONFIG_CONSOLE_POLL
  2026. .poll_init = uart_poll_init,
  2027. .poll_get_char = uart_poll_get_char,
  2028. .poll_put_char = uart_poll_put_char,
  2029. #endif
  2030. };
  2031. static const struct tty_port_operations uart_port_ops = {
  2032. .carrier_raised = uart_carrier_raised,
  2033. .dtr_rts = uart_dtr_rts,
  2034. };
  2035. /**
  2036. * uart_register_driver - register a driver with the uart core layer
  2037. * @drv: low level driver structure
  2038. *
  2039. * Register a uart driver with the core driver. We in turn register
  2040. * with the tty layer, and initialise the core driver per-port state.
  2041. *
  2042. * We have a proc file in /proc/tty/driver which is named after the
  2043. * normal driver.
  2044. *
  2045. * drv->port should be NULL, and the per-port structures should be
  2046. * registered using uart_add_one_port after this call has succeeded.
  2047. */
  2048. int uart_register_driver(struct uart_driver *drv)
  2049. {
  2050. struct tty_driver *normal;
  2051. int i, retval;
  2052. BUG_ON(drv->state);
  2053. /*
  2054. * Maybe we should be using a slab cache for this, especially if
  2055. * we have a large number of ports to handle.
  2056. */
  2057. drv->state = kzalloc(sizeof(struct uart_state) * drv->nr, GFP_KERNEL);
  2058. if (!drv->state)
  2059. goto out;
  2060. normal = alloc_tty_driver(drv->nr);
  2061. if (!normal)
  2062. goto out_kfree;
  2063. drv->tty_driver = normal;
  2064. normal->owner = drv->owner;
  2065. normal->driver_name = drv->driver_name;
  2066. normal->name = drv->dev_name;
  2067. normal->major = drv->major;
  2068. normal->minor_start = drv->minor;
  2069. normal->type = TTY_DRIVER_TYPE_SERIAL;
  2070. normal->subtype = SERIAL_TYPE_NORMAL;
  2071. normal->init_termios = tty_std_termios;
  2072. normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  2073. normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600;
  2074. normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  2075. normal->driver_state = drv;
  2076. tty_set_operations(normal, &uart_ops);
  2077. /*
  2078. * Initialise the UART state(s).
  2079. */
  2080. for (i = 0; i < drv->nr; i++) {
  2081. struct uart_state *state = drv->state + i;
  2082. struct tty_port *port = &state->port;
  2083. tty_port_init(port);
  2084. port->ops = &uart_port_ops;
  2085. port->close_delay = 500; /* .5 seconds */
  2086. port->closing_wait = 30000; /* 30 seconds */
  2087. tasklet_init(&state->tlet, uart_tasklet_action,
  2088. (unsigned long)state);
  2089. }
  2090. retval = tty_register_driver(normal);
  2091. if (retval >= 0)
  2092. return retval;
  2093. put_tty_driver(normal);
  2094. out_kfree:
  2095. kfree(drv->state);
  2096. out:
  2097. return -ENOMEM;
  2098. }
  2099. /**
  2100. * uart_unregister_driver - remove a driver from the uart core layer
  2101. * @drv: low level driver structure
  2102. *
  2103. * Remove all references to a driver from the core driver. The low
  2104. * level driver must have removed all its ports via the
  2105. * uart_remove_one_port() if it registered them with uart_add_one_port().
  2106. * (ie, drv->port == NULL)
  2107. */
  2108. void uart_unregister_driver(struct uart_driver *drv)
  2109. {
  2110. struct tty_driver *p = drv->tty_driver;
  2111. tty_unregister_driver(p);
  2112. put_tty_driver(p);
  2113. kfree(drv->state);
  2114. drv->tty_driver = NULL;
  2115. }
  2116. struct tty_driver *uart_console_device(struct console *co, int *index)
  2117. {
  2118. struct uart_driver *p = co->data;
  2119. *index = co->index;
  2120. return p->tty_driver;
  2121. }
  2122. /**
  2123. * uart_add_one_port - attach a driver-defined port structure
  2124. * @drv: pointer to the uart low level driver structure for this port
  2125. * @uport: uart port structure to use for this port.
  2126. *
  2127. * This allows the driver to register its own uart_port structure
  2128. * with the core driver. The main purpose is to allow the low
  2129. * level uart drivers to expand uart_port, rather than having yet
  2130. * more levels of structures.
  2131. */
  2132. int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
  2133. {
  2134. struct uart_state *state;
  2135. struct tty_port *port;
  2136. int ret = 0;
  2137. struct device *tty_dev;
  2138. BUG_ON(in_interrupt());
  2139. if (uport->line >= drv->nr)
  2140. return -EINVAL;
  2141. state = drv->state + uport->line;
  2142. port = &state->port;
  2143. mutex_lock(&port_mutex);
  2144. mutex_lock(&port->mutex);
  2145. if (state->uart_port) {
  2146. ret = -EINVAL;
  2147. goto out;
  2148. }
  2149. state->uart_port = uport;
  2150. state->pm_state = -1;
  2151. uport->cons = drv->cons;
  2152. uport->state = state;
  2153. /*
  2154. * If this port is a console, then the spinlock is already
  2155. * initialised.
  2156. */
  2157. if (!(uart_console(uport) && (uport->cons->flags & CON_ENABLED))) {
  2158. spin_lock_init(&uport->lock);
  2159. lockdep_set_class(&uport->lock, &port_lock_key);
  2160. }
  2161. uart_configure_port(drv, state, uport);
  2162. /*
  2163. * Register the port whether it's detected or not. This allows
  2164. * setserial to be used to alter this ports parameters.
  2165. */
  2166. tty_dev = tty_register_device(drv->tty_driver, uport->line, uport->dev);
  2167. if (likely(!IS_ERR(tty_dev))) {
  2168. device_init_wakeup(tty_dev, 1);
  2169. device_set_wakeup_enable(tty_dev, 0);
  2170. } else
  2171. printk(KERN_ERR "Cannot register tty device on line %d\n",
  2172. uport->line);
  2173. /*
  2174. * Ensure UPF_DEAD is not set.
  2175. */
  2176. uport->flags &= ~UPF_DEAD;
  2177. out:
  2178. mutex_unlock(&port->mutex);
  2179. mutex_unlock(&port_mutex);
  2180. return ret;
  2181. }
  2182. /**
  2183. * uart_remove_one_port - detach a driver defined port structure
  2184. * @drv: pointer to the uart low level driver structure for this port
  2185. * @uport: uart port structure for this port
  2186. *
  2187. * This unhooks (and hangs up) the specified port structure from the
  2188. * core driver. No further calls will be made to the low-level code
  2189. * for this port.
  2190. */
  2191. int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)
  2192. {
  2193. struct uart_state *state = drv->state + uport->line;
  2194. struct tty_port *port = &state->port;
  2195. BUG_ON(in_interrupt());
  2196. if (state->uart_port != uport)
  2197. printk(KERN_ALERT "Removing wrong port: %p != %p\n",
  2198. state->uart_port, uport);
  2199. mutex_lock(&port_mutex);
  2200. /*
  2201. * Mark the port "dead" - this prevents any opens from
  2202. * succeeding while we shut down the port.
  2203. */
  2204. mutex_lock(&port->mutex);
  2205. uport->flags |= UPF_DEAD;
  2206. mutex_unlock(&port->mutex);
  2207. /*
  2208. * Remove the devices from the tty layer
  2209. */
  2210. tty_unregister_device(drv->tty_driver, uport->line);
  2211. if (port->tty)
  2212. tty_vhangup(port->tty);
  2213. /*
  2214. * Free the port IO and memory resources, if any.
  2215. */
  2216. if (uport->type != PORT_UNKNOWN)
  2217. uport->ops->release_port(uport);
  2218. /*
  2219. * Indicate that there isn't a port here anymore.
  2220. */
  2221. uport->type = PORT_UNKNOWN;
  2222. /*
  2223. * Kill the tasklet, and free resources.
  2224. */
  2225. tasklet_kill(&state->tlet);
  2226. state->uart_port = NULL;
  2227. mutex_unlock(&port_mutex);
  2228. return 0;
  2229. }
  2230. /*
  2231. * Are the two ports equivalent?
  2232. */
  2233. int uart_match_port(struct uart_port *port1, struct uart_port *port2)
  2234. {
  2235. if (port1->iotype != port2->iotype)
  2236. return 0;
  2237. switch (port1->iotype) {
  2238. case UPIO_PORT:
  2239. return (port1->iobase == port2->iobase);
  2240. case UPIO_HUB6:
  2241. return (port1->iobase == port2->iobase) &&
  2242. (port1->hub6 == port2->hub6);
  2243. case UPIO_MEM:
  2244. case UPIO_MEM32:
  2245. case UPIO_AU:
  2246. case UPIO_TSI:
  2247. case UPIO_DWAPB:
  2248. return (port1->mapbase == port2->mapbase);
  2249. }
  2250. return 0;
  2251. }
  2252. EXPORT_SYMBOL(uart_match_port);
  2253. EXPORT_SYMBOL(uart_write_wakeup);
  2254. EXPORT_SYMBOL(uart_register_driver);
  2255. EXPORT_SYMBOL(uart_unregister_driver);
  2256. EXPORT_SYMBOL(uart_suspend_port);
  2257. EXPORT_SYMBOL(uart_resume_port);
  2258. EXPORT_SYMBOL(uart_add_one_port);
  2259. EXPORT_SYMBOL(uart_remove_one_port);
  2260. MODULE_DESCRIPTION("Serial driver core");
  2261. MODULE_LICENSE("GPL");