diff options
author | Federico Vaga <federico.vaga@cern.ch> | 2017-07-18 02:32:53 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-08-28 10:24:21 -0400 |
commit | 9f757f415210a7c85e2784e4a1733ea78b2e4e88 (patch) | |
tree | c29a08c4ead881258606731c66129aa0d3272771 /drivers/fmc | |
parent | 8e12381bd7637dcf61a0503b566d5d9ab5b5e1b3 (diff) |
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>
Diffstat (limited to 'drivers/fmc')
-rw-r--r-- | drivers/fmc/fmc-chardev.c | 3 | ||||
-rw-r--r-- | drivers/fmc/fmc-core.c | 55 | ||||
-rw-r--r-- | drivers/fmc/fmc-match.c | 2 | ||||
-rw-r--r-- | drivers/fmc/fmc-trivial.c | 20 | ||||
-rw-r--r-- | drivers/fmc/fmc-write-eeprom.c | 8 |
5 files changed, 69 insertions, 19 deletions
diff --git a/drivers/fmc/fmc-chardev.c b/drivers/fmc/fmc-chardev.c index ace6ef24d15e..5ecf4090a610 100644 --- a/drivers/fmc/fmc-chardev.c +++ b/drivers/fmc/fmc-chardev.c | |||
@@ -129,8 +129,7 @@ static int fc_probe(struct fmc_device *fmc) | |||
129 | 129 | ||
130 | struct fc_instance *fc; | 130 | struct fc_instance *fc; |
131 | 131 | ||
132 | if (fmc->op->validate) | 132 | index = fmc_validate(fmc, &fc_drv); |
133 | index = fmc->op->validate(fmc, &fc_drv); | ||
134 | if (index < 0) | 133 | if (index < 0) |
135 | return -EINVAL; /* not our device: invalid */ | 134 | return -EINVAL; /* not our device: invalid */ |
136 | 135 | ||
diff --git a/drivers/fmc/fmc-core.c b/drivers/fmc/fmc-core.c index 353fc546fb08..5263d0607b64 100644 --- a/drivers/fmc/fmc-core.c +++ b/drivers/fmc/fmc-core.c | |||
@@ -118,6 +118,61 @@ static struct bin_attribute fmc_eeprom_attr = { | |||
118 | .write = fmc_write_eeprom, | 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 | * Functions for client modules follow | 177 | * Functions for client modules follow |
123 | */ | 178 | */ |
diff --git a/drivers/fmc/fmc-match.c b/drivers/fmc/fmc-match.c index 104a5efc2207..a0956d1f7550 100644 --- a/drivers/fmc/fmc-match.c +++ b/drivers/fmc/fmc-match.c | |||
@@ -63,7 +63,7 @@ int fmc_fill_id_info(struct fmc_device *fmc) | |||
63 | if (!fmc->eeprom) | 63 | if (!fmc->eeprom) |
64 | return -ENOMEM; | 64 | return -ENOMEM; |
65 | allocated = 1; | 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 | if (ret < 0) | 67 | if (ret < 0) |
68 | goto out; | 68 | goto out; |
69 | } | 69 | } |
diff --git a/drivers/fmc/fmc-trivial.c b/drivers/fmc/fmc-trivial.c index 6c590f54c79d..8defdee3e3a3 100644 --- a/drivers/fmc/fmc-trivial.c +++ b/drivers/fmc/fmc-trivial.c | |||
@@ -24,7 +24,7 @@ static irqreturn_t t_handler(int irq, void *dev_id) | |||
24 | { | 24 | { |
25 | struct fmc_device *fmc = dev_id; | 25 | struct fmc_device *fmc = dev_id; |
26 | 26 | ||
27 | fmc->op->irq_ack(fmc); | 27 | fmc_irq_ack(fmc); |
28 | dev_info(&fmc->dev, "received irq %i\n", irq); | 28 | dev_info(&fmc->dev, "received irq %i\n", irq); |
29 | return IRQ_HANDLED; | 29 | return IRQ_HANDLED; |
30 | } | 30 | } |
@@ -46,25 +46,21 @@ static int t_probe(struct fmc_device *fmc) | |||
46 | int ret; | 46 | int ret; |
47 | int index = 0; | 47 | int index = 0; |
48 | 48 | ||
49 | if (fmc->op->validate) | 49 | index = fmc_validate(fmc, &t_drv); |
50 | index = fmc->op->validate(fmc, &t_drv); | ||
51 | if (index < 0) | 50 | if (index < 0) |
52 | return -EINVAL; /* not our device: invalid */ | 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 | if (ret < 0) | 54 | if (ret < 0) |
56 | return ret; | 55 | return ret; |
57 | /* ignore error code of call below, we really don't care */ | 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 */ | 59 | ret = fmc_reprogram(fmc, &t_drv, "", 0); |
61 | ret = -ESRCH; | 60 | if (ret == -EPERM) /* programming not supported */ |
62 | if (fmc->op->reprogram) | ||
63 | ret = fmc->op->reprogram(fmc, &t_drv, ""); | ||
64 | if (ret == -ESRCH) | ||
65 | ret = 0; | 61 | ret = 0; |
66 | if (ret < 0) | 62 | if (ret < 0) |
67 | fmc->op->irq_free(fmc); | 63 | fmc_irq_free(fmc); |
68 | 64 | ||
69 | /* FIXME: reprogram LM32 too */ | 65 | /* FIXME: reprogram LM32 too */ |
70 | return ret; | 66 | return ret; |
@@ -72,7 +68,7 @@ static int t_probe(struct fmc_device *fmc) | |||
72 | 68 | ||
73 | static int t_remove(struct fmc_device *fmc) | 69 | static int t_remove(struct fmc_device *fmc) |
74 | { | 70 | { |
75 | fmc->op->irq_free(fmc); | 71 | fmc_irq_free(fmc); |
76 | return 0; | 72 | return 0; |
77 | } | 73 | } |
78 | 74 | ||
diff --git a/drivers/fmc/fmc-write-eeprom.c b/drivers/fmc/fmc-write-eeprom.c index 9bb2cbd5c9f2..3eb81bb1f1fc 100644 --- a/drivers/fmc/fmc-write-eeprom.c +++ b/drivers/fmc/fmc-write-eeprom.c | |||
@@ -50,7 +50,7 @@ static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw, | |||
50 | if (write) { | 50 | if (write) { |
51 | dev_info(&fmc->dev, "write %i bytes at 0x%04x\n", | 51 | dev_info(&fmc->dev, "write %i bytes at 0x%04x\n", |
52 | thislen, thisaddr); | 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 | if (err < 0) { | 55 | if (err < 0) { |
56 | dev_err(&fmc->dev, "write failure @0x%04x\n", | 56 | dev_err(&fmc->dev, "write failure @0x%04x\n", |
@@ -70,7 +70,7 @@ static int fwe_run_bin(struct fmc_device *fmc, const struct firmware *fw) | |||
70 | int ret; | 70 | int ret; |
71 | 71 | ||
72 | dev_info(&fmc->dev, "programming %zi bytes\n", fw->size); | 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 | if (ret < 0) { | 74 | if (ret < 0) { |
75 | dev_info(&fmc->dev, "write_eeprom: error %i\n", ret); | 75 | dev_info(&fmc->dev, "write_eeprom: error %i\n", ret); |
76 | return ret; | 76 | return ret; |
@@ -115,8 +115,8 @@ static int fwe_probe(struct fmc_device *fmc) | |||
115 | KBUILD_MODNAME); | 115 | KBUILD_MODNAME); |
116 | return -ENODEV; | 116 | return -ENODEV; |
117 | } | 117 | } |
118 | if (fmc->op->validate) | 118 | |
119 | index = fmc->op->validate(fmc, &fwe_drv); | 119 | index = fmc_validate(fmc, &fwe_drv); |
120 | if (index < 0) { | 120 | if (index < 0) { |
121 | pr_err("%s: refusing device \"%s\"\n", KBUILD_MODNAME, | 121 | pr_err("%s: refusing device \"%s\"\n", KBUILD_MODNAME, |
122 | dev_name(dev)); | 122 | dev_name(dev)); |