]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/sh7760.c
Actual driver code for directly mapped SJA1000 into PCI mem region 0.
[lincan.git] / lincan / src / sh7760.c
1 /**************************************************************************/
2 /* File: sh7760.c - Renesas SH7760 HCAN2 integrated controller mappings   */
3 /*                                                                        */
4 /* LinCAN - (Not only) Linux CAN bus driver                               */
5 /* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz>   */
6 /* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz>             */
7 /* Copyright (C) 2007-2008 Martin Petera <peterm4@fel.cvut.cz>            */
8 /* Funded by OCERA and FRESCOR IST projects                               */
9 /* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl>      */
10 /*                                                                        */
11 /* LinCAN is free software; you can redistribute it and/or modify it      */
12 /* under terms of the GNU General Public License as published by the      */
13 /* Free Software Foundation; either version 2, or (at your option) any    */
14 /* later version.  LinCAN is distributed in the hope that it will be      */
15 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
16 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
17 /* General Public License for more details. You should have received a    */
18 /* copy of the GNU General Public License along with LinCAN; see file     */
19 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
20 /* Cambridge, MA 02139, USA.                                              */
21 /*                                                                        */
22 /* To allow use of LinCAN in the compact embedded systems firmware        */
23 /* and RT-executives (RTEMS for example), main authors agree with next    */
24 /* special exception:                                                     */
25 /*                                                                        */
26 /* Including LinCAN header files in a file, instantiating LinCAN generics */
27 /* or templates, or linking other files with LinCAN objects to produce    */
28 /* an application image/executable, does not by itself cause the          */
29 /* resulting application image/executable to be covered by                */
30 /* the GNU General Public License.                                        */
31 /* This exception does not however invalidate any other reasons           */
32 /* why the executable file might be covered by the GNU Public License.    */
33 /* Publication of enhanced or derived LinCAN files is required although.  */
34 /**************************************************************************/
35
36 #include "../include/can.h"
37 #include "../include/can_sysdep.h"
38 #include "../include/main.h"
39 #include "../include/sh7760.h"
40 #include "../include/hcan2.h"
41
42 int sh7760_request_io(struct candevice_t *candev)
43 {
44         if (!can_request_io_region(candev->io_addr, candev->nr_all_chips * IO_RANGE, DEVICE_NAME)) {
45                 CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
46                 return -ENODEV;
47         }
48
49         DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + candev->nr_all_chips * IO_RANGE - 1);
50         return 0;
51 }
52
53 int sh7760_release_io(struct candevice_t *candev)
54 {
55         can_release_io_region(candev->io_addr, candev->nr_all_chips * IO_RANGE);
56
57         return 0;
58 }
59
60 int sh7760_reset(struct candevice_t *candev)
61 {
62         int i;
63         DEBUGMSG("Resetting HCAN2 chips ...\n");
64
65         for (i = 0; i < candev->nr_all_chips; i++)
66         {
67             /* !!! Assuming this card has ONLY HCAN2 chips !!! */
68             if (hcan2_reset_chip(candev->chip[i])) return -ENODEV;
69         }
70
71         return 0;
72 }
73
74 int sh7760_init_hw_data(struct candevice_t *candev)
75 {
76         /* candev->res_addr = RESET_ADDR; */
77         candev->nr_82527_chips = NR_82527;
78         candev->nr_sja1000_chips = NR_SJA1000;
79         candev->nr_all_chips = NR_ALL;
80         /* candev->flags |= CANDEV_PROGRAMMABLE_IRQ; */
81
82         return 0;
83 }
84 int sh7760_init_chip_data(struct candevice_t *candev, int chipnr)
85 {
86         hcan2_fill_chipspecops(candev->chip[chipnr]);
87
88         candev->chip[chipnr]->chip_base_addr = can_ioport2ioptr(candev->io_addr) + chipnr * SH7760_CAN_CHIP_OFFSET; /* one chip with 2 interfaces */
89         candev->chip[chipnr]->clock = SH7760_CAN_CLOCK;
90         candev->chip[chipnr]->chip_irq = SH7760_CAN_IRQ + chipnr;
91         candev->chip[chipnr]->hostdevice = candev;
92
93         return 0;
94 }
95
96 int sh7760_init_obj_data(struct canchip_t *chip, int objnr)
97 {
98         chip->msgobj[objnr]->obj_base_addr = (can_ioptr_t) HCAN2_MB0 + HCAN2_MB_OFFSET * objnr;
99
100         return 0;
101 }
102
103 int sh7760_program_irq(struct candevice_t *candev)
104 {
105         /* sh7760 doesn't use programmable interrupt */
106         return 0;
107 }
108
109
110 void sh7760_write_register(unsigned data, can_ioptr_t address)
111 {
112         /* address is an absolute address */
113         writew(data, address);
114 }
115
116 unsigned sh7760_read_register(can_ioptr_t address)
117 {
118         /* address is an absolute address */
119         return readw(address);
120 }
121
122 int sh7760_register(struct hwspecops_t *hwspecops)
123 {
124         hwspecops->request_io = sh7760_request_io;
125         hwspecops->release_io = sh7760_release_io;
126         hwspecops->reset = sh7760_reset;
127         hwspecops->init_hw_data = sh7760_init_hw_data;
128         hwspecops->init_chip_data = sh7760_init_chip_data;
129         hwspecops->init_obj_data = sh7760_init_obj_data;
130         hwspecops->program_irq = sh7760_program_irq;
131         hwspecops->write_register = sh7760_write_register;
132         hwspecops->read_register = sh7760_read_register;
133         return 0;
134 }