PageRenderTime 199ms CodeModel.GetById 43ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/media/radio/miropcm20-rds.c

https://bitbucket.org/abioy/linux
C | 133 lines | 77 code | 21 blank | 35 comment | 7 complexity | f66b54d71832fdd6302822df00ed20fd MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0
  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 <asm/uaccess.h>
  16. #include "miropcm20-rds-core.h"
  17. static char * text_buffer;
  18. static int rds_users = 0;
  19. static int rds_f_open(struct inode *in, struct file *fi)
  20. {
  21. if (rds_users)
  22. return -EBUSY;
  23. rds_users++;
  24. if ((text_buffer=kmalloc(66, GFP_KERNEL)) == 0) {
  25. rds_users--;
  26. printk(KERN_NOTICE "aci-rds: Out of memory by open()...\n");
  27. return -ENOMEM;
  28. }
  29. return 0;
  30. }
  31. static int rds_f_release(struct inode *in, struct file *fi)
  32. {
  33. kfree(text_buffer);
  34. rds_users--;
  35. return 0;
  36. }
  37. static void print_matrix(char *ch, char out[])
  38. {
  39. int j;
  40. for (j=7; j>=0; j--) {
  41. out[7-j] = ((*ch >> j) & 0x1) + '0';
  42. }
  43. }
  44. static ssize_t rds_f_read(struct file *file, char *buffer, size_t length, loff_t *offset)
  45. {
  46. // i = sprintf(text_buffer, "length: %d, offset: %d\n", length, *offset);
  47. char c;
  48. char bits[8];
  49. current->state=TASK_UNINTERRUPTIBLE;
  50. schedule_timeout(2*HZ);
  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");