Skip to content

Commit 2d0ef4f

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "i2c has a bugfix and documentation improvements for you" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: Documentation: i2c: mention ACPI method for instantiating devices Documentation: i2c: describe devicetree method for instantiating devices i2c: mv64xxx: refactor message start to ensure proper initialization
2 parents 5a667a0 + fde1e41 commit 2d0ef4f

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
lines changed

Documentation/i2c/instantiating-devices

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ reason, the kernel code must instantiate I2C devices explicitly. There are
88
several ways to achieve this, depending on the context and requirements.
99

1010

11-
Method 1: Declare the I2C devices by bus number
12-
-----------------------------------------------
11+
Method 1a: Declare the I2C devices by bus number
12+
------------------------------------------------
1313

1414
This method is appropriate when the I2C bus is a system bus as is the case
1515
for many embedded systems. On such systems, each I2C bus has a number
@@ -51,6 +51,43 @@ The devices will be automatically unbound and destroyed when the I2C bus
5151
they sit on goes away (if ever.)
5252

5353

54+
Method 1b: Declare the I2C devices via devicetree
55+
-------------------------------------------------
56+
57+
This method has the same implications as method 1a. The declaration of I2C
58+
devices is here done via devicetree as subnodes of the master controller.
59+
60+
Example:
61+
62+
i2c1: i2c@400a0000 {
63+
/* ... master properties skipped ... */
64+
clock-frequency = <100000>;
65+
66+
flash@50 {
67+
compatible = "atmel,24c256";
68+
reg = <0x50>;
69+
};
70+
71+
pca9532: gpio@60 {
72+
compatible = "nxp,pca9532";
73+
gpio-controller;
74+
#gpio-cells = <2>;
75+
reg = <0x60>;
76+
};
77+
};
78+
79+
Here, two devices are attached to the bus using a speed of 100kHz. For
80+
additional properties which might be needed to set up the device, please refer
81+
to its devicetree documentation in Documentation/devicetree/bindings/.
82+
83+
84+
Method 1c: Declare the I2C devices via ACPI
85+
-------------------------------------------
86+
87+
ACPI can also describe I2C devices. There is special documentation for this
88+
which is currently located at Documentation/acpi/enumeration.txt.
89+
90+
5491
Method 2: Instantiate the devices explicitly
5592
--------------------------------------------
5693

drivers/i2c/busses/i2c-mv64xxx.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ enum {
9797
enum {
9898
MV64XXX_I2C_ACTION_INVALID,
9999
MV64XXX_I2C_ACTION_CONTINUE,
100-
MV64XXX_I2C_ACTION_OFFLOAD_SEND_START,
101100
MV64XXX_I2C_ACTION_SEND_START,
102101
MV64XXX_I2C_ACTION_SEND_RESTART,
103102
MV64XXX_I2C_ACTION_OFFLOAD_RESTART,
@@ -204,6 +203,9 @@ static int mv64xxx_i2c_offload_msg(struct mv64xxx_i2c_data *drv_data)
204203
unsigned long ctrl_reg;
205204
struct i2c_msg *msg = drv_data->msgs;
206205

206+
if (!drv_data->offload_enabled)
207+
return -EOPNOTSUPP;
208+
207209
drv_data->msg = msg;
208210
drv_data->byte_posn = 0;
209211
drv_data->bytes_left = msg->len;
@@ -433,8 +435,7 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
433435

434436
drv_data->msgs++;
435437
drv_data->num_msgs--;
436-
if (!(drv_data->offload_enabled &&
437-
mv64xxx_i2c_offload_msg(drv_data))) {
438+
if (mv64xxx_i2c_offload_msg(drv_data) < 0) {
438439
drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START;
439440
writel(drv_data->cntl_bits,
440441
drv_data->reg_base + drv_data->reg_offsets.control);
@@ -458,15 +459,14 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
458459
drv_data->reg_base + drv_data->reg_offsets.control);
459460
break;
460461

461-
case MV64XXX_I2C_ACTION_OFFLOAD_SEND_START:
462-
if (!mv64xxx_i2c_offload_msg(drv_data))
463-
break;
464-
else
465-
drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
466-
/* FALLTHRU */
467462
case MV64XXX_I2C_ACTION_SEND_START:
468-
writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START,
469-
drv_data->reg_base + drv_data->reg_offsets.control);
463+
/* Can we offload this msg ? */
464+
if (mv64xxx_i2c_offload_msg(drv_data) < 0) {
465+
/* No, switch to standard path */
466+
mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
467+
writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START,
468+
drv_data->reg_base + drv_data->reg_offsets.control);
469+
}
470470
break;
471471

472472
case MV64XXX_I2C_ACTION_SEND_ADDR_1:
@@ -625,15 +625,10 @@ mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg,
625625
unsigned long flags;
626626

627627
spin_lock_irqsave(&drv_data->lock, flags);
628-
if (drv_data->offload_enabled) {
629-
drv_data->action = MV64XXX_I2C_ACTION_OFFLOAD_SEND_START;
630-
drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
631-
} else {
632-
mv64xxx_i2c_prepare_for_io(drv_data, msg);
633628

634-
drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
635-
drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
636-
}
629+
drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
630+
drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
631+
637632
drv_data->send_stop = is_last;
638633
drv_data->block = 1;
639634
mv64xxx_i2c_do_action(drv_data);

0 commit comments

Comments
 (0)