uio_smx.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * UIO SMX Cryptengine driver.
  3. *
  4. * (C) 2008 Nias Digital P/L <bn@niasdigital.com>
  5. *
  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.
  9. *
  10. */
  11. #include <linux/device.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/uio_driver.h>
  15. #include <linux/io.h>
  16. #define DRV_NAME "smx-ce"
  17. #define DRV_VERSION "0.03"
  18. #define SMX_CSR 0x00000000
  19. #define SMX_EnD 0x00000001
  20. #define SMX_RUN 0x00000002
  21. #define SMX_DRDY 0x00000004
  22. #define SMX_ERR 0x00000008
  23. static irqreturn_t smx_handler(int irq, struct uio_info *dev_info)
  24. {
  25. void __iomem *csr = dev_info->mem[0].internal_addr + SMX_CSR;
  26. u32 status = ioread32(csr);
  27. if (!(status & SMX_DRDY))
  28. return IRQ_NONE;
  29. /* Disable interrupt */
  30. iowrite32(status & ~SMX_DRDY, csr);
  31. return IRQ_HANDLED;
  32. }
  33. static int __devinit smx_ce_probe(struct platform_device *dev)
  34. {
  35. int ret = -ENODEV;
  36. struct uio_info *info;
  37. struct resource *regs;
  38. info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
  39. if (!info)
  40. return -ENOMEM;
  41. regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
  42. if (!regs) {
  43. dev_err(&dev->dev, "No memory resource specified\n");
  44. goto out_free;
  45. }
  46. info->mem[0].addr = regs->start;
  47. if (!info->mem[0].addr) {
  48. dev_err(&dev->dev, "Invalid memory resource\n");
  49. goto out_free;
  50. }
  51. info->mem[0].size = regs->end - regs->start + 1;
  52. info->mem[0].internal_addr = ioremap(regs->start, info->mem[0].size);
  53. if (!info->mem[0].internal_addr) {
  54. dev_err(&dev->dev, "Can't remap memory address range\n");
  55. goto out_free;
  56. }
  57. info->mem[0].memtype = UIO_MEM_PHYS;
  58. info->name = "smx-ce";
  59. info->version = "0.03";
  60. info->irq = platform_get_irq(dev, 0);
  61. if (info->irq < 0) {
  62. ret = info->irq;
  63. dev_err(&dev->dev, "No (or invalid) IRQ resource specified\n");
  64. goto out_unmap;
  65. }
  66. info->irq_flags = IRQF_SHARED;
  67. info->handler = smx_handler;
  68. platform_set_drvdata(dev, info);
  69. ret = uio_register_device(&dev->dev, info);
  70. if (ret)
  71. goto out_unmap;
  72. return 0;
  73. out_unmap:
  74. iounmap(info->mem[0].internal_addr);
  75. out_free:
  76. kfree(info);
  77. return ret;
  78. }
  79. static int __devexit smx_ce_remove(struct platform_device *dev)
  80. {
  81. struct uio_info *info = platform_get_drvdata(dev);
  82. uio_unregister_device(info);
  83. platform_set_drvdata(dev, NULL);
  84. iounmap(info->mem[0].internal_addr);
  85. kfree(info);
  86. return 0;
  87. }
  88. static struct platform_driver smx_ce_driver = {
  89. .probe = smx_ce_probe,
  90. .remove = __devexit_p(smx_ce_remove),
  91. .driver = {
  92. .name = DRV_NAME,
  93. .owner = THIS_MODULE,
  94. },
  95. };
  96. static int __init smx_ce_init_module(void)
  97. {
  98. return platform_driver_register(&smx_ce_driver);
  99. }
  100. module_init(smx_ce_init_module);
  101. static void __exit smx_ce_exit_module(void)
  102. {
  103. platform_driver_unregister(&smx_ce_driver);
  104. }
  105. module_exit(smx_ce_exit_module);
  106. MODULE_LICENSE("GPL v2");
  107. MODULE_VERSION(DRV_VERSION);
  108. MODULE_AUTHOR("Ben Nizette <bn@niasdigital.com>");