tdmb_ebi.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. *
  3. * drivers/media/tdmb/tdmb_ebi.c
  4. *
  5. * tdmb driver
  6. *
  7. * Copyright (C) (2011, Samsung Electronics)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/io.h>
  20. #include <linux/of_gpio.h>
  21. #include <linux/clk.h>
  22. #include <linux/slab.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <plat/gpio-cfg.h>
  26. #include <plat/regs-srom.h>
  27. #include <mach/gpio.h>
  28. #include "tdmb.h"
  29. static struct tdmb_ebi_dt_data *ebi_dt_pdata;
  30. static void __iomem *v_addr_ebi_cs_base;
  31. /* SROMC bank attributes in BW (Bus width and Wait control) register */
  32. enum sromc_bank_attr {
  33. SROMC_DATA_16 = 0x1, /* 16-bit data bus */
  34. SROMC_BYTE_ADDR = 0x2, /* Byte base address */
  35. SROMC_WAIT_EN = 0x4, /* Wait enabled */
  36. SROMC_BYTE_EN = 0x8, /* Byte access enabled */
  37. SROMC_ATTR_MASK = 0xF
  38. };
  39. /* SROMC bank configuration */
  40. struct sromc_bank_cfg {
  41. unsigned csn; /* CSn # */
  42. unsigned attr; /* SROMC bank attributes */
  43. unsigned size; /* Size of a memory */
  44. unsigned addr; /* Start address (physical) */
  45. };
  46. /* SROMC bank access timing configuration */
  47. struct sromc_timing_cfg {
  48. u32 tacs; /* Address set-up before CSn */
  49. u32 tcos; /* Chip selection set-up before OEn */
  50. u32 tacc; /* Access cycle */
  51. u32 tcoh; /* Chip selection hold on OEn */
  52. u32 tcah; /* Address holding time after CSn */
  53. u32 tacp; /* Page mode access cycle at Page mode */
  54. u32 pmc; /* Page Mode config */
  55. };
  56. /**
  57. * sromc_enable
  58. *
  59. * Enables SROM controller (SROMC) block
  60. *
  61. */
  62. static int sromc_enable(struct platform_device *pdev)
  63. {
  64. struct device *dev = &pdev->dev;
  65. struct clk *clk;
  66. clk = devm_clk_get(dev, "sromc_clk");
  67. if (IS_ERR(clk)) {
  68. DPRINTK("Failed to get tdmb_sromc clock\n");
  69. return -1;
  70. }
  71. if (clk_prepare_enable(clk)) {
  72. DPRINTK("%s: clk_prepare_enable failed\n", __func__);
  73. return -1;
  74. }
  75. return 0;
  76. }
  77. /**
  78. * sromc_config_demux_gpio
  79. *
  80. * Configures GPIO pins for REn, WEn, LBn, UBn, address bus, and data bus
  81. * as demux mode
  82. *
  83. * Returns 0 if there is no error
  84. *
  85. */
  86. static int sromc_config_demux_gpio(struct platform_device *pdev)
  87. {
  88. struct device *dev = &pdev->dev;
  89. struct pinctrl *pinctrl;
  90. pinctrl = devm_pinctrl_get_select_default(dev);
  91. if (IS_ERR(pinctrl))
  92. DPRINTK("%s: Failed to configure pinctrl\n", __func__);
  93. return 0;
  94. }
  95. /**
  96. * sromc_config_access_attr
  97. * @csn: CSn number
  98. * @attr: SROMC attribute for this CSn
  99. *
  100. * Configures SROMC attribute for a CSn
  101. *
  102. */
  103. static void sromc_config_access_attr(unsigned int csn, unsigned int attr)
  104. {
  105. unsigned int bw = 0; /* Bus width and Wait control */
  106. DPRINTK("%s: for CSn%d\n", __func__, csn);
  107. bw = __raw_readl(S5P_SROM_BW);
  108. DPRINTK("%s: old BW setting = 0x%08X\n", __func__, bw);
  109. /* Configure BW control field for the CSn */
  110. bw &= ~(SROMC_ATTR_MASK << (csn << 2));
  111. bw |= (attr << (csn << 2));
  112. writel(bw, S5P_SROM_BW);
  113. /* Verify SROMC settings */
  114. bw = __raw_readl(S5P_SROM_BW);
  115. DPRINTK("%s: new BW setting = 0x%08X\n", __func__, bw);
  116. }
  117. /**
  118. * sromc_config_access_timing
  119. * @csn: CSn number
  120. * @tm_cfg: pointer to an sromc_timing_cfg
  121. *
  122. * Configures SROMC access timing register
  123. *
  124. */
  125. static void sromc_config_access_timing(unsigned int csn,
  126. struct sromc_timing_cfg *tm_cfg)
  127. {
  128. void __iomem *bank_sfr = S5P_SROM_BC0 + (4 * csn);
  129. unsigned int bc = 0; /* Bank Control */
  130. bc = __raw_readl(bank_sfr);
  131. DPRINTK("%s: old BC%d setting = 0x%08X\n", __func__, csn, bc);
  132. /* Configure memory access timing for the CSn */
  133. bc = tm_cfg->tacs | tm_cfg->tcos | tm_cfg->tacc |
  134. tm_cfg->tcoh | tm_cfg->tcah | tm_cfg->tacp | tm_cfg->pmc;
  135. writel(bc, bank_sfr);
  136. /* Verify SROMC settings */
  137. bc = __raw_readl(bank_sfr);
  138. DPRINTK("%s: new BC%d setting = 0x%08X\n", __func__, csn, bc);
  139. }
  140. static struct sromc_bank_cfg tdmb_sromc_bank_cfg = {
  141. .csn = 0,
  142. .attr = 0,
  143. };
  144. static struct sromc_timing_cfg tdmb_sromc_timing_cfg = {
  145. .tacs = 0x0F << 28,
  146. .tcos = 0x02 << 24,
  147. .tacc = 0x1F << 16,
  148. .tcoh = 0x02 << 12,
  149. .tcah = 0x0F << 8,
  150. .tacp = 0x00 << 4,
  151. .pmc = 0x00 << 0,
  152. };
  153. unsigned long tdmb_get_if_handle(void)
  154. {
  155. return (unsigned long)v_addr_ebi_cs_base;
  156. }
  157. EXPORT_SYMBOL_GPL(tdmb_get_if_handle);
  158. static int tdmb_ebi_init(struct platform_device *pdev)
  159. {
  160. struct sromc_bank_cfg *bnk_cfg;
  161. struct sromc_timing_cfg *tm_cfg;
  162. if (sromc_enable(pdev) < 0) {
  163. printk(KERN_DEBUG "tdmb_dev_init sromc_enable fail\n");
  164. return -1;
  165. }
  166. if (sromc_config_demux_gpio(pdev) < 0) {
  167. printk(KERN_DEBUG "tdmb_dev_init sromc_config_demux_gpio fail\n");
  168. return -1;
  169. }
  170. bnk_cfg = &tdmb_sromc_bank_cfg;
  171. sromc_config_access_attr(bnk_cfg->csn, bnk_cfg->attr);
  172. tm_cfg = &tdmb_sromc_timing_cfg;
  173. sromc_config_access_timing(bnk_cfg->csn, tm_cfg);
  174. return 0;
  175. }
  176. static struct tdmb_ebi_dt_data *get_ebi_dt_pdata(struct device *dev)
  177. {
  178. struct tdmb_ebi_dt_data *pdata;
  179. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  180. if (!pdata) {
  181. DPRINTK("%s : could not allocate memory for platform data\n", __func__);
  182. return NULL;
  183. }
  184. if (!of_property_read_u32(dev->of_node, "srom_cs_base", &pdata->cs_base))
  185. DPRINTK("%s - srom_cs_base : 0x%x\n", __func__, pdata->cs_base);
  186. else {
  187. DPRINTK("%s - cs_base missing\n", __func__);
  188. goto fail;
  189. }
  190. if (!of_property_read_u32(dev->of_node, "srom_mem_size", &pdata->mem_size))
  191. DPRINTK("%s - srom_mem_size : 0x%x\n", __func__, pdata->mem_size);
  192. else {
  193. DPRINTK("%s - mem_size missing\n", __func__);
  194. goto fail;
  195. }
  196. return pdata;
  197. fail:
  198. devm_kfree(dev, pdata);
  199. return NULL;
  200. }
  201. static int tdmb_sromc_remove(struct platform_device *pdev)
  202. {
  203. DPRINTK("tdmb_sromc_remove!\n");
  204. return 0;
  205. }
  206. static int tdmb_sromc_probe(struct platform_device *pdev)
  207. {
  208. if (pdev->dev.of_node) {
  209. ebi_dt_pdata = get_ebi_dt_pdata(&pdev->dev);
  210. if (!ebi_dt_pdata) {
  211. DPRINTK("%s : ebi_dt_pdata is NULL\n", __func__);
  212. return -1;
  213. }
  214. }
  215. if (tdmb_ebi_init(pdev) < 0) {
  216. DPRINTK("%s : tdmb_ebi_init error\n", __func__);
  217. return -1;
  218. }
  219. v_addr_ebi_cs_base = ioremap(ebi_dt_pdata->cs_base, ebi_dt_pdata->mem_size);
  220. DPRINTK("%s : v_addr_ebi_cs_base 0x%p\n", __func__, v_addr_ebi_cs_base);
  221. return 0;
  222. }
  223. static const struct of_device_id sromc_match_table[] = {
  224. {.compatible = "samsung,sromc"},
  225. {}
  226. };
  227. static struct platform_driver tdmb_ebi_driver = {
  228. .driver = {
  229. .name = "sromc",
  230. .owner = THIS_MODULE,
  231. .of_match_table = of_match_ptr(sromc_match_table),
  232. },
  233. .remove = tdmb_sromc_remove,
  234. };
  235. int __init tdmb_sromc_init(void)
  236. {
  237. return platform_driver_probe(&tdmb_ebi_driver, tdmb_sromc_probe);
  238. }
  239. module_init(tdmb_sromc_init);
  240. static void __exit tdmb_sromc_exit(void)
  241. {
  242. platform_driver_unregister(&tdmb_ebi_driver);
  243. }
  244. module_exit(tdmb_sromc_exit);
  245. MODULE_AUTHOR("Samsung");
  246. MODULE_DESCRIPTION("SROMC Driver");
  247. MODULE_LICENSE("GPL v2");