Commit ee394fea authored by Marek Vasut's avatar Marek Vasut Committed by David S. Miller

net: dsa: microchip: Dispose of ksz_io_ops

Since the driver now uses regmap , get rid of ad-hoc ksz_io_ops
abstraction, which no longer has any meaning. Moreover, since regmap
has it's own locking, get rid of the register access mutex.
Signed-off-by: default avatarMarek Vasut <marex@denx.de>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Tristram Ha <Tristram.Ha@microchip.com>
Cc: Woojung Huh <Woojung.Huh@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 46558d60
...@@ -46,67 +46,12 @@ static const struct regmap_config ksz9477_regmap_config[] = { ...@@ -46,67 +46,12 @@ static const struct regmap_config ksz9477_regmap_config[] = {
KSZ_REGMAP_COMMON(32), KSZ_REGMAP_COMMON(32),
}; };
static int ksz_spi_read8(struct ksz_device *dev, u32 reg, u8 *val)
{
unsigned int value;
int ret = regmap_read(dev->regmap, reg, &value);
*val = value;
return ret;
}
static int ksz_spi_read16(struct ksz_device *dev, u32 reg, u16 *val)
{
int ret = regmap_bulk_read(dev->regmap, reg, val, 2);
if (!ret)
*val = be16_to_cpu(*val);
return ret;
}
static int ksz_spi_read32(struct ksz_device *dev, u32 reg, u32 *val)
{
int ret = regmap_bulk_read(dev->regmap, reg, val, 4);
if (!ret)
*val = be32_to_cpu(*val);
return ret;
}
static int ksz_spi_write8(struct ksz_device *dev, u32 reg, u8 value)
{
return regmap_write(dev->regmap, reg, value);
}
static int ksz_spi_write16(struct ksz_device *dev, u32 reg, u16 value)
{
value = cpu_to_be16(value);
return regmap_bulk_write(dev->regmap, reg, &value, 2);
}
static int ksz_spi_write32(struct ksz_device *dev, u32 reg, u32 value)
{
value = cpu_to_be32(value);
return regmap_bulk_write(dev->regmap, reg, &value, 4);
}
static const struct ksz_io_ops ksz9477_spi_ops = {
.read8 = ksz_spi_read8,
.read16 = ksz_spi_read16,
.read32 = ksz_spi_read32,
.write8 = ksz_spi_write8,
.write16 = ksz_spi_write16,
.write32 = ksz_spi_write32,
};
static int ksz9477_spi_probe(struct spi_device *spi) static int ksz9477_spi_probe(struct spi_device *spi)
{ {
struct ksz_device *dev; struct ksz_device *dev;
int i, ret; int i, ret;
dev = ksz_switch_alloc(&spi->dev, &ksz9477_spi_ops, spi); dev = ksz_switch_alloc(&spi->dev, spi);
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
......
...@@ -396,9 +396,7 @@ void ksz_disable_port(struct dsa_switch *ds, int port) ...@@ -396,9 +396,7 @@ void ksz_disable_port(struct dsa_switch *ds, int port)
} }
EXPORT_SYMBOL_GPL(ksz_disable_port); EXPORT_SYMBOL_GPL(ksz_disable_port);
struct ksz_device *ksz_switch_alloc(struct device *base, struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
const struct ksz_io_ops *ops,
void *priv)
{ {
struct dsa_switch *ds; struct dsa_switch *ds;
struct ksz_device *swdev; struct ksz_device *swdev;
...@@ -416,7 +414,6 @@ struct ksz_device *ksz_switch_alloc(struct device *base, ...@@ -416,7 +414,6 @@ struct ksz_device *ksz_switch_alloc(struct device *base,
swdev->ds = ds; swdev->ds = ds;
swdev->priv = priv; swdev->priv = priv;
swdev->ops = ops;
return swdev; return swdev;
} }
...@@ -442,7 +439,6 @@ int ksz_switch_register(struct ksz_device *dev, ...@@ -442,7 +439,6 @@ int ksz_switch_register(struct ksz_device *dev,
} }
mutex_init(&dev->dev_mutex); mutex_init(&dev->dev_mutex);
mutex_init(&dev->reg_mutex);
mutex_init(&dev->stats_mutex); mutex_init(&dev->stats_mutex);
mutex_init(&dev->alu_mutex); mutex_init(&dev->alu_mutex);
mutex_init(&dev->vlan_mutex); mutex_init(&dev->vlan_mutex);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifndef __KSZ_COMMON_H #ifndef __KSZ_COMMON_H
#define __KSZ_COMMON_H #define __KSZ_COMMON_H
#include <linux/regmap.h>
void ksz_port_cleanup(struct ksz_device *dev, int port); void ksz_port_cleanup(struct ksz_device *dev, int port);
void ksz_update_port_member(struct ksz_device *dev, int port); void ksz_update_port_member(struct ksz_device *dev, int port);
void ksz_init_mib_timer(struct ksz_device *dev); void ksz_init_mib_timer(struct ksz_device *dev);
...@@ -41,68 +43,44 @@ void ksz_disable_port(struct dsa_switch *ds, int port); ...@@ -41,68 +43,44 @@ void ksz_disable_port(struct dsa_switch *ds, int port);
static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val) static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
{ {
int ret; unsigned int value;
int ret = regmap_read(dev->regmap[0], reg, &value);
mutex_lock(&dev->reg_mutex);
ret = dev->ops->read8(dev, reg, val);
mutex_unlock(&dev->reg_mutex);
*val = value;
return ret; return ret;
} }
static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val) static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
{ {
int ret; unsigned int value;
int ret = regmap_read(dev->regmap[1], reg, &value);
mutex_lock(&dev->reg_mutex);
ret = dev->ops->read16(dev, reg, val);
mutex_unlock(&dev->reg_mutex);
*val = value;
return ret; return ret;
} }
static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val) static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
{ {
int ret; unsigned int value;
int ret = regmap_read(dev->regmap[2], reg, &value);
mutex_lock(&dev->reg_mutex);
ret = dev->ops->read32(dev, reg, val);
mutex_unlock(&dev->reg_mutex);
*val = value;
return ret; return ret;
} }
static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value) static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
{ {
int ret; return regmap_write(dev->regmap[0], reg, value);
mutex_lock(&dev->reg_mutex);
ret = dev->ops->write8(dev, reg, value);
mutex_unlock(&dev->reg_mutex);
return ret;
} }
static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value) static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
{ {
int ret; return regmap_write(dev->regmap[1], reg, value);
mutex_lock(&dev->reg_mutex);
ret = dev->ops->write16(dev, reg, value);
mutex_unlock(&dev->reg_mutex);
return ret;
} }
static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value) static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
{ {
int ret; return regmap_write(dev->regmap[2], reg, value);
mutex_lock(&dev->reg_mutex);
ret = dev->ops->write32(dev, reg, value);
mutex_unlock(&dev->reg_mutex);
return ret;
} }
static inline void ksz_pread8(struct ksz_device *dev, int port, int offset, static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <net/dsa.h> #include <net/dsa.h>
struct ksz_io_ops;
struct vlan_table { struct vlan_table {
u32 table[3]; u32 table[3];
}; };
...@@ -49,11 +47,9 @@ struct ksz_device { ...@@ -49,11 +47,9 @@ struct ksz_device {
const char *name; const char *name;
struct mutex dev_mutex; /* device access */ struct mutex dev_mutex; /* device access */
struct mutex reg_mutex; /* register access */
struct mutex stats_mutex; /* status access */ struct mutex stats_mutex; /* status access */
struct mutex alu_mutex; /* ALU access */ struct mutex alu_mutex; /* ALU access */
struct mutex vlan_mutex; /* vlan access */ struct mutex vlan_mutex; /* vlan access */
const struct ksz_io_ops *ops;
const struct ksz_dev_ops *dev_ops; const struct ksz_dev_ops *dev_ops;
struct device *dev; struct device *dev;
...@@ -101,15 +97,6 @@ struct ksz_device { ...@@ -101,15 +97,6 @@ struct ksz_device {
u16 port_mask; u16 port_mask;
}; };
struct ksz_io_ops {
int (*read8)(struct ksz_device *dev, u32 reg, u8 *value);
int (*read16)(struct ksz_device *dev, u32 reg, u16 *value);
int (*read32)(struct ksz_device *dev, u32 reg, u32 *value);
int (*write8)(struct ksz_device *dev, u32 reg, u8 value);
int (*write16)(struct ksz_device *dev, u32 reg, u16 value);
int (*write32)(struct ksz_device *dev, u32 reg, u32 value);
};
struct alu_struct { struct alu_struct {
/* entry 1 */ /* entry 1 */
u8 is_static:1; u8 is_static:1;
...@@ -158,8 +145,7 @@ struct ksz_dev_ops { ...@@ -158,8 +145,7 @@ struct ksz_dev_ops {
void (*exit)(struct ksz_device *dev); void (*exit)(struct ksz_device *dev);
}; };
struct ksz_device *ksz_switch_alloc(struct device *base, struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
const struct ksz_io_ops *ops, void *priv);
int ksz_switch_register(struct ksz_device *dev, int ksz_switch_register(struct ksz_device *dev,
const struct ksz_dev_ops *ops); const struct ksz_dev_ops *ops);
void ksz_switch_remove(struct ksz_device *dev); void ksz_switch_remove(struct ksz_device *dev);
......
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