lcd.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * See file CREDITS for list of people who contributed to this
  3. * project.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <config.h>
  21. #include <common.h>
  22. #include <command.h>
  23. #include <asm/io.h>
  24. #include <asm/ppc4xx-gpio.h>
  25. #define LCD_CMD_ADDR 0x50100002
  26. #define LCD_DATA_ADDR 0x50100003
  27. #define LCD_BLK_CTRL CPLD_REG1_ADDR
  28. static char *amcc_logo = "AMCC 405EP TAIHU EVALUATION KIT";
  29. static int addr_flag = 0x80;
  30. static void lcd_bl_ctrl(char val)
  31. {
  32. out_8((u8 *) LCD_BLK_CTRL, in_8((u8 *) LCD_BLK_CTRL) | val);
  33. }
  34. static void lcd_putc(int val)
  35. {
  36. int i = 100;
  37. char addr;
  38. while (i--) {
  39. if ((in_8((u8 *) LCD_CMD_ADDR) & 0x80) != 0x80) { /*BF = 1 ?*/
  40. udelay(50);
  41. break;
  42. }
  43. udelay(50);
  44. }
  45. if (in_8((u8 *) LCD_CMD_ADDR) & 0x80) {
  46. printf("LCD is busy\n");
  47. return;
  48. }
  49. addr = in_8((u8 *) LCD_CMD_ADDR);
  50. udelay(50);
  51. if ((addr != 0) && (addr % 0x10 == 0)) {
  52. addr_flag ^= 0x40;
  53. out_8((u8 *) LCD_CMD_ADDR, addr_flag);
  54. }
  55. udelay(50);
  56. out_8((u8 *) LCD_DATA_ADDR, val);
  57. udelay(50);
  58. }
  59. static void lcd_puts(char *s)
  60. {
  61. char *p = s;
  62. int i = 100;
  63. while (i--) {
  64. if ((in_8((u8 *) LCD_CMD_ADDR) & 0x80) != 0x80) { /*BF = 1 ?*/
  65. udelay(50);
  66. break;
  67. }
  68. udelay(50);
  69. }
  70. if (in_8((u8 *) LCD_CMD_ADDR) & 0x80) {
  71. printf("LCD is busy\n");
  72. return;
  73. }
  74. while (*p)
  75. lcd_putc(*p++);
  76. }
  77. static void lcd_put_logo(void)
  78. {
  79. int i = 100;
  80. char *p = amcc_logo;
  81. while (i--) {
  82. if ((in_8((u8 *) LCD_CMD_ADDR) & 0x80) != 0x80) { /*BF = 1 ?*/
  83. udelay(50);
  84. break;
  85. }
  86. udelay(50);
  87. }
  88. if (in_8((u8 *) LCD_CMD_ADDR) & 0x80) {
  89. printf("LCD is busy\n");
  90. return;
  91. }
  92. out_8((u8 *) LCD_CMD_ADDR, 0x80);
  93. while (*p)
  94. lcd_putc(*p++);
  95. }
  96. int lcd_init(void)
  97. {
  98. puts("LCD: ");
  99. out_8((u8 *) LCD_CMD_ADDR, 0x38); /* set function:8-bit,2-line,5x7 font type */
  100. udelay(50);
  101. out_8((u8 *) LCD_CMD_ADDR, 0x0f); /* set display on,cursor on,blink on */
  102. udelay(50);
  103. out_8((u8 *) LCD_CMD_ADDR, 0x01); /* display clear */
  104. udelay(2000);
  105. out_8((u8 *) LCD_CMD_ADDR, 0x06); /* set entry */
  106. udelay(50);
  107. lcd_bl_ctrl(0x02); /* set backlight on */
  108. lcd_put_logo();
  109. puts("ready\n");
  110. return 0;
  111. }
  112. static int do_lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  113. {
  114. out_8((u8 *) LCD_CMD_ADDR, 0x01);
  115. udelay(2000);
  116. return 0;
  117. }
  118. static int do_lcd_puts (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  119. {
  120. if (argc < 2)
  121. return cmd_usage(cmdtp);
  122. lcd_puts(argv[1]);
  123. return 0;
  124. }
  125. static int do_lcd_putc (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  126. {
  127. if (argc < 2)
  128. return cmd_usage(cmdtp);
  129. lcd_putc((char)argv[1][0]);
  130. return 0;
  131. }
  132. static int do_lcd_cur (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  133. {
  134. ulong count;
  135. ulong dir;
  136. char cur_addr;
  137. if (argc < 3)
  138. return cmd_usage(cmdtp);
  139. count = simple_strtoul(argv[1], NULL, 16);
  140. if (count > 31) {
  141. printf("unable to shift > 0x20\n");
  142. count = 0;
  143. }
  144. dir = simple_strtoul(argv[2], NULL, 16);
  145. cur_addr = in_8((u8 *) LCD_CMD_ADDR);
  146. udelay(50);
  147. if (dir == 0x0) {
  148. if (addr_flag == 0x80) {
  149. if (count >= (cur_addr & 0xf)) {
  150. out_8((u8 *) LCD_CMD_ADDR, 0x80);
  151. udelay(50);
  152. count = 0;
  153. }
  154. } else {
  155. if (count >= ((cur_addr & 0x0f) + 0x0f)) {
  156. out_8((u8 *) LCD_CMD_ADDR, 0x80);
  157. addr_flag = 0x80;
  158. udelay(50);
  159. count = 0x0;
  160. } else if (count >= ( cur_addr & 0xf)) {
  161. count -= cur_addr & 0xf ;
  162. out_8((u8 *) LCD_CMD_ADDR, 0x80 | 0xf);
  163. addr_flag = 0x80;
  164. udelay(50);
  165. }
  166. }
  167. } else {
  168. if (addr_flag == 0x80) {
  169. if (count >= (0x1f - (cur_addr & 0xf))) {
  170. count = 0x0;
  171. addr_flag = 0xc0;
  172. out_8((u8 *) LCD_CMD_ADDR, 0xc0 | 0xf);
  173. udelay(50);
  174. } else if ((count + (cur_addr & 0xf ))>= 0x0f) {
  175. count = count + (cur_addr & 0xf) - 0x0f;
  176. addr_flag = 0xc0;
  177. out_8((u8 *) LCD_CMD_ADDR, 0xc0);
  178. udelay(50);
  179. }
  180. } else if ((count + (cur_addr & 0xf )) >= 0x0f) {
  181. count = 0x0;
  182. out_8((u8 *) LCD_CMD_ADDR, 0xC0 | 0x0F);
  183. udelay(50);
  184. }
  185. }
  186. while (count--) {
  187. if (dir == 0)
  188. out_8((u8 *) LCD_CMD_ADDR, 0x10);
  189. else
  190. out_8((u8 *) LCD_CMD_ADDR, 0x14);
  191. udelay(50);
  192. }
  193. return 0;
  194. }
  195. U_BOOT_CMD(
  196. lcd_cls, 1, 1, do_lcd_clear,
  197. "lcd clear display",
  198. ""
  199. );
  200. U_BOOT_CMD(
  201. lcd_puts, 2, 1, do_lcd_puts,
  202. "display string on lcd",
  203. "<string> - <string> to be displayed"
  204. );
  205. U_BOOT_CMD(
  206. lcd_putc, 2, 1, do_lcd_putc,
  207. "display char on lcd",
  208. "<char> - <char> to be displayed"
  209. );
  210. U_BOOT_CMD(
  211. lcd_cur, 3, 1, do_lcd_cur,
  212. "shift cursor on lcd",
  213. "<count> <dir> - shift cursor on lcd <count> times, direction is <dir> \n"
  214. " <count> - 0..31\n"
  215. " <dir> - 0=backward 1=forward"
  216. );