1a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 2a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * drivers/i2c/chips/lm8323.c 3a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 4a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Copyright (C) 2007-2009 Nokia Corporation 5a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 6a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Written by Daniel Stone <daniel.stone@nokia.com> 7a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Timo O. Karjalainen <timo.o.karjalainen@nokia.com> 8a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 9a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Updated by Felipe Balbi <felipe.balbi@nokia.com> 10a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 11a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * This program is free software; you can redistribute it and/or modify 12a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * it under the terms of the GNU General Public License as published by 13a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * the Free Software Foundation (version 2 of the License only). 14a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 15a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * This program is distributed in the hope that it will be useful, 16a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * but WITHOUT ANY WARRANTY; without even the implied warranty of 17a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * GNU General Public License for more details. 19a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 20a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * You should have received a copy of the GNU General Public License 21a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * along with this program; if not, write to the Free Software 22a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 24a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 25a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/module.h> 26a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/i2c.h> 27a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/interrupt.h> 28a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/sched.h> 29a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/mutex.h> 30a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/delay.h> 31a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/input.h> 32a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/leds.h> 3365b0c03852d75e4d7d0bc282344b1500fe471725Mark Brown#include <linux/pm.h> 34a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#include <linux/i2c/lm8323.h> 355a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 36a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 37a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Commands to send to the chip. */ 38a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_ID 0x80 /* Read chip ID. */ 39a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_WRITE_CFG 0x81 /* Set configuration item. */ 40a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_INT 0x82 /* Get interrupt status. */ 41a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_RESET 0x83 /* Reset, same as external one */ 42a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_WRITE_PORT_SEL 0x85 /* Set GPIO in/out. */ 43a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_WRITE_PORT_STATE 0x86 /* Set GPIO pullup. */ 44a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_PORT_SEL 0x87 /* Get GPIO in/out. */ 45a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_PORT_STATE 0x88 /* Get GPIO pullup. */ 46a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_FIFO 0x89 /* Read byte from FIFO. */ 47a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_RPT_READ_FIFO 0x8a /* Read FIFO (no increment). */ 48a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_SET_ACTIVE 0x8b /* Set active time. */ 49a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_ERR 0x8c /* Get error status. */ 50a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_ROTATOR 0x8e /* Read rotator status. */ 51a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_SET_DEBOUNCE 0x8f /* Set debouncing time. */ 52a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_SET_KEY_SIZE 0x90 /* Set keypad size. */ 53a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_KEY_SIZE 0x91 /* Get keypad size. */ 54a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_CFG 0x92 /* Get configuration item. */ 55a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_WRITE_CLOCK 0x93 /* Set clock config. */ 56a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_READ_CLOCK 0x94 /* Get clock config. */ 57a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_PWM_WRITE 0x95 /* Write PWM script. */ 58a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_START_PWM 0x96 /* Start PWM engine. */ 59a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_CMD_STOP_PWM 0x97 /* Stop PWM engine. */ 60a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 61a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Interrupt status. */ 62a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_KEYPAD 0x01 /* Key event. */ 63a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_ROTATOR 0x02 /* Rotator event. */ 64a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_ERROR 0x08 /* Error: use CMD_READ_ERR. */ 65a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_NOINIT 0x10 /* Lost configuration. */ 66a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_PWM1 0x20 /* PWM1 stopped. */ 67a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_PWM2 0x40 /* PWM2 stopped. */ 68a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define INT_PWM3 0x80 /* PWM3 stopped. */ 69a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 70a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Errors (signalled by INT_ERROR, read with CMD_READ_ERR). */ 71a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define ERR_BADPAR 0x01 /* Bad parameter. */ 72a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define ERR_CMDUNK 0x02 /* Unknown command. */ 73a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define ERR_KEYOVR 0x04 /* Too many keys pressed. */ 74a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define ERR_FIFOOVER 0x40 /* FIFO overflow. */ 75a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 76a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Configuration keys (CMD_{WRITE,READ}_CFG). */ 77a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CFG_MUX1SEL 0x01 /* Select MUX1_OUT input. */ 78a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CFG_MUX1EN 0x02 /* Enable MUX1_OUT. */ 79a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CFG_MUX2SEL 0x04 /* Select MUX2_OUT input. */ 80a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CFG_MUX2EN 0x08 /* Enable MUX2_OUT. */ 81a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CFG_PSIZE 0x20 /* Package size (must be 0). */ 82a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CFG_ROTEN 0x40 /* Enable rotator. */ 83a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 84a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Clock settings (CMD_{WRITE,READ}_CLOCK). */ 85a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CLK_RCPWM_INTERNAL 0x00 86a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CLK_RCPWM_EXTERNAL 0x03 87a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CLK_SLOWCLKEN 0x08 /* Enable 32.768kHz clock. */ 88a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define CLK_SLOWCLKOUT 0x40 /* Enable slow pulse output. */ 89a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 90a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* The possible addresses corresponding to CONFIG1 and CONFIG2 pin wirings. */ 91a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_I2C_ADDR00 (0x84 >> 1) /* 1000 010x */ 92a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_I2C_ADDR01 (0x86 >> 1) /* 1000 011x */ 93a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_I2C_ADDR10 (0x88 >> 1) /* 1000 100x */ 94a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_I2C_ADDR11 (0x8A >> 1) /* 1000 101x */ 95a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 96a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Key event fifo length */ 97a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_FIFO_LEN 15 98a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 99a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Commands for PWM engine; feed in with PWM_WRITE. */ 100a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Load ramp counter from duty cycle field (range 0 - 0xff). */ 101a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_SET(v) (0x4000 | ((v) & 0xff)) 102a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Go to start of script. */ 103a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_GOTOSTART 0x0000 104a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 105a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Stop engine (generates interrupt). If reset is 1, clear the program 106a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * counter, else leave it. 107a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 108a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_END(reset) (0xc000 | (!!(reset) << 11)) 109a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 110a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Ramp. If s is 1, divide clock by 512, else divide clock by 16. 111a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Take t clock scales (up to 63) per step, for n steps (up to 126). 112a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * If u is set, ramp up, else ramp down. 113a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 114a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_RAMP(s, t, n, u) ((!!(s) << 14) | ((t) & 0x3f) << 8 | \ 115a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ((n) & 0x7f) | ((u) ? 0 : 0x80)) 116a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 117a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Loop (i.e. jump back to pos) for a given number of iterations (up to 63). 118a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * If cnt is zero, execute until PWM_END is encountered. 119a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 120a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_LOOP(cnt, pos) (0xa000 | (((cnt) & 0x3f) << 7) | \ 121a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ((pos) & 0x3f)) 122a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 123a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Wait for trigger. Argument is a mask of channels, shifted by the channel 124a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * number, e.g. 0xa for channels 3 and 1. Note that channels are numbered 125a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * from 1, not 0. 126a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 127a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_WAIT_TRIG(chans) (0xe000 | (((chans) & 0x7) << 6)) 128a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* Send trigger. Argument is same as PWM_WAIT_TRIG. */ 129a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define PWM_SEND_TRIG(chans) (0xe000 | ((chans) & 0x7)) 130a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 131a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistruct lm8323_pwm { 132a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int id; 133a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int fade_time; 134a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int brightness; 135a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int desired_brightness; 136a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi bool enabled; 137a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi bool running; 138a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* pwm lock */ 139a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct mutex lock; 140a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct work_struct work; 141a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct led_classdev cdev; 142a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *chip; 143a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi}; 144a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 145a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistruct lm8323_chip { 146a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* device lock */ 147a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct mutex lock; 148a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct i2c_client *client; 149a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct input_dev *idev; 150a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi bool kp_enabled; 151a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi bool pm_suspend; 152a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi unsigned keys_down; 153a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi char phys[32]; 154a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi unsigned short keymap[LM8323_KEYMAP_SIZE]; 155a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int size_x; 156a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int size_y; 157a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int debounce_time; 158a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int active_time; 159a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_pwm pwm[LM8323_NUM_PWMS]; 160a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi}; 161a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 162a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define client_to_lm8323(c) container_of(c, struct lm8323_chip, client) 163a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define dev_to_lm8323(d) container_of(d, struct lm8323_chip, client->dev) 164a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define cdev_to_pwm(c) container_of(c, struct lm8323_pwm, cdev) 165a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define work_to_pwm(w) container_of(w, struct lm8323_pwm, work) 166a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 167a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#define LM8323_MAX_DATA 8 168a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 169a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 170a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * To write, we just access the chip's address in write mode, and dump the 171a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * command and data out on the bus. The command byte and data are taken as 172a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * sequential u8s out of varargs, to a maximum of LM8323_MAX_DATA. 173a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 174a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic int lm8323_write(struct lm8323_chip *lm, int len, ...) 175a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 176a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int ret, i; 177a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi va_list ap; 178a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 data[LM8323_MAX_DATA]; 179a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 180a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi va_start(ap, len); 181a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 182a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(len > LM8323_MAX_DATA)) { 183a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&lm->client->dev, "tried to send %d bytes\n", len); 184a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi va_end(ap); 185a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 186a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 187a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 188a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < len; i++) 189a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi data[i] = va_arg(ap, int); 190a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 191a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi va_end(ap); 192a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 193a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 194a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * If the host is asleep while we send the data, we can get a NACK 195a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * back while it wakes up, so try again, once. 196a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 197a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ret = i2c_master_send(lm->client, data, len); 198a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(ret == -EREMOTEIO)) 199a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ret = i2c_master_send(lm->client, data, len); 200a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(ret != len)) 201a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&lm->client->dev, "sent %d bytes of %d total\n", 202a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi len, ret); 203a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 204a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return ret; 205a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 206a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 207a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 208a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * To read, we first send the command byte to the chip and end the transaction, 209a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * then access the chip in read mode, at which point it will send the data. 210a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 211a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic int lm8323_read(struct lm8323_chip *lm, u8 cmd, u8 *buf, int len) 212a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 213a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int ret; 214a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 215a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 216a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * If the host is asleep while we send the byte, we can get a NACK 217a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * back while it wakes up, so try again, once. 218a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 219a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ret = i2c_master_send(lm->client, &cmd, 1); 220a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(ret == -EREMOTEIO)) 221a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ret = i2c_master_send(lm->client, &cmd, 1); 222a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(ret != 1)) { 223a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&lm->client->dev, "sending read cmd 0x%02x failed\n", 224a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi cmd); 225a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 226a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 227a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 228a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ret = i2c_master_recv(lm->client, buf, len); 229a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(ret != len)) 230a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&lm->client->dev, "wanted %d bytes, got %d\n", 231a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi len, ret); 232a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 233a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return ret; 234a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 235a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 236a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 237a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Set the chip active time (idle time before it enters halt). 238a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 239a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_set_active_time(struct lm8323_chip *lm, int time) 240a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 241a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 2, LM8323_CMD_SET_ACTIVE, time >> 2); 242a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 243a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 244a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 245a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * The signals are AT-style: the low 7 bits are the keycode, and the top 246a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * bit indicates the state (1 for down, 0 for up). 247a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 248a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic inline u8 lm8323_whichkey(u8 event) 249a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 250a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return event & 0x7f; 251a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 252a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 253a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic inline int lm8323_ispress(u8 event) 254a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 255a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return (event & 0x80) ? 1 : 0; 256a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 257a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 258a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void process_keys(struct lm8323_chip *lm) 259a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 260a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 event; 261a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 key_fifo[LM8323_FIFO_LEN + 1]; 262a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int old_keys_down = lm->keys_down; 263a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int ret; 264a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i = 0; 265a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 266a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 267a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Read all key events from the FIFO at once. Next READ_FIFO clears the 268a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * FIFO even if we didn't read all events previously. 269a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 270a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi ret = lm8323_read(lm, LM8323_CMD_READ_FIFO, key_fifo, LM8323_FIFO_LEN); 271a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 272a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (ret < 0) { 273a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&lm->client->dev, "Failed reading fifo \n"); 274a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return; 275a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 276a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi key_fifo[ret] = 0; 277a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 278a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi while ((event = key_fifo[i++])) { 279a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 key = lm8323_whichkey(event); 280a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int isdown = lm8323_ispress(event); 281a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi unsigned short keycode = lm->keymap[key]; 282a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 283a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, "key 0x%02x %s\n", 284a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi key, isdown ? "down" : "up"); 285a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 286a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (lm->kp_enabled) { 287a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi input_event(lm->idev, EV_MSC, MSC_SCAN, key); 288a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi input_report_key(lm->idev, keycode, isdown); 289a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi input_sync(lm->idev); 290a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 291a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 292a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (isdown) 293a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->keys_down++; 294a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi else 295a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->keys_down--; 296a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 297a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 298a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 299a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Errata: We need to ensure that the chip never enters halt mode 300a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * during a keypress, so set active time to 0. When it's released, 301a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * we can enter halt again, so set the active time back to normal. 302a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 303a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (!old_keys_down && lm->keys_down) 304a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_set_active_time(lm, 0); 305a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (old_keys_down && !lm->keys_down) 306a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_set_active_time(lm, lm->active_time); 307a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 308a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 309a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_process_error(struct lm8323_chip *lm) 310a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 311a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 error; 312a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 313a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (lm8323_read(lm, LM8323_CMD_READ_ERR, &error, 1) == 1) { 314a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (error & ERR_FIFOOVER) 315a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, "fifo overflow!\n"); 316a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (error & ERR_KEYOVR) 317a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, 318a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi "more than two keys pressed\n"); 319a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (error & ERR_CMDUNK) 320a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, 321a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi "unknown command submitted\n"); 322a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (error & ERR_BADPAR) 323a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, "bad command parameter\n"); 324a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 325a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 326a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 327a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_reset(struct lm8323_chip *lm) 328a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 329a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* The docs say we must pass 0xAA as the data byte. */ 330a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 2, LM8323_CMD_RESET, 0xAA); 331a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 332a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 333a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic int lm8323_configure(struct lm8323_chip *lm) 334a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 335a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int keysize = (lm->size_x << 4) | lm->size_y; 336a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int clock = (CLK_SLOWCLKEN | CLK_RCPWM_EXTERNAL); 337a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int debounce = lm->debounce_time >> 2; 338a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int active = lm->active_time >> 2; 339a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 340a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 341a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Active time must be greater than the debounce time: if it's 342a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * a close-run thing, give ourselves a 12ms buffer. 343a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 344a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (debounce >= active) 345a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi active = debounce + 3; 346a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 347a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 2, LM8323_CMD_WRITE_CFG, 0); 348a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 2, LM8323_CMD_WRITE_CLOCK, clock); 349a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 2, LM8323_CMD_SET_KEY_SIZE, keysize); 350a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_set_active_time(lm, lm->active_time); 351a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 2, LM8323_CMD_SET_DEBOUNCE, debounce); 352a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 3, LM8323_CMD_WRITE_PORT_STATE, 0xff, 0xff); 353a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(lm, 3, LM8323_CMD_WRITE_PORT_SEL, 0, 0); 354a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 355a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 356a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Not much we can do about errors at this point, so just hope 357a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * for the best. 358a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 359a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 360a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 361a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 362a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 363a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void pwm_done(struct lm8323_pwm *pwm) 364a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 365a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&pwm->lock); 366a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->running = false; 367a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (pwm->desired_brightness != pwm->brightness) 368a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi schedule_work(&pwm->work); 369a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&pwm->lock); 370a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 371a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 372a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 373a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Bottom half: handle the interrupt by posting key events, or dealing with 374a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * errors appropriately. 375a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 37661cf3813d32411b23d5df8a650bbd2aa89b4618cFelipe Balbistatic irqreturn_t lm8323_irq(int irq, void *_lm) 377a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 37861cf3813d32411b23d5df8a650bbd2aa89b4618cFelipe Balbi struct lm8323_chip *lm = _lm; 379a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 ints; 380a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i; 381a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 382a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&lm->lock); 383a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 384a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi while ((lm8323_read(lm, LM8323_CMD_READ_INT, &ints, 1) == 1) && ints) { 385a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (likely(ints & INT_KEYPAD)) 386a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi process_keys(lm); 387a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (ints & INT_ROTATOR) { 388a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* We don't currently support the rotator. */ 389a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, "rotator fired\n"); 390a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 391a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (ints & INT_ERROR) { 392a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, "error!\n"); 393a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_process_error(lm); 394a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 395a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (ints & INT_NOINIT) { 396a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&lm->client->dev, "chip lost config; " 397a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi "reinitialising\n"); 398a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_configure(lm); 399a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 400a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < LM8323_NUM_PWMS; i++) { 401bec7a4bbecf7da86b6e64bb78d22c92ea1ba4afeNickolai Zeldovich if (ints & (INT_PWM1 << i)) { 402a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&lm->client->dev, 403a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi "pwm%d engine completed\n", i); 404a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm_done(&lm->pwm[i]); 405a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 406a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 407a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 408a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 409a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&lm->lock); 410a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 411a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return IRQ_HANDLED; 412a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 413a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 414a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 415a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Read the chip ID. 416a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 417a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic int lm8323_read_id(struct lm8323_chip *lm, u8 *buf) 418a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 419a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int bytes; 420a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 421a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi bytes = lm8323_read(lm, LM8323_CMD_READ_ID, buf, 2); 422a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (unlikely(bytes != 2)) 423a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return -EIO; 424a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 425a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 426a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 427a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 428a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_write_pwm_one(struct lm8323_pwm *pwm, int pos, u16 cmd) 429a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 430a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(pwm->chip, 4, LM8323_CMD_PWM_WRITE, (pos << 2) | pwm->id, 431a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi (cmd & 0xff00) >> 8, cmd & 0x00ff); 432a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 433a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 434a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 435a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Write a script into a given PWM engine, concluding with PWM_END. 436a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * If 'kill' is nonzero, the engine will be shut down at the end 437a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * of the script, producing a zero output. Otherwise the engine 438a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * will be kept running at the final PWM level indefinitely. 439a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 440a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_write_pwm(struct lm8323_pwm *pwm, int kill, 441a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int len, const u16 *cmds) 442a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 443a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i; 444a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 445a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < len; i++) 446a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write_pwm_one(pwm, i, cmds[i]); 447a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 448a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write_pwm_one(pwm, i++, PWM_END(kill)); 449a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write(pwm->chip, 2, LM8323_CMD_START_PWM, pwm->id); 450a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->running = true; 451a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 452a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 453a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_pwm_work(struct work_struct *work) 454a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 455a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_pwm *pwm = work_to_pwm(work); 456a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int div512, perstep, steps, hz, up, kill; 457a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u16 pwm_cmds[3]; 458a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int num_cmds = 0; 459a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 460a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&pwm->lock); 461a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 462a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 463a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Do nothing if we're already at the requested level, 464a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * or previous setting is not yet complete. In the latter 465a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * case we will be called again when the previous PWM script 466a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * finishes. 467a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 468a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (pwm->running || pwm->desired_brightness == pwm->brightness) 469a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto out; 470a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 471a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi kill = (pwm->desired_brightness == 0); 472a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi up = (pwm->desired_brightness > pwm->brightness); 473a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi steps = abs(pwm->desired_brightness - pwm->brightness); 474a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 475a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 476a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Convert time (in ms) into a divisor (512 or 16 on a refclk of 477a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 32768Hz), and number of ticks per step. 478a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 479a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if ((pwm->fade_time / steps) > (32768 / 512)) { 480a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi div512 = 1; 481a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi hz = 32768 / 512; 482a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } else { 483a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi div512 = 0; 484a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi hz = 32768 / 16; 485a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 486a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 487a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi perstep = (hz * pwm->fade_time) / (steps * 1000); 488a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 489a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (perstep == 0) 490a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi perstep = 1; 491a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi else if (perstep > 63) 492a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi perstep = 63; 493a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 494a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi while (steps) { 495a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int s; 496a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 497a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi s = min(126, steps); 498a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm_cmds[num_cmds++] = PWM_RAMP(div512, perstep, s, up); 499a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi steps -= s; 500a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 501a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 502a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_write_pwm(pwm, kill, num_cmds, pwm_cmds); 503a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->brightness = pwm->desired_brightness; 504a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 505a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi out: 506a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&pwm->lock); 507a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 508a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 509a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic void lm8323_pwm_set_brightness(struct led_classdev *led_cdev, 510a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi enum led_brightness brightness) 511a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 512a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev); 513a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm = pwm->chip; 514a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 515a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&pwm->lock); 516a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->desired_brightness = brightness; 517a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&pwm->lock); 518a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 519a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (in_interrupt()) { 520a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi schedule_work(&pwm->work); 521a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } else { 522a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* 523a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * Schedule PWM work as usual unless we are going into suspend 524a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 525a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&lm->lock); 526a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (likely(!lm->pm_suspend)) 527a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi schedule_work(&pwm->work); 528a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi else 529a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_pwm_work(&pwm->work); 530a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&lm->lock); 531a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 532a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 533a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 534a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic ssize_t lm8323_pwm_show_time(struct device *dev, 535a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct device_attribute *attr, char *buf) 536a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 537a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct led_classdev *led_cdev = dev_get_drvdata(dev); 538a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev); 539a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 540a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return sprintf(buf, "%d\n", pwm->fade_time); 541a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 542a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 543a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic ssize_t lm8323_pwm_store_time(struct device *dev, 544a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct device_attribute *attr, const char *buf, size_t len) 545a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 546a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct led_classdev *led_cdev = dev_get_drvdata(dev); 547a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev); 54876496e7a02e99d42844f4fffa145b81e513e7acdJJ Ding int ret, time; 549a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 55076496e7a02e99d42844f4fffa145b81e513e7acdJJ Ding ret = kstrtoint(buf, 10, &time); 551a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* Numbers only, please. */ 552a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (ret) 55376496e7a02e99d42844f4fffa145b81e513e7acdJJ Ding return ret; 554a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 555a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->fade_time = time; 556a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 557a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return strlen(buf); 558a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 559a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic DEVICE_ATTR(time, 0644, lm8323_pwm_show_time, lm8323_pwm_store_time); 560a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 561f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovoldstatic struct attribute *lm8323_pwm_attrs[] = { 562f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold &dev_attr_time.attr, 563f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold NULL 564f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold}; 565f254bea49d05ee80b09d577947bd3b937e3a304aJohan HovoldATTRIBUTE_GROUPS(lm8323_pwm); 566f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold 567a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, 568a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi const char *name) 569a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 570a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_pwm *pwm; 571a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 572a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi BUG_ON(id > 3); 573a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 574a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm = &lm->pwm[id - 1]; 575a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 576a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->id = id; 577a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->fade_time = 0; 578a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->brightness = 0; 579a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->desired_brightness = 0; 580a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->running = false; 581a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->enabled = false; 582a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi INIT_WORK(&pwm->work, lm8323_pwm_work); 583a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_init(&pwm->lock); 584a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->chip = lm; 585a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 586a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (name) { 587a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->cdev.name = name; 588a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->cdev.brightness_set = lm8323_pwm_set_brightness; 589f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold pwm->cdev.groups = lm8323_pwm_groups; 590a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (led_classdev_register(dev, &pwm->cdev) < 0) { 591a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(dev, "couldn't register PWM %d\n", id); 592a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return -1; 593a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 594a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pwm->enabled = true; 595a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 596a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 597a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 598a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 599a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 600a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic struct i2c_driver lm8323_i2c_driver; 601a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 602a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic ssize_t lm8323_show_disable(struct device *dev, 603a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct device_attribute *attr, char *buf) 604a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 605a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm = dev_get_drvdata(dev); 606a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 607a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return sprintf(buf, "%u\n", !lm->kp_enabled); 608a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 609a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 610a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic ssize_t lm8323_set_disable(struct device *dev, 611a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct device_attribute *attr, 612a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi const char *buf, size_t count) 613a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 614a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm = dev_get_drvdata(dev); 615a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int ret; 61676496e7a02e99d42844f4fffa145b81e513e7acdJJ Ding unsigned int i; 617a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 61876496e7a02e99d42844f4fffa145b81e513e7acdJJ Ding ret = kstrtouint(buf, 10, &i); 619a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 620a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&lm->lock); 621a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->kp_enabled = !i; 622a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&lm->lock); 623a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 624a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return count; 625a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 626a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic DEVICE_ATTR(disable_kp, 0644, lm8323_show_disable, lm8323_set_disable); 627a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 6285298cc4cc753bbe4c530b41341834f6ef3344d0dBill Pembertonstatic int lm8323_probe(struct i2c_client *client, 629a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi const struct i2c_device_id *id) 630a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 631c838cb3d477f79738ee03ede53a3f724021f3ae0Jingoo Han struct lm8323_platform_data *pdata = dev_get_platdata(&client->dev); 632a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct input_dev *idev; 633a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm; 6341796b983cc4cbbed5e9e478b03591609a2c21987Dan Carpenter int pwm; 635a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i, err; 636a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi unsigned long tmo; 637a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi u8 data[2]; 638a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 639a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (!pdata || !pdata->size_x || !pdata->size_y) { 640a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&client->dev, "missing platform_data\n"); 641a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return -EINVAL; 642a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 643a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 644a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (pdata->size_x > 8) { 645a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&client->dev, "invalid x size %d specified\n", 646a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pdata->size_x); 647a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return -EINVAL; 648a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 649a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 650a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (pdata->size_y > 12) { 651a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&client->dev, "invalid y size %d specified\n", 652a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi pdata->size_y); 653a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return -EINVAL; 654a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 655a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 656a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm = kzalloc(sizeof *lm, GFP_KERNEL); 657a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi idev = input_allocate_device(); 658a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (!lm || !idev) { 659a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi err = -ENOMEM; 660a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto fail1; 661a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 662a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 663a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->client = client; 664a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->idev = idev; 665a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_init(&lm->lock); 666a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 667a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->size_x = pdata->size_x; 668a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->size_y = pdata->size_y; 669a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_vdbg(&client->dev, "Keypad size: %d x %d\n", 670a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->size_x, lm->size_y); 671a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 672a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->debounce_time = pdata->debounce_time; 673a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->active_time = pdata->active_time; 674a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 675a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_reset(lm); 676a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 677a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* Nothing's set up to service the IRQ yet, so just spin for max. 678a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * 100ms until we can configure. */ 679a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi tmo = jiffies + msecs_to_jiffies(100); 680a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi while (lm8323_read(lm, LM8323_CMD_READ_INT, data, 1) == 1) { 681a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (data[0] & INT_NOINIT) 682a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi break; 683a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 684a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (time_after(jiffies, tmo)) { 685a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&client->dev, 686a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi "timeout waiting for initialisation\n"); 687a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi break; 688a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 689a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 690a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi msleep(1); 691a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 692a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 693a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm8323_configure(lm); 694a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 695a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi /* If a true probe check the device */ 696a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (lm8323_read_id(lm, data) != 0) { 697a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&client->dev, "device not found\n"); 698a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi err = -ENODEV; 699a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto fail1; 700a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 701a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 7021796b983cc4cbbed5e9e478b03591609a2c21987Dan Carpenter for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) { 7031796b983cc4cbbed5e9e478b03591609a2c21987Dan Carpenter err = init_pwm(lm, pwm + 1, &client->dev, 7041796b983cc4cbbed5e9e478b03591609a2c21987Dan Carpenter pdata->pwm_names[pwm]); 705a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (err < 0) 706a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto fail2; 707a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 708a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 709a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->kp_enabled = true; 710a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi err = device_create_file(&client->dev, &dev_attr_disable_kp); 711a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (err < 0) 712a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto fail2; 713a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 714a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi idev->name = pdata->name ? : "LM8323 keypad"; 715a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi snprintf(lm->phys, sizeof(lm->phys), 716a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi "%s/input-kp", dev_name(&client->dev)); 717a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi idev->phys = lm->phys; 718a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 719a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi idev->evbit[0] = BIT(EV_KEY) | BIT(EV_MSC); 720a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi __set_bit(MSC_SCAN, idev->mscbit); 721a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < LM8323_KEYMAP_SIZE; i++) { 722a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi __set_bit(pdata->keymap[i], idev->keybit); 723a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->keymap[i] = pdata->keymap[i]; 724a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 725a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi __clear_bit(KEY_RESERVED, idev->keybit); 726a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 727a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (pdata->repeat) 728a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi __set_bit(EV_REP, idev->evbit); 729a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 730a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi err = input_register_device(idev); 731a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (err) { 732a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_dbg(&client->dev, "error registering input device\n"); 733a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto fail3; 734a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 735a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 73661cf3813d32411b23d5df8a650bbd2aa89b4618cFelipe Balbi err = request_threaded_irq(client->irq, NULL, lm8323_irq, 737eaa499aebf6265f18ffc836ead30059031c6d7a7Leigh Brown IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm); 738a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (err) { 739a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi dev_err(&client->dev, "could not get IRQ %d\n", client->irq); 740a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi goto fail4; 741a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi } 742a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 743a5b33e6a207d75120ad9dad0b5401b561991dcceWolfram Sang i2c_set_clientdata(client, lm); 744a5b33e6a207d75120ad9dad0b5401b561991dcceWolfram Sang 745a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi device_init_wakeup(&client->dev, 1); 746a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi enable_irq_wake(client->irq); 747a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 748a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 749a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 750a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbifail4: 751a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi input_unregister_device(idev); 752a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi idev = NULL; 753a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbifail3: 754a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi device_remove_file(&client->dev, &dev_attr_disable_kp); 755a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbifail2: 7561796b983cc4cbbed5e9e478b03591609a2c21987Dan Carpenter while (--pwm >= 0) 757f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold if (lm->pwm[pwm].enabled) 7581796b983cc4cbbed5e9e478b03591609a2c21987Dan Carpenter led_classdev_unregister(&lm->pwm[pwm].cdev); 759a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbifail1: 760a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi input_free_device(idev); 761a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi kfree(lm); 762a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return err; 763a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 764a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 765e2619cf78e19476bfd7ceaefa9eff0847529346eBill Pembertonstatic int lm8323_remove(struct i2c_client *client) 766a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 767a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm = i2c_get_clientdata(client); 768a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i; 769a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 770a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi disable_irq_wake(client->irq); 771a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi free_irq(client->irq, lm); 772a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 773a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi input_unregister_device(lm->idev); 774a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 775a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi device_remove_file(&lm->client->dev, &dev_attr_disable_kp); 776a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 777a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < 3; i++) 778f254bea49d05ee80b09d577947bd3b937e3a304aJohan Hovold if (lm->pwm[i].enabled) 779a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi led_classdev_unregister(&lm->pwm[i].cdev); 780a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 781a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi kfree(lm); 782a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 783a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 784a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 785a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 786f80aee7fd095d9014a92a250c688ff5dbc0a6649Dmitry Torokhov#ifdef CONFIG_PM_SLEEP 787a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi/* 788a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * We don't need to explicitly suspend the chip, as it already switches off 789a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi * when there's no activity. 790a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi */ 79165b0c03852d75e4d7d0bc282344b1500fe471725Mark Brownstatic int lm8323_suspend(struct device *dev) 792a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 79365b0c03852d75e4d7d0bc282344b1500fe471725Mark Brown struct i2c_client *client = to_i2c_client(dev); 794a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm = i2c_get_clientdata(client); 795a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i; 796a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 797dced35aeb0367dda2636ee9ee914bda14510dcc9Thomas Gleixner irq_set_irq_wake(client->irq, 0); 798a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi disable_irq(client->irq); 799a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 800a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&lm->lock); 801a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->pm_suspend = true; 802a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&lm->lock); 803a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 804a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < 3; i++) 805a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (lm->pwm[i].enabled) 806a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi led_classdev_suspend(&lm->pwm[i].cdev); 807a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 808a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 809a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 810a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 81165b0c03852d75e4d7d0bc282344b1500fe471725Mark Brownstatic int lm8323_resume(struct device *dev) 812a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi{ 81365b0c03852d75e4d7d0bc282344b1500fe471725Mark Brown struct i2c_client *client = to_i2c_client(dev); 814a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi struct lm8323_chip *lm = i2c_get_clientdata(client); 815a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi int i; 816a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 817a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_lock(&lm->lock); 818a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi lm->pm_suspend = false; 819a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi mutex_unlock(&lm->lock); 820a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 821a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi for (i = 0; i < 3; i++) 822a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi if (lm->pwm[i].enabled) 823a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi led_classdev_resume(&lm->pwm[i].cdev); 824a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 825a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi enable_irq(client->irq); 826dced35aeb0367dda2636ee9ee914bda14510dcc9Thomas Gleixner irq_set_irq_wake(client->irq, 1); 827a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 828a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi return 0; 829a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi} 830a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi#endif 831a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 83265b0c03852d75e4d7d0bc282344b1500fe471725Mark Brownstatic SIMPLE_DEV_PM_OPS(lm8323_pm_ops, lm8323_suspend, lm8323_resume); 83365b0c03852d75e4d7d0bc282344b1500fe471725Mark Brown 834a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic const struct i2c_device_id lm8323_id[] = { 835a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi { "lm8323", 0 }, 836a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi { } 837a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi}; 838a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 839a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbistatic struct i2c_driver lm8323_i2c_driver = { 840a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi .driver = { 841a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi .name = "lm8323", 84265b0c03852d75e4d7d0bc282344b1500fe471725Mark Brown .pm = &lm8323_pm_ops, 843a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi }, 844a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi .probe = lm8323_probe, 8451cb0aa88179b7a71c240529e9d781d7bbb43d2e8Bill Pemberton .remove = lm8323_remove, 846a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi .id_table = lm8323_id, 847a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi}; 848a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe BalbiMODULE_DEVICE_TABLE(i2c, lm8323_id); 849a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 8501b92c1cf6b638e7cbe9fdaac3f6efb8874f5cc02Axel Linmodule_i2c_driver(lm8323_i2c_driver); 851a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 852a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe BalbiMODULE_AUTHOR("Timo O. Karjalainen <timo.o.karjalainen@nokia.com>"); 853a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe BalbiMODULE_AUTHOR("Daniel Stone"); 854a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe BalbiMODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>"); 855a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe BalbiMODULE_DESCRIPTION("LM8323 keypad driver"); 856a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe BalbiMODULE_LICENSE("GPL"); 857a48b2d4a0091904b4cf57d667adc2faf689750d3Felipe Balbi 858