~ubuntu-branches/ubuntu/trusty/linux-armadaxp/trusty

« back to all changes in this revision

Viewing changes to drivers/char/hw_random/ppc4xx-rng.c

  • Committer: Package Import Robot
  • Author(s): Michael Casadevall, Bryan Wu, Dann Frazier, Michael Casadeall
  • Date: 2012-03-10 15:00:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120310150054-flugb39zon8vvgwe
Tags: 3.2.0-1600.1
[ Bryan Wu ]
* UBUNTU: import debian/debian.env and debian.armadaxp

[ Dann Frazier ]
* ARM: Armada XP: remove trailing '/' in dirnames in mvRules.mk

[ Michael Casadeall ]
* tools: add some tools for Marvell Armada XP processor
* kernel: timer tick hacking from Marvell
* kernel: Sheeva Errata: add delay on Sheeva when powering down
* net: add Marvell NFP netfilter
* net: socket and skb modifications made by Marvell
* miscdevice: add minor IDs for some Marvell Armada drivers
* fs: introduce memory pool for splice()
* video: EDID detection updates from Marvell Armada XP patchset
* video: backlight: add Marvell Dove LCD backlight driver
* video: display: add THS8200 display driver
* video: framebuffer: add Marvell Dove and Armada XP processor onchip LCD controller driver
* usbtest: add Interrupt transfer testing by Marvell Armada XP code
* usb: ehci: add support for Marvell EHCI controler
* tty/serial: 8250: add support for Marvell Armada XP processor and DeviceTree work
* rtc: add support for Marvell Armada XP onchip RTC controller
* net: pppoe: add Marvell ethernet NFP hook in PPPoE networking driver
* mtd: nand: add support for Marvell Armada XP Nand Flash Controller
* mtd: maps: add Marvell Armada XP specific map driver
* mmc: add support for Marvell Armada XP MMC/SD host controller
* i2c: add support for Marvell Armada XP onchip i2c bus controller
* hwmon: add Kconfig option for Armada XP onchip thermal sensor driver
* dmaengine: add Net DMA support for splice and update Marvell XOR DMA engine driver
* ata: add support for Marvell Armada XP SATA controller and update some quirks
* ARM: add Marvell Armada XP machine to mach-types
* ARM: oprofile: add support for Marvell PJ4B core
* ARM: mm: more ARMv6 switches for Marvell Armada XP
* ARM: remove static declaration to allow compilation
* ARM: alignment access fault trick
* ARM: mm: skip some fault fixing when run on NONE SMP ARMv6 mode during early abort event
* ARM: mm: add Marvell Sheeva CPU Architecture for PJ4B
* ARM: introduce optimized copy operation for Marvell Armada XP
* ARM: SAUCE: hardware breakpoint trick for Marvell Armada XP
* ARM: big endian and little endian tricks for Marvell Armada XP
* ARM: SAUCE: Add Marvell Armada XP build rules to arch/arm/kernel/Makefile
* ARM: vfp: add special handling for Marvell Armada XP
* ARM: add support for Marvell U-Boot
* ARM: add mv_controller_num for ARM PCI drivers
* ARM: add support for local PMUs, general SMP tweaks and cache flushing
* ARM: add Marvell device identifies in glue-proc.h
* ARM: add IPC driver support for Marvell platforms
* ARM: add DMA mapping for Marvell platforms
* ARM: add Sheeva errata and PJ4B code for booting
* ARM: update Kconfig and Makefile to include Marvell Armada XP platforms
* ARM: Armada XP: import LSP from Marvell for Armada XP 3.2 kernel enablement

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Generic PowerPC 44x RNG driver
 
3
 *
 
4
 * Copyright 2011 IBM Corporation
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License as published by the
 
8
 * Free Software Foundation; version 2 of the License.
 
9
 */
 
10
 
 
11
#include <linux/module.h>
 
12
#include <linux/kernel.h>
 
13
#include <linux/platform_device.h>
 
14
#include <linux/hw_random.h>
 
15
#include <linux/delay.h>
 
16
#include <linux/of_platform.h>
 
17
#include <asm/io.h>
 
18
 
 
19
#define PPC4XX_TRNG_DEV_CTRL 0x60080
 
20
 
 
21
#define PPC4XX_TRNGE 0x00020000
 
22
#define PPC4XX_TRNG_CTRL 0x0008
 
23
#define PPC4XX_TRNG_CTRL_DALM 0x20
 
24
#define PPC4XX_TRNG_STAT 0x0004
 
25
#define PPC4XX_TRNG_STAT_B 0x1
 
26
#define PPC4XX_TRNG_DATA 0x0000
 
27
 
 
28
#define MODULE_NAME "ppc4xx_rng"
 
29
 
 
30
static int ppc4xx_rng_data_present(struct hwrng *rng, int wait)
 
31
{
 
32
        void __iomem *rng_regs = (void __iomem *) rng->priv;
 
33
        int busy, i, present = 0;
 
34
 
 
35
        for (i = 0; i < 20; i++) {
 
36
                busy = (in_le32(rng_regs + PPC4XX_TRNG_STAT) & PPC4XX_TRNG_STAT_B);
 
37
                if (!busy || !wait) {
 
38
                        present = 1;
 
39
                        break;
 
40
                }
 
41
                udelay(10);
 
42
        }
 
43
        return present;
 
44
}
 
45
 
 
46
static int ppc4xx_rng_data_read(struct hwrng *rng, u32 *data)
 
47
{
 
48
        void __iomem *rng_regs = (void __iomem *) rng->priv;
 
49
        *data = in_le32(rng_regs + PPC4XX_TRNG_DATA);
 
50
        return 4;
 
51
}
 
52
 
 
53
static int ppc4xx_rng_enable(int enable)
 
54
{
 
55
        struct device_node *ctrl;
 
56
        void __iomem *ctrl_reg;
 
57
        int err = 0;
 
58
        u32 val;
 
59
 
 
60
        /* Find the main crypto device node and map it to turn the TRNG on */
 
61
        ctrl = of_find_compatible_node(NULL, NULL, "amcc,ppc4xx-crypto");
 
62
        if (!ctrl)
 
63
                return -ENODEV;
 
64
 
 
65
        ctrl_reg = of_iomap(ctrl, 0);
 
66
        if (!ctrl_reg) {
 
67
                err = -ENODEV;
 
68
                goto out;
 
69
        }
 
70
 
 
71
        val = in_le32(ctrl_reg + PPC4XX_TRNG_DEV_CTRL);
 
72
 
 
73
        if (enable)
 
74
                val |= PPC4XX_TRNGE;
 
75
        else
 
76
                val = val & ~PPC4XX_TRNGE;
 
77
 
 
78
        out_le32(ctrl_reg + PPC4XX_TRNG_DEV_CTRL, val);
 
79
        iounmap(ctrl_reg);
 
80
 
 
81
out:
 
82
        of_node_put(ctrl);
 
83
 
 
84
        return err;
 
85
}
 
86
 
 
87
static struct hwrng ppc4xx_rng = {
 
88
        .name = MODULE_NAME,
 
89
        .data_present = ppc4xx_rng_data_present,
 
90
        .data_read = ppc4xx_rng_data_read,
 
91
};
 
92
 
 
93
static int __devinit ppc4xx_rng_probe(struct platform_device *dev)
 
94
{
 
95
        void __iomem *rng_regs;
 
96
        int err = 0;
 
97
 
 
98
        rng_regs = of_iomap(dev->dev.of_node, 0);
 
99
        if (!rng_regs)
 
100
                return -ENODEV;
 
101
 
 
102
        err = ppc4xx_rng_enable(1);
 
103
        if (err)
 
104
                return err;
 
105
 
 
106
        out_le32(rng_regs + PPC4XX_TRNG_CTRL, PPC4XX_TRNG_CTRL_DALM);
 
107
        ppc4xx_rng.priv = (unsigned long) rng_regs;
 
108
 
 
109
        err = hwrng_register(&ppc4xx_rng);
 
110
 
 
111
        return err;
 
112
}
 
113
 
 
114
static int __devexit ppc4xx_rng_remove(struct platform_device *dev)
 
115
{
 
116
        void __iomem *rng_regs = (void __iomem *) ppc4xx_rng.priv;
 
117
 
 
118
        hwrng_unregister(&ppc4xx_rng);
 
119
        ppc4xx_rng_enable(0);
 
120
        iounmap(rng_regs);
 
121
 
 
122
        return 0;
 
123
}
 
124
 
 
125
static struct of_device_id ppc4xx_rng_match[] = {
 
126
        { .compatible = "ppc4xx-rng", },
 
127
        { .compatible = "amcc,ppc460ex-rng", },
 
128
        { .compatible = "amcc,ppc440epx-rng", },
 
129
        {},
 
130
};
 
131
 
 
132
static struct platform_driver ppc4xx_rng_driver = {
 
133
        .driver = {
 
134
                .name = MODULE_NAME,
 
135
                .owner = THIS_MODULE,
 
136
                .of_match_table = ppc4xx_rng_match,
 
137
        },
 
138
        .probe = ppc4xx_rng_probe,
 
139
        .remove = ppc4xx_rng_remove,
 
140
};
 
141
 
 
142
static int __init ppc4xx_rng_init(void)
 
143
{
 
144
        return platform_driver_register(&ppc4xx_rng_driver);
 
145
}
 
146
module_init(ppc4xx_rng_init);
 
147
 
 
148
static void __exit ppc4xx_rng_exit(void)
 
149
{
 
150
        platform_driver_unregister(&ppc4xx_rng_driver);
 
151
}
 
152
module_exit(ppc4xx_rng_exit);
 
153
 
 
154
MODULE_LICENSE("GPL");
 
155
MODULE_AUTHOR("Josh Boyer <jwboyer@linux.vnet.ibm.com>");
 
156
MODULE_DESCRIPTION("HW RNG driver for PPC 4xx processors");