Sumit Semwal | b7ee79a | 2011-01-24 06:21:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2plus display device setup / initialization. |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 5 | * Senthilvadivu Guruswamy |
| 6 | * Sumit Semwal |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 13 | * kind, whether express or implied; without even the implied warranty |
| 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Paul Gortmaker | d44b28c | 2011-07-31 10:52:44 -0400 | [diff] [blame] | 18 | #include <linux/string.h> |
Sumit Semwal | b7ee79a | 2011-01-24 06:21:54 +0000 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/io.h> |
| 23 | #include <linux/clk.h> |
| 24 | #include <linux/err.h> |
| 25 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 26 | #include <video/omapdss.h> |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 27 | #include <plat/omap_hwmod.h> |
| 28 | #include <plat/omap_device.h> |
Tomi Valkeinen | 700dee7 | 2011-05-23 15:50:47 +0300 | [diff] [blame] | 29 | #include <plat/omap-pm.h> |
Tomi Valkeinen | 13662dc | 2011-11-08 03:16:13 -0700 | [diff] [blame^] | 30 | #include <plat/common.h> |
Sumit Semwal | b7ee79a | 2011-01-24 06:21:54 +0000 | [diff] [blame] | 31 | |
Tomi Valkeinen | dc35835 | 2011-06-15 15:22:47 +0300 | [diff] [blame] | 32 | #include "control.h" |
| 33 | |
Sumit Semwal | b7ee79a | 2011-01-24 06:21:54 +0000 | [diff] [blame] | 34 | static struct platform_device omap_display_device = { |
| 35 | .name = "omapdss", |
| 36 | .id = -1, |
| 37 | .dev = { |
| 38 | .platform_data = NULL, |
| 39 | }, |
| 40 | }; |
| 41 | |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 42 | struct omap_dss_hwmod_data { |
| 43 | const char *oh_name; |
| 44 | const char *dev_name; |
| 45 | const int id; |
| 46 | }; |
| 47 | |
| 48 | static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = { |
| 49 | { "dss_core", "omapdss_dss", -1 }, |
| 50 | { "dss_dispc", "omapdss_dispc", -1 }, |
| 51 | { "dss_rfbi", "omapdss_rfbi", -1 }, |
| 52 | { "dss_venc", "omapdss_venc", -1 }, |
| 53 | }; |
| 54 | |
| 55 | static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = { |
| 56 | { "dss_core", "omapdss_dss", -1 }, |
| 57 | { "dss_dispc", "omapdss_dispc", -1 }, |
| 58 | { "dss_rfbi", "omapdss_rfbi", -1 }, |
| 59 | { "dss_venc", "omapdss_venc", -1 }, |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 60 | { "dss_dsi1", "omapdss_dsi", 0 }, |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = { |
| 64 | { "dss_core", "omapdss_dss", -1 }, |
| 65 | { "dss_dispc", "omapdss_dispc", -1 }, |
| 66 | { "dss_rfbi", "omapdss_rfbi", -1 }, |
| 67 | { "dss_venc", "omapdss_venc", -1 }, |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 68 | { "dss_dsi1", "omapdss_dsi", 0 }, |
| 69 | { "dss_dsi2", "omapdss_dsi", 1 }, |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 70 | { "dss_hdmi", "omapdss_hdmi", -1 }, |
| 71 | }; |
| 72 | |
Tomi Valkeinen | dc35835 | 2011-06-15 15:22:47 +0300 | [diff] [blame] | 73 | static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes) |
| 74 | { |
| 75 | u32 enable_mask, enable_shift; |
| 76 | u32 pipd_mask, pipd_shift; |
| 77 | u32 reg; |
| 78 | |
| 79 | if (dsi_id == 0) { |
| 80 | enable_mask = OMAP4_DSI1_LANEENABLE_MASK; |
| 81 | enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT; |
| 82 | pipd_mask = OMAP4_DSI1_PIPD_MASK; |
| 83 | pipd_shift = OMAP4_DSI1_PIPD_SHIFT; |
| 84 | } else if (dsi_id == 1) { |
| 85 | enable_mask = OMAP4_DSI2_LANEENABLE_MASK; |
| 86 | enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT; |
| 87 | pipd_mask = OMAP4_DSI2_PIPD_MASK; |
| 88 | pipd_shift = OMAP4_DSI2_PIPD_SHIFT; |
| 89 | } else { |
| 90 | return -ENODEV; |
| 91 | } |
| 92 | |
| 93 | reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY); |
| 94 | |
| 95 | reg &= ~enable_mask; |
| 96 | reg &= ~pipd_mask; |
| 97 | |
| 98 | reg |= (lanes << enable_shift) & enable_mask; |
| 99 | reg |= (lanes << pipd_shift) & pipd_mask; |
| 100 | |
| 101 | omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 106 | static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask) |
| 107 | { |
Tomi Valkeinen | dc35835 | 2011-06-15 15:22:47 +0300 | [diff] [blame] | 108 | if (cpu_is_omap44xx()) |
| 109 | return omap4_dsi_mux_pads(dsi_id, lane_mask); |
| 110 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask) |
| 115 | { |
Tomi Valkeinen | dc35835 | 2011-06-15 15:22:47 +0300 | [diff] [blame] | 116 | if (cpu_is_omap44xx()) |
| 117 | omap4_dsi_mux_pads(dsi_id, 0); |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 118 | } |
| 119 | |
Sumit Semwal | b7ee79a | 2011-01-24 06:21:54 +0000 | [diff] [blame] | 120 | int __init omap_display_init(struct omap_dss_board_info *board_data) |
| 121 | { |
| 122 | int r = 0; |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 123 | struct omap_hwmod *oh; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 124 | struct platform_device *pdev; |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 125 | int i, oh_count; |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 126 | struct omap_display_platform_data pdata; |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 127 | const struct omap_dss_hwmod_data *curr_dss_hwmod; |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 128 | |
| 129 | memset(&pdata, 0, sizeof(pdata)); |
| 130 | |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 131 | if (cpu_is_omap24xx()) { |
| 132 | curr_dss_hwmod = omap2_dss_hwmod_data; |
| 133 | oh_count = ARRAY_SIZE(omap2_dss_hwmod_data); |
| 134 | } else if (cpu_is_omap34xx()) { |
| 135 | curr_dss_hwmod = omap3_dss_hwmod_data; |
| 136 | oh_count = ARRAY_SIZE(omap3_dss_hwmod_data); |
| 137 | } else { |
| 138 | curr_dss_hwmod = omap4_dss_hwmod_data; |
| 139 | oh_count = ARRAY_SIZE(omap4_dss_hwmod_data); |
| 140 | } |
Mayuresh Janorkar | 545376e | 2011-01-27 11:17:04 +0000 | [diff] [blame] | 141 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 142 | if (board_data->dsi_enable_pads == NULL) |
| 143 | board_data->dsi_enable_pads = omap_dsi_enable_pads; |
| 144 | if (board_data->dsi_disable_pads == NULL) |
| 145 | board_data->dsi_disable_pads = omap_dsi_disable_pads; |
| 146 | |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 147 | pdata.board_data = board_data; |
Tomi Valkeinen | 700dee7 | 2011-05-23 15:50:47 +0300 | [diff] [blame] | 148 | pdata.board_data->get_context_loss_count = |
| 149 | omap_pm_get_dev_context_loss_count; |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 150 | |
| 151 | for (i = 0; i < oh_count; i++) { |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 152 | oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name); |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 153 | if (!oh) { |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 154 | pr_err("Could not look up %s\n", |
| 155 | curr_dss_hwmod[i].oh_name); |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 156 | return -ENODEV; |
| 157 | } |
Semwal, Sumit | fd4b34f | 2011-03-01 02:42:13 -0600 | [diff] [blame] | 158 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 159 | pdev = omap_device_build(curr_dss_hwmod[i].dev_name, |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 160 | curr_dss_hwmod[i].id, oh, &pdata, |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 161 | sizeof(struct omap_display_platform_data), |
Benoit Cousson | f718e2c | 2011-08-10 15:30:09 +0200 | [diff] [blame] | 162 | NULL, 0, 0); |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 163 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 164 | if (WARN((IS_ERR(pdev)), "Could not build omap_device for %s\n", |
Archit Taneja | 179e045 | 2011-04-18 09:32:13 +0530 | [diff] [blame] | 165 | curr_dss_hwmod[i].oh_name)) |
Senthilvadivu Guruswamy | cf07f53 | 2011-01-24 06:21:56 +0000 | [diff] [blame] | 166 | return -ENODEV; |
| 167 | } |
Sumit Semwal | b7ee79a | 2011-01-24 06:21:54 +0000 | [diff] [blame] | 168 | omap_display_device.dev.platform_data = board_data; |
| 169 | |
| 170 | r = platform_device_register(&omap_display_device); |
| 171 | if (r < 0) |
| 172 | printk(KERN_ERR "Unable to register OMAP-Display device\n"); |
| 173 | |
| 174 | return r; |
| 175 | } |
Tomi Valkeinen | 13662dc | 2011-11-08 03:16:13 -0700 | [diff] [blame^] | 176 | |
| 177 | #define MAX_MODULE_SOFTRESET_WAIT 10000 |
| 178 | int omap_dss_reset(struct omap_hwmod *oh) |
| 179 | { |
| 180 | struct omap_hwmod_opt_clk *oc; |
| 181 | int c = 0; |
| 182 | int i, r; |
| 183 | |
| 184 | if (!(oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)) { |
| 185 | pr_err("dss_core: hwmod data doesn't contain reset data\n"); |
| 186 | return -EINVAL; |
| 187 | } |
| 188 | |
| 189 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) |
| 190 | if (oc->_clk) |
| 191 | clk_enable(oc->_clk); |
| 192 | |
| 193 | omap_test_timeout((omap_hwmod_read(oh, oh->class->sysc->syss_offs) |
| 194 | & SYSS_RESETDONE_MASK), |
| 195 | MAX_MODULE_SOFTRESET_WAIT, c); |
| 196 | |
| 197 | if (c == MAX_MODULE_SOFTRESET_WAIT) |
| 198 | pr_warning("dss_core: waiting for reset to finish failed\n"); |
| 199 | else |
| 200 | pr_debug("dss_core: softreset done\n"); |
| 201 | |
| 202 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) |
| 203 | if (oc->_clk) |
| 204 | clk_disable(oc->_clk); |
| 205 | |
| 206 | r = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0; |
| 207 | |
| 208 | return r; |
| 209 | } |