clcd.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * linux/arch/arm/mach-nspire/clcd.c
  3. *
  4. * Copyright (C) 2013 Daniel Tang <tangrs@tangrs.id.au>
  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/init.h>
  12. #include <linux/of.h>
  13. #include <linux/amba/bus.h>
  14. #include <linux/amba/clcd.h>
  15. #include <linux/dma-mapping.h>
  16. static struct clcd_panel nspire_cx_lcd_panel = {
  17. .mode = {
  18. .name = "Color LCD",
  19. .refresh = 60,
  20. .xres = 320,
  21. .yres = 240,
  22. .sync = 0,
  23. .vmode = FB_VMODE_NONINTERLACED,
  24. .pixclock = 1,
  25. .hsync_len = 6,
  26. .vsync_len = 1,
  27. .right_margin = 50,
  28. .left_margin = 38,
  29. .lower_margin = 3,
  30. .upper_margin = 17,
  31. },
  32. .width = 65, /* ~6.50 cm */
  33. .height = 49, /* ~4.87 cm */
  34. .tim2 = TIM2_IPC,
  35. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  36. .bpp = 16,
  37. .caps = CLCD_CAP_565,
  38. };
  39. static struct clcd_panel nspire_classic_lcd_panel = {
  40. .mode = {
  41. .name = "Grayscale LCD",
  42. .refresh = 60,
  43. .xres = 320,
  44. .yres = 240,
  45. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  46. .vmode = FB_VMODE_NONINTERLACED,
  47. .pixclock = 1,
  48. .hsync_len = 6,
  49. .vsync_len = 1,
  50. .right_margin = 6,
  51. .left_margin = 6,
  52. },
  53. .width = 71, /* 7.11cm */
  54. .height = 53, /* 5.33cm */
  55. .tim2 = 0x80007d0,
  56. .cntl = CNTL_LCDMONO8,
  57. .bpp = 8,
  58. .grayscale = 1,
  59. .caps = CLCD_CAP_5551,
  60. };
  61. int nspire_clcd_setup(struct clcd_fb *fb)
  62. {
  63. struct clcd_panel *panel;
  64. size_t panel_size;
  65. const char *type;
  66. dma_addr_t dma;
  67. int err;
  68. BUG_ON(!fb->dev->dev.of_node);
  69. err = of_property_read_string(fb->dev->dev.of_node, "lcd-type", &type);
  70. if (err) {
  71. pr_err("CLCD: Could not find lcd-type property\n");
  72. return err;
  73. }
  74. if (!strcmp(type, "cx")) {
  75. panel = &nspire_cx_lcd_panel;
  76. } else if (!strcmp(type, "classic")) {
  77. panel = &nspire_classic_lcd_panel;
  78. } else {
  79. pr_err("CLCD: Unknown lcd-type %s\n", type);
  80. return -EINVAL;
  81. }
  82. panel_size = ((panel->mode.xres * panel->mode.yres) * panel->bpp) / 8;
  83. panel_size = ALIGN(panel_size, PAGE_SIZE);
  84. fb->fb.screen_base = dma_alloc_wc(&fb->dev->dev, panel_size, &dma,
  85. GFP_KERNEL);
  86. if (!fb->fb.screen_base) {
  87. pr_err("CLCD: unable to map framebuffer\n");
  88. return -ENOMEM;
  89. }
  90. fb->fb.fix.smem_start = dma;
  91. fb->fb.fix.smem_len = panel_size;
  92. fb->panel = panel;
  93. return 0;
  94. }
  95. int nspire_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  96. {
  97. return dma_mmap_wc(&fb->dev->dev, vma, fb->fb.screen_base,
  98. fb->fb.fix.smem_start, fb->fb.fix.smem_len);
  99. }
  100. void nspire_clcd_remove(struct clcd_fb *fb)
  101. {
  102. dma_free_wc(&fb->dev->dev, fb->fb.fix.smem_len, fb->fb.screen_base,
  103. fb->fb.fix.smem_start);
  104. }