diff options
author | Mark A. Greer <mgreer@animalcreek.com> | 2013-01-08 13:57:44 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-01-19 18:16:43 -0500 |
commit | bc69d124d8141dff942c8c7fbaae76f9c0f4c796 (patch) | |
tree | efb8d13358f53b47a8ad74ee0b7e13175b2a4076 /drivers/crypto | |
parent | 44f04c1d6f34fee940daed71151ca35b3f1f1e64 (diff) |
crypto: omap-aes - Add Device Tree Support
Add Device Tree suport to the omap-aes crypto
driver. Currently, only support for OMAP2 and
OMAP3 is being added but support for OMAP4 will
be added in a subsequent patch.
CC: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/omap-aes.c | 123 |
1 files changed, 97 insertions, 26 deletions
diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index faf522ff82d7..dfebd4025654 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c | |||
@@ -25,6 +25,9 @@ | |||
25 | #include <linux/dmaengine.h> | 25 | #include <linux/dmaengine.h> |
26 | #include <linux/omap-dma.h> | 26 | #include <linux/omap-dma.h> |
27 | #include <linux/pm_runtime.h> | 27 | #include <linux/pm_runtime.h> |
28 | #include <linux/of.h> | ||
29 | #include <linux/of_device.h> | ||
30 | #include <linux/of_address.h> | ||
28 | #include <linux/io.h> | 31 | #include <linux/io.h> |
29 | #include <linux/crypto.h> | 32 | #include <linux/crypto.h> |
30 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
@@ -819,11 +822,97 @@ static struct crypto_alg algs[] = { | |||
819 | } | 822 | } |
820 | }; | 823 | }; |
821 | 824 | ||
825 | #ifdef CONFIG_OF | ||
826 | static const struct of_device_id omap_aes_of_match[] = { | ||
827 | { | ||
828 | .compatible = "ti,omap2-aes", | ||
829 | }, | ||
830 | {}, | ||
831 | }; | ||
832 | MODULE_DEVICE_TABLE(of, omap_aes_of_match); | ||
833 | |||
834 | static int omap_aes_get_res_of(struct omap_aes_dev *dd, | ||
835 | struct device *dev, struct resource *res) | ||
836 | { | ||
837 | struct device_node *node = dev->of_node; | ||
838 | const struct of_device_id *match; | ||
839 | int err = 0; | ||
840 | |||
841 | match = of_match_device(of_match_ptr(omap_aes_of_match), dev); | ||
842 | if (!match) { | ||
843 | dev_err(dev, "no compatible OF match\n"); | ||
844 | err = -EINVAL; | ||
845 | goto err; | ||
846 | } | ||
847 | |||
848 | err = of_address_to_resource(node, 0, res); | ||
849 | if (err < 0) { | ||
850 | dev_err(dev, "can't translate OF node address\n"); | ||
851 | err = -EINVAL; | ||
852 | goto err; | ||
853 | } | ||
854 | |||
855 | dd->dma_out = -1; /* Dummy value that's unused */ | ||
856 | dd->dma_in = -1; /* Dummy value that's unused */ | ||
857 | |||
858 | err: | ||
859 | return err; | ||
860 | } | ||
861 | #else | ||
862 | static const struct of_device_id omap_aes_of_match[] = { | ||
863 | {}, | ||
864 | }; | ||
865 | |||
866 | static int omap_aes_get_res_of(struct omap_aes_dev *dd, | ||
867 | struct device *dev, struct resource *res) | ||
868 | { | ||
869 | return -EINVAL; | ||
870 | } | ||
871 | #endif | ||
872 | |||
873 | static int omap_aes_get_res_pdev(struct omap_aes_dev *dd, | ||
874 | struct platform_device *pdev, struct resource *res) | ||
875 | { | ||
876 | struct device *dev = &pdev->dev; | ||
877 | struct resource *r; | ||
878 | int err = 0; | ||
879 | |||
880 | /* Get the base address */ | ||
881 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
882 | if (!r) { | ||
883 | dev_err(dev, "no MEM resource info\n"); | ||
884 | err = -ENODEV; | ||
885 | goto err; | ||
886 | } | ||
887 | memcpy(res, r, sizeof(*res)); | ||
888 | |||
889 | /* Get the DMA out channel */ | ||
890 | r = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
891 | if (!r) { | ||
892 | dev_err(dev, "no DMA out resource info\n"); | ||
893 | err = -ENODEV; | ||
894 | goto err; | ||
895 | } | ||
896 | dd->dma_out = r->start; | ||
897 | |||
898 | /* Get the DMA in channel */ | ||
899 | r = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
900 | if (!r) { | ||
901 | dev_err(dev, "no DMA in resource info\n"); | ||
902 | err = -ENODEV; | ||
903 | goto err; | ||
904 | } | ||
905 | dd->dma_in = r->start; | ||
906 | |||
907 | err: | ||
908 | return err; | ||
909 | } | ||
910 | |||
822 | static int omap_aes_probe(struct platform_device *pdev) | 911 | static int omap_aes_probe(struct platform_device *pdev) |
823 | { | 912 | { |
824 | struct device *dev = &pdev->dev; | 913 | struct device *dev = &pdev->dev; |
825 | struct omap_aes_dev *dd; | 914 | struct omap_aes_dev *dd; |
826 | struct resource *res; | 915 | struct resource res; |
827 | int err = -ENOMEM, i, j; | 916 | int err = -ENOMEM, i, j; |
828 | u32 reg; | 917 | u32 reg; |
829 | 918 | ||
@@ -838,35 +927,18 @@ static int omap_aes_probe(struct platform_device *pdev) | |||
838 | spin_lock_init(&dd->lock); | 927 | spin_lock_init(&dd->lock); |
839 | crypto_init_queue(&dd->queue, OMAP_AES_QUEUE_LENGTH); | 928 | crypto_init_queue(&dd->queue, OMAP_AES_QUEUE_LENGTH); |
840 | 929 | ||
841 | /* Get the base address */ | 930 | err = (dev->of_node) ? omap_aes_get_res_of(dd, dev, &res) : |
842 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 931 | omap_aes_get_res_pdev(dd, pdev, &res); |
843 | if (!res) { | 932 | if (err) |
844 | dev_err(dev, "invalid resource type\n"); | ||
845 | err = -ENODEV; | ||
846 | goto err_res; | 933 | goto err_res; |
847 | } | 934 | |
848 | dd->phys_base = res->start; | 935 | dd->io_base = devm_request_and_ioremap(dev, &res); |
849 | |||
850 | /* Get the DMA */ | ||
851 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
852 | if (!res) | ||
853 | dev_info(dev, "no DMA info\n"); | ||
854 | else | ||
855 | dd->dma_out = res->start; | ||
856 | |||
857 | /* Get the DMA */ | ||
858 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
859 | if (!res) | ||
860 | dev_info(dev, "no DMA info\n"); | ||
861 | else | ||
862 | dd->dma_in = res->start; | ||
863 | |||
864 | dd->io_base = ioremap(dd->phys_base, SZ_4K); | ||
865 | if (!dd->io_base) { | 936 | if (!dd->io_base) { |
866 | dev_err(dev, "can't ioremap\n"); | 937 | dev_err(dev, "can't ioremap\n"); |
867 | err = -ENOMEM; | 938 | err = -ENOMEM; |
868 | goto err_res; | 939 | goto err_res; |
869 | } | 940 | } |
941 | dd->phys_base = res.start; | ||
870 | 942 | ||
871 | pm_runtime_enable(dev); | 943 | pm_runtime_enable(dev); |
872 | pm_runtime_get_sync(dev); | 944 | pm_runtime_get_sync(dev); |
@@ -904,7 +976,6 @@ err_algs: | |||
904 | err_dma: | 976 | err_dma: |
905 | tasklet_kill(&dd->done_task); | 977 | tasklet_kill(&dd->done_task); |
906 | tasklet_kill(&dd->queue_task); | 978 | tasklet_kill(&dd->queue_task); |
907 | iounmap(dd->io_base); | ||
908 | pm_runtime_disable(dev); | 979 | pm_runtime_disable(dev); |
909 | err_res: | 980 | err_res: |
910 | kfree(dd); | 981 | kfree(dd); |
@@ -932,7 +1003,6 @@ static int omap_aes_remove(struct platform_device *pdev) | |||
932 | tasklet_kill(&dd->done_task); | 1003 | tasklet_kill(&dd->done_task); |
933 | tasklet_kill(&dd->queue_task); | 1004 | tasklet_kill(&dd->queue_task); |
934 | omap_aes_dma_cleanup(dd); | 1005 | omap_aes_dma_cleanup(dd); |
935 | iounmap(dd->io_base); | ||
936 | pm_runtime_disable(dd->dev); | 1006 | pm_runtime_disable(dd->dev); |
937 | kfree(dd); | 1007 | kfree(dd); |
938 | dd = NULL; | 1008 | dd = NULL; |
@@ -965,6 +1035,7 @@ static struct platform_driver omap_aes_driver = { | |||
965 | .name = "omap-aes", | 1035 | .name = "omap-aes", |
966 | .owner = THIS_MODULE, | 1036 | .owner = THIS_MODULE, |
967 | .pm = &omap_aes_pm_ops, | 1037 | .pm = &omap_aes_pm_ops, |
1038 | .of_match_table = omap_aes_of_match, | ||
968 | }, | 1039 | }, |
969 | }; | 1040 | }; |
970 | 1041 | ||