spi-fsl-spi.c (8922a366ddd20964e3542e12f0315a8a88b3a638) spi-fsl-spi.c (447b0c7b939f1d9e4024edf07a471ce7b1bcf002)
1/*
2 * Freescale SPI controller driver.
3 *
4 * Maintainer: Kumar Gala
5 *
6 * Copyright (C) 2006 Polycom, Inc.
7 * Copyright 2010 Freescale Semiconductor, Inc.
8 *
9 * CPM SPI and QE buffer descriptors mode support:
10 * Copyright (c) 2009 MontaVista Software, Inc.
11 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
12 *
1/*
2 * Freescale SPI controller driver.
3 *
4 * Maintainer: Kumar Gala
5 *
6 * Copyright (C) 2006 Polycom, Inc.
7 * Copyright 2010 Freescale Semiconductor, Inc.
8 *
9 * CPM SPI and QE buffer descriptors mode support:
10 * Copyright (c) 2009 MontaVista Software, Inc.
11 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
12 *
13 * GRLIB support:
14 * Copyright (c) 2012 Aeroflex Gaisler AB.
15 * Author: Andreas Larsson <andreas@gaisler.com>
16 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18#include <linux/module.h>
19#include <linux/types.h>
20#include <linux/kernel.h>

--- 14 unchanged lines hidden (view full) ---

35#include <linux/gpio.h>
36#include <linux/of_gpio.h>
37
38#include "spi-fsl-lib.h"
39#include "spi-fsl-cpm.h"
40#include "spi-fsl-spi.h"
41
42#define TYPE_FSL 0
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 2 of the License, or (at your
20 * option) any later version.
21 */
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/kernel.h>

--- 14 unchanged lines hidden (view full) ---

