1/*
2 *  include/linux/mfd/viperboard.h
3 *
4 *  Nano River Technologies viperboard definitions
5 *
6 *  (C) 2012 by Lemonage GmbH
7 *  Author: Lars Poeschel <poeschel@lemonage.de>
8 *  All rights reserved.
9 *
10 *  This program is free software; you can redistribute  it and/or modify it
11 *  under  the terms of  the GNU General  Public License as published by the
12 *  Free Software Foundation;  either version 2 of the  License, or (at your
13 *  option) any later version.
14 *
15 */
16
17#ifndef __MFD_VIPERBOARD_H__
18#define __MFD_VIPERBOARD_H__
19
20#include <linux/types.h>
21#include <linux/usb.h>
22
23#define VPRBRD_EP_OUT               0x02
24#define VPRBRD_EP_IN                0x86
25
26#define VPRBRD_I2C_MSG_LEN          512 /* max length of a msg on USB level */
27
28#define VPRBRD_I2C_FREQ_6MHZ        1                        /*   6 MBit/s */
29#define VPRBRD_I2C_FREQ_3MHZ        2                        /*   3 MBit/s */
30#define VPRBRD_I2C_FREQ_1MHZ        3                        /*   1 MBit/s */
31#define VPRBRD_I2C_FREQ_FAST        4                        /* 400 kbit/s */
32#define VPRBRD_I2C_FREQ_400KHZ      VPRBRD_I2C_FREQ_FAST
33#define VPRBRD_I2C_FREQ_200KHZ      5                        /* 200 kbit/s */
34#define VPRBRD_I2C_FREQ_STD         6                        /* 100 kbit/s */
35#define VPRBRD_I2C_FREQ_100KHZ      VPRBRD_I2C_FREQ_STD
36#define VPRBRD_I2C_FREQ_10KHZ       7                        /*  10 kbit/s */
37
38#define VPRBRD_I2C_CMD_WRITE        0x00
39#define VPRBRD_I2C_CMD_READ         0x01
40#define VPRBRD_I2C_CMD_ADDR         0x02
41
42#define VPRBRD_USB_TYPE_OUT	    0x40
43#define VPRBRD_USB_TYPE_IN	    0xc0
44#define VPRBRD_USB_TIMEOUT_MS       100
45#define VPRBRD_USB_REQUEST_I2C_FREQ 0xe6
46#define VPRBRD_USB_REQUEST_I2C      0xe9
47#define VPRBRD_USB_REQUEST_MAJOR    0xea
48#define VPRBRD_USB_REQUEST_MINOR    0xeb
49#define VPRBRD_USB_REQUEST_ADC      0xec
50#define VPRBRD_USB_REQUEST_GPIOA    0xed
51#define VPRBRD_USB_REQUEST_GPIOB    0xdd
52
53struct vprbrd_i2c_write_hdr {
54	u8 cmd;
55	u16 addr;
56	u8 len1;
57	u8 len2;
58	u8 last;
59	u8 chan;
60	u16 spi;
61} __packed;
62
63struct vprbrd_i2c_read_hdr {
64	u8 cmd;
65	u16 addr;
66	u8 len0;
67	u8 len1;
68	u8 len2;
69	u8 len3;
70	u8 len4;
71	u8 len5;
72	u16 tf1;                        /* transfer 1 length */
73	u16 tf2;                        /* transfer 2 length */
74} __packed;
75
76struct vprbrd_i2c_status {
77	u8 unknown[11];
78	u8 status;
79} __packed;
80
81struct vprbrd_i2c_write_msg {
82	struct vprbrd_i2c_write_hdr header;
83	u8 data[VPRBRD_I2C_MSG_LEN
84		- sizeof(struct vprbrd_i2c_write_hdr)];
85} __packed;
86
87struct vprbrd_i2c_read_msg {
88	struct vprbrd_i2c_read_hdr header;
89	u8 data[VPRBRD_I2C_MSG_LEN
90		- sizeof(struct vprbrd_i2c_read_hdr)];
91} __packed;
92
93struct vprbrd_i2c_addr_msg {
94	u8 cmd;
95	u8 addr;
96	u8 unknown1;
97	u16 len;
98	u8 unknown2;
99	u8 unknown3;
100} __packed;
101
102/* Structure to hold all device specific stuff */
103struct vprbrd {
104	struct usb_device *usb_dev; /* the usb device for this device */
105	struct mutex lock;
106	u8 buf[sizeof(struct vprbrd_i2c_write_msg)];
107	struct platform_device pdev;
108};
109
110#endif /* __MFD_VIPERBOARD_H__ */
111