cregit-Linux how code gets into the kernel

Release 4.11 drivers/char/hw_random/pasemi-rng.c

/*
 * Copyright (C) 2006-2007 PA Semi, Inc
 *
 * Maintained by: Olof Johansson <olof@lixom.net>
 *
 * Driver for the PWRficient onchip rng
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/hw_random.h>
#include <linux/delay.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/io.h>


#define SDCRNG_CTL_REG			0x00

#define   SDCRNG_CTL_FVLD_M		0x0000f000

#define   SDCRNG_CTL_FVLD_S		12

#define   SDCRNG_CTL_KSZ		0x00000800

#define   SDCRNG_CTL_RSRC_CRG		0x00000010

#define   SDCRNG_CTL_RSRC_RRG		0x00000000

#define   SDCRNG_CTL_CE			0x00000004

#define   SDCRNG_CTL_RE			0x00000002

#define   SDCRNG_CTL_DR			0x00000001

#define   SDCRNG_CTL_SELECT_RRG_RNG	(SDCRNG_CTL_RE | SDCRNG_CTL_RSRC_RRG)

#define   SDCRNG_CTL_SELECT_CRG_RNG	(SDCRNG_CTL_CE | SDCRNG_CTL_RSRC_CRG)

#define SDCRNG_VAL_REG			0x20


#define MODULE_NAME "pasemi_rng"


static int pasemi_rng_data_present(struct hwrng *rng, int wait) { void __iomem *rng_regs = (void __iomem *)rng->priv; int data, i; for (i = 0; i < 20; i++) { data = (in_le32(rng_regs + SDCRNG_CTL_REG) & SDCRNG_CTL_FVLD_M) ? 1 : 0; if (data || !wait) break; udelay(10); } return data; }

Contributors

PersonTokensPropCommitsCommitProp
Olof Johansson4049.38%133.33%
Patrick McHardy3846.91%133.33%
Kamalesh Babulal33.70%133.33%
Total81100.00%3100.00%


static int pasemi_rng_data_read(struct hwrng *rng, u32 *data) { void __iomem *rng_regs = (void __iomem *)rng->priv; *data = in_le32(rng_regs + SDCRNG_VAL_REG); return 4; }

Contributors

PersonTokensPropCommitsCommitProp
Olof Johansson42100.00%1100.00%
Total42100.00%1100.00%


static int pasemi_rng_init(struct hwrng *rng) { void __iomem *rng_regs = (void __iomem *)rng->priv; u32 ctl; ctl = SDCRNG_CTL_DR | SDCRNG_CTL_SELECT_RRG_RNG | SDCRNG_CTL_KSZ; out_le32(rng_regs + SDCRNG_CTL_REG, ctl); out_le32(rng_regs + SDCRNG_CTL_REG, ctl & ~SDCRNG_CTL_DR); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Olof Johansson60100.00%1100.00%
Total60100.00%1100.00%


static void pasemi_rng_cleanup(struct hwrng *rng) { void __iomem *rng_regs = (void __iomem *)rng->priv; u32 ctl; ctl = SDCRNG_CTL_RE | SDCRNG_CTL_CE; out_le32(rng_regs + SDCRNG_CTL_REG, in_le32(rng_regs + SDCRNG_CTL_REG) & ~ctl); }

Contributors

PersonTokensPropCommitsCommitProp
Olof Johansson51100.00%1100.00%
Total51100.00%1100.00%

static struct hwrng pasemi_rng = { .name = MODULE_NAME, .init = pasemi_rng_init, .cleanup = pasemi_rng_cleanup, .data_present = pasemi_rng_data_present, .data_read = pasemi_rng_data_read, };
static int rng_probe(struct platform_device *pdev) { void __iomem *rng_regs; struct resource *res; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); rng_regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(rng_regs)) return PTR_ERR(rng_regs); pasemi_rng.priv = (unsigned long)rng_regs; pr_info("Registering PA Semi RNG\n"); return devm_hwrng_register(&pdev->dev, &pasemi_rng); }

Contributors

PersonTokensPropCommitsCommitProp
Olof Johansson5767.86%125.00%
PrasannaKumar Muralidharan2529.76%125.00%
Sudip Mukherjee11.19%125.00%
Grant C. Likely11.19%125.00%
Total84100.00%4100.00%

static const struct of_device_id rng_match[] = { { .compatible = "1682m-rng", }, { .compatible = "pasemi,pwrficient-rng", }, { }, }; MODULE_DEVICE_TABLE(of, rng_match); static struct platform_driver rng_driver = { .driver = { .name = "pasemi-rng", .of_match_table = rng_match, }, .probe = rng_probe, }; module_platform_driver(rng_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Egor Martovetsky <egor@pasemi.com>"); MODULE_DESCRIPTION("H/W RNG driver for PA Semi processor");

Overall Contributors

PersonTokensPropCommitsCommitProp
Olof Johansson41481.82%213.33%
Patrick McHardy418.10%16.67%
PrasannaKumar Muralidharan265.14%213.33%
Grant C. Likely81.58%320.00%
Luis de Bethencourt71.38%16.67%
Kamalesh Babulal30.59%16.67%
Rob Herring30.59%16.67%
Axel Lin10.20%16.67%
Stephen Rothwell10.20%16.67%
Sudip Mukherjee10.20%16.67%
Fabian Frederick10.20%16.67%
Total506100.00%15100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.