10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
14 #include <linux/i2c.h>
19 #define SIRFSOC_I2C_CLK_CTRL 0x00
20 #define SIRFSOC_I2C_STATUS 0x0C
21 #define SIRFSOC_I2C_CTRL 0x10
22 #define SIRFSOC_I2C_IO_CTRL 0x14
23 #define SIRFSOC_I2C_SDA_DELAY 0x18
24 #define SIRFSOC_I2C_CMD_START 0x1C
25 #define SIRFSOC_I2C_CMD_BUF 0x30
26 #define SIRFSOC_I2C_DATA_BUF 0x80
28 #define SIRFSOC_I2C_CMD_BUF_MAX 16
29 #define SIRFSOC_I2C_DATA_BUF_MAX 16
31 #define SIRFSOC_I2C_CMD(x) (SIRFSOC_I2C_CMD_BUF + (x)*0x04)
32 #define SIRFSOC_I2C_DATA_MASK(x) (0xFF<<(((x)&3)*8))
33 #define SIRFSOC_I2C_DATA_SHIFT(x) (((x)&3)*8)
35 #define SIRFSOC_I2C_DIV_MASK (0xFFFF)
38 #define SIRFSOC_I2C_STAT_BUSY BIT(0)
39 #define SIRFSOC_I2C_STAT_TIP BIT(1)
40 #define SIRFSOC_I2C_STAT_NACK BIT(2)
41 #define SIRFSOC_I2C_STAT_TR_INT BIT(4)
42 #define SIRFSOC_I2C_STAT_STOP BIT(6)
43 #define SIRFSOC_I2C_STAT_CMD_DONE BIT(8)
44 #define SIRFSOC_I2C_STAT_ERR BIT(9)
45 #define SIRFSOC_I2C_CMD_INDEX (0x1F<<16)
48 #define SIRFSOC_I2C_RESET BIT(0)
49 #define SIRFSOC_I2C_CORE_EN BIT(1)
50 #define SIRFSOC_I2C_MASTER_MODE BIT(2)
51 #define SIRFSOC_I2C_CMD_DONE_EN BIT(11)
52 #define SIRFSOC_I2C_ERR_INT_EN BIT(12)
54 #define SIRFSOC_I2C_SDA_DELAY_MASK (0xFF)
55 #define SIRFSOC_I2C_SCLF_FILTER (3<<8)
57 #define SIRFSOC_I2C_START_CMD BIT(0)
59 #define SIRFSOC_I2C_CMD_RP(x) ((x)&0x7)
60 #define SIRFSOC_I2C_NACK BIT(3)
61 #define SIRFSOC_I2C_WRITE BIT(4)
62 #define SIRFSOC_I2C_READ BIT(5)
63 #define SIRFSOC_I2C_STOP BIT(6)
64 #define SIRFSOC_I2C_START BIT(7)
66 #define SIRFSOC_I2C_DEFAULT_SPEED 100000
87 static void i2c_sirfsoc_read_data(
struct sirfsoc_i2c *siic)
101 static void i2c_sirfsoc_queue_cmd(
struct sirfsoc_i2c *siic)
157 i2c_sirfsoc_read_data(siic);
161 i2c_sirfsoc_queue_cmd(siic);
169 static void i2c_sirfsoc_set_address(
struct sirfsoc_i2c *siic,
176 if (siic->
last && (msg->
len == 0))
181 addr = msg->
addr << 1;
195 i2c_sirfsoc_set_address(siic, msg);
199 i2c_sirfsoc_queue_cmd(siic);
235 for (i = 0; i < num; i++) {
242 siic->
last = (i == (num - 1));
244 ret = i2c_sirfsoc_xfer_msg(siic, &msgs[i]);
257 .master_xfer = i2c_sirfsoc_xfer,
258 .functionality = i2c_sirfsoc_func,
283 dev_err(&pdev->
dev,
"Clock prepare failed\n");
297 dev_err(&pdev->
dev,
"Can't allocate driver data\n");
305 if (mem_res ==
NULL) {
306 dev_err(&pdev->
dev,
"Unable to get MEM resource\n");
323 err = devm_request_irq(&pdev->
dev, irq, i2c_sirfsoc_irq, 0,
324 dev_name(&pdev->
dev), siic);
328 adap->
algo = &i2c_sirfsoc_algo;
331 adap->
dev.parent = &pdev->
dev;
336 platform_set_drvdata(pdev, adap);
337 init_completion(&siic->
done);
349 err = of_property_read_u32(pdev->
dev.of_node,
350 "clock-frequency", &bitrate);
354 if (bitrate < 100000)
356 (2 * ctrl_speed) / (2 * bitrate * 11);
358 regval = ctrl_speed / (bitrate * 5);
368 dev_err(&pdev->
dev,
"Can't add new i2c adapter\n");
374 dev_info(&pdev->
dev,
" I2C adapter ready to operate\n");
401 static int i2c_sirfsoc_suspend(
struct device *
dev)
414 static int i2c_sirfsoc_resume(
struct device *
dev)
430 static const struct dev_pm_ops i2c_sirfsoc_pm_ops = {
431 .
suspend = i2c_sirfsoc_suspend,
432 .resume = i2c_sirfsoc_resume,
437 { .compatible =
"sirf,prima2-i2c", },
444 .name =
"sirfsoc_i2c",
447 .pm = &i2c_sirfsoc_pm_ops,
449 .of_match_table = sirfsoc_i2c_of_match,
451 .probe = i2c_sirfsoc_probe,