Lines Matching full:i2c
2 * Cavium ThunderX i2c driver.
16 #include <linux/i2c.h>
17 #include <linux/i2c-smbus.h>
24 #include "i2c-octeon-core.h"
26 #define DRV_NAME "i2c-thunderx"
40 static void thunder_i2c_int_enable(struct octeon_i2c *i2c) in thunder_i2c_int_enable() argument
43 i2c->twsi_base + TWSI_INT_ENA_W1S); in thunder_i2c_int_enable()
49 static void thunder_i2c_int_disable(struct octeon_i2c *i2c) in thunder_i2c_int_disable() argument
52 i2c->twsi_base + TWSI_INT_ENA_W1C); in thunder_i2c_int_disable()
55 static void thunder_i2c_hlc_int_enable(struct octeon_i2c *i2c) in thunder_i2c_hlc_int_enable() argument
58 i2c->twsi_base + TWSI_INT_ENA_W1S); in thunder_i2c_hlc_int_enable()
61 static void thunder_i2c_hlc_int_disable(struct octeon_i2c *i2c) in thunder_i2c_hlc_int_disable() argument
64 i2c->twsi_base + TWSI_INT_ENA_W1C); in thunder_i2c_hlc_int_disable()
84 static void thunder_i2c_clock_enable(struct device *dev, struct octeon_i2c *i2c) in thunder_i2c_clock_enable() argument
90 i2c->clk = clk_get(dev, NULL); in thunder_i2c_clock_enable()
91 if (IS_ERR(i2c->clk)) { in thunder_i2c_clock_enable()
92 i2c->clk = NULL; in thunder_i2c_clock_enable()
96 ret = clk_prepare_enable(i2c->clk); in thunder_i2c_clock_enable()
99 i2c->sys_freq = clk_get_rate(i2c->clk); in thunder_i2c_clock_enable()
102 device_property_read_u32(dev, "sclk", &i2c->sys_freq); in thunder_i2c_clock_enable()
106 if (!i2c->sys_freq) in thunder_i2c_clock_enable()
107 i2c->sys_freq = SYS_FREQ_DEFAULT; in thunder_i2c_clock_enable()
118 static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c, in thunder_i2c_smbus_setup_of() argument
126 i2c->alert_data.irq = irq_of_parse_and_map(node, 0); in thunder_i2c_smbus_setup_of()
127 if (!i2c->alert_data.irq) in thunder_i2c_smbus_setup_of()
130 ara = i2c_new_smbus_alert_device(&i2c->adap, &i2c->alert_data); in thunder_i2c_smbus_setup_of()
134 i2c->ara = ara; in thunder_i2c_smbus_setup_of()
139 static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c, in thunder_i2c_smbus_setup() argument
146 return thunder_i2c_smbus_setup_of(i2c, node); in thunder_i2c_smbus_setup()
149 static void thunder_i2c_smbus_remove(struct octeon_i2c *i2c) in thunder_i2c_smbus_remove() argument
151 i2c_unregister_device(i2c->ara); in thunder_i2c_smbus_remove()
158 struct octeon_i2c *i2c; in thunder_i2c_probe_pci() local
161 i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); in thunder_i2c_probe_pci()
162 if (!i2c) in thunder_i2c_probe_pci()
165 i2c->roff.sw_twsi = 0x1000; in thunder_i2c_probe_pci()
166 i2c->roff.twsi_int = 0x1010; in thunder_i2c_probe_pci()
167 i2c->roff.sw_twsi_ext = 0x1018; in thunder_i2c_probe_pci()
169 i2c->dev = dev; in thunder_i2c_probe_pci()
170 pci_set_drvdata(pdev, i2c); in thunder_i2c_probe_pci()
179 i2c->twsi_base = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0)); in thunder_i2c_probe_pci()
180 if (!i2c->twsi_base) in thunder_i2c_probe_pci()
183 thunder_i2c_clock_enable(dev, i2c); in thunder_i2c_probe_pci()
184 ret = device_property_read_u32(dev, "clock-frequency", &i2c->twsi_freq); in thunder_i2c_probe_pci()
186 i2c->twsi_freq = I2C_MAX_STANDARD_MODE_FREQ; in thunder_i2c_probe_pci()
188 init_waitqueue_head(&i2c->queue); in thunder_i2c_probe_pci()
190 i2c->int_enable = thunder_i2c_int_enable; in thunder_i2c_probe_pci()
191 i2c->int_disable = thunder_i2c_int_disable; in thunder_i2c_probe_pci()
192 i2c->hlc_int_enable = thunder_i2c_hlc_int_enable; in thunder_i2c_probe_pci()
193 i2c->hlc_int_disable = thunder_i2c_hlc_int_disable; in thunder_i2c_probe_pci()
200 DRV_NAME, i2c); in thunder_i2c_probe_pci()
204 ret = octeon_i2c_init_lowlevel(i2c); in thunder_i2c_probe_pci()
208 octeon_i2c_set_clock(i2c); in thunder_i2c_probe_pci()
210 i2c->adap = thunderx_i2c_ops; in thunder_i2c_probe_pci()
211 i2c->adap.retries = 5; in thunder_i2c_probe_pci()
212 i2c->adap.class = I2C_CLASS_HWMON; in thunder_i2c_probe_pci()
213 i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info; in thunder_i2c_probe_pci()
214 i2c->adap.dev.parent = dev; in thunder_i2c_probe_pci()
215 i2c->adap.dev.of_node = pdev->dev.of_node; in thunder_i2c_probe_pci()
216 i2c->adap.dev.fwnode = dev->fwnode; in thunder_i2c_probe_pci()
217 snprintf(i2c->adap.name, sizeof(i2c->adap.name), in thunder_i2c_probe_pci()
218 "Cavium ThunderX i2c adapter at %s", dev_name(dev)); in thunder_i2c_probe_pci()
219 i2c_set_adapdata(&i2c->adap, i2c); in thunder_i2c_probe_pci()
221 ret = i2c_add_adapter(&i2c->adap); in thunder_i2c_probe_pci()
225 dev_info(i2c->dev, "Probed. Set system clock to %u\n", i2c->sys_freq); in thunder_i2c_probe_pci()
227 ret = thunder_i2c_smbus_setup(i2c, pdev->dev.of_node); in thunder_i2c_probe_pci()
234 thunder_i2c_clock_disable(dev, i2c->clk); in thunder_i2c_probe_pci()
240 struct octeon_i2c *i2c = pci_get_drvdata(pdev); in thunder_i2c_remove_pci() local
242 thunder_i2c_smbus_remove(i2c); in thunder_i2c_remove_pci()
243 thunder_i2c_clock_disable(&pdev->dev, i2c->clk); in thunder_i2c_remove_pci()
244 i2c_del_adapter(&i2c->adap); in thunder_i2c_remove_pci()
265 MODULE_DESCRIPTION("I2C-Bus adapter for Cavium ThunderX SOC");