534
530
.formats = SSM2602_FORMATS,},
535
531
.ops = &ssm2602_dai_ops,
537
EXPORT_SYMBOL_GPL(ssm2602_dai);
539
static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state)
534
static int ssm2602_suspend(struct snd_soc_codec *codec, pm_message_t state)
541
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
542
struct snd_soc_codec *codec = socdev->card->codec;
544
536
ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
548
static int ssm2602_resume(struct platform_device *pdev)
540
static int ssm2602_resume(struct snd_soc_codec *codec)
550
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
551
struct snd_soc_codec *codec = socdev->card->codec;
554
544
u16 *cache = codec->reg_cache;
560
550
codec->hw_write(codec->control_data, data, 2);
562
552
ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
563
ssm2602_set_bias_level(codec, codec->suspend_bias_level);
568
* initialise the ssm2602 driver
569
* register the mixer and dsp interfaces with the kernel
571
static int ssm2602_init(struct snd_soc_device *socdev)
556
static int ssm2602_probe(struct snd_soc_codec *codec)
573
struct snd_soc_codec *codec = socdev->card->codec;
576
codec->name = "SSM2602";
577
codec->owner = THIS_MODULE;
578
codec->read = ssm2602_read_reg_cache;
579
codec->write = ssm2602_write;
580
codec->set_bias_level = ssm2602_set_bias_level;
581
codec->dai = &ssm2602_dai;
583
codec->reg_cache_size = sizeof(ssm2602_reg);
584
codec->reg_cache = kmemdup(ssm2602_reg, sizeof(ssm2602_reg),
586
if (codec->reg_cache == NULL)
558
struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
561
pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION);
563
codec->control_data = ssm2602->control_data;
589
565
ssm2602_reset(codec);
592
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
594
pr_err("ssm2602: failed to create pcms\n");
597
567
/*power on device*/
598
568
ssm2602_write(codec, SSM2602_ACTIVE, 0);
599
569
/* set the update bits */
615
585
ssm2602_add_widgets(codec);
620
kfree(codec->reg_cache);
624
static struct snd_soc_device *ssm2602_socdev;
590
/* remove everything here */
591
static int ssm2602_remove(struct snd_soc_codec *codec)
593
ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
597
static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
598
.probe = ssm2602_probe,
599
.remove = ssm2602_remove,
600
.suspend = ssm2602_suspend,
601
.resume = ssm2602_resume,
602
.read = ssm2602_read_reg_cache,
603
.write = ssm2602_write,
604
.set_bias_level = ssm2602_set_bias_level,
605
.reg_cache_size = sizeof(ssm2602_reg),
606
.reg_word_size = sizeof(u16),
607
.reg_cache_default = ssm2602_reg,
626
610
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
633
617
static int ssm2602_i2c_probe(struct i2c_client *i2c,
634
618
const struct i2c_device_id *id)
636
struct snd_soc_device *socdev = ssm2602_socdev;
637
struct snd_soc_codec *codec = socdev->card->codec;
620
struct ssm2602_priv *ssm2602;
640
i2c_set_clientdata(i2c, codec);
641
codec->control_data = i2c;
643
ret = ssm2602_init(socdev);
623
ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL);
627
i2c_set_clientdata(i2c, ssm2602);
628
ssm2602->control_data = i2c;
629
ssm2602->control_type = SND_SOC_I2C;
631
ret = snd_soc_register_codec(&i2c->dev,
632
&soc_codec_dev_ssm2602, &ssm2602_dai, 1);
645
pr_err("failed to initialise SSM2602\n");
650
638
static int ssm2602_i2c_remove(struct i2c_client *client)
652
struct snd_soc_codec *codec = i2c_get_clientdata(client);
653
kfree(codec->reg_cache);
640
snd_soc_unregister_codec(&client->dev);
641
kfree(i2c_get_clientdata(client));
661
649
MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id);
662
651
/* corgi i2c codec control layer */
663
652
static struct i2c_driver ssm2602_i2c_driver = {
665
.name = "SSM2602 I2C Codec",
654
.name = "ssm2602-codec",
666
655
.owner = THIS_MODULE,
668
657
.probe = ssm2602_i2c_probe,
669
658
.remove = ssm2602_i2c_remove,
670
659
.id_table = ssm2602_i2c_id,
673
static int ssm2602_add_i2c_device(struct platform_device *pdev,
674
const struct ssm2602_setup_data *setup)
664
static int __init ssm2602_modinit(void)
676
struct i2c_board_info info;
677
struct i2c_adapter *adapter;
678
struct i2c_client *client;
667
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
681
668
ret = i2c_add_driver(&ssm2602_i2c_driver);
683
dev_err(&pdev->dev, "can't add i2c driver\n");
686
memset(&info, 0, sizeof(struct i2c_board_info));
687
info.addr = setup->i2c_address;
688
strlcpy(info.type, "ssm2602", I2C_NAME_SIZE);
689
adapter = i2c_get_adapter(setup->i2c_bus);
691
dev_err(&pdev->dev, "can't get i2c adapter %d\n",
695
client = i2c_new_device(adapter, &info);
696
i2c_put_adapter(adapter);
698
dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
699
(unsigned int)info.addr);
704
i2c_del_driver(&ssm2602_i2c_driver);
709
static int ssm2602_probe(struct platform_device *pdev)
711
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
712
struct ssm2602_setup_data *setup;
713
struct snd_soc_codec *codec;
714
struct ssm2602_priv *ssm2602;
717
pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION);
719
setup = socdev->codec_data;
720
codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
724
ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL);
725
if (ssm2602 == NULL) {
730
codec->private_data = ssm2602;
731
socdev->card->codec = codec;
732
mutex_init(&codec->mutex);
733
INIT_LIST_HEAD(&codec->dapm_widgets);
734
INIT_LIST_HEAD(&codec->dapm_paths);
736
ssm2602_socdev = socdev;
737
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
738
if (setup->i2c_address) {
739
codec->hw_write = (hw_write_t)i2c_master_send;
740
ret = ssm2602_add_i2c_device(pdev, setup);
743
/* other interfaces */
670
printk(KERN_ERR "Failed to register SSM2602 I2C driver: %d\n",
748
/* remove everything here */
749
static int ssm2602_remove(struct platform_device *pdev)
751
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
752
struct snd_soc_codec *codec = socdev->card->codec;
754
if (codec->control_data)
755
ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
757
snd_soc_free_pcms(socdev);
758
snd_soc_dapm_free(socdev);
759
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
760
i2c_unregister_device(codec->control_data);
761
i2c_del_driver(&ssm2602_i2c_driver);
763
kfree(codec->private_data);
769
struct snd_soc_codec_device soc_codec_dev_ssm2602 = {
770
.probe = ssm2602_probe,
771
.remove = ssm2602_remove,
772
.suspend = ssm2602_suspend,
773
.resume = ssm2602_resume,
775
EXPORT_SYMBOL_GPL(soc_codec_dev_ssm2602);
777
static int __init ssm2602_modinit(void)
779
return snd_soc_register_dai(&ssm2602_dai);
781
676
module_init(ssm2602_modinit);
783
678
static void __exit ssm2602_exit(void)
785
snd_soc_unregister_dai(&ssm2602_dai);
680
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
681
i2c_del_driver(&ssm2602_i2c_driver);
787
684
module_exit(ssm2602_exit);