blob: 5acfcd5b5d6640c8fd840b2812d6e9d30ee3b072 [file] [log] [blame]
Rahul Kashyap2a906042012-01-12 19:10:05 +05301/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Chintan Pandya13490c02011-12-20 13:03:36 +05302 *
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;
Rahul Kashyapcfd33102012-01-02 16:56:46 +0530103 if (machine_is_msm7627a_evb())
104 gpio_bt_sys_rest_en = 16;
Chintan Pandya13490c02011-12-20 13:03:36 +0530105}
106
107static int bt_set_gpio(int on)
108{
109 int rc = 0;
110 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
111
112 if (on) {
113 rc = gpio_direction_output(gpio_bt_sys_rest_en, 1);
114 msleep(100);
115 } else {
116 if (!marimba_get_fm_status(&config) &&
117 !marimba_get_bt_status(&config)) {
118 gpio_set_value_cansleep(gpio_bt_sys_rest_en, 0);
119 rc = gpio_direction_input(gpio_bt_sys_rest_en);
120 msleep(100);
121 }
122 }
123 if (rc)
124 pr_err("%s: BT sys_reset_en GPIO : Error", __func__);
125
126 return rc;
127}
128
129static struct regulator *fm_regulator;
130static int fm_radio_setup(struct marimba_fm_platform_data *pdata)
131{
132 int rc = 0;
133 const char *id = "FMPW";
134 uint32_t irqcfg;
135 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
136 u8 value;
137
138 /* Voting for 1.8V Regulator */
139 fm_regulator = regulator_get(NULL , "msme1");
140 if (IS_ERR(fm_regulator)) {
141 rc = PTR_ERR(fm_regulator);
142 pr_err("%s: could not get regulator: %d\n", __func__, rc);
143 goto out;
144 }
145
146 /* Set the voltage level to 1.8V */
147 rc = regulator_set_voltage(fm_regulator, 1800000, 1800000);
148 if (rc < 0) {
149 pr_err("%s: could not set voltage: %d\n", __func__, rc);
150 goto reg_free;
151 }
152
153 /* Enabling the 1.8V regulator */
154 rc = regulator_enable(fm_regulator);
155 if (rc) {
156 pr_err("%s: could not enable regulator: %d\n", __func__, rc);
157 goto reg_free;
158 }
159
160 /* Voting for 19.2MHz clock */
161 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
162 PMAPP_CLOCK_VOTE_ON);
163 if (rc < 0) {
164 pr_err("%s: clock vote failed with :(%d)\n",
165 __func__, rc);
166 goto reg_disable;
167 }
168
169 rc = bt_set_gpio(1);
170 if (rc) {
171 pr_err("%s: bt_set_gpio = %d", __func__, rc);
172 goto gpio_deconfig;
173 }
174 /*re-write FM Slave Id, after reset*/
175 value = BAHAMA_SLAVE_ID_FM_ADDR;
176 rc = marimba_write_bit_mask(&config,
177 BAHAMA_SLAVE_ID_FM_REG, &value, 1, 0xFF);
178 if (rc < 0) {
179 pr_err("%s: FM Slave ID rewrite Failed = %d", __func__, rc);
180 goto gpio_deconfig;
181 }
182 /* Configuring the FM GPIO */
183 irqcfg = GPIO_CFG(FM_GPIO, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL,
184 GPIO_CFG_2MA);
185
186 rc = gpio_tlmm_config(irqcfg, GPIO_CFG_ENABLE);
187 if (rc) {
188 pr_err("%s: gpio_tlmm_config(%#x)=%d\n",
189 __func__, irqcfg, rc);
190 goto gpio_deconfig;
191 }
192
193 return 0;
194
195gpio_deconfig:
196 pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
197 PMAPP_CLOCK_VOTE_OFF);
198 bt_set_gpio(0);
199reg_disable:
200 regulator_disable(fm_regulator);
201reg_free:
202 regulator_put(fm_regulator);
203 fm_regulator = NULL;
204out:
205 return rc;
206};
207
208static void fm_radio_shutdown(struct marimba_fm_platform_data *pdata)
209{
210 int rc;
211 const char *id = "FMPW";
212
213 /* Releasing the GPIO line used by FM */
214 uint32_t irqcfg = GPIO_CFG(FM_GPIO, 0, GPIO_CFG_INPUT,
215 GPIO_CFG_PULL_UP, GPIO_CFG_2MA);
216
217 rc = gpio_tlmm_config(irqcfg, GPIO_CFG_ENABLE);
218 if (rc)
219 pr_err("%s: gpio_tlmm_config(%#x)=%d\n",
220 __func__, irqcfg, rc);
221
222 /* Releasing the 1.8V Regulator */
223 if (!IS_ERR_OR_NULL(fm_regulator)) {
224 rc = regulator_disable(fm_regulator);
225 if (rc)
226 pr_err("%s: could not disable regulator: %d\n",
227 __func__, rc);
228 regulator_put(fm_regulator);
229 fm_regulator = NULL;
230 }
231
232 /* Voting off the clock */
233 rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_D1,
234 PMAPP_CLOCK_VOTE_OFF);
235 if (rc < 0)
236 pr_err("%s: voting off failed with :(%d)\n",
237 __func__, rc);
238 rc = bt_set_gpio(0);
239 if (rc)
240 pr_err("%s: bt_set_gpio = %d", __func__, rc);
241}
242static int switch_pcm_i2s_reg_mode(int mode)
243{
244 unsigned char reg = 0;
245 int rc = -1;
246 unsigned char set = I2C_PIN_CTL; /*SET PIN CTL mode*/
247 unsigned char unset = I2C_NORMAL; /* UNSET PIN CTL MODE*/
248 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
249
250 if (mode == 0) {
251 /* as we need to switch path to FM we need to move
252 BT AUX PCM lines to PIN CONTROL mode then move
253 FM to normal mode.*/
254 for (reg = BT_PCM_BCLK_MODE; reg <= BT_PCM_SYNC_MODE; reg++) {
255 rc = marimba_write(&config, reg, &set, 1);
256 if (rc < 0) {
257 pr_err("pcm pinctl failed = %d", rc);
258 goto err_all;
259 }
260 }
261 for (reg = FM_I2S_SD_MODE; reg <= FM_I2S_SCK_MODE; reg++) {
262 rc = marimba_write(&config, reg, &unset, 1);
263 if (rc < 0) {
264 pr_err("i2s normal failed = %d", rc);
265 goto err_all;
266 }
267 }
268 } else {
269 /* as we need to switch path to AUXPCM we need to move
270 FM I2S lines to PIN CONTROL mode then move
271 BT AUX_PCM to normal mode.*/
272 for (reg = FM_I2S_SD_MODE; reg <= FM_I2S_SCK_MODE; reg++) {
273 rc = marimba_write(&config, reg, &set, 1);
274 if (rc < 0) {
275 pr_err("i2s pinctl failed = %d", rc);
276 goto err_all;
277 }
278 }
279 for (reg = BT_PCM_BCLK_MODE; reg <= BT_PCM_SYNC_MODE; reg++) {
280 rc = marimba_write(&config, reg, &unset, 1);
281 if (rc < 0) {
282 pr_err("pcm normal failed = %d", rc);
283 goto err_all;
284 }
285 }
286 }
287
288 return 0;
289
290err_all:
291 return rc;
292}
293
294
295static void config_pcm_i2s_mode(int mode)
296{
297 void __iomem *cfg_ptr;
298 u8 reg2;
299
300 cfg_ptr = ioremap_nocache(FPGA_MSM_CNTRL_REG2, sizeof(char));
301
302 if (!cfg_ptr)
303 return;
304 if (mode) {
305 /*enable the pcm mode in FPGA*/
306 reg2 = readb_relaxed(cfg_ptr);
307 if (reg2 == 0) {
308 reg2 = 1;
309 writeb_relaxed(reg2, cfg_ptr);
310 }
311 } else {
312 /*enable i2s mode in FPGA*/
313 reg2 = readb_relaxed(cfg_ptr);
314 if (reg2 == 1) {
315 reg2 = 0;
316 writeb_relaxed(reg2, cfg_ptr);
317 }
318 }
319 iounmap(cfg_ptr);
320}
321
322static int config_i2s(int mode)
323{
324 int pin, rc = 0;
325
326 if (mode == FM_I2S_ON) {
327 if (machine_is_msm7x27a_surf() || machine_is_msm7625a_surf())
328 config_pcm_i2s_mode(0);
329 pr_err("%s mode = FM_I2S_ON", __func__);
330
331 rc = switch_pcm_i2s_reg_mode(0);
332 if (rc) {
333 pr_err("switch mode failed");
334 return rc;
335 }
336 for (pin = 0; pin < ARRAY_SIZE(fm_i2s_config_power_on);
337 pin++) {
338 rc = gpio_tlmm_config(
339 fm_i2s_config_power_on[pin],
340 GPIO_CFG_ENABLE
341 );
342 if (rc < 0)
343 return rc;
344 }
345 } else if (mode == FM_I2S_OFF) {
346 pr_err("%s mode = FM_I2S_OFF", __func__);
347 rc = switch_pcm_i2s_reg_mode(1);
348 if (rc) {
349 pr_err("switch mode failed");
350 return rc;
351 }
352 for (pin = 0; pin < ARRAY_SIZE(fm_i2s_config_power_off);
353 pin++) {
354 rc = gpio_tlmm_config(
355 fm_i2s_config_power_off[pin],
356 GPIO_CFG_ENABLE
357 );
358 if (rc < 0)
359 return rc;
360 }
361 }
362 return rc;
363}
364
365static int config_pcm(int mode)
366{
367 int pin, rc = 0;
368
369 if (mode == BT_PCM_ON) {
370 if (machine_is_msm7x27a_surf() || machine_is_msm7625a_surf())
371 config_pcm_i2s_mode(1);
372 pr_err("%s mode =BT_PCM_ON", __func__);
373 rc = switch_pcm_i2s_reg_mode(1);
374 if (rc) {
375 pr_err("switch mode failed");
376 return rc;
377 }
378 for (pin = 0; pin < ARRAY_SIZE(bt_config_pcm_on);
379 pin++) {
380 rc = gpio_tlmm_config(bt_config_pcm_on[pin],
381 GPIO_CFG_ENABLE);
382 if (rc < 0)
383 return rc;
384 }
385 } else if (mode == BT_PCM_OFF) {
386 pr_err("%s mode =BT_PCM_OFF", __func__);
387 rc = switch_pcm_i2s_reg_mode(0);
388 if (rc) {
389 pr_err("switch mode failed");
390 return rc;
391 }
392 for (pin = 0; pin < ARRAY_SIZE(bt_config_pcm_off);
393 pin++) {
394 rc = gpio_tlmm_config(bt_config_pcm_off[pin],
395 GPIO_CFG_ENABLE);
396 if (rc < 0)
397 return rc;
398 }
399
400 }
401
402 return rc;
403}
404
405static int msm_bahama_setup_pcm_i2s(int mode)
406{
407 int fm_state = 0, bt_state = 0;
408 int rc = 0;
409 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
410
411 fm_state = marimba_get_fm_status(&config);
412 bt_state = marimba_get_bt_status(&config);
413
414 switch (mode) {
415 case BT_PCM_ON:
416 case BT_PCM_OFF:
417 if (!fm_state)
418 rc = config_pcm(mode);
419 break;
420 case FM_I2S_ON:
421 rc = config_i2s(mode);
422 break;
423 case FM_I2S_OFF:
424 if (bt_state)
425 rc = config_pcm(BT_PCM_ON);
426 else
427 rc = config_i2s(mode);
428 break;
429 default:
430 rc = -EIO;
431 pr_err("%s:Unsupported mode", __func__);
432 }
433 return rc;
434}
435
436static int bahama_bt(int on)
437{
438 int rc = 0;
439 int i;
440
441 struct marimba config = { .mod_id = SLAVE_ID_BAHAMA};
442
443 struct bahama_variant_register {
444 const size_t size;
445 const struct bahama_config_register *set;
446 };
447
448 const struct bahama_config_register *p;
449
450 u8 version;
451
452 const struct bahama_config_register v10_bt_on[] = {
453 { 0xE9, 0x00, 0xFF },
454 { 0xF4, 0x80, 0xFF },
455 { 0xE4, 0x00, 0xFF },
456 { 0xE5, 0x00, 0x0F },
457#ifdef CONFIG_WLAN
458 { 0xE6, 0x38, 0x7F },
459 { 0xE7, 0x06, 0xFF },
460#endif
461 { 0xE9, 0x21, 0xFF },
462 { 0x01, 0x0C, 0x1F },
463 { 0x01, 0x08, 0x1F },
464 };
465
466 const struct bahama_config_register v20_bt_on_fm_off[] = {
467 { 0x11, 0x0C, 0xFF },
468 { 0x13, 0x01, 0xFF },
469 { 0xF4, 0x80, 0xFF },
470 { 0xF0, 0x00, 0xFF },
471 { 0xE9, 0x00, 0xFF },
472#ifdef CONFIG_WLAN
473 { 0x81, 0x00, 0x7F },
474 { 0x82, 0x00, 0xFF },
475 { 0xE6, 0x38, 0x7F },
476 { 0xE7, 0x06, 0xFF },
477#endif
478 { 0x8E, 0x15, 0xFF },
479 { 0x8F, 0x15, 0xFF },
480 { 0x90, 0x15, 0xFF },
481
482 { 0xE9, 0x21, 0xFF },
483 };
484
485 const struct bahama_config_register v20_bt_on_fm_on[] = {
486 { 0x11, 0x0C, 0xFF },
487 { 0x13, 0x01, 0xFF },
488 { 0xF4, 0x86, 0xFF },
489 { 0xF0, 0x06, 0xFF },
490 { 0xE9, 0x00, 0xFF },
491#ifdef CONFIG_WLAN
492 { 0x81, 0x00, 0x7F },
493 { 0x82, 0x00, 0xFF },
494 { 0xE6, 0x38, 0x7F },
495 { 0xE7, 0x06, 0xFF },
496#endif
497 { 0xE9, 0x21, 0xFF },
498 };
499
500 const struct bahama_config_register v10_bt_off[] = {
501 { 0xE9, 0x00, 0xFF },
502 };
503
504 const struct bahama_config_register v20_bt_off_fm_off[] = {
505 { 0xF4, 0x84, 0xFF },
506 { 0xF0, 0x04, 0xFF },
507 { 0xE9, 0x00, 0xFF }
508 };
509
510 const struct bahama_config_register v20_bt_off_fm_on[] = {
511 { 0xF4, 0x86, 0xFF },
512 { 0xF0, 0x06, 0xFF },
513 { 0xE9, 0x00, 0xFF }
514 };
515
516 const struct bahama_variant_register bt_bahama[2][3] = {
517 {
518 { ARRAY_SIZE(v10_bt_off), v10_bt_off },
519 { ARRAY_SIZE(v20_bt_off_fm_off), v20_bt_off_fm_off },
520 { ARRAY_SIZE(v20_bt_off_fm_on), v20_bt_off_fm_on }
521 },
522 {
523 { ARRAY_SIZE(v10_bt_on), v10_bt_on },
524 { ARRAY_SIZE(v20_bt_on_fm_off), v20_bt_on_fm_off },
525 { ARRAY_SIZE(v20_bt_on_fm_on), v20_bt_on_fm_on }
526 }
527 };
528
529 u8 offset = 0; /* index into bahama configs */
530 on = on ? 1 : 0;
531 version = marimba_read_bahama_ver(&config);
532 if ((int)version < 0 || version == BAHAMA_VER_UNSUPPORTED) {
533 dev_err(&msm_bt_power_device.dev, "%s : Bahama "
534 "version read Error, version = %d\n",
535 __func__, version);
536 return -EIO;
537 }
538
539 if (version == BAHAMA_VER_2_0) {
540 if (marimba_get_fm_status(&config))
541 offset = 0x01;
542 }
543
544 p = bt_bahama[on][version + offset].set;
545
546 dev_info(&msm_bt_power_device.dev,
547 "%s: found version %d\n", __func__, version);
548
549 for (i = 0; i < bt_bahama[on][version + offset].size; i++) {
550 u8 value = (p+i)->value;
551 rc = marimba_write_bit_mask(&config,
552 (p+i)->reg,
553 &value,
554 sizeof((p+i)->value),
555 (p+i)->mask);
556 if (rc < 0) {
557 dev_err(&msm_bt_power_device.dev,
558 "%s: reg %x write failed: %d\n",
559 __func__, (p+i)->reg, rc);
560 return rc;
561 }
562 dev_dbg(&msm_bt_power_device.dev,
563 "%s: reg 0x%02x write value 0x%02x mask 0x%02x\n",
564 __func__, (p+i)->reg,
565 value, (p+i)->mask);
566 value = 0;
567 rc = marimba_read_bit_mask(&config,
568 (p+i)->reg, &value,
569 sizeof((p+i)->value), (p+i)->mask);
570 if (rc < 0)
571 dev_err(&msm_bt_power_device.dev,
572 "%s marimba_read_bit_mask- error",
573 __func__);
574 dev_dbg(&msm_bt_power_device.dev,
575 "%s: reg 0x%02x read value 0x%02x mask 0x%02x\n",
576 __func__, (p+i)->reg,
577 value, (p+i)->mask);
578 }
579 /* Update BT Status */
580 if (on)
581 marimba_set_bt_status(&config, true);
582 else
583 marimba_set_bt_status(&config, false);
584 return rc;
585}
586
587static int bluetooth_switch_regulators(int on)
588{
589 int i, rc = 0;
590 const char *id = "BTPW";
591
592 for (i = 0; i < ARRAY_SIZE(bt_vregs); i++) {
593 if (IS_ERR_OR_NULL(bt_vregs[i].reg)) {
594 rc = bt_vregs[i].reg ?
595 PTR_ERR(bt_vregs[i].reg) :
596 -ENODEV;
597 dev_err(&msm_bt_power_device.dev,
598 "%s: invalid regulator handle for %s: %d\n",
599 __func__, bt_vregs[i].name, rc);
600 goto reg_disable;
601 }
602
603 rc = on ? regulator_set_voltage(bt_vregs[i].reg,
604 bt_vregs[i].min_level,
605 bt_vregs[i].max_level) : 0;
606 if (rc) {
607 dev_err(&msm_bt_power_device.dev,
608 "%s: could not set voltage for %s: %d\n",
609 __func__, bt_vregs[i].name, rc);
610 goto reg_disable;
611 }
612
613 rc = on ? regulator_enable(bt_vregs[i].reg) : 0;
614 if (rc) {
615 dev_err(&msm_bt_power_device.dev,
616 "%s: could not %sable regulator %s: %d\n",
617 __func__, "en", bt_vregs[i].name, rc);
618 goto reg_disable;
619 }
620
621 if (bt_vregs[i].is_pin_controlled) {
622 rc = pmapp_vreg_lpm_pincntrl_vote(id,
623 bt_vregs[i].pmapp_id,
624 PMAPP_CLOCK_ID_D1,
625 on ? PMAPP_CLOCK_VOTE_ON :
626 PMAPP_CLOCK_VOTE_OFF);
627 if (rc) {
628 dev_err(&msm_bt_power_device.dev,
629 "%s: pin control failed for %s: %d\n",
630 __func__, bt_vregs[i].name, rc);
631 goto pin_cnt_fail;
632 }
633 }
634 rc = on ? 0 : regulator_disable(bt_vregs[i].reg);
635
636 if (rc) {
637 dev_err(&msm_bt_power_device.dev,
638 "%s: could not %sable regulator %s: %d\n",
639 __func__, "dis", bt_vregs[i].name, rc);
640 goto reg_disable;
641 }
642 }
643
644 return rc;
645pin_cnt_fail:
646 if (on)
647 regulator_disable(bt_vregs[i].reg);
648reg_disable:
649 while (i) {
650 if (on) {
651 i--;
652 regulator_disable(bt_vregs[i].reg);
653 regulator_put(bt_vregs[i].reg);
654 }
655 }
656 return rc;
657}
658
659static struct regulator *reg_s3;
660static unsigned int msm_bahama_setup_power(void)
661{
662 int rc = 0;
663
664 reg_s3 = regulator_get(NULL, "msme1");
665 if (IS_ERR(reg_s3)) {
666 rc = PTR_ERR(reg_s3);
667 pr_err("%s: could not get regulator: %d\n", __func__, rc);
668 goto out;
669 }
670
671 rc = regulator_set_voltage(reg_s3, 1800000, 1800000);
672 if (rc < 0) {
673 pr_err("%s: could not set voltage: %d\n", __func__, rc);
674 goto reg_fail;
675 }
676
677 rc = regulator_enable(reg_s3);
678 if (rc < 0) {
679 pr_err("%s: could not enable regulator: %d\n", __func__, rc);
680 goto reg_fail;
681 }
Rahul Kashyap2a906042012-01-12 19:10:05 +0530682 gpio_tlmm_config(GPIO_CFG(gpio_bt_sys_rest_en, 0,
683 GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL,
684 GPIO_CFG_2MA), GPIO_CFG_ENABLE);
Chintan Pandya13490c02011-12-20 13:03:36 +0530685
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
Chintan Pandya13490c02011-12-20 13:03:36 +0530938 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