Skip to content

Commit

Permalink
st7735s: add (step 1) simple module for spi and dts
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Pahomov <[email protected]>
  • Loading branch information
pahomov-and committed Jan 20, 2020
1 parent f956c4c commit a731247
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
43 changes: 43 additions & 0 deletions st7735s/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
MODULE_NAME=st7735s

ifneq ($(KERNELRELEASE),)

obj-m :=$(MODULE_NAME).o

else

ccflags-y := -Wall
DT_SRCS=$(wildcard *.dts)
DT_OBJS=$(DT_SRCS:.dts=.dtbo)
DTC_FLAGS ?= -i $(DCT_EXTRA_PATH)


.PHONY: all clean

all: $(DT_OBJS)
$(MAKE) -C $(BUILD_KERNEL) M=$(PWD) modules

clean:
$(MAKE) -C $(BUILD_KERNEL) M=$(PWD) clean
-rm ./*.dtbo


$(DT_OBJS): $(DT_SRCS)
$(DTC) -@ -I dts -O dtb -o $@ $<


upload_config:
ssh-copy-id -i ~/.ssh/id_rsa.pub $(SSH_ORANGE)
echo $(KERNEL_VERSION)
-ssh $(SSH_ORANGE) '[ ! -d "/lib/modules/$(KERNEL_VERSION)/kernel/drivers/" ] && mkdir -p "/lib/modules/$(KERNEL_VERSION)/kernel/drivers/"'

upload_dtso: $(DT_OBJS)
-scp $< $(SSH_ORANGE):/boot/dtb/overlay/

upload_module: $(MODULE_NAME).ko
-scp $< $(SSH_ORANGE):/lib/modules/$(KERNEL_VERSION)/kernel/drivers/
-ssh $(SSH_ORANGE) 'depmod'

upload: upload_dtso upload_module

endif
12 changes: 12 additions & 0 deletions st7735s/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

export BUILD_KERNEL=$(pwd)/../../build/kernel_opi
export KERNEL_VERSION=5.4.0-rc1-00258-g2d00aee21a5d
export DTC=$BUILD_KERNEL/scripts/dtc/dtc
export CROSS_COMPILE=$(pwd)/../../toolchain/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
export ARCH=arm
export [email protected]
#export INCLUDE_DTS=/home/tymbys/WORK/GL/linux/arch/arm/boot/dts
export DCT_EXTRA_PATH=/home/tymbys/WORK/GL/linux/

make clean && make && make upload
79 changes: 79 additions & 0 deletions st7735s/st7735s.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* st7735s.c - Display driver
*
* Copyright (C) 2020 Andrey Pahomov <[email protected]>
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/spi/spi.h>


static int st7735s_probe(struct spi_device *spi)
{
int ret;

dev_info(&spi->dev, "%s:%d\n", __func__, __LINE__);

spi->bits_per_word = 8;
spi->mode = SPI_MODE_0;
spi->max_speed_hz = 500000;
ret = spi_setup(spi);
if (ret < 0)
return ret;

dev_info(&spi->dev, "%s:%d\n", __func__, __LINE__);
return 0;

}


static int st7735s_remove(struct spi_device *spi)
{
return 0;
}



static const struct of_device_id of_tbl[] = {
{.compatible = "st7735s",},
{},
};

MODULE_DEVICE_TABLE(of, of_tbl);

static struct spi_driver st7735s_driver = {
.driver = {
.name = "st7735s",
.of_match_table = of_tbl,
.owner = THIS_MODULE,
},

.probe = st7735s_probe,
.remove = st7735s_remove,
};




static int st7735s_init(void)
{
pr_info("%s:%d\n", __func__, __LINE__);
return spi_register_driver(&st7735s_driver);
}

static void st7735s_exit(void)
{
pr_info("%s:%d\n", __func__, __LINE__);
spi_unregister_driver(&st7735s_driver);
}

module_init(st7735s_init);
module_exit(st7735s_exit);

MODULE_AUTHOR("Andrey Pahomov <[email protected]>");
MODULE_DESCRIPTION("st7735s SPI display");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.1");
36 changes: 36 additions & 0 deletions st7735s/sun8i-h3-st7735s.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* sun8i-h3-st7735s.dts - Display driver
*
* Copyright (C) 2020 Andrey Pahomov <[email protected]>
*/
/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun8i-h3";

fragment@0 {
target-path = "/soc/spi@1c68000";
__overlay__ {
status = "okay";
/*
spidev@0 {
compatible = "spidev";
spi-max-frequency = <10000000>;
reg = <0>;
status = "okay";
};
*/

st7735s {
compatible = "st7735s";
spi-max-frequency = <10000000>;
reg = <0>;
status = "okay";
};

};
};
};

0 comments on commit a731247

Please sign in to comment.