Skip to content

Commit 3a076b3

Browse files
committed
ipmi:ipmb: Add OF support
Add direct OF support for fetching control parameters from the device tree. Make it work like the device tree entries for the other IPMI devices. Also add documentation for this. Signed-off-by: Corey Minyard <[email protected]>
1 parent cd921b9 commit 3a076b3

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/ipmi/ipmi-ipmb.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: IPMI IPMB device bindings
8+
9+
description: IPMI IPMB device bindings
10+
11+
maintainers:
12+
- Corey Minyard <[email protected]>
13+
14+
properties:
15+
compatible:
16+
enum:
17+
- ipmi-ipmb
18+
19+
device_type:
20+
items:
21+
- const: "ipmi"
22+
23+
reg:
24+
maxItems: 1
25+
26+
bmcaddr:
27+
$ref: /schemas/types.yaml#/definitions/uint8
28+
description: The address of the BMC on the IPMB bus. Defaults to 0x20.
29+
30+
retry-time:
31+
$ref: /schemas/types.yaml#/definitions/uint32
32+
description: |
33+
Time between retries of sends, in milliseconds. Defaults to 250.
34+
35+
max-retries:
36+
$ref: /schemas/types.yaml#/definitions/uint32
37+
description: Number of retries before a failure is declared. Defaults to 1.
38+
39+
required:
40+
- compatible
41+
- reg
42+
43+
additionalProperties: false
44+
45+
examples:
46+
- |
47+
i2c {
48+
#address-cells = <1>;
49+
#size-cells = <0>;
50+
51+
ipmi-ipmb@40 {
52+
compatible = "ipmi-ipmb";
53+
device_type = "ipmi";
54+
reg = <0x40>;
55+
bmcaddr = /bits/ 8 <0x20>;
56+
retry-time = <250>;
57+
max-retries = <1>;
58+
};
59+
};

drivers/char/ipmi/ipmi_ipmb.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ struct ipmi_ipmb_dev {
4444

4545
bool ready;
4646

47-
u8 bmcaddr;
48-
4947
u8 curr_seq;
5048

49+
u8 bmcaddr;
50+
u32 retry_time_ms;
51+
u32 max_retries;
52+
5153
struct ipmi_smi_msg *next_msg;
5254
struct ipmi_smi_msg *working_msg;
5355

@@ -333,7 +335,7 @@ static int ipmi_ipmb_thread(void *data)
333335

334336
/* A command was sent, wait for its response. */
335337
ret = down_timeout(&iidev->got_rsp,
336-
msecs_to_jiffies(retry_time_ms));
338+
msecs_to_jiffies(iidev->retry_time_ms));
337339

338340
/*
339341
* Grab the message if we can. If the handler hasn't
@@ -353,7 +355,7 @@ static int ipmi_ipmb_thread(void *data)
353355
* the semaphore.
354356
*/
355357
down(&iidev->got_rsp);
356-
} else if (msg && ++retries <= max_retries) {
358+
} else if (msg && ++retries <= iidev->max_retries) {
357359
spin_lock_irqsave(&iidev->lock, flags);
358360
iidev->working_msg = msg;
359361
spin_unlock_irqrestore(&iidev->lock, flags);
@@ -437,14 +439,30 @@ static int ipmi_ipmb_remove(struct i2c_client *client)
437439
static int ipmi_ipmb_probe(struct i2c_client *client,
438440
const struct i2c_device_id *id)
439441
{
442+
struct device *dev = &client->dev;
440443
struct ipmi_ipmb_dev *iidev;
441444
int rv;
442445

443446
iidev = devm_kzalloc(&client->dev, sizeof(*iidev), GFP_KERNEL);
444447
if (!iidev)
445448
return -ENOMEM;
446449

447-
iidev->bmcaddr = bmcaddr;
450+
if (of_property_read_u8(dev->of_node, "bmcaddr", &iidev->bmcaddr) != 0)
451+
iidev->bmcaddr = bmcaddr;
452+
if (iidev->bmcaddr == 0 || iidev->bmcaddr & 1) {
453+
/* Can't have the write bit set. */
454+
dev_notice(&client->dev,
455+
"Invalid bmc address value %2.2x\n", iidev->bmcaddr);
456+
return -EINVAL;
457+
}
458+
459+
if (of_property_read_u32(dev->of_node, "retry-time",
460+
&iidev->retry_time_ms) != 0)
461+
iidev->retry_time_ms = retry_time_ms;
462+
463+
if (of_property_read_u32(dev->of_node, "max-retries",
464+
&iidev->max_retries) != 0)
465+
iidev->max_retries = max_retries;
448466

449467
i2c_set_clientdata(client, iidev);
450468
client->flags |= I2C_CLIENT_SLAVE;
@@ -488,6 +506,16 @@ static int ipmi_ipmb_probe(struct i2c_client *client,
488506
return rv;
489507
}
490508

509+
#ifdef CONFIG_OF
510+
static const struct of_device_id of_ipmi_ipmb_match[] = {
511+
{ .type = "ipmi", .compatible = DEVICE_NAME },
512+
{},
513+
};
514+
MODULE_DEVICE_TABLE(of, of_ipmi_ipmb_match);
515+
#else
516+
#define of_ipmi_ipmb_match NULL
517+
#endif
518+
491519
static const struct i2c_device_id ipmi_ipmb_id[] = {
492520
{ DEVICE_NAME, 0 },
493521
{},
@@ -498,6 +526,7 @@ static struct i2c_driver ipmi_ipmb_driver = {
498526
.class = I2C_CLASS_HWMON,
499527
.driver = {
500528
.name = DEVICE_NAME,
529+
.of_match_table = of_ipmi_ipmb_match,
501530
},
502531
.probe = ipmi_ipmb_probe,
503532
.remove = ipmi_ipmb_remove,

0 commit comments

Comments
 (0)