Add a new T31 kernel module for motors. (#913)

pull/919/head
Santiago Hormazabal 2023-07-20 06:01:05 -03:00 committed by GitHub
parent 76a3ed418f
commit dd3eba6aac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1327 additions and 0 deletions

View File

@ -108,6 +108,9 @@ BR2_PACKAGE_INGENIC_ATBM603X_SDIO_T31_MMC0=y
BR2_PACKAGE_INGENIC_ATBM603X_SDIO_T31_MMC1=y
# BR2_PACKAGE_RTL8188EU is not set
# Motors
BR2_PACKAGE_INGENIC_MOTORS_T31=y
# WIREGUARD
BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y
BR2_PACKAGE_WIREGUARD_TOOLS=y

View File

@ -31,6 +31,7 @@ source "$BR2_EXTERNAL_GENERAL_PATH/package/hisilicon-osdrv-hi3516ev200/Config.in
source "$BR2_EXTERNAL_GENERAL_PATH/package/hisilicon-osdrv-hi3519v101/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/hisilicon-osdrv-hi3536dv100/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/i2c-telemetry/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/ingenic-motors-t31/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/ingenic-atbm603x-sdio-t31/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/ingenic-opensdk/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/ingenic-osdrv-t20/Config.in"

View File

@ -0,0 +1,8 @@
config BR2_PACKAGE_INGENIC_MOTORS_T31
bool "ingenic-motors-t31"
depends on BR2_LINUX_KERNEL
help
Motor driver for Ingenic T31 using TCU2.2.
comment "ingenic-motors-t31 needs a Linux kernel to be built"
depends on !BR2_LINUX_KERNEL

View File

@ -0,0 +1,18 @@
################################################################################
#
# AltoBeam INGENIC_MOTORS_T31 wifi driver
#
################################################################################
INGENIC_MOTORS_T31_LICENSE = GPL-2.0
define INGENIC_MOTORS_T31_EXTRACT_CMDS
cp -av $(INGENIC_MOTORS_T31_PKGDIR)/src/* $(@D)/
endef
INGENIC_MOTORS_T31_MODULE_MAKE_OPTS = \
KVER=$(LINUX_VERSION_PROBED) \
KSRC=$(LINUX_DIR)
$(eval $(kernel-module))
$(eval $(generic-package))

View File

@ -0,0 +1,36 @@
#CROSS_COMPILE ?= mips-linux-gnu-
#KDIR := ${ISVP_ENV_KERNEL_DIR}
############################################################################
PWD:=$(shell pwd)
INSTALL_DIR := $(PWD)/output
DEFS =
MOTORS_NAME := sample_motor
$(MOTORS_NAME)-objs := motor.o
obj-m := $(MOTORS_NAME).o
EXTRA_CFLAGS := $(DEFS)
all: modules install
modules: clean
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KDIR) M=$(shell pwd) modules -j8
strip:
$(CROSS_COMPILE)strip $(INSTALL_DIR)/*.ko --strip-unneeded
install: modules
mkdir -p $(INSTALL_DIR)
chmod 777 $(INSTALL_DIR)
cp *.ko $(INSTALL_DIR)
clean:
@rm -rf *.o *~ .depend .*.cmd *.mod.c .tmp_versions *.ko *.symvers modules.order
make -C $(KDIR) M=$(PWD) ARCH=$(ARCH) clean
.PHONY: modules clean

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,161 @@
/*
* Copyright (C) 2015 Ingenic Semiconductor Co.,Ltd
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __MOTOR_H__
#define __MOTOR_H__
#include <linux/wait.h>
#include <linux/spinlock.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <jz_proc.h>
/*
* HORIZONTAL is X axis and VERTICAL is Y axis;
* while the Zero point is left-bottom, Origin point
* is cross point of horizontal midpoint and vertical midpoint.
*
*/
/*#define PLATFORM_HAS_HORIZONTAL_MOTOR 1*/
/*#define PLATFORM_HAS_VERTICAL_MOTOR 1*/
enum jz_motor_cnt {
HORIZONTAL_MOTOR,
VERTICAL_MOTOR,
HAS_MOTOR_CNT,
};
/* ioctl cmd */
#define MOTOR_STOP 0x1
#define MOTOR_RESET 0x2
#define MOTOR_MOVE 0x3
#define MOTOR_GET_STATUS 0x4
#define MOTOR_SPEED 0x5
#define MOTOR_GOBACK 0x6
#define MOTOR_CRUISE 0x7
#define MOTOR_GET_MAXSTEPS 0x8
/* motor speed */
#define MOTOR_MAX_SPEED 900 /**< unit: beats per second */
#define MOTOR_MIN_SPEED 100
enum motor_status {
MOTOR_IS_STOP,
MOTOR_IS_RUNNING,
};
struct motor_message {
int x;
int y;
enum motor_status status;
int speed;
unsigned int x_max_steps;
unsigned int y_max_steps;
};
struct motors_steps{
int x;
int y;
};
struct motor_reset_data {
unsigned int x_max_steps;
unsigned int y_max_steps;
unsigned int x_cur_step;
unsigned int y_cur_step;
};
enum motor_direction {
MOTOR_MOVE_LEFT_DOWN = -1,
MOTOR_MOVE_STOP,
MOTOR_MOVE_RIGHT_UP,
};
struct motor_platform_data {
const char name[32];
int motor_min_gpio;
int motor_max_gpio;
int motor_gpio_level;
int motor_st1_gpio;
int motor_st2_gpio;
int motor_st3_gpio;
int motor_st4_gpio;
};
enum motor_ops_state {
MOTOR_OPS_NORMAL,
MOTOR_OPS_CRUISE,
MOTOR_OPS_RESET,
MOTOR_OPS_STOP,
};
struct motor_driver {
struct motor_platform_data *pdata;
int max_pos_irq;
int min_pos_irq;
int max_steps; /* It is right-top point when x is max and y is max.*/
int cur_steps; /* It is left-bottom point when x is 0 and y is 0.*/
int total_steps;
char reset_min_pos;
char reset_max_pos;
enum motor_direction move_dir;
enum motor_ops_state state;
struct completion reset_completion;
struct timer_list min_timer;
struct timer_list max_timer;
/* debug parameters */
unsigned int max_pos_irq_cnt;
unsigned int min_pos_irq_cnt;
};
struct motor_move {
struct motors_steps one;
short times;
};
struct motor_device {
struct platform_device *pdev;
const struct mfd_cell *cell;
struct device *dev;
struct miscdevice misc_dev;
struct motor_driver motors[HAS_MOTOR_CNT];
char *skip_mode;
unsigned int counter;
struct completion stop_completion;
unsigned int wait_stop;
#ifdef CONFIG_SOC_T40
struct ingenic_tcu_chn *tcu;
#else
struct jz_tcu_chn *tcu;
#endif
int tcu_speed;
struct mutex dev_mutex;
spinlock_t slock;
enum motor_ops_state dev_state;
struct motor_message msg;
struct motor_move dst_move;
struct motor_move cur_move;
int run_step_irq;
int flag;
/* debug parameters */
struct proc_dir_entry *proc;
};
#endif // __MOTOR_H__

View File

@ -21,6 +21,7 @@ define MOTORS_BUILD_CMDS
(cd $(@D)/i2c-motor; $(TARGET_CC) -Os -s main.c -o i2c-motor)
(cd $(@D)/xm-kmotor; $(TARGET_CC) -Os -s main.c -o xm-kmotor)
(cd $(@D)/xm-uart; $(TARGET_CC) -Os -s main.c -o xm-uart)
(cd $(@D)/t31-kmotor; $(TARGET_CC) -Os -s main.c -o t31-kmotor)
endef
define MOTORS_INSTALL_TARGET_CMDS
@ -28,6 +29,7 @@ define MOTORS_INSTALL_TARGET_CMDS
$(INSTALL) -m 0755 -D $(@D)/i2c-motor/i2c-motor $(TARGET_DIR)/usr/bin/i2c-motor
$(INSTALL) -m 0755 -D $(@D)/xm-kmotor/xm-kmotor $(TARGET_DIR)/usr/bin/xm-kmotor
$(INSTALL) -m 0755 -D $(@D)/xm-uart/xm-uart $(TARGET_DIR)/usr/bin/xm-uart
$(INSTALL) -m 0755 -D $(@D)/t31-kmotor/t31-kmotor $(TARGET_DIR)/usr/bin/t31-kmotor
endef
$(eval $(generic-package))