@@ -23,17 +23,24 @@ struct can_transceiver_phy {
2323 struct phy * generic_phy ;
2424 struct gpio_desc * standby_gpio ;
2525 struct gpio_desc * enable_gpio ;
26+ struct can_transceiver_priv * priv ;
27+ };
28+
29+ struct can_transceiver_priv {
2630 struct mux_state * mux_state ;
31+ int num_ch ;
32+ struct can_transceiver_phy can_transceiver_phy [] __counted_by (num_ch );
2733};
2834
2935/* Power on function */
3036static int can_transceiver_phy_power_on (struct phy * phy )
3137{
3238 struct can_transceiver_phy * can_transceiver_phy = phy_get_drvdata (phy );
39+ struct can_transceiver_priv * priv = can_transceiver_phy -> priv ;
3340 int ret ;
3441
35- if (can_transceiver_phy -> mux_state ) {
36- ret = mux_state_select (can_transceiver_phy -> mux_state );
42+ if (priv -> mux_state ) {
43+ ret = mux_state_select (priv -> mux_state );
3744 if (ret ) {
3845 dev_err (& phy -> dev , "Failed to select CAN mux: %d\n" , ret );
3946 return ret ;
@@ -51,13 +58,14 @@ static int can_transceiver_phy_power_on(struct phy *phy)
5158static int can_transceiver_phy_power_off (struct phy * phy )
5259{
5360 struct can_transceiver_phy * can_transceiver_phy = phy_get_drvdata (phy );
61+ struct can_transceiver_priv * priv = can_transceiver_phy -> priv ;
5462
5563 if (can_transceiver_phy -> standby_gpio )
5664 gpiod_set_value_cansleep (can_transceiver_phy -> standby_gpio , 1 );
5765 if (can_transceiver_phy -> enable_gpio )
5866 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 );
67+ if (priv -> mux_state )
68+ mux_state_deselect (priv -> mux_state );
6169
6270 return 0 ;
6371}
@@ -108,27 +116,33 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
108116 struct phy_provider * phy_provider ;
109117 struct device * dev = & pdev -> dev ;
110118 struct can_transceiver_phy * can_transceiver_phy ;
119+ struct can_transceiver_priv * priv ;
111120 const struct can_transceiver_data * drvdata ;
112121 const struct of_device_id * match ;
113122 struct phy * phy ;
114123 struct gpio_desc * standby_gpio ;
115124 struct gpio_desc * enable_gpio ;
116125 struct mux_state * mux_state ;
117126 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 ;
127+ int err , num_ch = 1 ;
123128
124129 match = of_match_node (can_transceiver_phy_ids , pdev -> dev .of_node );
125130 drvdata = match -> data ;
126131
132+ priv = devm_kzalloc (dev , struct_size (priv , can_transceiver_phy , num_ch ), GFP_KERNEL );
133+ if (!priv )
134+ return - ENOMEM ;
135+
136+ priv -> num_ch = num_ch ;
137+ platform_set_drvdata (pdev , priv );
138+ can_transceiver_phy = & priv -> can_transceiver_phy [0 ];
139+ can_transceiver_phy -> priv = priv ;
140+
127141 mux_state = devm_mux_state_get_optional (dev , NULL );
128142 if (IS_ERR (mux_state ))
129143 return PTR_ERR (mux_state );
130144
131- can_transceiver_phy -> mux_state = mux_state ;
145+ priv -> mux_state = mux_state ;
132146
133147 phy = devm_phy_create (dev , dev -> of_node ,
134148 & can_transceiver_phy_ops );
0 commit comments