Lines Matching full:i2c
7 * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors.
16 #include <linux/i2c.h>
27 #include "i2c-octeon-core.h"
29 #define DRV_NAME "i2c-octeon"
33 * @i2c: The struct octeon_i2c
38 static void octeon_i2c_int_enable(struct octeon_i2c *i2c) in octeon_i2c_int_enable() argument
40 octeon_i2c_write_int(i2c, TWSI_INT_CORE_EN); in octeon_i2c_int_enable()
44 static void octeon_i2c_int_disable(struct octeon_i2c *i2c) in octeon_i2c_int_disable() argument
47 octeon_i2c_write_int(i2c, 0); in octeon_i2c_int_disable()
52 * @i2c: The struct octeon_i2c
57 static void octeon_i2c_int_enable78(struct octeon_i2c *i2c) in octeon_i2c_int_enable78() argument
59 atomic_inc_return(&i2c->int_enable_cnt); in octeon_i2c_int_enable78()
60 enable_irq(i2c->irq); in octeon_i2c_int_enable78()
78 static void octeon_i2c_int_disable78(struct octeon_i2c *i2c) in octeon_i2c_int_disable78() argument
80 __octeon_i2c_irq_disable(&i2c->int_enable_cnt, i2c->irq); in octeon_i2c_int_disable78()
85 * @i2c: The struct octeon_i2c
90 static void octeon_i2c_hlc_int_enable78(struct octeon_i2c *i2c) in octeon_i2c_hlc_int_enable78() argument
92 atomic_inc_return(&i2c->hlc_int_enable_cnt); in octeon_i2c_hlc_int_enable78()
93 enable_irq(i2c->hlc_irq); in octeon_i2c_hlc_int_enable78()
97 static void octeon_i2c_hlc_int_disable78(struct octeon_i2c *i2c) in octeon_i2c_hlc_int_disable78() argument
99 __octeon_i2c_irq_disable(&i2c->hlc_int_enable_cnt, i2c->hlc_irq); in octeon_i2c_hlc_int_disable78()
105 struct octeon_i2c *i2c = dev_id; in octeon_i2c_hlc_isr78() local
107 i2c->hlc_int_disable(i2c); in octeon_i2c_hlc_isr78()
108 wake_up(&i2c->queue); in octeon_i2c_hlc_isr78()
113 static void octeon_i2c_hlc_int_enable(struct octeon_i2c *i2c) in octeon_i2c_hlc_int_enable() argument
115 octeon_i2c_write_int(i2c, TWSI_INT_ST_EN); in octeon_i2c_hlc_int_enable()
139 struct octeon_i2c *i2c; in octeon_i2c_probe() local
158 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); in octeon_i2c_probe()
159 if (!i2c) { in octeon_i2c_probe()
163 i2c->dev = &pdev->dev; in octeon_i2c_probe()
165 i2c->roff.sw_twsi = 0x00; in octeon_i2c_probe()
166 i2c->roff.twsi_int = 0x10; in octeon_i2c_probe()
167 i2c->roff.sw_twsi_ext = 0x18; in octeon_i2c_probe()
169 i2c->twsi_base = devm_platform_ioremap_resource(pdev, 0); in octeon_i2c_probe()
170 if (IS_ERR(i2c->twsi_base)) { in octeon_i2c_probe()
171 result = PTR_ERR(i2c->twsi_base); in octeon_i2c_probe()
180 if (of_property_read_u32(node, "clock-frequency", &i2c->twsi_freq) && in octeon_i2c_probe()
181 of_property_read_u32(node, "clock-rate", &i2c->twsi_freq)) { in octeon_i2c_probe()
182 dev_err(i2c->dev, in octeon_i2c_probe()
183 "no I2C 'clock-rate' or 'clock-frequency' property\n"); in octeon_i2c_probe()
188 i2c->sys_freq = octeon_get_io_clock_rate(); in octeon_i2c_probe()
190 init_waitqueue_head(&i2c->queue); in octeon_i2c_probe()
192 i2c->irq = irq; in octeon_i2c_probe()
195 i2c->hlc_irq = hlc_irq; in octeon_i2c_probe()
197 i2c->int_enable = octeon_i2c_int_enable78; in octeon_i2c_probe()
198 i2c->int_disable = octeon_i2c_int_disable78; in octeon_i2c_probe()
199 i2c->hlc_int_enable = octeon_i2c_hlc_int_enable78; in octeon_i2c_probe()
200 i2c->hlc_int_disable = octeon_i2c_hlc_int_disable78; in octeon_i2c_probe()
202 irq_set_status_flags(i2c->irq, IRQ_NOAUTOEN); in octeon_i2c_probe()
203 irq_set_status_flags(i2c->hlc_irq, IRQ_NOAUTOEN); in octeon_i2c_probe()
205 result = devm_request_irq(&pdev->dev, i2c->hlc_irq, in octeon_i2c_probe()
207 DRV_NAME, i2c); in octeon_i2c_probe()
209 dev_err(i2c->dev, "failed to attach interrupt\n"); in octeon_i2c_probe()
213 i2c->int_enable = octeon_i2c_int_enable; in octeon_i2c_probe()
214 i2c->int_disable = octeon_i2c_int_disable; in octeon_i2c_probe()
215 i2c->hlc_int_enable = octeon_i2c_hlc_int_enable; in octeon_i2c_probe()
216 i2c->hlc_int_disable = octeon_i2c_int_disable; in octeon_i2c_probe()
219 result = devm_request_irq(&pdev->dev, i2c->irq, in octeon_i2c_probe()
220 octeon_i2c_isr, 0, DRV_NAME, i2c); in octeon_i2c_probe()
222 dev_err(i2c->dev, "failed to attach interrupt\n"); in octeon_i2c_probe()
227 i2c->broken_irq_check = true; in octeon_i2c_probe()
229 result = octeon_i2c_init_lowlevel(i2c); in octeon_i2c_probe()
231 dev_err(i2c->dev, "init low level failed\n"); in octeon_i2c_probe()
235 octeon_i2c_set_clock(i2c); in octeon_i2c_probe()
237 i2c->adap = octeon_i2c_ops; in octeon_i2c_probe()
238 i2c->adap.timeout = msecs_to_jiffies(2); in octeon_i2c_probe()
239 i2c->adap.retries = 5; in octeon_i2c_probe()
240 i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info; in octeon_i2c_probe()
241 i2c->adap.dev.parent = &pdev->dev; in octeon_i2c_probe()
242 i2c->adap.dev.of_node = node; in octeon_i2c_probe()
243 i2c_set_adapdata(&i2c->adap, i2c); in octeon_i2c_probe()
244 platform_set_drvdata(pdev, i2c); in octeon_i2c_probe()
246 result = i2c_add_adapter(&i2c->adap); in octeon_i2c_probe()
249 dev_info(i2c->dev, "probed\n"); in octeon_i2c_probe()
258 struct octeon_i2c *i2c = platform_get_drvdata(pdev); in octeon_i2c_remove() local
260 i2c_del_adapter(&i2c->adap); in octeon_i2c_remove()
283 MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");