platform.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. /*
  2. * platform.c - platform 'pseudo' bus for legacy devices
  3. *
  4. * Copyright (c) 2002-3 Patrick Mochel
  5. * Copyright (c) 2002-3 Open Source Development Labs
  6. *
  7. * This file is released under the GPLv2
  8. *
  9. * Please see Documentation/driver-model/platform.txt for more
  10. * information.
  11. */
  12. #include <linux/string.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/of_device.h>
  15. #include <linux/of_irq.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/err.h>
  21. #include <linux/slab.h>
  22. #include <linux/pm_runtime.h>
  23. #include <linux/pm_domain.h>
  24. #include <linux/idr.h>
  25. #include <linux/acpi.h>
  26. #include <linux/clk/clk-conf.h>
  27. #include <linux/limits.h>
  28. #include "base.h"
  29. #include "power/power.h"
  30. /* For automatically allocated device IDs */
  31. static DEFINE_IDA(platform_devid_ida);
  32. struct device platform_bus = {
  33. .init_name = "platform",
  34. };
  35. EXPORT_SYMBOL_GPL(platform_bus);
  36. /**
  37. * arch_setup_pdev_archdata - Allow manipulation of archdata before its used
  38. * @pdev: platform device
  39. *
  40. * This is called before platform_device_add() such that any pdev_archdata may
  41. * be setup before the platform_notifier is called. So if a user needs to
  42. * manipulate any relevant information in the pdev_archdata they can do:
  43. *
  44. * platform_device_alloc()
  45. * ... manipulate ...
  46. * platform_device_add()
  47. *
  48. * And if they don't care they can just call platform_device_register() and
  49. * everything will just work out.
  50. */
  51. void __weak arch_setup_pdev_archdata(struct platform_device *pdev)
  52. {
  53. }
  54. /**
  55. * platform_get_resource - get a resource for a device
  56. * @dev: platform device
  57. * @type: resource type
  58. * @num: resource index
  59. */
  60. struct resource *platform_get_resource(struct platform_device *dev,
  61. unsigned int type, unsigned int num)
  62. {
  63. int i;
  64. for (i = 0; i < dev->num_resources; i++) {
  65. struct resource *r = &dev->resource[i];
  66. if (type == resource_type(r) && num-- == 0)
  67. return r;
  68. }
  69. return NULL;
  70. }
  71. EXPORT_SYMBOL_GPL(platform_get_resource);
  72. /**
  73. * platform_get_irq - get an IRQ for a device
  74. * @dev: platform device
  75. * @num: IRQ number index
  76. */
  77. int platform_get_irq(struct platform_device *dev, unsigned int num)
  78. {
  79. #ifdef CONFIG_SPARC
  80. /* sparc does not have irqs represented as IORESOURCE_IRQ resources */
  81. if (!dev || num >= dev->archdata.num_irqs)
  82. return -ENXIO;
  83. return dev->archdata.irqs[num];
  84. #else
  85. struct resource *r;
  86. if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) {
  87. int ret;
  88. ret = of_irq_get(dev->dev.of_node, num);
  89. if (ret > 0 || ret == -EPROBE_DEFER)
  90. return ret;
  91. }
  92. r = platform_get_resource(dev, IORESOURCE_IRQ, num);
  93. /*
  94. * The resources may pass trigger flags to the irqs that need
  95. * to be set up. It so happens that the trigger flags for
  96. * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER*
  97. * settings.
  98. */
  99. if (r && r->flags & IORESOURCE_BITS)
  100. irqd_set_trigger_type(irq_get_irq_data(r->start),
  101. r->flags & IORESOURCE_BITS);
  102. return r ? r->start : -ENXIO;
  103. #endif
  104. }
  105. EXPORT_SYMBOL_GPL(platform_get_irq);
  106. /**
  107. * platform_get_resource_byname - get a resource for a device by name
  108. * @dev: platform device
  109. * @type: resource type
  110. * @name: resource name
  111. */
  112. struct resource *platform_get_resource_byname(struct platform_device *dev,
  113. unsigned int type,
  114. const char *name)
  115. {
  116. int i;
  117. for (i = 0; i < dev->num_resources; i++) {
  118. struct resource *r = &dev->resource[i];
  119. if (unlikely(!r->name))
  120. continue;
  121. if (type == resource_type(r) && !strcmp(r->name, name))
  122. return r;
  123. }
  124. return NULL;
  125. }
  126. EXPORT_SYMBOL_GPL(platform_get_resource_byname);
  127. /**
  128. * platform_get_irq_byname - get an IRQ for a device by name
  129. * @dev: platform device
  130. * @name: IRQ name
  131. */
  132. int platform_get_irq_byname(struct platform_device *dev, const char *name)
  133. {
  134. struct resource *r;
  135. if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) {
  136. int ret;
  137. ret = of_irq_get_byname(dev->dev.of_node, name);
  138. if (ret > 0 || ret == -EPROBE_DEFER)
  139. return ret;
  140. }
  141. r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
  142. return r ? r->start : -ENXIO;
  143. }
  144. EXPORT_SYMBOL_GPL(platform_get_irq_byname);
  145. /**
  146. * platform_add_devices - add a numbers of platform devices
  147. * @devs: array of platform devices to add
  148. * @num: number of platform devices in array
  149. */
  150. int platform_add_devices(struct platform_device **devs, int num)
  151. {
  152. int i, ret = 0;
  153. for (i = 0; i < num; i++) {
  154. ret = platform_device_register(devs[i]);
  155. if (ret) {
  156. while (--i >= 0)
  157. platform_device_unregister(devs[i]);
  158. break;
  159. }
  160. }
  161. return ret;
  162. }
  163. EXPORT_SYMBOL_GPL(platform_add_devices);
  164. struct platform_object {
  165. struct platform_device pdev;
  166. char name[];
  167. };
  168. /**
  169. * platform_device_put - destroy a platform device
  170. * @pdev: platform device to free
  171. *
  172. * Free all memory associated with a platform device. This function must
  173. * _only_ be externally called in error cases. All other usage is a bug.
  174. */
  175. void platform_device_put(struct platform_device *pdev)
  176. {
  177. if (pdev)
  178. put_device(&pdev->dev);
  179. }
  180. EXPORT_SYMBOL_GPL(platform_device_put);
  181. static void platform_device_release(struct device *dev)
  182. {
  183. struct platform_object *pa = container_of(dev, struct platform_object,
  184. pdev.dev);
  185. of_device_node_put(&pa->pdev.dev);
  186. kfree(pa->pdev.dev.platform_data);
  187. kfree(pa->pdev.mfd_cell);
  188. kfree(pa->pdev.resource);
  189. kfree(pa->pdev.driver_override);
  190. kfree(pa);
  191. }
  192. /**
  193. * platform_device_alloc - create a platform device
  194. * @name: base name of the device we're adding
  195. * @id: instance id
  196. *
  197. * Create a platform device object which can have other objects attached
  198. * to it, and which will have attached objects freed when it is released.
  199. */
  200. struct platform_device *platform_device_alloc(const char *name, int id)
  201. {
  202. struct platform_object *pa;
  203. pa = kzalloc(sizeof(*pa) + strlen(name) + 1, GFP_KERNEL);
  204. if (pa) {
  205. strcpy(pa->name, name);
  206. pa->pdev.name = pa->name;
  207. pa->pdev.id = id;
  208. device_initialize(&pa->pdev.dev);
  209. pa->pdev.dev.release = platform_device_release;
  210. arch_setup_pdev_archdata(&pa->pdev);
  211. }
  212. return pa ? &pa->pdev : NULL;
  213. }
  214. EXPORT_SYMBOL_GPL(platform_device_alloc);
  215. /**
  216. * platform_device_add_resources - add resources to a platform device
  217. * @pdev: platform device allocated by platform_device_alloc to add resources to
  218. * @res: set of resources that needs to be allocated for the device
  219. * @num: number of resources
  220. *
  221. * Add a copy of the resources to the platform device. The memory
  222. * associated with the resources will be freed when the platform device is
  223. * released.
  224. */
  225. int platform_device_add_resources(struct platform_device *pdev,
  226. const struct resource *res, unsigned int num)
  227. {
  228. struct resource *r = NULL;
  229. if (res) {
  230. r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
  231. if (!r)
  232. return -ENOMEM;
  233. }
  234. kfree(pdev->resource);
  235. pdev->resource = r;
  236. pdev->num_resources = num;
  237. return 0;
  238. }
  239. EXPORT_SYMBOL_GPL(platform_device_add_resources);
  240. /**
  241. * platform_device_add_data - add platform-specific data to a platform device
  242. * @pdev: platform device allocated by platform_device_alloc to add resources to
  243. * @data: platform specific data for this platform device
  244. * @size: size of platform specific data
  245. *
  246. * Add a copy of platform specific data to the platform device's
  247. * platform_data pointer. The memory associated with the platform data
  248. * will be freed when the platform device is released.
  249. */
  250. int platform_device_add_data(struct platform_device *pdev, const void *data,
  251. size_t size)
  252. {
  253. void *d = NULL;
  254. if (data) {
  255. d = kmemdup(data, size, GFP_KERNEL);
  256. if (!d)
  257. return -ENOMEM;
  258. }
  259. kfree(pdev->dev.platform_data);
  260. pdev->dev.platform_data = d;
  261. return 0;
  262. }
  263. EXPORT_SYMBOL_GPL(platform_device_add_data);
  264. /**
  265. * platform_device_add - add a platform device to device hierarchy
  266. * @pdev: platform device we're adding
  267. *
  268. * This is part 2 of platform_device_register(), though may be called
  269. * separately _iff_ pdev was allocated by platform_device_alloc().
  270. */
  271. int platform_device_add(struct platform_device *pdev)
  272. {
  273. int i, ret;
  274. if (!pdev)
  275. return -EINVAL;
  276. if (!pdev->dev.parent)
  277. pdev->dev.parent = &platform_bus;
  278. pdev->dev.bus = &platform_bus_type;
  279. switch (pdev->id) {
  280. default:
  281. dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
  282. break;
  283. case PLATFORM_DEVID_NONE:
  284. dev_set_name(&pdev->dev, "%s", pdev->name);
  285. break;
  286. case PLATFORM_DEVID_AUTO:
  287. /*
  288. * Automatically allocated device ID. We mark it as such so
  289. * that we remember it must be freed, and we append a suffix
  290. * to avoid namespace collision with explicit IDs.
  291. */
  292. ret = ida_simple_get(&platform_devid_ida, 0, 0, GFP_KERNEL);
  293. if (ret < 0)
  294. goto err_out;
  295. pdev->id = ret;
  296. pdev->id_auto = true;
  297. dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id);
  298. break;
  299. }
  300. for (i = 0; i < pdev->num_resources; i++) {
  301. struct resource *p, *r = &pdev->resource[i];
  302. if (r->name == NULL)
  303. r->name = dev_name(&pdev->dev);
  304. p = r->parent;
  305. if (!p) {
  306. if (resource_type(r) == IORESOURCE_MEM)
  307. p = &iomem_resource;
  308. else if (resource_type(r) == IORESOURCE_IO)
  309. p = &ioport_resource;
  310. }
  311. if (p && insert_resource(p, r)) {
  312. dev_err(&pdev->dev, "failed to claim resource %d\n", i);
  313. ret = -EBUSY;
  314. goto failed;
  315. }
  316. }
  317. pr_debug("Registering platform device '%s'. Parent at %s\n",
  318. dev_name(&pdev->dev), dev_name(pdev->dev.parent));
  319. ret = device_add(&pdev->dev);
  320. if (ret == 0)
  321. return ret;
  322. failed:
  323. if (pdev->id_auto) {
  324. ida_simple_remove(&platform_devid_ida, pdev->id);
  325. pdev->id = PLATFORM_DEVID_AUTO;
  326. }
  327. while (--i >= 0) {
  328. struct resource *r = &pdev->resource[i];
  329. if (r->parent)
  330. release_resource(r);
  331. }
  332. err_out:
  333. return ret;
  334. }
  335. EXPORT_SYMBOL_GPL(platform_device_add);
  336. /**
  337. * platform_device_del - remove a platform-level device
  338. * @pdev: platform device we're removing
  339. *
  340. * Note that this function will also release all memory- and port-based
  341. * resources owned by the device (@dev->resource). This function must
  342. * _only_ be externally called in error cases. All other usage is a bug.
  343. */
  344. void platform_device_del(struct platform_device *pdev)
  345. {
  346. int i;
  347. if (pdev) {
  348. device_del(&pdev->dev);
  349. if (pdev->id_auto) {
  350. ida_simple_remove(&platform_devid_ida, pdev->id);
  351. pdev->id = PLATFORM_DEVID_AUTO;
  352. }
  353. for (i = 0; i < pdev->num_resources; i++) {
  354. struct resource *r = &pdev->resource[i];
  355. if (r->parent)
  356. release_resource(r);
  357. }
  358. }
  359. }
  360. EXPORT_SYMBOL_GPL(platform_device_del);
  361. /**
  362. * platform_device_register - add a platform-level device
  363. * @pdev: platform device we're adding
  364. */
  365. int platform_device_register(struct platform_device *pdev)
  366. {
  367. device_initialize(&pdev->dev);
  368. arch_setup_pdev_archdata(pdev);
  369. return platform_device_add(pdev);
  370. }
  371. EXPORT_SYMBOL_GPL(platform_device_register);
  372. /**
  373. * platform_device_unregister - unregister a platform-level device
  374. * @pdev: platform device we're unregistering
  375. *
  376. * Unregistration is done in 2 steps. First we release all resources
  377. * and remove it from the subsystem, then we drop reference count by
  378. * calling platform_device_put().
  379. */
  380. void platform_device_unregister(struct platform_device *pdev)
  381. {
  382. platform_device_del(pdev);
  383. platform_device_put(pdev);
  384. }
  385. EXPORT_SYMBOL_GPL(platform_device_unregister);
  386. /**
  387. * platform_device_register_full - add a platform-level device with
  388. * resources and platform-specific data
  389. *
  390. * @pdevinfo: data used to create device
  391. *
  392. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  393. */
  394. struct platform_device *platform_device_register_full(
  395. const struct platform_device_info *pdevinfo)
  396. {
  397. int ret = -ENOMEM;
  398. struct platform_device *pdev;
  399. pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
  400. if (!pdev)
  401. goto err_alloc;
  402. pdev->dev.parent = pdevinfo->parent;
  403. pdev->dev.fwnode = pdevinfo->fwnode;
  404. if (pdevinfo->dma_mask) {
  405. /*
  406. * This memory isn't freed when the device is put,
  407. * I don't have a nice idea for that though. Conceptually
  408. * dma_mask in struct device should not be a pointer.
  409. * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
  410. */
  411. pdev->dev.dma_mask =
  412. kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
  413. if (!pdev->dev.dma_mask)
  414. goto err;
  415. *pdev->dev.dma_mask = pdevinfo->dma_mask;
  416. pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
  417. }
  418. ret = platform_device_add_resources(pdev,
  419. pdevinfo->res, pdevinfo->num_res);
  420. if (ret)
  421. goto err;
  422. ret = platform_device_add_data(pdev,
  423. pdevinfo->data, pdevinfo->size_data);
  424. if (ret)
  425. goto err;
  426. ret = platform_device_add(pdev);
  427. if (ret) {
  428. err:
  429. ACPI_COMPANION_SET(&pdev->dev, NULL);
  430. kfree(pdev->dev.dma_mask);
  431. err_alloc:
  432. platform_device_put(pdev);
  433. return ERR_PTR(ret);
  434. }
  435. return pdev;
  436. }
  437. EXPORT_SYMBOL_GPL(platform_device_register_full);
  438. static int platform_drv_probe(struct device *_dev)
  439. {
  440. struct platform_driver *drv = to_platform_driver(_dev->driver);
  441. struct platform_device *dev = to_platform_device(_dev);
  442. int ret;
  443. ret = of_clk_set_defaults(_dev->of_node, false);
  444. if (ret < 0)
  445. return ret;
  446. ret = dev_pm_domain_attach(_dev, true);
  447. if (ret != -EPROBE_DEFER) {
  448. if (drv->probe) {
  449. ret = drv->probe(dev);
  450. if (ret)
  451. dev_pm_domain_detach(_dev, true);
  452. } else {
  453. /* don't fail if just dev_pm_domain_attach failed */
  454. ret = 0;
  455. }
  456. }
  457. if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
  458. dev_warn(_dev, "probe deferral not supported\n");
  459. ret = -ENXIO;
  460. }
  461. return ret;
  462. }
  463. static int platform_drv_probe_fail(struct device *_dev)
  464. {
  465. return -ENXIO;
  466. }
  467. static int platform_drv_remove(struct device *_dev)
  468. {
  469. struct platform_driver *drv = to_platform_driver(_dev->driver);
  470. struct platform_device *dev = to_platform_device(_dev);
  471. int ret = 0;
  472. if (drv->remove)
  473. ret = drv->remove(dev);
  474. dev_pm_domain_detach(_dev, true);
  475. return ret;
  476. }
  477. static void platform_drv_shutdown(struct device *_dev)
  478. {
  479. struct platform_driver *drv = to_platform_driver(_dev->driver);
  480. struct platform_device *dev = to_platform_device(_dev);
  481. if (drv->shutdown)
  482. drv->shutdown(dev);
  483. dev_pm_domain_detach(_dev, true);
  484. }
  485. /**
  486. * __platform_driver_register - register a driver for platform-level devices
  487. * @drv: platform driver structure
  488. * @owner: owning module/driver
  489. */
  490. int __platform_driver_register(struct platform_driver *drv,
  491. struct module *owner)
  492. {
  493. drv->driver.owner = owner;
  494. drv->driver.bus = &platform_bus_type;
  495. drv->driver.probe = platform_drv_probe;
  496. drv->driver.remove = platform_drv_remove;
  497. drv->driver.shutdown = platform_drv_shutdown;
  498. return driver_register(&drv->driver);
  499. }
  500. EXPORT_SYMBOL_GPL(__platform_driver_register);
  501. /**
  502. * platform_driver_unregister - unregister a driver for platform-level devices
  503. * @drv: platform driver structure
  504. */
  505. void platform_driver_unregister(struct platform_driver *drv)
  506. {
  507. driver_unregister(&drv->driver);
  508. }
  509. EXPORT_SYMBOL_GPL(platform_driver_unregister);
  510. /**
  511. * __platform_driver_probe - register driver for non-hotpluggable device
  512. * @drv: platform driver structure
  513. * @probe: the driver probe routine, probably from an __init section
  514. * @module: module which will be the owner of the driver
  515. *
  516. * Use this instead of platform_driver_register() when you know the device
  517. * is not hotpluggable and has already been registered, and you want to
  518. * remove its run-once probe() infrastructure from memory after the driver
  519. * has bound to the device.
  520. *
  521. * One typical use for this would be with drivers for controllers integrated
  522. * into system-on-chip processors, where the controller devices have been
  523. * configured as part of board setup.
  524. *
  525. * Note that this is incompatible with deferred probing.
  526. *
  527. * Returns zero if the driver registered and bound to a device, else returns
  528. * a negative error code and with the driver not registered.
  529. */
  530. int __init_or_module __platform_driver_probe(struct platform_driver *drv,
  531. int (*probe)(struct platform_device *), struct module *module)
  532. {
  533. int retval, code;
  534. if (drv->driver.probe_type == PROBE_PREFER_ASYNCHRONOUS) {
  535. pr_err("%s: drivers registered with %s can not be probed asynchronously\n",
  536. drv->driver.name, __func__);
  537. return -EINVAL;
  538. }
  539. /*
  540. * We have to run our probes synchronously because we check if
  541. * we find any devices to bind to and exit with error if there
  542. * are any.
  543. */
  544. drv->driver.probe_type = PROBE_FORCE_SYNCHRONOUS;
  545. /*
  546. * Prevent driver from requesting probe deferral to avoid further
  547. * futile probe attempts.
  548. */
  549. drv->prevent_deferred_probe = true;
  550. /* make sure driver won't have bind/unbind attributes */
  551. drv->driver.suppress_bind_attrs = true;
  552. /* temporary section violation during probe() */
  553. drv->probe = probe;
  554. retval = code = __platform_driver_register(drv, module);
  555. /*
  556. * Fixup that section violation, being paranoid about code scanning
  557. * the list of drivers in order to probe new devices. Check to see
  558. * if the probe was successful, and make sure any forced probes of
  559. * new devices fail.
  560. */
  561. spin_lock(&drv->driver.bus->p->klist_drivers.k_lock);
  562. drv->probe = NULL;
  563. if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
  564. retval = -ENODEV;
  565. drv->driver.probe = platform_drv_probe_fail;
  566. spin_unlock(&drv->driver.bus->p->klist_drivers.k_lock);
  567. if (code != retval)
  568. platform_driver_unregister(drv);
  569. return retval;
  570. }
  571. EXPORT_SYMBOL_GPL(__platform_driver_probe);
  572. /**
  573. * __platform_create_bundle - register driver and create corresponding device
  574. * @driver: platform driver structure
  575. * @probe: the driver probe routine, probably from an __init section
  576. * @res: set of resources that needs to be allocated for the device
  577. * @n_res: number of resources
  578. * @data: platform specific data for this platform device
  579. * @size: size of platform specific data
  580. * @module: module which will be the owner of the driver
  581. *
  582. * Use this in legacy-style modules that probe hardware directly and
  583. * register a single platform device and corresponding platform driver.
  584. *
  585. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  586. */
  587. struct platform_device * __init_or_module __platform_create_bundle(
  588. struct platform_driver *driver,
  589. int (*probe)(struct platform_device *),
  590. struct resource *res, unsigned int n_res,
  591. const void *data, size_t size, struct module *module)
  592. {
  593. struct platform_device *pdev;
  594. int error;
  595. pdev = platform_device_alloc(driver->driver.name, -1);
  596. if (!pdev) {
  597. error = -ENOMEM;
  598. goto err_out;
  599. }
  600. error = platform_device_add_resources(pdev, res, n_res);
  601. if (error)
  602. goto err_pdev_put;
  603. error = platform_device_add_data(pdev, data, size);
  604. if (error)
  605. goto err_pdev_put;
  606. error = platform_device_add(pdev);
  607. if (error)
  608. goto err_pdev_put;
  609. error = __platform_driver_probe(driver, probe, module);
  610. if (error)
  611. goto err_pdev_del;
  612. return pdev;
  613. err_pdev_del:
  614. platform_device_del(pdev);
  615. err_pdev_put:
  616. platform_device_put(pdev);
  617. err_out:
  618. return ERR_PTR(error);
  619. }
  620. EXPORT_SYMBOL_GPL(__platform_create_bundle);
  621. /**
  622. * __platform_register_drivers - register an array of platform drivers
  623. * @drivers: an array of drivers to register
  624. * @count: the number of drivers to register
  625. * @owner: module owning the drivers
  626. *
  627. * Registers platform drivers specified by an array. On failure to register a
  628. * driver, all previously registered drivers will be unregistered. Callers of
  629. * this API should use platform_unregister_drivers() to unregister drivers in
  630. * the reverse order.
  631. *
  632. * Returns: 0 on success or a negative error code on failure.
  633. */
  634. int __platform_register_drivers(struct platform_driver * const *drivers,
  635. unsigned int count, struct module *owner)
  636. {
  637. unsigned int i;
  638. int err;
  639. for (i = 0; i < count; i++) {
  640. pr_debug("registering platform driver %ps\n", drivers[i]);
  641. err = __platform_driver_register(drivers[i], owner);
  642. if (err < 0) {
  643. pr_err("failed to register platform driver %ps: %d\n",
  644. drivers[i], err);
  645. goto error;
  646. }
  647. }
  648. return 0;
  649. error:
  650. while (i--) {
  651. pr_debug("unregistering platform driver %ps\n", drivers[i]);
  652. platform_driver_unregister(drivers[i]);
  653. }
  654. return err;
  655. }
  656. EXPORT_SYMBOL_GPL(__platform_register_drivers);
  657. /**
  658. * platform_unregister_drivers - unregister an array of platform drivers
  659. * @drivers: an array of drivers to unregister
  660. * @count: the number of drivers to unregister
  661. *
  662. * Unegisters platform drivers specified by an array. This is typically used
  663. * to complement an earlier call to platform_register_drivers(). Drivers are
  664. * unregistered in the reverse order in which they were registered.
  665. */
  666. void platform_unregister_drivers(struct platform_driver * const *drivers,
  667. unsigned int count)
  668. {
  669. while (count--) {
  670. pr_debug("unregistering platform driver %ps\n", drivers[count]);
  671. platform_driver_unregister(drivers[count]);
  672. }
  673. }
  674. EXPORT_SYMBOL_GPL(platform_unregister_drivers);
  675. /* modalias support enables more hands-off userspace setup:
  676. * (a) environment variable lets new-style hotplug events work once system is
  677. * fully running: "modprobe $MODALIAS"
  678. * (b) sysfs attribute lets new-style coldplug recover from hotplug events
  679. * mishandled before system is fully running: "modprobe $(cat modalias)"
  680. */
  681. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  682. char *buf)
  683. {
  684. struct platform_device *pdev = to_platform_device(dev);
  685. int len;
  686. len = of_device_get_modalias(dev, buf, PAGE_SIZE -1);
  687. if (len != -ENODEV)
  688. return len;
  689. len = acpi_device_modalias(dev, buf, PAGE_SIZE -1);
  690. if (len != -ENODEV)
  691. return len;
  692. len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
  693. return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
  694. }
  695. static DEVICE_ATTR_RO(modalias);
  696. static ssize_t driver_override_store(struct device *dev,
  697. struct device_attribute *attr,
  698. const char *buf, size_t count)
  699. {
  700. struct platform_device *pdev = to_platform_device(dev);
  701. char *driver_override, *old, *cp;
  702. /* We need to keep extra room for a newline */
  703. if (count >= (PAGE_SIZE - 1))
  704. return -EINVAL;
  705. driver_override = kstrndup(buf, count, GFP_KERNEL);
  706. if (!driver_override)
  707. return -ENOMEM;
  708. cp = strchr(driver_override, '\n');
  709. if (cp)
  710. *cp = '\0';
  711. device_lock(dev);
  712. old = pdev->driver_override;
  713. if (strlen(driver_override)) {
  714. pdev->driver_override = driver_override;
  715. } else {
  716. kfree(driver_override);
  717. pdev->driver_override = NULL;
  718. }
  719. device_unlock(dev);
  720. kfree(old);
  721. return count;
  722. }
  723. static ssize_t driver_override_show(struct device *dev,
  724. struct device_attribute *attr, char *buf)
  725. {
  726. struct platform_device *pdev = to_platform_device(dev);
  727. ssize_t len;
  728. device_lock(dev);
  729. len = sprintf(buf, "%s\n", pdev->driver_override);
  730. device_unlock(dev);
  731. return len;
  732. }
  733. static DEVICE_ATTR_RW(driver_override);
  734. static struct attribute *platform_dev_attrs[] = {
  735. &dev_attr_modalias.attr,
  736. &dev_attr_driver_override.attr,
  737. NULL,
  738. };
  739. ATTRIBUTE_GROUPS(platform_dev);
  740. static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
  741. {
  742. struct platform_device *pdev = to_platform_device(dev);
  743. int rc;
  744. /* Some devices have extra OF data and an OF-style MODALIAS */
  745. rc = of_device_uevent_modalias(dev, env);
  746. if (rc != -ENODEV)
  747. return rc;
  748. rc = acpi_device_uevent_modalias(dev, env);
  749. if (rc != -ENODEV)
  750. return rc;
  751. add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
  752. pdev->name);
  753. return 0;
  754. }
  755. static const struct platform_device_id *platform_match_id(
  756. const struct platform_device_id *id,
  757. struct platform_device *pdev)
  758. {
  759. while (id->name[0]) {
  760. if (strcmp(pdev->name, id->name) == 0) {
  761. pdev->id_entry = id;
  762. return id;
  763. }
  764. id++;
  765. }
  766. return NULL;
  767. }
  768. /**
  769. * platform_match - bind platform device to platform driver.
  770. * @dev: device.
  771. * @drv: driver.
  772. *
  773. * Platform device IDs are assumed to be encoded like this:
  774. * "<name><instance>", where <name> is a short description of the type of
  775. * device, like "pci" or "floppy", and <instance> is the enumerated
  776. * instance of the device, like '0' or '42'. Driver IDs are simply
  777. * "<name>". So, extract the <name> from the platform_device structure,
  778. * and compare it against the name of the driver. Return whether they match
  779. * or not.
  780. */
  781. static int platform_match(struct device *dev, struct device_driver *drv)
  782. {
  783. struct platform_device *pdev = to_platform_device(dev);
  784. struct platform_driver *pdrv = to_platform_driver(drv);
  785. /* When driver_override is set, only bind to the matching driver */
  786. if (pdev->driver_override)
  787. return !strcmp(pdev->driver_override, drv->name);
  788. /* Attempt an OF style match first */
  789. if (of_driver_match_device(dev, drv))
  790. return 1;
  791. /* Then try ACPI style match */
  792. if (acpi_driver_match_device(dev, drv))
  793. return 1;
  794. /* Then try to match against the id table */
  795. if (pdrv->id_table)
  796. return platform_match_id(pdrv->id_table, pdev) != NULL;
  797. /* fall-back to driver name match */
  798. return (strcmp(pdev->name, drv->name) == 0);
  799. }
  800. #ifdef CONFIG_PM_SLEEP
  801. static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
  802. {
  803. struct platform_driver *pdrv = to_platform_driver(dev->driver);
  804. struct platform_device *pdev = to_platform_device(dev);
  805. int ret = 0;
  806. if (dev->driver && pdrv->suspend)
  807. ret = pdrv->suspend(pdev, mesg);
  808. return ret;
  809. }
  810. static int platform_legacy_resume(struct device *dev)
  811. {
  812. struct platform_driver *pdrv = to_platform_driver(dev->driver);
  813. struct platform_device *pdev = to_platform_device(dev);
  814. int ret = 0;
  815. if (dev->driver && pdrv->resume)
  816. ret = pdrv->resume(pdev);
  817. return ret;
  818. }
  819. #endif /* CONFIG_PM_SLEEP */
  820. #ifdef CONFIG_SUSPEND
  821. int platform_pm_suspend(struct device *dev)
  822. {
  823. struct device_driver *drv = dev->driver;
  824. int ret = 0;
  825. if (!drv)
  826. return 0;
  827. if (drv->pm) {
  828. if (drv->pm->suspend)
  829. ret = drv->pm->suspend(dev);
  830. } else {
  831. ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
  832. }
  833. return ret;
  834. }
  835. int platform_pm_resume(struct device *dev)
  836. {
  837. struct device_driver *drv = dev->driver;
  838. int ret = 0;
  839. if (!drv)
  840. return 0;
  841. if (drv->pm) {
  842. if (drv->pm->resume)
  843. ret = drv->pm->resume(dev);
  844. } else {
  845. ret = platform_legacy_resume(dev);
  846. }
  847. return ret;
  848. }
  849. #endif /* CONFIG_SUSPEND */
  850. #ifdef CONFIG_HIBERNATE_CALLBACKS
  851. int platform_pm_freeze(struct device *dev)
  852. {
  853. struct device_driver *drv = dev->driver;
  854. int ret = 0;
  855. if (!drv)
  856. return 0;
  857. if (drv->pm) {
  858. if (drv->pm->freeze)
  859. ret = drv->pm->freeze(dev);
  860. } else {
  861. ret = platform_legacy_suspend(dev, PMSG_FREEZE);
  862. }
  863. return ret;
  864. }
  865. int platform_pm_thaw(struct device *dev)
  866. {
  867. struct device_driver *drv = dev->driver;
  868. int ret = 0;
  869. if (!drv)
  870. return 0;
  871. if (drv->pm) {
  872. if (drv->pm->thaw)
  873. ret = drv->pm->thaw(dev);
  874. } else {
  875. ret = platform_legacy_resume(dev);
  876. }
  877. return ret;
  878. }
  879. int platform_pm_poweroff(struct device *dev)
  880. {
  881. struct device_driver *drv = dev->driver;
  882. int ret = 0;
  883. if (!drv)
  884. return 0;
  885. if (drv->pm) {
  886. if (drv->pm->poweroff)
  887. ret = drv->pm->poweroff(dev);
  888. } else {
  889. ret = platform_legacy_suspend(dev, PMSG_HIBERNATE);
  890. }
  891. return ret;
  892. }
  893. int platform_pm_restore(struct device *dev)
  894. {
  895. struct device_driver *drv = dev->driver;
  896. int ret = 0;
  897. if (!drv)
  898. return 0;
  899. if (drv->pm) {
  900. if (drv->pm->restore)
  901. ret = drv->pm->restore(dev);
  902. } else {
  903. ret = platform_legacy_resume(dev);
  904. }
  905. return ret;
  906. }
  907. #endif /* CONFIG_HIBERNATE_CALLBACKS */
  908. static const struct dev_pm_ops platform_dev_pm_ops = {
  909. .runtime_suspend = pm_generic_runtime_suspend,
  910. .runtime_resume = pm_generic_runtime_resume,
  911. USE_PLATFORM_PM_SLEEP_OPS
  912. };
  913. struct bus_type platform_bus_type = {
  914. .name = "platform",
  915. .dev_groups = platform_dev_groups,
  916. .match = platform_match,
  917. .uevent = platform_uevent,
  918. .pm = &platform_dev_pm_ops,
  919. };
  920. EXPORT_SYMBOL_GPL(platform_bus_type);
  921. int __init platform_bus_init(void)
  922. {
  923. int error;
  924. early_platform_cleanup();
  925. error = device_register(&platform_bus);
  926. if (error)
  927. return error;
  928. error = bus_register(&platform_bus_type);
  929. if (error)
  930. device_unregister(&platform_bus);
  931. of_platform_register_reconfig_notifier();
  932. return error;
  933. }
  934. #ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
  935. u64 dma_get_required_mask(struct device *dev)
  936. {
  937. u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
  938. u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
  939. u64 mask;
  940. if (!high_totalram) {
  941. /* convert to mask just covering totalram */
  942. low_totalram = (1 << (fls(low_totalram) - 1));
  943. low_totalram += low_totalram - 1;
  944. mask = low_totalram;
  945. } else {
  946. high_totalram = (1 << (fls(high_totalram) - 1));
  947. high_totalram += high_totalram - 1;
  948. mask = (((u64)high_totalram) << 32) + 0xffffffff;
  949. }
  950. return mask;
  951. }
  952. EXPORT_SYMBOL_GPL(dma_get_required_mask);
  953. #endif
  954. static __initdata LIST_HEAD(early_platform_driver_list);
  955. static __initdata LIST_HEAD(early_platform_device_list);
  956. /**
  957. * early_platform_driver_register - register early platform driver
  958. * @epdrv: early_platform driver structure
  959. * @buf: string passed from early_param()
  960. *
  961. * Helper function for early_platform_init() / early_platform_init_buffer()
  962. */
  963. int __init early_platform_driver_register(struct early_platform_driver *epdrv,
  964. char *buf)
  965. {
  966. char *tmp;
  967. int n;
  968. /* Simply add the driver to the end of the global list.
  969. * Drivers will by default be put on the list in compiled-in order.
  970. */
  971. if (!epdrv->list.next) {
  972. INIT_LIST_HEAD(&epdrv->list);
  973. list_add_tail(&epdrv->list, &early_platform_driver_list);
  974. }
  975. /* If the user has specified device then make sure the driver
  976. * gets prioritized. The driver of the last device specified on
  977. * command line will be put first on the list.
  978. */
  979. n = strlen(epdrv->pdrv->driver.name);
  980. if (buf && !strncmp(buf, epdrv->pdrv->driver.name, n)) {
  981. list_move(&epdrv->list, &early_platform_driver_list);
  982. /* Allow passing parameters after device name */
  983. if (buf[n] == '\0' || buf[n] == ',')
  984. epdrv->requested_id = -1;
  985. else {
  986. epdrv->requested_id = simple_strtoul(&buf[n + 1],
  987. &tmp, 10);
  988. if (buf[n] != '.' || (tmp == &buf[n + 1])) {
  989. epdrv->requested_id = EARLY_PLATFORM_ID_ERROR;
  990. n = 0;
  991. } else
  992. n += strcspn(&buf[n + 1], ",") + 1;
  993. }
  994. if (buf[n] == ',')
  995. n++;
  996. if (epdrv->bufsize) {
  997. memcpy(epdrv->buffer, &buf[n],
  998. min_t(int, epdrv->bufsize, strlen(&buf[n]) + 1));
  999. epdrv->buffer[epdrv->bufsize - 1] = '\0';
  1000. }
  1001. }
  1002. return 0;
  1003. }
  1004. /**
  1005. * early_platform_add_devices - adds a number of early platform devices
  1006. * @devs: array of early platform devices to add
  1007. * @num: number of early platform devices in array
  1008. *
  1009. * Used by early architecture code to register early platform devices and
  1010. * their platform data.
  1011. */
  1012. void __init early_platform_add_devices(struct platform_device **devs, int num)
  1013. {
  1014. struct device *dev;
  1015. int i;
  1016. /* simply add the devices to list */
  1017. for (i = 0; i < num; i++) {
  1018. dev = &devs[i]->dev;
  1019. if (!dev->devres_head.next) {
  1020. pm_runtime_early_init(dev);
  1021. INIT_LIST_HEAD(&dev->devres_head);
  1022. list_add_tail(&dev->devres_head,
  1023. &early_platform_device_list);
  1024. }
  1025. }
  1026. }
  1027. /**
  1028. * early_platform_driver_register_all - register early platform drivers
  1029. * @class_str: string to identify early platform driver class
  1030. *
  1031. * Used by architecture code to register all early platform drivers
  1032. * for a certain class. If omitted then only early platform drivers
  1033. * with matching kernel command line class parameters will be registered.
  1034. */
  1035. void __init early_platform_driver_register_all(char *class_str)
  1036. {
  1037. /* The "class_str" parameter may or may not be present on the kernel
  1038. * command line. If it is present then there may be more than one
  1039. * matching parameter.
  1040. *
  1041. * Since we register our early platform drivers using early_param()
  1042. * we need to make sure that they also get registered in the case
  1043. * when the parameter is missing from the kernel command line.
  1044. *
  1045. * We use parse_early_options() to make sure the early_param() gets
  1046. * called at least once. The early_param() may be called more than
  1047. * once since the name of the preferred device may be specified on
  1048. * the kernel command line. early_platform_driver_register() handles
  1049. * this case for us.
  1050. */
  1051. parse_early_options(class_str);
  1052. }
  1053. /**
  1054. * early_platform_match - find early platform device matching driver
  1055. * @epdrv: early platform driver structure
  1056. * @id: id to match against
  1057. */
  1058. static struct platform_device * __init
  1059. early_platform_match(struct early_platform_driver *epdrv, int id)
  1060. {
  1061. struct platform_device *pd;
  1062. list_for_each_entry(pd, &early_platform_device_list, dev.devres_head)
  1063. if (platform_match(&pd->dev, &epdrv->pdrv->driver))
  1064. if (pd->id == id)
  1065. return pd;
  1066. return NULL;
  1067. }
  1068. /**
  1069. * early_platform_left - check if early platform driver has matching devices
  1070. * @epdrv: early platform driver structure
  1071. * @id: return true if id or above exists
  1072. */
  1073. static int __init early_platform_left(struct early_platform_driver *epdrv,
  1074. int id)
  1075. {
  1076. struct platform_device *pd;
  1077. list_for_each_entry(pd, &early_platform_device_list, dev.devres_head)
  1078. if (platform_match(&pd->dev, &epdrv->pdrv->driver))
  1079. if (pd->id >= id)
  1080. return 1;
  1081. return 0;
  1082. }
  1083. /**
  1084. * early_platform_driver_probe_id - probe drivers matching class_str and id
  1085. * @class_str: string to identify early platform driver class
  1086. * @id: id to match against
  1087. * @nr_probe: number of platform devices to successfully probe before exiting
  1088. */
  1089. static int __init early_platform_driver_probe_id(char *class_str,
  1090. int id,
  1091. int nr_probe)
  1092. {
  1093. struct early_platform_driver *epdrv;
  1094. struct platform_device *match;
  1095. int match_id;
  1096. int n = 0;
  1097. int left = 0;
  1098. list_for_each_entry(epdrv, &early_platform_driver_list, list) {
  1099. /* only use drivers matching our class_str */
  1100. if (strcmp(class_str, epdrv->class_str))
  1101. continue;
  1102. if (id == -2) {
  1103. match_id = epdrv->requested_id;
  1104. left = 1;
  1105. } else {
  1106. match_id = id;
  1107. left += early_platform_left(epdrv, id);
  1108. /* skip requested id */
  1109. switch (epdrv->requested_id) {
  1110. case EARLY_PLATFORM_ID_ERROR:
  1111. case EARLY_PLATFORM_ID_UNSET:
  1112. break;
  1113. default:
  1114. if (epdrv->requested_id == id)
  1115. match_id = EARLY_PLATFORM_ID_UNSET;
  1116. }
  1117. }
  1118. switch (match_id) {
  1119. case EARLY_PLATFORM_ID_ERROR:
  1120. pr_warn("%s: unable to parse %s parameter\n",
  1121. class_str, epdrv->pdrv->driver.name);
  1122. /* fall-through */
  1123. case EARLY_PLATFORM_ID_UNSET:
  1124. match = NULL;
  1125. break;
  1126. default:
  1127. match = early_platform_match(epdrv, match_id);
  1128. }
  1129. if (match) {
  1130. /*
  1131. * Set up a sensible init_name to enable
  1132. * dev_name() and others to be used before the
  1133. * rest of the driver core is initialized.
  1134. */
  1135. if (!match->dev.init_name && slab_is_available()) {
  1136. if (match->id != -1)
  1137. match->dev.init_name =
  1138. kasprintf(GFP_KERNEL, "%s.%d",
  1139. match->name,
  1140. match->id);
  1141. else
  1142. match->dev.init_name =
  1143. kasprintf(GFP_KERNEL, "%s",
  1144. match->name);
  1145. if (!match->dev.init_name)
  1146. return -ENOMEM;
  1147. }
  1148. if (epdrv->pdrv->probe(match))
  1149. pr_warn("%s: unable to probe %s early.\n",
  1150. class_str, match->name);
  1151. else
  1152. n++;
  1153. }
  1154. if (n >= nr_probe)
  1155. break;
  1156. }
  1157. if (left)
  1158. return n;
  1159. else
  1160. return -ENODEV;
  1161. }
  1162. /**
  1163. * early_platform_driver_probe - probe a class of registered drivers
  1164. * @class_str: string to identify early platform driver class
  1165. * @nr_probe: number of platform devices to successfully probe before exiting
  1166. * @user_only: only probe user specified early platform devices
  1167. *
  1168. * Used by architecture code to probe registered early platform drivers
  1169. * within a certain class. For probe to happen a registered early platform
  1170. * device matching a registered early platform driver is needed.
  1171. */
  1172. int __init early_platform_driver_probe(char *class_str,
  1173. int nr_probe,
  1174. int user_only)
  1175. {
  1176. int k, n, i;
  1177. n = 0;
  1178. for (i = -2; n < nr_probe; i++) {
  1179. k = early_platform_driver_probe_id(class_str, i, nr_probe - n);
  1180. if (k < 0)
  1181. break;
  1182. n += k;
  1183. if (user_only)
  1184. break;
  1185. }
  1186. return n;
  1187. }
  1188. /**
  1189. * early_platform_cleanup - clean up early platform code
  1190. */
  1191. void __init early_platform_cleanup(void)
  1192. {
  1193. struct platform_device *pd, *pd2;
  1194. /* clean up the devres list used to chain devices */
  1195. list_for_each_entry_safe(pd, pd2, &early_platform_device_list,
  1196. dev.devres_head) {
  1197. list_del(&pd->dev.devres_head);
  1198. memset(&pd->dev.devres_head, 0, sizeof(pd->dev.devres_head));
  1199. }
  1200. }