mipi.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /*
  2. * Copyright (C) 2013 NVIDIA Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #include <linux/clk.h>
  23. #include <linux/delay.h>
  24. #include <linux/host1x.h>
  25. #include <linux/io.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/slab.h>
  29. #include "dev.h"
  30. #define MIPI_CAL_CTRL 0x00
  31. #define MIPI_CAL_CTRL_NOISE_FILTER(x) (((x) & 0xf) << 26)
  32. #define MIPI_CAL_CTRL_PRESCALE(x) (((x) & 0x3) << 24)
  33. #define MIPI_CAL_CTRL_CLKEN_OVR (1 << 4)
  34. #define MIPI_CAL_CTRL_START (1 << 0)
  35. #define MIPI_CAL_AUTOCAL_CTRL 0x01
  36. #define MIPI_CAL_STATUS 0x02
  37. #define MIPI_CAL_STATUS_DONE (1 << 16)
  38. #define MIPI_CAL_STATUS_ACTIVE (1 << 0)
  39. #define MIPI_CAL_CONFIG_CSIA 0x05
  40. #define MIPI_CAL_CONFIG_CSIB 0x06
  41. #define MIPI_CAL_CONFIG_CSIC 0x07
  42. #define MIPI_CAL_CONFIG_CSID 0x08
  43. #define MIPI_CAL_CONFIG_CSIE 0x09
  44. #define MIPI_CAL_CONFIG_CSIF 0x0a
  45. #define MIPI_CAL_CONFIG_DSIA 0x0e
  46. #define MIPI_CAL_CONFIG_DSIB 0x0f
  47. #define MIPI_CAL_CONFIG_DSIC 0x10
  48. #define MIPI_CAL_CONFIG_DSID 0x11
  49. #define MIPI_CAL_CONFIG_DSIA_CLK 0x19
  50. #define MIPI_CAL_CONFIG_DSIB_CLK 0x1a
  51. #define MIPI_CAL_CONFIG_CSIAB_CLK 0x1b
  52. #define MIPI_CAL_CONFIG_DSIC_CLK 0x1c
  53. #define MIPI_CAL_CONFIG_CSICD_CLK 0x1c
  54. #define MIPI_CAL_CONFIG_DSID_CLK 0x1d
  55. #define MIPI_CAL_CONFIG_CSIE_CLK 0x1d
  56. /* for data and clock lanes */
  57. #define MIPI_CAL_CONFIG_SELECT (1 << 21)
  58. /* for data lanes */
  59. #define MIPI_CAL_CONFIG_HSPDOS(x) (((x) & 0x1f) << 16)
  60. #define MIPI_CAL_CONFIG_HSPUOS(x) (((x) & 0x1f) << 8)
  61. #define MIPI_CAL_CONFIG_TERMOS(x) (((x) & 0x1f) << 0)
  62. /* for clock lanes */
  63. #define MIPI_CAL_CONFIG_HSCLKPDOSD(x) (((x) & 0x1f) << 8)
  64. #define MIPI_CAL_CONFIG_HSCLKPUOSD(x) (((x) & 0x1f) << 0)
  65. #define MIPI_CAL_BIAS_PAD_CFG0 0x16
  66. #define MIPI_CAL_BIAS_PAD_PDVCLAMP (1 << 1)
  67. #define MIPI_CAL_BIAS_PAD_E_VCLAMP_REF (1 << 0)
  68. #define MIPI_CAL_BIAS_PAD_CFG1 0x17
  69. #define MIPI_CAL_BIAS_PAD_DRV_DN_REF(x) (((x) & 0x7) << 16)
  70. #define MIPI_CAL_BIAS_PAD_DRV_UP_REF(x) (((x) & 0x7) << 8)
  71. #define MIPI_CAL_BIAS_PAD_CFG2 0x18
  72. #define MIPI_CAL_BIAS_PAD_VCLAMP(x) (((x) & 0x7) << 16)
  73. #define MIPI_CAL_BIAS_PAD_VAUXP(x) (((x) & 0x7) << 4)
  74. #define MIPI_CAL_BIAS_PAD_PDVREG (1 << 1)
  75. struct tegra_mipi_pad {
  76. unsigned long data;
  77. unsigned long clk;
  78. };
  79. struct tegra_mipi_soc {
  80. bool has_clk_lane;
  81. const struct tegra_mipi_pad *pads;
  82. unsigned int num_pads;
  83. bool clock_enable_override;
  84. bool needs_vclamp_ref;
  85. /* bias pad configuration settings */
  86. u8 pad_drive_down_ref;
  87. u8 pad_drive_up_ref;
  88. u8 pad_vclamp_level;
  89. u8 pad_vauxp_level;
  90. /* calibration settings for data lanes */
  91. u8 hspdos;
  92. u8 hspuos;
  93. u8 termos;
  94. /* calibration settings for clock lanes */
  95. u8 hsclkpdos;
  96. u8 hsclkpuos;
  97. };
  98. struct tegra_mipi {
  99. const struct tegra_mipi_soc *soc;
  100. struct device *dev;
  101. void __iomem *regs;
  102. struct mutex lock;
  103. struct clk *clk;
  104. unsigned long usage_count;
  105. };
  106. struct tegra_mipi_device {
  107. struct platform_device *pdev;
  108. struct tegra_mipi *mipi;
  109. struct device *device;
  110. unsigned long pads;
  111. };
  112. static inline u32 tegra_mipi_readl(struct tegra_mipi *mipi,
  113. unsigned long offset)
  114. {
  115. return readl(mipi->regs + (offset << 2));
  116. }
  117. static inline void tegra_mipi_writel(struct tegra_mipi *mipi, u32 value,
  118. unsigned long offset)
  119. {
  120. writel(value, mipi->regs + (offset << 2));
  121. }
  122. static int tegra_mipi_power_up(struct tegra_mipi *mipi)
  123. {
  124. u32 value;
  125. int err;
  126. err = clk_enable(mipi->clk);
  127. if (err < 0)
  128. return err;
  129. value = tegra_mipi_readl(mipi, MIPI_CAL_BIAS_PAD_CFG0);
  130. value &= ~MIPI_CAL_BIAS_PAD_PDVCLAMP;
  131. if (mipi->soc->needs_vclamp_ref)
  132. value |= MIPI_CAL_BIAS_PAD_E_VCLAMP_REF;
  133. tegra_mipi_writel(mipi, value, MIPI_CAL_BIAS_PAD_CFG0);
  134. value = tegra_mipi_readl(mipi, MIPI_CAL_BIAS_PAD_CFG2);
  135. value &= ~MIPI_CAL_BIAS_PAD_PDVREG;
  136. tegra_mipi_writel(mipi, value, MIPI_CAL_BIAS_PAD_CFG2);
  137. clk_disable(mipi->clk);
  138. return 0;
  139. }
  140. static int tegra_mipi_power_down(struct tegra_mipi *mipi)
  141. {
  142. u32 value;
  143. int err;
  144. err = clk_enable(mipi->clk);
  145. if (err < 0)
  146. return err;
  147. /*
  148. * The MIPI_CAL_BIAS_PAD_PDVREG controls a voltage regulator that
  149. * supplies the DSI pads. This must be kept enabled until none of the
  150. * DSI lanes are used anymore.
  151. */
  152. value = tegra_mipi_readl(mipi, MIPI_CAL_BIAS_PAD_CFG2);
  153. value |= MIPI_CAL_BIAS_PAD_PDVREG;
  154. tegra_mipi_writel(mipi, value, MIPI_CAL_BIAS_PAD_CFG2);
  155. /*
  156. * MIPI_CAL_BIAS_PAD_PDVCLAMP and MIPI_CAL_BIAS_PAD_E_VCLAMP_REF
  157. * control a regulator that supplies current to the pre-driver logic.
  158. * Powering down this regulator causes DSI to fail, so it must remain
  159. * powered on until none of the DSI lanes are used anymore.
  160. */
  161. value = tegra_mipi_readl(mipi, MIPI_CAL_BIAS_PAD_CFG0);
  162. if (mipi->soc->needs_vclamp_ref)
  163. value &= ~MIPI_CAL_BIAS_PAD_E_VCLAMP_REF;
  164. value |= MIPI_CAL_BIAS_PAD_PDVCLAMP;
  165. tegra_mipi_writel(mipi, value, MIPI_CAL_BIAS_PAD_CFG0);
  166. return 0;
  167. }
  168. struct tegra_mipi_device *tegra_mipi_request(struct device *device)
  169. {
  170. struct device_node *np = device->of_node;
  171. struct tegra_mipi_device *dev;
  172. struct of_phandle_args args;
  173. int err;
  174. err = of_parse_phandle_with_args(np, "nvidia,mipi-calibrate",
  175. "#nvidia,mipi-calibrate-cells", 0,
  176. &args);
  177. if (err < 0)
  178. return ERR_PTR(err);
  179. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  180. if (!dev) {
  181. err = -ENOMEM;
  182. goto out;
  183. }
  184. dev->pdev = of_find_device_by_node(args.np);
  185. if (!dev->pdev) {
  186. err = -ENODEV;
  187. goto free;
  188. }
  189. dev->mipi = platform_get_drvdata(dev->pdev);
  190. if (!dev->mipi) {
  191. err = -EPROBE_DEFER;
  192. goto put;
  193. }
  194. of_node_put(args.np);
  195. dev->pads = args.args[0];
  196. dev->device = device;
  197. mutex_lock(&dev->mipi->lock);
  198. if (dev->mipi->usage_count++ == 0) {
  199. err = tegra_mipi_power_up(dev->mipi);
  200. if (err < 0) {
  201. dev_err(dev->mipi->dev,
  202. "failed to power up MIPI bricks: %d\n",
  203. err);
  204. return ERR_PTR(err);
  205. }
  206. }
  207. mutex_unlock(&dev->mipi->lock);
  208. return dev;
  209. put:
  210. platform_device_put(dev->pdev);
  211. free:
  212. kfree(dev);
  213. out:
  214. of_node_put(args.np);
  215. return ERR_PTR(err);
  216. }
  217. EXPORT_SYMBOL(tegra_mipi_request);
  218. void tegra_mipi_free(struct tegra_mipi_device *device)
  219. {
  220. int err;
  221. mutex_lock(&device->mipi->lock);
  222. if (--device->mipi->usage_count == 0) {
  223. err = tegra_mipi_power_down(device->mipi);
  224. if (err < 0) {
  225. /*
  226. * Not much that can be done here, so an error message
  227. * will have to do.
  228. */
  229. dev_err(device->mipi->dev,
  230. "failed to power down MIPI bricks: %d\n",
  231. err);
  232. }
  233. }
  234. mutex_unlock(&device->mipi->lock);
  235. platform_device_put(device->pdev);
  236. kfree(device);
  237. }
  238. EXPORT_SYMBOL(tegra_mipi_free);
  239. static int tegra_mipi_wait(struct tegra_mipi *mipi)
  240. {
  241. unsigned long timeout = jiffies + msecs_to_jiffies(250);
  242. u32 value;
  243. while (time_before(jiffies, timeout)) {
  244. value = tegra_mipi_readl(mipi, MIPI_CAL_STATUS);
  245. if ((value & MIPI_CAL_STATUS_ACTIVE) == 0 &&
  246. (value & MIPI_CAL_STATUS_DONE) != 0)
  247. return 0;
  248. usleep_range(10, 50);
  249. }
  250. return -ETIMEDOUT;
  251. }
  252. int tegra_mipi_calibrate(struct tegra_mipi_device *device)
  253. {
  254. const struct tegra_mipi_soc *soc = device->mipi->soc;
  255. unsigned int i;
  256. u32 value;
  257. int err;
  258. err = clk_enable(device->mipi->clk);
  259. if (err < 0)
  260. return err;
  261. mutex_lock(&device->mipi->lock);
  262. value = MIPI_CAL_BIAS_PAD_DRV_DN_REF(soc->pad_drive_down_ref) |
  263. MIPI_CAL_BIAS_PAD_DRV_UP_REF(soc->pad_drive_up_ref);
  264. tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG1);
  265. value = tegra_mipi_readl(device->mipi, MIPI_CAL_BIAS_PAD_CFG2);
  266. value &= ~MIPI_CAL_BIAS_PAD_VCLAMP(0x7);
  267. value &= ~MIPI_CAL_BIAS_PAD_VAUXP(0x7);
  268. value |= MIPI_CAL_BIAS_PAD_VCLAMP(soc->pad_vclamp_level);
  269. value |= MIPI_CAL_BIAS_PAD_VAUXP(soc->pad_vauxp_level);
  270. tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG2);
  271. for (i = 0; i < soc->num_pads; i++) {
  272. u32 clk = 0, data = 0;
  273. if (device->pads & BIT(i)) {
  274. data = MIPI_CAL_CONFIG_SELECT |
  275. MIPI_CAL_CONFIG_HSPDOS(soc->hspdos) |
  276. MIPI_CAL_CONFIG_HSPUOS(soc->hspuos) |
  277. MIPI_CAL_CONFIG_TERMOS(soc->termos);
  278. clk = MIPI_CAL_CONFIG_SELECT |
  279. MIPI_CAL_CONFIG_HSCLKPDOSD(soc->hsclkpdos) |
  280. MIPI_CAL_CONFIG_HSCLKPUOSD(soc->hsclkpuos);
  281. }
  282. tegra_mipi_writel(device->mipi, data, soc->pads[i].data);
  283. if (soc->has_clk_lane && soc->pads[i].clk != 0)
  284. tegra_mipi_writel(device->mipi, clk, soc->pads[i].clk);
  285. }
  286. value = tegra_mipi_readl(device->mipi, MIPI_CAL_CTRL);
  287. value &= ~MIPI_CAL_CTRL_NOISE_FILTER(0xf);
  288. value &= ~MIPI_CAL_CTRL_PRESCALE(0x3);
  289. value |= MIPI_CAL_CTRL_NOISE_FILTER(0xa);
  290. value |= MIPI_CAL_CTRL_PRESCALE(0x2);
  291. if (!soc->clock_enable_override)
  292. value &= ~MIPI_CAL_CTRL_CLKEN_OVR;
  293. else
  294. value |= MIPI_CAL_CTRL_CLKEN_OVR;
  295. tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL);
  296. /* clear any pending status bits */
  297. value = tegra_mipi_readl(device->mipi, MIPI_CAL_STATUS);
  298. tegra_mipi_writel(device->mipi, value, MIPI_CAL_STATUS);
  299. value = tegra_mipi_readl(device->mipi, MIPI_CAL_CTRL);
  300. value |= MIPI_CAL_CTRL_START;
  301. tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL);
  302. err = tegra_mipi_wait(device->mipi);
  303. mutex_unlock(&device->mipi->lock);
  304. clk_disable(device->mipi->clk);
  305. return err;
  306. }
  307. EXPORT_SYMBOL(tegra_mipi_calibrate);
  308. static const struct tegra_mipi_pad tegra114_mipi_pads[] = {
  309. { .data = MIPI_CAL_CONFIG_CSIA },
  310. { .data = MIPI_CAL_CONFIG_CSIB },
  311. { .data = MIPI_CAL_CONFIG_CSIC },
  312. { .data = MIPI_CAL_CONFIG_CSID },
  313. { .data = MIPI_CAL_CONFIG_CSIE },
  314. { .data = MIPI_CAL_CONFIG_DSIA },
  315. { .data = MIPI_CAL_CONFIG_DSIB },
  316. { .data = MIPI_CAL_CONFIG_DSIC },
  317. { .data = MIPI_CAL_CONFIG_DSID },
  318. };
  319. static const struct tegra_mipi_soc tegra114_mipi_soc = {
  320. .has_clk_lane = false,
  321. .pads = tegra114_mipi_pads,
  322. .num_pads = ARRAY_SIZE(tegra114_mipi_pads),
  323. .clock_enable_override = true,
  324. .needs_vclamp_ref = true,
  325. .pad_drive_down_ref = 0x2,
  326. .pad_drive_up_ref = 0x0,
  327. .pad_vclamp_level = 0x0,
  328. .pad_vauxp_level = 0x0,
  329. .hspdos = 0x0,
  330. .hspuos = 0x4,
  331. .termos = 0x5,
  332. .hsclkpdos = 0x0,
  333. .hsclkpuos = 0x4,
  334. };
  335. static const struct tegra_mipi_pad tegra124_mipi_pads[] = {
  336. { .data = MIPI_CAL_CONFIG_CSIA, .clk = MIPI_CAL_CONFIG_CSIAB_CLK },
  337. { .data = MIPI_CAL_CONFIG_CSIB, .clk = MIPI_CAL_CONFIG_CSIAB_CLK },
  338. { .data = MIPI_CAL_CONFIG_CSIC, .clk = MIPI_CAL_CONFIG_CSICD_CLK },
  339. { .data = MIPI_CAL_CONFIG_CSID, .clk = MIPI_CAL_CONFIG_CSICD_CLK },
  340. { .data = MIPI_CAL_CONFIG_CSIE, .clk = MIPI_CAL_CONFIG_CSIE_CLK },
  341. { .data = MIPI_CAL_CONFIG_DSIA, .clk = MIPI_CAL_CONFIG_DSIA_CLK },
  342. { .data = MIPI_CAL_CONFIG_DSIB, .clk = MIPI_CAL_CONFIG_DSIB_CLK },
  343. };
  344. static const struct tegra_mipi_soc tegra124_mipi_soc = {
  345. .has_clk_lane = true,
  346. .pads = tegra124_mipi_pads,
  347. .num_pads = ARRAY_SIZE(tegra124_mipi_pads),
  348. .clock_enable_override = true,
  349. .needs_vclamp_ref = true,
  350. .pad_drive_down_ref = 0x2,
  351. .pad_drive_up_ref = 0x0,
  352. .pad_vclamp_level = 0x0,
  353. .pad_vauxp_level = 0x0,
  354. .hspdos = 0x0,
  355. .hspuos = 0x0,
  356. .termos = 0x0,
  357. .hsclkpdos = 0x1,
  358. .hsclkpuos = 0x2,
  359. };
  360. static const struct tegra_mipi_soc tegra132_mipi_soc = {
  361. .has_clk_lane = true,
  362. .pads = tegra124_mipi_pads,
  363. .num_pads = ARRAY_SIZE(tegra124_mipi_pads),
  364. .clock_enable_override = false,
  365. .needs_vclamp_ref = false,
  366. .pad_drive_down_ref = 0x0,
  367. .pad_drive_up_ref = 0x3,
  368. .pad_vclamp_level = 0x0,
  369. .pad_vauxp_level = 0x0,
  370. .hspdos = 0x0,
  371. .hspuos = 0x0,
  372. .termos = 0x0,
  373. .hsclkpdos = 0x3,
  374. .hsclkpuos = 0x2,
  375. };
  376. static const struct tegra_mipi_pad tegra210_mipi_pads[] = {
  377. { .data = MIPI_CAL_CONFIG_CSIA, .clk = 0 },
  378. { .data = MIPI_CAL_CONFIG_CSIB, .clk = 0 },
  379. { .data = MIPI_CAL_CONFIG_CSIC, .clk = 0 },
  380. { .data = MIPI_CAL_CONFIG_CSID, .clk = 0 },
  381. { .data = MIPI_CAL_CONFIG_CSIE, .clk = 0 },
  382. { .data = MIPI_CAL_CONFIG_CSIF, .clk = 0 },
  383. { .data = MIPI_CAL_CONFIG_DSIA, .clk = MIPI_CAL_CONFIG_DSIA_CLK },
  384. { .data = MIPI_CAL_CONFIG_DSIB, .clk = MIPI_CAL_CONFIG_DSIB_CLK },
  385. { .data = MIPI_CAL_CONFIG_DSIC, .clk = MIPI_CAL_CONFIG_DSIC_CLK },
  386. { .data = MIPI_CAL_CONFIG_DSID, .clk = MIPI_CAL_CONFIG_DSID_CLK },
  387. };
  388. static const struct tegra_mipi_soc tegra210_mipi_soc = {
  389. .has_clk_lane = true,
  390. .pads = tegra210_mipi_pads,
  391. .num_pads = ARRAY_SIZE(tegra210_mipi_pads),
  392. .clock_enable_override = true,
  393. .needs_vclamp_ref = false,
  394. .pad_drive_down_ref = 0x0,
  395. .pad_drive_up_ref = 0x3,
  396. .pad_vclamp_level = 0x1,
  397. .pad_vauxp_level = 0x1,
  398. .hspdos = 0x0,
  399. .hspuos = 0x2,
  400. .termos = 0x0,
  401. .hsclkpdos = 0x0,
  402. .hsclkpuos = 0x2,
  403. };
  404. static const struct of_device_id tegra_mipi_of_match[] = {
  405. { .compatible = "nvidia,tegra114-mipi", .data = &tegra114_mipi_soc },
  406. { .compatible = "nvidia,tegra124-mipi", .data = &tegra124_mipi_soc },
  407. { .compatible = "nvidia,tegra132-mipi", .data = &tegra132_mipi_soc },
  408. { .compatible = "nvidia,tegra210-mipi", .data = &tegra210_mipi_soc },
  409. { },
  410. };
  411. static int tegra_mipi_probe(struct platform_device *pdev)
  412. {
  413. const struct of_device_id *match;
  414. struct tegra_mipi *mipi;
  415. struct resource *res;
  416. int err;
  417. match = of_match_node(tegra_mipi_of_match, pdev->dev.of_node);
  418. if (!match)
  419. return -ENODEV;
  420. mipi = devm_kzalloc(&pdev->dev, sizeof(*mipi), GFP_KERNEL);
  421. if (!mipi)
  422. return -ENOMEM;
  423. mipi->soc = match->data;
  424. mipi->dev = &pdev->dev;
  425. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  426. mipi->regs = devm_ioremap_resource(&pdev->dev, res);
  427. if (IS_ERR(mipi->regs))
  428. return PTR_ERR(mipi->regs);
  429. mutex_init(&mipi->lock);
  430. mipi->clk = devm_clk_get(&pdev->dev, NULL);
  431. if (IS_ERR(mipi->clk)) {
  432. dev_err(&pdev->dev, "failed to get clock\n");
  433. return PTR_ERR(mipi->clk);
  434. }
  435. err = clk_prepare(mipi->clk);
  436. if (err < 0)
  437. return err;
  438. platform_set_drvdata(pdev, mipi);
  439. return 0;
  440. }
  441. static int tegra_mipi_remove(struct platform_device *pdev)
  442. {
  443. struct tegra_mipi *mipi = platform_get_drvdata(pdev);
  444. clk_unprepare(mipi->clk);
  445. return 0;
  446. }
  447. struct platform_driver tegra_mipi_driver = {
  448. .driver = {
  449. .name = "tegra-mipi",
  450. .of_match_table = tegra_mipi_of_match,
  451. },
  452. .probe = tegra_mipi_probe,
  453. .remove = tegra_mipi_remove,
  454. };