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