setup.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * iop13xx platform Initialization
  3. * Copyright (c) 2005-2006, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. */
  19. #include <linux/serial_8250.h>
  20. #ifdef CONFIG_MTD_PHYSMAP
  21. #include <linux/mtd/physmap.h>
  22. #endif
  23. #include <asm/mach/map.h>
  24. #include <asm/hardware.h>
  25. #include <asm/irq.h>
  26. #define IOP13XX_UART_XTAL 33334000
  27. #define IOP13XX_SETUP_DEBUG 0
  28. #define PRINTK(x...) ((void)(IOP13XX_SETUP_DEBUG && printk(x)))
  29. /* Standard IO mapping for all IOP13XX based systems
  30. */
  31. static struct map_desc iop13xx_std_desc[] __initdata = {
  32. { /* mem mapped registers */
  33. .virtual = IOP13XX_PMMR_VIRT_MEM_BASE,
  34. .pfn = __phys_to_pfn(IOP13XX_PMMR_PHYS_MEM_BASE),
  35. .length = IOP13XX_PMMR_SIZE,
  36. .type = MT_DEVICE,
  37. }, { /* PCIE IO space */
  38. .virtual = IOP13XX_PCIE_LOWER_IO_VA,
  39. .pfn = __phys_to_pfn(IOP13XX_PCIE_LOWER_IO_PA),
  40. .length = IOP13XX_PCIX_IO_WINDOW_SIZE,
  41. .type = MT_DEVICE,
  42. }, { /* PCIX IO space */
  43. .virtual = IOP13XX_PCIX_LOWER_IO_VA,
  44. .pfn = __phys_to_pfn(IOP13XX_PCIX_LOWER_IO_PA),
  45. .length = IOP13XX_PCIX_IO_WINDOW_SIZE,
  46. .type = MT_DEVICE,
  47. },
  48. };
  49. static struct resource iop13xx_uart0_resources[] = {
  50. [0] = {
  51. .start = IOP13XX_UART0_PHYS,
  52. .end = IOP13XX_UART0_PHYS + 0x3f,
  53. .flags = IORESOURCE_MEM,
  54. },
  55. [1] = {
  56. .start = IRQ_IOP13XX_UART0,
  57. .end = IRQ_IOP13XX_UART0,
  58. .flags = IORESOURCE_IRQ
  59. }
  60. };
  61. static struct resource iop13xx_uart1_resources[] = {
  62. [0] = {
  63. .start = IOP13XX_UART1_PHYS,
  64. .end = IOP13XX_UART1_PHYS + 0x3f,
  65. .flags = IORESOURCE_MEM,
  66. },
  67. [1] = {
  68. .start = IRQ_IOP13XX_UART1,
  69. .end = IRQ_IOP13XX_UART1,
  70. .flags = IORESOURCE_IRQ
  71. }
  72. };
  73. static struct plat_serial8250_port iop13xx_uart0_data[] = {
  74. {
  75. .membase = (char*)(IOP13XX_UART0_VIRT),
  76. .mapbase = (IOP13XX_UART0_PHYS),
  77. .irq = IRQ_IOP13XX_UART0,
  78. .uartclk = IOP13XX_UART_XTAL,
  79. .regshift = 2,
  80. .iotype = UPIO_MEM,
  81. .flags = UPF_SKIP_TEST,
  82. },
  83. { },
  84. };
  85. static struct plat_serial8250_port iop13xx_uart1_data[] = {
  86. {
  87. .membase = (char*)(IOP13XX_UART1_VIRT),
  88. .mapbase = (IOP13XX_UART1_PHYS),
  89. .irq = IRQ_IOP13XX_UART1,
  90. .uartclk = IOP13XX_UART_XTAL,
  91. .regshift = 2,
  92. .iotype = UPIO_MEM,
  93. .flags = UPF_SKIP_TEST,
  94. },
  95. { },
  96. };
  97. /* The ids are fixed up later in iop13xx_platform_init */
  98. static struct platform_device iop13xx_uart0 = {
  99. .name = "serial8250",
  100. .id = 0,
  101. .dev.platform_data = iop13xx_uart0_data,
  102. .num_resources = 2,
  103. .resource = iop13xx_uart0_resources,
  104. };
  105. static struct platform_device iop13xx_uart1 = {
  106. .name = "serial8250",
  107. .id = 0,
  108. .dev.platform_data = iop13xx_uart1_data,
  109. .num_resources = 2,
  110. .resource = iop13xx_uart1_resources
  111. };
  112. static struct resource iop13xx_i2c_0_resources[] = {
  113. [0] = {
  114. .start = IOP13XX_I2C0_PHYS,
  115. .end = IOP13XX_I2C0_PHYS + 0x18,
  116. .flags = IORESOURCE_MEM,
  117. },
  118. [1] = {
  119. .start = IRQ_IOP13XX_I2C_0,
  120. .end = IRQ_IOP13XX_I2C_0,
  121. .flags = IORESOURCE_IRQ
  122. }
  123. };
  124. static struct resource iop13xx_i2c_1_resources[] = {
  125. [0] = {
  126. .start = IOP13XX_I2C1_PHYS,
  127. .end = IOP13XX_I2C1_PHYS + 0x18,
  128. .flags = IORESOURCE_MEM,
  129. },
  130. [1] = {
  131. .start = IRQ_IOP13XX_I2C_1,
  132. .end = IRQ_IOP13XX_I2C_1,
  133. .flags = IORESOURCE_IRQ
  134. }
  135. };
  136. static struct resource iop13xx_i2c_2_resources[] = {
  137. [0] = {
  138. .start = IOP13XX_I2C2_PHYS,
  139. .end = IOP13XX_I2C2_PHYS + 0x18,
  140. .flags = IORESOURCE_MEM,
  141. },
  142. [1] = {
  143. .start = IRQ_IOP13XX_I2C_2,
  144. .end = IRQ_IOP13XX_I2C_2,
  145. .flags = IORESOURCE_IRQ
  146. }
  147. };
  148. /* I2C controllers. The IOP13XX uses the same block as the IOP3xx, so
  149. * we just use the same device name.
  150. */
  151. /* The ids are fixed up later in iop13xx_platform_init */
  152. static struct platform_device iop13xx_i2c_0_controller = {
  153. .name = "IOP3xx-I2C",
  154. .id = 0,
  155. .num_resources = 2,
  156. .resource = iop13xx_i2c_0_resources
  157. };
  158. static struct platform_device iop13xx_i2c_1_controller = {
  159. .name = "IOP3xx-I2C",
  160. .id = 0,
  161. .num_resources = 2,
  162. .resource = iop13xx_i2c_1_resources
  163. };
  164. static struct platform_device iop13xx_i2c_2_controller = {
  165. .name = "IOP3xx-I2C",
  166. .id = 0,
  167. .num_resources = 2,
  168. .resource = iop13xx_i2c_2_resources
  169. };
  170. #ifdef CONFIG_MTD_PHYSMAP
  171. /* PBI Flash Device
  172. */
  173. static struct physmap_flash_data iq8134x_flash_data = {
  174. .width = 2,
  175. };
  176. static struct resource iq8134x_flash_resource = {
  177. .start = IQ81340_FLASHBASE,
  178. .end = 0,
  179. .flags = IORESOURCE_MEM,
  180. };
  181. static struct platform_device iq8134x_flash = {
  182. .name = "physmap-flash",
  183. .id = 0,
  184. .dev = { .platform_data = &iq8134x_flash_data, },
  185. .num_resources = 1,
  186. .resource = &iq8134x_flash_resource,
  187. };
  188. static unsigned long iq8134x_probe_flash_size(void)
  189. {
  190. uint8_t __iomem *flash_addr = ioremap(IQ81340_FLASHBASE, PAGE_SIZE);
  191. int i;
  192. char query[3];
  193. unsigned long size = 0;
  194. int width = iq8134x_flash_data.width;
  195. if (flash_addr) {
  196. /* send CFI 'query' command */
  197. writew(0x98, flash_addr);
  198. /* check for CFI compliance */
  199. for (i = 0; i < 3 * width; i += width)
  200. query[i / width] = readb(flash_addr + (0x10 * width) + i);
  201. /* read the size */
  202. if (memcmp(query, "QRY", 3) == 0)
  203. size = 1 << readb(flash_addr + (0x27 * width));
  204. /* send CFI 'read array' command */
  205. writew(0xff, flash_addr);
  206. iounmap(flash_addr);
  207. }
  208. return size;
  209. }
  210. #endif
  211. void __init iop13xx_map_io(void)
  212. {
  213. /* Initialize the Static Page Table maps */
  214. iotable_init(iop13xx_std_desc, ARRAY_SIZE(iop13xx_std_desc));
  215. }
  216. static int init_uart = 0;
  217. static int init_i2c = 0;
  218. void __init iop13xx_platform_init(void)
  219. {
  220. int i;
  221. u32 uart_idx, i2c_idx, plat_idx;
  222. struct platform_device *iop13xx_devices[IQ81340_MAX_PLAT_DEVICES];
  223. /* set the bases so we can read the device id */
  224. iop13xx_set_atu_mmr_bases();
  225. memset(iop13xx_devices, 0, sizeof(iop13xx_devices));
  226. if (init_uart == IOP13XX_INIT_UART_DEFAULT) {
  227. switch (iop13xx_dev_id()) {
  228. /* enable both uarts on iop341 and iop342 */
  229. case 0x3380:
  230. case 0x3384:
  231. case 0x3388:
  232. case 0x338c:
  233. case 0x3382:
  234. case 0x3386:
  235. case 0x338a:
  236. case 0x338e:
  237. init_uart |= IOP13XX_INIT_UART_0;
  238. init_uart |= IOP13XX_INIT_UART_1;
  239. break;
  240. /* only enable uart 1 */
  241. default:
  242. init_uart |= IOP13XX_INIT_UART_1;
  243. }
  244. }
  245. if (init_i2c == IOP13XX_INIT_I2C_DEFAULT) {
  246. switch (iop13xx_dev_id()) {
  247. /* enable all i2c units on iop341 and iop342 */
  248. case 0x3380:
  249. case 0x3384:
  250. case 0x3388:
  251. case 0x338c:
  252. case 0x3382:
  253. case 0x3386:
  254. case 0x338a:
  255. case 0x338e:
  256. init_i2c |= IOP13XX_INIT_I2C_0;
  257. init_i2c |= IOP13XX_INIT_I2C_1;
  258. init_i2c |= IOP13XX_INIT_I2C_2;
  259. break;
  260. /* only enable i2c 1 and 2 */
  261. default:
  262. init_i2c |= IOP13XX_INIT_I2C_1;
  263. init_i2c |= IOP13XX_INIT_I2C_2;
  264. }
  265. }
  266. plat_idx = 0;
  267. uart_idx = 0;
  268. i2c_idx = 0;
  269. /* uart 1 (if enabled) is ttyS0 */
  270. if (init_uart & IOP13XX_INIT_UART_1) {
  271. PRINTK("Adding uart1 to platform device list\n");
  272. iop13xx_uart1.id = uart_idx++;
  273. iop13xx_devices[plat_idx++] = &iop13xx_uart1;
  274. }
  275. if (init_uart & IOP13XX_INIT_UART_0) {
  276. PRINTK("Adding uart0 to platform device list\n");
  277. iop13xx_uart0.id = uart_idx++;
  278. iop13xx_devices[plat_idx++] = &iop13xx_uart0;
  279. }
  280. for(i = 0; i < IQ81340_NUM_I2C; i++) {
  281. if ((init_i2c & (1 << i)) && IOP13XX_SETUP_DEBUG)
  282. printk("Adding i2c%d to platform device list\n", i);
  283. switch(init_i2c & (1 << i)) {
  284. case IOP13XX_INIT_I2C_0:
  285. iop13xx_i2c_0_controller.id = i2c_idx++;
  286. iop13xx_devices[plat_idx++] =
  287. &iop13xx_i2c_0_controller;
  288. break;
  289. case IOP13XX_INIT_I2C_1:
  290. iop13xx_i2c_1_controller.id = i2c_idx++;
  291. iop13xx_devices[plat_idx++] =
  292. &iop13xx_i2c_1_controller;
  293. break;
  294. case IOP13XX_INIT_I2C_2:
  295. iop13xx_i2c_2_controller.id = i2c_idx++;
  296. iop13xx_devices[plat_idx++] =
  297. &iop13xx_i2c_2_controller;
  298. break;
  299. }
  300. }
  301. #ifdef CONFIG_MTD_PHYSMAP
  302. iq8134x_flash_resource.end = iq8134x_flash_resource.start +
  303. iq8134x_probe_flash_size() - 1;
  304. if (iq8134x_flash_resource.end > iq8134x_flash_resource.start)
  305. iop13xx_devices[plat_idx++] = &iq8134x_flash;
  306. else
  307. printk(KERN_ERR "%s: Failed to probe flash size\n", __FUNCTION__);
  308. #endif
  309. platform_add_devices(iop13xx_devices, plat_idx);
  310. }
  311. static int __init iop13xx_init_uart_setup(char *str)
  312. {
  313. if (str) {
  314. while (*str != '\0') {
  315. switch(*str) {
  316. case '0':
  317. init_uart |= IOP13XX_INIT_UART_0;
  318. break;
  319. case '1':
  320. init_uart |= IOP13XX_INIT_UART_1;
  321. break;
  322. case ',':
  323. case '=':
  324. break;
  325. default:
  326. PRINTK("\"iop13xx_init_uart\" malformed"
  327. " at character: \'%c\'", *str);
  328. *(str + 1) = '\0';
  329. init_uart = IOP13XX_INIT_UART_DEFAULT;
  330. }
  331. str++;
  332. }
  333. }
  334. return 1;
  335. }
  336. static int __init iop13xx_init_i2c_setup(char *str)
  337. {
  338. if (str) {
  339. while (*str != '\0') {
  340. switch(*str) {
  341. case '0':
  342. init_i2c |= IOP13XX_INIT_I2C_0;
  343. break;
  344. case '1':
  345. init_i2c |= IOP13XX_INIT_I2C_1;
  346. break;
  347. case '2':
  348. init_i2c |= IOP13XX_INIT_I2C_2;
  349. break;
  350. case ',':
  351. case '=':
  352. break;
  353. default:
  354. PRINTK("\"iop13xx_init_i2c\" malformed"
  355. " at character: \'%c\'", *str);
  356. *(str + 1) = '\0';
  357. init_i2c = IOP13XX_INIT_I2C_DEFAULT;
  358. }
  359. str++;
  360. }
  361. }
  362. return 1;
  363. }
  364. __setup("iop13xx_init_uart", iop13xx_init_uart_setup);
  365. __setup("iop13xx_init_i2c", iop13xx_init_i2c_setup);