| Florian Fainelli | 55e331c | 2009-06-16 15:33:53 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org> | 
|  | 3 | * | 
|  | 4 | * This program is free software; you can redistribute it and/or modify | 
|  | 5 | * it under the terms of the GNU General Public License as published by | 
|  | 6 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 7 | * (at your option) any later version. | 
|  | 8 | * | 
|  | 9 | * This program is distributed in the hope that it will be useful, | 
|  | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 12 | * GNU General Public License for more details. | 
|  | 13 | * | 
|  | 14 | * You should have received a copy of the GNU General Public License | 
|  | 15 | * along with this program; if not, write to the Free Software | 
|  | 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
|  | 17 | */ | 
|  | 18 |  | 
|  | 19 | #ifndef __VLYNQ_H__ | 
|  | 20 | #define __VLYNQ_H__ | 
|  | 21 |  | 
|  | 22 | #include <linux/device.h> | 
|  | 23 | #include <linux/module.h> | 
|  | 24 | #include <linux/types.h> | 
|  | 25 |  | 
|  | 26 | #define VLYNQ_NUM_IRQS 32 | 
|  | 27 |  | 
|  | 28 | struct vlynq_mapping { | 
|  | 29 | u32 size; | 
|  | 30 | u32 offset; | 
|  | 31 | }; | 
|  | 32 |  | 
|  | 33 | enum vlynq_divisor { | 
|  | 34 | vlynq_div_auto = 0, | 
|  | 35 | vlynq_ldiv1, | 
|  | 36 | vlynq_ldiv2, | 
|  | 37 | vlynq_ldiv3, | 
|  | 38 | vlynq_ldiv4, | 
|  | 39 | vlynq_ldiv5, | 
|  | 40 | vlynq_ldiv6, | 
|  | 41 | vlynq_ldiv7, | 
|  | 42 | vlynq_ldiv8, | 
|  | 43 | vlynq_rdiv1, | 
|  | 44 | vlynq_rdiv2, | 
|  | 45 | vlynq_rdiv3, | 
|  | 46 | vlynq_rdiv4, | 
|  | 47 | vlynq_rdiv5, | 
|  | 48 | vlynq_rdiv6, | 
|  | 49 | vlynq_rdiv7, | 
|  | 50 | vlynq_rdiv8, | 
|  | 51 | vlynq_div_external | 
|  | 52 | }; | 
|  | 53 |  | 
|  | 54 | struct vlynq_device_id { | 
|  | 55 | u32 id; | 
|  | 56 | enum vlynq_divisor divisor; | 
|  | 57 | unsigned long driver_data; | 
|  | 58 | }; | 
|  | 59 |  | 
|  | 60 | struct vlynq_regs; | 
|  | 61 | struct vlynq_device { | 
|  | 62 | u32 id, dev_id; | 
|  | 63 | int local_irq; | 
|  | 64 | int remote_irq; | 
|  | 65 | enum vlynq_divisor divisor; | 
|  | 66 | u32 regs_start, regs_end; | 
|  | 67 | u32 mem_start, mem_end; | 
|  | 68 | u32 irq_start, irq_end; | 
|  | 69 | int irq; | 
|  | 70 | int enabled; | 
|  | 71 | struct vlynq_regs *local; | 
|  | 72 | struct vlynq_regs *remote; | 
|  | 73 | struct device dev; | 
|  | 74 | }; | 
|  | 75 |  | 
|  | 76 | struct vlynq_driver { | 
|  | 77 | char *name; | 
|  | 78 | struct vlynq_device_id *id_table; | 
|  | 79 | int (*probe)(struct vlynq_device *dev, struct vlynq_device_id *id); | 
|  | 80 | void (*remove)(struct vlynq_device *dev); | 
|  | 81 | struct device_driver driver; | 
|  | 82 | }; | 
|  | 83 |  | 
|  | 84 | struct plat_vlynq_ops { | 
|  | 85 | int (*on)(struct vlynq_device *dev); | 
|  | 86 | void (*off)(struct vlynq_device *dev); | 
|  | 87 | }; | 
|  | 88 |  | 
|  | 89 | static inline struct vlynq_driver *to_vlynq_driver(struct device_driver *drv) | 
|  | 90 | { | 
|  | 91 | return container_of(drv, struct vlynq_driver, driver); | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | static inline struct vlynq_device *to_vlynq_device(struct device *device) | 
|  | 95 | { | 
|  | 96 | return container_of(device, struct vlynq_device, dev); | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | extern struct bus_type vlynq_bus_type; | 
|  | 100 |  | 
|  | 101 | extern int __vlynq_register_driver(struct vlynq_driver *driver, | 
|  | 102 | struct module *owner); | 
|  | 103 |  | 
|  | 104 | static inline int vlynq_register_driver(struct vlynq_driver *driver) | 
|  | 105 | { | 
|  | 106 | return __vlynq_register_driver(driver, THIS_MODULE); | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | static inline void *vlynq_get_drvdata(struct vlynq_device *dev) | 
|  | 110 | { | 
|  | 111 | return dev_get_drvdata(&dev->dev); | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | static inline void vlynq_set_drvdata(struct vlynq_device *dev, void *data) | 
|  | 115 | { | 
|  | 116 | dev_set_drvdata(&dev->dev, data); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | static inline u32 vlynq_mem_start(struct vlynq_device *dev) | 
|  | 120 | { | 
|  | 121 | return dev->mem_start; | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 | static inline u32 vlynq_mem_end(struct vlynq_device *dev) | 
|  | 125 | { | 
|  | 126 | return dev->mem_end; | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | static inline u32 vlynq_mem_len(struct vlynq_device *dev) | 
|  | 130 | { | 
|  | 131 | return dev->mem_end - dev->mem_start + 1; | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | static inline int vlynq_virq_to_irq(struct vlynq_device *dev, int virq) | 
|  | 135 | { | 
|  | 136 | int irq = dev->irq_start + virq; | 
|  | 137 | if ((irq < dev->irq_start) || (irq > dev->irq_end)) | 
|  | 138 | return -EINVAL; | 
|  | 139 |  | 
|  | 140 | return irq; | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | static inline int vlynq_irq_to_virq(struct vlynq_device *dev, int irq) | 
|  | 144 | { | 
|  | 145 | if ((irq < dev->irq_start) || (irq > dev->irq_end)) | 
|  | 146 | return -EINVAL; | 
|  | 147 |  | 
|  | 148 | return irq - dev->irq_start; | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | extern void vlynq_unregister_driver(struct vlynq_driver *driver); | 
|  | 152 | extern int vlynq_enable_device(struct vlynq_device *dev); | 
|  | 153 | extern void vlynq_disable_device(struct vlynq_device *dev); | 
|  | 154 | extern int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset, | 
|  | 155 | struct vlynq_mapping *mapping); | 
|  | 156 | extern int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset, | 
|  | 157 | struct vlynq_mapping *mapping); | 
|  | 158 | extern int vlynq_set_local_irq(struct vlynq_device *dev, int virq); | 
|  | 159 | extern int vlynq_set_remote_irq(struct vlynq_device *dev, int virq); | 
|  | 160 |  | 
|  | 161 | #endif /* __VLYNQ_H__ */ |