Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/dss/sdi.c |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #define DSS_SUBSYS_NAME "SDI" |
| 21 | |
| 22 | #include <linux/kernel.h> |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/err.h> |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 25 | #include <linux/regulator/consumer.h> |
Paul Gortmaker | a8a3593 | 2011-07-10 13:20:26 -0400 | [diff] [blame] | 26 | #include <linux/export.h> |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 28 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 29 | #include <video/omapdss.h> |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 30 | #include "dss.h" |
| 31 | |
| 32 | static struct { |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 33 | bool update_enabled; |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 34 | struct regulator *vdds_sdi_reg; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 35 | } sdi; |
| 36 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 37 | static void sdi_basic_init(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 38 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 39 | { |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 40 | dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS); |
| 41 | dispc_mgr_enable_stallmode(dssdev->manager->id, false); |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 42 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 43 | dispc_mgr_set_lcd_display_type(dssdev->manager->id, |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 44 | OMAP_DSS_LCD_DISPLAY_TFT); |
| 45 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 46 | dispc_mgr_set_tft_data_lines(dssdev->manager->id, 24); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 47 | dispc_lcd_enable_signal_polarity(1); |
| 48 | } |
| 49 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 50 | int omapdss_sdi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 51 | { |
| 52 | struct omap_video_timings *t = &dssdev->panel.timings; |
| 53 | struct dss_clock_info dss_cinfo; |
| 54 | struct dispc_clock_info dispc_cinfo; |
| 55 | u16 lck_div, pck_div; |
| 56 | unsigned long fck; |
| 57 | unsigned long pck; |
| 58 | int r; |
| 59 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 60 | if (dssdev->manager == NULL) { |
| 61 | DSSERR("failed to enable display: no manager\n"); |
| 62 | return -ENODEV; |
| 63 | } |
| 64 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 65 | r = omap_dss_start_device(dssdev); |
| 66 | if (r) { |
| 67 | DSSERR("failed to start device\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 68 | goto err_start_dev; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 69 | } |
| 70 | |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 71 | r = regulator_enable(sdi.vdds_sdi_reg); |
| 72 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 73 | goto err_reg_enable; |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 74 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 75 | r = dispc_runtime_get(); |
| 76 | if (r) |
| 77 | goto err_get_dispc; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 78 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 79 | sdi_basic_init(dssdev); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 80 | |
| 81 | /* 15.5.9.1.2 */ |
| 82 | dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF; |
| 83 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 84 | dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 85 | dssdev->panel.acbi, dssdev->panel.acb); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 86 | |
Tomi Valkeinen | 42c9dee | 2011-03-02 12:29:27 +0200 | [diff] [blame] | 87 | r = dss_calc_clock_div(1, t->pixel_clock * 1000, |
| 88 | &dss_cinfo, &dispc_cinfo); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 89 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 90 | goto err_calc_clock_div; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 91 | |
| 92 | fck = dss_cinfo.fck; |
| 93 | lck_div = dispc_cinfo.lck_div; |
| 94 | pck_div = dispc_cinfo.pck_div; |
| 95 | |
| 96 | pck = fck / lck_div / pck_div / 1000; |
| 97 | |
| 98 | if (pck != t->pixel_clock) { |
| 99 | DSSWARN("Could not find exact pixel clock. Requested %d kHz, " |
| 100 | "got %lu kHz\n", |
| 101 | t->pixel_clock, pck); |
| 102 | |
| 103 | t->pixel_clock = pck; |
| 104 | } |
| 105 | |
| 106 | |
Archit Taneja | 4172116 | 2012-04-26 20:10:46 +0530 | [diff] [blame] | 107 | dss_mgr_set_timings(dssdev->manager, t); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 108 | |
| 109 | r = dss_set_clock_div(&dss_cinfo); |
| 110 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 111 | goto err_set_dss_clock_div; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 112 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 113 | r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 114 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 115 | goto err_set_dispc_clock_div; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 116 | |
Tomi Valkeinen | 42c9dee | 2011-03-02 12:29:27 +0200 | [diff] [blame] | 117 | dss_sdi_init(dssdev->phy.sdi.datapairs); |
| 118 | r = dss_sdi_enable(); |
| 119 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 120 | goto err_sdi_enable; |
Tomi Valkeinen | 42c9dee | 2011-03-02 12:29:27 +0200 | [diff] [blame] | 121 | mdelay(2); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 122 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 123 | r = dss_mgr_enable(dssdev->manager); |
| 124 | if (r) |
| 125 | goto err_mgr_enable; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 126 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 127 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 128 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 129 | err_mgr_enable: |
| 130 | dss_sdi_disable(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 131 | err_sdi_enable: |
| 132 | err_set_dispc_clock_div: |
| 133 | err_set_dss_clock_div: |
| 134 | err_calc_clock_div: |
| 135 | dispc_runtime_put(); |
| 136 | err_get_dispc: |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 137 | regulator_disable(sdi.vdds_sdi_reg); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 138 | err_reg_enable: |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 139 | omap_dss_stop_device(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 140 | err_start_dev: |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 141 | return r; |
| 142 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 143 | EXPORT_SYMBOL(omapdss_sdi_display_enable); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 144 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 145 | void omapdss_sdi_display_disable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 146 | { |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 147 | dss_mgr_disable(dssdev->manager); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 148 | |
| 149 | dss_sdi_disable(); |
| 150 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 151 | dispc_runtime_put(); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 152 | |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 153 | regulator_disable(sdi.vdds_sdi_reg); |
| 154 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 155 | omap_dss_stop_device(dssdev); |
| 156 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 157 | EXPORT_SYMBOL(omapdss_sdi_display_disable); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 158 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 159 | int sdi_init_display(struct omap_dss_device *dssdev) |
| 160 | { |
| 161 | DSSDBG("SDI init\n"); |
| 162 | |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 163 | if (sdi.vdds_sdi_reg == NULL) { |
| 164 | struct regulator *vdds_sdi; |
| 165 | |
| 166 | vdds_sdi = dss_get_vdds_sdi(); |
| 167 | |
| 168 | if (IS_ERR(vdds_sdi)) { |
| 169 | DSSERR("can't get VDDS_SDI regulator\n"); |
| 170 | return PTR_ERR(vdds_sdi); |
| 171 | } |
| 172 | |
| 173 | sdi.vdds_sdi_reg = vdds_sdi; |
| 174 | } |
| 175 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 179 | static int __init omap_sdi_probe(struct platform_device *pdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 180 | { |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame^] | 181 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
| 182 | int i, r; |
| 183 | |
| 184 | for (i = 0; i < pdata->num_devices; ++i) { |
| 185 | struct omap_dss_device *dssdev = pdata->devices[i]; |
| 186 | |
| 187 | if (dssdev->type != OMAP_DISPLAY_TYPE_SDI) |
| 188 | continue; |
| 189 | |
| 190 | r = omap_dss_register_device(dssdev, &pdev->dev, i); |
| 191 | if (r) |
| 192 | DSSERR("device %s register failed: %d\n", |
| 193 | dssdev->name, r); |
| 194 | } |
| 195 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 199 | static int __exit omap_sdi_remove(struct platform_device *pdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 200 | { |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame^] | 201 | omap_dss_unregister_child_devices(&pdev->dev); |
| 202 | |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | static struct platform_driver omap_sdi_driver = { |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 207 | .remove = __exit_p(omap_sdi_remove), |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 208 | .driver = { |
| 209 | .name = "omapdss_sdi", |
| 210 | .owner = THIS_MODULE, |
| 211 | }, |
| 212 | }; |
| 213 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 214 | int __init sdi_init_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 215 | { |
Tomi Valkeinen | 61055d4 | 2012-03-07 12:53:38 +0200 | [diff] [blame] | 216 | return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe); |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 219 | void __exit sdi_uninit_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 220 | { |
| 221 | platform_driver_unregister(&omap_sdi_driver); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 222 | } |