39#include <linux/gpio.h>
40#include <linux/of_gpio.h>
41
42#include "spi-fsl-lib.h"
43#include "spi-fsl-cpm.h"
44#include "spi-fsl-spi.h"
45
46#define TYPE_FSL 0
47#define TYPE_GRLIB 1
43
44struct fsl_spi_match_data {
45 int type;
46};
47
48static struct fsl_spi_match_data of_fsl_spi_fsl_config = {
49 .type = TYPE_FSL,
50};
51
48
49struct fsl_spi_match_data {
50 int type;
51};
52
53static struct fsl_spi_match_data of_fsl_spi_fsl_config = {
54 .type = TYPE_FSL,
55};
56
57static struct fsl_spi_match_data of_fsl_spi_grlib_config = {
58 .type = TYPE_GRLIB,
59};
60
52static struct of_device_id of_fsl_spi_match[] = {
53 {
54 .compatible = "fsl,spi",
55 .data = &of_fsl_spi_fsl_config,
56 },
61static struct of_device_id of_fsl_spi_match[] = {
62 {
63 .compatible = "fsl,spi",
64 .data = &of_fsl_spi_fsl_config,
65 },
66 {
67 .compatible = "aeroflexgaisler,spictrl",
68 .data = &of_fsl_spi_grlib_config,
69 },
57 {}
58};
59MODULE_DEVICE_TABLE(of, of_fsl_spi_match);
60
61static int fsl_spi_get_type(struct device *dev)
62{
63 const struct of_device_id *match;
64

--- 71 unchanged lines hidden (view full) ---

136 *tx_shift = 16;
137 }
138 } else {
139 if (bits_per_word <= 8)
140 *rx_shift = 8;
141 }
142}
143
70 {}
71};
72MODULE_DEVICE_TABLE(of, of_fsl_spi_match);
73
74static int fsl_spi_get_type(struct device *dev)
75{
76 const struct of_device_id *match;
77

--- 71 unchanged lines hidden (view full) ---

149 *tx_shift = 16;
150 }
151 } else {
152 if (bits_per_word <= 8)
153 *rx_shift = 8;
154 }
155}
156
157static void fsl_spi_grlib_set_shifts(u32 *rx_shift, u32 *tx_shift,
158 int bits_per_word, int msb_first)
159{
160 *rx_shift = 0;
161 *tx_shift = 0;
162 if (bits_per_word <= 16) {
163 if (msb_first) {
164 *rx_shift = 16; /* LSB in bit 16 */
165 *tx_shift = 32 - bits_per_word; /* MSB in bit 31 */
166 } else {
167 *rx_shift = 16 - bits_per_word; /* MSB in bit 15 */
168 }
169 }
170}
171
144static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs,
145 struct spi_device *spi,
146 struct mpc8xxx_spi *mpc8xxx_spi,
147 int bits_per_word)
148{
149 cs->rx_shift = 0;
150 cs->tx_shift = 0;
151 if (bits_per_word <= 8) {

--- 337 unchanged lines hidden (view full) ---

489}
490
491static void fsl_spi_remove(struct mpc8xxx_spi *mspi)
492{
493 iounmap(mspi->reg_base);
494 fsl_spi_cpm_free(mspi);
495}
496
172static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs,
173 struct spi_device *spi,
174 struct mpc8xxx_spi *mpc8xxx_spi,
175 int bits_per_word)
176{
177 cs->rx_shift = 0;
178 cs->tx_shift = 0;
179 if (bits_per_word <= 8) {

--- 337 unchanged lines hidden (view full) ---

517}
518
519static void fsl_spi_remove(struct mpc8xxx_spi *mspi)
520{
521 iounmap(mspi->reg_base);
522 fsl_spi_cpm_free(mspi);
523}
524
525static void fsl_spi_grlib_cs_control(struct spi_device *spi, bool on)
526{
527 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
528 struct fsl_spi_reg *reg_base = mpc8xxx_spi->reg_base;
529 u32 slvsel;
530 u16 cs = spi->chip_select;
531
532 slvsel = mpc8xxx_spi_read_reg(&reg_base->slvsel);
533 slvsel = on ? (slvsel | (1 << cs)) : (slvsel & ~(1 << cs));
534 mpc8xxx_spi_write_reg(&reg_base->slvsel, slvsel);
535}
536
537static void fsl_spi_grlib_probe(struct device *dev)
538{
539 struct fsl_spi_platform_data *pdata = dev->platform_data;
540 struct spi_master *master = dev_get_drvdata(dev);
541 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master);
542 struct fsl_spi_reg *reg_base = mpc8xxx_spi->reg_base;
543 int mbits;
544 u32 capabilities;
545
546 capabilities = mpc8xxx_spi_read_reg(&reg_base->cap);
547
548 mpc8xxx_spi->set_shifts = fsl_spi_grlib_set_shifts;
549 mbits = SPCAP_MAXWLEN(capabilities);
550 if (mbits)
551 mpc8xxx_spi->max_bits_per_word = mbits + 1;
552
553 master->num_chipselect = 1; /* Allow for an always selected chip */
554 if (SPCAP_SSEN(capabilities)) {
555 master->num_chipselect = SPCAP_SSSZ(capabilities);
556 mpc8xxx_spi_write_reg(&reg_base->slvsel, 0xffffffff);
557 }
558 pdata->cs_control = fsl_spi_grlib_cs_control;
559}
560
497static struct spi_master * fsl_spi_probe(struct device *dev,
498 struct resource *mem, unsigned int irq)
499{
500 struct fsl_spi_platform_data *pdata = dev->platform_data;
501 struct spi_master *master;
502 struct mpc8xxx_spi *mpc8xxx_spi;
503 struct fsl_spi_reg *reg_base;
504 u32 regval;

--- 18 unchanged lines hidden (view full) ---

523 mpc8xxx_spi->spi_remove = fsl_spi_remove;
524 mpc8xxx_spi->max_bits_per_word = 32;
525 mpc8xxx_spi->type = fsl_spi_get_type(dev);
526
527 ret = fsl_spi_cpm_init(mpc8xxx_spi);
528 if (ret)
529 goto err_cpm_init;
530
561static struct spi_master * fsl_spi_probe(struct device *dev,
562 struct resource *mem, unsigned int irq)
563{
564 struct fsl_spi_platform_data *pdata = dev->platform_data;
565 struct spi_master *master;
566 struct mpc8xxx_spi *mpc8xxx_spi;
567 struct fsl_spi_reg *reg_base;
568 u32 regval;

--- 18 unchanged lines hidden (view full) ---

587 mpc8xxx_spi->spi_remove = fsl_spi_remove;
588 mpc8xxx_spi->max_bits_per_word = 32;
589 mpc8xxx_spi->type = fsl_spi_get_type(dev);
590
591 ret = fsl_spi_cpm_init(mpc8xxx_spi);
592 if (ret)
593 goto err_cpm_init;
594
595 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
596 if (mpc8xxx_spi->reg_base == NULL) {
597 ret = -ENOMEM;
598 goto err_ioremap;
599 }
600
601 if (mpc8xxx_spi->type == TYPE_GRLIB)
602 fsl_spi_grlib_probe(dev);
603
531 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)
532 mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts;
533
534 if (mpc8xxx_spi->set_shifts)
535 /* 8 bits per word and MSB first */
536 mpc8xxx_spi->set_shifts(&mpc8xxx_spi->rx_shift,
537 &mpc8xxx_spi->tx_shift, 8, 1);
538
604 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)
605 mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts;
606
607 if (mpc8xxx_spi->set_shifts)
608 /* 8 bits per word and MSB first */
609 mpc8xxx_spi->set_shifts(&mpc8xxx_spi->rx_shift,
610 &mpc8xxx_spi->tx_shift, 8, 1);
611
539 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
540 if (mpc8xxx_spi->reg_base == NULL) {
541 ret = -ENOMEM;
542 goto err_ioremap;
543 }
544
545 /* Register for SPI Interrupt */
546 ret = request_irq(mpc8xxx_spi->irq, fsl_spi_irq,
547 0, "fsl_spi", mpc8xxx_spi);
548
549 if (ret != 0)
550 goto free_irq;
551
552 reg_base = mpc8xxx_spi->reg_base;

