Skip to content

Commit 13909a0

Browse files
Rubuschherbertx
authored andcommitted
crypto: atmel-sha204a - provide the otp content
Set up sysfs for the Atmel SHA204a. Provide the content of the otp zone as an attribute field on the sysfs entry. Thereby make sure that if the chip is locked, not connected or trouble with the i2c bus, the sysfs device is not set up. This is mostly already handled in atmel-i2c. Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent e05ce44 commit 13909a0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

drivers/crypto/atmel-sha204a.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,39 @@ static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp)
114114
return ret;
115115
}
116116

117+
static ssize_t otp_show(struct device *dev,
118+
struct device_attribute *attr, char *buf)
119+
{
120+
u16 addr;
121+
u8 otp[OTP_ZONE_SIZE];
122+
char *str = buf;
123+
struct i2c_client *client = to_i2c_client(dev);
124+
int i;
125+
126+
for (addr = 0; addr < OTP_ZONE_SIZE/4; addr++) {
127+
if (atmel_sha204a_otp_read(client, addr, otp + addr * 4) < 0) {
128+
dev_err(dev, "failed to read otp zone\n");
129+
break;
130+
}
131+
}
132+
133+
for (i = 0; i < addr*2; i++)
134+
str += sprintf(str, "%02X", otp[i]);
135+
str += sprintf(str, "\n");
136+
return str - buf;
137+
}
138+
static DEVICE_ATTR_RO(otp);
139+
140+
static struct attribute *atmel_sha204a_attrs[] = {
141+
&dev_attr_otp.attr,
142+
NULL
143+
};
144+
145+
static const struct attribute_group atmel_sha204a_groups = {
146+
.name = "atsha204a",
147+
.attrs = atmel_sha204a_attrs,
148+
};
149+
117150
static int atmel_sha204a_probe(struct i2c_client *client)
118151
{
119152
struct atmel_i2c_client_priv *i2c_priv;
@@ -134,6 +167,16 @@ static int atmel_sha204a_probe(struct i2c_client *client)
134167
if (ret)
135168
dev_warn(&client->dev, "failed to register RNG (%d)\n", ret);
136169

170+
/* otp read out */
171+
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
172+
return -ENODEV;
173+
174+
ret = sysfs_create_group(&client->dev.kobj, &atmel_sha204a_groups);
175+
if (ret) {
176+
dev_err(&client->dev, "failed to register sysfs entry\n");
177+
return ret;
178+
}
179+
137180
return ret;
138181
}
139182

@@ -146,6 +189,8 @@ static void atmel_sha204a_remove(struct i2c_client *client)
146189
return;
147190
}
148191

192+
sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups);
193+
149194
kfree((void *)i2c_priv->hwrng.priv);
150195
}
151196

0 commit comments

Comments
 (0)