miropcm20-rds.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* MiroSOUND PCM20 radio rds interface driver
  2. * (c) 2001 Robert Siemer <Robert.Siemer@gmx.de>
  3. * Thanks to Fred Seidel. See miropcm20-rds-core.c for further information.
  4. */
  5. /* Revision history:
  6. *
  7. * 2001-04-18 Robert Siemer <Robert.Siemer@gmx.de>
  8. * separate file for user interface driver
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/fs.h>
  15. #include <linux/miscdevice.h>
  16. #include <linux/delay.h>
  17. #include <asm/uaccess.h>
  18. #include "miropcm20-rds-core.h"
  19. static char * text_buffer;
  20. static int rds_users;
  21. static int rds_f_open(struct inode *in, struct file *fi)
  22. {
  23. if (rds_users)
  24. return -EBUSY;
  25. lock_kernel();
  26. rds_users++;
  27. if ((text_buffer=kmalloc(66, GFP_KERNEL)) == 0) {
  28. rds_users--;
  29. printk(KERN_NOTICE "aci-rds: Out of memory by open()...\n");
  30. unlock_kernel();
  31. return -ENOMEM;
  32. }
  33. unlock_kernel();
  34. return 0;
  35. }
  36. static int rds_f_release(struct inode *in, struct file *fi)
  37. {
  38. kfree(text_buffer);
  39. rds_users--;
  40. return 0;
  41. }
  42. static void print_matrix(char *ch, char out[])
  43. {
  44. int j;
  45. for (j=7; j>=0; j--) {
  46. out[7-j] = ((*ch >> j) & 0x1) + '0';
  47. }
  48. }
  49. static ssize_t rds_f_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
  50. {
  51. // i = sprintf(text_buffer, "length: %d, offset: %d\n", length, *offset);
  52. char c;
  53. char bits[8];
  54. msleep(2000);
  55. aci_rds_cmd(RDS_STATUS, &c, 1);
  56. print_matrix(&c, bits);
  57. if (copy_to_user(buffer, bits, 8))
  58. return -EFAULT;
  59. /* if ((c >> 3) & 1) {
  60. aci_rds_cmd(RDS_STATIONNAME, text_buffer+1, 8);
  61. text_buffer[0] = ' ' ;
  62. text_buffer[9] = '\n';
  63. return copy_to_user(buffer+8, text_buffer, 10) ? -EFAULT: 18;
  64. }
  65. */
  66. /* if ((c >> 6) & 1) {
  67. aci_rds_cmd(RDS_PTYTATP, &c, 1);
  68. if ( c & 1)
  69. sprintf(text_buffer, " M");
  70. else
  71. sprintf(text_buffer, " S");
  72. if ((c >> 1) & 1)
  73. sprintf(text_buffer+2, " TA");
  74. else
  75. sprintf(text_buffer+2, " --");
  76. if ((c >> 7) & 1)
  77. sprintf(text_buffer+5, " TP");
  78. else
  79. sprintf(text_buffer+5, " --");
  80. sprintf(text_buffer+8, " %2d\n", (c >> 2) & 0x1f);
  81. return copy_to_user(buffer+8, text_buffer, 12) ? -EFAULT: 20;
  82. }
  83. */
  84. if ((c >> 4) & 1) {
  85. aci_rds_cmd(RDS_TEXT, text_buffer, 65);
  86. text_buffer[0] = ' ' ;
  87. text_buffer[65] = '\n';
  88. return copy_to_user(buffer+8, text_buffer,66) ? -EFAULT : 66+8;
  89. } else {
  90. put_user('\n', buffer+8);
  91. return 9;
  92. }
  93. }
  94. static const struct file_operations rds_fops = {
  95. .owner = THIS_MODULE,
  96. .read = rds_f_read,
  97. .open = rds_f_open,
  98. .release = rds_f_release
  99. };
  100. static struct miscdevice rds_miscdev = {
  101. .minor = MISC_DYNAMIC_MINOR,
  102. .name = "radiotext",
  103. .fops = &rds_fops,
  104. };
  105. static int __init miropcm20_rds_init(void)
  106. {
  107. return misc_register(&rds_miscdev);
  108. }
  109. static void __exit miropcm20_rds_cleanup(void)
  110. {
  111. misc_deregister(&rds_miscdev);
  112. }
  113. module_init(miropcm20_rds_init);
  114. module_exit(miropcm20_rds_cleanup);
  115. MODULE_LICENSE("GPL");