panel-taal.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574
  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 <plat/display.h>
  34. #include <plat/nokia-dsi-panel.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. #define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
  61. static irqreturn_t taal_te_isr(int irq, void *data);
  62. static void taal_te_timeout_work_callback(struct work_struct *work);
  63. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
  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. struct delayed_work te_timeout_work;
  189. bool use_dsi_bl;
  190. bool cabc_broken;
  191. unsigned cabc_mode;
  192. bool intro_printed;
  193. struct workqueue_struct *esd_wq;
  194. struct delayed_work esd_work;
  195. struct panel_config *panel_config;
  196. };
  197. static inline struct nokia_dsi_panel_data
  198. *get_panel_data(const struct omap_dss_device *dssdev)
  199. {
  200. return (struct nokia_dsi_panel_data *) dssdev->data;
  201. }
  202. static void taal_esd_work(struct work_struct *work);
  203. static void hw_guard_start(struct taal_data *td, int guard_msec)
  204. {
  205. td->hw_guard_wait = msecs_to_jiffies(guard_msec);
  206. td->hw_guard_end = jiffies + td->hw_guard_wait;
  207. }
  208. static void hw_guard_wait(struct taal_data *td)
  209. {
  210. unsigned long wait = td->hw_guard_end - jiffies;
  211. if ((long)wait > 0 && wait <= td->hw_guard_wait) {
  212. set_current_state(TASK_UNINTERRUPTIBLE);
  213. schedule_timeout(wait);
  214. }
  215. }
  216. static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
  217. {
  218. int r;
  219. u8 buf[1];
  220. r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
  221. if (r < 0)
  222. return r;
  223. *data = buf[0];
  224. return 0;
  225. }
  226. static int taal_dcs_write_0(u8 dcs_cmd)
  227. {
  228. return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
  229. }
  230. static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
  231. {
  232. u8 buf[2];
  233. buf[0] = dcs_cmd;
  234. buf[1] = param;
  235. return dsi_vc_dcs_write(TCH, buf, 2);
  236. }
  237. static int taal_sleep_in(struct taal_data *td)
  238. {
  239. u8 cmd;
  240. int r;
  241. hw_guard_wait(td);
  242. cmd = DCS_SLEEP_IN;
  243. r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
  244. if (r)
  245. return r;
  246. hw_guard_start(td, 120);
  247. if (td->panel_config->sleep.sleep_in)
  248. msleep(td->panel_config->sleep.sleep_in);
  249. return 0;
  250. }
  251. static int taal_sleep_out(struct taal_data *td)
  252. {
  253. int r;
  254. hw_guard_wait(td);
  255. r = taal_dcs_write_0(DCS_SLEEP_OUT);
  256. if (r)
  257. return r;
  258. hw_guard_start(td, 120);
  259. if (td->panel_config->sleep.sleep_out)
  260. msleep(td->panel_config->sleep.sleep_out);
  261. return 0;
  262. }
  263. static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
  264. {
  265. int r;
  266. r = taal_dcs_read_1(DCS_GET_ID1, id1);
  267. if (r)
  268. return r;
  269. r = taal_dcs_read_1(DCS_GET_ID2, id2);
  270. if (r)
  271. return r;
  272. r = taal_dcs_read_1(DCS_GET_ID3, id3);
  273. if (r)
  274. return r;
  275. return 0;
  276. }
  277. static int taal_set_addr_mode(u8 rotate, bool mirror)
  278. {
  279. int r;
  280. u8 mode;
  281. int b5, b6, b7;
  282. r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
  283. if (r)
  284. return r;
  285. switch (rotate) {
  286. default:
  287. case 0:
  288. b7 = 0;
  289. b6 = 0;
  290. b5 = 0;
  291. break;
  292. case 1:
  293. b7 = 0;
  294. b6 = 1;
  295. b5 = 1;
  296. break;
  297. case 2:
  298. b7 = 1;
  299. b6 = 1;
  300. b5 = 0;
  301. break;
  302. case 3:
  303. b7 = 1;
  304. b6 = 0;
  305. b5 = 1;
  306. break;
  307. }
  308. if (mirror)
  309. b6 = !b6;
  310. mode &= ~((1<<7) | (1<<6) | (1<<5));
  311. mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
  312. return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
  313. }
  314. static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
  315. {
  316. int r;
  317. u16 x1 = x;
  318. u16 x2 = x + w - 1;
  319. u16 y1 = y;
  320. u16 y2 = y + h - 1;
  321. u8 buf[5];
  322. buf[0] = DCS_COLUMN_ADDR;
  323. buf[1] = (x1 >> 8) & 0xff;
  324. buf[2] = (x1 >> 0) & 0xff;
  325. buf[3] = (x2 >> 8) & 0xff;
  326. buf[4] = (x2 >> 0) & 0xff;
  327. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  328. if (r)
  329. return r;
  330. buf[0] = DCS_PAGE_ADDR;
  331. buf[1] = (y1 >> 8) & 0xff;
  332. buf[2] = (y1 >> 0) & 0xff;
  333. buf[3] = (y2 >> 8) & 0xff;
  334. buf[4] = (y2 >> 0) & 0xff;
  335. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  336. if (r)
  337. return r;
  338. dsi_vc_send_bta_sync(TCH);
  339. return r;
  340. }
  341. static int taal_bl_update_status(struct backlight_device *dev)
  342. {
  343. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  344. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  345. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  346. int r;
  347. int level;
  348. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  349. dev->props.power == FB_BLANK_UNBLANK)
  350. level = dev->props.brightness;
  351. else
  352. level = 0;
  353. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  354. mutex_lock(&td->lock);
  355. if (td->use_dsi_bl) {
  356. if (td->enabled) {
  357. dsi_bus_lock();
  358. r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
  359. dsi_bus_unlock();
  360. } else {
  361. r = 0;
  362. }
  363. } else {
  364. if (!panel_data->set_backlight)
  365. r = -EINVAL;
  366. else
  367. r = panel_data->set_backlight(dssdev, level);
  368. }
  369. mutex_unlock(&td->lock);
  370. return r;
  371. }
  372. static int taal_bl_get_intensity(struct backlight_device *dev)
  373. {
  374. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  375. dev->props.power == FB_BLANK_UNBLANK)
  376. return dev->props.brightness;
  377. return 0;
  378. }
  379. static struct backlight_ops taal_bl_ops = {
  380. .get_brightness = taal_bl_get_intensity,
  381. .update_status = taal_bl_update_status,
  382. };
  383. static void taal_get_timings(struct omap_dss_device *dssdev,
  384. struct omap_video_timings *timings)
  385. {
  386. *timings = dssdev->panel.timings;
  387. }
  388. static void taal_get_resolution(struct omap_dss_device *dssdev,
  389. u16 *xres, u16 *yres)
  390. {
  391. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  392. if (td->rotate == 0 || td->rotate == 2) {
  393. *xres = dssdev->panel.timings.x_res;
  394. *yres = dssdev->panel.timings.y_res;
  395. } else {
  396. *yres = dssdev->panel.timings.x_res;
  397. *xres = dssdev->panel.timings.y_res;
  398. }
  399. }
  400. static ssize_t taal_num_errors_show(struct device *dev,
  401. struct device_attribute *attr, char *buf)
  402. {
  403. struct omap_dss_device *dssdev = to_dss_device(dev);
  404. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  405. u8 errors;
  406. int r;
  407. mutex_lock(&td->lock);
  408. if (td->enabled) {
  409. dsi_bus_lock();
  410. r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
  411. dsi_bus_unlock();
  412. } else {
  413. r = -ENODEV;
  414. }
  415. mutex_unlock(&td->lock);
  416. if (r)
  417. return r;
  418. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  419. }
  420. static ssize_t taal_hw_revision_show(struct device *dev,
  421. struct device_attribute *attr, char *buf)
  422. {
  423. struct omap_dss_device *dssdev = to_dss_device(dev);
  424. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  425. u8 id1, id2, id3;
  426. int r;
  427. mutex_lock(&td->lock);
  428. if (td->enabled) {
  429. dsi_bus_lock();
  430. r = taal_get_id(&id1, &id2, &id3);
  431. dsi_bus_unlock();
  432. } else {
  433. r = -ENODEV;
  434. }
  435. mutex_unlock(&td->lock);
  436. if (r)
  437. return r;
  438. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  439. }
  440. static const char *cabc_modes[] = {
  441. "off", /* used also always when CABC is not supported */
  442. "ui",
  443. "still-image",
  444. "moving-image",
  445. };
  446. static ssize_t show_cabc_mode(struct device *dev,
  447. struct device_attribute *attr,
  448. char *buf)
  449. {
  450. struct omap_dss_device *dssdev = to_dss_device(dev);
  451. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  452. const char *mode_str;
  453. int mode;
  454. int len;
  455. mode = td->cabc_mode;
  456. mode_str = "unknown";
  457. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  458. mode_str = cabc_modes[mode];
  459. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  460. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  461. }
  462. static ssize_t store_cabc_mode(struct device *dev,
  463. struct device_attribute *attr,
  464. const char *buf, size_t count)
  465. {
  466. struct omap_dss_device *dssdev = to_dss_device(dev);
  467. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  468. int i;
  469. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  470. if (sysfs_streq(cabc_modes[i], buf))
  471. break;
  472. }
  473. if (i == ARRAY_SIZE(cabc_modes))
  474. return -EINVAL;
  475. mutex_lock(&td->lock);
  476. if (td->enabled) {
  477. dsi_bus_lock();
  478. if (!td->cabc_broken)
  479. taal_dcs_write_1(DCS_WRITE_CABC, i);
  480. dsi_bus_unlock();
  481. }
  482. td->cabc_mode = i;
  483. mutex_unlock(&td->lock);
  484. return count;
  485. }
  486. static ssize_t show_cabc_available_modes(struct device *dev,
  487. struct device_attribute *attr,
  488. char *buf)
  489. {
  490. int len;
  491. int i;
  492. for (i = 0, len = 0;
  493. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  494. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  495. i ? " " : "", cabc_modes[i],
  496. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  497. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  498. }
  499. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  500. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  501. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  502. show_cabc_mode, store_cabc_mode);
  503. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  504. show_cabc_available_modes, NULL);
  505. static struct attribute *taal_attrs[] = {
  506. &dev_attr_num_dsi_errors.attr,
  507. &dev_attr_hw_revision.attr,
  508. &dev_attr_cabc_mode.attr,
  509. &dev_attr_cabc_available_modes.attr,
  510. NULL,
  511. };
  512. static struct attribute_group taal_attr_group = {
  513. .attrs = taal_attrs,
  514. };
  515. static void taal_hw_reset(struct omap_dss_device *dssdev)
  516. {
  517. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  518. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  519. if (panel_data->reset_gpio == -1)
  520. return;
  521. gpio_set_value(panel_data->reset_gpio, 1);
  522. if (td->panel_config->reset_sequence.high)
  523. udelay(td->panel_config->reset_sequence.high);
  524. /* reset the panel */
  525. gpio_set_value(panel_data->reset_gpio, 0);
  526. /* assert reset */
  527. if (td->panel_config->reset_sequence.low)
  528. udelay(td->panel_config->reset_sequence.low);
  529. gpio_set_value(panel_data->reset_gpio, 1);
  530. /* wait after releasing reset */
  531. if (td->panel_config->sleep.hw_reset)
  532. msleep(td->panel_config->sleep.hw_reset);
  533. }
  534. static int taal_probe(struct omap_dss_device *dssdev)
  535. {
  536. struct backlight_properties props;
  537. struct taal_data *td;
  538. struct backlight_device *bldev;
  539. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  540. struct panel_config *panel_config = NULL;
  541. int r, i;
  542. dev_dbg(&dssdev->dev, "probe\n");
  543. if (!panel_data || !panel_data->name) {
  544. r = -EINVAL;
  545. goto err;
  546. }
  547. for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
  548. if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
  549. panel_config = &panel_configs[i];
  550. break;
  551. }
  552. }
  553. if (!panel_config) {
  554. r = -EINVAL;
  555. goto err;
  556. }
  557. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  558. dssdev->panel.timings = panel_config->timings;
  559. dssdev->ctrl.pixel_size = 24;
  560. td = kzalloc(sizeof(*td), GFP_KERNEL);
  561. if (!td) {
  562. r = -ENOMEM;
  563. goto err;
  564. }
  565. td->dssdev = dssdev;
  566. td->panel_config = panel_config;
  567. mutex_init(&td->lock);
  568. atomic_set(&td->do_update, 0);
  569. r = init_regulators(dssdev, panel_config->regulators,
  570. panel_config->num_regulators);
  571. if (r)
  572. goto err_reg;
  573. td->esd_wq = create_singlethread_workqueue("taal_esd");
  574. if (td->esd_wq == NULL) {
  575. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  576. r = -ENOMEM;
  577. goto err_wq;
  578. }
  579. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  580. dev_set_drvdata(&dssdev->dev, td);
  581. taal_hw_reset(dssdev);
  582. /* if no platform set_backlight() defined, presume DSI backlight
  583. * control */
  584. memset(&props, 0, sizeof(struct backlight_properties));
  585. if (!panel_data->set_backlight)
  586. td->use_dsi_bl = true;
  587. if (td->use_dsi_bl)
  588. props.max_brightness = 255;
  589. else
  590. props.max_brightness = 127;
  591. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  592. &taal_bl_ops, &props);
  593. if (IS_ERR(bldev)) {
  594. r = PTR_ERR(bldev);
  595. goto err_bl;
  596. }
  597. td->bldev = bldev;
  598. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  599. bldev->props.power = FB_BLANK_UNBLANK;
  600. if (td->use_dsi_bl)
  601. bldev->props.brightness = 255;
  602. else
  603. bldev->props.brightness = 127;
  604. taal_bl_update_status(bldev);
  605. if (panel_data->use_ext_te) {
  606. int gpio = panel_data->ext_te_gpio;
  607. r = gpio_request(gpio, "taal irq");
  608. if (r) {
  609. dev_err(&dssdev->dev, "GPIO request failed\n");
  610. goto err_gpio;
  611. }
  612. gpio_direction_input(gpio);
  613. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  614. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  615. "taal vsync", dssdev);
  616. if (r) {
  617. dev_err(&dssdev->dev, "IRQ request failed\n");
  618. gpio_free(gpio);
  619. goto err_irq;
  620. }
  621. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  622. taal_te_timeout_work_callback);
  623. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  624. }
  625. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  626. if (r) {
  627. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  628. goto err_sysfs;
  629. }
  630. return 0;
  631. err_sysfs:
  632. if (panel_data->use_ext_te)
  633. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  634. err_irq:
  635. if (panel_data->use_ext_te)
  636. gpio_free(panel_data->ext_te_gpio);
  637. err_gpio:
  638. backlight_device_unregister(bldev);
  639. err_bl:
  640. destroy_workqueue(td->esd_wq);
  641. err_wq:
  642. free_regulators(panel_config->regulators, panel_config->num_regulators);
  643. err_reg:
  644. kfree(td);
  645. err:
  646. return r;
  647. }
  648. static void taal_remove(struct omap_dss_device *dssdev)
  649. {
  650. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  651. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  652. struct backlight_device *bldev;
  653. dev_dbg(&dssdev->dev, "remove\n");
  654. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  655. if (panel_data->use_ext_te) {
  656. int gpio = panel_data->ext_te_gpio;
  657. free_irq(gpio_to_irq(gpio), dssdev);
  658. gpio_free(gpio);
  659. }
  660. bldev = td->bldev;
  661. bldev->props.power = FB_BLANK_POWERDOWN;
  662. taal_bl_update_status(bldev);
  663. backlight_device_unregister(bldev);
  664. cancel_delayed_work(&td->esd_work);
  665. destroy_workqueue(td->esd_wq);
  666. /* reset, to be sure that the panel is in a valid state */
  667. taal_hw_reset(dssdev);
  668. free_regulators(td->panel_config->regulators,
  669. td->panel_config->num_regulators);
  670. kfree(td);
  671. }
  672. static int taal_power_on(struct omap_dss_device *dssdev)
  673. {
  674. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  675. u8 id1, id2, id3;
  676. int r;
  677. r = omapdss_dsi_display_enable(dssdev);
  678. if (r) {
  679. dev_err(&dssdev->dev, "failed to enable DSI\n");
  680. goto err0;
  681. }
  682. taal_hw_reset(dssdev);
  683. omapdss_dsi_vc_enable_hs(TCH, false);
  684. r = taal_sleep_out(td);
  685. if (r)
  686. goto err;
  687. r = taal_get_id(&id1, &id2, &id3);
  688. if (r)
  689. goto err;
  690. /* on early revisions CABC is broken */
  691. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  692. td->cabc_broken = true;
  693. r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  694. if (r)
  695. goto err;
  696. r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
  697. (1<<2) | (1<<5)); /* BL | BCTRL */
  698. if (r)
  699. goto err;
  700. r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  701. if (r)
  702. goto err;
  703. r = taal_set_addr_mode(td->rotate, td->mirror);
  704. if (r)
  705. goto err;
  706. if (!td->cabc_broken) {
  707. r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  708. if (r)
  709. goto err;
  710. }
  711. r = taal_dcs_write_0(DCS_DISPLAY_ON);
  712. if (r)
  713. goto err;
  714. r = _taal_enable_te(dssdev, td->te_enabled);
  715. if (r)
  716. goto err;
  717. td->enabled = 1;
  718. if (!td->intro_printed) {
  719. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  720. td->panel_config->name, id1, id2, id3);
  721. if (td->cabc_broken)
  722. dev_info(&dssdev->dev,
  723. "old Taal version, CABC disabled\n");
  724. td->intro_printed = true;
  725. }
  726. omapdss_dsi_vc_enable_hs(TCH, true);
  727. return 0;
  728. err:
  729. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  730. taal_hw_reset(dssdev);
  731. omapdss_dsi_display_disable(dssdev);
  732. err0:
  733. return r;
  734. }
  735. static void taal_power_off(struct omap_dss_device *dssdev)
  736. {
  737. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  738. int r;
  739. r = taal_dcs_write_0(DCS_DISPLAY_OFF);
  740. if (!r) {
  741. r = taal_sleep_in(td);
  742. /* HACK: wait a bit so that the message goes through */
  743. msleep(10);
  744. }
  745. if (r) {
  746. dev_err(&dssdev->dev,
  747. "error disabling panel, issuing HW reset\n");
  748. taal_hw_reset(dssdev);
  749. }
  750. omapdss_dsi_display_disable(dssdev);
  751. td->enabled = 0;
  752. }
  753. static int taal_enable(struct omap_dss_device *dssdev)
  754. {
  755. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  756. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  757. int r;
  758. dev_dbg(&dssdev->dev, "enable\n");
  759. mutex_lock(&td->lock);
  760. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  761. r = -EINVAL;
  762. goto err;
  763. }
  764. dsi_bus_lock();
  765. r = taal_power_on(dssdev);
  766. dsi_bus_unlock();
  767. if (r)
  768. goto err;
  769. if (panel_data->use_esd_check)
  770. queue_delayed_work(td->esd_wq, &td->esd_work,
  771. TAAL_ESD_CHECK_PERIOD);
  772. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  773. mutex_unlock(&td->lock);
  774. return 0;
  775. err:
  776. dev_dbg(&dssdev->dev, "enable failed\n");
  777. mutex_unlock(&td->lock);
  778. return r;
  779. }
  780. static void taal_disable(struct omap_dss_device *dssdev)
  781. {
  782. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  783. dev_dbg(&dssdev->dev, "disable\n");
  784. mutex_lock(&td->lock);
  785. cancel_delayed_work(&td->esd_work);
  786. dsi_bus_lock();
  787. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  788. taal_power_off(dssdev);
  789. dsi_bus_unlock();
  790. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  791. mutex_unlock(&td->lock);
  792. }
  793. static int taal_suspend(struct omap_dss_device *dssdev)
  794. {
  795. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  796. int r;
  797. dev_dbg(&dssdev->dev, "suspend\n");
  798. mutex_lock(&td->lock);
  799. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  800. r = -EINVAL;
  801. goto err;
  802. }
  803. cancel_delayed_work(&td->esd_work);
  804. dsi_bus_lock();
  805. taal_power_off(dssdev);
  806. dsi_bus_unlock();
  807. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  808. mutex_unlock(&td->lock);
  809. return 0;
  810. err:
  811. mutex_unlock(&td->lock);
  812. return r;
  813. }
  814. static int taal_resume(struct omap_dss_device *dssdev)
  815. {
  816. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  817. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  818. int r;
  819. dev_dbg(&dssdev->dev, "resume\n");
  820. mutex_lock(&td->lock);
  821. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  822. r = -EINVAL;
  823. goto err;
  824. }
  825. dsi_bus_lock();
  826. r = taal_power_on(dssdev);
  827. dsi_bus_unlock();
  828. if (r) {
  829. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  830. } else {
  831. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  832. if (panel_data->use_esd_check)
  833. queue_delayed_work(td->esd_wq, &td->esd_work,
  834. TAAL_ESD_CHECK_PERIOD);
  835. }
  836. mutex_unlock(&td->lock);
  837. return r;
  838. err:
  839. mutex_unlock(&td->lock);
  840. return r;
  841. }
  842. static void taal_framedone_cb(int err, void *data)
  843. {
  844. struct omap_dss_device *dssdev = data;
  845. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  846. dsi_bus_unlock();
  847. }
  848. static irqreturn_t taal_te_isr(int irq, void *data)
  849. {
  850. struct omap_dss_device *dssdev = data;
  851. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  852. int old;
  853. int r;
  854. old = atomic_cmpxchg(&td->do_update, 1, 0);
  855. if (old) {
  856. cancel_delayed_work(&td->te_timeout_work);
  857. r = omap_dsi_update(dssdev, TCH,
  858. td->update_region.x,
  859. td->update_region.y,
  860. td->update_region.w,
  861. td->update_region.h,
  862. taal_framedone_cb, dssdev);
  863. if (r)
  864. goto err;
  865. }
  866. return IRQ_HANDLED;
  867. err:
  868. dev_err(&dssdev->dev, "start update failed\n");
  869. dsi_bus_unlock();
  870. return IRQ_HANDLED;
  871. }
  872. static void taal_te_timeout_work_callback(struct work_struct *work)
  873. {
  874. struct taal_data *td = container_of(work, struct taal_data,
  875. te_timeout_work.work);
  876. struct omap_dss_device *dssdev = td->dssdev;
  877. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  878. atomic_set(&td->do_update, 0);
  879. dsi_bus_unlock();
  880. }
  881. static int taal_update(struct omap_dss_device *dssdev,
  882. u16 x, u16 y, u16 w, u16 h)
  883. {
  884. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  885. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  886. int r;
  887. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  888. mutex_lock(&td->lock);
  889. dsi_bus_lock();
  890. if (!td->enabled) {
  891. r = 0;
  892. goto err;
  893. }
  894. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  895. if (r)
  896. goto err;
  897. r = taal_set_update_window(x, y, w, h);
  898. if (r)
  899. goto err;
  900. if (td->te_enabled && panel_data->use_ext_te) {
  901. td->update_region.x = x;
  902. td->update_region.y = y;
  903. td->update_region.w = w;
  904. td->update_region.h = h;
  905. barrier();
  906. schedule_delayed_work(&td->te_timeout_work,
  907. msecs_to_jiffies(250));
  908. atomic_set(&td->do_update, 1);
  909. } else {
  910. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  911. taal_framedone_cb, dssdev);
  912. if (r)
  913. goto err;
  914. }
  915. /* note: no bus_unlock here. unlock is in framedone_cb */
  916. mutex_unlock(&td->lock);
  917. return 0;
  918. err:
  919. dsi_bus_unlock();
  920. mutex_unlock(&td->lock);
  921. return r;
  922. }
  923. static int taal_sync(struct omap_dss_device *dssdev)
  924. {
  925. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  926. dev_dbg(&dssdev->dev, "sync\n");
  927. mutex_lock(&td->lock);
  928. dsi_bus_lock();
  929. dsi_bus_unlock();
  930. mutex_unlock(&td->lock);
  931. dev_dbg(&dssdev->dev, "sync done\n");
  932. return 0;
  933. }
  934. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  935. {
  936. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  937. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  938. int r;
  939. if (enable)
  940. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  941. else
  942. r = taal_dcs_write_0(DCS_TEAR_OFF);
  943. if (!panel_data->use_ext_te)
  944. omapdss_dsi_enable_te(dssdev, enable);
  945. if (td->panel_config->sleep.enable_te)
  946. msleep(td->panel_config->sleep.enable_te);
  947. return r;
  948. }
  949. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  950. {
  951. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  952. int r;
  953. mutex_lock(&td->lock);
  954. dsi_bus_lock();
  955. if (td->enabled) {
  956. r = _taal_enable_te(dssdev, enable);
  957. if (r)
  958. goto err;
  959. }
  960. td->te_enabled = enable;
  961. dsi_bus_unlock();
  962. mutex_unlock(&td->lock);
  963. return 0;
  964. err:
  965. dsi_bus_unlock();
  966. mutex_unlock(&td->lock);
  967. return r;
  968. }
  969. static int taal_get_te(struct omap_dss_device *dssdev)
  970. {
  971. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  972. int r;
  973. mutex_lock(&td->lock);
  974. r = td->te_enabled;
  975. mutex_unlock(&td->lock);
  976. return r;
  977. }
  978. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  979. {
  980. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  981. int r;
  982. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  983. mutex_lock(&td->lock);
  984. dsi_bus_lock();
  985. if (td->enabled) {
  986. r = taal_set_addr_mode(rotate, td->mirror);
  987. if (r)
  988. goto err;
  989. }
  990. td->rotate = rotate;
  991. dsi_bus_unlock();
  992. mutex_unlock(&td->lock);
  993. return 0;
  994. err:
  995. dsi_bus_unlock();
  996. mutex_unlock(&td->lock);
  997. return r;
  998. }
  999. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1000. {
  1001. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1002. int r;
  1003. mutex_lock(&td->lock);
  1004. r = td->rotate;
  1005. mutex_unlock(&td->lock);
  1006. return r;
  1007. }
  1008. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1009. {
  1010. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1011. int r;
  1012. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1013. mutex_lock(&td->lock);
  1014. dsi_bus_lock();
  1015. if (td->enabled) {
  1016. r = taal_set_addr_mode(td->rotate, enable);
  1017. if (r)
  1018. goto err;
  1019. }
  1020. td->mirror = enable;
  1021. dsi_bus_unlock();
  1022. mutex_unlock(&td->lock);
  1023. return 0;
  1024. err:
  1025. dsi_bus_unlock();
  1026. mutex_unlock(&td->lock);
  1027. return r;
  1028. }
  1029. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1030. {
  1031. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1032. int r;
  1033. mutex_lock(&td->lock);
  1034. r = td->mirror;
  1035. mutex_unlock(&td->lock);
  1036. return r;
  1037. }
  1038. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1039. {
  1040. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1041. u8 id1, id2, id3;
  1042. int r;
  1043. mutex_lock(&td->lock);
  1044. if (!td->enabled) {
  1045. r = -ENODEV;
  1046. goto err1;
  1047. }
  1048. dsi_bus_lock();
  1049. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  1050. if (r)
  1051. goto err2;
  1052. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  1053. if (r)
  1054. goto err2;
  1055. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  1056. if (r)
  1057. goto err2;
  1058. dsi_bus_unlock();
  1059. mutex_unlock(&td->lock);
  1060. return 0;
  1061. err2:
  1062. dsi_bus_unlock();
  1063. err1:
  1064. mutex_unlock(&td->lock);
  1065. return r;
  1066. }
  1067. static int taal_memory_read(struct omap_dss_device *dssdev,
  1068. void *buf, size_t size,
  1069. u16 x, u16 y, u16 w, u16 h)
  1070. {
  1071. int r;
  1072. int first = 1;
  1073. int plen;
  1074. unsigned buf_used = 0;
  1075. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1076. if (size < w * h * 3)
  1077. return -ENOMEM;
  1078. mutex_lock(&td->lock);
  1079. if (!td->enabled) {
  1080. r = -ENODEV;
  1081. goto err1;
  1082. }
  1083. size = min(w * h * 3,
  1084. dssdev->panel.timings.x_res *
  1085. dssdev->panel.timings.y_res * 3);
  1086. dsi_bus_lock();
  1087. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1088. * use short packets. plen 32 works, but bigger packets seem to cause
  1089. * an error. */
  1090. if (size % 2)
  1091. plen = 1;
  1092. else
  1093. plen = 2;
  1094. taal_set_update_window(x, y, w, h);
  1095. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  1096. if (r)
  1097. goto err2;
  1098. while (buf_used < size) {
  1099. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1100. first = 0;
  1101. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  1102. buf + buf_used, size - buf_used);
  1103. if (r < 0) {
  1104. dev_err(&dssdev->dev, "read error\n");
  1105. goto err3;
  1106. }
  1107. buf_used += r;
  1108. if (r < plen) {
  1109. dev_err(&dssdev->dev, "short read\n");
  1110. break;
  1111. }
  1112. if (signal_pending(current)) {
  1113. dev_err(&dssdev->dev, "signal pending, "
  1114. "aborting memory read\n");
  1115. r = -ERESTARTSYS;
  1116. goto err3;
  1117. }
  1118. }
  1119. r = buf_used;
  1120. err3:
  1121. dsi_vc_set_max_rx_packet_size(TCH, 1);
  1122. err2:
  1123. dsi_bus_unlock();
  1124. err1:
  1125. mutex_unlock(&td->lock);
  1126. return r;
  1127. }
  1128. static void taal_esd_work(struct work_struct *work)
  1129. {
  1130. struct taal_data *td = container_of(work, struct taal_data,
  1131. esd_work.work);
  1132. struct omap_dss_device *dssdev = td->dssdev;
  1133. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1134. u8 state1, state2;
  1135. int r;
  1136. mutex_lock(&td->lock);
  1137. if (!td->enabled) {
  1138. mutex_unlock(&td->lock);
  1139. return;
  1140. }
  1141. dsi_bus_lock();
  1142. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  1143. if (r) {
  1144. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1145. goto err;
  1146. }
  1147. /* Run self diagnostics */
  1148. r = taal_sleep_out(td);
  1149. if (r) {
  1150. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1151. goto err;
  1152. }
  1153. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  1154. if (r) {
  1155. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1156. goto err;
  1157. }
  1158. /* Each sleep out command will trigger a self diagnostic and flip
  1159. * Bit6 if the test passes.
  1160. */
  1161. if (!((state1 ^ state2) & (1 << 6))) {
  1162. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1163. goto err;
  1164. }
  1165. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1166. * to re-enable TE after self diagnostics */
  1167. if (td->te_enabled && panel_data->use_ext_te) {
  1168. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  1169. if (r)
  1170. goto err;
  1171. }
  1172. dsi_bus_unlock();
  1173. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1174. mutex_unlock(&td->lock);
  1175. return;
  1176. err:
  1177. dev_err(&dssdev->dev, "performing LCD reset\n");
  1178. taal_power_off(dssdev);
  1179. taal_hw_reset(dssdev);
  1180. taal_power_on(dssdev);
  1181. dsi_bus_unlock();
  1182. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1183. mutex_unlock(&td->lock);
  1184. }
  1185. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  1186. enum omap_dss_update_mode mode)
  1187. {
  1188. if (mode != OMAP_DSS_UPDATE_MANUAL)
  1189. return -EINVAL;
  1190. return 0;
  1191. }
  1192. static enum omap_dss_update_mode taal_get_update_mode(
  1193. struct omap_dss_device *dssdev)
  1194. {
  1195. return OMAP_DSS_UPDATE_MANUAL;
  1196. }
  1197. static struct omap_dss_driver taal_driver = {
  1198. .probe = taal_probe,
  1199. .remove = taal_remove,
  1200. .enable = taal_enable,
  1201. .disable = taal_disable,
  1202. .suspend = taal_suspend,
  1203. .resume = taal_resume,
  1204. .set_update_mode = taal_set_update_mode,
  1205. .get_update_mode = taal_get_update_mode,
  1206. .update = taal_update,
  1207. .sync = taal_sync,
  1208. .get_resolution = taal_get_resolution,
  1209. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1210. .enable_te = taal_enable_te,
  1211. .get_te = taal_get_te,
  1212. .set_rotate = taal_rotate,
  1213. .get_rotate = taal_get_rotate,
  1214. .set_mirror = taal_mirror,
  1215. .get_mirror = taal_get_mirror,
  1216. .run_test = taal_run_test,
  1217. .memory_read = taal_memory_read,
  1218. .get_timings = taal_get_timings,
  1219. .driver = {
  1220. .name = "taal",
  1221. .owner = THIS_MODULE,
  1222. },
  1223. };
  1224. static int __init taal_init(void)
  1225. {
  1226. omap_dss_register_driver(&taal_driver);
  1227. return 0;
  1228. }
  1229. static void __exit taal_exit(void)
  1230. {
  1231. omap_dss_unregister_driver(&taal_driver);
  1232. }
  1233. module_init(taal_init);
  1234. module_exit(taal_exit);
  1235. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1236. MODULE_DESCRIPTION("Taal Driver");
  1237. MODULE_LICENSE("GPL");