Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Layerscape SFP driver
0004  *
0005  * Copyright (c) 2022 Michael Walle <michael@walle.cc>
0006  *
0007  */
0008 
0009 #include <linux/device.h>
0010 #include <linux/io.h>
0011 #include <linux/mod_devicetable.h>
0012 #include <linux/module.h>
0013 #include <linux/nvmem-provider.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/property.h>
0016 #include <linux/regmap.h>
0017 
0018 #define LAYERSCAPE_SFP_OTP_OFFSET   0x0200
0019 
0020 struct layerscape_sfp_priv {
0021     struct regmap *regmap;
0022 };
0023 
0024 struct layerscape_sfp_data {
0025     int size;
0026     enum regmap_endian endian;
0027 };
0028 
0029 static int layerscape_sfp_read(void *context, unsigned int offset, void *val,
0030                    size_t bytes)
0031 {
0032     struct layerscape_sfp_priv *priv = context;
0033 
0034     return regmap_bulk_read(priv->regmap,
0035                 LAYERSCAPE_SFP_OTP_OFFSET + offset, val,
0036                 bytes / 4);
0037 }
0038 
0039 static struct nvmem_config layerscape_sfp_nvmem_config = {
0040     .name = "fsl-sfp",
0041     .reg_read = layerscape_sfp_read,
0042     .word_size = 4,
0043     .stride = 4,
0044 };
0045 
0046 static int layerscape_sfp_probe(struct platform_device *pdev)
0047 {
0048     const struct layerscape_sfp_data *data;
0049     struct layerscape_sfp_priv *priv;
0050     struct nvmem_device *nvmem;
0051     struct regmap_config config = { 0 };
0052     void __iomem *base;
0053 
0054     priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
0055     if (!priv)
0056         return -ENOMEM;
0057 
0058     base = devm_platform_ioremap_resource(pdev, 0);
0059     if (IS_ERR(base))
0060         return PTR_ERR(base);
0061 
0062     data = device_get_match_data(&pdev->dev);
0063     config.reg_bits = 32;
0064     config.reg_stride = 4;
0065     config.val_bits = 32;
0066     config.val_format_endian = data->endian;
0067     config.max_register = LAYERSCAPE_SFP_OTP_OFFSET + data->size - 4;
0068     priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, &config);
0069     if (IS_ERR(priv->regmap))
0070         return PTR_ERR(priv->regmap);
0071 
0072     layerscape_sfp_nvmem_config.size = data->size;
0073     layerscape_sfp_nvmem_config.dev = &pdev->dev;
0074     layerscape_sfp_nvmem_config.priv = priv;
0075 
0076     nvmem = devm_nvmem_register(&pdev->dev, &layerscape_sfp_nvmem_config);
0077 
0078     return PTR_ERR_OR_ZERO(nvmem);
0079 }
0080 
0081 static const struct layerscape_sfp_data ls1021a_data = {
0082     .size = 0x88,
0083     .endian = REGMAP_ENDIAN_BIG,
0084 };
0085 
0086 static const struct layerscape_sfp_data ls1028a_data = {
0087     .size = 0x88,
0088     .endian = REGMAP_ENDIAN_LITTLE,
0089 };
0090 
0091 static const struct of_device_id layerscape_sfp_dt_ids[] = {
0092     { .compatible = "fsl,ls1021a-sfp", .data = &ls1021a_data },
0093     { .compatible = "fsl,ls1028a-sfp", .data = &ls1028a_data },
0094     {},
0095 };
0096 MODULE_DEVICE_TABLE(of, layerscape_sfp_dt_ids);
0097 
0098 static struct platform_driver layerscape_sfp_driver = {
0099     .probe  = layerscape_sfp_probe,
0100     .driver = {
0101         .name   = "layerscape_sfp",
0102         .of_match_table = layerscape_sfp_dt_ids,
0103     },
0104 };
0105 module_platform_driver(layerscape_sfp_driver);
0106 
0107 MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
0108 MODULE_DESCRIPTION("Layerscape Security Fuse Processor driver");
0109 MODULE_LICENSE("GPL");