board-mop500.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. * Copyright (C) 2008-2009 ST-Ericsson
  3. *
  4. * Author: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <linux/i2c.h>
  17. #include <linux/gpio.h>
  18. #include <linux/amba/bus.h>
  19. #include <linux/amba/pl022.h>
  20. #include <linux/amba/serial.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/mfd/ab8500.h>
  23. #include <linux/regulator/ab8500.h>
  24. #include <linux/mfd/tc3589x.h>
  25. #include <linux/mfd/tps6105x.h>
  26. #include <linux/mfd/ab8500/gpio.h>
  27. #include <linux/leds-lp5521.h>
  28. #include <linux/input.h>
  29. #include <linux/gpio_keys.h>
  30. #include <linux/delay.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <plat/i2c.h>
  34. #include <plat/ste_dma40.h>
  35. #include <plat/pincfg.h>
  36. #include <mach/hardware.h>
  37. #include <mach/setup.h>
  38. #include <mach/devices.h>
  39. #include <mach/irqs.h>
  40. #include "pins-db8500.h"
  41. #include "ste-dma40-db8500.h"
  42. #include "devices-db8500.h"
  43. #include "board-mop500.h"
  44. #include "board-mop500-regulators.h"
  45. static struct ab8500_gpio_platform_data ab8500_gpio_pdata = {
  46. .gpio_base = MOP500_AB8500_GPIO(0),
  47. .irq_base = MOP500_AB8500_VIR_GPIO_IRQ_BASE,
  48. /* config_reg is the initial configuration of ab8500 pins.
  49. * The pins can be configured as GPIO or alt functions based
  50. * on value present in GpioSel1 to GpioSel6 and AlternatFunction
  51. * register. This is the array of 7 configuration settings.
  52. * One has to compile time decide these settings. Below is the
  53. * explanation of these setting
  54. * GpioSel1 = 0x00 => Pins GPIO1 to GPIO8 are not used as GPIO
  55. * GpioSel2 = 0x1E => Pins GPIO10 to GPIO13 are configured as GPIO
  56. * GpioSel3 = 0x80 => Pin GPIO24 is configured as GPIO
  57. * GpioSel4 = 0x01 => Pin GPIo25 is configured as GPIO
  58. * GpioSel5 = 0x7A => Pins GPIO34, GPIO36 to GPIO39 are conf as GPIO
  59. * GpioSel6 = 0x00 => Pins GPIO41 & GPIo42 are not configured as GPIO
  60. * AlternaFunction = 0x00 => If Pins GPIO10 to 13 are not configured
  61. * as GPIO then this register selectes the alternate fucntions
  62. */
  63. .config_reg = {0x00, 0x1E, 0x80, 0x01,
  64. 0x7A, 0x00, 0x00},
  65. };
  66. static struct ab8500_platform_data ab8500_platdata = {
  67. .irq_base = MOP500_AB8500_IRQ_BASE,
  68. .regulator_reg_init = ab8500_regulator_reg_init,
  69. .num_regulator_reg_init = ARRAY_SIZE(ab8500_regulator_reg_init),
  70. .regulator = ab8500_regulators,
  71. .num_regulator = ARRAY_SIZE(ab8500_regulators),
  72. .gpio = &ab8500_gpio_pdata,
  73. };
  74. static struct resource ab8500_resources[] = {
  75. [0] = {
  76. .start = IRQ_DB8500_AB8500,
  77. .end = IRQ_DB8500_AB8500,
  78. .flags = IORESOURCE_IRQ
  79. }
  80. };
  81. struct platform_device ab8500_device = {
  82. .name = "ab8500-i2c",
  83. .id = 0,
  84. .dev = {
  85. .platform_data = &ab8500_platdata,
  86. },
  87. .num_resources = 1,
  88. .resource = ab8500_resources,
  89. };
  90. /*
  91. * TPS61052
  92. */
  93. static struct tps6105x_platform_data mop500_tps61052_data = {
  94. .mode = TPS6105X_MODE_VOLTAGE,
  95. .regulator_data = &tps61052_regulator,
  96. };
  97. /*
  98. * TC35892
  99. */
  100. static void mop500_tc35892_init(struct tc3589x *tc3589x, unsigned int base)
  101. {
  102. mop500_sdi_tc35892_init();
  103. }
  104. static struct tc3589x_gpio_platform_data mop500_tc35892_gpio_data = {
  105. .gpio_base = MOP500_EGPIO(0),
  106. .setup = mop500_tc35892_init,
  107. };
  108. static struct tc3589x_platform_data mop500_tc35892_data = {
  109. .block = TC3589x_BLOCK_GPIO,
  110. .gpio = &mop500_tc35892_gpio_data,
  111. .irq_base = MOP500_EGPIO_IRQ_BASE,
  112. };
  113. static struct lp5521_led_config lp5521_pri_led[] = {
  114. [0] = {
  115. .chan_nr = 0,
  116. .led_current = 0x2f,
  117. .max_current = 0x5f,
  118. },
  119. [1] = {
  120. .chan_nr = 1,
  121. .led_current = 0x2f,
  122. .max_current = 0x5f,
  123. },
  124. [2] = {
  125. .chan_nr = 2,
  126. .led_current = 0x2f,
  127. .max_current = 0x5f,
  128. },
  129. };
  130. static struct lp5521_platform_data __initdata lp5521_pri_data = {
  131. .label = "lp5521_pri",
  132. .led_config = &lp5521_pri_led[0],
  133. .num_channels = 3,
  134. .clock_mode = LP5521_CLOCK_EXT,
  135. };
  136. static struct lp5521_led_config lp5521_sec_led[] = {
  137. [0] = {
  138. .chan_nr = 0,
  139. .led_current = 0x2f,
  140. .max_current = 0x5f,
  141. },
  142. [1] = {
  143. .chan_nr = 1,
  144. .led_current = 0x2f,
  145. .max_current = 0x5f,
  146. },
  147. [2] = {
  148. .chan_nr = 2,
  149. .led_current = 0x2f,
  150. .max_current = 0x5f,
  151. },
  152. };
  153. static struct lp5521_platform_data __initdata lp5521_sec_data = {
  154. .label = "lp5521_sec",
  155. .led_config = &lp5521_sec_led[0],
  156. .num_channels = 3,
  157. .clock_mode = LP5521_CLOCK_EXT,
  158. };
  159. static struct i2c_board_info __initdata mop500_i2c0_devices[] = {
  160. {
  161. I2C_BOARD_INFO("tc3589x", 0x42),
  162. .irq = NOMADIK_GPIO_TO_IRQ(217),
  163. .platform_data = &mop500_tc35892_data,
  164. },
  165. /* I2C0 devices only available prior to HREFv60 */
  166. {
  167. I2C_BOARD_INFO("tps61052", 0x33),
  168. .platform_data = &mop500_tps61052_data,
  169. },
  170. };
  171. #define NUM_PRE_V60_I2C0_DEVICES 1
  172. static struct i2c_board_info __initdata mop500_i2c2_devices[] = {
  173. {
  174. /* lp5521 LED driver, 1st device */
  175. I2C_BOARD_INFO("lp5521", 0x33),
  176. .platform_data = &lp5521_pri_data,
  177. },
  178. {
  179. /* lp5521 LED driver, 2st device */
  180. I2C_BOARD_INFO("lp5521", 0x34),
  181. .platform_data = &lp5521_sec_data,
  182. },
  183. {
  184. /* Light sensor Rohm BH1780GLI */
  185. I2C_BOARD_INFO("bh1780", 0x29),
  186. },
  187. };
  188. #define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, t_out, _sm) \
  189. static struct nmk_i2c_controller u8500_i2c##id##_data = { \
  190. /* \
  191. * slave data setup time, which is \
  192. * 250 ns,100ns,10ns which is 14,6,2 \
  193. * respectively for a 48 Mhz \
  194. * i2c clock \
  195. */ \
  196. .slsu = _slsu, \
  197. /* Tx FIFO threshold */ \
  198. .tft = _tft, \
  199. /* Rx FIFO threshold */ \
  200. .rft = _rft, \
  201. /* std. mode operation */ \
  202. .clk_freq = clk, \
  203. /* Slave response timeout(ms) */\
  204. .timeout = t_out, \
  205. .sm = _sm, \
  206. }
  207. /*
  208. * The board uses 4 i2c controllers, initialize all of
  209. * them with slave data setup time of 250 ns,
  210. * Tx & Rx FIFO threshold values as 8 and standard
  211. * mode of operation
  212. */
  213. U8500_I2C_CONTROLLER(0, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
  214. U8500_I2C_CONTROLLER(1, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
  215. U8500_I2C_CONTROLLER(2, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
  216. U8500_I2C_CONTROLLER(3, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
  217. static void __init mop500_i2c_init(void)
  218. {
  219. db8500_add_i2c0(&u8500_i2c0_data);
  220. db8500_add_i2c1(&u8500_i2c1_data);
  221. db8500_add_i2c2(&u8500_i2c2_data);
  222. db8500_add_i2c3(&u8500_i2c3_data);
  223. }
  224. static struct gpio_keys_button mop500_gpio_keys[] = {
  225. {
  226. .desc = "SFH7741 Proximity Sensor",
  227. .type = EV_SW,
  228. .code = SW_FRONT_PROXIMITY,
  229. .active_low = 0,
  230. .can_disable = 1,
  231. }
  232. };
  233. static struct regulator *prox_regulator;
  234. static int mop500_prox_activate(struct device *dev);
  235. static void mop500_prox_deactivate(struct device *dev);
  236. static struct gpio_keys_platform_data mop500_gpio_keys_data = {
  237. .buttons = mop500_gpio_keys,
  238. .nbuttons = ARRAY_SIZE(mop500_gpio_keys),
  239. .enable = mop500_prox_activate,
  240. .disable = mop500_prox_deactivate,
  241. };
  242. static struct platform_device mop500_gpio_keys_device = {
  243. .name = "gpio-keys",
  244. .id = 0,
  245. .dev = {
  246. .platform_data = &mop500_gpio_keys_data,
  247. },
  248. };
  249. static int mop500_prox_activate(struct device *dev)
  250. {
  251. prox_regulator = regulator_get(&mop500_gpio_keys_device.dev,
  252. "vcc");
  253. if (IS_ERR(prox_regulator)) {
  254. dev_err(&mop500_gpio_keys_device.dev,
  255. "no regulator\n");
  256. return PTR_ERR(prox_regulator);
  257. }
  258. regulator_enable(prox_regulator);
  259. return 0;
  260. }
  261. static void mop500_prox_deactivate(struct device *dev)
  262. {
  263. regulator_disable(prox_regulator);
  264. regulator_put(prox_regulator);
  265. }
  266. /* add any platform devices here - TODO */
  267. static struct platform_device *platform_devs[] __initdata = {
  268. &mop500_gpio_keys_device,
  269. };
  270. #ifdef CONFIG_STE_DMA40
  271. static struct stedma40_chan_cfg ssp0_dma_cfg_rx = {
  272. .mode = STEDMA40_MODE_LOGICAL,
  273. .dir = STEDMA40_PERIPH_TO_MEM,
  274. .src_dev_type = DB8500_DMA_DEV8_SSP0_RX,
  275. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  276. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  277. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  278. };
  279. static struct stedma40_chan_cfg ssp0_dma_cfg_tx = {
  280. .mode = STEDMA40_MODE_LOGICAL,
  281. .dir = STEDMA40_MEM_TO_PERIPH,
  282. .src_dev_type = STEDMA40_DEV_SRC_MEMORY,
  283. .dst_dev_type = DB8500_DMA_DEV8_SSP0_TX,
  284. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  285. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  286. };
  287. #endif
  288. static struct pl022_ssp_controller ssp0_platform_data = {
  289. .bus_id = 0,
  290. #ifdef CONFIG_STE_DMA40
  291. .enable_dma = 1,
  292. .dma_filter = stedma40_filter,
  293. .dma_rx_param = &ssp0_dma_cfg_rx,
  294. .dma_tx_param = &ssp0_dma_cfg_tx,
  295. #else
  296. .enable_dma = 0,
  297. #endif
  298. /* on this platform, gpio 31,142,144,214 &
  299. * 224 are connected as chip selects
  300. */
  301. .num_chipselect = 5,
  302. };
  303. static void __init mop500_spi_init(void)
  304. {
  305. db8500_add_ssp0(&ssp0_platform_data);
  306. }
  307. #ifdef CONFIG_STE_DMA40
  308. static struct stedma40_chan_cfg uart0_dma_cfg_rx = {
  309. .mode = STEDMA40_MODE_LOGICAL,
  310. .dir = STEDMA40_PERIPH_TO_MEM,
  311. .src_dev_type = DB8500_DMA_DEV13_UART0_RX,
  312. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  313. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  314. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  315. };
  316. static struct stedma40_chan_cfg uart0_dma_cfg_tx = {
  317. .mode = STEDMA40_MODE_LOGICAL,
  318. .dir = STEDMA40_MEM_TO_PERIPH,
  319. .src_dev_type = STEDMA40_DEV_SRC_MEMORY,
  320. .dst_dev_type = DB8500_DMA_DEV13_UART0_TX,
  321. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  322. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  323. };
  324. static struct stedma40_chan_cfg uart1_dma_cfg_rx = {
  325. .mode = STEDMA40_MODE_LOGICAL,
  326. .dir = STEDMA40_PERIPH_TO_MEM,
  327. .src_dev_type = DB8500_DMA_DEV12_UART1_RX,
  328. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  329. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  330. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  331. };
  332. static struct stedma40_chan_cfg uart1_dma_cfg_tx = {
  333. .mode = STEDMA40_MODE_LOGICAL,
  334. .dir = STEDMA40_MEM_TO_PERIPH,
  335. .src_dev_type = STEDMA40_DEV_SRC_MEMORY,
  336. .dst_dev_type = DB8500_DMA_DEV12_UART1_TX,
  337. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  338. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  339. };
  340. static struct stedma40_chan_cfg uart2_dma_cfg_rx = {
  341. .mode = STEDMA40_MODE_LOGICAL,
  342. .dir = STEDMA40_PERIPH_TO_MEM,
  343. .src_dev_type = DB8500_DMA_DEV11_UART2_RX,
  344. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  345. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  346. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  347. };
  348. static struct stedma40_chan_cfg uart2_dma_cfg_tx = {
  349. .mode = STEDMA40_MODE_LOGICAL,
  350. .dir = STEDMA40_MEM_TO_PERIPH,
  351. .src_dev_type = STEDMA40_DEV_SRC_MEMORY,
  352. .dst_dev_type = DB8500_DMA_DEV11_UART2_TX,
  353. .src_info.data_width = STEDMA40_BYTE_WIDTH,
  354. .dst_info.data_width = STEDMA40_BYTE_WIDTH,
  355. };
  356. #endif
  357. static pin_cfg_t mop500_pins_uart0[] = {
  358. GPIO0_U0_CTSn | PIN_INPUT_PULLUP,
  359. GPIO1_U0_RTSn | PIN_OUTPUT_HIGH,
  360. GPIO2_U0_RXD | PIN_INPUT_PULLUP,
  361. GPIO3_U0_TXD | PIN_OUTPUT_HIGH,
  362. };
  363. #define PRCC_K_SOFTRST_SET 0x18
  364. #define PRCC_K_SOFTRST_CLEAR 0x1C
  365. static void ux500_uart0_reset(void)
  366. {
  367. void __iomem *prcc_rst_set, *prcc_rst_clr;
  368. prcc_rst_set = (void __iomem *)IO_ADDRESS(U8500_CLKRST1_BASE +
  369. PRCC_K_SOFTRST_SET);
  370. prcc_rst_clr = (void __iomem *)IO_ADDRESS(U8500_CLKRST1_BASE +
  371. PRCC_K_SOFTRST_CLEAR);
  372. /* Activate soft reset PRCC_K_SOFTRST_CLEAR */
  373. writel((readl(prcc_rst_clr) | 0x1), prcc_rst_clr);
  374. udelay(1);
  375. /* Release soft reset PRCC_K_SOFTRST_SET */
  376. writel((readl(prcc_rst_set) | 0x1), prcc_rst_set);
  377. udelay(1);
  378. }
  379. static void ux500_uart0_init(void)
  380. {
  381. int ret;
  382. ret = nmk_config_pins(mop500_pins_uart0,
  383. ARRAY_SIZE(mop500_pins_uart0));
  384. if (ret < 0)
  385. pr_err("pl011: uart pins_enable failed\n");
  386. }
  387. static void ux500_uart0_exit(void)
  388. {
  389. int ret;
  390. ret = nmk_config_pins_sleep(mop500_pins_uart0,
  391. ARRAY_SIZE(mop500_pins_uart0));
  392. if (ret < 0)
  393. pr_err("pl011: uart pins_disable failed\n");
  394. }
  395. static struct amba_pl011_data uart0_plat = {
  396. #ifdef CONFIG_STE_DMA40
  397. .dma_filter = stedma40_filter,
  398. .dma_rx_param = &uart0_dma_cfg_rx,
  399. .dma_tx_param = &uart0_dma_cfg_tx,
  400. #endif
  401. .init = ux500_uart0_init,
  402. .exit = ux500_uart0_exit,
  403. .reset = ux500_uart0_reset,
  404. };
  405. static struct amba_pl011_data uart1_plat = {
  406. #ifdef CONFIG_STE_DMA40
  407. .dma_filter = stedma40_filter,
  408. .dma_rx_param = &uart1_dma_cfg_rx,
  409. .dma_tx_param = &uart1_dma_cfg_tx,
  410. #endif
  411. };
  412. static struct amba_pl011_data uart2_plat = {
  413. #ifdef CONFIG_STE_DMA40
  414. .dma_filter = stedma40_filter,
  415. .dma_rx_param = &uart2_dma_cfg_rx,
  416. .dma_tx_param = &uart2_dma_cfg_tx,
  417. #endif
  418. };
  419. static void __init mop500_uart_init(void)
  420. {
  421. db8500_add_uart0(&uart0_plat);
  422. db8500_add_uart1(&uart1_plat);
  423. db8500_add_uart2(&uart2_plat);
  424. }
  425. static void __init mop500_init_machine(void)
  426. {
  427. int i2c0_devs;
  428. /*
  429. * The HREFv60 board removed a GPIO expander and routed
  430. * all these GPIO pins to the internal GPIO controller
  431. * instead.
  432. */
  433. if (machine_is_hrefv60())
  434. mop500_gpio_keys[0].gpio = HREFV60_PROX_SENSE_GPIO;
  435. else
  436. mop500_gpio_keys[0].gpio = GPIO_PROX_SENSOR;
  437. u8500_init_devices();
  438. mop500_pins_init();
  439. platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
  440. mop500_i2c_init();
  441. mop500_sdi_init();
  442. mop500_spi_init();
  443. mop500_uart_init();
  444. platform_device_register(&ab8500_device);
  445. i2c0_devs = ARRAY_SIZE(mop500_i2c0_devices);
  446. if (machine_is_hrefv60())
  447. i2c0_devs -= NUM_PRE_V60_I2C0_DEVICES;
  448. i2c_register_board_info(0, mop500_i2c0_devices, i2c0_devs);
  449. i2c_register_board_info(2, mop500_i2c2_devices,
  450. ARRAY_SIZE(mop500_i2c2_devices));
  451. }
  452. MACHINE_START(U8500, "ST-Ericsson MOP500 platform")
  453. /* Maintainer: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com> */
  454. .boot_params = 0x100,
  455. .map_io = u8500_map_io,
  456. .init_irq = ux500_init_irq,
  457. /* we re-use nomadik timer here */
  458. .timer = &ux500_timer,
  459. .init_machine = mop500_init_machine,
  460. MACHINE_END
  461. MACHINE_START(HREFV60, "ST-Ericsson U8500 Platform HREFv60+")
  462. .boot_params = 0x100,
  463. .map_io = u8500_map_io,
  464. .init_irq = ux500_init_irq,
  465. .timer = &ux500_timer,
  466. .init_machine = mop500_init_machine,
  467. MACHINE_END