board-osk.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * linux/arch/arm/mach-omap1/board-osk.c
  3. *
  4. * Board specific init for OMAP5912 OSK
  5. *
  6. * Written by Dirk Behme <dirk.behme@de.bosch.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  16. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  19. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #include <linux/gpio/consumer.h>
  29. #include <linux/gpio/driver.h>
  30. #include <linux/gpio/machine.h>
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/irq.h>
  36. #include <linux/i2c.h>
  37. #include <linux/leds.h>
  38. #include <linux/smc91x.h>
  39. #include <linux/omapfb.h>
  40. #include <linux/mtd/mtd.h>
  41. #include <linux/mtd/partitions.h>
  42. #include <linux/mtd/physmap.h>
  43. #include <linux/mfd/tps65010.h>
  44. #include <linux/platform_data/gpio-omap.h>
  45. #include <linux/platform_data/omap1_bl.h>
  46. #include <linux/soc/ti/omap1-io.h>
  47. #include <asm/mach-types.h>
  48. #include <asm/mach/arch.h>
  49. #include <asm/mach/map.h>
  50. #include "tc.h"
  51. #include "flash.h"
  52. #include "mux.h"
  53. #include "hardware.h"
  54. #include "usb.h"
  55. #include "common.h"
  56. /* Name of the GPIO chip used by the OMAP for GPIOs 0..15 */
  57. #define OMAP_GPIO_LABEL "gpio-0-15"
  58. /* At OMAP5912 OSK the Ethernet is directly connected to CS1 */
  59. #define OMAP_OSK_ETHR_START 0x04800300
  60. /* TPS65010 has four GPIOs. nPG and LED2 can be treated like GPIOs with
  61. * alternate pin configurations for hardware-controlled blinking.
  62. */
  63. #define OSK_TPS_GPIO_USB_PWR_EN 0
  64. #define OSK_TPS_GPIO_LED_D3 1
  65. #define OSK_TPS_GPIO_LAN_RESET 2
  66. #define OSK_TPS_GPIO_DSP_PWR_EN 3
  67. #define OSK_TPS_GPIO_LED_D9 4
  68. #define OSK_TPS_GPIO_LED_D2 5
  69. static struct mtd_partition osk_partitions[] = {
  70. /* bootloader (U-Boot, etc) in first sector */
  71. {
  72. .name = "bootloader",
  73. .offset = 0,
  74. .size = SZ_128K,
  75. .mask_flags = MTD_WRITEABLE, /* force read-only */
  76. },
  77. /* bootloader params in the next sector */
  78. {
  79. .name = "params",
  80. .offset = MTDPART_OFS_APPEND,
  81. .size = SZ_128K,
  82. .mask_flags = 0,
  83. }, {
  84. .name = "kernel",
  85. .offset = MTDPART_OFS_APPEND,
  86. .size = SZ_2M,
  87. .mask_flags = 0
  88. }, {
  89. .name = "filesystem",
  90. .offset = MTDPART_OFS_APPEND,
  91. .size = MTDPART_SIZ_FULL,
  92. .mask_flags = 0
  93. }
  94. };
  95. static struct physmap_flash_data osk_flash_data = {
  96. .width = 2,
  97. .set_vpp = omap1_set_vpp,
  98. .parts = osk_partitions,
  99. .nr_parts = ARRAY_SIZE(osk_partitions),
  100. };
  101. static struct resource osk_flash_resource = {
  102. /* this is on CS3, wherever it's mapped */
  103. .flags = IORESOURCE_MEM,
  104. };
  105. static struct platform_device osk5912_flash_device = {
  106. .name = "physmap-flash",
  107. .id = 0,
  108. .dev = {
  109. .platform_data = &osk_flash_data,
  110. },
  111. .num_resources = 1,
  112. .resource = &osk_flash_resource,
  113. };
  114. static struct smc91x_platdata osk5912_smc91x_info = {
  115. .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
  116. .leda = RPC_LED_100_10,
  117. .ledb = RPC_LED_TX_RX,
  118. };
  119. static struct resource osk5912_smc91x_resources[] = {
  120. [0] = {
  121. .start = OMAP_OSK_ETHR_START, /* Physical */
  122. .end = OMAP_OSK_ETHR_START + 0xf,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. [1] = {
  126. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  127. },
  128. };
  129. static struct platform_device osk5912_smc91x_device = {
  130. .name = "smc91x",
  131. .id = -1,
  132. .dev = {
  133. .platform_data = &osk5912_smc91x_info,
  134. },
  135. .num_resources = ARRAY_SIZE(osk5912_smc91x_resources),
  136. .resource = osk5912_smc91x_resources,
  137. };
  138. static struct resource osk5912_cf_resources[] = {
  139. [0] = {
  140. .flags = IORESOURCE_IRQ,
  141. },
  142. [1] = {
  143. .flags = IORESOURCE_MEM,
  144. },
  145. };
  146. static struct platform_device osk5912_cf_device = {
  147. .name = "omap_cf",
  148. .id = -1,
  149. .num_resources = ARRAY_SIZE(osk5912_cf_resources),
  150. .resource = osk5912_cf_resources,
  151. };
  152. static struct platform_device *osk5912_devices[] __initdata = {
  153. &osk5912_flash_device,
  154. &osk5912_smc91x_device,
  155. &osk5912_cf_device,
  156. };
  157. static const struct gpio_led tps_leds[] = {
  158. /* NOTE: D9 and D2 have hardware blink support.
  159. * Also, D9 requires non-battery power.
  160. */
  161. { .name = "d9", .default_trigger = "disk-activity", },
  162. { .name = "d2", },
  163. { .name = "d3", .default_trigger = "heartbeat", },
  164. };
  165. static struct gpiod_lookup_table tps_leds_gpio_table = {
  166. .dev_id = "leds-gpio",
  167. .table = {
  168. /* Use local offsets on TPS65010 */
  169. GPIO_LOOKUP_IDX("tps65010", OSK_TPS_GPIO_LED_D9, NULL, 0, GPIO_ACTIVE_HIGH),
  170. GPIO_LOOKUP_IDX("tps65010", OSK_TPS_GPIO_LED_D2, NULL, 1, GPIO_ACTIVE_HIGH),
  171. GPIO_LOOKUP_IDX("tps65010", OSK_TPS_GPIO_LED_D3, NULL, 2, GPIO_ACTIVE_LOW),
  172. { }
  173. },
  174. };
  175. static struct gpio_led_platform_data tps_leds_data = {
  176. .num_leds = 3,
  177. .leds = tps_leds,
  178. };
  179. static struct platform_device osk5912_tps_leds = {
  180. .name = "leds-gpio",
  181. .id = 0,
  182. .dev.platform_data = &tps_leds_data,
  183. };
  184. /* The board just hold these GPIOs hogged from setup to teardown */
  185. static struct gpio_desc *eth_reset;
  186. static struct gpio_desc *vdd_dsp;
  187. static int osk_tps_setup(struct i2c_client *client, struct gpio_chip *gc)
  188. {
  189. struct gpio_desc *d;
  190. if (!IS_BUILTIN(CONFIG_TPS65010))
  191. return -ENOSYS;
  192. /* Set GPIO 1 HIGH to disable VBUS power supply;
  193. * OHCI driver powers it up/down as needed.
  194. */
  195. d = gpiochip_request_own_desc(gc, OSK_TPS_GPIO_USB_PWR_EN, "n_vbus_en",
  196. GPIO_ACTIVE_HIGH, GPIOD_OUT_HIGH);
  197. /* Free the GPIO again as the driver will request it */
  198. gpiochip_free_own_desc(d);
  199. /* Set GPIO 2 high so LED D3 is off by default */
  200. tps65010_set_gpio_out_value(GPIO2, HIGH);
  201. /* Set GPIO 3 low to take ethernet out of reset */
  202. eth_reset = gpiochip_request_own_desc(gc, OSK_TPS_GPIO_LAN_RESET, "smc_reset",
  203. GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW);
  204. /* GPIO4 is VDD_DSP */
  205. vdd_dsp = gpiochip_request_own_desc(gc, OSK_TPS_GPIO_DSP_PWR_EN, "dsp_power",
  206. GPIO_ACTIVE_HIGH, GPIOD_OUT_HIGH);
  207. /* REVISIT if DSP support isn't configured, power it off ... */
  208. /* Let LED1 (D9) blink; leds-gpio may override it */
  209. tps65010_set_led(LED1, BLINK);
  210. /* Set LED2 off by default */
  211. tps65010_set_led(LED2, OFF);
  212. /* Enable LOW_PWR handshake */
  213. tps65010_set_low_pwr(ON);
  214. /* Switch VLDO2 to 3.0V for AIC23 */
  215. tps65010_config_vregs1(TPS_LDO2_ENABLE | TPS_VLDO2_3_0V
  216. | TPS_LDO1_ENABLE);
  217. /* register these three LEDs */
  218. osk5912_tps_leds.dev.parent = &client->dev;
  219. gpiod_add_lookup_table(&tps_leds_gpio_table);
  220. platform_device_register(&osk5912_tps_leds);
  221. return 0;
  222. }
  223. static void osk_tps_teardown(struct i2c_client *client, struct gpio_chip *gc)
  224. {
  225. gpiochip_free_own_desc(eth_reset);
  226. gpiochip_free_own_desc(vdd_dsp);
  227. }
  228. static struct tps65010_board tps_board = {
  229. .outmask = 0x0f,
  230. .setup = osk_tps_setup,
  231. .teardown = osk_tps_teardown,
  232. };
  233. static struct i2c_board_info __initdata osk_i2c_board_info[] = {
  234. {
  235. /* This device will get the name "i2c-tps65010" */
  236. I2C_BOARD_INFO("tps65010", 0x48),
  237. .dev_name = "tps65010",
  238. .platform_data = &tps_board,
  239. },
  240. {
  241. I2C_BOARD_INFO("tlv320aic23", 0x1B),
  242. },
  243. /* TODO when driver support is ready:
  244. * - optionally on Mistral, ov9640 camera sensor at 0x30
  245. */
  246. };
  247. static void __init osk_init_smc91x(void)
  248. {
  249. u32 l;
  250. /* Check EMIFS wait states to fix errors with SMC_GET_PKT_HDR */
  251. l = omap_readl(EMIFS_CCS(1));
  252. l |= 0x3;
  253. omap_writel(l, EMIFS_CCS(1));
  254. }
  255. static void __init osk_init_cf(int seg)
  256. {
  257. struct resource *res = &osk5912_cf_resources[1];
  258. omap_cfg_reg(M7_1610_GPIO62);
  259. switch (seg) {
  260. /* NOTE: CS0 could be configured too ... */
  261. case 1:
  262. res->start = OMAP_CS1_PHYS;
  263. break;
  264. case 2:
  265. res->start = OMAP_CS2_PHYS;
  266. break;
  267. case 3:
  268. res->start = omap_cs3_phys();
  269. break;
  270. }
  271. res->end = res->start + SZ_8K - 1;
  272. osk5912_cf_device.dev.platform_data = (void *)(uintptr_t)seg;
  273. /* NOTE: better EMIFS setup might support more cards; but the
  274. * TRM only shows how to affect regular flash signals, not their
  275. * CF/PCMCIA variants...
  276. */
  277. pr_debug("%s: cs%d, previous ccs %08x acs %08x\n", __func__,
  278. seg, omap_readl(EMIFS_CCS(seg)), omap_readl(EMIFS_ACS(seg)));
  279. omap_writel(0x0004a1b3, EMIFS_CCS(seg)); /* synch mode 4 etc */
  280. omap_writel(0x00000000, EMIFS_ACS(seg)); /* OE hold/setup */
  281. }
  282. static struct gpiod_lookup_table osk_usb_gpio_table = {
  283. .dev_id = "ohci",
  284. .table = {
  285. /* Power GPIO on the I2C-attached TPS65010 */
  286. GPIO_LOOKUP("tps65010", OSK_TPS_GPIO_USB_PWR_EN, "power",
  287. GPIO_ACTIVE_HIGH),
  288. GPIO_LOOKUP(OMAP_GPIO_LABEL, 9, "overcurrent",
  289. GPIO_ACTIVE_HIGH),
  290. { }
  291. },
  292. };
  293. static struct omap_usb_config osk_usb_config __initdata = {
  294. /* has usb host connector (A) ... for development it can also
  295. * be used, with a NONSTANDARD gender-bending cable/dongle, as
  296. * a peripheral.
  297. */
  298. #if IS_ENABLED(CONFIG_USB_OMAP)
  299. .register_dev = 1,
  300. .hmc_mode = 0,
  301. #else
  302. .register_host = 1,
  303. .hmc_mode = 16,
  304. .rwc = 1,
  305. #endif
  306. .pins[0] = 2,
  307. };
  308. #define EMIFS_CS3_VAL (0x88013141)
  309. static struct gpiod_lookup_table osk_irq_gpio_table = {
  310. .dev_id = NULL,
  311. .table = {
  312. /* GPIO used for SMC91x IRQ */
  313. GPIO_LOOKUP(OMAP_GPIO_LABEL, 0, "smc_irq",
  314. GPIO_ACTIVE_HIGH),
  315. /* GPIO used for CF IRQ */
  316. GPIO_LOOKUP("gpio-48-63", 14, "cf_irq",
  317. GPIO_ACTIVE_HIGH),
  318. /* GPIO used by the TPS65010 chip */
  319. GPIO_LOOKUP("mpuio", 1, "tps65010",
  320. GPIO_ACTIVE_HIGH),
  321. /* GPIOs used for serial wakeup IRQs */
  322. GPIO_LOOKUP_IDX("gpio-32-47", 5, "wakeup", 0,
  323. GPIO_ACTIVE_HIGH),
  324. GPIO_LOOKUP_IDX("gpio-16-31", 2, "wakeup", 1,
  325. GPIO_ACTIVE_HIGH),
  326. GPIO_LOOKUP_IDX("gpio-48-63", 1, "wakeup", 2,
  327. GPIO_ACTIVE_HIGH),
  328. { }
  329. },
  330. };
  331. static void __init osk_init(void)
  332. {
  333. struct gpio_desc *d;
  334. u32 l;
  335. osk_init_smc91x();
  336. osk_init_cf(2); /* CS2 */
  337. /* Workaround for wrong CS3 (NOR flash) timing
  338. * There are some U-Boot versions out there which configure
  339. * wrong CS3 memory timings. This mainly leads to CRC
  340. * or similar errors if you use NOR flash (e.g. with JFFS2)
  341. */
  342. l = omap_readl(EMIFS_CCS(3));
  343. if (l != EMIFS_CS3_VAL)
  344. omap_writel(EMIFS_CS3_VAL, EMIFS_CCS(3));
  345. osk_flash_resource.end = osk_flash_resource.start = omap_cs3_phys();
  346. osk_flash_resource.end += SZ_32M - 1;
  347. /*
  348. * Add the GPIOs to be used as IRQs and immediately look them up
  349. * to be passed as an IRQ resource. This is ugly but should work
  350. * until the day we convert to device tree.
  351. */
  352. gpiod_add_lookup_table(&osk_irq_gpio_table);
  353. d = gpiod_get(NULL, "smc_irq", GPIOD_IN);
  354. if (IS_ERR(d)) {
  355. pr_err("Unable to get SMC IRQ GPIO descriptor\n");
  356. } else {
  357. irq_set_irq_type(gpiod_to_irq(d), IRQ_TYPE_EDGE_RISING);
  358. osk5912_smc91x_resources[1] = DEFINE_RES_IRQ(gpiod_to_irq(d));
  359. }
  360. d = gpiod_get(NULL, "cf_irq", GPIOD_IN);
  361. if (IS_ERR(d)) {
  362. pr_err("Unable to get CF IRQ GPIO descriptor\n");
  363. } else {
  364. /* the CF I/O IRQ is really active-low */
  365. irq_set_irq_type(gpiod_to_irq(d), IRQ_TYPE_EDGE_FALLING);
  366. osk5912_cf_resources[0] = DEFINE_RES_IRQ(gpiod_to_irq(d));
  367. }
  368. platform_add_devices(osk5912_devices, ARRAY_SIZE(osk5912_devices));
  369. l = omap_readl(USB_TRANSCEIVER_CTRL);
  370. l |= (3 << 1);
  371. omap_writel(l, USB_TRANSCEIVER_CTRL);
  372. gpiod_add_lookup_table(&osk_usb_gpio_table);
  373. omap1_usb_init(&osk_usb_config);
  374. omap_serial_init();
  375. /* irq for tps65010 chip */
  376. /* bootloader effectively does: omap_cfg_reg(U19_1610_MPUIO1); */
  377. d = gpiod_get(NULL, "tps65010", GPIOD_IN);
  378. if (IS_ERR(d))
  379. pr_err("Unable to get TPS65010 IRQ GPIO descriptor\n");
  380. else
  381. osk_i2c_board_info[0].irq = gpiod_to_irq(d);
  382. omap_register_i2c_bus(1, 400, osk_i2c_board_info,
  383. ARRAY_SIZE(osk_i2c_board_info));
  384. }
  385. MACHINE_START(OMAP_OSK, "TI-OSK")
  386. /* Maintainer: Dirk Behme <dirk.behme@de.bosch.com> */
  387. .atag_offset = 0x100,
  388. .map_io = omap1_map_io,
  389. .init_early = omap1_init_early,
  390. .init_irq = omap1_init_irq,
  391. .init_machine = osk_init,
  392. .init_late = omap1_init_late,
  393. .init_time = omap1_timer_init,
  394. .restart = omap1_restart,
  395. MACHINE_END