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