aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/media/video/se401.h
blob: bf7d2e9765b0dee82c8ecb88c68e0cf6c29ed095 (plain) (tree)
1
2
3
4
5
6
7
8
9



                       
                          
                           
                              
                             
                        




                                                    

                                                                     
     
                                                     


































































































































































                                                                                
 











                                                       
                          








                                                                  
 



                                                             
                                                  

























                                                       

#ifndef __LINUX_se401_H
#define __LINUX_se401_H

#include <linux/uaccess.h>
#include <linux/videodev.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include <linux/mutex.h>

#define se401_DEBUG	/* Turn on debug messages */

#ifdef se401_DEBUG
#  define PDEBUG(level, fmt, args...) \
if (debug >= level) \
	info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args)
#else
#  define PDEBUG(level, fmt, args...) do {} while (0)
#endif

/* An almost drop-in replacement for sleep_on_interruptible */
#define wait_interruptible(test, queue, wait) \
{ \
	add_wait_queue(queue, wait); \
	set_current_state(TASK_INTERRUPTIBLE); \
	if (test) \
		schedule(); \
	remove_wait_queue(queue, wait); \
	set_current_state(TASK_RUNNING); \
	if (signal_pending(current)) \
		break; \
}

#define SE401_REQ_GET_CAMERA_DESCRIPTOR		0x06
#define SE401_REQ_START_CONTINUOUS_CAPTURE	0x41
#define SE401_REQ_STOP_CONTINUOUS_CAPTURE	0x42
#define SE401_REQ_CAPTURE_FRAME			0x43
#define SE401_REQ_GET_BRT			0x44
#define SE401_REQ_SET_BRT			0x45
#define SE401_REQ_GET_WIDTH			0x4c
#define SE401_REQ_SET_WIDTH			0x4d
#define SE401_REQ_GET_HEIGHT			0x4e
#define SE401_REQ_SET_HEIGHT			0x4f
#define SE401_REQ_GET_OUTPUT_MODE		0x50
#define SE401_REQ_SET_OUTPUT_MODE		0x51
#define SE401_REQ_GET_EXT_FEATURE		0x52
#define SE401_REQ_SET_EXT_FEATURE		0x53
#define SE401_REQ_CAMERA_POWER			0x56
#define SE401_REQ_LED_CONTROL			0x57
#define SE401_REQ_BIOS				0xff

#define SE401_BIOS_READ				0x07

#define SE401_FORMAT_BAYER	0x40

/* Hyundai hv7131b registers
   7121 and 7141 should be the same (haven't really checked...) */
/* Mode registers: */
#define HV7131_REG_MODE_A		0x00
#define HV7131_REG_MODE_B		0x01
#define HV7131_REG_MODE_C		0x02
/* Frame registers: */
#define HV7131_REG_FRSU		0x10
#define HV7131_REG_FRSL		0x11
#define HV7131_REG_FCSU		0x12
#define HV7131_REG_FCSL		0x13
#define HV7131_REG_FWHU		0x14
#define HV7131_REG_FWHL		0x15
#define HV7131_REG_FWWU		0x16
#define HV7131_REG_FWWL		0x17
/* Timing registers: */
#define HV7131_REG_THBU		0x20
#define HV7131_REG_THBL		0x21
#define HV7131_REG_TVBU		0x22
#define HV7131_REG_TVBL		0x23
#define HV7131_REG_TITU		0x25
#define HV7131_REG_TITM		0x26
#define HV7131_REG_TITL		0x27
#define HV7131_REG_TMCD		0x28
/* Adjust Registers: */
#define HV7131_REG_ARLV		0x30
#define HV7131_REG_ARCG		0x31
#define HV7131_REG_AGCG		0x32
#define HV7131_REG_ABCG		0x33
#define HV7131_REG_APBV		0x34
#define HV7131_REG_ASLP		0x54
/* Offset Registers: */
#define HV7131_REG_OFSR		0x50
#define HV7131_REG_OFSG		0x51
#define HV7131_REG_OFSB		0x52
/* REset level statistics registers: */
#define HV7131_REG_LOREFNOH	0x57
#define HV7131_REG_LOREFNOL	0x58
#define HV7131_REG_HIREFNOH	0x59
#define HV7131_REG_HIREFNOL	0x5a

