board-n8x0.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /*
  2. * linux/arch/arm/mach-omap2/board-n8x0.c
  3. *
  4. * Copyright (C) 2005-2009 Nokia Corporation
  5. * Author: Juha Yrjola <juha.yrjola@nokia.com>
  6. *
  7. * Modified from mach-omap2/board-generic.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/stddef.h>
  20. #include <linux/i2c.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/usb/musb.h>
  23. #include <linux/mmc/host.h>
  24. #include <linux/platform_data/spi-omap2-mcspi.h>
  25. #include <linux/platform_data/mmc-omap.h>
  26. #include <linux/mfd/menelaus.h>
  27. #include <sound/tlv320aic3x.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach-types.h>
  30. #include "common.h"
  31. #include "mmc.h"
  32. #include "soc.h"
  33. #include "common-board-devices.h"
  34. #define TUSB6010_ASYNC_CS 1
  35. #define TUSB6010_SYNC_CS 4
  36. #define TUSB6010_GPIO_INT 58
  37. #define TUSB6010_GPIO_ENABLE 0
  38. #define TUSB6010_DMACHAN 0x3f
  39. #define NOKIA_N810_WIMAX (1 << 2)
  40. #define NOKIA_N810 (1 << 1)
  41. #define NOKIA_N800 (1 << 0)
  42. static u32 board_caps;
  43. #define board_is_n800() (board_caps & NOKIA_N800)
  44. #define board_is_n810() (board_caps & NOKIA_N810)
  45. #define board_is_n810_wimax() (board_caps & NOKIA_N810_WIMAX)
  46. static void board_check_revision(void)
  47. {
  48. if (of_machine_is_compatible("nokia,n800"))
  49. board_caps = NOKIA_N800;
  50. else if (of_machine_is_compatible("nokia,n810"))
  51. board_caps = NOKIA_N810;
  52. else if (of_machine_is_compatible("nokia,n810-wimax"))
  53. board_caps = NOKIA_N810_WIMAX;
  54. if (!board_caps)
  55. pr_err("Unknown board\n");
  56. }
  57. #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010)
  58. /*
  59. * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and
  60. * 1.5 V voltage regulators of PM companion chip. Companion chip will then
  61. * provide then PGOOD signal to TUSB6010 which will release it from reset.
  62. */
  63. static int tusb_set_power(int state)
  64. {
  65. int i, retval = 0;
  66. if (state) {
  67. gpio_set_value(TUSB6010_GPIO_ENABLE, 1);
  68. msleep(1);
  69. /* Wait until TUSB6010 pulls INT pin down */
  70. i = 100;
  71. while (i && gpio_get_value(TUSB6010_GPIO_INT)) {
  72. msleep(1);
  73. i--;
  74. }
  75. if (!i) {
  76. printk(KERN_ERR "tusb: powerup failed\n");
  77. retval = -ENODEV;
  78. }
  79. } else {
  80. gpio_set_value(TUSB6010_GPIO_ENABLE, 0);
  81. msleep(10);
  82. }
  83. return retval;
  84. }
  85. static struct musb_hdrc_config musb_config = {
  86. .multipoint = 1,
  87. .dyn_fifo = 1,
  88. .num_eps = 16,
  89. .ram_bits = 12,
  90. };
  91. static struct musb_hdrc_platform_data tusb_data = {
  92. .mode = MUSB_OTG,
  93. .set_power = tusb_set_power,
  94. .min_power = 25, /* x2 = 50 mA drawn from VBUS as peripheral */
  95. .power = 100, /* Max 100 mA VBUS for host mode */
  96. .config = &musb_config,
  97. };
  98. static void __init n8x0_usb_init(void)
  99. {
  100. int ret = 0;
  101. static const char announce[] __initconst = KERN_INFO "TUSB 6010\n";
  102. /* PM companion chip power control pin */
  103. ret = gpio_request_one(TUSB6010_GPIO_ENABLE, GPIOF_OUT_INIT_LOW,
  104. "TUSB6010 enable");
  105. if (ret != 0) {
  106. printk(KERN_ERR "Could not get TUSB power GPIO%i\n",
  107. TUSB6010_GPIO_ENABLE);
  108. return;
  109. }
  110. tusb_set_power(0);
  111. ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2,
  112. TUSB6010_ASYNC_CS, TUSB6010_SYNC_CS,
  113. TUSB6010_GPIO_INT, TUSB6010_DMACHAN);
  114. if (ret != 0)
  115. goto err;
  116. printk(announce);
  117. return;
  118. err:
  119. gpio_free(TUSB6010_GPIO_ENABLE);
  120. }
  121. #else
  122. static void __init n8x0_usb_init(void) {}
  123. #endif /*CONFIG_USB_MUSB_TUSB6010 */
  124. static struct omap2_mcspi_device_config p54spi_mcspi_config = {
  125. .turbo_mode = 0,
  126. };
  127. static struct spi_board_info n800_spi_board_info[] __initdata = {
  128. {
  129. .modalias = "p54spi",
  130. .bus_num = 2,
  131. .chip_select = 0,
  132. .max_speed_hz = 48000000,
  133. .controller_data = &p54spi_mcspi_config,
  134. },
  135. };
  136. #if defined(CONFIG_MENELAUS) && IS_ENABLED(CONFIG_MMC_OMAP)
  137. /*
  138. * On both N800 and N810, only the first of the two MMC controllers is in use.
  139. * The two MMC slots are multiplexed via Menelaus companion chip over I2C.
  140. * On N800, both slots are powered via Menelaus. On N810, only one of the
  141. * slots is powered via Menelaus. The N810 EMMC is powered via GPIO.
  142. *
  143. * VMMC slot 1 on both N800 and N810
  144. * VDCDC3_APE and VMCS2_APE slot 2 on N800
  145. * GPIO23 and GPIO9 slot 2 EMMC on N810
  146. *
  147. */
  148. #define N8X0_SLOT_SWITCH_GPIO 96
  149. #define N810_EMMC_VSD_GPIO 23
  150. #define N810_EMMC_VIO_GPIO 9
  151. static int slot1_cover_open;
  152. static int slot2_cover_open;
  153. static struct device *mmc_device;
  154. static int n8x0_mmc_switch_slot(struct device *dev, int slot)
  155. {
  156. #ifdef CONFIG_MMC_DEBUG
  157. dev_dbg(dev, "Choose slot %d\n", slot + 1);
  158. #endif
  159. gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot);
  160. return 0;
  161. }
  162. static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,
  163. int power_on, int vdd)
  164. {
  165. int mV;
  166. #ifdef CONFIG_MMC_DEBUG
  167. dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
  168. power_on ? "on" : "off", vdd);
  169. #endif
  170. if (slot == 0) {
  171. if (!power_on)
  172. return menelaus_set_vmmc(0);
  173. switch (1 << vdd) {
  174. case MMC_VDD_33_34:
  175. case MMC_VDD_32_33:
  176. case MMC_VDD_31_32:
  177. mV = 3100;
  178. break;
  179. case MMC_VDD_30_31:
  180. mV = 3000;
  181. break;
  182. case MMC_VDD_28_29:
  183. mV = 2800;
  184. break;
  185. case MMC_VDD_165_195:
  186. mV = 1850;
  187. break;
  188. default:
  189. BUG();
  190. }
  191. return menelaus_set_vmmc(mV);
  192. } else {
  193. if (!power_on)
  194. return menelaus_set_vdcdc(3, 0);
  195. switch (1 << vdd) {
  196. case MMC_VDD_33_34:
  197. case MMC_VDD_32_33:
  198. mV = 3300;
  199. break;
  200. case MMC_VDD_30_31:
  201. case MMC_VDD_29_30:
  202. mV = 3000;
  203. break;
  204. case MMC_VDD_28_29:
  205. case MMC_VDD_27_28:
  206. mV = 2800;
  207. break;
  208. case MMC_VDD_24_25:
  209. case MMC_VDD_23_24:
  210. mV = 2400;
  211. break;
  212. case MMC_VDD_22_23:
  213. case MMC_VDD_21_22:
  214. mV = 2200;
  215. break;
  216. case MMC_VDD_20_21:
  217. mV = 2000;
  218. break;
  219. case MMC_VDD_165_195:
  220. mV = 1800;
  221. break;
  222. default:
  223. BUG();
  224. }
  225. return menelaus_set_vdcdc(3, mV);
  226. }
  227. return 0;
  228. }
  229. static void n810_set_power_emmc(struct device *dev,
  230. int power_on)
  231. {
  232. dev_dbg(dev, "Set EMMC power %s\n", power_on ? "on" : "off");
  233. if (power_on) {
  234. gpio_set_value(N810_EMMC_VSD_GPIO, 1);
  235. msleep(1);
  236. gpio_set_value(N810_EMMC_VIO_GPIO, 1);
  237. msleep(1);
  238. } else {
  239. gpio_set_value(N810_EMMC_VIO_GPIO, 0);
  240. msleep(50);
  241. gpio_set_value(N810_EMMC_VSD_GPIO, 0);
  242. msleep(50);
  243. }
  244. }
  245. static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,
  246. int vdd)
  247. {
  248. if (board_is_n800() || slot == 0)
  249. return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);
  250. n810_set_power_emmc(dev, power_on);
  251. return 0;
  252. }
  253. static int n8x0_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
  254. {
  255. int r;
  256. dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
  257. bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
  258. BUG_ON(slot != 0 && slot != 1);
  259. slot++;
  260. switch (bus_mode) {
  261. case MMC_BUSMODE_OPENDRAIN:
  262. r = menelaus_set_mmc_opendrain(slot, 1);
  263. break;
  264. case MMC_BUSMODE_PUSHPULL:
  265. r = menelaus_set_mmc_opendrain(slot, 0);
  266. break;
  267. default:
  268. BUG();
  269. }
  270. if (r != 0 && printk_ratelimit())
  271. dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
  272. slot);
  273. return r;
  274. }
  275. static int n8x0_mmc_get_cover_state(struct device *dev, int slot)
  276. {
  277. slot++;
  278. BUG_ON(slot != 1 && slot != 2);
  279. if (slot == 1)
  280. return slot1_cover_open;
  281. else
  282. return slot2_cover_open;
  283. }
  284. static void n8x0_mmc_callback(void *data, u8 card_mask)
  285. {
  286. int bit, *openp, index;
  287. if (board_is_n800()) {
  288. bit = 1 << 1;
  289. openp = &slot2_cover_open;
  290. index = 1;
  291. } else {
  292. bit = 1;
  293. openp = &slot1_cover_open;
  294. index = 0;
  295. }
  296. if (card_mask & bit)
  297. *openp = 1;
  298. else
  299. *openp = 0;
  300. #ifdef CONFIG_MMC_OMAP
  301. omap_mmc_notify_cover_event(mmc_device, index, *openp);
  302. #else
  303. pr_warn("MMC: notify cover event not available\n");
  304. #endif
  305. }
  306. static int n8x0_mmc_late_init(struct device *dev)
  307. {
  308. int r, bit, *openp;
  309. int vs2sel;
  310. mmc_device = dev;
  311. r = menelaus_set_slot_sel(1);
  312. if (r < 0)
  313. return r;
  314. if (board_is_n800())
  315. vs2sel = 0;
  316. else
  317. vs2sel = 2;
  318. r = menelaus_set_mmc_slot(2, 0, vs2sel, 1);
  319. if (r < 0)
  320. return r;
  321. n8x0_mmc_set_power(dev, 0, MMC_POWER_ON, 16); /* MMC_VDD_28_29 */
  322. n8x0_mmc_set_power(dev, 1, MMC_POWER_ON, 16);
  323. r = menelaus_set_mmc_slot(1, 1, 0, 1);
  324. if (r < 0)
  325. return r;
  326. r = menelaus_set_mmc_slot(2, 1, vs2sel, 1);
  327. if (r < 0)
  328. return r;
  329. r = menelaus_get_slot_pin_states();
  330. if (r < 0)
  331. return r;
  332. if (board_is_n800()) {
  333. bit = 1 << 1;
  334. openp = &slot2_cover_open;
  335. } else {
  336. bit = 1;
  337. openp = &slot1_cover_open;
  338. slot2_cover_open = 0;
  339. }
  340. /* All slot pin bits seem to be inversed until first switch change */
  341. if (r == 0xf || r == (0xf & ~bit))
  342. r = ~r;
  343. if (r & bit)
  344. *openp = 1;
  345. else
  346. *openp = 0;
  347. r = menelaus_register_mmc_callback(n8x0_mmc_callback, NULL);
  348. return r;
  349. }
  350. static void n8x0_mmc_shutdown(struct device *dev)
  351. {
  352. int vs2sel;
  353. if (board_is_n800())
  354. vs2sel = 0;
  355. else
  356. vs2sel = 2;
  357. menelaus_set_mmc_slot(1, 0, 0, 0);
  358. menelaus_set_mmc_slot(2, 0, vs2sel, 0);
  359. }
  360. static void n8x0_mmc_cleanup(struct device *dev)
  361. {
  362. menelaus_unregister_mmc_callback();
  363. gpio_free(N8X0_SLOT_SWITCH_GPIO);
  364. if (board_is_n810()) {
  365. gpio_free(N810_EMMC_VSD_GPIO);
  366. gpio_free(N810_EMMC_VIO_GPIO);
  367. }
  368. }
  369. /*
  370. * MMC controller1 has two slots that are multiplexed via I2C.
  371. * MMC controller2 is not in use.
  372. */
  373. static struct omap_mmc_platform_data mmc1_data = {
  374. .nr_slots = 0,
  375. .switch_slot = n8x0_mmc_switch_slot,
  376. .init = n8x0_mmc_late_init,
  377. .cleanup = n8x0_mmc_cleanup,
  378. .shutdown = n8x0_mmc_shutdown,
  379. .max_freq = 24000000,
  380. .slots[0] = {
  381. .wires = 4,
  382. .set_power = n8x0_mmc_set_power,
  383. .set_bus_mode = n8x0_mmc_set_bus_mode,
  384. .get_cover_state = n8x0_mmc_get_cover_state,
  385. .ocr_mask = MMC_VDD_165_195 | MMC_VDD_30_31 |
  386. MMC_VDD_32_33 | MMC_VDD_33_34,
  387. .name = "internal",
  388. },
  389. .slots[1] = {
  390. .set_power = n8x0_mmc_set_power,
  391. .set_bus_mode = n8x0_mmc_set_bus_mode,
  392. .get_cover_state = n8x0_mmc_get_cover_state,
  393. .ocr_mask = MMC_VDD_165_195 | MMC_VDD_20_21 |
  394. MMC_VDD_21_22 | MMC_VDD_22_23 |
  395. MMC_VDD_23_24 | MMC_VDD_24_25 |
  396. MMC_VDD_27_28 | MMC_VDD_28_29 |
  397. MMC_VDD_29_30 | MMC_VDD_30_31 |
  398. MMC_VDD_32_33 | MMC_VDD_33_34,
  399. .name = "external",
  400. },
  401. };
  402. static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
  403. static struct gpio n810_emmc_gpios[] __initdata = {
  404. { N810_EMMC_VSD_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vddf" },
  405. { N810_EMMC_VIO_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vdd" },
  406. };
  407. static void __init n8x0_mmc_init(void)
  408. {
  409. int err;
  410. if (board_is_n810()) {
  411. mmc1_data.slots[0].name = "external";
  412. /*
  413. * Some Samsung Movinand chips do not like open-ended
  414. * multi-block reads and fall to braind-dead state
  415. * while doing so. Reducing the number of blocks in
  416. * the transfer or delays in clock disable do not help
  417. */
  418. mmc1_data.slots[1].name = "internal";
  419. mmc1_data.slots[1].ban_openended = 1;
  420. }
  421. err = gpio_request_one(N8X0_SLOT_SWITCH_GPIO, GPIOF_OUT_INIT_LOW,
  422. "MMC slot switch");
  423. if (err)
  424. return;
  425. if (board_is_n810()) {
  426. err = gpio_request_array(n810_emmc_gpios,
  427. ARRAY_SIZE(n810_emmc_gpios));
  428. if (err) {
  429. gpio_free(N8X0_SLOT_SWITCH_GPIO);
  430. return;
  431. }
  432. }
  433. mmc1_data.nr_slots = 2;
  434. mmc_data[0] = &mmc1_data;
  435. }
  436. #else
  437. static struct omap_mmc_platform_data mmc1_data;
  438. void __init n8x0_mmc_init(void)
  439. {
  440. }
  441. #endif /* CONFIG_MMC_OMAP */
  442. #ifdef CONFIG_MENELAUS
  443. static int n8x0_auto_sleep_regulators(void)
  444. {
  445. u32 val;
  446. int ret;
  447. val = EN_VPLL_SLEEP | EN_VMMC_SLEEP \
  448. | EN_VAUX_SLEEP | EN_VIO_SLEEP \
  449. | EN_VMEM_SLEEP | EN_DC3_SLEEP \
  450. | EN_VC_SLEEP | EN_DC2_SLEEP;
  451. ret = menelaus_set_regulator_sleep(1, val);
  452. if (ret < 0) {
  453. pr_err("Could not set regulators to sleep on menelaus: %u\n",
  454. ret);
  455. return ret;
  456. }
  457. return 0;
  458. }
  459. static int n8x0_auto_voltage_scale(void)
  460. {
  461. int ret;
  462. ret = menelaus_set_vcore_hw(1400, 1050);
  463. if (ret < 0) {
  464. pr_err("Could not set VCORE voltage on menelaus: %u\n", ret);
  465. return ret;
  466. }
  467. return 0;
  468. }
  469. static int n8x0_menelaus_late_init(struct device *dev)
  470. {
  471. int ret;
  472. ret = n8x0_auto_voltage_scale();
  473. if (ret < 0)
  474. return ret;
  475. ret = n8x0_auto_sleep_regulators();
  476. if (ret < 0)
  477. return ret;
  478. return 0;
  479. }
  480. #else
  481. static int n8x0_menelaus_late_init(struct device *dev)
  482. {
  483. return 0;
  484. }
  485. #endif
  486. struct menelaus_platform_data n8x0_menelaus_platform_data = {
  487. .late_init = n8x0_menelaus_late_init,
  488. };
  489. struct aic3x_pdata n810_aic33_data = {
  490. .gpio_reset = 118,
  491. };
  492. static int __init n8x0_late_initcall(void)
  493. {
  494. if (!board_caps)
  495. return -ENODEV;
  496. n8x0_mmc_init();
  497. n8x0_usb_init();
  498. return 0;
  499. }
  500. omap_late_initcall(n8x0_late_initcall);
  501. /*
  502. * Legacy init pdata init for n8x0. Note that we want to follow the
  503. * I2C bus numbering starting at 0 for device tree like other omaps.
  504. */
  505. void * __init n8x0_legacy_init(void)
  506. {
  507. board_check_revision();
  508. spi_register_board_info(n800_spi_board_info,
  509. ARRAY_SIZE(n800_spi_board_info));
  510. return &mmc1_data;
  511. }