diff options
author | Anatolij Gustschin <agust@denx.de> | 2018-11-26 12:35:28 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-11-26 14:12:05 -0500 |
commit | 1a195d87d2c58aa9524af9531539ccfa203cd52c (patch) | |
tree | 21cae2d4de4ac35614ff93c4003bde1be0e1922b | |
parent | 30522a951f9d02f261d0697c35cb42205b1fae17 (diff) |
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>
-rw-r--r-- | drivers/fpga/altera-ps-spi.c | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c index 33aafda50af5..8c18beec6b57 100644 --- a/drivers/fpga/altera-ps-spi.c +++ b/drivers/fpga/altera-ps-spi.c | |||
@@ -75,6 +75,12 @@ static struct altera_ps_data a10_data = { | |||
75 | .t_st2ck_us = 10, /* min(t_ST2CK) */ | 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 | static const struct of_device_id of_ef_match[] = { | 84 | static const struct of_device_id of_ef_match[] = { |
79 | { .compatible = "altr,fpga-passive-serial", .data = &c5_data }, | 85 | { .compatible = "altr,fpga-passive-serial", .data = &c5_data }, |
80 | { .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data }, | 86 | { .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data }, |
@@ -234,6 +240,22 @@ static const struct fpga_manager_ops altera_ps_ops = { | |||
234 | .write_complete = altera_ps_write_complete, | 240 | .write_complete = altera_ps_write_complete, |
235 | }; | 241 | }; |
236 | 242 | ||
243 | static const struct altera_ps_data *id_to_data(const struct spi_device_id *id) | ||
244 | { | ||
245 | kernel_ulong_t devtype = id->driver_data; | ||
246 | const struct altera_ps_data *data; | ||
247 | |||
248 | /* someone added a altera_ps_devtype without adding to the map array */ | ||
249 | if (devtype >= ARRAY_SIZE(altera_ps_data_map)) | ||
250 | return NULL; | ||
251 | |||
252 | data = altera_ps_data_map[devtype]; | ||
253 | if (!data || data->devtype != devtype) | ||
254 | return NULL; | ||
255 | |||
256 | return data; | ||
257 | } | ||
258 | |||
237 | static int altera_ps_probe(struct spi_device *spi) | 259 | static int altera_ps_probe(struct spi_device *spi) |
238 | { | 260 | { |
239 | struct altera_ps_conf *conf; | 261 | struct altera_ps_conf *conf; |
@@ -244,11 +266,17 @@ static int altera_ps_probe(struct spi_device *spi) | |||
244 | if (!conf) | 266 | if (!conf) |
245 | return -ENOMEM; | 267 | return -ENOMEM; |
246 | 268 | ||
247 | of_id = of_match_device(of_ef_match, &spi->dev); | 269 | if (spi->dev.of_node) { |
248 | if (!of_id) | 270 | of_id = of_match_device(of_ef_match, &spi->dev); |
249 | return -ENODEV; | 271 | if (!of_id) |
272 | return -ENODEV; | ||
273 | conf->data = of_id->data; | ||
274 | } else { | ||
275 | conf->data = id_to_data(spi_get_device_id(spi)); | ||
276 | if (!conf->data) | ||
277 | return -ENODEV; | ||
278 | } | ||
250 | 279 | ||
251 | conf->data = of_id->data; | ||
252 | conf->spi = spi; | 280 | conf->spi = spi; |
253 | conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW); | 281 | conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW); |
254 | if (IS_ERR(conf->config)) { | 282 | if (IS_ERR(conf->config)) { |
@@ -294,7 +322,9 @@ static int altera_ps_remove(struct spi_device *spi) | |||
294 | } | 322 | } |
295 | 323 | ||
296 | static const struct spi_device_id altera_ps_spi_ids[] = { | 324 | static const struct spi_device_id altera_ps_spi_ids[] = { |
297 | {"cyclone-ps-spi", 0}, | 325 | { "cyclone-ps-spi", CYCLONE5 }, |
326 | { "fpga-passive-serial", CYCLONE5 }, | ||
327 | { "fpga-arria10-passive-serial", ARRIA10 }, | ||
298 | {} | 328 | {} |
299 | }; | 329 | }; |
300 | MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids); | 330 | MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids); |