Commit 2b3f558727244efb6edb0866952331f537da13a4

Authored by Takashi Iwai
Committed by Jaroslav Kysela
1 parent 792a6c5187

[ALSA] Use platform_device

Modules: SA11xx UDA1341 driver

Rewrite the probe/remove with platform_device.
Fix PM support, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

Showing 1 changed file with 57 additions and 21 deletions Side-by-side Diff

sound/arm/sa11xx-uda1341.c
... ... @@ -21,7 +21,7 @@
21 21 * merged HAL layer (patches from Brian)
22 22 */
23 23  
24   -/* $Id: sa11xx-uda1341.c,v 1.25 2005/11/17 15:10:58 tiwai Exp $ */
  24 +/* $Id: sa11xx-uda1341.c,v 1.26 2005/11/17 17:19:50 tiwai Exp $ */
25 25  
26 26 /***************************************************************************************************
27 27 *
... ... @@ -64,6 +64,8 @@
64 64 #include <linux/module.h>
65 65 #include <linux/moduleparam.h>
66 66 #include <linux/init.h>
  67 +#include <linux/err.h>
  68 +#include <linux/platform_device.h>
67 69 #include <linux/errno.h>
68 70 #include <linux/ioctl.h>
69 71 #include <linux/delay.h>
70 72  
71 73  
72 74  
... ... @@ -860,12 +862,15 @@
860 862  
861 863 #ifdef CONFIG_PM
862 864  
863   -static int snd_sa11xx_uda1341_suspend(struct snd_card *card, pm_message_t state)
  865 +static int snd_sa11xx_uda1341_suspend(struct platform_device *devptr,
  866 + pm_message_t state)
864 867 {
865   - struct sa11xx_uda1341 *chip = card->pm_private_data;
  868 + struct snd_card *card = platform_get_drvdata(devptr);
  869 + struct sa11xx_uda1341 *chip = card->private_data;
866 870  
  871 + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
867 872 snd_pcm_suspend_all(chip->pcm);
868   -#ifdef HH_VERSION
  873 +#ifdef HH_VERSION
869 874 sa1100_dma_sleep(chip->s[SNDRV_PCM_STREAM_PLAYBACK].dmach);
870 875 sa1100_dma_sleep(chip->s[SNDRV_PCM_STREAM_CAPTURE].dmach);
871 876 #else
872 877  
873 878  
... ... @@ -873,12 +878,14 @@
873 878 #endif
874 879 l3_command(chip->uda1341, CMD_SUSPEND, NULL);
875 880 sa11xx_uda1341_audio_shutdown(chip);
  881 +
876 882 return 0;
877 883 }
878 884  
879   -static int snd_sa11xx_uda1341_resume(struct snd_card *card)
  885 +static int snd_sa11xx_uda1341_resume(struct platform_device *devptr)
880 886 {
881   - struct sa11xx_uda1341 *chip = card->pm_private_data;
  887 + struct snd_card *card = platform_get_drvdata(devptr);
  888 + struct sa11xx_uda1341 *chip = card->private_data;
882 889  
883 890 sa11xx_uda1341_audio_init(chip);
884 891 l3_command(chip->uda1341, CMD_RESUME, NULL);
... ... @@ -888,6 +895,7 @@
888 895 #else
889 896 //FIXME
890 897 #endif
  898 + snd_power_change_state(card, SNDRV_CTL_POWER_D0);
891 899 return 0;
892 900 }
893 901 #endif /* COMFIG_PM */
894 902  
895 903  
896 904  
... ... @@ -900,27 +908,22 @@
900 908 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_CAPTURE]);
901 909 }
902 910  
903   -static struct snd_card *sa11xx_uda1341_card;
904   -
905   -static int __init sa11xx_uda1341_init(void)
  911 +static int __init sa11xx_uda1341_probe(struct platform_device *devptr)
