dm: core: Add dev_get_uclass_priv() to access uclass private data

Add a convenience function to access the private data that a uclass stores
for each of its devices. Convert over most existing uses for consistency
and to provide an example for others.

Signed-off-by: Simon Glass <sjg@chromium.org>
master
Simon Glass 10 years ago
parent 106cce9604
commit e564f054af
  1. 2
      common/cmd_sf.c
  2. 2
      common/cros_ec.c
  3. 10
      drivers/core/device.c
  4. 2
      drivers/gpio/at91_gpio.c
  5. 2
      drivers/gpio/bcm2835_gpio.c
  6. 22
      drivers/gpio/gpio-uclass.c
  7. 2
      drivers/gpio/intel_ich6_gpio.c
  8. 2
      drivers/gpio/mxc_gpio.c
  9. 2
      drivers/gpio/omap_gpio.c
  10. 2
      drivers/gpio/s5p_gpio.c
  11. 6
      drivers/gpio/sandbox.c
  12. 2
      drivers/gpio/sunxi_gpio.c
  13. 2
      drivers/gpio/tegra_gpio.c
  14. 6
      drivers/i2c/i2c-uclass.c
  15. 2
      drivers/i2c/sandbox_i2c.c
  16. 6
      drivers/misc/cros_ec.c
  17. 2
      drivers/misc/cros_ec_i2c.c
  18. 2
      drivers/misc/cros_ec_sandbox.c
  19. 4
      drivers/misc/cros_ec_spi.c
  20. 2
      drivers/mtd/spi/sf-uclass.c
  21. 8
      drivers/mtd/spi/sf_probe.c
  22. 4
      drivers/serial/serial-uclass.c
  23. 4
      drivers/spi/spi-uclass.c
  24. 10
      include/dm/device.h
  25. 8
      include/i2c.h
  26. 2
      test/dm/core.c
  27. 4
      test/dm/test-uclass.c

@ -130,7 +130,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
return 1; return 1;
} }
flash = new->uclass_priv; flash = dev_get_uclass_priv(new);
#else #else
new = spi_flash_probe(bus, cs, speed, mode); new = spi_flash_probe(bus, cs, speed, mode);
if (!new) { if (!new) {

@ -35,7 +35,7 @@ struct cros_ec_dev *board_get_cros_ec_dev(void)
debug("%s: Error %d\n", __func__, ret); debug("%s: Error %d\n", __func__, ret);
return NULL; return NULL;
} }
return dev->uclass_priv; return dev_get_uclass_priv(dev);
#else #else
return local.cros_ec_dev; return local.cros_ec_dev;
#endif #endif

