From: Lothar Rubusch <l.rubusch@gmail.com> To: herbert@gondor.apana.org.au, davem@davemloft.net Cc: nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH 5/5] crypto: atmel-sha204a - provide the otp content Date: Sat, 27 Apr 2024 00:14:39 +0000 [thread overview] Message-ID: <20240427001439.12726-6-l.rubusch@gmail.com> (raw) In-Reply-To: <20240427001439.12726-1-l.rubusch@gmail.com> 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> --- drivers/crypto/atmel-sha204a.c | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 81b5ea722..4a2027a60 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -105,6 +105,39 @@ static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp) return ret; } +static ssize_t otp_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u16 addr; + u8 otp[OTP_ZONE_SIZE]; + char *str = buf; + struct i2c_client *client = to_i2c_client(dev); + int i; + + for (addr = 0; addr < OTP_ZONE_SIZE/4; addr++) { + if (atmel_sha204a_otp_read(client, addr, otp + addr * 4) < 0) { + dev_err(dev, "failed to read otp zone\n"); + break; + } + } + + for (i = 0; i < addr*2; i++) + str += sprintf(str, "%02X", otp[i]); + str += sprintf(str, "\n"); + return str - buf; +} +static DEVICE_ATTR_RO(otp); + +static struct attribute *atmel_sha204a_attrs[] = { + &dev_attr_otp.attr, + NULL +}; + +static const struct attribute_group atmel_sha204a_groups = { + .name = "atsha204a", + .attrs = atmel_sha204a_attrs, +}; + static int atmel_sha204a_probe(struct i2c_client *client) { struct atmel_i2c_client_priv *i2c_priv; @@ -125,6 +158,16 @@ static int atmel_sha204a_probe(struct i2c_client *client) if (ret) dev_warn(&client->dev, "failed to register RNG (%d)\n", ret); + /* otp read out */ + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + ret = sysfs_create_group(&client->dev.kobj, &atmel_sha204a_groups); + if (ret) { + dev_err(&client->dev, "failed to register sysfs entry\n"); + return ret; + } + return ret; } @@ -137,6 +180,8 @@ static void atmel_sha204a_remove(struct i2c_client *client) return; } + sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups); + kfree((void *)i2c_priv->hwrng.priv); } -- 2.39.2
WARNING: multiple messages have this Message-ID (diff)
From: Lothar Rubusch <l.rubusch@gmail.com> To: herbert@gondor.apana.org.au, davem@davemloft.net Cc: alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, l.rubusch@gmail.com, linux-crypto@vger.kernel.org, claudiu.beznea@tuxon.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/5] crypto: atmel-sha204a - provide the otp content Date: Sat, 27 Apr 2024 00:14:39 +0000 [thread overview] Message-ID: <20240427001439.12726-6-l.rubusch@gmail.com> (raw) In-Reply-To: <20240427001439.12726-1-l.rubusch@gmail.com> 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> --- drivers/crypto/atmel-sha204a.c | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 81b5ea722..4a2027a60 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -105,6 +105,39 @@ static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp) return ret; } +static ssize_t otp_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u16 addr; + u8 otp[OTP_ZONE_SIZE]; + char *str = buf; + struct i2c_client *client = to_i2c_client(dev); + int i; + + for (addr = 0; addr < OTP_ZONE_SIZE/4; addr++) { + if (atmel_sha204a_otp_read(client, addr, otp + addr * 4) < 0) { + dev_err(dev, "failed to read otp zone\n"); + break; + } + } + + for (i = 0; i < addr*2; i++) + str += sprintf(str, "%02X", otp[i]); + str += sprintf(str, "\n"); + return str - buf; +} +static DEVICE_ATTR_RO(otp); + +static struct attribute *atmel_sha204a_attrs[] = { + &dev_attr_otp.attr, + NULL +}; + +static const struct attribute_group atmel_sha204a_groups = { + .name = "atsha204a", + .attrs = atmel_sha204a_attrs, +}; + static int atmel_sha204a_probe(struct i2c_client *client) { struct atmel_i2c_client_priv *i2c_priv; @@ -125,6 +158,16 @@ static int atmel_sha204a_probe(struct i2c_client *client) if (ret) dev_warn(&client->dev, "failed to register RNG (%d)\n", ret); + /* otp read out */ + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + ret = sysfs_create_group(&client->dev.kobj, &atmel_sha204a_groups); + if (ret) { + dev_err(&client->dev, "failed to register sysfs entry\n"); + return ret; + } + return ret; } @@ -137,6 +180,8 @@ static void atmel_sha204a_remove(struct i2c_client *client) return; } + sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups); + kfree((void *)i2c_priv->hwrng.priv); } -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-27 0:14 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-27 0:14 [PATCH 0/5] crypto: atmel-sha204a - read out otp zone Lothar Rubusch 2024-04-27 0:14 ` Lothar Rubusch 2024-04-27 0:14 ` [PATCH 1/5] crypto: atmel-i2 - add missing arg description Lothar Rubusch 2024-04-27 0:14 ` Lothar Rubusch 2024-04-27 0:14 ` [PATCH 2/5] crypto: atmel-sha204a - remove unused includes Lothar Rubusch 2024-04-27 0:14 ` Lothar Rubusch 2024-05-03 10:42 ` Herbert Xu 2024-05-03 10:42 ` Herbert Xu 2024-04-27 0:14 ` [PATCH 3/5] crypto: atmel-i2c - rename read function Lothar Rubusch 2024-04-27 0:14 ` Lothar Rubusch 2024-04-27 0:14 ` [PATCH 4/5] crypto: atmel-sha204a - add reading from otp zone Lothar Rubusch 2024-04-27 0:14 ` Lothar Rubusch 2024-04-27 0:14 ` Lothar Rubusch [this message] 2024-04-27 0:14 ` [PATCH 5/5] crypto: atmel-sha204a - provide the otp content Lothar Rubusch
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240427001439.12726-6-l.rubusch@gmail.com \ --to=l.rubusch@gmail.com \ --cc=alexandre.belloni@bootlin.com \ --cc=claudiu.beznea@tuxon.dev \ --cc=davem@davemloft.net \ --cc=herbert@gondor.apana.org.au \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-crypto@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=nicolas.ferre@microchip.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.