panel-taal.c 39 KB

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