setup.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /*
  2. * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
  3. * and RBTX49xx patch from CELF patch archive.
  4. *
  5. * 2003-2005 (c) MontaVista Software, Inc.
  6. * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/string.h>
  17. #include <linux/module.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/gpio.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/leds.h>
  25. #include <linux/sysdev.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/time.h>
  28. #include <asm/reboot.h>
  29. #include <asm/r4kcache.h>
  30. #include <asm/sections.h>
  31. #include <asm/txx9/generic.h>
  32. #include <asm/txx9/pci.h>
  33. #include <asm/txx9tmr.h>
  34. #include <asm/txx9/ndfmc.h>
  35. #include <asm/txx9/dmac.h>
  36. #ifdef CONFIG_CPU_TX49XX
  37. #include <asm/txx9/tx4938.h>
  38. #endif
  39. /* EBUSC settings of TX4927, etc. */
  40. struct resource txx9_ce_res[8];
  41. static char txx9_ce_res_name[8][4]; /* "CEn" */
  42. /* pcode, internal register */
  43. unsigned int txx9_pcode;
  44. char txx9_pcode_str[8];
  45. static struct resource txx9_reg_res = {
  46. .name = txx9_pcode_str,
  47. .flags = IORESOURCE_MEM,
  48. };
  49. void __init
  50. txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
  51. {
  52. int i;
  53. for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
  54. sprintf(txx9_ce_res_name[i], "CE%d", i);
  55. txx9_ce_res[i].flags = IORESOURCE_MEM;
  56. txx9_ce_res[i].name = txx9_ce_res_name[i];
  57. }
  58. txx9_pcode = pcode;
  59. sprintf(txx9_pcode_str, "TX%x", pcode);
  60. if (base) {
  61. txx9_reg_res.start = base & 0xfffffffffULL;
  62. txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
  63. request_resource(&iomem_resource, &txx9_reg_res);
  64. }
  65. }
  66. /* clocks */
  67. unsigned int txx9_master_clock;
  68. unsigned int txx9_cpu_clock;
  69. unsigned int txx9_gbus_clock;
  70. #ifdef CONFIG_CPU_TX39XX
  71. /* don't enable by default - see errata */
  72. int txx9_ccfg_toeon __initdata;
  73. #else
  74. int txx9_ccfg_toeon __initdata = 1;
  75. #endif
  76. /* Minimum CLK support */
  77. struct clk *clk_get(struct device *dev, const char *id)
  78. {
  79. if (!strcmp(id, "spi-baseclk"))
  80. return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 2);
  81. if (!strcmp(id, "imbus_clk"))
  82. return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
  83. return ERR_PTR(-ENOENT);
  84. }
  85. EXPORT_SYMBOL(clk_get);
  86. int clk_enable(struct clk *clk)
  87. {
  88. return 0;
  89. }
  90. EXPORT_SYMBOL(clk_enable);
  91. void clk_disable(struct clk *clk)
  92. {
  93. }
  94. EXPORT_SYMBOL(clk_disable);
  95. unsigned long clk_get_rate(struct clk *clk)
  96. {
  97. return (unsigned long)clk;
  98. }
  99. EXPORT_SYMBOL(clk_get_rate);
  100. void clk_put(struct clk *clk)
  101. {
  102. }
  103. EXPORT_SYMBOL(clk_put);
  104. /* GPIO support */
  105. #ifdef CONFIG_GENERIC_GPIO
  106. int gpio_to_irq(unsigned gpio)
  107. {
  108. return -EINVAL;
  109. }
  110. EXPORT_SYMBOL(gpio_to_irq);
  111. int irq_to_gpio(unsigned irq)
  112. {
  113. return -EINVAL;
  114. }
  115. EXPORT_SYMBOL(irq_to_gpio);
  116. #endif
  117. #define BOARD_VEC(board) extern struct txx9_board_vec board;
  118. #include <asm/txx9/boards.h>
  119. #undef BOARD_VEC
  120. struct txx9_board_vec *txx9_board_vec __initdata;
  121. static char txx9_system_type[32];
  122. static struct txx9_board_vec *board_vecs[] __initdata = {
  123. #define BOARD_VEC(board) &board,
  124. #include <asm/txx9/boards.h>
  125. #undef BOARD_VEC
  126. };
  127. static struct txx9_board_vec *__init find_board_byname(const char *name)
  128. {
  129. int i;
  130. /* search board_vecs table */
  131. for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
  132. if (strstr(board_vecs[i]->system, name))
  133. return board_vecs[i];
  134. }
  135. return NULL;
  136. }
  137. static void __init prom_init_cmdline(void)
  138. {
  139. int argc;
  140. int *argv32;
  141. int i; /* Always ignore the "-c" at argv[0] */
  142. if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) {
  143. /*
  144. * argc is not a valid number, or argv32 is not a valid
  145. * pointer
  146. */
  147. argc = 0;
  148. argv32 = NULL;
  149. } else {
  150. argc = (int)fw_arg0;
  151. argv32 = (int *)fw_arg1;
  152. }
  153. arcs_cmdline[0] = '\0';
  154. for (i = 1; i < argc; i++) {
  155. char *str = (char *)(long)argv32[i];
  156. if (i != 1)
  157. strcat(arcs_cmdline, " ");
  158. if (strchr(str, ' ')) {
  159. strcat(arcs_cmdline, "\"");
  160. strcat(arcs_cmdline, str);
  161. strcat(arcs_cmdline, "\"");
  162. } else
  163. strcat(arcs_cmdline, str);
  164. }
  165. }
  166. static int txx9_ic_disable __initdata;
  167. static int txx9_dc_disable __initdata;
  168. #if defined(CONFIG_CPU_TX49XX)
  169. /* flush all cache on very early stage (before 4k_cache_init) */
  170. static void __init early_flush_dcache(void)
  171. {
  172. unsigned int conf = read_c0_config();
  173. unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
  174. unsigned int linesz = 32;
  175. unsigned long addr, end;
  176. end = INDEX_BASE + dc_size / 4;
  177. /* 4way, waybit=0 */
  178. for (addr = INDEX_BASE; addr < end; addr += linesz) {
  179. cache_op(Index_Writeback_Inv_D, addr | 0);
  180. cache_op(Index_Writeback_Inv_D, addr | 1);
  181. cache_op(Index_Writeback_Inv_D, addr | 2);
  182. cache_op(Index_Writeback_Inv_D, addr | 3);
  183. }
  184. }
  185. static void __init txx9_cache_fixup(void)
  186. {
  187. unsigned int conf;
  188. conf = read_c0_config();
  189. /* flush and disable */
  190. if (txx9_ic_disable) {
  191. conf |= TX49_CONF_IC;
  192. write_c0_config(conf);
  193. }
  194. if (txx9_dc_disable) {
  195. early_flush_dcache();
  196. conf |= TX49_CONF_DC;
  197. write_c0_config(conf);
  198. }
  199. /* enable cache */
  200. conf = read_c0_config();
  201. if (!txx9_ic_disable)
  202. conf &= ~TX49_CONF_IC;
  203. if (!txx9_dc_disable)
  204. conf &= ~TX49_CONF_DC;
  205. write_c0_config(conf);
  206. if (conf & TX49_CONF_IC)
  207. pr_info("TX49XX I-Cache disabled.\n");
  208. if (conf & TX49_CONF_DC)
  209. pr_info("TX49XX D-Cache disabled.\n");
  210. }
  211. #elif defined(CONFIG_CPU_TX39XX)
  212. /* flush all cache on very early stage (before tx39_cache_init) */
  213. static void __init early_flush_dcache(void)
  214. {
  215. unsigned int conf = read_c0_config();
  216. unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
  217. TX39_CONF_DCS_SHIFT));
  218. unsigned int linesz = 16;
  219. unsigned long addr, end;
  220. end = INDEX_BASE + dc_size / 2;
  221. /* 2way, waybit=0 */
  222. for (addr = INDEX_BASE; addr < end; addr += linesz) {
  223. cache_op(Index_Writeback_Inv_D, addr | 0);
  224. cache_op(Index_Writeback_Inv_D, addr | 1);
  225. }
  226. }
  227. static void __init txx9_cache_fixup(void)
  228. {
  229. unsigned int conf;
  230. conf = read_c0_config();
  231. /* flush and disable */
  232. if (txx9_ic_disable) {
  233. conf &= ~TX39_CONF_ICE;
  234. write_c0_config(conf);
  235. }
  236. if (txx9_dc_disable) {
  237. early_flush_dcache();
  238. conf &= ~TX39_CONF_DCE;
  239. write_c0_config(conf);
  240. }
  241. /* enable cache */
  242. conf = read_c0_config();
  243. if (!txx9_ic_disable)
  244. conf |= TX39_CONF_ICE;
  245. if (!txx9_dc_disable)
  246. conf |= TX39_CONF_DCE;
  247. write_c0_config(conf);
  248. if (!(conf & TX39_CONF_ICE))
  249. pr_info("TX39XX I-Cache disabled.\n");
  250. if (!(conf & TX39_CONF_DCE))
  251. pr_info("TX39XX D-Cache disabled.\n");
  252. }
  253. #else
  254. static inline void txx9_cache_fixup(void)
  255. {
  256. }
  257. #endif
  258. static void __init preprocess_cmdline(void)
  259. {
  260. static char cmdline[COMMAND_LINE_SIZE] __initdata;
  261. char *s;
  262. strcpy(cmdline, arcs_cmdline);
  263. s = cmdline;
  264. arcs_cmdline[0] = '\0';
  265. while (s && *s) {
  266. char *str = strsep(&s, " ");
  267. if (strncmp(str, "board=", 6) == 0) {
  268. txx9_board_vec = find_board_byname(str + 6);
  269. continue;
  270. } else if (strncmp(str, "masterclk=", 10) == 0) {
  271. unsigned long val;
  272. if (strict_strtoul(str + 10, 10, &val) == 0)
  273. txx9_master_clock = val;
  274. continue;
  275. } else if (strcmp(str, "icdisable") == 0) {
  276. txx9_ic_disable = 1;
  277. continue;
  278. } else if (strcmp(str, "dcdisable") == 0) {
  279. txx9_dc_disable = 1;
  280. continue;
  281. } else if (strcmp(str, "toeoff") == 0) {
  282. txx9_ccfg_toeon = 0;
  283. continue;
  284. } else if (strcmp(str, "toeon") == 0) {
  285. txx9_ccfg_toeon = 1;
  286. continue;
  287. }
  288. if (arcs_cmdline[0])
  289. strcat(arcs_cmdline, " ");
  290. strcat(arcs_cmdline, str);
  291. }
  292. txx9_cache_fixup();
  293. }
  294. static void __init select_board(void)
  295. {
  296. const char *envstr;
  297. /* first, determine by "board=" argument in preprocess_cmdline() */
  298. if (txx9_board_vec)
  299. return;
  300. /* next, determine by "board" envvar */
  301. envstr = prom_getenv("board");
  302. if (envstr) {
  303. txx9_board_vec = find_board_byname(envstr);
  304. if (txx9_board_vec)
  305. return;
  306. }
  307. /* select "default" board */
  308. #ifdef CONFIG_CPU_TX39XX
  309. txx9_board_vec = &jmr3927_vec;
  310. #endif
  311. #ifdef CONFIG_CPU_TX49XX
  312. switch (TX4938_REV_PCODE()) {
  313. #ifdef CONFIG_TOSHIBA_RBTX4927
  314. case 0x4927:
  315. txx9_board_vec = &rbtx4927_vec;
  316. break;
  317. case 0x4937:
  318. txx9_board_vec = &rbtx4937_vec;
  319. break;
  320. #endif
  321. #ifdef CONFIG_TOSHIBA_RBTX4938
  322. case 0x4938:
  323. txx9_board_vec = &rbtx4938_vec;
  324. break;
  325. #endif
  326. #ifdef CONFIG_TOSHIBA_RBTX4939
  327. case 0x4939:
  328. txx9_board_vec = &rbtx4939_vec;
  329. break;
  330. #endif
  331. }
  332. #endif
  333. }
  334. void __init prom_init(void)
  335. {
  336. prom_init_cmdline();
  337. preprocess_cmdline();
  338. select_board();
  339. strcpy(txx9_system_type, txx9_board_vec->system);
  340. txx9_board_vec->prom_init();
  341. }
  342. void __init prom_free_prom_memory(void)
  343. {
  344. unsigned long saddr = PAGE_SIZE;
  345. unsigned long eaddr = __pa_symbol(&_text);
  346. if (saddr < eaddr)
  347. free_init_pages("prom memory", saddr, eaddr);
  348. }
  349. const char *get_system_type(void)
  350. {
  351. return txx9_system_type;
  352. }
  353. char * __init prom_getcmdline(void)
  354. {
  355. return &(arcs_cmdline[0]);
  356. }
  357. const char *__init prom_getenv(const char *name)
  358. {
  359. const s32 *str;
  360. if (fw_arg2 < CKSEG0)
  361. return NULL;
  362. str = (const s32 *)fw_arg2;
  363. /* YAMON style ("name", "value" pairs) */
  364. while (str[0] && str[1]) {
  365. if (!strcmp((const char *)(unsigned long)str[0], name))
  366. return (const char *)(unsigned long)str[1];
  367. str += 2;
  368. }
  369. return NULL;
  370. }
  371. static void __noreturn txx9_machine_halt(void)
  372. {
  373. local_irq_disable();
  374. clear_c0_status(ST0_IM);
  375. while (1) {
  376. if (cpu_wait) {
  377. (*cpu_wait)();
  378. if (cpu_has_counter) {
  379. /*
  380. * Clear counter interrupt while it
  381. * breaks WAIT instruction even if
  382. * masked.
  383. */
  384. write_c0_compare(0);
  385. }
  386. }
  387. }
  388. }
  389. /* Watchdog support */
  390. void __init txx9_wdt_init(unsigned long base)
  391. {
  392. struct resource res = {
  393. .start = base,
  394. .end = base + 0x100 - 1,
  395. .flags = IORESOURCE_MEM,
  396. };
  397. platform_device_register_simple("txx9wdt", -1, &res, 1);
  398. }
  399. void txx9_wdt_now(unsigned long base)
  400. {
  401. struct txx9_tmr_reg __iomem *tmrptr =
  402. ioremap(base, sizeof(struct txx9_tmr_reg));
  403. /* disable watch dog timer */
  404. __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
  405. __raw_writel(0, &tmrptr->tcr);
  406. /* kick watchdog */
  407. __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
  408. __raw_writel(1, &tmrptr->cpra); /* immediate */
  409. __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
  410. &tmrptr->tcr);
  411. }
  412. /* SPI support */
  413. void __init txx9_spi_init(int busid, unsigned long base, int irq)
  414. {
  415. struct resource res[] = {
  416. {
  417. .start = base,
  418. .end = base + 0x20 - 1,
  419. .flags = IORESOURCE_MEM,
  420. }, {
  421. .start = irq,
  422. .flags = IORESOURCE_IRQ,
  423. },
  424. };
  425. platform_device_register_simple("spi_txx9", busid,
  426. res, ARRAY_SIZE(res));
  427. }
  428. void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
  429. {
  430. struct platform_device *pdev =
  431. platform_device_alloc("tc35815-mac", id);
  432. if (!pdev ||
  433. platform_device_add_data(pdev, ethaddr, 6) ||
  434. platform_device_add(pdev))
  435. platform_device_put(pdev);
  436. }
  437. void __init txx9_sio_init(unsigned long baseaddr, int irq,
  438. unsigned int line, unsigned int sclk, int nocts)
  439. {
  440. #ifdef CONFIG_SERIAL_TXX9
  441. struct uart_port req;
  442. memset(&req, 0, sizeof(req));
  443. req.line = line;
  444. req.iotype = UPIO_MEM;
  445. req.membase = ioremap(baseaddr, 0x24);
  446. req.mapbase = baseaddr;
  447. req.irq = irq;
  448. if (!nocts)
  449. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  450. if (sclk) {
  451. req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
  452. req.uartclk = sclk;
  453. } else
  454. req.uartclk = TXX9_IMCLK;
  455. early_serial_txx9_setup(&req);
  456. #endif /* CONFIG_SERIAL_TXX9 */
  457. }
  458. #ifdef CONFIG_EARLY_PRINTK
  459. static void __init null_prom_putchar(char c)
  460. {
  461. }
  462. void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
  463. void __init prom_putchar(char c)
  464. {
  465. txx9_prom_putchar(c);
  466. }
  467. static void __iomem *early_txx9_sio_port;
  468. static void __init early_txx9_sio_putchar(char c)
  469. {
  470. #define TXX9_SICISR 0x0c
  471. #define TXX9_SITFIFO 0x1c
  472. #define TXX9_SICISR_TXALS 0x00000002
  473. while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
  474. TXX9_SICISR_TXALS))
  475. ;
  476. __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
  477. }
  478. void __init txx9_sio_putchar_init(unsigned long baseaddr)
  479. {
  480. early_txx9_sio_port = ioremap(baseaddr, 0x24);
  481. txx9_prom_putchar = early_txx9_sio_putchar;
  482. }
  483. #endif /* CONFIG_EARLY_PRINTK */
  484. /* wrappers */
  485. void __init plat_mem_setup(void)
  486. {
  487. ioport_resource.start = 0;
  488. ioport_resource.end = ~0UL; /* no limit */
  489. iomem_resource.start = 0;
  490. iomem_resource.end = ~0UL; /* no limit */
  491. /* fallback restart/halt routines */
  492. _machine_restart = (void (*)(char *))txx9_machine_halt;
  493. _machine_halt = txx9_machine_halt;
  494. pm_power_off = txx9_machine_halt;
  495. #ifdef CONFIG_PCI
  496. pcibios_plat_setup = txx9_pcibios_setup;
  497. #endif
  498. txx9_board_vec->mem_setup();
  499. }
  500. void __init arch_init_irq(void)
  501. {
  502. txx9_board_vec->irq_setup();
  503. }
  504. void __init plat_time_init(void)
  505. {
  506. #ifdef CONFIG_CPU_TX49XX
  507. mips_hpt_frequency = txx9_cpu_clock / 2;
  508. #endif
  509. txx9_board_vec->time_init();
  510. }
  511. static int __init _txx9_arch_init(void)
  512. {
  513. if (txx9_board_vec->arch_init)
  514. txx9_board_vec->arch_init();
  515. return 0;
  516. }
  517. arch_initcall(_txx9_arch_init);
  518. static int __init _txx9_device_init(void)
  519. {
  520. if (txx9_board_vec->device_init)
  521. txx9_board_vec->device_init();
  522. return 0;
  523. }
  524. device_initcall(_txx9_device_init);
  525. int (*txx9_irq_dispatch)(int pending);
  526. asmlinkage void plat_irq_dispatch(void)
  527. {
  528. int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  529. int irq = txx9_irq_dispatch(pending);
  530. if (likely(irq >= 0))
  531. do_IRQ(irq);
  532. else
  533. spurious_interrupt();
  534. }
  535. /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
  536. #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
  537. static unsigned long __swizzle_addr_none(unsigned long port)
  538. {
  539. return port;
  540. }
  541. unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
  542. EXPORT_SYMBOL(__swizzle_addr_b);
  543. #endif
  544. #ifdef NEEDS_TXX9_IOSWABW
  545. static u16 ioswabw_default(volatile u16 *a, u16 x)
  546. {
  547. return le16_to_cpu(x);
  548. }
  549. static u16 __mem_ioswabw_default(volatile u16 *a, u16 x)
  550. {
  551. return x;
  552. }
  553. u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default;
  554. EXPORT_SYMBOL(ioswabw);
  555. u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default;
  556. EXPORT_SYMBOL(__mem_ioswabw);
  557. #endif
  558. void __init txx9_physmap_flash_init(int no, unsigned long addr,
  559. unsigned long size,
  560. const struct physmap_flash_data *pdata)
  561. {
  562. #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
  563. struct resource res = {
  564. .start = addr,
  565. .end = addr + size - 1,
  566. .flags = IORESOURCE_MEM,
  567. };
  568. struct platform_device *pdev;
  569. #ifdef CONFIG_MTD_PARTITIONS
  570. static struct mtd_partition parts[2];
  571. struct physmap_flash_data pdata_part;
  572. /* If this area contained boot area, make separate partition */
  573. if (pdata->nr_parts == 0 && !pdata->parts &&
  574. addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
  575. !parts[0].name) {
  576. parts[0].name = "boot";
  577. parts[0].offset = 0x1fc00000 - addr;
  578. parts[0].size = addr + size - 0x1fc00000;
  579. parts[1].name = "user";
  580. parts[1].offset = 0;
  581. parts[1].size = 0x1fc00000 - addr;
  582. pdata_part = *pdata;
  583. pdata_part.nr_parts = ARRAY_SIZE(parts);
  584. pdata_part.parts = parts;
  585. pdata = &pdata_part;
  586. }
  587. #endif
  588. pdev = platform_device_alloc("physmap-flash", no);
  589. if (!pdev ||
  590. platform_device_add_resources(pdev, &res, 1) ||
  591. platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
  592. platform_device_add(pdev))
  593. platform_device_put(pdev);
  594. #endif
  595. }
  596. void __init txx9_ndfmc_init(unsigned long baseaddr,
  597. const struct txx9ndfmc_platform_data *pdata)
  598. {
  599. #if defined(CONFIG_MTD_NAND_TXX9NDFMC) || \
  600. defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE)
  601. struct resource res = {
  602. .start = baseaddr,
  603. .end = baseaddr + 0x1000 - 1,
  604. .flags = IORESOURCE_MEM,
  605. };
  606. struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
  607. if (!pdev ||
  608. platform_device_add_resources(pdev, &res, 1) ||
  609. platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
  610. platform_device_add(pdev))
  611. platform_device_put(pdev);
  612. #endif
  613. }
  614. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  615. static DEFINE_SPINLOCK(txx9_iocled_lock);
  616. #define TXX9_IOCLED_MAXLEDS 8
  617. struct txx9_iocled_data {
  618. struct gpio_chip chip;
  619. u8 cur_val;
  620. void __iomem *mmioaddr;
  621. struct gpio_led_platform_data pdata;
  622. struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
  623. char names[TXX9_IOCLED_MAXLEDS][32];
  624. };
  625. static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
  626. {
  627. struct txx9_iocled_data *data =
  628. container_of(chip, struct txx9_iocled_data, chip);
  629. return data->cur_val & (1 << offset);
  630. }
  631. static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
  632. int value)
  633. {
  634. struct txx9_iocled_data *data =
  635. container_of(chip, struct txx9_iocled_data, chip);
  636. unsigned long flags;
  637. spin_lock_irqsave(&txx9_iocled_lock, flags);
  638. if (value)
  639. data->cur_val |= 1 << offset;
  640. else
  641. data->cur_val &= ~(1 << offset);
  642. writeb(data->cur_val, data->mmioaddr);
  643. mmiowb();
  644. spin_unlock_irqrestore(&txx9_iocled_lock, flags);
  645. }
  646. static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
  647. {
  648. return 0;
  649. }
  650. static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
  651. int value)
  652. {
  653. txx9_iocled_set(chip, offset, value);
  654. return 0;
  655. }
  656. void __init txx9_iocled_init(unsigned long baseaddr,
  657. int basenum, unsigned int num, int lowactive,
  658. const char *color, char **deftriggers)
  659. {
  660. struct txx9_iocled_data *iocled;
  661. struct platform_device *pdev;
  662. int i;
  663. static char *default_triggers[] __initdata = {
  664. "heartbeat",
  665. "ide-disk",
  666. "nand-disk",
  667. NULL,
  668. };
  669. if (!deftriggers)
  670. deftriggers = default_triggers;
  671. iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
  672. if (!iocled)
  673. return;
  674. iocled->mmioaddr = ioremap(baseaddr, 1);
  675. if (!iocled->mmioaddr)
  676. goto out_free;
  677. iocled->chip.get = txx9_iocled_get;
  678. iocled->chip.set = txx9_iocled_set;
  679. iocled->chip.direction_input = txx9_iocled_dir_in;
  680. iocled->chip.direction_output = txx9_iocled_dir_out;
  681. iocled->chip.label = "iocled";
  682. iocled->chip.base = basenum;
  683. iocled->chip.ngpio = num;
  684. if (gpiochip_add(&iocled->chip))
  685. goto out_unmap;
  686. if (basenum < 0)
  687. basenum = iocled->chip.base;
  688. pdev = platform_device_alloc("leds-gpio", basenum);
  689. if (!pdev)
  690. goto out_gpio;
  691. iocled->pdata.num_leds = num;
  692. iocled->pdata.leds = iocled->leds;
  693. for (i = 0; i < num; i++) {
  694. struct gpio_led *led = &iocled->leds[i];
  695. snprintf(iocled->names[i], sizeof(iocled->names[i]),
  696. "iocled:%s:%u", color, i);
  697. led->name = iocled->names[i];
  698. led->gpio = basenum + i;
  699. led->active_low = lowactive;
  700. if (deftriggers && *deftriggers)
  701. led->default_trigger = *deftriggers++;
  702. }
  703. pdev->dev.platform_data = &iocled->pdata;
  704. if (platform_device_add(pdev))
  705. goto out_pdev;
  706. return;
  707. out_pdev:
  708. platform_device_put(pdev);
  709. out_gpio:
  710. if (gpiochip_remove(&iocled->chip))
  711. return;
  712. out_unmap:
  713. iounmap(iocled->mmioaddr);
  714. out_free:
  715. kfree(iocled);
  716. }
  717. #else /* CONFIG_LEDS_GPIO */
  718. void __init txx9_iocled_init(unsigned long baseaddr,
  719. int basenum, unsigned int num, int lowactive,
  720. const char *color, char **deftriggers)
  721. {
  722. }
  723. #endif /* CONFIG_LEDS_GPIO */
  724. void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
  725. const struct txx9dmac_platform_data *pdata)
  726. {
  727. #if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE)
  728. struct resource res[] = {
  729. {
  730. .start = baseaddr,
  731. .end = baseaddr + 0x800 - 1,
  732. .flags = IORESOURCE_MEM,
  733. #ifndef CONFIG_MACH_TX49XX
  734. }, {
  735. .start = irq,
  736. .flags = IORESOURCE_IRQ,
  737. #endif
  738. }
  739. };
  740. #ifdef CONFIG_MACH_TX49XX
  741. struct resource chan_res[] = {
  742. {
  743. .flags = IORESOURCE_IRQ,
  744. }
  745. };
  746. #endif
  747. struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
  748. struct txx9dmac_chan_platform_data cpdata;
  749. int i;
  750. if (!pdev ||
  751. platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
  752. platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
  753. platform_device_add(pdev)) {
  754. platform_device_put(pdev);
  755. return;
  756. }
  757. memset(&cpdata, 0, sizeof(cpdata));
  758. cpdata.dmac_dev = pdev;
  759. for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
  760. #ifdef CONFIG_MACH_TX49XX
  761. chan_res[0].start = irq + i;
  762. #endif
  763. pdev = platform_device_alloc("txx9dmac-chan",
  764. id * TXX9_DMA_MAX_NR_CHANNELS + i);
  765. if (!pdev ||
  766. #ifdef CONFIG_MACH_TX49XX
  767. platform_device_add_resources(pdev, chan_res,
  768. ARRAY_SIZE(chan_res)) ||
  769. #endif
  770. platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
  771. platform_device_add(pdev))
  772. platform_device_put(pdev);
  773. }
  774. #endif
  775. }
  776. void __init txx9_aclc_init(unsigned long baseaddr, int irq,
  777. unsigned int dmac_id,
  778. unsigned int dma_chan_out,
  779. unsigned int dma_chan_in)
  780. {
  781. #if defined(CONFIG_SND_SOC_TXX9ACLC) || \
  782. defined(CONFIG_SND_SOC_TXX9ACLC_MODULE)
  783. unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS;
  784. struct resource res[] = {
  785. {
  786. .start = baseaddr,
  787. .end = baseaddr + 0x100 - 1,
  788. .flags = IORESOURCE_MEM,
  789. }, {
  790. .start = irq,
  791. .flags = IORESOURCE_IRQ,
  792. }, {
  793. .name = "txx9dmac-chan",
  794. .start = dma_base + dma_chan_out,
  795. .flags = IORESOURCE_DMA,
  796. }, {
  797. .name = "txx9dmac-chan",
  798. .start = dma_base + dma_chan_in,
  799. .flags = IORESOURCE_DMA,
  800. }
  801. };
  802. struct platform_device *pdev =
  803. platform_device_alloc("txx9aclc-ac97", -1);
  804. if (!pdev ||
  805. platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
  806. platform_device_add(pdev))
  807. platform_device_put(pdev);
  808. #endif
  809. }
  810. static struct sysdev_class txx9_sramc_sysdev_class;
  811. struct txx9_sramc_sysdev {
  812. struct sys_device dev;
  813. struct bin_attribute bindata_attr;
  814. void __iomem *base;
  815. };
  816. static ssize_t txx9_sram_read(struct kobject *kobj,
  817. struct bin_attribute *bin_attr,
  818. char *buf, loff_t pos, size_t size)
  819. {
  820. struct txx9_sramc_sysdev *dev = bin_attr->private;
  821. size_t ramsize = bin_attr->size;
  822. if (pos >= ramsize)
  823. return 0;
  824. if (pos + size > ramsize)
  825. size = ramsize - pos;
  826. memcpy_fromio(buf, dev->base + pos, size);
  827. return size;
  828. }
  829. static ssize_t txx9_sram_write(struct kobject *kobj,
  830. struct bin_attribute *bin_attr,
  831. char *buf, loff_t pos, size_t size)
  832. {
  833. struct txx9_sramc_sysdev *dev = bin_attr->private;
  834. size_t ramsize = bin_attr->size;
  835. if (pos >= ramsize)
  836. return 0;
  837. if (pos + size > ramsize)
  838. size = ramsize - pos;
  839. memcpy_toio(dev->base + pos, buf, size);
  840. return size;
  841. }
  842. void __init txx9_sramc_init(struct resource *r)
  843. {
  844. struct txx9_sramc_sysdev *dev;
  845. size_t size;
  846. int err;
  847. if (!txx9_sramc_sysdev_class.name) {
  848. txx9_sramc_sysdev_class.name = "txx9_sram";
  849. err = sysdev_class_register(&txx9_sramc_sysdev_class);
  850. if (err) {
  851. txx9_sramc_sysdev_class.name = NULL;
  852. return;
  853. }
  854. }
  855. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  856. if (!dev)
  857. return;
  858. size = resource_size(r);
  859. dev->base = ioremap(r->start, size);
  860. if (!dev->base)
  861. goto exit;
  862. dev->dev.cls = &txx9_sramc_sysdev_class;
  863. dev->bindata_attr.attr.name = "bindata";
  864. dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
  865. dev->bindata_attr.read = txx9_sram_read;
  866. dev->bindata_attr.write = txx9_sram_write;
  867. dev->bindata_attr.size = size;
  868. dev->bindata_attr.private = dev;
  869. err = sysdev_register(&dev->dev);
  870. if (err)
  871. goto exit;
  872. err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
  873. if (err) {
  874. sysdev_unregister(&dev->dev);
  875. goto exit;
  876. }
  877. return;
  878. exit:
  879. if (dev) {
  880. if (dev->base)
  881. iounmap(dev->base);
  882. kfree(dev);
  883. }
  884. }