sunxi_sid.c (1cbc99dfe5d7d686fd022647f4e489b5eb8e9068) | sunxi_sid.c (9c7b16eb35d283f00ba278b62b5115dacdf12dd7) |
---|---|
1/* 2 * Allwinner sunXi SoCs Security ID support. 3 * 4 * Copyright (c) 2013 Oliver Schinagl <oliver@schinagl.nl> 5 * Copyright (C) 2014 Maxime Ripard <maxime.ripard@free-electrons.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by --- 7 unchanged lines hidden (view full) --- 16 */ 17 18#include <linux/device.h> 19#include <linux/io.h> 20#include <linux/module.h> 21#include <linux/nvmem-provider.h> 22#include <linux/of.h> 23#include <linux/platform_device.h> | 1/* 2 * Allwinner sunXi SoCs Security ID support. 3 * 4 * Copyright (c) 2013 Oliver Schinagl <oliver@schinagl.nl> 5 * Copyright (C) 2014 Maxime Ripard <maxime.ripard@free-electrons.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by --- 7 unchanged lines hidden (view full) --- 16 */ 17 18#include <linux/device.h> 19#include <linux/io.h> 20#include <linux/module.h> 21#include <linux/nvmem-provider.h> 22#include <linux/of.h> 23#include <linux/platform_device.h> |
24#include <linux/regmap.h> | |
25#include <linux/slab.h> 26#include <linux/random.h> 27 28static struct nvmem_config econfig = { 29 .name = "sunxi-sid", 30 .read_only = true, | 24#include <linux/slab.h> 25#include <linux/random.h> 26 27static struct nvmem_config econfig = { 28 .name = "sunxi-sid", 29 .read_only = true, |
30 .stride = 4, 31 .word_size = 1, |
|
31 .owner = THIS_MODULE, 32}; 33 34struct sunxi_sid { 35 void __iomem *base; 36}; 37 38/* We read the entire key, due to a 32 bit read alignment requirement. Since we --- 7 unchanged lines hidden (view full) --- 46 u32 sid_key; 47 48 sid_key = ioread32be(sid->base + round_down(offset, 4)); 49 sid_key >>= (offset % 4) * 8; 50 51 return sid_key; /* Only return the last byte */ 52} 53 | 32 .owner = THIS_MODULE, 33}; 34 35struct sunxi_sid { 36 void __iomem *base; 37}; 38 39/* We read the entire key, due to a 32 bit read alignment requirement. Since we --- 7 unchanged lines hidden (view full) --- 47 u32 sid_key; 48 49 sid_key = ioread32be(sid->base + round_down(offset, 4)); 50 sid_key >>= (offset % 4) * 8; 51 52 return sid_key; /* Only return the last byte */ 53} 54 |
54static int sunxi_sid_read(void *context, 55 const void *reg, size_t reg_size, 56 void *val, size_t val_size) | 55static int sunxi_sid_read(void *context, unsigned int offset, 56 void *val, size_t bytes) |
57{ 58 struct sunxi_sid *sid = context; | 57{ 58 struct sunxi_sid *sid = context; |
59 unsigned int offset = *(u32 *)reg; | |
60 u8 *buf = val; 61 | 59 u8 *buf = val; 60 |
62 while (val_size) { 63 *buf++ = sunxi_sid_read_byte(sid, offset); 64 val_size--; 65 offset++; 66 } | 61 while (bytes--) 62 *buf++ = sunxi_sid_read_byte(sid, offset++); |
67 68 return 0; 69} 70 | 63 64 return 0; 65} 66 |
71static int sunxi_sid_write(void *context, const void *data, size_t count) 72{ 73 /* Unimplemented, dummy to keep regmap core happy */ 74 return 0; 75} 76 77static struct regmap_bus sunxi_sid_bus = { 78 .read = sunxi_sid_read, 79 .write = sunxi_sid_write, 80 .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, 81 .val_format_endian_default = REGMAP_ENDIAN_NATIVE, 82}; 83 84static bool sunxi_sid_writeable_reg(struct device *dev, unsigned int reg) 85{ 86 return false; 87} 88 89static struct regmap_config sunxi_sid_regmap_config = { 90 .reg_bits = 32, 91 .val_bits = 8, 92 .reg_stride = 1, 93 .writeable_reg = sunxi_sid_writeable_reg, 94}; 95 | |
96static int sunxi_sid_probe(struct platform_device *pdev) 97{ 98 struct device *dev = &pdev->dev; 99 struct resource *res; 100 struct nvmem_device *nvmem; | 67static int sunxi_sid_probe(struct platform_device *pdev) 68{ 69 struct device *dev = &pdev->dev; 70 struct resource *res; 71 struct nvmem_device *nvmem; |
101 struct regmap *regmap; | |
102 struct sunxi_sid *sid; 103 int ret, i, size; 104 char *randomness; 105 106 sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); 107 if (!sid) 108 return -ENOMEM; 109 110 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 111 sid->base = devm_ioremap_resource(dev, res); 112 if (IS_ERR(sid->base)) 113 return PTR_ERR(sid->base); 114 115 size = resource_size(res) - 1; | 72 struct sunxi_sid *sid; 73 int ret, i, size; 74 char *randomness; 75 76 sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); 77 if (!sid) 78 return -ENOMEM; 79 80 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 81 sid->base = devm_ioremap_resource(dev, res); 82 if (IS_ERR(sid->base)) 83 return PTR_ERR(sid->base); 84 85 size = resource_size(res) - 1; |
116 sunxi_sid_regmap_config.max_register = size; 117 118 regmap = devm_regmap_init(dev, &sunxi_sid_bus, sid, 119 &sunxi_sid_regmap_config); 120 if (IS_ERR(regmap)) { 121 dev_err(dev, "regmap init failed\n"); 122 return PTR_ERR(regmap); 123 } 124 | 86 econfig.size = resource_size(res); |
125 econfig.dev = dev; | 87 econfig.dev = dev; |
88 econfig.reg_read = sunxi_sid_read; 89 econfig.priv = sid; |
|
126 nvmem = nvmem_register(&econfig); 127 if (IS_ERR(nvmem)) 128 return PTR_ERR(nvmem); 129 130 randomness = kzalloc(sizeof(u8) * (size), GFP_KERNEL); 131 if (!randomness) { 132 ret = -EINVAL; 133 goto err_unreg_nvmem; --- 44 unchanged lines hidden --- | 90 nvmem = nvmem_register(&econfig); 91 if (IS_ERR(nvmem)) 92 return PTR_ERR(nvmem); 93 94 randomness = kzalloc(sizeof(u8) * (size), GFP_KERNEL); 95 if (!randomness) { 96 ret = -EINVAL; 97 goto err_unreg_nvmem; --- 44 unchanged lines hidden --- |