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