Skip to content

Commit 9f757f4

Browse files
Federico Vagagregkh
authored andcommitted
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 <[email protected]> Tested-by: Pat Riehecky <[email protected]> Acked-by: Alessandro Rubini <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8e12381 commit 9f757f4

File tree

6 files changed

+87
-19
lines changed

6 files changed

+87
-19
lines changed

drivers/fmc/fmc-chardev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ static int fc_probe(struct fmc_device *fmc)
129129

130130
struct fc_instance *fc;
131131

132-
if (fmc->op->validate)
133-
index = fmc->op->validate(fmc, &fc_drv);
132+
index = fmc_validate(fmc, &fc_drv);
134133
if (index < 0)
135134
return -EINVAL; /* not our device: invalid */
136135

drivers/fmc/fmc-core.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,61 @@ static struct bin_attribute fmc_eeprom_attr = {
118118
.write = fmc_write_eeprom,
119119
};
120120

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+
121176
/*
122177
* Functions for client modules follow
123178
*/

drivers/fmc/fmc-match.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int fmc_fill_id_info(struct fmc_device *fmc)
6363
if (!fmc->eeprom)
6464
return -ENOMEM;
6565
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);
6767
if (ret < 0)
6868
goto out;
6969
}

drivers/fmc/fmc-trivial.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static irqreturn_t t_handler(int irq, void *dev_id)
2424
{
2525
struct fmc_device *fmc = dev_id;
2626

27-
fmc->op->irq_ack(fmc);
27+
fmc_irq_ack(fmc);
2828
dev_info(&fmc->dev, "received irq %i\n", irq);
2929
return IRQ_HANDLED;
3030
}
@@ -46,33 +46,29 @@ static int t_probe(struct fmc_device *fmc)
4646
int ret;
4747
int index = 0;
4848

49-
if (fmc->op->validate)
50-
index = fmc->op->validate(fmc, &t_drv);
49+
index = fmc_validate(fmc, &t_drv);
5150
if (index < 0)
5251
return -EINVAL; /* not our device: invalid */
5352

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);
5554
if (ret < 0)
5655
return ret;
5756
/* 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));
5958

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 */
6561
ret = 0;
6662
if (ret < 0)
67-
fmc->op->irq_free(fmc);
63+
fmc_irq_free(fmc);
6864

6965
/* FIXME: reprogram LM32 too */
7066
return ret;
7167
}
7268

7369
static int t_remove(struct fmc_device *fmc)
7470
{
75-
fmc->op->irq_free(fmc);
71+
fmc_irq_free(fmc);
7672
return 0;
7773
}
7874

drivers/fmc/fmc-write-eeprom.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw,
5050
if (write) {
5151
dev_info(&fmc->dev, "write %i bytes at 0x%04x\n",
5252
thislen, thisaddr);
53-
err = fmc->op->write_ee(fmc, thisaddr, p + 5, thislen);
53+
err = fmc_write_ee(fmc, thisaddr, p + 5, thislen);
5454
}
5555
if (err < 0) {
5656
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)
7070
int ret;
7171

7272
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);
7474
if (ret < 0) {
7575
dev_info(&fmc->dev, "write_eeprom: error %i\n", ret);
7676
return ret;
@@ -115,8 +115,8 @@ static int fwe_probe(struct fmc_device *fmc)
115115
KBUILD_MODNAME);
116116
return -ENODEV;
117117
}
118-
if (fmc->op->validate)
119-
index = fmc->op->validate(fmc, &fwe_drv);
118+
119+
index = fmc_validate(fmc, &fwe_drv);
120120
if (index < 0) {
121121
pr_err("%s: refusing device \"%s\"\n", KBUILD_MODNAME,
122122
dev_name(dev));

include/linux/fmc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,22 @@ extern void fmc_free_id_info(struct fmc_device *fmc);
234234
extern void fmc_dump_eeprom(const struct fmc_device *fmc);
235235
extern void fmc_dump_sdb(const struct fmc_device *fmc);
236236

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+
237255
#endif /* __LINUX_FMC_H__ */

0 commit comments

Comments
 (0)