1 /* This file is part of the program GDB, the GNU debugger.
3 Copyright (C) 1998 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 mn103ser - mn103002 I/O ports 0-3.
33 Implements the mn103002 i/o ports as described in the mn103002 user guide.
38 reg = <ioport-addr> <ioport-size> ...
46 /* The I/O ports' registers' address block */
48 struct mn103iop_block
{
55 enum io_port_register_types
{
87 typedef struct _mn10300_ioport
{
88 unsigned8 output
, output_mode
, control
, pin
;
89 struct hw_event
*event
;
95 struct mn103iop_block block
[NR_BLOCKS
];
96 mn10300_ioport port
[NR_PORTS
];
101 /* Finish off the partially created hw device. Attach our local
102 callbacks. Wire up our port names etc */
104 static hw_io_read_buffer_method mn103iop_io_read_buffer
;
105 static hw_io_write_buffer_method mn103iop_io_write_buffer
;
108 attach_mn103iop_regs (struct hw
*me
,
109 struct mn103iop
*io_port
)
112 unsigned_word attach_address
;
114 unsigned attach_size
;
115 reg_property_spec reg
;
117 if (hw_find_property (me
, "reg") == NULL
)
118 hw_abort (me
, "Missing \"reg\" property");
120 for (i
=0; i
< NR_BLOCKS
; ++i
)
122 if (!hw_find_reg_array_property (me
, "reg", i
, ®
))
123 hw_abort (me
, "\"reg\" property must contain five addr/size entries");
124 hw_unit_address_to_attach_address (hw_parent (me
),
129 io_port
->block
[i
].base
= attach_address
;
130 hw_unit_size_to_attach_size (hw_parent (me
),
133 io_port
->block
[i
].bound
= attach_address
+ (attach_size
- 1);
134 hw_attach_address (hw_parent (me
),
136 attach_space
, attach_address
, attach_size
,
142 mn103iop_finish (struct hw
*me
)
144 struct mn103iop
*io_port
;
147 io_port
= HW_ZALLOC (me
, struct mn103iop
);
148 set_hw_data (me
, io_port
);
149 set_hw_io_read_buffer (me
, mn103iop_io_read_buffer
);
150 set_hw_io_write_buffer (me
, mn103iop_io_write_buffer
);
152 /* Attach ourself to our parent bus */
153 attach_mn103iop_regs (me
, io_port
);
155 /* Initialize the i/o port registers. */
156 for ( i
=0; i
<NR_PORTS
; ++i
)
158 io_port
->port
[i
].output
= 0;
159 io_port
->port
[i
].output_mode
= 0;
160 io_port
->port
[i
].control
= 0;
161 io_port
->port
[i
].pin
= 0;
171 decode_addr (struct hw
*me
,
172 struct mn103iop
*io_port
,
173 unsigned_word address
)
175 unsigned_word offset
;
176 offset
= address
- io_port
->block
[0].base
;
179 case 0x00: return P0OUT
;
180 case 0x01: return P1OUT
;
181 case 0x04: return P2OUT
;
182 case 0x05: return P3OUT
;
183 case 0x20: return P0MD
;
184 case 0x21: return P1MD
;
185 case 0x24: return P2MD
;
186 case 0x25: return P3MD
;
187 case 0x44: return P2SS
;
188 case 0x48: return P4SS
;
189 case 0x60: return P0DIR
;
190 case 0x61: return P1DIR
;
191 case 0x64: return P2DIR
;
192 case 0x65: return P3DIR
;
193 case 0x80: return P0IN
;
194 case 0x81: return P1IN
;
195 case 0x84: return P2IN
;
196 case 0x85: return P3IN
;
199 hw_abort (me
, "bad address");
207 read_output_reg (struct hw
*me
,
208 struct mn103iop
*io_port
,
209 unsigned_word io_port_reg
,
215 *(unsigned8
*)dest
= io_port
->port
[io_port_reg
].output
;
219 hw_abort (me
, "bad read size of %d bytes from P%dOUT.", nr_bytes
,
226 read_output_mode_reg (struct hw
*me
,
227 struct mn103iop
*io_port
,
228 unsigned_word io_port_reg
,
234 /* check if there are fields which can't be written and
235 take appropriate action depending what bits are set */
236 *(unsigned8
*)dest
= io_port
->port
[io_port_reg
].output_mode
;
240 hw_abort (me
, "bad read size of %d bytes to P%dMD.", nr_bytes
,
247 read_control_reg (struct hw
*me
,
248 struct mn103iop
*io_port
,
249 unsigned_word io_port_reg
,
255 *(unsigned8
*)dest
= io_port
->port
[io_port_reg
].control
;
259 hw_abort (me
, "bad read size of %d bytes to P%dDIR.", nr_bytes
,
266 read_pin_reg (struct hw
*me
,
267 struct mn103iop
*io_port
,
268 unsigned_word io_port_reg
,
274 *(unsigned8
*)dest
= io_port
->port
[io_port_reg
].pin
;
278 hw_abort (me
, "bad read size of %d bytes to P%dIN.", nr_bytes
,
285 read_dedicated_control_reg (struct hw
*me
,
286 struct mn103iop
*io_port
,
287 unsigned_word io_port_reg
,
293 /* select on io_port_reg: */
294 if ( io_port_reg
== P2SS
)
296 *(unsigned8
*)dest
= io_port
->p2ss
;
300 *(unsigned8
*)dest
= io_port
->p4ss
;
305 hw_abort (me
, "bad read size of %d bytes to PSS.", nr_bytes
);
311 mn103iop_io_read_buffer (struct hw
*me
,
317 struct mn103iop
*io_port
= hw_data (me
);
318 enum io_port_register_types io_port_reg
;
319 HW_TRACE ((me
, "read 0x%08lx %d", (long) base
, (int) nr_bytes
));
321 io_port_reg
= decode_addr (me
, io_port
, base
);
324 /* Port output registers */
329 read_output_reg(me
, io_port
, io_port_reg
-P0OUT
, dest
, nr_bytes
);
332 /* Port output mode registers */
337 read_output_mode_reg(me
, io_port
, io_port_reg
-P0MD
, dest
, nr_bytes
);
340 /* Port control registers */
345 read_control_reg(me
, io_port
, io_port_reg
-P0DIR
, dest
, nr_bytes
);
348 /* Port pin registers */
352 read_pin_reg(me
, io_port
, io_port_reg
-P0IN
, dest
, nr_bytes
);
357 read_dedicated_control_reg(me
, io_port
, io_port_reg
, dest
, nr_bytes
);
361 hw_abort(me
, "invalid address");
369 write_output_reg (struct hw
*me
,
370 struct mn103iop
*io_port
,
371 unsigned_word io_port_reg
,
377 io_port
->port
[io_port_reg
].output
= *(unsigned16
*)source
;
381 hw_abort (me
, "bad read size of %d bytes from P%dOUT.", nr_bytes
,
388 write_output_mode_reg (struct hw
*me
,
389 struct mn103iop
*io_port
,
390 unsigned_word io_port_reg
,
396 /* check if there are fields which can't be written and
397 take appropriate action depending what bits are set */
398 io_port
->port
[io_port_reg
].output_mode
= *(unsigned8
*)source
;
402 hw_abort (me
, "bad write size of %d bytes to P%dMD.", nr_bytes
,
409 write_control_reg (struct hw
*me
,
410 struct mn103iop
*io_port
,
411 unsigned_word io_port_reg
,
417 io_port
->port
[io_port_reg
].control
= *(unsigned8
*)source
;
421 hw_abort (me
, "bad write size of %d bytes to P%dDIR.", nr_bytes
,
428 write_dedicated_control_reg (struct hw
*me
,
429 struct mn103iop
*io_port
,
430 unsigned_word io_port_reg
,
436 /* select on io_port_reg: */
437 if ( io_port_reg
== P2SS
)
439 io_port
->p2ss
= *(unsigned8
*)source
;
443 io_port
->p4ss
= *(unsigned8
*)source
;
448 hw_abort (me
, "bad write size of %d bytes to PSS.", nr_bytes
);
454 mn103iop_io_write_buffer (struct hw
*me
,
460 struct mn103iop
*io_port
= hw_data (me
);
461 enum io_port_register_types io_port_reg
;
462 HW_TRACE ((me
, "write 0x%08lx %d", (long) base
, (int) nr_bytes
));
464 io_port_reg
= decode_addr (me
, io_port
, base
);
467 /* Port output registers */
472 write_output_reg(me
, io_port
, io_port_reg
-P0OUT
, source
, nr_bytes
);
475 /* Port output mode registers */
480 write_output_mode_reg(me
, io_port
, io_port_reg
-P0MD
, source
, nr_bytes
);
483 /* Port control registers */
488 write_control_reg(me
, io_port
, io_port_reg
-P0DIR
, source
, nr_bytes
);
491 /* Port pin registers */
495 hw_abort(me
, "Cannot write to pin register.");
500 write_dedicated_control_reg(me
, io_port
, io_port_reg
, source
, nr_bytes
);
504 hw_abort(me
, "invalid address");
511 const struct hw_descriptor dv_mn103iop_descriptor
[] = {
512 { "mn103iop", mn103iop_finish
, },