lcd.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Driver for the LCD display on the Tensilica XTFPGA board family.
  3. * http://www.mytechcorp.com/cfdata/productFile/File1/MOC-16216B-B-A0A04.pdf
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. *
  9. * Copyright (C) 2001, 2006 Tensilica Inc.
  10. * Copyright (C) 2015 Cadence Design Systems Inc.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <platform/hardware.h>
  16. #include <platform/lcd.h>
  17. /* LCD instruction and data addresses. */
  18. #define LCD_INSTR_ADDR ((char *)IOADDR(CONFIG_XTFPGA_LCD_BASE_ADDR))
  19. #define LCD_DATA_ADDR (LCD_INSTR_ADDR + 4)
  20. #define LCD_CLEAR 0x1
  21. #define LCD_DISPLAY_ON 0xc
  22. /* 8bit and 2 lines display */
  23. #define LCD_DISPLAY_MODE8BIT 0x38
  24. #define LCD_DISPLAY_MODE4BIT 0x28
  25. #define LCD_DISPLAY_POS 0x80
  26. #define LCD_SHIFT_LEFT 0x18
  27. #define LCD_SHIFT_RIGHT 0x1c
  28. static void lcd_put_byte(u8 *addr, u8 data)
  29. {
  30. #ifdef CONFIG_XTFPGA_LCD_8BIT_ACCESS
  31. WRITE_ONCE(*addr, data);
  32. #else
  33. WRITE_ONCE(*addr, data & 0xf0);
  34. WRITE_ONCE(*addr, (data << 4) & 0xf0);
  35. #endif
  36. }
  37. static int __init lcd_init(void)
  38. {
  39. WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE8BIT);
  40. mdelay(5);
  41. WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE8BIT);
  42. udelay(200);
  43. WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE8BIT);
  44. udelay(50);
  45. #ifndef CONFIG_XTFPGA_LCD_8BIT_ACCESS
  46. WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE4BIT);
  47. udelay(50);
  48. lcd_put_byte(LCD_INSTR_ADDR, LCD_DISPLAY_MODE4BIT);
  49. udelay(50);
  50. #endif
  51. lcd_put_byte(LCD_INSTR_ADDR, LCD_DISPLAY_ON);
  52. udelay(50);
  53. lcd_put_byte(LCD_INSTR_ADDR, LCD_CLEAR);
  54. mdelay(10);
  55. lcd_disp_at_pos("XTENSA LINUX", 0);
  56. return 0;
  57. }
  58. void lcd_disp_at_pos(char *str, unsigned char pos)
  59. {
  60. lcd_put_byte(LCD_INSTR_ADDR, LCD_DISPLAY_POS | pos);
  61. udelay(100);
  62. while (*str != 0) {
  63. lcd_put_byte(LCD_DATA_ADDR, *str);
  64. udelay(200);
  65. str++;
  66. }
  67. }
  68. void lcd_shiftleft(void)
  69. {
  70. lcd_put_byte(LCD_INSTR_ADDR, LCD_SHIFT_LEFT);
  71. udelay(50);
  72. }
  73. void lcd_shiftright(void)
  74. {
  75. lcd_put_byte(LCD_INSTR_ADDR, LCD_SHIFT_RIGHT);
  76. udelay(50);
  77. }
  78. arch_initcall(lcd_init);