/* se401 registers */
#define SE401_OPERATINGMODE	0x2000


/* size of usb transfers */
#define SE401_PACKETSIZE	4096
/* number of queued bulk transfers to use, should be about 8 */
#define SE401_NUMSBUF		1
/* read the usb specs for this one :) */
#define SE401_VIDEO_ENDPOINT	1
#define SE401_BUTTON_ENDPOINT	2
/* number of frames supported by the v4l part */
#define SE401_NUMFRAMES		2
/* scratch buffers for passing data to the decoders */
#define SE401_NUMSCRATCH	32
/* maximum amount of data in a JangGu packet */
#define SE401_VLCDATALEN	1024
/* number of nul sized packets to receive before kicking the camera */
#define SE401_MAX_NULLPACKETS	4000
/* number of decoding errors before kicking the camera */
#define SE401_MAX_ERRORS	200

struct usb_device;

struct se401_sbuf {
	unsigned char *data;
};

enum {
	FRAME_UNUSED,		/* Unused (no MCAPTURE) */
	FRAME_READY,		/* Ready to start grabbing */
	FRAME_GRABBING,		/* In the process of being grabbed into */
	FRAME_DONE,		/* Finished grabbing, but not been synced yet */
	FRAME_ERROR,		/* Something bad happened while processing */
};

enum {
	FMT_BAYER,
	FMT_JANGGU,
};

enum {
	BUFFER_UNUSED,
	BUFFER_READY,
	BUFFER_BUSY,
	BUFFER_DONE,
};

struct se401_scratch {
	unsigned char *data;
	volatile int state;
	int offset;
	int length;
};

struct se401_frame {
	unsigned char *data;		/* Frame buffer */

	volatile int grabstate;	/* State of grabbing */

	unsigned char *curline;
	int curlinepix;
	int curpix;
};

struct usb_se401 {
	struct video_device vdev;

	/* Device structure */
	struct usb_device *dev;

	unsigned char iface;

	char *camera_name;

	int change;
	int brightness;
	int hue;
	int rgain;
	int ggain;
	int bgain;
	int expose_h;
	int expose_m;
	int expose_l;
	int resetlevel;

	int enhance;

	int format;
	int sizes;
	int *width;
	int *height;
	int cwidth;		/* current width */
	int cheight;		/* current height */
	int palette;
	int maxframesize;
	int cframesize;		/* current framesize */

	struct mutex lock;
	int user;		/* user count for exclusive use */
	int removed;		/* device disconnected */

	int streaming;		/* Are we streaming video? */

	char *fbuf;		/* Videodev buffer area */

	struct urb *urb[SE401_NUMSBUF];
	struct urb *inturb;

	int button;
	int buttonpressed;

	int curframe;		/* Current receiving frame */
	struct se401_frame frame[SE401_NUMFRAMES];
	int readcount;
	int framecount;
	int error;
	int dropped;

	int scratch_next;
	int scratch_use;
	int scratch_overflow;
	struct se401_scratch scratch[SE401_NUMSCRATCH];

	/* Decoder specific data: */
	unsigned char vlcdata[SE401_VLCDATALEN];
	int vlcdatapos;
	int bayeroffset;

	struct se401_sbuf sbuf[SE401_NUMSBUF];

	wait_queue_head_t wq;	/* Processes waiting */

	int nullpackets;
};



#endif

