/* get SB1000 PIDs */ static int sb1000_get_PIDs(const int ioaddr[], const char* name, short PID[]) { static const unsigned char Command0[6] = {0x80, 0x40, 0x00, 0x00, 0x00, 0x00}; static const unsigned char Command1[6] = {0x80, 0x41, 0x00, 0x00, 0x00, 0x00}; static const unsigned char Command2[6] = {0x80, 0x42, 0x00, 0x00, 0x00, 0x00}; static const unsigned char Command3[6] = {0x80, 0x43, 0x00, 0x00, 0x00, 0x00}; unsigned char st[7]; int status; udelay(1000); if ((status = sb1000_start_get_set_command(ioaddr, name))) return status; if ((status = card_send_command(ioaddr, name, Command0, st))) return status; PID[0] = st[1] << 8 | st[2]; if ((status = card_send_command(ioaddr, name, Command1, st))) return status; PID[1] = st[1] << 8 | st[2]; if ((status = card_send_command(ioaddr, name, Command2, st))) return status; PID[2] = st[1] << 8 | st[2]; if ((status = card_send_command(ioaddr, name, Command3, st))) return status; PID[3] = st[1] << 8 | st[2]; return sb1000_end_get_set_command(ioaddr, name); }
static inline int sb1000_end_get_set_command(const int ioaddr[], const char* name) { unsigned char st[7]; int status; const unsigned char Command0[6] = {0x80, 0x1b, 0x02, 0x00, 0x00, 0x00}; const unsigned char Command1[6] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00}; if ((status = card_send_command(ioaddr, name, Command0, st))) return status; return card_send_command(ioaddr, name, Command1, st); }
/* set SB1000 PIDs */ static int sb1000_set_PIDs(const int ioaddr[], const char* name, const short PID[]) { static const unsigned char Command4[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00}; unsigned char st[7]; short p; int status; unsigned char Command0[6] = {0x80, 0x31, 0x00, 0x00, 0x00, 0x00}; unsigned char Command1[6] = {0x80, 0x32, 0x00, 0x00, 0x00, 0x00}; unsigned char Command2[6] = {0x80, 0x33, 0x00, 0x00, 0x00, 0x00}; unsigned char Command3[6] = {0x80, 0x34, 0x00, 0x00, 0x00, 0x00}; udelay(1000); if ((status = sb1000_start_get_set_command(ioaddr, name))) return status; p = PID[0]; Command0[3] = p & 0xff; p >>= 8; Command0[2] = p & 0xff; if ((status = card_send_command(ioaddr, name, Command0, st))) return status; p = PID[1]; Command1[3] = p & 0xff; p >>= 8; Command1[2] = p & 0xff; if ((status = card_send_command(ioaddr, name, Command1, st))) return status; p = PID[2]; Command2[3] = p & 0xff; p >>= 8; Command2[2] = p & 0xff; if ((status = card_send_command(ioaddr, name, Command2, st))) return status; p = PID[3]; Command3[3] = p & 0xff; p >>= 8; Command3[2] = p & 0xff; if ((status = card_send_command(ioaddr, name, Command3, st))) return status; if ((status = card_send_command(ioaddr, name, Command4, st))) return status; return sb1000_end_get_set_command(ioaddr, name); }
/* set SB1000 frequency */ static int sb1000_set_frequency(const int ioaddr[], const char* name, int frequency) { unsigned char st[7]; int status; unsigned char Command0[6] = {0x80, 0x29, 0x00, 0x00, 0x00, 0x00}; const int FrequencyLowerLimit = 57000; const int FrequencyUpperLimit = 804000; if (frequency < FrequencyLowerLimit || frequency > FrequencyUpperLimit) { printk(KERN_ERR "%s: frequency chosen (%d kHz) is not in the range " "[%d,%d] kHz\n", name, frequency, FrequencyLowerLimit, FrequencyUpperLimit); return -EINVAL; } udelay(1000); if ((status = sb1000_start_get_set_command(ioaddr, name))) return status; Command0[5] = frequency & 0xff; frequency >>= 8; Command0[4] = frequency & 0xff; frequency >>= 8; Command0[3] = frequency & 0xff; frequency >>= 8; Command0[2] = frequency & 0xff; return card_send_command(ioaddr, name, Command0, st); }
/* reset SB1000 card */ static int sb1000_reset(const int ioaddr[], const char* name) { static const unsigned char Command0[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00}; unsigned char st[7]; int port, status; port = ioaddr[1] + 6; outb(0x4, port); inb(port); udelay(1000); outb(0x0, port); inb(port); ssleep(1); outb(0x4, port); inb(port); udelay(1000); outb(0x0, port); inb(port); udelay(0); if ((status = card_send_command(ioaddr, name, Command0, st))) return status; if (st[3] != 0xf0) return -EIO; return 0; }
static inline int sb1000_start_get_set_command(const int ioaddr[], const char* name) { unsigned char st[7]; const unsigned char Command0[6] = {0x80, 0x1b, 0x00, 0x00, 0x00, 0x00}; return card_send_command(ioaddr, name, Command0, st); }
static inline int sb1000_activate(const int ioaddr[], const char* name) { unsigned char st[7]; int status; const unsigned char Command0[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00}; const unsigned char Command1[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00}; ssleep(1); if ((status = card_send_command(ioaddr, name, Command0, st))) return status; if ((status = card_send_command(ioaddr, name, Command1, st))) return status; if (st[3] != 0xf1) { if ((status = sb1000_start_get_set_command(ioaddr, name))) return status; return -EIO; } udelay(1000); return sb1000_start_get_set_command(ioaddr, name); }
/* get SB1000 frequency */ static int sb1000_get_frequency(const int ioaddr[], const char* name, int* frequency) { unsigned char st[7]; int status; const unsigned char Command0[6] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00}; udelay(1000); if ((status = sb1000_start_get_set_command(ioaddr, name))) return status; if ((status = card_send_command(ioaddr, name, Command0, st))) return status; *frequency = ((st[1] << 8 | st[2]) << 8 | st[3]) << 8 | st[4]; return sb1000_end_get_set_command(ioaddr, name); }
/* check SB1000 firmware CRC */ static inline int sb1000_check_CRC(const int ioaddr[], const char* name) { unsigned char st[7]; int crc, status; const unsigned char Command0[6] = {0x80, 0x1f, 0x00, 0x00, 0x00, 0x00}; /* check CRC */ if ((status = card_send_command(ioaddr, name, Command0, st))) return status; if (st[1] != st[3] || st[2] != st[4]) return -EIO; crc = st[1] << 8 | st[2]; return 0; }
/* get SB1000 firmware version */ static int sb1000_get_firmware_version(const int ioaddr[], const char* name, unsigned char version[], int do_end) { unsigned char st[7]; int status; const unsigned char Command0[6] = {0x80, 0x23, 0x00, 0x00, 0x00, 0x00}; if ((status = sb1000_start_get_set_command(ioaddr, name))) return status; if ((status = card_send_command(ioaddr, name, Command0, st))) return status; if (st[0] != 0xa3) return -EIO; version[0] = st[1]; version[1] = st[2]; if (do_end) return sb1000_end_get_set_command(ioaddr, name); else return 0; }