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 | |
| 36 | #include <plat/display.h> |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 37 | #include <plat/nokia-dsi-panel.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; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 735 | bldev = backlight_device_register("taal", &dssdev->dev, dssdev, |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 736 | &taal_bl_ops, &props); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 737 | if (IS_ERR(bldev)) { |
| 738 | r = PTR_ERR(bldev); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 739 | goto err_bl; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | td->bldev = bldev; |
| 743 | |
| 744 | bldev->props.fb_blank = FB_BLANK_UNBLANK; |
| 745 | bldev->props.power = FB_BLANK_UNBLANK; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 746 | if (td->use_dsi_bl) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 747 | bldev->props.brightness = 255; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 748 | else |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 749 | bldev->props.brightness = 127; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 750 | |
| 751 | taal_bl_update_status(bldev); |
| 752 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 753 | if (panel_data->use_ext_te) { |
| 754 | int gpio = panel_data->ext_te_gpio; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 755 | |
| 756 | r = gpio_request(gpio, "taal irq"); |
| 757 | if (r) { |
| 758 | dev_err(&dssdev->dev, "GPIO request failed\n"); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 759 | goto err_gpio; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | gpio_direction_input(gpio); |
| 763 | |
| 764 | r = request_irq(gpio_to_irq(gpio), taal_te_isr, |
| 765 | IRQF_DISABLED | IRQF_TRIGGER_RISING, |
| 766 | "taal vsync", dssdev); |
| 767 | |
| 768 | if (r) { |
| 769 | dev_err(&dssdev->dev, "IRQ request failed\n"); |
| 770 | gpio_free(gpio); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 771 | goto err_irq; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 772 | } |
| 773 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 774 | INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work, |
| 775 | taal_te_timeout_work_callback); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 776 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 777 | dev_dbg(&dssdev->dev, "Using GPIO TE\n"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 778 | } |
| 779 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 780 | r = omap_dsi_request_vc(dssdev, &td->channel); |
| 781 | if (r) { |
| 782 | dev_err(&dssdev->dev, "failed to get virtual channel\n"); |
| 783 | goto err_req_vc; |
| 784 | } |
| 785 | |
| 786 | r = omap_dsi_set_vc_id(dssdev, td->channel, TCH); |
| 787 | if (r) { |
| 788 | dev_err(&dssdev->dev, "failed to set VC_ID\n"); |
| 789 | goto err_vc_id; |
| 790 | } |
| 791 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 792 | r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group); |
| 793 | if (r) { |
| 794 | dev_err(&dssdev->dev, "failed to create sysfs files\n"); |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 795 | goto err_vc_id; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | return 0; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 799 | |
| 800 | err_vc_id: |
| 801 | omap_dsi_release_vc(dssdev, td->channel); |
| 802 | err_req_vc: |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 803 | if (panel_data->use_ext_te) |
| 804 | free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 805 | err_irq: |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 806 | if (panel_data->use_ext_te) |
| 807 | gpio_free(panel_data->ext_te_gpio); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 808 | err_gpio: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 809 | backlight_device_unregister(bldev); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 810 | err_bl: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 811 | destroy_workqueue(td->esd_wq); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 812 | err_wq: |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 813 | free_regulators(panel_config->regulators, panel_config->num_regulators); |
| 814 | err_reg: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 815 | kfree(td); |
Jani Nikula | d2b6578 | 2010-04-15 12:24:36 +0300 | [diff] [blame] | 816 | err: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 817 | return r; |
| 818 | } |
| 819 | |
| 820 | static void taal_remove(struct omap_dss_device *dssdev) |
| 821 | { |
| 822 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 823 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 824 | struct backlight_device *bldev; |
| 825 | |
| 826 | dev_dbg(&dssdev->dev, "remove\n"); |
| 827 | |
| 828 | sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group); |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 829 | omap_dsi_release_vc(dssdev, td->channel); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 830 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 831 | if (panel_data->use_ext_te) { |
| 832 | int gpio = panel_data->ext_te_gpio; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 833 | free_irq(gpio_to_irq(gpio), dssdev); |
| 834 | gpio_free(gpio); |
| 835 | } |
| 836 | |
| 837 | bldev = td->bldev; |
| 838 | bldev->props.power = FB_BLANK_POWERDOWN; |
| 839 | taal_bl_update_status(bldev); |
| 840 | backlight_device_unregister(bldev); |
| 841 | |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 842 | cancel_delayed_work(&td->esd_work); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 843 | destroy_workqueue(td->esd_wq); |
| 844 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 845 | /* reset, to be sure that the panel is in a valid state */ |
| 846 | taal_hw_reset(dssdev); |
| 847 | |
Tomi Valkeinen | c8cd454 | 2010-06-09 15:24:46 +0300 | [diff] [blame] | 848 | free_regulators(td->panel_config->regulators, |
| 849 | td->panel_config->num_regulators); |
| 850 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 851 | kfree(td); |
| 852 | } |
| 853 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 854 | static int taal_power_on(struct omap_dss_device *dssdev) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 855 | { |
| 856 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 857 | u8 id1, id2, id3; |
| 858 | int r; |
| 859 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 860 | r = omapdss_dsi_display_enable(dssdev); |
| 861 | if (r) { |
| 862 | dev_err(&dssdev->dev, "failed to enable DSI\n"); |
| 863 | goto err0; |
| 864 | } |
| 865 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 866 | taal_hw_reset(dssdev); |
| 867 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 868 | omapdss_dsi_vc_enable_hs(td->channel, false); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 869 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 870 | r = taal_sleep_out(td); |
| 871 | if (r) |
| 872 | goto err; |
| 873 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 874 | r = taal_get_id(td, &id1, &id2, &id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 875 | if (r) |
| 876 | goto err; |
| 877 | |
Jani Nikula | 1e8943d | 2010-04-15 17:07:39 +0300 | [diff] [blame] | 878 | /* on early Taal revisions CABC is broken */ |
| 879 | if (td->panel_config->type == PANEL_TAAL && |
| 880 | (id2 == 0x00 || id2 == 0xff || id2 == 0x81)) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 881 | td->cabc_broken = true; |
| 882 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 883 | r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 884 | if (r) |
| 885 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 886 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 887 | r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY, |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 888 | (1<<2) | (1<<5)); /* BL | BCTRL */ |
| 889 | if (r) |
| 890 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 891 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 892 | r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */ |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 893 | if (r) |
| 894 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 895 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 896 | r = taal_set_addr_mode(td, td->rotate, td->mirror); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 897 | if (r) |
| 898 | goto err; |
| 899 | |
| 900 | if (!td->cabc_broken) { |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 901 | r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 902 | if (r) |
| 903 | goto err; |
| 904 | } |
| 905 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 906 | r = taal_dcs_write_0(td, DCS_DISPLAY_ON); |
Jani Nikula | f2a8b75 | 2010-04-09 14:15:12 +0300 | [diff] [blame] | 907 | if (r) |
| 908 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 909 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 910 | r = _taal_enable_te(dssdev, td->te_enabled); |
| 911 | if (r) |
| 912 | goto err; |
| 913 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 914 | td->enabled = 1; |
| 915 | |
| 916 | if (!td->intro_printed) { |
Jani Nikula | 0f45bdd | 2010-04-16 14:21:14 +0300 | [diff] [blame] | 917 | dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n", |
| 918 | td->panel_config->name, id1, id2, id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 919 | if (td->cabc_broken) |
| 920 | dev_info(&dssdev->dev, |
| 921 | "old Taal version, CABC disabled\n"); |
| 922 | td->intro_printed = true; |
| 923 | } |
| 924 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 925 | omapdss_dsi_vc_enable_hs(td->channel, true); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 926 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 927 | return 0; |
| 928 | err: |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 929 | dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n"); |
| 930 | |
| 931 | taal_hw_reset(dssdev); |
| 932 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 933 | omapdss_dsi_display_disable(dssdev); |
| 934 | err0: |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 935 | return r; |
| 936 | } |
| 937 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 938 | static void taal_power_off(struct omap_dss_device *dssdev) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 939 | { |
| 940 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 941 | int r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 942 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 943 | r = taal_dcs_write_0(td, DCS_DISPLAY_OFF); |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 944 | if (!r) { |
| 945 | r = taal_sleep_in(td); |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 946 | /* HACK: wait a bit so that the message goes through */ |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 947 | msleep(10); |
| 948 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 949 | |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 950 | if (r) { |
| 951 | dev_err(&dssdev->dev, |
| 952 | "error disabling panel, issuing HW reset\n"); |
| 953 | taal_hw_reset(dssdev); |
| 954 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 955 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 956 | omapdss_dsi_display_disable(dssdev); |
| 957 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 958 | td->enabled = 0; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static int taal_enable(struct omap_dss_device *dssdev) |
| 962 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 963 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Jani Nikula | 448dfe9 | 2010-04-15 12:42:16 +0300 | [diff] [blame] | 964 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 965 | int r; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 966 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 967 | dev_dbg(&dssdev->dev, "enable\n"); |
| 968 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 969 | mutex_lock(&td->lock); |
| 970 | |
| 971 | if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) { |
| 972 | r = -EINVAL; |
| 973 | goto err; |
| 974 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 975 | |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 976 | dsi_bus_lock(); |
| 977 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 978 | r = taal_power_on(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 979 | |
| 980 | dsi_bus_unlock(); |
| 981 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 982 | if (r) |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 983 | goto err; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 984 | |
Jani Nikula | 448dfe9 | 2010-04-15 12:42:16 +0300 | [diff] [blame] | 985 | if (panel_data->use_esd_check) |
| 986 | queue_delayed_work(td->esd_wq, &td->esd_work, |
| 987 | TAAL_ESD_CHECK_PERIOD); |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 988 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 989 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 990 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 991 | mutex_unlock(&td->lock); |
| 992 | |
| 993 | return 0; |
| 994 | err: |
| 995 | dev_dbg(&dssdev->dev, "enable failed\n"); |
| 996 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 997 | return r; |
| 998 | } |
| 999 | |
| 1000 | static void taal_disable(struct omap_dss_device *dssdev) |
| 1001 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1002 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1003 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1004 | dev_dbg(&dssdev->dev, "disable\n"); |
| 1005 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1006 | mutex_lock(&td->lock); |
| 1007 | |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1008 | cancel_delayed_work(&td->esd_work); |
| 1009 | |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1010 | dsi_bus_lock(); |
| 1011 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1012 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) |
| 1013 | taal_power_off(dssdev); |
| 1014 | |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1015 | dsi_bus_unlock(); |
| 1016 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1017 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1018 | |
| 1019 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static int taal_suspend(struct omap_dss_device *dssdev) |
| 1023 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1024 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1025 | int r; |
| 1026 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1027 | dev_dbg(&dssdev->dev, "suspend\n"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1028 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1029 | mutex_lock(&td->lock); |
| 1030 | |
| 1031 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { |
| 1032 | r = -EINVAL; |
| 1033 | goto err; |
| 1034 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1035 | |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1036 | cancel_delayed_work(&td->esd_work); |
| 1037 | |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1038 | dsi_bus_lock(); |
| 1039 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1040 | taal_power_off(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1041 | |
| 1042 | dsi_bus_unlock(); |
| 1043 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1044 | dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1045 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1046 | mutex_unlock(&td->lock); |
| 1047 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1048 | return 0; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1049 | err: |
| 1050 | mutex_unlock(&td->lock); |
| 1051 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | static int taal_resume(struct omap_dss_device *dssdev) |
| 1055 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1056 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Jani Nikula | 448dfe9 | 2010-04-15 12:42:16 +0300 | [diff] [blame] | 1057 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1058 | int r; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1059 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1060 | dev_dbg(&dssdev->dev, "resume\n"); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1061 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1062 | mutex_lock(&td->lock); |
| 1063 | |
| 1064 | if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) { |
| 1065 | r = -EINVAL; |
| 1066 | goto err; |
| 1067 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1068 | |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1069 | dsi_bus_lock(); |
| 1070 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1071 | r = taal_power_on(dssdev); |
Jani Nikula | 2c2fc15 | 2010-04-12 10:06:14 +0300 | [diff] [blame] | 1072 | |
| 1073 | dsi_bus_unlock(); |
| 1074 | |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1075 | if (r) { |
Jani Nikula | fed44b7 | 2010-04-12 10:25:21 +0300 | [diff] [blame] | 1076 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1077 | } else { |
Jani Nikula | fed44b7 | 2010-04-12 10:25:21 +0300 | [diff] [blame] | 1078 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
Jani Nikula | 448dfe9 | 2010-04-15 12:42:16 +0300 | [diff] [blame] | 1079 | if (panel_data->use_esd_check) |
| 1080 | queue_delayed_work(td->esd_wq, &td->esd_work, |
| 1081 | TAAL_ESD_CHECK_PERIOD); |
Jani Nikula | 4571a02 | 2010-04-12 10:23:46 +0300 | [diff] [blame] | 1082 | } |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1083 | |
| 1084 | mutex_unlock(&td->lock); |
| 1085 | |
| 1086 | return r; |
| 1087 | err: |
| 1088 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 1089 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1090 | } |
| 1091 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1092 | static void taal_framedone_cb(int err, void *data) |
| 1093 | { |
| 1094 | struct omap_dss_device *dssdev = data; |
| 1095 | dev_dbg(&dssdev->dev, "framedone, err %d\n", err); |
| 1096 | dsi_bus_unlock(); |
| 1097 | } |
| 1098 | |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1099 | static irqreturn_t taal_te_isr(int irq, void *data) |
| 1100 | { |
| 1101 | struct omap_dss_device *dssdev = data; |
| 1102 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1103 | int old; |
| 1104 | int r; |
| 1105 | |
| 1106 | old = atomic_cmpxchg(&td->do_update, 1, 0); |
| 1107 | |
| 1108 | if (old) { |
| 1109 | cancel_delayed_work(&td->te_timeout_work); |
| 1110 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1111 | r = omap_dsi_update(dssdev, td->channel, |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1112 | td->update_region.x, |
| 1113 | td->update_region.y, |
| 1114 | td->update_region.w, |
| 1115 | td->update_region.h, |
| 1116 | taal_framedone_cb, dssdev); |
| 1117 | if (r) |
| 1118 | goto err; |
| 1119 | } |
| 1120 | |
| 1121 | return IRQ_HANDLED; |
| 1122 | err: |
| 1123 | dev_err(&dssdev->dev, "start update failed\n"); |
| 1124 | dsi_bus_unlock(); |
| 1125 | return IRQ_HANDLED; |
| 1126 | } |
| 1127 | |
| 1128 | static void taal_te_timeout_work_callback(struct work_struct *work) |
| 1129 | { |
| 1130 | struct taal_data *td = container_of(work, struct taal_data, |
| 1131 | te_timeout_work.work); |
| 1132 | struct omap_dss_device *dssdev = td->dssdev; |
| 1133 | |
| 1134 | dev_err(&dssdev->dev, "TE not received for 250ms!\n"); |
| 1135 | |
| 1136 | atomic_set(&td->do_update, 0); |
| 1137 | dsi_bus_unlock(); |
| 1138 | } |
| 1139 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1140 | static int taal_update(struct omap_dss_device *dssdev, |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1141 | u16 x, u16 y, u16 w, u16 h) |
| 1142 | { |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1143 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1144 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1145 | int r; |
| 1146 | |
| 1147 | dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); |
| 1148 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1149 | mutex_lock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1150 | dsi_bus_lock(); |
| 1151 | |
| 1152 | if (!td->enabled) { |
| 1153 | r = 0; |
| 1154 | goto err; |
| 1155 | } |
| 1156 | |
Tomi Valkeinen | 26a8c25 | 2010-06-09 15:31:34 +0300 | [diff] [blame] | 1157 | r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1158 | if (r) |
| 1159 | goto err; |
| 1160 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1161 | r = taal_set_update_window(td, x, y, w, h); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1162 | if (r) |
| 1163 | goto err; |
| 1164 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1165 | if (td->te_enabled && panel_data->use_ext_te) { |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1166 | td->update_region.x = x; |
| 1167 | td->update_region.y = y; |
| 1168 | td->update_region.w = w; |
| 1169 | td->update_region.h = h; |
| 1170 | barrier(); |
| 1171 | schedule_delayed_work(&td->te_timeout_work, |
| 1172 | msecs_to_jiffies(250)); |
| 1173 | atomic_set(&td->do_update, 1); |
| 1174 | } else { |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1175 | r = omap_dsi_update(dssdev, td->channel, x, y, w, h, |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1176 | taal_framedone_cb, dssdev); |
| 1177 | if (r) |
| 1178 | goto err; |
| 1179 | } |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1180 | |
| 1181 | /* note: no bus_unlock here. unlock is in framedone_cb */ |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1182 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1183 | return 0; |
| 1184 | err: |
| 1185 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1186 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1187 | return r; |
| 1188 | } |
| 1189 | |
| 1190 | static int taal_sync(struct omap_dss_device *dssdev) |
| 1191 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1192 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1193 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1194 | dev_dbg(&dssdev->dev, "sync\n"); |
| 1195 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1196 | mutex_lock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1197 | dsi_bus_lock(); |
| 1198 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1199 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1200 | |
| 1201 | dev_dbg(&dssdev->dev, "sync done\n"); |
| 1202 | |
| 1203 | return 0; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1206 | static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable) |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1207 | { |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 1208 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1209 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1210 | int r; |
| 1211 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1212 | if (enable) |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1213 | r = taal_dcs_write_1(td, DCS_TEAR_ON, 0); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1214 | else |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1215 | r = taal_dcs_write_0(td, DCS_TEAR_OFF); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1216 | |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1217 | if (!panel_data->use_ext_te) |
Jani Nikula | 7ae2fb1 | 2010-04-13 10:57:52 +0300 | [diff] [blame] | 1218 | omapdss_dsi_enable_te(dssdev, enable); |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1219 | |
Jani Nikula | e7f6c3f | 2010-04-15 12:55:38 +0300 | [diff] [blame] | 1220 | if (td->panel_config->sleep.enable_te) |
| 1221 | msleep(td->panel_config->sleep.enable_te); |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1222 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1223 | return r; |
| 1224 | } |
| 1225 | |
| 1226 | static int taal_enable_te(struct omap_dss_device *dssdev, bool enable) |
| 1227 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1228 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1229 | int r; |
| 1230 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1231 | mutex_lock(&td->lock); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1232 | |
| 1233 | if (td->te_enabled == enable) |
| 1234 | goto end; |
| 1235 | |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1236 | dsi_bus_lock(); |
| 1237 | |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1238 | if (td->enabled) { |
| 1239 | r = _taal_enable_te(dssdev, enable); |
| 1240 | if (r) |
| 1241 | goto err; |
| 1242 | } |
Tomi Valkeinen | 21df20f | 2010-03-02 12:13:55 +0200 | [diff] [blame] | 1243 | |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1244 | td->te_enabled = enable; |
| 1245 | |
| 1246 | dsi_bus_unlock(); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1247 | end: |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1248 | mutex_unlock(&td->lock); |
| 1249 | |
| 1250 | return 0; |
| 1251 | err: |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1252 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1253 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1254 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1255 | return r; |
| 1256 | } |
| 1257 | |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1258 | static int taal_get_te(struct omap_dss_device *dssdev) |
| 1259 | { |
| 1260 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1261 | int r; |
| 1262 | |
| 1263 | mutex_lock(&td->lock); |
| 1264 | r = td->te_enabled; |
| 1265 | mutex_unlock(&td->lock); |
| 1266 | |
| 1267 | return r; |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1270 | static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate) |
| 1271 | { |
| 1272 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1273 | int r; |
| 1274 | |
| 1275 | dev_dbg(&dssdev->dev, "rotate %d\n", rotate); |
| 1276 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1277 | mutex_lock(&td->lock); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1278 | |
| 1279 | if (td->rotate == rotate) |
| 1280 | goto end; |
| 1281 | |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1282 | dsi_bus_lock(); |
| 1283 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1284 | if (td->enabled) { |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1285 | r = taal_set_addr_mode(td, rotate, td->mirror); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1286 | if (r) |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1287 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | td->rotate = rotate; |
| 1291 | |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1292 | dsi_bus_unlock(); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1293 | end: |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1294 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1295 | return 0; |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1296 | err: |
| 1297 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1298 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 87424e1 | 2010-01-08 16:52:48 +0200 | [diff] [blame] | 1299 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | static u8 taal_get_rotate(struct omap_dss_device *dssdev) |
| 1303 | { |
| 1304 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1305 | int r; |
| 1306 | |
| 1307 | mutex_lock(&td->lock); |
| 1308 | r = td->rotate; |
| 1309 | mutex_unlock(&td->lock); |
| 1310 | |
| 1311 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static int taal_mirror(struct omap_dss_device *dssdev, bool enable) |
| 1315 | { |
| 1316 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1317 | int r; |
| 1318 | |
| 1319 | dev_dbg(&dssdev->dev, "mirror %d\n", enable); |
| 1320 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1321 | mutex_lock(&td->lock); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1322 | |
| 1323 | if (td->mirror == enable) |
| 1324 | goto end; |
| 1325 | |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1326 | dsi_bus_lock(); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1327 | if (td->enabled) { |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1328 | r = taal_set_addr_mode(td, td->rotate, enable); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1329 | if (r) |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1330 | goto err; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | td->mirror = enable; |
| 1334 | |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1335 | dsi_bus_unlock(); |
Tomi Valkeinen | ffb63c9 | 2010-05-21 10:09:18 +0300 | [diff] [blame] | 1336 | end: |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1337 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1338 | return 0; |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1339 | err: |
| 1340 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1341 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 8d8aa61 | 2010-01-08 16:30:33 +0200 | [diff] [blame] | 1342 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static bool taal_get_mirror(struct omap_dss_device *dssdev) |
| 1346 | { |
| 1347 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1348 | int r; |
| 1349 | |
| 1350 | mutex_lock(&td->lock); |
| 1351 | r = td->mirror; |
| 1352 | mutex_unlock(&td->lock); |
| 1353 | |
| 1354 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | static int taal_run_test(struct omap_dss_device *dssdev, int test_num) |
| 1358 | { |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1359 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1360 | u8 id1, id2, id3; |
| 1361 | int r; |
| 1362 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1363 | mutex_lock(&td->lock); |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1364 | |
| 1365 | if (!td->enabled) { |
| 1366 | r = -ENODEV; |
| 1367 | goto err1; |
| 1368 | } |
| 1369 | |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 1370 | dsi_bus_lock(); |
| 1371 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1372 | r = taal_dcs_read_1(td, DCS_GET_ID1, &id1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1373 | if (r) |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1374 | goto err2; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1375 | r = taal_dcs_read_1(td, DCS_GET_ID2, &id2); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1376 | if (r) |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1377 | goto err2; |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1378 | r = taal_dcs_read_1(td, DCS_GET_ID3, &id3); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1379 | if (r) |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1380 | goto err2; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1381 | |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 1382 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1383 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1384 | return 0; |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1385 | err2: |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 1386 | dsi_bus_unlock(); |
Jani Nikula | ee52c0a | 2010-04-12 09:36:05 +0300 | [diff] [blame] | 1387 | err1: |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1388 | mutex_unlock(&td->lock); |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 1389 | return r; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static int taal_memory_read(struct omap_dss_device *dssdev, |
| 1393 | void *buf, size_t size, |
| 1394 | u16 x, u16 y, u16 w, u16 h) |
| 1395 | { |
| 1396 | int r; |
| 1397 | int first = 1; |
| 1398 | int plen; |
| 1399 | unsigned buf_used = 0; |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 1400 | struct taal_data *td = dev_get_drvdata(&dssdev->dev); |
| 1401 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1402 | if (size < w * h * 3) |
| 1403 | return -ENOMEM; |
| 1404 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1405 | mutex_lock(&td->lock); |
| 1406 | |
| 1407 | if (!td->enabled) { |
| 1408 | r = -ENODEV; |
| 1409 | goto err1; |
| 1410 | } |
| 1411 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1412 | size = min(w * h * 3, |
| 1413 | dssdev->panel.timings.x_res * |
| 1414 | dssdev->panel.timings.y_res * 3); |
| 1415 | |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 1416 | dsi_bus_lock(); |
| 1417 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1418 | /* plen 1 or 2 goes into short packet. until checksum error is fixed, |
| 1419 | * use short packets. plen 32 works, but bigger packets seem to cause |
| 1420 | * an error. */ |
| 1421 | if (size % 2) |
| 1422 | plen = 1; |
| 1423 | else |
| 1424 | plen = 2; |
| 1425 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1426 | taal_set_update_window(td, x, y, w, h); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1427 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1428 | r = dsi_vc_set_max_rx_packet_size(td->channel, plen); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1429 | if (r) |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1430 | goto err2; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1431 | |
| 1432 | while (buf_used < size) { |
| 1433 | u8 dcs_cmd = first ? 0x2e : 0x3e; |
| 1434 | first = 0; |
| 1435 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1436 | r = dsi_vc_dcs_read(td->channel, dcs_cmd, |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1437 | buf + buf_used, size - buf_used); |
| 1438 | |
| 1439 | if (r < 0) { |
| 1440 | dev_err(&dssdev->dev, "read error\n"); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1441 | goto err3; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | buf_used += r; |
| 1445 | |
| 1446 | if (r < plen) { |
| 1447 | dev_err(&dssdev->dev, "short read\n"); |
| 1448 | break; |
| 1449 | } |
| 1450 | |
| 1451 | if (signal_pending(current)) { |
| 1452 | dev_err(&dssdev->dev, "signal pending, " |
| 1453 | "aborting memory read\n"); |
| 1454 | r = -ERESTARTSYS; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1455 | goto err3; |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | r = buf_used; |
| 1460 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1461 | err3: |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1462 | dsi_vc_set_max_rx_packet_size(td->channel, 1); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1463 | err2: |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 1464 | dsi_bus_unlock(); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1465 | err1: |
| 1466 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1467 | return r; |
| 1468 | } |
| 1469 | |
| 1470 | static void taal_esd_work(struct work_struct *work) |
| 1471 | { |
| 1472 | struct taal_data *td = container_of(work, struct taal_data, |
| 1473 | esd_work.work); |
| 1474 | struct omap_dss_device *dssdev = td->dssdev; |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1475 | struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1476 | u8 state1, state2; |
| 1477 | int r; |
| 1478 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1479 | mutex_lock(&td->lock); |
| 1480 | |
| 1481 | if (!td->enabled) { |
| 1482 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1483 | return; |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1484 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1485 | |
| 1486 | dsi_bus_lock(); |
| 1487 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1488 | r = taal_dcs_read_1(td, DCS_RDDSDR, &state1); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1489 | if (r) { |
| 1490 | dev_err(&dssdev->dev, "failed to read Taal status\n"); |
| 1491 | goto err; |
| 1492 | } |
| 1493 | |
| 1494 | /* Run self diagnostics */ |
| 1495 | r = taal_sleep_out(td); |
| 1496 | if (r) { |
| 1497 | dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n"); |
| 1498 | goto err; |
| 1499 | } |
| 1500 | |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1501 | r = taal_dcs_read_1(td, DCS_RDDSDR, &state2); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1502 | if (r) { |
| 1503 | dev_err(&dssdev->dev, "failed to read Taal status\n"); |
| 1504 | goto err; |
| 1505 | } |
| 1506 | |
| 1507 | /* Each sleep out command will trigger a self diagnostic and flip |
| 1508 | * Bit6 if the test passes. |
| 1509 | */ |
| 1510 | if (!((state1 ^ state2) & (1 << 6))) { |
| 1511 | dev_err(&dssdev->dev, "LCD self diagnostics failed\n"); |
| 1512 | goto err; |
| 1513 | } |
| 1514 | /* Self-diagnostics result is also shown on TE GPIO line. We need |
| 1515 | * to re-enable TE after self diagnostics */ |
Tomi Valkeinen | 8d3573c | 2010-06-09 15:23:44 +0300 | [diff] [blame] | 1516 | if (td->te_enabled && panel_data->use_ext_te) { |
Archit Taneja | bc6d4b1 | 2011-03-01 13:59:46 +0530 | [diff] [blame^] | 1517 | r = taal_dcs_write_1(td, DCS_TEAR_ON, 0); |
Tomi Valkeinen | 1189b7f | 2010-03-01 13:52:10 +0200 | [diff] [blame] | 1518 | if (r) |
| 1519 | goto err; |
| 1520 | } |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1521 | |
| 1522 | dsi_bus_unlock(); |
| 1523 | |
| 1524 | queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD); |
| 1525 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1526 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1527 | return; |
| 1528 | err: |
| 1529 | dev_err(&dssdev->dev, "performing LCD reset\n"); |
| 1530 | |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1531 | taal_power_off(dssdev); |
Jani Nikula | 006db7b | 2010-04-09 12:25:59 +0300 | [diff] [blame] | 1532 | taal_hw_reset(dssdev); |
Tomi Valkeinen | a3201a0 | 2010-03-03 14:31:45 +0200 | [diff] [blame] | 1533 | taal_power_on(dssdev); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1534 | |
| 1535 | dsi_bus_unlock(); |
| 1536 | |
| 1537 | 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] | 1538 | |
| 1539 | mutex_unlock(&td->lock); |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1540 | } |
| 1541 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 1542 | static int taal_set_update_mode(struct omap_dss_device *dssdev, |
| 1543 | enum omap_dss_update_mode mode) |
| 1544 | { |
| 1545 | if (mode != OMAP_DSS_UPDATE_MANUAL) |
| 1546 | return -EINVAL; |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | static enum omap_dss_update_mode taal_get_update_mode( |
| 1551 | struct omap_dss_device *dssdev) |
| 1552 | { |
| 1553 | return OMAP_DSS_UPDATE_MANUAL; |
| 1554 | } |
| 1555 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1556 | static struct omap_dss_driver taal_driver = { |
| 1557 | .probe = taal_probe, |
| 1558 | .remove = taal_remove, |
| 1559 | |
| 1560 | .enable = taal_enable, |
| 1561 | .disable = taal_disable, |
| 1562 | .suspend = taal_suspend, |
| 1563 | .resume = taal_resume, |
| 1564 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 1565 | .set_update_mode = taal_set_update_mode, |
| 1566 | .get_update_mode = taal_get_update_mode, |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 1567 | |
| 1568 | .update = taal_update, |
| 1569 | .sync = taal_sync, |
| 1570 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 1571 | .get_resolution = taal_get_resolution, |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 1572 | .get_recommended_bpp = omapdss_default_get_recommended_bpp, |
| 1573 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1574 | .enable_te = taal_enable_te, |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1575 | .get_te = taal_get_te, |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 1576 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1577 | .set_rotate = taal_rotate, |
| 1578 | .get_rotate = taal_get_rotate, |
| 1579 | .set_mirror = taal_mirror, |
| 1580 | .get_mirror = taal_get_mirror, |
| 1581 | .run_test = taal_run_test, |
| 1582 | .memory_read = taal_memory_read, |
| 1583 | |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 1584 | .get_timings = taal_get_timings, |
| 1585 | |
Tomi Valkeinen | f133a9d | 2009-10-28 11:31:05 +0200 | [diff] [blame] | 1586 | .driver = { |
| 1587 | .name = "taal", |
| 1588 | .owner = THIS_MODULE, |
| 1589 | }, |
| 1590 | }; |
| 1591 | |
| 1592 | static int __init taal_init(void) |
| 1593 | { |
| 1594 | omap_dss_register_driver(&taal_driver); |
| 1595 | |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | static void __exit taal_exit(void) |
| 1600 | { |
| 1601 | omap_dss_unregister_driver(&taal_driver); |
| 1602 | } |
| 1603 | |
| 1604 | module_init(taal_init); |
| 1605 | module_exit(taal_exit); |
| 1606 | |
| 1607 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>"); |
| 1608 | MODULE_DESCRIPTION("Taal Driver"); |
| 1609 | MODULE_LICENSE("GPL"); |