Previous 15994 Revisions Next

r13745 Tuesday 27th December, 2011 at 16:04:42 UTC by Tim Schuerewegen
s3c24xx: lots of changes, for future Happy Fish 302-in-1 and Palm Z22 drivers
[src/emu/machine]s3c2400.h s3c2410.c s3c2410.h s3c2440.h s3c24xx.c
[src/mame/drivers]ghosteo.c
[src/mess/drivers]gizmondo.c hp49gp.c

src/mame/drivers/ghosteo.c
r13744r13745
8181      : driver_device(mconfig, type, tag) { }
8282
8383   UINT32 *m_system_memory;
84   UINT32 *m_steppingstone;
8584   int m_security_count;
8685   UINT32 m_bballoon_port[20];
8786   struct nand_t m_nand;
r13744r13745
11111024-ch external interrupts Controller (Wake-up source 16-ch)
112111*/
113112
113// GPIO
114
114115static const UINT8 security_data[] = { 0x01, 0xC4, 0xFF, 0x22 };
115116
116
117static UINT32 s3c2410_gpio_port_r( device_t *device, int port)
117static UINT32 s3c2410_gpio_port_r( device_t *device, int port, UINT32 mask)
118118{
119119   ghosteo_state *state = device->machine().driver_data<ghosteo_state>();
120120   UINT32 data = state->m_bballoon_port[port];
r13744r13745
135135   return data;
136136}
137137
138static void s3c2410_gpio_port_w( device_t *device, int port, UINT32 data)
138static void s3c2410_gpio_port_w( device_t *device, int port, UINT32 mask, UINT32 data)
139139{
140140   ghosteo_state *state = device->machine().driver_data<ghosteo_state>();
141141   UINT32 old_value = state->m_bballoon_port[port];
r13744r13745
165165   }
166166}
167167
168// CORE
169
170/*
171
172OM[1:0] = 00b : Enable NAND flash controller auto boot mode
173
174NAND flash memory page size should be 512Bytes.
175
176NCON : NAND flash memory address step selection
1770 : 3 Step addressing
1781 : 4 Step addressing
179
180*/
181
182static int s3c2410_core_pin_r( device_t *device, int pin)
183{
184   int data = 0;
185   switch (pin)
186   {
187      case S3C2410_CORE_PIN_NCON : data = 1; break;
188      case S3C2410_CORE_PIN_OM0  : data = 0; break;
189      case S3C2410_CORE_PIN_OM1  : data = 0; break;
190   }
191   return data;
192}
193
194// NAND
195
168196static WRITE8_DEVICE_HANDLER( s3c2410_nand_command_w )
169197{
170198   ghosteo_state *state = device->machine().driver_data<ghosteo_state>();
r13744r13745
276304   logerror( "s3c2410_nand_data_w %02X\n", data);
277305}
278306
307// I2C
308
279309static WRITE_LINE_DEVICE_HANDLER( s3c2410_i2c_scl_w )
280310{
281311   device_t *i2cmem = device->machine().device( "i2cmem");
r13744r13745
316346}
317347
318348static ADDRESS_MAP_START( bballoon_map, AS_PROGRAM, 32 )
319   AM_RANGE(0x00000000, 0x00000fff) AM_RAM AM_BASE_MEMBER(ghosteo_state, m_steppingstone) AM_MIRROR(0x40000000)
320349   AM_RANGE(0x10000000, 0x10000003) AM_READ_PORT("10000000")
321350   AM_RANGE(0x10100000, 0x10100003) AM_READ_PORT("10100000")
322351   AM_RANGE(0x10200000, 0x10200003) AM_READ_PORT("10200000")
r13744r13745
382411   PORT_BIT( 0xFFFFFF50, IP_ACTIVE_LOW, IPT_UNUSED )
383412INPUT_PORTS_END
384413
385/*
386static NAND_INTERFACE( bballoon_nand_intf )
387{
388    DEVCB_DEVICE_LINE("s3c2410", s3c2410_pin_frnb_w)
389};
390*/
391
392414static const s3c2410_interface bballoon_s3c2410_intf =
393415{
416   // CORE (pin read / pin write)
417   { s3c2410_core_pin_r, NULL },
394418   // GPIO (port read / port write)
395419   { s3c2410_gpio_port_r, s3c2410_gpio_port_w },
396420   // I2C (scl write / sda read / sda write)
r13744r13745
399423   { NULL },
400424   // I2S (data write)
401425   { NULL },
402   // NAND (command write, address write, data read, data write)
426   // NAND (command write / address write / data read / data write)
403427   { s3c2410_nand_command_w, s3c2410_nand_address_w, s3c2410_nand_data_r, s3c2410_nand_data_w }
404428};
405429
r13744r13745
549573
550574static DRIVER_INIT( bballoon )
551575{
552   ghosteo_state *state = machine.driver_data<ghosteo_state>();
553   memcpy( state->m_steppingstone, machine.region( "user1")->base(), 4 * 1024);
554576}
555577
556578GAME( 2003, bballoon, 0, bballoon, bballoon, bballoon, ROT0, "Eolith", "BnB Arcade", GAME_NO_SOUND )
src/emu/machine/s3c2400.h
r13744r13745
3939    TYPE DEFINITIONS
4040*******************************************************************************/
4141
42typedef UINT32 (*s3c24xx_gpio_port_r_func)( device_t *device, int port);
43typedef void (*s3c24xx_gpio_port_w_func)( device_t *device, int port, UINT32 data);
42typedef UINT32 (*s3c24xx_gpio_port_r_func)( device_t *device, int port, UINT32 mask);
43typedef void (*s3c24xx_gpio_port_w_func)( device_t *device, int port, UINT32 mask, UINT32 data);
4444
45typedef int (*s3c24xx_core_pin_r_func)( device_t *device, int pin);
46typedef void (*s3c24xx_core_pin_w_func)( device_t *device, int pin, int data);
47
48typedef struct _s3c2400_interface_core s3c2400_interface_core;
49struct _s3c2400_interface_core
50{
51   s3c24xx_core_pin_r_func pin_r;
52   s3c24xx_core_pin_w_func pin_w;
53};
54
4555typedef struct _s3c2400_interface_gpio s3c2400_interface_gpio;
4656struct _s3c2400_interface_gpio
4757{
r13744r13745
7888typedef struct _s3c2400_interface s3c2400_interface;
7989struct _s3c2400_interface
8090{
91   s3c2400_interface_core core;
8192   s3c2400_interface_gpio gpio;
8293   s3c2400_interface_i2c i2c;
8394   s3c2400_interface_adc adc;
r13744r13745
380391#define S3C24XX_GPIO_PORT_F S3C2400_GPIO_PORT_F
381392#define S3C24XX_GPIO_PORT_G S3C2400_GPIO_PORT_G
382393
394#define S3C24XX_UART_COUNT  2
395#define S3C24XX_DMA_COUNT   4
396#define S3C24XX_SPI_COUNT   1
397
383398/*******************************************************************************
384399    TYPE DEFINITIONS
385400*******************************************************************************/
r13744r13745
707722   s3c24xx_memcon_t memcon;
708723   s3c24xx_usbhost_t usbhost;
709724   s3c24xx_irq_t irq;
710   s3c24xx_dma_t dma[4];
725   s3c24xx_dma_t dma[S3C24XX_DMA_COUNT];
711726   s3c24xx_clkpow_t clkpow;
712727   s3c24xx_lcd_t lcd;
713728   s3c24xx_lcdpal_t lcdpal;
714   s3c24xx_uart_t uart[2];
729   s3c24xx_uart_t uart[S3C24XX_UART_COUNT];
715730   s3c24xx_pwm_t pwm;
716731   s3c24xx_usbdev_t usbdev;
717732   s3c24xx_wdt_t wdt;
r13744r13745
720735   s3c24xx_gpio_t gpio;
721736   s3c24xx_rtc_t rtc;
722737   s3c24xx_adc_t adc;
723   s3c24xx_spi_t spi[1];
738   s3c24xx_spi_t spi[S3C24XX_SPI_COUNT];
724739   s3c24xx_mmc_t mmc;
725740} s3c24xx_t;
726741
src/emu/machine/s3c2410.c
r13744r13745
104104
105105void s3c2410_nand_calculate_mecc( UINT8 *data, UINT32 size, UINT8 *mecc)
106106{
107   mecc[0] = mecc[1] = mecc[2] = mecc[3] = 0;
107   mecc[0] = mecc[1] = mecc[2] = mecc[3] = 0xFF;
108108   for (int i = 0; i < size; i++) nand_update_mecc( mecc, i, data[i]);
109109}
110110
src/emu/machine/s3c2410.h
r13744r13745
3434   S3C2410_GPIO_PORT_H
3535};
3636
37enum
38{
39   S3C2410_CORE_PIN_NCON = 0,
40   S3C2410_CORE_PIN_OM0,
41   S3C2410_CORE_PIN_OM1
42};
43
3744DECLARE_LEGACY_DEVICE(S3C2410, s3c2410);
3845
3946READ32_DEVICE_HANDLER( s3c2410_lcd_r );
r13744r13745
4249    TYPE DEFINITIONS
4350*******************************************************************************/
4451
45typedef UINT32 (*s3c24xx_gpio_port_r_func)( device_t *device, int port);
46typedef void (*s3c24xx_gpio_port_w_func)( device_t *device, int port, UINT32 data);
52typedef UINT32 (*s3c24xx_gpio_port_r_func)( device_t *device, int port, UINT32 mask);
53typedef void (*s3c24xx_gpio_port_w_func)( device_t *device, int port, UINT32 mask, UINT32 data);
4754
55typedef int (*s3c24xx_core_pin_r_func)( device_t *device, int pin);
56typedef void (*s3c24xx_core_pin_w_func)( device_t *device, int pin, int data);
57
58typedef struct _s3c2410_interface_core s3c2410_interface_core;
59struct _s3c2410_interface_core
60{
61   s3c24xx_core_pin_r_func pin_r;
62   s3c24xx_core_pin_w_func pin_w;
63};
64
4865typedef struct _s3c2410_interface_gpio s3c2410_interface_gpio;
4966struct _s3c2410_interface_gpio
5067{
r13744r13745
90107typedef struct _s3c2410_interface s3c2410_interface;
91108struct _s3c2410_interface
92109{
110   s3c2410_interface_core core;
93111   s3c2410_interface_gpio gpio;
94112   s3c2410_interface_i2c i2c;
95113   s3c2410_interface_adc adc;
r13744r13745
461479#define S3C24XX_GPIO_PORT_G S3C2410_GPIO_PORT_G
462480#define S3C24XX_GPIO_PORT_H S3C2410_GPIO_PORT_H
463481
482#define S3C24XX_CORE_PIN_NCON S3C2410_CORE_PIN_NCON
483#define S3C24XX_CORE_PIN_OM0  S3C2410_CORE_PIN_OM0
484#define S3C24XX_CORE_PIN_OM1  S3C2410_CORE_PIN_OM1
485
486#define S3C24XX_UART_COUNT  3
487#define S3C24XX_DMA_COUNT   4
488#define S3C24XX_SPI_COUNT   2
489
464490/*******************************************************************************
465491    TYPE DEFINITIONS
466492*******************************************************************************/
r13744r13745
618644   UINT32 gpadat;
619645   UINT32 pad_08;
620646   UINT32 pad_0c;
621   UINT32 gpbbon;
647   UINT32 gpbcon;
622648   UINT32 gpbdat;
623649   UINT32 gpbup;
624650   UINT32 pad_1c;
r13744r13745
765791{
766792   s3c24xx_nand_regs_t regs;
767793   UINT8 mecc[3];
768   int pos;
794   int ecc_pos, data_count;
769795} s3c24xx_nand_t;
770796
771797typedef struct
r13744r13745
839865typedef struct
840866{
841867   const s3c2410_interface *iface;
868   UINT8 steppingstone[4*1024];
842869   s3c24xx_memcon_t memcon;
843870   s3c24xx_usbhost_t usbhost;
844871   s3c24xx_irq_t irq;
845   s3c24xx_dma_t dma[4];
872   s3c24xx_dma_t dma[S3C24XX_DMA_COUNT];
846873   s3c24xx_clkpow_t clkpow;
847874   s3c24xx_lcd_t lcd;
848875   s3c24xx_lcdpal_t lcdpal;
849876   s3c24xx_nand_t nand;
850   s3c24xx_uart_t uart[3];
877   s3c24xx_uart_t uart[S3C24XX_UART_COUNT];
851878   s3c24xx_pwm_t pwm;
852879   s3c24xx_usbdev_t usbdev;
853880   s3c24xx_wdt_t wdt;
r13744r13745
856883   s3c24xx_gpio_t gpio;
857884   s3c24xx_rtc_t rtc;
858885   s3c24xx_adc_t adc;
859   s3c24xx_spi_t spi[2];
886   s3c24xx_spi_t spi[S3C24XX_SPI_COUNT];
860887   s3c24xx_sdi_t sdi;
861888} s3c24xx_t;
862889
src/emu/machine/s3c2440.h
r13744r13745
3333   S3C2440_GPIO_PORT_J
3434};
3535
36enum
37{
38   S3C2440_CORE_PIN_NCON = 0,
39   S3C2440_CORE_PIN_OM0,
40   S3C2440_CORE_PIN_OM1
41};
42
3643DECLARE_LEGACY_DEVICE(S3C2440, s3c2440);
3744
3845/*******************************************************************************
3946    TYPE DEFINITIONS
4047*******************************************************************************/
4148
42typedef UINT32 (*s3c24xx_gpio_port_r_func)( device_t *device, int port);
43typedef void (*s3c24xx_gpio_port_w_func)( device_t *device, int port, UINT32 data);
49typedef UINT32 (*s3c24xx_gpio_port_r_func)( device_t *device, int port, UINT32 mask);
50typedef void (*s3c24xx_gpio_port_w_func)( device_t *device, int port, UINT32 mask, UINT32 data);
4451
52typedef int (*s3c24xx_core_pin_r_func)( device_t *device, int pin);
53typedef void (*s3c24xx_core_pin_w_func)( device_t *device, int pin, int data);
54
55typedef struct _s3c2440_interface_core s3c2440_interface_core;
56struct _s3c2440_interface_core
57{
58   s3c24xx_core_pin_r_func pin_r;
59   s3c24xx_core_pin_w_func pin_w;
60};
61
4562typedef struct _s3c2440_interface_gpio s3c2440_interface_gpio;
4663struct _s3c2440_interface_gpio
4764{
r13744r13745
87104typedef struct _s3c2440_interface s3c2440_interface;
88105struct _s3c2440_interface
89106{
107   s3c2440_interface_core core;
90108   s3c2440_interface_gpio gpio;
91109   s3c2440_interface_i2c i2c;
92110   s3c2440_interface_adc adc;
r13744r13745
489507#define S3C24XX_GPIO_PORT_H S3C2440_GPIO_PORT_H
490508#define S3C24XX_GPIO_PORT_J S3C2440_GPIO_PORT_J
491509
510#define S3C24XX_CORE_PIN_NCON S3C2440_CORE_PIN_NCON
511#define S3C24XX_CORE_PIN_OM0  S3C2440_CORE_PIN_OM0
512#define S3C24XX_CORE_PIN_OM1  S3C2440_CORE_PIN_OM1
513
514#define S3C24XX_UART_COUNT  3
515#define S3C24XX_DMA_COUNT   4
516#define S3C24XX_SPI_COUNT   2
517
492518/*******************************************************************************
493519    TYPE DEFINITIONS
494520*******************************************************************************/
r13744r13745
663689   UINT32 gpadat;
664690   UINT32 pad_08;
665691   UINT32 pad_0c;
666   UINT32 gpbbon;
692   UINT32 gpbcon;
667693   UINT32 gpbdat;
668694   UINT32 gpbup;
669695   UINT32 pad_1c;
r13744r13745
824850   s3c24xx_nand_regs_t regs;
825851   UINT8 mecc[4];
826852   UINT8 secc[2];
827   int pos;
853   int ecc_pos, data_count;
828854} s3c24xx_nand_t;
829855
830856typedef struct
r13744r13745
907933typedef struct
908934{
909935   const s3c2440_interface *iface;
936   UINT8 steppingstone[4*1024];
910937   s3c24xx_memcon_t memcon;
911938   s3c24xx_usbhost_t usbhost;
912939   s3c24xx_irq_t irq;
913   s3c24xx_dma_t dma[4];
940   s3c24xx_dma_t dma[S3C24XX_DMA_COUNT];
914941   s3c24xx_clkpow_t clkpow;
915942   s3c24xx_lcd_t lcd;
916943   s3c24xx_lcdpal_t lcdpal;
917944   s3c24xx_nand_t nand;
918945   s3c24xx_cam_t cam;
919   s3c24xx_uart_t uart[3];
946   s3c24xx_uart_t uart[S3C24XX_UART_COUNT];
920947   s3c24xx_pwm_t pwm;
921948   s3c24xx_usbdev_t usbdev;
922949   s3c24xx_wdt_t wdt;
r13744r13745
925952   s3c24xx_gpio_t gpio;
926953   s3c24xx_rtc_t rtc;
927954   s3c24xx_adc_t adc;
928   s3c24xx_spi_t spi[2];
955   s3c24xx_spi_t spi[S3C24XX_SPI_COUNT];
929956   s3c24xx_sdi_t sdi;
930957   s3c24xx_ac97_t ac97;
931958} s3c24xx_t;
src/emu/machine/s3c24xx.c
r13744r13745
121121
122122static void s3c24xx_reset( device_t *device)
123123{
124   fatalerror( "s3c24xx_reset\n");
124   device_t *cpu = device->machine().device("maincpu");
125   verboselog( device->machine(), 1, "reset\n");
126   cpu->reset();
127   device->reset();
125128}
126129
130INLINE int iface_core_pin_r( device_t *device, int pin)
131{
132   s3c24xx_t *s3c24xx = get_token( device);
133   if (s3c24xx->iface->core.pin_r)
134   {
135      return (s3c24xx->iface->core.pin_r)( device, pin);
136   }
137   else
138   {
139      return 0;
140   }
141}
142
127143/* LCD Controller */
128144
145static void s3c24xx_lcd_reset( device_t *device)
146{
147   s3c24xx_t *s3c24xx = get_token( device);
148   s3c24xx_lcd_t *lcd = &s3c24xx->lcd;
149   memset( &lcd->regs, 0, sizeof( lcd->regs));
150   #if defined(DEVICE_S3C2410)
151   lcd->regs.lcdintmsk = 3;
152   lcd->regs.lpcsel = 4;
153   #elif defined(DEVICE_S3C2440)
154   lcd->regs.lcdintmsk = 3;
155   lcd->regs.tconsel = 0x0F84;
156   #endif
157   lcd->vramaddr_cur = lcd->vramaddr_max = 0;
158   lcd->offsize = 0;
159   lcd->pagewidth_cur = lcd->pagewidth_max = 0;
160   lcd->bppmode = 0;
161   lcd->bswp = lcd->hwswp = 0;
162   lcd->vpos = lcd->hpos = 0;
163   lcd->framerate = 0;
164   lcd->tpal = 0;
165   lcd->hpos_min = lcd->hpos_max = lcd->vpos_min = lcd->vpos_max = 0;
166   lcd->dma_data = lcd->dma_bits = 0;
167   lcd->timer->adjust( attotime::never);
168}
169
129170static rgb_t s3c24xx_get_color_tft_16( device_t *device, UINT16 data)
130171{
131172   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
225266   s3c24xx->lcd.offsize = BITS( s3c24xx->lcd.regs.lcdsaddr3, 21, 11);
226267   s3c24xx->lcd.pagewidth_cur = 0;
227268   s3c24xx->lcd.pagewidth_max = BITS( s3c24xx->lcd.regs.lcdsaddr3, 10, 0);
269   if (s3c24xx->lcd.pagewidth_max == 0)
270   {
271      if (s3c24xx->lcd.bppmode == S3C24XX_BPPMODE_STN_12_P)
272      {
273         s3c24xx->lcd.pagewidth_max = (s3c24xx->lcd.hpos_max - s3c24xx->lcd.hpos_min + 1) / 16 * 12;
274      }
275   }
228276   verboselog( device->machine(), 3, "LCD - vramaddr %08X %08X offsize %08X pagewidth %08X\n", s3c24xx->lcd.vramaddr_cur, s3c24xx->lcd.vramaddr_max, s3c24xx->lcd.offsize, s3c24xx->lcd.pagewidth_max);
229277   s3c24xx->lcd.dma_data = 0;
230278   s3c24xx->lcd.dma_bits = 0;
r13744r13745
233281static void s3c24xx_lcd_dma_init( device_t *device)
234282{
235283   s3c24xx_t *s3c24xx = get_token( device);
284   s3c24xx->lcd.bppmode = BITS( s3c24xx->lcd.regs.lcdcon1, 4, 1);
236285   s3c24xx_lcd_dma_reload( device);
237   s3c24xx->lcd.bppmode = BITS( s3c24xx->lcd.regs.lcdcon1, 4, 1);
238286   s3c24xx->lcd.bswp = BIT( s3c24xx->lcd.regs.lcdcon5, 1);
239287   s3c24xx->lcd.hwswp = BIT( s3c24xx->lcd.regs.lcdcon5, 0);
240288   s3c24xx->lcd.tpal = s3c24xx->lcd.regs.tpal;
r13744r13745
761809static UINT32 s3c24xx_video_update( device_t *device, screen_device *screen, bitmap_t *bitmap, const rectangle *cliprect)
762810{
763811   s3c24xx_t *s3c24xx = get_token( device);
764   if (s3c24xx->lcd.framerate >= 1195)
812   if (s3c24xx->lcd.regs.lcdcon1 & (1 << 0))
765813   {
766      bitmap_blend( bitmap, s3c24xx->lcd.bitmap[0], s3c24xx->lcd.bitmap[1]);
767      copybitmap( s3c24xx->lcd.bitmap[1], s3c24xx->lcd.bitmap[0], 0, 0, 0, 0, cliprect);
814      if (s3c24xx->lcd.framerate >= 1195)
815      {
816         bitmap_blend( bitmap, s3c24xx->lcd.bitmap[0], s3c24xx->lcd.bitmap[1]);
817         copybitmap( s3c24xx->lcd.bitmap[1], s3c24xx->lcd.bitmap[0], 0, 0, 0, 0, cliprect);
818      }
819      else
820      {
821         copybitmap( bitmap, s3c24xx->lcd.bitmap[0], 0, 0, 0, 0, cliprect);
822      }
823      s3c24xx_lcd_dma_init( device);
768824   }
769   else
770   {
771      copybitmap( bitmap, s3c24xx->lcd.bitmap[0], 0, 0, 0, 0, cliprect);
772   }
773   s3c24xx_lcd_dma_init( device);
774825   return 0;
775826}
776827
r13744r13745
809860   return data;
810861}
811862
812static void s3c24xx_lcd_configure_tft( device_t *device)
863static int s3c24xx_lcd_configure_tft( device_t *device)
813864{
814865   s3c24xx_t *s3c24xx = get_token( device);
815866   screen_device *screen = device->machine().primary_screen;
r13744r13745
847898   s3c24xx->lcd.vpos_min = (vspw + 1) + (vbpd + 1);
848899   s3c24xx->lcd.vpos_max = s3c24xx->lcd.vpos_min + (lineval + 1) - 1;
849900   screen->configure( width, height, visarea, HZ_TO_ATTOSECONDS( s3c24xx->lcd.framerate));
901   return TRUE;
850902}
851903
852static void s3c24xx_lcd_configure_stn( device_t *device)
904static int s3c24xx_lcd_configure_stn( device_t *device)
853905{
854906   s3c24xx_t *s3c24xx = get_token( device);
855907   screen_device *screen = device->machine().primary_screen;
r13744r13745
868920   wlh = BITS( s3c24xx->lcd.regs.lcdcon4, 1, 0);
869921   hclk = s3c24xx_get_hclk( device);
870922   verboselog( device->machine(), 3, "LCD - pnrmode %d bppmode %d clkval %d lineval %d wdly %d hozval %d lineblank %d wlh %d hclk %d\n", pnrmode, bppmode, clkval, lineval, wdly, hozval, lineblank, wlh, hclk);
923   if (clkval == 0)
924   {
925      return FALSE;
926   }
871927   vclk = (double)(hclk / ((clkval + 0) * 2));
872928   verboselog( device->machine(), 3, "LCD - vclk %f\n", vclk);
873929   framerate = 1 / (((1 / vclk) * (hozval + 1) + (1 / hclk) * ((1 << (4 + wlh)) + (1 << (4 + wdly)) + (lineblank * 8))) * (lineval + 1));
r13744r13745
892948   s3c24xx->lcd.vpos_min = 0;
893949   s3c24xx->lcd.vpos_max = height - 1;
894950   screen->configure( width, height, visarea, HZ_TO_ATTOSECONDS( s3c24xx->lcd.framerate));
951   return TRUE;
895952}
896953
897static void s3c24xx_lcd_configure( device_t *device)
954static int s3c24xx_lcd_configure( device_t *device)
898955{
899956   s3c24xx_t *s3c24xx = get_token( device);
900957   UINT32 bppmode;
r13744r13745
902959   bppmode = BITS( s3c24xx->lcd.regs.lcdcon1, 4, 1);
903960   if ((bppmode & (1 << 3)) == 0)
904961   {
905      s3c24xx_lcd_configure_stn( device);
962      return s3c24xx_lcd_configure_stn( device);
906963   }
907964   else
908965   {
909      s3c24xx_lcd_configure_tft( device);
966      return s3c24xx_lcd_configure_tft( device);
910967   }
911968}
912969
r13744r13745
915972   s3c24xx_t *s3c24xx = get_token( device);
916973   screen_device *screen = device->machine().primary_screen;
917974   verboselog( device->machine(), 1, "LCD start\n");
918   s3c24xx_lcd_configure( device);
919   s3c24xx_lcd_dma_init( device);
920   s3c24xx->lcd.timer->adjust( screen->time_until_pos( s3c24xx->lcd.vpos_min, s3c24xx->lcd.hpos_min));
975   if (s3c24xx_lcd_configure( device))
976   {
977      s3c24xx_lcd_dma_init( device);
978      s3c24xx->lcd.timer->adjust( screen->time_until_pos( s3c24xx->lcd.vpos_min, s3c24xx->lcd.hpos_min));
979   }
921980}
922981
923982static void s3c24xx_lcd_stop( device_t *device)
r13744r13745
9831042
9841043/* Clock & Power Management */
9851044
1045static void s3c24xx_clkpow_reset( device_t *device)
1046{
1047   s3c24xx_t *s3c24xx = get_token( device);
1048   s3c24xx_clkpow_t *clkpow = &s3c24xx->clkpow;
1049   memset( &clkpow->regs, 0, sizeof( clkpow->regs));
1050   #if defined(DEVICE_S3C2400)
1051   clkpow->regs.locktime = 0x00FFFFFF;
1052   clkpow->regs.mpllcon  = 0x0005C080;
1053   clkpow->regs.upllcon  = 0x00028080;
1054   clkpow->regs.clkcon   = 0x0000FFF8;
1055   #elif defined(DEVICE_S3C2410)
1056   clkpow->regs.locktime = 0x00FFFFFF;
1057   clkpow->regs.mpllcon  = 0x0005C080;
1058   clkpow->regs.upllcon  = 0x00028080;
1059   clkpow->regs.clkcon   = 0x0007FFF0;
1060   #elif defined(DEVICE_S3C2440)
1061   clkpow->regs.locktime = 0xFFFFFFFF;
1062   clkpow->regs.mpllcon  = 0x00096030;
1063   clkpow->regs.upllcon  = 0x0004D030;
1064   clkpow->regs.clkcon   = 0x00FFFFF0;
1065   #endif
1066   clkpow->regs.clkslow = 4;
1067}
1068
9861069static UINT32 s3c24xx_get_fclk( device_t *device)
9871070{
9881071   s3c24xx_t *s3c24xx = get_token( device);
989   UINT32 data, mdiv, pdiv, sdiv;
990   data = s3c24xx->clkpow.regs.mpllcon;
991   mdiv = BITS( data, 19, 12);
992   pdiv = BITS( data, 9, 4);
993   sdiv = BITS( data, 1, 0);
1072   UINT32 mpllcon, clkslow, mdiv, pdiv, sdiv, fclk;
1073   double temp1, temp2;
1074   mpllcon = s3c24xx->clkpow.regs.mpllcon;
1075   mdiv = BITS( mpllcon, 19, 12);
1076   pdiv = BITS( mpllcon, 9, 4);
1077   sdiv = BITS( mpllcon, 1, 0);
9941078#if defined(DEVICE_S3C2400) || defined(DEVICE_S3C2410)
995   return (UINT32)((double)(1 * (mdiv + 8) * device->clock()) / (double)((pdiv + 2) * (1 << sdiv)));
1079   temp1 = 1 * (mdiv + 8) * (double)device->clock();
9961080#else
997   return (UINT32)((double)(2 * (mdiv + 8) * device->clock()) / (double)((pdiv + 2) * (1 << sdiv)));
1081   temp1 = 2 * (mdiv + 8) * (double)device->clock();
9981082#endif
1083   temp2 = (double)((pdiv + 2) * (1 << sdiv));
1084   fclk = (UINT32)(temp1 / temp2);
1085   clkslow = s3c24xx->clkpow.regs.clkslow;
1086   if (BIT( clkslow, 4) == 1)
1087   {
1088      UINT32 slow_val = BITS( clkslow, 2, 0);
1089      if (slow_val > 0)
1090      {
1091         fclk = fclk / (2 * slow_val);
1092      }
1093   }
1094   return fclk;
9991095}
10001096
10011097static UINT32 s3c24xx_get_hclk( device_t *device)
r13744r13745
10421138         device->machine().device( "maincpu")->set_unscaled_clock(s3c24xx_get_fclk( device) * CLOCK_MULTIPLIER);
10431139      }
10441140      break;
1141      case S3C24XX_CLKSLOW :
1142      {
1143         verboselog( device->machine(), 5, "CLKPOW - fclk %d hclk %d pclk %d\n", s3c24xx_get_fclk( device), s3c24xx_get_hclk( device), s3c24xx_get_pclk( device));
1144         device->machine().device( "maincpu")->set_unscaled_clock(s3c24xx_get_fclk( device) * CLOCK_MULTIPLIER);
1145      }
1146      break;
10451147   }
10461148}
10471149
10481150/* Interrupt Controller */
10491151
1152static void s3c24xx_irq_reset( device_t *device)
1153{
1154   s3c24xx_t *s3c24xx = get_token( device);
1155   s3c24xx_irq_t *irq = &s3c24xx->irq;
1156   memset( &irq->regs, 0, sizeof( irq->regs));
1157   irq->line_irq = irq->line_fiq = CLEAR_LINE;
1158   irq->regs.intmsk = 0xFFFFFFFF;
1159   irq->regs.priority = 0x7F;
1160   #if defined(DEVICE_S3C2410)
1161   irq->regs.intsubmsk = 0x07FF;
1162   #elif defined(DEVICE_S3C2440)
1163   irq->regs.intsubmsk = 0xFFFF;
1164   #endif
1165}
1166
10501167static void s3c24xx_check_pending_irq( device_t *device)
10511168{
10521169   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
10561173   if (temp != 0)
10571174   {
10581175      UINT32 int_type = 0;
1176      verboselog( device->machine(), 5, "srcpnd %08X intmsk %08X intmod %08X\n", s3c24xx->irq.regs.srcpnd, s3c24xx->irq.regs.intmsk, s3c24xx->irq.regs.intmod);
10591177      while ((temp & 1) == 0)
10601178      {
10611179         int_type++;
10621180         temp = temp >> 1;
10631181      }
1182      verboselog( device->machine(), 5, "intpnd set bit %d\n", int_type);
10641183      s3c24xx->irq.regs.intpnd |= (1 << int_type);
10651184      s3c24xx->irq.regs.intoffset = int_type;
10661185      if (s3c24xx->irq.line_irq != ASSERT_LINE)
10671186      {
1187         verboselog( device->machine(), 5, "ARM7_IRQ_LINE -> ASSERT_LINE\n");
10681188         cputag_set_input_line( device->machine(), "maincpu", ARM7_IRQ_LINE, ASSERT_LINE);
10691189         s3c24xx->irq.line_irq = ASSERT_LINE;
10701190      }
r13744r13745
10731193   {
10741194      if (s3c24xx->irq.line_irq != CLEAR_LINE)
10751195      {
1196         verboselog( device->machine(), 5, "srcpnd %08X intmsk %08X intmod %08X\n", s3c24xx->irq.regs.srcpnd, s3c24xx->irq.regs.intmsk, s3c24xx->irq.regs.intmod);
1197         verboselog( device->machine(), 5, "ARM7_IRQ_LINE -> CLEAR_LINE\n");
10761198         cputag_set_input_line( device->machine(), "maincpu", ARM7_IRQ_LINE, CLEAR_LINE);
10771199         s3c24xx->irq.line_irq = CLEAR_LINE;
10781200      }
r13744r13745
10891211      }
10901212      if (s3c24xx->irq.line_fiq != ASSERT_LINE)
10911213      {
1214         verboselog( device->machine(), 5, "ARM7_FIRQ_LINE -> ASSERT_LINE\n");
10921215         cputag_set_input_line( device->machine(), "maincpu", ARM7_FIRQ_LINE, ASSERT_LINE);
10931216         s3c24xx->irq.line_fiq = ASSERT_LINE;
10941217      }
r13744r13745
10971220   {
10981221      if (s3c24xx->irq.line_fiq != CLEAR_LINE)
10991222      {
1223         verboselog( device->machine(), 5, "ARM7_FIRQ_LINE -> CLEAR_LINE\n");
11001224         cputag_set_input_line( device->machine(), "maincpu", ARM7_FIRQ_LINE, CLEAR_LINE);
11011225         s3c24xx->irq.line_fiq = CLEAR_LINE;
11021226      }
r13744r13745
11961320      case S3C24XX_SRCPND :
11971321      {
11981322         s3c24xx->irq.regs.srcpnd = (old_value & ~data); // clear only the bit positions of SRCPND corresponding to those set to one in the data
1323         s3c24xx->irq.regs.intoffset = 0; // "This bit can be cleared automatically by clearing SRCPND and INTPND."
11991324         s3c24xx_check_pending_irq( device);
12001325      }
12011326      break;
r13744r13745
12071332      case S3C24XX_INTPND :
12081333      {
12091334         s3c24xx->irq.regs.intpnd = (old_value & ~data); // clear only the bit positions of INTPND corresponding to those set to one in the data
1335         s3c24xx->irq.regs.intoffset = 0; // "This bit can be cleared automatically by clearing SRCPND and INTPND."
12101336      }
12111337      break;
12121338#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
r13744r13745
12271353
12281354/* PWM Timer */
12291355
1356static void s3c24xx_pwm_reset( device_t *device)
1357{
1358   s3c24xx_t *s3c24xx = get_token( device);
1359   s3c24xx_pwm_t *pwm = &s3c24xx->pwm;
1360   memset( &pwm->regs, 0, sizeof( pwm->regs));
1361   for (int i = 0; i < 5; i++)
1362   {
1363      pwm->timer[i]->adjust( attotime::never);
1364   }
1365}
1366
12301367static UINT16 s3c24xx_pwm_calc_observation( device_t *device, int ch)
12311368{
12321369   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
14401577
14411578/* DMA */
14421579
1580static void s3c24xx_dma_reset( device_t *device)
1581{
1582   s3c24xx_t *s3c24xx = get_token( device);
1583   for (int i = 0; i < S3C24XX_DMA_COUNT; i++)
1584   {
1585      s3c24xx_dma_t *dma = &s3c24xx->dma[i];
1586      memset( &dma->regs, 0, sizeof( dma->regs));
1587      dma->timer->adjust( attotime::never);
1588   }
1589}
1590
14431591static void s3c24xx_dma_reload( device_t *device, int ch)
14441592{
14451593   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
16831831
16841832/* I/O Port */
16851833
1686INLINE UINT32 iface_gpio_port_r( device_t *device, int port)
1834static void s3c24xx_gpio_reset( device_t *device)
16871835{
16881836   s3c24xx_t *s3c24xx = get_token( device);
1837   s3c24xx_gpio_t *gpio = &s3c24xx->gpio;
1838   memset( &gpio->regs, 0, sizeof( gpio->regs));
1839   #if defined(DEVICE_S3C2400)
1840   gpio->regs.gpacon = 0x0003FFFF;
1841   gpio->regs.gpbcon = 0xAAAAAAAA;
1842   gpio->regs.gpdup = 0x0620;
1843   gpio->regs.gpeup = 0x0003;
1844   #elif defined(DEVICE_S3C2410)
1845   gpio->regs.gpacon = 0x007FFFFF;
1846   gpio->regs.gpgup = 0xF800;
1847   gpio->regs.misccr = 0x00010330;
1848   gpio->regs.eintmask = 0x00FFFFF0;
1849   gpio->regs.gstatus1 = 0x32410002;
1850   #elif defined(DEVICE_S3C2440)
1851   gpio->regs.gpacon = 0x00FFFFFF;
1852   gpio->regs.gpgup = 0xFC00;
1853   gpio->regs.misccr = 0x00010020;
1854   gpio->regs.eintmask = 0x000FFFFF;
1855   gpio->regs.gstatus1 = 0x32440001;
1856   #endif
1857   gpio->regs.gpdup = 0xF000;
1858   #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
1859   gpio->regs.gstatus2 = 1 << 0; // Boot is caused by power on reset
1860   #endif
1861}
1862
1863INLINE UINT32 iface_gpio_port_r( device_t *device, int port, UINT32 mask)
1864{
1865   s3c24xx_t *s3c24xx = get_token( device);
16891866   if (s3c24xx->iface->gpio.port_r)
16901867   {
1691      return (s3c24xx->iface->gpio.port_r)( device, port);
1868      return (s3c24xx->iface->gpio.port_r)( device, port, mask);
16921869   }
16931870   else
16941871   {
r13744r13745
16961873   }
16971874}
16981875
1699INLINE void iface_gpio_port_w( device_t *device, int port, UINT32 data)
1876INLINE void iface_gpio_port_w( device_t *device, int port, UINT32 mask, UINT32 data)
17001877{
17011878   s3c24xx_t *s3c24xx = get_token( device);
17021879   if (s3c24xx->iface->gpio.port_w)
17031880   {
1704      (s3c24xx->iface->gpio.port_w)( device, port, data);
1881      (s3c24xx->iface->gpio.port_w)( device, port, mask, data);
17051882   }
17061883}
17071884
1885static UINT16 s3c24xx_gpio_get_mask( UINT32 con, int val)
1886{
1887   UINT16 mask = 0;
1888   for (int i = 0; i < 16; i++)
1889   {
1890      if (((con >> (i << 1)) & 3) == val)
1891      {
1892         mask = mask | (1 << i);
1893      }
1894   }
1895   return mask;
1896}
1897
17081898static READ32_DEVICE_HANDLER( s3c24xx_gpio_r )
17091899{
17101900   s3c24xx_t *s3c24xx = get_token( device);
1901   s3c24xx_gpio_t *gpio = &s3c24xx->gpio;
17111902   UINT32 data = ((UINT32*)&s3c24xx->gpio.regs)[offset];
17121903   switch (offset)
17131904   {
17141905      case S3C24XX_GPADAT :
17151906      {
1716         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_A) & S3C24XX_GPADAT_MASK;
1907         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_A, 0) & S3C24XX_GPADAT_MASK;
17171908      }
17181909      break;
17191910      case S3C24XX_GPBDAT :
17201911      {
1721         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_B) & S3C24XX_GPBDAT_MASK;
1912         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_B, s3c24xx_gpio_get_mask( gpio->regs.gpbcon, 0) & S3C24XX_GPBDAT_MASK) & S3C24XX_GPBDAT_MASK;
17221913      }
17231914      break;
17241915      case S3C24XX_GPCDAT :
17251916      {
1726         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_C) & S3C24XX_GPCDAT_MASK;
1917         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_C, s3c24xx_gpio_get_mask( gpio->regs.gpccon, 0) & S3C24XX_GPCDAT_MASK) & S3C24XX_GPCDAT_MASK;
17271918      }
17281919      break;
17291920      case S3C24XX_GPDDAT :
17301921      {
1731         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_D) & S3C24XX_GPDDAT_MASK;
1922         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_D, s3c24xx_gpio_get_mask( gpio->regs.gpdcon, 0) & S3C24XX_GPDDAT_MASK) & S3C24XX_GPDDAT_MASK;
17321923      }
17331924      break;
17341925      case S3C24XX_GPEDAT :
17351926      {
1736         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_E) & S3C24XX_GPEDAT_MASK;
1927         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_E, s3c24xx_gpio_get_mask( gpio->regs.gpecon, 0) & S3C24XX_GPEDAT_MASK) & S3C24XX_GPEDAT_MASK;
17371928      }
17381929      break;
17391930      case S3C24XX_GPFDAT :
17401931      {
1741         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_F) & S3C24XX_GPFDAT_MASK;
1932         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_F, s3c24xx_gpio_get_mask( gpio->regs.gpfcon, 0) & S3C24XX_GPFDAT_MASK) & S3C24XX_GPFDAT_MASK;
17421933      }
17431934      break;
17441935      case S3C24XX_GPGDAT :
17451936      {
1746         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_G) & S3C24XX_GPGDAT_MASK;
1937         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_G, s3c24xx_gpio_get_mask( gpio->regs.gpgcon, 0) & S3C24XX_GPGDAT_MASK) & S3C24XX_GPGDAT_MASK;
17471938      }
17481939      break;
17491940#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
17501941      case S3C24XX_GPHDAT :
17511942      {
1752         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_H) & S3C24XX_GPHDAT_MASK;
1943         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_H, s3c24xx_gpio_get_mask( gpio->regs.gphcon, 0) & S3C24XX_GPHDAT_MASK) & S3C24XX_GPHDAT_MASK;
17531944      }
17541945      break;
17551946#endif
17561947#if defined(DEVICE_S3C2440)
17571948      case S3C24XX_GPJDAT :
17581949      {
1759         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_J) & S3C24XX_GPJDAT_MASK;
1950         data = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_J, s3c24xx_gpio_get_mask( gpio->regs.gpjcon, 0) & S3C24XX_GPJDAT_MASK) & S3C24XX_GPJDAT_MASK;
17601951      }
17611952      break;
17621953#endif
r13744r13745
17681959static WRITE32_DEVICE_HANDLER( s3c24xx_gpio_w )
17691960{
17701961   s3c24xx_t *s3c24xx = get_token( device);
1962   s3c24xx_gpio_t *gpio = &s3c24xx->gpio;
17711963#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
17721964   UINT32 old_value = ((UINT32*)&s3c24xx->gpio.regs)[offset];
17731965#endif
r13744r13745
17771969   {
17781970      case S3C24XX_GPADAT :
17791971      {
1780          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_A, data & S3C24XX_GPADAT_MASK);
1972          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_A, gpio->regs.gpacon ^ 0xFFFFFFFF, data & S3C24XX_GPADAT_MASK);
17811973      }
17821974      break;
17831975      case S3C24XX_GPBDAT :
17841976      {
1785          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_B, data & S3C24XX_GPBDAT_MASK);
1977          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_B, s3c24xx_gpio_get_mask( gpio->regs.gpbcon, 1) & S3C24XX_GPBDAT_MASK, data & S3C24XX_GPBDAT_MASK);
17861978      }
17871979      break;
17881980      case S3C24XX_GPCDAT :
17891981      {
1790          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_C, data & S3C24XX_GPCDAT_MASK);
1982          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_C, s3c24xx_gpio_get_mask( gpio->regs.gpccon, 1) & S3C24XX_GPCDAT_MASK, data & S3C24XX_GPCDAT_MASK);
17911983      }
17921984      break;
17931985      case S3C24XX_GPDDAT :
17941986      {
1795          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_D, data & S3C24XX_GPDDAT_MASK);
1987          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_D, s3c24xx_gpio_get_mask( gpio->regs.gpdcon, 1) & S3C24XX_GPDDAT_MASK, data & S3C24XX_GPDDAT_MASK);
17961988      }
17971989      break;
17981990      case S3C24XX_GPEDAT :
17991991      {
1800          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_E, data & S3C24XX_GPEDAT_MASK);
1992          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_E, s3c24xx_gpio_get_mask( gpio->regs.gpecon, 1) & S3C24XX_GPEDAT_MASK, data & S3C24XX_GPEDAT_MASK);
18011993      }
18021994      break;
18031995      case S3C24XX_GPFDAT :
18041996      {
1805          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_F, data & S3C24XX_GPFDAT_MASK);
1997          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_F, s3c24xx_gpio_get_mask( gpio->regs.gpfcon, 1) & S3C24XX_GPFDAT_MASK, data & S3C24XX_GPFDAT_MASK);
18061998      }
18071999      break;
18082000      case S3C24XX_GPGDAT :
18092001      {
1810          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_G, data & S3C24XX_GPGDAT_MASK);
2002          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_G, s3c24xx_gpio_get_mask( gpio->regs.gpgcon, 1) & S3C24XX_GPGDAT_MASK, data & S3C24XX_GPGDAT_MASK);
18112003      }
18122004      break;
18132005#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
18142006      case S3C24XX_GPHDAT :
18152007      {
1816          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_H, data & S3C24XX_GPHDAT_MASK);
2008          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_H, s3c24xx_gpio_get_mask( gpio->regs.gphcon, 1) & S3C24XX_GPHDAT_MASK, data & S3C24XX_GPHDAT_MASK);
18172009      }
18182010      break;
18192011      case S3C24XX_EINTPEND :
r13744r13745
18272019         s3c24xx_check_pending_eint( device);
18282020      }
18292021      break;
2022      case S3C24XX_GSTATUS2 :
2023      {
2024         s3c24xx->gpio.regs.gstatus2 = (old_value & ~data) & 7; // "The setting is cleared by writing '1' to this bit"
2025      }
2026      break;
18302027#endif
18312028#if defined(DEVICE_S3C2440)
18322029      case S3C24XX_GPJDAT :
18332030      {
1834          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_J, data & S3C24XX_GPJDAT_MASK);
2031          iface_gpio_port_w( device, S3C24XX_GPIO_PORT_J, s3c24xx_gpio_get_mask( gpio->regs.gpjcon, 1) & S3C24XX_GPJDAT_MASK, data & S3C24XX_GPJDAT_MASK);
18352032      }
18362033      break;
18372034#endif
r13744r13745
18402037
18412038/* Memory Controller */
18422039
2040static void s3c24xx_memcon_reset( device_t *device)
2041{
2042   s3c24xx_t *s3c24xx = get_token( device);
2043   s3c24xx_memcon_t *memcon = &s3c24xx->memcon;
2044   memset( &memcon->regs, 0, sizeof( memcon->regs));
2045   memcon->regs.data[0x04/4] = 0x00000700;
2046   memcon->regs.data[0x08/4] = 0x00000700;
2047   memcon->regs.data[0x0C/4] = 0x00000700;
2048   memcon->regs.data[0x10/4] = 0x00000700;
2049   memcon->regs.data[0x14/4] = 0x00000700;
2050   memcon->regs.data[0x18/4] = 0x00000700;
2051   memcon->regs.data[0x1C/4] = 0x00018008;
2052   memcon->regs.data[0x20/4] = 0x00018008;
2053   memcon->regs.data[0x24/4] = 0x00AC0000;
2054}
2055
18432056static READ32_DEVICE_HANDLER( s3c24xx_memcon_r )
18442057{
18452058   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
18572070
18582071/* USB Host Controller */
18592072
2073static void s3c24xx_usb_host_reset( device_t *device)
2074{
2075   s3c24xx_t *s3c24xx = get_token( device);
2076   s3c24xx_usbhost_t *usbhost = &s3c24xx->usbhost;
2077   memset( &usbhost->regs, 0, sizeof( usbhost->regs));
2078}
2079
18602080static READ32_DEVICE_HANDLER( s3c24xx_usb_host_r )
18612081{
18622082   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
18692089         data = data & ~(1 << 0); // [bit 0] HostControllerReset
18702090      }
18712091      break;
2092      // HcPeriodStart
2093      case 0x40 / 4:
2094      {
2095         // "After a hardware reset, this field is cleared. This is then set by"
2096         // "HCD during the HC initialization. The value is calculated"
2097         // "roughly as 10% off from HcFmInterval.. A typical value will be 3E67h."
2098         data = (data & ~0x00003FFF) | 0x3E67;
2099      }
2100      break;
2101      // HcRhDescriptorA
2102      case 0x48 / 4:
2103      {
2104         data = (data & ~0xFF) | 2; // number of ports
2105      }
2106      break;
2107      // HcRhStatus
2108      case 0x50 / 4:
2109      {
2110         data = data & ~(1 << 16); // "The Root Hub does not support the local power status feature; thus, this bit is always read as ‘0’."
2111      }
2112      break;
18722113   }
18732114   verboselog( device->machine(), 9, "(USB H) %08X -> %08X\n", S3C24XX_BASE_USBHOST + (offset << 2), data);
18742115   return data;
r13744r13745
18832124
18842125/* UART */
18852126
2127static void s3c24xx_uart_reset( device_t *device)
2128{
2129   s3c24xx_t *s3c24xx = get_token( device);
2130   for (int i = 0; i < S3C24XX_UART_COUNT; i++)
2131   {
2132      s3c24xx_uart_t *uart = &s3c24xx->uart[i];
2133      memset( &uart->regs, 0, sizeof( uart->regs));
2134      uart->regs.utrstat = 6;
2135   }
2136}
2137
18862138static UINT32 s3c24xx_uart_r( device_t *device, UINT32 ch, UINT32 offset)
18872139{
18882140   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
19112163   COMBINE_DATA(&((UINT32*)&s3c24xx->uart[ch].regs)[offset]);
19122164   switch (offset)
19132165   {
2166      case S3C24XX_UFCON :
2167      {
2168         s3c24xx->uart[ch].regs.ufcon &= ~((1 << 2) | (1 << 1)); // bits 1 and 2 are auto-cleared after resetting FIFO
2169      }
2170      break;
19142171      case S3C24XX_UTXH :
19152172      {
19162173         UINT8 txdata = data & 0xFF;
r13744r13745
19802237
19812238/* USB Device */
19822239
2240static void s3c24xx_usb_device_reset( device_t *device)
2241{
2242   s3c24xx_t *s3c24xx = get_token( device);
2243   s3c24xx_usbdev_t *usbdev = &s3c24xx->usbdev;
2244   memset( &usbdev->regs, 0, sizeof( usbdev->regs));
2245   #if defined(DEVICE_S3C2400)
2246   usbdev->regs.data[0x0C/4] = 0x033F;
2247   usbdev->regs.data[0x14/4] = 0x000A;
2248   usbdev->regs.data[0x24/4] = 0x0001;
2249   usbdev->regs.data[0x44/4] = 0x0001;
2250   usbdev->regs.data[0x54/4] = 0x0001;
2251   usbdev->regs.data[0x64/4] = 0x0001;
2252   usbdev->regs.data[0x74/4] = 0x0001;
2253   usbdev->regs.data[0xB8/4] = 0x00FF;
2254   #elif defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
2255   usbdev->regs.data[0x1C/4] = 0xFF;
2256   usbdev->regs.data[0x2C/4] = 0x04;
2257   usbdev->regs.data[0x40/4] = 0x01;
2258   usbdev->regs.data[0x48/4] = 0x20;
2259   #endif
2260}
2261
19832262static READ32_DEVICE_HANDLER( s3c24xx_usb_device_r )
19842263{
19852264   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
19972276
19982277/* Watchdog Timer */
19992278
2279static void s3c24xx_wdt_reset( device_t *device)
2280{
2281   s3c24xx_t *s3c24xx = get_token( device);
2282   s3c24xx_wdt_t *wdt = &s3c24xx->wdt;
2283   memset( &wdt->regs, 0, sizeof( wdt->regs));
2284   wdt->regs.wtcon = 0x8021;
2285   wdt->regs.wtdat = 0x8000;
2286   wdt->regs.wtcnt = 0x8000;
2287   wdt->timer->adjust( attotime::never);
2288}
2289
20002290#if defined(DEVICE_S3C2410)
20012291
20022292static UINT16 s3c24xx_wdt_calc_current_count( device_t *device)
r13744r13745
21182408   if ((s3c24xx->wdt.regs.wtcon & (1 << 0)) != 0)
21192409   {
21202410      s3c24xx_reset( device);
2411      #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
2412      s3c24xx->gpio.regs.gstatus2 = 1 << 2; // Watchdog reset
2413      #endif
21212414   }
21222415}
21232416
21242417/* IIC */
21252418
2419static void s3c24xx_iic_reset( device_t *device)
2420{
2421   s3c24xx_t *s3c24xx = get_token( device);
2422   s3c24xx_iic_t *iic = &s3c24xx->iic;
2423   memset( &iic->regs, 0, sizeof( iic->regs));
2424   iic->count = 0;
2425   iic->timer->adjust( attotime::never);
2426}
2427
21262428INLINE void iface_i2c_scl_w( device_t *device, int state)
21272429{
21282430   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
23602662
23612663/* IIS */
23622664
2665static void s3c24xx_iis_reset( device_t *device)
2666{
2667   s3c24xx_t *s3c24xx = get_token( device);
2668   s3c24xx_iis_t *iis = &s3c24xx->iis;
2669   memset( &iis->regs, 0, sizeof( iis->regs));
2670   iis->fifo_index = 0;
2671   iis->regs.iiscon = 0x0100;
2672   iis->timer->adjust( attotime::never);
2673}
2674
23632675INLINE void iface_i2s_data_w( device_t *device, int ch, UINT16 data)
23642676{
23652677   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
24702782
24712783/* RTC */
24722784
2473static void s3c24xx_rtc_init( device_t *device)
2785static void s3c24xx_rtc_reset( device_t *device)
24742786{
24752787   s3c24xx_t *s3c24xx = get_token( device);
2476   s3c24xx->rtc.regs.bcdsec = dec_2_bcd( 0);
2477   s3c24xx->rtc.regs.bcdmin = dec_2_bcd( 0);
2478   s3c24xx->rtc.regs.bcdhour = dec_2_bcd( 0);
2479   s3c24xx->rtc.regs.bcdday = dec_2_bcd( 1);
2480   s3c24xx->rtc.regs.bcddow = dec_2_bcd( 1);
2481   s3c24xx->rtc.regs.bcdmon = dec_2_bcd( 1);
2482   s3c24xx->rtc.regs.bcdyear = dec_2_bcd( 4);
2788   s3c24xx_rtc_t *rtc = &s3c24xx->rtc;
2789   memset( &rtc->regs, 0, sizeof( rtc->regs));
2790   rtc->regs.almday = 1;
2791   rtc->regs.almmon = 1;
2792   rtc->timer_update->adjust( attotime::never);
2793   rtc->timer_update->adjust( attotime::from_msec( 1000), 0, attotime::from_msec( 1000));
24832794}
24842795
24852796static READ32_DEVICE_HANDLER( s3c24xx_rtc_r )
r13744r13745
26052916
26062917/* A/D Converter */
26072918
2919static void s3c24xx_adc_reset( device_t *device)
2920{
2921   s3c24xx_t *s3c24xx = get_token( device);
2922   s3c24xx_adc_t *adc = &s3c24xx->adc;
2923   memset( &adc->regs, 0, sizeof( adc->regs));
2924   adc->regs.adccon = 0x3FC4;
2925   #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
2926   adc->regs.adctsc = 0x58;
2927   adc->regs.adcdly = 0xFF;
2928   #endif
2929}
2930
26082931static UINT32 iface_adc_data_r( device_t *device, int ch)
26092932{
26102933   s3c24xx_t *s3c24xx = get_token( device);
26112934   if (s3c24xx->iface->adc.data_r)
26122935   {
2613      return (s3c24xx->iface->adc.data_r)( device, ch, 0);
2936      int offs = ch;
2937      #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
2938      if (BIT( s3c24xx->adc.regs.adctsc, 2) != 0)
2939      {
2940         offs += 2;
2941      }
2942      #endif
2943      return (s3c24xx->iface->adc.data_r)( device, offs, 0);
26142944   }
26152945   else
26162946   {
r13744r13745
26883018
26893019/* SPI */
26903020
3021static void s3c24xx_spi_reset( device_t *device)
3022{
3023   s3c24xx_t *s3c24xx = get_token( device);
3024   for (int i = 0; i < S3C24XX_SPI_COUNT; i++)
3025   {
3026      s3c24xx_spi_t *spi = &s3c24xx->spi[i];
3027      memset( &spi->regs, 0, sizeof( spi->regs));
3028      spi->regs.spsta = 1;
3029      #if defined(DEVICE_S3C2400) || defined(DEVICE_S3C2410)
3030      spi->regs.sppin = 2;
3031      #endif
3032   }
3033}
3034
26913035static UINT32 s3c24xx_spi_r( device_t *device, UINT32 ch, UINT32 offset)
26923036{
26933037   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
27473091
27483092#if defined(DEVICE_S3C2400)
27493093
3094static void s3c24xx_mmc_reset( device_t *device)
3095{
3096   s3c24xx_t *s3c24xx = get_token( device);
3097   s3c24xx_mmc_t *mmc = &s3c24xx->mmc;
3098   memset( &mmc->regs, 0, sizeof( mmc->regs));
3099}
3100
27503101static READ32_DEVICE_HANDLER( s3c24xx_mmc_r )
27513102{
27523103   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
27683119
27693120#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
27703121
3122static void s3c24xx_sdi_reset( device_t *device)
3123{
3124   s3c24xx_t *s3c24xx = get_token( device);
3125   s3c24xx_sdi_t *sdi = &s3c24xx->sdi;
3126   memset( &sdi->regs, 0, sizeof( sdi->regs));
3127   #if defined(DEVICE_S3C2410)
3128   sdi->regs.data[0x24/4] = 0x2000;
3129   #elif defined(DEVICE_S3C2440)
3130   sdi->regs.data[0x04/4] = 1;
3131   sdi->regs.data[0x24/4] = 0x10000;
3132   #endif
3133}
3134
27713135static READ32_DEVICE_HANDLER( s3c24xx_sdi_r )
27723136{
27733137   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
27893153
27903154#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
27913155
3156static void s3c24xx_nand_reset( device_t *device)
3157{
3158   s3c24xx_t *s3c24xx = get_token( device);
3159   s3c24xx_nand_t *nand = &s3c24xx->nand;
3160   memset( &nand->regs, 0, sizeof( nand->regs));
3161   #if defined(DEVICE_S3C2440)
3162   nand->regs.nfconf = 0x1000;
3163   nand->regs.nfcont = 0x0384;
3164   #endif
3165}
3166
27923167INLINE void iface_nand_command_w( device_t *device, UINT8 data)
27933168{
27943169   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
28973272static void s3c24xx_nand_update_ecc( device_t *device, UINT8 data)
28983273{
28993274   s3c24xx_t *s3c24xx = get_token( device);
3275   s3c24xx_nand_t *nand = &s3c24xx->nand;
29003276   UINT8 temp[4];
29013277#if defined(DEVICE_S3C2410)
2902   temp[0] = s3c24xx->nand.mecc[0];
2903   temp[1] = s3c24xx->nand.mecc[1];
2904   temp[2] = s3c24xx->nand.mecc[2];
2905   nand_update_mecc( s3c24xx->nand.mecc, s3c24xx->nand.pos++, data);
2906   verboselog( device->machine(), 5, "NAND - MECC %03X - %02X %02X %02X ->  %02X %02X %02X\n", s3c24xx->nand.pos - 1, temp[0], temp[1], temp[2], s3c24xx->nand.mecc[0], s3c24xx->nand.mecc[1], s3c24xx->nand.mecc[2]);
2907   if (s3c24xx->nand.pos == 512) s3c24xx->nand.pos = 0;
3278   temp[0] = nand->mecc[0];
3279   temp[1] = nand->mecc[1];
3280   temp[2] = nand->mecc[2];
3281   nand_update_mecc( nand->mecc, nand->ecc_pos++, data);
3282   verboselog( device->machine(), 5, "NAND - MECC %03X - %02X %02X %02X -> %02X %02X %02X\n", nand->ecc_pos - 1, temp[0], temp[1], temp[2], nand->mecc[0], nand->mecc[1], nand->mecc[2]);
3283   if (nand->ecc_pos == 512) nand->ecc_pos = 0;
29083284#else
2909   if ((s3c24xx->nand.regs.nfcont & (1 << 5)) == 0)
3285   if ((nand->regs.nfcont & (1 << 5)) == 0)
29103286   {
2911      temp[0] = s3c24xx->nand.mecc[0];
2912      temp[1] = s3c24xx->nand.mecc[1];
2913      temp[2] = s3c24xx->nand.mecc[2];
2914      temp[3] = s3c24xx->nand.mecc[3];
2915      nand_update_mecc( s3c24xx->nand.mecc, s3c24xx->nand.pos++, data);
2916      verboselog( device->machine(), 5, "NAND - MECC %03X - %02X %02X %02X %02X ->  %02X %02X %02X %02X\n", s3c24xx->nand.pos - 1, temp[0], temp[1], temp[2], temp[3], s3c24xx->nand.mecc[0], s3c24xx->nand.mecc[1], s3c24xx->nand.mecc[2], s3c24xx->nand.mecc[3]);
2917      if (s3c24xx->nand.pos == 2048) s3c24xx->nand.pos = 0;
3287      temp[0] = nand->mecc[0];
3288      temp[1] = nand->mecc[1];
3289      temp[2] = nand->mecc[2];
3290      temp[3] = nand->mecc[3];
3291      nand_update_mecc( nand->mecc, nand->ecc_pos++, data);
3292      verboselog( device->machine(), 5, "NAND - MECC %03X - %02X %02X %02X %02X -> %02X %02X %02X %02X\n", nand->ecc_pos - 1, temp[0], temp[1], temp[2], temp[3], nand->mecc[0], nand->mecc[1], nand->mecc[2], nand->mecc[3]);
3293      if (nand->ecc_pos == 2048) nand->ecc_pos = 0;
29183294   }
2919   if ((s3c24xx->nand.regs.nfcont & (1 << 6)) == 0)
3295   if ((nand->regs.nfcont & (1 << 6)) == 0)
29203296   {
2921      temp[0] = s3c24xx->nand.secc[0];
2922      temp[1] = s3c24xx->nand.secc[1];
2923      nand_update_secc( s3c24xx->nand.secc, s3c24xx->nand.pos++, data);
2924      verboselog( device->machine(), 5, "NAND - SECC %02X - %02X %02X ->  %02X %02X\n", s3c24xx->nand.pos - 1, temp[0], temp[1], s3c24xx->nand.secc[0], s3c24xx->nand.secc[1]);
2925      if (s3c24xx->nand.pos == 16) s3c24xx->nand.pos = 0;
3297      temp[0] = nand->secc[0];
3298      temp[1] = nand->secc[1];
3299      nand_update_secc( nand->secc, nand->ecc_pos++, data);
3300      verboselog( device->machine(), 5, "NAND - SECC %02X - %02X %02X -> %02X %02X\n", nand->ecc_pos - 1, temp[0], temp[1], nand->secc[0], nand->secc[1]);
3301      if (nand->ecc_pos == 16) nand->ecc_pos = 0;
29263302   }
29273303#endif
29283304}
29293305
29303306static void s3c24xx_nand_command_w( device_t *device, UINT8 data)
29313307{
3308   s3c24xx_t *s3c24xx = get_token( device);
29323309   verboselog( device->machine(), 5, "NAND write command %02X\n", data);
3310   s3c24xx->nand.data_count = 0;
29333311   iface_nand_command_w( device, data);
29343312}
29353313
29363314static void s3c24xx_nand_address_w( device_t *device, UINT8 data)
29373315{
3316   s3c24xx_t *s3c24xx = get_token( device);
29383317   verboselog( device->machine(), 5, "NAND write address %02X\n", data);
3318   s3c24xx->nand.data_count = 0;
29393319   iface_nand_address_w( device, data);
29403320}
29413321
29423322static UINT8 s3c24xx_nand_data_r( device_t *device)
29433323{
3324   s3c24xx_t *s3c24xx = get_token( device);
29443325   UINT8 data = iface_nand_data_r( device);
2945   verboselog( device->machine(), 5, "NAND data read %02X\n", data);
3326   verboselog( device->machine(), 5, "NAND read data %02X [%04X]\n", data, s3c24xx->nand.data_count++);
29463327   s3c24xx_nand_update_ecc( device, data);
29473328   return data;
29483329}
29493330
29503331static void s3c24xx_nand_data_w( device_t *device, UINT8 data)
29513332{
2952   verboselog( device->machine(), 5, "NAND write data %02X\n", data);
3333   s3c24xx_t *s3c24xx = get_token( device);
3334   verboselog( device->machine(), 5, "NAND write data %02X [%04X]\n", data, s3c24xx->nand.data_count++);
29533335   iface_nand_data_w( device, data);
29543336   s3c24xx_nand_update_ecc( device, data);
29553337}
r13744r13745
29633345      case S3C24XX_NFDATA :
29643346      {
29653347         data = 0;
3348         #if defined(DEVICE_S3C2410)
3349         data = data | s3c24xx_nand_data_r( device);
3350         #elif defined(DEVICE_S3C2440)
29663351         if ((mem_mask & 0x000000FF) != 0) data = data | (s3c24xx_nand_data_r( device) <<  0);
29673352         if ((mem_mask & 0x0000FF00) != 0) data = data | (s3c24xx_nand_data_r( device) <<  8);
29683353         if ((mem_mask & 0x00FF0000) != 0) data = data | (s3c24xx_nand_data_r( device) << 16);
29693354         if ((mem_mask & 0xFF000000) != 0) data = data | (s3c24xx_nand_data_r( device) << 24);
3355         #endif
29703356      }
29713357      break;
29723358#if defined(DEVICE_S3C2410)
29733359      case S3C24XX_NFECC :
29743360      {
2975         data = (s3c24xx->nand.mecc[2] << 16) | (s3c24xx->nand.mecc[1] << 8) | (s3c24xx->nand.mecc[0] << 0);
2976         //data = 0xFFFFFFFF;
3361         data = ((s3c24xx->nand.mecc[2] << 16) | (s3c24xx->nand.mecc[1] << 8) | (s3c24xx->nand.mecc[0] << 0));
29773362      }
29783363      break;
29793364#endif
r13744r13745
30093394{
30103395   s3c24xx_t *s3c24xx = get_token( device);
30113396   verboselog( device->machine(), 5, "NAND - init ecc\n");
3012#if defined(DEVICE_S3C2410)
3013   s3c24xx->nand.mecc[0] = 0;
3014   s3c24xx->nand.mecc[1] = 0;
3015   s3c24xx->nand.mecc[2] = 0;
3016#else
3017   s3c24xx->nand.mecc[0] = 0;
3018   s3c24xx->nand.mecc[1] = 0;
3019   s3c24xx->nand.mecc[2] = 0;
3020   s3c24xx->nand.mecc[3] = 0;
3397   s3c24xx->nand.mecc[0] = 0xFF;
3398   s3c24xx->nand.mecc[1] = 0xFF;
3399   s3c24xx->nand.mecc[2] = 0xFF;
3400   #if defined(DEVICE_S3C2440)
3401   s3c24xx->nand.mecc[3] = 0xFF;
30213402   s3c24xx->nand.secc[0] = 0;
30223403   s3c24xx->nand.secc[1] = 0;
3023#endif
3024   s3c24xx->nand.pos = 0;
3404   #endif
3405   s3c24xx->nand.ecc_pos = 0;
30253406}
30263407
30273408static WRITE32_DEVICE_HANDLER( s3c24xx_nand_w )
30283409{
30293410   s3c24xx_t *s3c24xx = get_token( device);
30303411   UINT32 old_value = ((UINT32*)&s3c24xx->nand.regs)[offset];
3031   verboselog( device->machine(), 9, "(NAND) %08X <- %08X\n", S3C24XX_BASE_NAND + (offset << 2), data);
3412   verboselog( device->machine(), 9, "(NAND) %08X <- %08X (%08X)\n", S3C24XX_BASE_NAND + (offset << 2), data, mem_mask);
30323413   COMBINE_DATA(&((UINT32*)&s3c24xx->nand.regs)[offset]);
30333414   switch (offset)
30343415   {
r13744r13745
30543435#endif
30553436      case S3C24XX_NFSTAT :
30563437      {
3057         s3c24xx->nand.regs.nfstat = (s3c24xx->nand.regs.nfstat & ~0x03) | (old_value & 0x03);
3438         s3c24xx->nand.regs.nfstat = (s3c24xx->nand.regs.nfstat & ~0x03) | (old_value & 0x03); // read-only
30583439#if defined(DEVICE_S3C2440)
30593440         if ((data & (1 << 2)) != 0)
30603441         {
r13744r13745
30753456      break;
30763457      case S3C24XX_NFDATA :
30773458      {
3459         #if defined(DEVICE_S3C2410)
3460         s3c24xx_nand_data_w( device, data & 0xFF);
3461         #elif defined(DEVICE_S3C2440)
30783462         if ((mem_mask & 0x000000FF) != 0) s3c24xx_nand_data_w( device, (data >>  0) & 0xFF);
30793463         if ((mem_mask & 0x0000FF00) != 0) s3c24xx_nand_data_w( device, (data >>  8) & 0xFF);
30803464         if ((mem_mask & 0x00FF0000) != 0) s3c24xx_nand_data_w( device, (data >> 16) & 0xFF);
30813465         if ((mem_mask & 0xFF000000) != 0) s3c24xx_nand_data_w( device, (data >> 24) & 0xFF);
3466         #endif
30823467      }
30833468      break;
30843469   }
r13744r13745
30873472ATTR_UNUSED static WRITE_LINE_DEVICE_HANDLER( s3c24xx_pin_frnb_w )
30883473{
30893474   s3c24xx_t *s3c24xx = get_token( device);
3475   verboselog( device->machine(), 9, "s3c24xx_pin_frnb_w (%d)\n", state);
30903476#if defined(DEVICE_S3C2440)
30913477   if ((BIT( s3c24xx->nand.regs.nfstat, 0) == 0) && (state != 0))
30923478   {
r13744r13745
31133499
31143500#if defined(DEVICE_S3C2440)
31153501
3502static void s3c24xx_cam_reset( device_t *device)
3503{
3504   s3c24xx_t *s3c24xx = get_token( device);
3505   s3c24xx_cam_t *cam = &s3c24xx->cam;
3506   memset( &cam->regs, 0, sizeof( cam->regs));
3507}
3508
31163509static READ32_DEVICE_HANDLER( s3c24xx_cam_r )
31173510{
31183511   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
31343527
31353528#if defined(DEVICE_S3C2440)
31363529
3530static void s3c24xx_ac97_reset( device_t *device)
3531{
3532   s3c24xx_t *s3c24xx = get_token( device);
3533   s3c24xx_ac97_t *ac97 = &s3c24xx->ac97;
3534   memset( &ac97->regs, 0, sizeof( ac97->regs));
3535}
3536
31373537static READ32_DEVICE_HANDLER( s3c24xx_ac97_r )
31383538{
31393539   s3c24xx_t *s3c24xx = get_token( device);
r13744r13745
31533553
31543554// ...
31553555
3556#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
3557
3558static void s3c24xx_nand_auto_boot( device_t *device)
3559{
3560   int om0 = iface_core_pin_r( device, S3C24XX_CORE_PIN_OM0);
3561   int om1 = iface_core_pin_r( device, S3C24XX_CORE_PIN_OM1);
3562   if ((om0 == 0) && (om1 == 0))
3563   {
3564      s3c24xx_t *s3c24xx = get_token( device);
3565      int ncon = iface_core_pin_r( device, S3C24XX_CORE_PIN_NCON);
3566      UINT8 *ptr = s3c24xx->steppingstone;
3567      int page_size, address_cycle;
3568      #if defined(DEVICE_S3C2410)
3569      page_size = 512;
3570      if (ncon == 0)
3571      {
3572         address_cycle = 3; // byte-page-page
3573      }
3574      else
3575      {
3576         address_cycle = 4; // byte-page-page-page
3577      }
3578      #elif defined(DEVICE_S3C2440)
3579      UINT32 port_g = iface_gpio_port_r( device, S3C24XX_GPIO_PORT_G, 0);
3580      if (ncon == 0)
3581      {
3582         if (BIT( port_g, 13) == 0)
3583         {
3584            page_size = 256;
3585            address_cycle = 3; // byte-page-page
3586         }
3587         else
3588         {
3589            page_size = 512;
3590            address_cycle = 4; // byte-page-page-page
3591         }
3592      }
3593      else
3594      {
3595         if (BIT( port_g, 13) == 0)
3596         {
3597            page_size = 1024;
3598            address_cycle = 4; // byte-byte-page-page or byte-page-page-page ??? assume latter
3599         }
3600         else
3601         {
3602            page_size = 2048;
3603            address_cycle = 5; // byte-byte-page-page-page
3604         }
3605      }
3606      #endif
3607      iface_nand_command_w( device, 0xFF);
3608      for (int page = 0; page < (4 * 1024) / page_size; page++)
3609      {
3610         iface_nand_command_w( device, 0x00);
3611         iface_nand_address_w( device, 0x00);
3612         if (address_cycle > 4)
3613         {
3614            iface_nand_address_w( device, 0x00);
3615         }
3616         iface_nand_address_w( device, (page >> 0) & 0xFF);
3617         iface_nand_address_w( device, (page >> 8) & 0xFF);
3618         if (address_cycle > 3)
3619         {
3620            iface_nand_address_w( device, (page >> 16) & 0xFF);
3621         }
3622         for (int i = 0; i < page_size; i++)
3623         {
3624            *ptr++ = iface_nand_data_r( device);
3625         }
3626      }
3627      iface_nand_command_w( device, 0xFF);
3628   }
3629}
3630
3631#endif
3632
31563633static DEVICE_RESET( s3c24xx )
31573634{
3158   s3c24xx_t *s3c24xx = get_token( device);
3159   s3c24xx->iis.fifo_index = 0;
3160//  s3c24xx->iic.data_index = 0;
3161#if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
3162   s3c24xx->gpio.regs.gstatus2 = 0x00000001; // Boot is caused by power on reset
3163#endif
3164   s3c24xx->irq.line_irq = s3c24xx->irq.line_fiq = CLEAR_LINE;
3635   verboselog( device->machine(), 1, "s3c24xx device reset\n");
3636   s3c24xx_uart_reset( device);
3637   s3c24xx_pwm_reset( device);
3638   s3c24xx_dma_reset( device);
3639   s3c24xx_iic_reset( device);
3640   s3c24xx_iis_reset( device);
3641   s3c24xx_lcd_reset( device);
3642   s3c24xx_rtc_reset( device);
3643   s3c24xx_wdt_reset( device);
3644   s3c24xx_irq_reset( device);
3645   s3c24xx_gpio_reset( device);
3646   s3c24xx_memcon_reset( device);
3647   s3c24xx_clkpow_reset( device);
3648   s3c24xx_usb_host_reset( device);
3649   s3c24xx_usb_device_reset( device);
3650   s3c24xx_adc_reset( device);
3651   s3c24xx_spi_reset( device);
3652   #if defined(DEVICE_S3C2400)
3653   s3c24xx_mmc_reset( device);
3654   #endif
3655   #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
3656   s3c24xx_sdi_reset( device);
3657   s3c24xx_nand_reset( device);
3658   #endif
3659   #if defined(DEVICE_S3C2440)
3660   s3c24xx_cam_reset( device);
3661   s3c24xx_ac97_reset( device);
3662   #endif
3663   #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
3664   s3c24xx_nand_auto_boot( device);
3665   #endif
31653666}
31663667
31673668static DEVICE_START( s3c24xx )
31683669{
31693670   s3c24xx_t *s3c24xx = get_token( device);
3671   verboselog( device->machine(), 1, "s3c24xx device start\n");
31703672   s3c24xx->iface = (const s3c24xx_interface *)device->static_config();
3171   for (int i = 0; i < 5; i++) s3c24xx->pwm.timer[i] = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_pwm_timer_exp), (void*)device);
3172   for (int i = 0; i < 4; i++) s3c24xx->dma[i].timer = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_dma_timer_exp), (void*)device);
3673   for (int i = 0; i < 5; i++)
3674   {
3675      s3c24xx->pwm.timer[i] = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_pwm_timer_exp), (void*)device);
3676   }
3677   for (int i = 0; i < S3C24XX_DMA_COUNT; i++)
3678   {
3679      s3c24xx->dma[i].timer = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_dma_timer_exp), (void*)device);
3680   }
31733681   s3c24xx->iic.timer = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_iic_timer_exp), (void*)device);
31743682   s3c24xx->iis.timer = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_iis_timer_exp), (void*)device);
31753683   s3c24xx->lcd.timer = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_lcd_timer_exp), (void*)device);
31763684   s3c24xx->rtc.timer_tick_count = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_rtc_timer_tick_count_exp), (void*)device);
31773685   s3c24xx->rtc.timer_update = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_rtc_timer_update_exp), (void*)device);
31783686   s3c24xx->wdt.timer = device->machine().scheduler().timer_alloc( FUNC(s3c24xx_wdt_timer_exp), (void*)device);
3179   s3c24xx->rtc.timer_update->adjust( attotime::from_msec( 1000), 0, attotime::from_msec( 1000));
3180   s3c24xx_rtc_init( device);
3687   #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440)
3688   int om0 = iface_core_pin_r( device, S3C24XX_CORE_PIN_OM0);
3689   int om1 = iface_core_pin_r( device, S3C24XX_CORE_PIN_OM1);
3690   if ((om0 == 0) && (om1 == 0))
3691   {
3692      address_space *space = device->machine().device( "maincpu")->memory().space( AS_PROGRAM);
3693      space->install_ram( 0x00000000, 0x00000fff, s3c24xx->steppingstone);
3694      space->install_ram( 0x40000000, 0x40000fff, s3c24xx->steppingstone);
3695   }
3696   #endif
31813697}
31823698
31833699static DEVICE_GET_INFO( s3c24xx )
src/mess/drivers/gizmondo.c
r13744r13745
6868
6969// I/O PORT
7070
71static UINT32 s3c2440_gpio_port_r( device_t *device, int port)
71static UINT32 s3c2440_gpio_port_r( device_t *device, int port, UINT32 mask)
7272{
7373   gizmondo_state *gizmondo = device->machine().driver_data<gizmondo_state>();
7474   UINT32 data = gizmondo->m_port[port];
r13744r13745
108108   return data;
109109}
110110
111static void s3c2440_gpio_port_w( device_t *device, int port, UINT32 data)
111static void s3c2440_gpio_port_w( device_t *device, int port, UINT32 mask, UINT32 data)
112112{
113113   gizmondo_state *gizmondo = device->machine().driver_data<gizmondo_state>();
114114   gizmondo->m_port[port] = data;
r13744r13745
171171
172172static S3C2440_INTERFACE( gizmondo_s3c2440_intf )
173173{
174   // CORE (pin read / pin write)
175   { NULL, NULL },
174176   // GPIO (port read / port write)
175177   { s3c2440_gpio_port_r, s3c2440_gpio_port_w },
176178   // I2C (scl write / sda read / sda write)
r13744r13745
179181   { NULL },
180182   // I2S (data write)
181183   { NULL },
182   // NAND (command write, address write, data read, data write)
184   // NAND (command write / address write / data read / data write)
183185   { NULL, NULL, NULL, NULL },
184186   // LCD (flags)
185187   { 0 }
src/mess/drivers/hp49gp.c
r13744r13745
158158
159159// I/O PORT
160160
161static UINT32 s3c2410_gpio_port_r( device_t *device, int port)
161static UINT32 s3c2410_gpio_port_r( device_t *device, int port, UINT32 mask)
162162{
163163   hp49gp_state *hp49gp = device->machine().driver_data<hp49gp_state>();
164164   UINT32 data = hp49gp->m_port[port];
r13744r13745
209209   return data;
210210}
211211
212static void s3c2410_gpio_port_w( device_t *device, int port, UINT32 data)
212static void s3c2410_gpio_port_w( device_t *device, int port, UINT32 mask, UINT32 data)
213213{
214214   hp49gp_state *hp49gp = device->machine().driver_data<hp49gp_state>();
215215   hp49gp->m_port[port] = data;
r13744r13745
273273
274274static S3C2410_INTERFACE( hp49gp_s3c2410_intf )
275275{
276   // CORE (pin read / pin write)
277   { NULL, NULL },
276278   // GPIO (port read / port write)
277279   { s3c2410_gpio_port_r, s3c2410_gpio_port_w },
278280   // I2C (scl write / sda read / sda write)
r13744r13745
281283   { NULL },
282284   // I2S (data write)
283285   { NULL },
284   // NAND (command write, address write, data read, data write)
286   // NAND (command write / address write / data read / data write)
285287   { NULL, NULL, NULL, NULL },
286288   // LCD (flags)
287289   { S3C24XX_INTERFACE_LCD_REVERSE }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team