mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-09-08 01:08:03 -04:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
65
drivers/net/ieee802154/Kconfig
Normal file
65
drivers/net/ieee802154/Kconfig
Normal file
|
@ -0,0 +1,65 @@
|
|||
menuconfig IEEE802154_DRIVERS
|
||||
tristate "IEEE 802.15.4 drivers"
|
||||
depends on NETDEVICES && IEEE802154
|
||||
default y
|
||||
---help---
|
||||
Say Y here to get to see options for IEEE 802.15.4 Low-Rate
|
||||
Wireless Personal Area Network device drivers. This option alone
|
||||
does not add any kernel code.
|
||||
|
||||
If you say N, all options in this submenu will be skipped and
|
||||
disabled.
|
||||
|
||||
config IEEE802154_FAKEHARD
|
||||
tristate "Fake LR-WPAN driver with several interconnected devices"
|
||||
depends on IEEE802154_DRIVERS
|
||||
---help---
|
||||
Say Y here to enable the fake driver that serves as an example
|
||||
of HardMAC device driver.
|
||||
|
||||
This driver can also be built as a module. To do so say M here.
|
||||
The module will be called 'fakehard'.
|
||||
|
||||
config IEEE802154_FAKELB
|
||||
depends on IEEE802154_DRIVERS && MAC802154
|
||||
tristate "IEEE 802.15.4 loopback driver"
|
||||
---help---
|
||||
Say Y here to enable the fake driver that can emulate a net
|
||||
of several interconnected radio devices.
|
||||
|
||||
This driver can also be built as a module. To do so say M here.
|
||||
The module will be called 'fakelb'.
|
||||
|
||||
config IEEE802154_AT86RF230
|
||||
depends on IEEE802154_DRIVERS && MAC802154
|
||||
tristate "AT86RF230/231/233/212 transceiver driver"
|
||||
depends on SPI
|
||||
select REGMAP_SPI
|
||||
---help---
|
||||
Say Y here to enable the at86rf230/231/233/212 SPI 802.15.4 wireless
|
||||
controller.
|
||||
|
||||
This driver can also be built as a module. To do so, say M here.
|
||||
the module will be called 'at86rf230'.
|
||||
|
||||
config IEEE802154_MRF24J40
|
||||
tristate "Microchip MRF24J40 transceiver driver"
|
||||
depends on IEEE802154_DRIVERS && MAC802154
|
||||
depends on SPI
|
||||
---help---
|
||||
Say Y here to enable the MRF24J20 SPI 802.15.4 wireless
|
||||
controller.
|
||||
|
||||
This driver can also be built as a module. To do so, say M here.
|
||||
the module will be called 'mrf24j40'.
|
||||
|
||||
config IEEE802154_CC2520
|
||||
depends on IEEE802154_DRIVERS && MAC802154
|
||||
tristate "CC2520 transceiver driver"
|
||||
depends on SPI
|
||||
---help---
|
||||
Say Y here to enable the CC2520 SPI 802.15.4 wireless
|
||||
controller.
|
||||
|
||||
This driver can also be built as a module. To do so, say M here.
|
||||
the module will be called 'cc2520'.
|
5
drivers/net/ieee802154/Makefile
Normal file
5
drivers/net/ieee802154/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
obj-$(CONFIG_IEEE802154_FAKEHARD) += fakehard.o
|
||||
obj-$(CONFIG_IEEE802154_FAKELB) += fakelb.o
|
||||
obj-$(CONFIG_IEEE802154_AT86RF230) += at86rf230.o
|
||||
obj-$(CONFIG_IEEE802154_MRF24J40) += mrf24j40.o
|
||||
obj-$(CONFIG_IEEE802154_CC2520) += cc2520.o
|
1624
drivers/net/ieee802154/at86rf230.c
Normal file
1624
drivers/net/ieee802154/at86rf230.c
Normal file
File diff suppressed because it is too large
Load diff
1039
drivers/net/ieee802154/cc2520.c
Normal file
1039
drivers/net/ieee802154/cc2520.c
Normal file
File diff suppressed because it is too large
Load diff
430
drivers/net/ieee802154/fakehard.c
Normal file
430
drivers/net/ieee802154/fakehard.c
Normal file
|
@ -0,0 +1,430 @@
|
|||
/*
|
||||
* Sample driver for HardMAC IEEE 802.15.4 devices
|
||||
*
|
||||
* Copyright (C) 2009 Siemens AG
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Written by:
|
||||
* Dmitry Eremin-Solenikov <dmitry.baryshkov@siemens.com>
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/if_arp.h>
|
||||
|
||||
#include <net/af_ieee802154.h>
|
||||
#include <net/ieee802154_netdev.h>
|
||||
#include <net/ieee802154.h>
|
||||
#include <net/nl802154.h>
|
||||
#include <net/wpan-phy.h>
|
||||
|
||||
struct fakehard_priv {
|
||||
struct wpan_phy *phy;
|
||||
};
|
||||
|
||||
static struct wpan_phy *fake_to_phy(const struct net_device *dev)
|
||||
{
|
||||
struct fakehard_priv *priv = netdev_priv(dev);
|
||||
return priv->phy;
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_get_phy - Return a phy corresponding to this device.
|
||||
* @dev: The network device for which to return the wan-phy object
|
||||
*
|
||||
* This function returns a wpan-phy object corresponding to the passed
|
||||
* network device. Reference counter for wpan-phy object is incremented,
|
||||
* so when the wpan-phy isn't necessary, you should drop the reference
|
||||
* via @wpan_phy_put() call.
|
||||
*/
|
||||
static struct wpan_phy *fake_get_phy(const struct net_device *dev)
|
||||
{
|
||||
struct wpan_phy *phy = fake_to_phy(dev);
|
||||
return to_phy(get_device(&phy->dev));
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_get_pan_id - Retrieve the PAN ID of the device.
|
||||
* @dev: The network device to retrieve the PAN of.
|
||||
*
|
||||
* Return the ID of the PAN from the PIB.
|
||||
*/
|
||||
static __le16 fake_get_pan_id(const struct net_device *dev)
|
||||
{
|
||||
BUG_ON(dev->type != ARPHRD_IEEE802154);
|
||||
|
||||
return cpu_to_le16(0xeba1);
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_get_short_addr - Retrieve the short address of the device.
|
||||
* @dev: The network device to retrieve the short address of.
|
||||
*
|
||||
* Returns the IEEE 802.15.4 short-form address cached for this
|
||||
* device. If the device has not yet had a short address assigned
|
||||
* then this should return 0xFFFF to indicate a lack of association.
|
||||
*/
|
||||
static __le16 fake_get_short_addr(const struct net_device *dev)
|
||||
{
|
||||
BUG_ON(dev->type != ARPHRD_IEEE802154);
|
||||
|
||||
return cpu_to_le16(0x1);
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_get_dsn - Retrieve the DSN of the device.
|
||||
* @dev: The network device to retrieve the DSN for.
|
||||
*
|
||||
* Returns the IEEE 802.15.4 DSN for the network device.
|
||||
* The DSN is the sequence number which will be added to each
|
||||
* packet or MAC command frame by the MAC during transmission.
|
||||
*
|
||||
* DSN means 'Data Sequence Number'.
|
||||
*
|
||||
* Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006
|
||||
* document.
|
||||
*/
|
||||
static u8 fake_get_dsn(const struct net_device *dev)
|
||||
{
|
||||
BUG_ON(dev->type != ARPHRD_IEEE802154);
|
||||
|
||||
return 0x00; /* DSN are implemented in HW, so return just 0 */
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_assoc_req - Make an association request to the HW.
|
||||
* @dev: The network device which we are associating to a network.
|
||||
* @addr: The coordinator with which we wish to associate.
|
||||
* @channel: The channel on which to associate.
|
||||
* @cap: The capability information field to use in the association.
|
||||
*
|
||||
* Start an association with a coordinator. The coordinator's address
|
||||
* and PAN ID can be found in @addr.
|
||||
*
|
||||
* Note: This is in section 7.3.1 and 7.5.3.1 of the IEEE
|
||||
* 802.15.4-2006 document.
|
||||
*/
|
||||
static int fake_assoc_req(struct net_device *dev,
|
||||
struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap)
|
||||
{
|
||||
struct wpan_phy *phy = fake_to_phy(dev);
|
||||
|
||||
mutex_lock(&phy->pib_lock);
|
||||
phy->current_channel = channel;
|
||||
phy->current_page = page;
|
||||
mutex_unlock(&phy->pib_lock);
|
||||
|
||||
/* We simply emulate it here */
|
||||
return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev),
|
||||
IEEE802154_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_assoc_resp - Send an association response to a device.
|
||||
* @dev: The network device on which to send the response.
|
||||
* @addr: The address of the device to respond to.
|
||||
* @short_addr: The assigned short address for the device (if any).
|
||||
* @status: The result of the association request.
|
||||
*
|
||||
* Queue the association response of the coordinator to another
|
||||
* device's attempt to associate with the network which we
|
||||
* coordinate. This is then added to the indirect-send queue to be
|
||||
* transmitted to the end device when it polls for data.
|
||||
*
|
||||
* Note: This is in section 7.3.2 and 7.5.3.1 of the IEEE
|
||||
* 802.15.4-2006 document.
|
||||
*/
|
||||
static int fake_assoc_resp(struct net_device *dev,
|
||||
struct ieee802154_addr *addr, __le16 short_addr, u8 status)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_disassoc_req - Disassociate a device from a network.
|
||||
* @dev: The network device on which we're disassociating a device.
|
||||
* @addr: The device to disassociate from the network.
|
||||
* @reason: The reason to give to the device for being disassociated.
|
||||
*
|
||||
* This sends a disassociation notification to the device being
|
||||
* disassociated from the network.
|
||||
*
|
||||
* Note: This is in section 7.5.3.2 of the IEEE 802.15.4-2006
|
||||
* document, with the reason described in 7.3.3.2.
|
||||
*/
|
||||
static int fake_disassoc_req(struct net_device *dev,
|
||||
struct ieee802154_addr *addr, u8 reason)
|
||||
{
|
||||
return ieee802154_nl_disassoc_confirm(dev, IEEE802154_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_start_req - Start an IEEE 802.15.4 PAN.
|
||||
* @dev: The network device on which to start the PAN.
|
||||
* @addr: The coordinator address to use when starting the PAN.
|
||||
* @channel: The channel on which to start the PAN.
|
||||
* @bcn_ord: Beacon order.
|
||||
* @sf_ord: Superframe order.
|
||||
* @pan_coord: Whether or not we are the PAN coordinator or just
|
||||
* requesting a realignment perhaps?
|
||||
* @blx: Battery Life Extension feature bitfield.
|
||||
* @coord_realign: Something to realign something else.
|
||||
*
|
||||
* If pan_coord is non-zero then this starts a network with the
|
||||
* provided parameters, otherwise it attempts a coordinator
|
||||
* realignment of the stated network instead.
|
||||
*
|
||||
* Note: This is in section 7.5.2.3 of the IEEE 802.15.4-2006
|
||||
* document, with 7.3.8 describing coordinator realignment.
|
||||
*/
|
||||
static int fake_start_req(struct net_device *dev,
|
||||
struct ieee802154_addr *addr, u8 channel, u8 page,
|
||||
u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
|
||||
u8 coord_realign)
|
||||
{
|
||||
struct wpan_phy *phy = fake_to_phy(dev);
|
||||
|
||||
mutex_lock(&phy->pib_lock);
|
||||
phy->current_channel = channel;
|
||||
phy->current_page = page;
|
||||
mutex_unlock(&phy->pib_lock);
|
||||
|
||||
/* We don't emulate beacons here at all, so START should fail */
|
||||
ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fake_scan_req - Start a channel scan.
|
||||
* @dev: The network device on which to perform a channel scan.
|
||||
* @type: The type of scan to perform.
|
||||
* @channels: The channel bitmask to scan.
|
||||
* @duration: How long to spend on each channel.
|
||||
*
|
||||
* This starts either a passive (energy) scan or an active (PAN) scan
|
||||
* on the channels indicated in the @channels bitmask. The duration of
|
||||
* the scan is measured in terms of superframe duration. Specifically,
|
||||
* the scan will spend aBaseSuperFrameDuration * ((2^n) + 1) on each
|
||||
* channel.
|
||||
*
|
||||
* Note: This is in section 7.5.2.1 of the IEEE 802.15.4-2006 document.
|
||||
*/
|
||||
static int fake_scan_req(struct net_device *dev, u8 type, u32 channels,
|
||||
u8 page, u8 duration)
|
||||
{
|
||||
u8 edl[27] = {};
|
||||
return ieee802154_nl_scan_confirm(dev, IEEE802154_SUCCESS, type,
|
||||
channels, page,
|
||||
type == IEEE802154_MAC_SCAN_ED ? edl : NULL);
|
||||
}
|
||||
|
||||
static struct ieee802154_mlme_ops fake_mlme = {
|
||||
.assoc_req = fake_assoc_req,
|
||||
.assoc_resp = fake_assoc_resp,
|
||||
.disassoc_req = fake_disassoc_req,
|
||||
.start_req = fake_start_req,
|
||||
.scan_req = fake_scan_req,
|
||||
|
||||
.get_phy = fake_get_phy,
|
||||
|
||||
.get_pan_id = fake_get_pan_id,
|
||||
.get_short_addr = fake_get_short_addr,
|
||||
.get_dsn = fake_get_dsn,
|
||||
};
|
||||
|
||||
static int ieee802154_fake_open(struct net_device *dev)
|
||||
{
|
||||
netif_start_queue(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ieee802154_fake_close(struct net_device *dev)
|
||||
{
|
||||
netif_stop_queue(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static netdev_tx_t ieee802154_fake_xmit(struct sk_buff *skb,
|
||||
struct net_device *dev)
|
||||
{
|
||||
dev->stats.tx_packets++;
|
||||
dev->stats.tx_bytes += skb->len;
|
||||
|
||||
/* FIXME: do hardware work here ... */
|
||||
|
||||
dev_kfree_skb(skb);
|
||||
return NETDEV_TX_OK;
|
||||
}
|
||||
|
||||
|
||||
static int ieee802154_fake_ioctl(struct net_device *dev, struct ifreq *ifr,
|
||||
int cmd)
|
||||
{
|
||||
struct sockaddr_ieee802154 *sa =
|
||||
(struct sockaddr_ieee802154 *)&ifr->ifr_addr;
|
||||
u16 pan_id, short_addr;
|
||||
|
||||
switch (cmd) {
|
||||
case SIOCGIFADDR:
|
||||
/* FIXME: fixed here, get from device IRL */
|
||||
pan_id = le16_to_cpu(fake_get_pan_id(dev));
|
||||
short_addr = le16_to_cpu(fake_get_short_addr(dev));
|
||||
if (pan_id == IEEE802154_PANID_BROADCAST ||
|
||||
short_addr == IEEE802154_ADDR_BROADCAST)
|
||||
return -EADDRNOTAVAIL;
|
||||
|
||||
sa->family = AF_IEEE802154;
|
||||
sa->addr.addr_type = IEEE802154_ADDR_SHORT;
|
||||
sa->addr.pan_id = pan_id;
|
||||
sa->addr.short_addr = short_addr;
|
||||
return 0;
|
||||
}
|
||||
return -ENOIOCTLCMD;
|
||||
}
|
||||
|
||||
static int ieee802154_fake_mac_addr(struct net_device *dev, void *p)
|
||||
{
|
||||
return -EBUSY; /* HW address is built into the device */
|
||||
}
|
||||
|
||||
static const struct net_device_ops fake_ops = {
|
||||
.ndo_open = ieee802154_fake_open,
|
||||
.ndo_stop = ieee802154_fake_close,
|
||||
.ndo_start_xmit = ieee802154_fake_xmit,
|
||||
.ndo_do_ioctl = ieee802154_fake_ioctl,
|
||||
.ndo_set_mac_address = ieee802154_fake_mac_addr,
|
||||
};
|
||||
|
||||
static void ieee802154_fake_destruct(struct net_device *dev)
|
||||
{
|
||||
struct wpan_phy *phy = fake_to_phy(dev);
|
||||
|
||||
wpan_phy_unregister(phy);
|
||||
free_netdev(dev);
|
||||
wpan_phy_free(phy);
|
||||
}
|
||||
|
||||
static void ieee802154_fake_setup(struct net_device *dev)
|
||||
{
|
||||
dev->addr_len = IEEE802154_ADDR_LEN;
|
||||
memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
|
||||
dev->features = NETIF_F_HW_CSUM;
|
||||
dev->needed_tailroom = 2; /* FCS */
|
||||
dev->mtu = 127;
|
||||
dev->tx_queue_len = 10;
|
||||
dev->type = ARPHRD_IEEE802154;
|
||||
dev->flags = IFF_NOARP | IFF_BROADCAST;
|
||||
dev->watchdog_timeo = 0;
|
||||
dev->destructor = ieee802154_fake_destruct;
|
||||
}
|
||||
|
||||
|
||||
static int ieee802154fake_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct net_device *dev;
|
||||
struct fakehard_priv *priv;
|
||||
struct wpan_phy *phy = wpan_phy_alloc(0);
|
||||
int err;
|
||||
|
||||
if (!phy)
|
||||
return -ENOMEM;
|
||||
|
||||
dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d",
|
||||
NET_NAME_UNKNOWN, ieee802154_fake_setup);
|
||||
if (!dev) {
|
||||
wpan_phy_free(phy);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef",
|
||||
dev->addr_len);
|
||||
|
||||
/*
|
||||
* For now we'd like to emulate 2.4 GHz-only device,
|
||||
* both O-QPSK and CSS
|
||||
*/
|
||||
/* 2.4 GHz O-QPSK 802.15.4-2003 */
|
||||
phy->channels_supported[0] |= 0x7FFF800;
|
||||
/* 2.4 GHz CSS 802.15.4a-2007 */
|
||||
phy->channels_supported[3] |= 0x3fff;
|
||||
|
||||
phy->transmit_power = 0xbf;
|
||||
|
||||
dev->netdev_ops = &fake_ops;
|
||||
dev->ml_priv = &fake_mlme;
|
||||
|
||||
priv = netdev_priv(dev);
|
||||
priv->phy = phy;
|
||||
|
||||
wpan_phy_set_dev(phy, &pdev->dev);
|
||||
SET_NETDEV_DEV(dev, &phy->dev);
|
||||
|
||||
platform_set_drvdata(pdev, dev);
|
||||
|
||||
err = wpan_phy_register(phy);
|
||||
if (err)
|
||||
goto err_phy_reg;
|
||||
|
||||
err = register_netdev(dev);
|
||||
if (err)
|
||||
goto err_netdev_reg;
|
||||
|
||||
dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
|
||||
return 0;
|
||||
|
||||
err_netdev_reg:
|
||||
wpan_phy_unregister(phy);
|
||||
err_phy_reg:
|
||||
free_netdev(dev);
|
||||
wpan_phy_free(phy);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int ieee802154fake_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct net_device *dev = platform_get_drvdata(pdev);
|
||||
unregister_netdev(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_device *ieee802154fake_dev;
|
||||
|
||||
static struct platform_driver ieee802154fake_driver = {
|
||||
.probe = ieee802154fake_probe,
|
||||
.remove = ieee802154fake_remove,
|
||||
.driver = {
|
||||
.name = "ieee802154hardmac",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
static __init int fake_init(void)
|
||||
{
|
||||
ieee802154fake_dev = platform_device_register_simple(
|
||||
"ieee802154hardmac", -1, NULL, 0);
|
||||
return platform_driver_register(&ieee802154fake_driver);
|
||||
}
|
||||
|
||||
static __exit void fake_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&ieee802154fake_driver);
|
||||
platform_device_unregister(ieee802154fake_dev);
|
||||
}
|
||||
|
||||
module_init(fake_init);
|
||||
module_exit(fake_exit);
|
||||
MODULE_LICENSE("GPL");
|
294
drivers/net/ieee802154/fakelb.c
Normal file
294
drivers/net/ieee802154/fakelb.c
Normal file
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* Loopback IEEE 802.15.4 interface
|
||||
*
|
||||
* Copyright 2007-2012 Siemens AG
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Written by:
|
||||
* Sergey Lapin <slapin@ossfans.org>
|
||||
* Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
|
||||
* Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <net/mac802154.h>
|
||||
#include <net/wpan-phy.h>
|
||||
|
||||
static int numlbs = 1;
|
||||
|
||||
struct fakelb_dev_priv {
|
||||
struct ieee802154_dev *dev;
|
||||
|
||||
struct list_head list;
|
||||
struct fakelb_priv *fake;
|
||||
|
||||
spinlock_t lock;
|
||||
bool working;
|
||||
};
|
||||
|
||||
struct fakelb_priv {
|
||||
struct list_head list;
|
||||
rwlock_t lock;
|
||||
};
|
||||
|
||||
static int
|
||||
fakelb_hw_ed(struct ieee802154_dev *dev, u8 *level)
|
||||
{
|
||||
might_sleep();
|
||||
BUG_ON(!level);
|
||||
*level = 0xbe;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
fakelb_hw_channel(struct ieee802154_dev *dev, int page, int channel)
|
||||
{
|
||||
pr_debug("set channel to %d\n", channel);
|
||||
|
||||
might_sleep();
|
||||
dev->phy->current_page = page;
|
||||
dev->phy->current_channel = channel;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
fakelb_hw_deliver(struct fakelb_dev_priv *priv, struct sk_buff *skb)
|
||||
{
|
||||
struct sk_buff *newskb;
|
||||
|
||||
spin_lock(&priv->lock);
|
||||
if (priv->working) {
|
||||
newskb = pskb_copy(skb, GFP_ATOMIC);
|
||||
ieee802154_rx_irqsafe(priv->dev, newskb, 0xcc);
|
||||
}
|
||||
spin_unlock(&priv->lock);
|
||||
}
|
||||
|
||||
static int
|
||||
fakelb_hw_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
|
||||
{
|
||||
struct fakelb_dev_priv *priv = dev->priv;
|
||||
struct fakelb_priv *fake = priv->fake;
|
||||
|
||||
might_sleep();
|
||||
|
||||
read_lock_bh(&fake->lock);
|
||||
if (priv->list.next == priv->list.prev) {
|
||||
/* we are the only one device */
|
||||
fakelb_hw_deliver(priv, skb);
|
||||
} else {
|
||||
struct fakelb_dev_priv *dp;
|
||||
list_for_each_entry(dp, &priv->fake->list, list) {
|
||||
if (dp != priv &&
|
||||
(dp->dev->phy->current_channel ==
|
||||
priv->dev->phy->current_channel))
|
||||
fakelb_hw_deliver(dp, skb);
|
||||
}
|
||||
}
|
||||
read_unlock_bh(&fake->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
fakelb_hw_start(struct ieee802154_dev *dev) {
|
||||
struct fakelb_dev_priv *priv = dev->priv;
|
||||
int ret = 0;
|
||||
|
||||
spin_lock(&priv->lock);
|
||||
if (priv->working)
|
||||
ret = -EBUSY;
|
||||
else
|
||||
priv->working = 1;
|
||||
spin_unlock(&priv->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
fakelb_hw_stop(struct ieee802154_dev *dev) {
|
||||
struct fakelb_dev_priv *priv = dev->priv;
|
||||
|
||||
spin_lock(&priv->lock);
|
||||
priv->working = 0;
|
||||
spin_unlock(&priv->lock);
|
||||
}
|
||||
|
||||
static struct ieee802154_ops fakelb_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.xmit = fakelb_hw_xmit,
|
||||
.ed = fakelb_hw_ed,
|
||||
.set_channel = fakelb_hw_channel,
|
||||
.start = fakelb_hw_start,
|
||||
.stop = fakelb_hw_stop,
|
||||
};
|
||||
|
||||
/* Number of dummy devices to be set up by this module. */
|
||||
module_param(numlbs, int, 0);
|
||||
MODULE_PARM_DESC(numlbs, " number of pseudo devices");
|
||||
|
||||
static int fakelb_add_one(struct device *dev, struct fakelb_priv *fake)
|
||||
{
|
||||
struct fakelb_dev_priv *priv;
|
||||
int err;
|
||||
struct ieee802154_dev *ieee;
|
||||
|
||||
ieee = ieee802154_alloc_device(sizeof(*priv), &fakelb_ops);
|
||||
if (!ieee)
|
||||
return -ENOMEM;
|
||||
|
||||
priv = ieee->priv;
|
||||
priv->dev = ieee;
|
||||
|
||||
/* 868 MHz BPSK 802.15.4-2003 */
|
||||
ieee->phy->channels_supported[0] |= 1;
|
||||
/* 915 MHz BPSK 802.15.4-2003 */
|
||||
ieee->phy->channels_supported[0] |= 0x7fe;
|
||||
/* 2.4 GHz O-QPSK 802.15.4-2003 */
|
||||
ieee->phy->channels_supported[0] |= 0x7FFF800;
|
||||
/* 868 MHz ASK 802.15.4-2006 */
|
||||
ieee->phy->channels_supported[1] |= 1;
|
||||
/* 915 MHz ASK 802.15.4-2006 */
|
||||
ieee->phy->channels_supported[1] |= 0x7fe;
|
||||
/* 868 MHz O-QPSK 802.15.4-2006 */
|
||||
ieee->phy->channels_supported[2] |= 1;
|
||||
/* 915 MHz O-QPSK 802.15.4-2006 */
|
||||
ieee->phy->channels_supported[2] |= 0x7fe;
|
||||
/* 2.4 GHz CSS 802.15.4a-2007 */
|
||||
ieee->phy->channels_supported[3] |= 0x3fff;
|
||||
/* UWB Sub-gigahertz 802.15.4a-2007 */
|
||||
ieee->phy->channels_supported[4] |= 1;
|
||||
/* UWB Low band 802.15.4a-2007 */
|
||||
ieee->phy->channels_supported[4] |= 0x1e;
|
||||
/* UWB High band 802.15.4a-2007 */
|
||||
ieee->phy->channels_supported[4] |= 0xffe0;
|
||||
/* 750 MHz O-QPSK 802.15.4c-2009 */
|
||||
ieee->phy->channels_supported[5] |= 0xf;
|
||||
/* 750 MHz MPSK 802.15.4c-2009 */
|
||||
ieee->phy->channels_supported[5] |= 0xf0;
|
||||
/* 950 MHz BPSK 802.15.4d-2009 */
|
||||
ieee->phy->channels_supported[6] |= 0x3ff;
|
||||
/* 950 MHz GFSK 802.15.4d-2009 */
|
||||
ieee->phy->channels_supported[6] |= 0x3ffc00;
|
||||
|
||||
INIT_LIST_HEAD(&priv->list);
|
||||
priv->fake = fake;
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
|
||||
ieee->parent = dev;
|
||||
|
||||
err = ieee802154_register_device(ieee);
|
||||
if (err)
|
||||
goto err_reg;
|
||||
|
||||
write_lock_bh(&fake->lock);
|
||||
list_add_tail(&priv->list, &fake->list);
|
||||
write_unlock_bh(&fake->lock);
|
||||
|
||||
return 0;
|
||||
|
||||
err_reg:
|
||||
ieee802154_free_device(priv->dev);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void fakelb_del(struct fakelb_dev_priv *priv)
|
||||
{
|
||||
write_lock_bh(&priv->fake->lock);
|
||||
list_del(&priv->list);
|
||||
write_unlock_bh(&priv->fake->lock);
|
||||
|
||||
ieee802154_unregister_device(priv->dev);
|
||||
ieee802154_free_device(priv->dev);
|
||||
}
|
||||
|
||||
static int fakelb_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct fakelb_priv *priv;
|
||||
struct fakelb_dev_priv *dp;
|
||||
int err = -ENOMEM;
|
||||
int i;
|
||||
|
||||
priv = devm_kzalloc(&pdev->dev, sizeof(struct fakelb_priv),
|
||||
GFP_KERNEL);
|
||||
if (!priv)
|
||||
goto err_alloc;
|
||||
|
||||
INIT_LIST_HEAD(&priv->list);
|
||||
rwlock_init(&priv->lock);
|
||||
|
||||
for (i = 0; i < numlbs; i++) {
|
||||
err = fakelb_add_one(&pdev->dev, priv);
|
||||
if (err < 0)
|
||||
goto err_slave;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, priv);
|
||||
dev_info(&pdev->dev, "added ieee802154 hardware\n");
|
||||
return 0;
|
||||
|
||||
err_slave:
|
||||
list_for_each_entry(dp, &priv->list, list)
|
||||
fakelb_del(dp);
|
||||
err_alloc:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int fakelb_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct fakelb_priv *priv = platform_get_drvdata(pdev);
|
||||
struct fakelb_dev_priv *dp, *temp;
|
||||
|
||||
list_for_each_entry_safe(dp, temp, &priv->list, list)
|
||||
fakelb_del(dp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_device *ieee802154fake_dev;
|
||||
|
||||
static struct platform_driver ieee802154fake_driver = {
|
||||
.probe = fakelb_probe,
|
||||
.remove = fakelb_remove,
|
||||
.driver = {
|
||||
.name = "ieee802154fakelb",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
static __init int fakelb_init_module(void)
|
||||
{
|
||||
ieee802154fake_dev = platform_device_register_simple(
|
||||
"ieee802154fakelb", -1, NULL, 0);
|
||||
return platform_driver_register(&ieee802154fake_driver);
|
||||
}
|
||||
|
||||
static __exit void fake_remove_module(void)
|
||||
{
|
||||
platform_driver_unregister(&ieee802154fake_driver);
|
||||
platform_device_unregister(ieee802154fake_dev);
|
||||
}
|
||||
|
||||
module_init(fakelb_init_module);
|
||||
module_exit(fake_remove_module);
|
||||
MODULE_LICENSE("GPL");
|
803
drivers/net/ieee802154/mrf24j40.c
Normal file
803
drivers/net/ieee802154/mrf24j40.c
Normal file
|
@ -0,0 +1,803 @@
|
|||
/*
|
||||
* Driver for Microchip MRF24J40 802.15.4 Wireless-PAN Networking controller
|
||||
*
|
||||
* Copyright (C) 2012 Alan Ott <alan@signal11.us>
|
||||
* Signal 11 Software
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/module.h>
|
||||
#include <net/wpan-phy.h>
|
||||
#include <net/mac802154.h>
|
||||
#include <net/ieee802154.h>
|
||||
|
||||
/* MRF24J40 Short Address Registers */
|
||||
#define REG_RXMCR 0x00 /* Receive MAC control */
|
||||
#define REG_PANIDL 0x01 /* PAN ID (low) */
|
||||
#define REG_PANIDH 0x02 /* PAN ID (high) */
|
||||
#define REG_SADRL 0x03 /* Short address (low) */
|
||||
#define REG_SADRH 0x04 /* Short address (high) */
|
||||
#define REG_EADR0 0x05 /* Long address (low) (high is EADR7) */
|
||||
#define REG_TXMCR 0x11 /* Transmit MAC control */
|
||||
#define REG_PACON0 0x16 /* Power Amplifier Control */
|
||||
#define REG_PACON1 0x17 /* Power Amplifier Control */
|
||||
#define REG_PACON2 0x18 /* Power Amplifier Control */
|
||||
#define REG_TXNCON 0x1B /* Transmit Normal FIFO Control */
|
||||
#define REG_TXSTAT 0x24 /* TX MAC Status Register */
|
||||
#define REG_SOFTRST 0x2A /* Soft Reset */
|
||||
#define REG_TXSTBL 0x2E /* TX Stabilization */
|
||||
#define REG_INTSTAT 0x31 /* Interrupt Status */
|
||||
#define REG_INTCON 0x32 /* Interrupt Control */
|
||||
#define REG_RFCTL 0x36 /* RF Control Mode Register */
|
||||
#define REG_BBREG1 0x39 /* Baseband Registers */
|
||||
#define REG_BBREG2 0x3A /* */
|
||||
#define REG_BBREG6 0x3E /* */
|
||||
#define REG_CCAEDTH 0x3F /* Energy Detection Threshold */
|
||||
|
||||
/* MRF24J40 Long Address Registers */
|
||||
#define REG_RFCON0 0x200 /* RF Control Registers */
|
||||
#define REG_RFCON1 0x201
|
||||
#define REG_RFCON2 0x202
|
||||
#define REG_RFCON3 0x203
|
||||
#define REG_RFCON5 0x205
|
||||
#define REG_RFCON6 0x206
|
||||
#define REG_RFCON7 0x207
|
||||
#define REG_RFCON8 0x208
|
||||
#define REG_RSSI 0x210
|
||||
#define REG_SLPCON0 0x211 /* Sleep Clock Control Registers */
|
||||
#define REG_SLPCON1 0x220
|
||||
#define REG_WAKETIMEL 0x222 /* Wake-up Time Match Value Low */
|
||||
#define REG_WAKETIMEH 0x223 /* Wake-up Time Match Value High */
|
||||
#define REG_RX_FIFO 0x300 /* Receive FIFO */
|
||||
|
||||
/* Device configuration: Only channels 11-26 on page 0 are supported. */
|
||||
#define MRF24J40_CHAN_MIN 11
|
||||
#define MRF24J40_CHAN_MAX 26
|
||||
#define CHANNEL_MASK (((u32)1 << (MRF24J40_CHAN_MAX + 1)) \
|
||||
- ((u32)1 << MRF24J40_CHAN_MIN))
|
||||
|
||||
#define TX_FIFO_SIZE 128 /* From datasheet */
|
||||
#define RX_FIFO_SIZE 144 /* From datasheet */
|
||||
#define SET_CHANNEL_DELAY_US 192 /* From datasheet */
|
||||
|
||||
/* Device Private Data */
|
||||
struct mrf24j40 {
|
||||
struct spi_device *spi;
|
||||
struct ieee802154_dev *dev;
|
||||
|
||||
struct mutex buffer_mutex; /* only used to protect buf */
|
||||
struct completion tx_complete;
|
||||
u8 *buf; /* 3 bytes. Used for SPI single-register transfers. */
|
||||
};
|
||||
|
||||
/* Read/Write SPI Commands for Short and Long Address registers. */
|
||||
#define MRF24J40_READSHORT(reg) ((reg) << 1)
|
||||
#define MRF24J40_WRITESHORT(reg) ((reg) << 1 | 1)
|
||||
#define MRF24J40_READLONG(reg) (1 << 15 | (reg) << 5)
|
||||
#define MRF24J40_WRITELONG(reg) (1 << 15 | (reg) << 5 | 1 << 4)
|
||||
|
||||
/* The datasheet indicates the theoretical maximum for SCK to be 10MHz */
|
||||
#define MAX_SPI_SPEED_HZ 10000000
|
||||
|
||||
#define printdev(X) (&X->spi->dev)
|
||||
|
||||
static int write_short_reg(struct mrf24j40 *devrec, u8 reg, u8 value)
|
||||
{
|
||||
int ret;
|
||||
struct spi_message msg;
|
||||
struct spi_transfer xfer = {
|
||||
.len = 2,
|
||||
.tx_buf = devrec->buf,
|
||||
.rx_buf = devrec->buf,
|
||||
};
|
||||
|
||||
spi_message_init(&msg);
|
||||
spi_message_add_tail(&xfer, &msg);
|
||||
|
||||
mutex_lock(&devrec->buffer_mutex);
|
||||
devrec->buf[0] = MRF24J40_WRITESHORT(reg);
|
||||
devrec->buf[1] = value;
|
||||
|
||||
ret = spi_sync(devrec->spi, &msg);
|
||||
if (ret)
|
||||
dev_err(printdev(devrec),
|
||||
"SPI write Failed for short register 0x%hhx\n", reg);
|
||||
|
||||
mutex_unlock(&devrec->buffer_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_short_reg(struct mrf24j40 *devrec, u8 reg, u8 *val)
|
||||
{
|
||||
int ret = -1;
|
||||
struct spi_message msg;
|
||||
struct spi_transfer xfer = {
|
||||
.len = 2,
|
||||
.tx_buf = devrec->buf,
|
||||
.rx_buf = devrec->buf,
|
||||
};
|
||||
|
||||
spi_message_init(&msg);
|
||||
spi_message_add_tail(&xfer, &msg);
|
||||
|
||||
mutex_lock(&devrec->buffer_mutex);
|
||||
devrec->buf[0] = MRF24J40_READSHORT(reg);
|
||||
devrec->buf[1] = 0;
|
||||
|
||||
ret = spi_sync(devrec->spi, &msg);
|
||||
if (ret)
|
||||
dev_err(printdev(devrec),
|
||||
"SPI read Failed for short register 0x%hhx\n", reg);
|
||||
else
|
||||
*val = devrec->buf[1];
|
||||
|
||||
mutex_unlock(&devrec->buffer_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_long_reg(struct mrf24j40 *devrec, u16 reg, u8 *value)
|
||||
{
|
||||
int ret;
|
||||
u16 cmd;
|
||||
struct spi_message msg;
|
||||
struct spi_transfer xfer = {
|
||||
.len = 3,
|
||||
.tx_buf = devrec->buf,
|
||||
.rx_buf = devrec->buf,
|
||||
};
|
||||
|
||||
spi_message_init(&msg);
|
||||
spi_message_add_tail(&xfer, &msg);
|
||||
|
||||
cmd = MRF24J40_READLONG(reg);
|
||||
mutex_lock(&devrec->buffer_mutex);
|
||||
devrec->buf[0] = cmd >> 8 & 0xff;
|
||||
devrec->buf[1] = cmd & 0xff;
|
||||
devrec->buf[2] = 0;
|
||||
|
||||
ret = spi_sync(devrec->spi, &msg);
|
||||
if (ret)
|
||||
dev_err(printdev(devrec),
|
||||
"SPI read Failed for long register 0x%hx\n", reg);
|
||||
else
|
||||
*value = devrec->buf[2];
|
||||
|
||||
mutex_unlock(&devrec->buffer_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_long_reg(struct mrf24j40 *devrec, u16 reg, u8 val)
|
||||
{
|
||||
int ret;
|
||||
u16 cmd;
|
||||
struct spi_message msg;
|
||||
struct spi_transfer xfer = {
|
||||
.len = 3,
|
||||
.tx_buf = devrec->buf,
|
||||
.rx_buf = devrec->buf,
|
||||
};
|
||||
|
||||
spi_message_init(&msg);
|
||||
spi_message_add_tail(&xfer, &msg);
|
||||
|
||||
cmd = MRF24J40_WRITELONG(reg);
|
||||
mutex_lock(&devrec->buffer_mutex);
|
||||
devrec->buf[0] = cmd >> 8 & 0xff;
|
||||
devrec->buf[1] = cmd & 0xff;
|
||||
devrec->buf[2] = val;
|
||||
|
||||
ret = spi_sync(devrec->spi, &msg);
|
||||
if (ret)
|
||||
dev_err(printdev(devrec),
|
||||
"SPI write Failed for long register 0x%hx\n", reg);
|
||||
|
||||
mutex_unlock(&devrec->buffer_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function relies on an undocumented write method. Once a write command
|
||||
and address is set, as many bytes of data as desired can be clocked into
|
||||
the device. The datasheet only shows setting one byte at a time. */
|
||||
static int write_tx_buf(struct mrf24j40 *devrec, u16 reg,
|
||||
const u8 *data, size_t length)
|
||||
{
|
||||
int ret;
|
||||
u16 cmd;
|
||||
u8 lengths[2];
|
||||
struct spi_message msg;
|
||||
struct spi_transfer addr_xfer = {
|
||||
.len = 2,
|
||||
.tx_buf = devrec->buf,
|
||||
};
|
||||
struct spi_transfer lengths_xfer = {
|
||||
.len = 2,
|
||||
.tx_buf = &lengths, /* TODO: Is DMA really required for SPI? */
|
||||
};
|
||||
struct spi_transfer data_xfer = {
|
||||
.len = length,
|
||||
.tx_buf = data,
|
||||
};
|
||||
|
||||
/* Range check the length. 2 bytes are used for the length fields.*/
|
||||
if (length > TX_FIFO_SIZE-2) {
|
||||
dev_err(printdev(devrec), "write_tx_buf() was passed too large a buffer. Performing short write.\n");
|
||||
length = TX_FIFO_SIZE-2;
|
||||
}
|
||||
|
||||
spi_message_init(&msg);
|
||||
spi_message_add_tail(&addr_xfer, &msg);
|
||||
spi_message_add_tail(&lengths_xfer, &msg);
|
||||
spi_message_add_tail(&data_xfer, &msg);
|
||||
|
||||
cmd = MRF24J40_WRITELONG(reg);
|
||||
mutex_lock(&devrec->buffer_mutex);
|
||||
devrec->buf[0] = cmd >> 8 & 0xff;
|
||||
devrec->buf[1] = cmd & 0xff;
|
||||
lengths[0] = 0x0; /* Header Length. Set to 0 for now. TODO */
|
||||
lengths[1] = length; /* Total length */
|
||||
|
||||
ret = spi_sync(devrec->spi, &msg);
|
||||
if (ret)
|
||||
dev_err(printdev(devrec), "SPI write Failed for TX buf\n");
|
||||
|
||||
mutex_unlock(&devrec->buffer_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mrf24j40_read_rx_buf(struct mrf24j40 *devrec,
|
||||
u8 *data, u8 *len, u8 *lqi)
|
||||
{
|
||||
u8 rx_len;
|
||||
u8 addr[2];
|
||||
u8 lqi_rssi[2];
|
||||
u16 cmd;
|
||||
int ret;
|
||||
struct spi_message msg;
|
||||
struct spi_transfer addr_xfer = {
|
||||
.len = 2,
|
||||
.tx_buf = &addr,
|
||||
};
|
||||
struct spi_transfer data_xfer = {
|
||||
.len = 0x0, /* set below */
|
||||
.rx_buf = data,
|
||||
};
|
||||
struct spi_transfer status_xfer = {
|
||||
.len = 2,
|
||||
.rx_buf = &lqi_rssi,
|
||||
};
|
||||
|
||||
/* Get the length of the data in the RX FIFO. The length in this
|
||||
* register exclues the 1-byte length field at the beginning. */
|
||||
ret = read_long_reg(devrec, REG_RX_FIFO, &rx_len);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
/* Range check the RX FIFO length, accounting for the one-byte
|
||||
* length field at the begining. */
|
||||
if (rx_len > RX_FIFO_SIZE-1) {
|
||||
dev_err(printdev(devrec), "Invalid length read from device. Performing short read.\n");
|
||||
rx_len = RX_FIFO_SIZE-1;
|
||||
}
|
||||
|
||||
if (rx_len > *len) {
|
||||
/* Passed in buffer wasn't big enough. Should never happen. */
|
||||
dev_err(printdev(devrec), "Buffer not big enough. Performing short read\n");
|
||||
rx_len = *len;
|
||||
}
|
||||
|
||||
/* Set up the commands to read the data. */
|
||||
cmd = MRF24J40_READLONG(REG_RX_FIFO+1);
|
||||
addr[0] = cmd >> 8 & 0xff;
|
||||
addr[1] = cmd & 0xff;
|
||||
data_xfer.len = rx_len;
|
||||
|
||||
spi_message_init(&msg);
|
||||
spi_message_add_tail(&addr_xfer, &msg);
|
||||
spi_message_add_tail(&data_xfer, &msg);
|
||||
spi_message_add_tail(&status_xfer, &msg);
|
||||
|
||||
ret = spi_sync(devrec->spi, &msg);
|
||||
if (ret) {
|
||||
dev_err(printdev(devrec), "SPI RX Buffer Read Failed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
*lqi = lqi_rssi[0];
|
||||
*len = rx_len;
|
||||
|
||||
#ifdef DEBUG
|
||||
print_hex_dump(KERN_DEBUG, "mrf24j40 rx: ",
|
||||
DUMP_PREFIX_OFFSET, 16, 1, data, *len, 0);
|
||||
pr_debug("mrf24j40 rx: lqi: %02hhx rssi: %02hhx\n",
|
||||
lqi_rssi[0], lqi_rssi[1]);
|
||||
#endif
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mrf24j40_tx(struct ieee802154_dev *dev, struct sk_buff *skb)
|
||||
{
|
||||
struct mrf24j40 *devrec = dev->priv;
|
||||
u8 val;
|
||||
int ret = 0;
|
||||
|
||||
dev_dbg(printdev(devrec), "tx packet of %d bytes\n", skb->len);
|
||||
|
||||
ret = write_tx_buf(devrec, 0x000, skb->data, skb->len);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
reinit_completion(&devrec->tx_complete);
|
||||
|
||||
/* Set TXNTRIG bit of TXNCON to send packet */
|
||||
ret = read_short_reg(devrec, REG_TXNCON, &val);
|
||||
if (ret)
|
||||
goto err;
|
||||
val |= 0x1;
|
||||
/* Set TXNACKREQ if the ACK bit is set in the packet. */
|
||||
if (skb->data[0] & IEEE802154_FC_ACK_REQ)
|
||||
val |= 0x4;
|
||||
write_short_reg(devrec, REG_TXNCON, val);
|
||||
|
||||
/* Wait for the device to send the TX complete interrupt. */
|
||||
ret = wait_for_completion_interruptible_timeout(
|
||||
&devrec->tx_complete,
|
||||
5 * HZ);
|
||||
if (ret == -ERESTARTSYS)
|
||||
goto err;
|
||||
if (ret == 0) {
|
||||
dev_warn(printdev(devrec), "Timeout waiting for TX interrupt\n");
|
||||
ret = -ETIMEDOUT;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check for send error from the device. */
|
||||
ret = read_short_reg(devrec, REG_TXSTAT, &val);
|
||||
if (ret)
|
||||
goto err;
|
||||
if (val & 0x1) {
|
||||
dev_dbg(printdev(devrec), "Error Sending. Retry count exceeded\n");
|
||||
ret = -ECOMM; /* TODO: Better error code ? */
|
||||
} else
|
||||
dev_dbg(printdev(devrec), "Packet Sent\n");
|
||||
|
||||
err:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mrf24j40_ed(struct ieee802154_dev *dev, u8 *level)
|
||||
{
|
||||
/* TODO: */
|
||||
pr_warn("mrf24j40: ed not implemented\n");
|
||||
*level = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mrf24j40_start(struct ieee802154_dev *dev)
|
||||
{
|
||||
struct mrf24j40 *devrec = dev->priv;
|
||||
u8 val;
|
||||
int ret;
|
||||
|
||||
dev_dbg(printdev(devrec), "start\n");
|
||||
|
||||
ret = read_short_reg(devrec, REG_INTCON, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
val &= ~(0x1|0x8); /* Clear TXNIE and RXIE. Enable interrupts */
|
||||
write_short_reg(devrec, REG_INTCON, val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mrf24j40_stop(struct ieee802154_dev *dev)
|
||||
{
|
||||
struct mrf24j40 *devrec = dev->priv;
|
||||
u8 val;
|
||||
int ret;
|
||||
|
||||
dev_dbg(printdev(devrec), "stop\n");
|
||||
|
||||
ret = read_short_reg(devrec, REG_INTCON, &val);
|
||||
if (ret)
|
||||
return;
|
||||
val |= 0x1|0x8; /* Set TXNIE and RXIE. Disable Interrupts */
|
||||
write_short_reg(devrec, REG_INTCON, val);
|
||||
}
|
||||
|
||||
static int mrf24j40_set_channel(struct ieee802154_dev *dev,
|
||||
int page, int channel)
|
||||
{
|
||||
struct mrf24j40 *devrec = dev->priv;
|
||||
u8 val;
|
||||
int ret;
|
||||
|
||||
dev_dbg(printdev(devrec), "Set Channel %d\n", channel);
|
||||
|
||||
WARN_ON(page != 0);
|
||||
WARN_ON(channel < MRF24J40_CHAN_MIN);
|
||||
WARN_ON(channel > MRF24J40_CHAN_MAX);
|
||||
|
||||
/* Set Channel TODO */
|
||||
val = (channel-11) << 4 | 0x03;
|
||||
write_long_reg(devrec, REG_RFCON0, val);
|
||||
|
||||
/* RF Reset */
|
||||
ret = read_short_reg(devrec, REG_RFCTL, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
val |= 0x04;
|
||||
write_short_reg(devrec, REG_RFCTL, val);
|
||||
val &= ~0x04;
|
||||
write_short_reg(devrec, REG_RFCTL, val);
|
||||
|
||||
udelay(SET_CHANNEL_DELAY_US); /* per datasheet */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mrf24j40_filter(struct ieee802154_dev *dev,
|
||||
struct ieee802154_hw_addr_filt *filt,
|
||||
unsigned long changed)
|
||||
{
|
||||
struct mrf24j40 *devrec = dev->priv;
|
||||
|
||||
dev_dbg(printdev(devrec), "filter\n");
|
||||
|
||||
if (changed & IEEE802515_AFILT_SADDR_CHANGED) {
|
||||
/* Short Addr */
|
||||
u8 addrh, addrl;
|
||||
|
||||
addrh = le16_to_cpu(filt->short_addr) >> 8 & 0xff;
|
||||
addrl = le16_to_cpu(filt->short_addr) & 0xff;
|
||||
|
||||
write_short_reg(devrec, REG_SADRH, addrh);
|
||||
write_short_reg(devrec, REG_SADRL, addrl);
|
||||
dev_dbg(printdev(devrec),
|
||||
"Set short addr to %04hx\n", filt->short_addr);
|
||||
}
|
||||
|
||||
if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) {
|
||||
/* Device Address */
|
||||
u8 i, addr[8];
|
||||
|
||||
memcpy(addr, &filt->ieee_addr, 8);
|
||||
for (i = 0; i < 8; i++)
|
||||
write_short_reg(devrec, REG_EADR0 + i, addr[i]);
|
||||
|
||||
#ifdef DEBUG
|
||||
pr_debug("Set long addr to: ");
|
||||
for (i = 0; i < 8; i++)
|
||||
pr_debug("%02hhx ", addr[7 - i]);
|
||||
pr_debug("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (changed & IEEE802515_AFILT_PANID_CHANGED) {
|
||||
/* PAN ID */
|
||||
u8 panidl, panidh;
|
||||
|
||||
panidh = le16_to_cpu(filt->pan_id) >> 8 & 0xff;
|
||||
panidl = le16_to_cpu(filt->pan_id) & 0xff;
|
||||
write_short_reg(devrec, REG_PANIDH, panidh);
|
||||
write_short_reg(devrec, REG_PANIDL, panidl);
|
||||
|
||||
dev_dbg(printdev(devrec), "Set PANID to %04hx\n", filt->pan_id);
|
||||
}
|
||||
|
||||
if (changed & IEEE802515_AFILT_PANC_CHANGED) {
|
||||
/* Pan Coordinator */
|
||||
u8 val;
|
||||
int ret;
|
||||
|
||||
ret = read_short_reg(devrec, REG_RXMCR, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (filt->pan_coord)
|
||||
val |= 0x8;
|
||||
else
|
||||
val &= ~0x8;
|
||||
write_short_reg(devrec, REG_RXMCR, val);
|
||||
|
||||
/* REG_SLOTTED is maintained as default (unslotted/CSMA-CA).
|
||||
* REG_ORDER is maintained as default (no beacon/superframe).
|
||||
*/
|
||||
|
||||
dev_dbg(printdev(devrec), "Set Pan Coord to %s\n",
|
||||
filt->pan_coord ? "on" : "off");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
|
||||
{
|
||||
u8 len = RX_FIFO_SIZE;
|
||||
u8 lqi = 0;
|
||||
u8 val;
|
||||
int ret = 0;
|
||||
struct sk_buff *skb;
|
||||
|
||||
/* Turn off reception of packets off the air. This prevents the
|
||||
* device from overwriting the buffer while we're reading it. */
|
||||
ret = read_short_reg(devrec, REG_BBREG1, &val);
|
||||
if (ret)
|
||||
goto out;
|
||||
val |= 4; /* SET RXDECINV */
|
||||
write_short_reg(devrec, REG_BBREG1, val);
|
||||
|
||||
skb = alloc_skb(len, GFP_KERNEL);
|
||||
if (!skb) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = mrf24j40_read_rx_buf(devrec, skb_put(skb, len), &len, &lqi);
|
||||
if (ret < 0) {
|
||||
dev_err(printdev(devrec), "Failure reading RX FIFO\n");
|
||||
kfree_skb(skb);
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Cut off the checksum */
|
||||
skb_trim(skb, len-2);
|
||||
|
||||
/* TODO: Other drivers call ieee20154_rx_irqsafe() here (eg: cc2040,
|
||||
* also from a workqueue). I think irqsafe is not necessary here.
|
||||
* Can someone confirm? */
|
||||
ieee802154_rx_irqsafe(devrec->dev, skb, lqi);
|
||||
|
||||
dev_dbg(printdev(devrec), "RX Handled\n");
|
||||
|
||||
out:
|
||||
/* Turn back on reception of packets off the air. */
|
||||
ret = read_short_reg(devrec, REG_BBREG1, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
val &= ~0x4; /* Clear RXDECINV */
|
||||
write_short_reg(devrec, REG_BBREG1, val);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct ieee802154_ops mrf24j40_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.xmit = mrf24j40_tx,
|
||||
.ed = mrf24j40_ed,
|
||||
.start = mrf24j40_start,
|
||||
.stop = mrf24j40_stop,
|
||||
.set_channel = mrf24j40_set_channel,
|
||||
.set_hw_addr_filt = mrf24j40_filter,
|
||||
};
|
||||
|
||||
static irqreturn_t mrf24j40_isr(int irq, void *data)
|
||||
{
|
||||
struct mrf24j40 *devrec = data;
|
||||
u8 intstat;
|
||||
int ret;
|
||||
|
||||
/* Read the interrupt status */
|
||||
ret = read_short_reg(devrec, REG_INTSTAT, &intstat);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
/* Check for TX complete */
|
||||
if (intstat & 0x1)
|
||||
complete(&devrec->tx_complete);
|
||||
|
||||
/* Check for Rx */
|
||||
if (intstat & 0x8)
|
||||
mrf24j40_handle_rx(devrec);
|
||||
|
||||
out:
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int mrf24j40_hw_init(struct mrf24j40 *devrec)
|
||||
{
|
||||
int ret;
|
||||
u8 val;
|
||||
|
||||
/* Initialize the device.
|
||||
From datasheet section 3.2: Initialization. */
|
||||
ret = write_short_reg(devrec, REG_SOFTRST, 0x07);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_PACON2, 0x98);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_TXSTBL, 0x95);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_RFCON0, 0x03);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_RFCON1, 0x01);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_RFCON2, 0x80);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_RFCON6, 0x90);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_RFCON7, 0x80);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_RFCON8, 0x10);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_long_reg(devrec, REG_SLPCON1, 0x21);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_BBREG2, 0x80);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_CCAEDTH, 0x60);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_BBREG6, 0x40);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_RFCTL, 0x04);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
ret = write_short_reg(devrec, REG_RFCTL, 0x0);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
udelay(192);
|
||||
|
||||
/* Set RX Mode. RXMCR<1:0>: 0x0 normal, 0x1 promisc, 0x2 error */
|
||||
ret = read_short_reg(devrec, REG_RXMCR, &val);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
val &= ~0x3; /* Clear RX mode (normal) */
|
||||
|
||||
ret = write_short_reg(devrec, REG_RXMCR, val);
|
||||
if (ret)
|
||||
goto err_ret;
|
||||
|
||||
return 0;
|
||||
|
||||
err_ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mrf24j40_probe(struct spi_device *spi)
|
||||
{
|
||||
int ret = -ENOMEM;
|
||||
struct mrf24j40 *devrec;
|
||||
|
||||
dev_info(&spi->dev, "probe(). IRQ: %d\n", spi->irq);
|
||||
|
||||
devrec = devm_kzalloc(&spi->dev, sizeof(struct mrf24j40), GFP_KERNEL);
|
||||
if (!devrec)
|
||||
goto err_ret;
|
||||
devrec->buf = devm_kzalloc(&spi->dev, 3, GFP_KERNEL);
|
||||
if (!devrec->buf)
|
||||
goto err_ret;
|
||||
|
||||
spi->mode = SPI_MODE_0; /* TODO: Is this appropriate for right here? */
|
||||
if (spi->max_speed_hz > MAX_SPI_SPEED_HZ)
|
||||
spi->max_speed_hz = MAX_SPI_SPEED_HZ;
|
||||
|
||||
mutex_init(&devrec->buffer_mutex);
|
||||
init_completion(&devrec->tx_complete);
|
||||
devrec->spi = spi;
|
||||
spi_set_drvdata(spi, devrec);
|
||||
|
||||
/* Register with the 802154 subsystem */
|
||||
|
||||
devrec->dev = ieee802154_alloc_device(0, &mrf24j40_ops);
|
||||
if (!devrec->dev)
|
||||
goto err_ret;
|
||||
|
||||
devrec->dev->priv = devrec;
|
||||
devrec->dev->parent = &devrec->spi->dev;
|
||||
devrec->dev->phy->channels_supported[0] = CHANNEL_MASK;
|
||||
devrec->dev->flags = IEEE802154_HW_OMIT_CKSUM|IEEE802154_HW_AACK;
|
||||
|
||||
dev_dbg(printdev(devrec), "registered mrf24j40\n");
|
||||
ret = ieee802154_register_device(devrec->dev);
|
||||
if (ret)
|
||||
goto err_register_device;
|
||||
|
||||
ret = mrf24j40_hw_init(devrec);
|
||||
if (ret)
|
||||
goto err_hw_init;
|
||||
|
||||
ret = devm_request_threaded_irq(&spi->dev,
|
||||
spi->irq,
|
||||
NULL,
|
||||
mrf24j40_isr,
|
||||
IRQF_TRIGGER_LOW|IRQF_ONESHOT,
|
||||
dev_name(&spi->dev),
|
||||
devrec);
|
||||
|
||||
if (ret) {
|
||||
dev_err(printdev(devrec), "Unable to get IRQ");
|
||||
goto err_irq;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_irq:
|
||||
err_hw_init:
|
||||
ieee802154_unregister_device(devrec->dev);
|
||||
err_register_device:
|
||||
ieee802154_free_device(devrec->dev);
|
||||
err_ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mrf24j40_remove(struct spi_device *spi)
|
||||
{
|
||||
struct mrf24j40 *devrec = spi_get_drvdata(spi);
|
||||
|
||||
dev_dbg(printdev(devrec), "remove\n");
|
||||
|
||||
ieee802154_unregister_device(devrec->dev);
|
||||
ieee802154_free_device(devrec->dev);
|
||||
/* TODO: Will ieee802154_free_device() wait until ->xmit() is
|
||||
* complete? */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spi_device_id mrf24j40_ids[] = {
|
||||
{ "mrf24j40", 0 },
|
||||
{ "mrf24j40ma", 0 },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(spi, mrf24j40_ids);
|
||||
|
||||
static struct spi_driver mrf24j40_driver = {
|
||||
.driver = {
|
||||
.name = "mrf24j40",
|
||||
.bus = &spi_bus_type,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.id_table = mrf24j40_ids,
|
||||
.probe = mrf24j40_probe,
|
||||
.remove = mrf24j40_remove,
|
||||
};
|
||||
|
||||
module_spi_driver(mrf24j40_driver);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Alan Ott");
|
||||
MODULE_DESCRIPTION("MRF24J40 SPI 802.15.4 Controller Driver");
|
Loading…
Add table
Add a link
Reference in a new issue