commit
a76596aa98
4 changed files with 584 additions and 69 deletions
|
|
@ -8,9 +8,9 @@
|
|||
# sudo ./adafruit-pitft.sh
|
||||
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
echo "Installer must be run as root."
|
||||
echo "Try 'sudo bash $0'"
|
||||
exit 1
|
||||
echo "Installer must be run as root."
|
||||
echo "Try 'sudo bash $0'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ TRANSFORM_28c270="0 -1 1 1 0 0 0 0 1"
|
|||
|
||||
|
||||
warning() {
|
||||
echo WARNING : $1
|
||||
echo WARNING : $1
|
||||
}
|
||||
|
||||
############################ Script assisters ############################
|
||||
|
|
@ -58,19 +58,19 @@ warning() {
|
|||
# preceded by a number (1 to N), display a prompt, check input until
|
||||
# a valid number within the selection range is entered.
|
||||
selectN() {
|
||||
for ((i=1; i<=$#; i++)); do
|
||||
echo $i. ${!i}
|
||||
done
|
||||
echo
|
||||
REPLY=""
|
||||
while :
|
||||
do
|
||||
echo -n "SELECT 1-$#: "
|
||||
read
|
||||
if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
|
||||
return $REPLY
|
||||
fi
|
||||
done
|
||||
for ((i=1; i<=$#; i++)); do
|
||||
echo $i. ${!i}
|
||||
done
|
||||
echo
|
||||
REPLY=""
|
||||
while :
|
||||
do
|
||||
echo -n "SELECT 1-$#: "
|
||||
read
|
||||
if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
|
||||
return $REPLY
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -161,9 +161,10 @@ progress() {
|
|||
|
||||
sysupdate() {
|
||||
if ! $UPDATE_DB; then
|
||||
# echo "Checking for correct software repositories..."
|
||||
# has_repo || { warning "Missing Apt repo, please add deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware to /etc/apt/sources.list.d/raspi.list" && exit 1; }
|
||||
# echo "Checking for correct software repositories..."
|
||||
# has_repo || { warning "Missing Apt repo, please add deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware to /etc/apt/sources.list.d/raspi.list" && exit 1; }
|
||||
echo "Updating apt indexes..." && progress 3 &
|
||||
sudo apt update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
|
||||
sudo apt-get update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
|
||||
echo "Reading package lists..."
|
||||
progress 3 && UPDATE_DB=true
|
||||
|
|
@ -175,14 +176,14 @@ sysupdate() {
|
|||
# perform replacement if found, else append replacement to end of file.
|
||||
# (# $1 = filename, $2 = pattern to match, $3 = replacement)
|
||||
reconfig() {
|
||||
grep $2 $1 >/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
# Pattern found; replace in file
|
||||
sed -i "s/$2/$3/g" $1 >/dev/null
|
||||
else
|
||||
# Not found; append (silently)
|
||||
echo $3 | sudo tee -a $1 >/dev/null
|
||||
fi
|
||||
grep $2 $1 >/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
# Pattern found; replace in file
|
||||
sed -i "s/$2/$3/g" $1 >/dev/null
|
||||
else
|
||||
# Not found; append (silently)
|
||||
echo $3 | sudo tee -a $1 >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -190,8 +191,8 @@ reconfig() {
|
|||
|
||||
function softwareinstall() {
|
||||
echo "Installing Pre-requisite Software...This may take a few minutes!"
|
||||
apt-get install -y libts0 1> /dev/null 2>&1 || apt-get install -y tslib 1> /dev/null 2>&1 || { warning "Apt failed to install TSLIB!" && exit 1; }
|
||||
apt-get install -y bc fbi git python-dev python-pip python-smbus python-spidev evtest libts-bin 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
|
||||
apt-get install -y libts0 1> /dev/null 2>&1 || apt-get install -y tslib 1> /dev/null 2>&1 || { warning "Apt failed to install TSLIB!" && exit 1; }
|
||||
apt-get install -y bc fbi git python-dev python-pip python-smbus python-spidev evtest libts-bin device-tree-compiler 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
|
||||
pip install evdev 1> /dev/null || { warning "Pip failed to install software!" && exit 1; }
|
||||
}
|
||||
|
||||
|
|
@ -199,9 +200,9 @@ function softwareinstall() {
|
|||
function update_configtxt() {
|
||||
if grep -q "adafruit-pitft-helper" "/boot/config.txt"; then
|
||||
echo "Already have an adafruit-pitft-helper section in /boot/config.txt."
|
||||
echo "Removing old section..."
|
||||
echo "Removing old section..."
|
||||
cp /boot/config.txt /boot/configtxt.bak
|
||||
sed -i -e "/^# --- added by adafruit-pitft-helper/,/^# --- end adafruit-pitft-helper/d" /boot/config.txt
|
||||
sed -i -e "/^# --- added by adafruit-pitft-helper/,/^# --- end adafruit-pitft-helper/d" /boot/config.txt
|
||||
fi
|
||||
|
||||
# remove any old flexfb/fbtft stuff
|
||||
|
|
@ -239,6 +240,19 @@ EOF
|
|||
overlay=""
|
||||
fi
|
||||
|
||||
if [ "${pitfttype}" == "st7789_240x135" ]; then
|
||||
dtc -@ -I dts -O dtb -o /boot/overlays/drm-minipitft114.dtbo overlays/minipitft114-overlay.dts
|
||||
echo "############# UPGRADING KERNEL ###############"
|
||||
sudo apt update || { warning "Apt failed to update itself!" && exit 1; }
|
||||
sudo apt-get upgrade || { warning "Apt failed to install software!" && exit 1; }
|
||||
apt-get install -y raspberrypi-kernel-headers 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
|
||||
[ -d /lib/modules/$(uname -r)/build ] || { warning "Kernel was updated, please reboot now and re-run script!" && exit 1; }
|
||||
cd st7789_module
|
||||
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules || { warning "Apt failed to compile ST7789V driver!" && exit 1; }
|
||||
mv /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.BACK
|
||||
mv st7789v_ada.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.ko
|
||||
overlay="dtoverlay=drm-minipitft114,rotation=${pitftrot}"
|
||||
fi
|
||||
|
||||
date=`date`
|
||||
|
||||
|
|
@ -362,8 +376,8 @@ function install_fbcp() {
|
|||
|
||||
# if there's X11 installed...
|
||||
if [ -e /etc/lightdm ]; then
|
||||
echo "Setting raspi-config to boot to desktop w/o login..."
|
||||
raspi-config nonint do_boot_behaviour B4
|
||||
echo "Setting raspi-config to boot to desktop w/o login..."
|
||||
raspi-config nonint do_boot_behaviour B4
|
||||
fi
|
||||
|
||||
# Disable overscan compensation (use full screen):
|
||||
|
|
@ -376,39 +390,39 @@ function install_fbcp() {
|
|||
|
||||
# if there's X11 installed...
|
||||
if [ -e /etc/lightdm ]; then
|
||||
if [ "${pitfttype}" == "35r" ]; then
|
||||
echo "Using x1.5 resolution"
|
||||
SCALE=1.5
|
||||
else
|
||||
echo "Using x2 resolution"
|
||||
SCALE=2.0
|
||||
fi
|
||||
if [ "${pitfttype}" == "35r" ]; then
|
||||
echo "Using x1.5 resolution"
|
||||
SCALE=1.5
|
||||
else
|
||||
echo "Using x2 resolution"
|
||||
SCALE=2.0
|
||||
fi
|
||||
else
|
||||
echo "Using native resolution"
|
||||
SCALE=1
|
||||
echo "Using native resolution"
|
||||
SCALE=1
|
||||
fi
|
||||
WIDTH=`python -c "print(int(${WIDTH_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
|
||||
HEIGHT=`python -c "print(int(${HEIGHT_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
|
||||
reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=${WIDTH} ${HEIGHT} 60 1 0 0 0"
|
||||
|
||||
if [ "${pitftrot}" == "90" ] || [ "${pitftrot}" == "270" ]; then
|
||||
# dont rotate HDMI on 90 or 270
|
||||
reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" ""
|
||||
# dont rotate HDMI on 90 or 270
|
||||
reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" ""
|
||||
fi
|
||||
|
||||
if [ "${pitftrot}" == "0" ]; then
|
||||
reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=1"
|
||||
# this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
|
||||
pitftrot=90
|
||||
update_configtxt || bail "Unable to update /boot/config.txt"
|
||||
pitftrot=0
|
||||
reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=1"
|
||||
# this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
|
||||
pitftrot=90
|
||||
update_configtxt || bail "Unable to update /boot/config.txt"
|
||||
pitftrot=0
|
||||
fi
|
||||
if [ "${pitftrot}" == "180" ]; then
|
||||
reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=3"
|
||||
# this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
|
||||
pitftrot=90
|
||||
update_configtxt || bail "Unable to update /boot/config.txt"
|
||||
pitftrot=180
|
||||
reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=3"
|
||||
# this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
|
||||
pitftrot=90
|
||||
update_configtxt || bail "Unable to update /boot/config.txt"
|
||||
pitftrot=180
|
||||
fi
|
||||
|
||||
}
|
||||
|
|
@ -449,8 +463,8 @@ function uninstall_fbcp_rclocal() {
|
|||
|
||||
function update_xorg() {
|
||||
if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
|
||||
matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
|
||||
transform="Option \"TransformationMatrix\" \"${matrix}\""
|
||||
matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
|
||||
transform="Option \"TransformationMatrix\" \"${matrix}\""
|
||||
cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
|
||||
Section "InputClass"
|
||||
Identifier "STMPE Touchscreen Calibration"
|
||||
|
|
@ -463,8 +477,8 @@ EOF
|
|||
fi
|
||||
|
||||
if [ "${pitfttype}" == "28c" ]; then
|
||||
matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
|
||||
transform="Option \"TransformationMatrix\" \"${matrix}\""
|
||||
matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
|
||||
transform="Option \"TransformationMatrix\" \"${matrix}\""
|
||||
cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
|
||||
Section "InputClass"
|
||||
Identifier "FocalTech Touchscreen Calibration"
|
||||
|
|
@ -495,9 +509,10 @@ selectN "PiTFT 2.4\", 2.8\" or 3.2\" resistive (240x320)" \
|
|||
"PiTFT 2.8\" capacitive touch (240x320)" \
|
||||
"PiTFT 3.5\" resistive touch (320x480)" \
|
||||
"Braincraft 1.54\" display (240x240)" \
|
||||
"MiniPiTFT 1.14\" display (240x135) - WARNING! CUTTING EDGE! WILL UPGRADE YOUR KERNEL TO LATEST" \
|
||||
"Quit without installing"
|
||||
PITFT_SELECT=$?
|
||||
if [ $PITFT_SELECT -gt 5 ]; then
|
||||
if [ $PITFT_SELECT -gt 6 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
@ -512,7 +527,7 @@ if [ $PITFT_ROTATE -gt 4 ]; then
|
|||
fi
|
||||
|
||||
PITFT_ROTATIONS=("90" "180" "270" "0")
|
||||
PITFT_TYPES=("28r" "22" "28c" "35r" "st7789_240x240")
|
||||
PITFT_TYPES=("28r" "22" "28c" "35r" "st7789_240x240" "st7789_240x135")
|
||||
WIDTH_VALUES=(320 320 320 480 240)
|
||||
HEIGHT_VALUES=(240 240 240 320 240)
|
||||
HZ_VALUES=(64000000 64000000 64000000 32000000 64000000)
|
||||
|
|
@ -573,13 +588,14 @@ pitfttype=${PITFT_TYPES[$PITFT_SELECT-1]}
|
|||
pitftrot=${PITFT_ROTATIONS[$PITFT_ROTATE-1]}
|
||||
|
||||
|
||||
if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ] && [ "${pitfttype}" != "st7789_240x240" ]; then
|
||||
if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ] && [ "${pitfttype}" != "st7789_240x240" ] && [ "${pitfttype}" != "st7789_240x135" ]; then
|
||||
echo "Type must be one of:"
|
||||
echo " '28r' (2.8\" resistive, PID 1601)"
|
||||
echo " '28c' (2.8\" capacitive, PID 1983)"
|
||||
echo " '35r' (3.5\" Resistive)"
|
||||
echo " '22' (2.2\" no touch)"
|
||||
echo " 'st7789_240x240' (1.54\" or 1.3\" no touch)"
|
||||
echo " 'st7789_240x135' 1.14\" no touch)"
|
||||
echo
|
||||
print_help
|
||||
fi
|
||||
|
|
@ -611,13 +627,13 @@ else
|
|||
uninstall_console || bail "Unable to configure console"
|
||||
|
||||
if ask "Would you like the HDMI display to mirror to the PiTFT display?"; then
|
||||
info PITFT "Adding FBCP support..."
|
||||
install_fbcp || bail "Unable to configure fbcp"
|
||||
info PITFT "Adding FBCP support..."
|
||||
install_fbcp || bail "Unable to configure fbcp"
|
||||
|
||||
if [ -e /etc/lightdm ]; then
|
||||
info PITFT "Updating X11 default calibration..."
|
||||
update_xorg || bail "Unable to update calibration"
|
||||
fi
|
||||
if [ -e /etc/lightdm ]; then
|
||||
info PITFT "Updating X11 default calibration..."
|
||||
update_xorg || bail "Unable to update calibration"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
@ -643,8 +659,8 @@ echo
|
|||
echo -n "REBOOT NOW? [y/N] "
|
||||
read
|
||||
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
|
||||
echo "Exiting without reboot."
|
||||
exit 0
|
||||
echo "Exiting without reboot."
|
||||
exit 0
|
||||
fi
|
||||
echo "Reboot started..."
|
||||
reboot
|
||||
|
|
|
|||
78
overlays/minipitft114-overlay.dts
Normal file
78
overlays/minipitft114-overlay.dts
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Device Tree overlay for Adafruit Mini PiTFT 1.14" Display
|
||||
*
|
||||
*/
|
||||
|
||||
/dts-v1/;
|
||||
/plugin/;
|
||||
|
||||
/ {
|
||||
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
|
||||
|
||||
fragment@0 {
|
||||
target = <&spi0>;
|
||||
__overlay__ {
|
||||
status = "okay";
|
||||
|
||||
spidev@0{
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
fragment@1 {
|
||||
target = <&gpio>;
|
||||
__overlay__ {
|
||||
pitft_pins: pitft_pins {
|
||||
brcm,pins = <25>; /* dc pin */
|
||||
brcm,function = <1>; /* out */
|
||||
brcm,pull = <0>; /* no pull */
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
fragment@2 {
|
||||
target = <&spi0>;
|
||||
__overlay__ {
|
||||
/* needed to avoid dtc warning */
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
pitft: pitft@0{
|
||||
compatible = "multi-inno,mi0283qt";
|
||||
reg = <0>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pitft_pins>;
|
||||
|
||||
spi-max-frequency = <32000000>;
|
||||
rotation = <90>;
|
||||
width = <136>;
|
||||
height = <240>;
|
||||
col_offset = <53>;
|
||||
row_offset = <40>;
|
||||
dc-gpios = <&gpio 25 0>;
|
||||
backlight = <&backlight>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
fragment@3 {
|
||||
target-path = "/soc";
|
||||
__overlay__ {
|
||||
backlight: backlight {
|
||||
compatible = "gpio-backlight";
|
||||
gpios = <&gpio 22 0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
__overrides__ {
|
||||
speed = <&pitft>,"spi-max-frequency:0";
|
||||
rotation = <&pitft>,"rotation:0";
|
||||
width = <&pitft>,"width:0";
|
||||
height = <&pitft>,"height:0";
|
||||
col_offset = <&pitft>,"col_offset:0";
|
||||
row_offset = <&pitft>,"row_offset:0";
|
||||
};
|
||||
};
|
||||
14
st7789_module/Makefile
Normal file
14
st7789_module/Makefile
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
obj-m+=st7789v_ada.o
|
||||
|
||||
KDIR ?= /lib/modules/`uname -r`/build
|
||||
|
||||
default:
|
||||
$(MAKE) -C $(KDIR) M=$(pwd) modules
|
||||
|
||||
install:
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) modules_install
|
||||
$(DEPMOD)
|
||||
|
||||
clean:
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) clean
|
||||
|
||||
407
st7789_module/st7789v_ada.c
Normal file
407
st7789_module/st7789v_ada.c
Normal file
|
|
@ -0,0 +1,407 @@
|
|||
/*
|
||||
* DRM driver for ST7789V panels with flexible config
|
||||
*
|
||||
* Copyright 2019 Limor Fried
|
||||
* Copyright 2016 Noralf Trønnes
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/backlight.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/property.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/spi/spi.h>
|
||||
|
||||
#include <drm/drm_fb_helper.h>
|
||||
#include <drm/drm_modeset_helper.h>
|
||||
#include <drm/drm_gem_framebuffer_helper.h>
|
||||
#include <drm/tinydrm/mipi-dbi.h>
|
||||
#include <drm/tinydrm/tinydrm-helpers.h>
|
||||
#include <video/mipi_display.h>
|
||||
|
||||
#define ST77XX_MADCTL_MY 0x80
|
||||
#define ST77XX_MADCTL_MX 0x40
|
||||
#define ST77XX_MADCTL_MV 0x20
|
||||
#define ST77XX_MADCTL_ML 0x10
|
||||
#define ST77XX_MADCTL_BGR 0x08
|
||||
#define ST77XX_MADCTL_RGB 0x00
|
||||
|
||||
static u32 col_offset = 0;
|
||||
static u32 row_offset = 0;
|
||||
static u8 col_hack_fix_offset = 0;
|
||||
static short x_offset = 0;
|
||||
static short y_offset = 0;
|
||||
|
||||
static void st7789vada_enable(struct drm_simple_display_pipe *pipe,
|
||||
struct drm_crtc_state *crtc_state,
|
||||
struct drm_plane_state *plane_state)
|
||||
{
|
||||
struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
|
||||
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
|
||||
u8 addr_mode;
|
||||
int ret;
|
||||
|
||||
DRM_DEBUG_KMS("\n");
|
||||
|
||||
ret = mipi_dbi_poweron_conditional_reset(mipi);
|
||||
if (ret < 0)
|
||||
return;
|
||||
if (ret == 1)
|
||||
goto out_enable;
|
||||
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF);
|
||||
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
|
||||
msleep(150);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
|
||||
msleep(10);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT, 0x55); // 16 bit color
|
||||
msleep(10);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, 0);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, 0, 0, 0, 240);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS, 0, 0, 320>>8, 320&0xFF);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_ENTER_INVERT_MODE); // odd hack, displays are inverted
|
||||
mipi_dbi_command(mipi, MIPI_DCS_ENTER_NORMAL_MODE);
|
||||
msleep(10);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
|
||||
msleep(10);
|
||||
|
||||
out_enable:
|
||||
/* The PiTFT (ili9340) has a hardware reset circuit that
|
||||
* resets only on power-on and not on each reboot through
|
||||
* a gpio like the rpi-display does.
|
||||
* As a result, we need to always apply the rotation value
|
||||
* regardless of the display "on/off" state.
|
||||
*/
|
||||
switch (mipi->rotation) {
|
||||
default:
|
||||
addr_mode = 0;
|
||||
x_offset = col_offset;
|
||||
y_offset = row_offset;
|
||||
break;
|
||||
case 90:
|
||||
addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MX;
|
||||
x_offset = row_offset;
|
||||
y_offset = col_offset;
|
||||
break;
|
||||
case 180:
|
||||
addr_mode = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY;
|
||||
x_offset = col_offset+col_hack_fix_offset;
|
||||
// hack tweak to account for extra pixel width to make even
|
||||
y_offset = row_offset;
|
||||
break;
|
||||
case 270:
|
||||
addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MY;
|
||||
x_offset = row_offset;
|
||||
y_offset = col_offset;
|
||||
break;
|
||||
}
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
|
||||
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
|
||||
|
||||
mipi_dbi_enable_flush(mipi, crtc_state, plane_state);
|
||||
|
||||
backlight_enable(mipi->backlight);
|
||||
}
|
||||
|
||||
static const struct drm_simple_display_pipe_funcs st7789vada_pipe_funcs = {
|
||||
.enable = st7789vada_enable,
|
||||
.disable = mipi_dbi_pipe_disable,
|
||||
.update = tinydrm_display_pipe_update,
|
||||
.prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
|
||||
};
|
||||
|
||||
static struct drm_display_mode st7789vada_mode = {
|
||||
TINYDRM_MODE(240, 320, 25, 15), // width, height, mm_w, mm_h
|
||||
};
|
||||
|
||||
DEFINE_DRM_GEM_CMA_FOPS(st7789vada_fops);
|
||||
|
||||
static struct drm_driver st7789vada_driver = {
|
||||
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
|
||||
DRIVER_ATOMIC,
|
||||
.fops = &st7789vada_fops,
|
||||
TINYDRM_GEM_DRIVER_OPS,
|
||||
.debugfs_init = mipi_dbi_debugfs_init,
|
||||
.name = "st7789vada",
|
||||
.desc = "ST7789V Adafruit",
|
||||
.date = "20190914",
|
||||
.major = 1,
|
||||
.minor = 0,
|
||||
};
|
||||
|
||||
static const struct of_device_id st7789vada_of_match[] = {
|
||||
{ .compatible = "multi-inno,mi0283qt" },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, st7789vada_of_match);
|
||||
|
||||
static const struct spi_device_id st7789vada_id[] = {
|
||||
{ "st7789vada", 0 },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(spi, st7789vada_id);
|
||||
|
||||
|
||||
static const struct drm_framebuffer_funcs st7789vada_fb_funcs = {
|
||||
.destroy = drm_gem_fb_destroy,
|
||||
.create_handle = drm_gem_fb_create_handle,
|
||||
.dirty = tinydrm_fb_dirty,
|
||||
};
|
||||
|
||||
static const uint32_t st7789vada_formats[] = {
|
||||
DRM_FORMAT_RGB565,
|
||||
DRM_FORMAT_XRGB8888,
|
||||
};
|
||||
|
||||
static int st7789vada_fb_dirty(struct drm_framebuffer *fb,
|
||||
struct drm_file *file_priv,
|
||||
unsigned int flags, unsigned int color,
|
||||
struct drm_clip_rect *clips,
|
||||
unsigned int num_clips)
|
||||
{
|
||||
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
|
||||
struct tinydrm_device *tdev = fb->dev->dev_private;
|
||||
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
|
||||
bool swap = mipi->swap_bytes;
|
||||
struct drm_clip_rect clip;
|
||||
int ret = 0;
|
||||
bool full;
|
||||
void *tr;
|
||||
u16 x1, x2, y1, y2;
|
||||
|
||||
if (!mipi->enabled)
|
||||
return 0;
|
||||
|
||||
full = tinydrm_merge_clips(&clip, clips, num_clips, flags,
|
||||
fb->width, fb->height);
|
||||
|
||||
DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id,
|
||||
clip.x1, clip.x2, clip.y1, clip.y2);
|
||||
|
||||
if (!mipi->dc || !full || swap ||
|
||||
fb->format->format == DRM_FORMAT_XRGB8888) {
|
||||
tr = mipi->tx_buf;
|
||||
ret = mipi_dbi_buf_copy(mipi->tx_buf, fb, &clip, swap);
|
||||
if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
tr = cma_obj->vaddr;
|
||||
}
|
||||
|
||||
x1 = clip.x1 + x_offset;
|
||||
x2 = clip.x2 - 1 + x_offset;
|
||||
y1 = clip.y1 + y_offset;
|
||||
y2 = clip.y2 - 1 + y_offset;
|
||||
|
||||
//printk(KERN_INFO "setaddrwin %d %d %d %d\n", x1, y1, x2, y2);
|
||||
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS,
|
||||
(x1 >> 8) & 0xFF, x1 & 0xFF,
|
||||
(x2 >> 8) & 0xFF, x2 & 0xFF);
|
||||
mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS,
|
||||
(y1 >> 8) & 0xFF, y1 & 0xFF,
|
||||
(y2 >> 8) & 0xFF, y2 & 0xFF);
|
||||
|
||||
ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START, tr,
|
||||
(clip.x2 - clip.x1) * (clip.y2 - clip.y1) * 2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* st7789vada - MIPI DBI initialization
|
||||
* @dev: Parent device
|
||||
* @mipi: &mipi_dbi structure to initialize
|
||||
* @pipe_funcs: Display pipe functions
|
||||
* @driver: DRM driver
|
||||
* @mode: Display mode
|
||||
* @rotation: Initial rotation in degrees Counter Clock Wise
|
||||
*
|
||||
* This function initializes a &mipi_dbi structure and it's underlying
|
||||
* @tinydrm_device. It also sets up the display pipeline.
|
||||
*
|
||||
* Supported formats: Native RGB565 and emulated XRGB8888.
|
||||
*
|
||||
* Objects created by this function will be automatically freed on driver
|
||||
* detach (devres).
|
||||
*
|
||||
* Returns:
|
||||
* Zero on success, negative error code on failure.
|
||||
*/
|
||||
int st7789vada_init(struct device *dev, struct mipi_dbi *mipi,
|
||||
const struct drm_simple_display_pipe_funcs *pipe_funcs,
|
||||
struct drm_driver *driver,
|
||||
const struct drm_display_mode *mode, unsigned int rotation)
|
||||
{
|
||||
size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16);
|
||||
struct tinydrm_device *tdev = &mipi->tinydrm;
|
||||
int ret;
|
||||
|
||||
if (!mipi->command)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_init(&mipi->cmdlock);
|
||||
|
||||
mipi->tx_buf = devm_kmalloc(dev, bufsize, GFP_KERNEL);
|
||||
if (!mipi->tx_buf)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = devm_tinydrm_init(dev, tdev, &st7789vada_fb_funcs, driver);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
tdev->fb_dirty = st7789vada_fb_dirty;
|
||||
|
||||
/* TODO: Maybe add DRM_MODE_CONNECTOR_SPI */
|
||||
ret = tinydrm_display_pipe_init(tdev, pipe_funcs,
|
||||
DRM_MODE_CONNECTOR_VIRTUAL,
|
||||
st7789vada_formats,
|
||||
ARRAY_SIZE(st7789vada_formats), mode,
|
||||
rotation);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
tdev->drm->mode_config.preferred_depth = 16;
|
||||
mipi->rotation = rotation;
|
||||
|
||||
drm_mode_config_reset(tdev->drm);
|
||||
|
||||
DRM_DEBUG_KMS("preferred_depth=%u, rotation = %u\n",
|
||||
tdev->drm->mode_config.preferred_depth, rotation);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int st7789vada_probe(struct spi_device *spi)
|
||||
{
|
||||
struct device *dev = &spi->dev;
|
||||
struct mipi_dbi *mipi;
|
||||
struct gpio_desc *dc;
|
||||
u32 rotation = 0;
|
||||
u32 width = 240;
|
||||
u32 height = 320;
|
||||
int ret;
|
||||
|
||||
mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL);
|
||||
if (!mipi)
|
||||
return -ENOMEM;
|
||||
|
||||
mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
|
||||
if (IS_ERR(mipi->reset)) {
|
||||
DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
|
||||
return PTR_ERR(mipi->reset);
|
||||
}
|
||||
|
||||
dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);
|
||||
if (IS_ERR(dc)) {
|
||||
DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
|
||||
return PTR_ERR(dc);
|
||||
}
|
||||
|
||||
mipi->regulator = devm_regulator_get(dev, "power");
|
||||
if (IS_ERR(mipi->regulator))
|
||||
return PTR_ERR(mipi->regulator);
|
||||
|
||||
mipi->backlight = devm_of_find_backlight(dev);
|
||||
if (IS_ERR(mipi->backlight))
|
||||
return PTR_ERR(mipi->backlight);
|
||||
|
||||
device_property_read_u32(dev, "rotation", &rotation);
|
||||
//printk(KERN_INFO "Rotation %d\n", rotation);
|
||||
|
||||
device_property_read_u32(dev, "width", &width);
|
||||
if (width % 2) {
|
||||
width +=1; // odd width will cause a kernel panic
|
||||
col_hack_fix_offset = 1;
|
||||
} else {
|
||||
col_hack_fix_offset = 0;
|
||||
}
|
||||
//printk(KERN_INFO "Width %d\n", width);
|
||||
if ((width == 0) || (width > 240)) {
|
||||
width = 240; // default to full framebuff;
|
||||
}
|
||||
device_property_read_u32(dev, "height", &height);
|
||||
//printk(KERN_INFO "Height %d\n", height);
|
||||
if ((height == 0) || (height > 320)) {
|
||||
height = 320; // default to full framebuff;
|
||||
}
|
||||
|
||||
st7789vada_mode.hdisplay = st7789vada_mode.hsync_start =
|
||||
st7789vada_mode.hsync_end = st7789vada_mode.htotal = width;
|
||||
st7789vada_mode.vdisplay = st7789vada_mode.vsync_start =
|
||||
st7789vada_mode.vsync_end = st7789vada_mode.vtotal = height;
|
||||
|
||||
device_property_read_u32(dev, "col_offset", &col_offset);
|
||||
//printk(KERN_INFO "Column offset %d\n", col_offset);
|
||||
|
||||
device_property_read_u32(dev, "row_offset", &row_offset);
|
||||
//printk(KERN_INFO "Row offset %d\n", row_offset);
|
||||
|
||||
ret = mipi_dbi_spi_init(spi, mipi, dc);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Cannot read from this controller via SPI */
|
||||
mipi->read_commands = NULL;
|
||||
|
||||
ret = st7789vada_init(&spi->dev, mipi, &st7789vada_pipe_funcs,
|
||||
&st7789vada_driver, &st7789vada_mode, rotation);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
spi_set_drvdata(spi, mipi);
|
||||
|
||||
return devm_tinydrm_register(&mipi->tinydrm);
|
||||
}
|
||||
|
||||
static void st7789vada_shutdown(struct spi_device *spi)
|
||||
{
|
||||
struct mipi_dbi *mipi = spi_get_drvdata(spi);
|
||||
|
||||
tinydrm_shutdown(&mipi->tinydrm);
|
||||
}
|
||||
|
||||
static int __maybe_unused st7789vada_pm_suspend(struct device *dev)
|
||||
{
|
||||
struct mipi_dbi *mipi = dev_get_drvdata(dev);
|
||||
|
||||
return drm_mode_config_helper_suspend(mipi->tinydrm.drm);
|
||||
}
|
||||
|
||||
static int __maybe_unused st7789vada_pm_resume(struct device *dev)
|
||||
{
|
||||
struct mipi_dbi *mipi = dev_get_drvdata(dev);
|
||||
|
||||
drm_mode_config_helper_resume(mipi->tinydrm.drm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops st7789vada_pm_ops = {
|
||||
SET_SYSTEM_SLEEP_PM_OPS(st7789vada_pm_suspend, st7789vada_pm_resume)
|
||||
};
|
||||
|
||||
static struct spi_driver st7789vada_spi_driver = {
|
||||
.driver = {
|
||||
.name = "st7789vada",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = st7789vada_of_match,
|
||||
.pm = &st7789vada_pm_ops,
|
||||
},
|
||||
.id_table = st7789vada_id,
|
||||
.probe = st7789vada_probe,
|
||||
.shutdown = st7789vada_shutdown,
|
||||
};
|
||||
module_spi_driver(st7789vada_spi_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Sitronix ST7789V Flexible DRM driver");
|
||||
MODULE_AUTHOR("Limor Fried");
|
||||
MODULE_LICENSE("GPL");
|
||||
Loading…
Reference in a new issue