808-guts-support-layerscape.patch 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. From 45b0e1589b25ea3106a8c8d18bf653fde95baa9f Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Wed, 17 Jan 2018 15:34:22 +0800
  4. Subject: [PATCH 20/30] guts: support layerscape
  5. This is an integrated patch for layerscape guts support.
  6. Signed-off-by: Roy Pledge <[email protected]>
  7. Signed-off-by: Geert Uytterhoeven <[email protected]>
  8. Signed-off-by: Amrita Kumari <[email protected]>
  9. Signed-off-by: Yangbo Lu <[email protected]>
  10. ---
  11. drivers/soc/fsl/guts.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++
  12. include/linux/fsl/guts.h | 125 +++++++++++++++----------
  13. 2 files changed, 315 insertions(+), 48 deletions(-)
  14. create mode 100644 drivers/soc/fsl/guts.c
  15. --- /dev/null
  16. +++ b/drivers/soc/fsl/guts.c
  17. @@ -0,0 +1,238 @@
  18. +/*
  19. + * Freescale QorIQ Platforms GUTS Driver
  20. + *
  21. + * Copyright (C) 2016 Freescale Semiconductor, Inc.
  22. + *
  23. + * This program is free software; you can redistribute it and/or modify
  24. + * it under the terms of the GNU General Public License as published by
  25. + * the Free Software Foundation; either version 2 of the License, or
  26. + * (at your option) any later version.
  27. + */
  28. +
  29. +#include <linux/io.h>
  30. +#include <linux/slab.h>
  31. +#include <linux/module.h>
  32. +#include <linux/of_fdt.h>
  33. +#include <linux/sys_soc.h>
  34. +#include <linux/of_address.h>
  35. +#include <linux/platform_device.h>
  36. +#include <linux/fsl/guts.h>
  37. +
  38. +struct guts {
  39. + struct ccsr_guts __iomem *regs;
  40. + bool little_endian;
  41. +};
  42. +
  43. +struct fsl_soc_die_attr {
  44. + char *die;
  45. + u32 svr;
  46. + u32 mask;
  47. +};
  48. +
  49. +static struct guts *guts;
  50. +static struct soc_device_attribute soc_dev_attr;
  51. +static struct soc_device *soc_dev;
  52. +
  53. +
  54. +/* SoC die attribute definition for QorIQ platform */
  55. +static const struct fsl_soc_die_attr fsl_soc_die[] = {
  56. + /*
  57. + * Power Architecture-based SoCs T Series
  58. + */
  59. +
  60. + /* Die: T4240, SoC: T4240/T4160/T4080 */
  61. + { .die = "T4240",
  62. + .svr = 0x82400000,
  63. + .mask = 0xfff00000,
  64. + },
  65. + /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
  66. + { .die = "T1040",
  67. + .svr = 0x85200000,
  68. + .mask = 0xfff00000,
  69. + },
  70. + /* Die: T2080, SoC: T2080/T2081 */
  71. + { .die = "T2080",
  72. + .svr = 0x85300000,
  73. + .mask = 0xfff00000,
  74. + },
  75. + /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
  76. + { .die = "T1024",
  77. + .svr = 0x85400000,
  78. + .mask = 0xfff00000,
  79. + },
  80. +
  81. + /*
  82. + * ARM-based SoCs LS Series
  83. + */
  84. +
  85. + /* Die: LS1043A, SoC: LS1043A/LS1023A */
  86. + { .die = "LS1043A",
  87. + .svr = 0x87920000,
  88. + .mask = 0xffff0000,
  89. + },
  90. + /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
  91. + { .die = "LS2080A",
  92. + .svr = 0x87010000,
  93. + .mask = 0xff3f0000,
  94. + },
  95. + /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
  96. + { .die = "LS1088A",
  97. + .svr = 0x87030000,
  98. + .mask = 0xff3f0000,
  99. + },
  100. + /* Die: LS1012A, SoC: LS1012A */
  101. + { .die = "LS1012A",
  102. + .svr = 0x87040000,
  103. + .mask = 0xffff0000,
  104. + },
  105. + /* Die: LS1046A, SoC: LS1046A/LS1026A */
  106. + { .die = "LS1046A",
  107. + .svr = 0x87070000,
  108. + .mask = 0xffff0000,
  109. + },
  110. + /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
  111. + { .die = "LS2088A",
  112. + .svr = 0x87090000,
  113. + .mask = 0xff3f0000,
  114. + },
  115. + /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
  116. + { .die = "LS1021A",
  117. + .svr = 0x87000000,
  118. + .mask = 0xfff70000,
  119. + },
  120. + { },
  121. +};
  122. +
  123. +static const struct fsl_soc_die_attr *fsl_soc_die_match(
  124. + u32 svr, const struct fsl_soc_die_attr *matches)
  125. +{
  126. + while (matches->svr) {
  127. + if (matches->svr == (svr & matches->mask))
  128. + return matches;
  129. + matches++;
  130. + };
  131. + return NULL;
  132. +}
  133. +
  134. +u32 fsl_guts_get_svr(void)
  135. +{
  136. + u32 svr = 0;
  137. +
  138. + if (!guts || !guts->regs)
  139. + return svr;
  140. +
  141. + if (guts->little_endian)
  142. + svr = ioread32(&guts->regs->svr);
  143. + else
  144. + svr = ioread32be(&guts->regs->svr);
  145. +
  146. + return svr;
  147. +}
  148. +EXPORT_SYMBOL(fsl_guts_get_svr);
  149. +
  150. +static int fsl_guts_probe(struct platform_device *pdev)
  151. +{
  152. + struct device_node *np = pdev->dev.of_node;
  153. + struct device *dev = &pdev->dev;
  154. + struct resource *res;
  155. + const struct fsl_soc_die_attr *soc_die;
  156. + const char *machine;
  157. + u32 svr;
  158. +
  159. + /* Initialize guts */
  160. + guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL);
  161. + if (!guts)
  162. + return -ENOMEM;
  163. +
  164. + guts->little_endian = of_property_read_bool(np, "little-endian");
  165. +
  166. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  167. + guts->regs = devm_ioremap_resource(dev, res);
  168. + if (IS_ERR(guts->regs))
  169. + return PTR_ERR(guts->regs);
  170. +
  171. + /* Register soc device */
  172. + machine = of_flat_dt_get_machine_name();
  173. + if (machine)
  174. + soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL);
  175. +
  176. + svr = fsl_guts_get_svr();
  177. + soc_die = fsl_soc_die_match(svr, fsl_soc_die);
  178. + if (soc_die) {
  179. + soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL,
  180. + "QorIQ %s", soc_die->die);
  181. + } else {
  182. + soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
  183. + }
  184. + soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
  185. + "svr:0x%08x", svr);
  186. + soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
  187. + (svr >> 4) & 0xf, svr & 0xf);
  188. +
  189. + soc_dev = soc_device_register(&soc_dev_attr);
  190. + if (IS_ERR(soc_dev))
  191. + return PTR_ERR(soc_dev);
  192. +
  193. + pr_info("Machine: %s\n", soc_dev_attr.machine);
  194. + pr_info("SoC family: %s\n", soc_dev_attr.family);
  195. + pr_info("SoC ID: %s, Revision: %s\n",
  196. + soc_dev_attr.soc_id, soc_dev_attr.revision);
  197. + return 0;
  198. +}
  199. +
  200. +static int fsl_guts_remove(struct platform_device *dev)
  201. +{
  202. + soc_device_unregister(soc_dev);
  203. + return 0;
  204. +}
  205. +
  206. +/*
  207. + * Table for matching compatible strings, for device tree
  208. + * guts node, for Freescale QorIQ SOCs.
  209. + */
  210. +static const struct of_device_id fsl_guts_of_match[] = {
  211. + { .compatible = "fsl,qoriq-device-config-1.0", },
  212. + { .compatible = "fsl,qoriq-device-config-2.0", },
  213. + { .compatible = "fsl,p1010-guts", },
  214. + { .compatible = "fsl,p1020-guts", },
  215. + { .compatible = "fsl,p1021-guts", },
  216. + { .compatible = "fsl,p1022-guts", },
  217. + { .compatible = "fsl,p1023-guts", },
  218. + { .compatible = "fsl,p2020-guts", },
  219. + { .compatible = "fsl,bsc9131-guts", },
  220. + { .compatible = "fsl,bsc9132-guts", },
  221. + { .compatible = "fsl,mpc8536-guts", },
  222. + { .compatible = "fsl,mpc8544-guts", },
  223. + { .compatible = "fsl,mpc8548-guts", },
  224. + { .compatible = "fsl,mpc8568-guts", },
  225. + { .compatible = "fsl,mpc8569-guts", },
  226. + { .compatible = "fsl,mpc8572-guts", },
  227. + { .compatible = "fsl,ls1021a-dcfg", },
  228. + { .compatible = "fsl,ls1043a-dcfg", },
  229. + { .compatible = "fsl,ls1046a-dcfg", },
  230. + { .compatible = "fsl,ls2080a-dcfg", },
  231. + { .compatible = "fsl,ls1088a-dcfg", },
  232. + {}
  233. +};
  234. +MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
  235. +
  236. +static struct platform_driver fsl_guts_driver = {
  237. + .driver = {
  238. + .name = "fsl-guts",
  239. + .of_match_table = fsl_guts_of_match,
  240. + },
  241. + .probe = fsl_guts_probe,
  242. + .remove = fsl_guts_remove,
  243. +};
  244. +
  245. +static int __init fsl_guts_init(void)
  246. +{
  247. + return platform_driver_register(&fsl_guts_driver);
  248. +}
  249. +core_initcall(fsl_guts_init);
  250. +
  251. +static void __exit fsl_guts_exit(void)
  252. +{
  253. + platform_driver_unregister(&fsl_guts_driver);
  254. +}
  255. +module_exit(fsl_guts_exit);
  256. --- a/include/linux/fsl/guts.h
  257. +++ b/include/linux/fsl/guts.h
  258. @@ -30,83 +30,112 @@
  259. * #ifdefs.
  260. */
  261. struct ccsr_guts {
  262. - __be32 porpllsr; /* 0x.0000 - POR PLL Ratio Status Register */
  263. - __be32 porbmsr; /* 0x.0004 - POR Boot Mode Status Register */
  264. - __be32 porimpscr; /* 0x.0008 - POR I/O Impedance Status and Control Register */
  265. - __be32 pordevsr; /* 0x.000c - POR I/O Device Status Register */
  266. - __be32 pordbgmsr; /* 0x.0010 - POR Debug Mode Status Register */
  267. - __be32 pordevsr2; /* 0x.0014 - POR device status register 2 */
  268. + u32 porpllsr; /* 0x.0000 - POR PLL Ratio Status Register */
  269. + u32 porbmsr; /* 0x.0004 - POR Boot Mode Status Register */
  270. + u32 porimpscr; /* 0x.0008 - POR I/O Impedance Status and
  271. + * Control Register
  272. + */
  273. + u32 pordevsr; /* 0x.000c - POR I/O Device Status Register */
  274. + u32 pordbgmsr; /* 0x.0010 - POR Debug Mode Status Register */
  275. + u32 pordevsr2; /* 0x.0014 - POR device status register 2 */
  276. u8 res018[0x20 - 0x18];
  277. - __be32 porcir; /* 0x.0020 - POR Configuration Information Register */
  278. + u32 porcir; /* 0x.0020 - POR Configuration Information
  279. + * Register
  280. + */
  281. u8 res024[0x30 - 0x24];
  282. - __be32 gpiocr; /* 0x.0030 - GPIO Control Register */
  283. + u32 gpiocr; /* 0x.0030 - GPIO Control Register */
  284. u8 res034[0x40 - 0x34];
  285. - __be32 gpoutdr; /* 0x.0040 - General-Purpose Output Data Register */
  286. + u32 gpoutdr; /* 0x.0040 - General-Purpose Output Data
  287. + * Register
  288. + */
  289. u8 res044[0x50 - 0x44];
  290. - __be32 gpindr; /* 0x.0050 - General-Purpose Input Data Register */
  291. + u32 gpindr; /* 0x.0050 - General-Purpose Input Data
  292. + * Register
  293. + */
  294. u8 res054[0x60 - 0x54];
  295. - __be32 pmuxcr; /* 0x.0060 - Alternate Function Signal Multiplex Control */
  296. - __be32 pmuxcr2; /* 0x.0064 - Alternate function signal multiplex control 2 */
  297. - __be32 dmuxcr; /* 0x.0068 - DMA Mux Control Register */
  298. + u32 pmuxcr; /* 0x.0060 - Alternate Function Signal
  299. + * Multiplex Control
  300. + */
  301. + u32 pmuxcr2; /* 0x.0064 - Alternate function signal
  302. + * multiplex control 2
  303. + */
  304. + u32 dmuxcr; /* 0x.0068 - DMA Mux Control Register */
  305. u8 res06c[0x70 - 0x6c];
  306. - __be32 devdisr; /* 0x.0070 - Device Disable Control */
  307. + u32 devdisr; /* 0x.0070 - Device Disable Control */
  308. #define CCSR_GUTS_DEVDISR_TB1 0x00001000
  309. #define CCSR_GUTS_DEVDISR_TB0 0x00004000
  310. - __be32 devdisr2; /* 0x.0074 - Device Disable Control 2 */
  311. + u32 devdisr2; /* 0x.0074 - Device Disable Control 2 */
  312. u8 res078[0x7c - 0x78];
  313. - __be32 pmjcr; /* 0x.007c - 4 Power Management Jog Control Register */
  314. - __be32 powmgtcsr; /* 0x.0080 - Power Management Status and Control Register */
  315. - __be32 pmrccr; /* 0x.0084 - Power Management Reset Counter Configuration Register */
  316. - __be32 pmpdccr; /* 0x.0088 - Power Management Power Down Counter Configuration Register */
  317. - __be32 pmcdr; /* 0x.008c - 4Power management clock disable register */
  318. - __be32 mcpsumr; /* 0x.0090 - Machine Check Summary Register */
  319. - __be32 rstrscr; /* 0x.0094 - Reset Request Status and Control Register */
  320. - __be32 ectrstcr; /* 0x.0098 - Exception reset control register */
  321. - __be32 autorstsr; /* 0x.009c - Automatic reset status register */
  322. - __be32 pvr; /* 0x.00a0 - Processor Version Register */
  323. - __be32 svr; /* 0x.00a4 - System Version Register */
  324. + u32 pmjcr; /* 0x.007c - 4 Power Management Jog Control
  325. + * Register
  326. + */
  327. + u32 powmgtcsr; /* 0x.0080 - Power Management Status and
  328. + * Control Register
  329. + */
  330. + u32 pmrccr; /* 0x.0084 - Power Management Reset Counter
  331. + * Configuration Register
  332. + */
  333. + u32 pmpdccr; /* 0x.0088 - Power Management Power Down Counter
  334. + * Configuration Register
  335. + */
  336. + u32 pmcdr; /* 0x.008c - 4Power management clock disable
  337. + * register
  338. + */
  339. + u32 mcpsumr; /* 0x.0090 - Machine Check Summary Register */
  340. + u32 rstrscr; /* 0x.0094 - Reset Request Status and
  341. + * Control Register
  342. + */
  343. + u32 ectrstcr; /* 0x.0098 - Exception reset control register */
  344. + u32 autorstsr; /* 0x.009c - Automatic reset status register */
  345. + u32 pvr; /* 0x.00a0 - Processor Version Register */
  346. + u32 svr; /* 0x.00a4 - System Version Register */
  347. u8 res0a8[0xb0 - 0xa8];
  348. - __be32 rstcr; /* 0x.00b0 - Reset Control Register */
  349. + u32 rstcr; /* 0x.00b0 - Reset Control Register */
  350. u8 res0b4[0xc0 - 0xb4];
  351. - __be32 iovselsr; /* 0x.00c0 - I/O voltage select status register
  352. + u32 iovselsr; /* 0x.00c0 - I/O voltage select status register
  353. Called 'elbcvselcr' on 86xx SOCs */
  354. u8 res0c4[0x100 - 0xc4];
  355. - __be32 rcwsr[16]; /* 0x.0100 - Reset Control Word Status registers
  356. + u32 rcwsr[16]; /* 0x.0100 - Reset Control Word Status registers
  357. There are 16 registers */
  358. u8 res140[0x224 - 0x140];
  359. - __be32 iodelay1; /* 0x.0224 - IO delay control register 1 */
  360. - __be32 iodelay2; /* 0x.0228 - IO delay control register 2 */
  361. + u32 iodelay1; /* 0x.0224 - IO delay control register 1 */
  362. + u32 iodelay2; /* 0x.0228 - IO delay control register 2 */
  363. u8 res22c[0x604 - 0x22c];
  364. - __be32 pamubypenr; /* 0x.604 - PAMU bypass enable register */
  365. + u32 pamubypenr; /* 0x.604 - PAMU bypass enable register */
  366. u8 res608[0x800 - 0x608];
  367. - __be32 clkdvdr; /* 0x.0800 - Clock Divide Register */
  368. + u32 clkdvdr; /* 0x.0800 - Clock Divide Register */
  369. u8 res804[0x900 - 0x804];
  370. - __be32 ircr; /* 0x.0900 - Infrared Control Register */
  371. + u32 ircr; /* 0x.0900 - Infrared Control Register */
  372. u8 res904[0x908 - 0x904];
  373. - __be32 dmacr; /* 0x.0908 - DMA Control Register */
  374. + u32 dmacr; /* 0x.0908 - DMA Control Register */
  375. u8 res90c[0x914 - 0x90c];
  376. - __be32 elbccr; /* 0x.0914 - eLBC Control Register */
  377. + u32 elbccr; /* 0x.0914 - eLBC Control Register */
  378. u8 res918[0xb20 - 0x918];
  379. - __be32 ddr1clkdr; /* 0x.0b20 - DDR1 Clock Disable Register */
  380. - __be32 ddr2clkdr; /* 0x.0b24 - DDR2 Clock Disable Register */
  381. - __be32 ddrclkdr; /* 0x.0b28 - DDR Clock Disable Register */
  382. + u32 ddr1clkdr; /* 0x.0b20 - DDR1 Clock Disable Register */
  383. + u32 ddr2clkdr; /* 0x.0b24 - DDR2 Clock Disable Register */
  384. + u32 ddrclkdr; /* 0x.0b28 - DDR Clock Disable Register */
  385. u8 resb2c[0xe00 - 0xb2c];
  386. - __be32 clkocr; /* 0x.0e00 - Clock Out Select Register */
  387. + u32 clkocr; /* 0x.0e00 - Clock Out Select Register */
  388. u8 rese04[0xe10 - 0xe04];
  389. - __be32 ddrdllcr; /* 0x.0e10 - DDR DLL Control Register */
  390. + u32 ddrdllcr; /* 0x.0e10 - DDR DLL Control Register */
  391. u8 rese14[0xe20 - 0xe14];
  392. - __be32 lbcdllcr; /* 0x.0e20 - LBC DLL Control Register */
  393. - __be32 cpfor; /* 0x.0e24 - L2 charge pump fuse override register */
  394. + u32 lbcdllcr; /* 0x.0e20 - LBC DLL Control Register */
  395. + u32 cpfor; /* 0x.0e24 - L2 charge pump fuse override
  396. + * register
  397. + */
  398. u8 rese28[0xf04 - 0xe28];
  399. - __be32 srds1cr0; /* 0x.0f04 - SerDes1 Control Register 0 */
  400. - __be32 srds1cr1; /* 0x.0f08 - SerDes1 Control Register 0 */
  401. + u32 srds1cr0; /* 0x.0f04 - SerDes1 Control Register 0 */
  402. + u32 srds1cr1; /* 0x.0f08 - SerDes1 Control Register 0 */
  403. u8 resf0c[0xf2c - 0xf0c];
  404. - __be32 itcr; /* 0x.0f2c - Internal transaction control register */
  405. + u32 itcr; /* 0x.0f2c - Internal transaction control
  406. + * register
  407. + */
  408. u8 resf30[0xf40 - 0xf30];
  409. - __be32 srds2cr0; /* 0x.0f40 - SerDes2 Control Register 0 */
  410. - __be32 srds2cr1; /* 0x.0f44 - SerDes2 Control Register 0 */
  411. + u32 srds2cr0; /* 0x.0f40 - SerDes2 Control Register 0 */
  412. + u32 srds2cr1; /* 0x.0f44 - SerDes2 Control Register 0 */
  413. } __attribute__ ((packed));
  414. +u32 fsl_guts_get_svr(void);
  415. /* Alternate function signal multiplex control */
  416. #define MPC85xx_PMUXCR_QE(x) (0x8000 >> (x))