Files
beagleconnect-freedom/sw/linux/0003-mikrobus-add-re-enter-id-mode-and-fix-multiple-port.patch
Vaishnav M A 853d3461e1 sw: linux: add mikrobus driver update patches
mikrobus driver works within buildroot but the click
device drivers are not being probed correctly:
in host /opt/gbridge.sh a hack for continously blinking the
led on the SensorTag/Launchpad is added(this background
transaction happening continously prevents some of the greybus
pm suspend events happening, which might have been the cause
for the kernel panic, with this continous background transfer
the kernel panic is not seen and qemu machine does not crash)

changes were tested using ATUSB, CC1352R SensorTag

Welcome to Buildroot
buildroot login: root
Password:
IFLP=`ifconfig | grep lowpan`
ip link set wpan0 down
iwpan phy phy0 set channel 0 26
iwpan dev wpan0 set pan_id 0xabcd
  ip link add link wpan0 name lowpan0 type lowpan
  ip link set lowpan0 up
ip link set wpan0 up
ip -6 addr add 2001:db8::2/64 dev lowpan0
sleep 1

killall -9 gbridge
sleep 1

sleep 5

gbridge > /dev/null 2&1 &
sleep 5
for i in `seq 1 100000`; do gpioset 0 6=1; gpioset 0 6=0; \
                         sleep 1; done

greybus 1-2.2: GMP VID=0x00000126, PID=0x00000126
greybus 1-2.2: DDBL1 Manufacturer=0x00000126, Product=0x00000126
greybus 1-2.2: excess descriptors in interface manifest
mikrobus:mikrobus_port_gb_register: mikrobus gb_probe , num cports= 3, manifest_size 252
mikrobus:mikrobus_port_gb_register: protocol added 11
mikrobus:mikrobus_port_gb_register: protocol added 3
mikrobus:mikrobus_port_gb_register: protocol added 2
mikrobus:mikrobus_port_register: registering port mikrobus-0
mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 1, driver=bme280, protocol=3, reg=76
mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 2, driver=opt3001, protocol=3, reg=44
mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 3, driver=ams-iaq-core, protocol=3, reg=5a
mikrobus_manifest:mikrobus_manifest_parse:  Greybus Service Sample Application manifest parsed with 3 devices
mikrobus mikrobus-0: registering device : bme280
mikrobus mikrobus-0: registering device : opt3001
mikrobus mikrobus-0: registering device : ams-iaq-core

0-0044  0-005a  0-0076  i2c-0

