68360serial.c 75 KB

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