# Configuring a usable FreeBSD ThinkPad



## ceteris (Nov 20, 2020)

Hello!

I'm going to try to keep this short and sweet by getting to the point as quickly as possible.

- I've decided to install FreeBSD 12.2 on my main laptop.
I have substantial experience with different Linux distributions, pfSense, OPNsense and FreeNAS as well as Windows Server (2016), so I'm not new to the OS game. I've also played around with straight FreeBSD quite a lot so I'm familiar with the basics and then some. I decided to install FreeBSD on my laptop to take advantage of 'ZFS on root', Boot Environments, security, jails and other advantages over Linux.

- I've gotten far, having successfully installed my favorite desktop, Xfce4, but I'm having some issues ironing out the remaining kinks. I'm not
expecting my experience be as perfect as with say Ubuntu but I need to make my laptop cooperate enough to enable normal workflow.

The laptop in question is a (2016) Lenovo ThinkPad E560 with:
Intel(R) Core(TM) i5-6200U 2C4T CPU @ 2.30GHz
with integrated Intel HD 520 graphics
2x 8GB DDR3 Kingston HyperX 1600 MT/s SODIMM
15.6" FullHD IPS LED LCD display
Lenovo BIOS from 2017
Sunrise Point-LP USB 3.0 xHCI Controller (PCIe)
Sunrise Point-LP [Intel] HD Audio (PCIe)
Intel(R) Dual Band Wireless AC 3165
Intel Ethernet Connection I219-V
Samsung SSD 840 EVO 250GB
Realtek RTS522A PCI Express Card Reader

Again, I don't expect this laptop to have amazing support for every multimedia key and obscure little feature, quite the opposite - I'm content to have it work just well enough to suit my needs -, but I do need to have SOME things:

I need a usable track/touchpad, some function keys (to regulate screen brightness, volume at least) and some kind of power management, allowing the machine to spin down while not under load and also allowing me to put it so sleep when need be. I also need a basic sound output via the inbuilt speakers as well as the 3.5mm (headphone) jack. I would also like to use a USB printer & scanner or two and have the ability to spin up virtual machines via bhyve, VirtualBox and have them pass through (at least) USB. I can live without the card reader and I can deal with the "reboot" command not executing a real reboot, instead forcing me to shutdown an restart manually. I'm hoping that's not too much to ask as otherwise I might be forced to retract to Linux.

I ask you, good people of FreeBSD forums, to tell me what further information (if any) would you like me to provide. /etc/rc.conf? /boot/loader.conf?

Thank you very much,
ceteris

Bonus question:
To avoid opening a second thread, I'll simply add a related question to this one: I've been trying to set up a home server, consisting of 2 virtual switches, a pfSense bhyve VM and multiple jails (NFS server, Plex, mail server etc.) with an Intel i5-650, 8GB DDR3, 2 Intel GbE NICs and a bunch of HDDs. While jail configuration went on without incident (iocage), setting up
a pfSense virtual machine using 'vm-bhyve' hit a wall: The pfSense VM I manage to install via vm-bhyve (using the pfSense.iso and without VNC/graphics support) seems to only briefly communicate with the network and the console provided by vm-bhyve is useless. I understand I might/should be installing the pfSense.img version of the OS but I don't know how to do it in vm-bhyve. The switches created via "vm switch create xyz" seem to work well with ordinary FreeBSD 12.x guests but my install of pfSense (latest version) barely assigns a WAN IP address DHCP and then vanishes. I've tried using both "virtio-net" and "e1000" type virtual NICs but all to no avail. Previously, on Debian/Proxmox, I used OpenvSwitch to facilitate networking so I'm inclined to do so again but I'd like to give the incorporated FreeBSD/vm-bhyve bridging solution a chance before denouncing it all together as I trust it to be good (enough). I'd like to have my FreeBSD host spin up the pfSense VM immediately after boot to have it serve the jails which should wake immediately after.  || Again, thank you very much. FreeBSD is a gem of an OS so I would love to use it whenever I can.


----------



## twllnbrck (Nov 21, 2020)

ceteris said:


> I need a usable track/touchpad, some function keys (to regulate screen brightness, volume at least) and some kind of power management,


For CPU freq scaling you can use powerd(8) or sysutils/powerdxx from ports. I use the latter on my T420s with

```
# /etc/rc.conf

powerdxx_enable="YES"
powerdxx_flags="-n adaptive -a hiadaptive -b adaptive -m 800 -M 1200"
```

