1 /* Blackfin Parallel Port Interface (PPI) model
2 For "old style" PPIs on BF53x/etc... parts.
4 Copyright (C) 2010-2019 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/>. */
26 #include "dv-bfin_ppi.h"
29 /* XXX: TX is merely a stub. */
33 /* This top portion matches common dv_bfin struct. */
35 struct hw
*dma_master
;
38 struct hw_event
*handler
;
46 /* Order after here is important -- matches hardware MMR layout. */
47 bu16
BFIN_MMR_16(control
);
48 bu16
BFIN_MMR_16(status
);
49 bu16
BFIN_MMR_16(count
);
50 bu16
BFIN_MMR_16(delay
);
51 bu16
BFIN_MMR_16(frame
);
53 #define mmr_base() offsetof(struct bfin_ppi, control)
54 #define mmr_offset(mmr) (offsetof(struct bfin_ppi, mmr) - mmr_base())
56 static const char * const mmr_names
[] =
58 "PPI_CONTROL", "PPI_STATUS", "PPI_COUNT", "PPI_DELAY", "PPI_FRAME",
60 #define mmr_name(off) mmr_names[(off) / 4]
63 bfin_ppi_gui_setup (struct bfin_ppi
*ppi
)
67 /* If we are in RX mode, nothing to do. */
68 if (!(ppi
->control
& PORT_DIR
))
71 bpp
= bfin_gui_color_depth (ppi
->color
);
72 ppi
->gui_state
= bfin_gui_setup (ppi
->gui_state
,
73 ppi
->control
& PORT_EN
,
74 (ppi
->count
+ 1) / (bpp
/ 8),
80 bfin_ppi_io_write_buffer (struct hw
*me
, const void *source
, int space
,
81 address_word addr
, unsigned nr_bytes
)
83 struct bfin_ppi
*ppi
= hw_data (me
);
88 /* Invalid access mode is higher priority than missing register. */
89 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, true))
92 value
= dv_load_2 (source
);
93 mmr_off
= addr
- ppi
->base
;
94 valuep
= (void *)((unsigned long)ppi
+ mmr_base() + mmr_off
);
100 case mmr_offset(control
):
102 bfin_ppi_gui_setup (ppi
);
104 case mmr_offset(count
):
105 case mmr_offset(delay
):
106 case mmr_offset(frame
):
109 case mmr_offset(status
):
110 dv_w1c_2 (valuep
, value
, ~(1 << 10));
113 dv_bfin_mmr_invalid (me
, addr
, nr_bytes
, true);
121 bfin_ppi_io_read_buffer (struct hw
*me
, void *dest
, int space
,
122 address_word addr
, unsigned nr_bytes
)
124 struct bfin_ppi
*ppi
= hw_data (me
);
128 /* Invalid access mode is higher priority than missing register. */
129 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, false))
132 mmr_off
= addr
- ppi
->base
;
133 valuep
= (void *)((unsigned long)ppi
+ mmr_base() + mmr_off
);
139 case mmr_offset(control
):
140 case mmr_offset(count
):
141 case mmr_offset(delay
):
142 case mmr_offset(frame
):
143 case mmr_offset(status
):
144 dv_store_2 (dest
, *valuep
);
147 dv_bfin_mmr_invalid (me
, addr
, nr_bytes
, false);
155 bfin_ppi_dma_read_buffer (struct hw
*me
, void *dest
, int space
,
156 unsigned_word addr
, unsigned nr_bytes
)
158 HW_TRACE_DMA_READ ();
163 bfin_ppi_dma_write_buffer (struct hw
*me
, const void *source
,
164 int space
, unsigned_word addr
,
166 int violate_read_only_section
)
168 struct bfin_ppi
*ppi
= hw_data (me
);
170 HW_TRACE_DMA_WRITE ();
172 return bfin_gui_update (ppi
->gui_state
, source
, nr_bytes
);
175 static const struct hw_port_descriptor bfin_ppi_ports
[] =
177 { "stat", 0, 0, output_port
, },
182 attach_bfin_ppi_regs (struct hw
*me
, struct bfin_ppi
*ppi
)
184 address_word attach_address
;
186 unsigned attach_size
;
187 reg_property_spec reg
;
189 if (hw_find_property (me
, "reg") == NULL
)
190 hw_abort (me
, "Missing \"reg\" property");
192 if (!hw_find_reg_array_property (me
, "reg", 0, ®
))
193 hw_abort (me
, "\"reg\" property must contain three addr/size entries");
195 hw_unit_address_to_attach_address (hw_parent (me
),
197 &attach_space
, &attach_address
, me
);
198 hw_unit_size_to_attach_size (hw_parent (me
), ®
.size
, &attach_size
, me
);
200 if (attach_size
!= BFIN_MMR_PPI_SIZE
)
201 hw_abort (me
, "\"reg\" size must be %#x", BFIN_MMR_PPI_SIZE
);
203 hw_attach_address (hw_parent (me
),
204 0, attach_space
, attach_address
, attach_size
, me
);
206 ppi
->base
= attach_address
;
210 bfin_ppi_finish (struct hw
*me
)
212 struct bfin_ppi
*ppi
;
215 ppi
= HW_ZALLOC (me
, struct bfin_ppi
);
217 set_hw_data (me
, ppi
);
218 set_hw_io_read_buffer (me
, bfin_ppi_io_read_buffer
);
219 set_hw_io_write_buffer (me
, bfin_ppi_io_write_buffer
);
220 set_hw_dma_read_buffer (me
, bfin_ppi_dma_read_buffer
);
221 set_hw_dma_write_buffer (me
, bfin_ppi_dma_write_buffer
);
222 set_hw_ports (me
, bfin_ppi_ports
);
224 attach_bfin_ppi_regs (me
, ppi
);
226 /* Initialize the PPI. */
227 if (hw_find_property (me
, "color"))
228 color
= hw_find_string_property (me
, "color");
231 ppi
->color
= bfin_gui_color (color
);
234 const struct hw_descriptor dv_bfin_ppi_descriptor
[] =
236 {"bfin_ppi", bfin_ppi_finish
,},