ans-lcd.c 3.8 KB

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