@@ -17,6 +17,7 @@ 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)
2021};
2122
2223struct can_transceiver_phy {
@@ -84,6 +85,10 @@ static const struct can_transceiver_data tcan1043_drvdata = {
8485 .flags = CAN_TRANSCEIVER_STB_PRESENT | CAN_TRANSCEIVER_EN_PRESENT ,
8586};
8687
88+ static const struct can_transceiver_data tja1048_drvdata = {
89+ .flags = CAN_TRANSCEIVER_STB_PRESENT | CAN_TRANSCEIVER_DUAL_CH ,
90+ };
91+
8792static const struct of_device_id can_transceiver_phy_ids [] = {
8893 {
8994 .compatible = "ti,tcan1042" ,
@@ -93,6 +98,10 @@ static const struct of_device_id can_transceiver_phy_ids[] = {
9398 .compatible = "ti,tcan1043" ,
9499 .data = & tcan1043_drvdata
95100 },
101+ {
102+ .compatible = "nxp,tja1048" ,
103+ .data = & tja1048_drvdata
104+ },
96105 {
97106 .compatible = "nxp,tjr1443" ,
98107 .data = & tcan1043_drvdata
@@ -111,6 +120,25 @@ devm_mux_state_get_optional(struct device *dev, const char *mux_name)
111120 return devm_mux_state_get (dev , mux_name );
112121}
113122
123+ static struct phy * can_transceiver_phy_xlate (struct device * dev ,
124+ const struct of_phandle_args * args )
125+ {
126+ struct can_transceiver_priv * priv = dev_get_drvdata (dev );
127+ u32 idx ;
128+
129+ if (priv -> num_ch == 1 )
130+ return priv -> can_transceiver_phy [0 ].generic_phy ;
131+
132+ if (args -> args_count != 1 )
133+ return ERR_PTR (- EINVAL );
134+
135+ idx = args -> args [0 ];
136+ if (idx >= priv -> num_ch )
137+ return ERR_PTR (- EINVAL );
138+
139+ return priv -> can_transceiver_phy [idx ].generic_phy ;
140+ }
141+
114142static int can_transceiver_phy_probe (struct platform_device * pdev )
115143{
116144 struct phy_provider * phy_provider ;
@@ -124,57 +152,65 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
124152 struct gpio_desc * enable_gpio ;
125153 struct mux_state * mux_state ;
126154 u32 max_bitrate = 0 ;
127- int err , num_ch = 1 ;
155+ int err , i , num_ch = 1 ;
128156
129157 match = of_match_node (can_transceiver_phy_ids , pdev -> dev .of_node );
130158 drvdata = match -> data ;
159+ if (drvdata -> flags & CAN_TRANSCEIVER_DUAL_CH )
160+ num_ch = 2 ;
131161
132162 priv = devm_kzalloc (dev , struct_size (priv , can_transceiver_phy , num_ch ), GFP_KERNEL );
133163 if (!priv )
134164 return - ENOMEM ;
135165
136166 priv -> num_ch = num_ch ;
137167 platform_set_drvdata (pdev , priv );
138- can_transceiver_phy = & priv -> can_transceiver_phy [0 ];
139- can_transceiver_phy -> priv = priv ;
140168
141169 mux_state = devm_mux_state_get_optional (dev , NULL );
142170 if (IS_ERR (mux_state ))
143171 return PTR_ERR (mux_state );
144172
145173 priv -> mux_state = mux_state ;
146174
147- phy = devm_phy_create (dev , dev -> of_node ,
148- & can_transceiver_phy_ops );
149- if (IS_ERR (phy )) {
150- dev_err (dev , "failed to create can transceiver phy\n" );
151- return PTR_ERR (phy );
152- }
153-
154175 err = device_property_read_u32 (dev , "max-bitrate" , & max_bitrate );
155176 if ((err != - EINVAL ) && !max_bitrate )
156177 dev_warn (dev , "Invalid value for transceiver max bitrate. Ignoring bitrate limit\n" );
157- phy -> attrs .max_link_rate = max_bitrate ;
158178
159- can_transceiver_phy -> generic_phy = phy ;
179+ for (i = 0 ; i < num_ch ; i ++ ) {
180+ can_transceiver_phy = & priv -> can_transceiver_phy [i ];
181+ can_transceiver_phy -> priv = priv ;
160182
161- if (drvdata -> flags & CAN_TRANSCEIVER_STB_PRESENT ) {
162- standby_gpio = devm_gpiod_get_optional (dev , "standby" , GPIOD_OUT_HIGH );
163- if (IS_ERR (standby_gpio ))
164- return PTR_ERR (standby_gpio );
165- can_transceiver_phy -> standby_gpio = standby_gpio ;
166- }
183+ phy = devm_phy_create (dev , dev -> of_node , & can_transceiver_phy_ops );
184+ if (IS_ERR (phy )) {
185+ dev_err (dev , "failed to create can transceiver phy\n" );
186+ return PTR_ERR (phy );
187+ }
167188
168- if (drvdata -> flags & CAN_TRANSCEIVER_EN_PRESENT ) {
169- enable_gpio = devm_gpiod_get_optional (dev , "enable" , GPIOD_OUT_LOW );
170- if (IS_ERR (enable_gpio ))
171- return PTR_ERR (enable_gpio );
172- can_transceiver_phy -> enable_gpio = enable_gpio ;
173- }
189+ phy -> attrs .max_link_rate = max_bitrate ;
190+
191+ can_transceiver_phy -> generic_phy = phy ;
192+ can_transceiver_phy -> priv = priv ;
174193
175- phy_set_drvdata (can_transceiver_phy -> generic_phy , can_transceiver_phy );
194+ if (drvdata -> flags & CAN_TRANSCEIVER_STB_PRESENT ) {
195+ standby_gpio = devm_gpiod_get_index_optional (dev , "standby" , i ,
196+ GPIOD_OUT_HIGH );
197+ if (IS_ERR (standby_gpio ))
198+ return PTR_ERR (standby_gpio );
199+ can_transceiver_phy -> standby_gpio = standby_gpio ;
200+ }
201+
202+ if (drvdata -> flags & CAN_TRANSCEIVER_EN_PRESENT ) {
203+ enable_gpio = devm_gpiod_get_index_optional (dev , "enable" , i ,
204+ GPIOD_OUT_LOW );
205+ if (IS_ERR (enable_gpio ))
206+ return PTR_ERR (enable_gpio );
207+ can_transceiver_phy -> enable_gpio = enable_gpio ;
208+ }
209+
210+ phy_set_drvdata (can_transceiver_phy -> generic_phy , can_transceiver_phy );
211+ }
176212
177- phy_provider = devm_of_phy_provider_register (dev , of_phy_simple_xlate );
213+ phy_provider = devm_of_phy_provider_register (dev , can_transceiver_phy_xlate );
178214
179215 return PTR_ERR_OR_ZERO (phy_provider );
180216}
0 commit comments