panel-taal.c 37 KB

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