Friday, February 13, 2015

Linux on the Zotac ZBOX Pi320

If you've found this post, you know what the Zotac ZBOX pico 320 (and 321) is, so I won't go into that. If you found this post, you also know how annoying it is to make this device work with linux.

Its 4:30am, so I'll keep this short. There's 3 main problems:
  1. 32bit EFI, which means you'll have to download an amd64 distribution, but patch the install-USB stick to also provide a 32bit grub. There's sufficient documentation on that.
  2. WiFi won't work.
  3. The power button doesn't work.
  4. Possibly sound doesn't work - but I don't care

For problems 2 and 3, I pestered people on the respective mailing lists. At the end, Arend van Spriel and Mika Westerberg were extremely helpful and had the right ideas:

http://marc.info/?t=142321396800002&r=1&w=2
http://www.spinics.net/lists/linux-acpi/msg55693.html

Some discussion took part off the lists (especially ACPI related), so I'd like to document the solution here. WiFi doesn't work because it is switched off by default

# cat /sys/bus/acpi/devices/INT33BB\:00/power_state
D3cold

You can enable it by issuing

# echo on > /sys/bus/platform/devices/INT33BB:00/power/control 

If you don't have the file already, copy brcmfmac4330-sdio.bin from linux-firmware to

/lib/firmware/brcm/brcmfmac4330-sdio.bin

The following file was copied from the windows driver and should be copied to

/lib/firmware/brcm/brcmfmac4330-sdio.txt:

#Sample variables file for BCM94330 SD FC AGB board T77H360.04_EVT5_20120731                     
manfid=0x2d0                                                                                      
prodid=0x0547                                                                                     
vendid=0x14e4                                                                                     
devid=0x4360                                                                                      
boardtype=0x05e1                                                                                  
boardrev=0x1202                                                                                     
boardflags=0x10080a00                                                                                 
nocrc=1                                                                                               
xtalfreq=26000                                                                                        
boardnum=22                                                                                             
macaddr=00:90:4c:c5:12:38                                                                               
ag0=0x40                                                                                                 
ag1=0xBF                                                                                                   
aa2g=1                                                                                                       
aa5g=1                                                                                                       
ccode=all                                                                                                     
pa0itssit=0x20
pa0b0=4924
pa0b1=-595
pa0b2=-157
rssismf2g=0xa
rssismc2g=0x3
rssisav2g=0x7
#rssi params for 5GHz
rssismf5g=0x4
rssismc5g=0x3
rssisav5g=0x7
#PA parameters for lower a-band
pa1lob0=5050
pa1lob1=-630
pa1lob2=-195
#PA parameters for midband
pa1b0=4880
pa1b1=-625
pa1b2=-200
#PA parameters for high band
pa1hib0=4880
pa1hib1=-620
pa1hib2=-190
rxpo5g=0
maxp2ga0=0x44
maxp5ga0=0x3A
maxp5gla0=0x3A
maxp5gha0=0x3A
# 2.4G Tx Power offsets
ofdm2gpo=0x22222222
mcs2gpo0=0x4444
mcs2gpo1=0x4444
# 5G Tx Power offsets
ofdm5gpo=0x00000000
ofdm5glpo=0x00000000
ofdm5ghpo=0x00000000
mcs5gpo0=0x2222
mcs5gpo1=0x2222
mcs5glpo0=0x2222
mcs5glpo1=0x2222
mcs5ghpo0=0x2222
mcs5ghpo1=0x2222
sromrev=3
il0macaddr=00:90:4c:c5:12:38
wl0id=0x431b
cckPwrOffset=6
triso2g=3
#swctrlmap_2g=0x44844484,0x42824282,0x42824282,0x18282,0x1ff
swctrlmap_2g=0x04040404,0x02020202,0x02020202,0x18282,0x1ff
triso5g=6
swctrlmap_5g=0x10101010,0x28282020,0x20202020,0x10202,0x0f8
noise_cal_ref_2g=53
rfreg033=0x19
rfreg033_cck=0x1f
dacrate2g=160
dacrate5g=160
txalpfbyp2g=1
bphyscale=17
cckPwrIdxCorr=-15
pacalpwr5glo=13
pacalpwr5glo1=11
pacalpwr5g=13
pacalpwr5g1=11
pacalpwr5ghi=13
pacalpwr5ghi1=11
#pacalpwr2g1=13
#pacalath2g=180
#pacalidx2g1=55
pacalpwr2g=13
txgaintbl=1
rfreg088=15
cckdigfilttype=20
noise_cal_adj_2g=-3
#wake on wireless LAN
sd_gpout=0
sd_gpval=1
sd_gpdc=0


