29 #include <linux/kernel.h>
30 #include <linux/string.h>
31 #include <linux/module.h>
36 #define BT_DEBUG_OFF 0
37 #define BT_DEBUG_ENABLE 1
38 #define BT_DEBUG_MSG 2
39 #define BT_DEBUG_STATES 4
58 #define BT_NORMAL_TIMEOUT 5
59 #define BT_NORMAL_RETRY_LIMIT 2
60 #define BT_RESET_DELAY 6
90 #define BT_STATE_CHANGE(X, Y) { bt->state = X; return Y; }
92 #define BT_SI_SM_RETURN(Y) { last_printed = BT_STATE_PRINTME; return Y; }
112 #define BT_CLR_WR_PTR 0x01
113 #define BT_CLR_RD_PTR 0x02
114 #define BT_H2B_ATN 0x04
115 #define BT_B2H_ATN 0x08
116 #define BT_SMS_ATN 0x10
118 #define BT_H_BUSY 0x40
119 #define BT_B_BUSY 0x80
129 #define BT_STATUS bt->io->inputb(bt->io, 0)
130 #define BT_CONTROL(x) bt->io->outputb(bt->io, 0, x)
132 #define BMC2HOST bt->io->inputb(bt->io, 1)
133 #define HOST2BMC(x) bt->io->outputb(bt->io, 1, x)
135 #define BT_INTMASK_R bt->io->inputb(bt->io, 2)
136 #define BT_INTMASK_W(x) bt->io->outputb(bt->io, 2, x)
143 static char *state2txt(
unsigned char state)
163 #define STATE2TXT state2txt(bt->state)
165 static char *status2txt(
unsigned char status)
190 #define STATUS2TXT status2txt(status)
244 for (i = 0; i <
size; i ++)
267 static int bt_get_result(
struct si_sm_data *bt,
280 if (length < msg_len || bt->truncated) {
286 if (bt_debug & BT_DEBUG_MSG) {
296 #define BT_BMC_HWRST 0x80
298 static void reset_flags(
struct si_sm_data *bt)
315 static void drain_BMC2HOST(
struct si_sm_data *bt)
331 for (i = 0; i <
size ; i++)
335 printk(
"drained %d bytes\n", size + 1);
338 static inline void write_all_bytes(
struct si_sm_data *bt)
342 if (bt_debug & BT_DEBUG_MSG) {
353 static inline int read_all_bytes(
struct si_sm_data *bt)
366 if (bt_debug & BT_DEBUG_MSG)
376 if (bt_debug & BT_DEBUG_MSG) {
383 for (i = 0; i <
max; i++)
394 if (bt_debug & BT_DEBUG_MSG)
396 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n",
417 reason =
"internal error";
430 printk(
"%d retries left\n",
464 force_result(bt, cCode);
472 unsigned char status, BT_CAP[8];
484 last_printed = bt->
state;
504 return error_recovery(bt,
541 if (status & BT_H_BUSY)
558 if (!(status & BT_B2H_ATN))
573 if (status & BT_B2H_ATN) {
582 if (!(status & BT_H_BUSY))
586 i = read_all_bytes(bt);
599 bt_init_data(bt, bt->
io);
641 unsigned char GetBT_CAP[] = { 0x18, 0x36 };
643 bt_start_transaction(bt, GetBT_CAP,
sizeof(GetBT_CAP));
650 i = bt_get_result(bt, BT_CAP,
sizeof(BT_CAP));
651 bt_init_data(bt, bt->
io);
652 if ((i == 8) && !BT_CAP[2]) {
666 return error_recovery(bt,
692 static int bt_size(
void)
698 .init_data = bt_init_data,
699 .start_transaction = bt_start_transaction,
700 .get_result = bt_get_result,
703 .cleanup = bt_cleanup,