regulator: tps65910: Provide settling time for DCDC voltage change
[linux-2.6.git] / drivers / regulator / tps65910-regulator.c
1 /*
2  * tps65910.c  --  TI tps65910
3  *
4  * Copyright 2010 Texas Instruments Inc.
5  *
6  * Author: Graeme Gregory <gg@slimlogic.co.uk>
7  * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
8  *
9  *  This program is free software; you can redistribute it and/or modify it
10  *  under  the terms of the GNU General  Public License as published by the
11  *  Free Software Foundation;  either version 2 of the License, or (at your
12  *  option) any later version.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/err.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/gpio.h>
26 #include <linux/mfd/tps65910.h>
27
28 #define TPS65910_SUPPLY_STATE_ENABLED   0x1
29 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 |       \
30                         TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 |          \
31                         TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
32
33 /* supported VIO voltages in milivolts */
34 static const u16 VIO_VSEL_table[] = {
35         1500, 1800, 2500, 3300,
36 };
37
38 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
39
40 /* supported VDD3 voltages in milivolts */
41 static const u16 VDD3_VSEL_table[] = {
42         5000,
43 };
44
45 /* supported VDIG1 voltages in milivolts */
46 static const u16 VDIG1_VSEL_table[] = {
47         1200, 1500, 1800, 2700,
48 };
49
50 /* supported VDIG2 voltages in milivolts */
51 static const u16 VDIG2_VSEL_table[] = {
52         1000, 1100, 1200, 1800,
53 };
54
55 /* supported VPLL voltages in milivolts */
56 static const u16 VPLL_VSEL_table[] = {
57         1000, 1100, 1800, 2500,
58 };
59
60 /* supported VDAC voltages in milivolts */
61 static const u16 VDAC_VSEL_table[] = {
62         1800, 2600, 2800, 2850,
63 };
64
65 /* supported VAUX1 voltages in milivolts */
66 static const u16 VAUX1_VSEL_table[] = {
67         1800, 2500, 2800, 2850,
68 };
69
70 /* supported VAUX2 voltages in milivolts */
71 static const u16 VAUX2_VSEL_table[] = {
72         1800, 2800, 2900, 3300,
73 };
74
75 /* supported VAUX33 voltages in milivolts */
76 static const u16 VAUX33_VSEL_table[] = {
77         1800, 2000, 2800, 3300,
78 };
79
80 /* supported VMMC voltages in milivolts */
81 static const u16 VMMC_VSEL_table[] = {
82         1800, 2800, 3000, 3300,
83 };
84
85 struct tps_info {
86         const char *name;
87         unsigned min_uV;
88         unsigned max_uV;
89         u8 n_voltages;
90         const u16 *voltage_table;
91         int enable_time_us;
92 };
93
94 static struct tps_info tps65910_regs[] = {
95         {
96                 .name = "VRTC",
97                 .enable_time_us = 2200,
98         },
99         {
100                 .name = "VIO",
101                 .min_uV = 1500000,
102                 .max_uV = 3300000,
103                 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
104                 .voltage_table = VIO_VSEL_table,
105                 .enable_time_us = 350,
106         },
107         {
108                 .name = "VDD1",
109                 .min_uV = 600000,
110                 .max_uV = 4500000,
111                 .enable_time_us = 350,
112         },
113         {
114                 .name = "VDD2",
115                 .min_uV = 600000,
116                 .max_uV = 4500000,
117                 .enable_time_us = 350,
118         },
119         {
120                 .name = "VDD3",
121                 .min_uV = 5000000,
122                 .max_uV = 5000000,
123                 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
124                 .voltage_table = VDD3_VSEL_table,
125                 .enable_time_us = 200,
126         },
127         {
128                 .name = "VDIG1",
129                 .min_uV = 1200000,
130                 .max_uV = 2700000,
131                 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
132                 .voltage_table = VDIG1_VSEL_table,
133                 .enable_time_us = 100,
134         },
135         {
136                 .name = "VDIG2",
137                 .min_uV = 1000000,
138                 .max_uV = 1800000,
139                 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
140                 .voltage_table = VDIG2_VSEL_table,
141                 .enable_time_us = 100,
142         },
143         {
144                 .name = "VPLL",
145                 .min_uV = 1000000,
146                 .max_uV = 2500000,
147                 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
148                 .voltage_table = VPLL_VSEL_table,
149                 .enable_time_us = 100,
150         },
151         {
152                 .name = "VDAC",
153                 .min_uV = 1800000,
154                 .max_uV = 2850000,
155                 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
156                 .voltage_table = VDAC_VSEL_table,
157                 .enable_time_us = 100,
158         },
159         {
160                 .name = "VAUX1",
161                 .min_uV = 1800000,
162                 .max_uV = 2850000,
163                 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
164                 .voltage_table = VAUX1_VSEL_table,
165                 .enable_time_us = 100,
166         },
167         {
168                 .name = "VAUX2",
169                 .min_uV = 1800000,
170                 .max_uV = 3300000,
171                 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
172                 .voltage_table = VAUX2_VSEL_table,
173                 .enable_time_us = 100,
174         },
175         {
176                 .name = "VAUX33",
177                 .min_uV = 1800000,
178                 .max_uV = 3300000,
179                 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
180                 .voltage_table = VAUX33_VSEL_table,
181                 .enable_time_us = 100,
182         },
183         {
184                 .name = "VMMC",
185                 .min_uV = 1800000,
186                 .max_uV = 3300000,
187                 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
188                 .voltage_table = VMMC_VSEL_table,
189                 .enable_time_us = 100,
190         },
191 };
192
193 static struct tps_info tps65911_regs[] = {
194         {
195                 .name = "VRTC",
196                 .enable_time_us = 2200,
197         },
198         {
199                 .name = "VIO",
200                 .min_uV = 1500000,
201                 .max_uV = 3300000,
202                 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
203                 .voltage_table = VIO_VSEL_table,
204                 .enable_time_us = 350,
205         },
206         {
207                 .name = "VDD1",
208                 .min_uV = 600000,
209                 .max_uV = 4500000,
210                 .n_voltages = 73,
211                 .enable_time_us = 350,
212         },
213         {
214                 .name = "VDD2",
215                 .min_uV = 600000,
216                 .max_uV = 4500000,
217                 .n_voltages = 73,
218                 .enable_time_us = 350,
219         },
220         {
221                 .name = "VDDCTRL",
222                 .min_uV = 600000,
223                 .max_uV = 1400000,
224                 .n_voltages = 65,
225                 .enable_time_us = 900,
226         },
227         {
228                 .name = "LDO1",
229                 .min_uV = 1000000,
230                 .max_uV = 3300000,
231                 .n_voltages = 47,
232                 .enable_time_us = 420,
233         },
234         {
235                 .name = "LDO2",
236                 .min_uV = 1000000,
237                 .max_uV = 3300000,
238                 .n_voltages = 47,
239                 .enable_time_us = 420,
240         },
241         {
242                 .name = "LDO3",
243                 .min_uV = 1000000,
244                 .max_uV = 3300000,
245                 .n_voltages = 24,
246                 .enable_time_us = 230,
247         },
248         {
249                 .name = "LDO4",
250                 .min_uV = 1000000,
251                 .max_uV = 3300000,
252                 .n_voltages = 47,
253                 .enable_time_us = 230,
254         },
255         {
256                 .name = "LDO5",
257                 .min_uV = 1000000,
258                 .max_uV = 3300000,
259                 .n_voltages = 24,
260                 .enable_time_us = 230,
261         },
262         {
263                 .name = "LDO6",
264                 .min_uV = 1000000,
265                 .max_uV = 3300000,
266                 .n_voltages = 24,
267                 .enable_time_us = 230,
268         },
269         {
270                 .name = "LDO7",
271                 .min_uV = 1000000,
272                 .max_uV = 3300000,
273                 .n_voltages = 24,
274                 .enable_time_us = 230,
275         },
276         {
277                 .name = "LDO8",
278                 .min_uV = 1000000,
279                 .max_uV = 3300000,
280                 .n_voltages = 24,
281                 .enable_time_us = 230,
282         },
283 };
284
285 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
286 static unsigned int tps65910_ext_sleep_control[] = {
287         0,
288         EXT_CONTROL_REG_BITS(VIO,    1, 0),
289         EXT_CONTROL_REG_BITS(VDD1,   1, 1),
290         EXT_CONTROL_REG_BITS(VDD2,   1, 2),
291         EXT_CONTROL_REG_BITS(VDD3,   1, 3),
292         EXT_CONTROL_REG_BITS(VDIG1,  0, 1),
293         EXT_CONTROL_REG_BITS(VDIG2,  0, 2),
294         EXT_CONTROL_REG_BITS(VPLL,   0, 6),
295         EXT_CONTROL_REG_BITS(VDAC,   0, 7),
296         EXT_CONTROL_REG_BITS(VAUX1,  0, 3),
297         EXT_CONTROL_REG_BITS(VAUX2,  0, 4),
298         EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
299         EXT_CONTROL_REG_BITS(VMMC,   0, 0),
300 };
301
302 static unsigned int tps65911_ext_sleep_control[] = {
303         0,
304         EXT_CONTROL_REG_BITS(VIO,     1, 0),
305         EXT_CONTROL_REG_BITS(VDD1,    1, 1),
306         EXT_CONTROL_REG_BITS(VDD2,    1, 2),
307         EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
308         EXT_CONTROL_REG_BITS(LDO1,    0, 1),
309         EXT_CONTROL_REG_BITS(LDO2,    0, 2),
310         EXT_CONTROL_REG_BITS(LDO3,    0, 7),
311         EXT_CONTROL_REG_BITS(LDO4,    0, 6),
312         EXT_CONTROL_REG_BITS(LDO5,    0, 3),
313         EXT_CONTROL_REG_BITS(LDO6,    0, 0),
314         EXT_CONTROL_REG_BITS(LDO7,    0, 5),
315         EXT_CONTROL_REG_BITS(LDO8,    0, 4),
316 };
317
318 struct tps65910_reg {
319         struct regulator_desc *desc;
320         struct tps65910 *mfd;
321         struct regulator_dev **rdev;
322         struct tps_info **info;
323         struct mutex mutex;
324         int num_regulators;
325         int mode;
326         int  (*get_ctrl_reg)(int);
327         unsigned int *ext_sleep_control;
328         unsigned int board_ext_control[TPS65910_NUM_REGS];
329 };
330
331 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
332 {
333         u8 val;
334         int err;
335
336         err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
337         if (err)
338                 return err;
339
340         return val;
341 }
342
343 static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
344 {
345         return pmic->mfd->write(pmic->mfd, reg, 1, &val);
346 }
347
348 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
349                                         u8 set_mask, u8 clear_mask)
350 {
351         int err, data;
352
353         mutex_lock(&pmic->mutex);
354
355         data = tps65910_read(pmic, reg);
356         if (data < 0) {
357                 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
358                 err = data;
359                 goto out;
360         }
361
362         data &= ~clear_mask;
363         data |= set_mask;
364         err = tps65910_write(pmic, reg, data);
365         if (err)
366                 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
367
368 out:
369         mutex_unlock(&pmic->mutex);
370         return err;
371 }
372
373 static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
374 {
375         int data;
376
377         mutex_lock(&pmic->mutex);
378
379         data = tps65910_read(pmic, reg);
380         if (data < 0)
381                 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
382
383         mutex_unlock(&pmic->mutex);
384         return data;
385 }
386
387 static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
388 {
389         int err;
390
391         mutex_lock(&pmic->mutex);
392
393         err = tps65910_write(pmic, reg, val);
394         if (err < 0)
395                 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
396
397         mutex_unlock(&pmic->mutex);
398         return err;
399 }
400
401 static int tps65910_get_ctrl_register(int id)
402 {
403         switch (id) {
404         case TPS65910_REG_VRTC:
405                 return TPS65910_VRTC;
406         case TPS65910_REG_VIO:
407                 return TPS65910_VIO;
408         case TPS65910_REG_VDD1:
409                 return TPS65910_VDD1;
410         case TPS65910_REG_VDD2:
411                 return TPS65910_VDD2;
412         case TPS65910_REG_VDD3:
413                 return TPS65910_VDD3;
414         case TPS65910_REG_VDIG1:
415                 return TPS65910_VDIG1;
416         case TPS65910_REG_VDIG2:
417                 return TPS65910_VDIG2;
418         case TPS65910_REG_VPLL:
419                 return TPS65910_VPLL;
420         case TPS65910_REG_VDAC:
421                 return TPS65910_VDAC;
422         case TPS65910_REG_VAUX1:
423                 return TPS65910_VAUX1;
424         case TPS65910_REG_VAUX2:
425                 return TPS65910_VAUX2;
426         case TPS65910_REG_VAUX33:
427                 return TPS65910_VAUX33;
428         case TPS65910_REG_VMMC:
429                 return TPS65910_VMMC;
430         default:
431                 return -EINVAL;
432         }
433 }
434
435 static int tps65911_get_ctrl_register(int id)
436 {
437         switch (id) {
438         case TPS65910_REG_VRTC:
439                 return TPS65910_VRTC;
440         case TPS65910_REG_VIO:
441                 return TPS65910_VIO;
442         case TPS65910_REG_VDD1:
443                 return TPS65910_VDD1;
444         case TPS65910_REG_VDD2:
445                 return TPS65910_VDD2;
446         case TPS65911_REG_VDDCTRL:
447                 return TPS65911_VDDCTRL;
448         case TPS65911_REG_LDO1:
449                 return TPS65911_LDO1;
450         case TPS65911_REG_LDO2:
451                 return TPS65911_LDO2;
452         case TPS65911_REG_LDO3:
453                 return TPS65911_LDO3;
454         case TPS65911_REG_LDO4:
455                 return TPS65911_LDO4;
456         case TPS65911_REG_LDO5:
457                 return TPS65911_LDO5;
458         case TPS65911_REG_LDO6:
459                 return TPS65911_LDO6;
460         case TPS65911_REG_LDO7:
461                 return TPS65911_LDO7;
462         case TPS65911_REG_LDO8:
463                 return TPS65911_LDO8;
464         default:
465                 return -EINVAL;
466         }
467 }
468
469 static int tps65910_is_enabled(struct regulator_dev *dev)
470 {
471         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
472         int reg, value, id = rdev_get_id(dev);
473
474         reg = pmic->get_ctrl_reg(id);
475         if (reg < 0)
476                 return reg;
477
478         value = tps65910_reg_read(pmic, reg);
479         if (value < 0)
480                 return value;
481
482         return value & TPS65910_SUPPLY_STATE_ENABLED;
483 }
484
485 static int tps65910_enable(struct regulator_dev *dev)
486 {
487         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
488         struct tps65910 *mfd = pmic->mfd;
489         int reg, id = rdev_get_id(dev);
490
491         reg = pmic->get_ctrl_reg(id);
492         if (reg < 0)
493                 return reg;
494
495         return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
496 }
497
498 static int tps65910_disable(struct regulator_dev *dev)
499 {
500         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
501         struct tps65910 *mfd = pmic->mfd;
502         int reg, id = rdev_get_id(dev);
503
504         reg = pmic->get_ctrl_reg(id);
505         if (reg < 0)
506                 return reg;
507
508         return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
509 }
510
511 static int tps65910_enable_time(struct regulator_dev *dev)
512 {
513         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
514         int id = rdev_get_id(dev);
515         return pmic->info[id]->enable_time_us;
516 }
517
518 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
519 {
520         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
521         struct tps65910 *mfd = pmic->mfd;
522         int reg, value, id = rdev_get_id(dev);
523
524         reg = pmic->get_ctrl_reg(id);
525         if (reg < 0)
526                 return reg;
527
528         switch (mode) {
529         case REGULATOR_MODE_NORMAL:
530                 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
531                                                         LDO_ST_MODE_BIT);
532         case REGULATOR_MODE_IDLE:
533                 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
534                 return tps65910_set_bits(mfd, reg, value);
535         case REGULATOR_MODE_STANDBY:
536                 return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
537         }
538
539         return -EINVAL;
540 }
541
542 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
543 {
544         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
545         int reg, value, id = rdev_get_id(dev);
546
547         reg = pmic->get_ctrl_reg(id);
548         if (reg < 0)
549                 return reg;
550
551         value = tps65910_reg_read(pmic, reg);
552         if (value < 0)
553                 return value;
554
555         if (!(value & LDO_ST_ON_BIT))
556                 return REGULATOR_MODE_STANDBY;
557         else if (value & LDO_ST_MODE_BIT)
558                 return REGULATOR_MODE_IDLE;
559         else
560                 return REGULATOR_MODE_NORMAL;
561 }
562
563 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
564 {
565         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
566         int id = rdev_get_id(dev);
567         int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
568
569         switch (id) {
570         case TPS65910_REG_VDD1:
571                 opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
572                 mult = tps65910_reg_read(pmic, TPS65910_VDD1);
573                 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
574                 srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
575                 sr = opvsel & VDD1_OP_CMD_MASK;
576                 opvsel &= VDD1_OP_SEL_MASK;
577                 srvsel &= VDD1_SR_SEL_MASK;
578                 vselmax = 75;
579                 break;
580         case TPS65910_REG_VDD2:
581                 opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
582                 mult = tps65910_reg_read(pmic, TPS65910_VDD2);
583                 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
584                 srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
585                 sr = opvsel & VDD2_OP_CMD_MASK;
586                 opvsel &= VDD2_OP_SEL_MASK;
587                 srvsel &= VDD2_SR_SEL_MASK;
588                 vselmax = 75;
589                 break;
590         case TPS65911_REG_VDDCTRL:
591                 opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
592                 srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
593                 sr = opvsel & VDDCTRL_OP_CMD_MASK;
594                 opvsel &= VDDCTRL_OP_SEL_MASK;
595                 srvsel &= VDDCTRL_SR_SEL_MASK;
596                 vselmax = 64;
597                 break;
598         }
599
600         /* multiplier 0 == 1 but 2,3 normal */
601         if (!mult)
602                 mult=1;
603
604         if (sr) {
605                 /* normalise to valid range */
606                 if (srvsel < 3)
607                         srvsel = 3;
608                 if (srvsel > vselmax)
609                         srvsel = vselmax;
610                 return srvsel - 3;
611         } else {
612
613                 /* normalise to valid range*/
614                 if (opvsel < 3)
615                         opvsel = 3;
616                 if (opvsel > vselmax)
617                         opvsel = vselmax;
618                 return opvsel - 3;
619         }
620         return -EINVAL;
621 }
622
623 static int tps65910_get_voltage(struct regulator_dev *dev)
624 {
625         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
626         int reg, value, id = rdev_get_id(dev), voltage = 0;
627
628         reg = pmic->get_ctrl_reg(id);
629         if (reg < 0)
630                 return reg;
631
632         value = tps65910_reg_read(pmic, reg);
633         if (value < 0)
634                 return value;
635
636         switch (id) {
637         case TPS65910_REG_VIO:
638         case TPS65910_REG_VDIG1:
639         case TPS65910_REG_VDIG2:
640         case TPS65910_REG_VPLL:
641         case TPS65910_REG_VDAC:
642         case TPS65910_REG_VAUX1:
643         case TPS65910_REG_VAUX2:
644         case TPS65910_REG_VAUX33:
645         case TPS65910_REG_VMMC:
646                 value &= LDO_SEL_MASK;
647                 value >>= LDO_SEL_SHIFT;
648                 break;
649         default:
650                 return -EINVAL;
651         }
652
653         voltage = pmic->info[id]->voltage_table[value] * 1000;
654
655         return voltage;
656 }
657
658 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
659 {
660         return 5 * 1000 * 1000;
661 }
662
663 static int tps65911_get_voltage(struct regulator_dev *dev)
664 {
665         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
666         int step_mv, id = rdev_get_id(dev);
667         u8 value, reg;
668
669         reg = pmic->get_ctrl_reg(id);
670
671         value = tps65910_reg_read(pmic, reg);
672
673         switch (id) {
674         case TPS65911_REG_LDO1:
675         case TPS65911_REG_LDO2:
676         case TPS65911_REG_LDO4:
677                 value &= LDO1_SEL_MASK;
678                 value >>= LDO_SEL_SHIFT;
679                 /* The first 5 values of the selector correspond to 1V */
680                 if (value < 5)
681                         value = 0;
682                 else
683                         value -= 4;
684
685                 step_mv = 50;
686                 break;
687         case TPS65911_REG_LDO3:
688         case TPS65911_REG_LDO5:
689         case TPS65911_REG_LDO6:
690         case TPS65911_REG_LDO7:
691         case TPS65911_REG_LDO8:
692                 value &= LDO3_SEL_MASK;
693                 value >>= LDO_SEL_SHIFT;
694                 /* The first 3 values of the selector correspond to 1V */
695                 if (value < 3)
696                         value = 0;
697                 else
698                         value -= 2;
699
700                 step_mv = 100;
701                 break;
702         case TPS65910_REG_VIO:
703                 value &= LDO_SEL_MASK;
704                 value >>= LDO_SEL_SHIFT;
705                 return pmic->info[id]->voltage_table[value] * 1000;
706         default:
707                 return -EINVAL;
708         }
709
710         return (LDO_MIN_VOLT + value * step_mv) * 1000;
711 }
712
713 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
714                                          unsigned selector)
715 {
716         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
717         int id = rdev_get_id(dev), vsel;
718         int dcdc_mult = 0;
719
720         switch (id) {
721         case TPS65910_REG_VDD1:
722                 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
723                 if (dcdc_mult == 1)
724                         dcdc_mult--;
725                 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
726
727                 tps65910_modify_bits(pmic, TPS65910_VDD1,
728                                 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
729                                                 VDD1_VGAIN_SEL_MASK);
730                 tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
731                 break;
732         case TPS65910_REG_VDD2:
733                 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
734                 if (dcdc_mult == 1)
735                         dcdc_mult--;
736                 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
737
738                 tps65910_modify_bits(pmic, TPS65910_VDD2,
739                                 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
740                                                 VDD1_VGAIN_SEL_MASK);
741                 tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
742                 break;
743         case TPS65911_REG_VDDCTRL:
744                 vsel = selector + 3;
745                 tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
746         }
747
748         return 0;
749 }
750
751 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
752                                     unsigned selector)
753 {
754         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
755         int reg, id = rdev_get_id(dev);
756
757         reg = pmic->get_ctrl_reg(id);
758         if (reg < 0)
759                 return reg;
760
761         switch (id) {
762         case TPS65910_REG_VIO:
763         case TPS65910_REG_VDIG1:
764         case TPS65910_REG_VDIG2:
765         case TPS65910_REG_VPLL:
766         case TPS65910_REG_VDAC:
767         case TPS65910_REG_VAUX1:
768         case TPS65910_REG_VAUX2:
769         case TPS65910_REG_VAUX33:
770         case TPS65910_REG_VMMC:
771                 return tps65910_modify_bits(pmic, reg,
772                                 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
773         }
774
775         return -EINVAL;
776 }
777
778 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
779                                     unsigned selector)
780 {
781         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
782         int reg, id = rdev_get_id(dev);
783
784         reg = pmic->get_ctrl_reg(id);
785         if (reg < 0)
786                 return reg;
787
788         switch (id) {
789         case TPS65911_REG_LDO1:
790         case TPS65911_REG_LDO2:
791         case TPS65911_REG_LDO4:
792                 return tps65910_modify_bits(pmic, reg,
793                                 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
794         case TPS65911_REG_LDO3:
795         case TPS65911_REG_LDO5:
796         case TPS65911_REG_LDO6:
797         case TPS65911_REG_LDO7:
798         case TPS65911_REG_LDO8:
799                 return tps65910_modify_bits(pmic, reg,
800                                 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
801         case TPS65910_REG_VIO:
802                 return tps65910_modify_bits(pmic, reg,
803                                 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
804         }
805
806         return -EINVAL;
807 }
808
809
810 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
811                                         unsigned selector)
812 {
813         int volt, mult = 1, id = rdev_get_id(dev);
814
815         switch (id) {
816         case TPS65910_REG_VDD1:
817         case TPS65910_REG_VDD2:
818                 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
819                 volt = VDD1_2_MIN_VOLT +
820                                 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
821                 break;
822         case TPS65911_REG_VDDCTRL:
823                 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
824                 break;
825         default:
826                 BUG();
827                 return -EINVAL;
828         }
829
830         return  volt * 100 * mult;
831 }
832
833 static int tps65910_list_voltage(struct regulator_dev *dev,
834                                         unsigned selector)
835 {
836         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
837         int id = rdev_get_id(dev), voltage;
838
839         if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
840                 return -EINVAL;
841
842         if (selector >= pmic->info[id]->n_voltages)
843                 return -EINVAL;
844         else
845                 voltage = pmic->info[id]->voltage_table[selector] * 1000;
846
847         return voltage;
848 }
849
850 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
851 {
852         struct tps65910_reg *pmic = rdev_get_drvdata(dev);
853         int step_mv = 0, id = rdev_get_id(dev);
854
855         switch(id) {
856         case TPS65911_REG_LDO1:
857         case TPS65911_REG_LDO2:
858         case TPS65911_REG_LDO4:
859                 /* The first 5 values of the selector correspond to 1V */
860                 if (selector < 5)
861                         selector = 0;
862                 else
863                         selector -= 4;
864
865                 step_mv = 50;
866                 break;
867         case TPS65911_REG_LDO3:
868         case TPS65911_REG_LDO5:
869         case TPS65911_REG_LDO6:
870         case TPS65911_REG_LDO7:
871         case TPS65911_REG_LDO8:
872                 /* The first 3 values of the selector correspond to 1V */
873                 if (selector < 3)
874                         selector = 0;
875                 else
876                         selector -= 2;
877
878                 step_mv = 100;
879                 break;
880         case TPS65910_REG_VIO:
881                 return pmic->info[id]->voltage_table[selector] * 1000;
882         default:
883                 return -EINVAL;
884         }
885
886         return (LDO_MIN_VOLT + selector * step_mv) * 1000;
887 }
888
889 static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev,
890                 unsigned int old_selector, unsigned int new_selector)
891 {
892         int id = rdev_get_id(dev);
893         int old_volt, new_volt;
894
895         old_volt = tps65910_list_voltage_dcdc(dev, old_selector);
896         if (old_volt < 0)
897                 return old_volt;
898
899         new_volt = tps65910_list_voltage_dcdc(dev, new_selector);
900         if (new_volt < 0)
901                 return new_volt;
902
903         /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
904         switch (id) {
905         case TPS65910_REG_VDD1:
906         case TPS65910_REG_VDD2:
907                 return DIV_ROUND_UP(abs(old_volt - new_volt), 12500);
908         case TPS65911_REG_VDDCTRL:
909                 return DIV_ROUND_UP(abs(old_volt - new_volt), 5000);
910         }
911         return -EINVAL;
912 }
913
914 /* Regulator ops (except VRTC) */
915 static struct regulator_ops tps65910_ops_dcdc = {
916         .is_enabled             = tps65910_is_enabled,
917         .enable                 = tps65910_enable,
918         .disable                = tps65910_disable,
919         .enable_time            = tps65910_enable_time,
920         .set_mode               = tps65910_set_mode,
921         .get_mode               = tps65910_get_mode,
922         .get_voltage_sel        = tps65910_get_voltage_dcdc_sel,
923         .set_voltage_sel        = tps65910_set_voltage_dcdc_sel,
924         .set_voltage_time_sel   = tps65910_set_voltage_dcdc_time_sel,
925         .list_voltage           = tps65910_list_voltage_dcdc,
926 };
927
928 static struct regulator_ops tps65910_ops_vdd3 = {
929         .is_enabled             = tps65910_is_enabled,
930         .enable                 = tps65910_enable,
931         .disable                = tps65910_disable,
932         .enable_time            = tps65910_enable_time,
933         .set_mode               = tps65910_set_mode,
934         .get_mode               = tps65910_get_mode,
935         .get_voltage            = tps65910_get_voltage_vdd3,
936         .list_voltage           = tps65910_list_voltage,
937 };
938
939 static struct regulator_ops tps65910_ops = {
940         .is_enabled             = tps65910_is_enabled,
941         .enable                 = tps65910_enable,
942         .disable                = tps65910_disable,
943         .enable_time            = tps65910_enable_time,
944         .set_mode               = tps65910_set_mode,
945         .get_mode               = tps65910_get_mode,
946         .get_voltage            = tps65910_get_voltage,
947         .set_voltage_sel        = tps65910_set_voltage_sel,
948         .list_voltage           = tps65910_list_voltage,
949 };
950
951 static struct regulator_ops tps65911_ops = {
952         .is_enabled             = tps65910_is_enabled,
953         .enable                 = tps65910_enable,
954         .disable                = tps65910_disable,
955         .enable_time            = tps65910_enable_time,
956         .set_mode               = tps65910_set_mode,
957         .get_mode               = tps65910_get_mode,
958         .get_voltage            = tps65911_get_voltage,
959         .set_voltage_sel        = tps65911_set_voltage_sel,
960         .list_voltage           = tps65911_list_voltage,
961 };
962
963 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
964                 int id, int ext_sleep_config)
965 {
966         struct tps65910 *mfd = pmic->mfd;
967         u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
968         u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
969         int ret;
970
971         /*
972          * Regulator can not be control from multiple external input EN1, EN2
973          * and EN3 together.
974          */
975         if (ext_sleep_config & EXT_SLEEP_CONTROL) {
976                 int en_count;
977                 en_count = ((ext_sleep_config &
978                                 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
979                 en_count += ((ext_sleep_config &
980                                 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
981                 en_count += ((ext_sleep_config &
982                                 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
983                 if (en_count > 1) {
984                         dev_err(mfd->dev,
985                                 "External sleep control flag is not proper\n");
986                         return -EINVAL;
987                 }
988         }
989
990         pmic->board_ext_control[id] = ext_sleep_config;
991
992         /* External EN1 control */
993         if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
994                 ret = tps65910_set_bits(mfd,
995                                 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
996         else
997                 ret = tps65910_clear_bits(mfd,
998                                 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
999         if (ret < 0) {
1000                 dev_err(mfd->dev,
1001                         "Error in configuring external control EN1\n");
1002                 return ret;
1003         }
1004
1005         /* External EN2 control */
1006         if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
1007                 ret = tps65910_set_bits(mfd,
1008                                 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
1009         else
1010                 ret = tps65910_clear_bits(mfd,
1011                                 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
1012         if (ret < 0) {
1013                 dev_err(mfd->dev,
1014                         "Error in configuring external control EN2\n");
1015                 return ret;
1016         }
1017
1018         /* External EN3 control for TPS65910 LDO only */
1019         if ((tps65910_chip_id(mfd) == TPS65910) &&
1020                         (id >= TPS65910_REG_VDIG1)) {
1021                 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
1022                         ret = tps65910_set_bits(mfd,
1023                                 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
1024                 else
1025                         ret = tps65910_clear_bits(mfd,
1026                                 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
1027                 if (ret < 0) {
1028                         dev_err(mfd->dev,
1029                                 "Error in configuring external control EN3\n");
1030                         return ret;
1031                 }
1032         }
1033
1034         /* Return if no external control is selected */
1035         if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
1036                 /* Clear all sleep controls */
1037                 ret = tps65910_clear_bits(mfd,
1038                         TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
1039                 if (!ret)
1040                         ret = tps65910_clear_bits(mfd,
1041                                 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1042                 if (ret < 0)
1043                         dev_err(mfd->dev,
1044                                 "Error in configuring SLEEP register\n");
1045                 return ret;
1046         }
1047
1048         /*
1049          * For regulator that has separate operational and sleep register make
1050          * sure that operational is used and clear sleep register to turn
1051          * regulator off when external control is inactive
1052          */
1053         if ((id == TPS65910_REG_VDD1) ||
1054                 (id == TPS65910_REG_VDD2) ||
1055                         ((id == TPS65911_REG_VDDCTRL) &&
1056                                 (tps65910_chip_id(mfd) == TPS65911))) {
1057                 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
1058                 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
1059                 int opvsel = tps65910_reg_read(pmic, op_reg_add);
1060                 int srvsel = tps65910_reg_read(pmic, sr_reg_add);
1061                 if (opvsel & VDD1_OP_CMD_MASK) {
1062                         u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
1063                         ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
1064                         if (ret < 0) {
1065                                 dev_err(mfd->dev,
1066                                         "Error in configuring op register\n");
1067                                 return ret;
1068                         }
1069                 }
1070                 ret = tps65910_reg_write(pmic, sr_reg_add, 0);
1071                 if (ret < 0) {
1072                         dev_err(mfd->dev, "Error in settting sr register\n");
1073                         return ret;
1074                 }
1075         }
1076
1077         ret = tps65910_clear_bits(mfd,
1078                         TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
1079         if (!ret)
1080                 ret = tps65910_set_bits(mfd,
1081                         TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1082         if (ret < 0)
1083                 dev_err(mfd->dev,
1084                         "Error in configuring SLEEP register\n");
1085         return ret;
1086 }
1087
1088 static __devinit int tps65910_probe(struct platform_device *pdev)
1089 {
1090         struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1091         struct tps_info *info;
1092         struct regulator_init_data *reg_data;
1093         struct regulator_dev *rdev;
1094         struct tps65910_reg *pmic;
1095         struct tps65910_board *pmic_plat_data;
1096         int i, err;
1097
1098         pmic_plat_data = dev_get_platdata(tps65910->dev);
1099         if (!pmic_plat_data)
1100                 return -EINVAL;
1101
1102         pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
1103         if (!pmic)
1104                 return -ENOMEM;
1105
1106         mutex_init(&pmic->mutex);
1107         pmic->mfd = tps65910;
1108         platform_set_drvdata(pdev, pmic);
1109
1110         /* Give control of all register to control port */
1111         tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1112                                 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1113
1114         switch(tps65910_chip_id(tps65910)) {
1115         case TPS65910:
1116                 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1117                 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1118                 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1119                 info = tps65910_regs;
1120                 break;
1121         case TPS65911:
1122                 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1123                 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1124                 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1125                 info = tps65911_regs;
1126                 break;
1127         default:
1128                 pr_err("Invalid tps chip version\n");
1129                 kfree(pmic);
1130                 return -ENODEV;
1131         }
1132
1133         pmic->desc = kcalloc(pmic->num_regulators,
1134                         sizeof(struct regulator_desc), GFP_KERNEL);
1135         if (!pmic->desc) {
1136                 err = -ENOMEM;
1137                 goto err_free_pmic;
1138         }
1139
1140         pmic->info = kcalloc(pmic->num_regulators,
1141                         sizeof(struct tps_info *), GFP_KERNEL);
1142         if (!pmic->info) {
1143                 err = -ENOMEM;
1144                 goto err_free_desc;
1145         }
1146
1147         pmic->rdev = kcalloc(pmic->num_regulators,
1148                         sizeof(struct regulator_dev *), GFP_KERNEL);
1149         if (!pmic->rdev) {
1150                 err = -ENOMEM;
1151                 goto err_free_info;
1152         }
1153
1154         for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1155                         i++, info++) {
1156
1157                 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1158
1159                 /* Regulator API handles empty constraints but not NULL
1160                  * constraints */
1161                 if (!reg_data)
1162                         continue;
1163
1164                 /* Register the regulators */
1165                 pmic->info[i] = info;
1166
1167                 pmic->desc[i].name = info->name;
1168                 pmic->desc[i].id = i;
1169                 pmic->desc[i].n_voltages = info->n_voltages;
1170
1171                 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1172                         pmic->desc[i].ops = &tps65910_ops_dcdc;
1173                         pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1174                                                         VDD1_2_NUM_VOLT_COARSE;
1175                 } else if (i == TPS65910_REG_VDD3) {
1176                         if (tps65910_chip_id(tps65910) == TPS65910)
1177                                 pmic->desc[i].ops = &tps65910_ops_vdd3;
1178                         else
1179                                 pmic->desc[i].ops = &tps65910_ops_dcdc;
1180                 } else {
1181                         if (tps65910_chip_id(tps65910) == TPS65910)
1182                                 pmic->desc[i].ops = &tps65910_ops;
1183                         else
1184                                 pmic->desc[i].ops = &tps65911_ops;
1185                 }
1186
1187                 err = tps65910_set_ext_sleep_config(pmic, i,
1188                                 pmic_plat_data->regulator_ext_sleep_control[i]);
1189                 /*
1190                  * Failing on regulator for configuring externally control
1191                  * is not a serious issue, just throw warning.
1192                  */
1193                 if (err < 0)
1194                         dev_warn(tps65910->dev,
1195                                 "Failed to initialise ext control config\n");
1196
1197                 pmic->desc[i].type = REGULATOR_VOLTAGE;
1198                 pmic->desc[i].owner = THIS_MODULE;
1199
1200                 rdev = regulator_register(&pmic->desc[i],
1201                                 tps65910->dev, reg_data, pmic, NULL);
1202                 if (IS_ERR(rdev)) {
1203                         dev_err(tps65910->dev,
1204                                 "failed to register %s regulator\n",
1205                                 pdev->name);
1206                         err = PTR_ERR(rdev);
1207                         goto err_unregister_regulator;
1208                 }
1209
1210                 /* Save regulator for cleanup */
1211                 pmic->rdev[i] = rdev;
1212         }
1213         return 0;
1214
1215 err_unregister_regulator:
1216         while (--i >= 0)
1217                 regulator_unregister(pmic->rdev[i]);
1218         kfree(pmic->rdev);
1219 err_free_info:
1220         kfree(pmic->info);
1221 err_free_desc:
1222         kfree(pmic->desc);
1223 err_free_pmic:
1224         kfree(pmic);
1225         return err;
1226 }
1227
1228 static int __devexit tps65910_remove(struct platform_device *pdev)
1229 {
1230         struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1231         int i;
1232
1233         for (i = 0; i < pmic->num_regulators; i++)
1234                 regulator_unregister(pmic->rdev[i]);
1235
1236         kfree(pmic->rdev);
1237         kfree(pmic->info);
1238         kfree(pmic->desc);
1239         kfree(pmic);
1240         return 0;
1241 }
1242
1243 static void tps65910_shutdown(struct platform_device *pdev)
1244 {
1245         struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1246         int i;
1247
1248         /*
1249          * Before bootloader jumps to kernel, it makes sure that required
1250          * external control signals are in desired state so that given rails
1251          * can be configure accordingly.
1252          * If rails are configured to be controlled from external control
1253          * then before shutting down/rebooting the system, the external
1254          * control configuration need to be remove from the rails so that
1255          * its output will be available as per register programming even
1256          * if external controls are removed. This is require when the POR
1257          * value of the control signals are not in active state and before
1258          * bootloader initializes it, the system requires the rail output
1259          * to be active for booting.
1260          */
1261         for (i = 0; i < pmic->num_regulators; i++) {
1262                 int err;
1263                 if (!pmic->rdev[i])
1264                         continue;
1265
1266                 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1267                 if (err < 0)
1268                         dev_err(&pdev->dev,
1269                                 "Error in clearing external control\n");
1270         }
1271 }
1272
1273 static struct platform_driver tps65910_driver = {
1274         .driver = {
1275                 .name = "tps65910-pmic",
1276                 .owner = THIS_MODULE,
1277         },
1278         .probe = tps65910_probe,
1279         .remove = __devexit_p(tps65910_remove),
1280         .shutdown = tps65910_shutdown,
1281 };
1282
1283 static int __init tps65910_init(void)
1284 {
1285         return platform_driver_register(&tps65910_driver);
1286 }
1287 subsys_initcall(tps65910_init);
1288
1289 static void __exit tps65910_cleanup(void)
1290 {
1291         platform_driver_unregister(&tps65910_driver);
1292 }
1293 module_exit(tps65910_cleanup);
1294
1295 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1296 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1297 MODULE_LICENSE("GPL v2");
1298 MODULE_ALIAS("platform:tps65910-pmic");