forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/staging/most/dim2/dim2.c
....@@ -20,8 +20,7 @@
2020 #include <linux/dma-mapping.h>
2121 #include <linux/sched.h>
2222 #include <linux/kthread.h>
23
-
24
-#include "most/core.h"
23
+#include <linux/most.h>
2524 #include "hal.h"
2625 #include "errors.h"
2726 #include "sysfs.h"
....@@ -47,7 +46,7 @@
4746 static DEFINE_SPINLOCK(dim_lock);
4847
4948 static void dim2_tasklet_fn(unsigned long data);
50
-static DECLARE_TASKLET(dim2_tasklet, dim2_tasklet_fn, 0);
49
+static DECLARE_TASKLET_OLD(dim2_tasklet, dim2_tasklet_fn);
5150
5251 /**
5352 * struct hdm_channel - private structure to keep channel specific data
....@@ -101,12 +100,12 @@
101100 struct medialb_bus bus;
102101 void (*on_netinfo)(struct most_interface *most_iface,
103102 unsigned char link_state, unsigned char *addrs);
104
- void (*disable_platform)(struct platform_device *);
103
+ void (*disable_platform)(struct platform_device *pdev);
105104 };
106105
107106 struct dim2_platform_data {
108
- int (*enable)(struct platform_device *);
109
- void (*disable)(struct platform_device *);
107
+ int (*enable)(struct platform_device *pdev);
108
+ void (*disable)(struct platform_device *pdev);
110109 };
111110
112111 #define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface)
....@@ -116,7 +115,8 @@
116115 (((p)[1] == 0x18) && ((p)[2] == 0x05) && ((p)[3] == 0x0C) && \
117116 ((p)[13] == 0x3C) && ((p)[14] == 0x00) && ((p)[15] == 0x0A))
118117
119
-bool dim2_sysfs_get_state_cb(void)
118
+static ssize_t state_show(struct device *dev, struct device_attribute *attr,
119
+ char *buf)
120120 {
121121 bool state;
122122 unsigned long flags;
....@@ -125,27 +125,17 @@
125125 state = dim_get_lock_state();
126126 spin_unlock_irqrestore(&dim_lock, flags);
127127
128
- return state;
128
+ return sysfs_emit(buf, "%s\n", state ? "locked" : "");
129129 }
130130
131
-/**
132
- * dimcb_io_read - callback from HAL to read an I/O register
133
- * @ptr32: register address
134
- */
135
-u32 dimcb_io_read(u32 __iomem *ptr32)
136
-{
137
- return readl(ptr32);
138
-}
131
+static DEVICE_ATTR_RO(state);
139132
140
-/**
141
- * dimcb_io_write - callback from HAL to write value to an I/O register
142
- * @ptr32: register address
143
- * @value: value to write
144
- */
145
-void dimcb_io_write(u32 __iomem *ptr32, u32 value)
146
-{
147
- writel(value, ptr32);
148
-}
133
+static struct attribute *dim2_attrs[] = {
134
+ &dev_attr_state.attr,
135
+ NULL,
136
+};
137
+
138
+ATTRIBUTE_GROUPS(dim2);
149139
150140 /**
151141 * dimcb_on_error - callback from HAL to report miscommunication between
....@@ -733,6 +723,23 @@
733723 return -EINVAL;
734724 }
735725
726
+static void dim2_release(struct device *d)
727
+{
728
+ struct dim2_hdm *dev = container_of(d, struct dim2_hdm, dev);
729
+ unsigned long flags;
730
+
731
+ kthread_stop(dev->netinfo_task);
732
+
733
+ spin_lock_irqsave(&dim_lock, flags);
734
+ dim_shutdown();
735
+ spin_unlock_irqrestore(&dim_lock, flags);
736
+
737
+ if (dev->disable_platform)
738
+ dev->disable_platform(to_platform_device(d->parent));
739
+
740
+ kfree(dev);
741
+}
742
+
736743 /*
737744 * dim2_probe - dim2 probe handler
738745 * @pdev: platform device structure
....@@ -753,7 +760,7 @@
753760
754761 enum { MLB_INT_IDX, AHB0_INT_IDX };
755762
756
- dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
763
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
757764 if (!dev)
758765 return -ENOMEM;
759766
....@@ -765,25 +772,27 @@
765772 "microchip,clock-speed", &clock_speed);
766773 if (ret) {
767774 dev_err(&pdev->dev, "missing dt property clock-speed\n");
768
- return ret;
775
+ goto err_free_dev;
769776 }
770777
771778 ret = get_dim2_clk_speed(clock_speed, &dev->clk_speed);
772779 if (ret) {
773780 dev_err(&pdev->dev, "bad dt property clock-speed\n");
774
- return ret;
781
+ goto err_free_dev;
775782 }
776783
777784 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
778785 dev->io_base = devm_ioremap_resource(&pdev->dev, res);
779
- if (IS_ERR(dev->io_base))
780
- return PTR_ERR(dev->io_base);
786
+ if (IS_ERR(dev->io_base)) {
787
+ ret = PTR_ERR(dev->io_base);
788
+ goto err_free_dev;
789
+ }
781790
782791 of_id = of_match_node(dim2_of_match, pdev->dev.of_node);
783792 pdata = of_id->data;
784793 ret = pdata && pdata->enable ? pdata->enable(pdev) : 0;
785794 if (ret)
786
- return ret;
795
+ goto err_free_dev;
787796
788797 dev->disable_platform = pdata ? pdata->disable : NULL;
789798
....@@ -797,7 +806,6 @@
797806
798807 irq = platform_get_irq(pdev, AHB0_INT_IDX);
799808 if (irq < 0) {
800
- dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
801809 ret = irq;
802810 goto err_shutdown_dim;
803811 }
....@@ -811,7 +819,6 @@
811819
812820 irq = platform_get_irq(pdev, MLB_INT_IDX);
813821 if (irq < 0) {
814
- dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
815822 ret = irq;
816823 goto err_shutdown_dim;
817824 }
....@@ -875,32 +882,20 @@
875882 dev->most_iface.poison_channel = poison_channel;
876883 dev->most_iface.request_netinfo = request_netinfo;
877884 dev->most_iface.driver_dev = &pdev->dev;
878
- dev->dev.init_name = "dim2_state";
879
- dev->dev.parent = &dev->most_iface.dev;
885
+ dev->most_iface.dev = &dev->dev;
886
+ dev->dev.init_name = dev->name;
887
+ dev->dev.parent = &pdev->dev;
888
+ dev->dev.release = dim2_release;
880889
881
- ret = most_register_interface(&dev->most_iface);
882
- if (ret) {
883
- dev_err(&pdev->dev, "failed to register MOST interface\n");
884
- goto err_stop_thread;
885
- }
890
+ return most_register_interface(&dev->most_iface);
886891
887
- ret = dim2_sysfs_probe(&dev->dev);
888
- if (ret) {
889
- dev_err(&pdev->dev, "failed to create sysfs attribute\n");
890
- goto err_unreg_iface;
891
- }
892
-
893
- return 0;
894
-
895
-err_unreg_iface:
896
- most_deregister_interface(&dev->most_iface);
897
-err_stop_thread:
898
- kthread_stop(dev->netinfo_task);
899892 err_shutdown_dim:
900893 dim_shutdown();
901894 err_disable_platform:
902895 if (dev->disable_platform)
903896 dev->disable_platform(pdev);
897
+err_free_dev:
898
+ kfree(dev);
904899
905900 return ret;
906901 }
....@@ -914,18 +909,8 @@
914909 static int dim2_remove(struct platform_device *pdev)
915910 {
916911 struct dim2_hdm *dev = platform_get_drvdata(pdev);
917
- unsigned long flags;
918912
919
- dim2_sysfs_destroy(&dev->dev);
920913 most_deregister_interface(&dev->most_iface);
921
- kthread_stop(dev->netinfo_task);
922
-
923
- spin_lock_irqsave(&dim_lock, flags);
924
- dim_shutdown();
925
- spin_unlock_irqrestore(&dim_lock, flags);
926
-
927
- if (dev->disable_platform)
928
- dev->disable_platform(pdev);
929914
930915 return 0;
931916 }
....@@ -1100,6 +1085,7 @@
11001085 .driver = {
11011086 .name = "hdm_dim2",
11021087 .of_match_table = dim2_of_match,
1088
+ .dev_groups = dim2_groups,
11031089 },
11041090 };
11051091