Lines Matching refs:pld
29 static void kempld_get_hardware_mutex(struct kempld_device_data *pld) in kempld_get_hardware_mutex() argument
32 while (ioread8(pld->io_index) & KEMPLD_MUTEX_KEY) in kempld_get_hardware_mutex()
36 static void kempld_release_hardware_mutex(struct kempld_device_data *pld) in kempld_release_hardware_mutex() argument
39 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index); in kempld_release_hardware_mutex()
42 static int kempld_get_info_generic(struct kempld_device_data *pld) in kempld_get_info_generic() argument
47 kempld_get_mutex(pld); in kempld_get_info_generic()
49 version = kempld_read16(pld, KEMPLD_VERSION); in kempld_get_info_generic()
50 spec = kempld_read8(pld, KEMPLD_SPEC); in kempld_get_info_generic()
51 pld->info.buildnr = kempld_read16(pld, KEMPLD_BUILDNR); in kempld_get_info_generic()
53 pld->info.minor = KEMPLD_VERSION_GET_MINOR(version); in kempld_get_info_generic()
54 pld->info.major = KEMPLD_VERSION_GET_MAJOR(version); in kempld_get_info_generic()
55 pld->info.number = KEMPLD_VERSION_GET_NUMBER(version); in kempld_get_info_generic()
56 pld->info.type = KEMPLD_VERSION_GET_TYPE(version); in kempld_get_info_generic()
59 pld->info.spec_minor = 0; in kempld_get_info_generic()
60 pld->info.spec_major = 1; in kempld_get_info_generic()
62 pld->info.spec_minor = KEMPLD_SPEC_GET_MINOR(spec); in kempld_get_info_generic()
63 pld->info.spec_major = KEMPLD_SPEC_GET_MAJOR(spec); in kempld_get_info_generic()
66 if (pld->info.spec_major > 0) in kempld_get_info_generic()
67 pld->feature_mask = kempld_read16(pld, KEMPLD_FEATURE); in kempld_get_info_generic()
69 pld->feature_mask = 0; in kempld_get_info_generic()
71 kempld_release_mutex(pld); in kempld_get_info_generic()
92 static int kempld_register_cells_generic(struct kempld_device_data *pld) in kempld_register_cells_generic() argument
97 if (pld->feature_mask & KEMPLD_FEATURE_BIT_I2C) in kempld_register_cells_generic()
100 if (pld->feature_mask & KEMPLD_FEATURE_BIT_WATCHDOG) in kempld_register_cells_generic()
103 if (pld->feature_mask & KEMPLD_FEATURE_BIT_GPIO) in kempld_register_cells_generic()
106 if (pld->feature_mask & KEMPLD_FEATURE_MASK_UART) in kempld_register_cells_generic()
109 return mfd_add_devices(pld->dev, -1, devs, i, NULL, 0, NULL); in kempld_register_cells_generic()
163 u8 kempld_read8(struct kempld_device_data *pld, u8 index) in kempld_read8() argument
165 iowrite8(index, pld->io_index); in kempld_read8()
166 return ioread8(pld->io_data); in kempld_read8()
178 void kempld_write8(struct kempld_device_data *pld, u8 index, u8 data) in kempld_write8() argument
180 iowrite8(index, pld->io_index); in kempld_write8()
181 iowrite8(data, pld->io_data); in kempld_write8()
192 u16 kempld_read16(struct kempld_device_data *pld, u8 index) in kempld_read16() argument
194 return kempld_read8(pld, index) | kempld_read8(pld, index + 1) << 8; in kempld_read16()
206 void kempld_write16(struct kempld_device_data *pld, u8 index, u16 data) in kempld_write16() argument
208 kempld_write8(pld, index, (u8)data); in kempld_write16()
209 kempld_write8(pld, index + 1, (u8)(data >> 8)); in kempld_write16()
220 u32 kempld_read32(struct kempld_device_data *pld, u8 index) in kempld_read32() argument
222 return kempld_read16(pld, index) | kempld_read16(pld, index + 2) << 16; in kempld_read32()
234 void kempld_write32(struct kempld_device_data *pld, u8 index, u32 data) in kempld_write32() argument
236 kempld_write16(pld, index, (u16)data); in kempld_write32()
237 kempld_write16(pld, index + 2, (u16)(data >> 16)); in kempld_write32()
245 void kempld_get_mutex(struct kempld_device_data *pld) in kempld_get_mutex() argument
247 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev); in kempld_get_mutex()
249 mutex_lock(&pld->lock); in kempld_get_mutex()
250 pdata->get_hardware_mutex(pld); in kempld_get_mutex()
258 void kempld_release_mutex(struct kempld_device_data *pld) in kempld_release_mutex() argument
260 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev); in kempld_release_mutex()
262 pdata->release_hardware_mutex(pld); in kempld_release_mutex()
263 mutex_unlock(&pld->lock); in kempld_release_mutex()
275 static int kempld_get_info(struct kempld_device_data *pld) in kempld_get_info() argument
278 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev); in kempld_get_info()
281 ret = pdata->get_info(pld); in kempld_get_info()
293 if (pld->info.major < 10) in kempld_get_info()
294 major = pld->info.major + '0'; in kempld_get_info()
296 major = (pld->info.major - 10) + 'A'; in kempld_get_info()
297 if (pld->info.minor < 10) in kempld_get_info()
298 minor = pld->info.minor + '0'; in kempld_get_info()
300 minor = (pld->info.minor - 10) + 'A'; in kempld_get_info()
302 ret = scnprintf(pld->info.version, sizeof(pld->info.version), in kempld_get_info()
303 "P%X%c%c.%04X", pld->info.number, major, minor, in kempld_get_info()
304 pld->info.buildnr); in kempld_get_info()
318 static int kempld_register_cells(struct kempld_device_data *pld) in kempld_register_cells() argument
320 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev); in kempld_register_cells()
322 return pdata->register_cells(pld); in kempld_register_cells()
325 static const char *kempld_get_type_string(struct kempld_device_data *pld) in kempld_get_type_string() argument
329 switch (pld->info.type) { in kempld_get_type_string()
350 struct kempld_device_data *pld = dev_get_drvdata(dev); in pld_version_show() local
352 return scnprintf(buf, PAGE_SIZE, "%s\n", pld->info.version); in pld_version_show()
358 struct kempld_device_data *pld = dev_get_drvdata(dev); in pld_specification_show() local
360 return scnprintf(buf, PAGE_SIZE, "%d.%d\n", pld->info.spec_major, in pld_specification_show()
361 pld->info.spec_minor); in pld_specification_show()
367 struct kempld_device_data *pld = dev_get_drvdata(dev); in pld_type_show() local
369 return scnprintf(buf, PAGE_SIZE, "%s\n", kempld_get_type_string(pld)); in pld_type_show()
387 static int kempld_detect_device(struct kempld_device_data *pld) in kempld_detect_device() argument
392 mutex_lock(&pld->lock); in kempld_detect_device()
395 index_reg = ioread8(pld->io_index); in kempld_detect_device()
396 if (index_reg == 0xff && ioread8(pld->io_data) == 0xff) { in kempld_detect_device()
397 mutex_unlock(&pld->lock); in kempld_detect_device()
403 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index); in kempld_detect_device()
405 iowrite8(KEMPLD_MUTEX_KEY, pld->io_index); in kempld_detect_device()
408 mutex_unlock(&pld->lock); in kempld_detect_device()
410 ret = kempld_get_info(pld); in kempld_detect_device()
414 dev_info(pld->dev, "Found Kontron PLD - %s (%s), spec %d.%d\n", in kempld_detect_device()
415 pld->info.version, kempld_get_type_string(pld), in kempld_detect_device()
416 pld->info.spec_major, pld->info.spec_minor); in kempld_detect_device()
418 ret = sysfs_create_group(&pld->dev->kobj, &pld_attr_group); in kempld_detect_device()
422 ret = kempld_register_cells(pld); in kempld_detect_device()
424 sysfs_remove_group(&pld->dev->kobj, &pld_attr_group); in kempld_detect_device()
490 struct kempld_device_data *pld; in kempld_probe() local
515 pld = devm_kzalloc(dev, sizeof(*pld), GFP_KERNEL); in kempld_probe()
516 if (!pld) in kempld_probe()
523 pld->io_base = devm_ioport_map(dev, ioport->start, in kempld_probe()
525 if (!pld->io_base) in kempld_probe()
528 pld->io_index = pld->io_base; in kempld_probe()
529 pld->io_data = pld->io_base + 1; in kempld_probe()
530 pld->pld_clock = pdata->pld_clock; in kempld_probe()
531 pld->dev = dev; in kempld_probe()
533 mutex_init(&pld->lock); in kempld_probe()
534 platform_set_drvdata(pdev, pld); in kempld_probe()
536 return kempld_detect_device(pld); in kempld_probe()
541 struct kempld_device_data *pld = platform_get_drvdata(pdev); in kempld_remove() local
542 const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev); in kempld_remove()
544 sysfs_remove_group(&pld->dev->kobj, &pld_attr_group); in kempld_remove()
547 pdata->release_hardware_mutex(pld); in kempld_remove()