68360serial.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995
  1. /*
  2. * UART driver for 68360 CPM SCC or SMC
  3. * Copyright (c) 2000 D. Jeff Dionne <jeff@uclinux.org>,
  4. * Copyright (c) 2000 Michael Leslie <mleslie@lineo.ca>
  5. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  6. *
  7. * I used the serial.c driver as the framework for this driver.
  8. * Give credit to those guys.
  9. * The original code was written for the MBX860 board. I tried to make
  10. * it generic, but there may be some assumptions in the structures that
  11. * have to be fixed later.
  12. * To save porting time, I did not bother to change any object names
  13. * that are not accessed outside of this file.
  14. * It still needs lots of work........When it was easy, I included code
  15. * to support the SCCs, but this has never been tested, nor is it complete.
  16. * Only the SCCs support modem control, so that is not complete either.
  17. *
  18. * This module exports the following rs232 io functions:
  19. *
  20. * int rs_360_init(void);
  21. */
  22. #include <linux/module.h>
  23. #include <linux/errno.h>
  24. #include <linux/signal.h>
  25. #include <linux/sched.h>
  26. #include <linux/timer.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/tty.h>
  29. #include <linux/tty_flip.h>
  30. #include <linux/serial.h>
  31. #include <linux/serialP.h>
  32. #include <linux/major.h>
  33. #include <linux/string.h>
  34. #include <linux/fcntl.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/mm.h>
  37. #include <linux/init.h>
  38. #include <linux/delay.h>
  39. #include <asm/irq.h>
  40. #include <asm/m68360.h>
  41. #include <asm/commproc.h>
  42. #ifdef CONFIG_KGDB
  43. extern void breakpoint(void);
  44. extern void set_debug_traps(void);
  45. extern int kgdb_output_string (const char* s, unsigned int count);
  46. #endif
  47. /* #ifdef CONFIG_SERIAL_CONSOLE */ /* This seems to be a post 2.0 thing - mles */
  48. #include <linux/console.h>
  49. /* this defines the index into rs_table for the port to use
  50. */
  51. #ifndef CONFIG_SERIAL_CONSOLE_PORT
  52. #define CONFIG_SERIAL_CONSOLE_PORT 1 /* ie SMC2 - note USE_SMC2 must be defined */
  53. #endif
  54. /* #endif */
  55. #if 0
  56. /* SCC2 for console
  57. */
  58. #undef CONFIG_SERIAL_CONSOLE_PORT
  59. #define CONFIG_SERIAL_CONSOLE_PORT 2
  60. #endif
  61. #define TX_WAKEUP ASYNC_SHARE_IRQ
  62. static char *serial_name = "CPM UART driver";
  63. static char *serial_version = "0.03";
  64. static struct tty_driver *serial_driver;
  65. int serial_console_setup(struct console *co, char *options);
  66. /*
  67. * Serial driver configuration section. Here are the various options:
  68. */
  69. #define SERIAL_PARANOIA_CHECK
  70. #define CONFIG_SERIAL_NOPAUSE_IO
  71. #define SERIAL_DO_RESTART
  72. /* Set of debugging defines */
  73. #undef SERIAL_DEBUG_INTR
  74. #undef SERIAL_DEBUG_OPEN
  75. #undef SERIAL_DEBUG_FLOW
  76. #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  77. #define _INLINE_ inline
  78. #define DBG_CNT(s)
  79. /* We overload some of the items in the data structure to meet our
  80. * needs. For example, the port address is the CPM parameter ram
  81. * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
  82. * 2 SMCs. The "hub6" field is used to indicate the channel number, with
  83. * a flag indicating SCC or SMC, and the number is used as an index into
  84. * the CPM parameter area for this device.
  85. * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
  86. * not currently used. I should probably use it to indicate the port
  87. * type of SMC or SCC.
  88. * The SMCs do not support any modem control signals.
  89. */
  90. #define smc_scc_num hub6
  91. #define NUM_IS_SCC ((int)0x00010000)
  92. #define PORT_NUM(P) ((P) & 0x0000ffff)
  93. #if defined (CONFIG_UCQUICC)
  94. volatile extern void *_periph_base;
  95. /* sipex transceiver
  96. * mode bits for are on pins
  97. *
  98. * SCC2 d16..19
  99. * SCC3 d20..23
  100. * SCC4 d24..27
  101. */
  102. #define SIPEX_MODE(n,m) ((m & 0x0f)<<(16+4*(n-1)))
  103. static uint sipex_mode_bits = 0x00000000;
  104. #endif
  105. /* There is no `serial_state' defined back here in 2.0.
  106. * Try to get by with serial_struct
  107. */
  108. /* #define serial_state serial_struct */
  109. /* 2.4 -> 2.0 portability problem: async_icount in 2.4 has a few
  110. * extras: */
  111. #if 0
  112. struct async_icount_24 {
  113. __u32 cts, dsr, rng, dcd, tx, rx;
  114. __u32 frame, parity, overrun, brk;
  115. __u32 buf_overrun;
  116. } icount;
  117. #endif
  118. #if 0
  119. struct serial_state {
  120. int magic;
  121. int baud_base;
  122. unsigned long port;
  123. int irq;
  124. int flags;
  125. int hub6;
  126. int type;
  127. int line;
  128. int revision; /* Chip revision (950) */
  129. int xmit_fifo_size;
  130. int custom_divisor;
  131. int count;
  132. u8 *iomem_base;
  133. u16 iomem_reg_shift;
  134. unsigned short close_delay;
  135. unsigned short closing_wait; /* time to wait before closing */
  136. struct async_icount_24 icount;
  137. int io_type;
  138. struct async_struct *info;
  139. };
  140. #endif
  141. #define SSTATE_MAGIC 0x5302
  142. /* SMC2 is sometimes used for low performance TDM interfaces. Define
  143. * this as 1 if you want SMC2 as a serial port UART managed by this driver.
  144. * Define this as 0 if you wish to use SMC2 for something else.
  145. */
  146. #define USE_SMC2 1
  147. #if 0
  148. /* Define SCC to ttySx mapping. */
  149. #define SCC_NUM_BASE (USE_SMC2 + 1) /* SCC base tty "number" */
  150. /* Define which SCC is the first one to use for a serial port. These
  151. * are 0-based numbers, i.e. this assumes the first SCC (SCC1) is used
  152. * for Ethernet, and the first available SCC for serial UART is SCC2.
  153. * NOTE: IF YOU CHANGE THIS, you have to change the PROFF_xxx and
  154. * interrupt vectors in the table below to match.
  155. */
  156. #define SCC_IDX_BASE 1 /* table index */
  157. #endif
  158. /* Processors other than the 860 only get SMCs configured by default.
  159. * Either they don't have SCCs or they are allocated somewhere else.
  160. * Of course, there are now 860s without some SCCs, so we will need to
  161. * address that someday.
  162. * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
  163. * stereo codec parts, and we use SMC2 to help support that.
  164. */
  165. static struct serial_state rs_table[] = {
  166. /* type line PORT IRQ FLAGS smc_scc_num (F.K.A. hub6) */
  167. { 0, 0, PRSLOT_SMC1, CPMVEC_SMC1, 0, 0 } /* SMC1 ttyS0 */
  168. #if USE_SMC2
  169. ,{ 0, 0, PRSLOT_SMC2, CPMVEC_SMC2, 0, 1 } /* SMC2 ttyS1 */
  170. #endif
  171. #if defined(CONFIG_SERIAL_68360_SCC)
  172. ,{ 0, 0, PRSLOT_SCC2, CPMVEC_SCC2, 0, (NUM_IS_SCC | 1) } /* SCC2 ttyS2 */
  173. ,{ 0, 0, PRSLOT_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) } /* SCC3 ttyS3 */
  174. ,{ 0, 0, PRSLOT_SCC4, CPMVEC_SCC4, 0, (NUM_IS_SCC | 3) } /* SCC4 ttyS4 */
  175. #endif
  176. };
  177. #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
  178. /* The number of buffer descriptors and their sizes.
  179. */
  180. #define RX_NUM_FIFO 4
  181. #define RX_BUF_SIZE 32
  182. #define TX_NUM_FIFO 4
  183. #define TX_BUF_SIZE 32
  184. #define CONSOLE_NUM_FIFO 2
  185. #define CONSOLE_BUF_SIZE 4
  186. char *console_fifos[CONSOLE_NUM_FIFO * CONSOLE_BUF_SIZE];
  187. /* The async_struct in serial.h does not really give us what we
  188. * need, so define our own here.
  189. */
  190. typedef struct serial_info {
  191. int magic;
  192. int flags;
  193. struct serial_state *state;
  194. /* struct serial_struct *state; */
  195. /* struct async_struct *state; */
  196. struct tty_struct *tty;
  197. int read_status_mask;
  198. int ignore_status_mask;
  199. int timeout;
  200. int line;
  201. int x_char; /* xon/xoff character */
  202. int close_delay;
  203. unsigned short closing_wait;
  204. unsigned short closing_wait2;
  205. unsigned long event;
  206. unsigned long last_active;
  207. int blocked_open; /* # of blocked opens */
  208. struct work_struct tqueue;
  209. struct work_struct tqueue_hangup;
  210. wait_queue_head_t open_wait;
  211. wait_queue_head_t close_wait;
  212. /* CPM Buffer Descriptor pointers.
  213. */
  214. QUICC_BD *rx_bd_base;
  215. QUICC_BD *rx_cur;
  216. QUICC_BD *tx_bd_base;
  217. QUICC_BD *tx_cur;
  218. } ser_info_t;
  219. /* since kmalloc_init() does not get called until much after this initialization: */
  220. static ser_info_t quicc_ser_info[NR_PORTS];
  221. static char rx_buf_pool[NR_PORTS * RX_NUM_FIFO * RX_BUF_SIZE];
  222. static char tx_buf_pool[NR_PORTS * TX_NUM_FIFO * TX_BUF_SIZE];
  223. static void change_speed(ser_info_t *info);
  224. static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout);
  225. static inline int serial_paranoia_check(ser_info_t *info,
  226. char *name, const char *routine)
  227. {
  228. #ifdef SERIAL_PARANOIA_CHECK
  229. static const char *badmagic =
  230. "Warning: bad magic number for serial struct (%s) in %s\n";
  231. static const char *badinfo =
  232. "Warning: null async_struct for (%s) in %s\n";
  233. if (!info) {
  234. printk(badinfo, name, routine);
  235. return 1;
  236. }
  237. if (info->magic != SERIAL_MAGIC) {
  238. printk(badmagic, name, routine);
  239. return 1;
  240. }
  241. #endif
  242. return 0;
  243. }
  244. /*
  245. * This is used to figure out the divisor speeds and the timeouts,
  246. * indexed by the termio value. The generic CPM functions are responsible
  247. * for setting and assigning baud rate generators for us.
  248. */
  249. static int baud_table[] = {
  250. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  251. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
  252. /* This sucks. There is a better way: */
  253. #if defined(CONFIG_CONSOLE_9600)
  254. #define CONSOLE_BAUDRATE 9600
  255. #elif defined(CONFIG_CONSOLE_19200)
  256. #define CONSOLE_BAUDRATE 19200
  257. #elif defined(CONFIG_CONSOLE_115200)
  258. #define CONSOLE_BAUDRATE 115200
  259. #else
  260. #warning "console baud rate undefined"
  261. #define CONSOLE_BAUDRATE 9600
  262. #endif
  263. /*
  264. * ------------------------------------------------------------
  265. * rs_stop() and rs_start()
  266. *
  267. * This routines are called before setting or resetting tty->stopped.
  268. * They enable or disable transmitter interrupts, as necessary.
  269. * ------------------------------------------------------------
  270. */
  271. static void rs_360_stop(struct tty_struct *tty)
  272. {
  273. ser_info_t *info = (ser_info_t *)tty->driver_data;
  274. int idx;
  275. unsigned long flags;
  276. volatile struct scc_regs *sccp;
  277. volatile struct smc_regs *smcp;
  278. if (serial_paranoia_check(info, tty->name, "rs_stop"))
  279. return;
  280. local_irq_save(flags);
  281. idx = PORT_NUM(info->state->smc_scc_num);
  282. if (info->state->smc_scc_num & NUM_IS_SCC) {
  283. sccp = &pquicc->scc_regs[idx];
  284. sccp->scc_sccm &= ~UART_SCCM_TX;
  285. } else {
  286. /* smcp = &cpmp->cp_smc[idx]; */
  287. smcp = &pquicc->smc_regs[idx];
  288. smcp->smc_smcm &= ~SMCM_TX;
  289. }
  290. local_irq_restore(flags);
  291. }
  292. static void rs_360_start(struct tty_struct *tty)
  293. {
  294. ser_info_t *info = (ser_info_t *)tty->driver_data;
  295. int idx;
  296. unsigned long flags;
  297. volatile struct scc_regs *sccp;
  298. volatile struct smc_regs *smcp;
  299. if (serial_paranoia_check(info, tty->name, "rs_stop"))
  300. return;
  301. local_irq_save(flags);
  302. idx = PORT_NUM(info->state->smc_scc_num);
  303. if (info->state->smc_scc_num & NUM_IS_SCC) {
  304. sccp = &pquicc->scc_regs[idx];
  305. sccp->scc_sccm |= UART_SCCM_TX;
  306. } else {
  307. smcp = &pquicc->smc_regs[idx];
  308. smcp->smc_smcm |= SMCM_TX;
  309. }
  310. local_irq_restore(flags);
  311. }
  312. /*
  313. * ----------------------------------------------------------------------
  314. *
  315. * Here starts the interrupt handling routines. All of the following
  316. * subroutines are declared as inline and are folded into
  317. * rs_interrupt(). They were separated out for readability's sake.
  318. *
  319. * Note: rs_interrupt() is a "fast" interrupt, which means that it
  320. * runs with interrupts turned off. People who may want to modify
  321. * rs_interrupt() should try to keep the interrupt handler as fast as
  322. * possible. After you are done making modifications, it is not a bad
  323. * idea to do:
  324. *
  325. * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
  326. *
  327. * and look at the resulting assemble code in serial.s.
  328. *
  329. * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
  330. * -----------------------------------------------------------------------
  331. */
  332. static _INLINE_ void receive_chars(ser_info_t *info)
  333. {
  334. struct tty_struct *tty = info->tty;
  335. unsigned char ch, flag, *cp;
  336. /*int ignored = 0;*/
  337. int i;
  338. ushort status;
  339. struct async_icount *icount;
  340. /* struct async_icount_24 *icount; */
  341. volatile QUICC_BD *bdp;
  342. icount = &info->state->icount;
  343. /* Just loop through the closed BDs and copy the characters into
  344. * the buffer.
  345. */
  346. bdp = info->rx_cur;
  347. for (;;) {
  348. if (bdp->status & BD_SC_EMPTY) /* If this one is empty */
  349. break; /* we are all done */
  350. /* The read status mask tell us what we should do with
  351. * incoming characters, especially if errors occur.
  352. * One special case is the use of BD_SC_EMPTY. If
  353. * this is not set, we are supposed to be ignoring
  354. * inputs. In this case, just mark the buffer empty and
  355. * continue.
  356. */
  357. if (!(info->read_status_mask & BD_SC_EMPTY)) {
  358. bdp->status |= BD_SC_EMPTY;
  359. bdp->status &=
  360. ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
  361. if (bdp->status & BD_SC_WRAP)
  362. bdp = info->rx_bd_base;
  363. else
  364. bdp++;
  365. continue;
  366. }
  367. /* Get the number of characters and the buffer pointer.
  368. */
  369. i = bdp->length;
  370. /* cp = (unsigned char *)__va(bdp->buf); */
  371. cp = (char *)bdp->buf;
  372. status = bdp->status;
  373. while (i-- > 0) {
  374. ch = *cp++;
  375. icount->rx++;
  376. #ifdef SERIAL_DEBUG_INTR
  377. printk("DR%02x:%02x...", ch, status);
  378. #endif
  379. flag = TTY_NORMAL;
  380. if (status & (BD_SC_BR | BD_SC_FR |
  381. BD_SC_PR | BD_SC_OV)) {
  382. /*
  383. * For statistics only
  384. */
  385. if (status & BD_SC_BR)
  386. icount->brk++;
  387. else if (status & BD_SC_PR)
  388. icount->parity++;
  389. else if (status & BD_SC_FR)
  390. icount->frame++;
  391. if (status & BD_SC_OV)
  392. icount->overrun++;
  393. /*
  394. * Now check to see if character should be
  395. * ignored, and mask off conditions which
  396. * should be ignored.
  397. if (status & info->ignore_status_mask) {
  398. if (++ignored > 100)
  399. break;
  400. continue;
  401. }
  402. */
  403. status &= info->read_status_mask;
  404. if (status & (BD_SC_BR)) {
  405. #ifdef SERIAL_DEBUG_INTR
  406. printk("handling break....");
  407. #endif
  408. *tty->flip.flag_buf_ptr = TTY_BREAK;
  409. if (info->flags & ASYNC_SAK)
  410. do_SAK(tty);
  411. } else if (status & BD_SC_PR)
  412. flag = TTY_PARITY;
  413. else if (status & BD_SC_FR)
  414. flag = TTY_FRAME;
  415. }
  416. tty_insert_flip_char(tty, ch, flag);
  417. if (status & BD_SC_OV)
  418. /*
  419. * Overrun is special, since it's
  420. * reported immediately, and doesn't
  421. * affect the current character
  422. */
  423. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  424. }
  425. /* This BD is ready to be used again. Clear status.
  426. * Get next BD.
  427. */
  428. bdp->status |= BD_SC_EMPTY;
  429. bdp->status &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
  430. if (bdp->status & BD_SC_WRAP)
  431. bdp = info->rx_bd_base;
  432. else
  433. bdp++;
  434. }
  435. info->rx_cur = (QUICC_BD *)bdp;
  436. tty_schedule_flip(tty);
  437. }
  438. static _INLINE_ void receive_break(ser_info_t *info)
  439. {
  440. struct tty_struct *tty = info->tty;
  441. info->state->icount.brk++;
  442. /* Check to see if there is room in the tty buffer for
  443. * the break. If not, we exit now, losing the break. FIXME
  444. */
  445. tty_insert_flip_char(tty, 0, TTY_BREAK);
  446. tty_schedule_flip(tty);
  447. }
  448. static _INLINE_ void transmit_chars(ser_info_t *info)
  449. {
  450. if ((info->flags & TX_WAKEUP) ||
  451. (info->tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
  452. schedule_work(&info->tqueue);
  453. }
  454. #ifdef SERIAL_DEBUG_INTR
  455. printk("THRE...");
  456. #endif
  457. }
  458. #ifdef notdef
  459. /* I need to do this for the SCCs, so it is left as a reminder.
  460. */
  461. static _INLINE_ void check_modem_status(struct async_struct *info)
  462. {
  463. int status;
  464. /* struct async_icount *icount; */
  465. struct async_icount_24 *icount;
  466. status = serial_in(info, UART_MSR);
  467. if (status & UART_MSR_ANY_DELTA) {
  468. icount = &info->state->icount;
  469. /* update input line counters */
  470. if (status & UART_MSR_TERI)
  471. icount->rng++;
  472. if (status & UART_MSR_DDSR)
  473. icount->dsr++;
  474. if (status & UART_MSR_DDCD) {
  475. icount->dcd++;
  476. #ifdef CONFIG_HARD_PPS
  477. if ((info->flags & ASYNC_HARDPPS_CD) &&
  478. (status & UART_MSR_DCD))
  479. hardpps();
  480. #endif
  481. }
  482. if (status & UART_MSR_DCTS)
  483. icount->cts++;
  484. wake_up_interruptible(&info->delta_msr_wait);
  485. }
  486. if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
  487. #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
  488. printk("ttys%d CD now %s...", info->line,
  489. (status & UART_MSR_DCD) ? "on" : "off");
  490. #endif
  491. if (status & UART_MSR_DCD)
  492. wake_up_interruptible(&info->open_wait);
  493. else {
  494. #ifdef SERIAL_DEBUG_OPEN
  495. printk("scheduling hangup...");
  496. #endif
  497. queue_task(&info->tqueue_hangup,
  498. &tq_scheduler);
  499. }
  500. }
  501. if (info->flags & ASYNC_CTS_FLOW) {
  502. if (info->tty->hw_stopped) {
  503. if (status & UART_MSR_CTS) {
  504. #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
  505. printk("CTS tx start...");
  506. #endif
  507. info->tty->hw_stopped = 0;
  508. info->IER |= UART_IER_THRI;
  509. serial_out(info, UART_IER, info->IER);
  510. rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
  511. return;
  512. }
  513. } else {
  514. if (!(status & UART_MSR_CTS)) {
  515. #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
  516. printk("CTS tx stop...");
  517. #endif
  518. info->tty->hw_stopped = 1;
  519. info->IER &= ~UART_IER_THRI;
  520. serial_out(info, UART_IER, info->IER);
  521. }
  522. }
  523. }
  524. }
  525. #endif
  526. /*
  527. * This is the serial driver's interrupt routine for a single port
  528. */
  529. /* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */
  530. static void rs_360_interrupt(int vec, void *dev_id)
  531. {
  532. u_char events;
  533. int idx;
  534. ser_info_t *info;
  535. volatile struct smc_regs *smcp;
  536. volatile struct scc_regs *sccp;
  537. info = dev_id;
  538. idx = PORT_NUM(info->state->smc_scc_num);
  539. if (info->state->smc_scc_num & NUM_IS_SCC) {
  540. sccp = &pquicc->scc_regs[idx];
  541. events = sccp->scc_scce;
  542. if (events & SCCM_RX)
  543. receive_chars(info);
  544. if (events & SCCM_TX)
  545. transmit_chars(info);
  546. sccp->scc_scce = events;
  547. } else {
  548. smcp = &pquicc->smc_regs[idx];
  549. events = smcp->smc_smce;
  550. if (events & SMCM_BRKE)
  551. receive_break(info);
  552. if (events & SMCM_RX)
  553. receive_chars(info);
  554. if (events & SMCM_TX)
  555. transmit_chars(info);
  556. smcp->smc_smce = events;
  557. }
  558. #ifdef SERIAL_DEBUG_INTR
  559. printk("rs_interrupt_single(%d, %x)...",
  560. info->state->smc_scc_num, events);
  561. #endif
  562. #ifdef modem_control
  563. check_modem_status(info);
  564. #endif
  565. info->last_active = jiffies;
  566. #ifdef SERIAL_DEBUG_INTR
  567. printk("end.\n");
  568. #endif
  569. }
  570. /*
  571. * -------------------------------------------------------------------
  572. * Here ends the serial interrupt routines.
  573. * -------------------------------------------------------------------
  574. */
  575. static void do_softint(void *private_)
  576. {
  577. ser_info_t *info = (ser_info_t *) private_;
  578. struct tty_struct *tty;
  579. tty = info->tty;
  580. if (!tty)
  581. return;
  582. if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
  583. tty_wakeup(tty);
  584. }
  585. /*
  586. * This routine is called from the scheduler tqueue when the interrupt
  587. * routine has signalled that a hangup has occurred. The path of
  588. * hangup processing is:
  589. *
  590. * serial interrupt routine -> (scheduler tqueue) ->
  591. * do_serial_hangup() -> tty->hangup() -> rs_hangup()
  592. *
  593. */
  594. static void do_serial_hangup(void *private_)
  595. {
  596. struct async_struct *info = (struct async_struct *) private_;
  597. struct tty_struct *tty;
  598. tty = info->tty;
  599. if (!tty)
  600. return;
  601. tty_hangup(tty);
  602. }
  603. static int startup(ser_info_t *info)
  604. {
  605. unsigned long flags;
  606. int retval=0;
  607. int idx;
  608. /*struct serial_state *state = info->state;*/
  609. volatile struct smc_regs *smcp;
  610. volatile struct scc_regs *sccp;
  611. volatile struct smc_uart_pram *up;
  612. volatile struct uart_pram *scup;
  613. local_irq_save(flags);
  614. if (info->flags & ASYNC_INITIALIZED) {
  615. goto errout;
  616. }
  617. #ifdef maybe
  618. if (!state->port || !state->type) {
  619. if (info->tty)
  620. set_bit(TTY_IO_ERROR, &info->tty->flags);
  621. goto errout;
  622. }
  623. #endif
  624. #ifdef SERIAL_DEBUG_OPEN
  625. printk("starting up ttys%d (irq %d)...", info->line, state->irq);
  626. #endif
  627. #ifdef modem_control
  628. info->MCR = 0;
  629. if (info->tty->termios->c_cflag & CBAUD)
  630. info->MCR = UART_MCR_DTR | UART_MCR_RTS;
  631. #endif
  632. if (info->tty)
  633. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  634. /*
  635. * and set the speed of the serial port
  636. */
  637. change_speed(info);
  638. idx = PORT_NUM(info->state->smc_scc_num);
  639. if (info->state->smc_scc_num & NUM_IS_SCC) {
  640. sccp = &pquicc->scc_regs[idx];
  641. scup = &pquicc->pram[info->state->port].scc.pscc.u;
  642. scup->mrblr = RX_BUF_SIZE;
  643. scup->max_idl = RX_BUF_SIZE;
  644. sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
  645. sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  646. } else {
  647. smcp = &pquicc->smc_regs[idx];
  648. /* Enable interrupts and I/O.
  649. */
  650. smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  651. smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
  652. /* We can tune the buffer length and idle characters
  653. * to take advantage of the entire incoming buffer size.
  654. * If mrblr is something other than 1, maxidl has to be
  655. * non-zero or we never get an interrupt. The maxidl
  656. * is the number of character times we wait after reception
  657. * of the last character before we decide no more characters
  658. * are coming.
  659. */
  660. /* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */
  661. /* holy unionized structures, Batman: */
  662. up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
  663. up->mrblr = RX_BUF_SIZE;
  664. up->max_idl = RX_BUF_SIZE;
  665. up->brkcr = 1; /* number of break chars */
  666. }
  667. info->flags |= ASYNC_INITIALIZED;
  668. local_irq_restore(flags);
  669. return 0;
  670. errout:
  671. local_irq_restore(flags);
  672. return retval;
  673. }
  674. /*
  675. * This routine will shutdown a serial port; interrupts are disabled, and
  676. * DTR is dropped if the hangup on close termio flag is on.
  677. */
  678. static void shutdown(ser_info_t *info)
  679. {
  680. unsigned long flags;
  681. struct serial_state *state;
  682. int idx;
  683. volatile struct smc_regs *smcp;
  684. volatile struct scc_regs *sccp;
  685. if (!(info->flags & ASYNC_INITIALIZED))
  686. return;
  687. state = info->state;
  688. #ifdef SERIAL_DEBUG_OPEN
  689. printk("Shutting down serial port %d (irq %d)....", info->line,
  690. state->irq);
  691. #endif
  692. local_irq_save(flags);
  693. idx = PORT_NUM(state->smc_scc_num);
  694. if (state->smc_scc_num & NUM_IS_SCC) {
  695. sccp = &pquicc->scc_regs[idx];
  696. sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  697. #ifdef CONFIG_SERIAL_CONSOLE
  698. /* We can't disable the transmitter if this is the
  699. * system console.
  700. */
  701. if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
  702. #endif
  703. sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
  704. } else {
  705. smcp = &pquicc->smc_regs[idx];
  706. /* Disable interrupts and I/O.
  707. */
  708. smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
  709. #ifdef CONFIG_SERIAL_CONSOLE
  710. /* We can't disable the transmitter if this is the
  711. * system console.
  712. */
  713. if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
  714. #endif
  715. smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  716. }
  717. if (info->tty)
  718. set_bit(TTY_IO_ERROR, &info->tty->flags);
  719. info->flags &= ~ASYNC_INITIALIZED;
  720. local_irq_restore(flags);
  721. }
  722. /*
  723. * This routine is called to set the UART divisor registers to match
  724. * the specified baud rate for a serial port.
  725. */
  726. static void change_speed(ser_info_t *info)
  727. {
  728. int baud_rate;
  729. unsigned cflag, cval, scval, prev_mode;
  730. int i, bits, sbits, idx;
  731. unsigned long flags;
  732. struct serial_state *state;
  733. volatile struct smc_regs *smcp;
  734. volatile struct scc_regs *sccp;
  735. if (!info->tty || !info->tty->termios)
  736. return;
  737. cflag = info->tty->termios->c_cflag;
  738. state = info->state;
  739. /* Character length programmed into the mode register is the
  740. * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
  741. * 1 or 2 stop bits, minus 1.
  742. * The value 'bits' counts this for us.
  743. */
  744. cval = 0;
  745. scval = 0;
  746. /* byte size and parity */
  747. switch (cflag & CSIZE) {
  748. case CS5: bits = 5; break;
  749. case CS6: bits = 6; break;
  750. case CS7: bits = 7; break;
  751. case CS8: bits = 8; break;
  752. /* Never happens, but GCC is too dumb to figure it out */
  753. default: bits = 8; break;
  754. }
  755. sbits = bits - 5;
  756. if (cflag & CSTOPB) {
  757. cval |= SMCMR_SL; /* Two stops */
  758. scval |= SCU_PMSR_SL;
  759. bits++;
  760. }
  761. if (cflag & PARENB) {
  762. cval |= SMCMR_PEN;
  763. scval |= SCU_PMSR_PEN;
  764. bits++;
  765. }
  766. if (!(cflag & PARODD)) {
  767. cval |= SMCMR_PM_EVEN;
  768. scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
  769. }
  770. /* Determine divisor based on baud rate */
  771. i = cflag & CBAUD;
  772. if (i >= (sizeof(baud_table)/sizeof(int)))
  773. baud_rate = 9600;
  774. else
  775. baud_rate = baud_table[i];
  776. info->timeout = (TX_BUF_SIZE*HZ*bits);
  777. info->timeout += HZ/50; /* Add .02 seconds of slop */
  778. #ifdef modem_control
  779. /* CTS flow control flag and modem status interrupts */
  780. info->IER &= ~UART_IER_MSI;
  781. if (info->flags & ASYNC_HARDPPS_CD)
  782. info->IER |= UART_IER_MSI;
  783. if (cflag & CRTSCTS) {
  784. info->flags |= ASYNC_CTS_FLOW;
  785. info->IER |= UART_IER_MSI;
  786. } else
  787. info->flags &= ~ASYNC_CTS_FLOW;
  788. if (cflag & CLOCAL)
  789. info->flags &= ~ASYNC_CHECK_CD;
  790. else {
  791. info->flags |= ASYNC_CHECK_CD;
  792. info->IER |= UART_IER_MSI;
  793. }
  794. serial_out(info, UART_IER, info->IER);
  795. #endif
  796. /*
  797. * Set up parity check flag
  798. */
  799. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  800. info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
  801. if (I_INPCK(info->tty))
  802. info->read_status_mask |= BD_SC_FR | BD_SC_PR;
  803. if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  804. info->read_status_mask |= BD_SC_BR;
  805. /*
  806. * Characters to ignore
  807. */
  808. info->ignore_status_mask = 0;
  809. if (I_IGNPAR(info->tty))
  810. info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
  811. if (I_IGNBRK(info->tty)) {
  812. info->ignore_status_mask |= BD_SC_BR;
  813. /*
  814. * If we're ignore parity and break indicators, ignore
  815. * overruns too. (For real raw support).
  816. */
  817. if (I_IGNPAR(info->tty))
  818. info->ignore_status_mask |= BD_SC_OV;
  819. }
  820. /*
  821. * !!! ignore all characters if CREAD is not set
  822. */
  823. if ((cflag & CREAD) == 0)
  824. info->read_status_mask &= ~BD_SC_EMPTY;
  825. local_irq_save(flags);
  826. /* Start bit has not been added (so don't, because we would just
  827. * subtract it later), and we need to add one for the number of
  828. * stops bits (there is always at least one).
  829. */
  830. bits++;
  831. idx = PORT_NUM(state->smc_scc_num);
  832. if (state->smc_scc_num & NUM_IS_SCC) {
  833. sccp = &pquicc->scc_regs[idx];
  834. sccp->scc_psmr = (sbits << 12) | scval;
  835. } else {
  836. smcp = &pquicc->smc_regs[idx];
  837. /* Set the mode register. We want to keep a copy of the
  838. * enables, because we want to put them back if they were
  839. * present.
  840. */
  841. prev_mode = smcp->smc_smcmr;
  842. smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
  843. smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
  844. }
  845. m360_cpm_setbrg((state - rs_table), baud_rate);
  846. local_irq_restore(flags);
  847. }
  848. static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
  849. {
  850. ser_info_t *info = (ser_info_t *)tty->driver_data;
  851. volatile QUICC_BD *bdp;
  852. if (serial_paranoia_check(info, tty->name, "rs_put_char"))
  853. return;
  854. if (!tty)
  855. return;
  856. bdp = info->tx_cur;
  857. while (bdp->status & BD_SC_READY);
  858. /* *((char *)__va(bdp->buf)) = ch; */
  859. *((char *)bdp->buf) = ch;
  860. bdp->length = 1;
  861. bdp->status |= BD_SC_READY;
  862. /* Get next BD.
  863. */
  864. if (bdp->status & BD_SC_WRAP)
  865. bdp = info->tx_bd_base;
  866. else
  867. bdp++;
  868. info->tx_cur = (QUICC_BD *)bdp;
  869. }
  870. static int rs_360_write(struct tty_struct * tty,
  871. const unsigned char *buf, int count)
  872. {
  873. int c, ret = 0;
  874. ser_info_t *info = (ser_info_t *)tty->driver_data;
  875. volatile QUICC_BD *bdp;
  876. #ifdef CONFIG_KGDB
  877. /* Try to let stub handle output. Returns true if it did. */
  878. if (kgdb_output_string(buf, count))
  879. return ret;
  880. #endif
  881. if (serial_paranoia_check(info, tty->name, "rs_write"))
  882. return 0;
  883. if (!tty)
  884. return 0;
  885. bdp = info->tx_cur;
  886. while (1) {
  887. c = min(count, TX_BUF_SIZE);
  888. if (c <= 0)
  889. break;
  890. if (bdp->status & BD_SC_READY) {
  891. info->flags |= TX_WAKEUP;
  892. break;
  893. }
  894. /* memcpy(__va(bdp->buf), buf, c); */
  895. memcpy((void *)bdp->buf, buf, c);
  896. bdp->length = c;
  897. bdp->status |= BD_SC_READY;
  898. buf += c;
  899. count -= c;
  900. ret += c;
  901. /* Get next BD.
  902. */
  903. if (bdp->status & BD_SC_WRAP)
  904. bdp = info->tx_bd_base;
  905. else
  906. bdp++;
  907. info->tx_cur = (QUICC_BD *)bdp;
  908. }
  909. return ret;
  910. }
  911. static int rs_360_write_room(struct tty_struct *tty)
  912. {
  913. ser_info_t *info = (ser_info_t *)tty->driver_data;
  914. int ret;
  915. if (serial_paranoia_check(info, tty->name, "rs_write_room"))
  916. return 0;
  917. if ((info->tx_cur->status & BD_SC_READY) == 0) {
  918. info->flags &= ~TX_WAKEUP;
  919. ret = TX_BUF_SIZE;
  920. }
  921. else {
  922. info->flags |= TX_WAKEUP;
  923. ret = 0;
  924. }
  925. return ret;
  926. }
  927. /* I could track this with transmit counters....maybe later.
  928. */
  929. static int rs_360_chars_in_buffer(struct tty_struct *tty)
  930. {
  931. ser_info_t *info = (ser_info_t *)tty->driver_data;
  932. if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
  933. return 0;
  934. return 0;
  935. }
  936. static void rs_360_flush_buffer(struct tty_struct *tty)
  937. {
  938. ser_info_t *info = (ser_info_t *)tty->driver_data;
  939. if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
  940. return;
  941. /* There is nothing to "flush", whatever we gave the CPM
  942. * is on its way out.
  943. */
  944. tty_wakeup(tty);
  945. info->flags &= ~TX_WAKEUP;
  946. }
  947. /*
  948. * This function is used to send a high-priority XON/XOFF character to
  949. * the device
  950. */
  951. static void rs_360_send_xchar(struct tty_struct *tty, char ch)
  952. {
  953. volatile QUICC_BD *bdp;
  954. ser_info_t *info = (ser_info_t *)tty->driver_data;
  955. if (serial_paranoia_check(info, tty->name, "rs_send_char"))
  956. return;
  957. bdp = info->tx_cur;
  958. while (bdp->status & BD_SC_READY);
  959. /* *((char *)__va(bdp->buf)) = ch; */
  960. *((char *)bdp->buf) = ch;
  961. bdp->length = 1;
  962. bdp->status |= BD_SC_READY;
  963. /* Get next BD.
  964. */
  965. if (bdp->status & BD_SC_WRAP)
  966. bdp = info->tx_bd_base;
  967. else
  968. bdp++;
  969. info->tx_cur = (QUICC_BD *)bdp;
  970. }
  971. /*
  972. * ------------------------------------------------------------
  973. * rs_throttle()
  974. *
  975. * This routine is called by the upper-layer tty layer to signal that
  976. * incoming characters should be throttled.
  977. * ------------------------------------------------------------
  978. */
  979. static void rs_360_throttle(struct tty_struct * tty)
  980. {
  981. ser_info_t *info = (ser_info_t *)tty->driver_data;
  982. #ifdef SERIAL_DEBUG_THROTTLE
  983. char buf[64];
  984. printk("throttle %s: %d....\n", _tty_name(tty, buf),
  985. tty->ldisc.chars_in_buffer(tty));
  986. #endif
  987. if (serial_paranoia_check(info, tty->name, "rs_throttle"))
  988. return;
  989. if (I_IXOFF(tty))
  990. rs_360_send_xchar(tty, STOP_CHAR(tty));
  991. #ifdef modem_control
  992. if (tty->termios->c_cflag & CRTSCTS)
  993. info->MCR &= ~UART_MCR_RTS;
  994. local_irq_disable();
  995. serial_out(info, UART_MCR, info->MCR);
  996. local_irq_enable();
  997. #endif
  998. }
  999. static void rs_360_unthrottle(struct tty_struct * tty)
  1000. {
  1001. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1002. #ifdef SERIAL_DEBUG_THROTTLE
  1003. char buf[64];
  1004. printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
  1005. tty->ldisc.chars_in_buffer(tty));
  1006. #endif
  1007. if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
  1008. return;
  1009. if (I_IXOFF(tty)) {
  1010. if (info->x_char)
  1011. info->x_char = 0;
  1012. else
  1013. rs_360_send_xchar(tty, START_CHAR(tty));
  1014. }
  1015. #ifdef modem_control
  1016. if (tty->termios->c_cflag & CRTSCTS)
  1017. info->MCR |= UART_MCR_RTS;
  1018. local_irq_disable();
  1019. serial_out(info, UART_MCR, info->MCR);
  1020. local_irq_enable();
  1021. #endif
  1022. }
  1023. /*
  1024. * ------------------------------------------------------------
  1025. * rs_ioctl() and friends
  1026. * ------------------------------------------------------------
  1027. */
  1028. #ifdef maybe
  1029. /*
  1030. * get_lsr_info - get line status register info
  1031. *
  1032. * Purpose: Let user call ioctl() to get info when the UART physically
  1033. * is emptied. On bus types like RS485, the transmitter must
  1034. * release the bus after transmitting. This must be done when
  1035. * the transmit shift register is empty, not be done when the
  1036. * transmit holding register is empty. This functionality
  1037. * allows an RS485 driver to be written in user space.
  1038. */
  1039. static int get_lsr_info(struct async_struct * info, unsigned int *value)
  1040. {
  1041. unsigned char status;
  1042. unsigned int result;
  1043. local_irq_disable();
  1044. status = serial_in(info, UART_LSR);
  1045. local_irq_enable();
  1046. result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
  1047. return put_user(result,value);
  1048. }
  1049. #endif
  1050. static int rs_360_tiocmget(struct tty_struct *tty, struct file *file)
  1051. {
  1052. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1053. unsigned int result = 0;
  1054. #ifdef modem_control
  1055. unsigned char control, status;
  1056. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  1057. return -ENODEV;
  1058. if (tty->flags & (1 << TTY_IO_ERROR))
  1059. return -EIO;
  1060. control = info->MCR;
  1061. local_irq_disable();
  1062. status = serial_in(info, UART_MSR);
  1063. local_irq_enable();
  1064. result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
  1065. | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
  1066. #ifdef TIOCM_OUT1
  1067. | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
  1068. | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
  1069. #endif
  1070. | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
  1071. | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
  1072. | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
  1073. | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
  1074. #endif
  1075. return result;
  1076. }
  1077. static int rs_360_tiocmset(struct tty_struct *tty, struct file *file,
  1078. unsigned int set, unsigned int clear)
  1079. {
  1080. #ifdef modem_control
  1081. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1082. unsigned int arg;
  1083. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  1084. return -ENODEV;
  1085. if (tty->flags & (1 << TTY_IO_ERROR))
  1086. return -EIO;
  1087. if (set & TIOCM_RTS)
  1088. info->mcr |= UART_MCR_RTS;
  1089. if (set & TIOCM_DTR)
  1090. info->mcr |= UART_MCR_DTR;
  1091. if (clear & TIOCM_RTS)
  1092. info->MCR &= ~UART_MCR_RTS;
  1093. if (clear & TIOCM_DTR)
  1094. info->MCR &= ~UART_MCR_DTR;
  1095. #ifdef TIOCM_OUT1
  1096. if (set & TIOCM_OUT1)
  1097. info->MCR |= UART_MCR_OUT1;
  1098. if (set & TIOCM_OUT2)
  1099. info->MCR |= UART_MCR_OUT2;
  1100. if (clear & TIOCM_OUT1)
  1101. info->MCR &= ~UART_MCR_OUT1;
  1102. if (clear & TIOCM_OUT2)
  1103. info->MCR &= ~UART_MCR_OUT2;
  1104. #endif
  1105. local_irq_disable();
  1106. serial_out(info, UART_MCR, info->MCR);
  1107. local_irq_enable();
  1108. #endif
  1109. return 0;
  1110. }
  1111. /* Sending a break is a two step process on the SMC/SCC. It is accomplished
  1112. * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
  1113. * command. We take advantage of the begin/end functions to make this
  1114. * happen.
  1115. */
  1116. static ushort smc_chan_map[] = {
  1117. CPM_CR_CH_SMC1,
  1118. CPM_CR_CH_SMC2
  1119. };
  1120. static ushort scc_chan_map[] = {
  1121. CPM_CR_CH_SCC1,
  1122. CPM_CR_CH_SCC2,
  1123. CPM_CR_CH_SCC3,
  1124. CPM_CR_CH_SCC4
  1125. };
  1126. static void begin_break(ser_info_t *info)
  1127. {
  1128. volatile QUICC *cp;
  1129. ushort chan;
  1130. int idx;
  1131. cp = pquicc;
  1132. idx = PORT_NUM(info->state->smc_scc_num);
  1133. if (info->state->smc_scc_num & NUM_IS_SCC)
  1134. chan = scc_chan_map[idx];
  1135. else
  1136. chan = smc_chan_map[idx];
  1137. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG;
  1138. while (cp->cp_cr & CPM_CR_FLG);
  1139. }
  1140. static void end_break(ser_info_t *info)
  1141. {
  1142. volatile QUICC *cp;
  1143. ushort chan;
  1144. int idx;
  1145. cp = pquicc;
  1146. idx = PORT_NUM(info->state->smc_scc_num);
  1147. if (info->state->smc_scc_num & NUM_IS_SCC)
  1148. chan = scc_chan_map[idx];
  1149. else
  1150. chan = smc_chan_map[idx];
  1151. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_RESTART_TX) | CPM_CR_FLG;
  1152. while (cp->cp_cr & CPM_CR_FLG);
  1153. }
  1154. /*
  1155. * This routine sends a break character out the serial port.
  1156. */
  1157. static void send_break(ser_info_t *info, unsigned int duration)
  1158. {
  1159. #ifdef SERIAL_DEBUG_SEND_BREAK
  1160. printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
  1161. #endif
  1162. begin_break(info);
  1163. msleep_interruptible(duration);
  1164. end_break(info);
  1165. #ifdef SERIAL_DEBUG_SEND_BREAK
  1166. printk("done jiffies=%lu\n", jiffies);
  1167. #endif
  1168. }
  1169. static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
  1170. unsigned int cmd, unsigned long arg)
  1171. {
  1172. int error;
  1173. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1174. int retval;
  1175. struct async_icount cnow;
  1176. /* struct async_icount_24 cnow;*/ /* kernel counter temps */
  1177. struct serial_icounter_struct *p_cuser; /* user space */
  1178. if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
  1179. return -ENODEV;
  1180. if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
  1181. if (tty->flags & (1 << TTY_IO_ERROR))
  1182. return -EIO;
  1183. }
  1184. switch (cmd) {
  1185. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1186. retval = tty_check_change(tty);
  1187. if (retval)
  1188. return retval;
  1189. tty_wait_until_sent(tty, 0);
  1190. if (signal_pending(current))
  1191. return -EINTR;
  1192. if (!arg) {
  1193. send_break(info, 250); /* 1/4 second */
  1194. if (signal_pending(current))
  1195. return -EINTR;
  1196. }
  1197. return 0;
  1198. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1199. retval = tty_check_change(tty);
  1200. if (retval)
  1201. return retval;
  1202. tty_wait_until_sent(tty, 0);
  1203. if (signal_pending(current))
  1204. return -EINTR;
  1205. send_break(info, arg ? arg*100 : 250);
  1206. if (signal_pending(current))
  1207. return -EINTR;
  1208. return 0;
  1209. case TIOCSBRK:
  1210. retval = tty_check_change(tty);
  1211. if (retval)
  1212. return retval;
  1213. tty_wait_until_sent(tty, 0);
  1214. begin_break(info);
  1215. return 0;
  1216. case TIOCCBRK:
  1217. retval = tty_check_change(tty);
  1218. if (retval)
  1219. return retval;
  1220. end_break(info);
  1221. return 0;
  1222. case TIOCGSOFTCAR:
  1223. /* return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg); */
  1224. put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
  1225. return 0;
  1226. case TIOCSSOFTCAR:
  1227. error = get_user(arg, (unsigned int *) arg);
  1228. if (error)
  1229. return error;
  1230. tty->termios->c_cflag =
  1231. ((tty->termios->c_cflag & ~CLOCAL) |
  1232. (arg ? CLOCAL : 0));
  1233. return 0;
  1234. #ifdef maybe
  1235. case TIOCSERGETLSR: /* Get line status register */
  1236. return get_lsr_info(info, (unsigned int *) arg);
  1237. #endif
  1238. /*
  1239. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  1240. * - mask passed in arg for lines of interest
  1241. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  1242. * Caller should use TIOCGICOUNT to see which one it was
  1243. */
  1244. case TIOCMIWAIT:
  1245. #ifdef modem_control
  1246. local_irq_disable();
  1247. /* note the counters on entry */
  1248. cprev = info->state->icount;
  1249. local_irq_enable();
  1250. while (1) {
  1251. interruptible_sleep_on(&info->delta_msr_wait);
  1252. /* see if a signal did it */
  1253. if (signal_pending(current))
  1254. return -ERESTARTSYS;
  1255. local_irq_disable();
  1256. cnow = info->state->icount; /* atomic copy */
  1257. local_irq_enable();
  1258. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  1259. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
  1260. return -EIO; /* no change => error */
  1261. if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  1262. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  1263. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  1264. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
  1265. return 0;
  1266. }
  1267. cprev = cnow;
  1268. }
  1269. /* NOTREACHED */
  1270. #else
  1271. return 0;
  1272. #endif
  1273. /*
  1274. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1275. * Return: write counters to the user passed counter struct
  1276. * NB: both 1->0 and 0->1 transitions are counted except for
  1277. * RI where only 0->1 is counted.
  1278. */
  1279. case TIOCGICOUNT:
  1280. local_irq_disable();
  1281. cnow = info->state->icount;
  1282. local_irq_enable();
  1283. p_cuser = (struct serial_icounter_struct *) arg;
  1284. /* error = put_user(cnow.cts, &p_cuser->cts); */
  1285. /* if (error) return error; */
  1286. /* error = put_user(cnow.dsr, &p_cuser->dsr); */
  1287. /* if (error) return error; */
  1288. /* error = put_user(cnow.rng, &p_cuser->rng); */
  1289. /* if (error) return error; */
  1290. /* error = put_user(cnow.dcd, &p_cuser->dcd); */
  1291. /* if (error) return error; */
  1292. put_user(cnow.cts, &p_cuser->cts);
  1293. put_user(cnow.dsr, &p_cuser->dsr);
  1294. put_user(cnow.rng, &p_cuser->rng);
  1295. put_user(cnow.dcd, &p_cuser->dcd);
  1296. return 0;
  1297. default:
  1298. return -ENOIOCTLCMD;
  1299. }
  1300. return 0;
  1301. }
  1302. /* FIX UP modem control here someday......
  1303. */
  1304. static void rs_360_set_termios(struct tty_struct *tty, struct termios *old_termios)
  1305. {
  1306. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1307. if ( (tty->termios->c_cflag == old_termios->c_cflag)
  1308. && ( RELEVANT_IFLAG(tty->termios->c_iflag)
  1309. == RELEVANT_IFLAG(old_termios->c_iflag)))
  1310. return;
  1311. change_speed(info);
  1312. #ifdef modem_control
  1313. /* Handle transition to B0 status */
  1314. if ((old_termios->c_cflag & CBAUD) &&
  1315. !(tty->termios->c_cflag & CBAUD)) {
  1316. info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
  1317. local_irq_disable();
  1318. serial_out(info, UART_MCR, info->MCR);
  1319. local_irq_enable();
  1320. }
  1321. /* Handle transition away from B0 status */
  1322. if (!(old_termios->c_cflag & CBAUD) &&
  1323. (tty->termios->c_cflag & CBAUD)) {
  1324. info->MCR |= UART_MCR_DTR;
  1325. if (!tty->hw_stopped ||
  1326. !(tty->termios->c_cflag & CRTSCTS)) {
  1327. info->MCR |= UART_MCR_RTS;
  1328. }
  1329. local_irq_disable();
  1330. serial_out(info, UART_MCR, info->MCR);
  1331. local_irq_enable();
  1332. }
  1333. /* Handle turning off CRTSCTS */
  1334. if ((old_termios->c_cflag & CRTSCTS) &&
  1335. !(tty->termios->c_cflag & CRTSCTS)) {
  1336. tty->hw_stopped = 0;
  1337. rs_360_start(tty);
  1338. }
  1339. #endif
  1340. #if 0
  1341. /*
  1342. * No need to wake up processes in open wait, since they
  1343. * sample the CLOCAL flag once, and don't recheck it.
  1344. * XXX It's not clear whether the current behavior is correct
  1345. * or not. Hence, this may change.....
  1346. */
  1347. if (!(old_termios->c_cflag & CLOCAL) &&
  1348. (tty->termios->c_cflag & CLOCAL))
  1349. wake_up_interruptible(&info->open_wait);
  1350. #endif
  1351. }
  1352. /*
  1353. * ------------------------------------------------------------
  1354. * rs_close()
  1355. *
  1356. * This routine is called when the serial port gets closed. First, we
  1357. * wait for the last remaining data to be sent. Then, we unlink its
  1358. * async structure from the interrupt chain if necessary, and we free
  1359. * that IRQ if nothing is left in the chain.
  1360. * ------------------------------------------------------------
  1361. */
  1362. static void rs_360_close(struct tty_struct *tty, struct file * filp)
  1363. {
  1364. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1365. /* struct async_state *state; */
  1366. struct serial_state *state;
  1367. unsigned long flags;
  1368. int idx;
  1369. volatile struct smc_regs *smcp;
  1370. volatile struct scc_regs *sccp;
  1371. if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
  1372. return;
  1373. state = info->state;
  1374. local_irq_save(flags);
  1375. if (tty_hung_up_p(filp)) {
  1376. DBG_CNT("before DEC-hung");
  1377. local_irq_restore(flags);
  1378. return;
  1379. }
  1380. #ifdef SERIAL_DEBUG_OPEN
  1381. printk("rs_close ttys%d, count = %d\n", info->line, state->count);
  1382. #endif
  1383. if ((tty->count == 1) && (state->count != 1)) {
  1384. /*
  1385. * Uh, oh. tty->count is 1, which means that the tty
  1386. * structure will be freed. state->count should always
  1387. * be one in these conditions. If it's greater than
  1388. * one, we've got real problems, since it means the
  1389. * serial port won't be shutdown.
  1390. */
  1391. printk("rs_close: bad serial port count; tty->count is 1, "
  1392. "state->count is %d\n", state->count);
  1393. state->count = 1;
  1394. }
  1395. if (--state->count < 0) {
  1396. printk("rs_close: bad serial port count for ttys%d: %d\n",
  1397. info->line, state->count);
  1398. state->count = 0;
  1399. }
  1400. if (state->count) {
  1401. DBG_CNT("before DEC-2");
  1402. local_irq_restore(flags);
  1403. return;
  1404. }
  1405. info->flags |= ASYNC_CLOSING;
  1406. /*
  1407. * Now we wait for the transmit buffer to clear; and we notify
  1408. * the line discipline to only process XON/XOFF characters.
  1409. */
  1410. tty->closing = 1;
  1411. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1412. tty_wait_until_sent(tty, info->closing_wait);
  1413. /*
  1414. * At this point we stop accepting input. To do this, we
  1415. * disable the receive line status interrupts, and tell the
  1416. * interrupt driver to stop checking the data ready bit in the
  1417. * line status register.
  1418. */
  1419. info->read_status_mask &= ~BD_SC_EMPTY;
  1420. if (info->flags & ASYNC_INITIALIZED) {
  1421. idx = PORT_NUM(info->state->smc_scc_num);
  1422. if (info->state->smc_scc_num & NUM_IS_SCC) {
  1423. sccp = &pquicc->scc_regs[idx];
  1424. sccp->scc_sccm &= ~UART_SCCM_RX;
  1425. sccp->scc_gsmr.w.low &= ~SCC_GSMRL_ENR;
  1426. } else {
  1427. smcp = &pquicc->smc_regs[idx];
  1428. smcp->smc_smcm &= ~SMCM_RX;
  1429. smcp->smc_smcmr &= ~SMCMR_REN;
  1430. }
  1431. /*
  1432. * Before we drop DTR, make sure the UART transmitter
  1433. * has completely drained; this is especially
  1434. * important if there is a transmit FIFO!
  1435. */
  1436. rs_360_wait_until_sent(tty, info->timeout);
  1437. }
  1438. shutdown(info);
  1439. if (tty->driver->flush_buffer)
  1440. tty->driver->flush_buffer(tty);
  1441. tty_ldisc_flush(tty);
  1442. tty->closing = 0;
  1443. info->event = 0;
  1444. info->tty = 0;
  1445. if (info->blocked_open) {
  1446. if (info->close_delay) {
  1447. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  1448. }
  1449. wake_up_interruptible(&info->open_wait);
  1450. }
  1451. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1452. wake_up_interruptible(&info->close_wait);
  1453. local_irq_restore(flags);
  1454. }
  1455. /*
  1456. * rs_wait_until_sent() --- wait until the transmitter is empty
  1457. */
  1458. static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
  1459. {
  1460. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1461. unsigned long orig_jiffies, char_time;
  1462. /*int lsr;*/
  1463. volatile QUICC_BD *bdp;
  1464. if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
  1465. return;
  1466. #ifdef maybe
  1467. if (info->state->type == PORT_UNKNOWN)
  1468. return;
  1469. #endif
  1470. orig_jiffies = jiffies;
  1471. /*
  1472. * Set the check interval to be 1/5 of the estimated time to
  1473. * send a single character, and make it at least 1. The check
  1474. * interval should also be less than the timeout.
  1475. *
  1476. * Note: we have to use pretty tight timings here to satisfy
  1477. * the NIST-PCTS.
  1478. */
  1479. char_time = 1;
  1480. if (timeout)
  1481. char_time = min(char_time, (unsigned long)timeout);
  1482. #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  1483. printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
  1484. printk("jiff=%lu...", jiffies);
  1485. #endif
  1486. /* We go through the loop at least once because we can't tell
  1487. * exactly when the last character exits the shifter. There can
  1488. * be at least two characters waiting to be sent after the buffers
  1489. * are empty.
  1490. */
  1491. do {
  1492. #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  1493. printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
  1494. #endif
  1495. /* current->counter = 0; make us low-priority */
  1496. msleep_interruptible(jiffies_to_msecs(char_time));
  1497. if (signal_pending(current))
  1498. break;
  1499. if (timeout && ((orig_jiffies + timeout) < jiffies))
  1500. break;
  1501. /* The 'tx_cur' is really the next buffer to send. We
  1502. * have to back up to the previous BD and wait for it
  1503. * to go. This isn't perfect, because all this indicates
  1504. * is the buffer is available. There are still characters
  1505. * in the CPM FIFO.
  1506. */
  1507. bdp = info->tx_cur;
  1508. if (bdp == info->tx_bd_base)
  1509. bdp += (TX_NUM_FIFO-1);
  1510. else
  1511. bdp--;
  1512. } while (bdp->status & BD_SC_READY);
  1513. current->state = TASK_RUNNING;
  1514. #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  1515. printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
  1516. #endif
  1517. }
  1518. /*
  1519. * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
  1520. */
  1521. static void rs_360_hangup(struct tty_struct *tty)
  1522. {
  1523. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1524. struct serial_state *state = info->state;
  1525. if (serial_paranoia_check(info, tty->name, "rs_hangup"))
  1526. return;
  1527. state = info->state;
  1528. rs_360_flush_buffer(tty);
  1529. shutdown(info);
  1530. info->event = 0;
  1531. state->count = 0;
  1532. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  1533. info->tty = 0;
  1534. wake_up_interruptible(&info->open_wait);
  1535. }
  1536. /*
  1537. * ------------------------------------------------------------
  1538. * rs_open() and friends
  1539. * ------------------------------------------------------------
  1540. */
  1541. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  1542. ser_info_t *info)
  1543. {
  1544. #ifdef DO_THIS_LATER
  1545. DECLARE_WAITQUEUE(wait, current);
  1546. #endif
  1547. struct serial_state *state = info->state;
  1548. int retval;
  1549. int do_clocal = 0;
  1550. /*
  1551. * If the device is in the middle of being closed, then block
  1552. * until it's done, and then try again.
  1553. */
  1554. if (tty_hung_up_p(filp) ||
  1555. (info->flags & ASYNC_CLOSING)) {
  1556. if (info->flags & ASYNC_CLOSING)
  1557. interruptible_sleep_on(&info->close_wait);
  1558. #ifdef SERIAL_DO_RESTART
  1559. if (info->flags & ASYNC_HUP_NOTIFY)
  1560. return -EAGAIN;
  1561. else
  1562. return -ERESTARTSYS;
  1563. #else
  1564. return -EAGAIN;
  1565. #endif
  1566. }
  1567. /*
  1568. * If non-blocking mode is set, or the port is not enabled,
  1569. * then make the check up front and then exit.
  1570. * If this is an SMC port, we don't have modem control to wait
  1571. * for, so just get out here.
  1572. */
  1573. if ((filp->f_flags & O_NONBLOCK) ||
  1574. (tty->flags & (1 << TTY_IO_ERROR)) ||
  1575. !(info->state->smc_scc_num & NUM_IS_SCC)) {
  1576. info->flags |= ASYNC_NORMAL_ACTIVE;
  1577. return 0;
  1578. }
  1579. if (tty->termios->c_cflag & CLOCAL)
  1580. do_clocal = 1;
  1581. /*
  1582. * Block waiting for the carrier detect and the line to become
  1583. * free (i.e., not in use by the callout). While we are in
  1584. * this loop, state->count is dropped by one, so that
  1585. * rs_close() knows when to free things. We restore it upon
  1586. * exit, either normal or abnormal.
  1587. */
  1588. retval = 0;
  1589. #ifdef DO_THIS_LATER
  1590. add_wait_queue(&info->open_wait, &wait);
  1591. #ifdef SERIAL_DEBUG_OPEN
  1592. printk("block_til_ready before block: ttys%d, count = %d\n",
  1593. state->line, state->count);
  1594. #endif
  1595. local_irq_disable();
  1596. if (!tty_hung_up_p(filp))
  1597. state->count--;
  1598. local_irq_enable();
  1599. info->blocked_open++;
  1600. while (1) {
  1601. local_irq_disable();
  1602. if (tty->termios->c_cflag & CBAUD)
  1603. serial_out(info, UART_MCR,
  1604. serial_inp(info, UART_MCR) |
  1605. (UART_MCR_DTR | UART_MCR_RTS));
  1606. local_irq_enable();
  1607. set_current_state(TASK_INTERRUPTIBLE);
  1608. if (tty_hung_up_p(filp) ||
  1609. !(info->flags & ASYNC_INITIALIZED)) {
  1610. #ifdef SERIAL_DO_RESTART
  1611. if (info->flags & ASYNC_HUP_NOTIFY)
  1612. retval = -EAGAIN;
  1613. else
  1614. retval = -ERESTARTSYS;
  1615. #else
  1616. retval = -EAGAIN;
  1617. #endif
  1618. break;
  1619. }
  1620. if (!(info->flags & ASYNC_CLOSING) &&
  1621. (do_clocal || (serial_in(info, UART_MSR) &
  1622. UART_MSR_DCD)))
  1623. break;
  1624. if (signal_pending(current)) {
  1625. retval = -ERESTARTSYS;
  1626. break;
  1627. }
  1628. #ifdef SERIAL_DEBUG_OPEN
  1629. printk("block_til_ready blocking: ttys%d, count = %d\n",
  1630. info->line, state->count);
  1631. #endif
  1632. schedule();
  1633. }
  1634. current->state = TASK_RUNNING;
  1635. remove_wait_queue(&info->open_wait, &wait);
  1636. if (!tty_hung_up_p(filp))
  1637. state->count++;
  1638. info->blocked_open--;
  1639. #ifdef SERIAL_DEBUG_OPEN
  1640. printk("block_til_ready after blocking: ttys%d, count = %d\n",
  1641. info->line, state->count);
  1642. #endif
  1643. #endif /* DO_THIS_LATER */
  1644. if (retval)
  1645. return retval;
  1646. info->flags |= ASYNC_NORMAL_ACTIVE;
  1647. return 0;
  1648. }
  1649. static int get_async_struct(int line, ser_info_t **ret_info)
  1650. {
  1651. struct serial_state *sstate;
  1652. sstate = rs_table + line;
  1653. if (sstate->info) {
  1654. sstate->count++;
  1655. *ret_info = (ser_info_t *)sstate->info;
  1656. return 0;
  1657. }
  1658. else {
  1659. return -ENOMEM;
  1660. }
  1661. }
  1662. /*
  1663. * This routine is called whenever a serial port is opened. It
  1664. * enables interrupts for a serial port, linking in its async structure into
  1665. * the IRQ chain. It also performs the serial-specific
  1666. * initialization for the tty structure.
  1667. */
  1668. static int rs_360_open(struct tty_struct *tty, struct file * filp)
  1669. {
  1670. ser_info_t *info;
  1671. int retval, line;
  1672. line = tty->index;
  1673. if ((line < 0) || (line >= NR_PORTS))
  1674. return -ENODEV;
  1675. retval = get_async_struct(line, &info);
  1676. if (retval)
  1677. return retval;
  1678. if (serial_paranoia_check(info, tty->name, "rs_open"))
  1679. return -ENODEV;
  1680. #ifdef SERIAL_DEBUG_OPEN
  1681. printk("rs_open %s, count = %d\n", tty->name, info->state->count);
  1682. #endif
  1683. tty->driver_data = info;
  1684. info->tty = tty;
  1685. /*
  1686. * Start up serial port
  1687. */
  1688. retval = startup(info);
  1689. if (retval)
  1690. return retval;
  1691. retval = block_til_ready(tty, filp, info);
  1692. if (retval) {
  1693. #ifdef SERIAL_DEBUG_OPEN
  1694. printk("rs_open returning after block_til_ready with %d\n",
  1695. retval);
  1696. #endif
  1697. return retval;
  1698. }
  1699. #ifdef SERIAL_DEBUG_OPEN
  1700. printk("rs_open %s successful...", tty->name);
  1701. #endif
  1702. return 0;
  1703. }
  1704. /*
  1705. * /proc fs routines....
  1706. */
  1707. static inline int line_info(char *buf, struct serial_state *state)
  1708. {
  1709. #ifdef notdef
  1710. struct async_struct *info = state->info, scr_info;
  1711. char stat_buf[30], control, status;
  1712. #endif
  1713. int ret;
  1714. ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
  1715. state->line,
  1716. (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC",
  1717. (unsigned int)(state->port), state->irq);
  1718. if (!state->port || (state->type == PORT_UNKNOWN)) {
  1719. ret += sprintf(buf+ret, "\n");
  1720. return ret;
  1721. }
  1722. #ifdef notdef
  1723. /*
  1724. * Figure out the current RS-232 lines
  1725. */
  1726. if (!info) {
  1727. info = &scr_info; /* This is just for serial_{in,out} */
  1728. info->magic = SERIAL_MAGIC;
  1729. info->port = state->port;
  1730. info->flags = state->flags;
  1731. info->quot = 0;
  1732. info->tty = 0;
  1733. }
  1734. local_irq_disable();
  1735. status = serial_in(info, UART_MSR);
  1736. control = info ? info->MCR : serial_in(info, UART_MCR);
  1737. local_irq_enable();
  1738. stat_buf[0] = 0;
  1739. stat_buf[1] = 0;
  1740. if (control & UART_MCR_RTS)
  1741. strcat(stat_buf, "|RTS");
  1742. if (status & UART_MSR_CTS)
  1743. strcat(stat_buf, "|CTS");
  1744. if (control & UART_MCR_DTR)
  1745. strcat(stat_buf, "|DTR");
  1746. if (status & UART_MSR_DSR)
  1747. strcat(stat_buf, "|DSR");
  1748. if (status & UART_MSR_DCD)
  1749. strcat(stat_buf, "|CD");
  1750. if (status & UART_MSR_RI)
  1751. strcat(stat_buf, "|RI");
  1752. if (info->quot) {
  1753. ret += sprintf(buf+ret, " baud:%d",
  1754. state->baud_base / info->quot);
  1755. }
  1756. ret += sprintf(buf+ret, " tx:%d rx:%d",
  1757. state->icount.tx, state->icount.rx);
  1758. if (state->icount.frame)
  1759. ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
  1760. if (state->icount.parity)
  1761. ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
  1762. if (state->icount.brk)
  1763. ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
  1764. if (state->icount.overrun)
  1765. ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
  1766. /*
  1767. * Last thing is the RS-232 status lines
  1768. */
  1769. ret += sprintf(buf+ret, " %s\n", stat_buf+1);
  1770. #endif
  1771. return ret;
  1772. }
  1773. int rs_360_read_proc(char *page, char **start, off_t off, int count,
  1774. int *eof, void *data)
  1775. {
  1776. int i, len = 0;
  1777. off_t begin = 0;
  1778. len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
  1779. for (i = 0; i < NR_PORTS && len < 4000; i++) {
  1780. len += line_info(page + len, &rs_table[i]);
  1781. if (len+begin > off+count)
  1782. goto done;
  1783. if (len+begin < off) {
  1784. begin += len;
  1785. len = 0;
  1786. }
  1787. }
  1788. *eof = 1;
  1789. done:
  1790. if (off >= len+begin)
  1791. return 0;
  1792. *start = page + (begin-off);
  1793. return ((count < begin+len-off) ? count : begin+len-off);
  1794. }
  1795. /*
  1796. * ---------------------------------------------------------------------
  1797. * rs_init() and friends
  1798. *
  1799. * rs_init() is called at boot-time to initialize the serial driver.
  1800. * ---------------------------------------------------------------------
  1801. */
  1802. /*
  1803. * This routine prints out the appropriate serial driver version
  1804. * number, and identifies which options were configured into this
  1805. * driver.
  1806. */
  1807. static _INLINE_ void show_serial_version(void)
  1808. {
  1809. printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
  1810. }
  1811. /*
  1812. * The serial console driver used during boot. Note that these names
  1813. * clash with those found in "serial.c", so we currently can't support
  1814. * the 16xxx uarts and these at the same time. I will fix this to become
  1815. * an indirect function call from tty_io.c (or something).
  1816. */
  1817. #ifdef CONFIG_SERIAL_CONSOLE
  1818. /*
  1819. * Print a string to the serial port trying not to disturb any possible
  1820. * real use of the port...
  1821. */
  1822. static void my_console_write(int idx, const char *s,
  1823. unsigned count)
  1824. {
  1825. struct serial_state *ser;
  1826. ser_info_t *info;
  1827. unsigned i;
  1828. QUICC_BD *bdp, *bdbase;
  1829. volatile struct smc_uart_pram *up;
  1830. volatile u_char *cp;
  1831. ser = rs_table + idx;
  1832. /* If the port has been initialized for general use, we have
  1833. * to use the buffer descriptors allocated there. Otherwise,
  1834. * we simply use the single buffer allocated.
  1835. */
  1836. if ((info = (ser_info_t *)ser->info) != NULL) {
  1837. bdp = info->tx_cur;
  1838. bdbase = info->tx_bd_base;
  1839. }
  1840. else {
  1841. /* Pointer to UART in parameter ram.
  1842. */
  1843. /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
  1844. up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
  1845. /* Get the address of the host memory buffer.
  1846. */
  1847. bdp = bdbase = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
  1848. }
  1849. /*
  1850. * We need to gracefully shut down the transmitter, disable
  1851. * interrupts, then send our bytes out.
  1852. */
  1853. /*
  1854. * Now, do each character. This is not as bad as it looks
  1855. * since this is a holding FIFO and not a transmitting FIFO.
  1856. * We could add the complexity of filling the entire transmit
  1857. * buffer, but we would just wait longer between accesses......
  1858. */
  1859. for (i = 0; i < count; i++, s++) {
  1860. /* Wait for transmitter fifo to empty.
  1861. * Ready indicates output is ready, and xmt is doing
  1862. * that, not that it is ready for us to send.
  1863. */
  1864. while (bdp->status & BD_SC_READY);
  1865. /* Send the character out.
  1866. */
  1867. cp = bdp->buf;
  1868. *cp = *s;
  1869. bdp->length = 1;
  1870. bdp->status |= BD_SC_READY;
  1871. if (bdp->status & BD_SC_WRAP)
  1872. bdp = bdbase;
  1873. else
  1874. bdp++;
  1875. /* if a LF, also do CR... */
  1876. if (*s == 10) {
  1877. while (bdp->status & BD_SC_READY);
  1878. /* cp = __va(bdp->buf); */
  1879. cp = bdp->buf;
  1880. *cp = 13;
  1881. bdp->length = 1;
  1882. bdp->status |= BD_SC_READY;
  1883. if (bdp->status & BD_SC_WRAP) {
  1884. bdp = bdbase;
  1885. }
  1886. else {
  1887. bdp++;
  1888. }
  1889. }
  1890. }
  1891. /*
  1892. * Finally, Wait for transmitter & holding register to empty
  1893. * and restore the IER
  1894. */
  1895. while (bdp->status & BD_SC_READY);
  1896. if (info)
  1897. info->tx_cur = (QUICC_BD *)bdp;
  1898. }
  1899. static void serial_console_write(struct console *c, const char *s,
  1900. unsigned count)
  1901. {
  1902. #ifdef CONFIG_KGDB
  1903. /* Try to let stub handle output. Returns true if it did. */
  1904. if (kgdb_output_string(s, count))
  1905. return;
  1906. #endif
  1907. my_console_write(c->index, s, count);
  1908. }
  1909. /*void console_print_68360(const char *p)
  1910. {
  1911. const char *cp = p;
  1912. int i;
  1913. for (i=0;cp[i]!=0;i++);
  1914. serial_console_write (p, i);
  1915. //Comment this if you want to have a strict interrupt-driven output
  1916. //rs_fair_output();
  1917. return;
  1918. }*/
  1919. #ifdef CONFIG_XMON
  1920. int
  1921. xmon_360_write(const char *s, unsigned count)
  1922. {
  1923. my_console_write(0, s, count);
  1924. return(count);
  1925. }
  1926. #endif
  1927. #ifdef CONFIG_KGDB
  1928. void
  1929. putDebugChar(char ch)
  1930. {
  1931. my_console_write(0, &ch, 1);
  1932. }
  1933. #endif
  1934. /*
  1935. * Receive character from the serial port. This only works well
  1936. * before the port is initialized for real use.
  1937. */
  1938. static int my_console_wait_key(int idx, int xmon, char *obuf)
  1939. {
  1940. struct serial_state *ser;
  1941. u_char c, *cp;
  1942. ser_info_t *info;
  1943. QUICC_BD *bdp;
  1944. volatile struct smc_uart_pram *up;
  1945. int i;
  1946. ser = rs_table + idx;
  1947. /* Get the address of the host memory buffer.
  1948. * If the port has been initialized for general use, we must
  1949. * use information from the port structure.
  1950. */
  1951. if ((info = (ser_info_t *)ser->info))
  1952. bdp = info->rx_cur;
  1953. else
  1954. /* bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase]; */
  1955. bdp = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
  1956. /* Pointer to UART in parameter ram.
  1957. */
  1958. /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
  1959. up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
  1960. /*
  1961. * We need to gracefully shut down the receiver, disable
  1962. * interrupts, then read the input.
  1963. * XMON just wants a poll. If no character, return -1, else
  1964. * return the character.
  1965. */
  1966. if (!xmon) {
  1967. while (bdp->status & BD_SC_EMPTY);
  1968. }
  1969. else {
  1970. if (bdp->status & BD_SC_EMPTY)
  1971. return -1;
  1972. }
  1973. cp = (char *)bdp->buf;
  1974. if (obuf) {
  1975. i = c = bdp->length;
  1976. while (i-- > 0)
  1977. *obuf++ = *cp++;
  1978. }
  1979. else {
  1980. c = *cp;
  1981. }
  1982. bdp->status |= BD_SC_EMPTY;
  1983. if (info) {
  1984. if (bdp->status & BD_SC_WRAP) {
  1985. bdp = info->rx_bd_base;
  1986. }
  1987. else {
  1988. bdp++;
  1989. }
  1990. info->rx_cur = (QUICC_BD *)bdp;
  1991. }
  1992. return((int)c);
  1993. }
  1994. static int serial_console_wait_key(struct console *co)
  1995. {
  1996. return(my_console_wait_key(co->index, 0, NULL));
  1997. }
  1998. #ifdef CONFIG_XMON
  1999. int
  2000. xmon_360_read_poll(void)
  2001. {
  2002. return(my_console_wait_key(0, 1, NULL));
  2003. }
  2004. int
  2005. xmon_360_read_char(void)
  2006. {
  2007. return(my_console_wait_key(0, 0, NULL));
  2008. }
  2009. #endif
  2010. #ifdef CONFIG_KGDB
  2011. static char kgdb_buf[RX_BUF_SIZE], *kgdp;
  2012. static int kgdb_chars;
  2013. unsigned char
  2014. getDebugChar(void)
  2015. {
  2016. if (kgdb_chars <= 0) {
  2017. kgdb_chars = my_console_wait_key(0, 0, kgdb_buf);
  2018. kgdp = kgdb_buf;
  2019. }
  2020. kgdb_chars--;
  2021. return(*kgdp++);
  2022. }
  2023. void kgdb_interruptible(int state)
  2024. {
  2025. }
  2026. void kgdb_map_scc(void)
  2027. {
  2028. struct serial_state *ser;
  2029. uint mem_addr;
  2030. volatile QUICC_BD *bdp;
  2031. volatile smc_uart_t *up;
  2032. cpmp = (cpm360_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
  2033. /* To avoid data cache CPM DMA coherency problems, allocate a
  2034. * buffer in the CPM DPRAM. This will work until the CPM and
  2035. * serial ports are initialized. At that time a memory buffer
  2036. * will be allocated.
  2037. * The port is already initialized from the boot procedure, all
  2038. * we do here is give it a different buffer and make it a FIFO.
  2039. */
  2040. ser = rs_table;
  2041. /* Right now, assume we are using SMCs.
  2042. */
  2043. up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
  2044. /* Allocate space for an input FIFO, plus a few bytes for output.
  2045. * Allocate bytes to maintain word alignment.
  2046. */
  2047. mem_addr = (uint)(&cpmp->cp_dpmem[0x1000]);
  2048. /* Set the physical address of the host memory buffers in
  2049. * the buffer descriptors.
  2050. */
  2051. bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase];
  2052. bdp->buf = mem_addr;
  2053. bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_tbase];
  2054. bdp->buf = mem_addr+RX_BUF_SIZE;
  2055. up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
  2056. up->smc_maxidl = RX_BUF_SIZE;
  2057. }
  2058. #endif
  2059. static struct tty_struct *serial_console_device(struct console *c, int *index)
  2060. {
  2061. *index = c->index;
  2062. return serial_driver;
  2063. }
  2064. struct console sercons = {
  2065. .name = "ttyS",
  2066. .write = serial_console_write,
  2067. .device = serial_console_device,
  2068. .wait_key = serial_console_wait_key,
  2069. .setup = serial_console_setup,
  2070. .flags = CON_PRINTBUFFER,
  2071. .index = CONFIG_SERIAL_CONSOLE_PORT,
  2072. };
  2073. /*
  2074. * Register console.
  2075. */
  2076. long console_360_init(long kmem_start, long kmem_end)
  2077. {
  2078. register_console(&sercons);
  2079. /*register_console (console_print_68360); - 2.0.38 only required a write
  2080. function pointer. */
  2081. return kmem_start;
  2082. }
  2083. #endif
  2084. /* Index in baud rate table of the default console baud rate.
  2085. */
  2086. static int baud_idx;
  2087. static const struct tty_operations rs_360_ops = {
  2088. .owner = THIS_MODULE,
  2089. .open = rs_360_open,
  2090. .close = rs_360_close,
  2091. .write = rs_360_write,
  2092. .put_char = rs_360_put_char,
  2093. .write_room = rs_360_write_room,
  2094. .chars_in_buffer = rs_360_chars_in_buffer,
  2095. .flush_buffer = rs_360_flush_buffer,
  2096. .ioctl = rs_360_ioctl,
  2097. .throttle = rs_360_throttle,
  2098. .unthrottle = rs_360_unthrottle,
  2099. /* .send_xchar = rs_360_send_xchar, */
  2100. .set_termios = rs_360_set_termios,
  2101. .stop = rs_360_stop,
  2102. .start = rs_360_start,
  2103. .hangup = rs_360_hangup,
  2104. /* .wait_until_sent = rs_360_wait_until_sent, */
  2105. /* .read_proc = rs_360_read_proc, */
  2106. .tiocmget = rs_360_tiocmget,
  2107. .tiocmset = rs_360_tiocmset,
  2108. };
  2109. static int __init rs_360_init(void)
  2110. {
  2111. struct serial_state * state;
  2112. ser_info_t *info;
  2113. void *mem_addr;
  2114. uint dp_addr, iobits;
  2115. int i, j, idx;
  2116. ushort chan;
  2117. QUICC_BD *bdp;
  2118. volatile QUICC *cp;
  2119. volatile struct smc_regs *sp;
  2120. volatile struct smc_uart_pram *up;
  2121. volatile struct scc_regs *scp;
  2122. volatile struct uart_pram *sup;
  2123. /* volatile immap_t *immap; */
  2124. serial_driver = alloc_tty_driver(NR_PORTS);
  2125. if (!serial_driver)
  2126. return -1;
  2127. show_serial_version();
  2128. serial_driver->name = "ttyS";
  2129. serial_driver->major = TTY_MAJOR;
  2130. serial_driver->minor_start = 64;
  2131. serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  2132. serial_driver->subtype = SERIAL_TYPE_NORMAL;
  2133. serial_driver->init_termios = tty_std_termios;
  2134. serial_driver->init_termios.c_cflag =
  2135. baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
  2136. serial_driver->flags = TTY_DRIVER_REAL_RAW;
  2137. tty_set_operations(serial_driver, &rs_360_ops);
  2138. if (tty_register_driver(serial_driver))
  2139. panic("Couldn't register serial driver\n");
  2140. cp = pquicc; /* Get pointer to Communication Processor */
  2141. /* immap = (immap_t *)IMAP_ADDR; */ /* and to internal registers */
  2142. /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
  2143. */
  2144. /* The "standard" configuration through the 860.
  2145. */
  2146. /* immap->im_ioport.iop_papar |= 0x00fc; */
  2147. /* immap->im_ioport.iop_padir &= ~0x00fc; */
  2148. /* immap->im_ioport.iop_paodr &= ~0x00fc; */
  2149. cp->pio_papar |= 0x00fc;
  2150. cp->pio_padir &= ~0x00fc;
  2151. /* cp->pio_paodr &= ~0x00fc; */
  2152. /* Since we don't yet do modem control, connect the port C pins
  2153. * as general purpose I/O. This will assert CTS and CD for the
  2154. * SCC ports.
  2155. */
  2156. /* FIXME: see 360um p.7-365 and 860um p.34-12
  2157. * I can't make sense of these bits - mleslie*/
  2158. /* immap->im_ioport.iop_pcdir |= 0x03c6; */
  2159. /* immap->im_ioport.iop_pcpar &= ~0x03c6; */
  2160. /* cp->pio_pcdir |= 0x03c6; */
  2161. /* cp->pio_pcpar &= ~0x03c6; */
  2162. /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
  2163. * BRG4 to SCC3.
  2164. */
  2165. cp->si_sicr &= ~0x00ffff00;
  2166. cp->si_sicr |= 0x001b1200;
  2167. #ifdef CONFIG_PP04
  2168. /* Frequentis PP04 forced to RS-232 until we know better.
  2169. * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
  2170. */
  2171. immap->im_ioport.iop_pcdir |= 0x000c;
  2172. immap->im_ioport.iop_pcpar &= ~0x000c;
  2173. immap->im_ioport.iop_pcdat &= ~0x000c;
  2174. /* This enables the TX driver.
  2175. */
  2176. cp->cp_pbpar &= ~0x6000;
  2177. cp->cp_pbdat &= ~0x6000;
  2178. #endif
  2179. for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
  2180. state->magic = SSTATE_MAGIC;
  2181. state->line = i;
  2182. state->type = PORT_UNKNOWN;
  2183. state->custom_divisor = 0;
  2184. state->close_delay = 5*HZ/10;
  2185. state->closing_wait = 30*HZ;
  2186. state->icount.cts = state->icount.dsr =
  2187. state->icount.rng = state->icount.dcd = 0;
  2188. state->icount.rx = state->icount.tx = 0;
  2189. state->icount.frame = state->icount.parity = 0;
  2190. state->icount.overrun = state->icount.brk = 0;
  2191. printk(KERN_INFO "ttyS%d at irq 0x%02x is an %s\n",
  2192. i, (unsigned int)(state->irq),
  2193. (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC");
  2194. #ifdef CONFIG_SERIAL_CONSOLE
  2195. /* If we just printed the message on the console port, and
  2196. * we are about to initialize it for general use, we have
  2197. * to wait a couple of character times for the CR/NL to
  2198. * make it out of the transmit buffer.
  2199. */
  2200. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2201. mdelay(8);
  2202. /* idx = PORT_NUM(info->state->smc_scc_num); */
  2203. /* if (info->state->smc_scc_num & NUM_IS_SCC) */
  2204. /* chan = scc_chan_map[idx]; */
  2205. /* else */
  2206. /* chan = smc_chan_map[idx]; */
  2207. /* cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG; */
  2208. /* while (cp->cp_cr & CPM_CR_FLG); */
  2209. #endif
  2210. /* info = kmalloc(sizeof(ser_info_t), GFP_KERNEL); */
  2211. info = &quicc_ser_info[i];
  2212. if (info) {
  2213. memset (info, 0, sizeof(ser_info_t));
  2214. info->magic = SERIAL_MAGIC;
  2215. info->line = i;
  2216. info->flags = state->flags;
  2217. INIT_WORK(&info->tqueue, do_softint, info);
  2218. INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
  2219. init_waitqueue_head(&info->open_wait);
  2220. init_waitqueue_head(&info->close_wait);
  2221. info->state = state;
  2222. state->info = (struct async_struct *)info;
  2223. /* We need to allocate a transmit and receive buffer
  2224. * descriptors from dual port ram, and a character
  2225. * buffer area from host mem.
  2226. */
  2227. dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * RX_NUM_FIFO);
  2228. /* Allocate space for FIFOs in the host memory.
  2229. * (for now this is from a static array of buffers :(
  2230. */
  2231. /* mem_addr = m360_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE); */
  2232. /* mem_addr = kmalloc (RX_NUM_FIFO * RX_BUF_SIZE, GFP_BUFFER); */
  2233. mem_addr = &rx_buf_pool[i * RX_NUM_FIFO * RX_BUF_SIZE];
  2234. /* Set the physical address of the host memory
  2235. * buffers in the buffer descriptors, and the
  2236. * virtual address for us to work with.
  2237. */
  2238. bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
  2239. info->rx_cur = info->rx_bd_base = bdp;
  2240. /* initialize rx buffer descriptors */
  2241. for (j=0; j<(RX_NUM_FIFO-1); j++) {
  2242. bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
  2243. bdp->status = BD_SC_EMPTY | BD_SC_INTRPT;
  2244. mem_addr += RX_BUF_SIZE;
  2245. bdp++;
  2246. }
  2247. bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
  2248. bdp->status = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
  2249. idx = PORT_NUM(info->state->smc_scc_num);
  2250. if (info->state->smc_scc_num & NUM_IS_SCC) {
  2251. #if defined (CONFIG_UCQUICC) && 1
  2252. /* set the transceiver mode to RS232 */
  2253. sipex_mode_bits &= ~(uint)SIPEX_MODE(idx,0x0f); /* clear current mode */
  2254. sipex_mode_bits |= (uint)SIPEX_MODE(idx,0x02);
  2255. *(uint *)_periph_base = sipex_mode_bits;
  2256. /* printk ("sipex bits = 0x%08x\n", sipex_mode_bits); */
  2257. #endif
  2258. }
  2259. dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * TX_NUM_FIFO);
  2260. /* Allocate space for FIFOs in the host memory.
  2261. */
  2262. /* mem_addr = m360_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE); */
  2263. /* mem_addr = kmalloc (TX_NUM_FIFO * TX_BUF_SIZE, GFP_BUFFER); */
  2264. mem_addr = &tx_buf_pool[i * TX_NUM_FIFO * TX_BUF_SIZE];
  2265. /* Set the physical address of the host memory
  2266. * buffers in the buffer descriptors, and the
  2267. * virtual address for us to work with.
  2268. */
  2269. /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
  2270. bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
  2271. info->tx_cur = info->tx_bd_base = (QUICC_BD *)bdp;
  2272. /* initialize tx buffer descriptors */
  2273. for (j=0; j<(TX_NUM_FIFO-1); j++) {
  2274. bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
  2275. bdp->status = BD_SC_INTRPT;
  2276. mem_addr += TX_BUF_SIZE;
  2277. bdp++;
  2278. }
  2279. bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
  2280. bdp->status = (BD_SC_WRAP | BD_SC_INTRPT);
  2281. if (info->state->smc_scc_num & NUM_IS_SCC) {
  2282. scp = &pquicc->scc_regs[idx];
  2283. sup = &pquicc->pram[info->state->port].scc.pscc.u;
  2284. sup->rbase = dp_addr;
  2285. sup->tbase = dp_addr;
  2286. /* Set up the uart parameters in the
  2287. * parameter ram.
  2288. */
  2289. sup->rfcr = SMC_EB;
  2290. sup->tfcr = SMC_EB;
  2291. /* Set this to 1 for now, so we get single
  2292. * character interrupts. Using idle charater
  2293. * time requires some additional tuning.
  2294. */
  2295. sup->mrblr = 1;
  2296. sup->max_idl = 0;
  2297. sup->brkcr = 1;
  2298. sup->parec = 0;
  2299. sup->frmer = 0;
  2300. sup->nosec = 0;
  2301. sup->brkec = 0;
  2302. sup->uaddr1 = 0;
  2303. sup->uaddr2 = 0;
  2304. sup->toseq = 0;
  2305. {
  2306. int i;
  2307. for (i=0;i<8;i++)
  2308. sup->cc[i] = 0x8000;
  2309. }
  2310. sup->rccm = 0xc0ff;
  2311. /* Send the CPM an initialize command.
  2312. */
  2313. chan = scc_chan_map[idx];
  2314. /* execute the INIT RX & TX PARAMS command for this channel. */
  2315. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2316. while (cp->cp_cr & CPM_CR_FLG);
  2317. /* Set UART mode, 8 bit, no parity, one stop.
  2318. * Enable receive and transmit.
  2319. */
  2320. scp->scc_gsmr.w.high = 0;
  2321. scp->scc_gsmr.w.low =
  2322. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  2323. /* Disable all interrupts and clear all pending
  2324. * events.
  2325. */
  2326. scp->scc_sccm = 0;
  2327. scp->scc_scce = 0xffff;
  2328. scp->scc_dsr = 0x7e7e;
  2329. scp->scc_psmr = 0x3000;
  2330. /* If the port is the console, enable Rx and Tx.
  2331. */
  2332. #ifdef CONFIG_SERIAL_CONSOLE
  2333. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2334. scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  2335. #endif
  2336. }
  2337. else {
  2338. /* Configure SMCs Tx/Rx instead of port B
  2339. * parallel I/O.
  2340. */
  2341. up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
  2342. up->rbase = dp_addr;
  2343. iobits = 0xc0 << (idx * 4);
  2344. cp->pip_pbpar |= iobits;
  2345. cp->pip_pbdir &= ~iobits;
  2346. cp->pip_pbodr &= ~iobits;
  2347. /* Connect the baud rate generator to the
  2348. * SMC based upon index in rs_table. Also
  2349. * make sure it is connected to NMSI.
  2350. */
  2351. cp->si_simode &= ~(0xffff << (idx * 16));
  2352. cp->si_simode |= (i << ((idx * 16) + 12));
  2353. up->tbase = dp_addr;
  2354. /* Set up the uart parameters in the
  2355. * parameter ram.
  2356. */
  2357. up->rfcr = SMC_EB;
  2358. up->tfcr = SMC_EB;
  2359. /* Set this to 1 for now, so we get single
  2360. * character interrupts. Using idle charater
  2361. * time requires some additional tuning.
  2362. */
  2363. up->mrblr = 1;
  2364. up->max_idl = 0;
  2365. up->brkcr = 1;
  2366. /* Send the CPM an initialize command.
  2367. */
  2368. chan = smc_chan_map[idx];
  2369. cp->cp_cr = mk_cr_cmd(chan,
  2370. CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2371. #ifdef CONFIG_SERIAL_CONSOLE
  2372. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2373. printk("");
  2374. #endif
  2375. while (cp->cp_cr & CPM_CR_FLG);
  2376. /* Set UART mode, 8 bit, no parity, one stop.
  2377. * Enable receive and transmit.
  2378. */
  2379. sp = &cp->smc_regs[idx];
  2380. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  2381. /* Disable all interrupts and clear all pending
  2382. * events.
  2383. */
  2384. sp->smc_smcm = 0;
  2385. sp->smc_smce = 0xff;
  2386. /* If the port is the console, enable Rx and Tx.
  2387. */
  2388. #ifdef CONFIG_SERIAL_CONSOLE
  2389. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2390. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  2391. #endif
  2392. }
  2393. /* Install interrupt handler.
  2394. */
  2395. /* cpm_install_handler(IRQ_MACHSPEC | state->irq, rs_360_interrupt, info); */
  2396. /*request_irq(IRQ_MACHSPEC | state->irq, rs_360_interrupt, */
  2397. request_irq(state->irq, rs_360_interrupt,
  2398. IRQ_FLG_LOCK, "ttyS", (void *)info);
  2399. /* Set up the baud rate generator.
  2400. */
  2401. m360_cpm_setbrg(i, baud_table[baud_idx]);
  2402. }
  2403. }
  2404. return 0;
  2405. }
  2406. module_init(rs_360_init);
  2407. /* This must always be called before the rs_360_init() function, otherwise
  2408. * it blows away the port control information.
  2409. */
  2410. //static int __init serial_console_setup( struct console *co, char *options)
  2411. int serial_console_setup( struct console *co, char *options)
  2412. {
  2413. struct serial_state *ser;
  2414. uint mem_addr, dp_addr, bidx, idx, iobits;
  2415. ushort chan;
  2416. QUICC_BD *bdp;
  2417. volatile QUICC *cp;
  2418. volatile struct smc_regs *sp;
  2419. volatile struct scc_regs *scp;
  2420. volatile struct smc_uart_pram *up;
  2421. volatile struct uart_pram *sup;
  2422. /* mleslie TODO:
  2423. * add something to the 68k bootloader to store a desired initial console baud rate */
  2424. /* bd_t *bd; */ /* a board info struct used by EPPC-bug */
  2425. /* bd = (bd_t *)__res; */
  2426. for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
  2427. /* if (bd->bi_baudrate == baud_table[bidx]) */
  2428. if (CONSOLE_BAUDRATE == baud_table[bidx])
  2429. break;
  2430. /* co->cflag = CREAD|CLOCAL|bidx|CS8; */
  2431. baud_idx = bidx;
  2432. ser = rs_table + CONFIG_SERIAL_CONSOLE_PORT;
  2433. cp = pquicc; /* Get pointer to Communication Processor */
  2434. idx = PORT_NUM(ser->smc_scc_num);
  2435. if (ser->smc_scc_num & NUM_IS_SCC) {
  2436. /* TODO: need to set up SCC pin assignment etc. here */
  2437. }
  2438. else {
  2439. iobits = 0xc0 << (idx * 4);
  2440. cp->pip_pbpar |= iobits;
  2441. cp->pip_pbdir &= ~iobits;
  2442. cp->pip_pbodr &= ~iobits;
  2443. /* Connect the baud rate generator to the
  2444. * SMC based upon index in rs_table. Also
  2445. * make sure it is connected to NMSI.
  2446. */
  2447. cp->si_simode &= ~(0xffff << (idx * 16));
  2448. cp->si_simode |= (idx << ((idx * 16) + 12));
  2449. }
  2450. /* When we get here, the CPM has been reset, so we need
  2451. * to configure the port.
  2452. * We need to allocate a transmit and receive buffer descriptor
  2453. * from dual port ram, and a character buffer area from host mem.
  2454. */
  2455. /* Allocate space for two buffer descriptors in the DP ram.
  2456. */
  2457. dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * CONSOLE_NUM_FIFO);
  2458. /* Allocate space for two 2 byte FIFOs in the host memory.
  2459. */
  2460. /* mem_addr = m360_cpm_hostalloc(8); */
  2461. mem_addr = (uint)console_fifos;
  2462. /* Set the physical address of the host memory buffers in
  2463. * the buffer descriptors.
  2464. */
  2465. /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
  2466. bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
  2467. bdp->buf = (char *)mem_addr;
  2468. (bdp+1)->buf = (char *)(mem_addr+4);
  2469. /* For the receive, set empty and wrap.
  2470. * For transmit, set wrap.
  2471. */
  2472. bdp->status = BD_SC_EMPTY | BD_SC_WRAP;
  2473. (bdp+1)->status = BD_SC_WRAP;
  2474. /* Set up the uart parameters in the parameter ram.
  2475. */
  2476. if (ser->smc_scc_num & NUM_IS_SCC) {
  2477. scp = &cp->scc_regs[idx];
  2478. /* sup = (scc_uart_t *)&cp->cp_dparam[ser->port]; */
  2479. sup = &pquicc->pram[ser->port].scc.pscc.u;
  2480. sup->rbase = dp_addr;
  2481. sup->tbase = dp_addr + sizeof(QUICC_BD);
  2482. /* Set up the uart parameters in the
  2483. * parameter ram.
  2484. */
  2485. sup->rfcr = SMC_EB;
  2486. sup->tfcr = SMC_EB;
  2487. /* Set this to 1 for now, so we get single
  2488. * character interrupts. Using idle charater
  2489. * time requires some additional tuning.
  2490. */
  2491. sup->mrblr = 1;
  2492. sup->max_idl = 0;
  2493. sup->brkcr = 1;
  2494. sup->parec = 0;
  2495. sup->frmer = 0;
  2496. sup->nosec = 0;
  2497. sup->brkec = 0;
  2498. sup->uaddr1 = 0;
  2499. sup->uaddr2 = 0;
  2500. sup->toseq = 0;
  2501. {
  2502. int i;
  2503. for (i=0;i<8;i++)
  2504. sup->cc[i] = 0x8000;
  2505. }
  2506. sup->rccm = 0xc0ff;
  2507. /* Send the CPM an initialize command.
  2508. */
  2509. chan = scc_chan_map[idx];
  2510. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2511. while (cp->cp_cr & CPM_CR_FLG);
  2512. /* Set UART mode, 8 bit, no parity, one stop.
  2513. * Enable receive and transmit.
  2514. */
  2515. scp->scc_gsmr.w.high = 0;
  2516. scp->scc_gsmr.w.low =
  2517. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  2518. /* Disable all interrupts and clear all pending
  2519. * events.
  2520. */
  2521. scp->scc_sccm = 0;
  2522. scp->scc_scce = 0xffff;
  2523. scp->scc_dsr = 0x7e7e;
  2524. scp->scc_psmr = 0x3000;
  2525. scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  2526. }
  2527. else {
  2528. /* up = (smc_uart_t *)&cp->cp_dparam[ser->port]; */
  2529. up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
  2530. up->rbase = dp_addr; /* Base of receive buffer desc. */
  2531. up->tbase = dp_addr+sizeof(QUICC_BD); /* Base of xmt buffer desc. */
  2532. up->rfcr = SMC_EB;
  2533. up->tfcr = SMC_EB;
  2534. /* Set this to 1 for now, so we get single character interrupts.
  2535. */
  2536. up->mrblr = 1; /* receive buffer length */
  2537. up->max_idl = 0; /* wait forever for next char */
  2538. /* Send the CPM an initialize command.
  2539. */
  2540. chan = smc_chan_map[idx];
  2541. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2542. while (cp->cp_cr & CPM_CR_FLG);
  2543. /* Set UART mode, 8 bit, no parity, one stop.
  2544. * Enable receive and transmit.
  2545. */
  2546. sp = &cp->smc_regs[idx];
  2547. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  2548. /* And finally, enable Rx and Tx.
  2549. */
  2550. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  2551. }
  2552. /* Set up the baud rate generator.
  2553. */
  2554. /* m360_cpm_setbrg((ser - rs_table), bd->bi_baudrate); */
  2555. m360_cpm_setbrg((ser - rs_table), CONSOLE_BAUDRATE);
  2556. return 0;
  2557. }
  2558. /*
  2559. * Local variables:
  2560. * c-indent-level: 4
  2561. * c-basic-offset: 4
  2562. * tab-width: 4
  2563. * End:
  2564. */