Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 291ab06e authored by Stefan Wahren's avatar Stefan Wahren Committed by David S. Miller
Browse files

net: qualcomm: new Ethernet over SPI driver for QCA7000



This patch adds the Ethernet over SPI driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7d50df8f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ config ETHOC
source "drivers/net/ethernet/packetengines/Kconfig"
source "drivers/net/ethernet/pasemi/Kconfig"
source "drivers/net/ethernet/qlogic/Kconfig"
source "drivers/net/ethernet/qualcomm/Kconfig"
source "drivers/net/ethernet/realtek/Kconfig"
source "drivers/net/ethernet/renesas/Kconfig"
source "drivers/net/ethernet/rdc/Kconfig"
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ obj-$(CONFIG_ETHOC) += ethoc.o
obj-$(CONFIG_NET_PACKET_ENGINE) += packetengines/
obj-$(CONFIG_NET_VENDOR_PASEMI) += pasemi/
obj-$(CONFIG_NET_VENDOR_QLOGIC) += qlogic/
obj-$(CONFIG_NET_VENDOR_QUALCOMM) += qualcomm/
obj-$(CONFIG_NET_VENDOR_REALTEK) += realtek/
obj-$(CONFIG_SH_ETH) += renesas/
obj-$(CONFIG_NET_VENDOR_RDC) += rdc/
+30 −0
Original line number Diff line number Diff line
#
# Qualcomm network device configuration
#

config NET_VENDOR_QUALCOMM
	bool "Qualcomm devices"
	default y
	depends on SPI_MASTER && OF_GPIO
	---help---
	  If you have a network (Ethernet) card belonging to this class, say Y
	  and read the Ethernet-HOWTO, available from
	  <http://www.tldp.org/docs.html#howto>.

	  Note that the answer to this question doesn't directly affect the
	  kernel: saying N will just cause the configurator to skip all
	  the questions about Qualcomm cards. If you say Y, you will be asked
	  for your specific card in the following questions.

if NET_VENDOR_QUALCOMM

config QCA7000
	tristate "Qualcomm Atheros QCA7000 support"
	depends on SPI_MASTER && OF_GPIO
	---help---
	  This SPI protocol driver supports the Qualcomm Atheros QCA7000.

	  To compile this driver as a module, choose M here. The module
	  will be called qcaspi.

endif # NET_VENDOR_QUALCOMM
+6 −0
Original line number Diff line number Diff line
#
# Makefile for the Qualcomm network device drivers.
#

obj-$(CONFIG_QCA7000) += qcaspi.o
qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+149 −0
Original line number Diff line number Diff line
/*
 *
 *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
 *   Copyright (c) 2014, I2SE GmbH
 *
 *   Permission to use, copy, modify, and/or distribute this software
 *   for any purpose with or without fee is hereby granted, provided
 *   that the above copyright notice and this permission notice appear
 *   in all copies.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
 *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

/*   This module implements the Qualcomm Atheros SPI protocol for
 *   kernel-based SPI device.
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/spi/spi.h>
#include <linux/version.h>

#include "qca_7k.h"

void
qcaspi_spi_error(struct qcaspi *qca)
{
	if (qca->sync != QCASPI_SYNC_READY)
		return;

	netdev_err(qca->net_dev, "spi error\n");
	qca->sync = QCASPI_SYNC_UNKNOWN;
	qca->stats.spi_err++;
}

int
qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result)
{
	__be16 rx_data;
	__be16 tx_data;
	struct spi_transfer *transfer;
	struct spi_message *msg;
	int ret;

	tx_data = cpu_to_be16(QCA7K_SPI_READ | QCA7K_SPI_INTERNAL | reg);

	if (qca->legacy_mode) {
		msg = &qca->spi_msg1;
		transfer = &qca->spi_xfer1;
		transfer->tx_buf = &tx_data;
		transfer->rx_buf = NULL;
		transfer->len = QCASPI_CMD_LEN;
		spi_sync(qca->spi_dev, msg);
	} else {
		msg = &qca->spi_msg2;
		transfer = &qca->spi_xfer2[0];
		transfer->tx_buf = &tx_data;
		transfer->rx_buf = NULL;
		transfer->len = QCASPI_CMD_LEN;
		transfer = &qca->spi_xfer2[1];
	}
	transfer->tx_buf = NULL;
	transfer->rx_buf = &rx_data;
	transfer->len = QCASPI_CMD_LEN;
	ret = spi_sync(qca->spi_dev, msg);

	if (!ret)
		ret = msg->status;

	if (ret)
		qcaspi_spi_error(qca);
	else
		*result = be16_to_cpu(rx_data);

	return ret;
}

int
qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value)
{
	__be16 tx_data[2];
	struct spi_transfer *transfer;
	struct spi_message *msg;
	int ret;

	tx_data[0] = cpu_to_be16(QCA7K_SPI_WRITE | QCA7K_SPI_INTERNAL | reg);
	tx_data[1] = cpu_to_be16(value);

	if (qca->legacy_mode) {
		msg = &qca->spi_msg1;
		transfer = &qca->spi_xfer1;
		transfer->tx_buf = &tx_data[0];
		transfer->rx_buf = NULL;
		transfer->len = QCASPI_CMD_LEN;
		spi_sync(qca->spi_dev, msg);
	} else {
		msg = &qca->spi_msg2;
		transfer = &qca->spi_xfer2[0];
		transfer->tx_buf = &tx_data[0];
		transfer->rx_buf = NULL;
		transfer->len = QCASPI_CMD_LEN;
		transfer = &qca->spi_xfer2[1];
	}
	transfer->tx_buf = &tx_data[1];
	transfer->rx_buf = NULL;
	transfer->len = QCASPI_CMD_LEN;
	ret = spi_sync(qca->spi_dev, msg);

	if (!ret)
		ret = msg->status;

	if (ret)
		qcaspi_spi_error(qca);

	return ret;
}

int
qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
{
	__be16 tx_data;
	struct spi_message *msg = &qca->spi_msg1;
	struct spi_transfer *transfer = &qca->spi_xfer1;
	int ret;

	tx_data = cpu_to_be16(cmd);
	transfer->len = sizeof(tx_data);
	transfer->tx_buf = &tx_data;
	transfer->rx_buf = NULL;

	ret = spi_sync(qca->spi_dev, msg);

	if (!ret)
		ret = msg->status;

	if (ret)
		qcaspi_spi_error(qca);

	return ret;
}
Loading