You can also configure Cx-states via /etc/rc.conf with `performance_cx_lowest` (AC) and `economy_cx_lowest` (battery).
If your wireless card supports power saving you can enable it as well

```
# /etc/rc.conf

ifconfig_wlan0="WPA DHCP powersave"
```
There are more power saving options, e.g. for usb devices via usbconfig(8). But the best guide on power saving is vermadens@ blog entry power-to-serve.
Lenovo uses ACPI for special keys, you can load acpi_ibm.ko kernel module in /etc/rc.conf

```
kld_list"${kld_list} acpi_ibm"
```
The brightness keys are working out of the box for me. This is also true for trackpoint/touchpad. But I increased trackpoint sensitivity with 

```
# /etc/sysctl.conf

hw.psm.trackpoint.sensitivity=255
hw.psm.trackpoint.upper_plateau=125
```
For the volume keys (XF86AudioRaiseVolume, XF86AudioLowerVolume) I use keybindings in openbox but I dont know how to configure bindings in XFCE.



ceteris said:


> I also need a basic sound output via the inbuilt speakers as well as the 3.5mm (headphone) jack.


The FreeBSD sound system remains a kind of mystery for me. I prefer audio/sndio as sound server. Anyway I had some struggle to configure the speaker to headphones switch. I was quite successful by adding

```
hint.hdaa.0.nid31.config="as=1 seq=0 device=Speaker"
hint.hdaa.0.nid25.config="as=1 seq=15 device=Headphones"
```
to /boot/device.hints. You may have to play with the nid channels. This guide might help you with the sound config.
Hope this will give you some starting points.


----------



## Lars Skogstad (Nov 21, 2020)

Ill give you a write up later. 
You need to use the libinput driver or what its called from linux. 
This makes it approx equal to the touchpad in linux. 

Have you checked the wiki page regarding touchpad? Lots of info there. 

Im running a lenovo t470 but tried on others as well. 

As far as I know, the maim problem is slow wifi drivers and suspend/resume isnt always working.


----------



## ceteris (Nov 22, 2020)

(I'm having hell-a time figuring up the BB editoring/highlighting commands of this board so I'll have to resort to a stile a little more oldschool

@twlnbrck
Thank you for your reply.
I already have "powerd_enable="YES"" enabled in /etc/rc.conf, have never heard of "powerdxx" but thank you for bringing it to my attention - it looks great.
I might go into configuring Cx-states but I'm not too concerned with batter life at this point. This laptop is getting quite old and the batter, while still usable, is getting worn out. I did have power draw optimized via TLP in Linux and, to tell you the truth, I just ended up running the machine full tilt at all times. The i5-6200U it hosts was never a powerhouse and since I quite often run MS Word inside a stripped down Windows VM while also having open a few instances of Firefox, Thunderbird, and countless terminal windows w/ SSH etc., what I'm concerned with  when it comes to power management is that the CPU governor is unlocking the most this chip can offer (which is cca. 2x2.4GHz HT).

I do have enabled "acpi_ibm_load="YES"" in /boot/loader.conf, is that the same as the "kld_list"${kld_list} acpi_ibm"" you've noted? I had known of vermaden's 'ZFS Madness' guide, did not know of the one you've mentioned; thank you very much, I'll be sure to give it a read.

For me, all  function keys (mute, vol up, vol down, mic cancel, bright up etc.) work out of the box on most desktop distributions of Linux. FreeBSD w/ Xfce4 gives me virtually nothing, even after enabling:
"acpi_video_load="YES""
"acpi_ibm_load="YES""
So far, I've been forced to regulate screen brightness by commanding "doas sysctl hw.acpi.video.lcd0.brightness=100". Xrandr seems to work as well but the results seem a little different and I don't really know why so I usually stick with the sysctl. The xrandr command I've found is:
"xrandr --output eDP-1 --brightness 0.7" [70% brightness; values above 1.0 work as well but I don't quite understand why.]

The Trackpad DOES work out the box for me, basically. The only thing refusing to respond is the third button / middle button above the Trackpad that would usually be used to scroll with the aid of the Trackpoint(?)(nipple), which I don't use. I've read the Synaptics wiki article about how to configure the Trackpad via /etc/sysctl.conf and the latest configuration I've come up with is as follows:



> # $FreeBSD: releng/12.2/sbin/sysctl/sysctl.conf 337624 2018-08-11 13:28:03Z brd $
> #
> #  This file is read when going to multi-user and its contents piped thru
> #  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
> ...



For a time, I was unsure where the quoted values/toggles belong, inside /etc/sysctl.conf or /boot/loader.conf? Well, now I'm pretty sure they're sysctl commands and therefore belong inside sysctl.conf. Although most of the values are currently commented out, I've had them active before, played with them quite a lot but NEVER managed to end up with usable configuration. What bothers me most about the trackpad is the LACK of
1) palm rejection while typing (my god, Is it annoying)
2) two finger scrolling (vertical)
3) middle button support
I can live with the trackpad not being perfect but I can hardly use the laptop when I'm constantly forced to correct myself because my palm keeps moving the cursor around. Another error I find with these Trackpad settings is that after completing the boot sequence, I get the following error messages (from dmesg -a | less):


