panel-taal.c 36 KB

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