ans-lcd.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * /dev/lcd driver for Apple Network Servers.
  3. */
  4. #include <linux/types.h>
  5. #include <linux/errno.h>
  6. #include <linux/kernel.h>
  7. #include <linux/miscdevice.h>
  8. #include <linux/fcntl.h>
  9. #include <linux/init.h>
  10. #include <linux/delay.h>
  11. #include <linux/fs.h>
  12. #include <asm/uaccess.h>
  13. #include <asm/sections.h>
  14. #include <asm/prom.h>
  15. #include <asm/ans-lcd.h>
  16. #include <asm/io.h>
  17. #define ANSLCD_ADDR 0xf301c000
  18. #define ANSLCD_CTRL_IX 0x00
  19. #define ANSLCD_DATA_IX 0x10
  20. static unsigned long anslcd_short_delay = 80;
  21. static unsigned long anslcd_long_delay = 3280;
  22. static volatile unsigned char __iomem *anslcd_ptr;
  23. #undef DEBUG
  24. static void
  25. anslcd_write_byte_ctrl ( unsigned char c )
  26. {
  27. #ifdef DEBUG
  28. printk(KERN_DEBUG "LCD: CTRL byte: %02x\n",c);
  29. #endif
  30. out_8(anslcd_ptr + ANSLCD_CTRL_IX, c);
  31. switch(c) {
  32. case 1:
  33. case 2:
  34. case 3:
  35. udelay(anslcd_long_delay); break;
  36. default: udelay(anslcd_short_delay);
  37. }
  38. }
  39. static void
  40. anslcd_write_byte_data ( unsigned char c )
  41. {
  42. out_8(anslcd_ptr + ANSLCD_DATA_IX, c);
  43. udelay(anslcd_short_delay);
  44. }
  45. static ssize_t
  46. anslcd_write( struct file * file, const char __user * buf,
  47. size_t count, loff_t *ppos )
  48. {
  49. const char __user *p = buf;
  50. int i;
  51. #ifdef DEBUG
  52. printk(KERN_DEBUG "LCD: write\n");
  53. #endif
  54. if (!access_ok(VERIFY_READ, buf, count))
  55. return -EFAULT;
  56. for ( i = *ppos; count > 0; ++i, ++p, --count )
  57. {
  58. char c;
  59. __get_user(c, p);
  60. anslcd_write_byte_data( c );
  61. }
  62. *ppos = i;
  63. return p - buf;
  64. }
  65. static int
  66. anslcd_ioctl( struct inode * inode, struct file * file,
  67. unsigned int cmd, unsigned long arg )
  68. {
  69. char ch, __user *temp;
  70. #ifdef DEBUG
  71. printk(KERN_DEBUG "LCD: ioctl(%d,%d)\n",cmd,arg);
  72. #endif
  73. switch ( cmd )
  74. {
  75. case ANSLCD_CLEAR:
  76. anslcd_write_byte_ctrl ( 0x38 );
  77. anslcd_write_byte_ctrl ( 0x0f );
  78. anslcd_write_byte_ctrl ( 0x06 );
  79. anslcd_write_byte_ctrl ( 0x01 );
  80. anslcd_write_byte_ctrl ( 0x02 );
  81. return 0;
  82. case ANSLCD_SENDCTRL:
  83. temp = (char __user *) arg;
  84. __get_user(ch, temp);
  85. for (; ch; temp++) { /* FIXME: This is ugly, but should work, as a \0 byte is not a valid command code */
  86. anslcd_write_byte_ctrl ( ch );
  87. __get_user(ch, temp);
  88. }
  89. return 0;
  90. case ANSLCD_SETSHORTDELAY:
  91. if (!capable(CAP_SYS_ADMIN))
  92. return -EACCES;
  93. anslcd_short_delay=arg;
  94. return 0;
  95. case ANSLCD_SETLONGDELAY:
  96. if (!capable(CAP_SYS_ADMIN))
  97. return -EACCES;
  98. anslcd_long_delay=arg;
  99. return 0;
  100. default:
  101. return -EINVAL;
  102. }
  103. }
  104. static int
  105. anslcd_open( struct inode * inode, struct file * file )
  106. {
  107. return 0;
  108. }
  109. struct file_operations anslcd_fops = {
  110. .write = anslcd_write,
  111. .ioctl = anslcd_ioctl,
  112. .open = anslcd_open,
  113. };
  114. static struct miscdevice anslcd_dev = {
  115. ANSLCD_MINOR,
  116. "anslcd",
  117. &anslcd_fops
  118. };
  119. const char anslcd_logo[] = "********************" /* Line #1 */
  120. "* LINUX! *" /* Line #3 */
  121. "* Welcome to *" /* Line #2 */
  122. "********************"; /* Line #4 */
  123. static int __init
  124. anslcd_init(void)
  125. {
  126. int a;
  127. int retval;
  128. struct device_node* node;
  129. node = find_devices("lcd");
  130. if (!node || !node->parent)
  131. return -ENODEV;
  132. if (strcmp(node->parent->name, "gc"))
  133. return -ENODEV;
  134. anslcd_ptr = ioremap(ANSLCD_ADDR, 0x20);
  135. retval = misc_register(&anslcd_dev);
  136. if(retval < 0){
  137. printk(KERN_INFO "LCD: misc_register failed\n");
  138. iounmap(anslcd_ptr);
  139. return retval;
  140. }
  141. #ifdef DEBUG
  142. printk(KERN_DEBUG "LCD: init\n");
  143. #endif
  144. anslcd_write_byte_ctrl ( 0x38 );
  145. anslcd_write_byte_ctrl ( 0x0c );
  146. anslcd_write_byte_ctrl ( 0x06 );
  147. anslcd_write_byte_ctrl ( 0x01 );
  148. anslcd_write_byte_ctrl ( 0x02 );
  149. for(a=0;a<80;a++) {
  150. anslcd_write_byte_data(anslcd_logo[a]);
  151. }
  152. return 0;
  153. }
  154. static void __exit
  155. anslcd_exit(void)
  156. {
  157. misc_deregister(&anslcd_dev);
  158. iounmap(anslcd_ptr);
  159. }
  160. module_init(anslcd_init);
  161. module_exit(anslcd_exit);