> sysctl: unknown oid 'kern.sched.preempt_tresh' at line 20
> sysctl: unknown oid 'hw.psm.synaptics.vscroll_hor_area' at line 30
> sysctl: unknown oid 'hw.psm.synaptics.min_pressure' at line 34
> sysctl: unknown oid 'hw.psm.synaptics.max_pressure' at line 35
> ...


Obviously, they correspond to the toggles I have active in /etc/sysctl.conf and I fear I'm somehow doing it all wrong.

I've discovered I can toggle sound output with:
"sysctl hw.snd.default_unit=0" (inbuilt speakers)
"sysctl hw.snd.default_unit=1" (headphone jack)
"sysctl hw.snd.default_unit=2" (Intel HDMI 8ch)
but that's not exactly optimal.
The audio driver I have in use is currently (from rc.conf):
"sound_load="YES""
"snd_hda_load="YES""
Other from being quite quiet and NOT switching output when I plug in headphones, It seems to work OK-ish.

Lars Skogstad
Thank you very much for your comment. I'm looking forward to the write up you've mentioned. I've already talked about the Trackpad at lenght in this post but the Wireless, well that's a special story...

I fiddled with the wireless A LOT until I finally more or less gave up on getting anything more than a -11g connection with shit speeds. It works but I'm certainly not about to settle for this because, although my wireless AP is cheap 11n device, I'm not about to have all the rest of my wirelessly connected devices downclocked to -11g because FreeBSD's Intel wifi driver is crap. I've already devised a devilish plan but have sadly lacked the time to put it into action - I'm planning on runing modest Alpine Linux VM immediately upon the bootup of the FreeBSD host and having my Intel 3165 PCIe card passed through to it. I'll set networking inside the VM so that the FreeBSD host will be able to connect to the internet through it. Running the card with the Linux driver should (in my experience) allow for full tilt 11ac speeds. The card also supports Bluetooth which also operates nicely inside Linux but I've yet to come up with a plan how to use it in this way.

Here are my complete config files:
rc.conf


> #
> sshd_enable="YES"
> powerd_enable="YES"
> #moused_enable="YES"
> ...



loader.conf


> aesni_load="YES"
> geom_eli_load="YES"
> security.bsd.allow_destructive_dtrace=0
> kern.geom.label.disk_ident.enable="0"
> ...


----------



## Lars Skogstad (Nov 22, 2020)

Ceteris:  FreeBSD Wiki - Laptops/Thinkpad_470

There is my setup on the laptop I have been using. I think all the .conf files is uploaded to the site.
Here you have 2 links regarding the libinput for touchpad. It seems it's merged into the default xorg-server now so it should be more easy to set it up properly now.

https://www.davidschlachter.com/misc/t480-freebsd 
_View: https://www.reddit.com/r/freebsd/comments/hzc5aj/touchpad_configuration/_


---

Sound related:
https://unix.stackexchange.com/ques...ween-sound-in-speaker-and-built-in-headphones
- This might help you with automatic changing from speakers -> headphones and vice versa.

--

https://www.freebsd.org/cgi/man.cgi?acpi_ibm
Have you tried loading in the ACPI_IBM?


```
Depending on the ThinkPad model, event codes may vary. 
     On    a ThinkPad T41p these    are as follows:

       0x01          Fn + F1
       0x02          Fn + F2
       0x03          Fn + F3 (LCD backlight)
       0x04          Fn + F4 (Suspend to RAM)
       0x05          Fn + F5 (Bluetooth)
       0x06          Fn + F6
       0x07          Fn + F7 (Screen expand)
       0x08          Fn + F8
       0x09          Fn + F9
       0x0a          Fn + F10
       0x0b          Fn + F11
       0x0c          Fn + F12 (Suspend    to disk)
       0x0d          Fn + Backspace
       0x0e          Fn + Insert
       0x0f          Fn + Delete
       0x10          Fn + Home    (Brightness up)
       0x11          Fn + End (Brightness down)
       0x12          Fn + PageUp (ThinkLight)
       0x13          Fn + PageDown
       0x14          Fn + Space (Zoom)
       0x15          Volume Up
       0x16          Volume Down
       0x17          Mute
       0x18          Access IBM Button
```

