]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/omap2_spican.h
Support for asynchronous SPI messages and callbacks
[lincan.git] / lincan / include / omap2_spican.h
1 /* spican.h
2  * Header file for the Linux CAN-bus driver - LinCAN.
3  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5  * email:pisa@cmp.felk.cvut.cz
6  * Adapted for spican by Jan Kriz
7  * email:devel@jojen.net
8  * This software is released under the GPL-License.
9  * Version lincan-0.3.4-r2  14 Sep 2010
10  */
11
12 #define OMAP2_SPICAN_NCHIPS 1 // Since the device is initiated from SPI, it's applies to 1 chip (and 1 irq) at a time
13
14 int spican_request_io(struct candevice_t *candev);
15 int spican_release_io(struct candevice_t *candev);
16 int spican_reset(struct candevice_t *candev); 
17 int spican_init_hw_data(struct candevice_t *candev);
18 int spican_init_chip_data(struct candevice_t *candev, int chipnr);
19 int spican_init_obj_data(struct canchip_t *chip, int objnr);
20 void spican_write_register(unsigned data, can_ioptr_t address);
21 unsigned spican_read_register(can_ioptr_t address);
22 int spican_program_irq(struct candevice_t *candev);
23
24 #define OMAP2_SPICAN_TRIG_IRQ   (1<<0)
25 #define OMAP2_SPICAN_TRIG_GPT   (1<<1)
26 #define OMAP2_SPICAN_TRIG_SYS   (1<<2)
27
28 #define OMAP2_SPICAN_MCP_CLK (20000000)
29 #define OMAP2_SPICAN_BAUDRATE (1000000)
30
31 #define OMAP2_SPICAN_CS_CHANGE (1)
32 #define OMAP2_SPICAN_DELAY_USECS (0)
33 #define OMAP2_SPICAN_SPEED_HZ (10000000)
34
35 #define OMAP2_SPICAN_PRE_ASYNC (256)
36 #define OMAP2_SPICAN_MAX_TRANSFERS (2)
37
38 struct omap2_spican_async_t {
39         void (*complete)(void *arg, uint8_t count);
40         struct can_spi_async_t data[OMAP2_SPICAN_MAX_TRANSFERS];
41         uint8_t count;
42         uint8_t bitmap_bit;
43         struct spi_transfer t[OMAP2_SPICAN_MAX_TRANSFERS];
44         struct spi_message m;
45         uint8_t fasthandler;
46 };
47
48 struct lincan_spican_platform_data {
49         u32 clk; /* Clock frequency of the chip */
50         u32 baudrate; /* Requested can communication speed */
51         u32 speed_hz; /* Speed of SPI communication */
52         const char *chiptype;
53         
54         u16 delay_usecs; /* Time gap between transmissions */
55         u8 cs_change; /* Cycle ~CS between transmissions? */
56 };
57
58 struct omap2_spican_platform_data {
59         /** This part must be kept the same as in struct lincan_spican_platform_data */
60         u32 clk; /* Clock frequency of the chip */
61         u32 baudrate; /* Requested can communication speed */
62         u32 speed_hz; /* Speed of SPI communication */
63         const char *chiptype;
64         
65         u16 delay_usecs; /* Time gap between transmissions */
66         u8 cs_change; /* Cycle ~CS between transmissions? */
67
68         /* Following options are set at runtime */
69         struct spi_device *spi; /* SPI device */
70         u8      trigger;
71         u32 irq;
72 #ifdef CONFIG_OMAP_DM_TIMER     
73         struct omap_dm_timer *timer_ptr; // timer object
74         int32_t timer_irq; // the IRQ # for our gp timer
75 #endif /* CONFIG_OMAP_DM_TIMER */
76         spinlock_t spi_lock;
77         struct omap2_spican_async_t async[OMAP2_SPICAN_PRE_ASYNC];
78         DECLARE_BITMAP(async_req_map, OMAP2_SPICAN_PRE_ASYNC);
79         DECLARE_BITMAP(lo_async_done_map, OMAP2_SPICAN_PRE_ASYNC);
80         struct tasklet_struct lo_async_tasklet;
81         struct work_struct lo_async_workqueue;
82         DECLARE_BITMAP(hi_async_done_map, OMAP2_SPICAN_PRE_ASYNC);
83         struct tasklet_struct hi_async_tasklet;
84 };
85
86 int omap2_spican_init(void);
87 void omap2_spican_exit(void);