panel-taal.c 39 KB

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