panel-taal.c 33 KB

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