panel-taal.c 33 KB

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