1 /* 2 * Freescale QorIQ Platforms GUTS Driver 3 * 4 * Copyright (C) 2016 Freescale Semiconductor, Inc. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 */ 11 12 #include <linux/io.h> 13 #include <linux/slab.h> 14 #include <linux/module.h> 15 #include <linux/of_fdt.h> 16 #include <linux/sys_soc.h> 17 #include <linux/of_address.h> 18 #include <linux/platform_device.h> 19 #include <linux/fsl/guts.h> 20 21 struct guts { 22 struct ccsr_guts __iomem *regs; 23 bool little_endian; 24 }; 25 26 struct fsl_soc_die_attr { 27 char *die; 28 u32 svr; 29 u32 mask; 30 }; 31 32 static struct guts *guts; 33 static struct soc_device_attribute soc_dev_attr; 34 static struct soc_device *soc_dev; 35 static struct device_node *root; 36 37 38 /* SoC die attribute definition for QorIQ platform */ 39 static const struct fsl_soc_die_attr fsl_soc_die[] = { 40 /* 41 * Power Architecture-based SoCs T Series 42 */ 43 44 /* Die: T4240, SoC: T4240/T4160/T4080 */ 45 { .die = "T4240", 46 .svr = 0x82400000, 47 .mask = 0xfff00000, 48 }, 49 /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */ 50 { .die = "T1040", 51 .svr = 0x85200000, 52 .mask = 0xfff00000, 53 }, 54 /* Die: T2080, SoC: T2080/T2081 */ 55 { .die = "T2080", 56 .svr = 0x85300000, 57 .mask = 0xfff00000, 58 }, 59 /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */ 60 { .die = "T1024", 61 .svr = 0x85400000, 62 .mask = 0xfff00000, 63 }, 64 65 /* 66 * ARM-based SoCs LS Series 67 */ 68 69 /* Die: LS1043A, SoC: LS1043A/LS1023A */ 70 { .die = "LS1043A", 71 .svr = 0x87920000, 72 .mask = 0xffff0000, 73 }, 74 /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */ 75 { .die = "LS2080A", 76 .svr = 0x87010000, 77 .mask = 0xff3f0000, 78 }, 79 /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */ 80 { .die = "LS1088A", 81 .svr = 0x87030000, 82 .mask = 0xff3f0000, 83 }, 84 /* Die: LS1012A, SoC: LS1012A */ 85 { .die = "LS1012A", 86 .svr = 0x87040000, 87 .mask = 0xffff0000, 88 }, 89 /* Die: LS1046A, SoC: LS1046A/LS1026A */ 90 { .die = "LS1046A", 91 .svr = 0x87070000, 92 .mask = 0xffff0000, 93 }, 94 /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */ 95 { .die = "LS2088A", 96 .svr = 0x87090000, 97 .mask = 0xff3f0000, 98 }, 99 /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */ 100 { .die = "LS1021A", 101 .svr = 0x87000000, 102 .mask = 0xfff70000, 103 }, 104 /* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */ 105 { .die = "LX2160A", 106 .svr = 0x87360000, 107 .mask = 0xff3f0000, 108 }, 109 { }, 110 }; 111 112 static const struct fsl_soc_die_attr *fsl_soc_die_match( 113 u32 svr, const struct fsl_soc_die_attr *matches) 114 { 115 while (matches->svr) { 116 if (matches->svr == (svr & matches->mask)) 117 return matches; 118 matches++; 119 }; 120 return NULL; 121 } 122 123 static u32 fsl_guts_get_svr(void) 124 { 125 u32 svr = 0; 126 127 if (!guts || !guts->regs) 128 return svr; 129 130 if (guts->little_endian) 131 svr = ioread32(&guts->regs->svr); 132 else 133 svr = ioread32be(&guts->regs->svr); 134 135 return svr; 136 } 137 138 static int fsl_guts_probe(struct platform_device *pdev) 139 { 140 struct device_node *np = pdev->dev.of_node; 141 struct device *dev = &pdev->dev; 142 struct resource *res; 143 const struct fsl_soc_die_attr *soc_die; 144 const char *machine; 145 u32 svr; 146 147 /* Initialize guts */ 148 guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL); 149 if (!guts) 150 return -ENOMEM; 151 152 guts->little_endian = of_property_read_bool(np, "little-endian"); 153 154 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 155 guts->regs = devm_ioremap_resource(dev, res); 156 if (IS_ERR(guts->regs)) 157 return PTR_ERR(guts->regs); 158 159 /* Register soc device */ 160 root = of_find_node_by_path("/"); 161 if (of_property_read_string(root, "model", &machine)) 162 of_property_read_string_index(root, "compatible", 0, &machine); 163 if (machine) 164 soc_dev_attr.machine = machine; 165 166 svr = fsl_guts_get_svr(); 167 soc_die = fsl_soc_die_match(svr, fsl_soc_die); 168 if (soc_die) { 169 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, 170 "QorIQ %s", soc_die->die); 171 } else { 172 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ"); 173 } 174 if (!soc_dev_attr.family) 175 return -ENOMEM; 176 soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL, 177 "svr:0x%08x", svr); 178 if (!soc_dev_attr.soc_id) 179 return -ENOMEM; 180 soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d", 181 (svr >> 4) & 0xf, svr & 0xf); 182 if (!soc_dev_attr.revision) 183 return -ENOMEM; 184 185 soc_dev = soc_device_register(&soc_dev_attr); 186 if (IS_ERR(soc_dev)) 187 return PTR_ERR(soc_dev); 188 189 pr_info("Machine: %s\n", soc_dev_attr.machine); 190 pr_info("SoC family: %s\n", soc_dev_attr.family); 191 pr_info("SoC ID: %s, Revision: %s\n", 192 soc_dev_attr.soc_id, soc_dev_attr.revision); 193 return 0; 194 } 195 196 static int fsl_guts_remove(struct platform_device *dev) 197 { 198 soc_device_unregister(soc_dev); 199 of_node_put(root); 200 return 0; 201 } 202 203 /* 204 * Table for matching compatible strings, for device tree 205 * guts node, for Freescale QorIQ SOCs. 206 */ 207 static const struct of_device_id fsl_guts_of_match[] = { 208 { .compatible = "fsl,qoriq-device-config-1.0", }, 209 { .compatible = "fsl,qoriq-device-config-2.0", }, 210 { .compatible = "fsl,p1010-guts", }, 211 { .compatible = "fsl,p1020-guts", }, 212 { .compatible = "fsl,p1021-guts", }, 213 { .compatible = "fsl,p1022-guts", }, 214 { .compatible = "fsl,p1023-guts", }, 215 { .compatible = "fsl,p2020-guts", }, 216 { .compatible = "fsl,bsc9131-guts", }, 217 { .compatible = "fsl,bsc9132-guts", }, 218 { .compatible = "fsl,mpc8536-guts", }, 219 { .compatible = "fsl,mpc8544-guts", }, 220 { .compatible = "fsl,mpc8548-guts", }, 221 { .compatible = "fsl,mpc8568-guts", }, 222 { .compatible = "fsl,mpc8569-guts", }, 223 { .compatible = "fsl,mpc8572-guts", }, 224 { .compatible = "fsl,ls1021a-dcfg", }, 225 { .compatible = "fsl,ls1043a-dcfg", }, 226 { .compatible = "fsl,ls2080a-dcfg", }, 227 { .compatible = "fsl,ls1088a-dcfg", }, 228 { .compatible = "fsl,ls1012a-dcfg", }, 229 { .compatible = "fsl,ls1046a-dcfg", }, 230 { .compatible = "fsl,lx2160a-dcfg", }, 231 {} 232 }; 233 MODULE_DEVICE_TABLE(of, fsl_guts_of_match); 234 235 static struct platform_driver fsl_guts_driver = { 236 .driver = { 237 .name = "fsl-guts", 238 .of_match_table = fsl_guts_of_match, 239 }, 240 .probe = fsl_guts_probe, 241 .remove = fsl_guts_remove, 242 }; 243 244 static int __init fsl_guts_init(void) 245 { 246 return platform_driver_register(&fsl_guts_driver); 247 } 248 core_initcall(fsl_guts_init); 249 250 static void __exit fsl_guts_exit(void) 251 { 252 platform_driver_unregister(&fsl_guts_driver); 253 } 254 module_exit(fsl_guts_exit); 255