Commit e4966784 authored by Federico Vaga's avatar Federico Vaga

sw:drv: find MFD by name and id

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 1063ce13
......@@ -90,33 +90,50 @@ static int __compat_spec_fw_load(struct fpga_manager *mgr, const char *name)
#endif
}
struct mfd_find_data {
const char *name;
int id;
};
static int mfd_find_device_match(struct device *dev, void *data)
{
struct mfd_cell *cell = data;
struct mfd_find_data *d = data;
struct platform_device *pdev = to_platform_device(dev);
return (strncmp(cell->name, mfd_get_cell(pdev)->name,
strnlen(cell->name, 32)) == 0);
if (strncmp(d->name, mfd_get_cell(pdev)->name,
strnlen(d->name, 32)) != 0)
return 0;
if (d->id >= 0 && pdev->id != d->id)
return 0;
return 1;
}
static struct device *mfd_find_device(struct device *parent,
const struct mfd_cell *cell)
static struct platform_device *mfd_find_device(struct device *parent,
const char *name,
int id)
{
return device_find_child(parent, (void *)cell, mfd_find_device_match);
struct mfd_find_data d = {name, id};
struct device *dev;
dev = device_find_child(parent, (void *)&d, mfd_find_device_match);
if (!dev)
return NULL;
return to_platform_device(dev);
}
int compat_spec_fw_load(struct spec_dev *spec, const struct mfd_cell *cell,
const char *name)
int compat_spec_fw_load(struct spec_dev *spec, const char *name)
{
struct fpga_manager *mgr;
struct device *fpga_dev;
struct platform_device *fpga_pdev;
int err;
fpga_dev = mfd_find_device(&spec->dev, cell);
if (!fpga_dev)
fpga_pdev = mfd_find_device(&spec->dev, "gn412x-fcl", -1);
if (!fpga_pdev)
return -ENODEV;
mgr = fpga_mgr_get(fpga_dev);
mgr = fpga_mgr_get(&fpga_pdev->dev);
if (IS_ERR(mgr))
return -ENODEV;
......
......@@ -49,8 +49,7 @@ int compat_spec_fpga_write_complete(struct fpga_manager *mgr,
#endif
int compat_get_fpga_last_word_size(struct fpga_image_info *info,
size_t count);
int compat_spec_fw_load(struct spec_dev *spec, const struct mfd_cell *cell,
const char *name);
int compat_spec_fw_load(struct spec_dev *spec, const char *name);
#if KERNEL_VERSION(3, 11, 0) > LINUX_VERSION_CODE
#define __ATTR_RW(_name) __ATTR(_name, (S_IWUSR | S_IRUGO), \
......
......@@ -129,7 +129,7 @@ int spec_fw_load(struct spec_dev *spec, const char *name)
spec_gpio_fpga_select(spec, SPEC_FPGA_SELECT_GN4124);
err = compat_spec_fw_load(spec, &spec_mfd_devs[SPEC_MFD_GN412X_FCL], name);
err = compat_spec_fw_load(spec, name);
if (err)
goto out;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment