Skip to content

Commit 4bc259e

Browse files
committed
phy: phy-can-transceiver: Support TJA1048/TJA1051
Peng Fan <peng.fan@nxp.com> says: TJA1048 is a Dual channel can transceiver with Sleep mode supported. TJA105{1,7} is a Single Channel can transceiver with Sleep mode supported. Link: https://patch.msgid.link/20251001-can-v7-0-fad29efc3884@nxp.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
2 parents 3a86608 + b817f50 commit 4bc259e

2 files changed

Lines changed: 183 additions & 44 deletions

File tree

Documentation/devicetree/bindings/phy/ti,tcan104x-can.yaml

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ properties:
2323
- enum:
2424
- ti,tcan1042
2525
- ti,tcan1043
26+
- nxp,tja1048
27+
- nxp,tja1051
28+
- nxp,tja1057
2629
- nxp,tjr1443
2730

2831
'#phy-cells':
29-
const: 0
32+
enum: [0, 1]
3033

31-
standby-gpios:
34+
silent-gpios:
3235
description:
33-
gpio node to toggle standby signal on transceiver
36+
gpio node to toggle silent signal on transceiver
3437
maxItems: 1
3538

39+
standby-gpios:
40+
description:
41+
gpio node to toggle standby signal on transceiver. For two Items, item 1
42+
is for stbn1, item 2 is for stbn2.
43+
minItems: 1
44+
maxItems: 2
45+
3646
enable-gpios:
3747
description:
3848
gpio node to toggle enable signal on transceiver
@@ -54,6 +64,59 @@ required:
5464
- compatible
5565
- '#phy-cells'
5666

67+
allOf:
68+
- if:
69+
properties:
70+
compatible:
71+
enum:
72+
- nxp,tjr1443
73+
- ti,tcan1042
74+
- ti,tcan1043
75+
then:
76+
properties:
77+
'#phy-cells':
78+
const: 0
79+
silent-gpios: false
80+
standby-gpios:
81+
maxItems: 1
82+
83+
- if:
84+
properties:
85+
compatible:
86+
contains:
87+
const: nxp,tja1048
88+
then:
89+
properties:
90+
'#phy-cells':
91+
const: 1
92+
enable-gpios: false
93+
silent-gpios: false
94+
standby-gpios:
95+
minItems: 2
96+
97+
- if:
98+
properties:
99+
compatible:
100+
contains:
101+
const: nxp,tja1051
102+
then:
103+
properties:
104+
'#phy-cells':
105+
const: 0
106+
standby-gpios: false
107+
108+
- if:
109+
properties:
110+
compatible:
111+
contains:
112+
const: nxp,tja1057
113+
then:
114+
properties:
115+
'#phy-cells':
116+
const: 0
117+
enable-gpios: false
118+
standby-gpios: false
119+
57120
additionalProperties: false
58121

59122
examples:

drivers/phy/phy-can-transceiver.c

Lines changed: 117 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,41 @@ struct can_transceiver_data {
1717
u32 flags;
1818
#define CAN_TRANSCEIVER_STB_PRESENT BIT(0)
1919
#define CAN_TRANSCEIVER_EN_PRESENT BIT(1)
20+
#define CAN_TRANSCEIVER_DUAL_CH BIT(2)
21+
#define CAN_TRANSCEIVER_SILENT_PRESENT BIT(3)
2022
};
2123

2224
struct can_transceiver_phy {
2325
struct phy *generic_phy;
26+
struct gpio_desc *silent_gpio;
2427
struct gpio_desc *standby_gpio;
2528
struct gpio_desc *enable_gpio;
29+
struct can_transceiver_priv *priv;
30+
};
31+
32+
struct can_transceiver_priv {
2633
struct mux_state *mux_state;
34+
int num_ch;
35+
struct can_transceiver_phy can_transceiver_phy[] __counted_by(num_ch);
2736
};
2837

