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