1 /* Calypso DBB internal TSP (Time Serial Port) Driver */
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <calypso/tpu.h>
29 #include <calypso/tsp.h>
31 static uint16_t tspact_state;
33 /* initiate a TSP write through the TPU */
34 void tsp_write(uint8_t dev_idx, uint8_t bitlen, uint32_t dout)
37 tpu_enq_move(TPUI_TX_1, dout & 0xff);
38 } else if (bitlen <= 16) {
39 tpu_enq_move(TPUI_TX_1, (dout >> 8) & 0xff);
40 tpu_enq_move(TPUI_TX_2, dout & 0xff);
41 } else if (bitlen <= 24) {
42 tpu_enq_move(TPUI_TX_1, (dout >> 16) & 0xff);
43 tpu_enq_move(TPUI_TX_2, (dout >> 8) & 0xff);
44 tpu_enq_move(TPUI_TX_3, dout & 0xff);
46 tpu_enq_move(TPUI_TX_1, (dout >> 24) & 0xff);
47 tpu_enq_move(TPUI_TX_2, (dout >> 16) & 0xff);
48 tpu_enq_move(TPUI_TX_3, (dout >> 8) & 0xff);
49 tpu_enq_move(TPUI_TX_4, dout & 0xff);
51 tpu_enq_move(TPUI_TSP_CTRL1, (dev_idx << 5) | (bitlen - 1));
52 tpu_enq_move(TPUI_TSP_CTRL2, TPUI_CTRL2_WR);
55 /* Configure clock edge and chip enable polarity for a device */
56 void tsp_setup(uint8_t dev_idx, int clk_rising, int en_positive, int en_edge)
58 uint8_t reg = TPUI_TSP_SET1 + (dev_idx / 2);
74 tpu_enq_move(reg, (val << shift));
77 /* Update the TSPACT state, including enable and disable */
78 void tsp_act_update(uint16_t new_act)
80 uint8_t low = new_act & 0xff;
81 uint8_t high = new_act >> 8;
83 if (low != (tspact_state & 0xff))
84 tpu_enq_move(TPUI_TSP_ACT_L, low);
85 if (high != (tspact_state >> 8))
86 tpu_enq_move(TPUI_TSP_ACT_U, high);
88 tspact_state = new_act;
91 /* Enable one or multiple TSPACT signals */
92 void tsp_act_enable(uint16_t bitmask)
94 uint16_t new_act = tspact_state | bitmask;
95 tsp_act_update(new_act);
98 /* Disable one or multiple TSPACT signals */
99 void tsp_act_disable(uint16_t bitmask)
101 uint16_t new_act = tspact_state & ~bitmask;
102 tsp_act_update(new_act);
105 /* Obtain the current tspact state */
106 uint16_t tsp_act_state(void)
111 /* Toggle one or multiple TSPACT signals */
112 void tsp_act_toggle(uint16_t bitmask)
114 uint16_t new_act = tspact_state ^ bitmask;
115 tsp_act_update(new_act);