summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/s3c24xx.h
blob: 3cd6ae6303de99bbf35c10eaeb38dbb5c1a187f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// license:BSD-3-Clause
// copyright-holders:Tim Schuerewegen
#ifndef MAME_MACHINE_S3C24XX_H
#define MAME_MACHINE_S3C24XX_H

#pragma once


class s3c24xx_peripheral_types // TODO: better name for this
{
protected:
	template <typename A, typename B, typename C> static constexpr auto BITS(A &&x, B &&m, C &&n)
	{
		return (x >> n) & ((uint32_t(1) << (m - n + 1)) - 1);
	}

	template <typename A, typename B, typename C> static constexpr auto CLR_BITS(A &&x, B &&m, C &&n)
	{
		return x & ~(((uint32_t(1) << (m - n + 1)) - 1) << n);
	}

	struct memcon_regs_t
	{
		uint32_t data[0x34/4];
	};

	struct usbhost_regs_t
	{
		uint32_t data[0x5c/4];
	};

	struct lcdpal_regs_t
	{
		uint32_t data[0x400/4];
	};

	struct uart_regs_t
	{
		uint32_t ulcon;
		uint32_t ucon;
		uint32_t ufcon;
		uint32_t umcon;
		uint32_t utrstat;
		uint32_t uerstat;
		uint32_t ufstat;
		uint32_t umstat;
		uint32_t utxh;
		uint32_t urxh;
		uint32_t ubrdiv;
	};

	struct pwm_regs_t
	{
		uint32_t tcfg0;
		uint32_t tcfg1;
		uint32_t tcon;
		uint32_t tcntb0;
		uint32_t tcmpb0;
		uint32_t tcnto0;
		uint32_t tcntb1;
		uint32_t tcmpb1;
		uint32_t tcnto1;
		uint32_t tcntb2;
		uint32_t tcmpb2;
		uint32_t tcnto2;
		uint32_t tcntb3;
		uint32_t tcmpb3;
		uint32_t tcnto3;
		uint32_t tcntb4;
		uint32_t tcnto4;
	};

	struct wdt_regs_t
	{
		uint32_t wtcon;
		uint32_t wtdat;
		uint32_t wtcnt;
	};

	struct iis_regs_t
	{
		uint32_t iiscon;
		uint32_t iismod;
		uint32_t iispsr;
		uint32_t iisfcon;
		uint32_t iisfifo;
	};

	struct rtc_regs_t
	{
		uint32_t rtccon;
		uint32_t ticnt;
		uint32_t reserved[2];
		uint32_t rtcalm;
		uint32_t almsec;
		uint32_t almmin;
		uint32_t almhour;
		uint32_t almday;
		uint32_t almmon;
		uint32_t almyear;
		uint32_t rtcrst;
		uint32_t bcdsec;
		uint32_t bcdmin;
		uint32_t bcdhour;
		uint32_t bcdday;
		uint32_t bcddow;
		uint32_t bcdmon;
		uint32_t bcdyear;
	};

	struct mmc_regs_t
	{
		uint32_t data[0x40/4];
	};

	struct spi_regs_t
	{
		uint32_t spcon;
		uint32_t spsta;
		uint32_t sppin;
		uint32_t sppre;
		uint32_t sptdat;
		uint32_t sprdat;
	};

	struct sdi_regs_t
	{
		uint32_t data[0x44/4];
	};

	struct cam_regs_t
	{
		uint32_t data[0xa4/4];
	};

	struct ac97_regs_t
	{
		uint32_t data[0x20/4];
	};


	struct memcon_t
	{
		void reset();

		memcon_regs_t regs;
	};

	struct usbhost_t
	{
		void reset();

		usbhost_regs_t regs;
	};

	struct lcdpal_t
	{
		lcdpal_regs_t regs;
	};

	struct uart_t
	{
		static constexpr offs_t ULCON   = 0x00 / 4; // UART Line Control
		static constexpr offs_t UCON    = 0x04 / 4; // UART Control
		static constexpr offs_t UFCON   = 0x08 / 4; // UART FIFO Control
		static constexpr offs_t UMCON   = 0x0c / 4; // UART Modem Control
		static constexpr offs_t UTRSTAT = 0x10 / 4; // UART Tx/Rx Status
		static constexpr offs_t UERSTAT = 0x14 / 4; // UART Rx Error Status
		static constexpr offs_t UFSTAT  = 0x18 / 4; // UART FIFO Status
		static constexpr offs_t UMSTAT  = 0x1c / 4; // UART Modem Status
		static constexpr offs_t UTXH    = 0x20 / 4; // UART Transmission Hold
		static constexpr offs_t URXH    = 0x24 / 4; // UART Receive Buffer
		static constexpr offs_t UBRDIV  = 0x28 / 4; // UART Baud Rate Divisor

		void reset();

		uart_regs_t regs;
	};

