1 /* Blackfin Watchdog (WDOG) model.
3 Copyright (C) 2010-2015 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
6 This file is part of simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "dv-sockser.h"
26 #include "dv-bfin_wdog.h"
28 /* XXX: Should we bother emulating the TX/RX FIFOs ? */
34 /* Order after here is important -- matches hardware MMR layout. */
35 bu16 BFIN_MMR_16(ctl);
38 #define mmr_base() offsetof(struct bfin_wdog, ctl)
39 #define mmr_offset(mmr) (offsetof(struct bfin_wdog, mmr) - mmr_base())
41 static const char * const mmr_names[] =
43 "WDOG_CTL", "WDOG_CNT", "WDOG_STAT",
45 #define mmr_name(off) mmr_names[(off) / 4]
48 bfin_wdog_enabled (struct bfin_wdog *wdog)
50 return ((wdog->ctl & WDEN) != WDDIS);
54 bfin_wdog_io_write_buffer (struct hw *me, const void *source,
55 int space, address_word addr, unsigned nr_bytes)
57 struct bfin_wdog *wdog = hw_data (me);
65 value = dv_load_4 (source);
67 value = dv_load_2 (source);
69 mmr_off = addr - wdog->base;
70 valuep = (void *)((unsigned long)wdog + mmr_base() + mmr_off);
79 dv_w1c_2_partial (value16p, value, WDRO);
80 /* XXX: Should enable an event here to handle timeouts. */
84 /* Writes are discarded when enabeld. */
85 if (!bfin_wdog_enabled (wdog))
88 /* Writes to CNT preloads the STAT. */
89 wdog->stat = wdog->cnt;
93 case mmr_offset(stat):
94 /* When enabled, writes to STAT reload the counter. */
95 if (bfin_wdog_enabled (wdog))
96 wdog->stat = wdog->cnt;
97 /* XXX: When disabled, are writes just ignored ? */
105 bfin_wdog_io_read_buffer (struct hw *me, void *dest,
106 int space, address_word addr, unsigned nr_bytes)
108 struct bfin_wdog *wdog = hw_data (me);
114 mmr_off = addr - wdog->base;
115 valuep = (void *)((unsigned long)wdog + mmr_base() + mmr_off);
123 case mmr_offset(ctl):
124 dv_bfin_mmr_require_16 (me, addr, nr_bytes, false);
125 dv_store_2 (dest, *value16p);
128 case mmr_offset(cnt):
129 case mmr_offset(stat):
130 dv_store_4 (dest, *value32p);
137 static const struct hw_port_descriptor bfin_wdog_ports[] =
139 { "reset", WDEV_RESET, 0, output_port, },
140 { "nmi", WDEV_NMI, 0, output_port, },
141 { "gpi", WDEV_GPI, 0, output_port, },
146 bfin_wdog_port_event (struct hw *me, int my_port, struct hw *source,
147 int source_port, int level)
149 struct bfin_wdog *wdog = hw_data (me);
153 wdev = (wdog->ctl & WDEV);
154 if (wdev != WDEV_NONE)
155 hw_port_event (me, wdev, 1);
159 attach_bfin_wdog_regs (struct hw *me, struct bfin_wdog *wdog)
161 address_word attach_address;
163 unsigned attach_size;
164 reg_property_spec reg;
166 if (hw_find_property (me, "reg") == NULL)
167 hw_abort (me, "Missing \"reg\" property");
169 if (!hw_find_reg_array_property (me, "reg", 0, ®))
170 hw_abort (me, "\"reg\" property must contain three addr/size entries");
172 hw_unit_address_to_attach_address (hw_parent (me),
174 &attach_space, &attach_address, me);
175 hw_unit_size_to_attach_size (hw_parent (me), ®.size, &attach_size, me);
177 if (attach_size != BFIN_MMR_WDOG_SIZE)
178 hw_abort (me, "\"reg\" size must be %#x", BFIN_MMR_WDOG_SIZE);
180 hw_attach_address (hw_parent (me),
181 0, attach_space, attach_address, attach_size, me);
183 wdog->base = attach_address;
187 bfin_wdog_finish (struct hw *me)
189 struct bfin_wdog *wdog;
191 wdog = HW_ZALLOC (me, struct bfin_wdog);
193 set_hw_data (me, wdog);
194 set_hw_io_read_buffer (me, bfin_wdog_io_read_buffer);
195 set_hw_io_write_buffer (me, bfin_wdog_io_write_buffer);
196 set_hw_ports (me, bfin_wdog_ports);
197 set_hw_port_event (me, bfin_wdog_port_event);
199 attach_bfin_wdog_regs (me, wdog);
201 /* Initialize the Watchdog. */
205 const struct hw_descriptor dv_bfin_wdog_descriptor[] =
207 {"bfin_wdog", bfin_wdog_finish,},