hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/staging/axis-fifo/axis-fifo.c
....@@ -16,7 +16,7 @@
1616
1717 #include <linux/kernel.h>
1818 #include <linux/wait.h>
19
-#include <linux/spinlock_types.h>
19
+#include <linux/mutex.h>
2020 #include <linux/device.h>
2121 #include <linux/cdev.h>
2222 #include <linux/init.h>
....@@ -27,8 +27,6 @@
2727 #include <linux/interrupt.h>
2828 #include <linux/param.h>
2929 #include <linux/fs.h>
30
-#include <linux/device.h>
31
-#include <linux/cdev.h>
3230 #include <linux/types.h>
3331 #include <linux/uaccess.h>
3432 #include <linux/jiffies.h>
....@@ -127,7 +125,6 @@
127125
128126 struct axis_fifo {
129127 int irq; /* interrupt */
130
- struct resource *mem; /* physical memory */
131128 void __iomem *base_addr; /* kernel space memory */
132129
133130 unsigned int rx_fifo_depth; /* max words in the receive fifo */
....@@ -136,9 +133,9 @@
136133 int has_tx_fifo; /* whether the IP has the tx fifo enabled */
137134
138135 wait_queue_head_t read_queue; /* wait queue for asynchronos read */
139
- spinlock_t read_queue_lock; /* lock for reading waitqueue */
136
+ struct mutex read_lock; /* lock for reading */
140137 wait_queue_head_t write_queue; /* wait queue for asynchronos write */
141
- spinlock_t write_queue_lock; /* lock for writing waitqueue */
138
+ struct mutex write_lock; /* lock for writing */
142139 unsigned int write_flags; /* write file flags */
143140 unsigned int read_flags; /* read file flags */
144141
....@@ -339,7 +336,21 @@
339336 iowrite32(XLLF_INT_ALL_MASK, fifo->base_addr + XLLF_ISR_OFFSET);
340337 }
341338
342
-/* reads a single packet from the fifo as dictated by the tlast signal */
339
+/**
340
+ * axis_fifo_write() - Read a packet from AXIS-FIFO character device.
341
+ * @f Open file.
342
+ * @buf User space buffer to read to.
343
+ * @len User space buffer length.
344
+ * @off Buffer offset.
345
+ *
346
+ * As defined by the device's documentation, we need to check the device's
347
+ * occupancy before reading the length register and then the data. All these
348
+ * operations must be executed atomically, in order and one after the other
349
+ * without missing any.
350
+ *
351
+ * Returns the number of bytes read from the device or negative error code
352
+ * on failure.
353
+ */
343354 static ssize_t axis_fifo_read(struct file *f, char __user *buf,
344355 size_t len, loff_t *off)
345356 {
....@@ -353,36 +364,38 @@
353364 u32 tmp_buf[READ_BUF_SIZE];
354365
355366 if (fifo->read_flags & O_NONBLOCK) {
356
- /* opened in non-blocking mode
357
- * return if there are no packets available
367
+ /*
368
+ * Device opened in non-blocking mode. Try to lock it and then
369
+ * check if any packet is available.
358370 */
359
- if (!ioread32(fifo->base_addr + XLLF_RDFO_OFFSET))
371
+ if (!mutex_trylock(&fifo->read_lock))
360372 return -EAGAIN;
373
+
374
+ if (!ioread32(fifo->base_addr + XLLF_RDFO_OFFSET)) {
375
+ ret = -EAGAIN;
376
+ goto end_unlock;
377
+ }
361378 } else {
362379 /* opened in blocking mode
363380 * wait for a packet available interrupt (or timeout)
364381 * if nothing is currently available
365382 */
366
- spin_lock_irq(&fifo->read_queue_lock);
367
- ret = wait_event_interruptible_lock_irq_timeout(
368
- fifo->read_queue,
383
+ mutex_lock(&fifo->read_lock);
384
+ ret = wait_event_interruptible_timeout(fifo->read_queue,
369385 ioread32(fifo->base_addr + XLLF_RDFO_OFFSET),
370
- fifo->read_queue_lock,
371
- (read_timeout >= 0) ? msecs_to_jiffies(read_timeout) :
372
- MAX_SCHEDULE_TIMEOUT);
373
- spin_unlock_irq(&fifo->read_queue_lock);
386
+ (read_timeout >= 0) ?
387
+ msecs_to_jiffies(read_timeout) :
388
+ MAX_SCHEDULE_TIMEOUT);
374389
375
- if (ret == 0) {
376
- /* timeout occurred */
377
- dev_dbg(fifo->dt_device, "read timeout");
378
- return -EAGAIN;
379
- } else if (ret == -ERESTARTSYS) {
380
- /* signal received */
381
- return -ERESTARTSYS;
382
- } else if (ret < 0) {
383
- dev_err(fifo->dt_device, "wait_event_interruptible_timeout() error in read (ret=%i)\n",
384
- ret);
385
- return ret;
390
+ if (ret <= 0) {
391
+ if (ret == 0) {
392
+ ret = -EAGAIN;
393
+ } else if (ret != -ERESTARTSYS) {
394
+ dev_err(fifo->dt_device, "wait_event_interruptible_timeout() error in read (ret=%i)\n",
395
+ ret);
396
+ }
397
+
398
+ goto end_unlock;
386399 }
387400 }
388401
....@@ -390,14 +403,16 @@
390403 if (!bytes_available) {
391404 dev_err(fifo->dt_device, "received a packet of length 0 - fifo core will be reset\n");
392405 reset_ip_core(fifo);
393
- return -EIO;
406
+ ret = -EIO;
407
+ goto end_unlock;
394408 }
395409
396410 if (bytes_available > len) {
397411 dev_err(fifo->dt_device, "user read buffer too small (available bytes=%zu user buffer bytes=%zu) - fifo core will be reset\n",
398412 bytes_available, len);
399413 reset_ip_core(fifo);
400
- return -EINVAL;
414
+ ret = -EINVAL;
415
+ goto end_unlock;
401416 }
402417
403418 if (bytes_available % sizeof(u32)) {
....@@ -406,7 +421,8 @@
406421 */
407422 dev_err(fifo->dt_device, "received a packet that isn't word-aligned - fifo core will be reset\n");
408423 reset_ip_core(fifo);
409
- return -EIO;
424
+ ret = -EIO;
425
+ goto end_unlock;
410426 }
411427
412428 words_available = bytes_available / sizeof(u32);
....@@ -426,16 +442,37 @@
426442 if (copy_to_user(buf + copied * sizeof(u32), tmp_buf,
427443 copy * sizeof(u32))) {
428444 reset_ip_core(fifo);
429
- return -EFAULT;
445
+ ret = -EFAULT;
446
+ goto end_unlock;
430447 }
431448
432449 copied += copy;
433450 words_available -= copy;
434451 }
435452
436
- return bytes_available;
453
+ ret = bytes_available;
454
+
455
+end_unlock:
456
+ mutex_unlock(&fifo->read_lock);
457
+
458
+ return ret;
437459 }
438460
461
+/**
462
+ * axis_fifo_write() - Write buffer to AXIS-FIFO character device.
463
+ * @f Open file.
464
+ * @buf User space buffer to write to the device.
465
+ * @len User space buffer length.
466
+ * @off Buffer offset.
467
+ *
468
+ * As defined by the device's documentation, we need to write to the device's
469
+ * data buffer then to the device's packet length register atomically. Also,
470
+ * we need to lock before checking if the device has available space to avoid
471
+ * any concurrency issue.
472
+ *
473
+ * Returns the number of bytes written to the device or negative error code
474
+ * on failure.
475
+ */
439476 static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
440477 size_t len, loff_t *off)
441478 {
....@@ -468,12 +505,17 @@
468505 }
469506
470507 if (fifo->write_flags & O_NONBLOCK) {
471
- /* opened in non-blocking mode
472
- * return if there is not enough room available in the fifo
508
+ /*
509
+ * Device opened in non-blocking mode. Try to lock it and then
510
+ * check if there is any room to write the given buffer.
473511 */
512
+ if (!mutex_trylock(&fifo->write_lock))
513
+ return -EAGAIN;
514
+
474515 if (words_to_write > ioread32(fifo->base_addr +
475516 XLLF_TDFV_OFFSET)) {
476
- return -EAGAIN;
517
+ ret = -EAGAIN;
518
+ goto end_unlock;
477519 }
478520 } else {
479521 /* opened in blocking mode */
....@@ -481,29 +523,23 @@
481523 /* wait for an interrupt (or timeout) if there isn't
482524 * currently enough room in the fifo
483525 */
484
- spin_lock_irq(&fifo->write_queue_lock);
485
- ret = wait_event_interruptible_lock_irq_timeout(
486
- fifo->write_queue,
526
+ mutex_lock(&fifo->write_lock);
527
+ ret = wait_event_interruptible_timeout(fifo->write_queue,
487528 ioread32(fifo->base_addr + XLLF_TDFV_OFFSET)
488
- >= words_to_write,
489
- fifo->write_queue_lock,
490
- (write_timeout >= 0) ? msecs_to_jiffies(write_timeout) :
491
- MAX_SCHEDULE_TIMEOUT);
492
- spin_unlock_irq(&fifo->write_queue_lock);
529
+ >= words_to_write,
530
+ (write_timeout >= 0) ?
531
+ msecs_to_jiffies(write_timeout) :
532
+ MAX_SCHEDULE_TIMEOUT);
493533
494
- if (ret == 0) {
495
- /* timeout occurred */
496
- dev_dbg(fifo->dt_device, "write timeout\n");
497
- return -EAGAIN;
498
- } else if (ret == -ERESTARTSYS) {
499
- /* signal received */
500
- return -ERESTARTSYS;
501
- } else if (ret < 0) {
502
- /* unknown error */
503
- dev_err(fifo->dt_device,
504
- "wait_event_interruptible_timeout() error in write (ret=%i)\n",
505
- ret);
506
- return ret;
534
+ if (ret <= 0) {
535
+ if (ret == 0) {
536
+ ret = -EAGAIN;
537
+ } else if (ret != -ERESTARTSYS) {
538
+ dev_err(fifo->dt_device, "wait_event_interruptible_timeout() error in write (ret=%i)\n",
539
+ ret);
540
+ }
541
+
542
+ goto end_unlock;
507543 }
508544 }
509545
....@@ -517,7 +553,8 @@
517553 if (copy_from_user(tmp_buf, buf + copied * sizeof(u32),
518554 copy * sizeof(u32))) {
519555 reset_ip_core(fifo);
520
- return -EFAULT;
556
+ ret = -EFAULT;
557
+ goto end_unlock;
521558 }
522559
523560 for (i = 0; i < copy; i++)
....@@ -528,10 +565,15 @@
528565 words_to_write -= copy;
529566 }
530567
531
- /* write packet size to fifo */
532
- iowrite32(copied * sizeof(u32), fifo->base_addr + XLLF_TLR_OFFSET);
568
+ ret = copied * sizeof(u32);
533569
534
- return (ssize_t)copied * sizeof(u32);
570
+ /* write packet size to fifo */
571
+ iowrite32(ret, fifo->base_addr + XLLF_TLR_OFFSET);
572
+
573
+end_unlock:
574
+ mutex_unlock(&fifo->write_lock);
575
+
576
+ return ret;
535577 }
536578
537579 static irqreturn_t axis_fifo_irq(int irq, void *dw)
....@@ -702,6 +744,68 @@
702744 return 0;
703745 }
704746
747
+static int axis_fifo_parse_dt(struct axis_fifo *fifo)
748
+{
749
+ int ret;
750
+ unsigned int value;
751
+
752
+ ret = get_dts_property(fifo, "xlnx,axi-str-rxd-tdata-width", &value);
753
+ if (ret) {
754
+ dev_err(fifo->dt_device, "missing xlnx,axi-str-rxd-tdata-width property\n");
755
+ goto end;
756
+ } else if (value != 32) {
757
+ dev_err(fifo->dt_device, "xlnx,axi-str-rxd-tdata-width only supports 32 bits\n");
758
+ ret = -EIO;
759
+ goto end;
760
+ }
761
+
762
+ ret = get_dts_property(fifo, "xlnx,axi-str-txd-tdata-width", &value);
763
+ if (ret) {
764
+ dev_err(fifo->dt_device, "missing xlnx,axi-str-txd-tdata-width property\n");
765
+ goto end;
766
+ } else if (value != 32) {
767
+ dev_err(fifo->dt_device, "xlnx,axi-str-txd-tdata-width only supports 32 bits\n");
768
+ ret = -EIO;
769
+ goto end;
770
+ }
771
+
772
+ ret = get_dts_property(fifo, "xlnx,rx-fifo-depth",
773
+ &fifo->rx_fifo_depth);
774
+ if (ret) {
775
+ dev_err(fifo->dt_device, "missing xlnx,rx-fifo-depth property\n");
776
+ ret = -EIO;
777
+ goto end;
778
+ }
779
+
780
+ ret = get_dts_property(fifo, "xlnx,tx-fifo-depth",
781
+ &fifo->tx_fifo_depth);
782
+ if (ret) {
783
+ dev_err(fifo->dt_device, "missing xlnx,tx-fifo-depth property\n");
784
+ ret = -EIO;
785
+ goto end;
786
+ }
787
+
788
+ /* IP sets TDFV to fifo depth - 4 so we will do the same */
789
+ fifo->tx_fifo_depth -= 4;
790
+
791
+ ret = get_dts_property(fifo, "xlnx,use-rx-data", &fifo->has_rx_fifo);
792
+ if (ret) {
793
+ dev_err(fifo->dt_device, "missing xlnx,use-rx-data property\n");
794
+ ret = -EIO;
795
+ goto end;
796
+ }
797
+
798
+ ret = get_dts_property(fifo, "xlnx,use-tx-data", &fifo->has_tx_fifo);
799
+ if (ret) {
800
+ dev_err(fifo->dt_device, "missing xlnx,use-tx-data property\n");
801
+ ret = -EIO;
802
+ goto end;
803
+ }
804
+
805
+end:
806
+ return ret;
807
+}
808
+
705809 static int axis_fifo_probe(struct platform_device *pdev)
706810 {
707811 struct resource *r_irq; /* interrupt resources */
....@@ -712,34 +816,6 @@
712816 char device_name[32];
713817
714818 int rc = 0; /* error return value */
715
-
716
- /* IP properties from device tree */
717
- unsigned int rxd_tdata_width;
718
- unsigned int txc_tdata_width;
719
- unsigned int txd_tdata_width;
720
- unsigned int tdest_width;
721
- unsigned int tid_width;
722
- unsigned int tuser_width;
723
- unsigned int data_interface_type;
724
- unsigned int has_tdest;
725
- unsigned int has_tid;
726
- unsigned int has_tkeep;
727
- unsigned int has_tstrb;
728
- unsigned int has_tuser;
729
- unsigned int rx_fifo_depth;
730
- unsigned int rx_programmable_empty_threshold;
731
- unsigned int rx_programmable_full_threshold;
732
- unsigned int axi_id_width;
733
- unsigned int axi4_data_width;
734
- unsigned int select_xpm;
735
- unsigned int tx_fifo_depth;
736
- unsigned int tx_programmable_empty_threshold;
737
- unsigned int tx_programmable_full_threshold;
738
- unsigned int use_rx_cut_through;
739
- unsigned int use_rx_data;
740
- unsigned int use_tx_control;
741
- unsigned int use_tx_cut_through;
742
- unsigned int use_tx_data;
743819
744820 /* ----------------------------
745821 * init wrapper device
....@@ -757,8 +833,8 @@
757833 init_waitqueue_head(&fifo->read_queue);
758834 init_waitqueue_head(&fifo->write_queue);
759835
760
- spin_lock_init(&fifo->read_queue_lock);
761
- spin_lock_init(&fifo->write_queue_lock);
836
+ mutex_init(&fifo->read_lock);
837
+ mutex_init(&fifo->write_lock);
762838
763839 /* ----------------------------
764840 * init device memory space
....@@ -773,32 +849,19 @@
773849 goto err_initial;
774850 }
775851
776
- fifo->mem = r_mem;
777
-
778852 /* request physical memory */
779
- if (!request_mem_region(fifo->mem->start, resource_size(fifo->mem),
780
- DRIVER_NAME)) {
781
- dev_err(fifo->dt_device,
782
- "couldn't lock memory region at 0x%pa\n",
783
- &fifo->mem->start);
784
- rc = -EBUSY;
853
+ fifo->base_addr = devm_ioremap_resource(fifo->dt_device, r_mem);
854
+ if (IS_ERR(fifo->base_addr)) {
855
+ rc = PTR_ERR(fifo->base_addr);
856
+ dev_err(fifo->dt_device, "can't remap IO resource (%d)\n", rc);
785857 goto err_initial;
786858 }
787
- dev_dbg(fifo->dt_device, "got memory location [0x%pa - 0x%pa]\n",
788
- &fifo->mem->start, &fifo->mem->end);
789859
790
- /* map physical memory to kernel virtual address space */
791
- fifo->base_addr = ioremap(fifo->mem->start, resource_size(fifo->mem));
792
- if (!fifo->base_addr) {
793
- dev_err(fifo->dt_device, "couldn't map physical memory\n");
794
- rc = -ENOMEM;
795
- goto err_mem;
796
- }
797860 dev_dbg(fifo->dt_device, "remapped memory to 0x%p\n", fifo->base_addr);
798861
799862 /* create unique device name */
800863 snprintf(device_name, sizeof(device_name), "%s_%pa",
801
- DRIVER_NAME, &fifo->mem->start);
864
+ DRIVER_NAME, &r_mem->start);
802865
803866 dev_dbg(fifo->dt_device, "device name [%s]\n", device_name);
804867
....@@ -807,164 +870,9 @@
807870 * ----------------------------
808871 */
809872
810
- /* retrieve device tree properties */
811
- rc = get_dts_property(fifo, "xlnx,axi-str-rxd-tdata-width",
812
- &rxd_tdata_width);
873
+ rc = axis_fifo_parse_dt(fifo);
813874 if (rc)
814
- goto err_unmap;
815
- rc = get_dts_property(fifo, "xlnx,axi-str-txc-tdata-width",
816
- &txc_tdata_width);
817
- if (rc)
818
- goto err_unmap;
819
- rc = get_dts_property(fifo, "xlnx,axi-str-txd-tdata-width",
820
- &txd_tdata_width);
821
- if (rc)
822
- goto err_unmap;
823
- rc = get_dts_property(fifo, "xlnx,axis-tdest-width", &tdest_width);
824
- if (rc)
825
- goto err_unmap;
826
- rc = get_dts_property(fifo, "xlnx,axis-tid-width", &tid_width);
827
- if (rc)
828
- goto err_unmap;
829
- rc = get_dts_property(fifo, "xlnx,axis-tuser-width", &tuser_width);
830
- if (rc)
831
- goto err_unmap;
832
- rc = get_dts_property(fifo, "xlnx,data-interface-type",
833
- &data_interface_type);
834
- if (rc)
835
- goto err_unmap;
836
- rc = get_dts_property(fifo, "xlnx,has-axis-tdest", &has_tdest);
837
- if (rc)
838
- goto err_unmap;
839
- rc = get_dts_property(fifo, "xlnx,has-axis-tid", &has_tid);
840
- if (rc)
841
- goto err_unmap;
842
- rc = get_dts_property(fifo, "xlnx,has-axis-tkeep", &has_tkeep);
843
- if (rc)
844
- goto err_unmap;
845
- rc = get_dts_property(fifo, "xlnx,has-axis-tstrb", &has_tstrb);
846
- if (rc)
847
- goto err_unmap;
848
- rc = get_dts_property(fifo, "xlnx,has-axis-tuser", &has_tuser);
849
- if (rc)
850
- goto err_unmap;
851
- rc = get_dts_property(fifo, "xlnx,rx-fifo-depth", &rx_fifo_depth);
852
- if (rc)
853
- goto err_unmap;
854
- rc = get_dts_property(fifo, "xlnx,rx-fifo-pe-threshold",
855
- &rx_programmable_empty_threshold);
856
- if (rc)
857
- goto err_unmap;
858
- rc = get_dts_property(fifo, "xlnx,rx-fifo-pf-threshold",
859
- &rx_programmable_full_threshold);
860
- if (rc)
861
- goto err_unmap;
862
- rc = get_dts_property(fifo, "xlnx,s-axi-id-width", &axi_id_width);
863
- if (rc)
864
- goto err_unmap;
865
- rc = get_dts_property(fifo, "xlnx,s-axi4-data-width", &axi4_data_width);
866
- if (rc)
867
- goto err_unmap;
868
- rc = get_dts_property(fifo, "xlnx,select-xpm", &select_xpm);
869
- if (rc)
870
- goto err_unmap;
871
- rc = get_dts_property(fifo, "xlnx,tx-fifo-depth", &tx_fifo_depth);
872
- if (rc)
873
- goto err_unmap;
874
- rc = get_dts_property(fifo, "xlnx,tx-fifo-pe-threshold",
875
- &tx_programmable_empty_threshold);
876
- if (rc)
877
- goto err_unmap;
878
- rc = get_dts_property(fifo, "xlnx,tx-fifo-pf-threshold",
879
- &tx_programmable_full_threshold);
880
- if (rc)
881
- goto err_unmap;
882
- rc = get_dts_property(fifo, "xlnx,use-rx-cut-through",
883
- &use_rx_cut_through);
884
- if (rc)
885
- goto err_unmap;
886
- rc = get_dts_property(fifo, "xlnx,use-rx-data", &use_rx_data);
887
- if (rc)
888
- goto err_unmap;
889
- rc = get_dts_property(fifo, "xlnx,use-tx-ctrl", &use_tx_control);
890
- if (rc)
891
- goto err_unmap;
892
- rc = get_dts_property(fifo, "xlnx,use-tx-cut-through",
893
- &use_tx_cut_through);
894
- if (rc)
895
- goto err_unmap;
896
- rc = get_dts_property(fifo, "xlnx,use-tx-data", &use_tx_data);
897
- if (rc)
898
- goto err_unmap;
899
-
900
- /* check validity of device tree properties */
901
- if (rxd_tdata_width != 32) {
902
- dev_err(fifo->dt_device,
903
- "rxd_tdata_width width [%u] unsupported\n",
904
- rxd_tdata_width);
905
- rc = -EIO;
906
- goto err_unmap;
907
- }
908
- if (txd_tdata_width != 32) {
909
- dev_err(fifo->dt_device,
910
- "txd_tdata_width width [%u] unsupported\n",
911
- txd_tdata_width);
912
- rc = -EIO;
913
- goto err_unmap;
914
- }
915
- if (has_tdest) {
916
- dev_err(fifo->dt_device, "tdest not supported\n");
917
- rc = -EIO;
918
- goto err_unmap;
919
- }
920
- if (has_tid) {
921
- dev_err(fifo->dt_device, "tid not supported\n");
922
- rc = -EIO;
923
- goto err_unmap;
924
- }
925
- if (has_tkeep) {
926
- dev_err(fifo->dt_device, "tkeep not supported\n");
927
- rc = -EIO;
928
- goto err_unmap;
929
- }
930
- if (has_tstrb) {
931
- dev_err(fifo->dt_device, "tstrb not supported\n");
932
- rc = -EIO;
933
- goto err_unmap;
934
- }
935
- if (has_tuser) {
936
- dev_err(fifo->dt_device, "tuser not supported\n");
937
- rc = -EIO;
938
- goto err_unmap;
939
- }
940
- if (use_rx_cut_through) {
941
- dev_err(fifo->dt_device, "rx cut-through not supported\n");
942
- rc = -EIO;
943
- goto err_unmap;
944
- }
945
- if (use_tx_cut_through) {
946
- dev_err(fifo->dt_device, "tx cut-through not supported\n");
947
- rc = -EIO;
948
- goto err_unmap;
949
- }
950
- if (use_tx_control) {
951
- dev_err(fifo->dt_device, "tx control not supported\n");
952
- rc = -EIO;
953
- goto err_unmap;
954
- }
955
-
956
- /* TODO
957
- * these exist in the device tree but it's unclear what they do
958
- * - select-xpm
959
- * - data-interface-type
960
- */
961
-
962
- /* set device wrapper properties based on IP config */
963
- fifo->rx_fifo_depth = rx_fifo_depth;
964
- /* IP sets TDFV to fifo depth - 4 so we will do the same */
965
- fifo->tx_fifo_depth = tx_fifo_depth - 4;
966
- fifo->has_rx_fifo = use_rx_data;
967
- fifo->has_tx_fifo = use_tx_data;
875
+ goto err_initial;
968876
969877 reset_ip_core(fifo);
970878
....@@ -977,18 +885,19 @@
977885 r_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
978886 if (!r_irq) {
979887 dev_err(fifo->dt_device, "no IRQ found for 0x%pa\n",
980
- &fifo->mem->start);
888
+ &r_mem->start);
981889 rc = -EIO;
982
- goto err_unmap;
890
+ goto err_initial;
983891 }
984892
985893 /* request IRQ */
986894 fifo->irq = r_irq->start;
987
- rc = request_irq(fifo->irq, &axis_fifo_irq, 0, DRIVER_NAME, fifo);
895
+ rc = devm_request_irq(fifo->dt_device, fifo->irq, &axis_fifo_irq, 0,
896
+ DRIVER_NAME, fifo);
988897 if (rc) {
989898 dev_err(fifo->dt_device, "couldn't allocate interrupt %i\n",
990899 fifo->irq);
991
- goto err_unmap;
900
+ goto err_initial;
992901 }
993902
994903 /* ----------------------------
....@@ -999,7 +908,7 @@
999908 /* allocate device number */
1000909 rc = alloc_chrdev_region(&fifo->devt, 0, 1, DRIVER_NAME);
1001910 if (rc < 0)
1002
- goto err_irq;
911
+ goto err_initial;
1003912 dev_dbg(fifo->dt_device, "allocated device number major %i minor %i\n",
1004913 MAJOR(fifo->devt), MINOR(fifo->devt));
1005914
....@@ -1023,14 +932,14 @@
1023932 }
1024933
1025934 /* create sysfs entries */
1026
- rc = sysfs_create_group(&fifo->device->kobj, &axis_fifo_attrs_group);
935
+ rc = devm_device_add_group(fifo->device, &axis_fifo_attrs_group);
1027936 if (rc < 0) {
1028937 dev_err(fifo->dt_device, "couldn't register sysfs group\n");
1029938 goto err_cdev;
1030939 }
1031940
1032941 dev_info(fifo->dt_device, "axis-fifo created at %pa mapped to 0x%pa, irq=%i, major=%i, minor=%i\n",
1033
- &fifo->mem->start, &fifo->base_addr, fifo->irq,
942
+ &r_mem->start, &fifo->base_addr, fifo->irq,
1034943 MAJOR(fifo->devt), MINOR(fifo->devt));
1035944
1036945 return 0;
....@@ -1041,12 +950,6 @@
1041950 device_destroy(axis_fifo_driver_class, fifo->devt);
1042951 err_chrdev_region:
1043952 unregister_chrdev_region(fifo->devt, 1);
1044
-err_irq:
1045
- free_irq(fifo->irq, fifo);
1046
-err_unmap:
1047
- iounmap(fifo->base_addr);
1048
-err_mem:
1049
- release_mem_region(fifo->mem->start, resource_size(fifo->mem));
1050953 err_initial:
1051954 dev_set_drvdata(dev, NULL);
1052955 return rc;
....@@ -1057,15 +960,12 @@
1057960 struct device *dev = &pdev->dev;
1058961 struct axis_fifo *fifo = dev_get_drvdata(dev);
1059962
1060
- sysfs_remove_group(&fifo->device->kobj, &axis_fifo_attrs_group);
1061963 cdev_del(&fifo->char_device);
1062964 dev_set_drvdata(fifo->device, NULL);
1063965 device_destroy(axis_fifo_driver_class, fifo->devt);
1064966 unregister_chrdev_region(fifo->devt, 1);
1065
- free_irq(fifo->irq, fifo);
1066
- iounmap(fifo->base_addr);
1067
- release_mem_region(fifo->mem->start, resource_size(fifo->mem));
1068967 dev_set_drvdata(dev, NULL);
968
+
1069969 return 0;
1070970 }
1071971
....@@ -1089,6 +989,8 @@
1089989 pr_info("axis-fifo driver loaded with parameters read_timeout = %i, write_timeout = %i\n",
1090990 read_timeout, write_timeout);
1091991 axis_fifo_driver_class = class_create(THIS_MODULE, DRIVER_NAME);
992
+ if (IS_ERR(axis_fifo_driver_class))
993
+ return PTR_ERR(axis_fifo_driver_class);
1092994 return platform_driver_register(&axis_fifo_driver);
1093995 }
1094996