16 #include <linux/kernel.h>
17 #include <linux/module.h>
19 #include <linux/errno.h>
21 #include <linux/i2c.h>
23 #include <linux/wait.h>
25 #include <linux/slab.h>
44 #define OCI2C_PRELOW 0
45 #define OCI2C_PREHIGH 1
46 #define OCI2C_CONTROL 2
49 #define OCI2C_STATUS 4
51 #define OCI2C_CTRL_IEN 0x40
52 #define OCI2C_CTRL_EN 0x80
54 #define OCI2C_CMD_START 0x91
55 #define OCI2C_CMD_STOP 0x41
56 #define OCI2C_CMD_READ 0x21
57 #define OCI2C_CMD_WRITE 0x11
58 #define OCI2C_CMD_READ_ACK 0x21
59 #define OCI2C_CMD_READ_NACK 0x29
60 #define OCI2C_CMD_IACK 0x01
62 #define OCI2C_STAT_IF 0x01
63 #define OCI2C_STAT_TIP 0x02
64 #define OCI2C_STAT_ARBLOST 0x20
65 #define OCI2C_STAT_BUSY 0x40
66 #define OCI2C_STAT_NACK 0x80
94 static void ocores_process(
struct ocores_i2c *i2c)
126 if (i2c->
pos == msg->
len) {
175 struct ocores_i2c *i2c = i2c_get_adapdata(adap);
183 (i2c->
msg->addr << 1) |
195 static void ocores_init(
struct ocores_i2c *i2c)
203 prescale = (i2c->
clock_khz / (5*100)) - 1;
219 .master_xfer = ocores_xfer,
220 .functionality = ocores_func,
225 .name =
"i2c-ocores",
227 .algo = &ocores_algorithm,
237 if (of_property_read_u32(np,
"reg-shift", &i2c->
reg_shift)) {
239 if (!of_property_read_u32(np,
"regstep", &val)) {
247 "regstep property deprecated, use reg-shift\n");
251 if (of_property_read_u32(np,
"clock-frequency", &val)) {
253 "Missing required parameter 'clock-frequency'\n");
258 of_property_read_u32(pdev->
dev.of_node,
"reg-io-width",
263 #define ocores_i2c_of_probe(pdev,i2c) -ENODEV
287 resource_size(res), pdev->
name)) {
295 dev_err(&pdev->
dev,
"Unable to map registers\n");
299 pdata = pdev->
dev.platform_data;
316 ret = devm_request_irq(&pdev->
dev, res2->
start, ocores_isr, 0,
324 platform_set_drvdata(pdev, i2c);
325 i2c->
adap = ocores_adapter;
326 i2c_set_adapdata(&i2c->
adap, i2c);
327 i2c->
adap.dev.parent = &pdev->
dev;
328 i2c->
adap.dev.of_node = pdev->
dev.of_node;
333 dev_err(&pdev->
dev,
"Failed to add adapter\n");
350 struct ocores_i2c *i2c = platform_get_drvdata(pdev);
358 platform_set_drvdata(pdev,
NULL);
364 static int ocores_i2c_suspend(
struct device *
dev)
375 static int ocores_i2c_resume(
struct device *dev)
385 #define OCORES_I2C_PM (&ocores_i2c_pm)
387 #define OCORES_I2C_PM NULL
391 { .compatible =
"opencores,i2c-ocores", },
397 .probe = ocores_i2c_probe,
401 .name =
"ocores-i2c",
402 .of_match_table = ocores_i2c_match,