Lines Matching full:mlc
2 * HIL MLC state machine and serio interface driver
37 * few bits of logic in addition to raw access to the HIL MLC,
44 * each time it runs, checking each MLC's progress at the current
45 * node in the state machine, and moving the MLC to subsequent nodes
66 MODULE_DESCRIPTION("HIL MLC serio");
72 #define PREFIX "HIL MLC: "
87 static void hil_mlc_clear_di_map(hil_mlc *mlc, int val) in hil_mlc_clear_di_map() argument
92 mlc->di_map[j] = -1; in hil_mlc_clear_di_map()
95 static void hil_mlc_clear_di_scratch(hil_mlc *mlc) in hil_mlc_clear_di_scratch() argument
97 memset(&mlc->di_scratch, 0, sizeof(mlc->di_scratch)); in hil_mlc_clear_di_scratch()
100 static void hil_mlc_copy_di_scratch(hil_mlc *mlc, int idx) in hil_mlc_copy_di_scratch() argument
102 memcpy(&mlc->di[idx], &mlc->di_scratch, sizeof(mlc->di_scratch)); in hil_mlc_copy_di_scratch()
105 static int hil_mlc_match_di_scratch(hil_mlc *mlc) in hil_mlc_match_di_scratch() argument
114 if (mlc->di_map[j] == idx) in hil_mlc_match_di_scratch()
120 if (!memcmp(mlc->di + idx, &mlc->di_scratch, in hil_mlc_match_di_scratch()
121 sizeof(mlc->di_scratch))) in hil_mlc_match_di_scratch()
127 static int hil_mlc_find_free_di(hil_mlc *mlc) in hil_mlc_find_free_di() argument
138 if (mlc->di_map[j] == idx) in hil_mlc_find_free_di()
148 static inline void hil_mlc_clean_serio_map(hil_mlc *mlc) in hil_mlc_clean_serio_map() argument
156 if (mlc->di_map[j] == idx) in hil_mlc_clean_serio_map()
160 mlc->serio_map[idx].di_revmap = -1; in hil_mlc_clean_serio_map()
164 static void hil_mlc_send_polls(hil_mlc *mlc) in hil_mlc_send_polls() argument
171 did = (mlc->ipacket[0] & HIL_PKT_ADDR_MASK) >> 8; in hil_mlc_send_polls()
172 serio = did ? mlc->serio[mlc->di_map[did - 1]] : NULL; in hil_mlc_send_polls()
175 while (mlc->icount < 15 - i) { in hil_mlc_send_polls()
178 p = mlc->ipacket[i]; in hil_mlc_send_polls()
188 serio = did ? mlc->serio[mlc->di_map[did-1]] : NULL; in hil_mlc_send_polls()
240 static int hilse_match(hil_mlc *mlc, int unused) in hilse_match() argument
244 rc = hil_mlc_match_di_scratch(mlc); in hilse_match()
246 rc = hil_mlc_find_free_di(mlc); in hilse_match()
253 hil_mlc_copy_di_scratch(mlc, rc); in hilse_match()
254 mlc->di_map[mlc->ddi] = rc; in hilse_match()
255 mlc->serio_map[rc].di_revmap = mlc->ddi; in hilse_match()
256 hil_mlc_clean_serio_map(mlc); in hilse_match()
257 serio_rescan(mlc->serio[rc]); in hilse_match()
261 mlc->di_map[mlc->ddi] = rc; in hilse_match()
265 mlc->serio_map[rc].di_revmap = mlc->ddi; in hilse_match()
266 hil_mlc_clean_serio_map(mlc); in hilse_match()
275 static int hilse_init_lcv(hil_mlc *mlc, int unused) in hilse_init_lcv() argument
279 if (mlc->lcv && (now - mlc->lcv_time) < 5) in hilse_init_lcv()
282 mlc->lcv_time = now; in hilse_init_lcv()
283 mlc->lcv = 0; in hilse_init_lcv()
288 static int hilse_inc_lcv(hil_mlc *mlc, int lim) in hilse_inc_lcv() argument
290 return mlc->lcv++ >= lim ? -1 : 0; in hilse_inc_lcv()
294 static int hilse_set_lcv(hil_mlc *mlc, int val)
296 mlc->lcv = val;
303 static int hilse_set_ddi(hil_mlc *mlc, int val) in hilse_set_ddi() argument
305 mlc->ddi = val; in hilse_set_ddi()
306 hil_mlc_clear_di_map(mlc, val + 1); in hilse_set_ddi()
311 static int hilse_dec_ddi(hil_mlc *mlc, int unused) in hilse_dec_ddi() argument
313 mlc->ddi--; in hilse_dec_ddi()
314 if (mlc->ddi <= -1) { in hilse_dec_ddi()
315 mlc->ddi = -1; in hilse_dec_ddi()
316 hil_mlc_clear_di_map(mlc, 0); in hilse_dec_ddi()
319 hil_mlc_clear_di_map(mlc, mlc->ddi + 1); in hilse_dec_ddi()
324 static int hilse_inc_ddi(hil_mlc *mlc, int unused) in hilse_inc_ddi() argument
326 BUG_ON(mlc->ddi >= 6); in hilse_inc_ddi()
327 mlc->ddi++; in hilse_inc_ddi()
332 static int hilse_take_idd(hil_mlc *mlc, int unused) in hilse_take_idd() argument
341 if (mlc->ipacket[0] & HIL_PKT_CMD) in hilse_take_idd()
346 if (((mlc->ipacket[i] & HIL_PKT_ADDR_MASK) == in hilse_take_idd()
347 (mlc->ipacket[0] & HIL_PKT_ADDR_MASK)) && in hilse_take_idd()
348 (mlc->ipacket[i] & HIL_PKT_CMD) && in hilse_take_idd()
349 ((mlc->ipacket[i] & HIL_PKT_DATA_MASK) == HIL_CMD_IDD)) in hilse_take_idd()
357 if (mlc->ipacket[i]) in hilse_take_idd()
364 mlc->di_scratch.idd[i] = in hilse_take_idd()
365 mlc->ipacket[i] & HIL_PKT_DATA_MASK; in hilse_take_idd()
368 if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_RSC) in hilse_take_idd()
371 if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD) in hilse_take_idd()
377 mlc->ddi--; in hilse_take_idd()
382 static int hilse_take_rsc(hil_mlc *mlc, int unused) in hilse_take_rsc() argument
387 mlc->di_scratch.rsc[i] = in hilse_take_rsc()
388 mlc->ipacket[i] & HIL_PKT_DATA_MASK; in hilse_take_rsc()
391 if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD) in hilse_take_rsc()
397 static int hilse_take_exd(hil_mlc *mlc, int unused) in hilse_take_exd() argument
402 mlc->di_scratch.exd[i] = in hilse_take_exd()
403 mlc->ipacket[i] & HIL_PKT_DATA_MASK; in hilse_take_exd()
406 if (mlc->di_scratch.exd[0] & HIL_EXD_HEADER_RNM) in hilse_take_exd()
412 static int hilse_take_rnm(hil_mlc *mlc, int unused) in hilse_take_rnm() argument
417 mlc->di_scratch.rnm[i] = in hilse_take_rnm()
418 mlc->ipacket[i] & HIL_PKT_DATA_MASK; in hilse_take_rnm()
421 mlc->di_scratch.rnm); in hilse_take_rnm()
426 static int hilse_operate(hil_mlc *mlc, int repoll) in hilse_operate() argument
429 if (mlc->opercnt == 0) in hilse_operate()
431 mlc->opercnt = 1; in hilse_operate()
433 hil_mlc_send_polls(mlc); in hilse_operate()
438 mlc->opercnt = 0; in hilse_operate()
583 static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node) in hilse_setup_input() argument
588 mlc->imatch = node->object.packet; in hilse_setup_input()
589 mlc->imatch |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT); in hilse_setup_input()
592 mlc->imatch = node->object.packet; in hilse_setup_input()
593 mlc->imatch |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT); in hilse_setup_input()
596 mlc->imatch = node->object.packet; in hilse_setup_input()
599 mlc->imatch = 0; in hilse_setup_input()
604 mlc->istarted = 1; in hilse_setup_input()
605 mlc->intimeout = usecs_to_jiffies(node->arg); in hilse_setup_input()
606 mlc->instart = jiffies; in hilse_setup_input()
607 mlc->icount = 15; in hilse_setup_input()
608 memset(mlc->ipacket, 0, 16 * sizeof(hil_packet)); in hilse_setup_input()
609 BUG_ON(down_trylock(&mlc->isem)); in hilse_setup_input()
617 static int hilse_donode(hil_mlc *mlc) in hilse_donode() argument
625 if (mlc->seidx && mlc->seidx != seidx && in hilse_donode()
626 mlc->seidx != 41 && mlc->seidx != 42 && mlc->seidx != 43) { in hilse_donode()
627 printk(KERN_DEBUG PREFIX "z%i \n {%i}", doze, mlc->seidx); in hilse_donode()
631 seidx = mlc->seidx; in hilse_donode()
633 node = hil_mlc_se + mlc->seidx; in hilse_donode()
641 rc = node->object.func(mlc, node->arg); in hilse_donode()
653 write_lock_irqsave(&mlc->lock, flags); in hilse_donode()
654 rc = mlc->in(mlc, node->arg); in hilse_donode()
658 write_unlock_irqrestore(&mlc->lock, flags); in hilse_donode()
667 mlc->istarted = 0; in hilse_donode()
668 write_unlock_irqrestore(&mlc->lock, flags); in hilse_donode()
672 write_lock_irqsave(&mlc->lock, flags); in hilse_donode()
674 pack |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT); in hilse_donode()
678 write_lock_irqsave(&mlc->lock, flags); in hilse_donode()
680 pack |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT); in hilse_donode()
684 write_lock_irqsave(&mlc->lock, flags); in hilse_donode()
687 if (!mlc->istarted) { in hilse_donode()
690 hilse_setup_input(mlc, node + 1); in hilse_donode()
693 write_unlock_irqrestore(&mlc->lock, flags); in hilse_donode()
695 if (down_trylock(&mlc->osem)) { in hilse_donode()
699 up(&mlc->osem); in hilse_donode()
701 write_lock_irqsave(&mlc->lock, flags); in hilse_donode()
702 if (!mlc->ostarted) { in hilse_donode()
703 mlc->ostarted = 1; in hilse_donode()
704 mlc->opacket = pack; in hilse_donode()
705 rc = mlc->out(mlc); in hilse_donode()
707 write_unlock_irqrestore(&mlc->lock, flags); in hilse_donode()
714 mlc->ostarted = 0; in hilse_donode()
715 mlc->instart = jiffies; in hilse_donode()
716 write_unlock_irqrestore(&mlc->lock, flags); in hilse_donode()
721 write_lock_irqsave(&mlc->lock, flags); in hilse_donode()
722 rc = mlc->cts(mlc); in hilse_donode()
724 write_unlock_irqrestore(&mlc->lock, flags); in hilse_donode()
746 if (time_after(now, mlc->instart + mlc->intimeout)) in hilse_donode()
748 mod_timer(&hil_mlcs_kicker, mlc->instart + mlc->intimeout); in hilse_donode()
756 mlc->seidx += nextidx & HILSEN_MASK; in hilse_donode()
758 mlc->seidx -= nextidx & HILSEN_MASK; in hilse_donode()
760 mlc->seidx = nextidx & HILSEN_MASK; in hilse_donode()
775 struct hil_mlc *mlc = list_entry(tmp, hil_mlc, list); in hil_mlcs_process() local
776 while (hilse_donode(mlc) == 0) { in hil_mlcs_process()
778 if (mlc->seidx != 41 && in hil_mlcs_process()
779 mlc->seidx != 42 && in hil_mlcs_process()
780 mlc->seidx != 43) in hil_mlcs_process()
794 pr_warn(PREFIX "HIL seems stuck - Disabling HIL MLC.\n"); in hil_mlcs_timer()
810 struct hil_mlc *mlc; in hil_mlc_serio_write() local
817 mlc = map->mlc; in hil_mlc_serio_write()
818 BUG_ON(mlc == NULL); in hil_mlc_serio_write()
820 mlc->serio_opacket[map->didx] |= in hil_mlc_serio_write()
821 ((hil_packet)c) << (8 * (3 - mlc->serio_oidx[map->didx])); in hil_mlc_serio_write()
823 if (mlc->serio_oidx[map->didx] >= 3) { in hil_mlc_serio_write()
825 if (!(mlc->serio_opacket[map->didx] & HIL_PKT_CMD)) in hil_mlc_serio_write()
827 switch (mlc->serio_opacket[map->didx] & HIL_PKT_DATA_MASK) { in hil_mlc_serio_write()
829 idx = mlc->di[map->didx].idd; in hil_mlc_serio_write()
832 idx = mlc->di[map->didx].rsc; in hil_mlc_serio_write()
835 idx = mlc->di[map->didx].exd; in hil_mlc_serio_write()
838 idx = mlc->di[map->didx].rnm; in hil_mlc_serio_write()
843 mlc->serio_oidx[map->didx] = 0; in hil_mlc_serio_write()
844 mlc->serio_opacket[map->didx] = 0; in hil_mlc_serio_write()
847 mlc->serio_oidx[map->didx]++; in hil_mlc_serio_write()
869 mlc->serio_oidx[map->didx] = 0; in hil_mlc_serio_write()
870 mlc->serio_opacket[map->didx] = 0; in hil_mlc_serio_write()
878 struct hil_mlc *mlc; in hil_mlc_serio_open() local
886 mlc = map->mlc; in hil_mlc_serio_open()
887 BUG_ON(mlc == NULL); in hil_mlc_serio_open()
895 struct hil_mlc *mlc; in hil_mlc_serio_close() local
900 mlc = map->mlc; in hil_mlc_serio_close()
901 BUG_ON(mlc == NULL); in hil_mlc_serio_close()
915 int hil_mlc_register(hil_mlc *mlc) in hil_mlc_register() argument
920 BUG_ON(mlc == NULL); in hil_mlc_register()
922 mlc->istarted = 0; in hil_mlc_register()
923 mlc->ostarted = 0; in hil_mlc_register()
925 rwlock_init(&mlc->lock); in hil_mlc_register()
926 sema_init(&mlc->osem, 1); in hil_mlc_register()
928 sema_init(&mlc->isem, 1); in hil_mlc_register()
929 mlc->icount = -1; in hil_mlc_register()
930 mlc->imatch = 0; in hil_mlc_register()
932 mlc->opercnt = 0; in hil_mlc_register()
934 sema_init(&(mlc->csem), 0); in hil_mlc_register()
936 hil_mlc_clear_di_scratch(mlc); in hil_mlc_register()
937 hil_mlc_clear_di_map(mlc, 0); in hil_mlc_register()
940 hil_mlc_copy_di_scratch(mlc, i); in hil_mlc_register()
942 mlc->serio[i] = mlc_serio; in hil_mlc_register()
943 if (!mlc->serio[i]) { in hil_mlc_register()
945 kfree(mlc->serio[i]); in hil_mlc_register()
955 mlc_serio->port_data = &(mlc->serio_map[i]); in hil_mlc_register()
956 mlc->serio_map[i].mlc = mlc; in hil_mlc_register()
957 mlc->serio_map[i].didx = i; in hil_mlc_register()
958 mlc->serio_map[i].di_revmap = -1; in hil_mlc_register()
959 mlc->serio_opacket[i] = 0; in hil_mlc_register()
960 mlc->serio_oidx[i] = 0; in hil_mlc_register()
964 mlc->tasklet = &hil_mlcs_tasklet; in hil_mlc_register()
967 list_add_tail(&mlc->list, &hil_mlcs); in hil_mlc_register()
968 mlc->seidx = HILSEN_START; in hil_mlc_register()
975 int hil_mlc_unregister(hil_mlc *mlc) in hil_mlc_unregister() argument
981 BUG_ON(mlc == NULL); in hil_mlc_unregister()
985 if (list_entry(tmp, hil_mlc, list) == mlc) in hil_mlc_unregister()
998 serio_unregister_port(mlc->serio[i]); in hil_mlc_unregister()
999 mlc->serio[i] = NULL; in hil_mlc_unregister()