|
@@ -10,37 +10,97 @@
|
|
|
#include <linux/workqueue.h>
|
|
|
#include <asm/ioctls.h>
|
|
|
#include <linux/spi/spidev.h>
|
|
|
+#include "defines.h"
|
|
|
#include "kfile.h"
|
|
|
#include "kspi.h"
|
|
|
+#include "ktiva.h"
|
|
|
#include "sfsattrib.h"
|
|
|
-
|
|
|
-#define _TIMER_INTERVAL (jiffies + 3 * HZ)
|
|
|
+#include "kfirmware.h"
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
MODULE_AUTHOR("GfA");
|
|
|
|
|
|
-/////////////////////////////////////////////////////////////////////////////
|
|
|
+#define _THREAD_DELAY_JIFFIES 5
|
|
|
+#define _IS_REVIVE_STATE(ret) ((ret) != -ECOMM)
|
|
|
|
|
|
-#define _SPI_DEVICE "/dev/spidev1.0"
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+// sys fs
|
|
|
|
|
|
-static void work_queue_func(struct work_struct *work);
|
|
|
static struct kobject *g_pKoGfa = NULL, *g_pKoTiva = NULL;
|
|
|
+static bool g_bHasFwVersion = false;
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
-// timer
|
|
|
+// worker threads
|
|
|
+
|
|
|
+static void _SysFsWorkProc(struct work_struct *work);
|
|
|
+static void _FwUploadWorkProc(struct work_struct *work);
|
|
|
|
|
|
static struct workqueue_struct *g_pwq = NULL;
|
|
|
-static DECLARE_WORK(g_wo, work_queue_func);
|
|
|
+static DECLARE_WORK(g_sysFsWorkObj, _SysFsWorkProc);
|
|
|
+static DECLARE_WORK(g_fwUploadWorkObj, _FwUploadWorkProc);
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+// timer
|
|
|
|
|
|
static volatile bool g_bTimerRunning = false;
|
|
|
static struct timer_list g_jiq_timer;
|
|
|
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+typedef enum _WorkerState
|
|
|
+{
|
|
|
+ WS_SysFs,
|
|
|
+ WS_FwUpload
|
|
|
+}WorkerState;
|
|
|
+
|
|
|
+static TIVA_UPLOAD_INFO g_tui;
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
static void OnJigTimer(unsigned long ptr)
|
|
|
{
|
|
|
-// printk(KERN_ALERT "%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
- queue_work(g_pwq, &g_wo);
|
|
|
+ static unsigned int nPass = 0;
|
|
|
+ static WorkerState ws = WS_SysFs;
|
|
|
+
|
|
|
+// KALERT("%s: %d, %p\n", __FUNCTION__, g_bTimerRunning ? 1 : 0, g_pwq);
|
|
|
+
|
|
|
+ if(g_bTimerRunning && g_pwq)
|
|
|
+ {
|
|
|
+ if(KfwQueryUploadInfo(&g_tui))
|
|
|
+ ws = WS_FwUpload;
|
|
|
+
|
|
|
+ switch(ws)
|
|
|
+ {
|
|
|
+ case WS_SysFs:
|
|
|
+ if(++nPass == 3)
|
|
|
+ {
|
|
|
+ if(!queue_work(g_pwq, &g_sysFsWorkObj))
|
|
|
+ {
|
|
|
+ KALERT("%s: queue_work failed\n", __FUNCTION__);
|
|
|
+ }
|
|
|
+
|
|
|
+ nPass = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mutex_lock(&g_mutex);
|
|
|
+ mod_timer(&g_jiq_timer, _TIMER_INTERVAL);
|
|
|
+ mutex_unlock(&g_mutex);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case WS_FwUpload:
|
|
|
+ if(!queue_work(g_pwq, &g_fwUploadWorkObj))
|
|
|
+ {
|
|
|
+ KALERT("%s: queue_work failed\n", __FUNCTION__);
|
|
|
+ }
|
|
|
+ ws = WS_SysFs;
|
|
|
+// nPass = 2;
|
|
|
+ nPass = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
@@ -49,119 +109,393 @@ static void OnJigTimer(unsigned long ptr)
|
|
|
// https://stackoverflow.com/questions/16367623/using-the-linux-sysfs-notify-call
|
|
|
//
|
|
|
|
|
|
-static void work_queue_func(struct work_struct *work)
|
|
|
+static void _FwUploadWorkProc(struct work_struct *work)
|
|
|
{
|
|
|
- TIVA_ADC tadc;
|
|
|
struct file *pfSpiDev = NULL;
|
|
|
- uint8_t mode = SPI_MODE_3;
|
|
|
- uint8_t bits = 8;
|
|
|
- uint32_t speed = 1000000;
|
|
|
- unsigned long start = jiffies;
|
|
|
-
|
|
|
-// printk(KERN_ALERT "%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
-// CmdGetFirmwareVersion(pfSpiDev, &g_hw, &g_sw);
|
|
|
-// sysfs_notify(g_pKoTiva, NULL, "firmware");
|
|
|
+ uint8_t mode = 0;
|
|
|
+ uint8_t bits = 0;
|
|
|
+ uint32_t speed = 0;
|
|
|
|
|
|
if((pfSpiDev = kf_open(_SPI_DEVICE, O_RDWR, 0)))
|
|
|
{
|
|
|
- if(kf_ioctl(pfSpiDev, SPI_IOC_WR_MODE, (unsigned long)&mode) < 0)
|
|
|
+ do
|
|
|
{
|
|
|
- printk(KERN_ALERT "can't set spi mode\n");
|
|
|
-// break;
|
|
|
- }
|
|
|
+ unsigned char stat = 0xFF;
|
|
|
|
|
|
- if(kf_ioctl(pfSpiDev, SPI_IOC_RD_MODE, (unsigned long)&mode) < 0)
|
|
|
- {
|
|
|
- printk(KERN_ALERT "can't get spi mode\n");
|
|
|
-// break;
|
|
|
- }
|
|
|
+ if(kspi_write_mode(pfSpiDev, SPI_MODE_3) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_write_mode failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- /////////////////////////////////////////////////////////////////////
|
|
|
+ if(kspi_read_mode(pfSpiDev, &mode) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_read_mode failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if(kf_ioctl(pfSpiDev, SPI_IOC_WR_BITS_PER_WORD, (unsigned long)&bits) < 0)
|
|
|
- {
|
|
|
- printk(KERN_ALERT "can't set bits per word\n");
|
|
|
-// break;
|
|
|
- }
|
|
|
+ if(mode != SPI_MODE_3)
|
|
|
+ {
|
|
|
+ KALERT("%s: Invalid mode!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if(kf_ioctl(pfSpiDev, SPI_IOC_RD_BITS_PER_WORD, (unsigned long)&bits) < 0)
|
|
|
- {
|
|
|
- printk(KERN_ALERT "can't get bits per word\n");
|
|
|
-// break;
|
|
|
- }
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- /////////////////////////////////////////////////////////////////////
|
|
|
+ if(kspi_write_bits_per_word(pfSpiDev, _SPI_BITS_PER_WORD) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_write_bits_per_word failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if(kf_ioctl(pfSpiDev, SPI_IOC_WR_MAX_SPEED_HZ, (unsigned long)&speed) < 0)
|
|
|
- {
|
|
|
- printk(KERN_ALERT "can't set max speed hz\n");
|
|
|
-// break;
|
|
|
- }
|
|
|
+ if(kspi_read_bits_per_word(pfSpiDev, &bits) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_read_bits_per_word failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if(kf_ioctl(pfSpiDev, SPI_IOC_RD_MAX_SPEED_HZ, (unsigned long)&speed) < 0)
|
|
|
- {
|
|
|
- printk(KERN_ALERT "can't get max speed hz\n");
|
|
|
-// break;
|
|
|
+ if(bits != _SPI_BITS_PER_WORD)
|
|
|
+ {
|
|
|
+ KALERT("%s: Invalid bits per word!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if(kspi_write_max_speed_hz(pfSpiDev, _SPI_SPEED_HZ) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_write_max_speed_hz failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(kspi_read_max_speed_hz(pfSpiDev, &speed) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_read_max_speed_hz failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(speed != _SPI_SPEED_HZ)
|
|
|
+ {
|
|
|
+ KALERT("%s: Invalid max. speed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if(g_sw >= KFW_MIN_HAS_MATERIAL_NR_VERSION)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ if(TivaCmdStartBootloader(pfSpiDev) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdStartBootloader failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ g_hw = -1;
|
|
|
+ g_sw = -1;
|
|
|
+ g_bHasFwVersion = false;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "version");
|
|
|
+
|
|
|
+ KALERT("%s: Started bootloader!\n", __FUNCTION__);
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ if(TivaCmdGetBootloaderStatus(pfSpiDev, &stat) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetStatus failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ KALERT("%s: Status: 0x%02hhX\n", __FUNCTION__, stat);
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ if(TivaCmdPing(pfSpiDev) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdPing failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ KALERT("%s: Ping success!\n", __FUNCTION__);
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ if(TivaCmdGetBootloaderStatus(pfSpiDev, &stat) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetStatus failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ KALERT("%s: Status: 0x%02hhX\n", __FUNCTION__, stat);
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ if(TivaCmdReset(pfSpiDev) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdReset failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ KALERT("%s: Started firmware!\n", __FUNCTION__);
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ if(TivaCmdGetStatus(pfSpiDev, &stat) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetStatus failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ KALERT("%s: Status: 0x%02hhX\n", __FUNCTION__, stat);
|
|
|
+
|
|
|
+// KALERT("%s: data: 0x%p, cb: %zu, mat: %s, bld: %s\n", __FUNCTION__, g_tui.pData, g_tui.nCbData, g_tui.pszMat, g_tui.pszBld);
|
|
|
}
|
|
|
+ while(0);
|
|
|
+
|
|
|
+ SfAttLockFirmware(false);
|
|
|
+ kf_close(pfSpiDev);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ KALERT("%s: kf_open failed\n", __FUNCTION__);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_bTimerRunning)
|
|
|
+ {
|
|
|
+ mutex_lock(&g_mutex);
|
|
|
+ mod_timer(&g_jiq_timer, _TIMER_INTERVAL);
|
|
|
+ mutex_unlock(&g_mutex);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+static void _SysFsWorkProc(struct work_struct *work)
|
|
|
+{
|
|
|
+ TIVA_ADC tadc;
|
|
|
+ unsigned char stat;
|
|
|
+ int hw, sw, ret;
|
|
|
+ unsigned long long nUpTime;
|
|
|
+ struct file *pfSpiDev = NULL;
|
|
|
+ uint8_t mode = 0;
|
|
|
+ uint8_t bits = 0;
|
|
|
+ uint32_t speed = 0;
|
|
|
+// unsigned long start = jiffies;
|
|
|
+
|
|
|
+// KALERT("%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
|
|
|
- if(CmdGetADC(pfSpiDev, &tadc) == 0)
|
|
|
+ if((pfSpiDev = kf_open(_SPI_DEVICE, O_RDWR, 0)))
|
|
|
+ {
|
|
|
+ do
|
|
|
{
|
|
|
- if(g_tadc.UVers != tadc.UVers)
|
|
|
+ if(kspi_write_mode(pfSpiDev, SPI_MODE_3) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_write_mode failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(kspi_read_mode(pfSpiDev, &mode) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_read_mode failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mode != SPI_MODE_3)
|
|
|
+ {
|
|
|
+ KALERT("%s: Invalid mode!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if(kspi_write_bits_per_word(pfSpiDev, _SPI_BITS_PER_WORD) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_write_bits_per_word failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(kspi_read_bits_per_word(pfSpiDev, &bits) < 0)
|
|
|
+ {
|
|
|
+ KALERT("%s: kspi_read_bits_per_word failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bits != _SPI_BITS_PER_WORD)
|
|
|
{
|
|
|
- g_tadc.UVers = tadc.UVers;
|
|
|
- sysfs_notify(g_pKoTiva, NULL, "UVers");
|
|
|
-// printk(KERN_ALERT "Update UVers.\n");
|
|
|
+ KALERT("%s: Invalid bits per word!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- if(g_tadc.UBatV3 != tadc.UBatV3)
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if(kspi_write_max_speed_hz(pfSpiDev, _SPI_SPEED_HZ) < 0)
|
|
|
{
|
|
|
- g_tadc.UBatV3 = tadc.UBatV3;
|
|
|
- sysfs_notify(g_pKoTiva, NULL, "UBatV3");
|
|
|
-// printk(KERN_ALERT "Update UBatV3.\n");
|
|
|
+ KALERT("%s: kspi_write_max_speed_hz failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- if(g_tadc.Temp != tadc.Temp)
|
|
|
+
|
|
|
+ if(kspi_read_max_speed_hz(pfSpiDev, &speed) < 0)
|
|
|
{
|
|
|
- g_tadc.Temp = tadc.Temp;
|
|
|
- sysfs_notify(g_pKoTiva, NULL, "Temp");
|
|
|
-// printk(KERN_ALERT "Update Temp.\n");
|
|
|
+ KALERT("%s: kspi_read_max_speed_hz failed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- if(g_tadc.UV5Vsys != tadc.UV5Vsys)
|
|
|
+
|
|
|
+ if(speed != _SPI_SPEED_HZ)
|
|
|
{
|
|
|
- g_tadc.UV5Vsys = tadc.UV5Vsys;
|
|
|
- sysfs_notify(g_pKoTiva, NULL, "UV5Vsys");
|
|
|
-// printk(KERN_ALERT "Update UV5Vsys.\n");
|
|
|
+ KALERT("%s: Invalid max. speed!\n", __FUNCTION__);
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- if(g_tadc.UV3V6Bat != tadc.UV3V6Bat)
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if( (ret = TivaCmdPing(pfSpiDev)) < 0 &&
|
|
|
+ _IS_REVIVE_STATE(ret))
|
|
|
{
|
|
|
- g_tadc.UV3V6Bat = tadc.UV3V6Bat;
|
|
|
- sysfs_notify(g_pKoTiva, NULL, "UV3V6Bat");
|
|
|
-// printk(KERN_ALERT "Update UV3V6Bat.\n");
|
|
|
+ KALERT("%s: TivaCmdPing failed: %d - call TivaRevive\n", __FUNCTION__, ret);
|
|
|
+ TivaRevive(pfSpiDev);
|
|
|
}
|
|
|
-
|
|
|
- if(g_tadc.TempTIVA != tadc.TempTIVA)
|
|
|
+
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if(!g_bHasFwVersion)
|
|
|
{
|
|
|
- g_tadc.TempTIVA = tadc.TempTIVA;
|
|
|
- sysfs_notify(g_pKoTiva, NULL, "TempTIVA");
|
|
|
-// printk(KERN_ALERT "Update TempTIVA.\n");
|
|
|
+ if((ret = TivaCmdGetFirmwareVersion(pfSpiDev, &hw, &sw)) == 0)
|
|
|
+ {
|
|
|
+ if((g_hw != hw) || (g_sw != sw))
|
|
|
+ {
|
|
|
+ g_hw = hw;
|
|
|
+ g_sw = sw;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "version");
|
|
|
+ }
|
|
|
+
|
|
|
+ g_bHasFwVersion = true;
|
|
|
+ }
|
|
|
+ else if(_IS_REVIVE_STATE(ret))
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetFirmwareVersion failed: %d - call TivaRevive\n", __FUNCTION__, ret);
|
|
|
+ TivaRevive(pfSpiDev);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
}
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if((ret = TivaCmdGetADC(pfSpiDev, &tadc)) == 0)
|
|
|
+ {
|
|
|
+ bool bModified = false;
|
|
|
+
|
|
|
+ if(g_tadc.UVers != tadc.UVers)
|
|
|
+ {
|
|
|
+ g_tadc.UVers = tadc.UVers;
|
|
|
+ bModified = true;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "UVers");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_tadc.UBatV3 != tadc.UBatV3)
|
|
|
+ {
|
|
|
+ g_tadc.UBatV3 = tadc.UBatV3;
|
|
|
+ bModified = true;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "UBatV3");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_tadc.Temp != tadc.Temp)
|
|
|
+ {
|
|
|
+ g_tadc.Temp = tadc.Temp;
|
|
|
+ bModified = true;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "TempBoard");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_tadc.UV5Vsys != tadc.UV5Vsys)
|
|
|
+ {
|
|
|
+ g_tadc.UV5Vsys = tadc.UV5Vsys;
|
|
|
+ bModified = true;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "UV5Vsys");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_tadc.UV3V6Bat != tadc.UV3V6Bat)
|
|
|
+ {
|
|
|
+ g_tadc.UV3V6Bat = tadc.UV3V6Bat;
|
|
|
+ bModified = true;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "UV3V6Bat");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_tadc.TempTIVA != tadc.TempTIVA)
|
|
|
+ {
|
|
|
+ g_tadc.TempTIVA = tadc.TempTIVA;
|
|
|
+ bModified = true;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "TempTIVA");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bModified) // if any of the ADC values have changed, signal the binary file
|
|
|
+ {
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "AdcBin");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(_IS_REVIVE_STATE(ret))
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetADC failed: %d - call TivaRevive\n", __FUNCTION__, ret);
|
|
|
+ TivaRevive(pfSpiDev);
|
|
|
+ }
|
|
|
+
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if((ret = TivaCmdGetUptime(pfSpiDev, &nUpTime)) == 0)
|
|
|
+ {
|
|
|
+ if(g_nUpTime != nUpTime)
|
|
|
+ {
|
|
|
+ g_nUpTime = nUpTime;
|
|
|
+ sysfs_notify(g_pKoTiva, NULL, "Uptime");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(_IS_REVIVE_STATE(ret))
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetUptime failed: %d - call TivaRevive\n", __FUNCTION__, ret);
|
|
|
+ TivaRevive(pfSpiDev);
|
|
|
+ }
|
|
|
+
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
+ schedule_timeout(_THREAD_DELAY_JIFFIES);
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ if((ret = TivaCmdGetStatus(pfSpiDev, &stat)) == 0)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else if(_IS_REVIVE_STATE(ret))
|
|
|
+ {
|
|
|
+ KALERT("%s: TivaCmdGetStatus failed: %d - call TivaRevive\n", __FUNCTION__, ret);
|
|
|
+ TivaRevive(pfSpiDev);
|
|
|
+ }
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+// KALERT("Worker pass - jiffies: %ld - status: 0x%02hhX\n", _JIFFY_DIFF(jiffies, start), stat);
|
|
|
}
|
|
|
+ while(0);
|
|
|
|
|
|
kf_close(pfSpiDev);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printk(KERN_ALERT "file_open failed\n");
|
|
|
+ KALERT("%s: kf_open failed\n", __FUNCTION__);
|
|
|
}
|
|
|
|
|
|
if(g_bTimerRunning)
|
|
|
{
|
|
|
+ mutex_lock(&g_mutex);
|
|
|
mod_timer(&g_jiq_timer, _TIMER_INTERVAL);
|
|
|
+ mutex_unlock(&g_mutex);
|
|
|
}
|
|
|
-
|
|
|
- printk(KERN_ALERT "Worker pass jiffies: %lu\n", ((long)jiffies - (long)start));
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
@@ -174,65 +508,87 @@ static int drv_init(void)
|
|
|
{
|
|
|
if(!(g_pKoGfa = kobject_create_and_add("gfa", NULL)))
|
|
|
{
|
|
|
- printk(KERN_ALERT "kobject_create_and_add failed\n");
|
|
|
+ KALERT("kobject_create_and_add failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(!(g_pKoTiva = kobject_create_and_add("tiva", g_pKoGfa)))
|
|
|
{
|
|
|
- printk(KERN_ALERT "kobject_create_and_add failed\n");
|
|
|
+ KALERT("kobject_create_and_add failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- if(sysfs_create_file(g_pKoTiva, &g_tivaFirmwareAtt.attr))
|
|
|
+ if(sysfs_create_file(g_pKoTiva, &g_tivaVersionAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(sysfs_create_file(g_pKoTiva, &g_tivaUptimeAtt.attr))
|
|
|
+ {
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(sysfs_create_file(g_pKoTiva, &g_tivaUVersAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(sysfs_create_file(g_pKoTiva, &g_tivaUBatV3Att.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(sysfs_create_file(g_pKoTiva, &g_tivaTempAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(sysfs_create_file(g_pKoTiva, &g_tivaUV5VsysAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(sysfs_create_file(g_pKoTiva, &g_tivaUV3V6BatAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(sysfs_create_file(g_pKoTiva, &g_tivaTempTIVAAtt.attr))
|
|
|
{
|
|
|
- printk(KERN_ALERT "sysfs_create_file failed\n");
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(sysfs_create_bin_file(g_pKoTiva, &g_tivaAdcBinAtt))
|
|
|
+ {
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
+ g_nCbFwData = 0;
|
|
|
+ if((g_pFwBuffer = (void*)__get_free_pages(GFP_KERNEL, _FIRMWARE_PAGES_COUNT)))
|
|
|
+ {
|
|
|
+ if(sysfs_create_bin_file(g_pKoTiva, &g_tivaFirmwareAtt))
|
|
|
+ {
|
|
|
+ KALERT("sysfs_create_file failed\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
if(!(g_pwq = create_workqueue("GfaWrk")))
|
|
|
{
|
|
|
- printk(KERN_ALERT "create_workqueue failed!\n");
|
|
|
+ KALERT("create_workqueue failed!\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -247,21 +603,21 @@ static int drv_init(void)
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- if(!queue_work(g_pwq, &g_wo))
|
|
|
+ if(!queue_work(g_pwq, &g_sysFsWorkObj))
|
|
|
{
|
|
|
- printk(KERN_ALERT "queue_work failed\n");
|
|
|
+ KALERT("%s: queue_work failed\n", __FUNCTION__);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- printk(KERN_ALERT "%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
+ KALERT("%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
return 0;
|
|
|
}
|
|
|
while(0);
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
+
|
|
|
if(g_bTimerRunning)
|
|
|
{
|
|
|
g_bTimerRunning = false;
|
|
@@ -269,17 +625,31 @@ static int drv_init(void)
|
|
|
}
|
|
|
|
|
|
if(g_pwq)
|
|
|
- destroy_workqueue(g_pwq);
|
|
|
+ {
|
|
|
+ destroy_workqueue(g_pwq);
|
|
|
+ g_pwq = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_pFwBuffer)
|
|
|
+ {
|
|
|
+ free_pages((unsigned long)g_pFwBuffer, _FIRMWARE_PAGES_COUNT);
|
|
|
+ g_pFwBuffer = NULL;
|
|
|
+ g_nCbFwData = 0;
|
|
|
+ }
|
|
|
|
|
|
if(g_pKoTiva)
|
|
|
{
|
|
|
- sysfs_remove_file(g_pKoTiva, &g_tivaFirmwareAtt.attr);
|
|
|
+ sysfs_remove_file(g_pKoTiva, &g_tivaVersionAtt.attr);
|
|
|
+ sysfs_remove_file(g_pKoTiva, &g_tivaUptimeAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUVersAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUBatV3Att.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaTempAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUV5VsysAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUV3V6BatAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaTempTIVAAtt.attr);
|
|
|
+ sysfs_remove_bin_file(g_pKoTiva, &g_tivaAdcBinAtt);
|
|
|
+ sysfs_remove_bin_file(g_pKoTiva, &g_tivaFirmwareAtt);
|
|
|
+
|
|
|
kobject_put(g_pKoTiva);
|
|
|
g_pKoTiva = NULL;
|
|
|
}
|
|
@@ -301,24 +671,37 @@ static void drv_exit(void)
|
|
|
del_timer_sync(&g_jiq_timer);
|
|
|
|
|
|
if(g_pwq)
|
|
|
- destroy_workqueue(g_pwq);
|
|
|
+ {
|
|
|
+ destroy_workqueue(g_pwq);
|
|
|
+ g_pwq = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(g_pFwBuffer)
|
|
|
+ {
|
|
|
+ free_pages((unsigned long)g_pFwBuffer, _FIRMWARE_PAGES_COUNT);
|
|
|
+ g_pFwBuffer = NULL;
|
|
|
+ g_nCbFwData = 0;
|
|
|
+ }
|
|
|
|
|
|
if(g_pKoTiva)
|
|
|
{
|
|
|
- sysfs_remove_file(g_pKoTiva, &g_tivaFirmwareAtt.attr);
|
|
|
+ sysfs_remove_file(g_pKoTiva, &g_tivaVersionAtt.attr);
|
|
|
+ sysfs_remove_file(g_pKoTiva, &g_tivaUptimeAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUVersAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUBatV3Att.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaTempAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUV5VsysAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaUV3V6BatAtt.attr);
|
|
|
sysfs_remove_file(g_pKoTiva, &g_tivaTempTIVAAtt.attr);
|
|
|
+ sysfs_remove_bin_file(g_pKoTiva, &g_tivaFirmwareAtt);
|
|
|
+
|
|
|
kobject_put(g_pKoTiva);
|
|
|
}
|
|
|
|
|
|
if(g_pKoGfa)
|
|
|
kobject_put(g_pKoGfa);
|
|
|
|
|
|
- printk(KERN_ALERT "%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
+ KALERT("%s, Ctx: \"%s\"-(%d)\n", __FUNCTION__, current->comm, current->pid);
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|