@@ -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
2224struct 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 */
3039static 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)
5160static 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+
79100static 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+
106158static 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