906 912 {
907 913 int err;
908 914 struct snd_card *card;
909 915 struct sa11xx_uda1341 *chip;
910 916  
911   - if (!machine_is_h3xxx())
912   - return -ENODEV;
913   -
914 917 /* register the soundcard */
915 918 card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct sa11xx_uda1341));
916 919 if (card == NULL)
917 920 return -ENOMEM;
918 921  
919   - card->private_free = snd_sa11xx_uda1341_free;
920 922 chip = card->private_data;
921 923 spin_lock_init(&chip->s[0].dma_lock);
922 924 spin_lock_init(&chip->s[1].dma_lock);
923 925  
  926 + card->private_free = snd_sa11xx_uda1341_free;
924 927 chip->card = card;
925 928 chip->samplerate = AUDIO_RATE_DEFAULT;
926 929  
927 930  
928 931  
... ... @@ -932,20 +935,15 @@
932 935 if ((err = snd_card_sa11xx_uda1341_pcm(chip, 0)) < 0)
933 936 goto nodev;
934 937  
935   - snd_card_set_generic_pm_callback(card,
936   - snd_sa11xx_uda1341_suspend, snd_sa11_uda1341_resume,
937   - chip);
938   -
939 938 strcpy(card->driver, "UDA1341");
940 939 strcpy(card->shortname, "H3600 UDA1341TS");
941 940 sprintf(card->longname, "Compaq iPAQ H3600 with Philips UDA1341TS");
942 941  
943   - if ((err = snd_card_set_generic_dev(card)) < 0)
944   - goto nodev;
  942 + snd_card_set_dev(card, &devptr->dev);
945 943  
946 944 if ((err = snd_card_register(card)) == 0) {
947 945 printk( KERN_INFO "iPAQ audio support initialized\n" );
948   - sa11xx_uda1341_card = card;
  946 + platform_set_drvdata(devptr, card);
949 947 return 0;
950 948 }
951 949  
952 950  
... ... @@ -954,9 +952,47 @@
954 952 return err;
955 953 }
956 954  
  955 +static int __devexit sa11xx_uda1341_remove(struct platform_device *devptr)
  956 +{
  957 + snd_card_free(platform_get_drvdata(devptr));
  958 + platform_set_drvdata(devptr, NULL);
  959 + return 0;
  960 +}
  961 +
  962 +#define SA11XX_UDA1341_DRIVER "sa11xx_uda1341"
  963 +
  964 +static struct platform_driver sa11xx_uda1341_driver = {
  965 + .probe = sa11xx_uda1341_probe,
  966 + .remove = __devexit_p(sa11xx_uda1341_remove),
  967 +#ifdef CONFIG_PM
  968 + .suspend = snd_sa11xx_uda1341_suspend,
  969 + .resume = snd_sa11xx_uda1341_resume,
  970 +#endif
  971 + .driver = {
  972 + .name = SA11XX_UDA1341_DRIVER,
  973 + },
  974 +};
  975 +
  976 +static int __init sa11xx_uda1341_init(void)
  977 +{
  978 + int err;
  979 + struct platform_device *device;
  980 +
  981 + if (!machine_is_h3xxx())
  982 + return -ENODEV;
  983 + if ((err = platform_driver_register(&sa11xx_uda1341_driver)) < 0)
  984 + return err;
  985 + device = platform_device_register_simple(SA11XX_UDA1341_DRIVER, -1, NULL, 0);
  986 + if (IS_ERR(device)) {
  987 + platform_driver_unregister(&sa11xx_uda1341_driver);
  988 + return PTR_ERR(device);
  989 + }
  990 + return 0;
  991 +}
  992 +
957 993 static void __exit sa11xx_uda1341_exit(void)
958 994 {
959   - snd_card_free(sa11xx_uda1341_card);
  995 + platform_driver_unregister(&sa11xx_uda1341_driver);
960 996 }
961 997  
962 998 module_init(sa11xx_uda1341_init);