PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/release/src-rt-6.x/cfe/cfe/dev/dev_promice.c

https://gitlab.com/envieidoc/advancedtomato2
C | 400 lines | 147 code | 60 blank | 193 comment | 12 complexity | b38805c878a58ed2bb75c54d2ec209ec MD5 | raw file
  1. /* *********************************************************************
  2. * Broadcom Common Firmware Environment (CFE)
  3. *
  4. * PromICE console device File: dev_promice.c
  5. *
  6. * This device driver supports Grammar Engine's PromICE AI2
  7. * serial communications options. With this console, you can
  8. * communicate with the firmware using only uncached reads in the
  9. * boot ROM space. See Grammar Engine's PromICE manuals
  10. * for more information at http://www.gei.com
  11. *
  12. * Author: Mitch Lichtenberg (mpl@broadcom.com)
  13. *
  14. *********************************************************************
  15. *
  16. * Copyright 2000,2001,2002,2003
  17. * Broadcom Corporation. All rights reserved.
  18. *
  19. * This software is furnished under license and may be used and
  20. * copied only in accordance with the following terms and
  21. * conditions. Subject to these conditions, you may download,
  22. * copy, install, use, modify and distribute modified or unmodified
  23. * copies of this software in source and/or binary form. No title
  24. * or ownership is transferred hereby.
  25. *
  26. * 1) Any source code used, modified or distributed must reproduce
  27. * and retain this copyright notice and list of conditions
  28. * as they appear in the source file.
  29. *
  30. * 2) No right is granted to use any trade name, trademark, or
  31. * logo of Broadcom Corporation. The "Broadcom Corporation"
  32. * name may not be used to endorse or promote products derived
  33. * from this software without the prior written permission of
  34. * Broadcom Corporation.
  35. *
  36. * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
  37. * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
  38. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  39. * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
  40. * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
  41. * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
  42. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  43. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  44. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  45. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  46. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  47. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
  48. * THE POSSIBILITY OF SUCH DAMAGE.
  49. ********************************************************************* */
  50. /*
  51. * Example PromICE initialization file:
  52. *
  53. * -----------------------
  54. * output=com1
  55. * pponly=lpt1
  56. * rom=27040
  57. * word=8
  58. * file=cfe.srec
  59. * ailoc 7FC00,9600
  60. * -----------------------
  61. *
  62. * The offset specified in the 'ailoc' line must be the location where you
  63. * will configure the AI2 serial port. In this example, the ROM is assumed
  64. * to be 512KB, and the AI2 serial port is at 511KB, or offset 0x7FC00.
  65. * This area is filled with 0xCC to detect AI2's initialization sequence
  66. * properly (see the PromICE manual). You should connect your
  67. * PromICE's serial port up to the PC and run a terminal emulator on it.
  68. * The parallel port will be used for downloading data to the PromICE.
  69. *
  70. * If you have connected the write line to the PromICE, then you can
  71. * define the _AIDIRT_ symbol to increase performance.
  72. */
  73. #include "lib_types.h"
  74. #include "lib_malloc.h"
  75. #include "lib_printf.h"
  76. #include "lib_string.h"
  77. #include "cfe_iocb.h"
  78. #include "cfe_device.h"
  79. #include "addrspace.h"
  80. #define _AIDIRT_
  81. /* *********************************************************************
  82. * Prototypes
  83. ********************************************************************* */
  84. static void promice_probe(cfe_driver_t *drv,
  85. unsigned long probe_a, unsigned long probe_b,
  86. void *probe_ptr);
  87. static int promice_open(cfe_devctx_t *ctx);
  88. static int promice_read(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
  89. static int promice_inpstat(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat);
  90. static int promice_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
  91. static int promice_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
  92. static int promice_close(cfe_devctx_t *ctx);
  93. /* *********************************************************************
  94. * Device dispatch table
  95. ********************************************************************* */
  96. const static cfe_devdisp_t promice_dispatch = {
  97. promice_open,
  98. promice_read,
  99. promice_inpstat,
  100. promice_write,
  101. promice_ioctl,
  102. promice_close,
  103. NULL,
  104. NULL
  105. };
  106. /* *********************************************************************
  107. * Device descriptor
  108. ********************************************************************* */
  109. const cfe_driver_t promice_uart = {
  110. "PromICE AI2 Serial Port",
  111. "promice",
  112. CFE_DEV_SERIAL,
  113. &promice_dispatch,
  114. promice_probe
  115. };
  116. /* *********************************************************************
  117. * Local constants and structures
  118. ********************************************************************* */
  119. /*
  120. * If your PromICE is connected to a 32-bit host (emulating four
  121. * flash ROMs) and the SB1250 is set to boot from that host, define
  122. * the PROMICE_32BITS symbol to make sure the AI2 interface is
  123. * configured correctly.
  124. */
  125. /*#define PROMICE_32BITS*/
  126. #ifdef PROMICE_32BITS
  127. #define WORDSIZE 4
  128. #define WORDTYPE uint32_t
  129. #else
  130. #define WORDSIZE 1
  131. #define WORDTYPE uint8_t
  132. #endif
  133. #define ZERO_OFFSET (0)
  134. #define ONE_OFFSET (1)
  135. #define DATA_OFFSET (2)
  136. #define STATUS_OFFSET (3)
  137. #define TDA 0x01 /* Target data available */
  138. #define HDA 0x02 /* Host data available */
  139. #define OVR 0x04 /* Host data overflow */
  140. typedef struct promice_s {
  141. unsigned long ai2_addr;
  142. unsigned int ai2_wordsize;
  143. volatile WORDTYPE *zero;
  144. volatile WORDTYPE *one;
  145. volatile WORDTYPE *data;
  146. volatile WORDTYPE *status;
  147. } promice_t;
  148. /* *********************************************************************
  149. * promice_probe(drv,probe_a,probe_b,probe_ptr)
  150. *
  151. * Device "Probe" routine. This routine creates the soft
  152. * context for the device and calls the attach routine.
  153. *
  154. * Input parameters:
  155. * drv - driver structure
  156. * probe_a,probe_b,probe_ptr - probe args
  157. *
  158. * Return value:
  159. * nothing
  160. ********************************************************************* */
  161. static void promice_probe(cfe_driver_t *drv,
  162. unsigned long probe_a,
  163. unsigned long probe_b,
  164. void *probe_ptr)
  165. {
  166. promice_t *softc;
  167. char descr[80];
  168. /*
  169. * probe_a is the address in the ROM of the AI2 interface
  170. * on the PromICE.
  171. * probe_b is the word size (1,2,4)
  172. */
  173. softc = (promice_t *) KMALLOC(sizeof(promice_t),0);
  174. if (softc) {
  175. softc->ai2_addr = probe_a;
  176. if (probe_b) softc->ai2_wordsize = probe_b;
  177. else softc->ai2_wordsize = WORDSIZE;
  178. xsprintf(descr,"%s at 0x%X",drv->drv_description,probe_a);
  179. cfe_attach(drv,softc,NULL,descr);
  180. }
  181. }
  182. /* *********************************************************************
  183. * promice_open(ctx)
  184. *
  185. * Open the device
  186. *
  187. * Input parameters:
  188. * ctx - device context
  189. *
  190. * Return value:
  191. * 0 if ok, else error code
  192. ********************************************************************* */
  193. static int promice_open(cfe_devctx_t *ctx)
  194. {
  195. promice_t *softc = ctx->dev_softc;
  196. uint8_t dummy;
  197. softc->zero = (volatile WORDTYPE *)
  198. UNCADDR(softc->ai2_addr + (ZERO_OFFSET*softc->ai2_wordsize));
  199. softc->one = (volatile WORDTYPE *)
  200. UNCADDR(softc->ai2_addr + (ONE_OFFSET*softc->ai2_wordsize));
  201. softc->data = (volatile WORDTYPE *)
  202. UNCADDR(softc->ai2_addr + (DATA_OFFSET*softc->ai2_wordsize));
  203. softc->status = (volatile WORDTYPE *)
  204. UNCADDR(softc->ai2_addr + (STATUS_OFFSET*softc->ai2_wordsize));
  205. /*
  206. * Wait for bit 3 to clear so we know the interface is ready.
  207. */
  208. while (*(softc->status) == 0xCC) ; /* NULL LOOP */
  209. /*
  210. * a dummy read is required to clear out the interface.
  211. */
  212. dummy = *(softc->data);
  213. return 0;
  214. }
  215. /* *********************************************************************
  216. * promice_read(ctx,buffer)
  217. *
  218. * Read data from the device
  219. *
  220. * Input parameters:
  221. * ctx - device context
  222. * buffer - I/O buffer descriptor
  223. *
  224. * Return value:
  225. * number of bytes transferred, or <0 if error
  226. ********************************************************************* */
  227. static int promice_read(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
  228. {
  229. promice_t *softc = ctx->dev_softc;
  230. unsigned char *bptr;
  231. int blen;
  232. bptr = buffer->buf_ptr;
  233. blen = buffer->buf_length;
  234. while ((blen > 0) && (*(softc->status) & HDA)) {
  235. *bptr++ = *(softc->data);
  236. blen--;
  237. }
  238. buffer->buf_retlen = buffer->buf_length - blen;
  239. return 0;
  240. }
  241. /* *********************************************************************
  242. * promice_inpstat(ctx,inpstat)
  243. *
  244. * Determine if read data is available
  245. *
  246. * Input parameters:
  247. * ctx - device context
  248. * inpstat - input status structure
  249. *
  250. * Return value:
  251. * 0
  252. ********************************************************************* */
  253. static int promice_inpstat(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat)
  254. {
  255. promice_t *softc = ctx->dev_softc;
  256. inpstat->inp_status = (*(softc->status) & HDA) ? 1 : 0;
  257. return 0;
  258. }
  259. /* *********************************************************************
  260. * promice_write(ctx,buffer)
  261. *
  262. * Write data to the device
  263. *
  264. * Input parameters:
  265. * ctx - device context
  266. * buffer - I/O buffer descriptor
  267. *
  268. * Return value:
  269. * number of bytes transferred, or <0 if error
  270. ********************************************************************* */
  271. static int promice_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
  272. {
  273. promice_t *softc = ctx->dev_softc;
  274. unsigned char *bptr;
  275. int blen;
  276. uint8_t data;
  277. #ifndef _AIDIRT_
  278. uint8_t dummy;
  279. int count;
  280. #endif
  281. bptr = buffer->buf_ptr;
  282. blen = buffer->buf_length;
  283. /*
  284. * The AI2 interface requires you to transmit characters
  285. * one bit at a time. First a '1' start bit,
  286. * then 8 data bits (lsb first) then another '1' stop bit.
  287. *
  288. * Just reference the right memory location to transmit a bit.
  289. */
  290. while ((blen > 0) && !(*(softc->status) & TDA)) {
  291. #ifdef _AIDIRT_
  292. data = *bptr++;
  293. *(softc->zero) = data;
  294. #else
  295. dummy = *(softc->one); /* send start bit */
  296. data = *bptr++;
  297. for (count = 0; count < 8; count++) {
  298. if (data & 1) dummy = *(softc->one);
  299. else dummy = *(softc->zero);
  300. data >>= 1; /* shift in next bit */
  301. }
  302. dummy = *(softc->one); /* send stop bit */
  303. #endif
  304. blen--;
  305. }
  306. buffer->buf_retlen = buffer->buf_length - blen;
  307. return 0;
  308. }
  309. /* *********************************************************************
  310. * promice_ioctl(ctx,buffer)
  311. *
  312. * Do I/O control operations
  313. *
  314. * Input parameters:
  315. * ctx - device context
  316. * buffer - I/O control args
  317. *
  318. * Return value:
  319. * 0 if ok
  320. * else error code
  321. ********************************************************************* */
  322. static int promice_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
  323. {
  324. return -1;
  325. }
  326. /* *********************************************************************
  327. * promice_close(ctx)
  328. *
  329. * Close the device.
  330. *
  331. * Input parameters:
  332. * ctx - device context
  333. *
  334. * Return value:
  335. * 0
  336. ********************************************************************* */
  337. static int promice_close(cfe_devctx_t *ctx)
  338. {
  339. return 0;
  340. }