Lines Matching refs:ks
191 static inline __be16 create_spi_cmd(struct ks8995_switch *ks, int cmd, in create_spi_cmd() argument
197 result <<= ks->chip->addr_width + ks->chip->addr_shift; in create_spi_cmd()
199 result |= address << ks->chip->addr_shift; in create_spi_cmd()
204 static int ks8995_read(struct ks8995_switch *ks, char *buf, in ks8995_read() argument
212 cmd = create_spi_cmd(ks, KS8995_CMD_READ, offset); in ks8995_read()
225 mutex_lock(&ks->lock); in ks8995_read()
226 err = spi_sync(ks->spi, &m); in ks8995_read()
227 mutex_unlock(&ks->lock); in ks8995_read()
232 static int ks8995_write(struct ks8995_switch *ks, char *buf, in ks8995_write() argument
240 cmd = create_spi_cmd(ks, KS8995_CMD_WRITE, offset); in ks8995_write()
253 mutex_lock(&ks->lock); in ks8995_write()
254 err = spi_sync(ks->spi, &m); in ks8995_write()
255 mutex_unlock(&ks->lock); in ks8995_write()
260 static inline int ks8995_read_reg(struct ks8995_switch *ks, u8 addr, u8 *buf) in ks8995_read_reg() argument
262 return ks8995_read(ks, buf, addr, 1) != 1; in ks8995_read_reg()
265 static inline int ks8995_write_reg(struct ks8995_switch *ks, u8 addr, u8 val) in ks8995_write_reg() argument
269 return ks8995_write(ks, &buf, addr, 1) != 1; in ks8995_write_reg()
274 static int ks8995_stop(struct ks8995_switch *ks) in ks8995_stop() argument
276 return ks8995_write_reg(ks, KS8995_REG_ID1, 0); in ks8995_stop()
279 static int ks8995_start(struct ks8995_switch *ks) in ks8995_start() argument
281 return ks8995_write_reg(ks, KS8995_REG_ID1, 1); in ks8995_start()
284 static int ks8995_reset(struct ks8995_switch *ks) in ks8995_reset() argument
288 err = ks8995_stop(ks); in ks8995_reset()
294 return ks8995_start(ks); in ks8995_reset()
326 static int ks8995_get_revision(struct ks8995_switch *ks) in ks8995_get_revision() argument
332 err = ks8995_read_reg(ks, KS8995_REG_ID0, &id0); in ks8995_get_revision()
339 if (id0 != ks->chip->family_id) { in ks8995_get_revision()
340 dev_err(&ks->spi->dev, "chip family id mismatch: expected 0x%02x but 0x%02x read\n", in ks8995_get_revision()
341 ks->chip->family_id, id0); in ks8995_get_revision()
346 switch (ks->chip->family_id) { in ks8995_get_revision()
349 err = ks8995_read_reg(ks, KS8995_REG_ID1, &id1); in ks8995_get_revision()
357 (get_chip_id(id1) == ks->chip->chip_id)) { in ks8995_get_revision()
359 ks->revision_id = get_chip_rev(id1); in ks8995_get_revision()
362 err = ks8995_read_reg(ks, KS8995_REG_ID1, &ksz8864_id); in ks8995_get_revision()
369 (ks->chip->chip_id == KSZ8864_CHIP_ID)) { in ks8995_get_revision()
370 ks->revision_id = get_chip_rev(id1); in ks8995_get_revision()
374 dev_err(&ks->spi->dev, "unsupported chip id for KS8995 family: 0x%02x\n", in ks8995_get_revision()
381 err = ks8995_read_reg(ks, KS8995_REG_ID1, &id1); in ks8995_get_revision()
387 if (get_chip_id(id1) == ks->chip->chip_id) { in ks8995_get_revision()
388 ks->revision_id = get_chip_rev(id1); in ks8995_get_revision()
390 dev_err(&ks->spi->dev, "unsupported chip id for KSZ8795 family: 0x%02x\n", in ks8995_get_revision()
396 dev_err(&ks->spi->dev, "unsupported family id: 0x%02x\n", id0); in ks8995_get_revision()
410 static void ks8995_parse_dt(struct ks8995_switch *ks) in ks8995_parse_dt() argument
412 struct device_node *np = ks->spi->dev.of_node; in ks8995_parse_dt()
413 struct ks8995_pdata *pdata = ks->pdata; in ks8995_parse_dt()
435 struct ks8995_switch *ks; in ks8995_probe() local
444 ks = devm_kzalloc(&spi->dev, sizeof(*ks), GFP_KERNEL); in ks8995_probe()
445 if (!ks) in ks8995_probe()
448 mutex_init(&ks->lock); in ks8995_probe()
449 ks->spi = spi; in ks8995_probe()
450 ks->chip = &ks8995_chip[variant]; in ks8995_probe()
452 if (ks->spi->dev.of_node) { in ks8995_probe()
453 ks->pdata = devm_kzalloc(&spi->dev, sizeof(*ks->pdata), in ks8995_probe()
455 if (!ks->pdata) in ks8995_probe()
458 ks->pdata->reset_gpio = -1; in ks8995_probe()
460 ks8995_parse_dt(ks); in ks8995_probe()
463 if (!ks->pdata) in ks8995_probe()
464 ks->pdata = spi->dev.platform_data; in ks8995_probe()
467 if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio)) { in ks8995_probe()
470 flags = (ks->pdata->reset_gpio_flags == OF_GPIO_ACTIVE_LOW ? in ks8995_probe()
474 ks->pdata->reset_gpio, in ks8995_probe()
482 gpiod_set_value(gpio_to_desc(ks->pdata->reset_gpio), 0); in ks8995_probe()
485 spi_set_drvdata(spi, ks); in ks8995_probe()
495 err = ks8995_get_revision(ks); in ks8995_probe()
499 memcpy(&ks->regs_attr, &ks8995_registers_attr, sizeof(ks->regs_attr)); in ks8995_probe()
500 ks->regs_attr.size = ks->chip->regs_size; in ks8995_probe()
502 err = ks8995_reset(ks); in ks8995_probe()
506 sysfs_attr_init(&ks->regs_attr.attr); in ks8995_probe()
507 err = sysfs_create_bin_file(&spi->dev.kobj, &ks->regs_attr); in ks8995_probe()
515 ks->chip->name, ks->chip->chip_id, ks->revision_id); in ks8995_probe()
522 struct ks8995_switch *ks = spi_get_drvdata(spi); in ks8995_remove() local
524 sysfs_remove_bin_file(&spi->dev.kobj, &ks->regs_attr); in ks8995_remove()
527 if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio)) in ks8995_remove()
528 gpiod_set_value(gpio_to_desc(ks->pdata->reset_gpio), 1); in ks8995_remove()