Lines Matching refs:pld
25 * Get hardware mutex to block firmware from accessing the pld.
29 static void kempld_get_hardware_mutex(struct kempld_device_data *pld)
32 while (ioread8(pld->io_index) & KEMPLD_MUTEX_KEY)
36 static void kempld_release_hardware_mutex(struct kempld_device_data *pld)
39 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
42 static int kempld_get_info_generic(struct kempld_device_data *pld)
47 kempld_get_mutex(pld);
49 version = kempld_read16(pld, KEMPLD_VERSION);
50 spec = kempld_read8(pld, KEMPLD_SPEC);
51 pld->info.buildnr = kempld_read16(pld, KEMPLD_BUILDNR);
53 pld->info.minor = KEMPLD_VERSION_GET_MINOR(version);
54 pld->info.major = KEMPLD_VERSION_GET_MAJOR(version);
55 pld->info.number = KEMPLD_VERSION_GET_NUMBER(version);
56 pld->info.type = KEMPLD_VERSION_GET_TYPE(version);
59 pld->info.spec_minor = 0;
60 pld->info.spec_major = 1;
62 pld->info.spec_minor = KEMPLD_SPEC_GET_MINOR(spec);
63 pld->info.spec_major = KEMPLD_SPEC_GET_MAJOR(spec);
66 if (pld->info.spec_major > 0)
67 pld->feature_mask = kempld_read16(pld, KEMPLD_FEATURE);
69 pld->feature_mask = 0;
71 kempld_release_mutex(pld);
92 static int kempld_register_cells_generic(struct kempld_device_data *pld)
97 if (pld->feature_mask & KEMPLD_FEATURE_BIT_I2C)
100 if (pld->feature_mask & KEMPLD_FEATURE_BIT_WATCHDOG)
103 if (pld->feature_mask & KEMPLD_FEATURE_BIT_GPIO)
106 if (pld->feature_mask & KEMPLD_FEATURE_MASK_UART)
109 return mfd_add_devices(pld->dev, -1, devs, i, NULL, 0, NULL);
159 * @pld: kempld_device_data structure describing the PLD
164 u8 kempld_read8(struct kempld_device_data *pld, u8 index)
166 iowrite8(index, pld->io_index);
167 return ioread8(pld->io_data);
173 * @pld: kempld_device_data structure describing the PLD
179 void kempld_write8(struct kempld_device_data *pld, u8 index, u8 data)
181 iowrite8(index, pld->io_index);
182 iowrite8(data, pld->io_data);
188 * @pld: kempld_device_data structure describing the PLD
193 u16 kempld_read16(struct kempld_device_data *pld, u8 index)
195 return kempld_read8(pld, index) | kempld_read8(pld, index + 1) << 8;
201 * @pld: kempld_device_data structure describing the PLD
207 void kempld_write16(struct kempld_device_data *pld, u8 index, u16 data)
209 kempld_write8(pld, index, (u8)data);
210 kempld_write8(pld, index + 1, (u8)(data >> 8));
216 * @pld: kempld_device_data structure describing the PLD
221 u32 kempld_read32(struct kempld_device_data *pld, u8 index)
223 return kempld_read16(pld, index) | kempld_read16(pld, index + 2) << 16;
229 * @pld: kempld_device_data structure describing the PLD
235 void kempld_write32(struct kempld_device_data *pld, u8 index, u32 data)
237 kempld_write16(pld, index, (u16)data);
238 kempld_write16(pld, index + 2, (u16)(data >> 16));
244 * @pld: kempld_device_data structure describing the PLD
246 void kempld_get_mutex(struct kempld_device_data *pld)
248 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
250 mutex_lock(&pld->lock);
251 pdata->get_hardware_mutex(pld);
257 * @pld: kempld_device_data structure describing the PLD
259 void kempld_release_mutex(struct kempld_device_data *pld)
261 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
263 pdata->release_hardware_mutex(pld);
264 mutex_unlock(&pld->lock);
270 * @pld: kempld_device_data structure describing the PLD
274 * hardware. The information is then stored within the pld structure.
276 static int kempld_get_info(struct kempld_device_data *pld)
279 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
282 ret = pdata->get_info(pld);
294 if (pld->info.major < 10)
295 major = pld->info.major + '0';
297 major = (pld->info.major - 10) + 'A';
298 if (pld->info.minor < 10)
299 minor = pld->info.minor + '0';
301 minor = (pld->info.minor - 10) + 'A';
303 ret = scnprintf(pld->info.version, sizeof(pld->info.version),
304 "P%X%c%c.%04X", pld->info.number, major, minor,
305 pld->info.buildnr);
319 static int kempld_register_cells(struct kempld_device_data *pld)
321 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
323 return pdata->register_cells(pld);
326 static const char *kempld_get_type_string(struct kempld_device_data *pld)
330 switch (pld->info.type) {
351 struct kempld_device_data *pld = dev_get_drvdata(dev);
353 return scnprintf(buf, PAGE_SIZE, "%s\n", pld->info.version);
359 struct kempld_device_data *pld = dev_get_drvdata(dev);
361 return scnprintf(buf, PAGE_SIZE, "%d.%d\n", pld->info.spec_major,
362 pld->info.spec_minor);
368 struct kempld_device_data *pld = dev_get_drvdata(dev);
370 return scnprintf(buf, PAGE_SIZE, "%s\n", kempld_get_type_string(pld));
389 static int kempld_detect_device(struct kempld_device_data *pld)
394 mutex_lock(&pld->lock);
397 index_reg = ioread8(pld->io_index);
398 if (index_reg == 0xff && ioread8(pld->io_data) == 0xff) {
399 mutex_unlock(&pld->lock);
405 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
407 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
410 mutex_unlock(&pld->lock);
412 ret = kempld_get_info(pld);
416 dev_info(pld->dev, "Found Kontron PLD - %s (%s), spec %d.%d\n",
417 pld->info.version, kempld_get_type_string(pld),
418 pld->info.spec_major, pld->info.spec_minor);
420 ret = sysfs_create_group(&pld->dev->kobj, &pld_attr_group);
424 ret = kempld_register_cells(pld);
426 sysfs_remove_group(&pld->dev->kobj, &pld_attr_group);
492 struct kempld_device_data *pld;
519 pld = devm_kzalloc(dev, sizeof(*pld), GFP_KERNEL);
520 if (!pld)
527 pld->io_base = devm_ioport_map(dev, ioport->start,
529 if (!pld->io_base)
532 pld->io_index = pld->io_base;
533 pld->io_data = pld->io_base + 1;
534 pld->pld_clock = pdata->pld_clock;
535 pld->dev = dev;
537 mutex_init(&pld->lock);
538 platform_set_drvdata(pdev, pld);
540 return kempld_detect_device(pld);
545 struct kempld_device_data *pld = platform_get_drvdata(pdev);
546 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
548 sysfs_remove_group(&pld->dev->kobj, &pld_attr_group);
551 pdata->release_hardware_mutex(pld);