vsel = 0; else if (min_uV < 1700000) vsel = ((min_uV - 900000) / 50000); else vsel = ((min_uV - 1700000) / 100000) + WM831X_GP_LDO_SELECTOR_LOW + 1; volt = wm831x_gp_ldo_list_voltage(rdev, vsel); if (volt < min_uV || volt > max_uV) return -EINVAL; return vsel; } static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV); if (sel < 0) return sel; return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel); } static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int ctrl_reg = ldo->base + WM831X_LDO_CONTROL; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, on_reg); if (ret < 0) return ret; if (!(ret & WM831X_LDO1_ON_MODE)) return REGULATOR_MODE_NORMAL; ret = wm831x_reg_read(wm831x, ctrl_reg); if (ret < 0) return ret; if (ret & WM831X_LDO1_LP_MODE) return REGULATOR_MODE_STANDBY; else return REGULATOR_MODE_IDLE; } static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int ctrl_reg = ldo->base + WM831X_LDO_CONTROL; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; switch (mode) { case REGULATOR_MODE_NORMAL: ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO1_ON_MODE, 0); if (ret < 0) return ret; break; case REGULATOR_MODE_IDLE: ret = wm831x_set_bits(wm831x, ctrl_reg, WM831X_LDO1_LP_MODE, 0); if (ret < 0) return ret; ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO1_ON_MODE, WM831X_LDO1_ON_MODE); if (ret < 0) return ret; break; case REGULATOR_MODE_STANDBY: ret = wm831x_set_bits(wm831x, ctrl_reg, WM831X_LDO1_LP_MODE, WM831X_LDO1_LP_MODE); if (ret < 0) return ret; ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO1_ON_MODE, WM831X_LDO1_ON_MODE); if (ret < 0) return ret; break; default: return -EINVAL; } return 0; } static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int ret; /* Is the regulator on? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); if (ret < 0) return ret; if (!(ret & mask)) return REGULATOR_STATUS_OFF; /* Is it reporting under voltage? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); if (ret & mask) return REGULATOR_STATUS_ERROR; ret = wm831x_gp_ldo_get_mode(rdev); if (ret < 0) return ret; else return regulator_mode_to_status(ret); } static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, int input_uV, int output_uV, int load_uA) { if (load_uA < 20000) return REGULATOR_MODE_STANDBY; if (load_uA < 50000) return REGULATOR_MODE_IDLE; return REGULATOR_MODE_NORMAL; } static struct regulator_ops wm831x_gp_ldo_ops = { .list_voltage = wm831x_gp_ldo_list_voltage, .map_voltage = wm831x_gp_ldo_map_voltage, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, .get_mode = wm831x_gp_ldo_get_mode, .set_mode = wm831x_gp_ldo_set_mode, .get_status = wm831x_gp_ldo_get_status, .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, }; static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) { struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); struct wm831x_pdata *pdata = wm831x->dev->platform_data; struct regulator_config config = { }; int id; struct wm831x_ldo *ldo; struct resource *res; int ret, irq; if (pdata && pdata->wm831x_num) id = (pdata->wm831x_num * 10) + 1; else id = 0; id = pdev->id - id; dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; } ldo->wm831x = wm831x; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (res == NULL) { dev_err(&pdev->dev, "No I/O resource\n"); ret = -EINVAL; goto err; } ldo->base = res->start; snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); ldo->desc.name = ldo->name; snprintf(ldo->supply_name, sizeof(ldo->supply_name), "LDO%dVDD", id + 1); ldo->desc.supply_name = ldo->supply_name; ldo->desc.id = id; ldo->desc.type = REGULATOR_VOLTAGE; ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; ldo->desc.ops = &wm831x_gp_ldo_ops; ldo->desc.owner = THIS_MODULE; ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK; ldo->desc.enable_reg = WM831X_LDO_ENABLE; ldo->desc.enable_mask = 1 << id; config.dev = pdev->dev.parent; if (pdata) config.init_data = pdata->ldo[id]; config.driver_data = ldo; config.regmap = wm831x->regmap; ldo->regulator = regulator_register(&ldo->desc, &config); if (IS_ERR(ldo->regulator)) { ret = PTR_ERR(ldo->regulator); dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", id + 1, ret); goto err; } irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, IRQF_TRIGGER_RISING, ldo->name, ldo); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); goto err_regulator; } platform_set_drvdata(pdev, ldo); return 0; err_regulator: regulator_unregister(ldo->regulator); err: return ret; } static __devexit int wm831x_gp_ldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")), ldo); regulator_unregister(ldo->regulator); return 0; } static struct platform_driver wm831x_gp_ldo_driver = { .probe = wm831x_gp_ldo_probe, .remove = __devexit_p(wm831x_gp_ldo_remove), .driver = { .name = "wm831x-ldo", .owner = THIS_MODULE, }, }; /* * Analogue LDOs */ #define WM831X_ALDO_SELECTOR_LOW 0xc #define WM831X_ALDO_MAX_SELECTOR 0x1f static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, unsigned int selector) { /* 1-1.6V in 50mV steps */ if (selector <= WM831X_ALDO_SELECTOR_LOW) return 1000000 + (selector * 50000); /* 1.7-3.5V in 100mV steps */ if (selector <= WM831X_ALDO_MAX_SELECTOR) return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW) * 100000); return -EINVAL; } static int wm831x_aldo_map_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) { int volt, vsel; if (min_uV < 1000000) vsel = 0; else if (min_uV < 1700000) vsel = ((min_uV - 1000000) / 50000); else vsel = ((min_uV - 1700000) / 100000) + WM831X_ALDO_SELECTOR_LOW + 1; volt = wm831x_aldo_list_voltage(rdev, vsel); if (volt < min_uV || volt > max_uV) return -EINVAL; return vsel; } static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; sel = wm831x_aldo_map_voltage(rdev, uV, uV); if (sel < 0) return sel; return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel); } static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, on_reg); if (ret < 0) return 0; if (ret & WM831X_LDO7_ON_MODE) return REGULATOR_MODE_IDLE; else return REGULATOR_MODE_NORMAL; } static int wm831x_aldo_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; switch (mode) { case REGULATOR_MODE_NORMAL: ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0); if (ret < 0) return ret; break; case REGULATOR_MODE_IDLE: ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, WM831X_LDO7_ON_MODE); if (ret < 0) return ret; break; default: return -EINVAL; } return 0; } static int wm831x_aldo_get_status(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int ret; /* Is the regulator on? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); if (ret < 0) return ret; if (!(ret & mask)) return REGULATOR_STATUS_OFF; /* Is it reporting under voltage? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); if (ret & mask) return REGULATOR_STATUS_ERROR; ret = wm831x_aldo_get_mode(rdev); if (ret < 0) return ret; else return regulator_mode_to_status(ret); } static struct regulator_ops wm831x_aldo_ops = { .list_voltage = wm831x_aldo_list_voltage, .map_voltage = wm831x_aldo_map_voltage, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, .get_mode = wm831x_aldo_get_mode, .set_mode = wm831x_aldo_set_mode, .get_status = wm831x_aldo_get_status, .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, }; static __devinit int wm831x_aldo_probe(struct platform_device *pdev) { struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); struct wm831x_pdata *pdata = wm831x->dev->platform_data; struct regulator_config config = { }; int id; struct wm831x_ldo *ldo; struct resource *res; int ret, irq; if (pdata && pdata->wm831x_num) id = (pdata->wm831x_num * 10) + 1; else id = 0; id = pdev->id - id; dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; } ldo->wm831x = wm831x; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (res == NULL) { dev_err(&pdev->dev, "No I/O resource\n"); ret = -EINVAL; goto err; } ldo->base = res->start; snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); ldo->desc.name = ldo->name; snprintf(ldo->supply_name, sizeof(ldo->supply_name), "LDO%dVDD", id + 1); ldo->desc.supply_name = ldo->supply_name; ldo->desc.id = id; ldo->desc.type = REGULATOR_VOLTAGE; ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; ldo->desc.ops = &wm831x_aldo_ops; ldo->desc.owner = THIS_MODULE; ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; ldo->desc.enable_reg = WM831X_LDO_ENABLE; ldo->desc.enable_mask = 1 << id; config.dev = pdev->dev.parent; if (pdata) config.init_data = pdata->ldo[id]; config.driver_data = ldo; config.regmap = wm831x->regmap; ldo->regulator = regulator_register(&ldo->desc, &config); if (IS_ERR(ldo->regulator)) { ret = PTR_ERR(ldo->regulator); dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", id + 1, ret); goto err; } irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, IRQF_TRIGGER_RISING, ldo->name, ldo); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); goto err_regulator; } platform_set_drvdata(pdev, ldo); return 0; err_regulator: regulator_unregister(ldo->regulator); err: return ret; } static __devexit int wm831x_aldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev); free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")), ldo); regulator_unregister(ldo->regulator); return 0; } static struct platform_driver wm831x_aldo_driver = { .probe = wm831x_aldo_probe, .remove = __devexit_p(wm831x_aldo_remove), .driver = { .name = "wm831x-aldo", .owner = THIS_MODULE, }, }; /* * Alive LDO */ #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; sel = regulator_map_voltage_linear(rdev, uV, uV); if (sel < 0) return sel; return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel); } static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int ret; /* Is the regulator on? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); if (ret < 0) return ret; if (ret & mask) return REGULATOR_STATUS_ON; else return REGULATOR_STATUS_OFF; } static struct regulator_ops wm831x_alive_ldo_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, .get_status = wm831x_alive_ldo_get_status, .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, }; static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) { struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); struct wm831x_pdata *pdata = wm831x->dev->platform_data; struct regulator_config config = { }; int id; struct wm831x_ldo *ldo; struct resource *res; int ret; if (pdata && pdata->wm831x_num) id = (pdata->wm831x_num * 10) + 1; else id = 0; id = pdev->id - id; dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; } ldo->wm831x = wm831x; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (res == NULL) { dev_err(&pdev->dev, "No I/O resource\n"); ret = -EINVAL; goto err; } ldo->base = res->start; snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); ldo->desc.name = ldo->name; snprintf(ldo->supply_name, sizeof(ldo->supply_name), "LDO%dVDD", id + 1); ldo->desc.supply_name = ldo->supply_name; ldo->desc.id = id; ldo->desc.type = REGULATOR_VOLTAGE; ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1; ldo->desc.ops = &wm831x_alive_ldo_ops; ldo->desc.owner = THIS_MODULE; ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK; ldo->desc.enable_reg = WM831X_LDO_ENABLE; ldo->desc.enable_mask = 1 << id; ldo->desc.min_uV = 800000; ldo->desc.uV_step = 50000; config.dev = pdev->dev.parent; if (pdata) config.init_data = pdata->ldo[id]; config.driver_data = ldo; config.regmap = wm831x->regmap; ldo->regulator = regulator_register(&ldo->desc, &config); if (IS_ERR(ldo->regulator)) { ret = PTR_ERR(ldo->regulator); dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", id + 1, ret); goto err; } platform_set_drvdata(pdev, ldo); return 0; err: return ret; } static __devexit int wm831x_alive_ldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev); regulator_unregister(ldo->regulator); return 0; } static struct platform_driver wm831x_alive_ldo_driver = { .probe = wm831x_alive_ldo_probe, .remove = __devexit_p(wm831x_alive_ldo_remove), .driver = { .name = "wm831x-alive-ldo", .owner = THIS_MODULE, }, }; static int __init wm831x_ldo_init(void) { int ret; ret = platform_driver_register(&wm831x_gp_ldo_driver); if (ret != 0) pr_err("Failed to register WM831x GP LDO driver: %d\n", ret); ret = platform_driver_register(&wm831x_aldo_driver); if (ret != 0) pr_err("Failed to register WM831x ALDO driver: %d\n", ret); ret = platform_driver_register(&wm831x_alive_ldo_driver); if (ret != 0) pr_err("Failed to register WM831x alive LDO driver: %d\n", ret); return 0; } subsys_initcall(wm831x_ldo_init); static void __exit wm831x_ldo_exit(void) { platform_driver_unregister(&wm831x_alive_ldo_driver); platform_driver_unregister(&wm831x_aldo_driver); platform_driver_unregister(&wm831x_gp_ldo_driver); } module_exit(wm831x_ldo_exit); /* Module information */ MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); MODULE_DESCRIPTION("WM831x LDO driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:wm831x-ldo"); MODULE_ALIAS("platform:wm831x-aldo"); MODULE_ALIAS("platform:wm831x-aliveldo");