panel-taal.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  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 const 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. props.type = BACKLIGHT_RAW;
  592. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  593. &taal_bl_ops, &props);
  594. if (IS_ERR(bldev)) {
  595. r = PTR_ERR(bldev);
  596. goto err_bl;
  597. }
  598. td->bldev = bldev;
  599. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  600. bldev->props.power = FB_BLANK_UNBLANK;
  601. if (td->use_dsi_bl)
  602. bldev->props.brightness = 255;
  603. else
  604. bldev->props.brightness = 127;
  605. taal_bl_update_status(bldev);
  606. if (panel_data->use_ext_te) {
  607. int gpio = panel_data->ext_te_gpio;
  608. r = gpio_request(gpio, "taal irq");
  609. if (r) {
  610. dev_err(&dssdev->dev, "GPIO request failed\n");
  611. goto err_gpio;
  612. }
  613. gpio_direction_input(gpio);
  614. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  615. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  616. "taal vsync", dssdev);
  617. if (r) {
  618. dev_err(&dssdev->dev, "IRQ request failed\n");
  619. gpio_free(gpio);
  620. goto err_irq;
  621. }
  622. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  623. taal_te_timeout_work_callback);
  624. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  625. }
  626. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  627. if (r) {
  628. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  629. goto err_sysfs;
  630. }
  631. return 0;
  632. err_sysfs:
  633. if (panel_data->use_ext_te)
  634. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  635. err_irq:
  636. if (panel_data->use_ext_te)
  637. gpio_free(panel_data->ext_te_gpio);
  638. err_gpio:
  639. backlight_device_unregister(bldev);
  640. err_bl:
  641. destroy_workqueue(td->esd_wq);
  642. err_wq:
  643. free_regulators(panel_config->regulators, panel_config->num_regulators);
  644. err_reg:
  645. kfree(td);
  646. err:
  647. return r;
  648. }
  649. static void taal_remove(struct omap_dss_device *dssdev)
  650. {
  651. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  652. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  653. struct backlight_device *bldev;
  654. dev_dbg(&dssdev->dev, "remove\n");
  655. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  656. if (panel_data->use_ext_te) {
  657. int gpio = panel_data->ext_te_gpio;
  658. free_irq(gpio_to_irq(gpio), dssdev);
  659. gpio_free(gpio);
  660. }
  661. bldev = td->bldev;
  662. bldev->props.power = FB_BLANK_POWERDOWN;
  663. taal_bl_update_status(bldev);
  664. backlight_device_unregister(bldev);
  665. cancel_delayed_work(&td->esd_work);
  666. destroy_workqueue(td->esd_wq);
  667. /* reset, to be sure that the panel is in a valid state */
  668. taal_hw_reset(dssdev);
  669. free_regulators(td->panel_config->regulators,
  670. td->panel_config->num_regulators);
  671. kfree(td);
  672. }
  673. static int taal_power_on(struct omap_dss_device *dssdev)
  674. {
  675. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  676. u8 id1, id2, id3;
  677. int r;
  678. r = omapdss_dsi_display_enable(dssdev);
  679. if (r) {
  680. dev_err(&dssdev->dev, "failed to enable DSI\n");
  681. goto err0;
  682. }
  683. taal_hw_reset(dssdev);
  684. omapdss_dsi_vc_enable_hs(TCH, false);
  685. r = taal_sleep_out(td);
  686. if (r)
  687. goto err;
  688. r = taal_get_id(&id1, &id2, &id3);
  689. if (r)
  690. goto err;
  691. /* on early Taal revisions CABC is broken */
  692. if (td->panel_config->type == PANEL_TAAL &&
  693. (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
  694. td->cabc_broken = true;
  695. r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  696. if (r)
  697. goto err;
  698. r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
  699. (1<<2) | (1<<5)); /* BL | BCTRL */
  700. if (r)
  701. goto err;
  702. r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  703. if (r)
  704. goto err;
  705. r = taal_set_addr_mode(td->rotate, td->mirror);
  706. if (r)
  707. goto err;
  708. if (!td->cabc_broken) {
  709. r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  710. if (r)
  711. goto err;
  712. }
  713. r = taal_dcs_write_0(DCS_DISPLAY_ON);
  714. if (r)
  715. goto err;
  716. r = _taal_enable_te(dssdev, td->te_enabled);
  717. if (r)
  718. goto err;
  719. td->enabled = 1;
  720. if (!td->intro_printed) {
  721. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  722. td->panel_config->name, id1, id2, id3);
  723. if (td->cabc_broken)
  724. dev_info(&dssdev->dev,
  725. "old Taal version, CABC disabled\n");
  726. td->intro_printed = true;
  727. }
  728. omapdss_dsi_vc_enable_hs(TCH, true);
  729. return 0;
  730. err:
  731. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  732. taal_hw_reset(dssdev);
  733. omapdss_dsi_display_disable(dssdev);
  734. err0:
  735. return r;
  736. }
  737. static void taal_power_off(struct omap_dss_device *dssdev)
  738. {
  739. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  740. int r;
  741. r = taal_dcs_write_0(DCS_DISPLAY_OFF);
  742. if (!r) {
  743. r = taal_sleep_in(td);
  744. /* HACK: wait a bit so that the message goes through */
  745. msleep(10);
  746. }
  747. if (r) {
  748. dev_err(&dssdev->dev,
  749. "error disabling panel, issuing HW reset\n");
  750. taal_hw_reset(dssdev);
  751. }
  752. omapdss_dsi_display_disable(dssdev);
  753. td->enabled = 0;
  754. }
  755. static int taal_enable(struct omap_dss_device *dssdev)
  756. {
  757. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  758. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  759. int r;
  760. dev_dbg(&dssdev->dev, "enable\n");
  761. mutex_lock(&td->lock);
  762. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  763. r = -EINVAL;
  764. goto err;
  765. }
  766. dsi_bus_lock();
  767. r = taal_power_on(dssdev);
  768. dsi_bus_unlock();
  769. if (r)
  770. goto err;
  771. if (panel_data->use_esd_check)
  772. queue_delayed_work(td->esd_wq, &td->esd_work,
  773. TAAL_ESD_CHECK_PERIOD);
  774. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  775. mutex_unlock(&td->lock);
  776. return 0;
  777. err:
  778. dev_dbg(&dssdev->dev, "enable failed\n");
  779. mutex_unlock(&td->lock);
  780. return r;
  781. }
  782. static void taal_disable(struct omap_dss_device *dssdev)
  783. {
  784. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  785. dev_dbg(&dssdev->dev, "disable\n");
  786. mutex_lock(&td->lock);
  787. cancel_delayed_work(&td->esd_work);
  788. dsi_bus_lock();
  789. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  790. taal_power_off(dssdev);
  791. dsi_bus_unlock();
  792. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  793. mutex_unlock(&td->lock);
  794. }
  795. static int taal_suspend(struct omap_dss_device *dssdev)
  796. {
  797. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  798. int r;
  799. dev_dbg(&dssdev->dev, "suspend\n");
  800. mutex_lock(&td->lock);
  801. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  802. r = -EINVAL;
  803. goto err;
  804. }
  805. cancel_delayed_work(&td->esd_work);
  806. dsi_bus_lock();
  807. taal_power_off(dssdev);
  808. dsi_bus_unlock();
  809. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  810. mutex_unlock(&td->lock);
  811. return 0;
  812. err:
  813. mutex_unlock(&td->lock);
  814. return r;
  815. }
  816. static int taal_resume(struct omap_dss_device *dssdev)
  817. {
  818. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  819. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  820. int r;
  821. dev_dbg(&dssdev->dev, "resume\n");
  822. mutex_lock(&td->lock);
  823. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  824. r = -EINVAL;
  825. goto err;
  826. }
  827. dsi_bus_lock();
  828. r = taal_power_on(dssdev);
  829. dsi_bus_unlock();
  830. if (r) {
  831. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  832. } else {
  833. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  834. if (panel_data->use_esd_check)
  835. queue_delayed_work(td->esd_wq, &td->esd_work,
  836. TAAL_ESD_CHECK_PERIOD);
  837. }
  838. mutex_unlock(&td->lock);
  839. return r;
  840. err:
  841. mutex_unlock(&td->lock);
  842. return r;
  843. }
  844. static void taal_framedone_cb(int err, void *data)
  845. {
  846. struct omap_dss_device *dssdev = data;
  847. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  848. dsi_bus_unlock();
  849. }
  850. static irqreturn_t taal_te_isr(int irq, void *data)
  851. {
  852. struct omap_dss_device *dssdev = data;
  853. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  854. int old;
  855. int r;
  856. old = atomic_cmpxchg(&td->do_update, 1, 0);
  857. if (old) {
  858. cancel_delayed_work(&td->te_timeout_work);
  859. r = omap_dsi_update(dssdev, TCH,
  860. td->update_region.x,
  861. td->update_region.y,
  862. td->update_region.w,
  863. td->update_region.h,
  864. taal_framedone_cb, dssdev);
  865. if (r)
  866. goto err;
  867. }
  868. return IRQ_HANDLED;
  869. err:
  870. dev_err(&dssdev->dev, "start update failed\n");
  871. dsi_bus_unlock();
  872. return IRQ_HANDLED;
  873. }
  874. static void taal_te_timeout_work_callback(struct work_struct *work)
  875. {
  876. struct taal_data *td = container_of(work, struct taal_data,
  877. te_timeout_work.work);
  878. struct omap_dss_device *dssdev = td->dssdev;
  879. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  880. atomic_set(&td->do_update, 0);
  881. dsi_bus_unlock();
  882. }
  883. static int taal_update(struct omap_dss_device *dssdev,
  884. u16 x, u16 y, u16 w, u16 h)
  885. {
  886. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  887. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  888. int r;
  889. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  890. mutex_lock(&td->lock);
  891. dsi_bus_lock();
  892. if (!td->enabled) {
  893. r = 0;
  894. goto err;
  895. }
  896. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
  897. if (r)
  898. goto err;
  899. r = taal_set_update_window(x, y, w, h);
  900. if (r)
  901. goto err;
  902. if (td->te_enabled && panel_data->use_ext_te) {
  903. td->update_region.x = x;
  904. td->update_region.y = y;
  905. td->update_region.w = w;
  906. td->update_region.h = h;
  907. barrier();
  908. schedule_delayed_work(&td->te_timeout_work,
  909. msecs_to_jiffies(250));
  910. atomic_set(&td->do_update, 1);
  911. } else {
  912. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  913. taal_framedone_cb, dssdev);
  914. if (r)
  915. goto err;
  916. }
  917. /* note: no bus_unlock here. unlock is in framedone_cb */
  918. mutex_unlock(&td->lock);
  919. return 0;
  920. err:
  921. dsi_bus_unlock();
  922. mutex_unlock(&td->lock);
  923. return r;
  924. }
  925. static int taal_sync(struct omap_dss_device *dssdev)
  926. {
  927. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  928. dev_dbg(&dssdev->dev, "sync\n");
  929. mutex_lock(&td->lock);
  930. dsi_bus_lock();
  931. dsi_bus_unlock();
  932. mutex_unlock(&td->lock);
  933. dev_dbg(&dssdev->dev, "sync done\n");
  934. return 0;
  935. }
  936. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  937. {
  938. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  939. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  940. int r;
  941. if (enable)
  942. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  943. else
  944. r = taal_dcs_write_0(DCS_TEAR_OFF);
  945. if (!panel_data->use_ext_te)
  946. omapdss_dsi_enable_te(dssdev, enable);
  947. if (td->panel_config->sleep.enable_te)
  948. msleep(td->panel_config->sleep.enable_te);
  949. return r;
  950. }
  951. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  952. {
  953. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  954. int r;
  955. mutex_lock(&td->lock);
  956. if (td->te_enabled == enable)
  957. goto end;
  958. dsi_bus_lock();
  959. if (td->enabled) {
  960. r = _taal_enable_te(dssdev, enable);
  961. if (r)
  962. goto err;
  963. }
  964. td->te_enabled = enable;
  965. dsi_bus_unlock();
  966. end:
  967. mutex_unlock(&td->lock);
  968. return 0;
  969. err:
  970. dsi_bus_unlock();
  971. mutex_unlock(&td->lock);
  972. return r;
  973. }
  974. static int taal_get_te(struct omap_dss_device *dssdev)
  975. {
  976. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  977. int r;
  978. mutex_lock(&td->lock);
  979. r = td->te_enabled;
  980. mutex_unlock(&td->lock);
  981. return r;
  982. }
  983. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  984. {
  985. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  986. int r;
  987. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  988. mutex_lock(&td->lock);
  989. if (td->rotate == rotate)
  990. goto end;
  991. dsi_bus_lock();
  992. if (td->enabled) {
  993. r = taal_set_addr_mode(rotate, td->mirror);
  994. if (r)
  995. goto err;
  996. }
  997. td->rotate = rotate;
  998. dsi_bus_unlock();
  999. end:
  1000. mutex_unlock(&td->lock);
  1001. return 0;
  1002. err:
  1003. dsi_bus_unlock();
  1004. mutex_unlock(&td->lock);
  1005. return r;
  1006. }
  1007. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1008. {
  1009. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1010. int r;
  1011. mutex_lock(&td->lock);
  1012. r = td->rotate;
  1013. mutex_unlock(&td->lock);
  1014. return r;
  1015. }
  1016. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1017. {
  1018. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1019. int r;
  1020. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1021. mutex_lock(&td->lock);
  1022. if (td->mirror == enable)
  1023. goto end;
  1024. dsi_bus_lock();
  1025. if (td->enabled) {
  1026. r = taal_set_addr_mode(td->rotate, enable);
  1027. if (r)
  1028. goto err;
  1029. }
  1030. td->mirror = enable;
  1031. dsi_bus_unlock();
  1032. end:
  1033. mutex_unlock(&td->lock);
  1034. return 0;
  1035. err:
  1036. dsi_bus_unlock();
  1037. mutex_unlock(&td->lock);
  1038. return r;
  1039. }
  1040. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1041. {
  1042. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1043. int r;
  1044. mutex_lock(&td->lock);
  1045. r = td->mirror;
  1046. mutex_unlock(&td->lock);
  1047. return r;
  1048. }
  1049. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1050. {
  1051. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1052. u8 id1, id2, id3;
  1053. int r;
  1054. mutex_lock(&td->lock);
  1055. if (!td->enabled) {
  1056. r = -ENODEV;
  1057. goto err1;
  1058. }
  1059. dsi_bus_lock();
  1060. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  1061. if (r)
  1062. goto err2;
  1063. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  1064. if (r)
  1065. goto err2;
  1066. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  1067. if (r)
  1068. goto err2;
  1069. dsi_bus_unlock();
  1070. mutex_unlock(&td->lock);
  1071. return 0;
  1072. err2:
  1073. dsi_bus_unlock();
  1074. err1:
  1075. mutex_unlock(&td->lock);
  1076. return r;
  1077. }
  1078. static int taal_memory_read(struct omap_dss_device *dssdev,
  1079. void *buf, size_t size,
  1080. u16 x, u16 y, u16 w, u16 h)
  1081. {
  1082. int r;
  1083. int first = 1;
  1084. int plen;
  1085. unsigned buf_used = 0;
  1086. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1087. if (size < w * h * 3)
  1088. return -ENOMEM;
  1089. mutex_lock(&td->lock);
  1090. if (!td->enabled) {
  1091. r = -ENODEV;
  1092. goto err1;
  1093. }
  1094. size = min(w * h * 3,
  1095. dssdev->panel.timings.x_res *
  1096. dssdev->panel.timings.y_res * 3);
  1097. dsi_bus_lock();
  1098. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1099. * use short packets. plen 32 works, but bigger packets seem to cause
  1100. * an error. */
  1101. if (size % 2)
  1102. plen = 1;
  1103. else
  1104. plen = 2;
  1105. taal_set_update_window(x, y, w, h);
  1106. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  1107. if (r)
  1108. goto err2;
  1109. while (buf_used < size) {
  1110. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1111. first = 0;
  1112. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  1113. buf + buf_used, size - buf_used);
  1114. if (r < 0) {
  1115. dev_err(&dssdev->dev, "read error\n");
  1116. goto err3;
  1117. }
  1118. buf_used += r;
  1119. if (r < plen) {
  1120. dev_err(&dssdev->dev, "short read\n");
  1121. break;
  1122. }
  1123. if (signal_pending(current)) {
  1124. dev_err(&dssdev->dev, "signal pending, "
  1125. "aborting memory read\n");
  1126. r = -ERESTARTSYS;
  1127. goto err3;
  1128. }
  1129. }
  1130. r = buf_used;
  1131. err3:
  1132. dsi_vc_set_max_rx_packet_size(TCH, 1);
  1133. err2:
  1134. dsi_bus_unlock();
  1135. err1:
  1136. mutex_unlock(&td->lock);
  1137. return r;
  1138. }
  1139. static void taal_esd_work(struct work_struct *work)
  1140. {
  1141. struct taal_data *td = container_of(work, struct taal_data,
  1142. esd_work.work);
  1143. struct omap_dss_device *dssdev = td->dssdev;
  1144. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1145. u8 state1, state2;
  1146. int r;
  1147. mutex_lock(&td->lock);
  1148. if (!td->enabled) {
  1149. mutex_unlock(&td->lock);
  1150. return;
  1151. }
  1152. dsi_bus_lock();
  1153. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  1154. if (r) {
  1155. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1156. goto err;
  1157. }
  1158. /* Run self diagnostics */
  1159. r = taal_sleep_out(td);
  1160. if (r) {
  1161. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1162. goto err;
  1163. }
  1164. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  1165. if (r) {
  1166. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1167. goto err;
  1168. }
  1169. /* Each sleep out command will trigger a self diagnostic and flip
  1170. * Bit6 if the test passes.
  1171. */
  1172. if (!((state1 ^ state2) & (1 << 6))) {
  1173. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1174. goto err;
  1175. }
  1176. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1177. * to re-enable TE after self diagnostics */
  1178. if (td->te_enabled && panel_data->use_ext_te) {
  1179. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  1180. if (r)
  1181. goto err;
  1182. }
  1183. dsi_bus_unlock();
  1184. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1185. mutex_unlock(&td->lock);
  1186. return;
  1187. err:
  1188. dev_err(&dssdev->dev, "performing LCD reset\n");
  1189. taal_power_off(dssdev);
  1190. taal_hw_reset(dssdev);
  1191. taal_power_on(dssdev);
  1192. dsi_bus_unlock();
  1193. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1194. mutex_unlock(&td->lock);
  1195. }
  1196. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  1197. enum omap_dss_update_mode mode)
  1198. {
  1199. if (mode != OMAP_DSS_UPDATE_MANUAL)
  1200. return -EINVAL;
  1201. return 0;
  1202. }
  1203. static enum omap_dss_update_mode taal_get_update_mode(
  1204. struct omap_dss_device *dssdev)
  1205. {
  1206. return OMAP_DSS_UPDATE_MANUAL;
  1207. }
  1208. static struct omap_dss_driver taal_driver = {
  1209. .probe = taal_probe,
  1210. .remove = taal_remove,
  1211. .enable = taal_enable,
  1212. .disable = taal_disable,
  1213. .suspend = taal_suspend,
  1214. .resume = taal_resume,
  1215. .set_update_mode = taal_set_update_mode,
  1216. .get_update_mode = taal_get_update_mode,
  1217. .update = taal_update,
  1218. .sync = taal_sync,
  1219. .get_resolution = taal_get_resolution,
  1220. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1221. .enable_te = taal_enable_te,
  1222. .get_te = taal_get_te,
  1223. .set_rotate = taal_rotate,
  1224. .get_rotate = taal_get_rotate,
  1225. .set_mirror = taal_mirror,
  1226. .get_mirror = taal_get_mirror,
  1227. .run_test = taal_run_test,
  1228. .memory_read = taal_memory_read,
  1229. .get_timings = taal_get_timings,
  1230. .driver = {
  1231. .name = "taal",
  1232. .owner = THIS_MODULE,
  1233. },
  1234. };
  1235. static int __init taal_init(void)
  1236. {
  1237. omap_dss_register_driver(&taal_driver);
  1238. return 0;
  1239. }
  1240. static void __exit taal_exit(void)
  1241. {
  1242. omap_dss_unregister_driver(&taal_driver);
  1243. }
  1244. module_init(taal_init);
  1245. module_exit(taal_exit);
  1246. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1247. MODULE_DESCRIPTION("Taal Driver");
  1248. MODULE_LICENSE("GPL");