Now "modprobe brcmfmac" and life should be good. I tested wpa_supplicant and hostapd, both work.

After a little email-pingpong, Mika Westerberg whipped up a patch that fixes the power button:

From 3404c6f2422c9e8d3f51a8832fbce01483c423d9 Mon Sep 17 00:00:00 2001
From: Mika Westerberg 
Date: Wed, 11 Feb 2015 17:21:18 +0200
Subject: [PATCH] pinctrl: baytrail: Relax GPIO request rules for certain pin

On Baytrail-T based machines the power button is part of GPIO keys like
button array (and implemented as a GPIO). However, Zotac ZBOX BIOS fails to
configure the pin properly which prevents the driver to request it.
Following is printed on the console:

  byt_gpio INT33FC:02: pin 16 cannot be used as GPIO.

Fix this by relaxing GPIO request rules for this particular pin.

Reported-by: Benjamin Adler 
Signed-off-by: Mika Westerberg 
---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 40 +++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-baytrail.c b/drivers/pinctrl/intel/pinctrl-baytrail.c
index 5afe03e28b91..44a7fef8a0f8 100644
--- a/drivers/pinctrl/intel/pinctrl-baytrail.c
+++ b/drivers/pinctrl/intel/pinctrl-baytrail.c
@@ -158,17 +158,29 @@ static void __iomem *byt_gpio_reg(struct gpio_chip *chip, unsigned offset,
  return vg->reg_base + reg_offset + reg;
 }
 
-static bool is_special_pin(struct byt_gpio *vg, unsigned offset)
+static unsigned get_gpio_mux(struct byt_gpio *vg, unsigned offset)
 {
  /* SCORE pin 92-93 */
  if (!strcmp(vg->range->name, BYT_SCORE_ACPI_UID) &&
   offset >= 92 && offset <= 93)
-  return true;
+  return 1;
 
  /* SUS pin 11-21 */
  if (!strcmp(vg->range->name, BYT_SUS_ACPI_UID) &&
   offset >= 11 && offset <= 21)
-  return true;
+  return 1;
+
+ return 0;
+}
+
+static bool can_mux_as_gpio(struct byt_gpio *vg, unsigned offset)
+{
+ if (!strcmp(vg->range->name, BYT_SUS_ACPI_UID)) {
+  switch (offset) {
+  case 16: /* Power button on BYT-T machines */
+   return true;
+  }
+ }
 
  return false;
 }
@@ -177,8 +189,10 @@ static int byt_gpio_request(struct gpio_chip *chip, unsigned offset)
 {
  struct byt_gpio *vg = to_byt_gpio(chip);
  void __iomem *reg = byt_gpio_reg(chip, offset, BYT_CONF0_REG);
+ unsigned long flags;
  u32 value;
- bool special;
+
+ spin_lock_irqsave(&vg->lock, flags);
 
  /*
   * In most cases, func pin mux 000 means GPIO function.
@@ -187,13 +201,21 @@ static int byt_gpio_request(struct gpio_chip *chip, unsigned offset)
   * func pin mux preset as GPIO function by BIOS/FW.
   */
  value = readl(reg) & BYT_PIN_MUX;
- special = is_special_pin(vg, offset);
- if ((special && value != 1) || (!special && value)) {
-  dev_err(&vg->pdev->dev,
-   "pin %u cannot be used as GPIO.\n", offset);
-  return -EINVAL;
+ if (value != get_gpio_mux(vg, offset)) {
+  /* Some misconfigured pins can still be muxed as GPIOs */
+  if (can_mux_as_gpio(vg, offset)) {
+   value = readl(reg);
+   value |= 1;
+   writel(value, reg);
+  } else {
+   dev_err(&vg->pdev->dev,
+    "pin %u cannot be used as GPIO.\n", offset);
+   spin_unlock_irqrestore(&vg->lock, flags);
+   return -EINVAL;
+  }
  }
 
+ spin_unlock_irqrestore(&vg->lock, flags);
  pm_runtime_get(&vg->pdev->dev);
 
  return 0;

This fix will become part of mainline, maybe 3.20, and once applied, acpid will catch the power button without any further configuration.

Godspeed!

3 comments:

  1. Thanks for sharing the solutions you found, Ben!

    ReplyDelete
  2. Many thanks for a post. Very much I helped to include WiFi.
    Best regards,
    Sergey from Moscow

    ReplyDelete
  3. Thanks for leaving this on the web. Got the WiFi up and working at around 4:30am :-D
    Much obliged.

    ReplyDelete