diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2012-02-14 07:52:42 -0500 |
---|---|---|
committer | Liam Girdwood <lrg@ti.com> | 2012-03-12 09:34:21 -0400 |
commit | 2ee6595069f29b918b957a013debfae83e68724d (patch) | |
tree | e3f32aa8b786fdb9c97a4cdf38b892ec021877ea /sound/soc/omap/mcbsp.c | |
parent | cb40b63a224b41325a8ecdbeed5290866864b9ae (diff) |
ASoC: omap-mcbsp: Cleanup of module probe/remove code
Use devm_* where it is possible to save on cleanup path.
Start merging the two mcbsp file content.
Move pm_runtime_enable/disable calls to ASoC probe, remove from module
probe/remove time.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Tested-by: Grazvydas Ignotas <notasas@gmail.com>
Tested-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Signed-off-by: Liam Girdwood <lrg@ti.com>
Diffstat (limited to 'sound/soc/omap/mcbsp.c')
-rw-r--r-- | sound/soc/omap/mcbsp.c | 136 |
1 files changed, 34 insertions, 102 deletions
diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c index 95ba7e0d207d..9e39c58a4671 100644 --- a/sound/soc/omap/mcbsp.c +++ b/sound/soc/omap/mcbsp.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | 27 | ||
28 | #include <plat/mcbsp.h> | 28 | #include <plat/mcbsp.h> |
29 | #include <linux/pm_runtime.h> | ||
30 | 29 | ||
31 | #include "mcbsp.h" | 30 | #include "mcbsp.h" |
32 | 31 | ||
@@ -915,90 +914,56 @@ static int __devinit omap_st_add(struct omap_mcbsp *mcbsp, | |||
915 | struct omap_mcbsp_st_data *st_data; | 914 | struct omap_mcbsp_st_data *st_data; |
916 | int err; | 915 | int err; |
917 | 916 | ||
918 | st_data = kzalloc(sizeof(*mcbsp->st_data), GFP_KERNEL); | 917 | st_data = devm_kzalloc(mcbsp->dev, sizeof(*mcbsp->st_data), GFP_KERNEL); |
919 | if (!st_data) { | 918 | if (!st_data) |
920 | err = -ENOMEM; | 919 | return -ENOMEM; |
921 | goto err1; | ||
922 | } | ||
923 | 920 | ||
924 | st_data->io_base_st = ioremap(res->start, resource_size(res)); | 921 | st_data->io_base_st = devm_ioremap(mcbsp->dev, res->start, |
925 | if (!st_data->io_base_st) { | 922 | resource_size(res)); |
926 | err = -ENOMEM; | 923 | if (!st_data->io_base_st) |
927 | goto err2; | 924 | return -ENOMEM; |
928 | } | ||
929 | 925 | ||
930 | err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group); | 926 | err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group); |
931 | if (err) | 927 | if (err) |
932 | goto err3; | 928 | return err; |
933 | 929 | ||
934 | mcbsp->st_data = st_data; | 930 | mcbsp->st_data = st_data; |
935 | return 0; | 931 | return 0; |
936 | |||
937 | err3: | ||
938 | iounmap(st_data->io_base_st); | ||
939 | err2: | ||
940 | kfree(st_data); | ||
941 | err1: | ||
942 | return err; | ||
943 | |||
944 | } | ||
945 | |||
946 | static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp) | ||
947 | { | ||
948 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; | ||
949 | |||
950 | sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group); | ||
951 | iounmap(st_data->io_base_st); | ||
952 | kfree(st_data); | ||
953 | } | 932 | } |
954 | 933 | ||
955 | /* | 934 | /* |
956 | * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. | 935 | * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. |
957 | * 730 has only 2 McBSP, and both of them are MPU peripherals. | 936 | * 730 has only 2 McBSP, and both of them are MPU peripherals. |
958 | */ | 937 | */ |
959 | int __devinit omap_mcbsp_probe(struct platform_device *pdev) | 938 | int __devinit omap_mcbsp_init(struct platform_device *pdev) |
960 | { | 939 | { |
961 | struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; | 940 | struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); |
962 | struct omap_mcbsp *mcbsp; | ||
963 | struct resource *res; | 941 | struct resource *res; |
964 | int ret = 0; | 942 | int ret = 0; |
965 | 943 | ||
966 | if (!pdata) { | ||
967 | dev_err(&pdev->dev, "McBSP device initialized without" | ||
968 | "platform data\n"); | ||
969 | ret = -EINVAL; | ||
970 | goto exit; | ||
971 | } | ||
972 | |||
973 | dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id); | ||
974 | |||
975 | mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL); | ||
976 | if (!mcbsp) { | ||
977 | ret = -ENOMEM; | ||
978 | goto exit; | ||
979 | } | ||
980 | |||
981 | spin_lock_init(&mcbsp->lock); | 944 | spin_lock_init(&mcbsp->lock); |
982 | mcbsp->id = pdev->id; | ||
983 | mcbsp->free = true; | 945 | mcbsp->free = true; |
984 | 946 | ||
985 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); | 947 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); |
986 | if (!res) { | 948 | if (!res) { |
987 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 949 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
988 | if (!res) { | 950 | if (!res) { |
989 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid memory" | 951 | dev_err(mcbsp->dev, "invalid memory resource\n"); |
990 | "resource\n", __func__, pdev->id); | 952 | return -ENOMEM; |
991 | ret = -ENOMEM; | ||
992 | goto exit; | ||
993 | } | 953 | } |
994 | } | 954 | } |
955 | if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res), | ||
956 | dev_name(&pdev->dev))) { | ||
957 | dev_err(mcbsp->dev, "memory region already claimed\n"); | ||
958 | return -ENODEV; | ||
959 | } | ||
960 | |||
995 | mcbsp->phys_base = res->start; | 961 | mcbsp->phys_base = res->start; |
996 | mcbsp->reg_cache_size = resource_size(res); | 962 | mcbsp->reg_cache_size = resource_size(res); |
997 | mcbsp->io_base = ioremap(res->start, resource_size(res)); | 963 | mcbsp->io_base = devm_ioremap(&pdev->dev, res->start, |
998 | if (!mcbsp->io_base) { | 964 | resource_size(res)); |
999 | ret = -ENOMEM; | 965 | if (!mcbsp->io_base) |
1000 | goto err_ioremap; | 966 | return -ENOMEM; |
1001 | } | ||
1002 | 967 | ||
1003 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); | 968 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); |
1004 | if (!res) | 969 | if (!res) |
@@ -1015,34 +980,25 @@ int __devinit omap_mcbsp_probe(struct platform_device *pdev) | |||
1015 | 980 | ||
1016 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); | 981 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
1017 | if (!res) { | 982 | if (!res) { |
1018 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid rx DMA channel\n", | 983 | dev_err(&pdev->dev, "invalid rx DMA channel\n"); |
1019 | __func__, pdev->id); | 984 | return -ENODEV; |
1020 | ret = -ENODEV; | ||
1021 | goto err_res; | ||
1022 | } | 985 | } |
1023 | mcbsp->dma_rx_sync = res->start; | 986 | mcbsp->dma_rx_sync = res->start; |
1024 | 987 | ||
1025 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); | 988 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
1026 | if (!res) { | 989 | if (!res) { |
1027 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid tx DMA channel\n", | 990 | dev_err(&pdev->dev, "invalid tx DMA channel\n"); |
1028 | __func__, pdev->id); | 991 | return -ENODEV; |
1029 | ret = -ENODEV; | ||
1030 | goto err_res; | ||
1031 | } | 992 | } |
1032 | mcbsp->dma_tx_sync = res->start; | 993 | mcbsp->dma_tx_sync = res->start; |
1033 | 994 | ||
1034 | mcbsp->fclk = clk_get(&pdev->dev, "fck"); | 995 | mcbsp->fclk = clk_get(&pdev->dev, "fck"); |
1035 | if (IS_ERR(mcbsp->fclk)) { | 996 | if (IS_ERR(mcbsp->fclk)) { |
1036 | ret = PTR_ERR(mcbsp->fclk); | 997 | ret = PTR_ERR(mcbsp->fclk); |
1037 | dev_err(&pdev->dev, "unable to get fck: %d\n", ret); | 998 | dev_err(mcbsp->dev, "unable to get fck: %d\n", ret); |
1038 | goto err_res; | 999 | return ret; |
1039 | } | 1000 | } |
1040 | 1001 | ||
1041 | mcbsp->pdata = pdata; | ||
1042 | mcbsp->dev = &pdev->dev; | ||
1043 | platform_set_drvdata(pdev, mcbsp); | ||
1044 | pm_runtime_enable(mcbsp->dev); | ||
1045 | |||
1046 | mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; | 1002 | mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; |
1047 | if (mcbsp->pdata->buffer_size) { | 1003 | if (mcbsp->pdata->buffer_size) { |
1048 | /* | 1004 | /* |
@@ -1082,41 +1038,17 @@ int __devinit omap_mcbsp_probe(struct platform_device *pdev) | |||
1082 | 1038 | ||
1083 | err_st: | 1039 | err_st: |
1084 | if (mcbsp->pdata->buffer_size) | 1040 | if (mcbsp->pdata->buffer_size) |
1085 | sysfs_remove_group(&mcbsp->dev->kobj, | 1041 | sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group); |
1086 | &additional_attr_group); | ||
1087 | err_thres: | 1042 | err_thres: |
1088 | clk_put(mcbsp->fclk); | 1043 | clk_put(mcbsp->fclk); |
1089 | err_res: | ||
1090 | iounmap(mcbsp->io_base); | ||
1091 | err_ioremap: | ||
1092 | kfree(mcbsp); | ||
1093 | exit: | ||
1094 | return ret; | 1044 | return ret; |
1095 | } | 1045 | } |
1096 | 1046 | ||
1097 | int __devexit omap_mcbsp_remove(struct platform_device *pdev) | 1047 | void __devexit omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp) |
1098 | { | 1048 | { |
1099 | struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); | 1049 | if (mcbsp->pdata->buffer_size) |
1100 | 1050 | sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group); | |
1101 | platform_set_drvdata(pdev, NULL); | ||
1102 | if (mcbsp) { | ||
1103 | |||
1104 | if (mcbsp->pdata && mcbsp->pdata->ops && | ||
1105 | mcbsp->pdata->ops->free) | ||
1106 | mcbsp->pdata->ops->free(mcbsp->id); | ||
1107 | |||
1108 | if (mcbsp->pdata->buffer_size) | ||
1109 | sysfs_remove_group(&mcbsp->dev->kobj, | ||
1110 | &additional_attr_group); | ||
1111 | |||
1112 | if (mcbsp->st_data) | ||
1113 | omap_st_remove(mcbsp); | ||
1114 | |||
1115 | clk_put(mcbsp->fclk); | ||
1116 | |||
1117 | iounmap(mcbsp->io_base); | ||
1118 | kfree(mcbsp); | ||
1119 | } | ||
1120 | 1051 | ||
1121 | return 0; | 1052 | if (mcbsp->st_data) |
1053 | sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group); | ||
1122 | } | 1054 | } |