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);
158 * @pld: kempld_device_data structure describing the PLD
163 u8 kempld_read8(struct kempld_device_data *pld, u8 index)
165 iowrite8(index, pld->io_index);
166 return ioread8(pld->io_data);
172 * @pld: kempld_device_data structure describing the PLD
178 void kempld_write8(struct kempld_device_data *pld, u8 index, u8 data)
180 iowrite8(index, pld->io_index);
181 iowrite8(data, pld->io_data);
187 * @pld: kempld_device_data structure describing the PLD
192 u16 kempld_read16(struct kempld_device_data *pld, u8 index)
194 return kempld_read8(pld, index) | kempld_read8(pld, index + 1) << 8;
200 * @pld: kempld_device_data structure describing the PLD
206 void kempld_write16(struct kempld_device_data *pld, u8 index, u16 data)
208 kempld_write8(pld, index, (u8)data);
209 kempld_write8(pld, index + 1, (u8)(data >> 8));
215 * @pld: kempld_device_data structure describing the PLD
220 u32 kempld_read32(struct kempld_device_data *pld, u8 index)
222 return kempld_read16(pld, index) | kempld_read16(pld, index + 2) << 16;
228 * @pld: kempld_device_data structure describing the PLD
234 void kempld_write32(struct kempld_device_data *pld, u8 index, u32 data)
236 kempld_write16(pld, index, (u16)data);
237 kempld_write16(pld, index + 2, (u16)(data >> 16));
243 * @pld: kempld_device_data structure describing the PLD
245 void kempld_get_mutex(struct kempld_device_data *pld)
247 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
249 mutex_lock(&pld->lock);
250 pdata->get_hardware_mutex(pld);
256 * @pld: kempld_device_data structure describing the PLD
258 void kempld_release_mutex(struct kempld_device_data *pld)
260 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
262 pdata->release_hardware_mutex(pld);
263 mutex_unlock(&pld->lock);
269 * @pld: kempld_device_data structure describing the PLD
273 * hardware. The information is then stored within the pld structure.
275 static int kempld_get_info(struct kempld_device_data *pld)
278 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
281 ret = pdata->get_info(pld);
293 if (pld->info.major < 10)
294 major = pld->info.major + '0';
296 major = (pld->info.major - 10) + 'A';
297 if (pld->info.minor < 10)
298 minor = pld->info.minor + '0';
300 minor = (pld->info.minor - 10) + 'A';
302 ret = scnprintf(pld->info.version, sizeof(pld->info.version),
303 "P%X%c%c.%04X", pld->info.number, major, minor,
304 pld->info.buildnr);
318 static int kempld_register_cells(struct kempld_device_data *pld)
320 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
322 return pdata->register_cells(pld);
325 static const char *kempld_get_type_string(struct kempld_device_data *pld)
329 switch (pld->info.type) {
350 struct kempld_device_data *pld = dev_get_drvdata(dev);
352 return sysfs_emit(buf, "%s\n", pld->info.version);
358 struct kempld_device_data *pld = dev_get_drvdata(dev);
360 return sysfs_emit(buf, "%d.%d\n", pld->info.spec_major, pld->info.spec_minor);
366 struct kempld_device_data *pld = dev_get_drvdata(dev);
368 return sysfs_emit(buf, "%s\n", kempld_get_type_string(pld));
386 static int kempld_detect_device(struct kempld_device_data *pld)
391 mutex_lock(&pld->lock);
394 index_reg = ioread8(pld->io_index);
395 if (index_reg == 0xff && ioread8(pld->io_data) == 0xff) {
396 mutex_unlock(&pld->lock);
402 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
404 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
407 mutex_unlock(&pld->lock);
409 ret = kempld_get_info(pld);
413 dev_info(pld->dev, "Found Kontron PLD - %s (%s), spec %d.%d\n",
414 pld->info.version, kempld_get_type_string(pld),
415 pld->info.spec_major, pld->info.spec_minor);
417 ret = sysfs_create_group(&pld->dev->kobj, &pld_attr_group);
421 ret = kempld_register_cells(pld);
423 sysfs_remove_group(&pld->dev->kobj, &pld_attr_group);
452 struct kempld_device_data *pld;
477 pld = devm_kzalloc(dev, sizeof(*pld), GFP_KERNEL);
478 if (!pld)
485 pld->io_base = devm_ioport_map(dev, ioport->start,
487 if (!pld->io_base)
490 pld->io_index = pld->io_base;
491 pld->io_data = pld->io_base + 1;
492 pld->pld_clock = pdata->pld_clock;
493 pld->dev = dev;
495 mutex_init(&pld->lock);
496 platform_set_drvdata(pdev, pld);
498 return kempld_detect_device(pld);
503 struct kempld_device_data *pld = platform_get_drvdata(pdev);
504 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
506 sysfs_remove_group(&pld->dev->kobj, &pld_attr_group);
509 pdata->release_hardware_mutex(pld);