--- 148 unchanged lines hidden (view full) ---

701}
702
703static int of_fsl_spi_probe(struct platform_device *ofdev)
704{
705 struct device *dev = &ofdev->dev;
706 struct device_node *np = ofdev->dev.of_node;
707 struct spi_master *master;
708 struct resource mem;
612 /* Register for SPI Interrupt */
613 ret = request_irq(mpc8xxx_spi->irq, fsl_spi_irq,
614 0, "fsl_spi", mpc8xxx_spi);
615
616 if (ret != 0)
617 goto free_irq;
618
619 reg_base = mpc8xxx_spi->reg_base;

--- 148 unchanged lines hidden (view full) ---

768}
769
770static int of_fsl_spi_probe(struct platform_device *ofdev)
771{
772 struct device *dev = &ofdev->dev;
773 struct device_node *np = ofdev->dev.of_node;
774 struct spi_master *master;
775 struct resource mem;
709 int irq;
776 int irq, type;
710 int ret = -ENOMEM;
711
712 ret = of_mpc8xxx_spi_probe(ofdev);
713 if (ret)
714 return ret;
715
777 int ret = -ENOMEM;
778
779 ret = of_mpc8xxx_spi_probe(ofdev);
780 if (ret)
781 return ret;
782
716 ret = of_fsl_spi_get_chipselects(dev);
717 if (ret)
718 goto err;
783 type = fsl_spi_get_type(&ofdev->dev);
784 if (type == TYPE_FSL) {
785 ret = of_fsl_spi_get_chipselects(dev);
786 if (ret)
787 goto err;
788 }
719
720 ret = of_address_to_resource(np, 0, &mem);
721 if (ret)
722 goto err;
723
724 irq = irq_of_parse_and_map(np, 0);
725 if (!irq) {
726 ret = -EINVAL;

--- 4 unchanged lines hidden (view full) ---

731 if (IS_ERR(master)) {
732 ret = PTR_ERR(master);
733 goto err;
734 }
735
736 return 0;
737
738err:
789
790 ret = of_address_to_resource(np, 0, &mem);
791 if (ret)
792 goto err;
793
794 irq = irq_of_parse_and_map(np, 0);
795 if (!irq) {
796 ret = -EINVAL;

--- 4 unchanged lines hidden (view full) ---

801 if (IS_ERR(master)) {
802 ret = PTR_ERR(master);
803 goto err;
804 }
805
806 return 0;
807
808err:
739 of_fsl_spi_free_chipselects(dev);
809 if (type == TYPE_FSL)
810 of_fsl_spi_free_chipselects(dev);
740 return ret;
741}
742
743static int of_fsl_spi_remove(struct platform_device *ofdev)
744{
811 return ret;
812}
813
814static int of_fsl_spi_remove(struct platform_device *ofdev)
815{
816 struct spi_master *master = dev_get_drvdata(&ofdev->dev);
817 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master);
745 int ret;
746
747 ret = mpc8xxx_spi_remove(&ofdev->dev);
748 if (ret)
749 return ret;
818 int ret;
819
820 ret = mpc8xxx_spi_remove(&ofdev->dev);
821 if (ret)
822 return ret;
750 of_fsl_spi_free_chipselects(&ofdev->dev);
823 if (mpc8xxx_spi->type == TYPE_FSL)
824 of_fsl_spi_free_chipselects(&ofdev->dev);
751 return 0;
752}
753
754static struct platform_driver of_fsl_spi_driver = {
755 .driver = {
756 .name = "fsl_spi",
757 .owner = THIS_MODULE,
758 .of_match_table = of_fsl_spi_match,

--- 84 unchanged lines hidden ---
825 return 0;
826}
827
828static struct platform_driver of_fsl_spi_driver = {
829 .driver = {
830 .name = "fsl_spi",
831 .owner = THIS_MODULE,
832 .of_match_table = of_fsl_spi_match,

--- 84 unchanged lines hidden ---