diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-09-01 11:46:57 -0400 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-09-09 03:11:11 -0400 |
commit | b6471305bbda16fd0d8d96a5cfb01fa6aec87eb5 (patch) | |
tree | ac2bbc6da8bdbe3908118369f3b21536c947cbe0 /sound/soc | |
parent | ad4503d8a0636ddae8175bd05b652264c4260e96 (diff) |
sound: ASoC: Convert neo1973/lm4857 to a new-style i2c driver
Convert the lm4857 driver in neo1973_wm8753 to the new (standard)
i2c device driver binding model. I assumed that the LM4857 was always
on the same I2C bus as the WM8753 codec.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Tim Niemeyer <reddog@mastersword.de>
Cc: Graeme Gregory <graeme@openmoko.org>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/soc')
-rw-r--r-- | sound/soc/s3c24xx/neo1973_wm8753.c | 110 |
1 files changed, 58 insertions, 52 deletions
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 181d2999fb20..47ddcdedc3a4 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c | |||
@@ -597,54 +597,20 @@ static struct snd_soc_device neo1973_snd_devdata = { | |||
597 | .codec_data = &neo1973_wm8753_setup, | 597 | .codec_data = &neo1973_wm8753_setup, |
598 | }; | 598 | }; |
599 | 599 | ||
600 | static struct i2c_client client_template; | 600 | static int lm4857_i2c_probe(struct i2c_client *client, |
601 | 601 | const struct i2c_device_id *id) | |
602 | static const unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END }; | ||
603 | |||
604 | /* Magic definition of all other variables and things */ | ||
605 | I2C_CLIENT_INSMOD; | ||
606 | |||
607 | static int lm4857_amp_probe(struct i2c_adapter *adap, int addr, int kind) | ||
608 | { | 602 | { |
609 | int ret; | ||
610 | |||
611 | DBG("Entered %s\n", __func__); | 603 | DBG("Entered %s\n", __func__); |
612 | 604 | ||
613 | client_template.adapter = adap; | ||
614 | client_template.addr = addr; | ||
615 | |||
616 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
617 | if (i2c == NULL) | ||
618 | return -ENOMEM; | ||
619 | |||
620 | ret = i2c_attach_client(i2c); | ||
621 | if (ret < 0) { | ||
622 | printk(KERN_ERR "LM4857 failed to attach at addr %x\n", addr); | ||
623 | goto exit_err; | ||
624 | } | ||
625 | |||
626 | lm4857_write_regs(); | 605 | lm4857_write_regs(); |
627 | return ret; | ||
628 | |||
629 | exit_err: | ||
630 | kfree(i2c); | ||
631 | return ret; | ||
632 | } | ||
633 | |||
634 | static int lm4857_i2c_detach(struct i2c_client *client) | ||
635 | { | ||
636 | DBG("Entered %s\n", __func__); | ||
637 | |||
638 | i2c_detach_client(client); | ||
639 | kfree(client); | ||
640 | return 0; | 606 | return 0; |
641 | } | 607 | } |
642 | 608 | ||
643 | static int lm4857_i2c_attach(struct i2c_adapter *adap) | 609 | static int lm4857_i2c_remove(struct i2c_client *client) |
644 | { | 610 | { |
645 | DBG("Entered %s\n", __func__); | 611 | DBG("Entered %s\n", __func__); |
646 | 612 | ||
647 | return i2c_probe(adap, &addr_data, lm4857_amp_probe); | 613 | return 0; |
648 | } | 614 | } |
649 | 615 | ||
650 | static u8 lm4857_state; | 616 | static u8 lm4857_state; |
@@ -682,27 +648,67 @@ static void lm4857_shutdown(struct i2c_client *dev) | |||
682 | lm4857_write_regs(); | 648 | lm4857_write_regs(); |
683 | } | 649 | } |
684 | 650 | ||
685 | /* corgi i2c codec control layer */ | 651 | static const struct i2c_device_id lm4857_i2c_id[] = { |
652 | { "neo1973_lm4857", 0 } | ||
653 | { } | ||
654 | }; | ||
655 | |||
686 | static struct i2c_driver lm4857_i2c_driver = { | 656 | static struct i2c_driver lm4857_i2c_driver = { |
687 | .driver = { | 657 | .driver = { |
688 | .name = "LM4857 I2C Amp", | 658 | .name = "LM4857 I2C Amp", |
689 | .owner = THIS_MODULE, | 659 | .owner = THIS_MODULE, |
690 | }, | 660 | }, |
691 | .id = I2C_DRIVERID_LM4857, | ||
692 | .suspend = lm4857_suspend, | 661 | .suspend = lm4857_suspend, |
693 | .resume = lm4857_resume, | 662 | .resume = lm4857_resume, |
694 | .shutdown = lm4857_shutdown, | 663 | .shutdown = lm4857_shutdown, |
695 | .attach_adapter = lm4857_i2c_attach, | 664 | .probe = lm4857_i2c_probe, |
696 | .detach_client = lm4857_i2c_detach, | 665 | .remove = lm4857_i2c_remove, |
697 | .command = NULL, | 666 | .id_table = lm4857_i2c_id, |
698 | }; | ||
699 | |||
700 | static struct i2c_client client_template = { | ||
701 | .name = "LM4857", | ||
702 | .driver = &lm4857_i2c_driver, | ||
703 | }; | 667 | }; |
704 | 668 | ||
705 | static struct platform_device *neo1973_snd_device; | 669 | static struct platform_device *neo1973_snd_device; |
670 | static struct i2c_client *lm4857_client; | ||
671 | |||
672 | static int __init neo1973_add_lm4857_device(struct platform_device *pdev, | ||
673 | int i2c_bus, | ||
674 | unsigned short i2c_address) | ||
675 | { | ||
676 | struct i2c_board_info info; | ||
677 | struct i2c_adapter *adapter; | ||
678 | struct i2c_client *client; | ||
679 | int ret; | ||
680 | |||
681 | ret = i2c_add_driver(&lm4857_i2c_driver); | ||
682 | if (ret != 0) { | ||
683 | dev_err(&pdev->dev, "can't add lm4857 driver\n"); | ||
684 | return ret; | ||
685 | } | ||
686 | |||
687 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
688 | info.addr = i2c_address; | ||
689 | strlcpy(info.type, "neo1973_lm4857", I2C_NAME_SIZE); | ||
690 | |||
691 | adapter = i2c_get_adapter(i2c_bus); | ||
692 | if (!adapter) { | ||
693 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", i2c_bus); | ||
694 | goto err_driver; | ||
695 | } | ||
696 | |||
697 | client = i2c_new_device(adapter, &info); | ||
698 | i2c_put_adapter(adapter); | ||
699 | if (!client) { | ||
700 | dev_err(&pdev->dev, "can't add lm4857 device at 0x%x\n", | ||
701 | (unsigned int)info.addr); | ||
702 | goto err_driver; | ||
703 | } | ||
704 | |||
705 | lm4857_client = client; | ||
706 | return 0; | ||
707 | |||
708 | err_driver: | ||
709 | i2c_del_driver(&lm4857_i2c_driver); | ||
710 | return -ENODEV; | ||
711 | } | ||
706 | 712 | ||
707 | static int __init neo1973_init(void) | 713 | static int __init neo1973_init(void) |
708 | { | 714 | { |
@@ -723,11 +729,10 @@ static int __init neo1973_init(void) | |||
723 | return ret; | 729 | return ret; |
724 | } | 730 | } |
725 | 731 | ||
726 | ret = i2c_add_driver(&lm4857_i2c_driver); | 732 | ret = neo1973_add_lm4857_device(neo1973_snd_device, |
727 | if (ret != 0) { | 733 | neo1973_wm8753_setup, 0x7C); |
728 | printk(KERN_ERR "can't add i2c driver"); | 734 | if (ret != 0) |
729 | platform_device_unregister(neo1973_snd_device); | 735 | platform_device_unregister(neo1973_snd_device); |
730 | } | ||
731 | 736 | ||
732 | return ret; | 737 | return ret; |
733 | } | 738 | } |
@@ -736,6 +741,7 @@ static void __exit neo1973_exit(void) | |||
736 | { | 741 | { |
737 | DBG("Entered %s\n", __func__); | 742 | DBG("Entered %s\n", __func__); |
738 | 743 | ||
744 | i2c_unregister_device(lm4857_client); | ||
739 | i2c_del_driver(&lm4857_i2c_driver); | 745 | i2c_del_driver(&lm4857_i2c_driver); |
740 | platform_device_unregister(neo1973_snd_device); | 746 | platform_device_unregister(neo1973_snd_device); |
741 | } | 747 | } |