summaryrefslogtreecommitdiffstats
path: root/drivers/fpga/altera-ps-spi.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 23:54:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 23:54:57 -0500
commit457fa3469a65a524be04412f5cd497fa3b11c9fd (patch)
treee826786d7838668595dfac115ced53b32e5c97b9 /drivers/fpga/altera-ps-spi.c
parentb07039b79c9ea64c1eacda1e01d645082e4a0d5d (diff)
parentfbc4904c287778ddb74bf6060ac9dec51992fc53 (diff)
Merge tag 'char-misc-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver updates from Greg KH: "Here is the big set of char and misc driver patches for 4.21-rc1. Lots of different types of driver things in here, as this tree seems to be the "collection of various driver subsystems not big enough to have their own git tree" lately. Anyway, some highlights of the changes in here: - binderfs: is it a rule that all driver subsystems will eventually grow to have their own filesystem? Binder now has one to handle the use of it in containerized systems. This was discussed at the Plumbers conference a few months ago and knocked into mergable shape very fast by Christian Brauner. Who also has signed up to be another binder maintainer, showing a distinct lack of good judgement :) - binder updates and fixes - mei driver updates - fpga driver updates and additions - thunderbolt driver updates - soundwire driver updates - extcon driver updates - nvmem driver updates - hyper-v driver updates - coresight driver updates - pvpanic driver additions and reworking for more device support - lp driver updates. Yes really, it's _finally_ moved to the proper parallal port driver model, something I never thought I would see happen. Good stuff. - other tiny driver updates and fixes. All of these have been in linux-next for a while with no reported issues" * tag 'char-misc-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (116 commits) MAINTAINERS: add another Android binder maintainer intel_th: msu: Fix an off-by-one in attribute store stm class: Add a reference to the SyS-T document stm class: Fix a module refcount leak in policy creation error path char: lp: use new parport device model char: lp: properly count the lp devices char: lp: use first unused lp number while registering char: lp: detach the device when parallel port is removed char: lp: introduce list to save port number bus: qcom: remove duplicated include from qcom-ebi2.c VMCI: Use memdup_user() rather than duplicating its implementation char/rtc: Use of_node_name_eq for node name comparisons misc: mic: fix a DMA pool free failure ptp: fix an IS_ERR() vs NULL check genwqe: Fix size check binder: implement binderfs binder: fix use-after-free due to ksys_close() during fdget() bus: fsl-mc: remove duplicated include files bus: fsl-mc: explicitly define the fsl_mc_command endianness misc: ti-st: make array read_ver_cmd static, shrinks object size ...
Diffstat (limited to 'drivers/fpga/altera-ps-spi.c')
-rw-r--r--drivers/fpga/altera-ps-spi.c40
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 */
79static const struct altera_ps_data *altera_ps_data_map[] = {
80 &c5_data,
81 &a10_data,
82};
83
78static const struct of_device_id of_ef_match[] = { 84static 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
243static 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
237static int altera_ps_probe(struct spi_device *spi) 259static 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
296static const struct spi_device_id altera_ps_spi_ids[] = { 324static 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};
300MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids); 330MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);