Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fpga: mgr: 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 spi ids with device names and
matching driver data as an index of a map array with data for
supported devices. Add this map array and a function for mapping
spi ids to driver data. This allows driver binding to dynamically
added PS-SPI devices (e.g. when added via spi_new_device() after
hot-plugging).

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Acked-by: Alan Tull <atull@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Anatolij Gustschin and committed by
Greg Kroah-Hartman
1a195d87 30522a95

+35 -5
+35 -5
drivers/fpga/altera-ps-spi.c
··· 75 75 .t_st2ck_us = 10, /* min(t_ST2CK) */ 76 76 }; 77 77 78 + /* Array index is enum altera_ps_devtype */ 79 + static const struct altera_ps_data *altera_ps_data_map[] = { 80 + &c5_data, 81 + &a10_data, 82 + }; 83 + 78 84 static const struct of_device_id of_ef_match[] = { 79 85 { .compatible = "altr,fpga-passive-serial", .data = &c5_data }, 80 86 { .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data }, ··· 240 234 .write_complete = altera_ps_write_complete, 241 235 }; 242 236 237 + static const struct altera_ps_data *id_to_data(const struct spi_device_id *id) 238 + { 239 + kernel_ulong_t devtype = id->driver_data; 240 + const struct altera_ps_data *data; 241 + 242 + /* someone added a altera_ps_devtype without adding to the map array */ 243 + if (devtype >= ARRAY_SIZE(altera_ps_data_map)) 244 + return NULL; 245 + 246 + data = altera_ps_data_map[devtype]; 247 + if (!data || data->devtype != devtype) 248 + return NULL; 249 + 250 + return data; 251 + } 252 + 243 253 static int altera_ps_probe(struct spi_device *spi) 244 254 { 245 255 struct altera_ps_conf *conf; ··· 266 244 if (!conf) 267 245 return -ENOMEM; 268 246 269 - of_id = of_match_device(of_ef_match, &spi->dev); 270 - if (!of_id) 271 - return -ENODEV; 247 + if (spi->dev.of_node) { 248 + of_id = of_match_device(of_ef_match, &spi->dev); 249 + if (!of_id) 250 + return -ENODEV; 251 + conf->data = of_id->data; 252 + } else { 253 + conf->data = id_to_data(spi_get_device_id(spi)); 254 + if (!conf->data) 255 + return -ENODEV; 256 + } 272 257 273 - conf->data = of_id->data; 274 258 conf->spi = spi; 275 259 conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW); 276 260 if (IS_ERR(conf->config)) { ··· 322 294 } 323 295 324 296 static const struct spi_device_id altera_ps_spi_ids[] = { 325 - {"cyclone-ps-spi", 0}, 297 + { "cyclone-ps-spi", CYCLONE5 }, 298 + { "fpga-passive-serial", CYCLONE5 }, 299 + { "fpga-arria10-passive-serial", ARRIA10 }, 326 300 {} 327 301 }; 328 302 MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);