David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Freescale QorIQ Platforms GUTS Driver |
| 4 | * |
| 5 | * Copyright (C) 2016 Freescale Semiconductor, Inc. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 guts { |
| 18 | struct ccsr_guts __iomem *regs; |
| 19 | bool little_endian; |
| 20 | }; |
| 21 | |
| 22 | struct fsl_soc_die_attr { |
| 23 | char *die; |
| 24 | u32 svr; |
| 25 | u32 mask; |
| 26 | }; |
| 27 | |
| 28 | static struct guts *guts; |
| 29 | static struct soc_device_attribute soc_dev_attr; |
| 30 | static struct soc_device *soc_dev; |
| 31 | |
| 32 | |
| 33 | /* SoC die attribute definition for QorIQ platform */ |
| 34 | static const struct fsl_soc_die_attr fsl_soc_die[] = { |
| 35 | /* |
| 36 | * Power Architecture-based SoCs T Series |
| 37 | */ |
| 38 | |
| 39 | /* Die: T4240, SoC: T4240/T4160/T4080 */ |
| 40 | { .die = "T4240", |
| 41 | .svr = 0x82400000, |
| 42 | .mask = 0xfff00000, |
| 43 | }, |
| 44 | /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */ |
| 45 | { .die = "T1040", |
| 46 | .svr = 0x85200000, |
| 47 | .mask = 0xfff00000, |
| 48 | }, |
| 49 | /* Die: T2080, SoC: T2080/T2081 */ |
| 50 | { .die = "T2080", |
| 51 | .svr = 0x85300000, |
| 52 | .mask = 0xfff00000, |
| 53 | }, |
| 54 | /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */ |
| 55 | { .die = "T1024", |
| 56 | .svr = 0x85400000, |
| 57 | .mask = 0xfff00000, |
| 58 | }, |
| 59 | |
| 60 | /* |
| 61 | * ARM-based SoCs LS Series |
| 62 | */ |
| 63 | |
| 64 | /* Die: LS1043A, SoC: LS1043A/LS1023A */ |
| 65 | { .die = "LS1043A", |
| 66 | .svr = 0x87920000, |
| 67 | .mask = 0xffff0000, |
| 68 | }, |
| 69 | /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */ |
| 70 | { .die = "LS2080A", |
| 71 | .svr = 0x87010000, |
| 72 | .mask = 0xff3f0000, |
| 73 | }, |
| 74 | /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */ |
| 75 | { .die = "LS1088A", |
| 76 | .svr = 0x87030000, |
| 77 | .mask = 0xff3f0000, |
| 78 | }, |
| 79 | /* Die: LS1012A, SoC: LS1012A */ |
| 80 | { .die = "LS1012A", |
| 81 | .svr = 0x87040000, |
| 82 | .mask = 0xffff0000, |
| 83 | }, |
| 84 | /* Die: LS1046A, SoC: LS1046A/LS1026A */ |
| 85 | { .die = "LS1046A", |
| 86 | .svr = 0x87070000, |
| 87 | .mask = 0xffff0000, |
| 88 | }, |
| 89 | /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */ |
| 90 | { .die = "LS2088A", |
| 91 | .svr = 0x87090000, |
| 92 | .mask = 0xff3f0000, |
| 93 | }, |
| 94 | /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */ |
| 95 | { .die = "LS1021A", |
| 96 | .svr = 0x87000000, |
| 97 | .mask = 0xfff70000, |
| 98 | }, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 99 | /* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */ |
| 100 | { .die = "LX2160A", |
| 101 | .svr = 0x87360000, |
| 102 | .mask = 0xff3f0000, |
| 103 | }, |
| 104 | /* Die: LS1028A, SoC: LS1028A */ |
| 105 | { .die = "LS1028A", |
| 106 | .svr = 0x870b0000, |
| 107 | .mask = 0xff3f0000, |
| 108 | }, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 123 | static u32 fsl_guts_get_svr(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 137 | |
| 138 | static int fsl_guts_probe(struct platform_device *pdev) |
| 139 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 140 | struct device_node *root, *np = pdev->dev.of_node; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 163 | if (machine) { |
| 164 | soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL); |
| 165 | if (!soc_dev_attr.machine) { |
| 166 | of_node_put(root); |
| 167 | return -ENOMEM; |
| 168 | } |
| 169 | } |
| 170 | of_node_put(root); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 171 | |
| 172 | svr = fsl_guts_get_svr(); |
| 173 | soc_die = fsl_soc_die_match(svr, fsl_soc_die); |
| 174 | if (soc_die) { |
| 175 | soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, |
| 176 | "QorIQ %s", soc_die->die); |
| 177 | } else { |
| 178 | soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ"); |
| 179 | } |
| 180 | if (!soc_dev_attr.family) |
| 181 | return -ENOMEM; |
| 182 | soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL, |
| 183 | "svr:0x%08x", svr); |
| 184 | if (!soc_dev_attr.soc_id) |
| 185 | return -ENOMEM; |
| 186 | soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d", |
| 187 | (svr >> 4) & 0xf, svr & 0xf); |
| 188 | if (!soc_dev_attr.revision) |
| 189 | return -ENOMEM; |
| 190 | |
| 191 | soc_dev = soc_device_register(&soc_dev_attr); |
| 192 | if (IS_ERR(soc_dev)) |
| 193 | return PTR_ERR(soc_dev); |
| 194 | |
| 195 | pr_info("Machine: %s\n", soc_dev_attr.machine); |
| 196 | pr_info("SoC family: %s\n", soc_dev_attr.family); |
| 197 | pr_info("SoC ID: %s, Revision: %s\n", |
| 198 | soc_dev_attr.soc_id, soc_dev_attr.revision); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static int fsl_guts_remove(struct platform_device *dev) |
| 203 | { |
| 204 | soc_device_unregister(soc_dev); |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Table for matching compatible strings, for device tree |
| 210 | * guts node, for Freescale QorIQ SOCs. |
| 211 | */ |
| 212 | static const struct of_device_id fsl_guts_of_match[] = { |
| 213 | { .compatible = "fsl,qoriq-device-config-1.0", }, |
| 214 | { .compatible = "fsl,qoriq-device-config-2.0", }, |
| 215 | { .compatible = "fsl,p1010-guts", }, |
| 216 | { .compatible = "fsl,p1020-guts", }, |
| 217 | { .compatible = "fsl,p1021-guts", }, |
| 218 | { .compatible = "fsl,p1022-guts", }, |
| 219 | { .compatible = "fsl,p1023-guts", }, |
| 220 | { .compatible = "fsl,p2020-guts", }, |
| 221 | { .compatible = "fsl,bsc9131-guts", }, |
| 222 | { .compatible = "fsl,bsc9132-guts", }, |
| 223 | { .compatible = "fsl,mpc8536-guts", }, |
| 224 | { .compatible = "fsl,mpc8544-guts", }, |
| 225 | { .compatible = "fsl,mpc8548-guts", }, |
| 226 | { .compatible = "fsl,mpc8568-guts", }, |
| 227 | { .compatible = "fsl,mpc8569-guts", }, |
| 228 | { .compatible = "fsl,mpc8572-guts", }, |
| 229 | { .compatible = "fsl,ls1021a-dcfg", }, |
| 230 | { .compatible = "fsl,ls1043a-dcfg", }, |
| 231 | { .compatible = "fsl,ls2080a-dcfg", }, |
| 232 | { .compatible = "fsl,ls1088a-dcfg", }, |
| 233 | { .compatible = "fsl,ls1012a-dcfg", }, |
| 234 | { .compatible = "fsl,ls1046a-dcfg", }, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 235 | { .compatible = "fsl,lx2160a-dcfg", }, |
| 236 | { .compatible = "fsl,ls1028a-dcfg", }, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 237 | {} |
| 238 | }; |
| 239 | MODULE_DEVICE_TABLE(of, fsl_guts_of_match); |
| 240 | |
| 241 | static struct platform_driver fsl_guts_driver = { |
| 242 | .driver = { |
| 243 | .name = "fsl-guts", |
| 244 | .of_match_table = fsl_guts_of_match, |
| 245 | }, |
| 246 | .probe = fsl_guts_probe, |
| 247 | .remove = fsl_guts_remove, |
| 248 | }; |
| 249 | |
| 250 | static int __init fsl_guts_init(void) |
| 251 | { |
| 252 | return platform_driver_register(&fsl_guts_driver); |
| 253 | } |
| 254 | core_initcall(fsl_guts_init); |
| 255 | |
| 256 | static void __exit fsl_guts_exit(void) |
| 257 | { |
| 258 | platform_driver_unregister(&fsl_guts_driver); |
| 259 | } |
| 260 | module_exit(fsl_guts_exit); |