Lines Matching refs:kcs
116 void init_kcs_data(struct kcs_data *kcs, unsigned int port, unsigned char *addr) in init_kcs_data() argument
118 kcs->state = KCS_IDLE; in init_kcs_data()
119 kcs->port = port; in init_kcs_data()
120 kcs->addr = addr; in init_kcs_data()
121 kcs->write_pos = 0; in init_kcs_data()
122 kcs->write_count = 0; in init_kcs_data()
123 kcs->orig_write_count = 0; in init_kcs_data()
124 kcs->read_pos = 0; in init_kcs_data()
125 kcs->error_retries = 0; in init_kcs_data()
126 kcs->truncated = 0; in init_kcs_data()
127 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in init_kcs_data()
128 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in init_kcs_data()
133 static inline unsigned char read_status(struct kcs_data *kcs) in read_status() argument
135 if (kcs->port) in read_status()
136 return inb(kcs->port + 1); in read_status()
138 return readb(kcs->addr + 1); in read_status()
141 static inline unsigned char read_data(struct kcs_data *kcs) in read_data() argument
143 if (kcs->port) in read_data()
144 return inb(kcs->port + 0); in read_data()
146 return readb(kcs->addr + 0); in read_data()
149 static inline void write_cmd(struct kcs_data *kcs, unsigned char data) in write_cmd() argument
151 if (kcs->port) in write_cmd()
152 outb(data, kcs->port + 1); in write_cmd()
154 writeb(data, kcs->addr + 1); in write_cmd()
157 static inline void write_data(struct kcs_data *kcs, unsigned char data) in write_data() argument
159 if (kcs->port) in write_data()
160 outb(data, kcs->port + 0); in write_data()
162 writeb(data, kcs->addr + 0); in write_data()
182 static inline void write_next_byte(struct kcs_data *kcs) in write_next_byte() argument
184 write_data(kcs, kcs->write_data[kcs->write_pos]); in write_next_byte()
185 (kcs->write_pos)++; in write_next_byte()
186 (kcs->write_count)--; in write_next_byte()
189 static inline void start_error_recovery(struct kcs_data *kcs, char *reason) in start_error_recovery() argument
191 (kcs->error_retries)++; in start_error_recovery()
192 if (kcs->error_retries > MAX_ERROR_RETRIES) { in start_error_recovery()
196 kcs->state = KCS_HOSED; in start_error_recovery()
198 kcs->state = KCS_ERROR0; in start_error_recovery()
202 static inline void read_next_byte(struct kcs_data *kcs) in read_next_byte() argument
204 if (kcs->read_pos >= MAX_KCS_READ_SIZE) { in read_next_byte()
206 read_data(kcs); in read_next_byte()
207 kcs->truncated = 1; in read_next_byte()
209 kcs->read_data[kcs->read_pos] = read_data(kcs); in read_next_byte()
210 (kcs->read_pos)++; in read_next_byte()
212 write_data(kcs, KCS_READ_BYTE); in read_next_byte()
215 static inline int check_ibf(struct kcs_data *kcs, in check_ibf() argument
220 kcs->ibf_timeout -= time; in check_ibf()
221 if (kcs->ibf_timeout < 0) { in check_ibf()
222 start_error_recovery(kcs, "IBF not ready in time"); in check_ibf()
223 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
228 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
232 static inline int check_obf(struct kcs_data *kcs, in check_obf() argument
237 kcs->obf_timeout -= time; in check_obf()
238 if (kcs->obf_timeout < 0) { in check_obf()
239 start_error_recovery(kcs, "OBF not ready in time"); in check_obf()
244 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
248 static void clear_obf(struct kcs_data *kcs, unsigned char status) in clear_obf() argument
251 read_data(kcs); in clear_obf()
254 static void restart_kcs_transaction(struct kcs_data *kcs) in restart_kcs_transaction() argument
256 kcs->write_count = kcs->orig_write_count; in restart_kcs_transaction()
257 kcs->write_pos = 0; in restart_kcs_transaction()
258 kcs->read_pos = 0; in restart_kcs_transaction()
259 kcs->state = KCS_WAIT_WRITE_START; in restart_kcs_transaction()
260 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in restart_kcs_transaction()
261 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in restart_kcs_transaction()
262 write_cmd(kcs, KCS_WRITE_START); in restart_kcs_transaction()
265 int start_kcs_transaction(struct kcs_data *kcs, char *data, unsigned int size) in start_kcs_transaction() argument
271 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) { in start_kcs_transaction()
275 kcs->error_retries = 0; in start_kcs_transaction()
276 memcpy(kcs->write_data, data, size); in start_kcs_transaction()
277 kcs->write_count = size; in start_kcs_transaction()
278 kcs->orig_write_count = size; in start_kcs_transaction()
279 kcs->write_pos = 0; in start_kcs_transaction()
280 kcs->read_pos = 0; in start_kcs_transaction()
281 kcs->state = KCS_START_OP; in start_kcs_transaction()
282 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in start_kcs_transaction()
283 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in start_kcs_transaction()
287 int kcs_get_result(struct kcs_data *kcs, unsigned char *data, int length) in kcs_get_result() argument
289 if (length < kcs->read_pos) { in kcs_get_result()
290 kcs->read_pos = length; in kcs_get_result()
291 kcs->truncated = 1; in kcs_get_result()
294 memcpy(data, kcs->read_data, kcs->read_pos); in kcs_get_result()
296 if ((length >= 3) && (kcs->read_pos < 3)) { in kcs_get_result()
300 kcs->read_pos = 3; in kcs_get_result()
302 if (kcs->truncated) { in kcs_get_result()
307 kcs->truncated = 0; in kcs_get_result()
310 return kcs->read_pos; in kcs_get_result()
316 enum kcs_result kcs_event(struct kcs_data *kcs, long time) in kcs_event() argument
321 status = read_status(kcs); in kcs_event()
324 printk(" State = %d, %x\n", kcs->state, status); in kcs_event()
327 if (!check_ibf(kcs, status, time)) in kcs_event()
333 switch (kcs->state) { in kcs_event()
336 clear_obf(kcs, status); in kcs_event()
345 start_error_recovery(kcs, in kcs_event()
350 clear_obf(kcs, status); in kcs_event()
351 write_cmd(kcs, KCS_WRITE_START); in kcs_event()
352 kcs->state = KCS_WAIT_WRITE_START; in kcs_event()
358 kcs, in kcs_event()
362 read_data(kcs); in kcs_event()
363 if (kcs->write_count == 1) { in kcs_event()
364 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
365 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
367 write_next_byte(kcs); in kcs_event()
368 kcs->state = KCS_WAIT_WRITE; in kcs_event()
374 start_error_recovery(kcs, in kcs_event()
378 clear_obf(kcs, status); in kcs_event()
379 if (kcs->write_count == 1) { in kcs_event()
380 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
381 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
383 write_next_byte(kcs); in kcs_event()
389 start_error_recovery(kcs, in kcs_event()
393 clear_obf(kcs, status); in kcs_event()
394 write_next_byte(kcs); in kcs_event()
395 kcs->state = KCS_WAIT_READ; in kcs_event()
401 kcs, in kcs_event()
407 if (! check_obf(kcs, status, time)) in kcs_event()
409 read_next_byte(kcs); in kcs_event()
418 clear_obf(kcs, status); in kcs_event()
419 kcs->orig_write_count = 0; in kcs_event()
420 kcs->state = KCS_IDLE; in kcs_event()
426 clear_obf(kcs, status); in kcs_event()
427 write_cmd(kcs, KCS_GET_STATUS_ABORT); in kcs_event()
428 kcs->state = KCS_ERROR1; in kcs_event()
432 clear_obf(kcs, status); in kcs_event()
433 write_data(kcs, 0); in kcs_event()
434 kcs->state = KCS_ERROR2; in kcs_event()
439 start_error_recovery(kcs, in kcs_event()
443 if (! check_obf(kcs, status, time)) in kcs_event()
446 clear_obf(kcs, status); in kcs_event()
447 write_data(kcs, KCS_READ_BYTE); in kcs_event()
448 kcs->state = KCS_ERROR3; in kcs_event()
453 start_error_recovery(kcs, in kcs_event()
458 if (! check_obf(kcs, status, time)) in kcs_event()
461 clear_obf(kcs, status); in kcs_event()
462 if (kcs->orig_write_count) { in kcs_event()
463 restart_kcs_transaction(kcs); in kcs_event()
465 kcs->state = KCS_IDLE; in kcs_event()
474 if (kcs->state == KCS_HOSED) { in kcs_event()
475 init_kcs_data(kcs, kcs->port, kcs->addr); in kcs_event()