1 /* Blackfin Enhanced Parallel Port Interface (EPPI) model
2 For "new style" PPIs on BF54x/etc... parts.
4 Copyright (C) 2010-2024 Free Software Foundation, Inc.
5 Contributed by Analog Devices, Inc.
7 This file is part of simulators.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* This must come before any other includes. */
27 #include "dv-bfin_eppi.h"
30 /* XXX: TX is merely a stub. */
34 /* This top portion matches common dv_bfin struct. */
36 struct hw
*dma_master
;
39 struct hw_event
*handler
;
47 /* Order after here is important -- matches hardware MMR layout. */
48 bu16
BFIN_MMR_16(status
);
49 bu16
BFIN_MMR_16(hcount
);
50 bu16
BFIN_MMR_16(hdelay
);
51 bu16
BFIN_MMR_16(vcount
);
52 bu16
BFIN_MMR_16(vdelay
);
53 bu16
BFIN_MMR_16(frame
);
54 bu16
BFIN_MMR_16(line
);
55 bu16
BFIN_MMR_16(clkdiv
);
56 bu32 control
, fs1w_hbl
, fs1p_avpl
, fsw2_lvb
, fs2p_lavf
, clip
, err
;
58 #define mmr_base() offsetof(struct bfin_eppi, status)
59 #define mmr_offset(mmr) (offsetof(struct bfin_eppi, mmr) - mmr_base())
61 static const char * const mmr_names
[] =
63 "EPPI_STATUS", "EPPI_HCOUNT", "EPPI_HDELAY", "EPPI_VCOUNT", "EPPI_VDELAY",
64 "EPPI_FRAME", "EPPI_LINE", "EPPI_CLKDIV", "EPPI_CONTROL", "EPPI_FS1W_HBL",
65 "EPPI_FS1P_AVPL", "EPPI_FS2W_LVB", "EPPI_FS2P_LAVF", "EPPI_CLIP", "EPPI_ERR",
67 #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
70 bfin_eppi_gui_setup (struct bfin_eppi
*eppi
)
72 /* If we are in RX mode, nothing to do. */
73 if (!(eppi
->control
& PORT_DIR
))
76 eppi
->gui_state
= bfin_gui_setup (eppi
->gui_state
,
77 eppi
->control
& PORT_EN
,
84 bfin_eppi_io_write_buffer (struct hw
*me
, const void *source
,
85 int space
, address_word addr
, unsigned nr_bytes
)
87 struct bfin_eppi
*eppi
= hw_data (me
);
94 /* Invalid access mode is higher priority than missing register. */
95 if (!dv_bfin_mmr_require_16_32 (me
, addr
, nr_bytes
, true))
99 value
= dv_load_4 (source
);
101 value
= dv_load_2 (source
);
103 mmr_off
= addr
- eppi
->base
;
104 valuep
= (void *)((uintptr_t)eppi
+ mmr_base() + mmr_off
);
112 case mmr_offset(status
):
113 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, true))
115 dv_w1c_2 (value16p
, value
, 0x1ff);
117 case mmr_offset(hcount
):
118 case mmr_offset(hdelay
):
119 case mmr_offset(vcount
):
120 case mmr_offset(vdelay
):
121 case mmr_offset(frame
):
122 case mmr_offset(line
):
123 case mmr_offset(clkdiv
):
124 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, true))
128 case mmr_offset(control
):
130 bfin_eppi_gui_setup (eppi
);
132 case mmr_offset(fs1w_hbl
):
133 case mmr_offset(fs1p_avpl
):
134 case mmr_offset(fsw2_lvb
):
135 case mmr_offset(fs2p_lavf
):
136 case mmr_offset(clip
):
137 case mmr_offset(err
):
138 if (!dv_bfin_mmr_require_32 (me
, addr
, nr_bytes
, true))
143 dv_bfin_mmr_invalid (me
, addr
, nr_bytes
, true);
151 bfin_eppi_io_read_buffer (struct hw
*me
, void *dest
,
152 int space
, address_word addr
, unsigned nr_bytes
)
154 struct bfin_eppi
*eppi
= hw_data (me
);
160 /* Invalid access mode is higher priority than missing register. */
161 if (!dv_bfin_mmr_require_16_32 (me
, addr
, nr_bytes
, true))
164 mmr_off
= addr
- eppi
->base
;
165 valuep
= (void *)((uintptr_t)eppi
+ mmr_base() + mmr_off
);
173 case mmr_offset(status
):
174 case mmr_offset(hcount
):
175 case mmr_offset(hdelay
):
176 case mmr_offset(vcount
):
177 case mmr_offset(vdelay
):
178 case mmr_offset(frame
):
179 case mmr_offset(line
):
180 case mmr_offset(clkdiv
):
181 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, false))
183 dv_store_2 (dest
, *value16p
);
185 case mmr_offset(control
):
186 case mmr_offset(fs1w_hbl
):
187 case mmr_offset(fs1p_avpl
):
188 case mmr_offset(fsw2_lvb
):
189 case mmr_offset(fs2p_lavf
):
190 case mmr_offset(clip
):
191 case mmr_offset(err
):
192 if (!dv_bfin_mmr_require_32 (me
, addr
, nr_bytes
, false))
194 dv_store_4 (dest
, *value32p
);
197 dv_bfin_mmr_invalid (me
, addr
, nr_bytes
, false);
205 bfin_eppi_dma_read_buffer (struct hw
*me
, void *dest
, int space
,
206 unsigned_word addr
, unsigned nr_bytes
)
208 HW_TRACE_DMA_READ ();
213 bfin_eppi_dma_write_buffer (struct hw
*me
, const void *source
,
214 int space
, unsigned_word addr
,
216 int violate_read_only_section
)
218 struct bfin_eppi
*eppi
= hw_data (me
);
220 HW_TRACE_DMA_WRITE ();
222 return bfin_gui_update (eppi
->gui_state
, source
, nr_bytes
);
225 static const struct hw_port_descriptor bfin_eppi_ports
[] =
227 { "stat", 0, 0, output_port
, },
232 attach_bfin_eppi_regs (struct hw
*me
, struct bfin_eppi
*eppi
)
234 address_word attach_address
;
236 unsigned attach_size
;
237 reg_property_spec reg
;
239 if (hw_find_property (me
, "reg") == NULL
)
240 hw_abort (me
, "Missing \"reg\" property");
242 if (!hw_find_reg_array_property (me
, "reg", 0, ®
))
243 hw_abort (me
, "\"reg\" property must contain three addr/size entries");
245 hw_unit_address_to_attach_address (hw_parent (me
),
247 &attach_space
, &attach_address
, me
);
248 hw_unit_size_to_attach_size (hw_parent (me
), ®
.size
, &attach_size
, me
);
250 if (attach_size
!= BFIN_MMR_EPPI_SIZE
)
251 hw_abort (me
, "\"reg\" size must be %#x", BFIN_MMR_EPPI_SIZE
);
253 hw_attach_address (hw_parent (me
),
254 0, attach_space
, attach_address
, attach_size
, me
);
256 eppi
->base
= attach_address
;
260 bfin_eppi_finish (struct hw
*me
)
262 struct bfin_eppi
*eppi
;
265 eppi
= HW_ZALLOC (me
, struct bfin_eppi
);
267 set_hw_data (me
, eppi
);
268 set_hw_io_read_buffer (me
, bfin_eppi_io_read_buffer
);
269 set_hw_io_write_buffer (me
, bfin_eppi_io_write_buffer
);
270 set_hw_dma_read_buffer (me
, bfin_eppi_dma_read_buffer
);
271 set_hw_dma_write_buffer (me
, bfin_eppi_dma_write_buffer
);
272 set_hw_ports (me
, bfin_eppi_ports
);
274 attach_bfin_eppi_regs (me
, eppi
);
276 /* Initialize the EPPI. */
277 if (hw_find_property (me
, "color"))
278 color
= hw_find_string_property (me
, "color");
281 eppi
->color
= bfin_gui_color (color
);
284 const struct hw_descriptor dv_bfin_eppi_descriptor
[] =
286 {"bfin_eppi", bfin_eppi_finish
,},