core.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. /*
  2. * nvmem framework core.
  3. *
  4. * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
  5. * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 and
  9. * only version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/device.h>
  17. #include <linux/export.h>
  18. #include <linux/fs.h>
  19. #include <linux/idr.h>
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/nvmem-consumer.h>
  23. #include <linux/nvmem-provider.h>
  24. #include <linux/of.h>
  25. #include <linux/slab.h>
  26. struct nvmem_device {
  27. const char *name;
  28. struct module *owner;
  29. struct device dev;
  30. int stride;
  31. int word_size;
  32. int id;
  33. int users;
  34. size_t size;
  35. bool read_only;
  36. int flags;
  37. struct bin_attribute eeprom;
  38. struct device *base_dev;
  39. nvmem_reg_read_t reg_read;
  40. nvmem_reg_write_t reg_write;
  41. void *priv;
  42. };
  43. #define FLAG_COMPAT BIT(0)
  44. struct nvmem_cell {
  45. const char *name;
  46. int offset;
  47. int bytes;
  48. int bit_offset;
  49. int nbits;
  50. struct nvmem_device *nvmem;
  51. struct list_head node;
  52. };
  53. static DEFINE_MUTEX(nvmem_mutex);
  54. static DEFINE_IDA(nvmem_ida);
  55. static LIST_HEAD(nvmem_cells);
  56. static DEFINE_MUTEX(nvmem_cells_mutex);
  57. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  58. static struct lock_class_key eeprom_lock_key;
  59. #endif
  60. #define to_nvmem_device(d) container_of(d, struct nvmem_device, dev)
  61. static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
  62. void *val, size_t bytes)
  63. {
  64. if (nvmem->reg_read)
  65. return nvmem->reg_read(nvmem->priv, offset, val, bytes);
  66. return -EINVAL;
  67. }
  68. static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
  69. void *val, size_t bytes)
  70. {
  71. if (nvmem->reg_write)
  72. return nvmem->reg_write(nvmem->priv, offset, val, bytes);
  73. return -EINVAL;
  74. }
  75. static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
  76. struct bin_attribute *attr,
  77. char *buf, loff_t pos, size_t count)
  78. {
  79. struct device *dev;
  80. struct nvmem_device *nvmem;
  81. int rc;
  82. if (attr->private)
  83. dev = attr->private;
  84. else
  85. dev = container_of(kobj, struct device, kobj);
  86. nvmem = to_nvmem_device(dev);
  87. /* Stop the user from reading */
  88. if (pos >= nvmem->size)
  89. return 0;
  90. if (count < nvmem->word_size)
  91. return -EINVAL;
  92. if (pos + count > nvmem->size)
  93. count = nvmem->size - pos;
  94. count = round_down(count, nvmem->word_size);
  95. rc = nvmem_reg_read(nvmem, pos, buf, count);
  96. if (rc)
  97. return rc;
  98. return count;
  99. }
  100. static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
  101. struct bin_attribute *attr,
  102. char *buf, loff_t pos, size_t count)
  103. {
  104. struct device *dev;
  105. struct nvmem_device *nvmem;
  106. int rc;
  107. if (attr->private)
  108. dev = attr->private;
  109. else
  110. dev = container_of(kobj, struct device, kobj);
  111. nvmem = to_nvmem_device(dev);
  112. /* Stop the user from writing */
  113. if (pos >= nvmem->size)
  114. return -EFBIG;
  115. if (count < nvmem->word_size)
  116. return -EINVAL;
  117. if (pos + count > nvmem->size)
  118. count = nvmem->size - pos;
  119. count = round_down(count, nvmem->word_size);
  120. rc = nvmem_reg_write(nvmem, pos, buf, count);
  121. if (rc)
  122. return rc;
  123. return count;
  124. }
  125. /* default read/write permissions */
  126. static struct bin_attribute bin_attr_rw_nvmem = {
  127. .attr = {
  128. .name = "nvmem",
  129. .mode = S_IWUSR | S_IRUGO,
  130. },
  131. .read = bin_attr_nvmem_read,
  132. .write = bin_attr_nvmem_write,
  133. };
  134. static struct bin_attribute *nvmem_bin_rw_attributes[] = {
  135. &bin_attr_rw_nvmem,
  136. NULL,
  137. };
  138. static const struct attribute_group nvmem_bin_rw_group = {
  139. .bin_attrs = nvmem_bin_rw_attributes,
  140. };
  141. static const struct attribute_group *nvmem_rw_dev_groups[] = {
  142. &nvmem_bin_rw_group,
  143. NULL,
  144. };
  145. /* read only permission */
  146. static struct bin_attribute bin_attr_ro_nvmem = {
  147. .attr = {
  148. .name = "nvmem",
  149. .mode = S_IRUGO,
  150. },
  151. .read = bin_attr_nvmem_read,
  152. };
  153. static struct bin_attribute *nvmem_bin_ro_attributes[] = {
  154. &bin_attr_ro_nvmem,
  155. NULL,
  156. };
  157. static const struct attribute_group nvmem_bin_ro_group = {
  158. .bin_attrs = nvmem_bin_ro_attributes,
  159. };
  160. static const struct attribute_group *nvmem_ro_dev_groups[] = {
  161. &nvmem_bin_ro_group,
  162. NULL,
  163. };
  164. /* default read/write permissions, root only */
  165. static struct bin_attribute bin_attr_rw_root_nvmem = {
  166. .attr = {
  167. .name = "nvmem",
  168. .mode = S_IWUSR | S_IRUSR,
  169. },
  170. .read = bin_attr_nvmem_read,
  171. .write = bin_attr_nvmem_write,
  172. };
  173. static struct bin_attribute *nvmem_bin_rw_root_attributes[] = {
  174. &bin_attr_rw_root_nvmem,
  175. NULL,
  176. };
  177. static const struct attribute_group nvmem_bin_rw_root_group = {
  178. .bin_attrs = nvmem_bin_rw_root_attributes,
  179. };
  180. static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
  181. &nvmem_bin_rw_root_group,
  182. NULL,
  183. };
  184. /* read only permission, root only */
  185. static struct bin_attribute bin_attr_ro_root_nvmem = {
  186. .attr = {
  187. .name = "nvmem",
  188. .mode = S_IRUSR,
  189. },
  190. .read = bin_attr_nvmem_read,
  191. };
  192. static struct bin_attribute *nvmem_bin_ro_root_attributes[] = {
  193. &bin_attr_ro_root_nvmem,
  194. NULL,
  195. };
  196. static const struct attribute_group nvmem_bin_ro_root_group = {
  197. .bin_attrs = nvmem_bin_ro_root_attributes,
  198. };
  199. static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
  200. &nvmem_bin_ro_root_group,
  201. NULL,
  202. };
  203. static void nvmem_release(struct device *dev)
  204. {
  205. struct nvmem_device *nvmem = to_nvmem_device(dev);
  206. ida_simple_remove(&nvmem_ida, nvmem->id);
  207. kfree(nvmem);
  208. }
  209. static const struct device_type nvmem_provider_type = {
  210. .release = nvmem_release,
  211. };
  212. static struct bus_type nvmem_bus_type = {
  213. .name = "nvmem",
  214. };
  215. static int of_nvmem_match(struct device *dev, void *nvmem_np)
  216. {
  217. return dev->of_node == nvmem_np;
  218. }
  219. static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
  220. {
  221. struct device *d;
  222. if (!nvmem_np)
  223. return NULL;
  224. d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
  225. if (!d)
  226. return NULL;
  227. return to_nvmem_device(d);
  228. }
  229. static struct nvmem_cell *nvmem_find_cell(const char *cell_id)
  230. {
  231. struct nvmem_cell *p;
  232. mutex_lock(&nvmem_cells_mutex);
  233. list_for_each_entry(p, &nvmem_cells, node)
  234. if (!strcmp(p->name, cell_id)) {
  235. mutex_unlock(&nvmem_cells_mutex);
  236. return p;
  237. }
  238. mutex_unlock(&nvmem_cells_mutex);
  239. return NULL;
  240. }
  241. static void nvmem_cell_drop(struct nvmem_cell *cell)
  242. {
  243. mutex_lock(&nvmem_cells_mutex);
  244. list_del(&cell->node);
  245. mutex_unlock(&nvmem_cells_mutex);
  246. kfree(cell);
  247. }
  248. static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem)
  249. {
  250. struct nvmem_cell *cell;
  251. struct list_head *p, *n;
  252. list_for_each_safe(p, n, &nvmem_cells) {
  253. cell = list_entry(p, struct nvmem_cell, node);
  254. if (cell->nvmem == nvmem)
  255. nvmem_cell_drop(cell);
  256. }
  257. }
  258. static void nvmem_cell_add(struct nvmem_cell *cell)
  259. {
  260. mutex_lock(&nvmem_cells_mutex);
  261. list_add_tail(&cell->node, &nvmem_cells);
  262. mutex_unlock(&nvmem_cells_mutex);
  263. }
  264. static int nvmem_cell_info_to_nvmem_cell(struct nvmem_device *nvmem,
  265. const struct nvmem_cell_info *info,
  266. struct nvmem_cell *cell)
  267. {
  268. cell->nvmem = nvmem;
  269. cell->offset = info->offset;
  270. cell->bytes = info->bytes;
  271. cell->name = info->name;
  272. cell->bit_offset = info->bit_offset;
  273. cell->nbits = info->nbits;
  274. if (cell->nbits)
  275. cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
  276. BITS_PER_BYTE);
  277. if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
  278. dev_err(&nvmem->dev,
  279. "cell %s unaligned to nvmem stride %d\n",
  280. cell->name, nvmem->stride);
  281. return -EINVAL;
  282. }
  283. return 0;
  284. }
  285. /**
  286. * nvmem_add_cells() - Add cell information to an nvmem device
  287. *
  288. * @nvmem: nvmem device to add cells to.
  289. * @info: nvmem cell info to add to the device
  290. * @ncells: number of cells in info
  291. *
  292. * Return: 0 or negative error code on failure.
  293. */
  294. int nvmem_add_cells(struct nvmem_device *nvmem,
  295. const struct nvmem_cell_info *info,
  296. int ncells)
  297. {
  298. struct nvmem_cell **cells;
  299. int i, rval;
  300. cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
  301. if (!cells)
  302. return -ENOMEM;
  303. for (i = 0; i < ncells; i++) {
  304. cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
  305. if (!cells[i]) {
  306. rval = -ENOMEM;
  307. goto err;
  308. }
  309. rval = nvmem_cell_info_to_nvmem_cell(nvmem, &info[i], cells[i]);
  310. if (rval) {
  311. kfree(cells[i]);
  312. goto err;
  313. }
  314. nvmem_cell_add(cells[i]);
  315. }
  316. /* remove tmp array */
  317. kfree(cells);
  318. return 0;
  319. err:
  320. while (i--)
  321. nvmem_cell_drop(cells[i]);
  322. kfree(cells);
  323. return rval;
  324. }
  325. EXPORT_SYMBOL_GPL(nvmem_add_cells);
  326. /*
  327. * nvmem_setup_compat() - Create an additional binary entry in
  328. * drivers sys directory, to be backwards compatible with the older
  329. * drivers/misc/eeprom drivers.
  330. */
  331. static int nvmem_setup_compat(struct nvmem_device *nvmem,
  332. const struct nvmem_config *config)
  333. {
  334. int rval;
  335. if (!config->base_dev)
  336. return -EINVAL;
  337. if (nvmem->read_only) {
  338. if (config->root_only)
  339. nvmem->eeprom = bin_attr_ro_root_nvmem;
  340. else
  341. nvmem->eeprom = bin_attr_ro_nvmem;
  342. } else {
  343. if (config->root_only)
  344. nvmem->eeprom = bin_attr_rw_root_nvmem;
  345. else
  346. nvmem->eeprom = bin_attr_rw_nvmem;
  347. }
  348. nvmem->eeprom.attr.name = "eeprom";
  349. nvmem->eeprom.size = nvmem->size;
  350. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  351. nvmem->eeprom.attr.key = &eeprom_lock_key;
  352. #endif
  353. nvmem->eeprom.private = &nvmem->dev;
  354. nvmem->base_dev = config->base_dev;
  355. rval = device_create_bin_file(nvmem->base_dev, &nvmem->eeprom);
  356. if (rval) {
  357. dev_err(&nvmem->dev,
  358. "Failed to create eeprom binary file %d\n", rval);
  359. return rval;
  360. }
  361. nvmem->flags |= FLAG_COMPAT;
  362. return 0;
  363. }
  364. /**
  365. * nvmem_register() - Register a nvmem device for given nvmem_config.
  366. * Also creates an binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
  367. *
  368. * @config: nvmem device configuration with which nvmem device is created.
  369. *
  370. * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
  371. * on success.
  372. */
  373. struct nvmem_device *nvmem_register(const struct nvmem_config *config)
  374. {
  375. struct nvmem_device *nvmem;
  376. int rval;
  377. if (!config->dev)
  378. return ERR_PTR(-EINVAL);
  379. nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL);
  380. if (!nvmem)
  381. return ERR_PTR(-ENOMEM);
  382. rval = ida_simple_get(&nvmem_ida, 0, 0, GFP_KERNEL);
  383. if (rval < 0) {
  384. kfree(nvmem);
  385. return ERR_PTR(rval);
  386. }
  387. nvmem->id = rval;
  388. nvmem->owner = config->owner;
  389. if (!nvmem->owner && config->dev->driver)
  390. nvmem->owner = config->dev->driver->owner;
  391. nvmem->stride = config->stride ?: 1;
  392. nvmem->word_size = config->word_size ?: 1;
  393. nvmem->size = config->size;
  394. nvmem->dev.type = &nvmem_provider_type;
  395. nvmem->dev.bus = &nvmem_bus_type;
  396. nvmem->dev.parent = config->dev;
  397. nvmem->priv = config->priv;
  398. nvmem->reg_read = config->reg_read;
  399. nvmem->reg_write = config->reg_write;
  400. nvmem->dev.of_node = config->dev->of_node;
  401. if (config->id == -1 && config->name) {
  402. dev_set_name(&nvmem->dev, "%s", config->name);
  403. } else {
  404. dev_set_name(&nvmem->dev, "%s%d",
  405. config->name ? : "nvmem",
  406. config->name ? config->id : nvmem->id);
  407. }
  408. nvmem->read_only = device_property_present(config->dev, "read-only") |
  409. config->read_only;
  410. if (config->root_only)
  411. nvmem->dev.groups = nvmem->read_only ?
  412. nvmem_ro_root_dev_groups :
  413. nvmem_rw_root_dev_groups;
  414. else
  415. nvmem->dev.groups = nvmem->read_only ?
  416. nvmem_ro_dev_groups :
  417. nvmem_rw_dev_groups;
  418. device_initialize(&nvmem->dev);
  419. dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
  420. rval = device_add(&nvmem->dev);
  421. if (rval)
  422. goto err_put_device;
  423. if (config->compat) {
  424. rval = nvmem_setup_compat(nvmem, config);
  425. if (rval)
  426. goto err_device_del;
  427. }
  428. if (config->cells) {
  429. rval = nvmem_add_cells(nvmem, config->cells, config->ncells);
  430. if (rval)
  431. goto err_teardown_compat;
  432. }
  433. return nvmem;
  434. err_teardown_compat:
  435. if (config->compat)
  436. device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
  437. err_device_del:
  438. device_del(&nvmem->dev);
  439. err_put_device:
  440. put_device(&nvmem->dev);
  441. return ERR_PTR(rval);
  442. }
  443. EXPORT_SYMBOL_GPL(nvmem_register);
  444. /**
  445. * nvmem_unregister() - Unregister previously registered nvmem device
  446. *
  447. * @nvmem: Pointer to previously registered nvmem device.
  448. *
  449. * Return: Will be an negative on error or a zero on success.
  450. */
  451. int nvmem_unregister(struct nvmem_device *nvmem)
  452. {
  453. mutex_lock(&nvmem_mutex);
  454. if (nvmem->users) {
  455. mutex_unlock(&nvmem_mutex);
  456. return -EBUSY;
  457. }
  458. mutex_unlock(&nvmem_mutex);
  459. if (nvmem->flags & FLAG_COMPAT)
  460. device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
  461. nvmem_device_remove_all_cells(nvmem);
  462. device_del(&nvmem->dev);
  463. put_device(&nvmem->dev);
  464. return 0;
  465. }
  466. EXPORT_SYMBOL_GPL(nvmem_unregister);
  467. static void devm_nvmem_release(struct device *dev, void *res)
  468. {
  469. WARN_ON(nvmem_unregister(*(struct nvmem_device **)res));
  470. }
  471. /**
  472. * devm_nvmem_register() - Register a managed nvmem device for given
  473. * nvmem_config.
  474. * Also creates an binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
  475. *
  476. * @dev: Device that uses the nvmem device.
  477. * @config: nvmem device configuration with which nvmem device is created.
  478. *
  479. * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
  480. * on success.
  481. */
  482. struct nvmem_device *devm_nvmem_register(struct device *dev,
  483. const struct nvmem_config *config)
  484. {
  485. struct nvmem_device **ptr, *nvmem;
  486. ptr = devres_alloc(devm_nvmem_release, sizeof(*ptr), GFP_KERNEL);
  487. if (!ptr)
  488. return ERR_PTR(-ENOMEM);
  489. nvmem = nvmem_register(config);
  490. if (!IS_ERR(nvmem)) {
  491. *ptr = nvmem;
  492. devres_add(dev, ptr);
  493. } else {
  494. devres_free(ptr);
  495. }
  496. return nvmem;
  497. }
  498. EXPORT_SYMBOL_GPL(devm_nvmem_register);
  499. static int devm_nvmem_match(struct device *dev, void *res, void *data)
  500. {
  501. struct nvmem_device **r = res;
  502. return *r == data;
  503. }
  504. /**
  505. * devm_nvmem_unregister() - Unregister previously registered managed nvmem
  506. * device.
  507. *
  508. * @dev: Device that uses the nvmem device.
  509. * @nvmem: Pointer to previously registered nvmem device.
  510. *
  511. * Return: Will be an negative on error or a zero on success.
  512. */
  513. int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
  514. {
  515. return devres_release(dev, devm_nvmem_release, devm_nvmem_match, nvmem);
  516. }
  517. EXPORT_SYMBOL(devm_nvmem_unregister);
  518. static struct nvmem_device *__nvmem_device_get(struct device_node *np,
  519. struct nvmem_cell **cellp,
  520. const char *cell_id)
  521. {
  522. struct nvmem_device *nvmem = NULL;
  523. mutex_lock(&nvmem_mutex);
  524. if (np) {
  525. nvmem = of_nvmem_find(np);
  526. if (!nvmem) {
  527. mutex_unlock(&nvmem_mutex);
  528. return ERR_PTR(-EPROBE_DEFER);
  529. }
  530. } else {
  531. struct nvmem_cell *cell = nvmem_find_cell(cell_id);
  532. if (cell) {
  533. nvmem = cell->nvmem;
  534. *cellp = cell;
  535. }
  536. if (!nvmem) {
  537. mutex_unlock(&nvmem_mutex);
  538. return ERR_PTR(-ENOENT);
  539. }
  540. }
  541. nvmem->users++;
  542. mutex_unlock(&nvmem_mutex);
  543. if (!try_module_get(nvmem->owner)) {
  544. dev_err(&nvmem->dev,
  545. "could not increase module refcount for cell %s\n",
  546. nvmem->name);
  547. mutex_lock(&nvmem_mutex);
  548. nvmem->users--;
  549. mutex_unlock(&nvmem_mutex);
  550. return ERR_PTR(-EINVAL);
  551. }
  552. return nvmem;
  553. }
  554. static void __nvmem_device_put(struct nvmem_device *nvmem)
  555. {
  556. module_put(nvmem->owner);
  557. mutex_lock(&nvmem_mutex);
  558. nvmem->users--;
  559. mutex_unlock(&nvmem_mutex);
  560. }
  561. static struct nvmem_device *nvmem_find(const char *name)
  562. {
  563. struct device *d;
  564. d = bus_find_device_by_name(&nvmem_bus_type, NULL, name);
  565. if (!d)
  566. return ERR_PTR(-ENOENT);
  567. return to_nvmem_device(d);
  568. }
  569. #if IS_ENABLED(CONFIG_OF)
  570. /**
  571. * of_nvmem_device_get() - Get nvmem device from a given id
  572. *
  573. * @np: Device tree node that uses the nvmem device.
  574. * @id: nvmem name from nvmem-names property.
  575. *
  576. * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
  577. * on success.
  578. */
  579. struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
  580. {
  581. struct device_node *nvmem_np;
  582. int index;
  583. index = of_property_match_string(np, "nvmem-names", id);
  584. nvmem_np = of_parse_phandle(np, "nvmem", index);
  585. if (!nvmem_np)
  586. return ERR_PTR(-EINVAL);
  587. return __nvmem_device_get(nvmem_np, NULL, NULL);
  588. }
  589. EXPORT_SYMBOL_GPL(of_nvmem_device_get);
  590. #endif
  591. /**
  592. * nvmem_device_get() - Get nvmem device from a given id
  593. *
  594. * @dev: Device that uses the nvmem device.
  595. * @dev_name: name of the requested nvmem device.
  596. *
  597. * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
  598. * on success.
  599. */
  600. struct nvmem_device *nvmem_device_get(struct device *dev, const char *dev_name)
  601. {
  602. if (dev->of_node) { /* try dt first */
  603. struct nvmem_device *nvmem;
  604. nvmem = of_nvmem_device_get(dev->of_node, dev_name);
  605. if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER)
  606. return nvmem;
  607. }
  608. return nvmem_find(dev_name);
  609. }
  610. EXPORT_SYMBOL_GPL(nvmem_device_get);
  611. static int devm_nvmem_device_match(struct device *dev, void *res, void *data)
  612. {
  613. struct nvmem_device **nvmem = res;
  614. if (WARN_ON(!nvmem || !*nvmem))
  615. return 0;
  616. return *nvmem == data;
  617. }
  618. static void devm_nvmem_device_release(struct device *dev, void *res)
  619. {
  620. nvmem_device_put(*(struct nvmem_device **)res);
  621. }
  622. /**
  623. * devm_nvmem_device_put() - put alredy got nvmem device
  624. *
  625. * @dev: Device that uses the nvmem device.
  626. * @nvmem: pointer to nvmem device allocated by devm_nvmem_cell_get(),
  627. * that needs to be released.
  628. */
  629. void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem)
  630. {
  631. int ret;
  632. ret = devres_release(dev, devm_nvmem_device_release,
  633. devm_nvmem_device_match, nvmem);
  634. WARN_ON(ret);
  635. }
  636. EXPORT_SYMBOL_GPL(devm_nvmem_device_put);
  637. /**
  638. * nvmem_device_put() - put alredy got nvmem device
  639. *
  640. * @nvmem: pointer to nvmem device that needs to be released.
  641. */
  642. void nvmem_device_put(struct nvmem_device *nvmem)
  643. {
  644. __nvmem_device_put(nvmem);
  645. }
  646. EXPORT_SYMBOL_GPL(nvmem_device_put);
  647. /**
  648. * devm_nvmem_device_get() - Get nvmem cell of device form a given id
  649. *
  650. * @dev: Device that requests the nvmem device.
  651. * @id: name id for the requested nvmem device.
  652. *
  653. * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_cell
  654. * on success. The nvmem_cell will be freed by the automatically once the
  655. * device is freed.
  656. */
  657. struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
  658. {
  659. struct nvmem_device **ptr, *nvmem;
  660. ptr = devres_alloc(devm_nvmem_device_release, sizeof(*ptr), GFP_KERNEL);
  661. if (!ptr)
  662. return ERR_PTR(-ENOMEM);
  663. nvmem = nvmem_device_get(dev, id);
  664. if (!IS_ERR(nvmem)) {
  665. *ptr = nvmem;
  666. devres_add(dev, ptr);
  667. } else {
  668. devres_free(ptr);
  669. }
  670. return nvmem;
  671. }
  672. EXPORT_SYMBOL_GPL(devm_nvmem_device_get);
  673. static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id)
  674. {
  675. struct nvmem_cell *cell = NULL;
  676. struct nvmem_device *nvmem;
  677. nvmem = __nvmem_device_get(NULL, &cell, cell_id);
  678. if (IS_ERR(nvmem))
  679. return ERR_CAST(nvmem);
  680. return cell;
  681. }
  682. #if IS_ENABLED(CONFIG_OF)
  683. /**
  684. * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
  685. *
  686. * @np: Device tree node that uses the nvmem cell.
  687. * @name: nvmem cell name from nvmem-cell-names property, or NULL
  688. * for the cell at index 0 (the lone cell with no accompanying
  689. * nvmem-cell-names property).
  690. *
  691. * Return: Will be an ERR_PTR() on error or a valid pointer
  692. * to a struct nvmem_cell. The nvmem_cell will be freed by the
  693. * nvmem_cell_put().
  694. */
  695. struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
  696. const char *name)
  697. {
  698. struct device_node *cell_np, *nvmem_np;
  699. struct nvmem_cell *cell;
  700. struct nvmem_device *nvmem;
  701. const __be32 *addr;
  702. int rval, len;
  703. int index = 0;
  704. /* if cell name exists, find index to the name */
  705. if (name)
  706. index = of_property_match_string(np, "nvmem-cell-names", name);
  707. cell_np = of_parse_phandle(np, "nvmem-cells", index);
  708. if (!cell_np)
  709. return ERR_PTR(-EINVAL);
  710. nvmem_np = of_get_next_parent(cell_np);
  711. if (!nvmem_np)
  712. return ERR_PTR(-EINVAL);
  713. nvmem = __nvmem_device_get(nvmem_np, NULL, NULL);
  714. of_node_put(nvmem_np);
  715. if (IS_ERR(nvmem))
  716. return ERR_CAST(nvmem);
  717. addr = of_get_property(cell_np, "reg", &len);
  718. if (!addr || (len < 2 * sizeof(u32))) {
  719. dev_err(&nvmem->dev, "nvmem: invalid reg on %pOF\n",
  720. cell_np);
  721. rval = -EINVAL;
  722. goto err_mem;
  723. }
  724. cell = kzalloc(sizeof(*cell), GFP_KERNEL);
  725. if (!cell) {
  726. rval = -ENOMEM;
  727. goto err_mem;
  728. }
  729. cell->nvmem = nvmem;
  730. cell->offset = be32_to_cpup(addr++);
  731. cell->bytes = be32_to_cpup(addr);
  732. cell->name = cell_np->name;
  733. addr = of_get_property(cell_np, "bits", &len);
  734. if (addr && len == (2 * sizeof(u32))) {
  735. cell->bit_offset = be32_to_cpup(addr++);
  736. cell->nbits = be32_to_cpup(addr);
  737. }
  738. if (cell->nbits)
  739. cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
  740. BITS_PER_BYTE);
  741. if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
  742. dev_err(&nvmem->dev,
  743. "cell %s unaligned to nvmem stride %d\n",
  744. cell->name, nvmem->stride);
  745. rval = -EINVAL;
  746. goto err_sanity;
  747. }
  748. nvmem_cell_add(cell);
  749. return cell;
  750. err_sanity:
  751. kfree(cell);
  752. err_mem:
  753. __nvmem_device_put(nvmem);
  754. return ERR_PTR(rval);
  755. }
  756. EXPORT_SYMBOL_GPL(of_nvmem_cell_get);
  757. #endif
  758. /**
  759. * nvmem_cell_get() - Get nvmem cell of device form a given cell name
  760. *
  761. * @dev: Device that requests the nvmem cell.
  762. * @cell_id: nvmem cell name to get.
  763. *
  764. * Return: Will be an ERR_PTR() on error or a valid pointer
  765. * to a struct nvmem_cell. The nvmem_cell will be freed by the
  766. * nvmem_cell_put().
  767. */
  768. struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *cell_id)
  769. {
  770. struct nvmem_cell *cell;
  771. if (dev->of_node) { /* try dt first */
  772. cell = of_nvmem_cell_get(dev->of_node, cell_id);
  773. if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER)
  774. return cell;
  775. }
  776. /* NULL cell_id only allowed for device tree; invalid otherwise */
  777. if (!cell_id)
  778. return ERR_PTR(-EINVAL);
  779. return nvmem_cell_get_from_list(cell_id);
  780. }
  781. EXPORT_SYMBOL_GPL(nvmem_cell_get);
  782. static void devm_nvmem_cell_release(struct device *dev, void *res)
  783. {
  784. nvmem_cell_put(*(struct nvmem_cell **)res);
  785. }
  786. /**
  787. * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
  788. *
  789. * @dev: Device that requests the nvmem cell.
  790. * @id: nvmem cell name id to get.
  791. *
  792. * Return: Will be an ERR_PTR() on error or a valid pointer
  793. * to a struct nvmem_cell. The nvmem_cell will be freed by the
  794. * automatically once the device is freed.
  795. */
  796. struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id)
  797. {
  798. struct nvmem_cell **ptr, *cell;
  799. ptr = devres_alloc(devm_nvmem_cell_release, sizeof(*ptr), GFP_KERNEL);
  800. if (!ptr)
  801. return ERR_PTR(-ENOMEM);
  802. cell = nvmem_cell_get(dev, id);
  803. if (!IS_ERR(cell)) {
  804. *ptr = cell;
  805. devres_add(dev, ptr);
  806. } else {
  807. devres_free(ptr);
  808. }
  809. return cell;
  810. }
  811. EXPORT_SYMBOL_GPL(devm_nvmem_cell_get);
  812. static int devm_nvmem_cell_match(struct device *dev, void *res, void *data)
  813. {
  814. struct nvmem_cell **c = res;
  815. if (WARN_ON(!c || !*c))
  816. return 0;
  817. return *c == data;
  818. }
  819. /**
  820. * devm_nvmem_cell_put() - Release previously allocated nvmem cell
  821. * from devm_nvmem_cell_get.
  822. *
  823. * @dev: Device that requests the nvmem cell.
  824. * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
  825. */
  826. void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell)
  827. {
  828. int ret;
  829. ret = devres_release(dev, devm_nvmem_cell_release,
  830. devm_nvmem_cell_match, cell);
  831. WARN_ON(ret);
  832. }
  833. EXPORT_SYMBOL(devm_nvmem_cell_put);
  834. /**
  835. * nvmem_cell_put() - Release previously allocated nvmem cell.
  836. *
  837. * @cell: Previously allocated nvmem cell by nvmem_cell_get().
  838. */
  839. void nvmem_cell_put(struct nvmem_cell *cell)
  840. {
  841. struct nvmem_device *nvmem = cell->nvmem;
  842. __nvmem_device_put(nvmem);
  843. nvmem_cell_drop(cell);
  844. }
  845. EXPORT_SYMBOL_GPL(nvmem_cell_put);
  846. static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf)
  847. {
  848. u8 *p, *b;
  849. int i, extra, bit_offset = cell->bit_offset;
  850. p = b = buf;
  851. if (bit_offset) {
  852. /* First shift */
  853. *b++ >>= bit_offset;
  854. /* setup rest of the bytes if any */
  855. for (i = 1; i < cell->bytes; i++) {
  856. /* Get bits from next byte and shift them towards msb */
  857. *p |= *b << (BITS_PER_BYTE - bit_offset);
  858. p = b;
  859. *b++ >>= bit_offset;
  860. }
  861. } else {
  862. /* point to the msb */
  863. p += cell->bytes - 1;
  864. }
  865. /* result fits in less bytes */
  866. extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
  867. while (--extra >= 0)
  868. *p-- = 0;
  869. /* clear msb bits if any leftover in the last byte */
  870. *p &= GENMASK((cell->nbits%BITS_PER_BYTE) - 1, 0);
  871. }
  872. static int __nvmem_cell_read(struct nvmem_device *nvmem,
  873. struct nvmem_cell *cell,
  874. void *buf, size_t *len)
  875. {
  876. int rc;
  877. rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes);
  878. if (rc)
  879. return rc;
  880. /* shift bits in-place */
  881. if (cell->bit_offset || cell->nbits)
  882. nvmem_shift_read_buffer_in_place(cell, buf);
  883. if (len)
  884. *len = cell->bytes;
  885. return 0;
  886. }
  887. /**
  888. * nvmem_cell_read() - Read a given nvmem cell
  889. *
  890. * @cell: nvmem cell to be read.
  891. * @len: pointer to length of cell which will be populated on successful read;
  892. * can be NULL.
  893. *
  894. * Return: ERR_PTR() on error or a valid pointer to a buffer on success. The
  895. * buffer should be freed by the consumer with a kfree().
  896. */
  897. void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
  898. {
  899. struct nvmem_device *nvmem = cell->nvmem;
  900. u8 *buf;
  901. int rc;
  902. if (!nvmem)
  903. return ERR_PTR(-EINVAL);
  904. buf = kzalloc(cell->bytes, GFP_KERNEL);
  905. if (!buf)
  906. return ERR_PTR(-ENOMEM);
  907. rc = __nvmem_cell_read(nvmem, cell, buf, len);
  908. if (rc) {
  909. kfree(buf);
  910. return ERR_PTR(rc);
  911. }
  912. return buf;
  913. }
  914. EXPORT_SYMBOL_GPL(nvmem_cell_read);
  915. static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
  916. u8 *_buf, int len)
  917. {
  918. struct nvmem_device *nvmem = cell->nvmem;
  919. int i, rc, nbits, bit_offset = cell->bit_offset;
  920. u8 v, *p, *buf, *b, pbyte, pbits;
  921. nbits = cell->nbits;
  922. buf = kzalloc(cell->bytes, GFP_KERNEL);
  923. if (!buf)
  924. return ERR_PTR(-ENOMEM);
  925. memcpy(buf, _buf, len);
  926. p = b = buf;
  927. if (bit_offset) {
  928. pbyte = *b;
  929. *b <<= bit_offset;
  930. /* setup the first byte with lsb bits from nvmem */
  931. rc = nvmem_reg_read(nvmem, cell->offset, &v, 1);
  932. if (rc)
  933. goto err;
  934. *b++ |= GENMASK(bit_offset - 1, 0) & v;
  935. /* setup rest of the byte if any */
  936. for (i = 1; i < cell->bytes; i++) {
  937. /* Get last byte bits and shift them towards lsb */
  938. pbits = pbyte >> (BITS_PER_BYTE - 1 - bit_offset);
  939. pbyte = *b;
  940. p = b;
  941. *b <<= bit_offset;
  942. *b++ |= pbits;
  943. }
  944. }
  945. /* if it's not end on byte boundary */
  946. if ((nbits + bit_offset) % BITS_PER_BYTE) {
  947. /* setup the last byte with msb bits from nvmem */
  948. rc = nvmem_reg_read(nvmem,
  949. cell->offset + cell->bytes - 1, &v, 1);
  950. if (rc)
  951. goto err;
  952. *p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v;
  953. }
  954. return buf;
  955. err:
  956. kfree(buf);
  957. return ERR_PTR(rc);
  958. }
  959. /**
  960. * nvmem_cell_write() - Write to a given nvmem cell
  961. *
  962. * @cell: nvmem cell to be written.
  963. * @buf: Buffer to be written.
  964. * @len: length of buffer to be written to nvmem cell.
  965. *
  966. * Return: length of bytes written or negative on failure.
  967. */
  968. int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
  969. {
  970. struct nvmem_device *nvmem = cell->nvmem;
  971. int rc;
  972. if (!nvmem || nvmem->read_only ||
  973. (cell->bit_offset == 0 && len != cell->bytes))
  974. return -EINVAL;
  975. if (cell->bit_offset || cell->nbits) {
  976. buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
  977. if (IS_ERR(buf))
  978. return PTR_ERR(buf);
  979. }
  980. rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes);
  981. /* free the tmp buffer */
  982. if (cell->bit_offset || cell->nbits)
  983. kfree(buf);
  984. if (rc)
  985. return rc;
  986. return len;
  987. }
  988. EXPORT_SYMBOL_GPL(nvmem_cell_write);
  989. /**
  990. * nvmem_cell_read_u32() - Read a cell value as an u32
  991. *
  992. * @dev: Device that requests the nvmem cell.
  993. * @cell_id: Name of nvmem cell to read.
  994. * @val: pointer to output value.
  995. *
  996. * Return: 0 on success or negative errno.
  997. */
  998. int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val)
  999. {
  1000. struct nvmem_cell *cell;
  1001. void *buf;
  1002. size_t len;
  1003. cell = nvmem_cell_get(dev, cell_id);
  1004. if (IS_ERR(cell))
  1005. return PTR_ERR(cell);
  1006. buf = nvmem_cell_read(cell, &len);
  1007. if (IS_ERR(buf)) {
  1008. nvmem_cell_put(cell);
  1009. return PTR_ERR(buf);
  1010. }
  1011. if (len != sizeof(*val)) {
  1012. kfree(buf);
  1013. nvmem_cell_put(cell);
  1014. return -EINVAL;
  1015. }
  1016. memcpy(val, buf, sizeof(*val));
  1017. kfree(buf);
  1018. nvmem_cell_put(cell);
  1019. return 0;
  1020. }
  1021. EXPORT_SYMBOL_GPL(nvmem_cell_read_u32);
  1022. /**
  1023. * nvmem_device_cell_read() - Read a given nvmem device and cell
  1024. *
  1025. * @nvmem: nvmem device to read from.
  1026. * @info: nvmem cell info to be read.
  1027. * @buf: buffer pointer which will be populated on successful read.
  1028. *
  1029. * Return: length of successful bytes read on success and negative
  1030. * error code on error.
  1031. */
  1032. ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
  1033. struct nvmem_cell_info *info, void *buf)
  1034. {
  1035. struct nvmem_cell cell;
  1036. int rc;
  1037. ssize_t len;
  1038. if (!nvmem)
  1039. return -EINVAL;
  1040. rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell);
  1041. if (rc)
  1042. return rc;
  1043. rc = __nvmem_cell_read(nvmem, &cell, buf, &len);
  1044. if (rc)
  1045. return rc;
  1046. return len;
  1047. }
  1048. EXPORT_SYMBOL_GPL(nvmem_device_cell_read);
  1049. /**
  1050. * nvmem_device_cell_write() - Write cell to a given nvmem device
  1051. *
  1052. * @nvmem: nvmem device to be written to.
  1053. * @info: nvmem cell info to be written.
  1054. * @buf: buffer to be written to cell.
  1055. *
  1056. * Return: length of bytes written or negative error code on failure.
  1057. * */
  1058. int nvmem_device_cell_write(struct nvmem_device *nvmem,
  1059. struct nvmem_cell_info *info, void *buf)
  1060. {
  1061. struct nvmem_cell cell;
  1062. int rc;
  1063. if (!nvmem)
  1064. return -EINVAL;
  1065. rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell);
  1066. if (rc)
  1067. return rc;
  1068. return nvmem_cell_write(&cell, buf, cell.bytes);
  1069. }
  1070. EXPORT_SYMBOL_GPL(nvmem_device_cell_write);
  1071. /**
  1072. * nvmem_device_read() - Read from a given nvmem device
  1073. *
  1074. * @nvmem: nvmem device to read from.
  1075. * @offset: offset in nvmem device.
  1076. * @bytes: number of bytes to read.
  1077. * @buf: buffer pointer which will be populated on successful read.
  1078. *
  1079. * Return: length of successful bytes read on success and negative
  1080. * error code on error.
  1081. */
  1082. int nvmem_device_read(struct nvmem_device *nvmem,
  1083. unsigned int offset,
  1084. size_t bytes, void *buf)
  1085. {
  1086. int rc;
  1087. if (!nvmem)
  1088. return -EINVAL;
  1089. rc = nvmem_reg_read(nvmem, offset, buf, bytes);
  1090. if (rc)
  1091. return rc;
  1092. return bytes;
  1093. }
  1094. EXPORT_SYMBOL_GPL(nvmem_device_read);
  1095. /**
  1096. * nvmem_device_write() - Write cell to a given nvmem device
  1097. *
  1098. * @nvmem: nvmem device to be written to.
  1099. * @offset: offset in nvmem device.
  1100. * @bytes: number of bytes to write.
  1101. * @buf: buffer to be written.
  1102. *
  1103. * Return: length of bytes written or negative error code on failure.
  1104. * */
  1105. int nvmem_device_write(struct nvmem_device *nvmem,
  1106. unsigned int offset,
  1107. size_t bytes, void *buf)
  1108. {
  1109. int rc;
  1110. if (!nvmem)
  1111. return -EINVAL;
  1112. rc = nvmem_reg_write(nvmem, offset, buf, bytes);
  1113. if (rc)
  1114. return rc;
  1115. return bytes;
  1116. }
  1117. EXPORT_SYMBOL_GPL(nvmem_device_write);
  1118. static int __init nvmem_init(void)
  1119. {
  1120. return bus_register(&nvmem_bus_type);
  1121. }
  1122. static void __exit nvmem_exit(void)
  1123. {
  1124. bus_unregister(&nvmem_bus_type);
  1125. }
  1126. subsys_initcall(nvmem_init);
  1127. module_exit(nvmem_exit);
  1128. MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
  1129. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com");
  1130. MODULE_DESCRIPTION("nvmem Driver Core");
  1131. MODULE_LICENSE("GPL v2");