Lines Matching refs:kcs

123 static unsigned int init_kcs_data(struct si_sm_data *kcs,  in init_kcs_data()  argument
126 kcs->state = KCS_IDLE; in init_kcs_data()
127 kcs->io = io; in init_kcs_data()
128 kcs->write_pos = 0; in init_kcs_data()
129 kcs->write_count = 0; in init_kcs_data()
130 kcs->orig_write_count = 0; in init_kcs_data()
131 kcs->read_pos = 0; in init_kcs_data()
132 kcs->error_retries = 0; in init_kcs_data()
133 kcs->truncated = 0; in init_kcs_data()
134 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in init_kcs_data()
135 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in init_kcs_data()
141 static inline unsigned char read_status(struct si_sm_data *kcs) in read_status() argument
143 return kcs->io->inputb(kcs->io, 1); in read_status()
146 static inline unsigned char read_data(struct si_sm_data *kcs) in read_data() argument
148 return kcs->io->inputb(kcs->io, 0); in read_data()
151 static inline void write_cmd(struct si_sm_data *kcs, unsigned char data) in write_cmd() argument
153 kcs->io->outputb(kcs->io, 1, data); in write_cmd()
156 static inline void write_data(struct si_sm_data *kcs, unsigned char data) in write_data() argument
158 kcs->io->outputb(kcs->io, 0, data); in write_data()
178 static inline void write_next_byte(struct si_sm_data *kcs) in write_next_byte() argument
180 write_data(kcs, kcs->write_data[kcs->write_pos]); in write_next_byte()
181 (kcs->write_pos)++; in write_next_byte()
182 (kcs->write_count)--; in write_next_byte()
185 static inline void start_error_recovery(struct si_sm_data *kcs, char *reason) in start_error_recovery() argument
187 (kcs->error_retries)++; in start_error_recovery()
188 if (kcs->error_retries > MAX_ERROR_RETRIES) { in start_error_recovery()
192 kcs->state = KCS_HOSED; in start_error_recovery()
194 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES; in start_error_recovery()
195 kcs->state = KCS_ERROR0; in start_error_recovery()
199 static inline void read_next_byte(struct si_sm_data *kcs) in read_next_byte() argument
201 if (kcs->read_pos >= MAX_KCS_READ_SIZE) { in read_next_byte()
203 read_data(kcs); in read_next_byte()
204 kcs->truncated = 1; in read_next_byte()
206 kcs->read_data[kcs->read_pos] = read_data(kcs); in read_next_byte()
207 (kcs->read_pos)++; in read_next_byte()
209 write_data(kcs, KCS_READ_BYTE); in read_next_byte()
212 static inline int check_ibf(struct si_sm_data *kcs, unsigned char status, in check_ibf() argument
216 kcs->ibf_timeout -= time; in check_ibf()
217 if (kcs->ibf_timeout < 0) { in check_ibf()
218 start_error_recovery(kcs, "IBF not ready in time"); in check_ibf()
219 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
224 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
228 static inline int check_obf(struct si_sm_data *kcs, unsigned char status, in check_obf() argument
232 kcs->obf_timeout -= time; in check_obf()
233 if (kcs->obf_timeout < 0) { in check_obf()
234 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
235 start_error_recovery(kcs, "OBF not ready in time"); in check_obf()
240 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
244 static void clear_obf(struct si_sm_data *kcs, unsigned char status) in clear_obf() argument
247 read_data(kcs); in clear_obf()
250 static void restart_kcs_transaction(struct si_sm_data *kcs) in restart_kcs_transaction() argument
252 kcs->write_count = kcs->orig_write_count; in restart_kcs_transaction()
253 kcs->write_pos = 0; in restart_kcs_transaction()
254 kcs->read_pos = 0; in restart_kcs_transaction()
255 kcs->state = KCS_WAIT_WRITE_START; in restart_kcs_transaction()
256 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in restart_kcs_transaction()
257 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in restart_kcs_transaction()
258 write_cmd(kcs, KCS_WRITE_START); in restart_kcs_transaction()
261 static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data, in start_kcs_transaction() argument
271 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) in start_kcs_transaction()
280 kcs->error_retries = 0; in start_kcs_transaction()
281 memcpy(kcs->write_data, data, size); in start_kcs_transaction()
282 kcs->write_count = size; in start_kcs_transaction()
283 kcs->orig_write_count = size; in start_kcs_transaction()
284 kcs->write_pos = 0; in start_kcs_transaction()
285 kcs->read_pos = 0; in start_kcs_transaction()
286 kcs->state = KCS_START_OP; in start_kcs_transaction()
287 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in start_kcs_transaction()
288 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in start_kcs_transaction()
292 static int get_kcs_result(struct si_sm_data *kcs, unsigned char *data, in get_kcs_result() argument
295 if (length < kcs->read_pos) { in get_kcs_result()
296 kcs->read_pos = length; in get_kcs_result()
297 kcs->truncated = 1; in get_kcs_result()
300 memcpy(data, kcs->read_data, kcs->read_pos); in get_kcs_result()
302 if ((length >= 3) && (kcs->read_pos < 3)) { in get_kcs_result()
306 kcs->read_pos = 3; in get_kcs_result()
308 if (kcs->truncated) { in get_kcs_result()
315 kcs->truncated = 0; in get_kcs_result()
318 return kcs->read_pos; in get_kcs_result()
326 static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time) in kcs_event() argument
331 status = read_status(kcs); in kcs_event()
334 printk(KERN_DEBUG "KCS: State = %d, %x\n", kcs->state, status); in kcs_event()
337 if (!check_ibf(kcs, status, time)) in kcs_event()
343 switch (kcs->state) { in kcs_event()
346 clear_obf(kcs, status); in kcs_event()
355 start_error_recovery(kcs, in kcs_event()
360 clear_obf(kcs, status); in kcs_event()
361 write_cmd(kcs, KCS_WRITE_START); in kcs_event()
362 kcs->state = KCS_WAIT_WRITE_START; in kcs_event()
368 kcs, in kcs_event()
372 read_data(kcs); in kcs_event()
373 if (kcs->write_count == 1) { in kcs_event()
374 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
375 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
377 write_next_byte(kcs); in kcs_event()
378 kcs->state = KCS_WAIT_WRITE; in kcs_event()
384 start_error_recovery(kcs, in kcs_event()
388 clear_obf(kcs, status); in kcs_event()
389 if (kcs->write_count == 1) { in kcs_event()
390 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
391 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
393 write_next_byte(kcs); in kcs_event()
399 start_error_recovery(kcs, in kcs_event()
404 clear_obf(kcs, status); in kcs_event()
405 write_next_byte(kcs); in kcs_event()
406 kcs->state = KCS_WAIT_READ; in kcs_event()
412 kcs, in kcs_event()
418 if (!check_obf(kcs, status, time)) in kcs_event()
420 read_next_byte(kcs); in kcs_event()
431 clear_obf(kcs, status); in kcs_event()
432 kcs->orig_write_count = 0; in kcs_event()
433 kcs->state = KCS_IDLE; in kcs_event()
439 clear_obf(kcs, status); in kcs_event()
440 status = read_status(kcs); in kcs_event()
443 if (time_before(jiffies, kcs->error0_timeout)) in kcs_event()
445 write_cmd(kcs, KCS_GET_STATUS_ABORT); in kcs_event()
446 kcs->state = KCS_ERROR1; in kcs_event()
450 clear_obf(kcs, status); in kcs_event()
451 write_data(kcs, 0); in kcs_event()
452 kcs->state = KCS_ERROR2; in kcs_event()
457 start_error_recovery(kcs, in kcs_event()
461 if (!check_obf(kcs, status, time)) in kcs_event()
464 clear_obf(kcs, status); in kcs_event()
465 write_data(kcs, KCS_READ_BYTE); in kcs_event()
466 kcs->state = KCS_ERROR3; in kcs_event()
471 start_error_recovery(kcs, in kcs_event()
476 if (!check_obf(kcs, status, time)) in kcs_event()
479 clear_obf(kcs, status); in kcs_event()
480 if (kcs->orig_write_count) { in kcs_event()
481 restart_kcs_transaction(kcs); in kcs_event()
483 kcs->state = KCS_IDLE; in kcs_event()
492 if (kcs->state == KCS_HOSED) { in kcs_event()
493 init_kcs_data(kcs, kcs->io); in kcs_event()
505 static int kcs_detect(struct si_sm_data *kcs) in kcs_detect() argument
513 if (read_status(kcs) == 0xff) in kcs_detect()
519 static void kcs_cleanup(struct si_sm_data *kcs) in kcs_cleanup() argument