Lines Matching +full:mmp2 +full:- +full:clock
1 // SPDX-License-Identifier: GPL-2.0-only
17 #include <media/v4l2-device.h>
18 #include <linux/platform_data/media/mmp-camera.h>
29 #include "mcam-core.h"
31 MODULE_ALIAS("platform:mmp-camera");
53 * dphy[0] - CSI2_DPHY3
54 * dphy[1] - CSI2_DPHY5
55 * dphy[2] - CSI2_DPHY6
62 struct mmp_camera_platform_data *pdata = cam->pdev->dev.platform_data; in mmpcam_calc_dphy()
63 struct device *dev = &cam->pdev->dev; in mmpcam_calc_dphy()
68 * pdata->lane_clk should be already set in mmpcam_calc_dphy()
73 * dphy[0] - CSI2_DPHY3: in mmpcam_calc_dphy()
81 * (Max T(D_TERM_EN)/Period(DDR)) - 1 in mmpcam_calc_dphy()
90 * MIPI Alliance Spectification for D-PHY in mmpcam_calc_dphy()
91 * document for explanation of HS-SETTLE in mmpcam_calc_dphy()
92 * and D-TERM-EN. in mmpcam_calc_dphy()
94 switch (pdata->dphy3_algo) { in mmpcam_calc_dphy()
99 pdata->dphy[0] = in mmpcam_calc_dphy()
100 (((1 + (pdata->lane_clk * 80) / 1000) & 0xff) << 8) in mmpcam_calc_dphy()
101 | (1 + pdata->lane_clk * 35 / 1000); in mmpcam_calc_dphy()
107 pdata->dphy[0] = in mmpcam_calc_dphy()
108 (((2 + (pdata->lane_clk * 110) / 1000) & 0xff) << 8) in mmpcam_calc_dphy()
109 | (1 + pdata->lane_clk * 35 / 1000); in mmpcam_calc_dphy()
121 if (IS_ERR(cam->mipi_clk)) in mmpcam_calc_dphy()
125 clk_prepare_enable(cam->mipi_clk); in mmpcam_calc_dphy()
126 tx_clk_esc = (clk_get_rate(cam->mipi_clk) / 1000000) / 12; in mmpcam_calc_dphy()
127 clk_disable_unprepare(cam->mipi_clk); in mmpcam_calc_dphy()
129 * dphy[2] - CSI2_DPHY6: in mmpcam_calc_dphy()
131 * Time for the Clock Lane receiver to enable the HS line in mmpcam_calc_dphy()
136 * any Clock Lane HS transitions. in mmpcam_calc_dphy()
139 pdata->dphy[2] = in mmpcam_calc_dphy()
140 ((((534 * tx_clk_esc) / 2000 - 1) & 0xff) << 8) in mmpcam_calc_dphy()
141 | (((38 * tx_clk_esc) / 1000 - 1) & 0xff); in mmpcam_calc_dphy()
144 pdata->dphy[0], pdata->dphy[1], pdata->dphy[2]); in mmpcam_calc_dphy()
152 spin_lock(&mcam->dev_lock); in mmpcam_irq()
155 spin_unlock(&mcam->dev_lock); in mmpcam_irq()
168 mcam->clk[i] = devm_clk_get(mcam->dev, mcam_clks[i]); in mcam_init_clk()
169 if (IS_ERR(mcam->clk[i])) in mcam_init_clk()
170 dev_warn(mcam->dev, "Could not get clk: %s\n", in mcam_init_clk()
186 cam = devm_kzalloc(&pdev->dev, sizeof(*cam), GFP_KERNEL); in mmpcam_probe()
188 return -ENOMEM; in mmpcam_probe()
190 cam->pdev = pdev; in mmpcam_probe()
191 INIT_LIST_HEAD(&cam->devlist); in mmpcam_probe()
193 mcam = &cam->mcam; in mmpcam_probe()
194 mcam->calc_dphy = mmpcam_calc_dphy; in mmpcam_probe()
195 mcam->dev = &pdev->dev; in mmpcam_probe()
196 pdata = pdev->dev.platform_data; in mmpcam_probe()
198 mcam->mclk_src = pdata->mclk_src; in mmpcam_probe()
199 mcam->mclk_div = pdata->mclk_div; in mmpcam_probe()
200 mcam->bus_type = pdata->bus_type; in mmpcam_probe()
201 mcam->dphy = pdata->dphy; in mmpcam_probe()
202 mcam->lane = pdata->lane; in mmpcam_probe()
205 * These are values that used to be hardcoded in mcam-core and in mmpcam_probe()
210 mcam->mclk_src = 3; in mmpcam_probe()
211 mcam->mclk_div = 2; in mmpcam_probe()
213 if (mcam->bus_type == V4L2_MBUS_CSI2_DPHY) { in mmpcam_probe()
214 cam->mipi_clk = devm_clk_get(mcam->dev, "mipi"); in mmpcam_probe()
215 if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0)) in mmpcam_probe()
216 return PTR_ERR(cam->mipi_clk); in mmpcam_probe()
218 mcam->mipi_enabled = false; in mmpcam_probe()
219 mcam->chip_id = MCAM_ARMADA610; in mmpcam_probe()
220 mcam->buffer_mode = B_DMA_sg; in mmpcam_probe()
221 strscpy(mcam->bus_info, "platform:mmp-camera", sizeof(mcam->bus_info)); in mmpcam_probe()
222 spin_lock_init(&mcam->dev_lock); in mmpcam_probe()
227 mcam->regs = devm_ioremap_resource(&pdev->dev, res); in mmpcam_probe()
228 if (IS_ERR(mcam->regs)) in mmpcam_probe()
229 return PTR_ERR(mcam->regs); in mmpcam_probe()
230 mcam->regs_size = resource_size(res); in mmpcam_probe()
237 ep = fwnode_graph_get_next_endpoint(of_fwnode_handle(pdev->dev.of_node), in mmpcam_probe()
240 return -ENODEV; in mmpcam_probe()
242 v4l2_async_nf_init(&mcam->notifier); in mmpcam_probe()
244 asd = v4l2_async_nf_add_fwnode_remote(&mcam->notifier, ep, in mmpcam_probe()
260 * Add OF clock provider. in mmpcam_probe()
262 ret = of_clk_add_provider(pdev->dev.of_node, of_clk_src_simple_get, in mmpcam_probe()
263 mcam->mclk); in mmpcam_probe()
265 dev_err(&pdev->dev, "can't add DT clock provider\n"); in mmpcam_probe()
276 cam->irq = ret; in mmpcam_probe()
277 ret = devm_request_irq(&pdev->dev, cam->irq, mmpcam_irq, IRQF_SHARED, in mmpcam_probe()
278 "mmp-camera", mcam); in mmpcam_probe()
282 pm_runtime_enable(&pdev->dev); in mmpcam_probe()
293 struct mcam_camera *mcam = &cam->mcam; in mmpcam_remove()
296 pm_runtime_force_suspend(mcam->dev); in mmpcam_remove()
305 return -ENODEV; in mmpcam_platform_remove()
316 struct mcam_camera *mcam = &cam->mcam; in mmpcam_runtime_resume()
320 if (!IS_ERR(mcam->clk[i])) in mmpcam_runtime_resume()
321 clk_prepare_enable(mcam->clk[i]); in mmpcam_runtime_resume()
330 struct mcam_camera *mcam = &cam->mcam; in mmpcam_runtime_suspend()
333 for (i = NR_MCAM_CLK - 1; i >= 0; i--) { in mmpcam_runtime_suspend()
334 if (!IS_ERR(mcam->clk[i])) in mmpcam_runtime_suspend()
335 clk_disable_unprepare(mcam->clk[i]); in mmpcam_runtime_suspend()
346 mccic_suspend(&cam->mcam); in mmpcam_suspend()
355 return mccic_resume(&cam->mcam); in mmpcam_resume()
365 { .compatible = "marvell,mmp2-ccic", },
374 .name = "mmp-camera",