dss.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  4. *
  5. * Some code and ideas taken from drivers/video/omap/ driver
  6. * by Imre Deak.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #define DSS_SUBSYS_NAME "DSS"
  21. #include <linux/debugfs.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/io.h>
  26. #include <linux/export.h>
  27. #include <linux/err.h>
  28. #include <linux/delay.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/clk.h>
  31. #include <linux/pinctrl/consumer.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/gfp.h>
  35. #include <linux/sizes.h>
  36. #include <linux/mfd/syscon.h>
  37. #include <linux/regmap.h>
  38. #include <linux/of.h>
  39. #include <linux/of_device.h>
  40. #include <linux/of_graph.h>
  41. #include <linux/regulator/consumer.h>
  42. #include <linux/suspend.h>
  43. #include <linux/component.h>
  44. #include <linux/sys_soc.h>
  45. #include "omapdss.h"
  46. #include "dss.h"
  47. #define DSS_SZ_REGS SZ_512
  48. struct dss_reg {
  49. u16 idx;
  50. };
  51. #define DSS_REG(idx) ((const struct dss_reg) { idx })
  52. #define DSS_REVISION DSS_REG(0x0000)
  53. #define DSS_SYSCONFIG DSS_REG(0x0010)
  54. #define DSS_SYSSTATUS DSS_REG(0x0014)
  55. #define DSS_CONTROL DSS_REG(0x0040)
  56. #define DSS_SDI_CONTROL DSS_REG(0x0044)
  57. #define DSS_PLL_CONTROL DSS_REG(0x0048)
  58. #define DSS_SDI_STATUS DSS_REG(0x005C)
  59. #define REG_GET(idx, start, end) \
  60. FLD_GET(dss_read_reg(idx), start, end)
  61. #define REG_FLD_MOD(idx, val, start, end) \
  62. dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
  63. struct dss_ops {
  64. int (*dpi_select_source)(int port, enum omap_channel channel);
  65. int (*select_lcd_source)(enum omap_channel channel,
  66. enum dss_clk_source clk_src);
  67. };
  68. struct dss_features {
  69. enum dss_model model;
  70. u8 fck_div_max;
  71. unsigned int fck_freq_max;
  72. u8 dss_fck_multiplier;
  73. const char *parent_clk_name;
  74. const enum omap_display_type *ports;
  75. int num_ports;
  76. const enum omap_dss_output_id *outputs;
  77. const struct dss_ops *ops;
  78. struct dss_reg_field dispc_clk_switch;
  79. bool has_lcd_clk_src;
  80. };
  81. static struct {
  82. struct platform_device *pdev;
  83. void __iomem *base;
  84. struct regmap *syscon_pll_ctrl;
  85. u32 syscon_pll_ctrl_offset;
  86. struct clk *parent_clk;
  87. struct clk *dss_clk;
  88. unsigned long dss_clk_rate;
  89. unsigned long cache_req_pck;
  90. unsigned long cache_prate;
  91. struct dispc_clock_info cache_dispc_cinfo;
  92. enum dss_clk_source dsi_clk_source[MAX_NUM_DSI];
  93. enum dss_clk_source dispc_clk_source;
  94. enum dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS];
  95. bool ctx_valid;
  96. u32 ctx[DSS_SZ_REGS / sizeof(u32)];
  97. const struct dss_features *feat;
  98. struct dss_pll *video1_pll;
  99. struct dss_pll *video2_pll;
  100. } dss;
  101. static const char * const dss_generic_clk_source_names[] = {
  102. [DSS_CLK_SRC_FCK] = "FCK",
  103. [DSS_CLK_SRC_PLL1_1] = "PLL1:1",
  104. [DSS_CLK_SRC_PLL1_2] = "PLL1:2",
  105. [DSS_CLK_SRC_PLL1_3] = "PLL1:3",
  106. [DSS_CLK_SRC_PLL2_1] = "PLL2:1",
  107. [DSS_CLK_SRC_PLL2_2] = "PLL2:2",
  108. [DSS_CLK_SRC_PLL2_3] = "PLL2:3",
  109. [DSS_CLK_SRC_HDMI_PLL] = "HDMI PLL",
  110. };
  111. static inline void dss_write_reg(const struct dss_reg idx, u32 val)
  112. {
  113. __raw_writel(val, dss.base + idx.idx);
  114. }
  115. static inline u32 dss_read_reg(const struct dss_reg idx)
  116. {
  117. return __raw_readl(dss.base + idx.idx);
  118. }
  119. #define SR(reg) \
  120. dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
  121. #define RR(reg) \
  122. dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
  123. static void dss_save_context(void)
  124. {
  125. DSSDBG("dss_save_context\n");
  126. SR(CONTROL);
  127. if (dss.feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
  128. SR(SDI_CONTROL);
  129. SR(PLL_CONTROL);
  130. }
  131. dss.ctx_valid = true;
  132. DSSDBG("context saved\n");
  133. }
  134. static void dss_restore_context(void)
  135. {
  136. DSSDBG("dss_restore_context\n");
  137. if (!dss.ctx_valid)
  138. return;
  139. RR(CONTROL);
  140. if (dss.feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
  141. RR(SDI_CONTROL);
  142. RR(PLL_CONTROL);
  143. }
  144. DSSDBG("context restored\n");
  145. }
  146. #undef SR
  147. #undef RR
  148. void dss_ctrl_pll_enable(enum dss_pll_id pll_id, bool enable)
  149. {
  150. unsigned shift;
  151. unsigned val;
  152. if (!dss.syscon_pll_ctrl)
  153. return;
  154. val = !enable;
  155. switch (pll_id) {
  156. case DSS_PLL_VIDEO1:
  157. shift = 0;
  158. break;
  159. case DSS_PLL_VIDEO2:
  160. shift = 1;
  161. break;
  162. case DSS_PLL_HDMI:
  163. shift = 2;
  164. break;
  165. default:
  166. DSSERR("illegal DSS PLL ID %d\n", pll_id);
  167. return;
  168. }
  169. regmap_update_bits(dss.syscon_pll_ctrl, dss.syscon_pll_ctrl_offset,
  170. 1 << shift, val << shift);
  171. }
  172. static int dss_ctrl_pll_set_control_mux(enum dss_clk_source clk_src,
  173. enum omap_channel channel)
  174. {
  175. unsigned shift, val;
  176. if (!dss.syscon_pll_ctrl)
  177. return -EINVAL;
  178. switch (channel) {
  179. case OMAP_DSS_CHANNEL_LCD:
  180. shift = 3;
  181. switch (clk_src) {
  182. case DSS_CLK_SRC_PLL1_1:
  183. val = 0; break;
  184. case DSS_CLK_SRC_HDMI_PLL:
  185. val = 1; break;
  186. default:
  187. DSSERR("error in PLL mux config for LCD\n");
  188. return -EINVAL;
  189. }
  190. break;
  191. case OMAP_DSS_CHANNEL_LCD2:
  192. shift = 5;
  193. switch (clk_src) {
  194. case DSS_CLK_SRC_PLL1_3:
  195. val = 0; break;
  196. case DSS_CLK_SRC_PLL2_3:
  197. val = 1; break;
  198. case DSS_CLK_SRC_HDMI_PLL:
  199. val = 2; break;
  200. default:
  201. DSSERR("error in PLL mux config for LCD2\n");
  202. return -EINVAL;
  203. }
  204. break;
  205. case OMAP_DSS_CHANNEL_LCD3:
  206. shift = 7;
  207. switch (clk_src) {
  208. case DSS_CLK_SRC_PLL2_1:
  209. val = 0; break;
  210. case DSS_CLK_SRC_PLL1_3:
  211. val = 1; break;
  212. case DSS_CLK_SRC_HDMI_PLL:
  213. val = 2; break;
  214. default:
  215. DSSERR("error in PLL mux config for LCD3\n");
  216. return -EINVAL;
  217. }
  218. break;
  219. default:
  220. DSSERR("error in PLL mux config\n");
  221. return -EINVAL;
  222. }
  223. regmap_update_bits(dss.syscon_pll_ctrl, dss.syscon_pll_ctrl_offset,
  224. 0x3 << shift, val << shift);
  225. return 0;
  226. }
  227. void dss_sdi_init(int datapairs)
  228. {
  229. u32 l;
  230. BUG_ON(datapairs > 3 || datapairs < 1);
  231. l = dss_read_reg(DSS_SDI_CONTROL);
  232. l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */
  233. l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */
  234. l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */
  235. dss_write_reg(DSS_SDI_CONTROL, l);
  236. l = dss_read_reg(DSS_PLL_CONTROL);
  237. l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
  238. l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */
  239. l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */
  240. dss_write_reg(DSS_PLL_CONTROL, l);
  241. }
  242. int dss_sdi_enable(void)
  243. {
  244. unsigned long timeout;
  245. dispc_pck_free_enable(1);
  246. /* Reset SDI PLL */
  247. REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */
  248. udelay(1); /* wait 2x PCLK */
  249. /* Lock SDI PLL */
  250. REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */
  251. /* Waiting for PLL lock request to complete */
  252. timeout = jiffies + msecs_to_jiffies(500);
  253. while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) {
  254. if (time_after_eq(jiffies, timeout)) {
  255. DSSERR("PLL lock request timed out\n");
  256. goto err1;
  257. }
  258. }
  259. /* Clearing PLL_GO bit */
  260. REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28);
  261. /* Waiting for PLL to lock */
  262. timeout = jiffies + msecs_to_jiffies(500);
  263. while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) {
  264. if (time_after_eq(jiffies, timeout)) {
  265. DSSERR("PLL lock timed out\n");
  266. goto err1;
  267. }
  268. }
  269. dispc_lcd_enable_signal(1);
  270. /* Waiting for SDI reset to complete */
  271. timeout = jiffies + msecs_to_jiffies(500);
  272. while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) {
  273. if (time_after_eq(jiffies, timeout)) {
  274. DSSERR("SDI reset timed out\n");
  275. goto err2;
  276. }
  277. }
  278. return 0;
  279. err2:
  280. dispc_lcd_enable_signal(0);
  281. err1:
  282. /* Reset SDI PLL */
  283. REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
  284. dispc_pck_free_enable(0);
  285. return -ETIMEDOUT;
  286. }
  287. void dss_sdi_disable(void)
  288. {
  289. dispc_lcd_enable_signal(0);
  290. dispc_pck_free_enable(0);
  291. /* Reset SDI PLL */
  292. REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
  293. }
  294. const char *dss_get_clk_source_name(enum dss_clk_source clk_src)
  295. {
  296. return dss_generic_clk_source_names[clk_src];
  297. }
  298. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  299. static void dss_dump_clocks(struct seq_file *s)
  300. {
  301. const char *fclk_name;
  302. unsigned long fclk_rate;
  303. if (dss_runtime_get())
  304. return;
  305. seq_printf(s, "- DSS -\n");
  306. fclk_name = dss_get_clk_source_name(DSS_CLK_SRC_FCK);
  307. fclk_rate = clk_get_rate(dss.dss_clk);
  308. seq_printf(s, "%s = %lu\n",
  309. fclk_name,
  310. fclk_rate);
  311. dss_runtime_put();
  312. }
  313. #endif
  314. static void dss_dump_regs(struct seq_file *s)
  315. {
  316. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
  317. if (dss_runtime_get())
  318. return;
  319. DUMPREG(DSS_REVISION);
  320. DUMPREG(DSS_SYSCONFIG);
  321. DUMPREG(DSS_SYSSTATUS);
  322. DUMPREG(DSS_CONTROL);
  323. if (dss.feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
  324. DUMPREG(DSS_SDI_CONTROL);
  325. DUMPREG(DSS_PLL_CONTROL);
  326. DUMPREG(DSS_SDI_STATUS);
  327. }
  328. dss_runtime_put();
  329. #undef DUMPREG
  330. }
  331. static int dss_get_channel_index(enum omap_channel channel)
  332. {
  333. switch (channel) {
  334. case OMAP_DSS_CHANNEL_LCD:
  335. return 0;
  336. case OMAP_DSS_CHANNEL_LCD2:
  337. return 1;
  338. case OMAP_DSS_CHANNEL_LCD3:
  339. return 2;
  340. default:
  341. WARN_ON(1);
  342. return 0;
  343. }
  344. }
  345. static void dss_select_dispc_clk_source(enum dss_clk_source clk_src)
  346. {
  347. int b;
  348. /*
  349. * We always use PRCM clock as the DISPC func clock, except on DSS3,
  350. * where we don't have separate DISPC and LCD clock sources.
  351. */
  352. if (WARN_ON(dss.feat->has_lcd_clk_src && clk_src != DSS_CLK_SRC_FCK))
  353. return;
  354. switch (clk_src) {
  355. case DSS_CLK_SRC_FCK:
  356. b = 0;
  357. break;
  358. case DSS_CLK_SRC_PLL1_1:
  359. b = 1;
  360. break;
  361. case DSS_CLK_SRC_PLL2_1:
  362. b = 2;
  363. break;
  364. default:
  365. BUG();
  366. return;
  367. }
  368. REG_FLD_MOD(DSS_CONTROL, b, /* DISPC_CLK_SWITCH */
  369. dss.feat->dispc_clk_switch.start,
  370. dss.feat->dispc_clk_switch.end);
  371. dss.dispc_clk_source = clk_src;
  372. }
  373. void dss_select_dsi_clk_source(int dsi_module,
  374. enum dss_clk_source clk_src)
  375. {
  376. int b, pos;
  377. switch (clk_src) {
  378. case DSS_CLK_SRC_FCK:
  379. b = 0;
  380. break;
  381. case DSS_CLK_SRC_PLL1_2:
  382. BUG_ON(dsi_module != 0);
  383. b = 1;
  384. break;
  385. case DSS_CLK_SRC_PLL2_2:
  386. BUG_ON(dsi_module != 1);
  387. b = 1;
  388. break;
  389. default:
  390. BUG();
  391. return;
  392. }
  393. pos = dsi_module == 0 ? 1 : 10;
  394. REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */
  395. dss.dsi_clk_source[dsi_module] = clk_src;
  396. }
  397. static int dss_lcd_clk_mux_dra7(enum omap_channel channel,
  398. enum dss_clk_source clk_src)
  399. {
  400. const u8 ctrl_bits[] = {
  401. [OMAP_DSS_CHANNEL_LCD] = 0,
  402. [OMAP_DSS_CHANNEL_LCD2] = 12,
  403. [OMAP_DSS_CHANNEL_LCD3] = 19,
  404. };
  405. u8 ctrl_bit = ctrl_bits[channel];
  406. int r;
  407. if (clk_src == DSS_CLK_SRC_FCK) {
  408. /* LCDx_CLK_SWITCH */
  409. REG_FLD_MOD(DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
  410. return -EINVAL;
  411. }
  412. r = dss_ctrl_pll_set_control_mux(clk_src, channel);
  413. if (r)
  414. return r;
  415. REG_FLD_MOD(DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
  416. return 0;
  417. }
  418. static int dss_lcd_clk_mux_omap5(enum omap_channel channel,
  419. enum dss_clk_source clk_src)
  420. {
  421. const u8 ctrl_bits[] = {
  422. [OMAP_DSS_CHANNEL_LCD] = 0,
  423. [OMAP_DSS_CHANNEL_LCD2] = 12,
  424. [OMAP_DSS_CHANNEL_LCD3] = 19,
  425. };
  426. const enum dss_clk_source allowed_plls[] = {
  427. [OMAP_DSS_CHANNEL_LCD] = DSS_CLK_SRC_PLL1_1,
  428. [OMAP_DSS_CHANNEL_LCD2] = DSS_CLK_SRC_FCK,
  429. [OMAP_DSS_CHANNEL_LCD3] = DSS_CLK_SRC_PLL2_1,
  430. };
  431. u8 ctrl_bit = ctrl_bits[channel];
  432. if (clk_src == DSS_CLK_SRC_FCK) {
  433. /* LCDx_CLK_SWITCH */
  434. REG_FLD_MOD(DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
  435. return -EINVAL;
  436. }
  437. if (WARN_ON(allowed_plls[channel] != clk_src))
  438. return -EINVAL;
  439. REG_FLD_MOD(DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
  440. return 0;
  441. }
  442. static int dss_lcd_clk_mux_omap4(enum omap_channel channel,
  443. enum dss_clk_source clk_src)
  444. {
  445. const u8 ctrl_bits[] = {
  446. [OMAP_DSS_CHANNEL_LCD] = 0,
  447. [OMAP_DSS_CHANNEL_LCD2] = 12,
  448. };
  449. const enum dss_clk_source allowed_plls[] = {
  450. [OMAP_DSS_CHANNEL_LCD] = DSS_CLK_SRC_PLL1_1,
  451. [OMAP_DSS_CHANNEL_LCD2] = DSS_CLK_SRC_PLL2_1,
  452. };
  453. u8 ctrl_bit = ctrl_bits[channel];
  454. if (clk_src == DSS_CLK_SRC_FCK) {
  455. /* LCDx_CLK_SWITCH */
  456. REG_FLD_MOD(DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
  457. return 0;
  458. }
  459. if (WARN_ON(allowed_plls[channel] != clk_src))
  460. return -EINVAL;
  461. REG_FLD_MOD(DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
  462. return 0;
  463. }
  464. void dss_select_lcd_clk_source(enum omap_channel channel,
  465. enum dss_clk_source clk_src)
  466. {
  467. int idx = dss_get_channel_index(channel);
  468. int r;
  469. if (!dss.feat->has_lcd_clk_src) {
  470. dss_select_dispc_clk_source(clk_src);
  471. dss.lcd_clk_source[idx] = clk_src;
  472. return;
  473. }
  474. r = dss.feat->ops->select_lcd_source(channel, clk_src);
  475. if (r)
  476. return;
  477. dss.lcd_clk_source[idx] = clk_src;
  478. }
  479. enum dss_clk_source dss_get_dispc_clk_source(void)
  480. {
  481. return dss.dispc_clk_source;
  482. }
  483. enum dss_clk_source dss_get_dsi_clk_source(int dsi_module)
  484. {
  485. return dss.dsi_clk_source[dsi_module];
  486. }
  487. enum dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel)
  488. {
  489. if (dss.feat->has_lcd_clk_src) {
  490. int idx = dss_get_channel_index(channel);
  491. return dss.lcd_clk_source[idx];
  492. } else {
  493. /* LCD_CLK source is the same as DISPC_FCLK source for
  494. * OMAP2 and OMAP3 */
  495. return dss.dispc_clk_source;
  496. }
  497. }
  498. bool dss_div_calc(unsigned long pck, unsigned long fck_min,
  499. dss_div_calc_func func, void *data)
  500. {
  501. int fckd, fckd_start, fckd_stop;
  502. unsigned long fck;
  503. unsigned long fck_hw_max;
  504. unsigned long fckd_hw_max;
  505. unsigned long prate;
  506. unsigned m;
  507. fck_hw_max = dss.feat->fck_freq_max;
  508. if (dss.parent_clk == NULL) {
  509. unsigned pckd;
  510. pckd = fck_hw_max / pck;
  511. fck = pck * pckd;
  512. fck = clk_round_rate(dss.dss_clk, fck);
  513. return func(fck, data);
  514. }
  515. fckd_hw_max = dss.feat->fck_div_max;
  516. m = dss.feat->dss_fck_multiplier;
  517. prate = clk_get_rate(dss.parent_clk);
  518. fck_min = fck_min ? fck_min : 1;
  519. fckd_start = min(prate * m / fck_min, fckd_hw_max);
  520. fckd_stop = max(DIV_ROUND_UP(prate * m, fck_hw_max), 1ul);
  521. for (fckd = fckd_start; fckd >= fckd_stop; --fckd) {
  522. fck = DIV_ROUND_UP(prate, fckd) * m;
  523. if (func(fck, data))
  524. return true;
  525. }
  526. return false;
  527. }
  528. int dss_set_fck_rate(unsigned long rate)
  529. {
  530. int r;
  531. DSSDBG("set fck to %lu\n", rate);
  532. r = clk_set_rate(dss.dss_clk, rate);
  533. if (r)
  534. return r;
  535. dss.dss_clk_rate = clk_get_rate(dss.dss_clk);
  536. WARN_ONCE(dss.dss_clk_rate != rate,
  537. "clk rate mismatch: %lu != %lu", dss.dss_clk_rate,
  538. rate);
  539. return 0;
  540. }
  541. unsigned long dss_get_dispc_clk_rate(void)
  542. {
  543. return dss.dss_clk_rate;
  544. }
  545. unsigned long dss_get_max_fck_rate(void)
  546. {
  547. return dss.feat->fck_freq_max;
  548. }
  549. enum omap_dss_output_id dss_get_supported_outputs(enum omap_channel channel)
  550. {
  551. return dss.feat->outputs[channel];
  552. }
  553. static int dss_setup_default_clock(void)
  554. {
  555. unsigned long max_dss_fck, prate;
  556. unsigned long fck;
  557. unsigned fck_div;
  558. int r;
  559. max_dss_fck = dss.feat->fck_freq_max;
  560. if (dss.parent_clk == NULL) {
  561. fck = clk_round_rate(dss.dss_clk, max_dss_fck);
  562. } else {
  563. prate = clk_get_rate(dss.parent_clk);
  564. fck_div = DIV_ROUND_UP(prate * dss.feat->dss_fck_multiplier,
  565. max_dss_fck);
  566. fck = DIV_ROUND_UP(prate, fck_div) * dss.feat->dss_fck_multiplier;
  567. }
  568. r = dss_set_fck_rate(fck);
  569. if (r)
  570. return r;
  571. return 0;
  572. }
  573. void dss_set_venc_output(enum omap_dss_venc_type type)
  574. {
  575. int l = 0;
  576. if (type == OMAP_DSS_VENC_TYPE_COMPOSITE)
  577. l = 0;
  578. else if (type == OMAP_DSS_VENC_TYPE_SVIDEO)
  579. l = 1;
  580. else
  581. BUG();
  582. /* venc out selection. 0 = comp, 1 = svideo */
  583. REG_FLD_MOD(DSS_CONTROL, l, 6, 6);
  584. }
  585. void dss_set_dac_pwrdn_bgz(bool enable)
  586. {
  587. REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */
  588. }
  589. void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src)
  590. {
  591. enum omap_dss_output_id outputs;
  592. outputs = dss.feat->outputs[OMAP_DSS_CHANNEL_DIGIT];
  593. /* Complain about invalid selections */
  594. WARN_ON((src == DSS_VENC_TV_CLK) && !(outputs & OMAP_DSS_OUTPUT_VENC));
  595. WARN_ON((src == DSS_HDMI_M_PCLK) && !(outputs & OMAP_DSS_OUTPUT_HDMI));
  596. /* Select only if we have options */
  597. if ((outputs & OMAP_DSS_OUTPUT_VENC) &&
  598. (outputs & OMAP_DSS_OUTPUT_HDMI))
  599. REG_FLD_MOD(DSS_CONTROL, src, 15, 15); /* VENC_HDMI_SWITCH */
  600. }
  601. enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void)
  602. {
  603. enum omap_dss_output_id outputs;
  604. outputs = dss.feat->outputs[OMAP_DSS_CHANNEL_DIGIT];
  605. if ((outputs & OMAP_DSS_OUTPUT_HDMI) == 0)
  606. return DSS_VENC_TV_CLK;
  607. if ((outputs & OMAP_DSS_OUTPUT_VENC) == 0)
  608. return DSS_HDMI_M_PCLK;
  609. return REG_GET(DSS_CONTROL, 15, 15);
  610. }
  611. static int dss_dpi_select_source_omap2_omap3(int port, enum omap_channel channel)
  612. {
  613. if (channel != OMAP_DSS_CHANNEL_LCD)
  614. return -EINVAL;
  615. return 0;
  616. }
  617. static int dss_dpi_select_source_omap4(int port, enum omap_channel channel)
  618. {
  619. int val;
  620. switch (channel) {
  621. case OMAP_DSS_CHANNEL_LCD2:
  622. val = 0;
  623. break;
  624. case OMAP_DSS_CHANNEL_DIGIT:
  625. val = 1;
  626. break;
  627. default:
  628. return -EINVAL;
  629. }
  630. REG_FLD_MOD(DSS_CONTROL, val, 17, 17);
  631. return 0;
  632. }
  633. static int dss_dpi_select_source_omap5(int port, enum omap_channel channel)
  634. {
  635. int val;
  636. switch (channel) {
  637. case OMAP_DSS_CHANNEL_LCD:
  638. val = 1;
  639. break;
  640. case OMAP_DSS_CHANNEL_LCD2:
  641. val = 2;
  642. break;
  643. case OMAP_DSS_CHANNEL_LCD3:
  644. val = 3;
  645. break;
  646. case OMAP_DSS_CHANNEL_DIGIT:
  647. val = 0;
  648. break;
  649. default:
  650. return -EINVAL;
  651. }
  652. REG_FLD_MOD(DSS_CONTROL, val, 17, 16);
  653. return 0;
  654. }
  655. static int dss_dpi_select_source_dra7xx(int port, enum omap_channel channel)
  656. {
  657. switch (port) {
  658. case 0:
  659. return dss_dpi_select_source_omap5(port, channel);
  660. case 1:
  661. if (channel != OMAP_DSS_CHANNEL_LCD2)
  662. return -EINVAL;
  663. break;
  664. case 2:
  665. if (channel != OMAP_DSS_CHANNEL_LCD3)
  666. return -EINVAL;
  667. break;
  668. default:
  669. return -EINVAL;
  670. }
  671. return 0;
  672. }
  673. int dss_dpi_select_source(int port, enum omap_channel channel)
  674. {
  675. return dss.feat->ops->dpi_select_source(port, channel);
  676. }
  677. static int dss_get_clocks(void)
  678. {
  679. struct clk *clk;
  680. clk = devm_clk_get(&dss.pdev->dev, "fck");
  681. if (IS_ERR(clk)) {
  682. DSSERR("can't get clock fck\n");
  683. return PTR_ERR(clk);
  684. }
  685. dss.dss_clk = clk;
  686. if (dss.feat->parent_clk_name) {
  687. clk = clk_get(NULL, dss.feat->parent_clk_name);
  688. if (IS_ERR(clk)) {
  689. DSSERR("Failed to get %s\n", dss.feat->parent_clk_name);
  690. return PTR_ERR(clk);
  691. }
  692. } else {
  693. clk = NULL;
  694. }
  695. dss.parent_clk = clk;
  696. return 0;
  697. }
  698. static void dss_put_clocks(void)
  699. {
  700. if (dss.parent_clk)
  701. clk_put(dss.parent_clk);
  702. }
  703. int dss_runtime_get(void)
  704. {
  705. int r;
  706. DSSDBG("dss_runtime_get\n");
  707. r = pm_runtime_get_sync(&dss.pdev->dev);
  708. WARN_ON(r < 0);
  709. return r < 0 ? r : 0;
  710. }
  711. void dss_runtime_put(void)
  712. {
  713. int r;
  714. DSSDBG("dss_runtime_put\n");
  715. r = pm_runtime_put_sync(&dss.pdev->dev);
  716. WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY);
  717. }
  718. /* DEBUGFS */
  719. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  720. static void dss_debug_dump_clocks(struct seq_file *s)
  721. {
  722. dss_dump_clocks(s);
  723. dispc_dump_clocks(s);
  724. #ifdef CONFIG_OMAP2_DSS_DSI
  725. dsi_dump_clocks(s);
  726. #endif
  727. }
  728. static int dss_debug_show(struct seq_file *s, void *unused)
  729. {
  730. void (*func)(struct seq_file *) = s->private;
  731. func(s);
  732. return 0;
  733. }
  734. static int dss_debug_open(struct inode *inode, struct file *file)
  735. {
  736. return single_open(file, dss_debug_show, inode->i_private);
  737. }
  738. static const struct file_operations dss_debug_fops = {
  739. .open = dss_debug_open,
  740. .read = seq_read,
  741. .llseek = seq_lseek,
  742. .release = single_release,
  743. };
  744. static struct dentry *dss_debugfs_dir;
  745. static int dss_initialize_debugfs(void)
  746. {
  747. dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
  748. if (IS_ERR(dss_debugfs_dir)) {
  749. int err = PTR_ERR(dss_debugfs_dir);
  750. dss_debugfs_dir = NULL;
  751. return err;
  752. }
  753. debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
  754. &dss_debug_dump_clocks, &dss_debug_fops);
  755. return 0;
  756. }
  757. static void dss_uninitialize_debugfs(void)
  758. {
  759. if (dss_debugfs_dir)
  760. debugfs_remove_recursive(dss_debugfs_dir);
  761. }
  762. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  763. {
  764. struct dentry *d;
  765. d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
  766. write, &dss_debug_fops);
  767. return PTR_ERR_OR_ZERO(d);
  768. }
  769. #else /* CONFIG_OMAP2_DSS_DEBUGFS */
  770. static inline int dss_initialize_debugfs(void)
  771. {
  772. return 0;
  773. }
  774. static inline void dss_uninitialize_debugfs(void)
  775. {
  776. }
  777. #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
  778. static const struct dss_ops dss_ops_omap2_omap3 = {
  779. .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
  780. };
  781. static const struct dss_ops dss_ops_omap4 = {
  782. .dpi_select_source = &dss_dpi_select_source_omap4,
  783. .select_lcd_source = &dss_lcd_clk_mux_omap4,
  784. };
  785. static const struct dss_ops dss_ops_omap5 = {
  786. .dpi_select_source = &dss_dpi_select_source_omap5,
  787. .select_lcd_source = &dss_lcd_clk_mux_omap5,
  788. };
  789. static const struct dss_ops dss_ops_dra7 = {
  790. .dpi_select_source = &dss_dpi_select_source_dra7xx,
  791. .select_lcd_source = &dss_lcd_clk_mux_dra7,
  792. };
  793. static const enum omap_display_type omap2plus_ports[] = {
  794. OMAP_DISPLAY_TYPE_DPI,
  795. };
  796. static const enum omap_display_type omap34xx_ports[] = {
  797. OMAP_DISPLAY_TYPE_DPI,
  798. OMAP_DISPLAY_TYPE_SDI,
  799. };
  800. static const enum omap_display_type dra7xx_ports[] = {
  801. OMAP_DISPLAY_TYPE_DPI,
  802. OMAP_DISPLAY_TYPE_DPI,
  803. OMAP_DISPLAY_TYPE_DPI,
  804. };
  805. static const enum omap_dss_output_id omap2_dss_supported_outputs[] = {
  806. /* OMAP_DSS_CHANNEL_LCD */
  807. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI,
  808. /* OMAP_DSS_CHANNEL_DIGIT */
  809. OMAP_DSS_OUTPUT_VENC,
  810. };
  811. static const enum omap_dss_output_id omap3430_dss_supported_outputs[] = {
  812. /* OMAP_DSS_CHANNEL_LCD */
  813. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
  814. OMAP_DSS_OUTPUT_SDI | OMAP_DSS_OUTPUT_DSI1,
  815. /* OMAP_DSS_CHANNEL_DIGIT */
  816. OMAP_DSS_OUTPUT_VENC,
  817. };
  818. static const enum omap_dss_output_id omap3630_dss_supported_outputs[] = {
  819. /* OMAP_DSS_CHANNEL_LCD */
  820. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
  821. OMAP_DSS_OUTPUT_DSI1,
  822. /* OMAP_DSS_CHANNEL_DIGIT */
  823. OMAP_DSS_OUTPUT_VENC,
  824. };
  825. static const enum omap_dss_output_id am43xx_dss_supported_outputs[] = {
  826. /* OMAP_DSS_CHANNEL_LCD */
  827. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI,
  828. };
  829. static const enum omap_dss_output_id omap4_dss_supported_outputs[] = {
  830. /* OMAP_DSS_CHANNEL_LCD */
  831. OMAP_DSS_OUTPUT_DBI | OMAP_DSS_OUTPUT_DSI1,
  832. /* OMAP_DSS_CHANNEL_DIGIT */
  833. OMAP_DSS_OUTPUT_VENC | OMAP_DSS_OUTPUT_HDMI,
  834. /* OMAP_DSS_CHANNEL_LCD2 */
  835. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
  836. OMAP_DSS_OUTPUT_DSI2,
  837. };
  838. static const enum omap_dss_output_id omap5_dss_supported_outputs[] = {
  839. /* OMAP_DSS_CHANNEL_LCD */
  840. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
  841. OMAP_DSS_OUTPUT_DSI1 | OMAP_DSS_OUTPUT_DSI2,
  842. /* OMAP_DSS_CHANNEL_DIGIT */
  843. OMAP_DSS_OUTPUT_HDMI,
  844. /* OMAP_DSS_CHANNEL_LCD2 */
  845. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
  846. OMAP_DSS_OUTPUT_DSI1,
  847. /* OMAP_DSS_CHANNEL_LCD3 */
  848. OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
  849. OMAP_DSS_OUTPUT_DSI2,
  850. };
  851. static const struct dss_features omap24xx_dss_feats = {
  852. .model = DSS_MODEL_OMAP2,
  853. /*
  854. * fck div max is really 16, but the divider range has gaps. The range
  855. * from 1 to 6 has no gaps, so let's use that as a max.
  856. */
  857. .fck_div_max = 6,
  858. .fck_freq_max = 133000000,
  859. .dss_fck_multiplier = 2,
  860. .parent_clk_name = "core_ck",
  861. .ports = omap2plus_ports,
  862. .num_ports = ARRAY_SIZE(omap2plus_ports),
  863. .outputs = omap2_dss_supported_outputs,
  864. .ops = &dss_ops_omap2_omap3,
  865. .dispc_clk_switch = { 0, 0 },
  866. .has_lcd_clk_src = false,
  867. };
  868. static const struct dss_features omap34xx_dss_feats = {
  869. .model = DSS_MODEL_OMAP3,
  870. .fck_div_max = 16,
  871. .fck_freq_max = 173000000,
  872. .dss_fck_multiplier = 2,
  873. .parent_clk_name = "dpll4_ck",
  874. .ports = omap34xx_ports,
  875. .outputs = omap3430_dss_supported_outputs,
  876. .num_ports = ARRAY_SIZE(omap34xx_ports),
  877. .ops = &dss_ops_omap2_omap3,
  878. .dispc_clk_switch = { 0, 0 },
  879. .has_lcd_clk_src = false,
  880. };
  881. static const struct dss_features omap3630_dss_feats = {
  882. .model = DSS_MODEL_OMAP3,
  883. .fck_div_max = 32,
  884. .fck_freq_max = 173000000,
  885. .dss_fck_multiplier = 1,
  886. .parent_clk_name = "dpll4_ck",
  887. .ports = omap2plus_ports,
  888. .num_ports = ARRAY_SIZE(omap2plus_ports),
  889. .outputs = omap3630_dss_supported_outputs,
  890. .ops = &dss_ops_omap2_omap3,
  891. .dispc_clk_switch = { 0, 0 },
  892. .has_lcd_clk_src = false,
  893. };
  894. static const struct dss_features omap44xx_dss_feats = {
  895. .model = DSS_MODEL_OMAP4,
  896. .fck_div_max = 32,
  897. .fck_freq_max = 186000000,
  898. .dss_fck_multiplier = 1,
  899. .parent_clk_name = "dpll_per_x2_ck",
  900. .ports = omap2plus_ports,
  901. .num_ports = ARRAY_SIZE(omap2plus_ports),
  902. .outputs = omap4_dss_supported_outputs,
  903. .ops = &dss_ops_omap4,
  904. .dispc_clk_switch = { 9, 8 },
  905. .has_lcd_clk_src = true,
  906. };
  907. static const struct dss_features omap54xx_dss_feats = {
  908. .model = DSS_MODEL_OMAP5,
  909. .fck_div_max = 64,
  910. .fck_freq_max = 209250000,
  911. .dss_fck_multiplier = 1,
  912. .parent_clk_name = "dpll_per_x2_ck",
  913. .ports = omap2plus_ports,
  914. .num_ports = ARRAY_SIZE(omap2plus_ports),
  915. .outputs = omap5_dss_supported_outputs,
  916. .ops = &dss_ops_omap5,
  917. .dispc_clk_switch = { 9, 7 },
  918. .has_lcd_clk_src = true,
  919. };
  920. static const struct dss_features am43xx_dss_feats = {
  921. .model = DSS_MODEL_OMAP3,
  922. .fck_div_max = 0,
  923. .fck_freq_max = 200000000,
  924. .dss_fck_multiplier = 0,
  925. .parent_clk_name = NULL,
  926. .ports = omap2plus_ports,
  927. .num_ports = ARRAY_SIZE(omap2plus_ports),
  928. .outputs = am43xx_dss_supported_outputs,
  929. .ops = &dss_ops_omap2_omap3,
  930. .dispc_clk_switch = { 0, 0 },
  931. .has_lcd_clk_src = true,
  932. };
  933. static const struct dss_features dra7xx_dss_feats = {
  934. .model = DSS_MODEL_DRA7,
  935. .fck_div_max = 64,
  936. .fck_freq_max = 209250000,
  937. .dss_fck_multiplier = 1,
  938. .parent_clk_name = "dpll_per_x2_ck",
  939. .ports = dra7xx_ports,
  940. .num_ports = ARRAY_SIZE(dra7xx_ports),
  941. .outputs = omap5_dss_supported_outputs,
  942. .ops = &dss_ops_dra7,
  943. .dispc_clk_switch = { 9, 7 },
  944. .has_lcd_clk_src = true,
  945. };
  946. static int dss_init_ports(struct platform_device *pdev)
  947. {
  948. struct device_node *parent = pdev->dev.of_node;
  949. struct device_node *port;
  950. int i;
  951. for (i = 0; i < dss.feat->num_ports; i++) {
  952. port = of_graph_get_port_by_id(parent, i);
  953. if (!port)
  954. continue;
  955. switch (dss.feat->ports[i]) {
  956. case OMAP_DISPLAY_TYPE_DPI:
  957. dpi_init_port(pdev, port, dss.feat->model);
  958. break;
  959. case OMAP_DISPLAY_TYPE_SDI:
  960. sdi_init_port(pdev, port);
  961. break;
  962. default:
  963. break;
  964. }
  965. }
  966. return 0;
  967. }
  968. static void dss_uninit_ports(struct platform_device *pdev)
  969. {
  970. struct device_node *parent = pdev->dev.of_node;
  971. struct device_node *port;
  972. int i;
  973. for (i = 0; i < dss.feat->num_ports; i++) {
  974. port = of_graph_get_port_by_id(parent, i);
  975. if (!port)
  976. continue;
  977. switch (dss.feat->ports[i]) {
  978. case OMAP_DISPLAY_TYPE_DPI:
  979. dpi_uninit_port(port);
  980. break;
  981. case OMAP_DISPLAY_TYPE_SDI:
  982. sdi_uninit_port(port);
  983. break;
  984. default:
  985. break;
  986. }
  987. }
  988. }
  989. static int dss_video_pll_probe(struct platform_device *pdev)
  990. {
  991. struct device_node *np = pdev->dev.of_node;
  992. struct regulator *pll_regulator;
  993. int r;
  994. if (!np)
  995. return 0;
  996. if (of_property_read_bool(np, "syscon-pll-ctrl")) {
  997. dss.syscon_pll_ctrl = syscon_regmap_lookup_by_phandle(np,
  998. "syscon-pll-ctrl");
  999. if (IS_ERR(dss.syscon_pll_ctrl)) {
  1000. dev_err(&pdev->dev,
  1001. "failed to get syscon-pll-ctrl regmap\n");
  1002. return PTR_ERR(dss.syscon_pll_ctrl);
  1003. }
  1004. if (of_property_read_u32_index(np, "syscon-pll-ctrl", 1,
  1005. &dss.syscon_pll_ctrl_offset)) {
  1006. dev_err(&pdev->dev,
  1007. "failed to get syscon-pll-ctrl offset\n");
  1008. return -EINVAL;
  1009. }
  1010. }
  1011. pll_regulator = devm_regulator_get(&pdev->dev, "vdda_video");
  1012. if (IS_ERR(pll_regulator)) {
  1013. r = PTR_ERR(pll_regulator);
  1014. switch (r) {
  1015. case -ENOENT:
  1016. pll_regulator = NULL;
  1017. break;
  1018. case -EPROBE_DEFER:
  1019. return -EPROBE_DEFER;
  1020. default:
  1021. DSSERR("can't get DPLL VDDA regulator\n");
  1022. return r;
  1023. }
  1024. }
  1025. if (of_property_match_string(np, "reg-names", "pll1") >= 0) {
  1026. dss.video1_pll = dss_video_pll_init(pdev, 0, pll_regulator);
  1027. if (IS_ERR(dss.video1_pll))
  1028. return PTR_ERR(dss.video1_pll);
  1029. }
  1030. if (of_property_match_string(np, "reg-names", "pll2") >= 0) {
  1031. dss.video2_pll = dss_video_pll_init(pdev, 1, pll_regulator);
  1032. if (IS_ERR(dss.video2_pll)) {
  1033. dss_video_pll_uninit(dss.video1_pll);
  1034. return PTR_ERR(dss.video2_pll);
  1035. }
  1036. }
  1037. return 0;
  1038. }
  1039. /* DSS HW IP initialisation */
  1040. static const struct of_device_id dss_of_match[] = {
  1041. { .compatible = "ti,omap2-dss", .data = &omap24xx_dss_feats },
  1042. { .compatible = "ti,omap3-dss", .data = &omap3630_dss_feats },
  1043. { .compatible = "ti,omap4-dss", .data = &omap44xx_dss_feats },
  1044. { .compatible = "ti,omap5-dss", .data = &omap54xx_dss_feats },
  1045. { .compatible = "ti,dra7-dss", .data = &dra7xx_dss_feats },
  1046. {},
  1047. };
  1048. MODULE_DEVICE_TABLE(of, dss_of_match);
  1049. static const struct soc_device_attribute dss_soc_devices[] = {
  1050. { .machine = "OMAP3430/3530", .data = &omap34xx_dss_feats },
  1051. { .machine = "AM35??", .data = &omap34xx_dss_feats },
  1052. { .family = "AM43xx", .data = &am43xx_dss_feats },
  1053. { /* sentinel */ }
  1054. };
  1055. static int dss_bind(struct device *dev)
  1056. {
  1057. struct platform_device *pdev = to_platform_device(dev);
  1058. struct resource *dss_mem;
  1059. u32 rev;
  1060. int r;
  1061. dss_mem = platform_get_resource(dss.pdev, IORESOURCE_MEM, 0);
  1062. dss.base = devm_ioremap_resource(&pdev->dev, dss_mem);
  1063. if (IS_ERR(dss.base))
  1064. return PTR_ERR(dss.base);
  1065. r = dss_get_clocks();
  1066. if (r)
  1067. return r;
  1068. r = dss_setup_default_clock();
  1069. if (r)
  1070. goto err_setup_clocks;
  1071. r = dss_video_pll_probe(pdev);
  1072. if (r)
  1073. goto err_pll_init;
  1074. r = dss_init_ports(pdev);
  1075. if (r)
  1076. goto err_init_ports;
  1077. pm_runtime_enable(&pdev->dev);
  1078. r = dss_runtime_get();
  1079. if (r)
  1080. goto err_runtime_get;
  1081. dss.dss_clk_rate = clk_get_rate(dss.dss_clk);
  1082. /* Select DPLL */
  1083. REG_FLD_MOD(DSS_CONTROL, 0, 0, 0);
  1084. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  1085. #ifdef CONFIG_OMAP2_DSS_VENC
  1086. REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */
  1087. REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */
  1088. REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */
  1089. #endif
  1090. dss.dsi_clk_source[0] = DSS_CLK_SRC_FCK;
  1091. dss.dsi_clk_source[1] = DSS_CLK_SRC_FCK;
  1092. dss.dispc_clk_source = DSS_CLK_SRC_FCK;
  1093. dss.lcd_clk_source[0] = DSS_CLK_SRC_FCK;
  1094. dss.lcd_clk_source[1] = DSS_CLK_SRC_FCK;
  1095. rev = dss_read_reg(DSS_REVISION);
  1096. pr_info("OMAP DSS rev %d.%d\n", FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  1097. dss_runtime_put();
  1098. r = component_bind_all(&pdev->dev, NULL);
  1099. if (r)
  1100. goto err_component;
  1101. dss_debugfs_create_file("dss", dss_dump_regs);
  1102. pm_set_vt_switch(0);
  1103. omapdss_gather_components(dev);
  1104. omapdss_set_is_initialized(true);
  1105. return 0;
  1106. err_component:
  1107. err_runtime_get:
  1108. pm_runtime_disable(&pdev->dev);
  1109. dss_uninit_ports(pdev);
  1110. err_init_ports:
  1111. if (dss.video1_pll)
  1112. dss_video_pll_uninit(dss.video1_pll);
  1113. if (dss.video2_pll)
  1114. dss_video_pll_uninit(dss.video2_pll);
  1115. err_pll_init:
  1116. err_setup_clocks:
  1117. dss_put_clocks();
  1118. return r;
  1119. }
  1120. static void dss_unbind(struct device *dev)
  1121. {
  1122. struct platform_device *pdev = to_platform_device(dev);
  1123. omapdss_set_is_initialized(false);
  1124. component_unbind_all(&pdev->dev, NULL);
  1125. if (dss.video1_pll)
  1126. dss_video_pll_uninit(dss.video1_pll);
  1127. if (dss.video2_pll)
  1128. dss_video_pll_uninit(dss.video2_pll);
  1129. dss_uninit_ports(pdev);
  1130. pm_runtime_disable(&pdev->dev);
  1131. dss_put_clocks();
  1132. }
  1133. static const struct component_master_ops dss_component_ops = {
  1134. .bind = dss_bind,
  1135. .unbind = dss_unbind,
  1136. };
  1137. static int dss_component_compare(struct device *dev, void *data)
  1138. {
  1139. struct device *child = data;
  1140. return dev == child;
  1141. }
  1142. static int dss_add_child_component(struct device *dev, void *data)
  1143. {
  1144. struct component_match **match = data;
  1145. /*
  1146. * HACK
  1147. * We don't have a working driver for rfbi, so skip it here always.
  1148. * Otherwise dss will never get probed successfully, as it will wait
  1149. * for rfbi to get probed.
  1150. */
  1151. if (strstr(dev_name(dev), "rfbi"))
  1152. return 0;
  1153. component_match_add(dev->parent, match, dss_component_compare, dev);
  1154. return 0;
  1155. }
  1156. static int dss_probe(struct platform_device *pdev)
  1157. {
  1158. const struct soc_device_attribute *soc;
  1159. struct component_match *match = NULL;
  1160. int r;
  1161. dss.pdev = pdev;
  1162. r = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  1163. if (r) {
  1164. dev_err(&pdev->dev, "Failed to set the DMA mask\n");
  1165. return r;
  1166. }
  1167. /*
  1168. * The various OMAP3-based SoCs can't be told apart using the compatible
  1169. * string, use SoC device matching.
  1170. */
  1171. soc = soc_device_match(dss_soc_devices);
  1172. if (soc)
  1173. dss.feat = soc->data;
  1174. else
  1175. dss.feat = of_match_device(dss_of_match, &pdev->dev)->data;
  1176. r = dss_initialize_debugfs();
  1177. if (r)
  1178. return r;
  1179. /* add all the child devices as components */
  1180. device_for_each_child(&pdev->dev, &match, dss_add_child_component);
  1181. r = component_master_add_with_match(&pdev->dev, &dss_component_ops, match);
  1182. if (r) {
  1183. dss_uninitialize_debugfs();
  1184. return r;
  1185. }
  1186. return 0;
  1187. }
  1188. static int dss_remove(struct platform_device *pdev)
  1189. {
  1190. component_master_del(&pdev->dev, &dss_component_ops);
  1191. dss_uninitialize_debugfs();
  1192. return 0;
  1193. }
  1194. static void dss_shutdown(struct platform_device *pdev)
  1195. {
  1196. struct omap_dss_device *dssdev = NULL;
  1197. DSSDBG("shutdown\n");
  1198. for_each_dss_dev(dssdev) {
  1199. if (!dssdev->driver)
  1200. continue;
  1201. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  1202. dssdev->driver->disable(dssdev);
  1203. }
  1204. }
  1205. static int dss_runtime_suspend(struct device *dev)
  1206. {
  1207. dss_save_context();
  1208. dss_set_min_bus_tput(dev, 0);
  1209. pinctrl_pm_select_sleep_state(dev);
  1210. return 0;
  1211. }
  1212. static int dss_runtime_resume(struct device *dev)
  1213. {
  1214. int r;
  1215. pinctrl_pm_select_default_state(dev);
  1216. /*
  1217. * Set an arbitrarily high tput request to ensure OPP100.
  1218. * What we should really do is to make a request to stay in OPP100,
  1219. * without any tput requirements, but that is not currently possible
  1220. * via the PM layer.
  1221. */
  1222. r = dss_set_min_bus_tput(dev, 1000000000);
  1223. if (r)
  1224. return r;
  1225. dss_restore_context();
  1226. return 0;
  1227. }
  1228. static const struct dev_pm_ops dss_pm_ops = {
  1229. .runtime_suspend = dss_runtime_suspend,
  1230. .runtime_resume = dss_runtime_resume,
  1231. };
  1232. struct platform_driver omap_dsshw_driver = {
  1233. .probe = dss_probe,
  1234. .remove = dss_remove,
  1235. .shutdown = dss_shutdown,
  1236. .driver = {
  1237. .name = "omapdss_dss",
  1238. .pm = &dss_pm_ops,
  1239. .of_match_table = dss_of_match,
  1240. .suppress_bind_attrs = true,
  1241. },
  1242. };