|
@@ -8,6 +8,7 @@
|
|
|
#include <asm/ioctls.h>
|
|
|
#include <linux/spi/spidev.h>
|
|
|
#include "kfile.h"
|
|
|
+#include "kspi.h"
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
@@ -17,31 +18,25 @@ MODULE_AUTHOR("GfA");
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#define _SPI_DEVICE "/dev/spidev1.0"
|
|
|
-static struct file *g_fdSpiDev = NULL;
|
|
|
+static struct file *g_pfSpiDev = NULL;
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-static int temp = 0;
|
|
|
static struct kobject *pKoGfa = NULL, *pKoTiva = NULL;
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-static ssize_t tivaTempShow(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
|
|
|
+static ssize_t firmware_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
|
|
|
{
|
|
|
- printk(KERN_ALERT "tivaTemp - Read!!!\n");
|
|
|
- return sprintf(buf, "%d", ++temp);
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t tivaTempStore(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count)
|
|
|
-{
|
|
|
- printk(KERN_ALERT "tivaTemp - Write!!!\n");
|
|
|
- sscanf(buf, "%d", &temp);
|
|
|
- return count;
|
|
|
+ int hw = 0, sw = 0;
|
|
|
+ printk(KERN_ALERT "%s, TID: %d, \"%s\"\n", __FUNCTION__, current->pid, current->comm);
|
|
|
+ CmdGetFirmwareVersion(g_pfSpiDev, &hw, &sw);
|
|
|
+ return sprintf(buf, "HW: %08X SW: %08X\n", hw, sw);
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-static struct kobj_attribute tivaTempAtt = __ATTR(temp, 0660, tivaTempShow, tivaTempStore);
|
|
|
+static struct kobj_attribute tivaFirmwareAtt = __ATTR_RO(firmware);
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
@@ -56,37 +51,37 @@ static int drv_init(void)
|
|
|
|
|
|
do
|
|
|
{
|
|
|
- if(!(pKoGfa = kobject_create_and_add("gfa", /*kernel_kobj*/NULL)))
|
|
|
+ if(!(g_pfSpiDev = kf_open(_SPI_DEVICE, O_RDWR, 0)))
|
|
|
{
|
|
|
- printk(KERN_ALERT "kobject_create_and_add failed\n");
|
|
|
+ printk(KERN_ALERT "file_open failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if(!(pKoTiva = kobject_create_and_add("tiva", pKoGfa)))
|
|
|
+ /////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if(!(pKoGfa = kobject_create_and_add("gfa", /*kernel_kobj*/NULL)))
|
|
|
{
|
|
|
printk(KERN_ALERT "kobject_create_and_add failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- /////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
- if(sysfs_create_file(pKoTiva, &tivaTempAtt.attr))
|
|
|
+ if(!(pKoTiva = kobject_create_and_add("tiva", pKoGfa)))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ printk(KERN_ALERT "kobject_create_and_add failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- if(!(g_fdSpiDev = kf_open(_SPI_DEVICE, O_RDWR, 0)))
|
|
|
+ if(sysfs_create_file(pKoTiva, &tivaFirmwareAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "file_open failed\n");
|
|
|
+ printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- ret = kf_ioctl(g_fdSpiDev, SPI_IOC_WR_MODE, (unsigned long)&mode);
|
|
|
+ ret = kf_ioctl(g_pfSpiDev, SPI_IOC_WR_MODE, (unsigned long)&mode);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
printk(KERN_ALERT "can't set spi mode\n");
|
|
@@ -94,14 +89,16 @@ static int drv_init(void)
|
|
|
}
|
|
|
|
|
|
mode = 0;
|
|
|
- ret = kf_ioctl(g_fdSpiDev, SPI_IOC_RD_MODE, (unsigned long)&mode);
|
|
|
+ ret = kf_ioctl(g_pfSpiDev, SPI_IOC_RD_MODE, (unsigned long)&mode);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
printk(KERN_ALERT "can't get spi mode\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- ret = kf_ioctl(g_fdSpiDev, SPI_IOC_WR_BITS_PER_WORD, (unsigned long)&bits);
|
|
|
+ /////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ ret = kf_ioctl(g_pfSpiDev, SPI_IOC_WR_BITS_PER_WORD, (unsigned long)&bits);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
printk(KERN_ALERT "can't set bits per word\n");
|
|
@@ -109,14 +106,16 @@ static int drv_init(void)
|
|
|
}
|
|
|
|
|
|
bits = 0;
|
|
|
- ret = kf_ioctl(g_fdSpiDev, SPI_IOC_RD_BITS_PER_WORD, (unsigned long)&bits);
|
|
|
+ ret = kf_ioctl(g_pfSpiDev, SPI_IOC_RD_BITS_PER_WORD, (unsigned long)&bits);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
printk(KERN_ALERT "can't get bits per word\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- ret = kf_ioctl(g_fdSpiDev, SPI_IOC_WR_MAX_SPEED_HZ, (unsigned long)&speed);
|
|
|
+ /////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ ret = kf_ioctl(g_pfSpiDev, SPI_IOC_WR_MAX_SPEED_HZ, (unsigned long)&speed);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
printk(KERN_ALERT "can't set max speed hz\n");
|
|
@@ -124,7 +123,7 @@ static int drv_init(void)
|
|
|
}
|
|
|
|
|
|
speed = 0;
|
|
|
- ret = kf_ioctl(g_fdSpiDev, SPI_IOC_RD_MAX_SPEED_HZ, (unsigned long)&speed);
|
|
|
+ ret = kf_ioctl(g_pfSpiDev, SPI_IOC_RD_MAX_SPEED_HZ, (unsigned long)&speed);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
printk(KERN_ALERT "can't get max speed hz\n");
|
|
@@ -136,19 +135,19 @@ static int drv_init(void)
|
|
|
printk(KERN_ALERT "mode: %hhu\n", mode);
|
|
|
printk(KERN_ALERT "bits: %hhu\n", bits);
|
|
|
printk(KERN_ALERT "speed: %u\n", speed);
|
|
|
- printk(KERN_ALERT "%s\n", __FUNCTION__);
|
|
|
+ printk(KERN_ALERT "%s, TID: %d, \"%s\"\n", __FUNCTION__, current->pid, current->comm);
|
|
|
return 0;
|
|
|
}
|
|
|
while(0);
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- if(g_fdSpiDev)
|
|
|
- kf_close(g_fdSpiDev);
|
|
|
+ if(g_pfSpiDev)
|
|
|
+ kf_close(g_pfSpiDev);
|
|
|
|
|
|
if(pKoTiva)
|
|
|
{
|
|
|
- sysfs_remove_file(pKoTiva, &tivaTempAtt.attr);
|
|
|
+ sysfs_remove_file(pKoTiva, &tivaFirmwareAtt.attr);
|
|
|
kobject_put(pKoTiva);
|
|
|
pKoTiva = NULL;
|
|
|
}
|
|
@@ -166,19 +165,19 @@ static int drv_init(void)
|
|
|
|
|
|
static void drv_exit(void)
|
|
|
{
|
|
|
- if(g_fdSpiDev)
|
|
|
- kf_close(g_fdSpiDev);
|
|
|
+ if(g_pfSpiDev)
|
|
|
+ kf_close(g_pfSpiDev);
|
|
|
|
|
|
if(pKoTiva)
|
|
|
{
|
|
|
- sysfs_remove_file(pKoTiva, &tivaTempAtt.attr);
|
|
|
+ sysfs_remove_file(pKoTiva, &tivaFirmwareAtt.attr);
|
|
|
kobject_put(pKoTiva);
|
|
|
}
|
|
|
|
|
|
if(pKoGfa)
|
|
|
kobject_put(pKoGfa);
|
|
|
|
|
|
- printk(KERN_ALERT "%s\n", __FUNCTION__);
|
|
|
+ printk(KERN_ALERT "%s, TID: %d, \"%s\"\n", __FUNCTION__, current->pid, current->comm);
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|