serial_core.c 65 KB

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