mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
f8c2afa66d
This matches /sys/devices/.../spi1.0/modalias content. Fixes:9b2d9f05cd
("net: dsa: microchip: add ksz9567 to ksz9477 driver") Fixes:d9033ae95c
("net: dsa: microchip: add KSZ8563 compatibility string") Fixes:8c29bebb1f
("net: dsa: microchip: add KSZ9893 switch support") Fixes:4531681837
("net: dsa: add support for ksz9897 ethernet switch") Fixes:b987e98e50
("dsa: add DSA switch driver for Microchip KSZ9477") Signed-off-by: Razvan Stefanescu <razvan.stefanescu@microchip.com> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
113 lines
2.6 KiB
C
113 lines
2.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Microchip KSZ9477 series register access through SPI
|
|
*
|
|
* Copyright (C) 2017-2019 Microchip Technology Inc.
|
|
*/
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include "ksz_common.h"
|
|
|
|
#define SPI_ADDR_SHIFT 24
|
|
#define SPI_ADDR_ALIGN 3
|
|
#define SPI_TURNAROUND_SHIFT 5
|
|
|
|
KSZ_REGMAP_TABLE(ksz9477, 32, SPI_ADDR_SHIFT,
|
|
SPI_TURNAROUND_SHIFT, SPI_ADDR_ALIGN);
|
|
|
|
static int ksz9477_spi_probe(struct spi_device *spi)
|
|
{
|
|
struct regmap_config rc;
|
|
struct ksz_device *dev;
|
|
int i, ret;
|
|
|
|
dev = ksz_switch_alloc(&spi->dev, spi);
|
|
if (!dev)
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) {
|
|
rc = ksz9477_regmap_config[i];
|
|
rc.lock_arg = &dev->regmap_mutex;
|
|
dev->regmap[i] = devm_regmap_init_spi(spi, &rc);
|
|
if (IS_ERR(dev->regmap[i])) {
|
|
ret = PTR_ERR(dev->regmap[i]);
|
|
dev_err(&spi->dev,
|
|
"Failed to initialize regmap%i: %d\n",
|
|
ksz9477_regmap_config[i].val_bits, ret);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
if (spi->dev.platform_data)
|
|
dev->pdata = spi->dev.platform_data;
|
|
|
|
ret = ksz9477_switch_register(dev);
|
|
|
|
/* Main DSA driver may not be started yet. */
|
|
if (ret)
|
|
return ret;
|
|
|
|
spi_set_drvdata(spi, dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ksz9477_spi_remove(struct spi_device *spi)
|
|
{
|
|
struct ksz_device *dev = spi_get_drvdata(spi);
|
|
|
|
if (dev)
|
|
ksz_switch_remove(dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void ksz9477_spi_shutdown(struct spi_device *spi)
|
|
{
|
|
struct ksz_device *dev = spi_get_drvdata(spi);
|
|
|
|
if (dev && dev->dev_ops->shutdown)
|
|
dev->dev_ops->shutdown(dev);
|
|
}
|
|
|
|
static const struct of_device_id ksz9477_dt_ids[] = {
|
|
{ .compatible = "microchip,ksz9477" },
|
|
{ .compatible = "microchip,ksz9897" },
|
|
{ .compatible = "microchip,ksz9893" },
|
|
{ .compatible = "microchip,ksz9563" },
|
|
{ .compatible = "microchip,ksz8563" },
|
|
{ .compatible = "microchip,ksz9567" },
|
|
{},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, ksz9477_dt_ids);
|
|
|
|
static struct spi_driver ksz9477_spi_driver = {
|
|
.driver = {
|
|
.name = "ksz9477-switch",
|
|
.owner = THIS_MODULE,
|
|
.of_match_table = of_match_ptr(ksz9477_dt_ids),
|
|
},
|
|
.probe = ksz9477_spi_probe,
|
|
.remove = ksz9477_spi_remove,
|
|
.shutdown = ksz9477_spi_shutdown,
|
|
};
|
|
|
|
module_spi_driver(ksz9477_spi_driver);
|
|
|
|
MODULE_ALIAS("spi:ksz9477");
|
|
MODULE_ALIAS("spi:ksz9897");
|
|
MODULE_ALIAS("spi:ksz9893");
|
|
MODULE_ALIAS("spi:ksz9563");
|
|
MODULE_ALIAS("spi:ksz8563");
|
|
MODULE_ALIAS("spi:ksz9567");
|
|
MODULE_AUTHOR("Woojung Huh <Woojung.Huh@microchip.com>");
|
|
MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch SPI access Driver");
|
|
MODULE_LICENSE("GPL");
|