	struct pwm_t
	{
		static constexpr offs_t TCFG0  = 0x00 / 4; // Timer Configuration
		static constexpr offs_t TCFG1  = 0x04 / 4; // Timer Configuration
		static constexpr offs_t TCON   = 0x08 / 4; // Timer Control
		static constexpr offs_t TCNTB0 = 0x0c / 4; // Timer Count Buffer 0
		static constexpr offs_t TCMPB0 = 0x10 / 4; // Timer Compare Buffer 0
		static constexpr offs_t TCNTO0 = 0x14 / 4; // Timer Count Observation 0
		static constexpr offs_t TCNTB1 = 0x18 / 4; // Timer Count Buffer 1
		static constexpr offs_t TCMPB1 = 0x1c / 4; // Timer Compare Buffer 1
		static constexpr offs_t TCNTO1 = 0x20 / 4; // Timer Count Observation 1
		static constexpr offs_t TCNTB2 = 0x24 / 4; // Timer Count Buffer 2
		static constexpr offs_t TCMPB2 = 0x28 / 4; // Timer Compare Buffer 2
		static constexpr offs_t TCNTO2 = 0x2c / 4; // Timer Count Observation 2
		static constexpr offs_t TCNTB3 = 0x30 / 4; // Timer Count Buffer 3
		static constexpr offs_t TCMPB3 = 0x34 / 4; // Timer Compare Buffer 3
		static constexpr offs_t TCNTO3 = 0x38 / 4; // Timer Count Observation 3
		static constexpr offs_t TCNTB4 = 0x3c / 4; // Timer Count Buffer 4
		static constexpr offs_t TCNTO4 = 0x40 / 4; // Timer Count Observation 4

		void reset();
		uint16_t calc_observation(unsigned ch) const;

		pwm_regs_t regs;
		emu_timer *timer[5];
		uint32_t cnt[5];
		uint32_t cmp[5];
		uint32_t freq[5];
	};

	struct wdt_t
	{
		static constexpr offs_t WTCON = 0x00 / 4; // Watchdog Timer Mode
		static constexpr offs_t WTDAT = 0x04 / 4; // Watchdog Timer Data
		static constexpr offs_t WTCNT = 0x08 / 4; // Watchdog Timer Count

		void reset();
		uint16_t calc_current_count() const;

		wdt_regs_t regs;
		emu_timer *timer;
		uint32_t freq, cnt;
	};

	struct iis_t
	{
		static constexpr offs_t IISCON  = 0x00 / 4; // IIS Control
		static constexpr offs_t IISMOD  = 0x04 / 4; // IIS Mode
		static constexpr offs_t IISPSR  = 0x08 / 4; // IIS Prescaler
		static constexpr offs_t IISFCON = 0x0c / 4; // IIS FIFO Control
		static constexpr offs_t IISFIFO = 0x10 / 4; // IIS FIFO Entry

		void reset();

		iis_regs_t regs;
		emu_timer *timer;
		uint16_t fifo[16/2];
		int fifo_index;
	};

	struct rtc_t
	{
		static constexpr offs_t RTCCON  = 0x00 / 4; // RTC Control
		static constexpr offs_t TICNT   = 0x04 / 4; // Tick Time count
		static constexpr offs_t RTCALM  = 0x10 / 4; // RTC Alarm Control
		static constexpr offs_t ALMSEC  = 0x14 / 4; // Alarm Second
		static constexpr offs_t ALMMIN  = 0x18 / 4; // Alarm Minute
		static constexpr offs_t ALMHOUR = 0x1c / 4; // Alarm Hour
		static constexpr offs_t ALMDAY  = 0x20 / 4; // Alarm Day
		static constexpr offs_t ALMMON  = 0x24 / 4; // Alarm Month
		static constexpr offs_t ALMYEAR = 0x28 / 4; // Alarm Year
		static constexpr offs_t RTCRST  = 0x2c / 4; // RTC Round Reset
		static constexpr offs_t BCDSEC  = 0x30 / 4; // BCD Second
		static constexpr offs_t BCDMIN  = 0x34 / 4; // BCD Minute
		static constexpr offs_t BCDHOUR = 0x38 / 4; // BCD Hour
		static constexpr offs_t BCDDAY  = 0x3c / 4; // BCD Day
		static constexpr offs_t BCDDOW  = 0x40 / 4; // BCD Day of Week
		static constexpr offs_t BCDMON  = 0x44 / 4; // BCD Month
		static constexpr offs_t BCDYEAR = 0x48 / 4; // BCD Year

		void reset();
		void recalc();
		void update();
		bool check_alarm() const;

		rtc_regs_t regs;
		emu_timer *timer_tick_count;
		emu_timer *timer_update;
	};

	struct mmc_t
	{
		void reset();

		mmc_regs_t regs;
	};

	struct spi_t
	{
		static constexpr offs_t SPCON  = 0x00 / 4; // SPI Control
		static constexpr offs_t SPSTA  = 0x04 / 4; // SPI Status
		static constexpr offs_t SPPIN  = 0x08 / 4; // SPI Pin Control
		static constexpr offs_t SPPRE  = 0x0c / 4; // SPI Baud Rate Prescaler
		static constexpr offs_t SPTDAT = 0x10 / 4; // SPI Tx Data
		static constexpr offs_t SPRDAT = 0x14 / 4; // SPI Rx Data

		spi_regs_t regs;
	};

	struct sdi_t
	{
		sdi_regs_t regs;
	};

	struct cam_t
	{
		void reset();

		cam_regs_t regs;
	};

	struct ac97_t
	{
		void reset();

		ac97_regs_t regs;
	};
};

#endif // MAME_MACHINE_S3C24XX_H