Commit 4658f2fe authored by Arun Ramadoss's avatar Arun Ramadoss Committed by David S. Miller

net: dsa: microchip: common ksz_spi_probe for ksz switches

As of now, there are two spi probes, one ksz8795_spi.c and other
ksz9477_spi.c. This patch combines two files into single ksz_spi.c. The
difference between the two are regmap config and struct ksz8. The regmap
config is assigned based on the platform data. And struct ksz8 is left
untouched, as it is used only ksz8795.c. It can be used for all
other switches also in future.
Signed-off-by: default avatarArun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ff3f3a30
...@@ -8,29 +8,19 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON ...@@ -8,29 +8,19 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
KSZ8795/KSZ88x3 switch chips. KSZ8795/KSZ88x3 switch chips.
config NET_DSA_MICROCHIP_KSZ9477_I2C config NET_DSA_MICROCHIP_KSZ9477_I2C
tristate "KSZ9477 series I2C connected switch driver" tristate "KSZ series I2C connected switch driver"
depends on NET_DSA_MICROCHIP_KSZ_COMMON && I2C depends on NET_DSA_MICROCHIP_KSZ_COMMON && I2C
select REGMAP_I2C select REGMAP_I2C
help help
Select to enable support for registering switches configured through I2C. Select to enable support for registering switches configured through I2C.
config NET_DSA_MICROCHIP_KSZ9477_SPI config NET_DSA_MICROCHIP_KSZ_SPI
tristate "KSZ9477 series SPI connected switch driver" tristate "KSZ series SPI connected switch driver"
depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI
select REGMAP_SPI select REGMAP_SPI
help help
Select to enable support for registering switches configured through SPI. Select to enable support for registering switches configured through SPI.
config NET_DSA_MICROCHIP_KSZ8795_SPI
tristate "KSZ8795 series SPI connected switch driver"
depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI
select REGMAP_SPI
help
This driver accesses KSZ8795 chip through SPI.
It is required to use the KSZ8795 switch driver as the only access
is through SPI.
config NET_DSA_MICROCHIP_KSZ8863_SMI config NET_DSA_MICROCHIP_KSZ8863_SMI
tristate "KSZ series SMI connected switch driver" tristate "KSZ series SMI connected switch driver"
depends on NET_DSA_MICROCHIP_KSZ_COMMON depends on NET_DSA_MICROCHIP_KSZ_COMMON
......
...@@ -4,6 +4,5 @@ ksz_switch-objs := ksz_common.o ...@@ -4,6 +4,5 @@ ksz_switch-objs := ksz_common.o
ksz_switch-objs += ksz9477.o ksz_switch-objs += ksz9477.o
ksz_switch-objs += ksz8795.o ksz_switch-objs += ksz8795.o
obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o
obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI) += ksz9477_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI) += ksz_spi.o
obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI) += ksz8795_spi.o
obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o
// 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;
/* setup spi */
spi->mode = SPI_MODE_3;
ret = spi_setup(spi);
if (ret)
return ret;
ret = ksz_switch_register(dev);
/* Main DSA driver may not be started yet. */
if (ret)
return ret;
spi_set_drvdata(spi, dev);
return 0;
}
static void ksz9477_spi_remove(struct spi_device *spi)
{
struct ksz_device *dev = spi_get_drvdata(spi);
if (dev)
ksz_switch_remove(dev);
spi_set_drvdata(spi, NULL);
}
static void ksz9477_spi_shutdown(struct spi_device *spi)
{
struct ksz_device *dev = spi_get_drvdata(spi);
if (dev)
dsa_switch_shutdown(dev->ds);
spi_set_drvdata(spi, NULL);
}
static const struct of_device_id ksz9477_dt_ids[] = {
{
.compatible = "microchip,ksz9477",
.data = &ksz_switch_chips[KSZ9477]
},
{
.compatible = "microchip,ksz9897",
.data = &ksz_switch_chips[KSZ9897]
},
{
.compatible = "microchip,ksz9893",
.data = &ksz_switch_chips[KSZ9893]
},
{
.compatible = "microchip,ksz9563",
.data = &ksz_switch_chips[KSZ9893]
},
{
.compatible = "microchip,ksz8563",
.data = &ksz_switch_chips[KSZ9893]
},
{
.compatible = "microchip,ksz9567",
.data = &ksz_switch_chips[KSZ9567]
},
{},
};
MODULE_DEVICE_TABLE(of, ksz9477_dt_ids);
static const struct spi_device_id ksz9477_spi_ids[] = {
{ "ksz9477" },
{ "ksz9897" },
{ "ksz9893" },
{ "ksz9563" },
{ "ksz8563" },
{ "ksz9567" },
{ },
};
MODULE_DEVICE_TABLE(spi, ksz9477_spi_ids);
static struct spi_driver ksz9477_spi_driver = {
.driver = {
.name = "ksz9477-switch",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(ksz9477_dt_ids),
},
.id_table = ksz9477_spi_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");
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Microchip KSZ8795 series register access through SPI * Microchip ksz series register access through SPI
* *
* Copyright (C) 2017 Microchip Technology Inc. * Copyright (C) 2017 Microchip Technology Inc.
* Tristram Ha <Tristram.Ha@microchip.com> * Tristram Ha <Tristram.Ha@microchip.com>
...@@ -25,13 +25,20 @@ ...@@ -25,13 +25,20 @@
#define KSZ8863_SPI_ADDR_ALIGN 8 #define KSZ8863_SPI_ADDR_ALIGN 8
#define KSZ8863_SPI_TURNAROUND_SHIFT 0 #define KSZ8863_SPI_TURNAROUND_SHIFT 0
#define KSZ9477_SPI_ADDR_SHIFT 24
#define KSZ9477_SPI_ADDR_ALIGN 3
#define KSZ9477_SPI_TURNAROUND_SHIFT 5
KSZ_REGMAP_TABLE(ksz8795, 16, KSZ8795_SPI_ADDR_SHIFT, KSZ_REGMAP_TABLE(ksz8795, 16, KSZ8795_SPI_ADDR_SHIFT,
KSZ8795_SPI_TURNAROUND_SHIFT, KSZ8795_SPI_ADDR_ALIGN); KSZ8795_SPI_TURNAROUND_SHIFT, KSZ8795_SPI_ADDR_ALIGN);
KSZ_REGMAP_TABLE(ksz8863, 16, KSZ8863_SPI_ADDR_SHIFT, KSZ_REGMAP_TABLE(ksz8863, 16, KSZ8863_SPI_ADDR_SHIFT,
KSZ8863_SPI_TURNAROUND_SHIFT, KSZ8863_SPI_ADDR_ALIGN); KSZ8863_SPI_TURNAROUND_SHIFT, KSZ8863_SPI_ADDR_ALIGN);
static int ksz8795_spi_probe(struct spi_device *spi) KSZ_REGMAP_TABLE(ksz9477, 32, KSZ9477_SPI_ADDR_SHIFT,
KSZ9477_SPI_TURNAROUND_SHIFT, KSZ9477_SPI_ADDR_ALIGN);
static int ksz_spi_probe(struct spi_device *spi)
{ {
const struct regmap_config *regmap_config; const struct regmap_config *regmap_config;
const struct ksz_chip_data *chip; const struct ksz_chip_data *chip;
...@@ -57,8 +64,12 @@ static int ksz8795_spi_probe(struct spi_device *spi) ...@@ -57,8 +64,12 @@ static int ksz8795_spi_probe(struct spi_device *spi)
if (chip->chip_id == KSZ8830_CHIP_ID) if (chip->chip_id == KSZ8830_CHIP_ID)
regmap_config = ksz8863_regmap_config; regmap_config = ksz8863_regmap_config;
else else if (chip->chip_id == KSZ8795_CHIP_ID ||
chip->chip_id == KSZ8794_CHIP_ID ||
chip->chip_id == KSZ8765_CHIP_ID)
regmap_config = ksz8795_regmap_config; regmap_config = ksz8795_regmap_config;
else
regmap_config = ksz9477_regmap_config;
for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) { for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) {
rc = regmap_config[i]; rc = regmap_config[i];
...@@ -93,7 +104,7 @@ static int ksz8795_spi_probe(struct spi_device *spi) ...@@ -93,7 +104,7 @@ static int ksz8795_spi_probe(struct spi_device *spi)
return 0; return 0;
} }
static void ksz8795_spi_remove(struct spi_device *spi) static void ksz_spi_remove(struct spi_device *spi)
{ {
struct ksz_device *dev = spi_get_drvdata(spi); struct ksz_device *dev = spi_get_drvdata(spi);
...@@ -103,7 +114,7 @@ static void ksz8795_spi_remove(struct spi_device *spi) ...@@ -103,7 +114,7 @@ static void ksz8795_spi_remove(struct spi_device *spi)
spi_set_drvdata(spi, NULL); spi_set_drvdata(spi, NULL);
} }
static void ksz8795_spi_shutdown(struct spi_device *spi) static void ksz_spi_shutdown(struct spi_device *spi)
{ {
struct ksz_device *dev = spi_get_drvdata(spi); struct ksz_device *dev = spi_get_drvdata(spi);
...@@ -118,7 +129,7 @@ static void ksz8795_spi_shutdown(struct spi_device *spi) ...@@ -118,7 +129,7 @@ static void ksz8795_spi_shutdown(struct spi_device *spi)
spi_set_drvdata(spi, NULL); spi_set_drvdata(spi, NULL);
} }
static const struct of_device_id ksz8795_dt_ids[] = { static const struct of_device_id ksz_dt_ids[] = {
{ {
.compatible = "microchip,ksz8765", .compatible = "microchip,ksz8765",
.data = &ksz_switch_chips[KSZ8765] .data = &ksz_switch_chips[KSZ8765]
...@@ -139,34 +150,70 @@ static const struct of_device_id ksz8795_dt_ids[] = { ...@@ -139,34 +150,70 @@ static const struct of_device_id ksz8795_dt_ids[] = {
.compatible = "microchip,ksz8873", .compatible = "microchip,ksz8873",
.data = &ksz_switch_chips[KSZ8830] .data = &ksz_switch_chips[KSZ8830]
}, },
{
.compatible = "microchip,ksz9477",
.data = &ksz_switch_chips[KSZ9477]
},
{
.compatible = "microchip,ksz9897",
.data = &ksz_switch_chips[KSZ9897]
},
{
.compatible = "microchip,ksz9893",
.data = &ksz_switch_chips[KSZ9893]
},
{
.compatible = "microchip,ksz9563",
.data = &ksz_switch_chips[KSZ9893]
},
{
.compatible = "microchip,ksz8563",
.data = &ksz_switch_chips[KSZ9893]
},
{
.compatible = "microchip,ksz9567",
.data = &ksz_switch_chips[KSZ9567]
},
{}, {},
}; };
MODULE_DEVICE_TABLE(of, ksz8795_dt_ids); MODULE_DEVICE_TABLE(of, ksz_dt_ids);
static const struct spi_device_id ksz8795_spi_ids[] = { static const struct spi_device_id ksz_spi_ids[] = {
{ "ksz8765" }, { "ksz8765" },
{ "ksz8794" }, { "ksz8794" },
{ "ksz8795" }, { "ksz8795" },
{ "ksz8863" }, { "ksz8863" },
{ "ksz8873" }, { "ksz8873" },
{ "ksz9477" },
{ "ksz9897" },
{ "ksz9893" },
{ "ksz9563" },
{ "ksz8563" },
{ "ksz9567" },
{ }, { },
}; };
MODULE_DEVICE_TABLE(spi, ksz8795_spi_ids); MODULE_DEVICE_TABLE(spi, ksz_spi_ids);
static struct spi_driver ksz8795_spi_driver = { static struct spi_driver ksz_spi_driver = {
.driver = { .driver = {
.name = "ksz8795-switch", .name = "ksz-switch",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_match_ptr(ksz8795_dt_ids), .of_match_table = of_match_ptr(ksz_dt_ids),
}, },
.id_table = ksz8795_spi_ids, .id_table = ksz_spi_ids,
.probe = ksz8795_spi_probe, .probe = ksz_spi_probe,
.remove = ksz8795_spi_remove, .remove = ksz_spi_remove,
.shutdown = ksz8795_spi_shutdown, .shutdown = ksz_spi_shutdown,
}; };
module_spi_driver(ksz8795_spi_driver); module_spi_driver(ksz_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("Tristram Ha <Tristram.Ha@microchip.com>"); MODULE_AUTHOR("Tristram Ha <Tristram.Ha@microchip.com>");
MODULE_DESCRIPTION("Microchip KSZ8795 Series Switch SPI Driver"); MODULE_DESCRIPTION("Microchip ksz Series Switch SPI Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment