@@ -154,9 +154,6 @@ int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable)
154
154
regmap_update_bits (regmap , CSI_EN_REG , CSI_EN_CSI_EN , 0 );
155
155
156
156
clk_disable_unprepare (csi_dev -> clock_ram );
157
- if (of_device_is_compatible (dev -> of_node ,
158
- "allwinner,sun50i-a64-csi" ))
159
- clk_rate_exclusive_put (csi_dev -> clock_mod );
160
157
clk_disable_unprepare (csi_dev -> clock_mod );
161
158
reset_control_assert (csi_dev -> reset );
162
159
return 0 ;
@@ -168,9 +165,6 @@ int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable)
168
165
return ret ;
169
166
}
170
167
171
- if (of_device_is_compatible (dev -> of_node , "allwinner,sun50i-a64-csi" ))
172
- clk_set_rate_exclusive (csi_dev -> clock_mod , 300000000 );
173
-
174
168
ret = clk_prepare_enable (csi_dev -> clock_ram );
175
169
if (ret ) {
176
170
dev_err (csi_dev -> dev , "Enable clk_dram_csi clk err %d\n" , ret );
@@ -190,8 +184,6 @@ int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable)
190
184
clk_ram_disable :
191
185
clk_disable_unprepare (csi_dev -> clock_ram );
192
186
clk_mod_disable :
193
- if (of_device_is_compatible (dev -> of_node , "allwinner,sun50i-a64-csi" ))
194
- clk_rate_exclusive_put (csi_dev -> clock_mod );
195
187
clk_disable_unprepare (csi_dev -> clock_mod );
196
188
return ret ;
197
189
}
@@ -816,6 +808,7 @@ static int sun6i_csi_resources_setup(struct sun6i_csi_device *csi_dev,
816
808
struct platform_device * platform_dev )
817
809
{
818
810
struct device * dev = csi_dev -> dev ;
811
+ unsigned long clock_mod_rate ;
819
812
void __iomem * io_base ;
820
813
int ret ;
821
814
int irq ;
@@ -847,28 +840,53 @@ static int sun6i_csi_resources_setup(struct sun6i_csi_device *csi_dev,
847
840
return PTR_ERR (csi_dev -> clock_ram );
848
841
}
849
842
843
+ if (of_device_is_compatible (dev -> of_node , "allwinner,sun50i-a64-csi" ))
844
+ clock_mod_rate = 300000000 ;
845
+ else
846
+ clock_mod_rate = 297000000 ;
847
+
848
+ ret = clk_set_rate_exclusive (csi_dev -> clock_mod , clock_mod_rate );
849
+ if (ret ) {
850
+ dev_err (dev , "failed to set mod clock rate\n" );
851
+ return ret ;
852
+ }
853
+
850
854
/* Reset */
851
855
852
856
csi_dev -> reset = devm_reset_control_get_shared (dev , NULL );
853
857
if (IS_ERR (csi_dev -> reset )) {
854
858
dev_err (dev , "failed to acquire reset\n" );
855
- return PTR_ERR (csi_dev -> reset );
859
+ ret = PTR_ERR (csi_dev -> reset );
860
+ goto error_clock_rate_exclusive ;
856
861
}
857
862
858
863
/* Interrupt */
859
864
860
865
irq = platform_get_irq (platform_dev , 0 );
861
- if (irq < 0 )
862
- return - ENXIO ;
866
+ if (irq < 0 ) {
867
+ dev_err (dev , "failed to get interrupt\n" );
868
+ ret = - ENXIO ;
869
+ goto error_clock_rate_exclusive ;
870
+ }
863
871
864
872
ret = devm_request_irq (dev , irq , sun6i_csi_interrupt , 0 , SUN6I_CSI_NAME ,
865
873
csi_dev );
866
874
if (ret ) {
867
875
dev_err (dev , "failed to request interrupt\n" );
868
- return ret ;
876
+ goto error_clock_rate_exclusive ;
869
877
}
870
878
871
879
return 0 ;
880
+
881
+ error_clock_rate_exclusive :
882
+ clk_rate_exclusive_put (csi_dev -> clock_mod );
883
+
884
+ return ret ;
885
+ }
886
+
887
+ static void sun6i_csi_resources_cleanup (struct sun6i_csi_device * csi_dev )
888
+ {
889
+ clk_rate_exclusive_put (csi_dev -> clock_mod );
872
890
}
873
891
874
892
static int sun6i_csi_probe (struct platform_device * platform_dev )
@@ -888,14 +906,24 @@ static int sun6i_csi_probe(struct platform_device *platform_dev)
888
906
if (ret )
889
907
return ret ;
890
908
891
- return sun6i_csi_v4l2_init (csi_dev );
909
+ ret = sun6i_csi_v4l2_init (csi_dev );
910
+ if (ret )
911
+ goto error_resources ;
912
+
913
+ return 0 ;
914
+
915
+ error_resources :
916
+ sun6i_csi_resources_cleanup (csi_dev );
917
+
918
+ return ret ;
892
919
}
893
920
894
921
static int sun6i_csi_remove (struct platform_device * pdev )
895
922
{
896
923
struct sun6i_csi_device * csi_dev = platform_get_drvdata (pdev );
897
924
898
925
sun6i_csi_v4l2_cleanup (csi_dev );
926
+ sun6i_csi_resources_cleanup (csi_dev );
899
927
900
928
return 0 ;
901
929
}
0 commit comments