-/* setup.c
- * Linux CAN-bus device driver.
- * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
- * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
- * email:pisa@cmp.felk.cvut.cz
- * This software is released under the GPL-License.
- * Version lincan-0.3 17 Jun 2004
- */
+/**************************************************************************/
+/* File: setup.c - CAN driver and chips setup code */
+/* */
+/* LinCAN - (Not only) Linux CAN bus driver */
+/* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz> */
+/* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz> */
+/* Funded by OCERA and FRESCOR IST projects */
+/* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl> */
+/* */
+/* LinCAN is free software; you can redistribute it and/or modify it */
+/* under terms of the GNU General Public License as published by the */
+/* Free Software Foundation; either version 2, or (at your option) any */
+/* later version. LinCAN is distributed in the hope that it will be */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* General Public License for more details. You should have received a */
+/* copy of the GNU General Public License along with LinCAN; see file */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
+/* Cambridge, MA 02139, USA. */
+/* */
+/* To allow use of LinCAN in the compact embedded systems firmware */
+/* and RT-executives (RTEMS for example), main authors agree with next */
+/* special exception: */
+/* */
+/* Including LinCAN header files in a file, instantiating LinCAN generics */
+/* or templates, or linking other files with LinCAN objects to produce */
+/* an application image/executable, does not by itself cause the */
+/* resulting application image/executable to be covered by */
+/* the GNU General Public License. */
+/* This exception does not however invalidate any other reasons */
+/* why the executable file might be covered by the GNU Public License. */
+/* Publication of enhanced or derived LinCAN files is required although. */
+/**************************************************************************/
#include "./can/can.h"
-#include "./can/can_sysless.h"
+#include "./can/can_sysdep.h"
#include "./can/main.h"
#include "./can/devcommon.h"
#include "./can/setup.h"
int init_hwspecops(struct candevice_t *candev, int *irqnum_p);
int init_device_struct(int card, int *chan_param_idx_p, int *irq_param_idx_p);
-int init_chip_struct(struct candevice_t *candev, int chipnr, int irq, long baudrate);
+int init_chip_struct(struct candevice_t *candev, int chipnr, int irq, long baudrate, long clock);
int init_obj_struct(struct candevice_t *candev, struct canchip_t *hostchip, int objnr);
/**
* This function is prepared to simplify board specific xxx_request_io() function
* for memory mapped devices.
*/
-int can_base_addr_fixup(struct candevice_t *candev, unsigned long new_base)
+int can_base_addr_fixup(struct candevice_t *candev, can_ioptr_t new_base)
{
- unsigned long offs;
+ long offs;
int i, j;
offs=new_base-candev->dev_base_addr;
*
* Return Value: returns negative number in the case of fail
*/
-int init_hw_struct(void)
-{
- int i=0;
- int irq_param_idx=0;
- int chan_param_idx=0;
-
- hardware_p->nr_boards=0;
- while ( (hw[i] != NULL) & (i < MAX_HW_CARDS) ) {
- hardware_p->nr_boards++;
-
- if (init_device_struct(i, &chan_param_idx, &irq_param_idx)) {
- CANMSG("Error initializing candevice_t structures.\n");
- return -ENODEV;
- }
- i++;
- }
-
- return 0;
-}
+// int init_hw_struct(void)
+// {
+// int i=0;
+// int irq_param_idx=0;
+// int chan_param_idx=0;
+//
+// hardware_p->nr_boards=0;
+// while ( (hw[i] != NULL) & (i < MAX_HW_CARDS) ) {
+// hardware_p->nr_boards++;
+//
+// if (init_device_struct(i, &chan_param_idx, &irq_param_idx)) {
+// CANMSG("Error initializing candevice_t structures.\n");
+// return -ENODEV;
+// }
+// i++;
+// }
+//
+// return 0;
+// }
/**
* init_device_struct - initializes single CAN device/board
*
* Return Value: returns negative number in the case of fail
*/
-int init_device_struct(int card, int *chan_param_idx_p, int *irq_param_idx_p)
-{
- struct candevice_t *candev;
- int ret;
- int irqnum;
- int chipnr;
- long bd;
- int irqsig=-1;
-
- candev=(struct candevice_t *)can_checked_malloc(sizeof(struct candevice_t));
- if (candev==NULL)
- return -ENOMEM;
-
- memset(candev, 0, sizeof(struct candevice_t));
-
- hardware_p->candevice[card]=candev;
- candev->candev_idx=card;
-
- candev=candev;
-
- candev->hwname=hw[card];
- candev->io_addr=io[card];
- candev->dev_base_addr=io[card];
-
- candev->hwspecops=(struct hwspecops_t *)can_checked_malloc(sizeof(struct hwspecops_t));
- if (candev->hwspecops==NULL)
- goto error_nomem;
-
- memset(candev->hwspecops, 0, sizeof(struct hwspecops_t));
-
- if (init_hwspecops(candev, &irqnum))
- goto error_nodev;
-
- if (candev->hwspecops->init_hw_data(candev))
- goto error_nodev;
-
- /* Alocate and initialize the chip structures */
- for (chipnr=0; chipnr < candev->nr_all_chips; chipnr++) {
-
- if(chipnr<irqnum)
- irqsig=irq[*irq_param_idx_p+chipnr];
-
- bd=baudrate[*chan_param_idx_p+chipnr];
- if(!bd) bd=baudrate[0];
-
- if ((ret=init_chip_struct(candev, chipnr, irqsig, bd*1000)))
- goto error_chip;
- }
-
-
-
- for (chipnr=0; chipnr < candev->nr_all_chips; chipnr++) {
- int m=minor[*chan_param_idx_p+chipnr];
- struct canchip_t *chip=candev->chip[chipnr];
- int objnr;
-
- register_chip_struct(chip, m);
-
- for (objnr=0; objnr<chip->max_objects; objnr++) {
- register_obj_struct(chip->msgobj[objnr], m);
- if(m>=0) m++;
- }
- }
-
- *irq_param_idx_p += irqnum;
- *chan_param_idx_p += candev->nr_all_chips;
-
- return 0;
-
- error_nodev:
- ret=-ENODEV;
- error_chip:
- candevice_done(candev);
- goto error_both;
-
- error_nomem:
- ret=-ENOMEM;
-
- error_both:
- hardware_p->candevice[card]=NULL;
- can_checked_free(candev);
- return ret;
-
-}
+// int init_device_struct(int card, int *chan_param_idx_p, int *irq_param_idx_p)
+// {
+// struct candevice_t *candev;
+// int ret;
+// int irqnum;
+// int chipnr;
+// long bd;
+// int irqsig=-1;
+//
+// candev=(struct candevice_t *)malloc(sizeof(struct candevice_t));
+// if (candev==NULL)
+// return -ENOMEM;
+//
+// memset(candev, 0, sizeof(struct candevice_t));
+//
+// hardware_p->candevice[card]=candev;
+// candev->candev_idx=card;
+//
+// candev=candev;
+//
+// candev->hwname=hw[card];
+// candev->io_addr=io[card];
+// candev->dev_base_addr=io[card];
+//
+// candev->hwspecops=(struct hwspecops_t *)malloc(sizeof(struct hwspecops_t));
+// if (candev->hwspecops==NULL)
+// goto error_nomem;
+//
+// memset(candev->hwspecops, 0, sizeof(struct hwspecops_t));
+//
+// if (init_hwspecops(candev, &irqnum))
+// goto error_nodev;
+//
+// if (candev->hwspecops->init_hw_data(candev))
+// goto error_nodev;
+//
+// /* Alocate and initialize the chip structures */
+// for (chipnr=0; chipnr < candev->nr_all_chips; chipnr++) {
+//
+// if(chipnr<irqnum)
+// irqsig=irq[*irq_param_idx_p+chipnr];
+//
+// bd=baudrate[*chan_param_idx_p+chipnr];
+// if(!bd) bd=baudrate[0];
+//
+// if ((ret=init_chip_struct(candev, chipnr, irqsig, bd*1000)))
+// goto error_chip;
+// }
+//
+//
+//
+// for (chipnr=0; chipnr < candev->nr_all_chips; chipnr++) {
+// int m=minor[*chan_param_idx_p+chipnr];
+// struct canchip_t *chip=candev->chip[chipnr];
+// int objnr;
+//
+// register_chip_struct(chip, m);
+//
+// for (objnr=0; objnr<chip->max_objects; objnr++) {
+// register_obj_struct(chip->msgobj[objnr], m);
+// if(m>=0) m++;
+// }
+// }
+//
+// *irq_param_idx_p += irqnum;
+// *chan_param_idx_p += candev->nr_all_chips;
+//
+// return 0;
+//
+// error_nodev:
+// ret=-ENODEV;
+// error_chip:
+// candevice_done(candev);
+// goto error_both;
+//
+// error_nomem:
+// ret=-ENOMEM;
+//
+// error_both:
+// hardware_p->candevice[card]=NULL;
+// free(candev);
+// return ret;
+//
+// }
/**
* init_chip_struct - initializes one CAN chip structure
* @chipnr: index of the chip in the corresponding device/board structure
* @irq: chip IRQ number or (-1) if not appropriate
* @baudrate: baudrate in the units of 1Bd
+ * @clock: optional chip base clock frequency in 1Hz step
*
* Chip structure is allocated and chip specific operations are filled by
* call to board specific init_chip_data() which calls chip specific
*
* Return Value: returns negative number in the case of fail
*/
-int init_chip_struct(struct candevice_t *candev, int chipnr, int irq, long baudrate)
+int init_chip_struct(struct candevice_t *candev, int chipnr, int irq, long baudrate, long clock)
{
struct canchip_t *chip;
int objnr;
int ret;
- candev->chip[chipnr]=(struct canchip_t *)can_checked_malloc(sizeof(struct canchip_t));
+ candev->chip[chipnr]=(struct canchip_t *)malloc(sizeof(struct canchip_t));
if ((chip=candev->chip[chipnr])==NULL)
return -ENOMEM;
chip->write_register=candev->hwspecops->write_register;
chip->read_register=candev->hwspecops->read_register;
- chip->chipspecops=can_checked_malloc(sizeof(struct chipspecops_t));
+ chip->chipspecops=malloc(sizeof(struct chipspecops_t));
if (chip->chipspecops==NULL)
return -ENOMEM;
memset(chip->chipspecops,0,sizeof(struct chipspecops_t));
chip->hostdevice=candev;
chip->chip_irq=irq;
chip->baudrate=baudrate;
+ chip->clock=clock;
chip->flags=0x0;
if(candev->hwspecops->init_chip_data(candev,chipnr)<0)
struct msgobj_t *obj;
int ret;
- obj=(struct msgobj_t *)can_checked_malloc(sizeof(struct msgobj_t));
+ obj=(struct msgobj_t *)malloc(sizeof(struct msgobj_t));
hostchip->msgobj[objnr]=obj;
if (obj == NULL)
return -ENOMEM;
atomic_set(&obj->obj_used,0);
INIT_LIST_HEAD(&obj->obj_users);
- init_timer(&obj->tx_timeout);
+// init_timer(&obj->tx_timeout);
- qends = (struct canque_ends_t *)can_checked_malloc(sizeof(struct canque_ends_t));
+ qends = (struct canque_ends_t *)malloc(sizeof(struct canque_ends_t));
if(qends == NULL) return -ENOMEM;
memset(qends, 0, sizeof(struct canque_ends_t));
obj->hostchip=hostchip;
*
* Return Value: returns negative number in the case of fail
*/
-int init_hwspecops(struct candevice_t *candev, int *irqnum_p)
-{
- const struct boardtype_t *brp;
-
- brp = boardtype_find(candev->hwname);
-
- if(!brp) {
- CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",candev->hwname);
- return -EINVAL;
- }
-
- if(irqnum_p)
- *irqnum_p=brp->irqnum;
- brp->board_register(candev->hwspecops);
-
- return 0;
-}
+// int init_hwspecops(struct candevice_t *candev, int *irqnum_p)
+// {
+// const struct boardtype_t *brp;
+//
+// brp = boardtype_find(candev->hwname);
+//
+// if(!brp) {
+// CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",candev->hwname);
+// return -EINVAL;
+// }
+//
+// if(irqnum_p)
+// *irqnum_p=brp->irqnum;
+// brp->board_register(candev->hwspecops);
+//
+// return 0;
+// }