#include <crypto/internal/rng.h>
#include <linux/crypto.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#define PRNG_DATA_OUT 0x0000
#define PRNG_STATUS 0x0004
#define PRNG_LFSR_CFG 0x0100
#define PRNG_CONFIG 0x0104
#define PRNG_LFSR_CFG_MASK 0x0000ffff
#define PRNG_LFSR_CFG_CLOCKS 0x0000dddd
#define PRNG_CONFIG_HW_ENABLE BIT(1)
#define PRNG_STATUS_DATA_AVAIL BIT(0)
static struct qcom_rng *qcom_rng_dev;
static int qcom_rng_read(struct qcom_rng *rng, u8 *data, unsigned int max)
unsigned int currsize = 0;
val = readl_relaxed(rng->base + PRNG_STATUS);
if (!(val & PRNG_STATUS_DATA_AVAIL))
val = readl_relaxed(rng->base + PRNG_DATA_OUT);
if ((max - currsize) >= WORD_SZ) {
memcpy(data, &val, WORD_SZ);
memcpy(data, &val, max - currsize);