.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License as published by |
---|
6 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
7 | | - * (at your option) any later version. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | | - * GNU General Public License for more details. |
---|
13 | 4 | */ |
---|
14 | 5 | |
---|
15 | 6 | #include <linux/clk.h> |
---|
.. | .. |
---|
44 | 35 | #define UNIPHIER_I2C_NOISE 0x1c /* noise filter control */ |
---|
45 | 36 | #define UNIPHIER_I2C_SETUP 0x20 /* setup time control */ |
---|
46 | 37 | |
---|
47 | | -#define UNIPHIER_I2C_DEFAULT_SPEED 100000 |
---|
48 | | -#define UNIPHIER_I2C_MAX_SPEED 400000 |
---|
49 | | - |
---|
50 | 38 | struct uniphier_i2c_priv { |
---|
51 | 39 | struct completion comp; |
---|
52 | 40 | struct i2c_adapter adap; |
---|
.. | .. |
---|
80 | 68 | reinit_completion(&priv->comp); |
---|
81 | 69 | |
---|
82 | 70 | txdata |= UNIPHIER_I2C_DTRM_IRQEN; |
---|
83 | | - dev_dbg(&adap->dev, "write data: 0x%04x\n", txdata); |
---|
84 | 71 | writel(txdata, priv->membase + UNIPHIER_I2C_DTRM); |
---|
85 | 72 | |
---|
86 | 73 | time_left = wait_for_completion_timeout(&priv->comp, adap->timeout); |
---|
.. | .. |
---|
90 | 77 | } |
---|
91 | 78 | |
---|
92 | 79 | rxdata = readl(priv->membase + UNIPHIER_I2C_DREC); |
---|
93 | | - dev_dbg(&adap->dev, "read data: 0x%04x\n", rxdata); |
---|
94 | | - |
---|
95 | 80 | if (rxdatap) |
---|
96 | 81 | *rxdatap = rxdata; |
---|
97 | 82 | |
---|
.. | .. |
---|
107 | 92 | if (ret) |
---|
108 | 93 | return ret; |
---|
109 | 94 | |
---|
110 | | - if (unlikely(rxdata & UNIPHIER_I2C_DREC_LAB)) { |
---|
111 | | - dev_dbg(&adap->dev, "arbitration lost\n"); |
---|
| 95 | + if (unlikely(rxdata & UNIPHIER_I2C_DREC_LAB)) |
---|
112 | 96 | return -EAGAIN; |
---|
113 | | - } |
---|
114 | | - if (unlikely(rxdata & UNIPHIER_I2C_DREC_LRB)) { |
---|
115 | | - dev_dbg(&adap->dev, "could not get ACK\n"); |
---|
| 97 | + |
---|
| 98 | + if (unlikely(rxdata & UNIPHIER_I2C_DREC_LRB)) |
---|
116 | 99 | return -ENXIO; |
---|
117 | | - } |
---|
118 | 100 | |
---|
119 | 101 | return 0; |
---|
120 | 102 | } |
---|
.. | .. |
---|
124 | 106 | { |
---|
125 | 107 | int ret; |
---|
126 | 108 | |
---|
127 | | - dev_dbg(&adap->dev, "start condition\n"); |
---|
128 | 109 | ret = uniphier_i2c_send_byte(adap, addr << 1 | |
---|
129 | 110 | UNIPHIER_I2C_DTRM_STA | |
---|
130 | 111 | UNIPHIER_I2C_DTRM_NACK); |
---|
.. | .. |
---|
146 | 127 | { |
---|
147 | 128 | int ret; |
---|
148 | 129 | |
---|
149 | | - dev_dbg(&adap->dev, "start condition\n"); |
---|
150 | 130 | ret = uniphier_i2c_send_byte(adap, addr << 1 | |
---|
151 | 131 | UNIPHIER_I2C_DTRM_STA | |
---|
152 | 132 | UNIPHIER_I2C_DTRM_NACK | |
---|
.. | .. |
---|
170 | 150 | |
---|
171 | 151 | static int uniphier_i2c_stop(struct i2c_adapter *adap) |
---|
172 | 152 | { |
---|
173 | | - dev_dbg(&adap->dev, "stop condition\n"); |
---|
174 | 153 | return uniphier_i2c_send_byte(adap, UNIPHIER_I2C_DTRM_STO | |
---|
175 | 154 | UNIPHIER_I2C_DTRM_NACK); |
---|
176 | 155 | } |
---|
.. | .. |
---|
181 | 160 | bool is_read = msg->flags & I2C_M_RD; |
---|
182 | 161 | bool recovery = false; |
---|
183 | 162 | int ret; |
---|
184 | | - |
---|
185 | | - dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n", |
---|
186 | | - is_read ? "receive" : "transmit", msg->addr, msg->len, stop); |
---|
187 | 163 | |
---|
188 | 164 | if (is_read) |
---|
189 | 165 | ret = uniphier_i2c_rx(adap, msg->addr, msg->len, msg->buf); |
---|
.. | .. |
---|
335 | 311 | { |
---|
336 | 312 | struct device *dev = &pdev->dev; |
---|
337 | 313 | struct uniphier_i2c_priv *priv; |
---|
338 | | - struct resource *regs; |
---|
339 | 314 | u32 bus_speed; |
---|
340 | 315 | unsigned long clk_rate; |
---|
341 | 316 | int irq, ret; |
---|
.. | .. |
---|
344 | 319 | if (!priv) |
---|
345 | 320 | return -ENOMEM; |
---|
346 | 321 | |
---|
347 | | - regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
348 | | - priv->membase = devm_ioremap_resource(dev, regs); |
---|
| 322 | + priv->membase = devm_platform_ioremap_resource(pdev, 0); |
---|
349 | 323 | if (IS_ERR(priv->membase)) |
---|
350 | 324 | return PTR_ERR(priv->membase); |
---|
351 | 325 | |
---|
352 | 326 | irq = platform_get_irq(pdev, 0); |
---|
353 | | - if (irq < 0) { |
---|
354 | | - dev_err(dev, "failed to get IRQ number\n"); |
---|
| 327 | + if (irq < 0) |
---|
355 | 328 | return irq; |
---|
356 | | - } |
---|
357 | 329 | |
---|
358 | 330 | if (of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed)) |
---|
359 | | - bus_speed = UNIPHIER_I2C_DEFAULT_SPEED; |
---|
| 331 | + bus_speed = I2C_MAX_STANDARD_MODE_FREQ; |
---|
360 | 332 | |
---|
361 | | - if (!bus_speed || bus_speed > UNIPHIER_I2C_MAX_SPEED) { |
---|
| 333 | + if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) { |
---|
362 | 334 | dev_err(dev, "invalid clock-frequency %d\n", bus_speed); |
---|
363 | 335 | return -EINVAL; |
---|
364 | 336 | } |
---|