Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Taal DSI command mode panel |
| 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 DEBUG*/ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/err.h> |
| 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/backlight.h> |
| 28 | #include <linux/fb.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/gpio.h> |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 31 | #include <linux/workqueue.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 33 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 34 | #include <linux/mutex.h> |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 35 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 36 | #include <video/omapdss.h> |
Tomi Valkeinen | 4e9f99d | 2011-05-11 14:10:07 +0300 | [diff] [blame] | 37 | #include <video/omap-panel-nokia-dsi.h> |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 38 | #include <video/mipi_display.h> |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 39 | |
| 40 | /* DSI Virtual channel. Hardcoded for now. */ |
| 41 | #define TCH 0 |
| 42 | |
| 43 | #define DCS_READ_NUM_ERRORS 0x05 |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 44 | #define DCS_BRIGHTNESS 0x51 |
| 45 | #define DCS_CTRL_DISPLAY 0x53 |
| 46 | #define DCS_WRITE_CABC 0x55 |
| 47 | #define DCS_READ_CABC 0x56 |
| 48 | #define DCS_GET_ID1 0xda |
| 49 | #define DCS_GET_ID2 0xdb |
| 50 | #define DCS_GET_ID3 0xdc |
| 51 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 52 | static irqreturn_t taal_te_isr(int irq, void *data); |
| 53 | static void taal_te_timeout_work_callback(struct work_struct *work); |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 54 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable); |
| 55 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 56 | static int taal_panel_reset(struct omap_dss_device *dssdev); |
| 57 | |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 58 | struct panel_regulator { |
| 59 | struct regulator *regulator; |
| 60 | const char *name; |
| 61 | int min_uV; |
| 62 | int max_uV; |
| 63 | }; |
| 64 | |
| 65 | static void free_regulators(struct panel_regulator *regulators, int n) |
| 66 | { |
| 67 | int i; |
| 68 | |
| 69 | for (i = 0; i < n; i++) { |
| 70 | /* disable/put in reverse order */ |
| 71 | regulator_disable(regulators[n - i - 1].regulator); |
| 72 | regulator_put(regulators[n - i - 1].regulator); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | static int init_regulators(struct omap_dss_device *dssdev, |
| 77 | struct panel_regulator *regulators, int n) |
| 78 | { |
| 79 | int r, i, v; |
| 80 | |
| 81 | for (i = 0; i < n; i++) { |
| 82 | struct regulator *reg; |
| 83 | |
| 84 | reg = regulator_get(&dssdev->dev, regulators[i].name); |
| 85 | if (IS_ERR(reg)) { |
| 86 | dev_err(&dssdev->dev, "failed to get regulator %s\n", |
| 87 | regulators[i].name); |
| 88 | r = PTR_ERR(reg); |
| 89 | goto err; |
| 90 | } |
| 91 | |
| 92 | /* FIXME: better handling of fixed vs. variable regulators */ |
| 93 | v = regulator_get_voltage(reg); |
| 94 | if (v < regulators[i].min_uV || v > regulators[i].max_uV) { |
| 95 | r = regulator_set_voltage(reg, regulators[i].min_uV, |
| 96 | regulators[i].max_uV); |
| 97 | if (r) { |
| 98 | dev_err(&dssdev->dev, |
| 99 | "failed to set regulator %s voltage\n", |
| 100 | regulators[i].name); |
| 101 | regulator_put(reg); |
| 102 | goto err; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | r = regulator_enable(reg); |
| 107 | if (r) { |
| 108 | dev_err(&dssdev->dev, "failed to enable regulator %s\n", |
| 109 | regulators[i].name); |
| 110 | regulator_put(reg); |
| 111 | goto err; |
| 112 | } |
| 113 | |
| 114 | regulators[i].regulator = reg; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | |
| 119 | err: |
| 120 | free_regulators(regulators, i); |
| 121 | |
| 122 | return r; |
| 123 | } |
| 124 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 125 | /** |
| 126 | * struct panel_config - panel configuration |
| 127 | * @name: panel name |
| 128 | * @type: panel type |
| 129 | * @timings: panel resolution |
| 130 | * @sleep: various panel specific delays, passed to msleep() if non-zero |
| 131 | * @reset_sequence: reset sequence timings, passed to udelay() if non-zero |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 132 | * @regulators: array of panel regulators |
| 133 | * @num_regulators: number of regulators in the array |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 134 | */ |
| 135 | struct panel_config { |
| 136 | const char *name; |
| 137 | int type; |
| 138 | |
| 139 | struct omap_video_timings timings; |
| 140 | |
| 141 | struct { |
| 142 | unsigned int sleep_in; |
| 143 | unsigned int sleep_out; |
| 144 | unsigned int hw_reset; |
| 145 | unsigned int enable_te; |
| 146 | } sleep; |
| 147 | |
| 148 | struct { |
| 149 | unsigned int high; |
| 150 | unsigned int low; |
| 151 | } reset_sequence; |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 152 | |
| 153 | struct panel_regulator *regulators; |
| 154 | int num_regulators; |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | enum { |
| 158 | PANEL_TAAL, |
| 159 | }; |
| 160 | |
| 161 | static struct panel_config panel_configs[] = { |
| 162 | { |
| 163 | .name = "taal", |
| 164 | .type = PANEL_TAAL, |
| 165 | .timings = { |
| 166 | .x_res = 864, |
| 167 | .y_res = 480, |
| 168 | }, |
| 169 | .sleep = { |
| 170 | .sleep_in = 5, |
| 171 | .sleep_out = 5, |
| 172 | .hw_reset = 5, |
| 173 | .enable_te = 100, /* possible panel bug */ |
| 174 | }, |
| 175 | .reset_sequence = { |
| 176 | .high = 10, |
| 177 | .low = 10, |
| 178 | }, |
| 179 | }, |
| 180 | }; |
| 181 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 182 | struct taal_data { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 183 | struct mutex lock; |
| 184 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 185 | struct backlight_device *bldev; |
| 186 | |
| 187 | unsigned long hw_guard_end; /* next value of jiffies when we can |
| 188 | * issue the next sleep in/out command |
| 189 | */ |
| 190 | unsigned long hw_guard_wait; /* max guard time in jiffies */ |
| 191 | |
| 192 | struct omap_dss_device *dssdev; |
| 193 | |
| 194 | bool enabled; |
| 195 | u8 rotate; |
| 196 | bool mirror; |
| 197 | |
| 198 | bool te_enabled; |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 199 | |
| 200 | atomic_t do_update; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 201 | int channel; |
| 202 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 203 | struct delayed_work te_timeout_work; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 204 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 205 | bool cabc_broken; |
| 206 | unsigned cabc_mode; |
| 207 | |
| 208 | bool intro_printed; |
| 209 | |
Tomi Valkeinen | 883b9ac | 2011-03-24 15:01:30 +0200 | [diff] [blame] | 210 | struct workqueue_struct *workqueue; |
| 211 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 212 | struct delayed_work esd_work; |
Tomi Valkeinen | 33a410b | 2011-03-24 13:58:01 +0200 | [diff] [blame] | 213 | unsigned esd_interval; |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 214 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 215 | bool ulps_enabled; |
| 216 | unsigned ulps_timeout; |
| 217 | struct delayed_work ulps_work; |
| 218 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 219 | struct panel_config *panel_config; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 220 | }; |
| 221 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 222 | static inline struct nokia_dsi_panel_data |
| 223 | *get_panel_data(const struct omap_dss_device *dssdev) |
| 224 | { |
| 225 | return (struct nokia_dsi_panel_data *) dssdev->data; |
| 226 | } |
| 227 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 228 | static void taal_esd_work(struct work_struct *work); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 229 | static void taal_ulps_work(struct work_struct *work); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 230 | |
| 231 | static void hw_guard_start(struct taal_data *td, int guard_msec) |
| 232 | { |
| 233 | td->hw_guard_wait = msecs_to_jiffies(guard_msec); |
| 234 | td->hw_guard_end = jiffies + td->hw_guard_wait; |
| 235 | } |
| 236 | |
| 237 | static void hw_guard_wait(struct taal_data *td) |
| 238 | { |
| 239 | unsigned long wait = td->hw_guard_end - jiffies; |
| 240 | |
| 241 | if ((long)wait > 0 && wait <= td->hw_guard_wait) { |
| 242 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 243 | schedule_timeout(wait); |
| 244 | } |
| 245 | } |
| 246 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 247 | static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 248 | { |
| 249 | int r; |
| 250 | u8 buf[1]; |
| 251 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 252 | r = dsi_vc_dcs_read(td->dssdev, td->channel, dcs_cmd, buf, 1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 253 | |
| 254 | if (r < 0) |
| 255 | return r; |
| 256 | |
| 257 | *data = buf[0]; |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 262 | static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 263 | { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 264 | return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 265 | } |
| 266 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 267 | static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 268 | { |
| 269 | u8 buf[2]; |
| 270 | buf[0] = dcs_cmd; |
| 271 | buf[1] = param; |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 272 | return dsi_vc_dcs_write(td->dssdev, td->channel, buf, 2); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static int taal_sleep_in(struct taal_data *td) |
| 276 | |
| 277 | { |
| 278 | u8 cmd; |
| 279 | int r; |
| 280 | |
| 281 | hw_guard_wait(td); |
| 282 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 283 | cmd = MIPI_DCS_ENTER_SLEEP_MODE; |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 284 | r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 285 | if (r) |
| 286 | return r; |
| 287 | |
| 288 | hw_guard_start(td, 120); |
| 289 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 290 | if (td->panel_config->sleep.sleep_in) |
| 291 | msleep(td->panel_config->sleep.sleep_in); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static int taal_sleep_out(struct taal_data *td) |
| 297 | { |
| 298 | int r; |
| 299 | |
| 300 | hw_guard_wait(td); |
| 301 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 302 | r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 303 | if (r) |
| 304 | return r; |
| 305 | |
| 306 | hw_guard_start(td, 120); |
| 307 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 308 | if (td->panel_config->sleep.sleep_out) |
| 309 | msleep(td->panel_config->sleep.sleep_out); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 314 | static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 315 | { |
| 316 | int r; |
| 317 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 318 | r = taal_dcs_read_1(td, DCS_GET_ID1, id1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 319 | if (r) |
| 320 | return r; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 321 | r = taal_dcs_read_1(td, DCS_GET_ID2, id2); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 322 | if (r) |
| 323 | return r; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 324 | r = taal_dcs_read_1(td, DCS_GET_ID3, id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 325 | if (r) |
| 326 | return r; |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 331 | static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 332 | { |
| 333 | int r; |
| 334 | u8 mode; |
| 335 | int b5, b6, b7; |
| 336 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 337 | r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 338 | if (r) |
| 339 | return r; |
| 340 | |
| 341 | switch (rotate) { |
| 342 | default: |
| 343 | case 0: |
| 344 | b7 = 0; |
| 345 | b6 = 0; |
| 346 | b5 = 0; |
| 347 | break; |
| 348 | case 1: |
| 349 | b7 = 0; |
| 350 | b6 = 1; |
| 351 | b5 = 1; |
| 352 | break; |
| 353 | case 2: |
| 354 | b7 = 1; |
| 355 | b6 = 1; |
| 356 | b5 = 0; |
| 357 | break; |
| 358 | case 3: |
| 359 | b7 = 1; |
| 360 | b6 = 0; |
| 361 | b5 = 1; |
| 362 | break; |
| 363 | } |
| 364 | |
| 365 | if (mirror) |
| 366 | b6 = !b6; |
| 367 | |
| 368 | mode &= ~((1<<7) | (1<<6) | (1<<5)); |
| 369 | mode |= (b7 << 7) | (b6 << 6) | (b5 << 5); |
| 370 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 371 | return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 374 | static int taal_set_update_window(struct taal_data *td, |
| 375 | u16 x, u16 y, u16 w, u16 h) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 376 | { |
| 377 | int r; |
| 378 | u16 x1 = x; |
| 379 | u16 x2 = x + w - 1; |
| 380 | u16 y1 = y; |
| 381 | u16 y2 = y + h - 1; |
| 382 | |
| 383 | u8 buf[5]; |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 384 | buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 385 | buf[1] = (x1 >> 8) & 0xff; |
| 386 | buf[2] = (x1 >> 0) & 0xff; |
| 387 | buf[3] = (x2 >> 8) & 0xff; |
| 388 | buf[4] = (x2 >> 0) & 0xff; |
| 389 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 390 | r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf)); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 391 | if (r) |
| 392 | return r; |
| 393 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 394 | buf[0] = MIPI_DCS_SET_PAGE_ADDRESS; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 395 | buf[1] = (y1 >> 8) & 0xff; |
| 396 | buf[2] = (y1 >> 0) & 0xff; |
| 397 | buf[3] = (y2 >> 8) & 0xff; |
| 398 | buf[4] = (y2 >> 0) & 0xff; |
| 399 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 400 | r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf)); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 401 | if (r) |
| 402 | return r; |
| 403 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 404 | dsi_vc_send_bta_sync(td->dssdev, td->channel); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 405 | |
| 406 | return r; |
| 407 | } |
| 408 | |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 409 | static void taal_queue_esd_work(struct omap_dss_device *dssdev) |
| 410 | { |
| 411 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 412 | |
| 413 | if (td->esd_interval > 0) |
Tomi Valkeinen | 883b9ac | 2011-03-24 15:01:30 +0200 | [diff] [blame] | 414 | queue_delayed_work(td->workqueue, &td->esd_work, |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 415 | msecs_to_jiffies(td->esd_interval)); |
| 416 | } |
| 417 | |
| 418 | static void taal_cancel_esd_work(struct omap_dss_device *dssdev) |
| 419 | { |
| 420 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 421 | |
| 422 | cancel_delayed_work(&td->esd_work); |
| 423 | } |
| 424 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 425 | static void taal_queue_ulps_work(struct omap_dss_device *dssdev) |
| 426 | { |
| 427 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 428 | |
| 429 | if (td->ulps_timeout > 0) |
| 430 | queue_delayed_work(td->workqueue, &td->ulps_work, |
| 431 | msecs_to_jiffies(td->ulps_timeout)); |
| 432 | } |
| 433 | |
| 434 | static void taal_cancel_ulps_work(struct omap_dss_device *dssdev) |
| 435 | { |
| 436 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 437 | |
| 438 | cancel_delayed_work(&td->ulps_work); |
| 439 | } |
| 440 | |
| 441 | static int taal_enter_ulps(struct omap_dss_device *dssdev) |
| 442 | { |
| 443 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 444 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
| 445 | int r; |
| 446 | |
| 447 | if (td->ulps_enabled) |
| 448 | return 0; |
| 449 | |
| 450 | taal_cancel_ulps_work(dssdev); |
| 451 | |
| 452 | r = _taal_enable_te(dssdev, false); |
| 453 | if (r) |
| 454 | goto err; |
| 455 | |
| 456 | disable_irq(gpio_to_irq(panel_data->ext_te_gpio)); |
| 457 | |
| 458 | omapdss_dsi_display_disable(dssdev, false, true); |
| 459 | |
| 460 | td->ulps_enabled = true; |
| 461 | |
| 462 | return 0; |
| 463 | |
| 464 | err: |
| 465 | dev_err(&dssdev->dev, "enter ULPS failed"); |
| 466 | taal_panel_reset(dssdev); |
| 467 | |
| 468 | td->ulps_enabled = false; |
| 469 | |
| 470 | taal_queue_ulps_work(dssdev); |
| 471 | |
| 472 | return r; |
| 473 | } |
| 474 | |
| 475 | static int taal_exit_ulps(struct omap_dss_device *dssdev) |
| 476 | { |
| 477 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 478 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
| 479 | int r; |
| 480 | |
| 481 | if (!td->ulps_enabled) |
| 482 | return 0; |
| 483 | |
| 484 | r = omapdss_dsi_display_enable(dssdev); |
Tomi Valkeinen | e894567 | 2011-05-31 16:39:01 +0300 | [diff] [blame] | 485 | if (r) { |
| 486 | dev_err(&dssdev->dev, "failed to enable DSI\n"); |
| 487 | goto err1; |
| 488 | } |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 489 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 490 | omapdss_dsi_vc_enable_hs(dssdev, td->channel, true); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 491 | |
| 492 | r = _taal_enable_te(dssdev, true); |
Tomi Valkeinen | e894567 | 2011-05-31 16:39:01 +0300 | [diff] [blame] | 493 | if (r) { |
| 494 | dev_err(&dssdev->dev, "failed to re-enable TE"); |
| 495 | goto err2; |
| 496 | } |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 497 | |
| 498 | enable_irq(gpio_to_irq(panel_data->ext_te_gpio)); |
| 499 | |
| 500 | taal_queue_ulps_work(dssdev); |
| 501 | |
| 502 | td->ulps_enabled = false; |
| 503 | |
| 504 | return 0; |
| 505 | |
Tomi Valkeinen | e894567 | 2011-05-31 16:39:01 +0300 | [diff] [blame] | 506 | err2: |
| 507 | dev_err(&dssdev->dev, "failed to exit ULPS"); |
| 508 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 509 | r = taal_panel_reset(dssdev); |
Tomi Valkeinen | e894567 | 2011-05-31 16:39:01 +0300 | [diff] [blame] | 510 | if (!r) { |
| 511 | enable_irq(gpio_to_irq(panel_data->ext_te_gpio)); |
| 512 | td->ulps_enabled = false; |
| 513 | } |
| 514 | err1: |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 515 | taal_queue_ulps_work(dssdev); |
| 516 | |
| 517 | return r; |
| 518 | } |
| 519 | |
| 520 | static int taal_wake_up(struct omap_dss_device *dssdev) |
| 521 | { |
| 522 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 523 | |
| 524 | if (td->ulps_enabled) |
| 525 | return taal_exit_ulps(dssdev); |
| 526 | |
| 527 | taal_cancel_ulps_work(dssdev); |
| 528 | taal_queue_ulps_work(dssdev); |
| 529 | return 0; |
| 530 | } |
| 531 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 532 | static int taal_bl_update_status(struct backlight_device *dev) |
| 533 | { |
| 534 | struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev); |
| 535 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 536 | int r; |
| 537 | int level; |
| 538 | |
| 539 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && |
| 540 | dev->props.power == FB_BLANK_UNBLANK) |
| 541 | level = dev->props.brightness; |
| 542 | else |
| 543 | level = 0; |
| 544 | |
| 545 | dev_dbg(&dssdev->dev, "update brightness to %d\n", level); |
| 546 | |
Tomi Valkeinen | 1cbc870 | 2010-04-15 16:41:07 +0300 | [diff] [blame] | 547 | mutex_lock(&td->lock); |
| 548 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 549 | if (td->enabled) { |
| 550 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 551 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 552 | r = taal_wake_up(dssdev); |
| 553 | if (!r) |
| 554 | r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 555 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 556 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 557 | } else { |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 558 | r = 0; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Tomi Valkeinen | 1cbc870 | 2010-04-15 16:41:07 +0300 | [diff] [blame] | 561 | mutex_unlock(&td->lock); |
| 562 | |
| 563 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static int taal_bl_get_intensity(struct backlight_device *dev) |
| 567 | { |
| 568 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && |
| 569 | dev->props.power == FB_BLANK_UNBLANK) |
| 570 | return dev->props.brightness; |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 575 | static const struct backlight_ops taal_bl_ops = { |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 576 | .get_brightness = taal_bl_get_intensity, |
| 577 | .update_status = taal_bl_update_status, |
| 578 | }; |
| 579 | |
| 580 | static void taal_get_timings(struct omap_dss_device *dssdev, |
| 581 | struct omap_video_timings *timings) |
| 582 | { |
| 583 | *timings = dssdev->panel.timings; |
| 584 | } |
| 585 | |
| 586 | static void taal_get_resolution(struct omap_dss_device *dssdev, |
| 587 | u16 *xres, u16 *yres) |
| 588 | { |
| 589 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 590 | |
| 591 | if (td->rotate == 0 || td->rotate == 2) { |
| 592 | *xres = dssdev->panel.timings.x_res; |
| 593 | *yres = dssdev->panel.timings.y_res; |
| 594 | } else { |
| 595 | *yres = dssdev->panel.timings.x_res; |
| 596 | *xres = dssdev->panel.timings.y_res; |
| 597 | } |
| 598 | } |
| 599 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 600 | static ssize_t taal_num_errors_show(struct device *dev, |
| 601 | struct device_attribute *attr, char *buf) |
| 602 | { |
| 603 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 604 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 605 | u8 errors; |
| 606 | int r; |
| 607 | |
Jani Nikula | 6b31671 | 2010-04-28 11:15:18 +0300 | [diff] [blame] | 608 | mutex_lock(&td->lock); |
| 609 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 610 | if (td->enabled) { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 611 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 612 | |
| 613 | r = taal_wake_up(dssdev); |
| 614 | if (!r) |
| 615 | r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors); |
| 616 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 617 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 618 | } else { |
| 619 | r = -ENODEV; |
| 620 | } |
| 621 | |
Jani Nikula | 6b31671 | 2010-04-28 11:15:18 +0300 | [diff] [blame] | 622 | mutex_unlock(&td->lock); |
| 623 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 624 | if (r) |
| 625 | return r; |
| 626 | |
| 627 | return snprintf(buf, PAGE_SIZE, "%d\n", errors); |
| 628 | } |
| 629 | |
| 630 | static ssize_t taal_hw_revision_show(struct device *dev, |
| 631 | struct device_attribute *attr, char *buf) |
| 632 | { |
| 633 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 634 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 635 | u8 id1, id2, id3; |
| 636 | int r; |
| 637 | |
Jani Nikula | 6b31671 | 2010-04-28 11:15:18 +0300 | [diff] [blame] | 638 | mutex_lock(&td->lock); |
| 639 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 640 | if (td->enabled) { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 641 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 642 | |
| 643 | r = taal_wake_up(dssdev); |
| 644 | if (!r) |
| 645 | r = taal_get_id(td, &id1, &id2, &id3); |
| 646 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 647 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 648 | } else { |
| 649 | r = -ENODEV; |
| 650 | } |
| 651 | |
Jani Nikula | 6b31671 | 2010-04-28 11:15:18 +0300 | [diff] [blame] | 652 | mutex_unlock(&td->lock); |
| 653 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 654 | if (r) |
| 655 | return r; |
| 656 | |
| 657 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3); |
| 658 | } |
| 659 | |
| 660 | static const char *cabc_modes[] = { |
| 661 | "off", /* used also always when CABC is not supported */ |
| 662 | "ui", |
| 663 | "still-image", |
| 664 | "moving-image", |
| 665 | }; |
| 666 | |
| 667 | static ssize_t show_cabc_mode(struct device *dev, |
| 668 | struct device_attribute *attr, |
| 669 | char *buf) |
| 670 | { |
| 671 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 672 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 673 | const char *mode_str; |
| 674 | int mode; |
| 675 | int len; |
| 676 | |
| 677 | mode = td->cabc_mode; |
| 678 | |
| 679 | mode_str = "unknown"; |
| 680 | if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes)) |
| 681 | mode_str = cabc_modes[mode]; |
| 682 | len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str); |
| 683 | |
| 684 | return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1; |
| 685 | } |
| 686 | |
| 687 | static ssize_t store_cabc_mode(struct device *dev, |
| 688 | struct device_attribute *attr, |
| 689 | const char *buf, size_t count) |
| 690 | { |
| 691 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 692 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 693 | int i; |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 694 | int r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 695 | |
| 696 | for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) { |
| 697 | if (sysfs_streq(cabc_modes[i], buf)) |
| 698 | break; |
| 699 | } |
| 700 | |
| 701 | if (i == ARRAY_SIZE(cabc_modes)) |
| 702 | return -EINVAL; |
| 703 | |
Jani Nikula | 6b31671 | 2010-04-28 11:15:18 +0300 | [diff] [blame] | 704 | mutex_lock(&td->lock); |
| 705 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 706 | if (td->enabled) { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 707 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 708 | |
| 709 | if (!td->cabc_broken) { |
| 710 | r = taal_wake_up(dssdev); |
| 711 | if (r) |
| 712 | goto err; |
| 713 | |
| 714 | r = taal_dcs_write_1(td, DCS_WRITE_CABC, i); |
| 715 | if (r) |
| 716 | goto err; |
| 717 | } |
| 718 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 719 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | td->cabc_mode = i; |
| 723 | |
Jani Nikula | 6b31671 | 2010-04-28 11:15:18 +0300 | [diff] [blame] | 724 | mutex_unlock(&td->lock); |
| 725 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 726 | return count; |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 727 | err: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 728 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 729 | mutex_unlock(&td->lock); |
| 730 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static ssize_t show_cabc_available_modes(struct device *dev, |
| 734 | struct device_attribute *attr, |
| 735 | char *buf) |
| 736 | { |
| 737 | int len; |
| 738 | int i; |
| 739 | |
| 740 | for (i = 0, len = 0; |
| 741 | len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++) |
| 742 | len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s", |
| 743 | i ? " " : "", cabc_modes[i], |
| 744 | i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : ""); |
| 745 | |
| 746 | return len < PAGE_SIZE ? len : PAGE_SIZE - 1; |
| 747 | } |
| 748 | |
Tomi Valkeinen | 1f8fa45 | 2011-03-24 14:06:51 +0200 | [diff] [blame] | 749 | static ssize_t taal_store_esd_interval(struct device *dev, |
| 750 | struct device_attribute *attr, |
| 751 | const char *buf, size_t count) |
| 752 | { |
| 753 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 754 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 755 | |
| 756 | unsigned long t; |
| 757 | int r; |
| 758 | |
| 759 | r = strict_strtoul(buf, 10, &t); |
| 760 | if (r) |
| 761 | return r; |
| 762 | |
| 763 | mutex_lock(&td->lock); |
| 764 | taal_cancel_esd_work(dssdev); |
| 765 | td->esd_interval = t; |
| 766 | if (td->enabled) |
| 767 | taal_queue_esd_work(dssdev); |
| 768 | mutex_unlock(&td->lock); |
| 769 | |
| 770 | return count; |
| 771 | } |
| 772 | |
| 773 | static ssize_t taal_show_esd_interval(struct device *dev, |
| 774 | struct device_attribute *attr, |
| 775 | char *buf) |
| 776 | { |
| 777 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 778 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 779 | unsigned t; |
| 780 | |
| 781 | mutex_lock(&td->lock); |
| 782 | t = td->esd_interval; |
| 783 | mutex_unlock(&td->lock); |
| 784 | |
| 785 | return snprintf(buf, PAGE_SIZE, "%u\n", t); |
| 786 | } |
| 787 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 788 | static ssize_t taal_store_ulps(struct device *dev, |
| 789 | struct device_attribute *attr, |
| 790 | const char *buf, size_t count) |
| 791 | { |
| 792 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 793 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 794 | unsigned long t; |
| 795 | int r; |
| 796 | |
| 797 | r = strict_strtoul(buf, 10, &t); |
| 798 | if (r) |
| 799 | return r; |
| 800 | |
| 801 | mutex_lock(&td->lock); |
| 802 | |
| 803 | if (td->enabled) { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 804 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 805 | |
| 806 | if (t) |
| 807 | r = taal_enter_ulps(dssdev); |
| 808 | else |
| 809 | r = taal_wake_up(dssdev); |
| 810 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 811 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | mutex_unlock(&td->lock); |
| 815 | |
| 816 | if (r) |
| 817 | return r; |
| 818 | |
| 819 | return count; |
| 820 | } |
| 821 | |
| 822 | static ssize_t taal_show_ulps(struct device *dev, |
| 823 | struct device_attribute *attr, |
| 824 | char *buf) |
| 825 | { |
| 826 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 827 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 828 | unsigned t; |
| 829 | |
| 830 | mutex_lock(&td->lock); |
| 831 | t = td->ulps_enabled; |
| 832 | mutex_unlock(&td->lock); |
| 833 | |
| 834 | return snprintf(buf, PAGE_SIZE, "%u\n", t); |
| 835 | } |
| 836 | |
| 837 | static ssize_t taal_store_ulps_timeout(struct device *dev, |
| 838 | struct device_attribute *attr, |
| 839 | const char *buf, size_t count) |
| 840 | { |
| 841 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 842 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 843 | unsigned long t; |
| 844 | int r; |
| 845 | |
| 846 | r = strict_strtoul(buf, 10, &t); |
| 847 | if (r) |
| 848 | return r; |
| 849 | |
| 850 | mutex_lock(&td->lock); |
| 851 | td->ulps_timeout = t; |
| 852 | |
| 853 | if (td->enabled) { |
| 854 | /* taal_wake_up will restart the timer */ |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 855 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 856 | r = taal_wake_up(dssdev); |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 857 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | mutex_unlock(&td->lock); |
| 861 | |
| 862 | if (r) |
| 863 | return r; |
| 864 | |
| 865 | return count; |
| 866 | } |
| 867 | |
| 868 | static ssize_t taal_show_ulps_timeout(struct device *dev, |
| 869 | struct device_attribute *attr, |
| 870 | char *buf) |
| 871 | { |
| 872 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 873 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 874 | unsigned t; |
| 875 | |
| 876 | mutex_lock(&td->lock); |
| 877 | t = td->ulps_timeout; |
| 878 | mutex_unlock(&td->lock); |
| 879 | |
| 880 | return snprintf(buf, PAGE_SIZE, "%u\n", t); |
| 881 | } |
| 882 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 883 | static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL); |
| 884 | static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL); |
| 885 | static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR, |
| 886 | show_cabc_mode, store_cabc_mode); |
| 887 | static DEVICE_ATTR(cabc_available_modes, S_IRUGO, |
| 888 | show_cabc_available_modes, NULL); |
Tomi Valkeinen | 1f8fa45 | 2011-03-24 14:06:51 +0200 | [diff] [blame] | 889 | static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR, |
| 890 | taal_show_esd_interval, taal_store_esd_interval); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 891 | static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR, |
| 892 | taal_show_ulps, taal_store_ulps); |
| 893 | static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR, |
| 894 | taal_show_ulps_timeout, taal_store_ulps_timeout); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 895 | |
| 896 | static struct attribute *taal_attrs[] = { |
| 897 | &dev_attr_num_dsi_errors.attr, |
| 898 | &dev_attr_hw_revision.attr, |
| 899 | &dev_attr_cabc_mode.attr, |
| 900 | &dev_attr_cabc_available_modes.attr, |
Tomi Valkeinen | 1f8fa45 | 2011-03-24 14:06:51 +0200 | [diff] [blame] | 901 | &dev_attr_esd_interval.attr, |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 902 | &dev_attr_ulps.attr, |
| 903 | &dev_attr_ulps_timeout.attr, |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 904 | NULL, |
| 905 | }; |
| 906 | |
| 907 | static struct attribute_group taal_attr_group = { |
| 908 | .attrs = taal_attrs, |
| 909 | }; |
| 910 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 911 | static void taal_hw_reset(struct omap_dss_device *dssdev) |
| 912 | { |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 913 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 914 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
| 915 | |
| 916 | if (panel_data->reset_gpio == -1) |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 917 | return; |
| 918 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 919 | gpio_set_value(panel_data->reset_gpio, 1); |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 920 | if (td->panel_config->reset_sequence.high) |
| 921 | udelay(td->panel_config->reset_sequence.high); |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 922 | /* reset the panel */ |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 923 | gpio_set_value(panel_data->reset_gpio, 0); |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 924 | /* assert reset */ |
| 925 | if (td->panel_config->reset_sequence.low) |
| 926 | udelay(td->panel_config->reset_sequence.low); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 927 | gpio_set_value(panel_data->reset_gpio, 1); |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 928 | /* wait after releasing reset */ |
| 929 | if (td->panel_config->sleep.hw_reset) |
| 930 | msleep(td->panel_config->sleep.hw_reset); |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 931 | } |
| 932 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 933 | static int taal_probe(struct omap_dss_device *dssdev) |
| 934 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 935 | struct backlight_properties props; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 936 | struct taal_data *td; |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 937 | struct backlight_device *bldev = NULL; |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 938 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 939 | struct panel_config *panel_config = NULL; |
| 940 | int r, i; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 941 | |
| 942 | dev_dbg(&dssdev->dev, "probe\n"); |
| 943 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 944 | if (!panel_data || !panel_data->name) { |
| 945 | r = -EINVAL; |
| 946 | goto err; |
| 947 | } |
| 948 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 949 | for (i = 0; i < ARRAY_SIZE(panel_configs); i++) { |
| 950 | if (strcmp(panel_data->name, panel_configs[i].name) == 0) { |
| 951 | panel_config = &panel_configs[i]; |
| 952 | break; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | if (!panel_config) { |
| 957 | r = -EINVAL; |
| 958 | goto err; |
| 959 | } |
| 960 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 961 | dssdev->panel.config = OMAP_DSS_LCD_TFT; |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 962 | dssdev->panel.timings = panel_config->timings; |
Archit Taneja | a3b3cc2 | 2011-09-08 18:42:16 +0530 | [diff] [blame] | 963 | dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 964 | |
| 965 | td = kzalloc(sizeof(*td), GFP_KERNEL); |
| 966 | if (!td) { |
| 967 | r = -ENOMEM; |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 968 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 969 | } |
| 970 | td->dssdev = dssdev; |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 971 | td->panel_config = panel_config; |
Tomi Valkeinen | 33a410b | 2011-03-24 13:58:01 +0200 | [diff] [blame] | 972 | td->esd_interval = panel_data->esd_interval; |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 973 | td->ulps_enabled = false; |
| 974 | td->ulps_timeout = panel_data->ulps_timeout; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 975 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 976 | mutex_init(&td->lock); |
| 977 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 978 | atomic_set(&td->do_update, 0); |
| 979 | |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 980 | r = init_regulators(dssdev, panel_config->regulators, |
| 981 | panel_config->num_regulators); |
| 982 | if (r) |
| 983 | goto err_reg; |
| 984 | |
Tomi Valkeinen | 883b9ac | 2011-03-24 15:01:30 +0200 | [diff] [blame] | 985 | td->workqueue = create_singlethread_workqueue("taal_esd"); |
| 986 | if (td->workqueue == NULL) { |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 987 | dev_err(&dssdev->dev, "can't create ESD workqueue\n"); |
| 988 | r = -ENOMEM; |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 989 | goto err_wq; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 990 | } |
| 991 | INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 992 | INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 993 | |
| 994 | dev_set_drvdata(&dssdev->dev, td); |
| 995 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 996 | taal_hw_reset(dssdev); |
| 997 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 998 | if (panel_data->use_dsi_backlight) { |
| 999 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 1000 | props.max_brightness = 255; |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 1001 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 1002 | props.type = BACKLIGHT_RAW; |
| 1003 | bldev = backlight_device_register(dev_name(&dssdev->dev), |
| 1004 | &dssdev->dev, dssdev, &taal_bl_ops, &props); |
| 1005 | if (IS_ERR(bldev)) { |
| 1006 | r = PTR_ERR(bldev); |
| 1007 | goto err_bl; |
| 1008 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1009 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 1010 | td->bldev = bldev; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1011 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 1012 | bldev->props.fb_blank = FB_BLANK_UNBLANK; |
| 1013 | bldev->props.power = FB_BLANK_UNBLANK; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1014 | bldev->props.brightness = 255; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1015 | |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 1016 | taal_bl_update_status(bldev); |
| 1017 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1018 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1019 | if (panel_data->use_ext_te) { |
| 1020 | int gpio = panel_data->ext_te_gpio; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1021 | |
Jingoo Han | f8bd493 | 2012-01-26 19:32:34 +0900 | [diff] [blame] | 1022 | r = gpio_request_one(gpio, GPIOF_IN, "taal irq"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1023 | if (r) { |
| 1024 | dev_err(&dssdev->dev, "GPIO request failed\n"); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1025 | goto err_gpio; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1028 | r = request_irq(gpio_to_irq(gpio), taal_te_isr, |
Yong Zhang | f8798cc | 2011-09-22 16:59:16 +0800 | [diff] [blame] | 1029 | IRQF_TRIGGER_RISING, |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1030 | "taal vsync", dssdev); |
| 1031 | |
| 1032 | if (r) { |
| 1033 | dev_err(&dssdev->dev, "IRQ request failed\n"); |
| 1034 | gpio_free(gpio); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1035 | goto err_irq; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1038 | INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work, |
| 1039 | taal_te_timeout_work_callback); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1040 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1041 | dev_dbg(&dssdev->dev, "Using GPIO TE\n"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1042 | } |
| 1043 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1044 | r = omap_dsi_request_vc(dssdev, &td->channel); |
| 1045 | if (r) { |
| 1046 | dev_err(&dssdev->dev, "failed to get virtual channel\n"); |
| 1047 | goto err_req_vc; |
| 1048 | } |
| 1049 | |
| 1050 | r = omap_dsi_set_vc_id(dssdev, td->channel, TCH); |
| 1051 | if (r) { |
| 1052 | dev_err(&dssdev->dev, "failed to set VC_ID\n"); |
| 1053 | goto err_vc_id; |
| 1054 | } |
| 1055 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1056 | r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group); |
| 1057 | if (r) { |
| 1058 | dev_err(&dssdev->dev, "failed to create sysfs files\n"); |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1059 | goto err_vc_id; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | return 0; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1063 | |
| 1064 | err_vc_id: |
| 1065 | omap_dsi_release_vc(dssdev, td->channel); |
| 1066 | err_req_vc: |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1067 | if (panel_data->use_ext_te) |
| 1068 | free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1069 | err_irq: |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1070 | if (panel_data->use_ext_te) |
| 1071 | gpio_free(panel_data->ext_te_gpio); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1072 | err_gpio: |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 1073 | if (bldev != NULL) |
| 1074 | backlight_device_unregister(bldev); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1075 | err_bl: |
Tomi Valkeinen | 883b9ac | 2011-03-24 15:01:30 +0200 | [diff] [blame] | 1076 | destroy_workqueue(td->workqueue); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1077 | err_wq: |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 1078 | free_regulators(panel_config->regulators, panel_config->num_regulators); |
| 1079 | err_reg: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1080 | kfree(td); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 1081 | err: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1082 | return r; |
| 1083 | } |
| 1084 | |
Tomi Valkeinen | 14e4d78 | 2011-03-31 12:03:51 +0300 | [diff] [blame] | 1085 | static void __exit taal_remove(struct omap_dss_device *dssdev) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1086 | { |
| 1087 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1088 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1089 | struct backlight_device *bldev; |
| 1090 | |
| 1091 | dev_dbg(&dssdev->dev, "remove\n"); |
| 1092 | |
| 1093 | sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group); |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1094 | omap_dsi_release_vc(dssdev, td->channel); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1095 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1096 | if (panel_data->use_ext_te) { |
| 1097 | int gpio = panel_data->ext_te_gpio; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1098 | free_irq(gpio_to_irq(gpio), dssdev); |
| 1099 | gpio_free(gpio); |
| 1100 | } |
| 1101 | |
| 1102 | bldev = td->bldev; |
Tomi Valkeinen | bb36dbf | 2011-08-09 11:39:27 +0300 | [diff] [blame] | 1103 | if (bldev != NULL) { |
| 1104 | bldev->props.power = FB_BLANK_POWERDOWN; |
| 1105 | taal_bl_update_status(bldev); |
| 1106 | backlight_device_unregister(bldev); |
| 1107 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1108 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1109 | taal_cancel_ulps_work(dssdev); |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1110 | taal_cancel_esd_work(dssdev); |
Tomi Valkeinen | 883b9ac | 2011-03-24 15:01:30 +0200 | [diff] [blame] | 1111 | destroy_workqueue(td->workqueue); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1112 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1113 | /* reset, to be sure that the panel is in a valid state */ |
| 1114 | taal_hw_reset(dssdev); |
| 1115 | |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 1116 | free_regulators(td->panel_config->regulators, |
| 1117 | td->panel_config->num_regulators); |
| 1118 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1119 | kfree(td); |
| 1120 | } |
| 1121 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1122 | static int taal_power_on(struct omap_dss_device *dssdev) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1123 | { |
| 1124 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1125 | u8 id1, id2, id3; |
| 1126 | int r; |
| 1127 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1128 | r = omapdss_dsi_display_enable(dssdev); |
| 1129 | if (r) { |
| 1130 | dev_err(&dssdev->dev, "failed to enable DSI\n"); |
| 1131 | goto err0; |
| 1132 | } |
| 1133 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1134 | taal_hw_reset(dssdev); |
| 1135 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1136 | omapdss_dsi_vc_enable_hs(dssdev, td->channel, false); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1137 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1138 | r = taal_sleep_out(td); |
| 1139 | if (r) |
| 1140 | goto err; |
| 1141 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1142 | r = taal_get_id(td, &id1, &id2, &id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1143 | if (r) |
| 1144 | goto err; |
| 1145 | |
Jani Nikula | 1e8943d | 2010-04-15 17:07:39 +0300 | [diff] [blame] | 1146 | /* on early Taal revisions CABC is broken */ |
| 1147 | if (td->panel_config->type == PANEL_TAAL && |
| 1148 | (id2 == 0x00 || id2 == 0xff || id2 == 0x81)) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1149 | td->cabc_broken = true; |
| 1150 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1151 | r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 1152 | if (r) |
| 1153 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1154 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1155 | r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY, |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 1156 | (1<<2) | (1<<5)); /* BL | BCTRL */ |
| 1157 | if (r) |
| 1158 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1159 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1160 | r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT, |
| 1161 | MIPI_DCS_PIXEL_FMT_24BIT); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 1162 | if (r) |
| 1163 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1164 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1165 | r = taal_set_addr_mode(td, td->rotate, td->mirror); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 1166 | if (r) |
| 1167 | goto err; |
| 1168 | |
| 1169 | if (!td->cabc_broken) { |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1170 | r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 1171 | if (r) |
| 1172 | goto err; |
| 1173 | } |
| 1174 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1175 | r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 1176 | if (r) |
| 1177 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1178 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1179 | r = _taal_enable_te(dssdev, td->te_enabled); |
| 1180 | if (r) |
| 1181 | goto err; |
| 1182 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 1183 | r = dsi_enable_video_output(dssdev, td->channel); |
| 1184 | if (r) |
| 1185 | goto err; |
| 1186 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1187 | td->enabled = 1; |
| 1188 | |
| 1189 | if (!td->intro_printed) { |
Jani Nikula | 0f45bdd | 2010-04-16 14:21:14 +0300 | [diff] [blame] | 1190 | dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n", |
| 1191 | td->panel_config->name, id1, id2, id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1192 | if (td->cabc_broken) |
| 1193 | dev_info(&dssdev->dev, |
| 1194 | "old Taal version, CABC disabled\n"); |
| 1195 | td->intro_printed = true; |
| 1196 | } |
| 1197 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1198 | omapdss_dsi_vc_enable_hs(dssdev, td->channel, true); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1199 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1200 | return 0; |
| 1201 | err: |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1202 | dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n"); |
| 1203 | |
| 1204 | taal_hw_reset(dssdev); |
| 1205 | |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 1206 | omapdss_dsi_display_disable(dssdev, true, false); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1207 | err0: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1208 | return r; |
| 1209 | } |
| 1210 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1211 | static void taal_power_off(struct omap_dss_device *dssdev) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1212 | { |
| 1213 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1214 | int r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1215 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 1216 | dsi_disable_video_output(dssdev, td->channel); |
| 1217 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1218 | r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF); |
Tomi Valkeinen | 15ffa1d | 2011-06-16 14:34:06 +0300 | [diff] [blame] | 1219 | if (!r) |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1220 | r = taal_sleep_in(td); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1221 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1222 | if (r) { |
| 1223 | dev_err(&dssdev->dev, |
| 1224 | "error disabling panel, issuing HW reset\n"); |
| 1225 | taal_hw_reset(dssdev); |
| 1226 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1227 | |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 1228 | omapdss_dsi_display_disable(dssdev, true, false); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1229 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1230 | td->enabled = 0; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
Tomi Valkeinen | bb5476c7 | 2011-03-24 15:00:06 +0200 | [diff] [blame] | 1233 | static int taal_panel_reset(struct omap_dss_device *dssdev) |
| 1234 | { |
| 1235 | dev_err(&dssdev->dev, "performing LCD reset\n"); |
| 1236 | |
| 1237 | taal_power_off(dssdev); |
| 1238 | taal_hw_reset(dssdev); |
| 1239 | return taal_power_on(dssdev); |
| 1240 | } |
| 1241 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1242 | static int taal_enable(struct omap_dss_device *dssdev) |
| 1243 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1244 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1245 | int r; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1246 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1247 | dev_dbg(&dssdev->dev, "enable\n"); |
| 1248 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1249 | mutex_lock(&td->lock); |
| 1250 | |
| 1251 | if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) { |
| 1252 | r = -EINVAL; |
| 1253 | goto err; |
| 1254 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1255 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1256 | dsi_bus_lock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1257 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1258 | r = taal_power_on(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1259 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1260 | dsi_bus_unlock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1261 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1262 | if (r) |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1263 | goto err; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1264 | |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1265 | taal_queue_esd_work(dssdev); |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1266 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1267 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 1268 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1269 | mutex_unlock(&td->lock); |
| 1270 | |
| 1271 | return 0; |
| 1272 | err: |
| 1273 | dev_dbg(&dssdev->dev, "enable failed\n"); |
| 1274 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1275 | return r; |
| 1276 | } |
| 1277 | |
| 1278 | static void taal_disable(struct omap_dss_device *dssdev) |
| 1279 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1280 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1281 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1282 | dev_dbg(&dssdev->dev, "disable\n"); |
| 1283 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1284 | mutex_lock(&td->lock); |
| 1285 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1286 | taal_cancel_ulps_work(dssdev); |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1287 | taal_cancel_esd_work(dssdev); |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1288 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1289 | dsi_bus_lock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1290 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1291 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
Tomi Valkeinen | e894567 | 2011-05-31 16:39:01 +0300 | [diff] [blame] | 1292 | int r; |
| 1293 | |
| 1294 | r = taal_wake_up(dssdev); |
| 1295 | if (!r) |
| 1296 | taal_power_off(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1297 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1298 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1299 | dsi_bus_unlock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1300 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1301 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1302 | |
| 1303 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | static int taal_suspend(struct omap_dss_device *dssdev) |
| 1307 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1308 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1309 | int r; |
| 1310 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1311 | dev_dbg(&dssdev->dev, "suspend\n"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1312 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1313 | mutex_lock(&td->lock); |
| 1314 | |
| 1315 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { |
| 1316 | r = -EINVAL; |
| 1317 | goto err; |
| 1318 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1319 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1320 | taal_cancel_ulps_work(dssdev); |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1321 | taal_cancel_esd_work(dssdev); |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1322 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1323 | dsi_bus_lock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1324 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1325 | r = taal_wake_up(dssdev); |
| 1326 | if (!r) |
| 1327 | taal_power_off(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1328 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1329 | dsi_bus_unlock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1330 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1331 | dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1332 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1333 | mutex_unlock(&td->lock); |
| 1334 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1335 | return 0; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1336 | err: |
| 1337 | mutex_unlock(&td->lock); |
| 1338 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | static int taal_resume(struct omap_dss_device *dssdev) |
| 1342 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1343 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1344 | int r; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1345 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1346 | dev_dbg(&dssdev->dev, "resume\n"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1347 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1348 | mutex_lock(&td->lock); |
| 1349 | |
| 1350 | if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) { |
| 1351 | r = -EINVAL; |
| 1352 | goto err; |
| 1353 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1354 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1355 | dsi_bus_lock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1356 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1357 | r = taal_power_on(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1358 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1359 | dsi_bus_unlock(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1360 | |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1361 | if (r) { |
Jani Nikula | fed44b7 | 2010-04-12 10:25:21 +0300 | [diff] [blame] | 1362 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1363 | } else { |
Jani Nikula | fed44b7 | 2010-04-12 10:25:21 +0300 | [diff] [blame] | 1364 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1365 | taal_queue_esd_work(dssdev); |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1366 | } |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1367 | |
| 1368 | mutex_unlock(&td->lock); |
| 1369 | |
| 1370 | return r; |
| 1371 | err: |
| 1372 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1373 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1376 | static void taal_framedone_cb(int err, void *data) |
| 1377 | { |
| 1378 | struct omap_dss_device *dssdev = data; |
| 1379 | dev_dbg(&dssdev->dev, "framedone, err %d\n", err); |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1380 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1381 | } |
| 1382 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1383 | static irqreturn_t taal_te_isr(int irq, void *data) |
| 1384 | { |
| 1385 | struct omap_dss_device *dssdev = data; |
| 1386 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1387 | int old; |
| 1388 | int r; |
| 1389 | |
| 1390 | old = atomic_cmpxchg(&td->do_update, 1, 0); |
| 1391 | |
| 1392 | if (old) { |
| 1393 | cancel_delayed_work(&td->te_timeout_work); |
| 1394 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 1395 | r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb, |
| 1396 | dssdev); |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1397 | if (r) |
| 1398 | goto err; |
| 1399 | } |
| 1400 | |
| 1401 | return IRQ_HANDLED; |
| 1402 | err: |
| 1403 | dev_err(&dssdev->dev, "start update failed\n"); |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1404 | dsi_bus_unlock(dssdev); |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1405 | return IRQ_HANDLED; |
| 1406 | } |
| 1407 | |
| 1408 | static void taal_te_timeout_work_callback(struct work_struct *work) |
| 1409 | { |
| 1410 | struct taal_data *td = container_of(work, struct taal_data, |
| 1411 | te_timeout_work.work); |
| 1412 | struct omap_dss_device *dssdev = td->dssdev; |
| 1413 | |
| 1414 | dev_err(&dssdev->dev, "TE not received for 250ms!\n"); |
| 1415 | |
| 1416 | atomic_set(&td->do_update, 0); |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1417 | dsi_bus_unlock(dssdev); |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1418 | } |
| 1419 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1420 | static int taal_update(struct omap_dss_device *dssdev, |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1421 | u16 x, u16 y, u16 w, u16 h) |
| 1422 | { |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1423 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1424 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1425 | int r; |
| 1426 | |
| 1427 | dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); |
| 1428 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1429 | mutex_lock(&td->lock); |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1430 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1431 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1432 | r = taal_wake_up(dssdev); |
| 1433 | if (r) |
| 1434 | goto err; |
| 1435 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1436 | if (!td->enabled) { |
| 1437 | r = 0; |
| 1438 | goto err; |
| 1439 | } |
| 1440 | |
Tomi Valkeinen | 6331709 | 2011-11-03 16:45:07 +0200 | [diff] [blame] | 1441 | /* XXX no need to send this every frame, but dsi break if not done */ |
| 1442 | r = taal_set_update_window(td, 0, 0, |
| 1443 | td->panel_config->timings.x_res, |
| 1444 | td->panel_config->timings.y_res); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1445 | if (r) |
| 1446 | goto err; |
| 1447 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1448 | if (td->te_enabled && panel_data->use_ext_te) { |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1449 | schedule_delayed_work(&td->te_timeout_work, |
| 1450 | msecs_to_jiffies(250)); |
| 1451 | atomic_set(&td->do_update, 1); |
| 1452 | } else { |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 1453 | r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb, |
| 1454 | dssdev); |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1455 | if (r) |
| 1456 | goto err; |
| 1457 | } |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1458 | |
| 1459 | /* note: no bus_unlock here. unlock is in framedone_cb */ |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1460 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1461 | return 0; |
| 1462 | err: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1463 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1464 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1465 | return r; |
| 1466 | } |
| 1467 | |
| 1468 | static int taal_sync(struct omap_dss_device *dssdev) |
| 1469 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1470 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1471 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1472 | dev_dbg(&dssdev->dev, "sync\n"); |
| 1473 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1474 | mutex_lock(&td->lock); |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1475 | dsi_bus_lock(dssdev); |
| 1476 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1477 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1478 | |
| 1479 | dev_dbg(&dssdev->dev, "sync done\n"); |
| 1480 | |
| 1481 | return 0; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1484 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1485 | { |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 1486 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1487 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1488 | int r; |
| 1489 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1490 | if (enable) |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1491 | r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1492 | else |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1493 | r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1494 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1495 | if (!panel_data->use_ext_te) |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1496 | omapdss_dsi_enable_te(dssdev, enable); |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1497 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 1498 | if (td->panel_config->sleep.enable_te) |
| 1499 | msleep(td->panel_config->sleep.enable_te); |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1500 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1501 | return r; |
| 1502 | } |
| 1503 | |
| 1504 | static int taal_enable_te(struct omap_dss_device *dssdev, bool enable) |
| 1505 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1506 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1507 | int r; |
| 1508 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1509 | mutex_lock(&td->lock); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1510 | |
| 1511 | if (td->te_enabled == enable) |
| 1512 | goto end; |
| 1513 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1514 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1515 | |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1516 | if (td->enabled) { |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1517 | r = taal_wake_up(dssdev); |
| 1518 | if (r) |
| 1519 | goto err; |
| 1520 | |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1521 | r = _taal_enable_te(dssdev, enable); |
| 1522 | if (r) |
| 1523 | goto err; |
| 1524 | } |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1525 | |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1526 | td->te_enabled = enable; |
| 1527 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1528 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1529 | end: |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1530 | mutex_unlock(&td->lock); |
| 1531 | |
| 1532 | return 0; |
| 1533 | err: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1534 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1535 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1536 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1537 | return r; |
| 1538 | } |
| 1539 | |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1540 | static int taal_get_te(struct omap_dss_device *dssdev) |
| 1541 | { |
| 1542 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1543 | int r; |
| 1544 | |
| 1545 | mutex_lock(&td->lock); |
| 1546 | r = td->te_enabled; |
| 1547 | mutex_unlock(&td->lock); |
| 1548 | |
| 1549 | return r; |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1550 | } |
| 1551 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1552 | static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate) |
| 1553 | { |
| 1554 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1555 | int r; |
| 1556 | |
| 1557 | dev_dbg(&dssdev->dev, "rotate %d\n", rotate); |
| 1558 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1559 | mutex_lock(&td->lock); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1560 | |
| 1561 | if (td->rotate == rotate) |
| 1562 | goto end; |
| 1563 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1564 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1565 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1566 | if (td->enabled) { |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1567 | r = taal_wake_up(dssdev); |
| 1568 | if (r) |
| 1569 | goto err; |
| 1570 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1571 | r = taal_set_addr_mode(td, rotate, td->mirror); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1572 | if (r) |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1573 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | td->rotate = rotate; |
| 1577 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1578 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1579 | end: |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1580 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1581 | return 0; |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1582 | err: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1583 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1584 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1585 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | static u8 taal_get_rotate(struct omap_dss_device *dssdev) |
| 1589 | { |
| 1590 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1591 | int r; |
| 1592 | |
| 1593 | mutex_lock(&td->lock); |
| 1594 | r = td->rotate; |
| 1595 | mutex_unlock(&td->lock); |
| 1596 | |
| 1597 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | static int taal_mirror(struct omap_dss_device *dssdev, bool enable) |
| 1601 | { |
| 1602 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1603 | int r; |
| 1604 | |
| 1605 | dev_dbg(&dssdev->dev, "mirror %d\n", enable); |
| 1606 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1607 | mutex_lock(&td->lock); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1608 | |
| 1609 | if (td->mirror == enable) |
| 1610 | goto end; |
| 1611 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1612 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1613 | if (td->enabled) { |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1614 | r = taal_wake_up(dssdev); |
| 1615 | if (r) |
| 1616 | goto err; |
| 1617 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1618 | r = taal_set_addr_mode(td, td->rotate, enable); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1619 | if (r) |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1620 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | td->mirror = enable; |
| 1624 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1625 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1626 | end: |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1627 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1628 | return 0; |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1629 | err: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1630 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1631 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1632 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | static bool taal_get_mirror(struct omap_dss_device *dssdev) |
| 1636 | { |
| 1637 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1638 | int r; |
| 1639 | |
| 1640 | mutex_lock(&td->lock); |
| 1641 | r = td->mirror; |
| 1642 | mutex_unlock(&td->lock); |
| 1643 | |
| 1644 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | static int taal_run_test(struct omap_dss_device *dssdev, int test_num) |
| 1648 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1649 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1650 | u8 id1, id2, id3; |
| 1651 | int r; |
| 1652 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1653 | mutex_lock(&td->lock); |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1654 | |
| 1655 | if (!td->enabled) { |
| 1656 | r = -ENODEV; |
| 1657 | goto err1; |
| 1658 | } |
| 1659 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1660 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 1661 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1662 | r = taal_wake_up(dssdev); |
| 1663 | if (r) |
| 1664 | goto err2; |
| 1665 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1666 | r = taal_dcs_read_1(td, DCS_GET_ID1, &id1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1667 | if (r) |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1668 | goto err2; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1669 | r = taal_dcs_read_1(td, DCS_GET_ID2, &id2); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1670 | if (r) |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1671 | goto err2; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1672 | r = taal_dcs_read_1(td, DCS_GET_ID3, &id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1673 | if (r) |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1674 | goto err2; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1675 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1676 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1677 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1678 | return 0; |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1679 | err2: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1680 | dsi_bus_unlock(dssdev); |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1681 | err1: |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1682 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 1683 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | static int taal_memory_read(struct omap_dss_device *dssdev, |
| 1687 | void *buf, size_t size, |
| 1688 | u16 x, u16 y, u16 w, u16 h) |
| 1689 | { |
| 1690 | int r; |
| 1691 | int first = 1; |
| 1692 | int plen; |
| 1693 | unsigned buf_used = 0; |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 1694 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1695 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1696 | if (size < w * h * 3) |
| 1697 | return -ENOMEM; |
| 1698 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1699 | mutex_lock(&td->lock); |
| 1700 | |
| 1701 | if (!td->enabled) { |
| 1702 | r = -ENODEV; |
| 1703 | goto err1; |
| 1704 | } |
| 1705 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1706 | size = min(w * h * 3, |
| 1707 | dssdev->panel.timings.x_res * |
| 1708 | dssdev->panel.timings.y_res * 3); |
| 1709 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1710 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 1711 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1712 | r = taal_wake_up(dssdev); |
| 1713 | if (r) |
| 1714 | goto err2; |
| 1715 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1716 | /* plen 1 or 2 goes into short packet. until checksum error is fixed, |
| 1717 | * use short packets. plen 32 works, but bigger packets seem to cause |
| 1718 | * an error. */ |
| 1719 | if (size % 2) |
| 1720 | plen = 1; |
| 1721 | else |
| 1722 | plen = 2; |
| 1723 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame] | 1724 | taal_set_update_window(td, x, y, w, h); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1725 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1726 | r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1727 | if (r) |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1728 | goto err2; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1729 | |
| 1730 | while (buf_used < size) { |
| 1731 | u8 dcs_cmd = first ? 0x2e : 0x3e; |
| 1732 | first = 0; |
| 1733 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1734 | r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd, |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1735 | buf + buf_used, size - buf_used); |
| 1736 | |
| 1737 | if (r < 0) { |
| 1738 | dev_err(&dssdev->dev, "read error\n"); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1739 | goto err3; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | buf_used += r; |
| 1743 | |
| 1744 | if (r < plen) { |
| 1745 | dev_err(&dssdev->dev, "short read\n"); |
| 1746 | break; |
| 1747 | } |
| 1748 | |
| 1749 | if (signal_pending(current)) { |
| 1750 | dev_err(&dssdev->dev, "signal pending, " |
| 1751 | "aborting memory read\n"); |
| 1752 | r = -ERESTARTSYS; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1753 | goto err3; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | r = buf_used; |
| 1758 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1759 | err3: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1760 | dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1761 | err2: |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1762 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1763 | err1: |
| 1764 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1765 | return r; |
| 1766 | } |
| 1767 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1768 | static void taal_ulps_work(struct work_struct *work) |
| 1769 | { |
| 1770 | struct taal_data *td = container_of(work, struct taal_data, |
| 1771 | ulps_work.work); |
| 1772 | struct omap_dss_device *dssdev = td->dssdev; |
| 1773 | |
| 1774 | mutex_lock(&td->lock); |
| 1775 | |
| 1776 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) { |
| 1777 | mutex_unlock(&td->lock); |
| 1778 | return; |
| 1779 | } |
| 1780 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1781 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1782 | |
| 1783 | taal_enter_ulps(dssdev); |
| 1784 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1785 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1786 | mutex_unlock(&td->lock); |
| 1787 | } |
| 1788 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1789 | static void taal_esd_work(struct work_struct *work) |
| 1790 | { |
| 1791 | struct taal_data *td = container_of(work, struct taal_data, |
| 1792 | esd_work.work); |
| 1793 | struct omap_dss_device *dssdev = td->dssdev; |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1794 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1795 | u8 state1, state2; |
| 1796 | int r; |
| 1797 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1798 | mutex_lock(&td->lock); |
| 1799 | |
| 1800 | if (!td->enabled) { |
| 1801 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1802 | return; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1803 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1804 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1805 | dsi_bus_lock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1806 | |
Tomi Valkeinen | 1abf781 | 2011-03-24 14:53:27 +0200 | [diff] [blame] | 1807 | r = taal_wake_up(dssdev); |
| 1808 | if (r) { |
| 1809 | dev_err(&dssdev->dev, "failed to exit ULPS\n"); |
| 1810 | goto err; |
| 1811 | } |
| 1812 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1813 | r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1814 | if (r) { |
| 1815 | dev_err(&dssdev->dev, "failed to read Taal status\n"); |
| 1816 | goto err; |
| 1817 | } |
| 1818 | |
| 1819 | /* Run self diagnostics */ |
| 1820 | r = taal_sleep_out(td); |
| 1821 | if (r) { |
| 1822 | dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n"); |
| 1823 | goto err; |
| 1824 | } |
| 1825 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1826 | r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1827 | if (r) { |
| 1828 | dev_err(&dssdev->dev, "failed to read Taal status\n"); |
| 1829 | goto err; |
| 1830 | } |
| 1831 | |
| 1832 | /* Each sleep out command will trigger a self diagnostic and flip |
| 1833 | * Bit6 if the test passes. |
| 1834 | */ |
| 1835 | if (!((state1 ^ state2) & (1 << 6))) { |
| 1836 | dev_err(&dssdev->dev, "LCD self diagnostics failed\n"); |
| 1837 | goto err; |
| 1838 | } |
| 1839 | /* Self-diagnostics result is also shown on TE GPIO line. We need |
| 1840 | * to re-enable TE after self diagnostics */ |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1841 | if (td->te_enabled && panel_data->use_ext_te) { |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 1842 | r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0); |
Tomi Valkeinen | 1189b7f | 2010-03-01 13:52:10 +0200 | [diff] [blame] | 1843 | if (r) |
| 1844 | goto err; |
| 1845 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1846 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1847 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1848 | |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1849 | taal_queue_esd_work(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1850 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1851 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1852 | return; |
| 1853 | err: |
| 1854 | dev_err(&dssdev->dev, "performing LCD reset\n"); |
| 1855 | |
Tomi Valkeinen | bb5476c7 | 2011-03-24 15:00:06 +0200 | [diff] [blame] | 1856 | taal_panel_reset(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1857 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 1858 | dsi_bus_unlock(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1859 | |
Tomi Valkeinen | 1663d2f | 2011-03-24 14:01:49 +0200 | [diff] [blame] | 1860 | taal_queue_esd_work(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1861 | |
| 1862 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | static struct omap_dss_driver taal_driver = { |
| 1866 | .probe = taal_probe, |
Tomi Valkeinen | 14e4d78 | 2011-03-31 12:03:51 +0300 | [diff] [blame] | 1867 | .remove = __exit_p(taal_remove), |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1868 | |
| 1869 | .enable = taal_enable, |
| 1870 | .disable = taal_disable, |
| 1871 | .suspend = taal_suspend, |
| 1872 | .resume = taal_resume, |
| 1873 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1874 | .update = taal_update, |
| 1875 | .sync = taal_sync, |
| 1876 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 1877 | .get_resolution = taal_get_resolution, |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 1878 | .get_recommended_bpp = omapdss_default_get_recommended_bpp, |
| 1879 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1880 | .enable_te = taal_enable_te, |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1881 | .get_te = taal_get_te, |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1882 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1883 | .set_rotate = taal_rotate, |
| 1884 | .get_rotate = taal_get_rotate, |
| 1885 | .set_mirror = taal_mirror, |
| 1886 | .get_mirror = taal_get_mirror, |
| 1887 | .run_test = taal_run_test, |
| 1888 | .memory_read = taal_memory_read, |
| 1889 | |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 1890 | .get_timings = taal_get_timings, |
| 1891 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1892 | .driver = { |
| 1893 | .name = "taal", |
| 1894 | .owner = THIS_MODULE, |
| 1895 | }, |
| 1896 | }; |
| 1897 | |
| 1898 | static int __init taal_init(void) |
| 1899 | { |
| 1900 | omap_dss_register_driver(&taal_driver); |
| 1901 | |
| 1902 | return 0; |
| 1903 | } |
| 1904 | |
| 1905 | static void __exit taal_exit(void) |
| 1906 | { |
| 1907 | omap_dss_unregister_driver(&taal_driver); |
| 1908 | } |
| 1909 | |
| 1910 | module_init(taal_init); |
| 1911 | module_exit(taal_exit); |
| 1912 | |
| 1913 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>"); |
| 1914 | MODULE_DESCRIPTION("Taal Driver"); |
| 1915 | MODULE_LICENSE("GPL"); |