Lines Matching +full:i2c +full:- +full:0
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"
28 #define PCI_DEVICE_ID_THUNDER_TWSI 0xa012
33 #define TWSI_INT_ENA_W1C 0x1028
34 #define TWSI_INT_ENA_W1S 0x1030
38 * The interrupt will be asserted when there is non-STAT_IDLE state in the
41 static void thunder_i2c_int_enable(struct octeon_i2c *i2c) in thunder_i2c_int_enable() argument
44 i2c->twsi_base + TWSI_INT_ENA_W1S); in thunder_i2c_int_enable()
50 static void thunder_i2c_int_disable(struct octeon_i2c *i2c) in thunder_i2c_int_disable() argument
53 i2c->twsi_base + TWSI_INT_ENA_W1C); in thunder_i2c_int_disable()
56 static void thunder_i2c_hlc_int_enable(struct octeon_i2c *i2c) in thunder_i2c_hlc_int_enable() argument
59 i2c->twsi_base + TWSI_INT_ENA_W1S); in thunder_i2c_hlc_int_enable()
62 static void thunder_i2c_hlc_int_disable(struct octeon_i2c *i2c) in thunder_i2c_hlc_int_disable() argument
65 i2c->twsi_base + TWSI_INT_ENA_W1C); in thunder_i2c_hlc_int_disable()
85 static void thunder_i2c_clock_enable(struct device *dev, struct octeon_i2c *i2c) in thunder_i2c_clock_enable() argument
91 i2c->clk = clk_get(dev, NULL); in thunder_i2c_clock_enable()
92 if (IS_ERR(i2c->clk)) { in thunder_i2c_clock_enable()
93 i2c->clk = NULL; in thunder_i2c_clock_enable()
97 ret = clk_prepare_enable(i2c->clk); in thunder_i2c_clock_enable()
100 i2c->sys_freq = clk_get_rate(i2c->clk); in thunder_i2c_clock_enable()
103 if (device_property_read_u32(dev, "sclk", &i2c->sys_freq)) in thunder_i2c_clock_enable()
104 device_property_read_u32(dev, "ioclk", &i2c->sys_freq); in thunder_i2c_clock_enable()
108 if (!i2c->sys_freq) in thunder_i2c_clock_enable()
109 i2c->sys_freq = SYS_FREQ_DEFAULT; in thunder_i2c_clock_enable()
120 static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c, in thunder_i2c_smbus_setup_of() argument
126 return -EINVAL; in thunder_i2c_smbus_setup_of()
128 i2c->alert_data.irq = irq_of_parse_and_map(node, 0); in thunder_i2c_smbus_setup_of()
129 if (!i2c->alert_data.irq) in thunder_i2c_smbus_setup_of()
130 return -EINVAL; in thunder_i2c_smbus_setup_of()
132 ara = i2c_new_smbus_alert_device(&i2c->adap, &i2c->alert_data); in thunder_i2c_smbus_setup_of()
136 i2c->ara = ara; in thunder_i2c_smbus_setup_of()
138 return 0; in thunder_i2c_smbus_setup_of()
141 static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c, in thunder_i2c_smbus_setup() argument
146 return -EOPNOTSUPP; in thunder_i2c_smbus_setup()
148 return thunder_i2c_smbus_setup_of(i2c, node); in thunder_i2c_smbus_setup()
151 static void thunder_i2c_smbus_remove(struct octeon_i2c *i2c) in thunder_i2c_smbus_remove() argument
153 i2c_unregister_device(i2c->ara); in thunder_i2c_smbus_remove()
159 struct device *dev = &pdev->dev; in thunder_i2c_probe_pci()
160 struct octeon_i2c *i2c; in thunder_i2c_probe_pci() local
163 i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); in thunder_i2c_probe_pci()
164 if (!i2c) in thunder_i2c_probe_pci()
165 return -ENOMEM; in thunder_i2c_probe_pci()
167 i2c->roff.sw_twsi = 0x1000; in thunder_i2c_probe_pci()
168 i2c->roff.twsi_int = 0x1010; in thunder_i2c_probe_pci()
169 i2c->roff.sw_twsi_ext = 0x1018; in thunder_i2c_probe_pci()
170 i2c->roff.mode = 0x1038; in thunder_i2c_probe_pci()
172 i2c->dev = dev; in thunder_i2c_probe_pci()
173 pci_set_drvdata(pdev, i2c); in thunder_i2c_probe_pci()
182 i2c->twsi_base = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0)); in thunder_i2c_probe_pci()
183 if (!i2c->twsi_base) in thunder_i2c_probe_pci()
184 return -EINVAL; in thunder_i2c_probe_pci()
186 thunder_i2c_clock_enable(dev, i2c); in thunder_i2c_probe_pci()
187 ret = device_property_read_u32(dev, "clock-frequency", &i2c->twsi_freq); in thunder_i2c_probe_pci()
189 i2c->twsi_freq = I2C_MAX_STANDARD_MODE_FREQ; in thunder_i2c_probe_pci()
191 init_waitqueue_head(&i2c->queue); in thunder_i2c_probe_pci()
193 i2c->int_enable = thunder_i2c_int_enable; in thunder_i2c_probe_pci()
194 i2c->int_disable = thunder_i2c_int_disable; in thunder_i2c_probe_pci()
195 i2c->hlc_int_enable = thunder_i2c_hlc_int_enable; in thunder_i2c_probe_pci()
196 i2c->hlc_int_disable = thunder_i2c_hlc_int_disable; in thunder_i2c_probe_pci()
199 if (ret < 0) in thunder_i2c_probe_pci()
202 ret = devm_request_irq(dev, pci_irq_vector(pdev, 0), octeon_i2c_isr, 0, in thunder_i2c_probe_pci()
203 DRV_NAME, i2c); in thunder_i2c_probe_pci()
207 ret = octeon_i2c_init_lowlevel(i2c); in thunder_i2c_probe_pci()
215 if (octeon_i2c_is_otx2(pdev) && IS_LS_FREQ(i2c->twsi_freq)) in thunder_i2c_probe_pci()
216 i2c->sys_freq = OTX2_REF_FREQ_DEFAULT; in thunder_i2c_probe_pci()
217 octeon_i2c_set_clock(i2c); in thunder_i2c_probe_pci()
219 i2c->adap = thunderx_i2c_ops; in thunder_i2c_probe_pci()
220 i2c->adap.retries = 5; in thunder_i2c_probe_pci()
221 i2c->adap.class = I2C_CLASS_HWMON; in thunder_i2c_probe_pci()
222 i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info; in thunder_i2c_probe_pci()
223 i2c->adap.dev.parent = dev; in thunder_i2c_probe_pci()
224 i2c->adap.dev.of_node = pdev->dev.of_node; in thunder_i2c_probe_pci()
225 i2c->adap.dev.fwnode = dev->fwnode; in thunder_i2c_probe_pci()
226 snprintf(i2c->adap.name, sizeof(i2c->adap.name), in thunder_i2c_probe_pci()
227 "Cavium ThunderX i2c adapter at %s", dev_name(dev)); in thunder_i2c_probe_pci()
228 i2c_set_adapdata(&i2c->adap, i2c); in thunder_i2c_probe_pci()
230 ret = i2c_add_adapter(&i2c->adap); in thunder_i2c_probe_pci()
234 dev_info(i2c->dev, "Probed. Set system clock to %u\n", i2c->sys_freq); in thunder_i2c_probe_pci()
236 ret = thunder_i2c_smbus_setup(i2c, pdev->dev.of_node); in thunder_i2c_probe_pci()
240 return 0; in thunder_i2c_probe_pci()
243 thunder_i2c_clock_disable(dev, i2c->clk); in thunder_i2c_probe_pci()
249 struct octeon_i2c *i2c = pci_get_drvdata(pdev); in thunder_i2c_remove_pci() local
251 thunder_i2c_smbus_remove(i2c); in thunder_i2c_remove_pci()
252 thunder_i2c_clock_disable(&pdev->dev, i2c->clk); in thunder_i2c_remove_pci()
253 i2c_del_adapter(&i2c->adap); in thunder_i2c_remove_pci()
258 { 0, }
274 MODULE_DESCRIPTION("I2C-Bus adapter for Cavium ThunderX SOC");