hwrng: amd - Convert to new hwrng read() API

This patch convert the hwrng interface used by amd768-rng to its new API
by replacing data_read()/data_present() by read().

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Corentin LABBE 2016-08-26 13:11:36 +02:00 коммит произвёл Herbert Xu
Родитель 3c343a3764
Коммит 85962d2248
1 изменённых файлов: 27 добавлений и 18 удалений

Просмотреть файл

@ -58,27 +58,37 @@ struct amd768_priv {
u32 pmbase; u32 pmbase;
}; };
static int amd_rng_data_present(struct hwrng *rng, int wait) static int amd_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
{ {
u32 *data = buf;
struct amd768_priv *priv = (struct amd768_priv *)rng->priv; struct amd768_priv *priv = (struct amd768_priv *)rng->priv;
int data, i; size_t read = 0;
/* We will wait at maximum one time per read */
int timeout = max / 4 + 1;
for (i = 0; i < 20; i++) { /*
data = !!(ioread32(priv->iobase + RNGDONE) & 1); * RNG data is available when RNGDONE is set to 1
if (data || !wait) * New random numbers are generated approximately 128 microseconds
break; * after RNGDATA is read
udelay(10); */
while (read < max) {
if (ioread32(priv->iobase + RNGDONE) == 0) {
if (wait) {
/* Delay given by datasheet */
usleep_range(128, 196);
if (timeout-- == 0)
return read;
} else {
return 0;
}
} else {
*data = ioread32(priv->iobase + RNGDATA);
data++;
read += 4;
}
} }
return data;
}
static int amd_rng_data_read(struct hwrng *rng, u32 *data) return read;
{
struct amd768_priv *priv = (struct amd768_priv *)rng->priv;
*data = ioread32(priv->iobase + RNGDATA);
return 4;
} }
static int amd_rng_init(struct hwrng *rng) static int amd_rng_init(struct hwrng *rng)
@ -111,8 +121,7 @@ static struct hwrng amd_rng = {
.name = "amd", .name = "amd",
.init = amd_rng_init, .init = amd_rng_init,
.cleanup = amd_rng_cleanup, .cleanup = amd_rng_cleanup,
.data_present = amd_rng_data_present, .read = amd_rng_read,
.data_read = amd_rng_data_read,
}; };
static int __init mod_init(void) static int __init mod_init(void)