liquidLevelDataOperation.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. * R8A7740 processor support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/io.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/serial_sci.h>
  28. #include <linux/sh_dma.h>
  29. #include <linux/sh_timer.h>
  30. #include <linux/dma-mapping.h>
  31. #include <mach/dma-register.h>
  32. #include <mach/r8a7740.h>
  33. #include <mach/pm-rmobile.h>
  34. #include <mach/common.h>
  35. #include <mach/irqs.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/time.h>
  40. static struct map_desc r8a7740_io_desc[] __initdata = {
  41. /*
  42. * for CPGA/INTC/PFC
  43. * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
  44. */
  45. {
  46. .virtual = 0xe6000000,
  47. .pfn = __phys_to_pfn(0xe6000000),
  48. .length = 160 << 20,
  49. .type = MT_DEVICE_NONSHARED
  50. },
  51. #ifdef CONFIG_CACHE_L2X0
  52. /*
  53. * for l2x0_init()
  54. * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
  55. */
  56. {
  57. .virtual = 0xf0002000,
  58. .pfn = __phys_to_pfn(0xf0100000),
  59. .length = PAGE_SIZE,
  60. .type = MT_DEVICE_NONSHARED
  61. },
  62. #endif
  63. };
  64. void __init r8a7740_map_io(void)
  65. {
  66. iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
  67. }
  68. /* SCIFA0 */
  69. static struct plat_sci_port scif0_platform_data = {
  70. .mapbase = 0xe6c40000,
  71. .flags = UPF_BOOT_AUTOCONF,
  72. .scscr = SCSCR_RE | SCSCR_TE,
  73. .scbrr_algo_id = SCBRR_ALGO_4,
  74. .type = PORT_SCIFA,
  75. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
  76. };
  77. static struct platform_device scif0_device = {
  78. .name = "sh-sci",
  79. .id = 0,
  80. .dev = {
  81. .platform_data = &scif0_platform_data,
  82. },
  83. };
  84. /* SCIFA1 */
  85. static struct plat_sci_port scif1_platform_data = {
  86. .mapbase = 0xe6c50000,
  87. .flags = UPF_BOOT_AUTOCONF,
  88. .scscr = SCSCR_RE | SCSCR_TE,
  89. .scbrr_algo_id = SCBRR_ALGO_4,
  90. .type = PORT_SCIFA,
  91. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
  92. };
  93. static struct platform_device scif1_device = {
  94. .name = "sh-sci",
  95. .id = 1,
  96. .dev = {
  97. .platform_data = &scif1_platform_data,
  98. },
  99. };
  100. /* SCIFA2 */
  101. static struct plat_sci_port scif2_platform_data = {
  102. .mapbase = 0xe6c60000,
  103. .flags = UPF_BOOT_AUTOCONF,
  104. .scscr = SCSCR_RE | SCSCR_TE,
  105. .scbrr_algo_id = SCBRR_ALGO_4,
  106. .type = PORT_SCIFA,
  107. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
  108. };
  109. static struct platform_device scif2_device = {
  110. .name = "sh-sci",
  111. .id = 2,
  112. .dev = {
  113. .platform_data = &scif2_platform_data,
  114. },
  115. };
  116. /* SCIFA3 */
  117. static struct plat_sci_port scif3_platform_data = {
  118. .mapbase = 0xe6c70000,
  119. .flags = UPF_BOOT_AUTOCONF,
  120. .scscr = SCSCR_RE | SCSCR_TE,
  121. .scbrr_algo_id = SCBRR_ALGO_4,
  122. .type = PORT_SCIFA,
  123. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
  124. };
  125. static struct platform_device scif3_device = {
  126. .name = "sh-sci",
  127. .id = 3,
  128. .dev = {
  129. .platform_data = &scif3_platform_data,
  130. },
  131. };
  132. /* SCIFA4 */
  133. static struct plat_sci_port scif4_platform_data = {
  134. .mapbase = 0xe6c80000,
  135. .flags = UPF_BOOT_AUTOCONF,
  136. .scscr = SCSCR_RE | SCSCR_TE,
  137. .scbrr_algo_id = SCBRR_ALGO_4,
  138. .type = PORT_SCIFA,
  139. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
  140. };
  141. static struct platform_device scif4_device = {
  142. .name = "sh-sci",
  143. .id = 4,
  144. .dev = {
  145. .platform_data = &scif4_platform_data,
  146. },
  147. };
  148. /* SCIFA5 */
  149. static struct plat_sci_port scif5_platform_data = {
  150. .mapbase = 0xe6cb0000,
  151. .flags = UPF_BOOT_AUTOCONF,
  152. .scscr = SCSCR_RE | SCSCR_TE,
  153. .scbrr_algo_id = SCBRR_ALGO_4,
  154. .type = PORT_SCIFA,
  155. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
  156. };
  157. static struct platform_device scif5_device = {
  158. .name = "sh-sci",
  159. .id = 5,
  160. .dev = {
  161. .platform_data = &scif5_platform_data,
  162. },
  163. };
  164. /* SCIFA6 */
  165. static struct plat_sci_port scif6_platform_data = {
  166. .mapbase = 0xe6cc0000,
  167. .flags = UPF_BOOT_AUTOCONF,
  168. .scscr = SCSCR_RE | SCSCR_TE,
  169. .scbrr_algo_id = SCBRR_ALGO_4,
  170. .type = PORT_SCIFA,
  171. .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
  172. };
  173. static struct platform_device scif6_device = {
  174. .name = "sh-sci",
  175. .id = 6,
  176. .dev = {
  177. .platform_data = &scif6_platform_data,
  178. },
  179. };
  180. /* SCIFA7 */
  181. static struct plat_sci_port scif7_platform_data = {
  182. .mapbase = 0xe6cd0000,
  183. .flags = UPF_BOOT_AUTOCONF,
  184. .scscr = SCSCR_RE | SCSCR_TE,
  185. .scbrr_algo_id = SCBRR_ALGO_4,
  186. .type = PORT_SCIFA,
  187. .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
  188. };
  189. static struct platform_device scif7_device = {
  190. .name = "sh-sci",
  191. .id = 7,
  192. .dev = {
  193. .platform_data = &scif7_platform_data,
  194. },
  195. };
  196. /* SCIFB */
  197. static struct plat_sci_port scifb_platform_data = {
  198. .mapbase = 0xe6c30000,
  199. .flags = UPF_BOOT_AUTOCONF,
  200. .scscr = SCSCR_RE | SCSCR_TE,
  201. .scbrr_algo_id = SCBRR_ALGO_4,
  202. .type = PORT_SCIFB,
  203. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
  204. };
  205. static struct platform_device scifb_device = {
  206. .name = "sh-sci",
  207. .id = 8,
  208. .dev = {
  209. .platform_data = &scifb_platform_data,
  210. },
  211. };
  212. /* CMT */
  213. static struct sh_timer_config cmt10_platform_data = {
  214. .name = "CMT10",
  215. .channel_offset = 0x10,
  216. .timer_bit = 0,
  217. .clockevent_rating = 125,
  218. .clocksource_rating = 125,
  219. };
  220. static struct resource cmt10_resources[] = {
  221. [0] = {
  222. .name = "CMT10",
  223. .start = 0xe6138010,
  224. .end = 0xe613801b,
  225. .flags = IORESOURCE_MEM,
  226. },
  227. [1] = {
  228. .start = evt2irq(0x0b00),
  229. .flags = IORESOURCE_IRQ,
  230. },
  231. };
  232. static struct platform_device cmt10_device = {
  233. .name = "sh_cmt",
  234. .id = 10,
  235. .dev = {
  236. .platform_data = &cmt10_platform_data,
  237. },
  238. .resource = cmt10_resources,
  239. .num_resources = ARRAY_SIZE(cmt10_resources),
  240. };
  241. static struct platform_device *r8a7740_early_devices[] __initdata = {
  242. &scif0_device,
  243. &scif1_device,
  244. &scif2_device,
  245. &scif3_device,
  246. &scif4_device,
  247. &scif5_device,
  248. &scif6_device,
  249. &scif7_device,
  250. &scifb_device,
  251. &cmt10_device,
  252. };
  253. /* DMA */
  254. static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
  255. {
  256. .slave_id = SHDMA_SLAVE_SDHI0_TX,
  257. .addr = 0xe6850030,
  258. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  259. .mid_rid = 0xc1,
  260. }, {
  261. .slave_id = SHDMA_SLAVE_SDHI0_RX,
  262. .addr = 0xe6850030,
  263. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  264. .mid_rid = 0xc2,
  265. }, {
  266. .slave_id = SHDMA_SLAVE_SDHI1_TX,
  267. .addr = 0xe6860030,
  268. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  269. .mid_rid = 0xc9,
  270. }, {
  271. .slave_id = SHDMA_SLAVE_SDHI1_RX,
  272. .addr = 0xe6860030,
  273. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  274. .mid_rid = 0xca,
  275. }, {
  276. .slave_id = SHDMA_SLAVE_SDHI2_TX,
  277. .addr = 0xe6870030,
  278. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  279. .mid_rid = 0xcd,
  280. }, {
  281. .slave_id = SHDMA_SLAVE_SDHI2_RX,
  282. .addr = 0xe6870030,
  283. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  284. .mid_rid = 0xce,
  285. }, {
  286. .slave_id = SHDMA_SLAVE_FSIA_TX,
  287. .addr = 0xfe1f0024,
  288. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  289. .mid_rid = 0xb1,
  290. }, {
  291. .slave_id = SHDMA_SLAVE_FSIA_RX,
  292. .addr = 0xfe1f0020,
  293. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  294. .mid_rid = 0xb2,
  295. }, {
  296. .slave_id = SHDMA_SLAVE_FSIB_TX,
  297. .addr = 0xfe1f0064,
  298. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  299. .mid_rid = 0xb5,
  300. },
  301. };
  302. #define DMA_CHANNEL(a, b, c) \
  303. { \
  304. .offset = a, \
  305. .dmars = b, \
  306. .dmars_bit = c, \
  307. .chclr_offset = (0x220 - 0x20) + a \
  308. }
  309. static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
  310. DMA_CHANNEL(0x00, 0, 0),
  311. DMA_CHANNEL(0x10, 0, 8),
  312. DMA_CHANNEL(0x20, 4, 0),
  313. DMA_CHANNEL(0x30, 4, 8),
  314. DMA_CHANNEL(0x50, 8, 0),
  315. DMA_CHANNEL(0x60, 8, 8),
  316. };
  317. static struct sh_dmae_pdata dma_platform_data = {
  318. .slave = r8a7740_dmae_slaves,
  319. .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
  320. .channel = r8a7740_dmae_channels,
  321. .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
  322. .ts_low_shift = TS_LOW_SHIFT,
  323. .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
  324. .ts_high_shift = TS_HI_SHIFT,
  325. .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
  326. .ts_shift = dma_ts_shift,
  327. .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
  328. .dmaor_init = DMAOR_DME,
  329. .chclr_present = 1,
  330. };
  331. /* Resource order important! */
  332. static struct resource r8a7740_dmae0_resources[] = {
  333. {
  334. /* Channel registers and DMAOR */
  335. .start = 0xfe008020,
  336. .end = 0xfe00828f,
  337. .flags = IORESOURCE_MEM,
  338. },
  339. {
  340. /* DMARSx */
  341. .start = 0xfe009000,
  342. .end = 0xfe00900b,
  343. .flags = IORESOURCE_MEM,
  344. },
  345. {
  346. .name = "error_irq",
  347. .start = evt2irq(0x20c0),
  348. .end = evt2irq(0x20c0),
  349. .flags = IORESOURCE_IRQ,
  350. },
  351. {
  352. /* IRQ for channels 0-5 */
  353. .start = evt2irq(0x2000),
  354. .end = evt2irq(0x20a0),
  355. .flags = IORESOURCE_IRQ,
  356. },
  357. };
  358. /* Resource order important! */
  359. static struct resource r8a7740_dmae1_resources[] = {
  360. {
  361. /* Channel registers and DMAOR */
  362. .start = 0xfe018020,
  363. .end = 0xfe01828f,
  364. .flags = IORESOURCE_MEM,
  365. },
  366. {
  367. /* DMARSx */
  368. .start = 0xfe019000,
  369. .end = 0xfe01900b,
  370. .flags = IORESOURCE_MEM,
  371. },
  372. {
  373. .name = "error_irq",
  374. .start = evt2irq(0x21c0),
  375. .end = evt2irq(0x21c0),
  376. .flags = IORESOURCE_IRQ,
  377. },
  378. {
  379. /* IRQ for channels 0-5 */
  380. .start = evt2irq(0x2100),
  381. .end = evt2irq(0x21a0),
  382. .flags = IORESOURCE_IRQ,
  383. },
  384. };
  385. /* Resource order important! */
  386. static struct resource r8a7740_dmae2_resources[] = {
  387. {
  388. /* Channel registers and DMAOR */
  389. .start = 0xfe028020,
  390. .end = 0xfe02828f,
  391. .flags = IORESOURCE_MEM,
  392. },
  393. {
  394. /* DMARSx */
  395. .start = 0xfe029000,
  396. .end = 0xfe02900b,
  397. .flags = IORESOURCE_MEM,
  398. },
  399. {
  400. .name = "error_irq",
  401. .start = evt2irq(0x22c0),
  402. .end = evt2irq(0x22c0),
  403. .flags = IORESOURCE_IRQ,
  404. },
  405. {
  406. /* IRQ for channels 0-5 */
  407. .start = evt2irq(0x2200),
  408. .end = evt2irq(0x22a0),
  409. .flags = IORESOURCE_IRQ,
  410. },
  411. };
  412. static struct platform_device dma0_device = {
  413. .name = "sh-dma-engine",
  414. .id = 0,
  415. .resource = r8a7740_dmae0_resources,
  416. .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
  417. .dev = {
  418. .platform_data = &dma_platform_data,
  419. },
  420. };
  421. static struct platform_device dma1_device = {
  422. .name = "sh-dma-engine",
  423. .id = 1,
  424. .resource = r8a7740_dmae1_resources,
  425. .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
  426. .dev = {
  427. .platform_data = &dma_platform_data,
  428. },
  429. };
  430. static struct platform_device dma2_device = {
  431. .name = "sh-dma-engine",
  432. .id = 2,
  433. .resource = r8a7740_dmae2_resources,
  434. .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
  435. .dev = {
  436. .platform_data = &dma_platform_data,
  437. },
  438. };
  439. /* USB-DMAC */
  440. static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
  441. {
  442. .offset = 0,
  443. }, {
  444. .offset = 0x20,
  445. },
  446. };
  447. static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
  448. {
  449. .slave_id = SHDMA_SLAVE_USBHS_TX,
  450. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  451. }, {
  452. .slave_id = SHDMA_SLAVE_USBHS_RX,
  453. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  454. },
  455. };
  456. static struct sh_dmae_pdata usb_dma_platform_data = {
  457. .slave = r8a7740_usb_dma_slaves,
  458. .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
  459. .channel = r8a7740_usb_dma_channels,
  460. .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
  461. .ts_low_shift = USBTS_LOW_SHIFT,
  462. .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
  463. .ts_high_shift = USBTS_HI_SHIFT,
  464. .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
  465. .ts_shift = dma_usbts_shift,
  466. .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
  467. .dmaor_init = DMAOR_DME,
  468. .chcr_offset = 0x14,
  469. .chcr_ie_bit = 1 << 5,
  470. .dmaor_is_32bit = 1,
  471. .needs_tend_set = 1,
  472. .no_dmars = 1,
  473. .slave_only = 1,
  474. };