Hi jimmychan,
thanks for the response and the link.
I tried it out, but it did not work in my case.
I also tried to debug in the spi-imx.c driver, making a lot of printks in it.
One, where I moved the gpio-requesting block of code in spi_imx_probe
to a spot before bitbang_start and one after.
See the one with the switch below:
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 91e32291c44e..4a9c27415009 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1553,7 +1553,7 @@ static int spi_imx_transfer(struct spi_device *spi,
static int spi_imx_setup(struct spi_device *spi)
{
- dev_dbg(&spi->dev, "%s: mode %d, %u bpw, %d hz\n", __func__,
+ printk("spi-imx %s: mode %d, %u bpw, %d hz\n", __func__,
spi->mode, spi->bits_per_word, spi->max_speed_hz);
if (spi->mode & SPI_NO_CS)
@@ -1632,6 +1632,7 @@ static int spi_imx_probe(struct platform_device *pdev)
(struct spi_imx_devtype_data *)pdev->id_entry->driver_data;
bool slave_mode;
+ printk("spi-imx probe called\n");
if (!np && !mxc_platform_info) {
dev_err(&pdev->dev, "can't get the platform data\n");
return -EINVAL;
@@ -1663,11 +1664,14 @@ static int spi_imx_probe(struct platform_device *pdev)
spi_imx->bitbang.master = master;
spi_imx->dev = &pdev->dev;
spi_imx->slave_mode = slave_mode;
+ printk("spi-imx slave-mode=%d\n", slave_mode);
spi_imx->devtype_data = devtype_data;
+ printk("spi-imx getting chip select\n");
/* Get number of chip selects, either platform data or OF */
if (mxc_platform_info) {
+ printk("spi-imx mxc platform inf is valid, getting chipselect\n");
master->num_chipselect = mxc_platform_info->num_chipselect;
if (mxc_platform_info->chipselect) {
master->cs_gpios = devm_kcalloc(&master->dev,
@@ -1681,9 +1685,11 @@ static int spi_imx_probe(struct platform_device *pdev)
}
} else {
u32 num_cs;
-
- if (!of_property_read_u32(np, "num-cs", &num_cs))
+ printk("spi-imx mxc platform info is invalid, getting cs of dts\n");
+ if (!of_property_read_u32(np, "num-cs", &num_cs)){
+ printk("spi-imx num-cs=%d", num_cs);
master->num_chipselect = num_cs;
+ }
/* If not preset, default value of 1 is used */
}
@@ -1704,6 +1710,7 @@ static int spi_imx_probe(struct platform_device *pdev)
spi_imx->spi_drctl = spi_drctl;
init_completion(&spi_imx->xfer_done);
+ printk("spi-imx init_completion done\n");
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
spi_imx->base = devm_ioremap_resource(&pdev->dev, res);
@@ -1766,14 +1773,11 @@ static int spi_imx_probe(struct platform_device *pdev)
spi_imx->devtype_data->intctrl(spi_imx, 0);
master->dev.of_node = pdev->dev.of_node;
- ret = spi_bitbang_start(&spi_imx->bitbang);
- if (ret) {
- dev_err(&pdev->dev, "bitbang start failed with %d\n", ret);
- goto out_clk_put;
- }
/* Request GPIO CS lines, if any */
+ printk("spi-imx request gpio cs lines\n");
if (!spi_imx->slave_mode && master->cs_gpios) {
+ printk("spi-imx go through chip selects\n");
for (i = 0; i < master->num_chipselect; i++) {
if (!gpio_is_valid(master->cs_gpios[i]))
continue;
@@ -1788,6 +1792,26 @@ static int spi_imx_probe(struct platform_device *pdev)
}
}
}
+ else{
+ printk("spi-imx slave mode on or master cs gpios unvalid\n");
+ printk("master->num_chipselect=%d\n", master->num_chipselect);
+ if(!spi_imx->slave_mode)
+ printk("spi-imx slave mode is off");
+ else
+ printk("spi-imx slave mode is on");
+ if(master->cs_gpios)
+ printk("master-cs-gpios are valid");
+ else
+ printk("master cs-gpios are not valid");
+ }
+
+ printk("spi-imx starting bitbang\n");
+ ret = spi_bitbang_start(&spi_imx->bitbang);
+ if (ret) {
+ dev_err(&pdev->dev, "bitbang start failed with %d\n", ret);
+ goto out_clk_put;
+ }
+
dev_info(&pdev->dev, "probed\n");
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 26b91ee0855d..bc451b0ab265 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -775,6 +775,7 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
static void spi_set_cs(struct spi_device *spi, bool enable)
{
+ printk("spi_set_cs called\n");
if (spi->mode & SPI_CS_HIGH)
enable = !enable;
@@ -2245,10 +2246,12 @@ static int of_spi_get_gpio_numbers(struct spi_controller *ctlr)
int nb, i, *cs;
struct device_node *np = ctlr->dev.of_node;
+ printk("of_spi_get_gpio_numbers called\n");
if (!np)
return 0;
nb = of_gpio_named_count(np, "cs-gpios");
+ printk("of_spi_get_gpio_numbers nb=%d\n", nb);
ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect);
/* Return error only for an incorrectly formed cs-gpios property */
@@ -2267,8 +2270,10 @@ static int of_spi_get_gpio_numbers(struct spi_controller *ctlr)
for (i = 0; i < ctlr->num_chipselect; i++)
cs[i] = -ENOENT;
- for (i = 0; i < nb; i++)
+ for (i = 0; i < nb; i++){
+ printk("of_spi getting named gpios\n");
cs[i] = of_get_named_gpio(np, "cs-gpios", i);
+ }
return 0;
}
@@ -2385,6 +2390,7 @@ int spi_register_controller(struct spi_controller *ctlr)
int status;
int id, first_dynamic;
+ printk("spi register controller called\n");
if (!dev)
return -ENODEV;
--
2.17.1
When I start the Board and check the seriel output, I already see, that moving the gpio request to another place, is (if I understand that correctly) not the right option.
The output with the switch:
[ 0.964689] spi-imx probe called
[ 0.967935] spi-imx slave-mode=0
[ 0.971168] spi-imx getting chip select
[ 0.975008] spi-imx mxc platform info is invalid, getting cs of dts
[ 0.981279] spi-imx init_completion done
[ 0.985317] spi-imx request gpio cs lines
[ 0.989333] spi-imx slave mode on or master cs gpios unvalid
[ 0.994998] master->num_chipselect=1
[ 0.998577] spi-imx slave mode is off
[ 0.998579] master cs-gpios are not valid
[ 1.002244] spi-imx starting bitbang
[ 1.009835] spi register controller called
[ 1.013945] of_spi_get_gpio_numbers called
[ 1.018049] of_spi_get_gpio_numbers nb=1
[ 1.021976] of_spi getting named gpios
[ 1.025935] spi-imx spi_imx_setup: mode 4, 8 bpw, 10000000 hz
[ 1.031736] spi_set_cs called
[ 1.034843] ------------[ cut here ]------------
[ 1.039470] /soc@0/bus@30800000/spi@30830000/spidev@0x00: buggy DT: spidev listed directly in DT
[ 1.048300] WARNING: CPU: 0 PID: 1 at drivers/spi/spidev.c:723 spidev_probe+0x104/0x220
[ 1.056300] Modules linked in:
[ 1.059358] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.3-lts-lf-5.4.y+gf8118585ee3c #1
[ 1.067531] Hardware name: NXP i.MX8MNano DDR4 EVK board (DT)
[ 1.073275] pstate: 60000005 (nZCv daif -PAN -UAO)
[ 1.078064] pc : spidev_probe+0x104/0x220
[ 1.082071] lr : spidev_probe+0x104/0x220
[ 1.086077] sp : ffff80001003b7d0
[ 1.089389] x29: ffff80001003b7d0 x28: 0000000000000001
[ 1.094700] x27: ffff000078aedb80 x26: ffff800011923330
[ 1.100010] x25: 0000000000000000 x24: 0000000000000000
[ 1.105320] x23: ffff800011932e60 x22: 0000000000000000
[ 1.110631] x21: ffff800011932e40 x20: ffff00007868c800
[ 1.115941] x19: 0000000000000000 x18: 0000000000000010
[ 1.121252] x17: 00000000fd12cf85 x16: ffff000078006510
[ 1.126562] x15: ffff000078090470 x14: 6c20766564697073
[ 1.131873] x13: 203a544420796767 x12: 7562203a30307830
[ 1.137183] x11: 407665646970732f x10: 3030303033383033
[ 1.142493] x9 : 406970732f303030 x8 : ffff8000119e3000
[ 1.147804] x7 : ffff80001067f5e8 x6 : 00000000000000d3
[ 1.153114] x5 : 0000000000000000 x4 : 0000000000000000
[ 1.158424] x3 : 00000000ffffffff x2 : ffff8000118d1520
[ 1.163734] x1 : 77bee9e389fa8f00 x0 : 0000000000000000
[ 1.169044] Call trace:
[ 1.171490] spidev_probe+0x104/0x220
[ 1.175152] spi_drv_probe+0x7c/0xd8
[ 1.178728] really_probe+0xd4/0x308
[ 1.182303] driver_probe_device+0x54/0xe8
[ 1.186399] __device_attach_driver+0x80/0xb8
[ 1.190755] bus_for_each_drv+0x74/0xc0
[ 1.194589] __device_attach+0xdc/0x138
[ 1.198424] device_initial_probe+0x10/0x18
[ 1.202605] bus_probe_device+0x90/0x98
[ 1.206440] device_add+0x378/0x648
[ 1.209927] spi_add_device+0xe4/0x1c8
[ 1.213675] of_register_spi_device+0x204/0x3c8
[ 1.218204] spi_register_controller+0x664/0x74c
[ 1.222819] spi_bitbang_start+0x34/0x80
[ 1.226741] spi_imx_probe+0x608/0x6f0
[ 1.230489] platform_drv_probe+0x50/0xa0
[ 1.234498] really_probe+0xd4/0x308
[ 1.238072] driver_probe_device+0x54/0xe8
[ 1.242167] device_driver_attach+0x6c/0x78
[ 1.246349] __driver_attach+0x54/0xd0
[ 1.250097] bus_for_each_dev+0x6c/0xc0
[ 1.253931] driver_attach+0x20/0x28
[ 1.257506] bus_add_driver+0x140/0x1e8
[ 1.261340] driver_register+0x60/0x110
[ 1.265174] __platform_driver_register+0x44/0x50
[ 1.269879] spi_imx_driver_init+0x1c/0x24
[ 1.273975] do_one_initcall+0x50/0x190
[ 1.277811] kernel_init_freeable+0x194/0x22c
[ 1.282168] kernel_init+0x10/0x100
[ 1.285655] ret_from_fork+0x10/0x18
[ 1.289232] ---[ end trace de09230545766b9c ]---
[ 1.293994] spi_imx 30830000.spi: probed
the output without it:
[ 0.965239] spi-imx probe called
[ 0.968486] spi-imx slave-mode=0
[ 0.971719] spi-imx getting chip select
[ 0.975558] spi-imx mxc platform info is invalid, getting cs of dts
[ 0.981829] spi-imx init_completion done
[ 0.985870] spi-imx spi bitbang start
[ 0.989540] spi register controller called
[ 0.993649] of_spi_get_gpio_numbers called
[ 0.997752] of_spi_get_gpio_numbers nb=1
[ 1.001682] of_spi getting named gpios
[ 1.005641] spi-imx spi_imx_setup: mode 0, 8 bpw, 10000000 hz
[ 1.011405] spi_set_cs called
[ 1.014504] ------------[ cut here ]------------
[ 1.019131] /soc@0/bus@30800000/spi@30830000/spidev@0x00: buggy DT: spidev listed directly in DT
[ 1.027963] WARNING: CPU: 3 PID: 1 at drivers/spi/spidev.c:723 spidev_probe+0x104/0x220
[ 1.035963] Modules linked in:
[ 1.039020] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.4.3-lts-lf-5.4.y+gf8118585ee3c #1
[ 1.047193] Hardware name: NXP i.MX8MNano DDR4 EVK board (DT)
[ 1.052937] pstate: 60000005 (nZCv daif -PAN -UAO)
[ 1.057726] pc : spidev_probe+0x104/0x220
[ 1.061734] lr : spidev_probe+0x104/0x220
[ 1.065739] sp : ffff80001003b7d0
[ 1.069051] x29: ffff80001003b7d0 x28: 0000000000000001
[ 1.074362] x27: ffff000078b88080 x26: ffff800011923330
[ 1.079673] x25: 0000000000000000 x24: 0000000000000000
[ 1.084983] x23: ffff800011932e60 x22: 0000000000000000
[ 1.090294] x21: ffff800011932e40 x20: ffff000078385000
[ 1.095604] x19: 0000000000000000 x18: 0000000000000010
[ 1.100914] x17: 0000000000000001 x16: 0000000000000019
[ 1.106224] x15: ffff000078090470 x14: 6c20766564697073
[ 1.111534] x13: 203a544420796767 x12: 7562203a30307830
[ 1.116845] x11: 407665646970732f x10: 3030303033383033
[ 1.122155] x9 : 406970732f303030 x8 : ffff8000119e3000
[ 1.127465] x7 : ffff80001067f5e8 x6 : 00000000000000ce
[ 1.132776] x5 : 0000000000000000 x4 : 0000000000000000
[ 1.138086] x3 : 00000000ffffffff x2 : ffff8000118d1520
[ 1.143396] x1 : 9586de38223a3d00 x0 : 0000000000000000
[ 1.148706] Call trace:
[ 1.151152] spidev_probe+0x104/0x220
[ 1.154814] spi_drv_probe+0x7c/0xd8
[ 1.158390] really_probe+0xd4/0x308
[ 1.161965] driver_probe_device+0x54/0xe8
[ 1.166060] __device_attach_driver+0x80/0xb8
[ 1.170417] bus_for_each_drv+0x74/0xc0
[ 1.174252] __device_attach+0xdc/0x138
[ 1.178087] device_initial_probe+0x10/0x18
[ 1.182269] bus_probe_device+0x90/0x98
[ 1.186103] device_add+0x378/0x648
[ 1.189591] spi_add_device+0xe4/0x1c8
[ 1.193339] of_register_spi_device+0x204/0x3c8
[ 1.197869] spi_register_controller+0x664/0x74c
[ 1.202484] spi_bitbang_start+0x34/0x80
[ 1.206407] spi_imx_probe+0x500/0x6f8
[ 1.210155] platform_drv_probe+0x50/0xa0
[ 1.214163] really_probe+0xd4/0x308
[ 1.217737] driver_probe_device+0x54/0xe8
[ 1.221832] device_driver_attach+0x6c/0x78
[ 1.226014] __driver_attach+0x54/0xd0
[ 1.229762] bus_for_each_dev+0x6c/0xc0
[ 1.233597] driver_attach+0x20/0x28
[ 1.237171] bus_add_driver+0x140/0x1e8
[ 1.241005] driver_register+0x60/0x110
[ 1.244839] __platform_driver_register+0x44/0x50
[ 1.249544] spi_imx_driver_init+0x1c/0x24
[ 1.253640] do_one_initcall+0x50/0x190
[ 1.257476] kernel_init_freeable+0x194/0x22c
[ 1.261833] kernel_init+0x10/0x100
[ 1.265320] ret_from_fork+0x10/0x18
[ 1.268898] ---[ end trace b6ad49a34d072e58 ]---
[ 1.273651] spi-imx request gpio cs lines
[ 1.277667] spi-imx go through chip selects
[ 1.281860] spi_imx 30830000.spi: probed
sorry, it is not pretty and the english is bad.
the thing is, that when I switch the place for the gpio_request, there are no master->cs_gpios created and the function
if (!spi_imx->slave_mode && master->cs_gpios) {
will always be evaluated as "no"
In both cases, the CS is not toggled. It remains low infinitely.
I will try to reproduce the behaviour with another board and let you know, if I find out anything.