better separation
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_AUTHOR("Wolfgang Hottgenroth");
|
MODULE_AUTHOR("Wolfgang Hottgenroth");
|
||||||
MODULE_DESCRIPTION("A simple LKM to parse the device tree for a specific device and its properties");
|
MODULE_DESCRIPTION("Driver for the MainsCnt measurement hat");
|
||||||
|
|
||||||
|
|
||||||
extern struct platform_driver leds_driver;
|
extern struct platform_driver leds_driver;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <linux/of_irq.h>
|
#include <linux/of_irq.h>
|
||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
|
|
||||||
|
#include "ls7366r_registers.h"
|
||||||
#include "ls7366r.h"
|
#include "ls7366r.h"
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ static int writeCmdData(struct spi_device *client, u8 c, u8 d) {
|
|||||||
return spi_write(client, buf, 2);
|
return spi_write(client, buf, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int read32(struct spi_device *client, u8 c, u32 *r) {
|
static int read32(struct spi_device *client, u8 c, u32 *r) {
|
||||||
u8 tx_buf[5];
|
u8 tx_buf[5];
|
||||||
tx_buf[0] = c;
|
tx_buf[0] = c;
|
||||||
u8 rx_buf[5];
|
u8 rx_buf[5];
|
||||||
@ -49,6 +50,10 @@ int read32(struct spi_device *client, u8 c, u32 *r) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int read_otr(struct spi_device *client, u32 *r) {
|
||||||
|
return read32(client, CMD_RD | REG_OTR, r);
|
||||||
|
}
|
||||||
|
|
||||||
static int read8(struct spi_device *client, u8 c, u8 *r) {
|
static int read8(struct spi_device *client, u8 c, u8 *r) {
|
||||||
u8 tx_buf[2];
|
u8 tx_buf[2];
|
||||||
tx_buf[0] = c;
|
tx_buf[0] = c;
|
||||||
|
@ -1,56 +1,6 @@
|
|||||||
#ifndef _LS7366R_H_
|
#ifndef _LS7366R_H_
|
||||||
#define _LS7366R_H_
|
#define _LS7366R_H_
|
||||||
|
|
||||||
#define REG_MDR0 0b00001000
|
int read_otr(struct spi_device *client, u32 *r);
|
||||||
#define REG_MDR1 0b00010000
|
|
||||||
#define REG_DTR 0b00011000
|
|
||||||
#define REG_CNTR 0b00100000
|
|
||||||
#define REG_OTR 0b00101000
|
|
||||||
#define REG_STR 0b00110000
|
|
||||||
|
|
||||||
#define CMD_CLR 0b00000000
|
|
||||||
#define CMD_RD 0b01000000
|
|
||||||
#define CMD_WR 0b10000000
|
|
||||||
#define CMD_LOAD 0b11000000
|
|
||||||
|
|
||||||
#define STR_CY 0b10000000
|
|
||||||
#define STR_BW 0b01000000
|
|
||||||
#define STR_CMP 0b00100000
|
|
||||||
#define STR_IDX 0b00010000
|
|
||||||
#define STR_CEN 0b00001000
|
|
||||||
#define STR_PLS 0b00000100
|
|
||||||
#define STR_UD 0b00000010
|
|
||||||
#define STR_S 0b00000001
|
|
||||||
|
|
||||||
#define MDR0_NOQ 0b00000000
|
|
||||||
#define MDR0_Q1 0b00000001
|
|
||||||
#define MDR0_Q2 0b00000010
|
|
||||||
#define MDR0_Q4 0b00000011
|
|
||||||
#define MDR0_FRC 0b00000000
|
|
||||||
#define MDR0_SCC 0b00000100
|
|
||||||
#define MDR0_RLC 0b00001000
|
|
||||||
#define MDR0_MNC 0b00001100
|
|
||||||
#define MDR0_DI 0b00000000
|
|
||||||
#define MDR0_ILC 0b00010000
|
|
||||||
#define MDR0_IRC 0b00100000
|
|
||||||
#define MDR0_ILO 0b00110000
|
|
||||||
#define MDR0_AI 0b00000000
|
|
||||||
#define MDR0_SI 0b01000000
|
|
||||||
#define MDR0_FC1 0b00000000
|
|
||||||
#define MDR0_FC2 0b10000000
|
|
||||||
|
|
||||||
#define MDR1_4CM 0b00000000
|
|
||||||
#define MDR1_3CM 0b00000001
|
|
||||||
#define MDR1_2CM 0b00000010
|
|
||||||
#define MDR1_1CM 0b00000011
|
|
||||||
#define MDR1_EC 0b00000000
|
|
||||||
#define MDR1_DC 0b00000100
|
|
||||||
#define MDR1_F_IDX 0b00010000
|
|
||||||
#define MDR1_F_CMP 0b00100000
|
|
||||||
#define MDR1_F_BW 0b01000000
|
|
||||||
#define MDR1_F_CY 0b10000000
|
|
||||||
|
|
||||||
|
|
||||||
int read32(struct spi_device *client, u8 c, u32 *r);
|
|
||||||
|
|
||||||
#endif /* _LS7366R_H_ */
|
#endif /* _LS7366R_H_ */
|
||||||
|
53
driver/ls7366r_registers.h
Normal file
53
driver/ls7366r_registers.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef _LS7366R_REGISTERS_H_
|
||||||
|
#define _LS7366R_REGISTERS_H_
|
||||||
|
|
||||||
|
#define REG_MDR0 0b00001000
|
||||||
|
#define REG_MDR1 0b00010000
|
||||||
|
#define REG_DTR 0b00011000
|
||||||
|
#define REG_CNTR 0b00100000
|
||||||
|
#define REG_OTR 0b00101000
|
||||||
|
#define REG_STR 0b00110000
|
||||||
|
|
||||||
|
#define CMD_CLR 0b00000000
|
||||||
|
#define CMD_RD 0b01000000
|
||||||
|
#define CMD_WR 0b10000000
|
||||||
|
#define CMD_LOAD 0b11000000
|
||||||
|
|
||||||
|
#define STR_CY 0b10000000
|
||||||
|
#define STR_BW 0b01000000
|
||||||
|
#define STR_CMP 0b00100000
|
||||||
|
#define STR_IDX 0b00010000
|
||||||
|
#define STR_CEN 0b00001000
|
||||||
|
#define STR_PLS 0b00000100
|
||||||
|
#define STR_UD 0b00000010
|
||||||
|
#define STR_S 0b00000001
|
||||||
|
|
||||||
|
#define MDR0_NOQ 0b00000000
|
||||||
|
#define MDR0_Q1 0b00000001
|
||||||
|
#define MDR0_Q2 0b00000010
|
||||||
|
#define MDR0_Q4 0b00000011
|
||||||
|
#define MDR0_FRC 0b00000000
|
||||||
|
#define MDR0_SCC 0b00000100
|
||||||
|
#define MDR0_RLC 0b00001000
|
||||||
|
#define MDR0_MNC 0b00001100
|
||||||
|
#define MDR0_DI 0b00000000
|
||||||
|
#define MDR0_ILC 0b00010000
|
||||||
|
#define MDR0_IRC 0b00100000
|
||||||
|
#define MDR0_ILO 0b00110000
|
||||||
|
#define MDR0_AI 0b00000000
|
||||||
|
#define MDR0_SI 0b01000000
|
||||||
|
#define MDR0_FC1 0b00000000
|
||||||
|
#define MDR0_FC2 0b10000000
|
||||||
|
|
||||||
|
#define MDR1_4CM 0b00000000
|
||||||
|
#define MDR1_3CM 0b00000001
|
||||||
|
#define MDR1_2CM 0b00000010
|
||||||
|
#define MDR1_1CM 0b00000011
|
||||||
|
#define MDR1_EC 0b00000000
|
||||||
|
#define MDR1_DC 0b00000100
|
||||||
|
#define MDR1_F_IDX 0b00010000
|
||||||
|
#define MDR1_F_CMP 0b00100000
|
||||||
|
#define MDR1_F_BW 0b01000000
|
||||||
|
#define MDR1_F_CY 0b10000000
|
||||||
|
|
||||||
|
#endif /* _LS7366R_REGISTERS_H_ */
|
@ -56,7 +56,7 @@ static void counter_worker(struct work_struct *work) {
|
|||||||
u64 ts = data->timestamp;
|
u64 ts = data->timestamp;
|
||||||
|
|
||||||
u32 counter_value;
|
u32 counter_value;
|
||||||
int ret = read32(data->client, CMD_RD | REG_OTR, &counter_value);
|
int ret = read_otr(data->client, &counter_value);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printk("counter - Error! read32 failed in counter_worker\n");
|
printk("counter - Error! read32 failed in counter_worker\n");
|
||||||
|
Reference in New Issue
Block a user