Re: [U-Boot] [PATCH v2 03/12] dm: pmic: add implementation of driver model pmic uclass
Hello Simon, On 03/06/2015 03:11 PM, Simon Glass wrote: Hi Przemyslaw, On 3 March 2015 at 09:24, Przemyslaw Marczak p.marc...@samsung.com wrote: This is an introduction to driver-model multi uclass PMIC support. It starts with UCLASS_PMIC - a common PMIC devices uclass type to provide device read/write operations only. Beside two basic operations the pmic platform data is introduced, which provides basic informations about the pmic device I/O interface and is shared with all childs (and should also for childs new uclass types in the future). Usually PMIC devices provides various functionalities with single or multiple I/O interfaces. Using this new framework and new uclass types introduced in the future, it can be handle like this: _ root device | |_ BUS 0 device (e.g. I2C0)- UCLASS_I2C/SPI/... | |_ PMIC device 1 (read/write ops)- UCLASS_PMIC | |_ REGULATOR device (ldo/buck/... ops) - UCLASS_REGULATOR | |_ CHARGER device (charger ops)- UCLASS_CHARGER (in the future) | |_ MUIC device (microUSB con ops) - UCLASS_MUIC(in the future) | |_ ... | |_ BUS 1 device (e.g. I2C1)- UCLASS_I2C/SPI/... |_ PMIC device 2 (read/write ops)- UCLASS_PMIC |_ RTC device (rtc ops)- UCLASS_MUIC (in the future) For each PMIC device interface, new UCLASS_PMIC device is bind with proper pmic driver, and it's child devices provides some specified operations. All new definitions can be found in file: - 'include/power/pmic.h' Uclass file: - pmic-uclass.c - provides a common code for UCLASS_PMIC device drivers The old pmic framework is still kept and is independent. Changes: - new uclass-id: UCLASS_PMIC - new config: CONFIG_DM_PMIC New pmic api is documented in: doc/README.power-framework-dm Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com --- Changes V2: - pmic uclass: adjust uclass code to the mainline changes - pmic uclass: remove pmic_i2c and pmic_spi - pmic uclass: modify pmic_platdata - pmic uclass: add pmic_if_* functions - pmic uclass: remove pmic_init_dm() - pmic uclass: cleanup - pmic.h: define pmic ops structure (read/write operations) - pmic.h: add comments to functions --- drivers/power/Makefile | 1 + drivers/power/pmic-uclass.c | 191 +++ include/dm/uclass-id.h | 3 + include/power/pmic.h| 265 4 files changed, 460 insertions(+) create mode 100644 drivers/power/pmic-uclass.c This should have a Kconfig file. diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 2145652..5c9a189 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -21,3 +21,4 @@ obj-$(CONFIG_DIALOG_POWER) += power_dialog.o obj-$(CONFIG_POWER_FSL) += power_fsl.o obj-$(CONFIG_POWER_I2C) += power_i2c.o obj-$(CONFIG_POWER_SPI) += power_spi.o +obj-$(CONFIG_DM_PMIC) += pmic-uclass.o diff --git a/drivers/power/pmic-uclass.c b/drivers/power/pmic-uclass.c new file mode 100644 index 000..309463e --- /dev/null +++ b/drivers/power/pmic-uclass.c @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2014-2015 Samsung Electronics + * Przemyslaw Marczak p.marc...@samsung.com + * + * SPDX-License-Identifier:GPL-2.0+ + */ +#include common.h +#include linux/types.h +#include fdtdec.h +#include dm.h +#include power/pmic.h +#include dm/device-internal.h +#include dm/uclass-internal.h +#include dm/root.h +#include dm/lists.h +#include compiler.h +#include errno.h + +DECLARE_GLOBAL_DATA_PTR; + +static char * const pmic_interfaces[] = { + I2C, + SPI, + --, +}; + +const char *pmic_if_str(struct udevice *pmic) +{ + int if_types = ARRAY_SIZE(pmic_interfaces); + int if_type; + + if_type = pmic_if_type(pmic); + if (if_type 0 || if_type = if_types) + return pmic_interfaces[if_types - 1]; + + return pmic_interfaces[if_type]; +} + +int pmic_if_type(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_type; +} + +int pmic_if_bus_num(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_bus_num; +} + +int pmic_if_addr_cs(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_addr_cs; +} + +int pmic_if_max_offset(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_max_offset; +} + +int pmic_read(struct udevice *pmic, unsigned reg, unsigned char *val) +{ + const struct dm_pmic_ops *ops; + + ops = pmic_get_uclass_ops(pmic, UCLASS_PMIC); + if (!ops) + return -ENODEV; + + if (!ops-read) + return -EPERM; + + if (ops-read(pmic, reg, val)) + return -EIO; + + return 0; +} + +int pmic_write(struct udevice *pmic, unsigned reg, unsigned char val) +{ + const struct dm_pmic_ops *ops; + + ops = pmic_get_uclass_ops(pmic,
Re: [U-Boot] [PATCH v2 03/12] dm: pmic: add implementation of driver model pmic uclass
Hi Przemyslaw, On 3 March 2015 at 09:24, Przemyslaw Marczak p.marc...@samsung.com wrote: This is an introduction to driver-model multi uclass PMIC support. It starts with UCLASS_PMIC - a common PMIC devices uclass type to provide device read/write operations only. Beside two basic operations the pmic platform data is introduced, which provides basic informations about the pmic device I/O interface and is shared with all childs (and should also for childs new uclass types in the future). Usually PMIC devices provides various functionalities with single or multiple I/O interfaces. Using this new framework and new uclass types introduced in the future, it can be handle like this: _ root device | |_ BUS 0 device (e.g. I2C0)- UCLASS_I2C/SPI/... | |_ PMIC device 1 (read/write ops)- UCLASS_PMIC | |_ REGULATOR device (ldo/buck/... ops) - UCLASS_REGULATOR | |_ CHARGER device (charger ops)- UCLASS_CHARGER (in the future) | |_ MUIC device (microUSB con ops) - UCLASS_MUIC(in the future) | |_ ... | |_ BUS 1 device (e.g. I2C1)- UCLASS_I2C/SPI/... |_ PMIC device 2 (read/write ops)- UCLASS_PMIC |_ RTC device (rtc ops)- UCLASS_MUIC (in the future) For each PMIC device interface, new UCLASS_PMIC device is bind with proper pmic driver, and it's child devices provides some specified operations. All new definitions can be found in file: - 'include/power/pmic.h' Uclass file: - pmic-uclass.c - provides a common code for UCLASS_PMIC device drivers The old pmic framework is still kept and is independent. Changes: - new uclass-id: UCLASS_PMIC - new config: CONFIG_DM_PMIC New pmic api is documented in: doc/README.power-framework-dm Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com --- Changes V2: - pmic uclass: adjust uclass code to the mainline changes - pmic uclass: remove pmic_i2c and pmic_spi - pmic uclass: modify pmic_platdata - pmic uclass: add pmic_if_* functions - pmic uclass: remove pmic_init_dm() - pmic uclass: cleanup - pmic.h: define pmic ops structure (read/write operations) - pmic.h: add comments to functions --- drivers/power/Makefile | 1 + drivers/power/pmic-uclass.c | 191 +++ include/dm/uclass-id.h | 3 + include/power/pmic.h| 265 4 files changed, 460 insertions(+) create mode 100644 drivers/power/pmic-uclass.c This should have a Kconfig file. diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 2145652..5c9a189 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -21,3 +21,4 @@ obj-$(CONFIG_DIALOG_POWER) += power_dialog.o obj-$(CONFIG_POWER_FSL) += power_fsl.o obj-$(CONFIG_POWER_I2C) += power_i2c.o obj-$(CONFIG_POWER_SPI) += power_spi.o +obj-$(CONFIG_DM_PMIC) += pmic-uclass.o diff --git a/drivers/power/pmic-uclass.c b/drivers/power/pmic-uclass.c new file mode 100644 index 000..309463e --- /dev/null +++ b/drivers/power/pmic-uclass.c @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2014-2015 Samsung Electronics + * Przemyslaw Marczak p.marc...@samsung.com + * + * SPDX-License-Identifier:GPL-2.0+ + */ +#include common.h +#include linux/types.h +#include fdtdec.h +#include dm.h +#include power/pmic.h +#include dm/device-internal.h +#include dm/uclass-internal.h +#include dm/root.h +#include dm/lists.h +#include compiler.h +#include errno.h + +DECLARE_GLOBAL_DATA_PTR; + +static char * const pmic_interfaces[] = { + I2C, + SPI, + --, +}; + +const char *pmic_if_str(struct udevice *pmic) +{ + int if_types = ARRAY_SIZE(pmic_interfaces); + int if_type; + + if_type = pmic_if_type(pmic); + if (if_type 0 || if_type = if_types) + return pmic_interfaces[if_types - 1]; + + return pmic_interfaces[if_type]; +} + +int pmic_if_type(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_type; +} + +int pmic_if_bus_num(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_bus_num; +} + +int pmic_if_addr_cs(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_addr_cs; +} + +int pmic_if_max_offset(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_max_offset; +} + +int pmic_read(struct udevice *pmic, unsigned reg, unsigned char *val) +{ + const struct dm_pmic_ops *ops; + + ops = pmic_get_uclass_ops(pmic, UCLASS_PMIC); + if (!ops) + return -ENODEV; + + if (!ops-read) + return -EPERM; + + if (ops-read(pmic, reg, val)) + return -EIO; + + return 0; +} + +int pmic_write(struct udevice *pmic, unsigned reg, unsigned char val) +{ +
[U-Boot] [PATCH v2 03/12] dm: pmic: add implementation of driver model pmic uclass
This is an introduction to driver-model multi uclass PMIC support. It starts with UCLASS_PMIC - a common PMIC devices uclass type to provide device read/write operations only. Beside two basic operations the pmic platform data is introduced, which provides basic informations about the pmic device I/O interface and is shared with all childs (and should also for childs new uclass types in the future). Usually PMIC devices provides various functionalities with single or multiple I/O interfaces. Using this new framework and new uclass types introduced in the future, it can be handle like this: _ root device | |_ BUS 0 device (e.g. I2C0)- UCLASS_I2C/SPI/... | |_ PMIC device 1 (read/write ops)- UCLASS_PMIC | |_ REGULATOR device (ldo/buck/... ops) - UCLASS_REGULATOR | |_ CHARGER device (charger ops)- UCLASS_CHARGER (in the future) | |_ MUIC device (microUSB con ops) - UCLASS_MUIC(in the future) | |_ ... | |_ BUS 1 device (e.g. I2C1)- UCLASS_I2C/SPI/... |_ PMIC device 2 (read/write ops)- UCLASS_PMIC |_ RTC device (rtc ops)- UCLASS_MUIC (in the future) For each PMIC device interface, new UCLASS_PMIC device is bind with proper pmic driver, and it's child devices provides some specified operations. All new definitions can be found in file: - 'include/power/pmic.h' Uclass file: - pmic-uclass.c - provides a common code for UCLASS_PMIC device drivers The old pmic framework is still kept and is independent. Changes: - new uclass-id: UCLASS_PMIC - new config: CONFIG_DM_PMIC New pmic api is documented in: doc/README.power-framework-dm Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com --- Changes V2: - pmic uclass: adjust uclass code to the mainline changes - pmic uclass: remove pmic_i2c and pmic_spi - pmic uclass: modify pmic_platdata - pmic uclass: add pmic_if_* functions - pmic uclass: remove pmic_init_dm() - pmic uclass: cleanup - pmic.h: define pmic ops structure (read/write operations) - pmic.h: add comments to functions --- drivers/power/Makefile | 1 + drivers/power/pmic-uclass.c | 191 +++ include/dm/uclass-id.h | 3 + include/power/pmic.h| 265 4 files changed, 460 insertions(+) create mode 100644 drivers/power/pmic-uclass.c diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 2145652..5c9a189 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -21,3 +21,4 @@ obj-$(CONFIG_DIALOG_POWER) += power_dialog.o obj-$(CONFIG_POWER_FSL) += power_fsl.o obj-$(CONFIG_POWER_I2C) += power_i2c.o obj-$(CONFIG_POWER_SPI) += power_spi.o +obj-$(CONFIG_DM_PMIC) += pmic-uclass.o diff --git a/drivers/power/pmic-uclass.c b/drivers/power/pmic-uclass.c new file mode 100644 index 000..309463e --- /dev/null +++ b/drivers/power/pmic-uclass.c @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2014-2015 Samsung Electronics + * Przemyslaw Marczak p.marc...@samsung.com + * + * SPDX-License-Identifier:GPL-2.0+ + */ +#include common.h +#include linux/types.h +#include fdtdec.h +#include dm.h +#include power/pmic.h +#include dm/device-internal.h +#include dm/uclass-internal.h +#include dm/root.h +#include dm/lists.h +#include compiler.h +#include errno.h + +DECLARE_GLOBAL_DATA_PTR; + +static char * const pmic_interfaces[] = { + I2C, + SPI, + --, +}; + +const char *pmic_if_str(struct udevice *pmic) +{ + int if_types = ARRAY_SIZE(pmic_interfaces); + int if_type; + + if_type = pmic_if_type(pmic); + if (if_type 0 || if_type = if_types) + return pmic_interfaces[if_types - 1]; + + return pmic_interfaces[if_type]; +} + +int pmic_if_type(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_type; +} + +int pmic_if_bus_num(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_bus_num; +} + +int pmic_if_addr_cs(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_addr_cs; +} + +int pmic_if_max_offset(struct udevice *pmic) +{ + struct pmic_platdata *pl = pmic-platdata; + + return pl-if_max_offset; +} + +int pmic_read(struct udevice *pmic, unsigned reg, unsigned char *val) +{ + const struct dm_pmic_ops *ops; + + ops = pmic_get_uclass_ops(pmic, UCLASS_PMIC); + if (!ops) + return -ENODEV; + + if (!ops-read) + return -EPERM; + + if (ops-read(pmic, reg, val)) + return -EIO; + + return 0; +} + +int pmic_write(struct udevice *pmic, unsigned reg, unsigned char val) +{ + const struct dm_pmic_ops *ops; + + ops = pmic_get_uclass_ops(pmic, UCLASS_PMIC); + if (!ops) + return -ENODEV; + + if (!ops-write) + return -EPERM; + + if (ops-write(pmic, reg, val)) + return -EIO; + + return