It seems it's a bit different for certain ThinkPad models, some supports certain stuff and others don't.


----------



## Argentum (Nov 23, 2020)

ceteris said:


> I need a usable track/touchpad, some function keys (to regulate screen brightness, volume at least) and some kind of power management, allowing the machine to spin down while not under load and also allowing me to put it so sleep when need be. I also need a basic sound output via the inbuilt speakers as well as the 3.5mm (headphone) jack. I would also like to use a USB printer & scanner or two and have the ability to spin up virtual machines via bhyve, VirtualBox and have them pass through (at least) USB. I can live without the card reader and I can deal with the "reboot" command not executing a real reboot, instead forcing me to shutdown an restart manually. I'm hoping that's not too much to ask as otherwise I might be forced to retract to Linux.


Hello!

I am writing this reply on *Lenovo ThinkPad*, using FreeBSD 12.2 and MATE GUI. The touch-pad works. This came out of the box. No special action was needed. It works as well as mouse and built in sound.


----------



## ceteris (Nov 23, 2020)

Argentum:
I'm not too picky when it comes to desktops so I wouldn't hesitate switching to MATE if that was what was needed for a fully functional Trackpad, but I doubt it. My Trackpad works out the box as well but the middle click button is dead.

I've not had time to delve into things with more dedication but I do have a little update (for those who might be dealing with similar issues):

Here are some of the things you can do if faced with too low a sound volume on Intel Audio:
- Set volume to 100% by issuing command "mixer vol 100:100".
- Set pcm to 100% by issuing command "mixer pcm 100:100".
If maximizing those two parameters still doesn't produce the adequate volume, you can also* lower* the value of the following sysctl:
- "sysctl hw.snd.vpc_0db"
I'm not skilled enough to talk about what these settings do exactly but they do
seem to work with no ill effects, just be sure not to lower "hw.snd.vpc_0db" too much. In my case that means anything below ~10 (the sound starts clipping).


----------



## luboy (Dec 5, 2020)

Hi,
You can try to use the Realtek SD card reader with the help of rtsx driver. You can get it from here:
https://github.com/hlh-restart/rtsx
You will have to compile it but it is not difficult and so far I have had no issues.


----------



## ranefjord (Dec 6, 2020)

Hi!

I run FreeBSD 12.1 (again not 14.1, sorry for the version mixup) on a Thinkpad 450s, and had the same trouble as you have getting the brightness buttons to work. I did some reading and finally solved the problem, but I'm not sure I have done it the right way. It works however. This is what I did:

At first I did what you have already done. I loaded acpi_video and acpi_ibm in loader.conf and configured devd.conf as suggested above. Didn't work, and I tried this with alot of different configurations. Then I read the acpi_video man again. This is what it says under the BUGS-headline:

