mipi.c 14 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. return dev;
  198. put:
  199. platform_device_put(dev->pdev);
  200. free:
  201. kfree(dev);
  202. out:
  203. of_node_put(args.np);
  204. return ERR_PTR(err);
  205. }
  206. EXPORT_SYMBOL(tegra_mipi_request);
  207. void tegra_mipi_free(struct tegra_mipi_device *device)
  208. {
  209. platform_device_put(device->pdev);
  210. kfree(device);
  211. }
  212. EXPORT_SYMBOL(tegra_mipi_free);
  213. int tegra_mipi_enable(struct tegra_mipi_device *dev)
  214. {
  215. int err = 0;
  216. mutex_lock(&dev->mipi->lock);
  217. if (dev->mipi->usage_count++ == 0)
  218. err = tegra_mipi_power_up(dev->mipi);
  219. mutex_unlock(&dev->mipi->lock);
  220. return err;
  221. }
  222. EXPORT_SYMBOL(tegra_mipi_enable);
  223. int tegra_mipi_disable(struct tegra_mipi_device *dev)
  224. {
  225. int err = 0;
  226. mutex_lock(&dev->mipi->lock);
  227. if (--dev->mipi->usage_count == 0)
  228. err = tegra_mipi_power_down(dev->mipi);
  229. mutex_unlock(&dev->mipi->lock);
  230. return err;
  231. }
  232. EXPORT_SYMBOL(tegra_mipi_disable);
  233. static int tegra_mipi_wait(struct tegra_mipi *mipi)
  234. {
  235. unsigned long timeout = jiffies + msecs_to_jiffies(250);
  236. u32 value;
  237. while (time_before(jiffies, timeout)) {
  238. value = tegra_mipi_readl(mipi, MIPI_CAL_STATUS);
  239. if ((value & MIPI_CAL_STATUS_ACTIVE) == 0 &&
  240. (value & MIPI_CAL_STATUS_DONE) != 0)
  241. return 0;
  242. usleep_range(10, 50);
  243. }
  244. return -ETIMEDOUT;
  245. }
  246. int tegra_mipi_calibrate(struct tegra_mipi_device *device)
  247. {
  248. const struct tegra_mipi_soc *soc = device->mipi->soc;
  249. unsigned int i;
  250. u32 value;
  251. int err;
  252. err = clk_enable(device->mipi->clk);
  253. if (err < 0)
  254. return err;
  255. mutex_lock(&device->mipi->lock);
  256. value = MIPI_CAL_BIAS_PAD_DRV_DN_REF(soc->pad_drive_down_ref) |
  257. MIPI_CAL_BIAS_PAD_DRV_UP_REF(soc->pad_drive_up_ref);
  258. tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG1);
  259. value = tegra_mipi_readl(device->mipi, MIPI_CAL_BIAS_PAD_CFG2);
  260. value &= ~MIPI_CAL_BIAS_PAD_VCLAMP(0x7);
  261. value &= ~MIPI_CAL_BIAS_PAD_VAUXP(0x7);
  262. value |= MIPI_CAL_BIAS_PAD_VCLAMP(soc->pad_vclamp_level);
  263. value |= MIPI_CAL_BIAS_PAD_VAUXP(soc->pad_vauxp_level);
  264. tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG2);
  265. for (i = 0; i < soc->num_pads; i++) {
  266. u32 clk = 0, data = 0;
  267. if (device->pads & BIT(i)) {
  268. data = MIPI_CAL_CONFIG_SELECT |
  269. MIPI_CAL_CONFIG_HSPDOS(soc->hspdos) |
  270. MIPI_CAL_CONFIG_HSPUOS(soc->hspuos) |
  271. MIPI_CAL_CONFIG_TERMOS(soc->termos);
  272. clk = MIPI_CAL_CONFIG_SELECT |
  273. MIPI_CAL_CONFIG_HSCLKPDOSD(soc->hsclkpdos) |
  274. MIPI_CAL_CONFIG_HSCLKPUOSD(soc->hsclkpuos);
  275. }
  276. tegra_mipi_writel(device->mipi, data, soc->pads[i].data);
  277. if (soc->has_clk_lane && soc->pads[i].clk != 0)
  278. tegra_mipi_writel(device->mipi, clk, soc->pads[i].clk);
  279. }
  280. value = tegra_mipi_readl(device->mipi, MIPI_CAL_CTRL);
  281. value &= ~MIPI_CAL_CTRL_NOISE_FILTER(0xf);
  282. value &= ~MIPI_CAL_CTRL_PRESCALE(0x3);
  283. value |= MIPI_CAL_CTRL_NOISE_FILTER(0xa);
  284. value |= MIPI_CAL_CTRL_PRESCALE(0x2);
  285. if (!soc->clock_enable_override)
  286. value &= ~MIPI_CAL_CTRL_CLKEN_OVR;
  287. else
  288. value |= MIPI_CAL_CTRL_CLKEN_OVR;
  289. tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL);
  290. /* clear any pending status bits */
  291. value = tegra_mipi_readl(device->mipi, MIPI_CAL_STATUS);
  292. tegra_mipi_writel(device->mipi, value, MIPI_CAL_STATUS);
  293. value = tegra_mipi_readl(device->mipi, MIPI_CAL_CTRL);
  294. value |= MIPI_CAL_CTRL_START;
  295. tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL);
  296. err = tegra_mipi_wait(device->mipi);
  297. mutex_unlock(&device->mipi->lock);
  298. clk_disable(device->mipi->clk);
  299. return err;
  300. }
  301. EXPORT_SYMBOL(tegra_mipi_calibrate);
  302. static const struct tegra_mipi_pad tegra114_mipi_pads[] = {
  303. { .data = MIPI_CAL_CONFIG_CSIA },
  304. { .data = MIPI_CAL_CONFIG_CSIB },
  305. { .data = MIPI_CAL_CONFIG_CSIC },
  306. { .data = MIPI_CAL_CONFIG_CSID },
  307. { .data = MIPI_CAL_CONFIG_CSIE },
  308. { .data = MIPI_CAL_CONFIG_DSIA },
  309. { .data = MIPI_CAL_CONFIG_DSIB },
  310. { .data = MIPI_CAL_CONFIG_DSIC },
  311. { .data = MIPI_CAL_CONFIG_DSID },
  312. };
  313. static const struct tegra_mipi_soc tegra114_mipi_soc = {
  314. .has_clk_lane = false,
  315. .pads = tegra114_mipi_pads,
  316. .num_pads = ARRAY_SIZE(tegra114_mipi_pads),
  317. .clock_enable_override = true,
  318. .needs_vclamp_ref = true,
  319. .pad_drive_down_ref = 0x2,
  320. .pad_drive_up_ref = 0x0,
  321. .pad_vclamp_level = 0x0,
  322. .pad_vauxp_level = 0x0,
  323. .hspdos = 0x0,
  324. .hspuos = 0x4,
  325. .termos = 0x5,
  326. .hsclkpdos = 0x0,
  327. .hsclkpuos = 0x4,
  328. };
  329. static const struct tegra_mipi_pad tegra124_mipi_pads[] = {
  330. { .data = MIPI_CAL_CONFIG_CSIA, .clk = MIPI_CAL_CONFIG_CSIAB_CLK },
  331. { .data = MIPI_CAL_CONFIG_CSIB, .clk = MIPI_CAL_CONFIG_CSIAB_CLK },
  332. { .data = MIPI_CAL_CONFIG_CSIC, .clk = MIPI_CAL_CONFIG_CSICD_CLK },
  333. { .data = MIPI_CAL_CONFIG_CSID, .clk = MIPI_CAL_CONFIG_CSICD_CLK },
  334. { .data = MIPI_CAL_CONFIG_CSIE, .clk = MIPI_CAL_CONFIG_CSIE_CLK },
  335. { .data = MIPI_CAL_CONFIG_DSIA, .clk = MIPI_CAL_CONFIG_DSIA_CLK },
  336. { .data = MIPI_CAL_CONFIG_DSIB, .clk = MIPI_CAL_CONFIG_DSIB_CLK },
  337. };
  338. static const struct tegra_mipi_soc tegra124_mipi_soc = {
  339. .has_clk_lane = true,
  340. .pads = tegra124_mipi_pads,
  341. .num_pads = ARRAY_SIZE(tegra124_mipi_pads),
  342. .clock_enable_override = true,
  343. .needs_vclamp_ref = true,
  344. .pad_drive_down_ref = 0x2,
  345. .pad_drive_up_ref = 0x0,
  346. .pad_vclamp_level = 0x0,
  347. .pad_vauxp_level = 0x0,
  348. .hspdos = 0x0,
  349. .hspuos = 0x0,
  350. .termos = 0x0,
  351. .hsclkpdos = 0x1,
  352. .hsclkpuos = 0x2,
  353. };
  354. static const struct tegra_mipi_soc tegra132_mipi_soc = {
  355. .has_clk_lane = true,
  356. .pads = tegra124_mipi_pads,
  357. .num_pads = ARRAY_SIZE(tegra124_mipi_pads),
  358. .clock_enable_override = false,
  359. .needs_vclamp_ref = false,
  360. .pad_drive_down_ref = 0x0,
  361. .pad_drive_up_ref = 0x3,
  362. .pad_vclamp_level = 0x0,
  363. .pad_vauxp_level = 0x0,
  364. .hspdos = 0x0,
  365. .hspuos = 0x0,
  366. .termos = 0x0,
  367. .hsclkpdos = 0x3,
  368. .hsclkpuos = 0x2,
  369. };
  370. static const struct tegra_mipi_pad tegra210_mipi_pads[] = {
  371. { .data = MIPI_CAL_CONFIG_CSIA, .clk = 0 },
  372. { .data = MIPI_CAL_CONFIG_CSIB, .clk = 0 },
  373. { .data = MIPI_CAL_CONFIG_CSIC, .clk = 0 },
  374. { .data = MIPI_CAL_CONFIG_CSID, .clk = 0 },
  375. { .data = MIPI_CAL_CONFIG_CSIE, .clk = 0 },
  376. { .data = MIPI_CAL_CONFIG_CSIF, .clk = 0 },
  377. { .data = MIPI_CAL_CONFIG_DSIA, .clk = MIPI_CAL_CONFIG_DSIA_CLK },
  378. { .data = MIPI_CAL_CONFIG_DSIB, .clk = MIPI_CAL_CONFIG_DSIB_CLK },
  379. { .data = MIPI_CAL_CONFIG_DSIC, .clk = MIPI_CAL_CONFIG_DSIC_CLK },
  380. { .data = MIPI_CAL_CONFIG_DSID, .clk = MIPI_CAL_CONFIG_DSID_CLK },
  381. };
  382. static const struct tegra_mipi_soc tegra210_mipi_soc = {
  383. .has_clk_lane = true,
  384. .pads = tegra210_mipi_pads,
  385. .num_pads = ARRAY_SIZE(tegra210_mipi_pads),
  386. .clock_enable_override = true,
  387. .needs_vclamp_ref = false,
  388. .pad_drive_down_ref = 0x0,
  389. .pad_drive_up_ref = 0x3,
  390. .pad_vclamp_level = 0x1,
  391. .pad_vauxp_level = 0x1,
  392. .hspdos = 0x0,
  393. .hspuos = 0x2,
  394. .termos = 0x0,
  395. .hsclkpdos = 0x0,
  396. .hsclkpuos = 0x2,
  397. };
  398. static const struct of_device_id tegra_mipi_of_match[] = {
  399. { .compatible = "nvidia,tegra114-mipi", .data = &tegra114_mipi_soc },
  400. { .compatible = "nvidia,tegra124-mipi", .data = &tegra124_mipi_soc },
  401. { .compatible = "nvidia,tegra132-mipi", .data = &tegra132_mipi_soc },
  402. { .compatible = "nvidia,tegra210-mipi", .data = &tegra210_mipi_soc },
  403. { },
  404. };
  405. static int tegra_mipi_probe(struct platform_device *pdev)
  406. {
  407. const struct of_device_id *match;
  408. struct tegra_mipi *mipi;
  409. struct resource *res;
  410. int err;
  411. match = of_match_node(tegra_mipi_of_match, pdev->dev.of_node);
  412. if (!match)
  413. return -ENODEV;
  414. mipi = devm_kzalloc(&pdev->dev, sizeof(*mipi), GFP_KERNEL);
  415. if (!mipi)
  416. return -ENOMEM;
  417. mipi->soc = match->data;
  418. mipi->dev = &pdev->dev;
  419. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  420. mipi->regs = devm_ioremap_resource(&pdev->dev, res);
  421. if (IS_ERR(mipi->regs))
  422. return PTR_ERR(mipi->regs);
  423. mutex_init(&mipi->lock);
  424. mipi->clk = devm_clk_get(&pdev->dev, NULL);
  425. if (IS_ERR(mipi->clk)) {
  426. dev_err(&pdev->dev, "failed to get clock\n");
  427. return PTR_ERR(mipi->clk);
  428. }
  429. err = clk_prepare(mipi->clk);
  430. if (err < 0)
  431. return err;
  432. platform_set_drvdata(pdev, mipi);
  433. return 0;
  434. }
  435. static int tegra_mipi_remove(struct platform_device *pdev)
  436. {
  437. struct tegra_mipi *mipi = platform_get_drvdata(pdev);
  438. clk_unprepare(mipi->clk);
  439. return 0;
  440. }
  441. struct platform_driver tegra_mipi_driver = {
  442. .driver = {
  443. .name = "tegra-mipi",
  444. .of_match_table = tegra_mipi_of_match,
  445. },
  446. .probe = tegra_mipi_probe,
  447. .remove = tegra_mipi_remove,
  448. };