blob: 6553dde45c2c2cd40e38ed08c72636936481a9d5 [file] [log] [blame]
developer84c7a632018-11-15 10:07:58 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2018 MediaTek Inc.
4 * Author: Ryder Lee <ryder.lee@mediatek.com>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <dm/device-internal.h>
10#include <dm/lists.h>
11#include <dm/pinctrl.h>
12#include <asm/io.h>
13#include <asm-generic/gpio.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
developer84c7a632018-11-15 10:07:58 +080015
16#include "pinctrl-mtk-common.h"
17
Fabien Parent105f6c82019-07-18 19:08:08 +020018#if CONFIG_IS_ENABLED(PINCONF)
developer84c7a632018-11-15 10:07:58 +080019/**
20 * struct mtk_drive_desc - the structure that holds the information
21 * of the driving current
22 * @min: the minimum current of this group
23 * @max: the maximum current of this group
24 * @step: the step current of this group
25 * @scal: the weight factor
26 *
27 * formula: output = ((input) / step - 1) * scal
28 */
29struct mtk_drive_desc {
30 u8 min;
31 u8 max;
32 u8 step;
33 u8 scal;
34};
35
36/* The groups of drive strength */
37static const struct mtk_drive_desc mtk_drive[] = {
38 [DRV_GRP0] = { 4, 16, 4, 1 },
39 [DRV_GRP1] = { 4, 16, 4, 2 },
40 [DRV_GRP2] = { 2, 8, 2, 1 },
41 [DRV_GRP3] = { 2, 8, 2, 2 },
42 [DRV_GRP4] = { 2, 16, 2, 1 },
43};
Fabien Parent105f6c82019-07-18 19:08:08 +020044#endif
developer84c7a632018-11-15 10:07:58 +080045
46static const char *mtk_pinctrl_dummy_name = "_dummy";
47
48static void mtk_w32(struct udevice *dev, u32 reg, u32 val)
49{
50 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
51
52 __raw_writel(val, priv->base + reg);
53}
54
55static u32 mtk_r32(struct udevice *dev, u32 reg)
56{
57 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
58
59 return __raw_readl(priv->base + reg);
60}
61
62static inline int get_count_order(unsigned int count)
63{
64 int order;
65
66 order = fls(count) - 1;
67 if (count & (count - 1))
68 order++;
69 return order;
70}
71
72void mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set)
73{
74 u32 val;
75
76 val = mtk_r32(dev, reg);
77 val &= ~mask;
78 val |= set;
79 mtk_w32(dev, reg, val);
80}
81
82static int mtk_hw_pin_field_lookup(struct udevice *dev, int pin,
83 const struct mtk_pin_reg_calc *rc,
84 struct mtk_pin_field *pfd)
85{
86 const struct mtk_pin_field_calc *c, *e;
87 u32 bits;
88
89 c = rc->range;
90 e = c + rc->nranges;
91
92 while (c < e) {
93 if (pin >= c->s_pin && pin <= c->e_pin)
94 break;
95 c++;
96 }
97
98 if (c >= e)
99 return -EINVAL;
100
101 /* Calculated bits as the overall offset the pin is located at,
102 * if c->fixed is held, that determines the all the pins in the
103 * range use the same field with the s_pin.
104 */
105 bits = c->fixed ? c->s_bit : c->s_bit + (pin - c->s_pin) * (c->x_bits);
106
107 /* Fill pfd from bits. For example 32-bit register applied is assumed
108 * when c->sz_reg is equal to 32.
109 */
110 pfd->offset = c->s_addr + c->x_addrs * (bits / c->sz_reg);
111 pfd->bitpos = bits % c->sz_reg;
112 pfd->mask = (1 << c->x_bits) - 1;
113
114 /* pfd->next is used for indicating that bit wrapping-around happens
115 * which requires the manipulation for bit 0 starting in the next
116 * register to form the complete field read/write.
117 */
118 pfd->next = pfd->bitpos + c->x_bits > c->sz_reg ? c->x_addrs : 0;
119
120 return 0;
121}
122
123static int mtk_hw_pin_field_get(struct udevice *dev, int pin,
124 int field, struct mtk_pin_field *pfd)
125{
126 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
127 const struct mtk_pin_reg_calc *rc;
128
129 if (field < 0 || field >= PINCTRL_PIN_REG_MAX)
130 return -EINVAL;
131
132 if (priv->soc->reg_cal && priv->soc->reg_cal[field].range)
133 rc = &priv->soc->reg_cal[field];
134 else
135 return -EINVAL;
136
137 return mtk_hw_pin_field_lookup(dev, pin, rc, pfd);
138}
139
140static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l)
141{
142 *l = 32 - pf->bitpos;
143 *h = get_count_order(pf->mask) - *l;
144}
145
146static void mtk_hw_write_cross_field(struct udevice *dev,
147 struct mtk_pin_field *pf, int value)
148{
149 int nbits_l, nbits_h;
150
151 mtk_hw_bits_part(pf, &nbits_h, &nbits_l);
152
153 mtk_rmw(dev, pf->offset, pf->mask << pf->bitpos,
154 (value & pf->mask) << pf->bitpos);
155
156 mtk_rmw(dev, pf->offset + pf->next, BIT(nbits_h) - 1,
157 (value & pf->mask) >> nbits_l);
158}
159
160static void mtk_hw_read_cross_field(struct udevice *dev,
161 struct mtk_pin_field *pf, int *value)
162{
163 int nbits_l, nbits_h, h, l;
164
165 mtk_hw_bits_part(pf, &nbits_h, &nbits_l);
166
167 l = (mtk_r32(dev, pf->offset) >> pf->bitpos) & (BIT(nbits_l) - 1);
168 h = (mtk_r32(dev, pf->offset + pf->next)) & (BIT(nbits_h) - 1);
169
170 *value = (h << nbits_l) | l;
171}
172
173static int mtk_hw_set_value(struct udevice *dev, int pin, int field,
174 int value)
175{
176 struct mtk_pin_field pf;
177 int err;
178
179 err = mtk_hw_pin_field_get(dev, pin, field, &pf);
180 if (err)
181 return err;
182
183 if (!pf.next)
184 mtk_rmw(dev, pf.offset, pf.mask << pf.bitpos,
185 (value & pf.mask) << pf.bitpos);
186 else
187 mtk_hw_write_cross_field(dev, &pf, value);
188
189 return 0;
190}
191
192static int mtk_hw_get_value(struct udevice *dev, int pin, int field,
193 int *value)
194{
195 struct mtk_pin_field pf;
196 int err;
197
198 err = mtk_hw_pin_field_get(dev, pin, field, &pf);
199 if (err)
200 return err;
201
202 if (!pf.next)
203 *value = (mtk_r32(dev, pf.offset) >> pf.bitpos) & pf.mask;
204 else
205 mtk_hw_read_cross_field(dev, &pf, value);
206
207 return 0;
208}
209
210static int mtk_get_groups_count(struct udevice *dev)
211{
212 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
213
214 return priv->soc->ngrps;
215}
216
217static const char *mtk_get_pin_name(struct udevice *dev,
218 unsigned int selector)
219{
220 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
221
222 if (!priv->soc->grps[selector].name)
223 return mtk_pinctrl_dummy_name;
224
225 return priv->soc->pins[selector].name;
226}
227
228static int mtk_get_pins_count(struct udevice *dev)
229{
230 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
231
232 return priv->soc->npins;
233}
234
235static const char *mtk_get_group_name(struct udevice *dev,
236 unsigned int selector)
237{
238 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
239
240 if (!priv->soc->grps[selector].name)
241 return mtk_pinctrl_dummy_name;
242
243 return priv->soc->grps[selector].name;
244}
245
246static int mtk_get_functions_count(struct udevice *dev)
247{
248 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
249
250 return priv->soc->nfuncs;
251}
252
253static const char *mtk_get_function_name(struct udevice *dev,
254 unsigned int selector)
255{
256 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
257
258 if (!priv->soc->funcs[selector].name)
259 return mtk_pinctrl_dummy_name;
260
261 return priv->soc->funcs[selector].name;
262}
263
264static int mtk_pinmux_group_set(struct udevice *dev,
265 unsigned int group_selector,
266 unsigned int func_selector)
267{
268 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
269 const struct mtk_group_desc *grp =
270 &priv->soc->grps[group_selector];
271 int i;
272
273 for (i = 0; i < grp->num_pins; i++) {
274 int *pin_modes = grp->data;
275
276 mtk_hw_set_value(dev, grp->pins[i], PINCTRL_PIN_REG_MODE,
277 pin_modes[i]);
278 }
279
280 return 0;
281}
282
283#if CONFIG_IS_ENABLED(PINCONF)
284static const struct pinconf_param mtk_conf_params[] = {
285 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
286 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
287 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
288 { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },
289 { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },
290 { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
291 { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
292 { "output-enable", PIN_CONFIG_OUTPUT_ENABLE, 1 },
293 { "output-high", PIN_CONFIG_OUTPUT, 1, },
294 { "output-low", PIN_CONFIG_OUTPUT, 0, },
295 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
296};
297
developer74d69012020-01-10 16:30:28 +0800298
David Woodhouse32102752020-06-19 12:40:20 +0100299int mtk_pinconf_bias_set_v0(struct udevice *dev, u32 pin, u32 arg, u32 val)
developer74d69012020-01-10 16:30:28 +0800300{
301 int err, disable, pullup;
302
303 disable = (arg == PIN_CONFIG_BIAS_DISABLE);
304 pullup = (arg == PIN_CONFIG_BIAS_PULL_UP);
305
306 if (disable) {
307 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PU, 0);
308 if (err)
309 return err;
310 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PD, 0);
311 if (err)
312 return err;
313
314 } else {
315 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PU, pullup);
316 if (err)
317 return err;
318 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PD, !pullup);
319 if (err)
320 return err;
321 }
322
323 return 0;
324}
325
David Woodhouse32102752020-06-19 12:40:20 +0100326int mtk_pinconf_bias_set_v1(struct udevice *dev, u32 pin, u32 arg, u32 val)
developer74d69012020-01-10 16:30:28 +0800327{
David Woodhouse32102752020-06-19 12:40:20 +0100328 int err, disable, pullup, r0, r1;
developer74d69012020-01-10 16:30:28 +0800329
330 disable = (arg == PIN_CONFIG_BIAS_DISABLE);
331 pullup = (arg == PIN_CONFIG_BIAS_PULL_UP);
David Woodhouse32102752020-06-19 12:40:20 +0100332 r0 = !!(val & 1);
333 r1 = !!(val & 2);
developer74d69012020-01-10 16:30:28 +0800334
335 if (disable) {
336 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLEN, 0);
337 if (err)
338 return err;
339 } else {
340 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLEN, 1);
341 if (err)
342 return err;
343 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLSEL,
344 pullup);
345 if (err)
346 return err;
347 }
348
David Woodhouse32102752020-06-19 12:40:20 +0100349 /* Also set PUPD/R0/R1 if the pin has them */
350 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PUPD, !pullup);
351 if (err != -EINVAL) {
352 mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_R0, r0);
353 mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_R1, r1);
354 }
355
developer74d69012020-01-10 16:30:28 +0800356 return 0;
357}
358
359int mtk_pinconf_input_enable_v1(struct udevice *dev, u32 pin, u32 arg)
360{
361 int err;
362
363 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_IES, 1);
364 if (err)
365 return err;
366 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DIR, 0);
367 if (err)
368 return err;
369 return 0;
370}
371
372int mtk_pinconf_drive_set_v0(struct udevice *dev, u32 pin, u32 arg)
developer84c7a632018-11-15 10:07:58 +0800373{
374 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
375 const struct mtk_pin_desc *desc = &priv->soc->pins[pin];
376 const struct mtk_drive_desc *tb;
377 int err = -ENOTSUPP;
378
379 tb = &mtk_drive[desc->drv_n];
380 /* 4mA when (e8, e4) = (0, 0)
381 * 8mA when (e8, e4) = (0, 1)
382 * 12mA when (e8, e4) = (1, 0)
383 * 16mA when (e8, e4) = (1, 1)
384 */
385 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
386 arg = (arg / tb->step - 1) * tb->scal;
developer74d69012020-01-10 16:30:28 +0800387 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_E4,
388 arg & 0x1);
389 if (err)
390 return err;
391 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_E8,
392 (arg & 0x2) >> 1);
393 if (err)
394 return err;
395 }
396
397 return 0;
398}
developer84c7a632018-11-15 10:07:58 +0800399
developer74d69012020-01-10 16:30:28 +0800400
401int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg)
402{
403 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
404 const struct mtk_pin_desc *desc = &priv->soc->pins[pin];
405 const struct mtk_drive_desc *tb;
406 int err = -ENOTSUPP;
407
408 tb = &mtk_drive[desc->drv_n];
409 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
410 arg = (arg / tb->step - 1) * tb->scal;
developer84c7a632018-11-15 10:07:58 +0800411 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DRV, arg);
412 if (err)
413 return err;
414 }
415
416 return 0;
417}
418
419static int mtk_pinconf_set(struct udevice *dev, unsigned int pin,
420 unsigned int param, unsigned int arg)
421{
422 int err = 0;
developer74d69012020-01-10 16:30:28 +0800423 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
424 int rev = priv->soc->rev;
developer84c7a632018-11-15 10:07:58 +0800425
426 switch (param) {
427 case PIN_CONFIG_BIAS_DISABLE:
428 case PIN_CONFIG_BIAS_PULL_UP:
429 case PIN_CONFIG_BIAS_PULL_DOWN:
developer74d69012020-01-10 16:30:28 +0800430 if (rev == MTK_PINCTRL_V0)
David Woodhouse32102752020-06-19 12:40:20 +0100431 err = mtk_pinconf_bias_set_v0(dev, pin, param, arg);
developer74d69012020-01-10 16:30:28 +0800432 else
David Woodhouse32102752020-06-19 12:40:20 +0100433 err = mtk_pinconf_bias_set_v1(dev, pin, param, arg);
developer84c7a632018-11-15 10:07:58 +0800434 if (err)
435 goto err;
436 break;
437 case PIN_CONFIG_OUTPUT_ENABLE:
438 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_SMT, 0);
439 if (err)
440 goto err;
441 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DIR, 1);
442 if (err)
443 goto err;
444 break;
445 case PIN_CONFIG_INPUT_ENABLE:
developer74d69012020-01-10 16:30:28 +0800446 if (rev == MTK_PINCTRL_V1)
447 err = mtk_pinconf_input_enable_v1(dev, pin, param);
developer84c7a632018-11-15 10:07:58 +0800448 if (err)
449 goto err;
450 break;
451 case PIN_CONFIG_OUTPUT:
452 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DIR, 1);
453 if (err)
454 goto err;
455
456 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DO, arg);
457 if (err)
458 goto err;
459 break;
460 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
461 /* arg = 1: Input mode & SMT enable ;
462 * arg = 0: Output mode & SMT disable
463 */
464 arg = arg ? 2 : 1;
465 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DIR,
466 arg & 1);
467 if (err)
468 goto err;
469
470 err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_SMT,
471 !!(arg & 2));
472 if (err)
473 goto err;
474 break;
475 case PIN_CONFIG_DRIVE_STRENGTH:
developer74d69012020-01-10 16:30:28 +0800476 if (rev == MTK_PINCTRL_V0)
477 err = mtk_pinconf_drive_set_v0(dev, pin, arg);
478 else
479 err = mtk_pinconf_drive_set_v1(dev, pin, arg);
developer84c7a632018-11-15 10:07:58 +0800480 if (err)
481 goto err;
482 break;
483
484 default:
485 err = -ENOTSUPP;
486 }
487
488err:
489
490 return err;
491}
492
493static int mtk_pinconf_group_set(struct udevice *dev,
494 unsigned int group_selector,
495 unsigned int param, unsigned int arg)
496{
497 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
498 const struct mtk_group_desc *grp =
499 &priv->soc->grps[group_selector];
500 int i, ret;
501
502 for (i = 0; i < grp->num_pins; i++) {
503 ret = mtk_pinconf_set(dev, grp->pins[i], param, arg);
504 if (ret)
505 return ret;
506 }
507
508 return 0;
509}
510#endif
511
512const struct pinctrl_ops mtk_pinctrl_ops = {
513 .get_pins_count = mtk_get_pins_count,
514 .get_pin_name = mtk_get_pin_name,
515 .get_groups_count = mtk_get_groups_count,
516 .get_group_name = mtk_get_group_name,
517 .get_functions_count = mtk_get_functions_count,
518 .get_function_name = mtk_get_function_name,
519 .pinmux_group_set = mtk_pinmux_group_set,
520#if CONFIG_IS_ENABLED(PINCONF)
521 .pinconf_num_params = ARRAY_SIZE(mtk_conf_params),
522 .pinconf_params = mtk_conf_params,
523 .pinconf_set = mtk_pinconf_set,
524 .pinconf_group_set = mtk_pinconf_group_set,
525#endif
526 .set_state = pinctrl_generic_set_state,
527};
528
529static int mtk_gpio_get(struct udevice *dev, unsigned int off)
530{
531 int val, err;
532
533 err = mtk_hw_get_value(dev->parent, off, PINCTRL_PIN_REG_DI, &val);
534 if (err)
535 return err;
536
537 return !!val;
538}
539
540static int mtk_gpio_set(struct udevice *dev, unsigned int off, int val)
541{
542 return mtk_hw_set_value(dev->parent, off, PINCTRL_PIN_REG_DO, !!val);
543}
544
545static int mtk_gpio_get_direction(struct udevice *dev, unsigned int off)
546{
547 int val, err;
548
549 err = mtk_hw_get_value(dev->parent, off, PINCTRL_PIN_REG_DIR, &val);
550 if (err)
551 return err;
552
553 return val ? GPIOF_OUTPUT : GPIOF_INPUT;
554}
555
556static int mtk_gpio_direction_input(struct udevice *dev, unsigned int off)
557{
558 return mtk_hw_set_value(dev->parent, off, PINCTRL_PIN_REG_DIR, 0);
559}
560
561static int mtk_gpio_direction_output(struct udevice *dev,
562 unsigned int off, int val)
563{
564 mtk_gpio_set(dev, off, val);
565
566 /* And set the requested value */
567 return mtk_hw_set_value(dev->parent, off, PINCTRL_PIN_REG_DIR, 1);
568}
569
570static int mtk_gpio_request(struct udevice *dev, unsigned int off,
571 const char *label)
572{
developer74d69012020-01-10 16:30:28 +0800573 struct mtk_pinctrl_priv *priv = dev_get_priv(dev->parent);
574
575 return mtk_hw_set_value(dev->parent, off, PINCTRL_PIN_REG_MODE,
576 priv->soc->gpio_mode);
developer84c7a632018-11-15 10:07:58 +0800577}
578
579static int mtk_gpio_probe(struct udevice *dev)
580{
581 struct mtk_pinctrl_priv *priv = dev_get_priv(dev->parent);
582 struct gpio_dev_priv *uc_priv;
583
584 uc_priv = dev_get_uclass_priv(dev);
585 uc_priv->bank_name = priv->soc->name;
586 uc_priv->gpio_count = priv->soc->npins;
587
588 return 0;
589}
590
591static const struct dm_gpio_ops mtk_gpio_ops = {
592 .request = mtk_gpio_request,
593 .set_value = mtk_gpio_set,
594 .get_value = mtk_gpio_get,
595 .get_function = mtk_gpio_get_direction,
596 .direction_input = mtk_gpio_direction_input,
597 .direction_output = mtk_gpio_direction_output,
598};
599
600static struct driver mtk_gpio_driver = {
601 .name = "mediatek_gpio",
602 .id = UCLASS_GPIO,
603 .probe = mtk_gpio_probe,
604 .ops = &mtk_gpio_ops,
605};
606
607static int mtk_gpiochip_register(struct udevice *parent)
608{
609 struct uclass_driver *drv;
610 struct udevice *dev;
611 int ret;
612 ofnode node;
613
614 drv = lists_uclass_lookup(UCLASS_GPIO);
615 if (!drv)
616 return -ENOENT;
617
618 dev_for_each_subnode(node, parent)
619 if (ofnode_read_bool(node, "gpio-controller")) {
620 ret = 0;
621 break;
622 }
623
624 if (ret)
625 return ret;
626
627 ret = device_bind_with_driver_data(parent, &mtk_gpio_driver,
628 "mediatek_gpio", 0, node,
629 &dev);
630 if (ret)
631 return ret;
632
633 return 0;
634}
635
636int mtk_pinctrl_common_probe(struct udevice *dev,
637 struct mtk_pinctrl_soc *soc)
638{
639 struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
640 int ret;
641
642 priv->base = dev_read_addr_ptr(dev);
Sean Anderson42db70b2020-06-24 06:41:13 -0400643 if (!priv->base)
developer84c7a632018-11-15 10:07:58 +0800644 return -EINVAL;
645
646 priv->soc = soc;
647
648 ret = mtk_gpiochip_register(dev);
649 if (ret)
650 return ret;
651
652 return 0;
653}