blob: d4f06fa0b832be2a31b069ccdd348b00c814eca0 [file] [log] [blame]
Chintan Pandya13490c02011-12-20 13:03:36 +05301/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/delay.h>
15#include <linux/rfkill.h>
16#include <linux/platform_device.h>
17#include <linux/regulator/consumer.h>
18#include <linux/mfd/marimba.h>
19#include <linux/io.h>
20#include <asm/gpio.h>
21#include <asm/mach-types.h>
22#include <mach/rpc_pmapp.h>
23
24#include "board-msm7627a.h"
25#include "devices-msm7x2xa.h"
26
27#if defined(CONFIG_BT) && defined(CONFIG_MARIMBA_CORE)
28
29
30static struct bt_vreg_info bt_vregs[] = {
31 {"msme1", 2, 1800000, 1800000, 0, NULL},
32 {"bt", 21, 2900000, 3300000, 1, NULL}
33};
34
35struct platform_device msm_bt_power_device = {
36 .name = "bt_power",
37};
38
39static unsigned bt_config_power_on[] = {
40 /*RFR*/
41 GPIO_CFG(43, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
42 /*CTS*/
43 GPIO_CFG(44, 2, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
44 /*RX*/
45 GPIO_CFG(45, 2, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
46 /*TX*/
47 GPIO_CFG(46, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
48};
49static unsigned bt_config_pcm_on[] = {
50 /*PCM_DOUT*/
51 GPIO_CFG(68, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
52 /*PCM_DIN*/
53 GPIO_CFG(69, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
54 /*PCM_SYNC*/
55 GPIO_CFG(70, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
56 /*PCM_CLK*/
57 GPIO_CFG(71, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
58};
59static unsigned bt_config_power_off[] = {
60 /*RFR*/
61 GPIO_CFG(43, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
62 /*CTS*/
63 GPIO_CFG(44, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
64 /*RX*/
65 GPIO_CFG(45, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
66 /*TX*/
67 GPIO_CFG(46, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
68};
69static unsigned bt_config_pcm_off[] = {
70 /*PCM_DOUT*/
71 GPIO_CFG(68, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
72 /*PCM_DIN*/
73 GPIO_CFG(69, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
74 /*PCM_SYNC*/
75 GPIO_CFG(70, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
76 /*PCM_CLK*/
77 GPIO_CFG(71, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
78};
79
80static unsigned fm_i2s_config_power_on[] = {
81 /*FM_I2S_SD*/
82 GPIO_CFG(68, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
83 /*FM_I2S_WS*/
84 GPIO_CFG(70, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
85 /*FM_I2S_SCK*/
86 GPIO_CFG(71, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
87};
88
89static unsigned fm_i2s_config_power_off[] = {
90 /*FM_I2S_SD*/
91 GPIO_CFG(68, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
92 /*FM_I2S_WS*/
93 GPIO_CFG(70, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
94 /*FM_I2S_SCK*/
95 GPIO_CFG(71, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
96};
97
98int gpio_bt_sys_rest_en = 133;
99static void gpio_bt_config(void)
100{
101 if (machine_is_msm7627a_qrd1())
102 gpio_bt_sys_rest_en = 114;
103}
104
105static int bt_set_gpio(int on)
106{
107 int rc = 0;
108 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
109
110 if (on) {
111 rc = gpio_direction_output(gpio_bt_sys_rest_en, 1);
112 msleep(100);
113 } else {
114 if (!marimba_get_fm_status(&config) &&
115 !marimba_get_bt_status(&config)) {
116 gpio_set_value_cansleep(gpio_bt_sys_rest_en, 0);
117 rc = gpio_direction_input(gpio_bt_sys_rest_en);
118 msleep(100);
119 }
120 }
121 if (rc)
122 pr_err("%s: BT sys_reset_en GPIO : Error", __func__);
123
124 return rc;
125}
126
127static struct regulator *fm_regulator;
128static int fm_radio_setup(struct marimba_fm_platform_data *pdata)
129{
130 int rc = 0;
131 const char *id = "FMPW";
132 uint32_t irqcfg;
133 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
134 u8 value;
135
136 /* Voting for 1.8V Regulator */
137 fm_regulator = regulator_get(NULL , "msme1");
138 if (IS_ERR(fm_regulator)) {
139 rc = PTR_ERR(fm_regulator);
140 pr_err("%s: could not get regulator: %d\n", __func__, rc);
141 goto out;
142 }
143
144 /* Set the voltage level to 1.8V */
145 rc = regulator_set_voltage(fm_regulator, 1800000, 1800000);
146 if (rc < 0) {
147 pr_err("%s: could not set voltage: %d\n", __func__, rc);
148 goto reg_free;
149 }
150
151 /* Enabling the 1.8V regulator */
152 rc = regulator_enable(fm_regulator);
153 if (rc) {
154 pr_err("%s: could not enable regulator: %d\n", __func__, rc);
155 goto reg_free;
156 }
157
158 /* Voting for 19.2MHz clock */
159 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
160 PMAPP_CLOCK_VOTE_ON);
161 if (rc < 0) {
162 pr_err("%s: clock vote failed with :(%d)\n",
163 __func__, rc);
164 goto reg_disable;
165 }
166
167 rc = bt_set_gpio(1);
168 if (rc) {
169 pr_err("%s: bt_set_gpio = %d", __func__, rc);
170 goto gpio_deconfig;
171 }
172 /*re-write FM Slave Id, after reset*/
173 value = BAHAMA_SLAVE_ID_FM_ADDR;
174 rc = marimba_write_bit_mask(&config,
175 BAHAMA_SLAVE_ID_FM_REG, &value, 1, 0xFF);
176 if (rc < 0) {
177 pr_err("%s: FM Slave ID rewrite Failed = %d", __func__, rc);
178 goto gpio_deconfig;
179 }
180 /* Configuring the FM GPIO */
181 irqcfg = GPIO_CFG(FM_GPIO, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL,
182 GPIO_CFG_2MA);
183
184 rc = gpio_tlmm_config(irqcfg, GPIO_CFG_ENABLE);
185 if (rc) {
186 pr_err("%s: gpio_tlmm_config(%#x)=%d\n",
187 __func__, irqcfg, rc);
188 goto gpio_deconfig;
189 }
190
191 return 0;
192
193gpio_deconfig:
194 pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
195 PMAPP_CLOCK_VOTE_OFF);
196 bt_set_gpio(0);
197reg_disable:
198 regulator_disable(fm_regulator);
199reg_free:
200 regulator_put(fm_regulator);
201 fm_regulator = NULL;
202out:
203 return rc;
204};
205
206static void fm_radio_shutdown(struct marimba_fm_platform_data *pdata)
207{
208 int rc;
209 const char *id = "FMPW";
210
211 /* Releasing the GPIO line used by FM */
212 uint32_t irqcfg = GPIO_CFG(FM_GPIO, 0, GPIO_CFG_INPUT,
213 GPIO_CFG_PULL_UP, GPIO_CFG_2MA);
214
215 rc = gpio_tlmm_config(irqcfg, GPIO_CFG_ENABLE);
216 if (rc)
217 pr_err("%s: gpio_tlmm_config(%#x)=%d\n",
218 __func__, irqcfg, rc);
219
220 /* Releasing the 1.8V Regulator */
221 if (!IS_ERR_OR_NULL(fm_regulator)) {
222 rc = regulator_disable(fm_regulator);
223 if (rc)
224 pr_err("%s: could not disable regulator: %d\n",
225 __func__, rc);
226 regulator_put(fm_regulator);
227 fm_regulator = NULL;
228 }
229
230 /* Voting off the clock */
231 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
232 PMAPP_CLOCK_VOTE_OFF);
233 if (rc < 0)
234 pr_err("%s: voting off failed with :(%d)\n",
235 __func__, rc);
236 rc = bt_set_gpio(0);
237 if (rc)
238 pr_err("%s: bt_set_gpio = %d", __func__, rc);
239}
240static int switch_pcm_i2s_reg_mode(int mode)
241{
242 unsigned char reg = 0;
243 int rc = -1;
244 unsigned char set = I2C_PIN_CTL; /*SET PIN CTL mode*/
245 unsigned char unset = I2C_NORMAL; /* UNSET PIN CTL MODE*/
246 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
247
248 if (mode == 0) {
249 /* as we need to switch path to FM we need to move
250 BT AUX PCM lines to PIN CONTROL mode then move
251 FM to normal mode.*/
252 for (reg = BT_PCM_BCLK_MODE; reg <= BT_PCM_SYNC_MODE; reg++) {
253 rc = marimba_write(&config, reg, &set, 1);
254 if (rc < 0) {
255 pr_err("pcm pinctl failed = %d", rc);
256 goto err_all;
257 }
258 }
259 for (reg = FM_I2S_SD_MODE; reg <= FM_I2S_SCK_MODE; reg++) {
260 rc = marimba_write(&config, reg, &unset, 1);
261 if (rc < 0) {
262 pr_err("i2s normal failed = %d", rc);
263 goto err_all;
264 }
265 }
266 } else {
267 /* as we need to switch path to AUXPCM we need to move
268 FM I2S lines to PIN CONTROL mode then move
269 BT AUX_PCM to normal mode.*/
270 for (reg = FM_I2S_SD_MODE; reg <= FM_I2S_SCK_MODE; reg++) {
271 rc = marimba_write(&config, reg, &set, 1);
272 if (rc < 0) {
273 pr_err("i2s pinctl failed = %d", rc);
274 goto err_all;
275 }
276 }
277 for (reg = BT_PCM_BCLK_MODE; reg <= BT_PCM_SYNC_MODE; reg++) {
278 rc = marimba_write(&config, reg, &unset, 1);
279 if (rc < 0) {
280 pr_err("pcm normal failed = %d", rc);
281 goto err_all;
282 }
283 }
284 }
285
286 return 0;
287
288err_all:
289 return rc;
290}
291
292
293static void config_pcm_i2s_mode(int mode)
294{
295 void __iomem *cfg_ptr;
296 u8 reg2;
297
298 cfg_ptr = ioremap_nocache(FPGA_MSM_CNTRL_REG2, sizeof(char));
299
300 if (!cfg_ptr)
301 return;
302 if (mode) {
303 /*enable the pcm mode in FPGA*/
304 reg2 = readb_relaxed(cfg_ptr);
305 if (reg2 == 0) {
306 reg2 = 1;
307 writeb_relaxed(reg2, cfg_ptr);
308 }
309 } else {
310 /*enable i2s mode in FPGA*/
311 reg2 = readb_relaxed(cfg_ptr);
312 if (reg2 == 1) {
313 reg2 = 0;
314 writeb_relaxed(reg2, cfg_ptr);
315 }
316 }
317 iounmap(cfg_ptr);
318}
319
320static int config_i2s(int mode)
321{
322 int pin, rc = 0;
323
324 if (mode == FM_I2S_ON) {
325 if (machine_is_msm7x27a_surf() || machine_is_msm7625a_surf())
326 config_pcm_i2s_mode(0);
327 pr_err("%s mode = FM_I2S_ON", __func__);
328
329 rc = switch_pcm_i2s_reg_mode(0);
330 if (rc) {
331 pr_err("switch mode failed");
332 return rc;
333 }
334 for (pin = 0; pin < ARRAY_SIZE(fm_i2s_config_power_on);
335 pin++) {
336 rc = gpio_tlmm_config(
337 fm_i2s_config_power_on[pin],
338 GPIO_CFG_ENABLE
339 );
340 if (rc < 0)
341 return rc;
342 }
343 } else if (mode == FM_I2S_OFF) {
344 pr_err("%s mode = FM_I2S_OFF", __func__);
345 rc = switch_pcm_i2s_reg_mode(1);
346 if (rc) {
347 pr_err("switch mode failed");
348 return rc;
349 }
350 for (pin = 0; pin < ARRAY_SIZE(fm_i2s_config_power_off);
351 pin++) {
352 rc = gpio_tlmm_config(
353 fm_i2s_config_power_off[pin],
354 GPIO_CFG_ENABLE
355 );
356 if (rc < 0)
357 return rc;
358 }
359 }
360 return rc;
361}
362
363static int config_pcm(int mode)
364{
365 int pin, rc = 0;
366
367 if (mode == BT_PCM_ON) {
368 if (machine_is_msm7x27a_surf() || machine_is_msm7625a_surf())
369 config_pcm_i2s_mode(1);
370 pr_err("%s mode =BT_PCM_ON", __func__);
371 rc = switch_pcm_i2s_reg_mode(1);
372 if (rc) {
373 pr_err("switch mode failed");
374 return rc;
375 }
376 for (pin = 0; pin < ARRAY_SIZE(bt_config_pcm_on);
377 pin++) {
378 rc = gpio_tlmm_config(bt_config_pcm_on[pin],
379 GPIO_CFG_ENABLE);
380 if (rc < 0)
381 return rc;
382 }
383 } else if (mode == BT_PCM_OFF) {
384 pr_err("%s mode =BT_PCM_OFF", __func__);
385 rc = switch_pcm_i2s_reg_mode(0);
386 if (rc) {
387 pr_err("switch mode failed");
388 return rc;
389 }
390 for (pin = 0; pin < ARRAY_SIZE(bt_config_pcm_off);
391 pin++) {
392 rc = gpio_tlmm_config(bt_config_pcm_off[pin],
393 GPIO_CFG_ENABLE);
394 if (rc < 0)
395 return rc;
396 }
397
398 }
399
400 return rc;
401}
402
403static int msm_bahama_setup_pcm_i2s(int mode)
404{
405 int fm_state = 0, bt_state = 0;
406 int rc = 0;
407 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
408
409 fm_state = marimba_get_fm_status(&config);
410 bt_state = marimba_get_bt_status(&config);
411
412 switch (mode) {
413 case BT_PCM_ON:
414 case BT_PCM_OFF:
415 if (!fm_state)
416 rc = config_pcm(mode);
417 break;
418 case FM_I2S_ON:
419 rc = config_i2s(mode);
420 break;
421 case FM_I2S_OFF:
422 if (bt_state)
423 rc = config_pcm(BT_PCM_ON);
424 else
425 rc = config_i2s(mode);
426 break;
427 default:
428 rc = -EIO;
429 pr_err("%s:Unsupported mode", __func__);
430 }
431 return rc;
432}
433
434static int bahama_bt(int on)
435{
436 int rc = 0;
437 int i;
438
439 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
440
441 struct bahama_variant_register {
442 const size_t size;
443 const struct bahama_config_register *set;
444 };
445
446 const struct bahama_config_register *p;
447
448 u8 version;
449
450 const struct bahama_config_register v10_bt_on[] = {
451 { 0xE9, 0x00, 0xFF },
452 { 0xF4, 0x80, 0xFF },
453 { 0xE4, 0x00, 0xFF },
454 { 0xE5, 0x00, 0x0F },
455#ifdef CONFIG_WLAN
456 { 0xE6, 0x38, 0x7F },
457 { 0xE7, 0x06, 0xFF },
458#endif
459 { 0xE9, 0x21, 0xFF },
460 { 0x01, 0x0C, 0x1F },
461 { 0x01, 0x08, 0x1F },
462 };
463
464 const struct bahama_config_register v20_bt_on_fm_off[] = {
465 { 0x11, 0x0C, 0xFF },
466 { 0x13, 0x01, 0xFF },
467 { 0xF4, 0x80, 0xFF },
468 { 0xF0, 0x00, 0xFF },
469 { 0xE9, 0x00, 0xFF },
470#ifdef CONFIG_WLAN
471 { 0x81, 0x00, 0x7F },
472 { 0x82, 0x00, 0xFF },
473 { 0xE6, 0x38, 0x7F },
474 { 0xE7, 0x06, 0xFF },
475#endif
476 { 0x8E, 0x15, 0xFF },
477 { 0x8F, 0x15, 0xFF },
478 { 0x90, 0x15, 0xFF },
479
480 { 0xE9, 0x21, 0xFF },
481 };
482
483 const struct bahama_config_register v20_bt_on_fm_on[] = {
484 { 0x11, 0x0C, 0xFF },
485 { 0x13, 0x01, 0xFF },
486 { 0xF4, 0x86, 0xFF },
487 { 0xF0, 0x06, 0xFF },
488 { 0xE9, 0x00, 0xFF },
489#ifdef CONFIG_WLAN
490 { 0x81, 0x00, 0x7F },
491 { 0x82, 0x00, 0xFF },
492 { 0xE6, 0x38, 0x7F },
493 { 0xE7, 0x06, 0xFF },
494#endif
495 { 0xE9, 0x21, 0xFF },
496 };
497
498 const struct bahama_config_register v10_bt_off[] = {
499 { 0xE9, 0x00, 0xFF },
500 };
501
502 const struct bahama_config_register v20_bt_off_fm_off[] = {
503 { 0xF4, 0x84, 0xFF },
504 { 0xF0, 0x04, 0xFF },
505 { 0xE9, 0x00, 0xFF }
506 };
507
508 const struct bahama_config_register v20_bt_off_fm_on[] = {
509 { 0xF4, 0x86, 0xFF },
510 { 0xF0, 0x06, 0xFF },
511 { 0xE9, 0x00, 0xFF }
512 };
513
514 const struct bahama_variant_register bt_bahama[2][3] = {
515 {
516 { ARRAY_SIZE(v10_bt_off), v10_bt_off },
517 { ARRAY_SIZE(v20_bt_off_fm_off), v20_bt_off_fm_off },
518 { ARRAY_SIZE(v20_bt_off_fm_on), v20_bt_off_fm_on }
519 },
520 {
521 { ARRAY_SIZE(v10_bt_on), v10_bt_on },
522 { ARRAY_SIZE(v20_bt_on_fm_off), v20_bt_on_fm_off },
523 { ARRAY_SIZE(v20_bt_on_fm_on), v20_bt_on_fm_on }
524 }
525 };
526
527 u8 offset = 0; /* index into bahama configs */
528 on = on ? 1 : 0;
529 version = marimba_read_bahama_ver(&config);
530 if ((int)version < 0 || version == BAHAMA_VER_UNSUPPORTED) {
531 dev_err(&msm_bt_power_device.dev, "%s : Bahama "
532 "version read Error, version = %d\n",
533 __func__, version);
534 return -EIO;
535 }
536
537 if (version == BAHAMA_VER_2_0) {
538 if (marimba_get_fm_status(&config))
539 offset = 0x01;
540 }
541
542 p = bt_bahama[on][version + offset].set;
543
544 dev_info(&msm_bt_power_device.dev,
545 "%s: found version %d\n", __func__, version);
546
547 for (i = 0; i < bt_bahama[on][version + offset].size; i++) {
548 u8 value = (p+i)->value;
549 rc = marimba_write_bit_mask(&config,
550 (p+i)->reg,
551 &value,
552 sizeof((p+i)->value),
553 (p+i)->mask);
554 if (rc < 0) {
555 dev_err(&msm_bt_power_device.dev,
556 "%s: reg %x write failed: %d\n",
557 __func__, (p+i)->reg, rc);
558 return rc;
559 }
560 dev_dbg(&msm_bt_power_device.dev,
561 "%s: reg 0x%02x write value 0x%02x mask 0x%02x\n",
562 __func__, (p+i)->reg,
563 value, (p+i)->mask);
564 value = 0;
565 rc = marimba_read_bit_mask(&config,
566 (p+i)->reg, &value,
567 sizeof((p+i)->value), (p+i)->mask);
568 if (rc < 0)
569 dev_err(&msm_bt_power_device.dev,
570 "%s marimba_read_bit_mask- error",
571 __func__);
572 dev_dbg(&msm_bt_power_device.dev,
573 "%s: reg 0x%02x read value 0x%02x mask 0x%02x\n",
574 __func__, (p+i)->reg,
575 value, (p+i)->mask);
576 }
577 /* Update BT Status */
578 if (on)
579 marimba_set_bt_status(&config, true);
580 else
581 marimba_set_bt_status(&config, false);
582 return rc;
583}
584
585static int bluetooth_switch_regulators(int on)
586{
587 int i, rc = 0;
588 const char *id = "BTPW";
589
590 for (i = 0; i < ARRAY_SIZE(bt_vregs); i++) {
591 if (IS_ERR_OR_NULL(bt_vregs[i].reg)) {
592 rc = bt_vregs[i].reg ?
593 PTR_ERR(bt_vregs[i].reg) :
594 -ENODEV;
595 dev_err(&msm_bt_power_device.dev,
596 "%s: invalid regulator handle for %s: %d\n",
597 __func__, bt_vregs[i].name, rc);
598 goto reg_disable;
599 }
600
601 rc = on ? regulator_set_voltage(bt_vregs[i].reg,
602 bt_vregs[i].min_level,
603 bt_vregs[i].max_level) : 0;
604 if (rc) {
605 dev_err(&msm_bt_power_device.dev,
606 "%s: could not set voltage for %s: %d\n",
607 __func__, bt_vregs[i].name, rc);
608 goto reg_disable;
609 }
610
611 rc = on ? regulator_enable(bt_vregs[i].reg) : 0;
612 if (rc) {
613 dev_err(&msm_bt_power_device.dev,
614 "%s: could not %sable regulator %s: %d\n",
615 __func__, "en", bt_vregs[i].name, rc);
616 goto reg_disable;
617 }
618
619 if (bt_vregs[i].is_pin_controlled) {
620 rc = pmapp_vreg_lpm_pincntrl_vote(id,
621 bt_vregs[i].pmapp_id,
622 PMAPP_CLOCK_ID_D1,
623 on ? PMAPP_CLOCK_VOTE_ON :
624 PMAPP_CLOCK_VOTE_OFF);
625 if (rc) {
626 dev_err(&msm_bt_power_device.dev,
627 "%s: pin control failed for %s: %d\n",
628 __func__, bt_vregs[i].name, rc);
629 goto pin_cnt_fail;
630 }
631 }
632 rc = on ? 0 : regulator_disable(bt_vregs[i].reg);
633
634 if (rc) {
635 dev_err(&msm_bt_power_device.dev,
636 "%s: could not %sable regulator %s: %d\n",
637 __func__, "dis", bt_vregs[i].name, rc);
638 goto reg_disable;
639 }
640 }
641
642 return rc;
643pin_cnt_fail:
644 if (on)
645 regulator_disable(bt_vregs[i].reg);
646reg_disable:
647 while (i) {
648 if (on) {
649 i--;
650 regulator_disable(bt_vregs[i].reg);
651 regulator_put(bt_vregs[i].reg);
652 }
653 }
654 return rc;
655}
656
657static struct regulator *reg_s3;
658static unsigned int msm_bahama_setup_power(void)
659{
660 int rc = 0;
661
662 reg_s3 = regulator_get(NULL, "msme1");
663 if (IS_ERR(reg_s3)) {
664 rc = PTR_ERR(reg_s3);
665 pr_err("%s: could not get regulator: %d\n", __func__, rc);
666 goto out;
667 }
668
669 rc = regulator_set_voltage(reg_s3, 1800000, 1800000);
670 if (rc < 0) {
671 pr_err("%s: could not set voltage: %d\n", __func__, rc);
672 goto reg_fail;
673 }
674
675 rc = regulator_enable(reg_s3);
676 if (rc < 0) {
677 pr_err("%s: could not enable regulator: %d\n", __func__, rc);
678 goto reg_fail;
679 }
680 if (machine_is_msm7627a_qrd1())
681 gpio_tlmm_config(GPIO_CFG(gpio_bt_sys_rest_en, 0,
682 GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL,
683 GPIO_CFG_2MA), GPIO_CFG_ENABLE);
684
685
686 /*setup Bahama_sys_reset_n*/
687 rc = gpio_request(gpio_bt_sys_rest_en, "bahama sys_rst_n");
688 if (rc < 0) {
689 pr_err("%s: gpio_request %d = %d\n", __func__,
690 gpio_bt_sys_rest_en, rc);
691 goto reg_disable;
692 }
693
694 rc = bt_set_gpio(1);
695 if (rc < 0) {
696 pr_err("%s: bt_set_gpio %d = %d\n", __func__,
697 gpio_bt_sys_rest_en, rc);
698 goto gpio_fail;
699 }
700
701 return rc;
702
703gpio_fail:
704 gpio_free(gpio_bt_sys_rest_en);
705reg_disable:
706 regulator_disable(reg_s3);
707reg_fail:
708 regulator_put(reg_s3);
709out:
710 reg_s3 = NULL;
711 return rc;
712}
713
714static unsigned int msm_bahama_shutdown_power(int value)
715{
716 int rc = 0;
717
718 if (IS_ERR_OR_NULL(reg_s3)) {
719 rc = reg_s3 ? PTR_ERR(reg_s3) : -ENODEV;
720 goto out;
721 }
722
723 rc = regulator_disable(reg_s3);
724 if (rc) {
725 pr_err("%s: could not disable regulator: %d\n", __func__, rc);
726 goto out;
727 }
728
729 if (value == BAHAMA_ID) {
730 rc = bt_set_gpio(0);
731 if (rc) {
732 pr_err("%s: bt_set_gpio = %d\n",
733 __func__, rc);
734 goto reg_enable;
735 }
736 gpio_free(gpio_bt_sys_rest_en);
737 }
738
739 regulator_put(reg_s3);
740 reg_s3 = NULL;
741
742 return 0;
743
744reg_enable:
745 regulator_enable(reg_s3);
746out:
747 return rc;
748}
749
750static unsigned int msm_bahama_core_config(int type)
751{
752 int rc = 0;
753
754 if (type == BAHAMA_ID) {
755 int i;
756 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
757 const struct bahama_config_register v20_init[] = {
758 /* reg, value, mask */
759 { 0xF4, 0x84, 0xFF }, /* AREG */
760 { 0xF0, 0x04, 0xFF } /* DREG */
761 };
762 if (marimba_read_bahama_ver(&config) == BAHAMA_VER_2_0) {
763 for (i = 0; i < ARRAY_SIZE(v20_init); i++) {
764 u8 value = v20_init[i].value;
765 rc = marimba_write_bit_mask(&config,
766 v20_init[i].reg,
767 &value,
768 sizeof(v20_init[i].value),
769 v20_init[i].mask);
770 if (rc < 0) {
771 pr_err("%s: reg %d write failed: %d\n",
772 __func__, v20_init[i].reg, rc);
773 return rc;
774 }
775 pr_debug("%s: reg 0x%02x value 0x%02x"
776 " mask 0x%02x\n",
777 __func__, v20_init[i].reg,
778 v20_init[i].value, v20_init[i].mask);
779 }
780 }
781 }
782 rc = bt_set_gpio(0);
783 if (rc) {
784 pr_err("%s: bt_set_gpio = %d\n",
785 __func__, rc);
786 }
787 pr_debug("core type: %d\n", type);
788 return rc;
789}
790
791static int bluetooth_power(int on)
792{
793 int pin, rc = 0;
794 const char *id = "BTPW";
795 int cid = 0;
796
797 cid = adie_get_detected_connectivity_type();
798 if (cid != BAHAMA_ID) {
799 pr_err("%s: unexpected adie connectivity type: %d\n",
800 __func__, cid);
801 return -ENODEV;
802 }
803 if (on) {
804 /*setup power for BT SOC*/
805 rc = bt_set_gpio(on);
806 if (rc) {
807 pr_err("%s: bt_set_gpio = %d\n",
808 __func__, rc);
809 goto exit;
810 }
811 rc = bluetooth_switch_regulators(on);
812 if (rc < 0) {
813 pr_err("%s: bluetooth_switch_regulators rc = %d",
814 __func__, rc);
815 goto exit;
816 }
817 /*setup BT GPIO lines*/
818 for (pin = 0; pin < ARRAY_SIZE(bt_config_power_on);
819 pin++) {
820 rc = gpio_tlmm_config(bt_config_power_on[pin],
821 GPIO_CFG_ENABLE);
822 if (rc < 0) {
823 pr_err("%s: gpio_tlmm_config(%#x)=%d\n",
824 __func__,
825 bt_config_power_on[pin],
826 rc);
827 goto fail_power;
828 }
829 }
830 /*Setup BT clocks*/
831 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
832 PMAPP_CLOCK_VOTE_ON);
833 if (rc < 0) {
834 pr_err("Failed to vote for TCXO_D1 ON\n");
835 goto fail_clock;
836 }
837 msleep(20);
838
839 /*I2C config for Bahama*/
840 rc = bahama_bt(1);
841 if (rc < 0) {
842 pr_err("%s: bahama_bt rc = %d", __func__, rc);
843 goto fail_i2c;
844 }
845 msleep(20);
846
847 /*setup BT PCM lines*/
848 rc = msm_bahama_setup_pcm_i2s(BT_PCM_ON);
849 if (rc < 0) {
850 pr_err("%s: msm_bahama_setup_pcm_i2s , rc =%d\n",
851 __func__, rc);
852 goto fail_power;
853 }
854 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
855 PMAPP_CLOCK_VOTE_PIN_CTRL);
856 if (rc < 0)
857 pr_err("%s:Pin Control Failed, rc = %d",
858 __func__, rc);
859
860 } else {
861 rc = bahama_bt(0);
862 if (rc < 0)
863 pr_err("%s: bahama_bt rc = %d", __func__, rc);
864
Rahul Kashyap387e9532011-12-30 15:57:34 +0530865 rc = msm_bahama_setup_pcm_i2s(BT_PCM_OFF);
866 if (rc < 0) {
867 pr_err("%s: msm_bahama_setup_pcm_i2s, rc =%d\n",
868 __func__, rc);
869 }
Chintan Pandya13490c02011-12-20 13:03:36 +0530870 rc = bt_set_gpio(on);
871 if (rc) {
872 pr_err("%s: bt_set_gpio = %d\n",
873 __func__, rc);
874 }
875fail_i2c:
876 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
877 PMAPP_CLOCK_VOTE_OFF);
878 if (rc < 0)
879 pr_err("%s: Failed to vote Off D1\n", __func__);
880fail_clock:
881 for (pin = 0; pin < ARRAY_SIZE(bt_config_power_off);
882 pin++) {
883 rc = gpio_tlmm_config(bt_config_power_off[pin],
884 GPIO_CFG_ENABLE);
885 if (rc < 0) {
886 pr_err("%s:"
887 " gpio_tlmm_config(%#x)=%d\n",
888 __func__,
889 bt_config_power_off[pin], rc);
890 }
891 }
Chintan Pandya13490c02011-12-20 13:03:36 +0530892fail_power:
893 rc = bluetooth_switch_regulators(0);
894 if (rc < 0) {
895 pr_err("%s: switch_regulators : rc = %d",\
896 __func__, rc);
897 goto exit;
898 }
899 }
900 return rc;
901exit:
902 pr_err("%s: failed with rc = %d", __func__, rc);
903 return rc;
904}
905
906static struct marimba_fm_platform_data marimba_fm_pdata = {
907 .fm_setup = fm_radio_setup,
908 .fm_shutdown = fm_radio_shutdown,
909 .irq = MSM_GPIO_TO_INT(FM_GPIO),
910 .vreg_s2 = NULL,
911 .vreg_xo_out = NULL,
912 /* Configuring the FM SoC as I2S Master */
913 .is_fm_soc_i2s_master = true,
914 .config_i2s_gpio = msm_bahama_setup_pcm_i2s,
915};
916
917static struct marimba_platform_data marimba_pdata = {
918 .slave_id[SLAVE_ID_BAHAMA_FM] = BAHAMA_SLAVE_ID_FM_ADDR,
919 .slave_id[SLAVE_ID_BAHAMA_QMEMBIST] = BAHAMA_SLAVE_ID_QMEMBIST_ADDR,
920 .bahama_setup = msm_bahama_setup_power,
921 .bahama_shutdown = msm_bahama_shutdown_power,
922 .bahama_core_config = msm_bahama_core_config,
923 .fm = &marimba_fm_pdata,
924};
925
926static struct i2c_board_info bahama_devices[] = {
927{
928 I2C_BOARD_INFO("marimba", 0xc),
929 .platform_data = &marimba_pdata,
930},
931};
932
933void __init msm7627a_bt_power_init(void)
934{
935 int i, rc = 0;
936 struct device *dev;
937
938 gpio_bt_config();
939
940 i2c_register_board_info(MSM_GSBI1_QUP_I2C_BUS_ID,
941 bahama_devices,
942 ARRAY_SIZE(bahama_devices));
943 dev = &msm_bt_power_device.dev;
944
945 for (i = 0; i < ARRAY_SIZE(bt_vregs); i++) {
946 bt_vregs[i].reg = regulator_get(dev, bt_vregs[i].name);
947 if (IS_ERR(bt_vregs[i].reg)) {
948 rc = PTR_ERR(bt_vregs[i].reg);
949 dev_err(dev, "%s: could not get regulator %s: %d\n",
950 __func__, bt_vregs[i].name, rc);
951 goto reg_get_fail;
952 }
953 }
954
955 dev->platform_data = &bluetooth_power;
956
957 return;
958
959reg_get_fail:
960 while (i--) {
961 regulator_put(bt_vregs[i].reg);
962 bt_vregs[i].reg = NULL;
963 }
964 return;
965}
966#endif