setup.c 20 KB

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