board-n8x0.c 13 KB

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