summaryrefslogtreecommitdiffstats
path: root/drivers/spi/imx_spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/imx_spi.c')
-rw-r--r--drivers/spi/imx_spi.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index 80a14504f0..c3dc6cc863 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -11,10 +11,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
*
*/
@@ -24,6 +20,7 @@
#include <spi/spi.h>
#include <xfuncs.h>
#include <io.h>
+#include <errno.h>
#include <gpio.h>
#include <mach/spi.h>
#include <mach/generic.h>
@@ -495,6 +492,32 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
#endif
};
+static int imx_spi_dt_probe(struct imx_spi *imx)
+{
+ struct device_node *node = imx->master.dev->device_node;
+ int ret, i;
+ u32 num_cs;
+
+ if (!node)
+ return -ENODEV;
+
+ ret = of_property_read_u32(node, "fsl,spi-num-chipselects", &num_cs);
+ if (ret)
+ return ret;
+
+ imx->master.num_chipselect = num_cs;
+ imx->cs_array = xzalloc(sizeof(u32) * num_cs);
+
+ for (i = 0; i < num_cs; i++) {
+ int cs_gpio = of_get_named_gpio(node, "cs-gpios", i);
+ imx->cs_array[i] = cs_gpio;
+ }
+
+ spi_of_register_slaves(&imx->master, node);
+
+ return 0;
+}
+
static int imx_spi_probe(struct device_d *dev)
{
struct spi_master *master;
@@ -509,8 +532,13 @@ static int imx_spi_probe(struct device_d *dev)
master->setup = imx_spi_setup;
master->transfer = imx_spi_transfer;
- master->num_chipselect = pdata->num_chipselect;
- imx->cs_array = pdata->chipselect;
+ if (pdata) {
+ master->num_chipselect = pdata->num_chipselect;
+ imx->cs_array = pdata->chipselect;
+ } else {
+ if (IS_ENABLED(CONFIG_OFDEVICE))
+ imx_spi_dt_probe(imx);
+ }
#ifdef CONFIG_DRIVER_SPI_IMX_0_0
if (cpu_is_mx27())
@@ -536,9 +564,22 @@ static int imx_spi_probe(struct device_d *dev)
return 0;
}
+static __maybe_unused struct of_device_id imx_spi_dt_ids[] = {
+ {
+ .compatible = "fsl,imx27-cspi",
+ }, {
+ .compatible = "fsl,imx35-cspi",
+ }, {
+ .compatible = "fsl,imx51-ecspi",
+ }, {
+ /* sentinel */
+ }
+};
+
static struct driver_d imx_spi_driver = {
.name = "imx_spi",
.probe = imx_spi_probe,
+ .of_compatible = DRV_OF_COMPAT(imx_spi_dt_ids),
};
static int imx_spi_init(void)