0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/device.h>
0016 #include <linux/errno.h>
0017 #include <linux/mfd/syscon.h>
0018 #include <linux/module.h>
0019 #include <linux/of.h>
0020 #include <linux/of_device.h>
0021 #include <linux/platform_device.h>
0022 #include <linux/regmap.h>
0023 #include <linux/slab.h>
0024 #include <linux/soc/samsung/exynos-chipid.h>
0025 #include <linux/sys_soc.h>
0026
0027 #include "exynos-asv.h"
0028
0029 struct exynos_chipid_variant {
0030 unsigned int rev_reg;
0031 unsigned int main_rev_shift;
0032 unsigned int sub_rev_shift;
0033 };
0034
0035 struct exynos_chipid_info {
0036 u32 product_id;
0037 u32 revision;
0038 };
0039
0040 static const struct exynos_soc_id {
0041 const char *name;
0042 unsigned int id;
0043 } soc_ids[] = {
0044
0045
0046 { "EXYNOS3250", 0xE3472000 },
0047 { "EXYNOS4210", 0x43200000 },
0048 { "EXYNOS4210", 0x43210000 },
0049 { "EXYNOS4212", 0x43220000 },
0050 { "EXYNOS4412", 0xE4412000 },
0051 { "EXYNOS5250", 0x43520000 },
0052 { "EXYNOS5260", 0xE5260000 },
0053 { "EXYNOS5410", 0xE5410000 },
0054 { "EXYNOS5420", 0xE5420000 },
0055 { "EXYNOS5433", 0xE5433000 },
0056 { "EXYNOS5440", 0xE5440000 },
0057 { "EXYNOS5800", 0xE5422000 },
0058 { "EXYNOS7420", 0xE7420000 },
0059
0060 { "EXYNOS7885", 0xE7885000 },
0061 { "EXYNOS850", 0xE3830000 },
0062 { "EXYNOSAUTOV9", 0xAAA80000 },
0063 };
0064
0065 static const char *product_id_to_soc_id(unsigned int product_id)
0066 {
0067 int i;
0068
0069 for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
0070 if (product_id == soc_ids[i].id)
0071 return soc_ids[i].name;
0072 return NULL;
0073 }
0074
0075 static int exynos_chipid_get_chipid_info(struct regmap *regmap,
0076 const struct exynos_chipid_variant *data,
0077 struct exynos_chipid_info *soc_info)
0078 {
0079 int ret;
0080 unsigned int val, main_rev, sub_rev;
0081
0082 ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &val);
0083 if (ret < 0)
0084 return ret;
0085 soc_info->product_id = val & EXYNOS_MASK;
0086
0087 if (data->rev_reg != EXYNOS_CHIPID_REG_PRO_ID) {
0088 ret = regmap_read(regmap, data->rev_reg, &val);
0089 if (ret < 0)
0090 return ret;
0091 }
0092 main_rev = (val >> data->main_rev_shift) & EXYNOS_REV_PART_MASK;
0093 sub_rev = (val >> data->sub_rev_shift) & EXYNOS_REV_PART_MASK;
0094 soc_info->revision = (main_rev << EXYNOS_REV_PART_SHIFT) | sub_rev;
0095
0096 return 0;
0097 }
0098
0099 static int exynos_chipid_probe(struct platform_device *pdev)
0100 {
0101 const struct exynos_chipid_variant *drv_data;
0102 struct exynos_chipid_info soc_info;
0103 struct soc_device_attribute *soc_dev_attr;
0104 struct soc_device *soc_dev;
0105 struct device_node *root;
0106 struct regmap *regmap;
0107 int ret;
0108
0109 drv_data = of_device_get_match_data(&pdev->dev);
0110 if (!drv_data)
0111 return -EINVAL;
0112
0113 regmap = device_node_to_regmap(pdev->dev.of_node);
0114 if (IS_ERR(regmap))
0115 return PTR_ERR(regmap);
0116
0117 ret = exynos_chipid_get_chipid_info(regmap, drv_data, &soc_info);
0118 if (ret < 0)
0119 return ret;
0120
0121 soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
0122 GFP_KERNEL);
0123 if (!soc_dev_attr)
0124 return -ENOMEM;
0125
0126 soc_dev_attr->family = "Samsung Exynos";
0127
0128 root = of_find_node_by_path("/");
0129 of_property_read_string(root, "model", &soc_dev_attr->machine);
0130 of_node_put(root);
0131
0132 soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL,
0133 "%x", soc_info.revision);
0134 soc_dev_attr->soc_id = product_id_to_soc_id(soc_info.product_id);
0135 if (!soc_dev_attr->soc_id) {
0136 pr_err("Unknown SoC\n");
0137 return -ENODEV;
0138 }
0139
0140
0141 soc_dev = soc_device_register(soc_dev_attr);
0142 if (IS_ERR(soc_dev))
0143 return PTR_ERR(soc_dev);
0144
0145 ret = exynos_asv_init(&pdev->dev, regmap);
0146 if (ret)
0147 goto err;
0148
0149 platform_set_drvdata(pdev, soc_dev);
0150
0151 dev_info(&pdev->dev, "Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
0152 soc_dev_attr->soc_id, soc_info.product_id, soc_info.revision);
0153
0154 return 0;
0155
0156 err:
0157 soc_device_unregister(soc_dev);
0158
0159 return ret;
0160 }
0161
0162 static int exynos_chipid_remove(struct platform_device *pdev)
0163 {
0164 struct soc_device *soc_dev = platform_get_drvdata(pdev);
0165
0166 soc_device_unregister(soc_dev);
0167
0168 return 0;
0169 }
0170
0171 static const struct exynos_chipid_variant exynos4210_chipid_drv_data = {
0172 .rev_reg = 0x0,
0173 .main_rev_shift = 4,
0174 .sub_rev_shift = 0,
0175 };
0176
0177 static const struct exynos_chipid_variant exynos850_chipid_drv_data = {
0178 .rev_reg = 0x10,
0179 .main_rev_shift = 20,
0180 .sub_rev_shift = 16,
0181 };
0182
0183 static const struct of_device_id exynos_chipid_of_device_ids[] = {
0184 {
0185 .compatible = "samsung,exynos4210-chipid",
0186 .data = &exynos4210_chipid_drv_data,
0187 }, {
0188 .compatible = "samsung,exynos850-chipid",
0189 .data = &exynos850_chipid_drv_data,
0190 },
0191 { }
0192 };
0193 MODULE_DEVICE_TABLE(of, exynos_chipid_of_device_ids);
0194
0195 static struct platform_driver exynos_chipid_driver = {
0196 .driver = {
0197 .name = "exynos-chipid",
0198 .of_match_table = exynos_chipid_of_device_ids,
0199 },
0200 .probe = exynos_chipid_probe,
0201 .remove = exynos_chipid_remove,
0202 };
0203 module_platform_driver(exynos_chipid_driver);
0204
0205 MODULE_DESCRIPTION("Samsung Exynos ChipID controller and ASV driver");
0206 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
0207 MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>");
0208 MODULE_AUTHOR("Pankaj Dubey <pankaj.dubey@samsung.com>");
0209 MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
0210 MODULE_LICENSE("GPL");