lcd.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/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 *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 *argv[])
  119. {
  120. if (argc < 2) {
  121. cmd_usage(cmdtp);
  122. return 1;
  123. }
  124. lcd_puts(argv[1]);
  125. return 0;
  126. }
  127. static int do_lcd_putc (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  128. {
  129. if (argc < 2) {
  130. cmd_usage(cmdtp);
  131. return 1;
  132. }
  133. lcd_putc((char)argv[1][0]);
  134. return 0;
  135. }
  136. static int do_lcd_cur (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  137. {
  138. ulong count;
  139. ulong dir;
  140. char cur_addr;
  141. if (argc < 3) {
  142. cmd_usage(cmdtp);
  143. return 1;
  144. }
  145. count = simple_strtoul(argv[1], NULL, 16);
  146. if (count > 31) {
  147. printf("unable to shift > 0x20\n");
  148. count = 0;
  149. }
  150. dir = simple_strtoul(argv[2], NULL, 16);
  151. cur_addr = in_8((u8 *) LCD_CMD_ADDR);
  152. udelay(50);
  153. if (dir == 0x0) {
  154. if (addr_flag == 0x80) {
  155. if (count >= (cur_addr & 0xf)) {
  156. out_8((u8 *) LCD_CMD_ADDR, 0x80);
  157. udelay(50);
  158. count = 0;
  159. }
  160. } else {
  161. if (count >= ((cur_addr & 0x0f) + 0x0f)) {
  162. out_8((u8 *) LCD_CMD_ADDR, 0x80);
  163. addr_flag = 0x80;
  164. udelay(50);
  165. count = 0x0;
  166. } else if (count >= ( cur_addr & 0xf)) {
  167. count -= cur_addr & 0xf ;
  168. out_8((u8 *) LCD_CMD_ADDR, 0x80 | 0xf);
  169. addr_flag = 0x80;
  170. udelay(50);
  171. }
  172. }
  173. } else {
  174. if (addr_flag == 0x80) {
  175. if (count >= (0x1f - (cur_addr & 0xf))) {
  176. count = 0x0;
  177. addr_flag = 0xc0;
  178. out_8((u8 *) LCD_CMD_ADDR, 0xc0 | 0xf);
  179. udelay(50);
  180. } else if ((count + (cur_addr & 0xf ))>= 0x0f) {
  181. count = count + (cur_addr & 0xf) - 0x0f;
  182. addr_flag = 0xc0;
  183. out_8((u8 *) LCD_CMD_ADDR, 0xc0);
  184. udelay(50);
  185. }
  186. } else if ((count + (cur_addr & 0xf )) >= 0x0f) {
  187. count = 0x0;
  188. out_8((u8 *) LCD_CMD_ADDR, 0xC0 | 0x0F);
  189. udelay(50);
  190. }
  191. }
  192. while (count--) {
  193. if (dir == 0)
  194. out_8((u8 *) LCD_CMD_ADDR, 0x10);
  195. else
  196. out_8((u8 *) LCD_CMD_ADDR, 0x14);
  197. udelay(50);
  198. }
  199. return 0;
  200. }
  201. U_BOOT_CMD(
  202. lcd_cls, 1, 1, do_lcd_clear,
  203. "lcd clear display",
  204. ""
  205. );
  206. U_BOOT_CMD(
  207. lcd_puts, 2, 1, do_lcd_puts,
  208. "display string on lcd",
  209. "<string> - <string> to be displayed"
  210. );
  211. U_BOOT_CMD(
  212. lcd_putc, 2, 1, do_lcd_putc,
  213. "display char on lcd",
  214. "<char> - <char> to be displayed"
  215. );
  216. U_BOOT_CMD(
  217. lcd_cur, 3, 1, do_lcd_cur,
  218. "shift cursor on lcd",
  219. "<count> <dir> - shift cursor on lcd <count> times, direction is <dir> \n"
  220. " <count> - 0..31\n"
  221. " <dir> - 0=backward 1=forward"
  222. );