@ -305,6 +305,16 @@ void *dev_get_priv(struct udevice *dev)
return dev->priv; return dev->priv;
} }
void *dev_get_uclass_priv(struct udevice *dev)
{
if (!dev) {
dm_warn("%s: null device\n", __func__);
return NULL;
}
return dev->uclass_priv;
}
void *dev_get_parentdata(struct udevice *dev) void *dev_get_parentdata(struct udevice *dev)
{ {
if (!dev) { if (!dev) {

@ -511,7 +511,7 @@ static int at91_gpio_probe(struct udevice *dev)
{ {
struct at91_port_priv *port = dev_get_priv(dev); struct at91_port_priv *port = dev_get_priv(dev);
struct at91_port_platdata *plat = dev_get_platdata(dev); struct at91_port_platdata *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
uc_priv->bank_name = plat->bank_name; uc_priv->bank_name = plat->bank_name;
uc_priv->gpio_count = GPIO_PER_BANK; uc_priv->gpio_count = GPIO_PER_BANK;

@ -105,7 +105,7 @@ static int bcm2835_gpio_probe(struct udevice *dev)
{ {
struct bcm2835_gpios *gpios = dev_get_priv(dev); struct bcm2835_gpios *gpios = dev_get_priv(dev);
struct bcm2835_gpio_platdata *plat = dev_get_platdata(dev); struct bcm2835_gpio_platdata *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
uc_priv->bank_name = "GPIO"; uc_priv->bank_name = "GPIO";
uc_priv->gpio_count = BCM2835_GPIO_COUNT; uc_priv->gpio_count = BCM2835_GPIO_COUNT;

@ -34,7 +34,7 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
for (ret = uclass_first_device(UCLASS_GPIO, &dev); for (ret = uclass_first_device(UCLASS_GPIO, &dev);
dev; dev;
ret = uclass_next_device(&dev)) { ret = uclass_next_device(&dev)) {
uc_priv = dev->uclass_priv; uc_priv = dev_get_uclass_priv(dev);
if (gpio >= uc_priv->gpio_base && if (gpio >= uc_priv->gpio_base &&
gpio < uc_priv->gpio_base + uc_priv->gpio_count) { gpio < uc_priv->gpio_base + uc_priv->gpio_count) {
desc->dev = dev; desc->dev = dev;
@ -65,7 +65,7 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
ret = uclass_next_device(&dev)) { ret = uclass_next_device(&dev)) {
int len; int len;
uc_priv = dev->uclass_priv; uc_priv = dev_get_uclass_priv(dev);
if (numeric != -1) { if (numeric != -1) {
offset = numeric - uc_priv->gpio_base; offset = numeric - uc_priv->gpio_base;
/* Allow GPIOs to be numbered from 0 */ /* Allow GPIOs to be numbered from 0 */
@ -116,7 +116,7 @@ static int dm_gpio_request(struct gpio_desc *desc, const char *label)
char *str; char *str;
int ret; int ret;
uc_priv = dev->uclass_priv; uc_priv = dev_get_uclass_priv(dev);
if (uc_priv->name[desc->offset]) if (uc_priv->name[desc->offset])
return -EBUSY; return -EBUSY;
str = strdup(label); str = strdup(label);
@ -195,7 +195,7 @@ int _dm_gpio_free(struct udevice *dev, uint offset)
struct gpio_dev_priv *uc_priv; struct gpio_dev_priv *uc_priv;
int ret; int ret;
uc_priv = dev->uclass_priv; uc_priv = dev_get_uclass_priv(dev);
if (!uc_priv->name[offset]) if (!uc_priv->name[offset])
return -ENXIO; return -ENXIO;
if (gpio_get_ops(dev)->free) { if (gpio_get_ops(dev)->free) {
@ -232,7 +232,7 @@ int gpio_free(unsigned gpio)
static int check_reserved(struct gpio_desc *desc, const char *func) static int check_reserved(struct gpio_desc *desc, const char *func)
{ {
struct gpio_dev_priv *uc_priv = desc->dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(desc->dev);
if (!uc_priv->name[desc->offset]) { if (!uc_priv->name[desc->offset]) {
printf("%s: %s: error: gpio %s%d not reserved\n", printf("%s: %s: error: gpio %s%d not reserved\n",
@ -402,7 +402,7 @@ const char *gpio_get_bank_info(struct udevice *dev, int *bit_count)
struct gpio_dev_priv *priv; struct gpio_dev_priv *priv;
/* Must be called on an active device */ /* Must be called on an active device */
priv = dev->uclass_priv; priv = dev_get_uclass_priv(dev);
assert(priv); assert(priv);
*bit_count = priv->gpio_count; *bit_count = priv->gpio_count;
@ -420,7 +420,7 @@ static const char * const gpio_function[GPIOF_COUNT] = {
int get_function(struct udevice *dev, int offset, bool skip_unused, int get_function(struct udevice *dev, int offset, bool skip_unused,
const char **namep) const char **namep)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct dm_gpio_ops *ops = gpio_get_ops(dev); struct dm_gpio_ops *ops = gpio_get_ops(dev);
BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function));
@ -468,7 +468,7 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function));
*buf = 0; *buf = 0;
priv = dev->uclass_priv; priv = dev_get_uclass_priv(dev);
ret = gpio_get_raw_function(dev, offset, NULL); ret = gpio_get_raw_function(dev, offset, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -680,7 +680,7 @@ static int gpio_renumber(struct udevice *removed_dev)
base = 0; base = 0;
uclass_foreach_dev(dev, uc) { uclass_foreach_dev(dev, uc) {
if (device_active(dev) && dev != removed_dev) { if (device_active(dev) && dev != removed_dev) {
uc_priv = dev->uclass_priv; uc_priv = dev_get_uclass_priv(dev);
uc_priv->gpio_base = base; uc_priv->gpio_base = base;
base += uc_priv->gpio_count; base += uc_priv->gpio_count;
} }
@ -691,7 +691,7 @@ static int gpio_renumber(struct udevice *removed_dev)
static int gpio_post_probe(struct udevice *dev) static int gpio_post_probe(struct udevice *dev)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
uc_priv->name = calloc(uc_priv->gpio_count, sizeof(char *)); uc_priv->name = calloc(uc_priv->gpio_count, sizeof(char *));
if (!uc_priv->name) if (!uc_priv->name)
@ -702,7 +702,7 @@ static int gpio_post_probe(struct udevice *dev)
static int gpio_pre_remove(struct udevice *dev) static int gpio_pre_remove(struct udevice *dev)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
int i; int i;
for (i = 0; i < uc_priv->gpio_count; i++) { for (i = 0; i < uc_priv->gpio_count; i++) {

@ -151,7 +151,7 @@ static int gpio_ich6_ofdata_to_platdata(struct udevice *dev)
static int ich6_gpio_probe(struct udevice *dev) static int ich6_gpio_probe(struct udevice *dev)
{ {
struct ich6_bank_platdata *plat = dev_get_platdata(dev); struct ich6_bank_platdata *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct ich6_bank_priv *bank = dev_get_priv(dev); struct ich6_bank_priv *bank = dev_get_priv(dev);
if (gd->arch.gpio_map) { if (gd->arch.gpio_map) {

@ -266,7 +266,7 @@ static int mxc_gpio_probe(struct udevice *dev)
{ {
struct mxc_bank_info *bank = dev_get_priv(dev); struct mxc_bank_info *bank = dev_get_priv(dev);
struct mxc_gpio_plat *plat = dev_get_platdata(dev); struct mxc_gpio_plat *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
int banknum; int banknum;
char name[18], *str; char name[18], *str;

@ -309,7 +309,7 @@ static int omap_gpio_probe(struct udevice *dev)
{ {
struct gpio_bank *bank = dev_get_priv(dev); struct gpio_bank *bank = dev_get_priv(dev);
struct omap_gpio_platdata *plat = dev_get_platdata(dev); struct omap_gpio_platdata *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
char name[18], *str; char name[18], *str;
sprintf(name, "GPIO%d_", plat->bank_index); sprintf(name, "GPIO%d_", plat->bank_index);

@ -296,7 +296,7 @@ static const struct dm_gpio_ops gpio_exynos_ops = {
static int gpio_exynos_probe(struct udevice *dev) static int gpio_exynos_probe(struct udevice *dev)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct exynos_bank_info *priv = dev->priv; struct exynos_bank_info *priv = dev->priv;
struct exynos_gpio_platdata *plat = dev->platdata; struct exynos_gpio_platdata *plat = dev->platdata;

@ -24,7 +24,7 @@ struct gpio_state {
/* Access routines for GPIO state */ /* Access routines for GPIO state */
static u8 *get_gpio_flags(struct udevice *dev, unsigned offset) static u8 *get_gpio_flags(struct udevice *dev, unsigned offset)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct gpio_state *state = dev_get_priv(dev); struct gpio_state *state = dev_get_priv(dev);
if (offset >= uc_priv->gpio_count) { if (offset >= uc_priv->gpio_count) {
@ -160,7 +160,7 @@ static const struct dm_gpio_ops gpio_sandbox_ops = {
static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev) static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
uc_priv->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset, uc_priv->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
"num-gpios", 0); "num-gpios", 0);
@ -172,7 +172,7 @@ static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
static int gpio_sandbox_probe(struct udevice *dev) static int gpio_sandbox_probe(struct udevice *dev)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
if (dev->of_offset == -1) { if (dev->of_offset == -1) {
/* Tell the uclass how many GPIOs we have */ /* Tell the uclass how many GPIOs we have */

@ -261,7 +261,7 @@ static char *gpio_bank_name(int bank)
static int gpio_sunxi_probe(struct udevice *dev) static int gpio_sunxi_probe(struct udevice *dev)
{ {
struct sunxi_gpio_platdata *plat = dev_get_platdata(dev); struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
/* Tell the uclass how many GPIOs we have */ /* Tell the uclass how many GPIOs we have */
if (plat) { if (plat) {

@ -295,7 +295,7 @@ static const struct udevice_id tegra_gpio_ids[] = {
static int gpio_tegra_probe(struct udevice *dev) static int gpio_tegra_probe(struct udevice *dev)
{ {
struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct tegra_port_info *priv = dev->priv; struct tegra_port_info *priv = dev->priv;
struct tegra_gpio_platdata *plat = dev->platdata; struct tegra_gpio_platdata *plat = dev->platdata;

@ -330,7 +330,7 @@ int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags,
int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
{ {
struct dm_i2c_ops *ops = i2c_get_ops(bus); struct dm_i2c_ops *ops = i2c_get_ops(bus);
struct dm_i2c_bus *i2c = bus->uclass_priv; struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus);
int ret; int ret;
/* /*
@ -351,7 +351,7 @@ int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
int dm_i2c_get_bus_speed(struct udevice *bus) int dm_i2c_get_bus_speed(struct udevice *bus)
{ {
struct dm_i2c_ops *ops = i2c_get_ops(bus); struct dm_i2c_ops *ops = i2c_get_ops(bus);
struct dm_i2c_bus *i2c = bus->uclass_priv; struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus);
if (!ops->get_bus_speed) if (!ops->get_bus_speed)
return i2c->speed_hz; return i2c->speed_hz;
@ -432,7 +432,7 @@ int i2c_chip_ofdata_to_platdata(const void *blob, int node,
static int i2c_post_probe(struct udevice *dev) static int i2c_post_probe(struct udevice *dev)
{ {
struct dm_i2c_bus *i2c = dev->uclass_priv; struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
i2c->speed_hz = fdtdec_get_int(gd->fdt_blob, dev->of_offset, i2c->speed_hz = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
"clock-frequency", 100000); "clock-frequency", 100000);

@ -50,7 +50,7 @@ static int get_emul(struct udevice *dev, struct udevice **devp,
static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
int nmsgs) int nmsgs)
{ {
struct dm_i2c_bus *i2c = bus->uclass_priv; struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus);
struct dm_i2c_ops *ops; struct dm_i2c_ops *ops;
struct udevice *emul, *dev; struct udevice *emul, *dev;
bool is_read; bool is_read;

@ -1087,7 +1087,7 @@ static int cros_ec_decode_fdt(const void *blob, int node,
#ifdef CONFIG_DM_CROS_EC #ifdef CONFIG_DM_CROS_EC
int cros_ec_register(struct udevice *dev) int cros_ec_register(struct udevice *dev)
{ {
struct cros_ec_dev *cdev = dev->uclass_priv; struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
const void *blob = gd->fdt_blob; const void *blob = gd->fdt_blob;
int node = dev->of_offset; int node = dev->of_offset;
char id[MSG_BYTES]; char id[MSG_BYTES];
@ -1128,7 +1128,7 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp)
ret = uclass_get_device(UCLASS_CROS_EC, 0, &udev); ret = uclass_get_device(UCLASS_CROS_EC, 0, &udev);
if (ret) if (ret)
return ret; return ret;
dev = udev->uclass_priv; dev = dev_get_uclass_priv(udev);
return 0; return 0;
#else #else
int node = 0; int node = 0;
@ -1610,7 +1610,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("Cannot get cros-ec device (err=%d)\n", ret); printf("Cannot get cros-ec device (err=%d)\n", ret);
return 1; return 1;
} }
dev = udev->uclass_priv; dev = dev_get_uclass_priv(udev);
#else #else
/* Just use the last allocated device; there should be only one */ /* Just use the last allocated device; there should be only one */
if (!last_dev) { if (!last_dev) {

@ -28,7 +28,7 @@ static int cros_ec_i2c_command(struct udevice *udev, uint8_t cmd,
int cmd_version, const uint8_t *dout, int cmd_version, const uint8_t *dout,
int dout_len, uint8_t **dinp, int din_len) int dout_len, uint8_t **dinp, int din_len)
{ {
struct cros_ec_dev *dev = udev->uclass_priv; struct cros_ec_dev *dev = dev_get_uclass_priv(udev);
/* version8, cmd8, arglen8, out8[dout_len], csum8 */ /* version8, cmd8, arglen8, out8[dout_len], csum8 */
int out_bytes = dout_len + 4; int out_bytes = dout_len + 4;
/* response8, arglen8, in8[din_len], checksum8 */ /* response8, arglen8, in8[din_len], checksum8 */

@ -470,7 +470,7 @@ static int process_cmd(struct ec_state *ec,
#ifdef CONFIG_DM_CROS_EC #ifdef CONFIG_DM_CROS_EC
int cros_ec_sandbox_packet(struct udevice *udev, int out_bytes, int in_bytes) int cros_ec_sandbox_packet(struct udevice *udev, int out_bytes, int in_bytes)
{ {
struct cros_ec_dev *dev = udev->uclass_priv; struct cros_ec_dev *dev = dev_get_uclass_priv(udev);
struct ec_state *ec = dev_get_priv(dev->dev); struct ec_state *ec = dev_get_priv(dev->dev);
#else #else
int cros_ec_sandbox_packet(struct cros_ec_dev *dev, int out_bytes, int cros_ec_sandbox_packet(struct cros_ec_dev *dev, int out_bytes,

@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
int cros_ec_spi_packet(struct udevice *udev, int out_bytes, int in_bytes) int cros_ec_spi_packet(struct udevice *udev, int out_bytes, int in_bytes)
{ {
struct cros_ec_dev *dev = udev->uclass_priv; struct cros_ec_dev *dev = dev_get_uclass_priv(udev);
struct spi_slave *slave = dev_get_parentdata(dev->dev); struct spi_slave *slave = dev_get_parentdata(dev->dev);
int rv; int rv;
@ -66,7 +66,7 @@ int cros_ec_spi_command(struct udevice *udev, uint8_t cmd, int cmd_version,
const uint8_t *dout, int dout_len, const uint8_t *dout, int dout_len,
uint8_t **dinp, int din_len) uint8_t **dinp, int din_len)
{ {
struct cros_ec_dev *dev = udev->uclass_priv; struct cros_ec_dev *dev = dev_get_uclass_priv(udev);
struct spi_slave *slave = dev_get_parentdata(dev->dev); struct spi_slave *slave = dev_get_parentdata(dev->dev);
int in_bytes = din_len + 4; /* status, length, checksum, trailer */ int in_bytes = din_len + 4; /* status, length, checksum, trailer */
uint8_t *out; uint8_t *out;

@ -23,7 +23,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev)) if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev))
return NULL; return NULL;
return dev->uclass_priv; return dev_get_uclass_priv(dev);
} }
void spi_flash_free(struct spi_flash *flash) void spi_flash_free(struct spi_flash *flash)

@ -458,7 +458,7 @@ void spi_flash_free(struct spi_flash *flash)
static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len, static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,
void *buf) void *buf)
{ {
struct spi_flash *flash = dev->uclass_priv; struct spi_flash *flash = dev_get_uclass_priv(dev);
return spi_flash_cmd_read_ops(flash, offset, len, buf); return spi_flash_cmd_read_ops(flash, offset, len, buf);
} }
@ -466,14 +466,14 @@ static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,
int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len, int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
const void *buf) const void *buf)
{ {
struct spi_flash *flash = dev->uclass_priv; struct spi_flash *flash = dev_get_uclass_priv(dev);
return spi_flash_cmd_write_ops(flash, offset, len, buf); return spi_flash_cmd_write_ops(flash, offset, len, buf);
} }
int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len) int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
{ {
struct spi_flash *flash = dev->uclass_priv; struct spi_flash *flash = dev_get_uclass_priv(dev);
return spi_flash_cmd_erase_ops(flash, offset, len); return spi_flash_cmd_erase_ops(flash, offset, len);
} }
@ -484,7 +484,7 @@ int spi_flash_std_probe(struct udevice *dev)
struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev); struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
struct spi_flash *flash; struct spi_flash *flash;
flash = dev->uclass_priv; flash = dev_get_uclass_priv(dev);
flash->dev = dev; flash->dev = dev;
debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs); debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
return spi_flash_probe_slave(slave, flash); return spi_flash_probe_slave(slave, flash);

@ -251,7 +251,7 @@ static int serial_post_probe(struct udevice *dev)
{ {
struct dm_serial_ops *ops = serial_get_ops(dev); struct dm_serial_ops *ops = serial_get_ops(dev);
#ifdef CONFIG_DM_STDIO #ifdef CONFIG_DM_STDIO
struct serial_dev_priv *upriv = dev->uclass_priv; struct serial_dev_priv *upriv = dev_get_uclass_priv(dev);
struct stdio_dev sdev; struct stdio_dev sdev;
#endif #endif
int ret; int ret;
@ -299,7 +299,7 @@ static int serial_post_probe(struct udevice *dev)
static int serial_pre_remove(struct udevice *dev) static int serial_pre_remove(struct udevice *dev)
{ {
#ifdef CONFIG_SYS_STDIO_DEREGISTER #ifdef CONFIG_SYS_STDIO_DEREGISTER
struct serial_dev_priv *upriv = dev->uclass_priv; struct serial_dev_priv *upriv = dev_get_uclass_priv(dev);
if (stdio_deregister_dev(upriv->sdev, 0)) if (stdio_deregister_dev(upriv->sdev, 0))
return -EPERM; return -EPERM;

@ -50,7 +50,7 @@ int spi_claim_bus(struct spi_slave *slave)
struct udevice *dev = slave->dev; struct udevice *dev = slave->dev;
struct udevice *bus = dev->parent; struct udevice *bus = dev->parent;
struct dm_spi_ops *ops = spi_get_ops(bus); struct dm_spi_ops *ops = spi_get_ops(bus);
struct dm_spi_bus *spi = bus->uclass_priv; struct dm_spi_bus *spi = dev_get_uclass_priv(bus);
int speed; int speed;
int ret; int ret;
@ -110,7 +110,7 @@ int spi_child_post_bind(struct udevice *dev)
int spi_post_probe(struct udevice *bus) int spi_post_probe(struct udevice *bus)
{ {
struct dm_spi_bus *spi = bus->uclass_priv; struct dm_spi_bus *spi = dev_get_uclass_priv(bus);
spi->max_hz = fdtdec_get_int(gd->fdt_blob, bus->of_offset, spi->max_hz = fdtdec_get_int(gd->fdt_blob, bus->of_offset,
"spi-max-frequency", 0); "spi-max-frequency", 0);

@ -238,6 +238,16 @@ void *dev_get_priv(struct udevice *dev);
struct udevice *dev_get_parent(struct udevice *child); struct udevice *dev_get_parent(struct udevice *child);
/** /**
* dev_get_uclass_priv() - Get the private uclass data for a device
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return private uclass data for this device, or NULL if none
*/
void *dev_get_uclass_priv(struct udevice *dev);
/**
* dev_get_of_data() - get the device tree data used to bind a device * dev_get_of_data() - get the device tree data used to bind a device
* *
* When a device is bound using a device tree node, it matches a * When a device is bound using a device tree node, it matches a

@ -64,8 +64,8 @@ struct dm_i2c_chip {
* bus can operate at different speeds (measured in Hz, typically 100KHz * bus can operate at different speeds (measured in Hz, typically 100KHz
* or 400KHz). * or 400KHz).
* *
* To obtain this structure, use bus->uclass_priv where bus is the I2C * To obtain this structure, use dev_get_uclass_priv(bus) where bus is the
* bus udevice. * I2C bus udevice.
* *
* @speed_hz: Bus speed in hertz (typically 100000) * @speed_hz: Bus speed in hertz (typically 100000)
*/ */
@ -340,7 +340,7 @@ struct dm_i2c_ops {
* The bus speed value will be updated by the uclass if this function * The bus speed value will be updated by the uclass if this function
* does not return an error. This method is optional - if it is not * does not return an error. This method is optional - if it is not
* provided then the driver can read the speed from * provided then the driver can read the speed from
* bus->uclass_priv->speed_hz * dev_get_uclass_priv(bus)->speed_hz
* *
* @bus: Bus to adjust * @bus: Bus to adjust
* @speed: Requested speed in Hz * @speed: Requested speed in Hz
@ -354,7 +354,7 @@ struct dm_i2c_ops {
* Normally this can be provided by the uclass, but if you want your * Normally this can be provided by the uclass, but if you want your
* driver to check the bus speed by looking at the hardware, you can * driver to check the bus speed by looking at the hardware, you can
* implement that here. This method is optional. This method would * implement that here. This method is optional. This method would
* normally be expected to return bus->uclass_priv->speed_hz. * normally be expected to return dev_get_uclass_priv(bus)->speed_hz.
* *
* @bus: Bus to check * @bus: Bus to check
* @return speed of selected I2C bus in Hz, -ve on error * @return speed of selected I2C bus in Hz, -ve on error

@ -179,7 +179,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms)
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev); ut_assert(dev);
priv = dev->uclass_priv; priv = dev_get_uclass_priv(dev);
ut_assert(priv); ut_assert(priv);
ut_asserteq(expected_base_add, priv->base_add); ut_asserteq(expected_base_add, priv->base_add);

@ -47,7 +47,7 @@ static int test_post_probe(struct udevice *dev)
struct udevice *prev = list_entry(dev->uclass_node.prev, struct udevice *prev = list_entry(dev->uclass_node.prev,
struct udevice, uclass_node); struct udevice, uclass_node);
struct dm_test_uclass_perdev_priv *priv = dev->uclass_priv; struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
struct uclass *uc = dev->uclass; struct uclass *uc = dev->uclass;
dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++;
@ -58,7 +58,7 @@ static int test_post_probe(struct udevice *dev)
return 0; return 0;
if (&prev->uclass_node != &uc->dev_head) { if (&prev->uclass_node != &uc->dev_head) {
struct dm_test_uclass_perdev_priv *prev_uc_priv struct dm_test_uclass_perdev_priv *prev_uc_priv
= prev->uclass_priv; = dev_get_uclass_priv(prev);
struct dm_test_pdata *pdata = prev->platdata; struct dm_test_pdata *pdata = prev->platdata;
ut_assert(pdata); ut_assert(pdata);

Loading…
Cancel
Save