| .. | .. |
|---|
| 21 | 21 | */ |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | #include <linux/clk.h> |
|---|
| 24 | | -#include <linux/delay.h> |
|---|
| 25 | 24 | #include <linux/host1x.h> |
|---|
| 26 | 25 | #include <linux/io.h> |
|---|
| 26 | +#include <linux/iopoll.h> |
|---|
| 27 | 27 | #include <linux/of_platform.h> |
|---|
| 28 | 28 | #include <linux/platform_device.h> |
|---|
| 29 | 29 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 206 | 206 | return 0; |
|---|
| 207 | 207 | } |
|---|
| 208 | 208 | |
|---|
| 209 | | -struct tegra_mipi_device *tegra_mipi_request(struct device *device) |
|---|
| 209 | +struct tegra_mipi_device *tegra_mipi_request(struct device *device, |
|---|
| 210 | + struct device_node *np) |
|---|
| 210 | 211 | { |
|---|
| 211 | | - struct device_node *np = device->of_node; |
|---|
| 212 | 212 | struct tegra_mipi_device *dev; |
|---|
| 213 | 213 | struct of_phandle_args args; |
|---|
| 214 | 214 | int err; |
|---|
| .. | .. |
|---|
| 293 | 293 | } |
|---|
| 294 | 294 | EXPORT_SYMBOL(tegra_mipi_disable); |
|---|
| 295 | 295 | |
|---|
| 296 | | -static int tegra_mipi_wait(struct tegra_mipi *mipi) |
|---|
| 296 | +int tegra_mipi_finish_calibration(struct tegra_mipi_device *device) |
|---|
| 297 | 297 | { |
|---|
| 298 | | - unsigned long timeout = jiffies + msecs_to_jiffies(250); |
|---|
| 298 | + struct tegra_mipi *mipi = device->mipi; |
|---|
| 299 | + void __iomem *status_reg = mipi->regs + (MIPI_CAL_STATUS << 2); |
|---|
| 299 | 300 | u32 value; |
|---|
| 301 | + int err; |
|---|
| 300 | 302 | |
|---|
| 301 | | - while (time_before(jiffies, timeout)) { |
|---|
| 302 | | - value = tegra_mipi_readl(mipi, MIPI_CAL_STATUS); |
|---|
| 303 | | - if ((value & MIPI_CAL_STATUS_ACTIVE) == 0 && |
|---|
| 304 | | - (value & MIPI_CAL_STATUS_DONE) != 0) |
|---|
| 305 | | - return 0; |
|---|
| 303 | + err = readl_relaxed_poll_timeout(status_reg, value, |
|---|
| 304 | + !(value & MIPI_CAL_STATUS_ACTIVE) && |
|---|
| 305 | + (value & MIPI_CAL_STATUS_DONE), 50, |
|---|
| 306 | + 250000); |
|---|
| 307 | + mutex_unlock(&device->mipi->lock); |
|---|
| 308 | + clk_disable(device->mipi->clk); |
|---|
| 306 | 309 | |
|---|
| 307 | | - usleep_range(10, 50); |
|---|
| 308 | | - } |
|---|
| 309 | | - |
|---|
| 310 | | - return -ETIMEDOUT; |
|---|
| 310 | + return err; |
|---|
| 311 | 311 | } |
|---|
| 312 | +EXPORT_SYMBOL(tegra_mipi_finish_calibration); |
|---|
| 312 | 313 | |
|---|
| 313 | | -int tegra_mipi_calibrate(struct tegra_mipi_device *device) |
|---|
| 314 | +int tegra_mipi_start_calibration(struct tegra_mipi_device *device) |
|---|
| 314 | 315 | { |
|---|
| 315 | 316 | const struct tegra_mipi_soc *soc = device->mipi->soc; |
|---|
| 316 | 317 | unsigned int i; |
|---|
| .. | .. |
|---|
| 374 | 375 | value |= MIPI_CAL_CTRL_START; |
|---|
| 375 | 376 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL); |
|---|
| 376 | 377 | |
|---|
| 377 | | - err = tegra_mipi_wait(device->mipi); |
|---|
| 378 | + /* |
|---|
| 379 | + * Wait for min 72uS to let calibration logic finish calibration |
|---|
| 380 | + * sequence codes before waiting for pads idle state to apply the |
|---|
| 381 | + * results. |
|---|
| 382 | + */ |
|---|
| 383 | + usleep_range(75, 80); |
|---|
| 378 | 384 | |
|---|
| 379 | | - mutex_unlock(&device->mipi->lock); |
|---|
| 380 | | - clk_disable(device->mipi->clk); |
|---|
| 381 | | - |
|---|
| 382 | | - return err; |
|---|
| 385 | + return 0; |
|---|
| 383 | 386 | } |
|---|
| 384 | | -EXPORT_SYMBOL(tegra_mipi_calibrate); |
|---|
| 387 | +EXPORT_SYMBOL(tegra_mipi_start_calibration); |
|---|
| 385 | 388 | |
|---|
| 386 | 389 | static const struct tegra_mipi_pad tegra114_mipi_pads[] = { |
|---|
| 387 | 390 | { .data = MIPI_CAL_CONFIG_CSIA }, |
|---|