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.
8 * 2001-04-18 Robert Siemer <Robert.Siemer@gmx.de>
9 * separate file for user interface driver
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/smp_lock.h>
17 #include <linux/miscdevice.h>
18 #include <linux/delay.h>
19 #include <asm/uaccess.h>
20 #include "miropcm20-rds-core.h"
22 static char * text_buffer;
26 static int rds_f_open(struct inode *in, struct file *fi)
33 if ((text_buffer=kmalloc(66, GFP_KERNEL)) == 0) {
35 printk(KERN_NOTICE "aci-rds: Out of memory by open()...\n");
44 static int rds_f_release(struct inode *in, struct file *fi)
52 static void print_matrix(char *ch, char out[])
56 for (j=7; j>=0; j--) {
57 out[7-j] = ((*ch >> j) & 0x1) + '0';
61 static ssize_t rds_f_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
63 // i = sprintf(text_buffer, "length: %d, offset: %d\n", length, *offset);
69 aci_rds_cmd(RDS_STATUS, &c, 1);
70 print_matrix(&c, bits);
71 if (copy_to_user(buffer, bits, 8))
74 /* if ((c >> 3) & 1) {
75 aci_rds_cmd(RDS_STATIONNAME, text_buffer+1, 8);
76 text_buffer[0] = ' ' ;
77 text_buffer[9] = '\n';
78 return copy_to_user(buffer+8, text_buffer, 10) ? -EFAULT: 18;
81 /* if ((c >> 6) & 1) {
82 aci_rds_cmd(RDS_PTYTATP, &c, 1);
84 sprintf(text_buffer, " M");
86 sprintf(text_buffer, " S");
88 sprintf(text_buffer+2, " TA");
90 sprintf(text_buffer+2, " --");
92 sprintf(text_buffer+5, " TP");
94 sprintf(text_buffer+5, " --");
95 sprintf(text_buffer+8, " %2d\n", (c >> 2) & 0x1f);
96 return copy_to_user(buffer+8, text_buffer, 12) ? -EFAULT: 20;
101 aci_rds_cmd(RDS_TEXT, text_buffer, 65);
102 text_buffer[0] = ' ' ;
103 text_buffer[65] = '\n';
104 return copy_to_user(buffer+8, text_buffer,66) ? -EFAULT : 66+8;
106 put_user('\n', buffer+8);
111 static const struct file_operations rds_fops = {
112 .owner = THIS_MODULE,
115 .release = rds_f_release
118 static struct miscdevice rds_miscdev = {
119 .minor = MISC_DYNAMIC_MINOR,
124 static int __init miropcm20_rds_init(void)
126 return misc_register(&rds_miscdev);
129 static void __exit miropcm20_rds_cleanup(void)
131 misc_deregister(&rds_miscdev);
134 module_init(miropcm20_rds_init);
135 module_exit(miropcm20_rds_cleanup);
136 MODULE_LICENSE("GPL");