Skip to contentSkip to conversation

fpga-manager: altera-ps-spi: enable usage on non-dt platforms

PATCH Superseded Anatolij Gustschin 2 participants 3 messages Feb 1, 2018 – Feb 12, 2018 FPGA manager framework

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpga-manager: altera-ps-spi: enable usage on non-dt platforms

Driver probing fails on non-dt platforms since of_match_device() always returns NULL here. Add device names and matching driver data to the spi_device_id table. This allows driver binding to dynamically added PS-SPI devices (e.g. added via spi_new_device() after hot-plugging).

---
 drivers/fpga/altera-ps-spi.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/fpga/altera-ps-spi.c +16 -5
index 14f14efdf0d5..c593f33d8db9 100644
@@ -238,16 +238,25 @@ static int altera_ps_probe(struct spi_device *spi)
 {
 	struct altera_ps_conf *conf;
 	const struct of_device_id *of_id;
+	const struct spi_device_id *id;
 
 	conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
 	if (!conf)
 		return -ENOMEM;
 
-	of_id = of_match_device(of_ef_match, &spi->dev);
-	if (!of_id)
-		return -ENODEV;
+	if (spi->dev.of_node) {
+		of_id = of_match_device(of_ef_match, &spi->dev);
+		if (!of_id)
+			return -ENODEV;
+
+		conf->data = of_id->data;
+	} else {
+		id = spi_get_device_id(spi);
+		if (!id)
+			return -ENODEV;
+		conf->data = (struct altera_ps_data *)id->driver_data;
+	}
 
-	conf->data = of_id->data;
 	conf->spi = spi;
 	conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW);
 	if (IS_ERR(conf->config)) {
@@ -285,7 +294,9 @@ static int altera_ps_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id altera_ps_spi_ids[] = {
-	{"cyclone-ps-spi", 0},
+	{"cyclone-ps-spi", (kernel_ulong_t)&c5_data},
+	{"fpga-passive-serial", (kernel_ulong_t)&c5_data},
+	{"fpga-arria10-passive-serial", (kernel_ulong_t)&a10_data},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);
Signature · 1 line
2.11.0
#1 lore raw

On Thu, Feb 1, 2018 at 4:31 PM, Anatolij Gustschin <[email protected]> wrote:

Hi Anatolij,

Quoted 28 lines

Driver probing fails on non-dt platforms since of_match_device() always returns NULL here. Add device names and matching driver data to the spi_device_id table. This allows driver binding to dynamically added PS-SPI devices (e.g. added via spi_new_device() after hot-plugging).

---
 drivers/fpga/altera-ps-spi.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/fpga/altera-ps-spi.c +1 -3
index 14f14efdf0d5..c593f33d8db9 100644
@@ -238,16 +238,25 @@ static int altera_ps_probe(struct spi_device *spi)
 {
        struct altera_ps_conf *conf;
        const struct of_device_id *of_id;
+       const struct spi_device_id *id;
 
        conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
        if (!conf)
                return -ENOMEM;
 
-       of_id = of_match_device(of_ef_match, &spi->dev);
-       if (!of_id)
-               return -ENODEV;

drivers/fpga/altera-ps-spi.c static int altera_ps_probe(struct spi_device *spi) · line 256

Quoted 10 lines
drivers/fpga/altera-ps-spi.c +10 -0
+       if (spi->dev.of_node) {
+               of_id = of_match_device(of_ef_match, &spi->dev);
+               if (!of_id)
+                       return -ENODEV;
+
+               conf->data = of_id->data;
+       } else {
+               id = spi_get_device_id(spi);
+               if (!id)
+                       return -ENODEV;

Is it actually possible for !id at this point? Seems like if we are in this probe function and we get this far, this would always succeed.

Alan

Quoted 21 lines
drivers/fpga/altera-ps-spi.c +5 -3
+               conf->data = (struct altera_ps_data *)id->driver_data;
+       }
 
-       conf->data = of_id->data;
        conf->spi = spi;
        conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW);
        if (IS_ERR(conf->config)) {
@@ -285,7 +294,9 @@ static int altera_ps_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id altera_ps_spi_ids[] = {
-       {"cyclone-ps-spi", 0},
+       {"cyclone-ps-spi", (kernel_ulong_t)&c5_data},
+       {"fpga-passive-serial", (kernel_ulong_t)&c5_data},
+       {"fpga-arria10-passive-serial", (kernel_ulong_t)&a10_data},
        {}
 };
 MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);
--

2.11.0

#2 lore raw

Hi Alan,

On Mon, 12 Feb 2018 10:19:06 -0600
Alan Tull [email protected] wrote:
...

Quoted 11 lines

drivers/fpga/altera-ps-spi.c static int altera_ps_probe(struct spi_device *spi) · line 256

Quoted 10 lines
drivers/fpga/altera-ps-spi.c +10 -0
+       if (spi->dev.of_node) {
+               of_id = of_match_device(of_ef_match, &spi->dev);
+               if (!of_id)
+                       return -ENODEV;
+
+               conf->data = of_id->data;
+       } else {
+               id = spi_get_device_id(spi);
+               if (!id)
+                       return -ENODEV;  
Quoted 2 lines

Is it actually possible for !id at this point? Seems like if we are in this probe function and we get this far, this would always succeed.

Yes, !id should be always false here. I'll drop this check then.

Thanks,

Anatolij