diff options
Diffstat (limited to 'drivers/spi/spi_mpc83xx.c')
-rw-r--r-- | drivers/spi/spi_mpc83xx.c | 366 |
1 files changed, 310 insertions, 56 deletions
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c index 44a2b46ccb7..f4573a96af2 100644 --- a/drivers/spi/spi_mpc83xx.c +++ b/drivers/spi/spi_mpc83xx.c | |||
@@ -14,6 +14,8 @@ | |||
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/errno.h> | ||
18 | #include <linux/err.h> | ||
17 | #include <linux/completion.h> | 19 | #include <linux/completion.h> |
18 | #include <linux/interrupt.h> | 20 | #include <linux/interrupt.h> |
19 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
@@ -23,7 +25,13 @@ | |||
23 | #include <linux/spi/spi_bitbang.h> | 25 | #include <linux/spi/spi_bitbang.h> |
24 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
25 | #include <linux/fsl_devices.h> | 27 | #include <linux/fsl_devices.h> |
28 | #include <linux/of.h> | ||
29 | #include <linux/of_platform.h> | ||
30 | #include <linux/gpio.h> | ||
31 | #include <linux/of_gpio.h> | ||
32 | #include <linux/of_spi.h> | ||
26 | 33 | ||
34 | #include <sysdev/fsl_soc.h> | ||
27 | #include <asm/irq.h> | 35 | #include <asm/irq.h> |
28 | #include <asm/io.h> | 36 | #include <asm/io.h> |
29 | 37 | ||
@@ -79,7 +87,7 @@ struct mpc83xx_spi { | |||
79 | u32(*get_tx) (struct mpc83xx_spi *); | 87 | u32(*get_tx) (struct mpc83xx_spi *); |
80 | 88 | ||
81 | unsigned int count; | 89 | unsigned int count; |
82 | int irq; | 90 | unsigned int irq; |
83 | 91 | ||
84 | unsigned nsecs; /* (clock cycle time)/2 */ | 92 | unsigned nsecs; /* (clock cycle time)/2 */ |
85 | 93 | ||
@@ -89,9 +97,6 @@ struct mpc83xx_spi { | |||
89 | 97 | ||
90 | bool qe_mode; | 98 | bool qe_mode; |
91 | 99 | ||
92 | void (*activate_cs) (u8 cs, u8 polarity); | ||
93 | void (*deactivate_cs) (u8 cs, u8 polarity); | ||
94 | |||
95 | u8 busy; | 100 | u8 busy; |
96 | 101 | ||
97 | struct workqueue_struct *workqueue; | 102 | struct workqueue_struct *workqueue; |
@@ -123,6 +128,7 @@ static inline u32 mpc83xx_spi_read_reg(__be32 __iomem * reg) | |||
123 | } | 128 | } |
124 | 129 | ||
125 | #define MPC83XX_SPI_RX_BUF(type) \ | 130 | #define MPC83XX_SPI_RX_BUF(type) \ |
131 | static \ | ||
126 | void mpc83xx_spi_rx_buf_##type(u32 data, struct mpc83xx_spi *mpc83xx_spi) \ | 132 | void mpc83xx_spi_rx_buf_##type(u32 data, struct mpc83xx_spi *mpc83xx_spi) \ |
127 | { \ | 133 | { \ |
128 | type * rx = mpc83xx_spi->rx; \ | 134 | type * rx = mpc83xx_spi->rx; \ |
@@ -131,6 +137,7 @@ void mpc83xx_spi_rx_buf_##type(u32 data, struct mpc83xx_spi *mpc83xx_spi) \ | |||
131 | } | 137 | } |
132 | 138 | ||
133 | #define MPC83XX_SPI_TX_BUF(type) \ | 139 | #define MPC83XX_SPI_TX_BUF(type) \ |
140 | static \ | ||
134 | u32 mpc83xx_spi_tx_buf_##type(struct mpc83xx_spi *mpc83xx_spi) \ | 141 | u32 mpc83xx_spi_tx_buf_##type(struct mpc83xx_spi *mpc83xx_spi) \ |
135 | { \ | 142 | { \ |
136 | u32 data; \ | 143 | u32 data; \ |
@@ -151,15 +158,14 @@ MPC83XX_SPI_TX_BUF(u32) | |||
151 | 158 | ||
152 | static void mpc83xx_spi_chipselect(struct spi_device *spi, int value) | 159 | static void mpc83xx_spi_chipselect(struct spi_device *spi, int value) |
153 | { | 160 | { |
154 | struct mpc83xx_spi *mpc83xx_spi; | 161 | struct mpc83xx_spi *mpc83xx_spi = spi_master_get_devdata(spi->master); |
155 | u8 pol = spi->mode & SPI_CS_HIGH ? 1 : 0; | 162 | struct fsl_spi_platform_data *pdata = spi->dev.parent->platform_data; |
163 | bool pol = spi->mode & SPI_CS_HIGH; | ||
156 | struct spi_mpc83xx_cs *cs = spi->controller_state; | 164 | struct spi_mpc83xx_cs *cs = spi->controller_state; |
157 | 165 | ||
158 | mpc83xx_spi = spi_master_get_devdata(spi->master); | ||
159 | |||
160 | if (value == BITBANG_CS_INACTIVE) { | 166 | if (value == BITBANG_CS_INACTIVE) { |
161 | if (mpc83xx_spi->deactivate_cs) | 167 | if (pdata->cs_control) |
162 | mpc83xx_spi->deactivate_cs(spi->chip_select, pol); | 168 | pdata->cs_control(spi, !pol); |
163 | } | 169 | } |
164 | 170 | ||
165 | if (value == BITBANG_CS_ACTIVE) { | 171 | if (value == BITBANG_CS_ACTIVE) { |
@@ -172,7 +178,7 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value) | |||
172 | 178 | ||
173 | if (cs->hw_mode != regval) { | 179 | if (cs->hw_mode != regval) { |
174 | unsigned long flags; | 180 | unsigned long flags; |
175 | void *tmp_ptr = &mpc83xx_spi->base->mode; | 181 | __be32 __iomem *mode = &mpc83xx_spi->base->mode; |
176 | 182 | ||
177 | regval = cs->hw_mode; | 183 | regval = cs->hw_mode; |
178 | /* Turn off IRQs locally to minimize time that | 184 | /* Turn off IRQs locally to minimize time that |
@@ -180,12 +186,12 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value) | |||
180 | */ | 186 | */ |
181 | local_irq_save(flags); | 187 | local_irq_save(flags); |
182 | /* Turn off SPI unit prior changing mode */ | 188 | /* Turn off SPI unit prior changing mode */ |
183 | mpc83xx_spi_write_reg(tmp_ptr, regval & ~SPMODE_ENABLE); | 189 | mpc83xx_spi_write_reg(mode, regval & ~SPMODE_ENABLE); |
184 | mpc83xx_spi_write_reg(tmp_ptr, regval); | 190 | mpc83xx_spi_write_reg(mode, regval); |
185 | local_irq_restore(flags); | 191 | local_irq_restore(flags); |
186 | } | 192 | } |
187 | if (mpc83xx_spi->activate_cs) | 193 | if (pdata->cs_control) |
188 | mpc83xx_spi->activate_cs(spi->chip_select, pol); | 194 | pdata->cs_control(spi, pol); |
189 | } | 195 | } |
190 | } | 196 | } |
191 | 197 | ||
@@ -284,7 +290,7 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
284 | regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); | 290 | regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); |
285 | if (cs->hw_mode != regval) { | 291 | if (cs->hw_mode != regval) { |
286 | unsigned long flags; | 292 | unsigned long flags; |
287 | void *tmp_ptr = &mpc83xx_spi->base->mode; | 293 | __be32 __iomem *mode = &mpc83xx_spi->base->mode; |
288 | 294 | ||
289 | regval = cs->hw_mode; | 295 | regval = cs->hw_mode; |
290 | /* Turn off IRQs locally to minimize time | 296 | /* Turn off IRQs locally to minimize time |
@@ -292,8 +298,8 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
292 | */ | 298 | */ |
293 | local_irq_save(flags); | 299 | local_irq_save(flags); |
294 | /* Turn off SPI unit prior changing mode */ | 300 | /* Turn off SPI unit prior changing mode */ |
295 | mpc83xx_spi_write_reg(tmp_ptr, regval & ~SPMODE_ENABLE); | 301 | mpc83xx_spi_write_reg(mode, regval & ~SPMODE_ENABLE); |
296 | mpc83xx_spi_write_reg(tmp_ptr, regval); | 302 | mpc83xx_spi_write_reg(mode, regval); |
297 | local_irq_restore(flags); | 303 | local_irq_restore(flags); |
298 | } | 304 | } |
299 | return 0; | 305 | return 0; |
@@ -483,7 +489,7 @@ static int mpc83xx_spi_setup(struct spi_device *spi) | |||
483 | return 0; | 489 | return 0; |
484 | } | 490 | } |
485 | 491 | ||
486 | irqreturn_t mpc83xx_spi_irq(s32 irq, void *context_data) | 492 | static irqreturn_t mpc83xx_spi_irq(s32 irq, void *context_data) |
487 | { | 493 | { |
488 | struct mpc83xx_spi *mpc83xx_spi = context_data; | 494 | struct mpc83xx_spi *mpc83xx_spi = context_data; |
489 | u32 event; | 495 | u32 event; |
@@ -545,43 +551,28 @@ static void mpc83xx_spi_cleanup(struct spi_device *spi) | |||
545 | kfree(spi->controller_state); | 551 | kfree(spi->controller_state); |
546 | } | 552 | } |
547 | 553 | ||
548 | static int __init mpc83xx_spi_probe(struct platform_device *dev) | 554 | static struct spi_master * __devinit |
555 | mpc83xx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq) | ||
549 | { | 556 | { |
557 | struct fsl_spi_platform_data *pdata = dev->platform_data; | ||
550 | struct spi_master *master; | 558 | struct spi_master *master; |
551 | struct mpc83xx_spi *mpc83xx_spi; | 559 | struct mpc83xx_spi *mpc83xx_spi; |
552 | struct fsl_spi_platform_data *pdata; | ||
553 | struct resource *r; | ||
554 | u32 regval; | 560 | u32 regval; |
555 | int ret = 0; | 561 | int ret = 0; |
556 | 562 | ||
557 | /* Get resources(memory, IRQ) associated with the device */ | 563 | master = spi_alloc_master(dev, sizeof(struct mpc83xx_spi)); |
558 | master = spi_alloc_master(&dev->dev, sizeof(struct mpc83xx_spi)); | ||
559 | |||
560 | if (master == NULL) { | 564 | if (master == NULL) { |
561 | ret = -ENOMEM; | 565 | ret = -ENOMEM; |
562 | goto err; | 566 | goto err; |
563 | } | 567 | } |
564 | 568 | ||
565 | platform_set_drvdata(dev, master); | 569 | dev_set_drvdata(dev, master); |
566 | pdata = dev->dev.platform_data; | ||
567 | 570 | ||
568 | if (pdata == NULL) { | ||
569 | ret = -ENODEV; | ||
570 | goto free_master; | ||
571 | } | ||
572 | |||
573 | r = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
574 | if (r == NULL) { | ||
575 | ret = -ENODEV; | ||
576 | goto free_master; | ||
577 | } | ||
578 | master->setup = mpc83xx_spi_setup; | 571 | master->setup = mpc83xx_spi_setup; |
579 | master->transfer = mpc83xx_spi_transfer; | 572 | master->transfer = mpc83xx_spi_transfer; |
580 | master->cleanup = mpc83xx_spi_cleanup; | 573 | master->cleanup = mpc83xx_spi_cleanup; |
581 | 574 | ||
582 | mpc83xx_spi = spi_master_get_devdata(master); | 575 | mpc83xx_spi = spi_master_get_devdata(master); |
583 | mpc83xx_spi->activate_cs = pdata->activate_cs; | ||
584 | mpc83xx_spi->deactivate_cs = pdata->deactivate_cs; | ||
585 | mpc83xx_spi->qe_mode = pdata->qe_mode; | 576 | mpc83xx_spi->qe_mode = pdata->qe_mode; |
586 | mpc83xx_spi->get_rx = mpc83xx_spi_rx_buf_u8; | 577 | mpc83xx_spi->get_rx = mpc83xx_spi_rx_buf_u8; |
587 | mpc83xx_spi->get_tx = mpc83xx_spi_tx_buf_u8; | 578 | mpc83xx_spi->get_tx = mpc83xx_spi_tx_buf_u8; |
@@ -596,18 +587,13 @@ static int __init mpc83xx_spi_probe(struct platform_device *dev) | |||
596 | 587 | ||
597 | init_completion(&mpc83xx_spi->done); | 588 | init_completion(&mpc83xx_spi->done); |
598 | 589 | ||
599 | mpc83xx_spi->base = ioremap(r->start, r->end - r->start + 1); | 590 | mpc83xx_spi->base = ioremap(mem->start, mem->end - mem->start + 1); |
600 | if (mpc83xx_spi->base == NULL) { | 591 | if (mpc83xx_spi->base == NULL) { |
601 | ret = -ENOMEM; | 592 | ret = -ENOMEM; |
602 | goto put_master; | 593 | goto put_master; |
603 | } | 594 | } |
604 | 595 | ||
605 | mpc83xx_spi->irq = platform_get_irq(dev, 0); | 596 | mpc83xx_spi->irq = irq; |
606 | |||
607 | if (mpc83xx_spi->irq < 0) { | ||
608 | ret = -ENXIO; | ||
609 | goto unmap_io; | ||
610 | } | ||
611 | 597 | ||
612 | /* Register for SPI Interrupt */ | 598 | /* Register for SPI Interrupt */ |
613 | ret = request_irq(mpc83xx_spi->irq, mpc83xx_spi_irq, | 599 | ret = request_irq(mpc83xx_spi->irq, mpc83xx_spi_irq, |
@@ -649,9 +635,9 @@ static int __init mpc83xx_spi_probe(struct platform_device *dev) | |||
649 | 635 | ||
650 | printk(KERN_INFO | 636 | printk(KERN_INFO |
651 | "%s: MPC83xx SPI Controller driver at 0x%p (irq = %d)\n", | 637 | "%s: MPC83xx SPI Controller driver at 0x%p (irq = %d)\n", |
652 | dev_name(&dev->dev), mpc83xx_spi->base, mpc83xx_spi->irq); | 638 | dev_name(dev), mpc83xx_spi->base, mpc83xx_spi->irq); |
653 | 639 | ||
654 | return ret; | 640 | return master; |
655 | 641 | ||
656 | unreg_master: | 642 | unreg_master: |
657 | destroy_workqueue(mpc83xx_spi->workqueue); | 643 | destroy_workqueue(mpc83xx_spi->workqueue); |
@@ -661,18 +647,16 @@ unmap_io: | |||
661 | iounmap(mpc83xx_spi->base); | 647 | iounmap(mpc83xx_spi->base); |
662 | put_master: | 648 | put_master: |
663 | spi_master_put(master); | 649 | spi_master_put(master); |
664 | free_master: | ||
665 | kfree(master); | ||
666 | err: | 650 | err: |
667 | return ret; | 651 | return ERR_PTR(ret); |
668 | } | 652 | } |
669 | 653 | ||
670 | static int __exit mpc83xx_spi_remove(struct platform_device *dev) | 654 | static int __devexit mpc83xx_spi_remove(struct device *dev) |
671 | { | 655 | { |
672 | struct mpc83xx_spi *mpc83xx_spi; | 656 | struct mpc83xx_spi *mpc83xx_spi; |
673 | struct spi_master *master; | 657 | struct spi_master *master; |
674 | 658 | ||
675 | master = platform_get_drvdata(dev); | 659 | master = dev_get_drvdata(dev); |
676 | mpc83xx_spi = spi_master_get_devdata(master); | 660 | mpc83xx_spi = spi_master_get_devdata(master); |
677 | 661 | ||
678 | flush_workqueue(mpc83xx_spi->workqueue); | 662 | flush_workqueue(mpc83xx_spi->workqueue); |
@@ -685,23 +669,293 @@ static int __exit mpc83xx_spi_remove(struct platform_device *dev) | |||
685 | return 0; | 669 | return 0; |
686 | } | 670 | } |
687 | 671 | ||
672 | struct mpc83xx_spi_probe_info { | ||
673 | struct fsl_spi_platform_data pdata; | ||
674 | int *gpios; | ||
675 | bool *alow_flags; | ||
676 | }; | ||
677 | |||
678 | static struct mpc83xx_spi_probe_info * | ||
679 | to_of_pinfo(struct fsl_spi_platform_data *pdata) | ||
680 | { | ||
681 | return container_of(pdata, struct mpc83xx_spi_probe_info, pdata); | ||
682 | } | ||
683 | |||
684 | static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on) | ||
685 | { | ||
686 | struct device *dev = spi->dev.parent; | ||
687 | struct mpc83xx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data); | ||
688 | u16 cs = spi->chip_select; | ||
689 | int gpio = pinfo->gpios[cs]; | ||
690 | bool alow = pinfo->alow_flags[cs]; | ||
691 | |||
692 | gpio_set_value(gpio, on ^ alow); | ||
693 | } | ||
694 | |||
695 | static int of_mpc83xx_spi_get_chipselects(struct device *dev) | ||
696 | { | ||
697 | struct device_node *np = dev_archdata_get_node(&dev->archdata); | ||
698 | struct fsl_spi_platform_data *pdata = dev->platform_data; | ||
699 | struct mpc83xx_spi_probe_info *pinfo = to_of_pinfo(pdata); | ||
700 | unsigned int ngpios; | ||
701 | int i = 0; | ||
702 | int ret; | ||
703 | |||
704 | ngpios = of_gpio_count(np); | ||
705 | if (!ngpios) { | ||
706 | /* | ||
707 | * SPI w/o chip-select line. One SPI device is still permitted | ||
708 | * though. | ||
709 | */ | ||
710 | pdata->max_chipselect = 1; | ||
711 | return 0; | ||
712 | } | ||
713 | |||
714 | pinfo->gpios = kmalloc(ngpios * sizeof(pinfo->gpios), GFP_KERNEL); | ||
715 | if (!pinfo->gpios) | ||
716 | return -ENOMEM; | ||
717 | memset(pinfo->gpios, -1, ngpios * sizeof(pinfo->gpios)); | ||
718 | |||
719 | pinfo->alow_flags = kzalloc(ngpios * sizeof(pinfo->alow_flags), | ||
720 | GFP_KERNEL); | ||
721 | if (!pinfo->alow_flags) { | ||
722 | ret = -ENOMEM; | ||
723 | goto err_alloc_flags; | ||
724 | } | ||
725 | |||
726 | for (; i < ngpios; i++) { | ||
727 | int gpio; | ||
728 | enum of_gpio_flags flags; | ||
729 | |||
730 | gpio = of_get_gpio_flags(np, i, &flags); | ||
731 | if (!gpio_is_valid(gpio)) { | ||
732 | dev_err(dev, "invalid gpio #%d: %d\n", i, gpio); | ||
733 | goto err_loop; | ||
734 | } | ||
735 | |||
736 | ret = gpio_request(gpio, dev_name(dev)); | ||
737 | if (ret) { | ||
738 | dev_err(dev, "can't request gpio #%d: %d\n", i, ret); | ||
739 | goto err_loop; | ||
740 | } | ||
741 | |||
742 | pinfo->gpios[i] = gpio; | ||
743 | pinfo->alow_flags[i] = flags & OF_GPIO_ACTIVE_LOW; | ||
744 | |||
745 | ret = gpio_direction_output(pinfo->gpios[i], | ||
746 | pinfo->alow_flags[i]); | ||
747 | if (ret) { | ||
748 | dev_err(dev, "can't set output direction for gpio " | ||
749 | "#%d: %d\n", i, ret); | ||
750 | goto err_loop; | ||
751 | } | ||
752 | } | ||
753 | |||
754 | pdata->max_chipselect = ngpios; | ||
755 | pdata->cs_control = mpc83xx_spi_cs_control; | ||
756 | |||
757 | return 0; | ||
758 | |||
759 | err_loop: | ||
760 | while (i >= 0) { | ||
761 | if (gpio_is_valid(pinfo->gpios[i])) | ||
762 | gpio_free(pinfo->gpios[i]); | ||
763 | i--; | ||
764 | } | ||
765 | |||
766 | kfree(pinfo->alow_flags); | ||
767 | pinfo->alow_flags = NULL; | ||
768 | err_alloc_flags: | ||
769 | kfree(pinfo->gpios); | ||
770 | pinfo->gpios = NULL; | ||
771 | return ret; | ||
772 | } | ||
773 | |||
774 | static int of_mpc83xx_spi_free_chipselects(struct device *dev) | ||
775 | { | ||
776 | struct fsl_spi_platform_data *pdata = dev->platform_data; | ||
777 | struct mpc83xx_spi_probe_info *pinfo = to_of_pinfo(pdata); | ||
778 | int i; | ||
779 | |||
780 | if (!pinfo->gpios) | ||
781 | return 0; | ||
782 | |||
783 | for (i = 0; i < pdata->max_chipselect; i++) { | ||
784 | if (gpio_is_valid(pinfo->gpios[i])) | ||
785 | gpio_free(pinfo->gpios[i]); | ||
786 | } | ||
787 | |||
788 | kfree(pinfo->gpios); | ||
789 | kfree(pinfo->alow_flags); | ||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int __devinit of_mpc83xx_spi_probe(struct of_device *ofdev, | ||
794 | const struct of_device_id *ofid) | ||
795 | { | ||
796 | struct device *dev = &ofdev->dev; | ||
797 | struct device_node *np = ofdev->node; | ||
798 | struct mpc83xx_spi_probe_info *pinfo; | ||
799 | struct fsl_spi_platform_data *pdata; | ||
800 | struct spi_master *master; | ||
801 | struct resource mem; | ||
802 | struct resource irq; | ||
803 | const void *prop; | ||
804 | int ret = -ENOMEM; | ||
805 | |||
806 | pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); | ||
807 | if (!pinfo) | ||
808 | return -ENOMEM; | ||
809 | |||
810 | pdata = &pinfo->pdata; | ||
811 | dev->platform_data = pdata; | ||
812 | |||
813 | /* Allocate bus num dynamically. */ | ||
814 | pdata->bus_num = -1; | ||
815 | |||
816 | /* SPI controller is either clocked from QE or SoC clock. */ | ||
817 | pdata->sysclk = get_brgfreq(); | ||
818 | if (pdata->sysclk == -1) { | ||
819 | pdata->sysclk = fsl_get_sys_freq(); | ||
820 | if (pdata->sysclk == -1) { | ||
821 | ret = -ENODEV; | ||
822 | goto err_clk; | ||
823 | } | ||
824 | } | ||
825 | |||
826 | prop = of_get_property(np, "mode", NULL); | ||
827 | if (prop && !strcmp(prop, "cpu-qe")) | ||
828 | pdata->qe_mode = 1; | ||
829 | |||
830 | ret = of_mpc83xx_spi_get_chipselects(dev); | ||
831 | if (ret) | ||
832 | goto err; | ||
833 | |||
834 | ret = of_address_to_resource(np, 0, &mem); | ||
835 | if (ret) | ||
836 | goto err; | ||
837 | |||
838 | ret = of_irq_to_resource(np, 0, &irq); | ||
839 | if (!ret) { | ||
840 | ret = -EINVAL; | ||
841 | goto err; | ||
842 | } | ||
843 | |||
844 | master = mpc83xx_spi_probe(dev, &mem, irq.start); | ||
845 | if (IS_ERR(master)) { | ||
846 | ret = PTR_ERR(master); | ||
847 | goto err; | ||
848 | } | ||
849 | |||
850 | of_register_spi_devices(master, np); | ||
851 | |||
852 | return 0; | ||
853 | |||
854 | err: | ||
855 | of_mpc83xx_spi_free_chipselects(dev); | ||
856 | err_clk: | ||
857 | kfree(pinfo); | ||
858 | return ret; | ||
859 | } | ||
860 | |||
861 | static int __devexit of_mpc83xx_spi_remove(struct of_device *ofdev) | ||
862 | { | ||
863 | int ret; | ||
864 | |||
865 | ret = mpc83xx_spi_remove(&ofdev->dev); | ||
866 | if (ret) | ||
867 | return ret; | ||
868 | of_mpc83xx_spi_free_chipselects(&ofdev->dev); | ||
869 | return 0; | ||
870 | } | ||
871 | |||
872 | static const struct of_device_id of_mpc83xx_spi_match[] = { | ||
873 | { .compatible = "fsl,spi" }, | ||
874 | {}, | ||
875 | }; | ||
876 | MODULE_DEVICE_TABLE(of, of_mpc83xx_spi_match); | ||
877 | |||
878 | static struct of_platform_driver of_mpc83xx_spi_driver = { | ||
879 | .name = "mpc83xx_spi", | ||
880 | .match_table = of_mpc83xx_spi_match, | ||
881 | .probe = of_mpc83xx_spi_probe, | ||
882 | .remove = __devexit_p(of_mpc83xx_spi_remove), | ||
883 | }; | ||
884 | |||
885 | #ifdef CONFIG_MPC832x_RDB | ||
886 | /* | ||
887 | * XXX XXX XXX | ||
888 | * This is "legacy" platform driver, was used by the MPC8323E-RDB boards | ||
889 | * only. The driver should go away soon, since newer MPC8323E-RDB's device | ||
890 | * tree can work with OpenFirmware driver. But for now we support old trees | ||
891 | * as well. | ||
892 | */ | ||
893 | static int __devinit plat_mpc83xx_spi_probe(struct platform_device *pdev) | ||
894 | { | ||
895 | struct resource *mem; | ||
896 | unsigned int irq; | ||
897 | struct spi_master *master; | ||
898 | |||
899 | if (!pdev->dev.platform_data) | ||
900 | return -EINVAL; | ||
901 | |||
902 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
903 | if (!mem) | ||
904 | return -EINVAL; | ||
905 | |||
906 | irq = platform_get_irq(pdev, 0); | ||
907 | if (!irq) | ||
908 | return -EINVAL; | ||
909 | |||
910 | master = mpc83xx_spi_probe(&pdev->dev, mem, irq); | ||
911 | if (IS_ERR(master)) | ||
912 | return PTR_ERR(master); | ||
913 | return 0; | ||
914 | } | ||
915 | |||
916 | static int __devexit plat_mpc83xx_spi_remove(struct platform_device *pdev) | ||
917 | { | ||
918 | return mpc83xx_spi_remove(&pdev->dev); | ||
919 | } | ||
920 | |||
688 | MODULE_ALIAS("platform:mpc83xx_spi"); | 921 | MODULE_ALIAS("platform:mpc83xx_spi"); |
689 | static struct platform_driver mpc83xx_spi_driver = { | 922 | static struct platform_driver mpc83xx_spi_driver = { |
690 | .remove = __exit_p(mpc83xx_spi_remove), | 923 | .probe = plat_mpc83xx_spi_probe, |
924 | .remove = __exit_p(plat_mpc83xx_spi_remove), | ||
691 | .driver = { | 925 | .driver = { |
692 | .name = "mpc83xx_spi", | 926 | .name = "mpc83xx_spi", |
693 | .owner = THIS_MODULE, | 927 | .owner = THIS_MODULE, |
694 | }, | 928 | }, |
695 | }; | 929 | }; |
696 | 930 | ||
931 | static bool legacy_driver_failed; | ||
932 | |||
933 | static void __init legacy_driver_register(void) | ||
934 | { | ||
935 | legacy_driver_failed = platform_driver_register(&mpc83xx_spi_driver); | ||
936 | } | ||
937 | |||
938 | static void __exit legacy_driver_unregister(void) | ||
939 | { | ||
940 | if (legacy_driver_failed) | ||
941 | return; | ||
942 | platform_driver_unregister(&mpc83xx_spi_driver); | ||
943 | } | ||
944 | #else | ||
945 | static void __init legacy_driver_register(void) {} | ||
946 | static void __exit legacy_driver_unregister(void) {} | ||
947 | #endif /* CONFIG_MPC832x_RDB */ | ||
948 | |||
697 | static int __init mpc83xx_spi_init(void) | 949 | static int __init mpc83xx_spi_init(void) |
698 | { | 950 | { |
699 | return platform_driver_probe(&mpc83xx_spi_driver, mpc83xx_spi_probe); | 951 | legacy_driver_register(); |
952 | return of_register_platform_driver(&of_mpc83xx_spi_driver); | ||
700 | } | 953 | } |
701 | 954 | ||
702 | static void __exit mpc83xx_spi_exit(void) | 955 | static void __exit mpc83xx_spi_exit(void) |
703 | { | 956 | { |
704 | platform_driver_unregister(&mpc83xx_spi_driver); | 957 | of_unregister_platform_driver(&of_mpc83xx_spi_driver); |
958 | legacy_driver_unregister(); | ||
705 | } | 959 | } |
706 | 960 | ||
707 | module_init(mpc83xx_spi_init); | 961 | module_init(mpc83xx_spi_init); |