Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/fmc: hide fmc operations behind helpers

This gave us more freedom to change/add/remove operations without
recompiling all device driver.

Typically, Carrier board implement the fmc operations, so they will not
use these helpers.

Signed-off-by: Federico Vaga <federico.vaga@cern.ch>
Tested-by: Pat Riehecky <riehecky@fnal.gov>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Federico Vaga and committed by
Greg Kroah-Hartman
9f757f41 8e12381b

+87 -19
+1 -2
drivers/fmc/fmc-chardev.c
··· 129 129 130 130 struct fc_instance *fc; 131 131 132 - if (fmc->op->validate) 133 - index = fmc->op->validate(fmc, &fc_drv); 132 + index = fmc_validate(fmc, &fc_drv); 134 133 if (index < 0) 135 134 return -EINVAL; /* not our device: invalid */ 136 135
+55
drivers/fmc/fmc-core.c
··· 118 118 .write = fmc_write_eeprom, 119 119 }; 120 120 121 + int fmc_irq_request(struct fmc_device *fmc, irq_handler_t h, 122 + char *name, int flags) 123 + { 124 + if (fmc->op->irq_request) 125 + return fmc->op->irq_request(fmc, h, name, flags); 126 + return -EPERM; 127 + } 128 + EXPORT_SYMBOL(fmc_irq_request); 129 + 130 + void fmc_irq_free(struct fmc_device *fmc) 131 + { 132 + if (fmc->op->irq_free) 133 + fmc->op->irq_free(fmc); 134 + } 135 + EXPORT_SYMBOL(fmc_irq_free); 136 + 137 + void fmc_irq_ack(struct fmc_device *fmc) 138 + { 139 + if (likely(fmc->op->irq_ack)) 140 + fmc->op->irq_ack(fmc); 141 + } 142 + EXPORT_SYMBOL(fmc_irq_ack); 143 + 144 + int fmc_validate(struct fmc_device *fmc, struct fmc_driver *drv) 145 + { 146 + if (fmc->op->validate) 147 + return fmc->op->validate(fmc, drv); 148 + return -EPERM; 149 + } 150 + EXPORT_SYMBOL(fmc_validate); 151 + 152 + int fmc_gpio_config(struct fmc_device *fmc, struct fmc_gpio *gpio, int ngpio) 153 + { 154 + if (fmc->op->gpio_config) 155 + return fmc->op->gpio_config(fmc, gpio, ngpio); 156 + return -EPERM; 157 + } 158 + EXPORT_SYMBOL(fmc_gpio_config); 159 + 160 + int fmc_read_ee(struct fmc_device *fmc, int pos, void *d, int l) 161 + { 162 + if (fmc->op->read_ee) 163 + return fmc->op->read_ee(fmc, pos, d, l); 164 + return -EPERM; 165 + } 166 + EXPORT_SYMBOL(fmc_read_ee); 167 + 168 + int fmc_write_ee(struct fmc_device *fmc, int pos, const void *d, int l) 169 + { 170 + if (fmc->op->write_ee) 171 + return fmc->op->write_ee(fmc, pos, d, l); 172 + return -EPERM; 173 + } 174 + EXPORT_SYMBOL(fmc_write_ee); 175 + 121 176 /* 122 177 * Functions for client modules follow 123 178 */
+1 -1
drivers/fmc/fmc-match.c
··· 63 63 if (!fmc->eeprom) 64 64 return -ENOMEM; 65 65 allocated = 1; 66 - ret = fmc->op->read_ee(fmc, 0, fmc->eeprom, fmc->eeprom_len); 66 + ret = fmc_read_ee(fmc, 0, fmc->eeprom, fmc->eeprom_len); 67 67 if (ret < 0) 68 68 goto out; 69 69 }
+8 -12
drivers/fmc/fmc-trivial.c
··· 24 24 { 25 25 struct fmc_device *fmc = dev_id; 26 26 27 - fmc->op->irq_ack(fmc); 27 + fmc_irq_ack(fmc); 28 28 dev_info(&fmc->dev, "received irq %i\n", irq); 29 29 return IRQ_HANDLED; 30 30 } ··· 46 46 int ret; 47 47 int index = 0; 48 48 49 - if (fmc->op->validate) 50 - index = fmc->op->validate(fmc, &t_drv); 49 + index = fmc_validate(fmc, &t_drv); 51 50 if (index < 0) 52 51 return -EINVAL; /* not our device: invalid */ 53 52 54 - ret = fmc->op->irq_request(fmc, t_handler, "fmc-trivial", IRQF_SHARED); 53 + ret = fmc_irq_request(fmc, t_handler, "fmc-trivial", IRQF_SHARED); 55 54 if (ret < 0) 56 55 return ret; 57 56 /* ignore error code of call below, we really don't care */ 58 - fmc->op->gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio)); 57 + fmc_gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio)); 59 58 60 - /* Reprogram, if asked to. ESRCH == no filename specified */ 61 - ret = -ESRCH; 62 - if (fmc->op->reprogram) 63 - ret = fmc->op->reprogram(fmc, &t_drv, ""); 64 - if (ret == -ESRCH) 59 + ret = fmc_reprogram(fmc, &t_drv, "", 0); 60 + if (ret == -EPERM) /* programming not supported */ 65 61 ret = 0; 66 62 if (ret < 0) 67 - fmc->op->irq_free(fmc); 63 + fmc_irq_free(fmc); 68 64 69 65 /* FIXME: reprogram LM32 too */ 70 66 return ret; ··· 68 72 69 73 static int t_remove(struct fmc_device *fmc) 70 74 { 71 - fmc->op->irq_free(fmc); 75 + fmc_irq_free(fmc); 72 76 return 0; 73 77 } 74 78
+4 -4
drivers/fmc/fmc-write-eeprom.c
··· 50 50 if (write) { 51 51 dev_info(&fmc->dev, "write %i bytes at 0x%04x\n", 52 52 thislen, thisaddr); 53 - err = fmc->op->write_ee(fmc, thisaddr, p + 5, thislen); 53 + err = fmc_write_ee(fmc, thisaddr, p + 5, thislen); 54 54 } 55 55 if (err < 0) { 56 56 dev_err(&fmc->dev, "write failure @0x%04x\n", ··· 70 70 int ret; 71 71 72 72 dev_info(&fmc->dev, "programming %zi bytes\n", fw->size); 73 - ret = fmc->op->write_ee(fmc, 0, (void *)fw->data, fw->size); 73 + ret = fmc_write_ee(fmc, 0, (void *)fw->data, fw->size); 74 74 if (ret < 0) { 75 75 dev_info(&fmc->dev, "write_eeprom: error %i\n", ret); 76 76 return ret; ··· 115 115 KBUILD_MODNAME); 116 116 return -ENODEV; 117 117 } 118 - if (fmc->op->validate) 119 - index = fmc->op->validate(fmc, &fwe_drv); 118 + 119 + index = fmc_validate(fmc, &fwe_drv); 120 120 if (index < 0) { 121 121 pr_err("%s: refusing device \"%s\"\n", KBUILD_MODNAME, 122 122 dev_name(dev));
+18
include/linux/fmc.h
··· 234 234 extern void fmc_dump_eeprom(const struct fmc_device *fmc); 235 235 extern void fmc_dump_sdb(const struct fmc_device *fmc); 236 236 237 + /* helpers for FMC operations */ 238 + extern int fmc_irq_request(struct fmc_device *fmc, irq_handler_t h, 239 + char *name, int flags); 240 + extern void fmc_irq_free(struct fmc_device *fmc); 241 + extern void fmc_irq_ack(struct fmc_device *fmc); 242 + extern int fmc_validate(struct fmc_device *fmc, struct fmc_driver *drv); 243 + extern int fmc_gpio_config(struct fmc_device *fmc, struct fmc_gpio *gpio, 244 + int ngpio); 245 + extern int fmc_read_ee(struct fmc_device *fmc, int pos, void *d, int l); 246 + extern int fmc_write_ee(struct fmc_device *fmc, int pos, const void *d, int l); 247 + 248 + /* helpers for FMC operations */ 249 + extern int fmc_irq_request(struct fmc_device *fmc, irq_handler_t h, 250 + char *name, int flags); 251 + extern void fmc_irq_free(struct fmc_device *fmc); 252 + extern void fmc_irq_ack(struct fmc_device *fmc); 253 + extern int fmc_validate(struct fmc_device *fmc, struct fmc_driver *drv); 254 + 237 255 #endif /* __LINUX_FMC_H__ */