"Some systems only perform output switching via SMM even though they export the proper information via ACPI. On such systems, the proper hotkeys or OEM driver (for example, acpi_toshiba(4)) must be used *instead*." (https://www.freebsd.org/cgi/man.cgi?acpi_video(4))

So acpi_video is the common driver and the acpi_ibm is a replacement if you use a IBM/Lenovo thinkpad. At first I understood acpi_ibm as an extra addition to acpi_video, but I guess it is a replacement. I'm still not sure about this though. So I removed the acpi_video_load from loader.conf and only kept the acpi_ibm_load. That did the trick. Worked without configuring devd.conf.

In /boot/loader.conf:
acpi_ibm_load="YES"

Thats it!


----------



## twllnbrck (Dec 6, 2020)

ranefjord said:


> I run FreeBSD 14.1 on a Thinkpad 450s,


I doubt it ..


----------



## Jose (Dec 6, 2020)

twllnbrck said:


> I doubt it ..


Ssshh! He's from the future! Don't make him mad or he'll warp the space-time continuum around us!


----------



## twllnbrck (Dec 6, 2020)

Oh. I see.


----------



## phalange (Dec 6, 2020)

ranefjord said:


> In /boot/loader.conf:
> acpi_ibm_load="YES"



Tried this on Thinkpad t470s but no effect. Without acpi_video_load="YES" (loading only the IBM module) pressing brightness keys does nothing.

I've been trying to have sane monitor backlight control for a while. Thread 77015


----------



## luboy (Dec 7, 2020)

Hi, I use openbox and my configuration is mostly based on the very nice vermaden's guide - https://vermaden.wordpress.com/freebsd-desktop/. There might  still be some things that are "leftovers" from before 12.0 but in general it is regularly updated and gives a lot of helpful hints.
I am on FreeBSD 12.2 (gradually updated from 12.0) on Thinkpad T450. drm is compiled from 'ports' and enabled by setting kld_list="/boot/modules/i915kms.ko" in rc.conf. Reading through the forum I just recently found out that I do not need acpi_ibm.ko, acpi_video and moused in order to use the brightness keys (Fn+F5/F6) and the trackpad/touchpad in Xorg. The brightness keys work also in terminal, outside of Xorg. While moused is necessary in terminal, in Xorg the trackpad and the touchpad work much better with gestures and horizontal/vertical scrolling without moused.
One annoying problem at the moment is how to auto set the brightness on startup in drm, as it goes 100% on reboot and I have to manually set it with the keys.
Another thing that bothers me is how to invert the vertical mouse scroll (without moused).


----------



## twllnbrck (Dec 7, 2020)

luboy said:


> One annoying problem at the moment is how to auto set the brightness on startup in drm, as it goes 100% on reboot and I have to manually set it with the keys.


You can adjust the initial brightness with accessibility/redshift.


----------



## luboy (Dec 12, 2020)

twllnbrck said:


> You can adjust the initial brightness with accessibility/redshift.


Thanks for the proposal. Probably I haven't used the correct terminology. I want my backlight to go down from 100%. I tried with redshift and it was only software dimming the screen. The backlight was still 100%. For the moment I suppose I have to use some acpi_* module to do this.


----------



## twllnbrck (Dec 12, 2020)

luboy said:


> Thanks for the proposal. Probably I haven't used the correct terminology. I want my backlight to go down from 100%


Ah ok. Have you tried graphics/intel-backlight?


----------



## luboy (Dec 13, 2020)

Yes. I think it could save my day. I am still looking for another "direct" solution through drm.


----------



## twllnbrck (Dec 13, 2020)

Good. At least something is happening. Im not sure you'll succeed via drm.
Do you have a sysctl oid sys.class.backlight or check

```
sysctl sys.class.backlight.intel_backlight.bl_device.actual_brightness
```


----------



## luboy (Dec 14, 2020)

I don't have this OID. I have:

```
# sysctl sys.class
sys.class.drm.card0-HDMI-A-2.modes:
sys.class.drm.card0-HDMI-A-2.dpms: Off
sys.class.drm.card0-HDMI-A-2.enabled: disabled
sys.class.drm.card0-DP-2.modes:
sys.class.drm.card0-DP-2.dpms: Off
sys.class.drm.card0-DP-2.enabled: disabled
sys.class.drm.card0-HDMI-A-1.modes:
sys.class.drm.card0-HDMI-A-1.dpms: Off
sys.class.drm.card0-HDMI-A-1.enabled: disabled
sys.class.drm.card0-DP-1.modes:
sys.class.drm.card0-DP-1.dpms: Off
sys.class.drm.card0-DP-1.enabled: disabled
sys.class.drm.card0-eDP-1.modes: 1600x900
sys.class.drm.card0-eDP-1.dpms: On
sys.class.drm.card0-eDP-1.enabled: enabled
sys.class.drm.version: drm 1.1.0 20060810
```


----------



## ChrisPoulsen (Jan 12, 2021)

Hi
I'm trying to run FreeBSD 12.2 on a similar laptop as OP (Thinkpad E560) - I'm also having a hard time getting the middle button on the trackpoint working in Xorg, I've tried a lot of things suggested in various posts on this forum, but without success.

The touchpad/trackpoint is an ALPS GlidePoint and registers as such with libinput. Both the touchpad and track point are functional (except for the middle button) - I have not experimented with scrolling as I need the middle click to work first.

All trackpoint/touchpad buttons are functional in a plain console (no X) using moused, so the buttons are physically working.

In X I have tried dumping events using things like 'xev' but nothing registers for the middle button, everything else does emit something when activated.

Does anyone have a fully functional trackpoint (and touchpad) setup on identical (or similar hardware?) - Or is running FreeBSD on this old laptop a lost cause?


----------

