panel-taal.c 36 KB

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