@@ -81,26 +81,10 @@ const char *lima_ip_name(struct lima_ip *ip)
8181 return lima_ip_desc [ip -> id ].name ;
8282}
8383
84- static int lima_clk_init (struct lima_device * dev )
84+ static int lima_clk_enable (struct lima_device * dev )
8585{
8686 int err ;
8787
88- dev -> clk_bus = devm_clk_get (dev -> dev , "bus" );
89- if (IS_ERR (dev -> clk_bus )) {
90- err = PTR_ERR (dev -> clk_bus );
91- if (err != - EPROBE_DEFER )
92- dev_err (dev -> dev , "get bus clk failed %d\n" , err );
93- return err ;
94- }
95-
96- dev -> clk_gpu = devm_clk_get (dev -> dev , "core" );
97- if (IS_ERR (dev -> clk_gpu )) {
98- err = PTR_ERR (dev -> clk_gpu );
99- if (err != - EPROBE_DEFER )
100- dev_err (dev -> dev , "get core clk failed %d\n" , err );
101- return err ;
102- }
103-
10488 err = clk_prepare_enable (dev -> clk_bus );
10589 if (err )
10690 return err ;
@@ -109,15 +93,7 @@ static int lima_clk_init(struct lima_device *dev)
10993 if (err )
11094 goto error_out0 ;
11195
112- dev -> reset = devm_reset_control_array_get_optional_shared (dev -> dev );
113-
114- if (IS_ERR (dev -> reset )) {
115- err = PTR_ERR (dev -> reset );
116- if (err != - EPROBE_DEFER )
117- dev_err (dev -> dev , "get reset controller failed %d\n" ,
118- err );
119- goto error_out1 ;
120- } else if (dev -> reset != NULL ) {
96+ if (dev -> reset ) {
12197 err = reset_control_deassert (dev -> reset );
12298 if (err ) {
12399 dev_err (dev -> dev ,
@@ -135,14 +111,76 @@ static int lima_clk_init(struct lima_device *dev)
135111 return err ;
136112}
137113
138- static void lima_clk_fini (struct lima_device * dev )
114+ static void lima_clk_disable (struct lima_device * dev )
139115{
140- if (dev -> reset != NULL )
116+ if (dev -> reset )
141117 reset_control_assert (dev -> reset );
142118 clk_disable_unprepare (dev -> clk_gpu );
143119 clk_disable_unprepare (dev -> clk_bus );
144120}
145121
122+ static int lima_clk_init (struct lima_device * dev )
123+ {
124+ int err ;
125+
126+ dev -> clk_bus = devm_clk_get (dev -> dev , "bus" );
127+ if (IS_ERR (dev -> clk_bus )) {
128+ err = PTR_ERR (dev -> clk_bus );
129+ if (err != - EPROBE_DEFER )
130+ dev_err (dev -> dev , "get bus clk failed %d\n" , err );
131+ dev -> clk_bus = NULL ;
132+ return err ;
133+ }
134+
135+ dev -> clk_gpu = devm_clk_get (dev -> dev , "core" );
136+ if (IS_ERR (dev -> clk_gpu )) {
137+ err = PTR_ERR (dev -> clk_gpu );
138+ if (err != - EPROBE_DEFER )
139+ dev_err (dev -> dev , "get core clk failed %d\n" , err );
140+ dev -> clk_gpu = NULL ;
141+ return err ;
142+ }
143+
144+ dev -> reset = devm_reset_control_array_get_optional_shared (dev -> dev );
145+ if (IS_ERR (dev -> reset )) {
146+ err = PTR_ERR (dev -> reset );
147+ if (err != - EPROBE_DEFER )
148+ dev_err (dev -> dev , "get reset controller failed %d\n" ,
149+ err );
150+ dev -> reset = NULL ;
151+ return err ;
152+ }
153+
154+ return lima_clk_enable (dev );
155+ }
156+
157+ static void lima_clk_fini (struct lima_device * dev )
158+ {
159+ lima_clk_disable (dev );
160+ }
161+
162+ static int lima_regulator_enable (struct lima_device * dev )
163+ {
164+ int ret ;
165+
166+ if (!dev -> regulator )
167+ return 0 ;
168+
169+ ret = regulator_enable (dev -> regulator );
170+ if (ret < 0 ) {
171+ dev_err (dev -> dev , "failed to enable regulator: %d\n" , ret );
172+ return ret ;
173+ }
174+
175+ return 0 ;
176+ }
177+
178+ static void lima_regulator_disable (struct lima_device * dev )
179+ {
180+ if (dev -> regulator )
181+ regulator_disable (dev -> regulator );
182+ }
183+
146184static int lima_regulator_init (struct lima_device * dev )
147185{
148186 int ret ;
@@ -158,19 +196,12 @@ static int lima_regulator_init(struct lima_device *dev)
158196 return ret ;
159197 }
160198
161- ret = regulator_enable (dev -> regulator );
162- if (ret < 0 ) {
163- dev_err (dev -> dev , "failed to enable regulator: %d\n" , ret );
164- return ret ;
165- }
166-
167- return 0 ;
199+ return lima_regulator_enable (dev );
168200}
169201
170202static void lima_regulator_fini (struct lima_device * dev )
171203{
172- if (dev -> regulator )
173- regulator_disable (dev -> regulator );
204+ lima_regulator_disable (dev );
174205}
175206
176207static int lima_init_ip (struct lima_device * dev , int index )
0 commit comments