Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 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 | |
| 23 | #include <linux/clk.h> |
| 24 | #include <linux/delay.h> |
Thierry Reding | aef03d3 | 2013-11-08 13:28:34 +0100 | [diff] [blame] | 25 | #include <linux/host1x.h> |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 26 | #include <linux/io.h> |
| 27 | #include <linux/of_platform.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/slab.h> |
| 30 | |
Thierry Reding | aef03d3 | 2013-11-08 13:28:34 +0100 | [diff] [blame] | 31 | #include "dev.h" |
| 32 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 33 | #define MIPI_CAL_CTRL 0x00 |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 34 | #define MIPI_CAL_CTRL_NOISE_FILTER(x) (((x) & 0xf) << 26) |
| 35 | #define MIPI_CAL_CTRL_PRESCALE(x) (((x) & 0x3) << 24) |
| 36 | #define MIPI_CAL_CTRL_CLKEN_OVR (1 << 4) |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 37 | #define MIPI_CAL_CTRL_START (1 << 0) |
| 38 | |
| 39 | #define MIPI_CAL_AUTOCAL_CTRL 0x01 |
| 40 | |
| 41 | #define MIPI_CAL_STATUS 0x02 |
| 42 | #define MIPI_CAL_STATUS_DONE (1 << 16) |
| 43 | #define MIPI_CAL_STATUS_ACTIVE (1 << 0) |
| 44 | |
| 45 | #define MIPI_CAL_CONFIG_CSIA 0x05 |
| 46 | #define MIPI_CAL_CONFIG_CSIB 0x06 |
| 47 | #define MIPI_CAL_CONFIG_CSIC 0x07 |
| 48 | #define MIPI_CAL_CONFIG_CSID 0x08 |
| 49 | #define MIPI_CAL_CONFIG_CSIE 0x09 |
Thierry Reding | 5e77524 | 2015-04-08 17:23:20 +0200 | [diff] [blame^] | 50 | #define MIPI_CAL_CONFIG_CSIF 0x0a |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 51 | #define MIPI_CAL_CONFIG_DSIA 0x0e |
| 52 | #define MIPI_CAL_CONFIG_DSIB 0x0f |
| 53 | #define MIPI_CAL_CONFIG_DSIC 0x10 |
| 54 | #define MIPI_CAL_CONFIG_DSID 0x11 |
| 55 | |
Thierry Reding | 8ed5c06 | 2015-04-08 17:06:08 +0200 | [diff] [blame] | 56 | #define MIPI_CAL_CONFIG_DSIA_CLK 0x19 |
| 57 | #define MIPI_CAL_CONFIG_DSIB_CLK 0x1a |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 58 | #define MIPI_CAL_CONFIG_CSIAB_CLK 0x1b |
Thierry Reding | 5e77524 | 2015-04-08 17:23:20 +0200 | [diff] [blame^] | 59 | #define MIPI_CAL_CONFIG_DSIC_CLK 0x1c |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 60 | #define MIPI_CAL_CONFIG_CSICD_CLK 0x1c |
Thierry Reding | 5e77524 | 2015-04-08 17:23:20 +0200 | [diff] [blame^] | 61 | #define MIPI_CAL_CONFIG_DSID_CLK 0x1d |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 62 | #define MIPI_CAL_CONFIG_CSIE_CLK 0x1d |
| 63 | |
| 64 | /* for data and clock lanes */ |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 65 | #define MIPI_CAL_CONFIG_SELECT (1 << 21) |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 66 | |
| 67 | /* for data lanes */ |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 68 | #define MIPI_CAL_CONFIG_HSPDOS(x) (((x) & 0x1f) << 16) |
| 69 | #define MIPI_CAL_CONFIG_HSPUOS(x) (((x) & 0x1f) << 8) |
| 70 | #define MIPI_CAL_CONFIG_TERMOS(x) (((x) & 0x1f) << 0) |
| 71 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 72 | /* for clock lanes */ |
| 73 | #define MIPI_CAL_CONFIG_HSCLKPDOSD(x) (((x) & 0x1f) << 8) |
| 74 | #define MIPI_CAL_CONFIG_HSCLKPUOSD(x) (((x) & 0x1f) << 0) |
| 75 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 76 | #define MIPI_CAL_BIAS_PAD_CFG0 0x16 |
| 77 | #define MIPI_CAL_BIAS_PAD_PDVCLAMP (1 << 1) |
| 78 | #define MIPI_CAL_BIAS_PAD_E_VCLAMP_REF (1 << 0) |
| 79 | |
| 80 | #define MIPI_CAL_BIAS_PAD_CFG1 0x17 |
Sean Paul | b298e98 | 2014-09-10 10:52:05 -0400 | [diff] [blame] | 81 | #define MIPI_CAL_BIAS_PAD_DRV_DN_REF(x) (((x) & 0x7) << 16) |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 82 | #define MIPI_CAL_BIAS_PAD_DRV_UP_REF(x) (((x) & 0x7) << 8) |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 83 | |
| 84 | #define MIPI_CAL_BIAS_PAD_CFG2 0x18 |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 85 | #define MIPI_CAL_BIAS_PAD_VCLAMP(x) (((x) & 0x7) << 16) |
| 86 | #define MIPI_CAL_BIAS_PAD_VAUXP(x) (((x) & 0x7) << 4) |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 87 | #define MIPI_CAL_BIAS_PAD_PDVREG (1 << 1) |
| 88 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 89 | struct tegra_mipi_pad { |
| 90 | unsigned long data; |
| 91 | unsigned long clk; |
| 92 | }; |
| 93 | |
| 94 | struct tegra_mipi_soc { |
| 95 | bool has_clk_lane; |
| 96 | const struct tegra_mipi_pad *pads; |
| 97 | unsigned int num_pads; |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 98 | |
| 99 | bool clock_enable_override; |
| 100 | bool needs_vclamp_ref; |
| 101 | |
| 102 | /* bias pad configuration settings */ |
| 103 | u8 pad_drive_down_ref; |
| 104 | u8 pad_drive_up_ref; |
| 105 | |
| 106 | u8 pad_vclamp_level; |
| 107 | u8 pad_vauxp_level; |
| 108 | |
| 109 | /* calibration settings for data lanes */ |
| 110 | u8 hspdos; |
| 111 | u8 hspuos; |
| 112 | u8 termos; |
| 113 | |
| 114 | /* calibration settings for clock lanes */ |
| 115 | u8 hsclkpdos; |
| 116 | u8 hsclkpuos; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | struct tegra_mipi { |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 120 | const struct tegra_mipi_soc *soc; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 121 | void __iomem *regs; |
| 122 | struct mutex lock; |
| 123 | struct clk *clk; |
| 124 | }; |
| 125 | |
| 126 | struct tegra_mipi_device { |
| 127 | struct platform_device *pdev; |
| 128 | struct tegra_mipi *mipi; |
| 129 | struct device *device; |
| 130 | unsigned long pads; |
| 131 | }; |
| 132 | |
Thierry Reding | 57b17ae | 2014-10-02 14:33:31 +0200 | [diff] [blame] | 133 | static inline u32 tegra_mipi_readl(struct tegra_mipi *mipi, |
| 134 | unsigned long offset) |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 135 | { |
Thierry Reding | 57b17ae | 2014-10-02 14:33:31 +0200 | [diff] [blame] | 136 | return readl(mipi->regs + (offset << 2)); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Thierry Reding | 57b17ae | 2014-10-02 14:33:31 +0200 | [diff] [blame] | 139 | static inline void tegra_mipi_writel(struct tegra_mipi *mipi, u32 value, |
| 140 | unsigned long offset) |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 141 | { |
Thierry Reding | 57b17ae | 2014-10-02 14:33:31 +0200 | [diff] [blame] | 142 | writel(value, mipi->regs + (offset << 2)); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | struct tegra_mipi_device *tegra_mipi_request(struct device *device) |
| 146 | { |
| 147 | struct device_node *np = device->of_node; |
| 148 | struct tegra_mipi_device *dev; |
| 149 | struct of_phandle_args args; |
| 150 | int err; |
| 151 | |
| 152 | err = of_parse_phandle_with_args(np, "nvidia,mipi-calibrate", |
| 153 | "#nvidia,mipi-calibrate-cells", 0, |
| 154 | &args); |
| 155 | if (err < 0) |
| 156 | return ERR_PTR(err); |
| 157 | |
| 158 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 159 | if (!dev) { |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 160 | err = -ENOMEM; |
| 161 | goto out; |
| 162 | } |
| 163 | |
| 164 | dev->pdev = of_find_device_by_node(args.np); |
| 165 | if (!dev->pdev) { |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 166 | err = -ENODEV; |
| 167 | goto free; |
| 168 | } |
| 169 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 170 | dev->mipi = platform_get_drvdata(dev->pdev); |
| 171 | if (!dev->mipi) { |
| 172 | err = -EPROBE_DEFER; |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 173 | goto put; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 176 | of_node_put(args.np); |
| 177 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 178 | dev->pads = args.args[0]; |
| 179 | dev->device = device; |
| 180 | |
| 181 | return dev; |
| 182 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 183 | put: |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 184 | platform_device_put(dev->pdev); |
| 185 | free: |
| 186 | kfree(dev); |
| 187 | out: |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 188 | of_node_put(args.np); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 189 | return ERR_PTR(err); |
| 190 | } |
| 191 | EXPORT_SYMBOL(tegra_mipi_request); |
| 192 | |
| 193 | void tegra_mipi_free(struct tegra_mipi_device *device) |
| 194 | { |
| 195 | platform_device_put(device->pdev); |
| 196 | kfree(device); |
| 197 | } |
| 198 | EXPORT_SYMBOL(tegra_mipi_free); |
| 199 | |
| 200 | static int tegra_mipi_wait(struct tegra_mipi *mipi) |
| 201 | { |
| 202 | unsigned long timeout = jiffies + msecs_to_jiffies(250); |
Thierry Reding | 57b17ae | 2014-10-02 14:33:31 +0200 | [diff] [blame] | 203 | u32 value; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 204 | |
| 205 | while (time_before(jiffies, timeout)) { |
| 206 | value = tegra_mipi_readl(mipi, MIPI_CAL_STATUS); |
| 207 | if ((value & MIPI_CAL_STATUS_ACTIVE) == 0 && |
| 208 | (value & MIPI_CAL_STATUS_DONE) != 0) |
| 209 | return 0; |
| 210 | |
| 211 | usleep_range(10, 50); |
| 212 | } |
| 213 | |
| 214 | return -ETIMEDOUT; |
| 215 | } |
| 216 | |
| 217 | int tegra_mipi_calibrate(struct tegra_mipi_device *device) |
| 218 | { |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 219 | const struct tegra_mipi_soc *soc = device->mipi->soc; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 220 | unsigned int i; |
Thierry Reding | 57b17ae | 2014-10-02 14:33:31 +0200 | [diff] [blame] | 221 | u32 value; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 222 | int err; |
| 223 | |
| 224 | err = clk_enable(device->mipi->clk); |
| 225 | if (err < 0) |
| 226 | return err; |
| 227 | |
| 228 | mutex_lock(&device->mipi->lock); |
| 229 | |
| 230 | value = tegra_mipi_readl(device->mipi, MIPI_CAL_BIAS_PAD_CFG0); |
| 231 | value &= ~MIPI_CAL_BIAS_PAD_PDVCLAMP; |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 232 | |
| 233 | if (soc->needs_vclamp_ref) |
| 234 | value |= MIPI_CAL_BIAS_PAD_E_VCLAMP_REF; |
| 235 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 236 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG0); |
| 237 | |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 238 | value = MIPI_CAL_BIAS_PAD_DRV_DN_REF(soc->pad_drive_down_ref) | |
| 239 | MIPI_CAL_BIAS_PAD_DRV_UP_REF(soc->pad_drive_up_ref); |
| 240 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG1); |
Sean Paul | b298e98 | 2014-09-10 10:52:05 -0400 | [diff] [blame] | 241 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 242 | value = tegra_mipi_readl(device->mipi, MIPI_CAL_BIAS_PAD_CFG2); |
| 243 | value &= ~MIPI_CAL_BIAS_PAD_PDVREG; |
| 244 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG2); |
| 245 | |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 246 | value = tegra_mipi_readl(device->mipi, MIPI_CAL_BIAS_PAD_CFG2); |
| 247 | value &= ~MIPI_CAL_BIAS_PAD_VCLAMP(0x7); |
| 248 | value &= ~MIPI_CAL_BIAS_PAD_VAUXP(0x7); |
| 249 | value |= MIPI_CAL_BIAS_PAD_VCLAMP(soc->pad_vclamp_level); |
| 250 | value |= MIPI_CAL_BIAS_PAD_VAUXP(soc->pad_vauxp_level); |
| 251 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_BIAS_PAD_CFG2); |
| 252 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 253 | for (i = 0; i < soc->num_pads; i++) { |
| 254 | u32 clk = 0, data = 0; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 255 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 256 | if (device->pads & BIT(i)) { |
| 257 | data = MIPI_CAL_CONFIG_SELECT | |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 258 | MIPI_CAL_CONFIG_HSPDOS(soc->hspdos) | |
| 259 | MIPI_CAL_CONFIG_HSPUOS(soc->hspuos) | |
| 260 | MIPI_CAL_CONFIG_TERMOS(soc->termos); |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 261 | clk = MIPI_CAL_CONFIG_SELECT | |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 262 | MIPI_CAL_CONFIG_HSCLKPDOSD(soc->hsclkpdos) | |
| 263 | MIPI_CAL_CONFIG_HSCLKPUOSD(soc->hsclkpuos); |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | tegra_mipi_writel(device->mipi, data, soc->pads[i].data); |
| 267 | |
Thierry Reding | 5e77524 | 2015-04-08 17:23:20 +0200 | [diff] [blame^] | 268 | if (soc->has_clk_lane && soc->pads[i].clk != 0) |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 269 | tegra_mipi_writel(device->mipi, clk, soc->pads[i].clk); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Sean Paul | 26f7a92 | 2014-09-10 10:52:03 -0400 | [diff] [blame] | 272 | value = tegra_mipi_readl(device->mipi, MIPI_CAL_CTRL); |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 273 | value &= ~MIPI_CAL_CTRL_NOISE_FILTER(0xf); |
| 274 | value &= ~MIPI_CAL_CTRL_PRESCALE(0x3); |
| 275 | value |= MIPI_CAL_CTRL_NOISE_FILTER(0xa); |
| 276 | value |= MIPI_CAL_CTRL_PRESCALE(0x2); |
| 277 | |
| 278 | if (!soc->clock_enable_override) |
| 279 | value &= ~MIPI_CAL_CTRL_CLKEN_OVR; |
| 280 | else |
| 281 | value |= MIPI_CAL_CTRL_CLKEN_OVR; |
| 282 | |
| 283 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL); |
| 284 | |
Thierry Reding | 2ed264b | 2015-04-08 17:17:44 +0200 | [diff] [blame] | 285 | /* clear any pending status bits */ |
| 286 | value = tegra_mipi_readl(device->mipi, MIPI_CAL_STATUS); |
| 287 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_STATUS); |
| 288 | |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 289 | value = tegra_mipi_readl(device->mipi, MIPI_CAL_CTRL); |
Sean Paul | 26f7a92 | 2014-09-10 10:52:03 -0400 | [diff] [blame] | 290 | value |= MIPI_CAL_CTRL_START; |
| 291 | tegra_mipi_writel(device->mipi, value, MIPI_CAL_CTRL); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 292 | |
| 293 | err = tegra_mipi_wait(device->mipi); |
| 294 | |
| 295 | mutex_unlock(&device->mipi->lock); |
| 296 | clk_disable(device->mipi->clk); |
| 297 | |
| 298 | return err; |
| 299 | } |
| 300 | EXPORT_SYMBOL(tegra_mipi_calibrate); |
| 301 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 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 | |
| 314 | static const struct tegra_mipi_soc tegra114_mipi_soc = { |
| 315 | .has_clk_lane = false, |
| 316 | .pads = tegra114_mipi_pads, |
| 317 | .num_pads = ARRAY_SIZE(tegra114_mipi_pads), |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 318 | .clock_enable_override = true, |
| 319 | .needs_vclamp_ref = true, |
| 320 | .pad_drive_down_ref = 0x2, |
| 321 | .pad_drive_up_ref = 0x0, |
| 322 | .pad_vclamp_level = 0x0, |
| 323 | .pad_vauxp_level = 0x0, |
| 324 | .hspdos = 0x0, |
| 325 | .hspuos = 0x4, |
| 326 | .termos = 0x5, |
| 327 | .hsclkpdos = 0x0, |
| 328 | .hsclkpuos = 0x4, |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | static const struct tegra_mipi_pad tegra124_mipi_pads[] = { |
| 332 | { .data = MIPI_CAL_CONFIG_CSIA, .clk = MIPI_CAL_CONFIG_CSIAB_CLK }, |
| 333 | { .data = MIPI_CAL_CONFIG_CSIB, .clk = MIPI_CAL_CONFIG_CSIAB_CLK }, |
| 334 | { .data = MIPI_CAL_CONFIG_CSIC, .clk = MIPI_CAL_CONFIG_CSICD_CLK }, |
| 335 | { .data = MIPI_CAL_CONFIG_CSID, .clk = MIPI_CAL_CONFIG_CSICD_CLK }, |
Thierry Reding | 8ed5c06 | 2015-04-08 17:06:08 +0200 | [diff] [blame] | 336 | { .data = MIPI_CAL_CONFIG_CSIE, .clk = MIPI_CAL_CONFIG_CSIE_CLK }, |
| 337 | { .data = MIPI_CAL_CONFIG_DSIA, .clk = MIPI_CAL_CONFIG_DSIA_CLK }, |
| 338 | { .data = MIPI_CAL_CONFIG_DSIB, .clk = MIPI_CAL_CONFIG_DSIB_CLK }, |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | static const struct tegra_mipi_soc tegra124_mipi_soc = { |
| 342 | .has_clk_lane = true, |
| 343 | .pads = tegra124_mipi_pads, |
| 344 | .num_pads = ARRAY_SIZE(tegra124_mipi_pads), |
Thierry Reding | 83a3c22 | 2015-04-08 17:03:49 +0200 | [diff] [blame] | 345 | .clock_enable_override = true, |
| 346 | .needs_vclamp_ref = true, |
| 347 | .pad_drive_down_ref = 0x2, |
| 348 | .pad_drive_up_ref = 0x0, |
| 349 | .pad_vclamp_level = 0x0, |
| 350 | .pad_vauxp_level = 0x0, |
| 351 | .hspdos = 0x0, |
| 352 | .hspuos = 0x0, |
| 353 | .termos = 0x0, |
| 354 | .hsclkpdos = 0x1, |
| 355 | .hsclkpuos = 0x2, |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 356 | }; |
| 357 | |
Thierry Reding | 7fd3eca | 2015-04-08 17:20:32 +0200 | [diff] [blame] | 358 | static const struct tegra_mipi_soc tegra132_mipi_soc = { |
| 359 | .has_clk_lane = true, |
| 360 | .pads = tegra124_mipi_pads, |
| 361 | .num_pads = ARRAY_SIZE(tegra124_mipi_pads), |
| 362 | .clock_enable_override = false, |
| 363 | .needs_vclamp_ref = false, |
| 364 | .pad_drive_down_ref = 0x0, |
| 365 | .pad_drive_up_ref = 0x3, |
| 366 | .pad_vclamp_level = 0x0, |
| 367 | .pad_vauxp_level = 0x0, |
| 368 | .hspdos = 0x0, |
| 369 | .hspuos = 0x0, |
| 370 | .termos = 0x0, |
| 371 | .hsclkpdos = 0x3, |
| 372 | .hsclkpuos = 0x2, |
| 373 | }; |
| 374 | |
Thierry Reding | 5e77524 | 2015-04-08 17:23:20 +0200 | [diff] [blame^] | 375 | static const struct tegra_mipi_pad tegra210_mipi_pads[] = { |
| 376 | { .data = MIPI_CAL_CONFIG_CSIA, .clk = 0 }, |
| 377 | { .data = MIPI_CAL_CONFIG_CSIB, .clk = 0 }, |
| 378 | { .data = MIPI_CAL_CONFIG_CSIC, .clk = 0 }, |
| 379 | { .data = MIPI_CAL_CONFIG_CSID, .clk = 0 }, |
| 380 | { .data = MIPI_CAL_CONFIG_CSIE, .clk = 0 }, |
| 381 | { .data = MIPI_CAL_CONFIG_CSIF, .clk = 0 }, |
| 382 | { .data = MIPI_CAL_CONFIG_DSIA, .clk = MIPI_CAL_CONFIG_DSIA_CLK }, |
| 383 | { .data = MIPI_CAL_CONFIG_DSIB, .clk = MIPI_CAL_CONFIG_DSIB_CLK }, |
| 384 | { .data = MIPI_CAL_CONFIG_DSIC, .clk = MIPI_CAL_CONFIG_DSIC_CLK }, |
| 385 | { .data = MIPI_CAL_CONFIG_DSID, .clk = MIPI_CAL_CONFIG_DSID_CLK }, |
| 386 | }; |
| 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 | |
Thierry Reding | c22fb79 | 2015-04-08 17:19:19 +0200 | [diff] [blame] | 405 | static const struct of_device_id tegra_mipi_of_match[] = { |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 406 | { .compatible = "nvidia,tegra114-mipi", .data = &tegra114_mipi_soc }, |
| 407 | { .compatible = "nvidia,tegra124-mipi", .data = &tegra124_mipi_soc }, |
Thierry Reding | 7fd3eca | 2015-04-08 17:20:32 +0200 | [diff] [blame] | 408 | { .compatible = "nvidia,tegra132-mipi", .data = &tegra132_mipi_soc }, |
Thierry Reding | 5e77524 | 2015-04-08 17:23:20 +0200 | [diff] [blame^] | 409 | { .compatible = "nvidia,tegra210-mipi", .data = &tegra210_mipi_soc }, |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 410 | { }, |
| 411 | }; |
| 412 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 413 | static int tegra_mipi_probe(struct platform_device *pdev) |
| 414 | { |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 415 | const struct of_device_id *match; |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 416 | struct tegra_mipi *mipi; |
| 417 | struct resource *res; |
| 418 | int err; |
| 419 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 420 | match = of_match_node(tegra_mipi_of_match, pdev->dev.of_node); |
| 421 | if (!match) |
| 422 | return -ENODEV; |
| 423 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 424 | mipi = devm_kzalloc(&pdev->dev, sizeof(*mipi), GFP_KERNEL); |
| 425 | if (!mipi) |
| 426 | return -ENOMEM; |
| 427 | |
Sean Paul | 08a15cc | 2014-09-10 10:52:04 -0400 | [diff] [blame] | 428 | mipi->soc = match->data; |
| 429 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 430 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 431 | mipi->regs = devm_ioremap_resource(&pdev->dev, res); |
| 432 | if (IS_ERR(mipi->regs)) |
| 433 | return PTR_ERR(mipi->regs); |
| 434 | |
| 435 | mutex_init(&mipi->lock); |
| 436 | |
| 437 | mipi->clk = devm_clk_get(&pdev->dev, NULL); |
| 438 | if (IS_ERR(mipi->clk)) { |
| 439 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 440 | return PTR_ERR(mipi->clk); |
| 441 | } |
| 442 | |
| 443 | err = clk_prepare(mipi->clk); |
| 444 | if (err < 0) |
| 445 | return err; |
| 446 | |
| 447 | platform_set_drvdata(pdev, mipi); |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int tegra_mipi_remove(struct platform_device *pdev) |
| 453 | { |
| 454 | struct tegra_mipi *mipi = platform_get_drvdata(pdev); |
| 455 | |
| 456 | clk_unprepare(mipi->clk); |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 461 | struct platform_driver tegra_mipi_driver = { |
| 462 | .driver = { |
| 463 | .name = "tegra-mipi", |
| 464 | .of_match_table = tegra_mipi_of_match, |
| 465 | }, |
| 466 | .probe = tegra_mipi_probe, |
| 467 | .remove = tegra_mipi_remove, |
| 468 | }; |