0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/clk.h>
0012 #include <linux/delay.h>
0013 #include <linux/gpio.h>
0014 #include <linux/init.h>
0015 #include <linux/io.h>
0016 #include <linux/irq.h>
0017 #include <linux/stddef.h>
0018 #include <linux/i2c.h>
0019 #include <linux/spi/spi.h>
0020 #include <linux/usb/musb.h>
0021 #include <linux/mmc/host.h>
0022 #include <linux/platform_data/spi-omap2-mcspi.h>
0023 #include <linux/platform_data/mmc-omap.h>
0024 #include <linux/mfd/menelaus.h>
0025 #include <sound/tlv320aic3x.h>
0026
0027 #include <asm/mach/arch.h>
0028 #include <asm/mach-types.h>
0029
0030 #include "common.h"
0031 #include "mmc.h"
0032 #include "soc.h"
0033 #include "common-board-devices.h"
0034
0035 #define TUSB6010_ASYNC_CS 1
0036 #define TUSB6010_SYNC_CS 4
0037 #define TUSB6010_GPIO_INT 58
0038 #define TUSB6010_GPIO_ENABLE 0
0039 #define TUSB6010_DMACHAN 0x3f
0040
0041 #define NOKIA_N810_WIMAX (1 << 2)
0042 #define NOKIA_N810 (1 << 1)
0043 #define NOKIA_N800 (1 << 0)
0044
0045 static u32 board_caps;
0046
0047 #define board_is_n800() (board_caps & NOKIA_N800)
0048 #define board_is_n810() (board_caps & NOKIA_N810)
0049 #define board_is_n810_wimax() (board_caps & NOKIA_N810_WIMAX)
0050
0051 static void board_check_revision(void)
0052 {
0053 if (of_machine_is_compatible("nokia,n800"))
0054 board_caps = NOKIA_N800;
0055 else if (of_machine_is_compatible("nokia,n810"))
0056 board_caps = NOKIA_N810;
0057 else if (of_machine_is_compatible("nokia,n810-wimax"))
0058 board_caps = NOKIA_N810_WIMAX;
0059
0060 if (!board_caps)
0061 pr_err("Unknown board\n");
0062 }
0063
0064 #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010)
0065
0066
0067
0068
0069
0070 static int tusb_set_power(int state)
0071 {
0072 int i, retval = 0;
0073
0074 if (state) {
0075 gpio_set_value(TUSB6010_GPIO_ENABLE, 1);
0076 msleep(1);
0077
0078
0079 i = 100;
0080 while (i && gpio_get_value(TUSB6010_GPIO_INT)) {
0081 msleep(1);
0082 i--;
0083 }
0084
0085 if (!i) {
0086 printk(KERN_ERR "tusb: powerup failed\n");
0087 retval = -ENODEV;
0088 }
0089 } else {
0090 gpio_set_value(TUSB6010_GPIO_ENABLE, 0);
0091 msleep(10);
0092 }
0093
0094 return retval;
0095 }
0096
0097 static struct musb_hdrc_config musb_config = {
0098 .multipoint = 1,
0099 .dyn_fifo = 1,
0100 .num_eps = 16,
0101 .ram_bits = 12,
0102 };
0103
0104 static struct musb_hdrc_platform_data tusb_data = {
0105 .mode = MUSB_OTG,
0106 .set_power = tusb_set_power,
0107 .min_power = 25,
0108 .power = 100,
0109 .config = &musb_config,
0110 };
0111
0112 static void __init n8x0_usb_init(void)
0113 {
0114 int ret = 0;
0115 static const char announce[] __initconst = KERN_INFO "TUSB 6010\n";
0116
0117
0118 ret = gpio_request_one(TUSB6010_GPIO_ENABLE, GPIOF_OUT_INIT_LOW,
0119 "TUSB6010 enable");
0120 if (ret != 0) {
0121 printk(KERN_ERR "Could not get TUSB power GPIO%i\n",
0122 TUSB6010_GPIO_ENABLE);
0123 return;
0124 }
0125 tusb_set_power(0);
0126
0127 ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2,
0128 TUSB6010_ASYNC_CS, TUSB6010_SYNC_CS,
0129 TUSB6010_GPIO_INT, TUSB6010_DMACHAN);
0130 if (ret != 0)
0131 goto err;
0132
0133 printk(announce);
0134
0135 return;
0136
0137 err:
0138 gpio_free(TUSB6010_GPIO_ENABLE);
0139 }
0140 #else
0141
0142 static void __init n8x0_usb_init(void) {}
0143
0144 #endif
0145
0146
0147 static struct omap2_mcspi_device_config p54spi_mcspi_config = {
0148 .turbo_mode = 0,
0149 };
0150
0151 static struct spi_board_info n800_spi_board_info[] __initdata = {
0152 {
0153 .modalias = "p54spi",
0154 .bus_num = 2,
0155 .chip_select = 0,
0156 .max_speed_hz = 48000000,
0157 .controller_data = &p54spi_mcspi_config,
0158 },
0159 };
0160
0161 #if defined(CONFIG_MENELAUS) && IS_ENABLED(CONFIG_MMC_OMAP)
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 #define N8X0_SLOT_SWITCH_GPIO 96
0175 #define N810_EMMC_VSD_GPIO 23
0176 #define N810_EMMC_VIO_GPIO 9
0177
0178 static int slot1_cover_open;
0179 static int slot2_cover_open;
0180 static struct device *mmc_device;
0181
0182 static int n8x0_mmc_switch_slot(struct device *dev, int slot)
0183 {
0184 #ifdef CONFIG_MMC_DEBUG
0185 dev_dbg(dev, "Choose slot %d\n", slot + 1);
0186 #endif
0187 gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot);
0188 return 0;
0189 }
0190
0191 static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,
0192 int power_on, int vdd)
0193 {
0194 int mV;
0195
0196 #ifdef CONFIG_MMC_DEBUG
0197 dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
0198 power_on ? "on" : "off", vdd);
0199 #endif
0200 if (slot == 0) {
0201 if (!power_on)
0202 return menelaus_set_vmmc(0);
0203 switch (1 << vdd) {
0204 case MMC_VDD_33_34:
0205 case MMC_VDD_32_33:
0206 case MMC_VDD_31_32:
0207 mV = 3100;
0208 break;
0209 case MMC_VDD_30_31:
0210 mV = 3000;
0211 break;
0212 case MMC_VDD_28_29:
0213 mV = 2800;
0214 break;
0215 case MMC_VDD_165_195:
0216 mV = 1850;
0217 break;
0218 default:
0219 BUG();
0220 }
0221 return menelaus_set_vmmc(mV);
0222 } else {
0223 if (!power_on)
0224 return menelaus_set_vdcdc(3, 0);
0225 switch (1 << vdd) {
0226 case MMC_VDD_33_34:
0227 case MMC_VDD_32_33:
0228 mV = 3300;
0229 break;
0230 case MMC_VDD_30_31:
0231 case MMC_VDD_29_30:
0232 mV = 3000;
0233 break;
0234 case MMC_VDD_28_29:
0235 case MMC_VDD_27_28:
0236 mV = 2800;
0237 break;
0238 case MMC_VDD_24_25:
0239 case MMC_VDD_23_24:
0240 mV = 2400;
0241 break;
0242 case MMC_VDD_22_23:
0243 case MMC_VDD_21_22:
0244 mV = 2200;
0245 break;
0246 case MMC_VDD_20_21:
0247 mV = 2000;
0248 break;
0249 case MMC_VDD_165_195:
0250 mV = 1800;
0251 break;
0252 default:
0253 BUG();
0254 }
0255 return menelaus_set_vdcdc(3, mV);
0256 }
0257 return 0;
0258 }
0259
0260 static void n810_set_power_emmc(struct device *dev,
0261 int power_on)
0262 {
0263 dev_dbg(dev, "Set EMMC power %s\n", power_on ? "on" : "off");
0264
0265 if (power_on) {
0266 gpio_set_value(N810_EMMC_VSD_GPIO, 1);
0267 msleep(1);
0268 gpio_set_value(N810_EMMC_VIO_GPIO, 1);
0269 msleep(1);
0270 } else {
0271 gpio_set_value(N810_EMMC_VIO_GPIO, 0);
0272 msleep(50);
0273 gpio_set_value(N810_EMMC_VSD_GPIO, 0);
0274 msleep(50);
0275 }
0276 }
0277
0278 static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,
0279 int vdd)
0280 {
0281 if (board_is_n800() || slot == 0)
0282 return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);
0283
0284 n810_set_power_emmc(dev, power_on);
0285
0286 return 0;
0287 }
0288
0289 static int n8x0_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
0290 {
0291 int r;
0292
0293 dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
0294 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
0295 BUG_ON(slot != 0 && slot != 1);
0296 slot++;
0297 switch (bus_mode) {
0298 case MMC_BUSMODE_OPENDRAIN:
0299 r = menelaus_set_mmc_opendrain(slot, 1);
0300 break;
0301 case MMC_BUSMODE_PUSHPULL:
0302 r = menelaus_set_mmc_opendrain(slot, 0);
0303 break;
0304 default:
0305 BUG();
0306 }
0307 if (r != 0 && printk_ratelimit())
0308 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
0309 slot);
0310 return r;
0311 }
0312
0313 static int n8x0_mmc_get_cover_state(struct device *dev, int slot)
0314 {
0315 slot++;
0316 BUG_ON(slot != 1 && slot != 2);
0317 if (slot == 1)
0318 return slot1_cover_open;
0319 else
0320 return slot2_cover_open;
0321 }
0322
0323 static void n8x0_mmc_callback(void *data, u8 card_mask)
0324 {
0325 #ifdef CONFIG_MMC_OMAP
0326 int bit, *openp, index;
0327
0328 if (board_is_n800()) {
0329 bit = 1 << 1;
0330 openp = &slot2_cover_open;
0331 index = 1;
0332 } else {
0333 bit = 1;
0334 openp = &slot1_cover_open;
0335 index = 0;
0336 }
0337
0338 if (card_mask & bit)
0339 *openp = 1;
0340 else
0341 *openp = 0;
0342
0343 omap_mmc_notify_cover_event(mmc_device, index, *openp);
0344 #else
0345 pr_warn("MMC: notify cover event not available\n");
0346 #endif
0347 }
0348
0349 static int n8x0_mmc_late_init(struct device *dev)
0350 {
0351 int r, bit, *openp;
0352 int vs2sel;
0353
0354 mmc_device = dev;
0355
0356 r = menelaus_set_slot_sel(1);
0357 if (r < 0)
0358 return r;
0359
0360 if (board_is_n800())
0361 vs2sel = 0;
0362 else
0363 vs2sel = 2;
0364
0365 r = menelaus_set_mmc_slot(2, 0, vs2sel, 1);
0366 if (r < 0)
0367 return r;
0368
0369 n8x0_mmc_set_power(dev, 0, MMC_POWER_ON, 16);
0370 n8x0_mmc_set_power(dev, 1, MMC_POWER_ON, 16);
0371
0372 r = menelaus_set_mmc_slot(1, 1, 0, 1);
0373 if (r < 0)
0374 return r;
0375 r = menelaus_set_mmc_slot(2, 1, vs2sel, 1);
0376 if (r < 0)
0377 return r;
0378
0379 r = menelaus_get_slot_pin_states();
0380 if (r < 0)
0381 return r;
0382
0383 if (board_is_n800()) {
0384 bit = 1 << 1;
0385 openp = &slot2_cover_open;
0386 } else {
0387 bit = 1;
0388 openp = &slot1_cover_open;
0389 slot2_cover_open = 0;
0390 }
0391
0392
0393 if (r == 0xf || r == (0xf & ~bit))
0394 r = ~r;
0395
0396 if (r & bit)
0397 *openp = 1;
0398 else
0399 *openp = 0;
0400
0401 r = menelaus_register_mmc_callback(n8x0_mmc_callback, NULL);
0402
0403 return r;
0404 }
0405
0406 static void n8x0_mmc_shutdown(struct device *dev)
0407 {
0408 int vs2sel;
0409
0410 if (board_is_n800())
0411 vs2sel = 0;
0412 else
0413 vs2sel = 2;
0414
0415 menelaus_set_mmc_slot(1, 0, 0, 0);
0416 menelaus_set_mmc_slot(2, 0, vs2sel, 0);
0417 }
0418
0419 static void n8x0_mmc_cleanup(struct device *dev)
0420 {
0421 menelaus_unregister_mmc_callback();
0422
0423 gpio_free(N8X0_SLOT_SWITCH_GPIO);
0424
0425 if (board_is_n810()) {
0426 gpio_free(N810_EMMC_VSD_GPIO);
0427 gpio_free(N810_EMMC_VIO_GPIO);
0428 }
0429 }
0430
0431
0432
0433
0434
0435 static struct omap_mmc_platform_data mmc1_data = {
0436 .nr_slots = 0,
0437 .switch_slot = n8x0_mmc_switch_slot,
0438 .init = n8x0_mmc_late_init,
0439 .cleanup = n8x0_mmc_cleanup,
0440 .shutdown = n8x0_mmc_shutdown,
0441 .max_freq = 24000000,
0442 .slots[0] = {
0443 .wires = 4,
0444 .set_power = n8x0_mmc_set_power,
0445 .set_bus_mode = n8x0_mmc_set_bus_mode,
0446 .get_cover_state = n8x0_mmc_get_cover_state,
0447 .ocr_mask = MMC_VDD_165_195 | MMC_VDD_30_31 |
0448 MMC_VDD_32_33 | MMC_VDD_33_34,
0449 .name = "internal",
0450 },
0451 .slots[1] = {
0452 .set_power = n8x0_mmc_set_power,
0453 .set_bus_mode = n8x0_mmc_set_bus_mode,
0454 .get_cover_state = n8x0_mmc_get_cover_state,
0455 .ocr_mask = MMC_VDD_165_195 | MMC_VDD_20_21 |
0456 MMC_VDD_21_22 | MMC_VDD_22_23 |
0457 MMC_VDD_23_24 | MMC_VDD_24_25 |
0458 MMC_VDD_27_28 | MMC_VDD_28_29 |
0459 MMC_VDD_29_30 | MMC_VDD_30_31 |
0460 MMC_VDD_32_33 | MMC_VDD_33_34,
0461 .name = "external",
0462 },
0463 };
0464
0465 static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
0466
0467 static struct gpio n810_emmc_gpios[] __initdata = {
0468 { N810_EMMC_VSD_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vddf" },
0469 { N810_EMMC_VIO_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vdd" },
0470 };
0471
0472 static void __init n8x0_mmc_init(void)
0473 {
0474 int err;
0475
0476 if (board_is_n810()) {
0477 mmc1_data.slots[0].name = "external";
0478
0479
0480
0481
0482
0483
0484
0485 mmc1_data.slots[1].name = "internal";
0486 mmc1_data.slots[1].ban_openended = 1;
0487 }
0488
0489 err = gpio_request_one(N8X0_SLOT_SWITCH_GPIO, GPIOF_OUT_INIT_LOW,
0490 "MMC slot switch");
0491 if (err)
0492 return;
0493
0494 if (board_is_n810()) {
0495 err = gpio_request_array(n810_emmc_gpios,
0496 ARRAY_SIZE(n810_emmc_gpios));
0497 if (err) {
0498 gpio_free(N8X0_SLOT_SWITCH_GPIO);
0499 return;
0500 }
0501 }
0502
0503 mmc1_data.nr_slots = 2;
0504 mmc_data[0] = &mmc1_data;
0505 }
0506 #else
0507 static struct omap_mmc_platform_data mmc1_data;
0508 void __init n8x0_mmc_init(void)
0509 {
0510 }
0511 #endif
0512
0513 #ifdef CONFIG_MENELAUS
0514
0515 static int n8x0_auto_sleep_regulators(void)
0516 {
0517 u32 val;
0518 int ret;
0519
0520 val = EN_VPLL_SLEEP | EN_VMMC_SLEEP \
0521 | EN_VAUX_SLEEP | EN_VIO_SLEEP \
0522 | EN_VMEM_SLEEP | EN_DC3_SLEEP \
0523 | EN_VC_SLEEP | EN_DC2_SLEEP;
0524
0525 ret = menelaus_set_regulator_sleep(1, val);
0526 if (ret < 0) {
0527 pr_err("Could not set regulators to sleep on menelaus: %u\n",
0528 ret);
0529 return ret;
0530 }
0531 return 0;
0532 }
0533
0534 static int n8x0_auto_voltage_scale(void)
0535 {
0536 int ret;
0537
0538 ret = menelaus_set_vcore_hw(1400, 1050);
0539 if (ret < 0) {
0540 pr_err("Could not set VCORE voltage on menelaus: %u\n", ret);
0541 return ret;
0542 }
0543 return 0;
0544 }
0545
0546 static int n8x0_menelaus_late_init(struct device *dev)
0547 {
0548 int ret;
0549
0550 ret = n8x0_auto_voltage_scale();
0551 if (ret < 0)
0552 return ret;
0553 ret = n8x0_auto_sleep_regulators();
0554 if (ret < 0)
0555 return ret;
0556 return 0;
0557 }
0558
0559 #else
0560 static int n8x0_menelaus_late_init(struct device *dev)
0561 {
0562 return 0;
0563 }
0564 #endif
0565
0566 struct menelaus_platform_data n8x0_menelaus_platform_data = {
0567 .late_init = n8x0_menelaus_late_init,
0568 };
0569
0570 struct aic3x_pdata n810_aic33_data = {
0571 .gpio_reset = 118,
0572 };
0573
0574 static int __init n8x0_late_initcall(void)
0575 {
0576 if (!board_caps)
0577 return -ENODEV;
0578
0579 n8x0_mmc_init();
0580 n8x0_usb_init();
0581
0582 return 0;
0583 }
0584 omap_late_initcall(n8x0_late_initcall);
0585
0586
0587
0588
0589
0590 void * __init n8x0_legacy_init(void)
0591 {
0592 board_check_revision();
0593 spi_register_board_info(n800_spi_board_info,
0594 ARRAY_SIZE(n800_spi_board_info));
0595 return &mmc1_data;
0596 }