| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/arch/arm/mach-w90x900/dev.c | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2009 Nuvoton corporation. | 
|  | 5 | * | 
|  | 6 | * Wan ZongShun <mcuos.com@gmail.com> | 
|  | 7 | * | 
|  | 8 | * This program is free software; you can redistribute it and/or | 
|  | 9 | * modify it under the terms of the GNU General Public License as | 
|  | 10 | * published by the Free Software Foundation;version 2 of the License. | 
|  | 11 | * | 
|  | 12 | */ | 
|  | 13 |  | 
|  | 14 | #include <linux/kernel.h> | 
|  | 15 | #include <linux/types.h> | 
|  | 16 | #include <linux/interrupt.h> | 
|  | 17 | #include <linux/list.h> | 
|  | 18 | #include <linux/timer.h> | 
|  | 19 | #include <linux/init.h> | 
|  | 20 | #include <linux/platform_device.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> | 
| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 22 |  | 
|  | 23 | #include <linux/mtd/physmap.h> | 
|  | 24 | #include <linux/mtd/mtd.h> | 
|  | 25 | #include <linux/mtd/partitions.h> | 
|  | 26 |  | 
|  | 27 | #include <linux/spi/spi.h> | 
|  | 28 | #include <linux/spi/flash.h> | 
|  | 29 |  | 
|  | 30 | #include <asm/mach/arch.h> | 
|  | 31 | #include <asm/mach/map.h> | 
|  | 32 | #include <asm/mach/irq.h> | 
|  | 33 | #include <asm/mach-types.h> | 
|  | 34 |  | 
|  | 35 | #include <mach/regs-serial.h> | 
| wanzongshun | 39986ca | 2009-12-01 14:01:55 +0100 | [diff] [blame] | 36 | #include <mach/nuc900_spi.h> | 
| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 37 | #include <mach/map.h> | 
| Wang Qiang | 8661970 | 2010-03-10 15:21:47 -0800 | [diff] [blame] | 38 | #include <mach/fb.h> | 
| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 39 |  | 
|  | 40 | #include "cpu.h" | 
|  | 41 |  | 
|  | 42 | /*NUC900 evb norflash driver data */ | 
|  | 43 |  | 
|  | 44 | #define NUC900_FLASH_BASE	0xA0000000 | 
|  | 45 | #define NUC900_FLASH_SIZE	0x400000 | 
|  | 46 | #define SPIOFFSET		0x200 | 
|  | 47 | #define SPIOREG_SIZE		0x100 | 
|  | 48 |  | 
|  | 49 | static struct mtd_partition nuc900_flash_partitions[] = { | 
|  | 50 | { | 
|  | 51 | .name	=	"NOR Partition 1 for kernel (960K)", | 
|  | 52 | .size	=	0xF0000, | 
|  | 53 | .offset	=	0x10000, | 
|  | 54 | }, | 
|  | 55 | { | 
|  | 56 | .name	=	"NOR Partition 2 for image (1M)", | 
|  | 57 | .size	=	0x100000, | 
|  | 58 | .offset	=	0x100000, | 
|  | 59 | }, | 
|  | 60 | { | 
|  | 61 | .name	=	"NOR Partition 3 for user (2M)", | 
|  | 62 | .size	=	0x200000, | 
|  | 63 | .offset	=	0x00200000, | 
|  | 64 | } | 
|  | 65 | }; | 
|  | 66 |  | 
|  | 67 | static struct physmap_flash_data nuc900_flash_data = { | 
|  | 68 | .width		=	2, | 
|  | 69 | .parts		=	nuc900_flash_partitions, | 
|  | 70 | .nr_parts	=	ARRAY_SIZE(nuc900_flash_partitions), | 
|  | 71 | }; | 
|  | 72 |  | 
|  | 73 | static struct resource nuc900_flash_resources[] = { | 
|  | 74 | { | 
|  | 75 | .start	=	NUC900_FLASH_BASE, | 
|  | 76 | .end	=	NUC900_FLASH_BASE + NUC900_FLASH_SIZE - 1, | 
|  | 77 | .flags	=	IORESOURCE_MEM, | 
|  | 78 | } | 
|  | 79 | }; | 
|  | 80 |  | 
|  | 81 | static struct platform_device nuc900_flash_device = { | 
|  | 82 | .name		=	"physmap-flash", | 
|  | 83 | .id		=	0, | 
|  | 84 | .dev		= { | 
|  | 85 | .platform_data = &nuc900_flash_data, | 
|  | 86 | }, | 
|  | 87 | .resource	=	nuc900_flash_resources, | 
|  | 88 | .num_resources	=	ARRAY_SIZE(nuc900_flash_resources), | 
|  | 89 | }; | 
|  | 90 |  | 
|  | 91 | /* USB EHCI Host Controller */ | 
|  | 92 |  | 
|  | 93 | static struct resource nuc900_usb_ehci_resource[] = { | 
|  | 94 | [0] = { | 
|  | 95 | .start = W90X900_PA_USBEHCIHOST, | 
|  | 96 | .end   = W90X900_PA_USBEHCIHOST + W90X900_SZ_USBEHCIHOST - 1, | 
|  | 97 | .flags = IORESOURCE_MEM, | 
|  | 98 | }, | 
|  | 99 | [1] = { | 
|  | 100 | .start = IRQ_USBH, | 
|  | 101 | .end   = IRQ_USBH, | 
|  | 102 | .flags = IORESOURCE_IRQ, | 
|  | 103 | } | 
|  | 104 | }; | 
|  | 105 |  | 
|  | 106 | static u64 nuc900_device_usb_ehci_dmamask = 0xffffffffUL; | 
|  | 107 |  | 
|  | 108 | static struct platform_device nuc900_device_usb_ehci = { | 
|  | 109 | .name		  = "nuc900-ehci", | 
|  | 110 | .id		  = -1, | 
|  | 111 | .num_resources	  = ARRAY_SIZE(nuc900_usb_ehci_resource), | 
|  | 112 | .resource	  = nuc900_usb_ehci_resource, | 
|  | 113 | .dev              = { | 
|  | 114 | .dma_mask = &nuc900_device_usb_ehci_dmamask, | 
|  | 115 | .coherent_dma_mask = 0xffffffffUL | 
|  | 116 | } | 
|  | 117 | }; | 
|  | 118 |  | 
|  | 119 | /* USB OHCI Host Controller */ | 
|  | 120 |  | 
|  | 121 | static struct resource nuc900_usb_ohci_resource[] = { | 
|  | 122 | [0] = { | 
|  | 123 | .start = W90X900_PA_USBOHCIHOST, | 
|  | 124 | .end   = W90X900_PA_USBOHCIHOST + W90X900_SZ_USBOHCIHOST - 1, | 
|  | 125 | .flags = IORESOURCE_MEM, | 
|  | 126 | }, | 
|  | 127 | [1] = { | 
|  | 128 | .start = IRQ_USBH, | 
|  | 129 | .end   = IRQ_USBH, | 
|  | 130 | .flags = IORESOURCE_IRQ, | 
|  | 131 | } | 
|  | 132 | }; | 
|  | 133 |  | 
|  | 134 | static u64 nuc900_device_usb_ohci_dmamask = 0xffffffffUL; | 
|  | 135 | static struct platform_device nuc900_device_usb_ohci = { | 
|  | 136 | .name		  = "nuc900-ohci", | 
|  | 137 | .id		  = -1, | 
|  | 138 | .num_resources	  = ARRAY_SIZE(nuc900_usb_ohci_resource), | 
|  | 139 | .resource	  = nuc900_usb_ohci_resource, | 
|  | 140 | .dev              = { | 
|  | 141 | .dma_mask = &nuc900_device_usb_ohci_dmamask, | 
|  | 142 | .coherent_dma_mask = 0xffffffffUL | 
|  | 143 | } | 
|  | 144 | }; | 
|  | 145 |  | 
|  | 146 | /* USB Device (Gadget)*/ | 
|  | 147 |  | 
|  | 148 | static struct resource nuc900_usbgadget_resource[] = { | 
|  | 149 | [0] = { | 
|  | 150 | .start = W90X900_PA_USBDEV, | 
|  | 151 | .end   = W90X900_PA_USBDEV + W90X900_SZ_USBDEV - 1, | 
|  | 152 | .flags = IORESOURCE_MEM, | 
|  | 153 | }, | 
|  | 154 | [1] = { | 
|  | 155 | .start = IRQ_USBD, | 
|  | 156 | .end   = IRQ_USBD, | 
|  | 157 | .flags = IORESOURCE_IRQ, | 
|  | 158 | } | 
|  | 159 | }; | 
|  | 160 |  | 
|  | 161 | static struct platform_device nuc900_device_usbgadget = { | 
|  | 162 | .name		= "nuc900-usbgadget", | 
|  | 163 | .id		= -1, | 
|  | 164 | .num_resources	= ARRAY_SIZE(nuc900_usbgadget_resource), | 
|  | 165 | .resource	= nuc900_usbgadget_resource, | 
|  | 166 | }; | 
|  | 167 |  | 
|  | 168 | /* MAC device */ | 
|  | 169 |  | 
|  | 170 | static struct resource nuc900_emc_resource[] = { | 
|  | 171 | [0] = { | 
|  | 172 | .start = W90X900_PA_EMC, | 
|  | 173 | .end   = W90X900_PA_EMC + W90X900_SZ_EMC - 1, | 
|  | 174 | .flags = IORESOURCE_MEM, | 
|  | 175 | }, | 
|  | 176 | [1] = { | 
|  | 177 | .start = IRQ_EMCTX, | 
|  | 178 | .end   = IRQ_EMCTX, | 
|  | 179 | .flags = IORESOURCE_IRQ, | 
|  | 180 | }, | 
|  | 181 | [2] = { | 
|  | 182 | .start = IRQ_EMCRX, | 
|  | 183 | .end   = IRQ_EMCRX, | 
|  | 184 | .flags = IORESOURCE_IRQ, | 
|  | 185 | } | 
|  | 186 | }; | 
|  | 187 |  | 
|  | 188 | static u64 nuc900_device_emc_dmamask = 0xffffffffUL; | 
|  | 189 | static struct platform_device nuc900_device_emc = { | 
|  | 190 | .name		= "nuc900-emc", | 
|  | 191 | .id		= -1, | 
|  | 192 | .num_resources	= ARRAY_SIZE(nuc900_emc_resource), | 
|  | 193 | .resource	= nuc900_emc_resource, | 
|  | 194 | .dev              = { | 
|  | 195 | .dma_mask = &nuc900_device_emc_dmamask, | 
|  | 196 | .coherent_dma_mask = 0xffffffffUL | 
|  | 197 | } | 
|  | 198 | }; | 
|  | 199 |  | 
|  | 200 | /* SPI device */ | 
|  | 201 |  | 
| wanzongshun | d76cdf2 | 2009-12-18 17:58:58 +0100 | [diff] [blame] | 202 | static struct nuc900_spi_info nuc900_spiflash_data = { | 
| wanzongshun | 39986ca | 2009-12-01 14:01:55 +0100 | [diff] [blame] | 203 | .num_cs		= 1, | 
|  | 204 | .lsb		= 0, | 
|  | 205 | .txneg		= 1, | 
|  | 206 | .rxneg		= 0, | 
|  | 207 | .divider	= 24, | 
|  | 208 | .sleep		= 0, | 
|  | 209 | .txnum		= 0, | 
|  | 210 | .txbitlen	= 1, | 
|  | 211 | .bus_num	= 0, | 
|  | 212 | }; | 
|  | 213 |  | 
| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 214 | static struct resource nuc900_spi_resource[] = { | 
|  | 215 | [0] = { | 
|  | 216 | .start = W90X900_PA_I2C + SPIOFFSET, | 
|  | 217 | .end   = W90X900_PA_I2C + SPIOFFSET + SPIOREG_SIZE - 1, | 
|  | 218 | .flags = IORESOURCE_MEM, | 
|  | 219 | }, | 
|  | 220 | [1] = { | 
|  | 221 | .start = IRQ_SSP, | 
|  | 222 | .end   = IRQ_SSP, | 
|  | 223 | .flags = IORESOURCE_IRQ, | 
|  | 224 | } | 
|  | 225 | }; | 
|  | 226 |  | 
|  | 227 | static struct platform_device nuc900_device_spi = { | 
|  | 228 | .name		= "nuc900-spi", | 
|  | 229 | .id		= -1, | 
|  | 230 | .num_resources	= ARRAY_SIZE(nuc900_spi_resource), | 
|  | 231 | .resource	= nuc900_spi_resource, | 
| wanzongshun | 39986ca | 2009-12-01 14:01:55 +0100 | [diff] [blame] | 232 | .dev		= { | 
|  | 233 | .platform_data = &nuc900_spiflash_data, | 
|  | 234 | } | 
| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 235 | }; | 
|  | 236 |  | 
|  | 237 | /* spi device, spi flash info */ | 
|  | 238 |  | 
|  | 239 | static struct mtd_partition nuc900_spi_flash_partitions[] = { | 
|  | 240 | { | 
|  | 241 | .name = "bootloader(spi)", | 
|  | 242 | .size = 0x0100000, | 
|  | 243 | .offset = 0, | 
|  | 244 | }, | 
|  | 245 | }; | 
|  | 246 |  | 
|  | 247 | static struct flash_platform_data nuc900_spi_flash_data = { | 
|  | 248 | .name = "m25p80", | 
|  | 249 | .parts =  nuc900_spi_flash_partitions, | 
|  | 250 | .nr_parts = ARRAY_SIZE(nuc900_spi_flash_partitions), | 
|  | 251 | .type = "w25x16", | 
|  | 252 | }; | 
|  | 253 |  | 
|  | 254 | static struct spi_board_info nuc900_spi_board_info[] __initdata = { | 
|  | 255 | { | 
|  | 256 | .modalias = "m25p80", | 
|  | 257 | .max_speed_hz = 20000000, | 
|  | 258 | .bus_num = 0, | 
|  | 259 | .chip_select = 1, | 
|  | 260 | .platform_data = &nuc900_spi_flash_data, | 
|  | 261 | .mode = SPI_MODE_0, | 
|  | 262 | }, | 
|  | 263 | }; | 
|  | 264 |  | 
|  | 265 | /* WDT Device */ | 
|  | 266 |  | 
|  | 267 | static struct resource nuc900_wdt_resource[] = { | 
|  | 268 | [0] = { | 
|  | 269 | .start = W90X900_PA_TIMER, | 
|  | 270 | .end   = W90X900_PA_TIMER + W90X900_SZ_TIMER - 1, | 
|  | 271 | .flags = IORESOURCE_MEM, | 
|  | 272 | }, | 
|  | 273 | [1] = { | 
|  | 274 | .start = IRQ_WDT, | 
|  | 275 | .end   = IRQ_WDT, | 
|  | 276 | .flags = IORESOURCE_IRQ, | 
|  | 277 | } | 
|  | 278 | }; | 
|  | 279 |  | 
|  | 280 | static struct platform_device nuc900_device_wdt = { | 
|  | 281 | .name		= "nuc900-wdt", | 
|  | 282 | .id		= -1, | 
|  | 283 | .num_resources	= ARRAY_SIZE(nuc900_wdt_resource), | 
|  | 284 | .resource	= nuc900_wdt_resource, | 
|  | 285 | }; | 
|  | 286 |  | 
|  | 287 | /* | 
|  | 288 | * public device definition between 910 and 920, or 910 | 
|  | 289 | * and 950 or 950 and 960...,their dev platform register | 
|  | 290 | * should be in specific file such as nuc950, nuc960 c | 
|  | 291 | * files rather than the public dev.c file here. so the | 
|  | 292 | * corresponding platform_device definition should not be | 
|  | 293 | * static. | 
|  | 294 | */ | 
|  | 295 |  | 
|  | 296 | /* RTC controller*/ | 
|  | 297 |  | 
|  | 298 | static struct resource nuc900_rtc_resource[] = { | 
|  | 299 | [0] = { | 
|  | 300 | .start = W90X900_PA_RTC, | 
|  | 301 | .end   = W90X900_PA_RTC + 0xff, | 
|  | 302 | .flags = IORESOURCE_MEM, | 
|  | 303 | }, | 
|  | 304 | [1] = { | 
|  | 305 | .start = IRQ_RTC, | 
|  | 306 | .end   = IRQ_RTC, | 
|  | 307 | .flags = IORESOURCE_IRQ, | 
|  | 308 | }, | 
|  | 309 | }; | 
|  | 310 |  | 
|  | 311 | struct platform_device nuc900_device_rtc = { | 
|  | 312 | .name		= "nuc900-rtc", | 
|  | 313 | .id		= -1, | 
|  | 314 | .num_resources	= ARRAY_SIZE(nuc900_rtc_resource), | 
|  | 315 | .resource	= nuc900_rtc_resource, | 
|  | 316 | }; | 
|  | 317 |  | 
|  | 318 | /*TouchScreen controller*/ | 
|  | 319 |  | 
|  | 320 | static struct resource nuc900_ts_resource[] = { | 
|  | 321 | [0] = { | 
|  | 322 | .start = W90X900_PA_ADC, | 
|  | 323 | .end   = W90X900_PA_ADC + W90X900_SZ_ADC-1, | 
|  | 324 | .flags = IORESOURCE_MEM, | 
|  | 325 | }, | 
|  | 326 | [1] = { | 
|  | 327 | .start = IRQ_ADC, | 
|  | 328 | .end   = IRQ_ADC, | 
|  | 329 | .flags = IORESOURCE_IRQ, | 
|  | 330 | }, | 
|  | 331 | }; | 
|  | 332 |  | 
|  | 333 | struct platform_device nuc900_device_ts = { | 
|  | 334 | .name		= "nuc900-ts", | 
|  | 335 | .id		= -1, | 
|  | 336 | .resource	= nuc900_ts_resource, | 
|  | 337 | .num_resources	= ARRAY_SIZE(nuc900_ts_resource), | 
|  | 338 | }; | 
|  | 339 |  | 
|  | 340 | /* FMI Device */ | 
|  | 341 |  | 
|  | 342 | static struct resource nuc900_fmi_resource[] = { | 
|  | 343 | [0] = { | 
|  | 344 | .start = W90X900_PA_FMI, | 
|  | 345 | .end   = W90X900_PA_FMI + W90X900_SZ_FMI - 1, | 
|  | 346 | .flags = IORESOURCE_MEM, | 
|  | 347 | }, | 
|  | 348 | [1] = { | 
|  | 349 | .start = IRQ_FMI, | 
|  | 350 | .end   = IRQ_FMI, | 
|  | 351 | .flags = IORESOURCE_IRQ, | 
|  | 352 | } | 
|  | 353 | }; | 
|  | 354 |  | 
|  | 355 | struct platform_device nuc900_device_fmi = { | 
|  | 356 | .name		= "nuc900-fmi", | 
|  | 357 | .id		= -1, | 
|  | 358 | .num_resources	= ARRAY_SIZE(nuc900_fmi_resource), | 
|  | 359 | .resource	= nuc900_fmi_resource, | 
|  | 360 | }; | 
|  | 361 |  | 
|  | 362 | /* KPI controller*/ | 
|  | 363 |  | 
|  | 364 | static struct resource nuc900_kpi_resource[] = { | 
|  | 365 | [0] = { | 
|  | 366 | .start = W90X900_PA_KPI, | 
|  | 367 | .end   = W90X900_PA_KPI + W90X900_SZ_KPI - 1, | 
|  | 368 | .flags = IORESOURCE_MEM, | 
|  | 369 | }, | 
|  | 370 | [1] = { | 
|  | 371 | .start = IRQ_KPI, | 
|  | 372 | .end   = IRQ_KPI, | 
|  | 373 | .flags = IORESOURCE_IRQ, | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | }; | 
|  | 377 |  | 
|  | 378 | struct platform_device nuc900_device_kpi = { | 
|  | 379 | .name		= "nuc900-kpi", | 
|  | 380 | .id		= -1, | 
|  | 381 | .num_resources	= ARRAY_SIZE(nuc900_kpi_resource), | 
|  | 382 | .resource	= nuc900_kpi_resource, | 
|  | 383 | }; | 
|  | 384 |  | 
| Wang Qiang | 8661970 | 2010-03-10 15:21:47 -0800 | [diff] [blame] | 385 | #ifdef CONFIG_FB_NUC900 | 
|  | 386 |  | 
|  | 387 | static struct resource nuc900_lcd_resource[] = { | 
|  | 388 | [0] = { | 
|  | 389 | .start = W90X900_PA_LCD, | 
|  | 390 | .end   = W90X900_PA_LCD + W90X900_SZ_LCD - 1, | 
|  | 391 | .flags = IORESOURCE_MEM, | 
|  | 392 | }, | 
|  | 393 | [1] = { | 
|  | 394 | .start = IRQ_LCD, | 
|  | 395 | .end   = IRQ_LCD, | 
|  | 396 | .flags = IORESOURCE_IRQ, | 
|  | 397 | } | 
|  | 398 | }; | 
|  | 399 |  | 
|  | 400 | static u64 nuc900_device_lcd_dmamask = -1; | 
|  | 401 | struct platform_device nuc900_device_lcd = { | 
|  | 402 | .name             = "nuc900-lcd", | 
|  | 403 | .id               = -1, | 
|  | 404 | .num_resources    = ARRAY_SIZE(nuc900_lcd_resource), | 
|  | 405 | .resource         = nuc900_lcd_resource, | 
|  | 406 | .dev              = { | 
|  | 407 | .dma_mask               = &nuc900_device_lcd_dmamask, | 
|  | 408 | .coherent_dma_mask      = -1, | 
|  | 409 | } | 
|  | 410 | }; | 
|  | 411 |  | 
|  | 412 | void  nuc900_fb_set_platdata(struct nuc900fb_mach_info *pd) | 
|  | 413 | { | 
|  | 414 | struct nuc900fb_mach_info *npd; | 
|  | 415 |  | 
|  | 416 | npd = kmalloc(sizeof(*npd), GFP_KERNEL); | 
|  | 417 | if (npd) { | 
|  | 418 | memcpy(npd, pd, sizeof(*npd)); | 
|  | 419 | nuc900_device_lcd.dev.platform_data = npd; | 
|  | 420 | } else { | 
|  | 421 | printk(KERN_ERR "no memory for LCD platform data\n"); | 
|  | 422 | } | 
|  | 423 | } | 
|  | 424 | #endif | 
|  | 425 |  | 
| wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 426 | /*Here should be your evb resourse,such as LCD*/ | 
|  | 427 |  | 
|  | 428 | static struct platform_device *nuc900_public_dev[] __initdata = { | 
|  | 429 | &nuc900_serial_device, | 
|  | 430 | &nuc900_flash_device, | 
|  | 431 | &nuc900_device_usb_ehci, | 
|  | 432 | &nuc900_device_usb_ohci, | 
|  | 433 | &nuc900_device_usbgadget, | 
|  | 434 | &nuc900_device_emc, | 
|  | 435 | &nuc900_device_spi, | 
|  | 436 | &nuc900_device_wdt, | 
|  | 437 | }; | 
|  | 438 |  | 
|  | 439 | /* Provide adding specific CPU platform devices API */ | 
|  | 440 |  | 
|  | 441 | void __init nuc900_board_init(struct platform_device **device, int size) | 
|  | 442 | { | 
|  | 443 | platform_add_devices(device, size); | 
|  | 444 | platform_add_devices(nuc900_public_dev, ARRAY_SIZE(nuc900_public_dev)); | 
|  | 445 | spi_register_board_info(nuc900_spi_board_info, | 
|  | 446 | ARRAY_SIZE(nuc900_spi_board_info)); | 
|  | 447 | } | 
|  | 448 |  |