#define KS8995_RESET_DELAY 10 /* usec */
+enum ks8995_chip_variant {
+ ks8995,
+ ksz8864,
+ max_variant
+};
+
+struct ks8995_chip_params {
+ char *name;
+ int regs_size;
+};
+
+static const struct ks8995_chip_params ks8995_chip[] = {
+ [ks8995] = {
+ .name = "KS8995MA",
+ .regs_size = KS8995_REGS_SIZE,
+ },
+ [ksz8864] = {
+ .name = "KSZ8864RMN",
+ .regs_size = KSZ8864_REGS_SIZE,
+ },
+};
+
struct ks8995_pdata {
/* not yet implemented */
};
struct mutex lock;
struct ks8995_pdata *pdata;
struct bin_attribute regs_attr;
+ const struct ks8995_chip_params *chip;
};
+static const struct spi_device_id ks8995_id[] = {
+ {"ks8995", ks8995},
+ {"ksz8864", ksz8864},
+ { }
+};
+MODULE_DEVICE_TABLE(spi, ks8995_id);
+
static inline u8 get_chip_id(u8 val)
{
return (val >> ID1_CHIPID_S) & ID1_CHIPID_M;
};
/* ------------------------------------------------------------------------ */
-
static int ks8995_probe(struct spi_device *spi)
{
struct ks8995_switch *ks;
struct ks8995_pdata *pdata;
u8 ids[2];
int err;
+ int variant = spi_get_device_id(spi)->driver_data;
/* Chip description */
pdata = spi->dev.platform_data;
+ if (variant >= max_variant) {
+ dev_err(&spi->dev, "bad chip variant %d\n", variant);
+ return -ENODEV;
+ }
+
ks = devm_kzalloc(&spi->dev, sizeof(*ks), GFP_KERNEL);
if (!ks)
return -ENOMEM;
mutex_init(&ks->lock);
ks->pdata = pdata;
ks->spi = spi_dev_get(spi);
+ ks->chip = &ks8995_chip[variant];
+
spi_set_drvdata(spi, ks);
spi->mode = SPI_MODE_0;
return -ENODEV;
}
+ ks->regs_attr.size = ks->chip->regs_size;
memcpy(&ks->regs_attr, &ks8995_registers_attr, sizeof(ks->regs_attr));
if (get_chip_id(ids[1]) != CHIPID_M) {
u8 val;
dev_err(&spi->dev, "unknown chip:%02x,0\n", ids[1]);
return err;
}
- ks->regs_attr.size = KSZ8864_REGS_SIZE;
}
err = ks8995_reset(ks);
},
.probe = ks8995_probe,
.remove = ks8995_remove,
+ .id_table = ks8995_id,
};
module_spi_driver(ks8995_driver);