aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-ibm_iic.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-ibm_iic.c')
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c206
1 files changed, 8 insertions, 198 deletions
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 85dbf34382e1..651f2f1ae5b7 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -42,13 +42,8 @@
42#include <asm/io.h> 42#include <asm/io.h>
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/i2c-id.h> 44#include <linux/i2c-id.h>
45
46#ifdef CONFIG_IBM_OCP
47#include <asm/ocp.h>
48#include <asm/ibm4xx.h>
49#else
50#include <linux/of_platform.h> 45#include <linux/of_platform.h>
51#endif 46#include <linux/of_i2c.h>
52 47
53#include "i2c-ibm_iic.h" 48#include "i2c-ibm_iic.h"
54 49
@@ -665,180 +660,6 @@ static inline u8 iic_clckdiv(unsigned int opb)
665 return (u8)((opb + 9) / 10 - 1); 660 return (u8)((opb + 9) / 10 - 1);
666} 661}
667 662
668#ifdef CONFIG_IBM_OCP
669/*
670 * Register single IIC interface
671 */
672static int __devinit iic_probe(struct ocp_device *ocp){
673
674 struct ibm_iic_private* dev;
675 struct i2c_adapter* adap;
676 struct ocp_func_iic_data* iic_data = ocp->def->additions;
677 int ret;
678
679 if (!iic_data)
680 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n",
681 ocp->def->index);
682
683 if (!(dev = kzalloc(sizeof(*dev), GFP_KERNEL))) {
684 printk(KERN_ERR "ibm-iic%d: failed to allocate device data\n",
685 ocp->def->index);
686 return -ENOMEM;
687 }
688
689 dev->idx = ocp->def->index;
690 ocp_set_drvdata(ocp, dev);
691
692 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs),
693 "ibm_iic")) {
694 ret = -EBUSY;
695 goto fail1;
696 }
697
698 if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){
699 printk(KERN_ERR "ibm-iic%d: failed to ioremap device registers\n",
700 dev->idx);
701 ret = -ENXIO;
702 goto fail2;
703 }
704
705 init_waitqueue_head(&dev->wq);
706
707 dev->irq = iic_force_poll ? -1 : ocp->def->irq;
708 if (dev->irq >= 0){
709 /* Disable interrupts until we finish initialization,
710 assumes level-sensitive IRQ setup...
711 */
712 iic_interrupt_mode(dev, 0);
713 if (request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev)){
714 printk(KERN_ERR "ibm-iic%d: request_irq %d failed\n",
715 dev->idx, dev->irq);
716 /* Fallback to the polling mode */
717 dev->irq = -1;
718 }
719 }
720
721 if (dev->irq < 0)
722 printk(KERN_WARNING "ibm-iic%d: using polling mode\n",
723 dev->idx);
724
725 /* Board specific settings */
726 dev->fast_mode = iic_force_fast ? 1 : (iic_data ? iic_data->fast_mode : 0);
727
728 /* clckdiv is the same for *all* IIC interfaces,
729 * but I'd rather make a copy than introduce another global. --ebs
730 */
731 dev->clckdiv = iic_clckdiv(ocp_sys_info.opb_bus_freq);
732 DBG("%d: clckdiv = %d\n", dev->idx, dev->clckdiv);
733
734 /* Initialize IIC interface */
735 iic_dev_init(dev);
736
737 /* Register it with i2c layer */
738 adap = &dev->adap;
739 adap->dev.parent = &ocp->dev;
740 strcpy(adap->name, "IBM IIC");
741 i2c_set_adapdata(adap, dev);
742 adap->id = I2C_HW_OCP;
743 adap->class = I2C_CLASS_HWMON;
744 adap->algo = &iic_algo;
745 adap->client_register = NULL;
746 adap->client_unregister = NULL;
747 adap->timeout = 1;
748
749 /*
750 * If "dev->idx" is negative we consider it as zero.
751 * The reason to do so is to avoid sysfs names that only make
752 * sense when there are multiple adapters.
753 */
754 adap->nr = dev->idx >= 0 ? dev->idx : 0;
755
756 if ((ret = i2c_add_numbered_adapter(adap)) < 0) {
757 printk(KERN_ERR "ibm-iic%d: failed to register i2c adapter\n",
758 dev->idx);
759 goto fail;
760 }
761
762 printk(KERN_INFO "ibm-iic%d: using %s mode\n", dev->idx,
763 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
764
765 return 0;
766
767fail:
768 if (dev->irq >= 0){
769 iic_interrupt_mode(dev, 0);
770 free_irq(dev->irq, dev);
771 }
772
773 iounmap(dev->vaddr);
774fail2:
775 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
776fail1:
777 ocp_set_drvdata(ocp, NULL);
778 kfree(dev);
779 return ret;
780}
781
782/*
783 * Cleanup initialized IIC interface
784 */
785static void __devexit iic_remove(struct ocp_device *ocp)
786{
787 struct ibm_iic_private* dev = (struct ibm_iic_private*)ocp_get_drvdata(ocp);
788 BUG_ON(dev == NULL);
789 if (i2c_del_adapter(&dev->adap)){
790 printk(KERN_ERR "ibm-iic%d: failed to delete i2c adapter :(\n",
791 dev->idx);
792 /* That's *very* bad, just shutdown IRQ ... */
793 if (dev->irq >= 0){
794 iic_interrupt_mode(dev, 0);
795 free_irq(dev->irq, dev);
796 dev->irq = -1;
797 }
798 } else {
799 if (dev->irq >= 0){
800 iic_interrupt_mode(dev, 0);
801 free_irq(dev->irq, dev);
802 }
803 iounmap(dev->vaddr);
804 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
805 kfree(dev);
806 }
807}
808
809static struct ocp_device_id ibm_iic_ids[] __devinitdata =
810{
811 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_IIC },
812 { .vendor = OCP_VENDOR_INVALID }
813};
814
815MODULE_DEVICE_TABLE(ocp, ibm_iic_ids);
816
817static struct ocp_driver ibm_iic_driver =
818{
819 .name = "iic",
820 .id_table = ibm_iic_ids,
821 .probe = iic_probe,
822 .remove = __devexit_p(iic_remove),
823#if defined(CONFIG_PM)
824 .suspend = NULL,
825 .resume = NULL,
826#endif
827};
828
829static int __init iic_init(void)
830{
831 printk(KERN_INFO "IBM IIC driver v" DRIVER_VERSION "\n");
832 return ocp_register_driver(&ibm_iic_driver);
833}
834
835static void __exit iic_exit(void)
836{
837 ocp_unregister_driver(&ibm_iic_driver);
838}
839
840#else /* !CONFIG_IBM_OCP */
841
842static int __devinit iic_request_irq(struct of_device *ofdev, 663static int __devinit iic_request_irq(struct of_device *ofdev,
843 struct ibm_iic_private *dev) 664 struct ibm_iic_private *dev)
844{ 665{
@@ -876,7 +697,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
876 struct device_node *np = ofdev->node; 697 struct device_node *np = ofdev->node;
877 struct ibm_iic_private *dev; 698 struct ibm_iic_private *dev;
878 struct i2c_adapter *adap; 699 struct i2c_adapter *adap;
879 const u32 *indexp, *freq; 700 const u32 *freq;
880 int ret; 701 int ret;
881 702
882 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 703 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -887,14 +708,6 @@ static int __devinit iic_probe(struct of_device *ofdev,
887 708
888 dev_set_drvdata(&ofdev->dev, dev); 709 dev_set_drvdata(&ofdev->dev, dev);
889 710
890 indexp = of_get_property(np, "index", NULL);
891 if (!indexp) {
892 dev_err(&ofdev->dev, "no index specified\n");
893 ret = -EINVAL;
894 goto error_cleanup;
895 }
896 dev->idx = *indexp;
897
898 dev->vaddr = of_iomap(np, 0); 711 dev->vaddr = of_iomap(np, 0);
899 if (dev->vaddr == NULL) { 712 if (dev->vaddr == NULL) {
900 dev_err(&ofdev->dev, "failed to iomap device\n"); 713 dev_err(&ofdev->dev, "failed to iomap device\n");
@@ -934,17 +747,19 @@ static int __devinit iic_probe(struct of_device *ofdev,
934 strlcpy(adap->name, "IBM IIC", sizeof(adap->name)); 747 strlcpy(adap->name, "IBM IIC", sizeof(adap->name));
935 i2c_set_adapdata(adap, dev); 748 i2c_set_adapdata(adap, dev);
936 adap->id = I2C_HW_OCP; 749 adap->id = I2C_HW_OCP;
937 adap->class = I2C_CLASS_HWMON; 750 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
938 adap->algo = &iic_algo; 751 adap->algo = &iic_algo;
939 adap->timeout = 1; 752 adap->timeout = 1;
940 adap->nr = dev->idx;
941 753
942 ret = i2c_add_numbered_adapter(adap); 754 ret = i2c_add_adapter(adap);
943 if (ret < 0) { 755 if (ret < 0) {
944 dev_err(&ofdev->dev, "failed to register i2c adapter\n"); 756 dev_err(&ofdev->dev, "failed to register i2c adapter\n");
945 goto error_cleanup; 757 goto error_cleanup;
946 } 758 }
947 759
760 /* Now register all the child nodes */
761 of_register_i2c_devices(adap, np);
762
948 dev_info(&ofdev->dev, "using %s mode\n", 763 dev_info(&ofdev->dev, "using %s mode\n",
949 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 764 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
950 765
@@ -987,11 +802,7 @@ static int __devexit iic_remove(struct of_device *ofdev)
987} 802}
988 803
989static const struct of_device_id ibm_iic_match[] = { 804static const struct of_device_id ibm_iic_match[] = {
990 { .compatible = "ibm,iic-405ex", }, 805 { .compatible = "ibm,iic", },
991 { .compatible = "ibm,iic-405gp", },
992 { .compatible = "ibm,iic-440gp", },
993 { .compatible = "ibm,iic-440gpx", },
994 { .compatible = "ibm,iic-440grx", },
995 {} 806 {}
996}; 807};
997 808
@@ -1011,7 +822,6 @@ static void __exit iic_exit(void)
1011{ 822{
1012 of_unregister_platform_driver(&ibm_iic_driver); 823 of_unregister_platform_driver(&ibm_iic_driver);
1013} 824}
1014#endif /* CONFIG_IBM_OCP */
1015 825
1016module_init(iic_init); 826module_init(iic_init);
1017module_exit(iic_exit); 827module_exit(iic_exit);