miropcm20-rds.c 2.8 KB

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