ans-lcd.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/module.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/io.h>
  16. #include "ans-lcd.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. static DEFINE_MUTEX(anslcd_mutex);
  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. mutex_lock(&anslcd_mutex);
  58. for ( i = *ppos; count > 0; ++i, ++p, --count )
  59. {
  60. char c;
  61. __get_user(c, p);
  62. anslcd_write_byte_data( c );
  63. }
  64. mutex_unlock(&anslcd_mutex);
  65. *ppos = i;
  66. return p - buf;
  67. }
  68. static long
  69. anslcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  70. {
  71. char ch, __user *temp;
  72. long ret = 0;
  73. #ifdef DEBUG
  74. printk(KERN_DEBUG "LCD: ioctl(%d,%d)\n",cmd,arg);
  75. #endif
  76. mutex_lock(&anslcd_mutex);
  77. switch ( cmd )
  78. {
  79. case ANSLCD_CLEAR:
  80. anslcd_write_byte_ctrl ( 0x38 );
  81. anslcd_write_byte_ctrl ( 0x0f );
  82. anslcd_write_byte_ctrl ( 0x06 );
  83. anslcd_write_byte_ctrl ( 0x01 );
  84. anslcd_write_byte_ctrl ( 0x02 );
  85. break;
  86. case ANSLCD_SENDCTRL:
  87. temp = (char __user *) arg;
  88. __get_user(ch, temp);
  89. for (; ch; temp++) { /* FIXME: This is ugly, but should work, as a \0 byte is not a valid command code */
  90. anslcd_write_byte_ctrl ( ch );
  91. __get_user(ch, temp);
  92. }
  93. break;
  94. case ANSLCD_SETSHORTDELAY:
  95. if (!capable(CAP_SYS_ADMIN))
  96. ret =-EACCES;
  97. else
  98. anslcd_short_delay=arg;
  99. break;
  100. case ANSLCD_SETLONGDELAY:
  101. if (!capable(CAP_SYS_ADMIN))
  102. ret = -EACCES;
  103. else
  104. anslcd_long_delay=arg;
  105. break;
  106. default:
  107. ret = -EINVAL;
  108. }
  109. mutex_unlock(&anslcd_mutex);
  110. return ret;
  111. }
  112. static int
  113. anslcd_open( struct inode * inode, struct file * file )
  114. {
  115. return 0;
  116. }
  117. const struct file_operations anslcd_fops = {
  118. .write = anslcd_write,
  119. .unlocked_ioctl = anslcd_ioctl,
  120. .open = anslcd_open,
  121. .llseek = default_llseek,
  122. };
  123. static struct miscdevice anslcd_dev = {
  124. ANSLCD_MINOR,
  125. "anslcd",
  126. &anslcd_fops
  127. };
  128. const char anslcd_logo[] = "********************" /* Line #1 */
  129. "* LINUX! *" /* Line #3 */
  130. "* Welcome to *" /* Line #2 */
  131. "********************"; /* Line #4 */
  132. static int __init
  133. anslcd_init(void)
  134. {
  135. int a;
  136. int retval;
  137. struct device_node* node;
  138. node = of_find_node_by_name(NULL, "lcd");
  139. if (!node || !node->parent || strcmp(node->parent->name, "gc")) {
  140. of_node_put(node);
  141. return -ENODEV;
  142. }
  143. of_node_put(node);
  144. anslcd_ptr = ioremap(ANSLCD_ADDR, 0x20);
  145. retval = misc_register(&anslcd_dev);
  146. if(retval < 0){
  147. printk(KERN_INFO "LCD: misc_register failed\n");
  148. iounmap(anslcd_ptr);
  149. return retval;
  150. }
  151. #ifdef DEBUG
  152. printk(KERN_DEBUG "LCD: init\n");
  153. #endif
  154. mutex_lock(&anslcd_mutex);
  155. anslcd_write_byte_ctrl ( 0x38 );
  156. anslcd_write_byte_ctrl ( 0x0c );
  157. anslcd_write_byte_ctrl ( 0x06 );
  158. anslcd_write_byte_ctrl ( 0x01 );
  159. anslcd_write_byte_ctrl ( 0x02 );
  160. for(a=0;a<80;a++) {
  161. anslcd_write_byte_data(anslcd_logo[a]);
  162. }
  163. mutex_unlock(&anslcd_mutex);
  164. return 0;
  165. }
  166. static void __exit
  167. anslcd_exit(void)
  168. {
  169. misc_deregister(&anslcd_dev);
  170. iounmap(anslcd_ptr);
  171. }
  172. module_init(anslcd_init);
  173. module_exit(anslcd_exit);