summaryrefslogtreecommitdiff
path: root/mtac.h
blob: 2e36119029af15e480ac5d2d1787f7831336e9d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef IO_MODULE_MTAC_H_
#define IO_MODULE_MTAC_H_
// NUM_AP should be defined from the board code
// it should be set to the value of CONFIG_MTS_NUM_ACCESSORY_PORTS
// arch/arm/mach-at91/board-dt-sam9.c
// if it is 0 or undefined, there is no accessory card support on this HW
#ifdef CONFIG_MTS_NUM_ACCESSORY_PORTS

#ifndef NUM_AP
#define NUM_AP CONFIG_MTS_NUM_ACCESSORY_PORTS
#endif

#else
#define NUM_AP 0
#endif


#define PRODUCT_ID_MTAC_GPIOB			"MTAC-GPIOB"
#define PRODUCT_ID_MTAC_MFSER			"MTAC-MFSER"
#define PRODUCT_ID_MTAC_ETH				"MTAC-ETH"
#define PRODUCT_ID_MTAC_LORA			"MTAC-LORA"
#define PRODUCT_ID_MTAC_LORA_003		"MTAC-003"
#define PRODUCT_ID_MTAC_PULSE			"MTAC-PULSE"
#define PRODUCT_ID_MTAC_XDOT			"MTAC-XDOT"

/* Hardware version must be fewer characters than hw_version
   in struct mts_ap_eeprom_layout */
/* MTAC-LORA with native SPI or FTDI FT4222 */
#define HW_VERSION_MTAC_LORA_0_0		"MTAC-LORA-0.0"
/* MTAC-LORA2 with FTDI FT232H */
#define HW_VERSION_MTAC_LORA_1_0		"MTAC-LORA-1.0"
#define HW_VERSION_MTAC_LORA_1_1		"MTAC-LORA-1.1"
#define HW_VERSION_MTAC_LORA_1_5		"MTAC-LORA-1.5"
#define HW_VERSION_MTAC_LORA_003_0_0		"MTAC-003-0.0"
#define HW_VERSION_MTAC_LORA_003_0_1		"MTAC-003-0.1"
/* Code assumes CRESET/CDONE (SPI programming) cases will not
 * exactly match MTAC-LORA-0.0, 1.0, or 1.1.  Also levels before
 * 1.5 must be the same length.
 */

#define HW_VERSION_MTAC_LORA_2G4_0_0	"MTAC-LORA-2G4-0.0"

enum {
	MTAC_NONE,
	MTAC_GPIOB_0_0,
	MTAC_MFSER_0_0,
	MTAC_ETH_0_0,
	MTAC_LORA_0_0,
	MTAC_LORA_1_0,
	MTAC_LORA_1_1,
	MTAC_LORA_1_5,
	MTAC_LORA_003_0_0,
	MTAC_LORA_003_0_1,
	MTAC_PULSE_1_0,
	MTAC_XDOT_0_0,
	MTAC_LORA_2G4_0_0,
};

enum ap {
	port_1 = 1,
	port_2,
};

// info for accessory port
// contains function pointers for setup and teardown and useful info
// each type of accessory card should have one of these
struct ap_info {
	char  product_id[32];
	bool (*setup)(enum ap port);
	bool (*teardown)(enum ap port);
	char* (*gpio_pin_name_by_attr_name)(const char* name, int port);
	struct gpio_pin *gpio_pins;
	struct kobject *subdirs;
	struct attribute_group attr_group;
};

extern struct platform_device *mts_io_platform_device;

extern struct mutex mtac_mutex;

extern void mtac_clear_port_pins(int port_index);
extern void mtac_set_port_pins(int port_index, struct gpio_pin *pins, struct kobject *subdir);
extern struct kobj_attribute* mtac_create_attribute(const char* _name, umode_t _mode);
extern int mtac_port_from_kobject(struct kobject *kobj);
extern ssize_t mtac_show_product_info(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
extern bool mtac_add_product_info_attributes(int port, struct attribute** attrs, int* index);
extern struct gpio_pin *mtac_gpio_pin_by_attr_name(const char *name, int port);
extern ssize_t mtac_attr_show_ap_gpio_pin(struct kobject *kobj,
			struct kobj_attribute *attr,
			char *buf);
extern ssize_t mtac_attr_store_ap_gpio_pin(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count);
extern struct gpio_pin *mtac_gpio_pin_by_num(unsigned num, int port_index);
extern struct gpio_pin *mtac_gpio_pin_by_name(const char *name, int port_index);
extern void mtac_clear_port_pins(int port_index);
extern int mtac_find(void(*set_info)(struct ap_info* info), const char *target_product_id);
extern struct ap_info *mtac_port_info[];
extern void mtac_free(const char * product_id, bool (* setup)(enum ap port), const char *link);
#define MTS_AP_EEPROM_SIZE (512)
extern uint8_t mts_ap_eeprom[NUM_AP][MTS_AP_EEPROM_SIZE];
#endif /* IO_MODULE_MTAC_H_ */