Mem: 29624K used, 471572K free, 84K shrd, 624K buff, 5152K cached
CPU:   7% usr   4% sys   0% nic  86% idle   0% io   0% irq   1% sirq
Load average: 0.22 0.10 0.03 1/56 378
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
  193   178 root     S    16060   3%   1% gbridge 2
  178   174 root     S     3744   1%   1% {gbridge.sh} /bin/sh -xv /opt/gbridge.
  312   174 root     R     1532   0%   1% top
   47     2 root     IW       0   0%   1% [kworker/0:3-eve]
   10     2 root     IW       0   0%   0% [rcu_sched]
    9     2 root     SW       0   0%   0% [ksoftirqd/0]
  173     1 root     S     3744   1%   0% /usr/sbin/iiod -D
  165     1 avahi    S     1924   0%   0% avahi-daemon: running [buildroot.local
  174     1 root     S     1548   0%   0% -sh
    1     0 root     S     1532   0%   0% init
  175     1 root     S     1528   0%   0% /sbin/getty -L tty1 0 vt100
  150     1 root     S     1528   0%   0% udhcpc -R -n -O search -p /var/run/udh
   64     1 root     S     1524   0%   0% /sbin/syslogd -n
   68     1 root     S     1520   0%   0% /sbin/klogd -n
  378   178 root     S     1520   0%   0% sleep 1
  115     1 dbus     S     1492   0%   0% dbus-daemon --system
  169     1 root     S     1080   0%   0% /usr/sbin/dropbear -R
   29     2 root     IW       0   0%   0% [kworker/u2:1-fl]
    7     2 root     IW       0   0%   0% [kworker/u2:0-gr]
   13     2 root     SW       0   0%   0% [kdevtmpfs]

Signed-off-by: Vaishnav M A <vaishnav@beagleboard.org>
2021-01-13 13:33:35 +05:30

150 lines
5.1 KiB
Diff

From 4c615e665cfd762e6ff2c75dfc00569c53aebca9 Mon Sep 17 00:00:00 2001
From: Vaishnav M A <vaishnav@beagleboard.org>
Date: Thu, 24 Dec 2020 19:50:34 +0530
Subject: [PATCH] mikrobus: add re-enter id mode and fix multiple port
Signed-off-by: Vaishnav M A <vaishnav@beagleboard.org>
---
drivers/misc/mikrobus/mikrobus_core.c | 63 ++++++++++++++++++++++-----
drivers/misc/mikrobus/mikrobus_core.h | 1 +
2 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/drivers/misc/mikrobus/mikrobus_core.c b/drivers/misc/mikrobus/mikrobus_core.c
index f736df3a89fc..4c6ca2036fe6 100644
--- a/drivers/misc/mikrobus/mikrobus_core.c
+++ b/drivers/misc/mikrobus/mikrobus_core.c
@@ -63,6 +63,10 @@ int mikrobus_port_scan_eeprom(struct mikrobus_port *port)
char header[12];
int retval;
char *buf;
+
+ if(port->skip_scan)
+ return -EINVAL;
+
retval = nvmem_device_read(port->eeprom, 0, 12, header);
if (retval != 12) {
dev_err(&port->dev, "failed to fetch manifest header %d\n",
@@ -197,6 +201,7 @@ static ssize_t rescan_store(struct device *dev, struct device_attribute *attr,
}
msleep(100); /* temporary delay to fix ROM ID copy */
+ port->skip_scan = 0;
retval = mikrobus_port_scan_eeprom(port);
if (retval) {
dev_err(dev, "board register from manifest failed\n");
@@ -206,6 +211,47 @@ static ssize_t rescan_store(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_WO(rescan);
+static ssize_t idmode_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct mikrobus_port *port = to_mikrobus_port(dev);
+ unsigned long id;
+ int retval;
+ int i;
+
+ if (kstrtoul(buf, 0, &id)) {
+ dev_err(dev, "cannot parse trigger\n");
+ return -EINVAL;
+ }
+ if (port->board) {
+ dev_err(dev, "already has board registered\n");
+ return -EBUSY;
+ }
+
+ if (!port->eeprom){
+ return mikrobus_port_id_eeprom_probe(port);
+ }
+ /* Enter ID Mode */
+ sprintf(port->pinctrl_selected[MIKROBUS_PINCTRL_SPI], "%s_%s",
+ MIKROBUS_PINCTRL_STR[MIKROBUS_PINCTRL_SPI], MIKROBUS_PINCTRL_STATE_GPIO);
+
+ retval = mikrobus_port_pinctrl_select(port);
+ /* set MOSI LOW, SCK HIGH */
+ gpiod_direction_output(port->gpios->desc[MIKROBUS_PIN_MOSI], 0);
+ gpiod_direction_output(port->gpios->desc[MIKROBUS_PIN_SCK], 1);
+ msleep(100);
+ for( i = 0; i < 4; i++){
+ gpiod_set_value(port->gpios->desc[MIKROBUS_PIN_MOSI] , 1);
+ udelay(1000);
+ gpiod_set_value(port->gpios->desc[MIKROBUS_PIN_MOSI] , 0);
+ udelay(1000);
+ }
+ msleep(100); /* temporary delay to fix ROM ID copy */
+ port->skip_scan = 1;
+ return count;
+}
+static DEVICE_ATTR_WO(idmode);
+
static ssize_t delete_device_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
@@ -226,7 +272,7 @@ static ssize_t delete_device_store(struct device *dev, struct device_attribute *
static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, delete_device_store);
static struct attribute *mikrobus_port_attrs[] = {
- &dev_attr_new_device.attr, &dev_attr_rescan.attr,
+ &dev_attr_new_device.attr, &dev_attr_rescan.attr, &dev_attr_idmode.attr,
&dev_attr_delete_device.attr, &dev_attr_name.attr, NULL};
ATTRIBUTE_GROUPS(mikrobus_port);
@@ -627,7 +673,6 @@ static struct w1_gpio_platform_data mikrobus_id_eeprom_w1_pdata = {
static struct platform_device mikrobus_id_eeprom_w1_device = {
.name = "w1-gpio",
- .id = -1,
.dev.platform_data = &mikrobus_id_eeprom_w1_pdata,
};
@@ -635,6 +680,7 @@ static int mikrobus_port_id_eeprom_probe(struct mikrobus_port *port)
{
struct w1_bus_master *bm;
struct gpiod_lookup_table *lookup;
+ char devname[MIKROBUS_NAME_SIZE];
int retval;
int i;
@@ -658,7 +704,11 @@ static int mikrobus_port_id_eeprom_probe(struct mikrobus_port *port)
GFP_KERNEL);
if (!lookup)
return -ENOMEM;
- lookup->dev_id = mikrobus_id_eeprom_w1_device.name;
+ snprintf(devname, sizeof(devname), "%s.%u",
+ mikrobus_id_eeprom_w1_device.name,
+ port->id);
+ mikrobus_id_eeprom_w1_device.id = port->id;
+ lookup->dev_id = kmemdup(devname, MIKROBUS_NAME_SIZE, GFP_KERNEL);
lookup->table[0].key = mikrobus_gpio_chip_name_get(port,
MIKROBUS_PIN_CS);
lookup->table[0].flags = GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN;
@@ -734,13 +784,6 @@ int mikrobus_port_register(struct mikrobus_port *port)
port->id);
retval = mikrobus_port_id_eeprom_probe(port);
}
- // if (port->w1_master) {
- // retval = mikrobus_port_scan_eeprom(port);
- // if (retval) {
- // dev_warn(&port->dev, "failed to register board from manifest\n");
- // return 0;
- // }
- // }
return retval;
}
EXPORT_SYMBOL_GPL(mikrobus_port_register);
diff --git a/drivers/misc/mikrobus/mikrobus_core.h b/drivers/misc/mikrobus/mikrobus_core.h
index f7c53d760a12..ef7ddce660cb 100644
--- a/drivers/misc/mikrobus/mikrobus_core.h
+++ b/drivers/misc/mikrobus/mikrobus_core.h
@@ -185,6 +185,7 @@ struct mikrobus_port {
char name[MIKROBUS_NAME_SIZE];
char *pinctrl_selected[MIKROBUS_NUM_PINCTRL_STATE];
unsigned int chip_select[MIKROBUS_NUM_CS];
+ int skip_scan;
int id;
};
#define to_mikrobus_port(d) container_of(d, struct mikrobus_port, dev)
--
2.25.1