generic: update nvmem cell mac-address-ascii support
Instead of use mac-address-ascii in nvmem_get_mac_address function, move it into of_get_mac_addr_nvmem function to support more devices. Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
This commit is contained in:
		 Chukun Pan
					Chukun Pan
				
			
				
					committed by
					
						 Christian Marangi
						Christian Marangi
					
				
			
			
				
	
			
			
			 Christian Marangi
						Christian Marangi
					
				
			
						parent
						
							31c15813f9
						
					
				
				
					commit
					28ce677fa7
				
			| @@ -1,19 +1,19 @@ | |||||||
| From: Yousong Zhou <yszhou4tech@gmail.com> | From: Yousong Zhou <yszhou4tech@gmail.com> | ||||||
| Subject: [PATCH] ath79: add nvmem cell mac-address-ascii support | Subject: [PATCH] of: net: add nvmem cell mac-address-ascii support | ||||||
|  |  | ||||||
| This is needed for devices with mac address stored in ascii format, e.g. | This is needed for devices with mac address stored in ascii format, | ||||||
| HiWiFi HC6361 to be ported in the following patch. | e.g. HiWiFi HC6361 to be ported in the following patch. | ||||||
|  |  | ||||||
| Submitted-by: Yousong Zhou <yszhou4tech@gmail.com> | Submitted-by: Yousong Zhou <yszhou4tech@gmail.com> | ||||||
| --- | --- | ||||||
|  net/ethernet/eth.c                            | 83 ++++++++++++------ |  net/core/of_net.c | 83 ++++++++++++------ | ||||||
|  1 files changed, 72 insertions(+), 11 deletions(-) |  1 files changed, 72 insertions(+), 11 deletions(-) | ||||||
|  |  | ||||||
| --- a/net/ethernet/eth.c | --- a/drivers/of/of_net.c | ||||||
| +++ b/net/ethernet/eth.c | +++ b/drivers/of/of_net.c | ||||||
| @@ -539,6 +539,63 @@ int eth_platform_get_mac_address(struct | @@ -57,13 +57,70 @@ static int of_get_mac_addr(struct device | ||||||
|  |  	return -ENODEV; | ||||||
|  } |  } | ||||||
|  EXPORT_SYMBOL(eth_platform_get_mac_address); |  | ||||||
|   |   | ||||||
| +static void *nvmem_cell_get_mac_address(struct nvmem_cell *cell) | +static void *nvmem_cell_get_mac_address(struct nvmem_cell *cell) | ||||||
| +{ | +{ | ||||||
| @@ -72,35 +72,40 @@ Submitted-by: Yousong Zhou <yszhou4tech@gmail.com> | |||||||
| +	}, | +	}, | ||||||
| +}; | +}; | ||||||
| + | + | ||||||
|  /** |  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr) | ||||||
|   * Obtain the MAC address from an nvmem cell named 'mac-address' associated |  | ||||||
|   * with given device. |  | ||||||
| @@ -550,21 +607,28 @@ EXPORT_SYMBOL(eth_platform_get_mac_addre |  | ||||||
|   */ |  | ||||||
|  int nvmem_get_mac_address(struct device *dev, void *addrbuf) |  | ||||||
|  { |  { | ||||||
|  |  	struct platform_device *pdev = of_find_device_by_node(np); | ||||||
| +	struct nvmem_cell_mac_address_property *property; | +	struct nvmem_cell_mac_address_property *property; | ||||||
|  	struct nvmem_cell *cell; |  	struct nvmem_cell *cell; | ||||||
|  	const void *mac; |  	const void *mac; | ||||||
| -	size_t len; | -	size_t len; | ||||||
| +	int i; | -	int ret; | ||||||
| + | +	int ret, i; | ||||||
|  |   | ||||||
|  |  	/* Try lookup by device first, there might be a nvmem_cell_lookup | ||||||
|  |  	 * associated with a given device. | ||||||
|  | @@ -74,17 +131,26 @@ static int of_get_mac_addr_nvmem(struct | ||||||
|  |  		return ret; | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | -	cell = of_nvmem_cell_get(np, "mac-address"); | ||||||
| +	for (i = 0; i < ARRAY_SIZE(nvmem_cell_mac_address_properties); i++) { | +	for (i = 0; i < ARRAY_SIZE(nvmem_cell_mac_address_properties); i++) { | ||||||
| +		property = &nvmem_cell_mac_address_properties[i]; | +		property = &nvmem_cell_mac_address_properties[i]; | ||||||
| +		cell = nvmem_cell_get(dev, property->name); | +		cell = of_nvmem_cell_get(np, property->name); | ||||||
| +		/* For -EPROBE_DEFER don't try other properties. We'll get back to this one. */ | +		/* For -EPROBE_DEFER don't try other properties. | ||||||
|  | +		 * We'll get back to this one. | ||||||
|  | +		 */ | ||||||
| +		if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) | +		if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) | ||||||
| +			break; | +			break; | ||||||
| +	} | +	} | ||||||
|   | + | ||||||
| -	cell = nvmem_cell_get(dev, "mac-address"); |  | ||||||
|  	if (IS_ERR(cell)) |  	if (IS_ERR(cell)) | ||||||
|  		return PTR_ERR(cell); |  		return PTR_ERR(cell); | ||||||
|   |   | ||||||
| -	mac = nvmem_cell_read(cell, &len); | -	mac = nvmem_cell_read(cell, &len); | ||||||
| +	mac = property->read(cell); | +	mac = property->read(cell); | ||||||
|  	nvmem_cell_put(cell); |  	nvmem_cell_put(cell); | ||||||
| - |   | ||||||
|  	if (IS_ERR(mac)) |  	if (IS_ERR(mac)) | ||||||
|  		return PTR_ERR(mac); |  		return PTR_ERR(mac); | ||||||
|   |   | ||||||
|   | |||||||
| @@ -1,19 +1,19 @@ | |||||||
| From: Yousong Zhou <yszhou4tech@gmail.com> | From: Yousong Zhou <yszhou4tech@gmail.com> | ||||||
| Subject: [PATCH] ath79: add nvmem cell mac-address-ascii support | Subject: [PATCH] of: net: add nvmem cell mac-address-ascii support | ||||||
|  |  | ||||||
| This is needed for devices with mac address stored in ascii format, e.g. | This is needed for devices with mac address stored in ascii format, | ||||||
| HiWiFi HC6361 to be ported in the following patch. | e.g. HiWiFi HC6361 to be ported in the following patch. | ||||||
|  |  | ||||||
| Submitted-by: Yousong Zhou <yszhou4tech@gmail.com> | Submitted-by: Yousong Zhou <yszhou4tech@gmail.com> | ||||||
| --- | --- | ||||||
|  net/ethernet/eth.c                            | 83 ++++++++++++------ |  net/core/of_net.c | 83 ++++++++++++------ | ||||||
|  1 files changed, 72 insertions(+), 11 deletions(-) |  1 files changed, 72 insertions(+), 11 deletions(-) | ||||||
|  |  | ||||||
| --- a/net/ethernet/eth.c | --- a/net/core/of_net.c | ||||||
| +++ b/net/ethernet/eth.c | +++ b/net/core/of_net.c | ||||||
| @@ -538,6 +538,63 @@ int eth_platform_get_mac_address(struct | @@ -57,13 +57,70 @@ static int of_get_mac_addr(struct device | ||||||
|  |  	return -ENODEV; | ||||||
|  } |  } | ||||||
|  EXPORT_SYMBOL(eth_platform_get_mac_address); |  | ||||||
|   |   | ||||||
| +static void *nvmem_cell_get_mac_address(struct nvmem_cell *cell) | +static void *nvmem_cell_get_mac_address(struct nvmem_cell *cell) | ||||||
| +{ | +{ | ||||||
| @@ -72,35 +72,40 @@ Submitted-by: Yousong Zhou <yszhou4tech@gmail.com> | |||||||
| +	}, | +	}, | ||||||
| +}; | +}; | ||||||
| + | + | ||||||
|  /** |  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr) | ||||||
|   * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named |  | ||||||
|   * 'mac-address' associated with given device. |  | ||||||
| @@ -549,21 +606,28 @@ EXPORT_SYMBOL(eth_platform_get_mac_addre |  | ||||||
|   */ |  | ||||||
|  int nvmem_get_mac_address(struct device *dev, void *addrbuf) |  | ||||||
|  { |  { | ||||||
|  |  	struct platform_device *pdev = of_find_device_by_node(np); | ||||||
| +	struct nvmem_cell_mac_address_property *property; | +	struct nvmem_cell_mac_address_property *property; | ||||||
|  	struct nvmem_cell *cell; |  	struct nvmem_cell *cell; | ||||||
|  	const void *mac; |  	const void *mac; | ||||||
| -	size_t len; | -	size_t len; | ||||||
| +	int i; | -	int ret; | ||||||
| + | +	int ret, i; | ||||||
|  |   | ||||||
|  |  	/* Try lookup by device first, there might be a nvmem_cell_lookup | ||||||
|  |  	 * associated with a given device. | ||||||
|  | @@ -74,17 +131,26 @@ static int of_get_mac_addr_nvmem(struct | ||||||
|  |  		return ret; | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | -	cell = of_nvmem_cell_get(np, "mac-address"); | ||||||
| +	for (i = 0; i < ARRAY_SIZE(nvmem_cell_mac_address_properties); i++) { | +	for (i = 0; i < ARRAY_SIZE(nvmem_cell_mac_address_properties); i++) { | ||||||
| +		property = &nvmem_cell_mac_address_properties[i]; | +		property = &nvmem_cell_mac_address_properties[i]; | ||||||
| +		cell = nvmem_cell_get(dev, property->name); | +		cell = of_nvmem_cell_get(np, property->name); | ||||||
| +		/* For -EPROBE_DEFER don't try other properties. We'll get back to this one. */ | +		/* For -EPROBE_DEFER don't try other properties. | ||||||
|  | +		 * We'll get back to this one. | ||||||
|  | +		 */ | ||||||
| +		if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) | +		if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) | ||||||
| +			break; | +			break; | ||||||
| +	} | +	} | ||||||
|   | + | ||||||
| -	cell = nvmem_cell_get(dev, "mac-address"); |  | ||||||
|  	if (IS_ERR(cell)) |  	if (IS_ERR(cell)) | ||||||
|  		return PTR_ERR(cell); |  		return PTR_ERR(cell); | ||||||
|   |   | ||||||
| -	mac = nvmem_cell_read(cell, &len); | -	mac = nvmem_cell_read(cell, &len); | ||||||
| +	mac = property->read(cell); | +	mac = property->read(cell); | ||||||
|  	nvmem_cell_put(cell); |  	nvmem_cell_put(cell); | ||||||
| - |   | ||||||
|  	if (IS_ERR(mac)) |  	if (IS_ERR(mac)) | ||||||
|  		return PTR_ERR(mac); |  		return PTR_ERR(mac); | ||||||
|   |   | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user