2 * Many thanks to Fred Seidel <seidel@metabox.de>, the
3 * designer of the RDS decoder hardware. With his help
4 * I was able to code this driver.
5 * Thanks also to Norberto Pellicci, Dominic Mounteney
6 * <DMounteney@pinnaclesys.com> and www.teleauskunft.de
7 * for good hints on finding Fred. It was somewhat hard
8 * to locate him here in Germany... [:
12 * 2000-08-09 Robert Siemer <Robert.Siemer@gmx.de>
13 * RDS support for MiroSound PCM20 radio
16 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
20 #include <linux/slab.h>
21 #include <asm/semaphore.h>
23 #include "../../../sound/oss/aci.h"
24 #include "miropcm20-rds-core.h"
28 static struct semaphore aci_rds_sem
;
30 #define RDS_DATASHIFT 2 /* Bit 2 */
31 #define RDS_DATAMASK (1 << RDS_DATASHIFT)
32 #define RDS_BUSYMASK 0x10 /* Bit 4 */
33 #define RDS_CLOCKMASK 0x08 /* Bit 3 */
35 #define RDS_DATA(x) (((x) >> RDS_DATASHIFT) & 1)
39 static void print_matrix(char array
[], unsigned int length
)
43 for (i
=0; i
<length
; i
++) {
44 printk(KERN_DEBUG
"aci-rds: ");
45 for (j
=7; j
>=0; j
--) {
46 printk("%d", (array
[i
] >> j
) & 0x1);
49 printk(" byte-border\n");
56 static int byte2trans(unsigned char byte
, unsigned char sendbuffer
[], int size
)
62 for (i
= 7; i
>= 0; i
--)
63 sendbuffer
[7-i
] = (byte
& (1 << i
)) ? RDS_DATAMASK
: 0;
64 sendbuffer
[0] |= RDS_CLOCKMASK
;
69 static int rds_waitread(void)
75 byte
=inb(RDS_REGISTER
);
78 while ((byte
& RDS_BUSYMASK
) && i
);
82 printk(KERN_DEBUG
"rds_waitread()");
83 print_matrix(&byte
, 1);
87 printk(KERN_WARNING
"aci-rds: rds_waitread() timeout...\n");
92 /* don't use any ..._nowait() function if you are not sure what you do... */
94 static inline void rds_rawwrite_nowait(unsigned char byte
)
97 printk(KERN_DEBUG
"rds_rawwrite()");
98 print_matrix(&byte
, 1);
100 outb(byte
, RDS_REGISTER
);
103 static int rds_rawwrite(unsigned char byte
)
105 if (rds_waitread() >= 0) {
106 rds_rawwrite_nowait(byte
);
112 static int rds_write(unsigned char cmd
)
114 unsigned char sendbuffer
[8];
117 if (byte2trans(cmd
, sendbuffer
, 8) != 0){
120 for (i
=0; i
<8; i
++) {
121 rds_rawwrite(sendbuffer
[i
]);
127 static int rds_readcycle_nowait(void)
129 rds_rawwrite_nowait(0);
130 return rds_waitread();
133 static int rds_readcycle(void)
135 if (rds_rawwrite(0) < 0)
137 return rds_waitread();
140 static int rds_read(unsigned char databuffer
[], int datasize
)
142 #define READSIZE (8*datasize)
146 if (datasize
< 1) /* nothing to read */
149 /* to be able to use rds_readcycle_nowait()
150 I have to waitread() here */
151 if (rds_waitread() < 0)
154 memset(databuffer
, 0, datasize
);
156 for (i
=0; i
< READSIZE
; i
++)
157 if((j
=rds_readcycle_nowait()) < 0) {
160 databuffer
[i
/8]|=(RDS_DATA(j
) << (7-(i
%8)));
166 static int rds_ack(void)
168 int i
=rds_readcycle();
172 if (i
& RDS_DATAMASK
) {
175 printk(KERN_DEBUG
"aci-rds: NACK\n");
180 int aci_rds_cmd(unsigned char cmd
, unsigned char databuffer
[], int datasize
)
184 if (down_interruptible(&aci_rds_sem
))
189 /* RDS_RESET doesn't need further processing */
190 if (cmd
!=RDS_RESET
&& (rds_ack() || rds_read(databuffer
, datasize
)))
199 EXPORT_SYMBOL(aci_rds_cmd
);
201 int __init
attach_aci_rds(void)
203 init_MUTEX(&aci_rds_sem
);
207 void __exit
unload_aci_rds(void)
210 MODULE_LICENSE("GPL");