Commit d4921643 authored by Hugo Villeneuve's avatar Hugo Villeneuve Committed by Greg Kroah-Hartman

serial: sc16is7xx: split into core and I2C/SPI parts (core)

Split the common code from sc16is7xx driver and move the I2C and SPI bus
parts into interface-specific source files.

sc16is7xx becomes the core functions which can support multiple bus
interfaces like I2C and SPI.

No functional changes intended.

Also simplify and improve Kconfig entries.
  - Capitalize SPI keyword for consistency
  - Display list of supported ICs each on a separate line (and aligned) to
    facilitate locating a specific IC model
  - Add Manufacturer name at start of description string
  - Add UART keyword to description string
Suggested-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarHugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://lore.kernel.org/r/20240409154253.3043822-4-hugo@hugovil.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7f335744
...@@ -1024,41 +1024,30 @@ config SERIAL_SCCNXP_CONSOLE ...@@ -1024,41 +1024,30 @@ config SERIAL_SCCNXP_CONSOLE
Support for console on SCCNXP serial ports. Support for console on SCCNXP serial ports.
config SERIAL_SC16IS7XX_CORE config SERIAL_SC16IS7XX_CORE
tristate tristate "NXP SC16IS7xx UART support"
config SERIAL_SC16IS7XX
tristate "SC16IS7xx serial support"
select SERIAL_CORE select SERIAL_CORE
depends on (SPI_MASTER && !I2C) || I2C select SERIAL_SC16IS7XX_SPI if SPI_MASTER
select SERIAL_SC16IS7XX_I2C if I2C
help help
This selects support for SC16IS7xx serial ports. Core driver for NXP SC16IS7xx UARTs.
Supported ICs are SC16IS740, SC16IS741, SC16IS750, SC16IS752, Supported ICs are:
SC16IS760 and SC16IS762. Select supported buses using options below.
SC16IS740
SC16IS741
SC16IS750
SC16IS752
SC16IS760
SC16IS762
The driver supports both I2C and SPI interfaces.
config SERIAL_SC16IS7XX_I2C config SERIAL_SC16IS7XX_I2C
bool "SC16IS7xx for I2C interface" tristate
depends on SERIAL_SC16IS7XX select REGMAP_I2C
depends on I2C
select SERIAL_SC16IS7XX_CORE if SERIAL_SC16IS7XX
select REGMAP_I2C if I2C
default y
help
Enable SC16IS7xx driver on I2C bus,
If required say y, and say n to i2c if not required,
Enabled by default to support oldconfig.
You must select at least one bus for the driver to be built.
config SERIAL_SC16IS7XX_SPI config SERIAL_SC16IS7XX_SPI
bool "SC16IS7xx for spi interface" tristate
depends on SERIAL_SC16IS7XX select REGMAP_SPI
depends on SPI_MASTER
select SERIAL_SC16IS7XX_CORE if SERIAL_SC16IS7XX
select REGMAP_SPI if SPI_MASTER
help
Enable SC16IS7xx driver on SPI bus,
If required say y, and say n to spi if not required,
This is additional support to existing driver.
You must select at least one bus for the driver to be built.
config SERIAL_TIMBERDALE config SERIAL_TIMBERDALE
tristate "Support for timberdale UART" tristate "Support for timberdale UART"
......
...@@ -76,6 +76,8 @@ obj-$(CONFIG_SERIAL_SAMSUNG) += samsung_tty.o ...@@ -76,6 +76,8 @@ obj-$(CONFIG_SERIAL_SAMSUNG) += samsung_tty.o
obj-$(CONFIG_SERIAL_SB1250_DUART) += sb1250-duart.o obj-$(CONFIG_SERIAL_SB1250_DUART) += sb1250-duart.o
obj-$(CONFIG_SERIAL_SCCNXP) += sccnxp.o obj-$(CONFIG_SERIAL_SCCNXP) += sccnxp.o
obj-$(CONFIG_SERIAL_SC16IS7XX_CORE) += sc16is7xx.o obj-$(CONFIG_SERIAL_SC16IS7XX_CORE) += sc16is7xx.o
obj-$(CONFIG_SERIAL_SC16IS7XX_SPI) += sc16is7xx_spi.o
obj-$(CONFIG_SERIAL_SC16IS7XX_I2C) += sc16is7xx_i2c.o
obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o
obj-$(CONFIG_SERIAL_SIFIVE) += sifive.o obj-$(CONFIG_SERIAL_SIFIVE) += sifive.o
obj-$(CONFIG_SERIAL_SPRD) += sprd_serial.o obj-$(CONFIG_SERIAL_SPRD) += sprd_serial.o
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0+ */
/* SC16IS7xx SPI/I2C tty serial driver */
#ifndef _SC16IS7XX_H_
#define _SC16IS7XX_H_
#include <linux/mod_devicetable.h>
#include <linux/regmap.h>
#include <linux/types.h>
#define SC16IS7XX_NAME "sc16is7xx"
#define SC16IS7XX_MAX_PORTS 2 /* Maximum number of UART ports per IC. */
struct device;
struct sc16is7xx_devtype {
char name[10];
int nr_gpio;
int nr_uart;
};
extern struct regmap_config sc16is7xx_regcfg;
extern const struct of_device_id sc16is7xx_dt_ids[];
extern const struct sc16is7xx_devtype sc16is74x_devtype;
extern const struct sc16is7xx_devtype sc16is750_devtype;
extern const struct sc16is7xx_devtype sc16is752_devtype;
extern const struct sc16is7xx_devtype sc16is760_devtype;
extern const struct sc16is7xx_devtype sc16is762_devtype;
const char *sc16is7xx_regmap_name(u8 port_id);
unsigned int sc16is7xx_regmap_port_mask(unsigned int port_id);
int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
struct regmap *regmaps[], int irq);
void sc16is7xx_remove(struct device *dev);
#endif /* _SC16IS7XX_H_ */
// SPDX-License-Identifier: GPL-2.0+
/* SC16IS7xx I2C interface driver */
#include <linux/dev_printk.h>
#include <linux/i2c.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/string.h>
#include "sc16is7xx.h"
static int sc16is7xx_i2c_probe(struct i2c_client *i2c)
{
const struct sc16is7xx_devtype *devtype;
struct regmap *regmaps[SC16IS7XX_MAX_PORTS];
unsigned int i;
devtype = i2c_get_match_data(i2c);
if (!devtype)
return dev_err_probe(&i2c->dev, -ENODEV, "Failed to match device\n");
for (i = 0; i < devtype->nr_uart; i++) {
sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i);
sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i);
sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
regmaps[i] = devm_regmap_init_i2c(i2c, &sc16is7xx_regcfg);
}
return sc16is7xx_probe(&i2c->dev, devtype, regmaps, i2c->irq);
}
static void sc16is7xx_i2c_remove(struct i2c_client *client)
{
sc16is7xx_remove(&client->dev);
}
static const struct i2c_device_id sc16is7xx_i2c_id_table[] = {
{ "sc16is74x", (kernel_ulong_t)&sc16is74x_devtype, },
{ "sc16is740", (kernel_ulong_t)&sc16is74x_devtype, },
{ "sc16is741", (kernel_ulong_t)&sc16is74x_devtype, },
{ "sc16is750", (kernel_ulong_t)&sc16is750_devtype, },
{ "sc16is752", (kernel_ulong_t)&sc16is752_devtype, },
{ "sc16is760", (kernel_ulong_t)&sc16is760_devtype, },
{ "sc16is762", (kernel_ulong_t)&sc16is762_devtype, },
{ }
};
MODULE_DEVICE_TABLE(i2c, sc16is7xx_i2c_id_table);
static struct i2c_driver sc16is7xx_i2c_driver = {
.driver = {
.name = SC16IS7XX_NAME,
.of_match_table = sc16is7xx_dt_ids,
},
.probe = sc16is7xx_i2c_probe,
.remove = sc16is7xx_i2c_remove,
.id_table = sc16is7xx_i2c_id_table,
};
module_i2c_driver(sc16is7xx_i2c_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SC16IS7xx I2C interface driver");
MODULE_IMPORT_NS(SERIAL_NXP_SC16IS7XX);
// SPDX-License-Identifier: GPL-2.0+
/* SC16IS7xx SPI interface driver */
#include <linux/dev_printk.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include <linux/string.h>
#include <linux/units.h>
#include "sc16is7xx.h"
/* SPI definitions */
#define SC16IS7XX_SPI_READ_BIT BIT(7)
static int sc16is7xx_spi_probe(struct spi_device *spi)
{
const struct sc16is7xx_devtype *devtype;
struct regmap *regmaps[SC16IS7XX_MAX_PORTS];
unsigned int i;
int ret;
/* Setup SPI bus */
spi->bits_per_word = 8;
/* For all variants, only mode 0 is supported */
if ((spi->mode & SPI_MODE_X_MASK) != SPI_MODE_0)
return dev_err_probe(&spi->dev, -EINVAL, "Unsupported SPI mode\n");
spi->mode = spi->mode ? : SPI_MODE_0;
spi->max_speed_hz = spi->max_speed_hz ? : 4 * HZ_PER_MHZ;
ret = spi_setup(spi);
if (ret)
return ret;
devtype = spi_get_device_match_data(spi);
if (!devtype)
return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n");
for (i = 0; i < devtype->nr_uart; i++) {
sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i);
/*
* If read_flag_mask is 0, the regmap code sets it to a default
* of 0x80. Since we specify our own mask, we must add the READ
* bit ourselves:
*/
sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i) |
SC16IS7XX_SPI_READ_BIT;
sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
regmaps[i] = devm_regmap_init_spi(spi, &sc16is7xx_regcfg);
}
return sc16is7xx_probe(&spi->dev, devtype, regmaps, spi->irq);
}
static void sc16is7xx_spi_remove(struct spi_device *spi)
{
sc16is7xx_remove(&spi->dev);
}
static const struct spi_device_id sc16is7xx_spi_id_table[] = {
{ "sc16is74x", (kernel_ulong_t)&sc16is74x_devtype, },
{ "sc16is740", (kernel_ulong_t)&sc16is74x_devtype, },
{ "sc16is741", (kernel_ulong_t)&sc16is74x_devtype, },
{ "sc16is750", (kernel_ulong_t)&sc16is750_devtype, },
{ "sc16is752", (kernel_ulong_t)&sc16is752_devtype, },
{ "sc16is760", (kernel_ulong_t)&sc16is760_devtype, },
{ "sc16is762", (kernel_ulong_t)&sc16is762_devtype, },
{ }
};
MODULE_DEVICE_TABLE(spi, sc16is7xx_spi_id_table);
static struct spi_driver sc16is7xx_spi_driver = {
.driver = {
.name = SC16IS7XX_NAME,
.of_match_table = sc16is7xx_dt_ids,
},
.probe = sc16is7xx_spi_probe,
.remove = sc16is7xx_spi_remove,
.id_table = sc16is7xx_spi_id_table,
};
module_spi_driver(sc16is7xx_spi_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SC16IS7xx SPI interface driver");
MODULE_IMPORT_NS(SERIAL_NXP_SC16IS7XX);
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