2 * UIO SMX Cryptengine driver.
4 * (C) 2008 Nias Digital P/L <bn@niasdigital.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/device.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/uio_driver.h>
18 #define DRV_NAME "smx-ce"
19 #define DRV_VERSION "0.03"
21 #define SMX_CSR 0x00000000
22 #define SMX_EnD 0x00000001
23 #define SMX_RUN 0x00000002
24 #define SMX_DRDY 0x00000004
25 #define SMX_ERR 0x00000008
27 static irqreturn_t smx_handler(int irq, struct uio_info *dev_info)
29 void __iomem *csr = dev_info->mem[0].internal_addr + SMX_CSR;
31 u32 status = ioread32(csr);
33 if (!(status & SMX_DRDY))
36 /* Disable interrupt */
37 iowrite32(status & ~SMX_DRDY, csr);
41 static int __devinit smx_ce_probe(struct platform_device *dev)
45 struct uio_info *info;
46 struct resource *regs;
48 info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
52 regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
54 dev_err(&dev->dev, "No memory resource specified\n");
58 info->mem[0].addr = regs->start;
59 if (!info->mem[0].addr) {
60 dev_err(&dev->dev, "Invalid memory resource\n");
64 info->mem[0].size = regs->end - regs->start + 1;
65 info->mem[0].internal_addr = ioremap(regs->start, info->mem[0].size);
67 if (!info->mem[0].internal_addr) {
68 dev_err(&dev->dev, "Can't remap memory address range\n");
72 info->mem[0].memtype = UIO_MEM_PHYS;
74 info->name = "smx-ce";
75 info->version = "0.03";
77 info->irq = platform_get_irq(dev, 0);
80 dev_err(&dev->dev, "No (or invalid) IRQ resource specified\n");
84 info->irq_flags = IRQF_SHARED;
85 info->handler = smx_handler;
87 platform_set_drvdata(dev, info);
89 ret = uio_register_device(&dev->dev, info);
97 iounmap(info->mem[0].internal_addr);
104 static int __devexit smx_ce_remove(struct platform_device *dev)
106 struct uio_info *info = platform_get_drvdata(dev);
108 uio_unregister_device(info);
109 platform_set_drvdata(dev, NULL);
110 iounmap(info->mem[0].internal_addr);
117 static struct platform_driver smx_ce_driver = {
118 .probe = smx_ce_probe,
119 .remove = __devexit_p(smx_ce_remove),
122 .owner = THIS_MODULE,
126 static int __init smx_ce_init_module(void)
128 return platform_driver_register(&smx_ce_driver);
130 module_init(smx_ce_init_module);
132 static void __exit smx_ce_exit_module(void)
134 platform_driver_unregister(&smx_ce_driver);
136 module_exit(smx_ce_exit_module);
138 MODULE_LICENSE("GPL v2");
139 MODULE_VERSION(DRV_VERSION);
140 MODULE_AUTHOR("Ben Nizette <bn@niasdigital.com>");