2938
/* Power on function */
3039
static int can_transceiver_phy_power_on(struct phy *phy)
3140
{
3241
struct can_transceiver_phy *can_transceiver_phy = phy_get_drvdata(phy);
42+
struct can_transceiver_priv *priv = can_transceiver_phy->priv;
3343
int ret;
3444

35-
if (can_transceiver_phy->mux_state) {
36-
ret = mux_state_select(can_transceiver_phy->mux_state);
45+
if (priv->mux_state) {
46+
ret = mux_state_select(priv->mux_state);
3747
if (ret) {
3848
dev_err(&phy->dev, "Failed to select CAN mux: %d\n", ret);
3949
return ret;
4050
}
4151
}
42-
if (can_transceiver_phy->standby_gpio)
43-
gpiod_set_value_cansleep(can_transceiver_phy->standby_gpio, 0);
44-
if (can_transceiver_phy->enable_gpio)
45-
gpiod_set_value_cansleep(can_transceiver_phy->enable_gpio, 1);
52+
gpiod_set_value_cansleep(can_transceiver_phy->silent_gpio, 0);
53+
gpiod_set_value_cansleep(can_transceiver_phy->standby_gpio, 0);
54+
gpiod_set_value_cansleep(can_transceiver_phy->enable_gpio, 1);
4655

4756
return 0;
4857
}
@@ -51,13 +60,13 @@ static int can_transceiver_phy_power_on(struct phy *phy)
5160
static int can_transceiver_phy_power_off(struct phy *phy)
5261
{
5362
struct can_transceiver_phy *can_transceiver_phy = phy_get_drvdata(phy);
63+
struct can_transceiver_priv *priv = can_transceiver_phy->priv;
5464

55-
if (can_transceiver_phy->standby_gpio)
56-
gpiod_set_value_cansleep(can_transceiver_phy->standby_gpio, 1);
57-
if (can_transceiver_phy->enable_gpio)
58-
gpiod_set_value_cansleep(can_transceiver_phy->enable_gpio, 0);
59-
if (can_transceiver_phy->mux_state)
60-
mux_state_deselect(can_transceiver_phy->mux_state);
65+
gpiod_set_value_cansleep(can_transceiver_phy->silent_gpio, 1);
66+
gpiod_set_value_cansleep(can_transceiver_phy->standby_gpio, 1);
67+
gpiod_set_value_cansleep(can_transceiver_phy->enable_gpio, 0);
68+
if (priv->mux_state)
69+
mux_state_deselect(priv->mux_state);
6170

6271
return 0;
6372
}
@@ -76,6 +85,18 @@ static const struct can_transceiver_data tcan1043_drvdata = {
7685
.flags = CAN_TRANSCEIVER_STB_PRESENT | CAN_TRANSCEIVER_EN_PRESENT,
7786
};
7887

88+
static const struct can_transceiver_data tja1048_drvdata = {
89+
.flags = CAN_TRANSCEIVER_STB_PRESENT | CAN_TRANSCEIVER_DUAL_CH,
90+
};
91+
92+
static const struct can_transceiver_data tja1051_drvdata = {
93+
.flags = CAN_TRANSCEIVER_SILENT_PRESENT | CAN_TRANSCEIVER_EN_PRESENT,
94+
};
95+
96+
static const struct can_transceiver_data tja1057_drvdata = {
97+
.flags = CAN_TRANSCEIVER_SILENT_PRESENT,
98+
};
99+
79100
static const struct of_device_id can_transceiver_phy_ids[] = {
80101
{
81102
.compatible = "ti,tcan1042",
@@ -85,6 +106,18 @@ static const struct of_device_id can_transceiver_phy_ids[] = {
85106
.compatible = "ti,tcan1043",
86107
.data = &tcan1043_drvdata
87108
},
109+
{
110+
.compatible = "nxp,tja1048",
111+
.data = &tja1048_drvdata
112+
},
113+
{
114+
.compatible = "nxp,tja1051",
115+
.data = &tja1051_drvdata
116+
},
117+
{
118+
.compatible = "nxp,tja1057",
119+
.data = &tja1057_drvdata
120+
},
88121
{
89122
.compatible = "nxp,tjr1443",
90123
.data = &tcan1043_drvdata
@@ -103,64 +136,107 @@ devm_mux_state_get_optional(struct device *dev, const char *mux_name)
103136
return devm_mux_state_get(dev, mux_name);
104137
}
105138

139+
static struct phy *can_transceiver_phy_xlate(struct device *dev,
140+
const struct of_phandle_args *args)
141+
{
142+
struct can_transceiver_priv *priv = dev_get_drvdata(dev);
143+
u32 idx;
144+
145+
if (priv->num_ch == 1)
146+
return priv->can_transceiver_phy[0].generic_phy;
147+
148+
if (args->args_count != 1)
149+
return ERR_PTR(-EINVAL);
150+
151+
idx = args->args[0];
152+
if (idx >= priv->num_ch)
153+
return ERR_PTR(-EINVAL);
154+
155+
return priv->can_transceiver_phy[idx].generic_phy;
156+
}
157+
106158
static int can_transceiver_phy_probe(struct platform_device *pdev)
107159
{
108160
struct phy_provider *phy_provider;
109161
struct device *dev = &pdev->dev;
110162
struct can_transceiver_phy *can_transceiver_phy;
163+
struct can_transceiver_priv *priv;
111164
const struct can_transceiver_data *drvdata;
112165
const struct of_device_id *match;
113166
struct phy *phy;
167+
struct gpio_desc *silent_gpio;
114168
struct gpio_desc *standby_gpio;
115169
struct gpio_desc *enable_gpio;
116170
struct mux_state *mux_state;
117171
u32 max_bitrate = 0;
118-
int err;
119-
120-
can_transceiver_phy = devm_kzalloc(dev, sizeof(struct can_transceiver_phy), GFP_KERNEL);
121-
if (!can_transceiver_phy)
122-
return -ENOMEM;
172+
int err, i, num_ch = 1;
123173

124174
match = of_match_node(can_transceiver_phy_ids, pdev->dev.of_node);
125175
drvdata = match->data;
176+
if (drvdata->flags & CAN_TRANSCEIVER_DUAL_CH)
177+
num_ch = 2;
178+
179+
priv = devm_kzalloc(dev, struct_size(priv, can_transceiver_phy, num_ch), GFP_KERNEL);
180+
if (!priv)
181+
return -ENOMEM;
182+
183+
priv->num_ch = num_ch;
184+
platform_set_drvdata(pdev, priv);
126185

127186
mux_state = devm_mux_state_get_optional(dev, NULL);
128187
if (IS_ERR(mux_state))
129188
return PTR_ERR(mux_state);
130189

131-
can_transceiver_phy->mux_state = mux_state;
132-
133-
phy = devm_phy_create(dev, dev->of_node,
134-
&can_transceiver_phy_ops);
135-
if (IS_ERR(phy)) {
136-
dev_err(dev, "failed to create can transceiver phy\n");
137-
return PTR_ERR(phy);
138-
}
190+
priv->mux_state = mux_state;
139191

140192
err = device_property_read_u32(dev, "max-bitrate", &max_bitrate);
141193
if ((err != -EINVAL) && !max_bitrate)
142194
dev_warn(dev, "Invalid value for transceiver max bitrate. Ignoring bitrate limit\n");
143-
phy->attrs.max_link_rate = max_bitrate;
144195

145-
can_transceiver_phy->generic_phy = phy;
196+
for (i = 0; i < num_ch; i++) {
197+
can_transceiver_phy = &priv->can_transceiver_phy[i];
198+
can_transceiver_phy->priv = priv;
146199

147-
if (drvdata->flags & CAN_TRANSCEIVER_STB_PRESENT) {
148-
standby_gpio = devm_gpiod_get_optional(dev, "standby", GPIOD_OUT_HIGH);
149-
if (IS_ERR(standby_gpio))
150-
return PTR_ERR(standby_gpio);
151-
can_transceiver_phy->standby_gpio = standby_gpio;
152-
}
200+
phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
201+
if (IS_ERR(phy)) {
202+
dev_err(dev, "failed to create can transceiver phy\n");
203+
return PTR_ERR(phy);
204+
}
153205

154-
if (drvdata->flags & CAN_TRANSCEIVER_EN_PRESENT) {
155-
enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
156-
if (IS_ERR(enable_gpio))
157-
return PTR_ERR(enable_gpio);
158-
can_transceiver_phy->enable_gpio = enable_gpio;
159-
}
206+
phy->attrs.max_link_rate = max_bitrate;
207+
208+
can_transceiver_phy->generic_phy = phy;
209+
can_transceiver_phy->priv = priv;
210+
211+
if (drvdata->flags & CAN_TRANSCEIVER_STB_PRESENT) {
212+
standby_gpio = devm_gpiod_get_index_optional(dev, "standby", i,
213+
GPIOD_OUT_HIGH);
214+
if (IS_ERR(standby_gpio))
215+
return PTR_ERR(standby_gpio);
216+
can_transceiver_phy->standby_gpio = standby_gpio;
217+
}
218+
219+
if (drvdata->flags & CAN_TRANSCEIVER_EN_PRESENT) {
220+
enable_gpio = devm_gpiod_get_index_optional(dev, "enable", i,
221+
GPIOD_OUT_LOW);
222+
if (IS_ERR(enable_gpio))
223+
return PTR_ERR(enable_gpio);
224+
can_transceiver_phy->enable_gpio = enable_gpio;
225+
}
226+
227+
if (drvdata->flags & CAN_TRANSCEIVER_SILENT_PRESENT) {
228+
silent_gpio = devm_gpiod_get_index_optional(dev, "silent", i,
229+
GPIOD_OUT_LOW);
230+
if (IS_ERR(silent_gpio))
231+
return PTR_ERR(silent_gpio);
232+
can_transceiver_phy->silent_gpio = silent_gpio;
233+
}
160234

161-
phy_set_drvdata(can_transceiver_phy->generic_phy, can_transceiver_phy);
235+
phy_set_drvdata(can_transceiver_phy->generic_phy, can_transceiver_phy);
236+
237+
}
162238

163-
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
239+
phy_provider = devm_of_phy_provider_register(dev, can_transceiver_phy_xlate);
164240

165241
return PTR_ERR_OR_ZERO(phy_provider);
166242
}

0 commit comments

Comments
 (0)