panel-taal.c 39 KB

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