mainstone.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * linux/arch/arm/mach-pxa/mainstone.c
  3. *
  4. * Support for the Intel HCDDBBVA0 Development Platform.
  5. * (go figure how they came up with such name...)
  6. *
  7. * Author: Nicolas Pitre
  8. * Created: Nov 05, 2002
  9. * Copyright: MontaVista Software Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/gpio.h>
  16. #include <linux/gpio/machine.h>
  17. #include <linux/init.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/syscore_ops.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/sched.h>
  22. #include <linux/bitops.h>
  23. #include <linux/fb.h>
  24. #include <linux/ioport.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/input.h>
  28. #include <linux/gpio_keys.h>
  29. #include <linux/pwm.h>
  30. #include <linux/pwm_backlight.h>
  31. #include <linux/smc91x.h>
  32. #include <linux/i2c/pxa-i2c.h>
  33. #include <linux/slab.h>
  34. #include <linux/leds.h>
  35. #include <asm/types.h>
  36. #include <asm/setup.h>
  37. #include <asm/memory.h>
  38. #include <asm/mach-types.h>
  39. #include <mach/hardware.h>
  40. #include <asm/irq.h>
  41. #include <asm/sizes.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/mach/map.h>
  44. #include <asm/mach/irq.h>
  45. #include <asm/mach/flash.h>
  46. #include "pxa27x.h"
  47. #include <mach/mainstone.h>
  48. #include <mach/audio.h>
  49. #include <linux/platform_data/video-pxafb.h>
  50. #include <linux/platform_data/mmc-pxamci.h>
  51. #include <linux/platform_data/irda-pxaficp.h>
  52. #include <linux/platform_data/usb-ohci-pxa27x.h>
  53. #include <linux/platform_data/keypad-pxa27x.h>
  54. #include <mach/smemc.h>
  55. #include "generic.h"
  56. #include "devices.h"
  57. static unsigned long mainstone_pin_config[] = {
  58. /* Chip Select */
  59. GPIO15_nCS_1,
  60. /* LCD - 16bpp Active TFT */
  61. GPIOxx_LCD_TFT_16BPP,
  62. GPIO16_PWM0_OUT, /* Backlight */
  63. /* MMC */
  64. GPIO32_MMC_CLK,
  65. GPIO112_MMC_CMD,
  66. GPIO92_MMC_DAT_0,
  67. GPIO109_MMC_DAT_1,
  68. GPIO110_MMC_DAT_2,
  69. GPIO111_MMC_DAT_3,
  70. /* USB Host Port 1 */
  71. GPIO88_USBH1_PWR,
  72. GPIO89_USBH1_PEN,
  73. /* PC Card */
  74. GPIO48_nPOE,
  75. GPIO49_nPWE,
  76. GPIO50_nPIOR,
  77. GPIO51_nPIOW,
  78. GPIO85_nPCE_1,
  79. GPIO54_nPCE_2,
  80. GPIO79_PSKTSEL,
  81. GPIO55_nPREG,
  82. GPIO56_nPWAIT,
  83. GPIO57_nIOIS16,
  84. /* AC97 */
  85. GPIO28_AC97_BITCLK,
  86. GPIO29_AC97_SDATA_IN_0,
  87. GPIO30_AC97_SDATA_OUT,
  88. GPIO31_AC97_SYNC,
  89. GPIO45_AC97_SYSCLK,
  90. /* Keypad */
  91. GPIO93_KP_DKIN_0,
  92. GPIO94_KP_DKIN_1,
  93. GPIO95_KP_DKIN_2,
  94. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  95. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  96. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  97. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  98. GPIO98_KP_MKIN_4 | WAKEUP_ON_LEVEL_HIGH,
  99. GPIO99_KP_MKIN_5 | WAKEUP_ON_LEVEL_HIGH,
  100. GPIO103_KP_MKOUT_0,
  101. GPIO104_KP_MKOUT_1,
  102. GPIO105_KP_MKOUT_2,
  103. GPIO106_KP_MKOUT_3,
  104. GPIO107_KP_MKOUT_4,
  105. GPIO108_KP_MKOUT_5,
  106. GPIO96_KP_MKOUT_6,
  107. /* I2C */
  108. GPIO117_I2C_SCL,
  109. GPIO118_I2C_SDA,
  110. /* GPIO */
  111. GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
  112. };
  113. static struct resource smc91x_resources[] = {
  114. [0] = {
  115. .start = (MST_ETH_PHYS + 0x300),
  116. .end = (MST_ETH_PHYS + 0xfffff),
  117. .flags = IORESOURCE_MEM,
  118. },
  119. [1] = {
  120. .start = MAINSTONE_IRQ(3),
  121. .end = MAINSTONE_IRQ(3),
  122. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  123. }
  124. };
  125. static struct smc91x_platdata mainstone_smc91x_info = {
  126. .flags = SMC91X_USE_8BIT | SMC91X_USE_16BIT | SMC91X_USE_32BIT |
  127. SMC91X_NOWAIT | SMC91X_USE_DMA,
  128. .pxa_u16_align4 = true,
  129. };
  130. static struct platform_device smc91x_device = {
  131. .name = "smc91x",
  132. .id = 0,
  133. .num_resources = ARRAY_SIZE(smc91x_resources),
  134. .resource = smc91x_resources,
  135. .dev = {
  136. .platform_data = &mainstone_smc91x_info,
  137. },
  138. };
  139. static int mst_audio_startup(struct snd_pcm_substream *substream, void *priv)
  140. {
  141. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  142. MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
  143. return 0;
  144. }
  145. static void mst_audio_shutdown(struct snd_pcm_substream *substream, void *priv)
  146. {
  147. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  148. MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
  149. }
  150. static long mst_audio_suspend_mask;
  151. static void mst_audio_suspend(void *priv)
  152. {
  153. mst_audio_suspend_mask = MST_MSCWR2;
  154. MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
  155. }
  156. static void mst_audio_resume(void *priv)
  157. {
  158. MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
  159. }
  160. static pxa2xx_audio_ops_t mst_audio_ops = {
  161. .startup = mst_audio_startup,
  162. .shutdown = mst_audio_shutdown,
  163. .suspend = mst_audio_suspend,
  164. .resume = mst_audio_resume,
  165. };
  166. static struct resource flash_resources[] = {
  167. [0] = {
  168. .start = PXA_CS0_PHYS,
  169. .end = PXA_CS0_PHYS + SZ_64M - 1,
  170. .flags = IORESOURCE_MEM,
  171. },
  172. [1] = {
  173. .start = PXA_CS1_PHYS,
  174. .end = PXA_CS1_PHYS + SZ_64M - 1,
  175. .flags = IORESOURCE_MEM,
  176. },
  177. };
  178. static struct mtd_partition mainstoneflash0_partitions[] = {
  179. {
  180. .name = "Bootloader",
  181. .size = 0x00040000,
  182. .offset = 0,
  183. .mask_flags = MTD_WRITEABLE /* force read-only */
  184. },{
  185. .name = "Kernel",
  186. .size = 0x00400000,
  187. .offset = 0x00040000,
  188. },{
  189. .name = "Filesystem",
  190. .size = MTDPART_SIZ_FULL,
  191. .offset = 0x00440000
  192. }
  193. };
  194. static struct flash_platform_data mst_flash_data[2] = {
  195. {
  196. .map_name = "cfi_probe",
  197. .parts = mainstoneflash0_partitions,
  198. .nr_parts = ARRAY_SIZE(mainstoneflash0_partitions),
  199. }, {
  200. .map_name = "cfi_probe",
  201. .parts = NULL,
  202. .nr_parts = 0,
  203. }
  204. };
  205. static struct platform_device mst_flash_device[2] = {
  206. {
  207. .name = "pxa2xx-flash",
  208. .id = 0,
  209. .dev = {
  210. .platform_data = &mst_flash_data[0],
  211. },
  212. .resource = &flash_resources[0],
  213. .num_resources = 1,
  214. },
  215. {
  216. .name = "pxa2xx-flash",
  217. .id = 1,
  218. .dev = {
  219. .platform_data = &mst_flash_data[1],
  220. },
  221. .resource = &flash_resources[1],
  222. .num_resources = 1,
  223. },
  224. };
  225. #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
  226. static struct pwm_lookup mainstone_pwm_lookup[] = {
  227. PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 78770,
  228. PWM_POLARITY_NORMAL),
  229. };
  230. static struct platform_pwm_backlight_data mainstone_backlight_data = {
  231. .max_brightness = 1023,
  232. .dft_brightness = 1023,
  233. .enable_gpio = -1,
  234. };
  235. static struct platform_device mainstone_backlight_device = {
  236. .name = "pwm-backlight",
  237. .dev = {
  238. .parent = &pxa27x_device_pwm0.dev,
  239. .platform_data = &mainstone_backlight_data,
  240. },
  241. };
  242. static void __init mainstone_backlight_register(void)
  243. {
  244. int ret;
  245. pwm_add_table(mainstone_pwm_lookup, ARRAY_SIZE(mainstone_pwm_lookup));
  246. ret = platform_device_register(&mainstone_backlight_device);
  247. if (ret) {
  248. printk(KERN_ERR "mainstone: failed to register backlight device: %d\n", ret);
  249. pwm_remove_table(mainstone_pwm_lookup,
  250. ARRAY_SIZE(mainstone_pwm_lookup));
  251. }
  252. }
  253. #else
  254. #define mainstone_backlight_register() do { } while (0)
  255. #endif
  256. static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
  257. .pixclock = 50000,
  258. .xres = 640,
  259. .yres = 480,
  260. .bpp = 16,
  261. .hsync_len = 1,
  262. .left_margin = 0x9f,
  263. .right_margin = 1,
  264. .vsync_len = 44,
  265. .upper_margin = 0,
  266. .lower_margin = 0,
  267. .sync = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  268. };
  269. static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
  270. .pixclock = 110000,
  271. .xres = 240,
  272. .yres = 320,
  273. .bpp = 16,
  274. .hsync_len = 4,
  275. .left_margin = 8,
  276. .right_margin = 20,
  277. .vsync_len = 3,
  278. .upper_margin = 1,
  279. .lower_margin = 10,
  280. .sync = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  281. };
  282. static struct pxafb_mach_info mainstone_pxafb_info = {
  283. .num_modes = 1,
  284. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  285. };
  286. static int mainstone_mci_init(struct device *dev, irq_handler_t mstone_detect_int, void *data)
  287. {
  288. int err;
  289. /* make sure SD/Memory Stick multiplexer's signals
  290. * are routed to MMC controller
  291. */
  292. MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL;
  293. err = request_irq(MAINSTONE_MMC_IRQ, mstone_detect_int, 0,
  294. "MMC card detect", data);
  295. if (err)
  296. printk(KERN_ERR "mainstone_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  297. return err;
  298. }
  299. static int mainstone_mci_setpower(struct device *dev, unsigned int vdd)
  300. {
  301. struct pxamci_platform_data* p_d = dev->platform_data;
  302. if (( 1 << vdd) & p_d->ocr_mask) {
  303. printk(KERN_DEBUG "%s: on\n", __func__);
  304. MST_MSCWR1 |= MST_MSCWR1_MMC_ON;
  305. MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL;
  306. } else {
  307. printk(KERN_DEBUG "%s: off\n", __func__);
  308. MST_MSCWR1 &= ~MST_MSCWR1_MMC_ON;
  309. }
  310. return 0;
  311. }
  312. static void mainstone_mci_exit(struct device *dev, void *data)
  313. {
  314. free_irq(MAINSTONE_MMC_IRQ, data);
  315. }
  316. static struct pxamci_platform_data mainstone_mci_platform_data = {
  317. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  318. .init = mainstone_mci_init,
  319. .setpower = mainstone_mci_setpower,
  320. .exit = mainstone_mci_exit,
  321. .gpio_card_detect = -1,
  322. .gpio_card_ro = -1,
  323. .gpio_power = -1,
  324. };
  325. static void mainstone_irda_transceiver_mode(struct device *dev, int mode)
  326. {
  327. unsigned long flags;
  328. local_irq_save(flags);
  329. if (mode & IR_SIRMODE) {
  330. MST_MSCWR1 &= ~MST_MSCWR1_IRDA_FIR;
  331. } else if (mode & IR_FIRMODE) {
  332. MST_MSCWR1 |= MST_MSCWR1_IRDA_FIR;
  333. }
  334. pxa2xx_transceiver_mode(dev, mode);
  335. if (mode & IR_OFF) {
  336. MST_MSCWR1 = (MST_MSCWR1 & ~MST_MSCWR1_IRDA_MASK) | MST_MSCWR1_IRDA_OFF;
  337. } else {
  338. MST_MSCWR1 = (MST_MSCWR1 & ~MST_MSCWR1_IRDA_MASK) | MST_MSCWR1_IRDA_FULL;
  339. }
  340. local_irq_restore(flags);
  341. }
  342. static struct pxaficp_platform_data mainstone_ficp_platform_data = {
  343. .gpio_pwdown = -1,
  344. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  345. .transceiver_mode = mainstone_irda_transceiver_mode,
  346. };
  347. static struct gpio_keys_button gpio_keys_button[] = {
  348. [0] = {
  349. .desc = "wakeup",
  350. .code = KEY_SUSPEND,
  351. .type = EV_KEY,
  352. .gpio = 1,
  353. .wakeup = 1,
  354. },
  355. };
  356. static struct gpio_keys_platform_data mainstone_gpio_keys = {
  357. .buttons = gpio_keys_button,
  358. .nbuttons = 1,
  359. };
  360. static struct platform_device mst_gpio_keys_device = {
  361. .name = "gpio-keys",
  362. .id = -1,
  363. .dev = {
  364. .platform_data = &mainstone_gpio_keys,
  365. },
  366. };
  367. static struct resource mst_cplds_resources[] = {
  368. [0] = {
  369. .start = MST_FPGA_PHYS + 0xc0,
  370. .end = MST_FPGA_PHYS + 0xe0 - 1,
  371. .flags = IORESOURCE_MEM,
  372. },
  373. [1] = {
  374. .start = PXA_GPIO_TO_IRQ(0),
  375. .end = PXA_GPIO_TO_IRQ(0),
  376. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
  377. },
  378. [2] = {
  379. .start = MAINSTONE_IRQ(0),
  380. .end = MAINSTONE_IRQ(15),
  381. .flags = IORESOURCE_IRQ,
  382. },
  383. };
  384. static struct platform_device mst_cplds_device = {
  385. .name = "pxa_cplds_irqs",
  386. .id = -1,
  387. .resource = &mst_cplds_resources[0],
  388. .num_resources = 3,
  389. };
  390. static struct platform_device *platform_devices[] __initdata = {
  391. &smc91x_device,
  392. &mst_flash_device[0],
  393. &mst_flash_device[1],
  394. &mst_gpio_keys_device,
  395. &mst_cplds_device,
  396. };
  397. static struct pxaohci_platform_data mainstone_ohci_platform_data = {
  398. .port_mode = PMM_PERPORT_MODE,
  399. .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
  400. };
  401. #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
  402. static const unsigned int mainstone_matrix_keys[] = {
  403. KEY(0, 0, KEY_A), KEY(1, 0, KEY_B), KEY(2, 0, KEY_C),
  404. KEY(3, 0, KEY_D), KEY(4, 0, KEY_E), KEY(5, 0, KEY_F),
  405. KEY(0, 1, KEY_G), KEY(1, 1, KEY_H), KEY(2, 1, KEY_I),
  406. KEY(3, 1, KEY_J), KEY(4, 1, KEY_K), KEY(5, 1, KEY_L),
  407. KEY(0, 2, KEY_M), KEY(1, 2, KEY_N), KEY(2, 2, KEY_O),
  408. KEY(3, 2, KEY_P), KEY(4, 2, KEY_Q), KEY(5, 2, KEY_R),
  409. KEY(0, 3, KEY_S), KEY(1, 3, KEY_T), KEY(2, 3, KEY_U),
  410. KEY(3, 3, KEY_V), KEY(4, 3, KEY_W), KEY(5, 3, KEY_X),
  411. KEY(2, 4, KEY_Y), KEY(3, 4, KEY_Z),
  412. KEY(0, 4, KEY_DOT), /* . */
  413. KEY(1, 4, KEY_CLOSE), /* @ */
  414. KEY(4, 4, KEY_SLASH),
  415. KEY(5, 4, KEY_BACKSLASH),
  416. KEY(0, 5, KEY_HOME),
  417. KEY(1, 5, KEY_LEFTSHIFT),
  418. KEY(2, 5, KEY_SPACE),
  419. KEY(3, 5, KEY_SPACE),
  420. KEY(4, 5, KEY_ENTER),
  421. KEY(5, 5, KEY_BACKSPACE),
  422. KEY(0, 6, KEY_UP),
  423. KEY(1, 6, KEY_DOWN),
  424. KEY(2, 6, KEY_LEFT),
  425. KEY(3, 6, KEY_RIGHT),
  426. KEY(4, 6, KEY_SELECT),
  427. };
  428. static struct matrix_keymap_data mainstone_matrix_keymap_data = {
  429. .keymap = mainstone_matrix_keys,
  430. .keymap_size = ARRAY_SIZE(mainstone_matrix_keys),
  431. };
  432. struct pxa27x_keypad_platform_data mainstone_keypad_info = {
  433. .matrix_key_rows = 6,
  434. .matrix_key_cols = 7,
  435. .matrix_keymap_data = &mainstone_matrix_keymap_data,
  436. .enable_rotary0 = 1,
  437. .rotary0_up_key = KEY_UP,
  438. .rotary0_down_key = KEY_DOWN,
  439. .debounce_interval = 30,
  440. };
  441. static void __init mainstone_init_keypad(void)
  442. {
  443. pxa_set_keypad_info(&mainstone_keypad_info);
  444. }
  445. #else
  446. static inline void mainstone_init_keypad(void) {}
  447. #endif
  448. static void __init mainstone_init(void)
  449. {
  450. int SW7 = 0; /* FIXME: get from SCR (Mst doc section 3.2.1.1) */
  451. pxa2xx_mfp_config(ARRAY_AND_SIZE(mainstone_pin_config));
  452. pxa_set_ffuart_info(NULL);
  453. pxa_set_btuart_info(NULL);
  454. pxa_set_stuart_info(NULL);
  455. mst_flash_data[0].width = (__raw_readl(BOOT_DEF) & 1) ? 2 : 4;
  456. mst_flash_data[1].width = 4;
  457. /* Compensate for SW7 which swaps the flash banks */
  458. mst_flash_data[SW7].name = "processor-flash";
  459. mst_flash_data[SW7 ^ 1].name = "mainboard-flash";
  460. printk(KERN_NOTICE "Mainstone configured to boot from %s\n",
  461. mst_flash_data[0].name);
  462. /* system bus arbiter setting
  463. * - Core_Park
  464. * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
  465. */
  466. ARB_CNTRL = ARB_CORE_PARK | 0x234;
  467. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  468. /* reading Mainstone's "Virtual Configuration Register"
  469. might be handy to select LCD type here */
  470. if (0)
  471. mainstone_pxafb_info.modes = &toshiba_ltm04c380k_mode;
  472. else
  473. mainstone_pxafb_info.modes = &toshiba_ltm035a776c_mode;
  474. pxa_set_fb_info(NULL, &mainstone_pxafb_info);
  475. mainstone_backlight_register();
  476. pxa_set_mci_info(&mainstone_mci_platform_data);
  477. pxa_set_ficp_info(&mainstone_ficp_platform_data);
  478. pxa_set_ohci_info(&mainstone_ohci_platform_data);
  479. pxa_set_i2c_info(NULL);
  480. pxa_set_ac97_info(&mst_audio_ops);
  481. mainstone_init_keypad();
  482. }
  483. static struct map_desc mainstone_io_desc[] __initdata = {
  484. { /* CPLD */
  485. .virtual = MST_FPGA_VIRT,
  486. .pfn = __phys_to_pfn(MST_FPGA_PHYS),
  487. .length = 0x00100000,
  488. .type = MT_DEVICE
  489. }
  490. };
  491. static void __init mainstone_map_io(void)
  492. {
  493. pxa27x_map_io();
  494. iotable_init(mainstone_io_desc, ARRAY_SIZE(mainstone_io_desc));
  495. /* for use I SRAM as framebuffer. */
  496. PSLR |= 0xF04;
  497. PCFR = 0x66;
  498. }
  499. /*
  500. * Driver for the 8 discrete LEDs available for general use:
  501. * Note: bits [15-8] are used to enable/blank the 8 7 segment hex displays
  502. * so be sure to not monkey with them here.
  503. */
  504. #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
  505. struct mainstone_led {
  506. struct led_classdev cdev;
  507. u8 mask;
  508. };
  509. /*
  510. * The triggers lines up below will only be used if the
  511. * LED triggers are compiled in.
  512. */
  513. static const struct {
  514. const char *name;
  515. const char *trigger;
  516. } mainstone_leds[] = {
  517. { "mainstone:D28", "default-on", },
  518. { "mainstone:D27", "cpu0", },
  519. { "mainstone:D26", "heartbeat" },
  520. { "mainstone:D25", },
  521. { "mainstone:D24", },
  522. { "mainstone:D23", },
  523. { "mainstone:D22", },
  524. { "mainstone:D21", },
  525. };
  526. static void mainstone_led_set(struct led_classdev *cdev,
  527. enum led_brightness b)
  528. {
  529. struct mainstone_led *led = container_of(cdev,
  530. struct mainstone_led, cdev);
  531. u32 reg = MST_LEDCTRL;
  532. if (b != LED_OFF)
  533. reg |= led->mask;
  534. else
  535. reg &= ~led->mask;
  536. MST_LEDCTRL = reg;
  537. }
  538. static enum led_brightness mainstone_led_get(struct led_classdev *cdev)
  539. {
  540. struct mainstone_led *led = container_of(cdev,
  541. struct mainstone_led, cdev);
  542. u32 reg = MST_LEDCTRL;
  543. return (reg & led->mask) ? LED_FULL : LED_OFF;
  544. }
  545. static int __init mainstone_leds_init(void)
  546. {
  547. int i;
  548. if (!machine_is_mainstone())
  549. return -ENODEV;
  550. /* All ON */
  551. MST_LEDCTRL |= 0xff;
  552. for (i = 0; i < ARRAY_SIZE(mainstone_leds); i++) {
  553. struct mainstone_led *led;
  554. led = kzalloc(sizeof(*led), GFP_KERNEL);
  555. if (!led)
  556. break;
  557. led->cdev.name = mainstone_leds[i].name;
  558. led->cdev.brightness_set = mainstone_led_set;
  559. led->cdev.brightness_get = mainstone_led_get;
  560. led->cdev.default_trigger = mainstone_leds[i].trigger;
  561. led->mask = BIT(i);
  562. if (led_classdev_register(NULL, &led->cdev) < 0) {
  563. kfree(led);
  564. break;
  565. }
  566. }
  567. return 0;
  568. }
  569. /*
  570. * Since we may have triggers on any subsystem, defer registration
  571. * until after subsystem_init.
  572. */
  573. fs_initcall(mainstone_leds_init);
  574. #endif
  575. MACHINE_START(MAINSTONE, "Intel HCDDBBVA0 Development Platform (aka Mainstone)")
  576. /* Maintainer: MontaVista Software Inc. */
  577. .atag_offset = 0x100, /* BLOB boot parameter setting */
  578. .map_io = mainstone_map_io,
  579. .nr_irqs = MAINSTONE_NR_IRQS,
  580. .init_irq = pxa27x_init_irq,
  581. .handle_irq = pxa27x_handle_irq,
  582. .init_time = pxa_timer_init,
  583. .init_machine = mainstone_init,
  584. .restart = pxa_restart,
  585. MACHINE_END