Lines Matching +full:revision +full:- +full:id1

1 // SPDX-License-Identifier: GPL-2.0
26 /* ------------------------------------------------------------------------ */
29 #define KS8995_REG_ID1 0x01 /* Chip ID1 */
174 /* create_spi_cmd - create a chip specific SPI command header
191 result <<= ks->chip->addr_width + ks->chip->addr_shift; in create_spi_cmd()
193 result |= address << ks->chip->addr_shift; in create_spi_cmd()
197 /* ------------------------------------------------------------------------ */
219 mutex_lock(&ks->lock); in ks8995_read()
220 err = spi_sync(ks->spi, &m); in ks8995_read()
221 mutex_unlock(&ks->lock); in ks8995_read()
247 mutex_lock(&ks->lock); in ks8995_write()
248 err = spi_sync(ks->spi, &m); in ks8995_write()
249 mutex_unlock(&ks->lock); in ks8995_write()
266 /* ------------------------------------------------------------------------ */
315 /* ks8995_get_revision - get chip revision
318 * Verify chip family and id and get chip revision.
323 u8 id0, id1, ksz8864_id; in ks8995_get_revision() local
328 err = -EIO; in ks8995_get_revision()
333 if (id0 != ks->chip->family_id) { in ks8995_get_revision()
334 dev_err(&ks->spi->dev, "chip family id mismatch: expected 0x%02x but 0x%02x read\n", in ks8995_get_revision()
335 ks->chip->family_id, id0); in ks8995_get_revision()
336 err = -ENODEV; in ks8995_get_revision()
340 switch (ks->chip->family_id) { in ks8995_get_revision()
342 /* try reading chip id at CHIP ID1 */ in ks8995_get_revision()
343 err = ks8995_read_reg(ks, KS8995_REG_ID1, &id1); in ks8995_get_revision()
345 err = -EIO; in ks8995_get_revision()
350 if ((get_chip_id(id1) == CHIPID_M) && in ks8995_get_revision()
351 (get_chip_id(id1) == ks->chip->chip_id)) { in ks8995_get_revision()
353 ks->revision_id = get_chip_rev(id1); in ks8995_get_revision()
354 } else if (get_chip_id(id1) != CHIPID_M) { in ks8995_get_revision()
358 err = -EIO; in ks8995_get_revision()
363 (ks->chip->chip_id == KSZ8864_CHIP_ID)) { in ks8995_get_revision()
364 ks->revision_id = get_chip_rev(id1); in ks8995_get_revision()
368 dev_err(&ks->spi->dev, "unsupported chip id for KS8995 family: 0x%02x\n", in ks8995_get_revision()
369 id1); in ks8995_get_revision()
370 err = -ENODEV; in ks8995_get_revision()
374 /* try reading chip id at CHIP ID1 */ in ks8995_get_revision()
375 err = ks8995_read_reg(ks, KS8995_REG_ID1, &id1); in ks8995_get_revision()
377 err = -EIO; in ks8995_get_revision()
381 if (get_chip_id(id1) == ks->chip->chip_id) { in ks8995_get_revision()
382 ks->revision_id = get_chip_rev(id1); in ks8995_get_revision()
384 dev_err(&ks->spi->dev, "unsupported chip id for KSZ8795 family: 0x%02x\n", in ks8995_get_revision()
385 id1); in ks8995_get_revision()
386 err = -ENODEV; in ks8995_get_revision()
390 dev_err(&ks->spi->dev, "unsupported family id: 0x%02x\n", id0); in ks8995_get_revision()
391 err = -ENODEV; in ks8995_get_revision()
408 /* ------------------------------------------------------------------------ */
413 int variant = spi_get_device_id(spi)->driver_data; in ks8995_probe()
416 dev_err(&spi->dev, "bad chip variant %d\n", variant); in ks8995_probe()
417 return -ENODEV; in ks8995_probe()
420 ks = devm_kzalloc(&spi->dev, sizeof(*ks), GFP_KERNEL); in ks8995_probe()
422 return -ENOMEM; in ks8995_probe()
424 mutex_init(&ks->lock); in ks8995_probe()
425 ks->spi = spi; in ks8995_probe()
426 ks->chip = &ks8995_chip[variant]; in ks8995_probe()
428 ks->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", in ks8995_probe()
430 err = PTR_ERR_OR_ZERO(ks->reset_gpio); in ks8995_probe()
432 dev_err(&spi->dev, in ks8995_probe()
437 err = gpiod_set_consumer_name(ks->reset_gpio, "switch-reset"); in ks8995_probe()
441 /* de-assert switch reset */ in ks8995_probe()
443 gpiod_set_value_cansleep(ks->reset_gpio, 0); in ks8995_probe()
447 spi->mode = SPI_MODE_0; in ks8995_probe()
448 spi->bits_per_word = 8; in ks8995_probe()
451 dev_err(&spi->dev, "spi_setup failed, err=%d\n", err); in ks8995_probe()
459 memcpy(&ks->regs_attr, &ks8995_registers_attr, sizeof(ks->regs_attr)); in ks8995_probe()
460 ks->regs_attr.size = ks->chip->regs_size; in ks8995_probe()
466 sysfs_attr_init(&ks->regs_attr.attr); in ks8995_probe()
467 err = sysfs_create_bin_file(&spi->dev.kobj, &ks->regs_attr); in ks8995_probe()
469 dev_err(&spi->dev, "unable to create sysfs file, err=%d\n", in ks8995_probe()
474 dev_info(&spi->dev, "%s device found, Chip ID:%x, Revision:%x\n", in ks8995_probe()
475 ks->chip->name, ks->chip->chip_id, ks->revision_id); in ks8995_probe()
484 sysfs_remove_bin_file(&spi->dev.kobj, &ks->regs_attr); in ks8995_remove()
487 gpiod_set_value_cansleep(ks->reset_gpio, 1); in ks8995_remove()
490 /* ------------------------------------------------------------------------ */
493 .name = "spi-ks8995",