mpc52xx-psc.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * MPC5200 PSC serial console support.
  3. *
  4. * Author: Grant Likely <grant.likely@secretlab.ca>
  5. *
  6. * Copyright (c) 2007 Secret Lab Technologies Ltd.
  7. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  8. *
  9. * It is assumed that the firmware (or the platform file) has already set
  10. * up the port.
  11. */
  12. #include "types.h"
  13. #include "io.h"
  14. #include "ops.h"
  15. /* Programmable Serial Controller (PSC) status register bits */
  16. #define MPC52xx_PSC_SR 0x04
  17. #define MPC52xx_PSC_SR_RXRDY 0x0100
  18. #define MPC52xx_PSC_SR_RXFULL 0x0200
  19. #define MPC52xx_PSC_SR_TXRDY 0x0400
  20. #define MPC52xx_PSC_SR_TXEMP 0x0800
  21. #define MPC52xx_PSC_BUFFER 0x0C
  22. static void *psc;
  23. static int psc_open(void)
  24. {
  25. /* Assume the firmware has already configured the PSC into
  26. * uart mode */
  27. return 0;
  28. }
  29. static void psc_putc(unsigned char c)
  30. {
  31. while (!(in_be16(psc + MPC52xx_PSC_SR) & MPC52xx_PSC_SR_TXRDY)) ;
  32. out_8(psc + MPC52xx_PSC_BUFFER, c);
  33. }
  34. static unsigned char psc_tstc(void)
  35. {
  36. return (in_be16(psc + MPC52xx_PSC_SR) & MPC52xx_PSC_SR_RXRDY) != 0;
  37. }
  38. static unsigned char psc_getc(void)
  39. {
  40. while (!(in_be16(psc + MPC52xx_PSC_SR) & MPC52xx_PSC_SR_RXRDY)) ;
  41. return in_8(psc + MPC52xx_PSC_BUFFER);
  42. }
  43. int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp)
  44. {
  45. /* Get the base address of the psc registers */
  46. if (dt_get_virtual_reg(devp, &psc, 1) < 1)
  47. return -1;
  48. scdp->open = psc_open;
  49. scdp->putc = psc_putc;
  50. scdp->getc = psc_getc;
  51. scdp->tstc = psc_tstc;
  52. return 0;
  53. }