setup.c 23 KB

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