Main Page | Class List | File List | Class Members | File Members

spi.h

Go to the documentation of this file.
00001 /*
00002  *  linux/include/linux/spi/spi.h
00003  *
00004  *  Copyright (C) 2001 Russell King, All Rights Reserved.
00005  *  Copyright (C) 2002 Compaq Computer Corporation, All Rights Reserved.
00006  *  Copyright (C) 2004 Kate Alhola, All Rights Reserved.
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License.
00011  *
00012  * Derived from l3.h by Jamey Hicks
00013  */
00020 #ifndef SPI_H
00021 #define SPI_H
00022 
00028 struct spi_msg {
00029     unsigned char       addr;   
00030     unsigned char       flags;  
00031 #define SPI_M_RD        0x01    
00032 #define SPI_M_WR        0x02    
00033 #define SPI_M_NOADDR    0x04
00034 #define SPI_CS          0x08    
00035         unsigned short  len;    
00036         unsigned char   *buf;   
00037 };
00038 
00039 #ifdef __KERNEL__
00040 
00041 #include <linux/types.h>
00042 #include <linux/list.h>
00043 
00044 
00045 #define SPI_MAJOR 228  /* This will change */
00046 
00047 struct spi_client;
00048 struct spi_adapter;
00049 
00050 struct spi_ops {
00051         int     (*open)(struct spi_client *);
00052         int     (*command)(struct spi_client *, int cmd, void *arg);
00053         void    (*close)(struct spi_client *);
00054 };
00055 
00061 struct spi_driver {
00066     char                        name[32];
00067 
00068         unsigned int flags;             /* div., see below              */
00069 
00076         int                     (*attach_adapter)(struct spi_adapter *);
00077 
00084         void                    (*detach_client)(struct spi_client *);
00085 
00089         int (*command)(struct spi_client *client,unsigned int cmd, void *arg);
00093         struct spi_ops          *ops;
00094 
00098         struct module           *owner;
00099 
00100         /*
00101          * drivers list
00102          */
00103         struct list_head        drivers;
00104 
00114         void (*inc_use)(struct spi_client *client);
00115         void (*dec_use)(struct spi_client *client);
00116 };
00117 
00119 #define SPI_DF_NOTIFY   0x01            /* notify on bus (de/a)ttaches  */
00120 #define SPI_DF_DUMMY    0x02            /* do not connect any clients */
00121 
00122 
00123 struct spi_algorithm {
00124 
00125         char name[32];     
00128         int (*xfer)(struct spi_adapter *, struct spi_msg msgs[], int num);     
00129 };
00130 
00131 struct spi_cs {
00132         char name[32];
00133         int id;
00134 };
00135 
00136 struct semaphore;
00137 
00142 struct spi_adapter {
00147         char                    name[32];
00148 
00152         struct spi_algorithm    *algo;
00153 
00157         void                    *algo_data;
00158 
00163         int (* set_spi_adap_cs)(struct spi_adapter *,int id,int val);
00167         struct spi_cs *cs;
00171         struct module           *owner;
00172 
00176         void                    *data;
00177 
00181         struct semaphore        lock;
00182 
00184         int inode;
00185 
00187         int   id;
00191         struct list_head        clients;
00192 
00196         struct list_head        adapters;
00197 };
00198 
00204 struct spi_client {
00205         char                    name[32];
00206         struct spi_adapter      *adapter;       
00207         struct spi_driver       *driver;        
00208         void                    *driver_data;   
00209         struct list_head        __adap;
00210         int                     addr;           
00211 };
00212 
00213 
00214 extern int spi_add_adapter(struct spi_adapter *);
00215 extern int spi_del_adapter(struct spi_adapter *);
00216 
00217 extern int spi_add_driver(struct spi_driver *);
00218 extern int spi_del_driver(struct spi_driver *);
00219 
00220 extern int spi_attach_client(struct spi_client *, const char *, const char *);
00221 extern int spi_detach_client(struct spi_client *);
00222 
00223 extern int spi_transfer(struct spi_adapter *, struct spi_msg msgs[], int);
00224 extern int spi_write(struct spi_client *, int, const char *, int);
00225 extern int spi_read(struct spi_client *, int, char *, int);
00226 /* This call returns a unique low identifier for each registered adapter,
00227  * or -1 if the adapter was not registered. 
00228  */
00229 extern int spi_adapter_id(struct spi_adapter *adap);
00230 
00242 static inline int spi_command(struct spi_client *clnt, int cmd, void *arg)
00243 {
00244         struct spi_ops *ops = clnt->driver->ops;
00245         int ret = -EINVAL;
00246 
00247         if (ops && ops->command)
00248                 ret = ops->command(clnt, cmd, arg);
00249 
00250         return ret;
00251 }
00252 
00253 static inline int spi_open(struct spi_client *clnt)
00254 {
00255         struct spi_ops *ops = clnt->driver->ops;
00256         int ret = 0;
00257 
00258         if (ops && ops->open)
00259                 ret = ops->open(clnt);
00260         return ret;
00261 }
00262 
00263 static inline void spi_close(struct spi_client *clnt)
00264 {
00265         struct spi_ops *ops = clnt->driver->ops;
00266         if (ops && ops->close)
00267                 ops->close(clnt);
00268 }
00269 #endif
00270 
00273 #define SPI_RDWR        0x6207  
00274 #define SPI_SETADDR     0x6206  
00275 #define SPI_FUNCS       0x6205  
00280 struct spi_rdwr_ioctl_data {
00281         struct spi_msg *msgs;   
00282         unsigned int   nmsgs;   
00283 };
00284 
00285 
00286 #endif /* SPI_H */

Generated on Sun Oct 24 20:23:05 2004 for Linux SPI subsystem by doxygen 1.3.6