Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: sja1105: Simplify reset handling

We don't really need 10k species of reset. Remove everything except cold
reset which is what is actually used. Too bad the hardware designers
couldn't agree to use the same bit field for rev 1 and rev 2, so the
(*reset_cmd) function pointer is there to stay.

However let's simplify the prototype and give it a struct dsa_switch (we
want to avoid forward-declarations of structures, in this case struct
sja1105_private, wherever we can).

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vladimir Oltean and committed by
David S. Miller
abfb228a ccb68993

+14 -96
+1 -1
drivers/net/dsa/sja1105/sja1105.h
··· 78 78 const struct sja1105_dynamic_table_ops *dyn_ops; 79 79 const struct sja1105_table_ops *static_ops; 80 80 const struct sja1105_regs *regs; 81 - int (*reset_cmd)(const void *ctx, const void *data); 81 + int (*reset_cmd)(struct dsa_switch *ds); 82 82 int (*setup_rgmii_delay)(const void *ctx, int port); 83 83 /* Prototypes from include/net/dsa.h */ 84 84 int (*fdb_add_cmd)(struct dsa_switch *ds, int port,
+13 -95
drivers/net/dsa/sja1105/sja1105_spi.c
··· 205 205 return rc; 206 206 } 207 207 208 - /* Back-ported structure from UM11040 Table 112. 209 - * Reset control register (addr. 100440h) 210 - * In the SJA1105 E/T, only warm_rst and cold_rst are 211 - * supported (exposed in UM10944 as rst_ctrl), but the bit 212 - * offsets of warm_rst and cold_rst are actually reversed. 213 - */ 214 - struct sja1105_reset_cmd { 215 - u64 switch_rst; 216 - u64 cfg_rst; 217 - u64 car_rst; 218 - u64 otp_rst; 219 - u64 warm_rst; 220 - u64 cold_rst; 221 - u64 por_rst; 222 - }; 223 - 224 - static void 225 - sja1105et_reset_cmd_pack(void *buf, const struct sja1105_reset_cmd *reset) 208 + static int sja1105et_reset_cmd(struct dsa_switch *ds) 226 209 { 227 - const int size = SJA1105_SIZE_RESET_CMD; 228 - 229 - memset(buf, 0, size); 230 - 231 - sja1105_pack(buf, &reset->cold_rst, 3, 3, size); 232 - sja1105_pack(buf, &reset->warm_rst, 2, 2, size); 233 - } 234 - 235 - static void 236 - sja1105pqrs_reset_cmd_pack(void *buf, const struct sja1105_reset_cmd *reset) 237 - { 238 - const int size = SJA1105_SIZE_RESET_CMD; 239 - 240 - memset(buf, 0, size); 241 - 242 - sja1105_pack(buf, &reset->switch_rst, 8, 8, size); 243 - sja1105_pack(buf, &reset->cfg_rst, 7, 7, size); 244 - sja1105_pack(buf, &reset->car_rst, 5, 5, size); 245 - sja1105_pack(buf, &reset->otp_rst, 4, 4, size); 246 - sja1105_pack(buf, &reset->warm_rst, 3, 3, size); 247 - sja1105_pack(buf, &reset->cold_rst, 2, 2, size); 248 - sja1105_pack(buf, &reset->por_rst, 1, 1, size); 249 - } 250 - 251 - static int sja1105et_reset_cmd(const void *ctx, const void *data) 252 - { 253 - const struct sja1105_private *priv = ctx; 254 - const struct sja1105_reset_cmd *reset = data; 210 + struct sja1105_private *priv = ds->priv; 255 211 const struct sja1105_regs *regs = priv->info->regs; 256 - struct device *dev = priv->ds->dev; 257 - u8 packed_buf[SJA1105_SIZE_RESET_CMD]; 212 + u8 packed_buf[SJA1105_SIZE_RESET_CMD] = {0}; 213 + const int size = SJA1105_SIZE_RESET_CMD; 214 + u64 cold_rst = 1; 258 215 259 - if (reset->switch_rst || 260 - reset->cfg_rst || 261 - reset->car_rst || 262 - reset->otp_rst || 263 - reset->por_rst) { 264 - dev_err(dev, "Only warm and cold reset is supported " 265 - "for SJA1105 E/T!\n"); 266 - return -EINVAL; 267 - } 268 - 269 - if (reset->warm_rst) 270 - dev_dbg(dev, "Warm reset requested\n"); 271 - if (reset->cold_rst) 272 - dev_dbg(dev, "Cold reset requested\n"); 273 - 274 - sja1105et_reset_cmd_pack(packed_buf, reset); 216 + sja1105_pack(packed_buf, &cold_rst, 3, 3, size); 275 217 276 218 return sja1105_xfer_buf(priv, SPI_WRITE, regs->rgu, packed_buf, 277 219 SJA1105_SIZE_RESET_CMD); 278 220 } 279 221 280 - static int sja1105pqrs_reset_cmd(const void *ctx, const void *data) 222 + static int sja1105pqrs_reset_cmd(struct dsa_switch *ds) 281 223 { 282 - const struct sja1105_private *priv = ctx; 283 - const struct sja1105_reset_cmd *reset = data; 224 + struct sja1105_private *priv = ds->priv; 284 225 const struct sja1105_regs *regs = priv->info->regs; 285 - struct device *dev = priv->ds->dev; 286 - u8 packed_buf[SJA1105_SIZE_RESET_CMD]; 226 + u8 packed_buf[SJA1105_SIZE_RESET_CMD] = {0}; 227 + const int size = SJA1105_SIZE_RESET_CMD; 228 + u64 cold_rst = 1; 287 229 288 - if (reset->switch_rst) 289 - dev_dbg(dev, "Main reset for all functional modules requested\n"); 290 - if (reset->cfg_rst) 291 - dev_dbg(dev, "Chip configuration reset requested\n"); 292 - if (reset->car_rst) 293 - dev_dbg(dev, "Clock and reset control logic reset requested\n"); 294 - if (reset->otp_rst) 295 - dev_dbg(dev, "OTP read cycle for reading product " 296 - "config settings requested\n"); 297 - if (reset->warm_rst) 298 - dev_dbg(dev, "Warm reset requested\n"); 299 - if (reset->cold_rst) 300 - dev_dbg(dev, "Cold reset requested\n"); 301 - if (reset->por_rst) 302 - dev_dbg(dev, "Power-on reset requested\n"); 303 - 304 - sja1105pqrs_reset_cmd_pack(packed_buf, reset); 230 + sja1105_pack(packed_buf, &cold_rst, 2, 2, size); 305 231 306 232 return sja1105_xfer_buf(priv, SPI_WRITE, regs->rgu, packed_buf, 307 233 SJA1105_SIZE_RESET_CMD); 308 - } 309 - 310 - static int sja1105_cold_reset(const struct sja1105_private *priv) 311 - { 312 - struct sja1105_reset_cmd reset = {0}; 313 - 314 - reset.cold_rst = 1; 315 - return priv->info->reset_cmd(priv, &reset); 316 234 } 317 235 318 236 int sja1105_inhibit_tx(const struct sja1105_private *priv, ··· 377 459 usleep_range(500, 1000); 378 460 do { 379 461 /* Put the SJA1105 in programming mode */ 380 - rc = sja1105_cold_reset(priv); 462 + rc = priv->info->reset_cmd(priv->ds); 381 463 if (rc < 0) { 382 464 dev_err(dev, "Failed to reset switch, retrying...\n"); 383 465 continue;