PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/arch/arm/mach-tegra/include/mach/dc.h

https://bitbucket.org/ayysir/asdk-grouper
C Header | 578 lines | 426 code | 103 blank | 49 comment | 0 complexity | 011ae2858b07e03577d6cd03dadd68d5 MD5 | raw file
  1. /*
  2. * arch/arm/mach-tegra/include/mach/dc.h
  3. *
  4. * Copyright (C) 2010 Google, Inc.
  5. *
  6. * Author:
  7. * Erik Gilling <konkers@google.com>
  8. *
  9. * Copyright (C) 2010-2011 NVIDIA Corporation
  10. *
  11. * This software is licensed under the terms of the GNU General Public
  12. * License version 2, as published by the Free Software Foundation, and
  13. * may be copied, distributed, and modified under those terms.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. */
  21. #ifndef __MACH_TEGRA_DC_H
  22. #define __MACH_TEGRA_DC_H
  23. #include <linux/pm.h>
  24. #include <linux/types.h>
  25. #include <drm/drm_fixed.h>
  26. #define TEGRA_MAX_DC 2
  27. #define DC_N_WINDOWS 3
  28. /* DSI pixel data format */
  29. enum {
  30. TEGRA_DSI_PIXEL_FORMAT_16BIT_P,
  31. TEGRA_DSI_PIXEL_FORMAT_18BIT_P,
  32. TEGRA_DSI_PIXEL_FORMAT_18BIT_NP,
  33. TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
  34. };
  35. /* DSI virtual channel number */
  36. enum {
  37. TEGRA_DSI_VIRTUAL_CHANNEL_0,
  38. TEGRA_DSI_VIRTUAL_CHANNEL_1,
  39. TEGRA_DSI_VIRTUAL_CHANNEL_2,
  40. TEGRA_DSI_VIRTUAL_CHANNEL_3,
  41. };
  42. /* DSI transmit method for video data */
  43. enum {
  44. TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE,
  45. TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE,
  46. };
  47. /* DSI HS clock mode */
  48. enum {
  49. TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS,
  50. TEGRA_DSI_VIDEO_CLOCK_TX_ONLY,
  51. };
  52. /* DSI burst mode setting in video mode. Each mode is assigned with a
  53. * fixed value. The rationale behind this is to avoid change of these
  54. * values, since the calculation of dsi clock depends on them. */
  55. enum {
  56. TEGRA_DSI_VIDEO_NONE_BURST_MODE = 0,
  57. TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END = 1,
  58. TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED = 2,
  59. TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED = 3,
  60. TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED = 4,
  61. TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED = 5,
  62. TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED = 6,
  63. };
  64. enum {
  65. TEGRA_DSI_PACKET_CMD,
  66. TEGRA_DSI_DELAY_MS,
  67. };
  68. struct tegra_dsi_cmd {
  69. u8 cmd_type;
  70. u8 data_id;
  71. union {
  72. u16 data_len;
  73. u16 delay_ms;
  74. struct {
  75. u8 data0;
  76. u8 data1;
  77. } sp;
  78. } sp_len_dly;
  79. u8 *pdata;
  80. };
  81. #define DSI_CMD_SHORT(di, p0, p1) { \
  82. .cmd_type = TEGRA_DSI_PACKET_CMD, \
  83. .data_id = di, \
  84. .sp_len_dly.sp.data0 = p0, \
  85. .sp_len_dly.sp.data1 = p1, \
  86. }
  87. #define DSI_DLY_MS(ms) { \
  88. .cmd_type = TEGRA_DSI_DELAY_MS, \
  89. .sp_len_dly.delay_ms = ms, \
  90. }
  91. #define DSI_CMD_LONG(di, ptr) { \
  92. .cmd_type = TEGRA_DSI_PACKET_CMD, \
  93. .data_id = di, \
  94. .sp_len_dly.data_len = ARRAY_SIZE(ptr), \
  95. .pdata = ptr, \
  96. }
  97. struct dsi_phy_timing_ns {
  98. u16 t_hsdexit_ns;
  99. u16 t_hstrail_ns;
  100. u16 t_datzero_ns;
  101. u16 t_hsprepare_ns;
  102. u16 t_clktrail_ns;
  103. u16 t_clkpost_ns;
  104. u16 t_clkzero_ns;
  105. u16 t_tlpx_ns;
  106. u16 t_clkprepare_ns;
  107. u16 t_clkpre_ns;
  108. u16 t_wakeup_ns;
  109. u16 t_taget_ns;
  110. u16 t_tasure_ns;
  111. u16 t_tago_ns;
  112. };
  113. struct tegra_dsi_out {
  114. u8 n_data_lanes; /* required */
  115. u8 pixel_format; /* required */
  116. u8 refresh_rate; /* required */
  117. u8 rated_refresh_rate;
  118. u8 panel_reset; /* required */
  119. u8 virtual_channel; /* required */
  120. u8 dsi_instance;
  121. u8 chip_id;
  122. u8 chip_rev;
  123. bool panel_has_frame_buffer; /* required*/
  124. struct tegra_dsi_cmd *dsi_init_cmd; /* required */
  125. u16 n_init_cmd; /* required */
  126. struct tegra_dsi_cmd *dsi_early_suspend_cmd;
  127. u16 n_early_suspend_cmd;
  128. struct tegra_dsi_cmd *dsi_late_resume_cmd;
  129. u16 n_late_resume_cmd;
  130. struct tegra_dsi_cmd *dsi_suspend_cmd; /* required */
  131. u16 n_suspend_cmd; /* required */
  132. u8 video_data_type; /* required */
  133. u8 video_clock_mode;
  134. u8 video_burst_mode;
  135. u16 panel_buffer_size_byte;
  136. u16 panel_reset_timeout_msec;
  137. bool hs_cmd_mode_supported;
  138. bool hs_cmd_mode_on_blank_supported;
  139. bool enable_hs_clock_on_lp_cmd_mode;
  140. bool no_pkt_seq_eot; /* 1st generation panel may not
  141. * support eot. Don't set it for
  142. * most panels. */
  143. bool te_polarity_low;
  144. bool power_saving_suspend;
  145. u32 max_panel_freq_khz;
  146. u32 lp_cmd_mode_freq_khz;
  147. u32 lp_read_cmd_mode_freq_khz;
  148. u32 hs_clk_in_lp_cmd_mode_freq_khz;
  149. u32 burst_mode_freq_khz;
  150. struct dsi_phy_timing_ns phy_timing;
  151. };
  152. enum {
  153. TEGRA_DC_STEREO_MODE_2D,
  154. TEGRA_DC_STEREO_MODE_3D
  155. };
  156. enum {
  157. TEGRA_DC_STEREO_LANDSCAPE,
  158. TEGRA_DC_STEREO_PORTRAIT
  159. };
  160. struct tegra_stereo_out {
  161. int mode_2d_3d;
  162. int orientation;
  163. void (*set_mode)(int mode);
  164. void (*set_orientation)(int orientation);
  165. };
  166. struct tegra_dc_mode {
  167. int pclk;
  168. int rated_pclk;
  169. int h_ref_to_sync;
  170. int v_ref_to_sync;
  171. int h_sync_width;
  172. int v_sync_width;
  173. int h_back_porch;
  174. int v_back_porch;
  175. int h_active;
  176. int v_active;
  177. int h_front_porch;
  178. int v_front_porch;
  179. int stereo_mode;
  180. u32 flags;
  181. };
  182. #define TEGRA_DC_MODE_FLAG_NEG_V_SYNC (1 << 0)
  183. #define TEGRA_DC_MODE_FLAG_NEG_H_SYNC (1 << 1)
  184. enum {
  185. TEGRA_DC_OUT_RGB,
  186. TEGRA_DC_OUT_HDMI,
  187. TEGRA_DC_OUT_DSI,
  188. };
  189. struct tegra_dc_out_pin {
  190. int name;
  191. int pol;
  192. };
  193. enum {
  194. TEGRA_DC_OUT_PIN_DATA_ENABLE,
  195. TEGRA_DC_OUT_PIN_H_SYNC,
  196. TEGRA_DC_OUT_PIN_V_SYNC,
  197. TEGRA_DC_OUT_PIN_PIXEL_CLOCK,
  198. };
  199. enum {
  200. TEGRA_DC_OUT_PIN_POL_LOW,
  201. TEGRA_DC_OUT_PIN_POL_HIGH,
  202. };
  203. enum {
  204. TEGRA_DC_DISABLE_DITHER = 1,
  205. TEGRA_DC_ORDERED_DITHER,
  206. TEGRA_DC_ERRDIFF_DITHER,
  207. };
  208. typedef u8 tegra_dc_bl_output[256];
  209. typedef u8 *p_tegra_dc_bl_output;
  210. struct tegra_dc_sd_blp {
  211. u16 time_constant;
  212. u8 step;
  213. };
  214. struct tegra_dc_sd_fc {
  215. u8 time_limit;
  216. u8 threshold;
  217. };
  218. struct tegra_dc_sd_rgb {
  219. u8 r;
  220. u8 g;
  221. u8 b;
  222. };
  223. struct tegra_dc_sd_agg_priorities {
  224. u8 pri_lvl;
  225. u8 agg[4];
  226. };
  227. struct tegra_dc_sd_settings {
  228. unsigned enable;
  229. bool use_auto_pwm;
  230. u8 hw_update_delay;
  231. u8 aggressiveness;
  232. short bin_width;
  233. u8 phase_in_settings;
  234. u8 phase_in_adjustments;
  235. u8 panel_min_brightness;
  236. u8 cmd;
  237. u8 final_agg;
  238. u16 cur_agg_step;
  239. u16 phase_settings_step;
  240. u16 phase_adj_step;
  241. u16 num_phase_in_steps;
  242. struct tegra_dc_sd_agg_priorities agg_priorities;
  243. bool use_vid_luma;
  244. struct tegra_dc_sd_rgb coeff;
  245. struct tegra_dc_sd_fc fc;
  246. struct tegra_dc_sd_blp blp;
  247. u8 bltf[4][4][4];
  248. struct tegra_dc_sd_rgb lut[4][9];
  249. atomic_t *sd_brightness;
  250. struct platform_device *bl_device;
  251. };
  252. enum {
  253. NO_CMD = 0x0,
  254. ENABLE = 0x1,
  255. DISABLE = 0x2,
  256. PHASE_IN = 0x4,
  257. AGG_CHG = 0x8,
  258. };
  259. enum {
  260. TEGRA_PIN_OUT_CONFIG_SEL_LHP0_LD21,
  261. TEGRA_PIN_OUT_CONFIG_SEL_LHP1_LD18,
  262. TEGRA_PIN_OUT_CONFIG_SEL_LHP2_LD19,
  263. TEGRA_PIN_OUT_CONFIG_SEL_LVP0_LVP0_Out,
  264. TEGRA_PIN_OUT_CONFIG_SEL_LVP1_LD20,
  265. TEGRA_PIN_OUT_CONFIG_SEL_LM1_M1,
  266. TEGRA_PIN_OUT_CONFIG_SEL_LM1_LD21,
  267. TEGRA_PIN_OUT_CONFIG_SEL_LM1_PM1,
  268. TEGRA_PIN_OUT_CONFIG_SEL_LDI_LD22,
  269. TEGRA_PIN_OUT_CONFIG_SEL_LPP_LD23,
  270. TEGRA_PIN_OUT_CONFIG_SEL_LDC_SDC,
  271. TEGRA_PIN_OUT_CONFIG_SEL_LSPI_DE,
  272. };
  273. struct tegra_dc_out {
  274. int type;
  275. unsigned flags;
  276. /* size in mm */
  277. unsigned h_size;
  278. unsigned v_size;
  279. int dcc_bus;
  280. int hotplug_gpio;
  281. const char *parent_clk;
  282. const char *parent_clk_backup;
  283. unsigned max_pixclock;
  284. unsigned order;
  285. unsigned align;
  286. unsigned depth;
  287. unsigned dither;
  288. struct tegra_dc_mode *modes;
  289. int n_modes;
  290. struct tegra_dsi_out *dsi;
  291. struct tegra_stereo_out *stereo;
  292. unsigned height; /* mm */
  293. unsigned width; /* mm */
  294. struct tegra_dc_out_pin *out_pins;
  295. unsigned n_out_pins;
  296. struct tegra_dc_sd_settings *sd_settings;
  297. u8 *out_sel_configs;
  298. unsigned n_out_sel_configs;
  299. int (*enable)(void);
  300. int (*postpoweron)(void);
  301. int (*disable)(void);
  302. int (*hotplug_init)(void);
  303. int (*postsuspend)(void);
  304. };
  305. /* bits for tegra_dc_out.flags */
  306. #define TEGRA_DC_OUT_HOTPLUG_HIGH (0 << 1)
  307. #define TEGRA_DC_OUT_HOTPLUG_LOW (1 << 1)
  308. #define TEGRA_DC_OUT_HOTPLUG_MASK (1 << 1)
  309. #define TEGRA_DC_OUT_NVHDCP_POLICY_ALWAYS_ON (0 << 2)
  310. #define TEGRA_DC_OUT_NVHDCP_POLICY_ON_DEMAND (1 << 2)
  311. #define TEGRA_DC_OUT_NVHDCP_POLICY_MASK (1 << 2)
  312. #define TEGRA_DC_OUT_CONTINUOUS_MODE (0 << 3)
  313. #define TEGRA_DC_OUT_ONE_SHOT_MODE (1 << 3)
  314. #define TEGRA_DC_OUT_N_SHOT_MODE (1 << 4)
  315. #define TEGRA_DC_ALIGN_MSB 0
  316. #define TEGRA_DC_ALIGN_LSB 1
  317. #define TEGRA_DC_ORDER_RED_BLUE 0
  318. #define TEGRA_DC_ORDER_BLUE_RED 1
  319. #define V_BLANK_FLIP 0
  320. #define V_BLANK_NVSD 1
  321. struct tegra_dc;
  322. struct nvmap_handle_ref;
  323. struct tegra_dc_csc {
  324. unsigned short yof;
  325. unsigned short kyrgb;
  326. unsigned short kur;
  327. unsigned short kvr;
  328. unsigned short kug;
  329. unsigned short kvg;
  330. unsigned short kub;
  331. unsigned short kvb;
  332. };
  333. /* palette lookup table */
  334. struct tegra_dc_lut {
  335. u8 r[256];
  336. u8 g[256];
  337. u8 b[256];
  338. };
  339. struct tegra_dc_win {
  340. u8 idx;
  341. u8 fmt;
  342. u8 ppflags; /* see TEGRA_WIN_PPFLAG* */
  343. u32 flags;
  344. void *virt_addr;
  345. dma_addr_t phys_addr;
  346. dma_addr_t phys_addr_u;
  347. dma_addr_t phys_addr_v;
  348. unsigned stride;
  349. unsigned stride_uv;
  350. fixed20_12 x;
  351. fixed20_12 y;
  352. fixed20_12 w;
  353. fixed20_12 h;
  354. unsigned out_x;
  355. unsigned out_y;
  356. unsigned out_w;
  357. unsigned out_h;
  358. unsigned z;
  359. struct tegra_dc_csc csc;
  360. int dirty;
  361. int underflows;
  362. struct tegra_dc *dc;
  363. struct nvmap_handle_ref *cur_handle;
  364. unsigned bandwidth;
  365. unsigned new_bandwidth;
  366. struct tegra_dc_lut lut;
  367. };
  368. #define TEGRA_WIN_PPFLAG_CP_ENABLE (1 << 0) /* enable RGB color lut */
  369. #define TEGRA_WIN_PPFLAG_CP_FBOVERRIDE (1 << 1) /* override fbdev color lut */
  370. #define TEGRA_WIN_FLAG_ENABLED (1 << 0)
  371. #define TEGRA_WIN_FLAG_BLEND_PREMULT (1 << 1)
  372. #define TEGRA_WIN_FLAG_BLEND_COVERAGE (1 << 2)
  373. #define TEGRA_WIN_FLAG_INVERT_H (1 << 3)
  374. #define TEGRA_WIN_FLAG_INVERT_V (1 << 4)
  375. #define TEGRA_WIN_FLAG_TILED (1 << 5)
  376. #define TEGRA_WIN_FLAG_H_FILTER (1 << 6)
  377. #define TEGRA_WIN_FLAG_V_FILTER (1 << 7)
  378. #define TEGRA_WIN_BLEND_FLAGS_MASK \
  379. (TEGRA_WIN_FLAG_BLEND_PREMULT | TEGRA_WIN_FLAG_BLEND_COVERAGE)
  380. /* Note: These are the actual values written to the DC_WIN_COLOR_DEPTH register
  381. * and may change in new tegra architectures.
  382. */
  383. #define TEGRA_WIN_FMT_P1 0
  384. #define TEGRA_WIN_FMT_P2 1
  385. #define TEGRA_WIN_FMT_P4 2
  386. #define TEGRA_WIN_FMT_P8 3
  387. #define TEGRA_WIN_FMT_B4G4R4A4 4
  388. #define TEGRA_WIN_FMT_B5G5R5A 5
  389. #define TEGRA_WIN_FMT_B5G6R5 6
  390. #define TEGRA_WIN_FMT_AB5G5R5 7
  391. #define TEGRA_WIN_FMT_B8G8R8A8 12
  392. #define TEGRA_WIN_FMT_R8G8B8A8 13
  393. #define TEGRA_WIN_FMT_B6x2G6x2R6x2A8 14
  394. #define TEGRA_WIN_FMT_R6x2G6x2B6x2A8 15
  395. #define TEGRA_WIN_FMT_YCbCr422 16
  396. #define TEGRA_WIN_FMT_YUV422 17
  397. #define TEGRA_WIN_FMT_YCbCr420P 18
  398. #define TEGRA_WIN_FMT_YUV420P 19
  399. #define TEGRA_WIN_FMT_YCbCr422P 20
  400. #define TEGRA_WIN_FMT_YUV422P 21
  401. #define TEGRA_WIN_FMT_YCbCr422R 22
  402. #define TEGRA_WIN_FMT_YUV422R 23
  403. #define TEGRA_WIN_FMT_YCbCr422RA 24
  404. #define TEGRA_WIN_FMT_YUV422RA 25
  405. struct tegra_fb_data {
  406. int win;
  407. int xres;
  408. int yres;
  409. int bits_per_pixel; /* -1 means autodetect */
  410. unsigned long flags;
  411. };
  412. #define TEGRA_FB_FLIP_ON_PROBE (1 << 0)
  413. struct tegra_dc_platform_data {
  414. unsigned long flags;
  415. unsigned long emc_clk_rate;
  416. struct tegra_dc_out *default_out;
  417. struct tegra_fb_data *fb;
  418. unsigned long min_emc_clk_rate; /* used to make sure
  419. * emc clock rate is enough
  420. * during DC is enabled
  421. */
  422. };
  423. #define TEGRA_DC_FLAG_ENABLED (1 << 0)
  424. struct tegra_dc *tegra_dc_get_dc(unsigned idx);
  425. struct tegra_dc_win *tegra_dc_get_window(struct tegra_dc *dc, unsigned win);
  426. bool tegra_dc_get_connected(struct tegra_dc *);
  427. void tegra_dc_blank(struct tegra_dc *dc);
  428. void tegra_dc_enable(struct tegra_dc *dc);
  429. void tegra_dc_disable(struct tegra_dc *dc);
  430. u32 tegra_dc_get_syncpt_id(const struct tegra_dc *dc, int i);
  431. u32 tegra_dc_incr_syncpt_max(struct tegra_dc *dc, int i);
  432. void tegra_dc_incr_syncpt_min(struct tegra_dc *dc, int i, u32 val);
  433. /* tegra_dc_update_windows and tegra_dc_sync_windows do not support windows
  434. * with differenct dcs in one call
  435. */
  436. int tegra_dc_update_windows(struct tegra_dc_win *windows[], int n);
  437. int tegra_dc_sync_windows(struct tegra_dc_win *windows[], int n);
  438. int tegra_dc_set_mode(struct tegra_dc *dc, const struct tegra_dc_mode *mode);
  439. struct fb_videomode;
  440. int tegra_dc_set_fb_mode(struct tegra_dc *dc, const struct fb_videomode *fbmode,
  441. bool stereo_mode);
  442. unsigned tegra_dc_get_out_height(const struct tegra_dc *dc);
  443. unsigned tegra_dc_get_out_width(const struct tegra_dc *dc);
  444. unsigned tegra_dc_get_out_max_pixclock(const struct tegra_dc *dc);
  445. /* PM0 and PM1 signal control */
  446. #define TEGRA_PWM_PM0 0
  447. #define TEGRA_PWM_PM1 1
  448. struct tegra_dc_pwm_params {
  449. int which_pwm;
  450. void (*switch_to_sfio)(int);
  451. int gpio_conf_to_sfio;
  452. unsigned int period;
  453. unsigned int clk_div;
  454. unsigned int clk_select;
  455. unsigned int duty_cycle;
  456. };
  457. void tegra_dc_config_pwm(struct tegra_dc *dc, struct tegra_dc_pwm_params *cfg);
  458. int tegra_dsi_send_panel_short_cmd(struct tegra_dc *dc, u8 *pdata, u8 data_len);
  459. void tegra_dc_host_trigger(struct tegra_dc *dc);
  460. int tegra_dc_update_csc(struct tegra_dc *dc, int win_index);
  461. int tegra_dc_update_lut(struct tegra_dc *dc, int win_index, int fboveride);
  462. /*
  463. * In order to get a dc's current EDID, first call tegra_dc_get_edid() from an
  464. * interruptible context. The returned value (if non-NULL) points to a
  465. * snapshot of the current state; after copying data from it, call
  466. * tegra_dc_put_edid() on that pointer. Do not dereference anything through
  467. * that pointer after calling tegra_dc_put_edid().
  468. */
  469. struct tegra_dc_edid {
  470. size_t len;
  471. u8 buf[0];
  472. };
  473. struct tegra_dc_edid *tegra_dc_get_edid(struct tegra_dc *dc);
  474. void tegra_dc_put_edid(struct tegra_dc_edid *edid);
  475. #endif