mpc52xx-psc.c 1.5 KB

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